mirror of
https://github.com/paboyle/Grid.git
synced 2025-06-13 20:57:06 +01:00
Adding fermions actions support in the factories
This commit is contained in:
@ -30,132 +30,110 @@ directory
|
||||
/* END LEGAL */
|
||||
#include <Grid/Grid.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace Grid;
|
||||
using namespace Grid::QCD;
|
||||
int main(int argc, char **argv) {
|
||||
using namespace Grid;
|
||||
using namespace Grid::QCD;
|
||||
|
||||
namespace Grid {
|
||||
namespace QCD {
|
||||
Grid_init(&argc, &argv);
|
||||
int threads = GridThread::GetThreads();
|
||||
// here make a routine to print all the relevant information on the run
|
||||
std::cout << GridLogMessage << "Grid is setup to use " << threads << " threads" << std::endl;
|
||||
|
||||
class HMCRunnerParameters : Serializable {
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(HMCRunnerParameters,
|
||||
double, beta,
|
||||
double, mass,
|
||||
int, MaxCGIterations,
|
||||
double, StoppingCondition,
|
||||
bool, smearedAction,
|
||||
int, SaveInterval,
|
||||
std::string, format,
|
||||
std::string, conf_prefix,
|
||||
std::string, rng_prefix,
|
||||
double, rho,
|
||||
int, SmearingLevels,
|
||||
);
|
||||
// Typedefs to simplify notation
|
||||
typedef GenericHMCRunner<MinimumNorm2> HMCWrapper; // Uses the default minimum norm
|
||||
typedef WilsonImplR FermionImplPolicy;
|
||||
typedef WilsonFermionR FermionAction;
|
||||
typedef typename FermionAction::FermionField FermionField;
|
||||
|
||||
HMCRunnerParameters() {}
|
||||
};
|
||||
|
||||
// Derive from the BinaryHmcRunner (templated for gauge fields)
|
||||
class HmcRunner : public BinaryHmcRunner {
|
||||
public:
|
||||
void BuildTheAction(int argc, char **argv)
|
||||
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
||||
HMCWrapper TheHMC;
|
||||
|
||||
{
|
||||
typedef WilsonImplR ImplPolicy;
|
||||
typedef WilsonFermionR FermionAction;
|
||||
typedef typename FermionAction::FermionField FermionField;
|
||||
// Grid from the command line
|
||||
TheHMC.Resources.AddFourDimGrid("gauge");
|
||||
// Possibile to create the module by hand
|
||||
// hardcoding parameters or using a Reader
|
||||
|
||||
UGrid = SpaceTimeGrid::makeFourDimGrid(
|
||||
GridDefaultLatt(), GridDefaultSimd(Nd, vComplex::Nsimd()),
|
||||
GridDefaultMpi());
|
||||
UrbGrid = SpaceTimeGrid::makeFourDimRedBlackGrid(UGrid);
|
||||
|
||||
FGrid = UGrid;
|
||||
FrbGrid = UrbGrid;
|
||||
// Checkpointer definition
|
||||
CheckpointerParameters CPparams;
|
||||
CPparams.config_prefix = "ckpoint_lat";
|
||||
CPparams.rng_prefix = "ckpoint_rng";
|
||||
CPparams.saveInterval = 5;
|
||||
CPparams.format = "IEEE64BIG";
|
||||
|
||||
TheHMC.Resources.LoadBinaryCheckpointer(CPparams);
|
||||
|
||||
RNGModuleParameters RNGpar;
|
||||
RNGpar.SerialSeed = {1,2,3,4,5};
|
||||
RNGpar.ParallelSeed = {6,7,8,9,10};
|
||||
TheHMC.Resources.SetRNGSeeds(RNGpar);
|
||||
|
||||
// Construct observables
|
||||
// here there is too much indirection
|
||||
PlaquetteObsParameters PlPar;
|
||||
PlPar.output_prefix = "Plaquette";
|
||||
PlaquetteMod<HMCWrapper::ImplPolicy> PlaqModule(PlPar);
|
||||
TheHMC.Resources.AddObservable(&PlaqModule);
|
||||
//////////////////////////////////////////////
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Collect actions, here use more encapsulation
|
||||
// need wrappers of the fermionic classes
|
||||
// that have a complex construction
|
||||
// standard
|
||||
RealD beta = 5.6 ;
|
||||
WilsonGaugeActionR Waction(beta);
|
||||
|
||||
// temporarily need a gauge field
|
||||
LatticeGaugeField U(UGrid);
|
||||
auto GridPtr = TheHMC.Resources.GetCartesian();
|
||||
auto GridRBPtr = TheHMC.Resources.GetRBCartesian();
|
||||
|
||||
// Gauge action
|
||||
WilsonGaugeActionR Waction(5.6);
|
||||
LatticeGaugeField U(GridPtr);
|
||||
|
||||
Real mass = -0.77;
|
||||
Real mass = -0.77;
|
||||
|
||||
// Can we define an overloaded operator that does not need U and initialises
|
||||
// it with zeroes?
|
||||
FermionAction FermOp(U, *FGrid, *FrbGrid, mass);
|
||||
// Can we define an overloaded operator that does not need U and initialises
|
||||
// it with zeroes?
|
||||
FermionAction FermOp(U, *GridPtr, *GridRBPtr, mass);
|
||||
|
||||
ConjugateGradient<FermionField> CG(1.0e-8, 2000);
|
||||
ConjugateGradient<FermionField> CG(1.0e-8, 2000);
|
||||
|
||||
TwoFlavourPseudoFermionAction<ImplPolicy> Nf2(FermOp, CG, CG);
|
||||
TwoFlavourPseudoFermionAction<FermionImplPolicy> Nf2(FermOp, CG, CG);
|
||||
|
||||
// Set smearing (true/false), default: false
|
||||
Nf2.is_smeared = false;
|
||||
Nf2.is_smeared = false;
|
||||
|
||||
|
||||
// Collect actions
|
||||
ActionLevel<Field> Level1(1);
|
||||
Level1.push_back(&Nf2);
|
||||
ActionLevel<HMCWrapper::Field> Level1(1);
|
||||
Level1.push_back(&Nf2);
|
||||
|
||||
ActionLevel<Field> Level2(4);
|
||||
Level2.push_back(&Waction);
|
||||
ActionLevel<HMCWrapper::Field> Level2(4);
|
||||
Level2.push_back(&Waction);
|
||||
|
||||
TheAction.push_back(Level1);
|
||||
TheAction.push_back(Level2);
|
||||
TheHMC.TheAction.push_back(Level1);
|
||||
TheHMC.TheAction.push_back(Level2);
|
||||
/////////////////////////////////////////////////////////////
|
||||
|
||||
// Add observables
|
||||
int SaveInterval = 1;
|
||||
std::string format = std::string("IEEE64BIG");
|
||||
std::string conf_prefix = std::string("ckpoint_lat");
|
||||
std::string rng_prefix = std::string("ckpoint_rng");
|
||||
BinaryHmcCheckpointer<BinaryHmcRunner::ImplPolicy> Checkpoint(
|
||||
conf_prefix, rng_prefix, SaveInterval, format);
|
||||
// Can implement also a specific function in the hmcrunner
|
||||
// AddCheckpoint (...) that takes the same parameters + a string/tag
|
||||
// defining the type of the checkpointer
|
||||
// with tags can be implemented by overloading and no ifs
|
||||
// Then force all checkpoint to have few common functions
|
||||
// return an object that is then passed to the Run function
|
||||
|
||||
PlaquetteLogger<BinaryHmcRunner::ImplPolicy> PlaqLog(
|
||||
std::string("Plaquette"));
|
||||
ObservablesList.push_back(&PlaqLog);
|
||||
ObservablesList.push_back(&Checkpoint);
|
||||
|
||||
// Smearing section, omit if not needed
|
||||
/*
|
||||
/*
|
||||
double rho = 0.1; // smearing parameter
|
||||
int Nsmear = 2; // number of smearing levels
|
||||
Smear_Stout<BinaryHmcRunner::ImplPolicy> Stout(rho);
|
||||
SmearedConfiguration<BinaryHmcRunner::ImplPolicy> SmearingPolicy(
|
||||
Smear_Stout<HMCWrapper::ImplPolicy> Stout(rho);
|
||||
SmearedConfiguration<HMCWrapper::ImplPolicy> SmearingPolicy(
|
||||
UGrid, Nsmear, Stout);
|
||||
*/
|
||||
///////////////////
|
||||
*/
|
||||
|
||||
// Run(argc, argv, Checkpoint, SmearingPolicy);
|
||||
Run(argc, argv, Checkpoint); // no smearing
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
// HMC parameters are serialisable
|
||||
TheHMC.Parameters.MD.MDsteps = 20;
|
||||
TheHMC.Parameters.MD.trajL = 1.0;
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
Grid_init(&argc, &argv);
|
||||
|
||||
int threads = GridThread::GetThreads();
|
||||
std::cout << GridLogMessage << "Grid is setup to use " << threads
|
||||
<< " threads" << std::endl;
|
||||
|
||||
HmcRunner TheHMC;
|
||||
|
||||
// Seeds for the random number generators
|
||||
std::vector<int> SerSeed({1, 2, 3, 4, 5});
|
||||
std::vector<int> ParSeed({6, 7, 8, 9, 10});
|
||||
TheHMC.RNGSeeds(SerSeed, ParSeed);
|
||||
|
||||
TheHMC.MDparameters.set(10, 1.0);// MDsteps, traj length
|
||||
|
||||
TheHMC.BuildTheAction(argc, argv);
|
||||
TheHMC.ReadCommandLine(argc, argv); // these can be parameters from file
|
||||
TheHMC.Run(); // no smearing
|
||||
// TheHMC.Run(SmearingPolicy); // for smearing
|
||||
|
||||
Grid_finalize();
|
||||
}
|
||||
|
||||
} // main
|
||||
|
||||
|
||||
|
@ -78,7 +78,7 @@ int main(int argc, char **argv) {
|
||||
// standard
|
||||
RealD beta = 5.6 ;
|
||||
WilsonGaugeActionR Waction(beta);
|
||||
|
||||
|
||||
ActionLevel<HMCWrapper::Field> Level1(1);
|
||||
Level1.push_back(&Waction);
|
||||
//Level1.push_back(WGMod.getPtr());
|
||||
@ -89,7 +89,7 @@ int main(int argc, char **argv) {
|
||||
TheHMC.Parameters.MD.MDsteps = 20;
|
||||
TheHMC.Parameters.MD.trajL = 1.0;
|
||||
|
||||
TheHMC.ReadCommandLine(argc, argv); // these must be parameters from file
|
||||
TheHMC.ReadCommandLine(argc, argv); // these can be parameters from file
|
||||
TheHMC.Run(); // no smearing
|
||||
|
||||
Grid_finalize();
|
||||
|
Reference in New Issue
Block a user