mirror of
https://github.com/paboyle/Grid.git
synced 2024-11-10 07:55:35 +00:00
Reduced code duplication in hadron tests
This commit is contained in:
parent
d44cc204d1
commit
98f610ce53
@ -33,6 +33,30 @@ using namespace Hadrons;
|
||||
/*******************************************************************************
|
||||
* Macros to reduce code duplication.
|
||||
******************************************************************************/
|
||||
// Common initialisation
|
||||
#define HADRONS_DEFAULT_INIT \
|
||||
Grid_init(&argc, &argv); \
|
||||
HadronsLogError.Active(GridLogError.isActive()); \
|
||||
HadronsLogWarning.Active(GridLogWarning.isActive()); \
|
||||
HadronsLogMessage.Active(GridLogMessage.isActive()); \
|
||||
HadronsLogIterative.Active(GridLogIterative.isActive()); \
|
||||
HadronsLogDebug.Active(GridLogDebug.isActive()); \
|
||||
LOG(Message) << "Grid initialized" << std::endl;
|
||||
|
||||
#define HADRONS_DEFAULT_GLOBALS(application) \
|
||||
{ \
|
||||
Application::GlobalPar globalPar; \
|
||||
globalPar.trajCounter.start = 1500; \
|
||||
globalPar.trajCounter.end = 1520; \
|
||||
globalPar.trajCounter.step = 20; \
|
||||
globalPar.seed = "1 2 3 4"; \
|
||||
globalPar.genetic.maxGen = 1000; \
|
||||
globalPar.genetic.maxCstGen = 200; \
|
||||
globalPar.genetic.popSize = 20; \
|
||||
globalPar.genetic.mutationRate = .1; \
|
||||
application.setPar(globalPar); \
|
||||
}
|
||||
|
||||
// Useful definitions
|
||||
#define ZERO_MOM "0. 0. 0. 0."
|
||||
#define INIT_INDEX(s, n) (std::string(s) + "_" + std::to_string(n))
|
||||
@ -73,10 +97,82 @@ using namespace Hadrons;
|
||||
makePropagator(application, propName, srcName, solver);\
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Action setups.
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Name: makeWilsonAction
|
||||
* Parameters: application - main application that stores modules.
|
||||
* actionName - name of action module to create.
|
||||
* gaugeField - gauge field module.
|
||||
* mass - quark mass.
|
||||
* Returns: None.
|
||||
******************************************************************************/
|
||||
inline void makeWilsonAction(Application &application, std::string actionName,
|
||||
std::string &gaugeField, double mass)
|
||||
{
|
||||
if (!(Environment::getInstance().hasModule(actionName)))
|
||||
{
|
||||
MAction::Wilson::Par actionPar;
|
||||
actionPar.gauge = gaugeField;
|
||||
actionPar.mass = mass;
|
||||
application.createModule<MAction::Wilson>(actionName, actionPar);
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Name: makeDWFAction
|
||||
* Parameters: application - main application that stores modules.
|
||||
* actionName - name of action module to create.
|
||||
* gaugeField - gauge field module.
|
||||
* mass - quark mass.
|
||||
* M5 - domain wall height.
|
||||
* Ls - fifth dimension extent.
|
||||
* Returns: None.
|
||||
******************************************************************************/
|
||||
inline void makeDWFAction(Application &application, std::string actionName,
|
||||
std::string &gaugeField, double mass, double M5,
|
||||
unsigned int Ls)
|
||||
{
|
||||
if (!(Environment::getInstance().hasModule(actionName)))
|
||||
{
|
||||
MAction::DWF::Par actionPar;
|
||||
actionPar.gauge = gaugeField;
|
||||
actionPar.Ls = Ls;
|
||||
actionPar.M5 = M5;
|
||||
actionPar.mass = mass;
|
||||
application.createModule<MAction::DWF>(actionName, actionPar);
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Functions for propagator construction.
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Name: makeRBPrecCGSolver
|
||||
* Purpose: Make RBPrecCG solver module for specified action.
|
||||
* Parameters: application - main application that stores modules.
|
||||
* solverName - name of solver module to create.
|
||||
* actionName - action module corresponding to propagators to be
|
||||
* computed.
|
||||
* residual - CG target residual.
|
||||
* Returns: None.
|
||||
******************************************************************************/
|
||||
inline void makeRBPrecCGSolver(Application &application, std::string &solverName,
|
||||
std::string &actionName, double residual = 1e-8)
|
||||
{
|
||||
if (!(Environment::getInstance().hasModule(solverName)))
|
||||
{
|
||||
MSolver::RBPrecCG::Par solverPar;
|
||||
solverPar.action = actionName;
|
||||
solverPar.residual = residual;
|
||||
application.createModule<MSolver::RBPrecCG>(solverName,
|
||||
solverPar);
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Name: makePointSource
|
||||
* Purpose: Construct point source and add to application module.
|
||||
|
@ -51,13 +51,7 @@ int main(int argc, char *argv[])
|
||||
configStem = argv[1];
|
||||
|
||||
// initialization //////////////////////////////////////////////////////////
|
||||
Grid_init(&argc, &argv);
|
||||
HadronsLogError.Active(GridLogError.isActive());
|
||||
HadronsLogWarning.Active(GridLogWarning.isActive());
|
||||
HadronsLogMessage.Active(GridLogMessage.isActive());
|
||||
HadronsLogIterative.Active(GridLogIterative.isActive());
|
||||
HadronsLogDebug.Active(GridLogDebug.isActive());
|
||||
LOG(Message) << "Grid initialized" << std::endl;
|
||||
HADRONS_DEFAULT_INIT;
|
||||
|
||||
// run setup ///////////////////////////////////////////////////////////////
|
||||
Application application;
|
||||
@ -74,46 +68,33 @@ int main(int argc, char *argv[])
|
||||
unsigned int n_noise = 1;
|
||||
unsigned int nt = 32;
|
||||
bool do_disconnected(false);
|
||||
Gamma::Algebra gT = Gamma::Algebra::GammaT;
|
||||
unsigned int Ls = 16;
|
||||
double M5 = 1.8;
|
||||
|
||||
// Global parameters.
|
||||
Application::GlobalPar globalPar;
|
||||
globalPar.trajCounter.start = 1500;
|
||||
globalPar.trajCounter.end = 1520;
|
||||
globalPar.trajCounter.step = 20;
|
||||
globalPar.seed = "1 2 3 4";
|
||||
globalPar.genetic.maxGen = 1000;
|
||||
globalPar.genetic.maxCstGen = 200;
|
||||
globalPar.genetic.popSize = 20;
|
||||
globalPar.genetic.mutationRate = .1;
|
||||
application.setPar(globalPar);
|
||||
HADRONS_DEFAULT_GLOBALS(application);
|
||||
|
||||
// gauge field
|
||||
std::string gaugeField = "gauge";
|
||||
if (configStem == "None")
|
||||
{
|
||||
application.createModule<MGauge::Unit>("gauge");
|
||||
application.createModule<MGauge::Unit>(gaugeField);
|
||||
}
|
||||
else
|
||||
{
|
||||
MGauge::Load::Par gaugePar;
|
||||
gaugePar.file = configStem;
|
||||
application.createModule<MGauge::Load>("gauge", gaugePar);
|
||||
application.createModule<MGauge::Load>(gaugeField, gaugePar);
|
||||
}
|
||||
for (unsigned int i = 0; i < flavour.size(); ++i)
|
||||
{
|
||||
// actions
|
||||
MAction::DWF::Par actionPar;
|
||||
actionPar.gauge = "gauge";
|
||||
actionPar.Ls = 16;
|
||||
actionPar.M5 = 1.8;
|
||||
actionPar.mass = mass[i];
|
||||
application.createModule<MAction::DWF>("DWF_" + flavour[i], actionPar);
|
||||
std::string actionName = "DWF_" + flavour[i];
|
||||
makeDWFAction(application, actionName, gaugeField, mass[i], M5, Ls);
|
||||
|
||||
// solvers
|
||||
MSolver::RBPrecCG::Par solverPar;
|
||||
solverPar.action = "DWF_" + flavour[i];
|
||||
solverPar.residual = 1.0e-8;
|
||||
application.createModule<MSolver::RBPrecCG>(solvers[i],
|
||||
solverPar);
|
||||
makeRBPrecCGSolver(application, solvers[i], actionName);
|
||||
}
|
||||
|
||||
// Create noise propagators for loops.
|
||||
|
Loading…
Reference in New Issue
Block a user