mirror of
https://github.com/paboyle/Grid.git
synced 2025-06-11 03:46:55 +01:00
Added support for input file HMC modules (missing the actions yet)
This commit is contained in:
@ -50,6 +50,7 @@ public:
|
||||
const ProductCreator& name) const;
|
||||
private:
|
||||
std::map<std::string, Func> builder_;
|
||||
virtual std::string obj_type() const = 0;
|
||||
};
|
||||
|
||||
/******************************************************************************
|
||||
@ -79,20 +80,24 @@ std::vector<std::string> Factory<T, ProductCreator>::getBuilderList(void) const
|
||||
// factory /////////////////////////////////////////////////////////////////////
|
||||
template <typename T, typename ProductCreator>
|
||||
std::unique_ptr<T> Factory<T, ProductCreator>::create(const std::string type,
|
||||
const ProductCreator& name) const
|
||||
const ProductCreator& input) const
|
||||
{
|
||||
Func func;
|
||||
|
||||
std::cout << GridLogDebug << "Creating object of type "<< type << std::endl;
|
||||
try
|
||||
{
|
||||
func = builder_.at(type);
|
||||
}
|
||||
catch (std::out_of_range &)
|
||||
{
|
||||
//HADRON_ERROR("object of type '" + type + "' unknown");
|
||||
//HADRON_ERROR("object of type '" + type + "' unknown");
|
||||
std::cout << GridLogError << "Error" << std::endl;
|
||||
std::cout << GridLogError << obj_type() << " object of name [" << type << "] unknown" << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return func(name);
|
||||
return func(input);
|
||||
}
|
||||
|
||||
}
|
||||
|
35
lib/qcd/modules/Modules.cc
Normal file
35
lib/qcd/modules/Modules.cc
Normal file
@ -0,0 +1,35 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: ./lib/qcd/modules/Modules.cc
|
||||
|
||||
Copyright (C) 2016
|
||||
|
||||
Author: Guido Cossu <guido.cossu@ed.ac.uk>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
See the full license in the file "LICENSE" in the top level distribution
|
||||
directory
|
||||
*************************************************************************************/
|
||||
/* END LEGAL */
|
||||
|
||||
namespace Grid{
|
||||
|
||||
char gauge_string[] = "gauge";
|
||||
char cp_string[] = "CheckPointer";
|
||||
|
||||
}
|
@ -50,6 +50,16 @@ public:
|
||||
Parametrized(Reader<ReaderClass> & Reader){
|
||||
read(Reader, section_name(), Par_);
|
||||
}
|
||||
|
||||
void set_parameters(Parameters Par){
|
||||
Par_ = Par;
|
||||
}
|
||||
|
||||
|
||||
void print_parameters(){
|
||||
std::cout << Par_ << std::endl;
|
||||
}
|
||||
|
||||
protected:
|
||||
Parameters Par_;
|
||||
|
||||
@ -70,6 +80,7 @@ class HMCModuleBase{
|
||||
public:
|
||||
typedef Prod Product;
|
||||
virtual Prod* getPtr() = 0;
|
||||
virtual void print_parameters(){}; //default to nothing
|
||||
};
|
||||
|
||||
|
||||
@ -87,6 +98,8 @@ class ActionModule
|
||||
typedef HMCModuleBase< QCD::Action<typename ActionType::GaugeField> > Base;
|
||||
typedef typename Base::Product Product;
|
||||
|
||||
|
||||
|
||||
std::unique_ptr<ActionType> ActionPtr;
|
||||
|
||||
ActionModule(APar Par) : Parametrized<APar>(Par) {}
|
||||
@ -94,6 +107,10 @@ class ActionModule
|
||||
template <class ReaderClass>
|
||||
ActionModule(Reader<ReaderClass>& Reader) : Parametrized<APar>(Reader){};
|
||||
|
||||
virtual void print_parameters(){
|
||||
std::cout << this->Par_ << std::endl;
|
||||
}
|
||||
|
||||
Product* getPtr() {
|
||||
if (!ActionPtr) initialize();
|
||||
|
||||
@ -102,8 +119,16 @@ class ActionModule
|
||||
|
||||
private:
|
||||
virtual void initialize() = 0;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
namespace QCD{
|
||||
|
||||
class WilsonGaugeActionParameters : Serializable {
|
||||
@ -118,11 +143,11 @@ class WilsonGaugeActionParameters : Serializable {
|
||||
template<class Impl>
|
||||
class WilsonGModule: public ActionModule<WilsonGaugeAction<Impl>, WilsonGaugeActionParameters> {
|
||||
typedef ActionModule<WilsonGaugeAction<Impl>, WilsonGaugeActionParameters> ActionBase;
|
||||
using ActionBase::ActionBase;
|
||||
using ActionBase::ActionBase; // for constructors
|
||||
|
||||
// acquire resource
|
||||
virtual void initialize(){
|
||||
ActionBase::ActionPtr.reset(new WilsonGaugeAction<Impl>(ActionBase::Par_.beta));
|
||||
this->ActionPtr.reset(new WilsonGaugeAction<Impl>(this->Par_.beta));
|
||||
}
|
||||
|
||||
};
|
||||
@ -137,31 +162,38 @@ typedef WilsonGModule<PeriodicGimplR> WilsonGMod;
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////
|
||||
// Factories specialisations
|
||||
////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
// use the same classed defined by Antonin, does not make sense to rewrite
|
||||
// Factory is perfectly fine
|
||||
// Registar must be changed because I do not want to use the ModuleFactory
|
||||
/*
|
||||
define
|
||||
*/
|
||||
|
||||
// ref to LatticeGaugeField must be changed
|
||||
typedef HMCModuleBase< QCD::Action< QCD::LatticeGaugeField > > HMC_LGTActionModBase;
|
||||
|
||||
typedef HMCModuleBase< QCD::Action< QCD::LatticeGaugeField > > HMCModBase;
|
||||
|
||||
template <class ReaderClass >
|
||||
class HMCActionModuleFactory
|
||||
: public Factory < HMCModBase , Reader<ReaderClass> > {
|
||||
template <char const *str, class ReaderClass >
|
||||
class HMC_LGTActionModuleFactory
|
||||
: public Factory < HMC_LGTActionModBase , Reader<ReaderClass> > {
|
||||
public:
|
||||
typedef Reader<ReaderClass> TheReader;
|
||||
typedef Reader<ReaderClass> TheReader;
|
||||
// use SINGLETON FUNCTOR MACRO HERE
|
||||
HMCActionModuleFactory(const HMCActionModuleFactory& e) = delete;
|
||||
void operator=(const HMCActionModuleFactory& e) = delete;
|
||||
static HMCActionModuleFactory& getInstance(void) {
|
||||
static HMCActionModuleFactory e;
|
||||
HMC_LGTActionModuleFactory(const HMC_LGTActionModuleFactory& e) = delete;
|
||||
void operator=(const HMC_LGTActionModuleFactory& e) = delete;
|
||||
static HMC_LGTActionModuleFactory& getInstance(void) {
|
||||
static HMC_LGTActionModuleFactory e;
|
||||
return e;
|
||||
}
|
||||
|
||||
private:
|
||||
HMCActionModuleFactory(void) = default;
|
||||
HMC_LGTActionModuleFactory(void) = default;
|
||||
std::string obj_type() const {
|
||||
return std::string(str);
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
@ -178,6 +210,8 @@ when needed a pointer is released
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
template <class T, class TheFactory>
|
||||
class Registrar {
|
||||
public:
|
||||
@ -188,9 +222,10 @@ class Registrar {
|
||||
}
|
||||
};
|
||||
|
||||
Registrar<QCD::WilsonGMod, HMCActionModuleFactory<XmlReader> > __WGmodInit("WilsonGaugeAction");
|
||||
|
||||
|
||||
extern char gauge_string[];
|
||||
static Registrar<QCD::WilsonGMod, HMC_LGTActionModuleFactory<gauge_string, XmlReader> > __WGmodXMLInit("Wilson");
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user