mirror of
https://github.com/paboyle/Grid.git
synced 2025-04-07 04:35:56 +01:00
Hadrons: module parameters can now be accessed from outside
This commit is contained in:
parent
3d78ed03ef
commit
362f255100
@ -67,9 +67,8 @@ namespace Grid {
|
||||
return os;
|
||||
}
|
||||
|
||||
class Serializable {};
|
||||
|
||||
// static polymorphism implemented using CRTP idiom
|
||||
class Serializable;
|
||||
|
||||
// Static abstract writer
|
||||
template <typename T>
|
||||
@ -122,6 +121,27 @@ namespace Grid {
|
||||
T *upcast;
|
||||
};
|
||||
|
||||
// serializable base class
|
||||
class Serializable
|
||||
{
|
||||
public:
|
||||
template <typename T>
|
||||
static inline void write(Writer<T> &WR,const std::string &s,
|
||||
const Serializable &obj)
|
||||
{}
|
||||
|
||||
template <typename T>
|
||||
static inline void read(Reader<T> &RD,const std::string &s,
|
||||
Serializable &obj)
|
||||
{}
|
||||
|
||||
friend inline std::ostream & operator<<(std::ostream &os,
|
||||
const Serializable &obj)
|
||||
{
|
||||
return os;
|
||||
}
|
||||
};
|
||||
|
||||
// Generic writer interface
|
||||
template <typename T>
|
||||
inline void push(Writer<T> &w, const std::string &s)
|
||||
|
@ -200,7 +200,7 @@ void Environment::createModule(const std::string name, const std::string type,
|
||||
}
|
||||
}
|
||||
|
||||
Module * Environment::getModule(const unsigned int address) const
|
||||
ModuleBase * Environment::getModule(const unsigned int address) const
|
||||
{
|
||||
if (hasModule(address))
|
||||
{
|
||||
@ -212,7 +212,7 @@ Module * Environment::getModule(const unsigned int address) const
|
||||
}
|
||||
}
|
||||
|
||||
Module * Environment::getModule(const std::string name) const
|
||||
ModuleBase * Environment::getModule(const std::string name) const
|
||||
{
|
||||
return getModule(getModuleAddress(name));
|
||||
}
|
||||
|
@ -37,13 +37,13 @@ BEGIN_HADRONS_NAMESPACE
|
||||
* Global environment *
|
||||
******************************************************************************/
|
||||
// forward declaration of Module
|
||||
class Module;
|
||||
class ModuleBase;
|
||||
|
||||
class Environment
|
||||
{
|
||||
SINGLETON(Environment);
|
||||
public:
|
||||
typedef std::unique_ptr<Module> ModPt;
|
||||
typedef std::unique_ptr<ModuleBase> ModPt;
|
||||
typedef std::unique_ptr<GridCartesian> GridPt;
|
||||
typedef std::unique_ptr<GridRedBlackCartesian> GridRbPt;
|
||||
typedef FermionOperator<WilsonImplR> FMat;
|
||||
@ -76,8 +76,8 @@ public:
|
||||
void createModule(const std::string name,
|
||||
const std::string type,
|
||||
XmlReader &reader);
|
||||
Module * getModule(const unsigned int address) const;
|
||||
Module * getModule(const std::string name) const;
|
||||
ModuleBase * getModule(const unsigned int address) const;
|
||||
ModuleBase * getModule(const std::string name) const;
|
||||
unsigned int getModuleAddress(const std::string name) const;
|
||||
std::string getModuleName(const unsigned int address) const;
|
||||
std::string getModuleType(const unsigned int address) const;
|
||||
|
@ -35,24 +35,24 @@ using namespace Hadrons;
|
||||
* Module implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
Module::Module(const std::string name)
|
||||
ModuleBase::ModuleBase(const std::string name)
|
||||
: name_(name)
|
||||
, env_(Environment::getInstance())
|
||||
{}
|
||||
|
||||
// access //////////////////////////////////////////////////////////////////////
|
||||
std::string Module::getName(void) const
|
||||
std::string ModuleBase::getName(void) const
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
||||
Environment & Module::env(void) const
|
||||
Environment & ModuleBase::env(void) const
|
||||
{
|
||||
return env_;
|
||||
}
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
void Module::operator()(void)
|
||||
void ModuleBase::operator()(void)
|
||||
{
|
||||
setup();
|
||||
if (!env().isDryRun())
|
||||
|
@ -52,21 +52,21 @@ static mod##ModuleRegistrar mod##ModuleRegistrarInstance;
|
||||
/******************************************************************************
|
||||
* Module *
|
||||
******************************************************************************/
|
||||
class Module
|
||||
class ModuleBase
|
||||
{
|
||||
public:
|
||||
// constructor
|
||||
Module(const std::string name);
|
||||
ModuleBase(const std::string name);
|
||||
// destructor
|
||||
virtual ~Module(void) = default;
|
||||
virtual ~ModuleBase(void) = default;
|
||||
// access
|
||||
std::string getName(void) const;
|
||||
Environment &env(void) const;
|
||||
// parse parameters
|
||||
virtual void parseParameters(XmlReader &reader, const std::string name) {};
|
||||
// dependencies/products
|
||||
virtual std::vector<std::string> getInput(void) = 0;
|
||||
virtual std::vector<std::string> getOutput(void) = 0;
|
||||
// parse parameters
|
||||
virtual void parseParameters(XmlReader &reader, const std::string name) = 0;
|
||||
// setup
|
||||
virtual void setup(void) {};
|
||||
// execution
|
||||
@ -77,6 +77,50 @@ private:
|
||||
Environment &env_;
|
||||
};
|
||||
|
||||
typedef Serializable NoPar;
|
||||
|
||||
template <typename P>
|
||||
class Module: public ModuleBase
|
||||
{
|
||||
public:
|
||||
typedef P Par;
|
||||
public:
|
||||
// constructor
|
||||
Module(const std::string name);
|
||||
// destructor
|
||||
virtual ~Module(void) = default;
|
||||
// parse parameters
|
||||
virtual void parseParameters(XmlReader &reader, const std::string name);
|
||||
// parameter access
|
||||
const P & par(void) const;
|
||||
void setPar(const P &par);
|
||||
private:
|
||||
P par_;
|
||||
};
|
||||
|
||||
template <typename P>
|
||||
Module<P>::Module(const std::string name)
|
||||
: ModuleBase(name)
|
||||
{}
|
||||
|
||||
template <typename P>
|
||||
void Module<P>::parseParameters(XmlReader &reader, const std::string name)
|
||||
{
|
||||
read(reader, name, par_);read(reader, name, par_);
|
||||
}
|
||||
|
||||
template <typename P>
|
||||
const P & Module<P>::par(void) const
|
||||
{
|
||||
return par_;
|
||||
}
|
||||
|
||||
template <typename P>
|
||||
void Module<P>::setPar(const P &par)
|
||||
{
|
||||
par_ = par;
|
||||
}
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_Module_hpp_
|
||||
|
@ -37,7 +37,7 @@ BEGIN_HADRONS_NAMESPACE
|
||||
/******************************************************************************
|
||||
* ModuleFactory *
|
||||
******************************************************************************/
|
||||
class ModuleFactory: public Factory<Module>
|
||||
class ModuleFactory: public Factory<ModuleBase>
|
||||
{
|
||||
SINGLETON_DEFCTOR(ModuleFactory)
|
||||
};
|
||||
|
@ -35,19 +35,13 @@ using namespace Hadrons;
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
AWilson::AWilson(const std::string name)
|
||||
: Module(name)
|
||||
: Module<AWilsonPar>(name)
|
||||
{}
|
||||
|
||||
// parse parameters ////////////////////////////////////////////////////////////
|
||||
void AWilson::parseParameters(XmlReader &reader, const std::string name)
|
||||
{
|
||||
read(reader, name, par_);
|
||||
}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
std::vector<std::string> AWilson::getInput(void)
|
||||
{
|
||||
std::vector<std::string> in = {par_.gauge};
|
||||
std::vector<std::string> in = {par().gauge};
|
||||
|
||||
return in;
|
||||
}
|
||||
@ -71,13 +65,13 @@ void AWilson::setup(void)
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
void AWilson::execute()
|
||||
{
|
||||
auto &U = *env().get<LatticeGaugeField>(par_.gauge);
|
||||
auto &U = *env().get<LatticeGaugeField>(par().gauge);
|
||||
auto &grid = *env().getGrid();
|
||||
auto &gridRb = *env().getRbGrid();
|
||||
auto fMatPt = new WilsonFermionR(U, grid, gridRb, par_.mass);
|
||||
auto fMatPt = new WilsonFermionR(U, grid, gridRb, par().mass);
|
||||
unsigned int size;
|
||||
|
||||
LOG(Message) << "Setting up Wilson fermion matrix with m= " << par_.mass
|
||||
<< " using gauge field '" << par_.gauge << "'" << std::endl;
|
||||
LOG(Message) << "Setting up Wilson fermion matrix with m= " << par().mass
|
||||
<< " using gauge field '" << par().gauge << "'" << std::endl;
|
||||
env().addFermionMatrix(getName(), fMatPt);
|
||||
}
|
||||
|
@ -37,22 +37,21 @@ BEGIN_HADRONS_NAMESPACE
|
||||
/******************************************************************************
|
||||
* Wilson quark action *
|
||||
******************************************************************************/
|
||||
class AWilson: public Module
|
||||
class AWilsonPar: Serializable
|
||||
{
|
||||
public:
|
||||
class Par: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(Par, std::string, gauge,
|
||||
double , mass);
|
||||
};
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(AWilsonPar,
|
||||
std::string, gauge,
|
||||
double , mass);
|
||||
};
|
||||
|
||||
class AWilson: public Module<AWilsonPar>
|
||||
{
|
||||
public:
|
||||
// constructor
|
||||
AWilson(const std::string name);
|
||||
// destructor
|
||||
virtual ~AWilson(void) = default;
|
||||
// parse parameters
|
||||
virtual void parseParameters(XmlReader &reader, const std::string name);
|
||||
// dependencies/products
|
||||
virtual std::vector<std::string> getInput(void);
|
||||
virtual std::vector<std::string> getOutput(void);
|
||||
@ -60,8 +59,6 @@ public:
|
||||
virtual void setup(void);
|
||||
// execution
|
||||
virtual void execute(void);
|
||||
private:
|
||||
Par par_;
|
||||
};
|
||||
|
||||
MODULE_REGISTER(AWilson);
|
||||
|
@ -36,19 +36,13 @@ using namespace Hadrons;
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
CMeson::CMeson(const std::string name)
|
||||
: Module(name)
|
||||
: Module<CMesonPar>(name)
|
||||
{}
|
||||
|
||||
// parse parameters ////////////////////////////////////////////////////////////
|
||||
void CMeson::parseParameters(XmlReader &reader, const std::string name)
|
||||
{
|
||||
read(reader, name, par_);
|
||||
}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
std::vector<std::string> CMeson::getInput(void)
|
||||
{
|
||||
std::vector<std::string> input = {par_.q1, par_.q2};
|
||||
std::vector<std::string> input = {par().q1, par().q2};
|
||||
|
||||
return input;
|
||||
}
|
||||
@ -64,12 +58,12 @@ std::vector<std::string> CMeson::getOutput(void)
|
||||
void CMeson::execute(void)
|
||||
{
|
||||
LOG(Message) << "Computing meson contraction '" << getName() << "' using"
|
||||
<< " quarks '" << par_.q1 << "' and '" << par_.q2 << "'"
|
||||
<< " quarks '" << par().q1 << "' and '" << par().q2 << "'"
|
||||
<< std::endl;
|
||||
|
||||
XmlWriter writer(par_.output);
|
||||
LatticePropagator &q1 = *env().get<LatticePropagator>(par_.q1);
|
||||
LatticePropagator &q2 = *env().get<LatticePropagator>(par_.q2);
|
||||
XmlWriter writer(par().output);
|
||||
LatticePropagator &q1 = *env().get<LatticePropagator>(par().q1);
|
||||
LatticePropagator &q2 = *env().get<LatticePropagator>(par().q2);
|
||||
LatticeComplex c(env().getGrid());
|
||||
SpinMatrix g[Ns*Ns], g5;
|
||||
std::vector<TComplex> buf;
|
||||
|
@ -37,17 +37,18 @@ BEGIN_HADRONS_NAMESPACE
|
||||
/******************************************************************************
|
||||
* CMeson *
|
||||
******************************************************************************/
|
||||
class CMeson: public Module
|
||||
class CMesonPar: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(CMesonPar,
|
||||
std::string, q1,
|
||||
std::string, q2,
|
||||
std::string, output);
|
||||
};
|
||||
|
||||
class CMeson: public Module<CMesonPar>
|
||||
{
|
||||
public:
|
||||
class Par: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(Par,
|
||||
std::string, q1,
|
||||
std::string, q2,
|
||||
std::string, output);
|
||||
};
|
||||
class Result: Serializable
|
||||
{
|
||||
public:
|
||||
@ -59,15 +60,11 @@ public:
|
||||
CMeson(const std::string name);
|
||||
// destructor
|
||||
virtual ~CMeson(void) = default;
|
||||
// parse parameters
|
||||
virtual void parseParameters(XmlReader &reader, const std::string name);
|
||||
// dependencies/products
|
||||
virtual std::vector<std::string> getInput(void);
|
||||
virtual std::vector<std::string> getOutput(void);
|
||||
// execution
|
||||
virtual void execute(void);
|
||||
private:
|
||||
Par par_;
|
||||
};
|
||||
|
||||
MODULE_REGISTER(CMeson);
|
||||
|
@ -35,15 +35,9 @@ using namespace Hadrons;
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
GLoad::GLoad(const std::string name)
|
||||
: Module(name)
|
||||
: Module<GLoadPar>(name)
|
||||
{}
|
||||
|
||||
// parse parameters ////////////////////////////////////////////////////////////
|
||||
void GLoad::parseParameters(XmlReader &reader, const std::string name)
|
||||
{
|
||||
read(reader, name, par_);
|
||||
}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
std::vector<std::string> GLoad::getInput(void)
|
||||
{
|
||||
@ -69,7 +63,7 @@ void GLoad::setup(void)
|
||||
void GLoad::execute(void)
|
||||
{
|
||||
NerscField header;
|
||||
std::string fileName = par_.file + "."
|
||||
std::string fileName = par().file + "."
|
||||
+ std::to_string(env().getTrajectory());
|
||||
|
||||
LOG(Message) << "Loading NERSC configuration from file '" << fileName
|
||||
|
@ -37,21 +37,20 @@ BEGIN_HADRONS_NAMESPACE
|
||||
/******************************************************************************
|
||||
* Load a NERSC configuration *
|
||||
******************************************************************************/
|
||||
class GLoad: public Module
|
||||
class GLoadPar: Serializable
|
||||
{
|
||||
public:
|
||||
class Par: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(Par, std::string, file);
|
||||
};
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(GLoadPar,
|
||||
std::string, file);
|
||||
};
|
||||
|
||||
class GLoad: public Module<GLoadPar>
|
||||
{
|
||||
public:
|
||||
// constructor
|
||||
GLoad(const std::string name);
|
||||
// destructor
|
||||
virtual ~GLoad(void) = default;
|
||||
// parse parameters
|
||||
virtual void parseParameters(XmlReader &reader, const std::string name);
|
||||
// dependency relation
|
||||
virtual std::vector<std::string> getInput(void);
|
||||
virtual std::vector<std::string> getOutput(void);
|
||||
@ -59,8 +58,6 @@ public:
|
||||
virtual void setup(void);
|
||||
// execution
|
||||
virtual void execute(void);
|
||||
private:
|
||||
Par par_;
|
||||
};
|
||||
|
||||
MODULE_REGISTER(GLoad);
|
||||
|
@ -35,7 +35,7 @@ using namespace Hadrons;
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
GRandom::GRandom(const std::string name)
|
||||
: Module(name)
|
||||
: Module<NoPar>(name)
|
||||
{}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
|
@ -37,7 +37,7 @@ BEGIN_HADRONS_NAMESPACE
|
||||
/******************************************************************************
|
||||
* Random gauge *
|
||||
******************************************************************************/
|
||||
class GRandom: public Module
|
||||
class GRandom: public Module<NoPar>
|
||||
{
|
||||
public:
|
||||
// constructor
|
||||
|
@ -35,7 +35,7 @@ using namespace Hadrons;
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
GUnit::GUnit(const std::string name)
|
||||
: Module(name)
|
||||
: Module<NoPar>(name)
|
||||
{}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
|
@ -37,7 +37,7 @@ BEGIN_HADRONS_NAMESPACE
|
||||
/******************************************************************************
|
||||
* Unit gauge *
|
||||
******************************************************************************/
|
||||
class GUnit: public Module
|
||||
class GUnit: public Module<NoPar>
|
||||
{
|
||||
public:
|
||||
// constructor
|
||||
|
@ -39,16 +39,10 @@ MQuark::MQuark(const std::string name)
|
||||
: Module(name)
|
||||
{}
|
||||
|
||||
// parse parameters ////////////////////////////////////////////////////////////
|
||||
void MQuark::parseParameters(XmlReader &reader, const std::string name)
|
||||
{
|
||||
read(reader, name, par_);
|
||||
}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
std::vector<std::string> MQuark::getInput(void)
|
||||
{
|
||||
std::vector<std::string> in = {par_.source, par_.solver};
|
||||
std::vector<std::string> in = {par().source, par().solver};
|
||||
|
||||
return in;
|
||||
}
|
||||
@ -63,7 +57,7 @@ std::vector<std::string> MQuark::getOutput(void)
|
||||
// setup ///////////////////////////////////////////////////////////////////////
|
||||
void MQuark::setup(void)
|
||||
{
|
||||
Ls_ = env().getObjectLs(env().getSolverAction(par_.solver));
|
||||
Ls_ = env().getObjectLs(env().getSolverAction(par().solver));
|
||||
env().registerLattice<LatticePropagator>(getName());
|
||||
if (Ls_ > 1)
|
||||
{
|
||||
@ -74,54 +68,59 @@ void MQuark::setup(void)
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
void MQuark::execute(void)
|
||||
{
|
||||
LatticePropagator *fullSource;
|
||||
LatticeFermion source(env().getGrid(Ls_)), sol(env().getGrid(Ls_));
|
||||
std::string propName = (Ls_ == 1) ? getName() : (getName() + "_5d");
|
||||
LatticeFermion source(env().getGrid(Ls_)), sol(env().getGrid(Ls_)),
|
||||
tmp(env().getGrid());
|
||||
std::string propName = (Ls_ == 1) ? getName() : (getName() + "_5d");
|
||||
|
||||
LOG(Message) << "Computing quark propagator '" << getName() << "'"
|
||||
<< std::endl;
|
||||
LatticePropagator &prop = *env().create<LatticePropagator>(propName);
|
||||
// source conversion for 4D sources
|
||||
if (!env().isObject5d(par_.source))
|
||||
{
|
||||
if (Ls_ == 1)
|
||||
{
|
||||
fullSource = env().get<LatticePropagator>(par_.source);
|
||||
}
|
||||
else
|
||||
{
|
||||
HADRON_ERROR("MQuark not implemented with 5D actions");
|
||||
}
|
||||
}
|
||||
// source conversion for 5D sources
|
||||
else
|
||||
{
|
||||
if (Ls_ == 1)
|
||||
{
|
||||
HADRON_ERROR("MQuark not implemented with 5D actions");
|
||||
}
|
||||
else if (Ls_ != env().getObjectLs(par_.source))
|
||||
{
|
||||
HADRON_ERROR("Ls mismatch between quark action and source");
|
||||
}
|
||||
else
|
||||
{
|
||||
fullSource = env().get<LatticePropagator>(par_.source);
|
||||
}
|
||||
}
|
||||
LOG(Message) << "Inverting using solver '" << par_.solver
|
||||
<< "' on source '" << par_.source << "'" << std::endl;
|
||||
LatticePropagator &prop = *env().create<LatticePropagator>(propName);
|
||||
LatticePropagator &fullSrc = *env().create<LatticePropagator>(par().source);
|
||||
|
||||
LOG(Message) << "Inverting using solver '" << par().solver
|
||||
<< "' on source '" << par().source << "'" << std::endl;
|
||||
for (unsigned int s = 0; s < Ns; ++s)
|
||||
for (unsigned int c = 0; c < Nc; ++c)
|
||||
{
|
||||
PropToFerm(source, *fullSource, s, c);
|
||||
// source conversion for 4D sources
|
||||
if (!env().isObject5d(par().source))
|
||||
{
|
||||
if (Ls_ == 1)
|
||||
{
|
||||
PropToFerm(source, fullSrc, s, c);
|
||||
}
|
||||
else
|
||||
{
|
||||
PropToFerm(tmp, fullSrc, s, c);
|
||||
InsertSlice(source, tmp, 0, 0);
|
||||
InsertSlice(source, tmp, Ls_ - 1, 0);
|
||||
axpby_ssp_pplus(source, 0., source, 1., source,
|
||||
0, 0);
|
||||
axpby_ssp_pminus(source, 0., source, 1., source,
|
||||
Ls_ - 1, Ls_ - 1);
|
||||
}
|
||||
}
|
||||
// source conversion for 5D sources
|
||||
else
|
||||
{
|
||||
if (Ls_ != env().getObjectLs(par().source))
|
||||
{
|
||||
HADRON_ERROR("Ls mismatch between quark action and source");
|
||||
}
|
||||
else
|
||||
{
|
||||
PropToFerm(source, fullSrc, s, c);
|
||||
}
|
||||
}
|
||||
sol = zero;
|
||||
env().callSolver(par_.solver, sol, source);
|
||||
env().callSolver(par().solver, sol, source);
|
||||
FermToProp(prop, sol, s, c);
|
||||
}
|
||||
// create 4D propagators from 5D one if necessary
|
||||
if (Ls_ > 1)
|
||||
{
|
||||
HADRON_ERROR("MQuark not implemented with 5D actions");
|
||||
LatticePropagator &prop4d = *env().create<LatticePropagator>(getName());
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -37,22 +37,21 @@ BEGIN_HADRONS_NAMESPACE
|
||||
/******************************************************************************
|
||||
* MQuark *
|
||||
******************************************************************************/
|
||||
class MQuark: public Module
|
||||
class MQuarkPar: Serializable
|
||||
{
|
||||
public:
|
||||
class Par: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(Par, std::string, source,
|
||||
std::string, solver);
|
||||
};
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(MQuarkPar,
|
||||
std::string, source,
|
||||
std::string, solver);
|
||||
};
|
||||
|
||||
class MQuark: public Module<MQuarkPar>
|
||||
{
|
||||
public:
|
||||
// constructor
|
||||
MQuark(const std::string name);
|
||||
// destructor
|
||||
virtual ~MQuark(void) = default;
|
||||
// parse parameters
|
||||
virtual void parseParameters(XmlReader &reader, const std::string name);
|
||||
// dependencies/products
|
||||
virtual std::vector<std::string> getInput(void);
|
||||
virtual std::vector<std::string> getOutput(void);
|
||||
@ -61,7 +60,6 @@ public:
|
||||
// execution
|
||||
virtual void execute(void);
|
||||
private:
|
||||
Par par_;
|
||||
unsigned int Ls_;
|
||||
Environment::Solver *solver_{nullptr};
|
||||
};
|
||||
|
@ -39,16 +39,10 @@ SolRBPrecCG::SolRBPrecCG(const std::string name)
|
||||
: Module(name)
|
||||
{}
|
||||
|
||||
// parse parameters ////////////////////////////////////////////////////////////
|
||||
void SolRBPrecCG::parseParameters(XmlReader &reader, const std::string name)
|
||||
{
|
||||
read(reader, name, par_);
|
||||
}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
std::vector<std::string> SolRBPrecCG::getInput(void)
|
||||
{
|
||||
std::vector<std::string> in = {par_.action};
|
||||
std::vector<std::string> in = {par().action};
|
||||
|
||||
return in;
|
||||
}
|
||||
@ -64,25 +58,25 @@ std::vector<std::string> SolRBPrecCG::getOutput(void)
|
||||
void SolRBPrecCG::setup(void)
|
||||
{
|
||||
env().registerObject(getName(), 0);
|
||||
env().addOwnership(getName(), par_.action);
|
||||
env().setSolverAction(getName(), par_.action);
|
||||
env().addOwnership(getName(), par().action);
|
||||
env().setSolverAction(getName(), par().action);
|
||||
}
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
void SolRBPrecCG::execute(void)
|
||||
{
|
||||
auto &mat = *(env().getFermionMatrix(par_.action));
|
||||
auto &mat = *(env().getFermionMatrix(par().action));
|
||||
auto solver = [&mat, this](LatticeFermion &sol,
|
||||
const LatticeFermion &source)
|
||||
{
|
||||
ConjugateGradient<LatticeFermion> cg(par_.residual, 10000);
|
||||
ConjugateGradient<LatticeFermion> cg(par().residual, 10000);
|
||||
SchurRedBlackDiagMooeeSolve<LatticeFermion> schurSolver(cg);
|
||||
|
||||
schurSolver(mat, source, sol);
|
||||
};
|
||||
|
||||
LOG(Message) << "setting up Schur red-black preconditioned CG for"
|
||||
<< " action '" << par_.action << "' with residual "
|
||||
<< par_.residual << std::endl;
|
||||
<< " action '" << par().action << "' with residual "
|
||||
<< par().residual << std::endl;
|
||||
env().addSolver(getName(), solver);
|
||||
}
|
||||
|
@ -37,22 +37,21 @@ BEGIN_HADRONS_NAMESPACE
|
||||
/******************************************************************************
|
||||
* Schur red-black preconditioned CG *
|
||||
******************************************************************************/
|
||||
class SolRBPrecCG: public Module
|
||||
class SolRBPrecCGPar: Serializable
|
||||
{
|
||||
public:
|
||||
class Par: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(Par, std::string, action,
|
||||
double , residual);
|
||||
};
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(SolRBPrecCGPar,
|
||||
std::string, action,
|
||||
double , residual);
|
||||
};
|
||||
|
||||
class SolRBPrecCG: public Module<SolRBPrecCGPar>
|
||||
{
|
||||
public:
|
||||
// constructor
|
||||
SolRBPrecCG(const std::string name);
|
||||
// destructor
|
||||
virtual ~SolRBPrecCG(void) = default;
|
||||
// parse parameters
|
||||
virtual void parseParameters(XmlReader &reader, const std::string name);
|
||||
// dependencies/products
|
||||
virtual std::vector<std::string> getInput(void);
|
||||
virtual std::vector<std::string> getOutput(void);
|
||||
@ -60,8 +59,6 @@ public:
|
||||
virtual void setup(void);
|
||||
// execution
|
||||
virtual void execute(void);
|
||||
private:
|
||||
Par par_;
|
||||
};
|
||||
|
||||
MODULE_REGISTER(SolRBPrecCG);
|
||||
|
@ -35,15 +35,9 @@ using namespace Hadrons;
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
SrcPoint::SrcPoint(const std::string name)
|
||||
: Module(name)
|
||||
: Module<SrcPointPar>(name)
|
||||
{}
|
||||
|
||||
// parse parameters ////////////////////////////////////////////////////////////
|
||||
void SrcPoint::parseParameters(XmlReader &reader, const std::string name)
|
||||
{
|
||||
read(reader, name, par_);
|
||||
}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
std::vector<std::string> SrcPoint::getInput(void)
|
||||
{
|
||||
@ -68,10 +62,10 @@ void SrcPoint::setup(void)
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
void SrcPoint::execute(void)
|
||||
{
|
||||
std::vector<int> position = strToVec<int>(par_.position);
|
||||
std::vector<int> position = strToVec<int>(par().position);
|
||||
SpinColourMatrix id;
|
||||
|
||||
LOG(Message) << "Creating point source at position [" << par_.position
|
||||
LOG(Message) << "Creating point source at position [" << par().position
|
||||
<< "]" << std::endl;
|
||||
LatticePropagator &src = *env().create<LatticePropagator>(getName());
|
||||
id = 1.;
|
||||
|
@ -48,21 +48,20 @@ BEGIN_HADRONS_NAMESPACE
|
||||
/******************************************************************************
|
||||
* SrcPoint *
|
||||
******************************************************************************/
|
||||
class SrcPoint: public Module
|
||||
class SrcPointPar: Serializable
|
||||
{
|
||||
public:
|
||||
class Par: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(Par, std::string, position);
|
||||
};
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(SrcPointPar,
|
||||
std::string, position);
|
||||
};
|
||||
|
||||
class SrcPoint: public Module<SrcPointPar>
|
||||
{
|
||||
public:
|
||||
// constructor
|
||||
SrcPoint(const std::string name);
|
||||
// destructor
|
||||
virtual ~SrcPoint(void) = default;
|
||||
// parse parameters
|
||||
virtual void parseParameters(XmlReader &reader, const std::string name);
|
||||
// dependency relation
|
||||
virtual std::vector<std::string> getInput(void);
|
||||
virtual std::vector<std::string> getOutput(void);
|
||||
@ -70,8 +69,6 @@ public:
|
||||
virtual void setup(void);
|
||||
// execution
|
||||
virtual void execute(void);
|
||||
private:
|
||||
Par par_;
|
||||
};
|
||||
|
||||
MODULE_REGISTER(SrcPoint);
|
||||
|
@ -35,15 +35,9 @@ using namespace Hadrons;
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
SrcZ2::SrcZ2(const std::string name)
|
||||
: Module(name)
|
||||
: Module<SrcZ2Par>(name)
|
||||
{}
|
||||
|
||||
// parse parameters ////////////////////////////////////////////////////////////
|
||||
void SrcZ2::parseParameters(XmlReader &reader, const std::string name)
|
||||
{
|
||||
read(reader, name, par_);
|
||||
}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
std::vector<std::string> SrcZ2::getInput(void)
|
||||
{
|
||||
@ -73,21 +67,21 @@ void SrcZ2::execute(void)
|
||||
LatticeFermion phi(env().getGrid());
|
||||
Complex shift(1., 1.);
|
||||
|
||||
if (par_.tA == par_.tB)
|
||||
if (par().tA == par().tB)
|
||||
{
|
||||
LOG(Message) << "Generating Z_2 wall source at t= " << par_.tA
|
||||
LOG(Message) << "Generating Z_2 wall source at t= " << par().tA
|
||||
<< std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG(Message) << "Generating Z_2 band for " << par_.tA << " <= t <= "
|
||||
<< par_.tB << std::endl;
|
||||
LOG(Message) << "Generating Z_2 band for " << par().tA << " <= t <= "
|
||||
<< par().tB << std::endl;
|
||||
}
|
||||
LatticePropagator &src = *env().create<LatticePropagator>(getName());
|
||||
LatticeCoordinate(t, Tp);
|
||||
bernoulli(*env().get4dRng(), eta);
|
||||
eta = (2.*eta - shift)*(1./::sqrt(2.));
|
||||
eta = where((t >= par_.tA) and (t <= par_.tB), eta, 0.*eta);
|
||||
eta = where((t >= par().tA) and (t <= par().tB), eta, 0.*eta);
|
||||
src = 1.;
|
||||
src = src*eta;
|
||||
}
|
||||
|
@ -49,22 +49,21 @@ BEGIN_HADRONS_NAMESPACE
|
||||
/******************************************************************************
|
||||
* SrcZ2 *
|
||||
******************************************************************************/
|
||||
class SrcZ2: public Module
|
||||
class SrcZ2Par: Serializable
|
||||
{
|
||||
public:
|
||||
class Par: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(Par, unsigned int, tA,
|
||||
unsigned int, tB);
|
||||
};
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(SrcZ2Par,
|
||||
unsigned int, tA,
|
||||
unsigned int, tB);
|
||||
};
|
||||
|
||||
class SrcZ2: public Module<SrcZ2Par>
|
||||
{
|
||||
public:
|
||||
// constructor
|
||||
SrcZ2(const std::string name);
|
||||
// destructor
|
||||
virtual ~SrcZ2(void) = default;
|
||||
// parse parameters
|
||||
virtual void parseParameters(XmlReader &reader, const std::string name);
|
||||
// dependency relation
|
||||
virtual std::vector<std::string> getInput(void);
|
||||
virtual std::vector<std::string> getOutput(void);
|
||||
@ -72,8 +71,6 @@ public:
|
||||
virtual void setup(void);
|
||||
// execution
|
||||
virtual void execute(void);
|
||||
private:
|
||||
Par par_;
|
||||
};
|
||||
|
||||
MODULE_REGISTER(SrcZ2);
|
||||
|
Loading…
x
Reference in New Issue
Block a user