CHROMA
force_monitors.cc
Go to the documentation of this file.
1 /*! @file
2  * @brief Helper function for calculating forces
3  */
4 
7 #include "util/gauge/taproj.h"
8 
9 namespace Chroma
10 {
11 
12 
13  //! Writes a ForceCalc_t
14  /*! @ingroup monomial */
15  void write(XMLWriter& xml_out, const std::string& path, const ForceMonitors& param)
16  {
17  push(xml_out, path);
18 
19  write(xml_out, "F_sq_per_direction", param.F_sq_dir);
20  write(xml_out, "F_avg_per_direction", param.F_avg_dir);
21  write(xml_out, "F_max_per_direction", param.F_max_dir);
22  write(xml_out, "F_max_dt_per_direction", param.F_max_dt_dir);
23  write(xml_out, "F_sq", param.F_sq);
24  write(xml_out, "F_avg", param.F_avg);
25  write(xml_out, "F_max", param.F_max);
26  write(xml_out, "F_max_dt", param.F_max_dt);
27 
28  pop(xml_out);
29  }
30 
31 
32  //! Helper function for calculating forces
33  /*! @ingroup monomial */
34  inline
35  void forceMonitorCalc(const multi1d<LatticeColorMatrix>& F, ForceMonitors& forces)
36  {
37  START_CODE();
38 
39  // ForceCalc_t forces;
40 
41  forces.F_sq = zero;
42  forces.F_avg = zero;
43  forces.F_max = zero;
44 
45  forces.F_sq_dir.resize(Nd);
46  forces.F_avg_dir.resize(Nd);
47  forces.F_max_dir.resize(Nd);
48  forces.F_max_dt_dir.resize(Nd);
49 
50  // Precompute these
51  multi1d<LatticeReal> f2(F.size());
52  multi1d<LatticeReal> f1(F.size());
53  Real num_sites = QDP::Layout::vol();
54 
55  for(int mu=0; mu < F.size(); ++mu)
56  {
57  // This may be expensive
58  LatticeColorMatrix F_tmp = F[mu];
59 
60  // Force will get taproj-ed at the end...
61  // Make sure we look at the right hing
62  taproj(F_tmp);
63 
64  // Jansens measure
65  // -2 Tr F^2 = -2 ( -F^\dagger F ) = 2 F^\dagger F
66  // the 2 counteracts taproj normalization maybe?
67  f2[mu] = Real(-2)*real(trace(F_tmp*F_tmp));
68 
69  f1[mu] = sqrt(f2[mu]);
70  }
71 
73 
74 
75  // Standard kind of sums
76  for(int mu=0; mu < F.size(); ++mu)
77  {
78  // Get Square norms for direction mu - divide to get 'per site'
79  forces.F_sq_dir[mu] = sum(f2[mu])/num_sites;
80 
81  // Get average norm for direction mu - divide to get 'per site'
82  forces.F_avg_dir[mu] = sum(f1[mu])/num_sites;
83 
84  // Get max force for direction mu - this is already 'per site'
85  forces.F_max_dir[mu] = globalMax(f1[mu]);
86 
87  // multiply max force per dir with its actual step-size.
88  forces.F_max_dt_dir[mu] = aniso_step.getStepSizeFactor(mu)*forces.F_max_dir[mu];
89 
90  //Sum up squares and averages
91  forces.F_sq += forces.F_sq_dir[mu];
92  forces.F_avg += forces.F_avg_dir[mu];
93  }
94 
95  // Divide F_sq and F_avg by the number of directions now (for average)
96  Real fact_tmp = Real(1)/Real(Nd);
97  forces.F_sq *= fact_tmp;
98  forces.F_avg *= fact_tmp;
99 
100  // Find the maximum of the 4 directions.
101  forces.F_max = forces.F_max_dir[0];
102  forces.F_max_dt =forces.F_max_dt_dir[0];
103 
104  for(int mu=1; mu < F.size(); ++mu)
105  {
106  if( toBool( forces.F_max < forces.F_max_dir[mu] ) ) {
107  forces.F_max = forces.F_max_dir[mu];
108  }
109  if( toBool( forces.F_max_dt < forces.F_max_dt_dir[mu]) ) {
110  forces.F_max_dt = forces.F_max_dt_dir[mu];
111  }
112  }
113 
114  END_CODE();
115 
116  return;
117  }
118 
119 
120  namespace ForceMonitorEnv {
121  static bool monitorForcesP = true;
122  }
123 
124  void setForceMonitoring(bool monitorP)
125  {
127  }
128 
129 
130  void monitorForces(XMLWriter& xml_out, const std::string& path, const multi1d<LatticeColorMatrix>& F)
131  {
132  if( ForceMonitorEnv::monitorForcesP == true ) {
133  QDPIO::cout << "Monitoring force" << std::endl;
134  ForceMonitors mon;
135  forceMonitorCalc(F, mon);
136  write(xml_out, path, mon);
137  }
138  }
139 } //end namespace Chroma
140 
141 
static T & Instance()
Definition: singleton.h:432
int mu
Definition: cool.cc:24
Helper function for calculating forces.
void write(XMLWriter &xml, const std::string &path, const AsqtadFermActParams &param)
Writer parameters.
void taproj(LatticeColorMatrix &a)
Take the traceless antihermitian projection of a color matrix.
Definition: taproj.cc:31
void forceMonitorCalc(const multi1d< LatticeColorMatrix > &F, ForceMonitors &forces)
Helper function for calculating forces.
void monitorForces(XMLWriter &xml_out, const std::string &path, const multi1d< LatticeColorMatrix > &F)
Calculate and write out forces.
Nd
Definition: meslate.cc:74
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
push(xml_out,"Condensates")
void setForceMonitoring(bool monitorP)
pop(xml_out)
START_CODE()
Double zero
Definition: invbicg.cc:106
const T1 const T2 & f2
Definition: gtest.h:1321
const T1 & f1
Definition: gtest.h:1316
::std::string string
Definition: gtest.h:1979
Double sum
Definition: qtopcor.cc:37
Diagnostics about the forces, per direction and total.
multi1d< Real > F_max_dir
multi1d< Real > F_avg_dir
multi1d< Real > F_max_dt_dir
multi1d< Real > F_sq_dir
Take the traceless antihermitian projection of a color matrix.
static INTERNAL_PRECISION F