1
0
mirror of https://github.com/paboyle/Grid.git synced 2024-09-20 09:15:38 +01:00

Hadrons: module parameters can now be accessed from outside

This commit is contained in:
Antonin Portelli 2016-05-12 11:59:28 +01:00
parent 3d78ed03ef
commit 362f255100
24 changed files with 216 additions and 209 deletions

View File

@ -67,9 +67,8 @@ namespace Grid {
return os; return os;
} }
class Serializable {};
// static polymorphism implemented using CRTP idiom // static polymorphism implemented using CRTP idiom
class Serializable;
// Static abstract writer // Static abstract writer
template <typename T> template <typename T>
@ -122,6 +121,27 @@ namespace Grid {
T *upcast; 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 // Generic writer interface
template <typename T> template <typename T>
inline void push(Writer<T> &w, const std::string &s) inline void push(Writer<T> &w, const std::string &s)

View File

@ -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)) 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)); return getModule(getModuleAddress(name));
} }

View File

@ -37,13 +37,13 @@ BEGIN_HADRONS_NAMESPACE
* Global environment * * Global environment *
******************************************************************************/ ******************************************************************************/
// forward declaration of Module // forward declaration of Module
class Module; class ModuleBase;
class Environment class Environment
{ {
SINGLETON(Environment); SINGLETON(Environment);
public: public:
typedef std::unique_ptr<Module> ModPt; typedef std::unique_ptr<ModuleBase> ModPt;
typedef std::unique_ptr<GridCartesian> GridPt; typedef std::unique_ptr<GridCartesian> GridPt;
typedef std::unique_ptr<GridRedBlackCartesian> GridRbPt; typedef std::unique_ptr<GridRedBlackCartesian> GridRbPt;
typedef FermionOperator<WilsonImplR> FMat; typedef FermionOperator<WilsonImplR> FMat;
@ -76,8 +76,8 @@ public:
void createModule(const std::string name, void createModule(const std::string name,
const std::string type, const std::string type,
XmlReader &reader); XmlReader &reader);
Module * getModule(const unsigned int address) const; ModuleBase * getModule(const unsigned int address) const;
Module * getModule(const std::string name) const; ModuleBase * getModule(const std::string name) const;
unsigned int getModuleAddress(const std::string name) const; unsigned int getModuleAddress(const std::string name) const;
std::string getModuleName(const unsigned int address) const; std::string getModuleName(const unsigned int address) const;
std::string getModuleType(const unsigned int address) const; std::string getModuleType(const unsigned int address) const;

View File

@ -35,24 +35,24 @@ using namespace Hadrons;
* Module implementation * * Module implementation *
******************************************************************************/ ******************************************************************************/
// constructor ///////////////////////////////////////////////////////////////// // constructor /////////////////////////////////////////////////////////////////
Module::Module(const std::string name) ModuleBase::ModuleBase(const std::string name)
: name_(name) : name_(name)
, env_(Environment::getInstance()) , env_(Environment::getInstance())
{} {}
// access ////////////////////////////////////////////////////////////////////// // access //////////////////////////////////////////////////////////////////////
std::string Module::getName(void) const std::string ModuleBase::getName(void) const
{ {
return name_; return name_;
} }
Environment & Module::env(void) const Environment & ModuleBase::env(void) const
{ {
return env_; return env_;
} }
// execution /////////////////////////////////////////////////////////////////// // execution ///////////////////////////////////////////////////////////////////
void Module::operator()(void) void ModuleBase::operator()(void)
{ {
setup(); setup();
if (!env().isDryRun()) if (!env().isDryRun())

View File

@ -52,21 +52,21 @@ static mod##ModuleRegistrar mod##ModuleRegistrarInstance;
/****************************************************************************** /******************************************************************************
* Module * * Module *
******************************************************************************/ ******************************************************************************/
class Module class ModuleBase
{ {
public: public:
// constructor // constructor
Module(const std::string name); ModuleBase(const std::string name);
// destructor // destructor
virtual ~Module(void) = default; virtual ~ModuleBase(void) = default;
// access // access
std::string getName(void) const; std::string getName(void) const;
Environment &env(void) const; Environment &env(void) const;
// parse parameters
virtual void parseParameters(XmlReader &reader, const std::string name) {};
// dependencies/products // dependencies/products
virtual std::vector<std::string> getInput(void) = 0; virtual std::vector<std::string> getInput(void) = 0;
virtual std::vector<std::string> getOutput(void) = 0; virtual std::vector<std::string> getOutput(void) = 0;
// parse parameters
virtual void parseParameters(XmlReader &reader, const std::string name) = 0;
// setup // setup
virtual void setup(void) {}; virtual void setup(void) {};
// execution // execution
@ -77,6 +77,50 @@ private:
Environment &env_; 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 END_HADRONS_NAMESPACE
#endif // Hadrons_Module_hpp_ #endif // Hadrons_Module_hpp_

View File

@ -37,7 +37,7 @@ BEGIN_HADRONS_NAMESPACE
/****************************************************************************** /******************************************************************************
* ModuleFactory * * ModuleFactory *
******************************************************************************/ ******************************************************************************/
class ModuleFactory: public Factory<Module> class ModuleFactory: public Factory<ModuleBase>
{ {
SINGLETON_DEFCTOR(ModuleFactory) SINGLETON_DEFCTOR(ModuleFactory)
}; };

View File

@ -35,19 +35,13 @@ using namespace Hadrons;
******************************************************************************/ ******************************************************************************/
// constructor ///////////////////////////////////////////////////////////////// // constructor /////////////////////////////////////////////////////////////////
AWilson::AWilson(const std::string name) 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 /////////////////////////////////////////////////////// // dependencies/products ///////////////////////////////////////////////////////
std::vector<std::string> AWilson::getInput(void) std::vector<std::string> AWilson::getInput(void)
{ {
std::vector<std::string> in = {par_.gauge}; std::vector<std::string> in = {par().gauge};
return in; return in;
} }
@ -71,13 +65,13 @@ void AWilson::setup(void)
// execution /////////////////////////////////////////////////////////////////// // execution ///////////////////////////////////////////////////////////////////
void AWilson::execute() void AWilson::execute()
{ {
auto &U = *env().get<LatticeGaugeField>(par_.gauge); auto &U = *env().get<LatticeGaugeField>(par().gauge);
auto &grid = *env().getGrid(); auto &grid = *env().getGrid();
auto &gridRb = *env().getRbGrid(); 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; unsigned int size;
LOG(Message) << "Setting up Wilson fermion matrix with m= " << par_.mass LOG(Message) << "Setting up Wilson fermion matrix with m= " << par().mass
<< " using gauge field '" << par_.gauge << "'" << std::endl; << " using gauge field '" << par().gauge << "'" << std::endl;
env().addFermionMatrix(getName(), fMatPt); env().addFermionMatrix(getName(), fMatPt);
} }

View File

@ -37,22 +37,21 @@ BEGIN_HADRONS_NAMESPACE
/****************************************************************************** /******************************************************************************
* Wilson quark action * * Wilson quark action *
******************************************************************************/ ******************************************************************************/
class AWilson: public Module class AWilsonPar: Serializable
{ {
public: public:
class Par: Serializable GRID_SERIALIZABLE_CLASS_MEMBERS(AWilsonPar,
{ std::string, gauge,
public:
GRID_SERIALIZABLE_CLASS_MEMBERS(Par, std::string, gauge,
double , mass); double , mass);
}; };
class AWilson: public Module<AWilsonPar>
{
public: public:
// constructor // constructor
AWilson(const std::string name); AWilson(const std::string name);
// destructor // destructor
virtual ~AWilson(void) = default; virtual ~AWilson(void) = default;
// parse parameters
virtual void parseParameters(XmlReader &reader, const std::string name);
// dependencies/products // dependencies/products
virtual std::vector<std::string> getInput(void); virtual std::vector<std::string> getInput(void);
virtual std::vector<std::string> getOutput(void); virtual std::vector<std::string> getOutput(void);
@ -60,8 +59,6 @@ public:
virtual void setup(void); virtual void setup(void);
// execution // execution
virtual void execute(void); virtual void execute(void);
private:
Par par_;
}; };
MODULE_REGISTER(AWilson); MODULE_REGISTER(AWilson);

View File

@ -36,19 +36,13 @@ using namespace Hadrons;
******************************************************************************/ ******************************************************************************/
// constructor ///////////////////////////////////////////////////////////////// // constructor /////////////////////////////////////////////////////////////////
CMeson::CMeson(const std::string name) 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 /////////////////////////////////////////////////////// // dependencies/products ///////////////////////////////////////////////////////
std::vector<std::string> CMeson::getInput(void) 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; return input;
} }
@ -64,12 +58,12 @@ std::vector<std::string> CMeson::getOutput(void)
void CMeson::execute(void) void CMeson::execute(void)
{ {
LOG(Message) << "Computing meson contraction '" << getName() << "' using" LOG(Message) << "Computing meson contraction '" << getName() << "' using"
<< " quarks '" << par_.q1 << "' and '" << par_.q2 << "'" << " quarks '" << par().q1 << "' and '" << par().q2 << "'"
<< std::endl; << std::endl;
XmlWriter writer(par_.output); XmlWriter writer(par().output);
LatticePropagator &q1 = *env().get<LatticePropagator>(par_.q1); LatticePropagator &q1 = *env().get<LatticePropagator>(par().q1);
LatticePropagator &q2 = *env().get<LatticePropagator>(par_.q2); LatticePropagator &q2 = *env().get<LatticePropagator>(par().q2);
LatticeComplex c(env().getGrid()); LatticeComplex c(env().getGrid());
SpinMatrix g[Ns*Ns], g5; SpinMatrix g[Ns*Ns], g5;
std::vector<TComplex> buf; std::vector<TComplex> buf;

View File

@ -37,17 +37,18 @@ BEGIN_HADRONS_NAMESPACE
/****************************************************************************** /******************************************************************************
* CMeson * * CMeson *
******************************************************************************/ ******************************************************************************/
class CMeson: public Module class CMesonPar: Serializable
{ {
public: public:
class Par: Serializable GRID_SERIALIZABLE_CLASS_MEMBERS(CMesonPar,
{
public:
GRID_SERIALIZABLE_CLASS_MEMBERS(Par,
std::string, q1, std::string, q1,
std::string, q2, std::string, q2,
std::string, output); std::string, output);
}; };
class CMeson: public Module<CMesonPar>
{
public:
class Result: Serializable class Result: Serializable
{ {
public: public:
@ -59,15 +60,11 @@ public:
CMeson(const std::string name); CMeson(const std::string name);
// destructor // destructor
virtual ~CMeson(void) = default; virtual ~CMeson(void) = default;
// parse parameters
virtual void parseParameters(XmlReader &reader, const std::string name);
// dependencies/products // dependencies/products
virtual std::vector<std::string> getInput(void); virtual std::vector<std::string> getInput(void);
virtual std::vector<std::string> getOutput(void); virtual std::vector<std::string> getOutput(void);
// execution // execution
virtual void execute(void); virtual void execute(void);
private:
Par par_;
}; };
MODULE_REGISTER(CMeson); MODULE_REGISTER(CMeson);

View File

@ -35,15 +35,9 @@ using namespace Hadrons;
******************************************************************************/ ******************************************************************************/
// constructor ///////////////////////////////////////////////////////////////// // constructor /////////////////////////////////////////////////////////////////
GLoad::GLoad(const std::string name) 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 /////////////////////////////////////////////////////// // dependencies/products ///////////////////////////////////////////////////////
std::vector<std::string> GLoad::getInput(void) std::vector<std::string> GLoad::getInput(void)
{ {
@ -69,7 +63,7 @@ void GLoad::setup(void)
void GLoad::execute(void) void GLoad::execute(void)
{ {
NerscField header; NerscField header;
std::string fileName = par_.file + "." std::string fileName = par().file + "."
+ std::to_string(env().getTrajectory()); + std::to_string(env().getTrajectory());
LOG(Message) << "Loading NERSC configuration from file '" << fileName LOG(Message) << "Loading NERSC configuration from file '" << fileName

View File

@ -37,21 +37,20 @@ BEGIN_HADRONS_NAMESPACE
/****************************************************************************** /******************************************************************************
* Load a NERSC configuration * * Load a NERSC configuration *
******************************************************************************/ ******************************************************************************/
class GLoad: public Module class GLoadPar: Serializable
{ {
public: public:
class Par: Serializable GRID_SERIALIZABLE_CLASS_MEMBERS(GLoadPar,
{ std::string, file);
public: };
GRID_SERIALIZABLE_CLASS_MEMBERS(Par, std::string, file);
}; class GLoad: public Module<GLoadPar>
{
public: public:
// constructor // constructor
GLoad(const std::string name); GLoad(const std::string name);
// destructor // destructor
virtual ~GLoad(void) = default; virtual ~GLoad(void) = default;
// parse parameters
virtual void parseParameters(XmlReader &reader, const std::string name);
// dependency relation // dependency relation
virtual std::vector<std::string> getInput(void); virtual std::vector<std::string> getInput(void);
virtual std::vector<std::string> getOutput(void); virtual std::vector<std::string> getOutput(void);
@ -59,8 +58,6 @@ public:
virtual void setup(void); virtual void setup(void);
// execution // execution
virtual void execute(void); virtual void execute(void);
private:
Par par_;
}; };
MODULE_REGISTER(GLoad); MODULE_REGISTER(GLoad);

View File

@ -35,7 +35,7 @@ using namespace Hadrons;
******************************************************************************/ ******************************************************************************/
// constructor ///////////////////////////////////////////////////////////////// // constructor /////////////////////////////////////////////////////////////////
GRandom::GRandom(const std::string name) GRandom::GRandom(const std::string name)
: Module(name) : Module<NoPar>(name)
{} {}
// dependencies/products /////////////////////////////////////////////////////// // dependencies/products ///////////////////////////////////////////////////////

View File

@ -37,7 +37,7 @@ BEGIN_HADRONS_NAMESPACE
/****************************************************************************** /******************************************************************************
* Random gauge * * Random gauge *
******************************************************************************/ ******************************************************************************/
class GRandom: public Module class GRandom: public Module<NoPar>
{ {
public: public:
// constructor // constructor

View File

@ -35,7 +35,7 @@ using namespace Hadrons;
******************************************************************************/ ******************************************************************************/
// constructor ///////////////////////////////////////////////////////////////// // constructor /////////////////////////////////////////////////////////////////
GUnit::GUnit(const std::string name) GUnit::GUnit(const std::string name)
: Module(name) : Module<NoPar>(name)
{} {}
// dependencies/products /////////////////////////////////////////////////////// // dependencies/products ///////////////////////////////////////////////////////

View File

@ -37,7 +37,7 @@ BEGIN_HADRONS_NAMESPACE
/****************************************************************************** /******************************************************************************
* Unit gauge * * Unit gauge *
******************************************************************************/ ******************************************************************************/
class GUnit: public Module class GUnit: public Module<NoPar>
{ {
public: public:
// constructor // constructor

View File

@ -39,16 +39,10 @@ MQuark::MQuark(const std::string name)
: Module(name) : Module(name)
{} {}
// parse parameters ////////////////////////////////////////////////////////////
void MQuark::parseParameters(XmlReader &reader, const std::string name)
{
read(reader, name, par_);
}
// dependencies/products /////////////////////////////////////////////////////// // dependencies/products ///////////////////////////////////////////////////////
std::vector<std::string> MQuark::getInput(void) 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; return in;
} }
@ -63,7 +57,7 @@ std::vector<std::string> MQuark::getOutput(void)
// setup /////////////////////////////////////////////////////////////////////// // setup ///////////////////////////////////////////////////////////////////////
void MQuark::setup(void) void MQuark::setup(void)
{ {
Ls_ = env().getObjectLs(env().getSolverAction(par_.solver)); Ls_ = env().getObjectLs(env().getSolverAction(par().solver));
env().registerLattice<LatticePropagator>(getName()); env().registerLattice<LatticePropagator>(getName());
if (Ls_ > 1) if (Ls_ > 1)
{ {
@ -74,54 +68,59 @@ void MQuark::setup(void)
// execution /////////////////////////////////////////////////////////////////// // execution ///////////////////////////////////////////////////////////////////
void MQuark::execute(void) void MQuark::execute(void)
{ {
LatticePropagator *fullSource; LatticeFermion source(env().getGrid(Ls_)), sol(env().getGrid(Ls_)),
LatticeFermion source(env().getGrid(Ls_)), sol(env().getGrid(Ls_)); tmp(env().getGrid());
std::string propName = (Ls_ == 1) ? getName() : (getName() + "_5d"); std::string propName = (Ls_ == 1) ? getName() : (getName() + "_5d");
LOG(Message) << "Computing quark propagator '" << getName() << "'" LOG(Message) << "Computing quark propagator '" << getName() << "'"
<< std::endl; << std::endl;
LatticePropagator &prop = *env().create<LatticePropagator>(propName); 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)
{
// source conversion for 4D sources // source conversion for 4D sources
if (!env().isObject5d(par_.source)) if (!env().isObject5d(par().source))
{ {
if (Ls_ == 1) if (Ls_ == 1)
{ {
fullSource = env().get<LatticePropagator>(par_.source); PropToFerm(source, fullSrc, s, c);
} }
else else
{ {
HADRON_ERROR("MQuark not implemented with 5D actions"); 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 // source conversion for 5D sources
else else
{ {
if (Ls_ == 1) if (Ls_ != env().getObjectLs(par().source))
{
HADRON_ERROR("MQuark not implemented with 5D actions");
}
else if (Ls_ != env().getObjectLs(par_.source))
{ {
HADRON_ERROR("Ls mismatch between quark action and source"); HADRON_ERROR("Ls mismatch between quark action and source");
} }
else else
{ {
fullSource = env().get<LatticePropagator>(par_.source); PropToFerm(source, fullSrc, s, c);
} }
} }
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);
sol = zero; sol = zero;
env().callSolver(par_.solver, sol, source); env().callSolver(par().solver, sol, source);
FermToProp(prop, sol, s, c); FermToProp(prop, sol, s, c);
} }
// create 4D propagators from 5D one if necessary // create 4D propagators from 5D one if necessary
if (Ls_ > 1) if (Ls_ > 1)
{ {
HADRON_ERROR("MQuark not implemented with 5D actions"); LatticePropagator &prop4d = *env().create<LatticePropagator>(getName());
} }
} }

View File

@ -37,22 +37,21 @@ BEGIN_HADRONS_NAMESPACE
/****************************************************************************** /******************************************************************************
* MQuark * * MQuark *
******************************************************************************/ ******************************************************************************/
class MQuark: public Module class MQuarkPar: Serializable
{ {
public: public:
class Par: Serializable GRID_SERIALIZABLE_CLASS_MEMBERS(MQuarkPar,
{ std::string, source,
public:
GRID_SERIALIZABLE_CLASS_MEMBERS(Par, std::string, source,
std::string, solver); std::string, solver);
}; };
class MQuark: public Module<MQuarkPar>
{
public: public:
// constructor // constructor
MQuark(const std::string name); MQuark(const std::string name);
// destructor // destructor
virtual ~MQuark(void) = default; virtual ~MQuark(void) = default;
// parse parameters
virtual void parseParameters(XmlReader &reader, const std::string name);
// dependencies/products // dependencies/products
virtual std::vector<std::string> getInput(void); virtual std::vector<std::string> getInput(void);
virtual std::vector<std::string> getOutput(void); virtual std::vector<std::string> getOutput(void);
@ -61,7 +60,6 @@ public:
// execution // execution
virtual void execute(void); virtual void execute(void);
private: private:
Par par_;
unsigned int Ls_; unsigned int Ls_;
Environment::Solver *solver_{nullptr}; Environment::Solver *solver_{nullptr};
}; };

View File

@ -39,16 +39,10 @@ SolRBPrecCG::SolRBPrecCG(const std::string name)
: Module(name) : Module(name)
{} {}
// parse parameters ////////////////////////////////////////////////////////////
void SolRBPrecCG::parseParameters(XmlReader &reader, const std::string name)
{
read(reader, name, par_);
}
// dependencies/products /////////////////////////////////////////////////////// // dependencies/products ///////////////////////////////////////////////////////
std::vector<std::string> SolRBPrecCG::getInput(void) std::vector<std::string> SolRBPrecCG::getInput(void)
{ {
std::vector<std::string> in = {par_.action}; std::vector<std::string> in = {par().action};
return in; return in;
} }
@ -64,25 +58,25 @@ std::vector<std::string> SolRBPrecCG::getOutput(void)
void SolRBPrecCG::setup(void) void SolRBPrecCG::setup(void)
{ {
env().registerObject(getName(), 0); env().registerObject(getName(), 0);
env().addOwnership(getName(), par_.action); env().addOwnership(getName(), par().action);
env().setSolverAction(getName(), par_.action); env().setSolverAction(getName(), par().action);
} }
// execution /////////////////////////////////////////////////////////////////// // execution ///////////////////////////////////////////////////////////////////
void SolRBPrecCG::execute(void) void SolRBPrecCG::execute(void)
{ {
auto &mat = *(env().getFermionMatrix(par_.action)); auto &mat = *(env().getFermionMatrix(par().action));
auto solver = [&mat, this](LatticeFermion &sol, auto solver = [&mat, this](LatticeFermion &sol,
const LatticeFermion &source) const LatticeFermion &source)
{ {
ConjugateGradient<LatticeFermion> cg(par_.residual, 10000); ConjugateGradient<LatticeFermion> cg(par().residual, 10000);
SchurRedBlackDiagMooeeSolve<LatticeFermion> schurSolver(cg); SchurRedBlackDiagMooeeSolve<LatticeFermion> schurSolver(cg);
schurSolver(mat, source, sol); schurSolver(mat, source, sol);
}; };
LOG(Message) << "setting up Schur red-black preconditioned CG for" LOG(Message) << "setting up Schur red-black preconditioned CG for"
<< " action '" << par_.action << "' with residual " << " action '" << par().action << "' with residual "
<< par_.residual << std::endl; << par().residual << std::endl;
env().addSolver(getName(), solver); env().addSolver(getName(), solver);
} }

View File

@ -37,22 +37,21 @@ BEGIN_HADRONS_NAMESPACE
/****************************************************************************** /******************************************************************************
* Schur red-black preconditioned CG * * Schur red-black preconditioned CG *
******************************************************************************/ ******************************************************************************/
class SolRBPrecCG: public Module class SolRBPrecCGPar: Serializable
{ {
public: public:
class Par: Serializable GRID_SERIALIZABLE_CLASS_MEMBERS(SolRBPrecCGPar,
{ std::string, action,
public:
GRID_SERIALIZABLE_CLASS_MEMBERS(Par, std::string, action,
double , residual); double , residual);
}; };
class SolRBPrecCG: public Module<SolRBPrecCGPar>
{
public: public:
// constructor // constructor
SolRBPrecCG(const std::string name); SolRBPrecCG(const std::string name);
// destructor // destructor
virtual ~SolRBPrecCG(void) = default; virtual ~SolRBPrecCG(void) = default;
// parse parameters
virtual void parseParameters(XmlReader &reader, const std::string name);
// dependencies/products // dependencies/products
virtual std::vector<std::string> getInput(void); virtual std::vector<std::string> getInput(void);
virtual std::vector<std::string> getOutput(void); virtual std::vector<std::string> getOutput(void);
@ -60,8 +59,6 @@ public:
virtual void setup(void); virtual void setup(void);
// execution // execution
virtual void execute(void); virtual void execute(void);
private:
Par par_;
}; };
MODULE_REGISTER(SolRBPrecCG); MODULE_REGISTER(SolRBPrecCG);

View File

@ -35,15 +35,9 @@ using namespace Hadrons;
******************************************************************************/ ******************************************************************************/
// constructor ///////////////////////////////////////////////////////////////// // constructor /////////////////////////////////////////////////////////////////
SrcPoint::SrcPoint(const std::string name) 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 /////////////////////////////////////////////////////// // dependencies/products ///////////////////////////////////////////////////////
std::vector<std::string> SrcPoint::getInput(void) std::vector<std::string> SrcPoint::getInput(void)
{ {
@ -68,10 +62,10 @@ void SrcPoint::setup(void)
// execution /////////////////////////////////////////////////////////////////// // execution ///////////////////////////////////////////////////////////////////
void SrcPoint::execute(void) void SrcPoint::execute(void)
{ {
std::vector<int> position = strToVec<int>(par_.position); std::vector<int> position = strToVec<int>(par().position);
SpinColourMatrix id; SpinColourMatrix id;
LOG(Message) << "Creating point source at position [" << par_.position LOG(Message) << "Creating point source at position [" << par().position
<< "]" << std::endl; << "]" << std::endl;
LatticePropagator &src = *env().create<LatticePropagator>(getName()); LatticePropagator &src = *env().create<LatticePropagator>(getName());
id = 1.; id = 1.;

View File

@ -48,21 +48,20 @@ BEGIN_HADRONS_NAMESPACE
/****************************************************************************** /******************************************************************************
* SrcPoint * * SrcPoint *
******************************************************************************/ ******************************************************************************/
class SrcPoint: public Module class SrcPointPar: Serializable
{ {
public: public:
class Par: Serializable GRID_SERIALIZABLE_CLASS_MEMBERS(SrcPointPar,
{ std::string, position);
public: };
GRID_SERIALIZABLE_CLASS_MEMBERS(Par, std::string, position);
}; class SrcPoint: public Module<SrcPointPar>
{
public: public:
// constructor // constructor
SrcPoint(const std::string name); SrcPoint(const std::string name);
// destructor // destructor
virtual ~SrcPoint(void) = default; virtual ~SrcPoint(void) = default;
// parse parameters
virtual void parseParameters(XmlReader &reader, const std::string name);
// dependency relation // dependency relation
virtual std::vector<std::string> getInput(void); virtual std::vector<std::string> getInput(void);
virtual std::vector<std::string> getOutput(void); virtual std::vector<std::string> getOutput(void);
@ -70,8 +69,6 @@ public:
virtual void setup(void); virtual void setup(void);
// execution // execution
virtual void execute(void); virtual void execute(void);
private:
Par par_;
}; };
MODULE_REGISTER(SrcPoint); MODULE_REGISTER(SrcPoint);

View File

@ -35,15 +35,9 @@ using namespace Hadrons;
******************************************************************************/ ******************************************************************************/
// constructor ///////////////////////////////////////////////////////////////// // constructor /////////////////////////////////////////////////////////////////
SrcZ2::SrcZ2(const std::string name) 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 /////////////////////////////////////////////////////// // dependencies/products ///////////////////////////////////////////////////////
std::vector<std::string> SrcZ2::getInput(void) std::vector<std::string> SrcZ2::getInput(void)
{ {
@ -73,21 +67,21 @@ void SrcZ2::execute(void)
LatticeFermion phi(env().getGrid()); LatticeFermion phi(env().getGrid());
Complex shift(1., 1.); 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; << std::endl;
} }
else else
{ {
LOG(Message) << "Generating Z_2 band for " << par_.tA << " <= t <= " LOG(Message) << "Generating Z_2 band for " << par().tA << " <= t <= "
<< par_.tB << std::endl; << par().tB << std::endl;
} }
LatticePropagator &src = *env().create<LatticePropagator>(getName()); LatticePropagator &src = *env().create<LatticePropagator>(getName());
LatticeCoordinate(t, Tp); LatticeCoordinate(t, Tp);
bernoulli(*env().get4dRng(), eta); bernoulli(*env().get4dRng(), eta);
eta = (2.*eta - shift)*(1./::sqrt(2.)); 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 = 1.;
src = src*eta; src = src*eta;
} }

View File

@ -49,22 +49,21 @@ BEGIN_HADRONS_NAMESPACE
/****************************************************************************** /******************************************************************************
* SrcZ2 * * SrcZ2 *
******************************************************************************/ ******************************************************************************/
class SrcZ2: public Module class SrcZ2Par: Serializable
{ {
public: public:
class Par: Serializable GRID_SERIALIZABLE_CLASS_MEMBERS(SrcZ2Par,
{ unsigned int, tA,
public:
GRID_SERIALIZABLE_CLASS_MEMBERS(Par, unsigned int, tA,
unsigned int, tB); unsigned int, tB);
}; };
class SrcZ2: public Module<SrcZ2Par>
{
public: public:
// constructor // constructor
SrcZ2(const std::string name); SrcZ2(const std::string name);
// destructor // destructor
virtual ~SrcZ2(void) = default; virtual ~SrcZ2(void) = default;
// parse parameters
virtual void parseParameters(XmlReader &reader, const std::string name);
// dependency relation // dependency relation
virtual std::vector<std::string> getInput(void); virtual std::vector<std::string> getInput(void);
virtual std::vector<std::string> getOutput(void); virtual std::vector<std::string> getOutput(void);
@ -72,8 +71,6 @@ public:
virtual void setup(void); virtual void setup(void);
// execution // execution
virtual void execute(void); virtual void execute(void);
private:
Par par_;
}; };
MODULE_REGISTER(SrcZ2); MODULE_REGISTER(SrcZ2);