Bridge++  Version 1.5.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
gradientFlow_AdaptiveRungeKutta.cpp
Go to the documentation of this file.
1 
15 
16 const std::string GradientFlow_AdaptiveRungeKutta::class_name = "GradientFlow_AdaptiveRungeKutta";
17 
18 //====================================================================
19 void GradientFlow_AdaptiveRungeKutta::flow(double& t, double& Estep, Field_G& U)
20 {
21  while (true)
22  {
23  copy(m_U_rough, U);
24  copy(m_U_fine, U);
25 
26  //- rough step
27  double t2 = t;
28  double estep2 = 2.0 * Estep;
29 
30  m_RK->flow(t2, estep2, m_U_rough);
31 
32  //- two original steps
33  double t1 = t;
34  double estep1 = Estep;
35 
36  m_RK->flow(t1, estep1, m_U_fine);
37  m_RK->flow(t1, estep1, m_U_fine);
38 
39  double diff = max_diff_U(m_U_rough, m_U_fine);
40 
41  vout.general(m_vl, " Estep,diff,m_tolerance = %e %e %e\n", Estep, diff, m_tolerance);
42 
43  if (diff < m_tolerance) {
44  copy(U, m_U_fine);
45  t += estep2;
46 
47  // extend stepsize
48  Estep *= m_safety * pow(m_tolerance / diff, 1.0 / (Norder_RK() + 1));
49 
50  break; // exit loop
51  } else {
52  // shrink stepsize
53  Estep *= m_safety * pow(m_tolerance / diff, 1.0 / (Norder_RK() + 1));
54 
55  if (Estep < m_tolerance) {
56  vout.crucial(m_vl, "Error at %s: too small Estep = %e\n", class_name.c_str(), Estep);
57  exit(EXIT_FAILURE);
58  }
59 
60  // proceed to next trial
61  }
62  }
63 }
64 
65 
66 //====================================================================
68 {
69  const int Nvol = U1.nvol();
70  const int Nex = U0.nex();
71  const int Nc = CommonParameters::Nc();
72 
73  double max_norm = 0.0;
74 
75  for (int ex = 0; ex < Nex; ++ex) {
76  for (int site = 0; site < Nvol; ++site) {
77  Mat_SU_N u0(Nc);
78  U1.mat(u0, site, ex);
79 
80  Mat_SU_N u1(Nc);
81  U0.mat(u1, site, ex);
82 
83  Mat_SU_N u2(Nc);
84  u2 = u1 - u0;
85 
86  double norm = sqrt(u2.norm2()) / Nc;
87 
88  if (norm > max_norm) max_norm = norm;
89  }
90  }
91 
92  max_norm = Communicator::reduce_max(max_norm);
93 
94  return max_norm;
95 }
96 
97 
98 //====================================================================
99 //============================================================END=====
BridgeIO vout
Definition: bridgeIO.cpp:503
static int reduce_max(int count, double *recv_buf, double *send_buf, int pattern=0)
find a global maximum of an array of double over the communicator. pattern specifies the dimensions t...
void general(const char *format,...)
Definition: bridgeIO.cpp:197
void flow(double &t, double &Estep, Field_G &U)
int nvol() const
Definition: field.h:127
void copy(Field &y, const Field &x)
copy(y, x): y = x
Definition: field.cpp:532
double max_diff_U(const Field_G &U1, const Field_G &U0) const
SU(N) gauge field.
Definition: field_G.h:38
int nex() const
Definition: field.h:128
void crucial(const char *format,...)
Definition: bridgeIO.cpp:178
double norm2()
Definition: mat_SU_N.h:155
virtual void flow(double &t, double &Estep, Field_G &U)=0
Mat_SU_N mat(const int site, const int mn=0) const
Definition: field_G.h:114