Bridge++  Ver. 2.0.2
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=====
GradientFlow_AdaptiveRungeKutta::m_RK
GradientFlow_RungeKutta * m_RK
Definition: gradientFlow_AdaptiveRungeKutta.h:48
GradientFlow_RungeKutta::flow
virtual void flow(double &t, double &Estep, Field_G &U)=0
GradientFlow_AdaptiveRungeKutta::flow
void flow(double &t, double &Estep, Field_G &U)
Definition: gradientFlow_AdaptiveRungeKutta.cpp:19
Communicator::reduce_max
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...
Definition: communicator.cpp:290
Field::nex
int nex() const
Definition: field.h:128
copy
void copy(Field &y, const Field &x)
copy(y, x): y = x
Definition: field.cpp:212
GradientFlow_AdaptiveRungeKutta::class_name
static const std::string class_name
Definition: gradientFlow_AdaptiveRungeKutta.h:37
gradientFlow_AdaptiveRungeKutta.h
GradientFlow_AdaptiveRungeKutta::Norder_RK
int Norder_RK() const
Definition: gradientFlow_AdaptiveRungeKutta.h:75
CommonParameters::Nc
static int Nc()
Definition: commonParameters.h:115
GradientFlow_AdaptiveRungeKutta::m_U_fine
Field_G m_U_fine
Definition: gradientFlow_AdaptiveRungeKutta.h:53
GradientFlow_AdaptiveRungeKutta::m_U_rough
Field_G m_U_rough
Definition: gradientFlow_AdaptiveRungeKutta.h:53
SU_N::Mat_SU_N
Definition: mat_SU_N.h:36
GradientFlow_AdaptiveRungeKutta::max_diff_U
double max_diff_U(const Field_G &U1, const Field_G &U0) const
Definition: gradientFlow_AdaptiveRungeKutta.cpp:67
Field::nvol
int nvol() const
Definition: field.h:127
Bridge::BridgeIO::crucial
void crucial(const char *format,...)
Definition: bridgeIO.cpp:180
GradientFlow_AdaptiveRungeKutta::m_vl
Bridge::VerboseLevel m_vl
Definition: gradientFlow_AdaptiveRungeKutta.h:40
Field_G::mat
Mat_SU_N mat(const int site, const int mn=0) const
Definition: field_G.h:114
Field_G
SU(N) gauge field.
Definition: field_G.h:38
Bridge::BridgeIO::general
void general(const char *format,...)
Definition: bridgeIO.cpp:200
GradientFlow_AdaptiveRungeKutta::m_tolerance
double m_tolerance
Definition: gradientFlow_AdaptiveRungeKutta.h:50
GradientFlow_AdaptiveRungeKutta::m_safety
double m_safety
Definition: gradientFlow_AdaptiveRungeKutta.h:51
Bridge::vout
BridgeIO vout
Definition: bridgeIO.cpp:512
SU_N::Mat_SU_N::norm2
double norm2()
Definition: mat_SU_N.h:181