Grid 0.7.0
ActionBase.h
Go to the documentation of this file.
1/*************************************************************************************
2
3Grid physics library, www.github.com/paboyle/Grid
4
5Source file: ./lib/qcd/action/ActionBase.h
6
7Copyright (C) 2015-2016
8
9Author: Peter Boyle <paboyle@ph.ed.ac.uk>
10Author: neo <cossu@post.kek.jp>
11Author: Guido Cossu <guido.cossu@ed.ac.uk>
12
13This program is free software; you can redistribute it and/or modify
14it under the terms of the GNU General Public License as published by
15the Free Software Foundation; either version 2 of the License, or
16(at your option) any later version.
17
18This program is distributed in the hope that it will be useful,
19but WITHOUT ANY WARRANTY; without even the implied warranty of
20MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21GNU General Public License for more details.
22
23You should have received a copy of the GNU General Public License along
24with this program; if not, write to the Free Software Foundation, Inc.,
2551 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26
27See the full license in the file "LICENSE" in the top level distribution
28directory
29*************************************************************************************/
30 /* END LEGAL */
31
32#ifndef ACTION_BASE_H
33#define ACTION_BASE_H
34
38
46
47template< class Field >
51{
52public:
54 virtual ~ConfigurationBase() {}
55 virtual void set_Field(Field& U) =0;
56 virtual void smeared_force(Field&) = 0;
57 virtual Field& get_SmearedU() =0;
58 virtual Field &get_U(bool smeared = false) = 0;
59};
60
61template <class GaugeField >
62class Action
64{
65public:
66 bool is_smeared = false;
75
79 void reset_timer(void) {
80 deriv_us = S_us = refresh_us = 0.0;
83 deriv_num=0;
84 }
85
91 void deriv_log(RealD nrm, RealD max,RealD Fdt_nrm,RealD Fdt_max) {
92 if ( max > deriv_max_sum ) {
93 deriv_max_sum=max;
94 }
95 deriv_norm_sum+=nrm;
96 if ( Fdt_max > Fdt_max_sum ) {
97 Fdt_max_sum=Fdt_max;
98 }
99 Fdt_norm_sum+=Fdt_nrm; deriv_num++;
100 }
101
110 RealD deriv_timer(void) { return deriv_us; };
112 RealD S_timer(void) { return S_us; };
114 RealD refresh_timer(void) { return refresh_us; };
124 void S_timer_start(void) { S_us-=usecond(); }
126 void S_timer_stop(void) { S_us+=usecond(); }
128
132 // Heatbath?
134
139 virtual void refresh(const GaugeField& U, GridSerialRNG &sRNG, GridParallelRNG& pRNG) = 0;
140
145 virtual RealD S(const GaugeField& U) = 0;
146
155 /* An alternative approach would be to have a refreshAndAction() function,
156 * with the caller responsible for caching. */
157 virtual RealD Sinitial(const GaugeField& U) { return this->S(U); } ;
158
164 virtual void deriv(const GaugeField& U, GaugeField& dSdU) = 0;
166
179 {
180 refresh(U.get_U(is_smeared),sRNG,pRNG);
181 }
182
188 {
189 return S(U.get_U(is_smeared));
190 }
191
199 /* An alternative approach would be to have a refreshAndAction() function,
200 * with the caller responsible for caching. */
202 {
203 return Sinitial(U.get_U(is_smeared));
204 }
205
210 virtual void deriv(ConfigurationBase<GaugeField>& U, GaugeField& dSdU)
211 {
212 deriv(U.get_U(is_smeared),dSdU);
213 if ( is_smeared ) {
214 U.smeared_force(dSdU);
215 }
216 }
217
220 virtual std::string action_name() = 0;
221 virtual std::string LogParameters() = 0;
223 virtual ~Action(){}
224};
225
226template <class GaugeField >
227class EmptyAction : public Action <GaugeField>
229{
230 using Action<GaugeField>::refresh;
231 using Action<GaugeField>::Sinitial;
232 using Action<GaugeField>::deriv;
233
234 virtual void refresh(const GaugeField& U, GridSerialRNG &sRNG, GridParallelRNG& pRNG) { assert(0);}; // refresh pseudofermions
235 virtual RealD S(const GaugeField& U) { return 0.0;}; // evaluate the action
236 virtual void deriv(const GaugeField& U, GaugeField& dSdU) { assert(0); }; // evaluate the action derivative
237
239 // Logging
241 virtual std::string action_name() { return std::string("Level Force Log"); };
242 virtual std::string LogParameters() { return std::string("No parameters");};
243};
244
245
249
250#endif // ACTION_BASE_H
#define NAMESPACE_BEGIN(A)
Definition Namespace.h:35
#define NAMESPACE_END(A)
Definition Namespace.h:36
double RealD
Definition Simd.h:61
double usecond(void)
Definition Timer.h:50
static INTERNAL_PRECISION U
Definition Zolotarev.cc:230
Base class for all actions.
Definition ActionBase.h:64
virtual RealD S(const GaugeField &U)=0
Evaluate this action with the given gauge field.
RealD Fdt_norm_average(void)
Mean (absolute value of) impulse (force integrated over a time step) for a trajectory.
Definition ActionBase.h:108
void deriv_log(RealD nrm, RealD max, RealD Fdt_nrm, RealD Fdt_max)
Record statistics on the action and derivative.
Definition ActionBase.h:91
virtual RealD Sinitial(ConfigurationBase< GaugeField > &U)
Get the action at the start of the trajectory.
Definition ActionBase.h:201
void deriv_timer_start(void)
Start timing derivative computation.
Definition ActionBase.h:116
virtual void refresh(ConfigurationBase< GaugeField > &U, GridSerialRNG &sRNG, GridParallelRNG &pRNG)
Refresh pseudofermion fields.
Definition ActionBase.h:178
virtual RealD S(ConfigurationBase< GaugeField > &U)
Evaluate this action with the given gauge field.
Definition ActionBase.h:187
virtual void deriv(ConfigurationBase< GaugeField > &U, GaugeField &dSdU)
Definition ActionBase.h:210
void refresh_timer_stop(void)
Stop timing pseudofermion field refresh.
Definition ActionBase.h:122
void deriv_timer_stop(void)
Stop timing derivative computation.
Definition ActionBase.h:118
RealD refresh_timer(void)
Time spent refreshing pseudofermion fields in microseconds.
Definition ActionBase.h:114
virtual RealD Sinitial(const GaugeField &U)
Get the action at the start of the trajectory.
Definition ActionBase.h:157
virtual std::string LogParameters()=0
Print the parameters of the action.
virtual std::string action_name()=0
Report the name of the action.
RealD deriv_norm_average(void)
Mean (absolute value of) derivative for a trajectory.
Definition ActionBase.h:104
void reset_timer(void)
Zero timers associated with this action.
Definition ActionBase.h:79
RealD Fdt_max_average(void)
Mean maximum value of impulse (force integrated over a time step) for a trajectory.
Definition ActionBase.h:106
RealD deriv_max_average(void)
Mean maximum derivative for a trajectory.
Definition ActionBase.h:102
void S_timer_start(void)
Start timing action computation.
Definition ActionBase.h:124
void S_timer_stop(void)
Stop timing action computation.
Definition ActionBase.h:126
virtual void refresh(const GaugeField &U, GridSerialRNG &sRNG, GridParallelRNG &pRNG)=0
Refresh pseudofermion fields.
RealD S_timer(void)
Time spent computing the action in microseconds.
Definition ActionBase.h:112
void refresh_timer_start(void)
Start timing pseudofermion field refresh.
Definition ActionBase.h:120
virtual ~Action()
Definition ActionBase.h:223
virtual void deriv(const GaugeField &U, GaugeField &dSdU)=0
RealD deriv_timer(void)
Time spent computing the derivative in microseconds.
Definition ActionBase.h:110
Base class for "smart configuration", a container for a gauge configuration holding unsmeared and sme...
Definition ActionBase.h:51
virtual Field & get_SmearedU()=0
virtual ~ConfigurationBase()
Definition ActionBase.h:54
virtual void set_Field(Field &U)=0
virtual void smeared_force(Field &)=0
virtual Field & get_U(bool smeared=false)=0
A trivial action, which may be used as a placeholder.
Definition ActionBase.h:229
virtual void refresh(const GaugeField &U, GridSerialRNG &sRNG, GridParallelRNG &pRNG)
Refresh pseudofermion fields.
Definition ActionBase.h:234
virtual void deriv(const GaugeField &U, GaugeField &dSdU)
Definition ActionBase.h:236
virtual std::string LogParameters()
Print the parameters of the action.
Definition ActionBase.h:242
virtual RealD S(const GaugeField &U)
Evaluate this action with the given gauge field.
Definition ActionBase.h:235
virtual std::string action_name()
Report the name of the action.
Definition ActionBase.h:241