diff --git a/lib/serialisation/BaseIO.h b/lib/serialisation/BaseIO.h index 6deb17f5..7761a8e6 100644 --- a/lib/serialisation/BaseIO.h +++ b/lib/serialisation/BaseIO.h @@ -67,9 +67,8 @@ namespace Grid { return os; } - class Serializable {}; - // static polymorphism implemented using CRTP idiom + class Serializable; // Static abstract writer template @@ -122,6 +121,27 @@ namespace Grid { T *upcast; }; + // serializable base class + class Serializable + { + public: + template + static inline void write(Writer &WR,const std::string &s, + const Serializable &obj) + {} + + template + static inline void read(Reader &RD,const std::string &s, + Serializable &obj) + {} + + friend inline std::ostream & operator<<(std::ostream &os, + const Serializable &obj) + { + return os; + } + }; + // Generic writer interface template inline void push(Writer &w, const std::string &s) diff --git a/programs/Hadrons/Environment.cc b/programs/Hadrons/Environment.cc index 98724035..f92ab9d4 100644 --- a/programs/Hadrons/Environment.cc +++ b/programs/Hadrons/Environment.cc @@ -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)); } diff --git a/programs/Hadrons/Environment.hpp b/programs/Hadrons/Environment.hpp index 4cecf7da..b56b1680 100644 --- a/programs/Hadrons/Environment.hpp +++ b/programs/Hadrons/Environment.hpp @@ -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 ModPt; + typedef std::unique_ptr ModPt; typedef std::unique_ptr GridPt; typedef std::unique_ptr GridRbPt; typedef FermionOperator 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; diff --git a/programs/Hadrons/Module.cc b/programs/Hadrons/Module.cc index a2dedb52..70fcd79f 100644 --- a/programs/Hadrons/Module.cc +++ b/programs/Hadrons/Module.cc @@ -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()) diff --git a/programs/Hadrons/Module.hpp b/programs/Hadrons/Module.hpp index 2b4bfabe..7260eee8 100644 --- a/programs/Hadrons/Module.hpp +++ b/programs/Hadrons/Module.hpp @@ -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 getInput(void) = 0; virtual std::vector 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 +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 +Module

::Module(const std::string name) +: ModuleBase(name) +{} + +template +void Module

::parseParameters(XmlReader &reader, const std::string name) +{ + read(reader, name, par_);read(reader, name, par_); +} + +template +const P & Module

::par(void) const +{ + return par_; +} + +template +void Module

::setPar(const P &par) +{ + par_ = par; +} + END_HADRONS_NAMESPACE #endif // Hadrons_Module_hpp_ diff --git a/programs/Hadrons/ModuleFactory.hpp b/programs/Hadrons/ModuleFactory.hpp index 263a0828..0169ef94 100644 --- a/programs/Hadrons/ModuleFactory.hpp +++ b/programs/Hadrons/ModuleFactory.hpp @@ -37,7 +37,7 @@ BEGIN_HADRONS_NAMESPACE /****************************************************************************** * ModuleFactory * ******************************************************************************/ -class ModuleFactory: public Factory +class ModuleFactory: public Factory { SINGLETON_DEFCTOR(ModuleFactory) }; diff --git a/programs/Hadrons/Modules/AWilson.cc b/programs/Hadrons/Modules/AWilson.cc index 77f9cc25..9b7c1b04 100644 --- a/programs/Hadrons/Modules/AWilson.cc +++ b/programs/Hadrons/Modules/AWilson.cc @@ -35,19 +35,13 @@ using namespace Hadrons; ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// AWilson::AWilson(const std::string name) -: Module(name) +: Module(name) {} -// parse parameters //////////////////////////////////////////////////////////// -void AWilson::parseParameters(XmlReader &reader, const std::string name) -{ - read(reader, name, par_); -} - // dependencies/products /////////////////////////////////////////////////////// std::vector AWilson::getInput(void) { - std::vector in = {par_.gauge}; + std::vector in = {par().gauge}; return in; } @@ -71,13 +65,13 @@ void AWilson::setup(void) // execution /////////////////////////////////////////////////////////////////// void AWilson::execute() { - auto &U = *env().get(par_.gauge); + auto &U = *env().get(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); } diff --git a/programs/Hadrons/Modules/AWilson.hpp b/programs/Hadrons/Modules/AWilson.hpp index 1eaf0a36..cb35525e 100644 --- a/programs/Hadrons/Modules/AWilson.hpp +++ b/programs/Hadrons/Modules/AWilson.hpp @@ -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 +{ 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 getInput(void); virtual std::vector getOutput(void); @@ -60,8 +59,6 @@ public: virtual void setup(void); // execution virtual void execute(void); -private: - Par par_; }; MODULE_REGISTER(AWilson); diff --git a/programs/Hadrons/Modules/CMeson.cc b/programs/Hadrons/Modules/CMeson.cc index 28b2dd81..53088c43 100644 --- a/programs/Hadrons/Modules/CMeson.cc +++ b/programs/Hadrons/Modules/CMeson.cc @@ -36,19 +36,13 @@ using namespace Hadrons; ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// CMeson::CMeson(const std::string name) -: Module(name) +: Module(name) {} -// parse parameters //////////////////////////////////////////////////////////// -void CMeson::parseParameters(XmlReader &reader, const std::string name) -{ - read(reader, name, par_); -} - // dependencies/products /////////////////////////////////////////////////////// std::vector CMeson::getInput(void) { - std::vector input = {par_.q1, par_.q2}; + std::vector input = {par().q1, par().q2}; return input; } @@ -64,12 +58,12 @@ std::vector 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(par_.q1); - LatticePropagator &q2 = *env().get(par_.q2); + XmlWriter writer(par().output); + LatticePropagator &q1 = *env().get(par().q1); + LatticePropagator &q2 = *env().get(par().q2); LatticeComplex c(env().getGrid()); SpinMatrix g[Ns*Ns], g5; std::vector buf; diff --git a/programs/Hadrons/Modules/CMeson.hpp b/programs/Hadrons/Modules/CMeson.hpp index bc9f3177..1cbd6d86 100644 --- a/programs/Hadrons/Modules/CMeson.hpp +++ b/programs/Hadrons/Modules/CMeson.hpp @@ -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 { 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 getInput(void); virtual std::vector getOutput(void); // execution virtual void execute(void); -private: - Par par_; }; MODULE_REGISTER(CMeson); diff --git a/programs/Hadrons/Modules/GLoad.cc b/programs/Hadrons/Modules/GLoad.cc index 8f1b4d95..590c4135 100644 --- a/programs/Hadrons/Modules/GLoad.cc +++ b/programs/Hadrons/Modules/GLoad.cc @@ -35,15 +35,9 @@ using namespace Hadrons; ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// GLoad::GLoad(const std::string name) -: Module(name) +: Module(name) {} -// parse parameters //////////////////////////////////////////////////////////// -void GLoad::parseParameters(XmlReader &reader, const std::string name) -{ - read(reader, name, par_); -} - // dependencies/products /////////////////////////////////////////////////////// std::vector 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 diff --git a/programs/Hadrons/Modules/GLoad.hpp b/programs/Hadrons/Modules/GLoad.hpp index cb076bb5..af01e40e 100644 --- a/programs/Hadrons/Modules/GLoad.hpp +++ b/programs/Hadrons/Modules/GLoad.hpp @@ -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 +{ 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 getInput(void); virtual std::vector getOutput(void); @@ -59,8 +58,6 @@ public: virtual void setup(void); // execution virtual void execute(void); -private: - Par par_; }; MODULE_REGISTER(GLoad); diff --git a/programs/Hadrons/Modules/GRandom.cc b/programs/Hadrons/Modules/GRandom.cc index 34b1d57e..f40c8121 100644 --- a/programs/Hadrons/Modules/GRandom.cc +++ b/programs/Hadrons/Modules/GRandom.cc @@ -35,7 +35,7 @@ using namespace Hadrons; ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// GRandom::GRandom(const std::string name) -: Module(name) +: Module(name) {} // dependencies/products /////////////////////////////////////////////////////// diff --git a/programs/Hadrons/Modules/GRandom.hpp b/programs/Hadrons/Modules/GRandom.hpp index 5d0f4197..a31028fd 100644 --- a/programs/Hadrons/Modules/GRandom.hpp +++ b/programs/Hadrons/Modules/GRandom.hpp @@ -37,7 +37,7 @@ BEGIN_HADRONS_NAMESPACE /****************************************************************************** * Random gauge * ******************************************************************************/ -class GRandom: public Module +class GRandom: public Module { public: // constructor diff --git a/programs/Hadrons/Modules/GUnit.cc b/programs/Hadrons/Modules/GUnit.cc index d61f5551..20d815f1 100644 --- a/programs/Hadrons/Modules/GUnit.cc +++ b/programs/Hadrons/Modules/GUnit.cc @@ -35,7 +35,7 @@ using namespace Hadrons; ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// GUnit::GUnit(const std::string name) -: Module(name) +: Module(name) {} // dependencies/products /////////////////////////////////////////////////////// diff --git a/programs/Hadrons/Modules/GUnit.hpp b/programs/Hadrons/Modules/GUnit.hpp index 3c72bd07..eff34020 100644 --- a/programs/Hadrons/Modules/GUnit.hpp +++ b/programs/Hadrons/Modules/GUnit.hpp @@ -37,7 +37,7 @@ BEGIN_HADRONS_NAMESPACE /****************************************************************************** * Unit gauge * ******************************************************************************/ -class GUnit: public Module +class GUnit: public Module { public: // constructor diff --git a/programs/Hadrons/Modules/MQuark.cc b/programs/Hadrons/Modules/MQuark.cc index ffb91791..aa8344ac 100644 --- a/programs/Hadrons/Modules/MQuark.cc +++ b/programs/Hadrons/Modules/MQuark.cc @@ -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 MQuark::getInput(void) { - std::vector in = {par_.source, par_.solver}; + std::vector in = {par().source, par().solver}; return in; } @@ -63,7 +57,7 @@ std::vector MQuark::getOutput(void) // setup /////////////////////////////////////////////////////////////////////// void MQuark::setup(void) { - Ls_ = env().getObjectLs(env().getSolverAction(par_.solver)); + Ls_ = env().getObjectLs(env().getSolverAction(par().solver)); env().registerLattice(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(propName); - // source conversion for 4D sources - if (!env().isObject5d(par_.source)) - { - if (Ls_ == 1) - { - fullSource = env().get(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(par_.source); - } - } - LOG(Message) << "Inverting using solver '" << par_.solver - << "' on source '" << par_.source << "'" << std::endl; + LatticePropagator &prop = *env().create(propName); + LatticePropagator &fullSrc = *env().create(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(getName()); + + } } diff --git a/programs/Hadrons/Modules/MQuark.hpp b/programs/Hadrons/Modules/MQuark.hpp index 14ced177..0080090b 100644 --- a/programs/Hadrons/Modules/MQuark.hpp +++ b/programs/Hadrons/Modules/MQuark.hpp @@ -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 +{ 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 getInput(void); virtual std::vector getOutput(void); @@ -61,7 +60,6 @@ public: // execution virtual void execute(void); private: - Par par_; unsigned int Ls_; Environment::Solver *solver_{nullptr}; }; diff --git a/programs/Hadrons/Modules/SolRBPrecCG.cc b/programs/Hadrons/Modules/SolRBPrecCG.cc index 3db4a4d1..14a09be5 100644 --- a/programs/Hadrons/Modules/SolRBPrecCG.cc +++ b/programs/Hadrons/Modules/SolRBPrecCG.cc @@ -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 SolRBPrecCG::getInput(void) { - std::vector in = {par_.action}; + std::vector in = {par().action}; return in; } @@ -64,25 +58,25 @@ std::vector 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 cg(par_.residual, 10000); + ConjugateGradient cg(par().residual, 10000); SchurRedBlackDiagMooeeSolve 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); } diff --git a/programs/Hadrons/Modules/SolRBPrecCG.hpp b/programs/Hadrons/Modules/SolRBPrecCG.hpp index 82784666..b987eb95 100644 --- a/programs/Hadrons/Modules/SolRBPrecCG.hpp +++ b/programs/Hadrons/Modules/SolRBPrecCG.hpp @@ -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 +{ 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 getInput(void); virtual std::vector getOutput(void); @@ -60,8 +59,6 @@ public: virtual void setup(void); // execution virtual void execute(void); -private: - Par par_; }; MODULE_REGISTER(SolRBPrecCG); diff --git a/programs/Hadrons/Modules/SrcPoint.cc b/programs/Hadrons/Modules/SrcPoint.cc index b668f7bb..3b7c3d10 100644 --- a/programs/Hadrons/Modules/SrcPoint.cc +++ b/programs/Hadrons/Modules/SrcPoint.cc @@ -35,15 +35,9 @@ using namespace Hadrons; ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// SrcPoint::SrcPoint(const std::string name) -: Module(name) +: Module(name) {} -// parse parameters //////////////////////////////////////////////////////////// -void SrcPoint::parseParameters(XmlReader &reader, const std::string name) -{ - read(reader, name, par_); -} - // dependencies/products /////////////////////////////////////////////////////// std::vector SrcPoint::getInput(void) { @@ -68,10 +62,10 @@ void SrcPoint::setup(void) // execution /////////////////////////////////////////////////////////////////// void SrcPoint::execute(void) { - std::vector position = strToVec(par_.position); + std::vector position = strToVec(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(getName()); id = 1.; diff --git a/programs/Hadrons/Modules/SrcPoint.hpp b/programs/Hadrons/Modules/SrcPoint.hpp index 8cfa89c9..75108319 100644 --- a/programs/Hadrons/Modules/SrcPoint.hpp +++ b/programs/Hadrons/Modules/SrcPoint.hpp @@ -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 +{ 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 getInput(void); virtual std::vector getOutput(void); @@ -70,8 +69,6 @@ public: virtual void setup(void); // execution virtual void execute(void); -private: - Par par_; }; MODULE_REGISTER(SrcPoint); diff --git a/programs/Hadrons/Modules/SrcZ2.cc b/programs/Hadrons/Modules/SrcZ2.cc index 2c9bb403..c77c2943 100644 --- a/programs/Hadrons/Modules/SrcZ2.cc +++ b/programs/Hadrons/Modules/SrcZ2.cc @@ -35,15 +35,9 @@ using namespace Hadrons; ******************************************************************************/ // constructor ///////////////////////////////////////////////////////////////// SrcZ2::SrcZ2(const std::string name) -: Module(name) +: Module(name) {} -// parse parameters //////////////////////////////////////////////////////////// -void SrcZ2::parseParameters(XmlReader &reader, const std::string name) -{ - read(reader, name, par_); -} - // dependencies/products /////////////////////////////////////////////////////// std::vector 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(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; } diff --git a/programs/Hadrons/Modules/SrcZ2.hpp b/programs/Hadrons/Modules/SrcZ2.hpp index a1458693..a61f8688 100644 --- a/programs/Hadrons/Modules/SrcZ2.hpp +++ b/programs/Hadrons/Modules/SrcZ2.hpp @@ -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 +{ 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 getInput(void); virtual std::vector getOutput(void); @@ -72,8 +71,6 @@ public: virtual void setup(void); // execution virtual void execute(void); -private: - Par par_; }; MODULE_REGISTER(SrcZ2);