mirror of
https://github.com/paboyle/Grid.git
synced 2025-04-10 06:00:45 +01:00
Hadrons: sources are now independent modules
This commit is contained in:
parent
b865dd9da8
commit
ba878724ce
@ -1,144 +0,0 @@
|
||||
/*******************************************************************************
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: programs/Hadrons/MSource.cc
|
||||
|
||||
Copyright (C) 2016
|
||||
|
||||
Author: Antonin Portelli <antonin.portelli@me.com>
|
||||
|
||||
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.
|
||||
*******************************************************************************/
|
||||
|
||||
#include <Hadrons/MSource.hpp>
|
||||
|
||||
#define ERROR_SUF " (source '" << getName() << "')"
|
||||
|
||||
using namespace Grid;
|
||||
using namespace QCD;
|
||||
using namespace Hadrons;
|
||||
|
||||
/******************************************************************************
|
||||
* MSource implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
MSource::MSource(const std::string name)
|
||||
: Module(name)
|
||||
{}
|
||||
|
||||
// parse parameters ////////////////////////////////////////////////////////////
|
||||
void MSource::parseParameters(XmlReader &reader, const std::string name)
|
||||
{
|
||||
read(reader, name, par_);
|
||||
}
|
||||
|
||||
// dependencies/products ///////////////////////////////////////////////////////
|
||||
std::vector<std::string> MSource::getInput(void)
|
||||
{
|
||||
return std::vector<std::string>();
|
||||
}
|
||||
|
||||
std::vector<std::string> MSource::getOutput(void)
|
||||
{
|
||||
std::vector<std::string> out = {getName()};
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
// allocation //////////////////////////////////////////////////////////////////
|
||||
void MSource::allocate(Environment &env)
|
||||
{
|
||||
switch (par_.sourceType)
|
||||
{
|
||||
// 4D sources
|
||||
case Grid::SourceType::point:
|
||||
case Grid::SourceType::z2Band:
|
||||
env.createProp(getName());
|
||||
src_ = env.getProp(getName());
|
||||
break;
|
||||
// error
|
||||
default:
|
||||
HADRON_ERROR("no allocation implemented for source type '"
|
||||
<< par_.sourceType << "'" << ERROR_SUF);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// execution
|
||||
#define ARG_CHECK(n)\
|
||||
if (par_.arguments.size() != (n))\
|
||||
{\
|
||||
HADRON_ERROR("source type '" << par_.sourceType << "' expect "\
|
||||
<< (n) << " arguments (got "\
|
||||
<< par_.arguments.size() << ")" << ERROR_SUF);\
|
||||
}
|
||||
|
||||
void MSource::execute(Environment &env)
|
||||
{
|
||||
LOG(Message) << "generating source '" << getName() << "' of type '"
|
||||
<< par_.sourceType << "'" << std::endl;
|
||||
switch (par_.sourceType)
|
||||
{
|
||||
// point source
|
||||
case Grid::SourceType::point:
|
||||
{
|
||||
ARG_CHECK(1);
|
||||
|
||||
std::vector<int> origin = strToVec<int>(par_.arguments[0]);
|
||||
SpinColourMatrix id(1.);
|
||||
|
||||
if (origin.size() != Nd)
|
||||
{
|
||||
HADRON_ERROR("point source origin dimension different from "
|
||||
<< Nd << ERROR_SUF);
|
||||
}
|
||||
*src_ = zero;
|
||||
pokeSite(id, *src_, origin);
|
||||
|
||||
break;
|
||||
}
|
||||
// z2Band source
|
||||
case Grid::SourceType::z2Band:
|
||||
{
|
||||
ARG_CHECK(2);
|
||||
|
||||
int ta = std::stoi(par_.arguments[0]);
|
||||
int tb = std::stoi(par_.arguments[1]);
|
||||
Lattice<iScalar<vInteger>> t(env.getGrid());
|
||||
LatticeComplex eta(env.getGrid());
|
||||
LatticeFermion phi(env.getGrid());
|
||||
Complex shift(1., 1.);
|
||||
|
||||
LatticeCoordinate(t, Tp);
|
||||
bernoulli(*env.get4dRng(), eta);
|
||||
eta = (2.*eta - shift)*(1./::sqrt(2.));
|
||||
eta = where((t >= ta) and (t <= tb), eta, 0.*eta);
|
||||
*src_ = 1.;
|
||||
*src_ = (*src_)*eta;
|
||||
|
||||
break;
|
||||
}
|
||||
// error
|
||||
default:
|
||||
{
|
||||
HADRON_ERROR("no definition implemented for source type '"
|
||||
<< par_.sourceType << "'" << ERROR_SUF);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
@ -13,8 +13,7 @@ Hadrons_SOURCES = \
|
||||
|
||||
# general modules
|
||||
Hadrons_SOURCES += \
|
||||
MQuark.cc \
|
||||
MSource.cc
|
||||
MQuark.cc
|
||||
|
||||
# fermion actions
|
||||
Hadrons_SOURCES += \
|
||||
@ -34,4 +33,9 @@ Hadrons_SOURCES += \
|
||||
Hadrons_SOURCES += \
|
||||
SolRBPrecCG.cc
|
||||
|
||||
# source modules
|
||||
Hadrons_SOURCES += \
|
||||
SrcPoint.cc \
|
||||
SrcZ2.cc
|
||||
|
||||
Hadrons_LDADD = -lGrid
|
||||
|
80
programs/Hadrons/SrcPoint.cc
Normal file
80
programs/Hadrons/SrcPoint.cc
Normal file
@ -0,0 +1,80 @@
|
||||
/*******************************************************************************
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: programs/Hadrons/SrcPoint.cc
|
||||
|
||||
Copyright (C) 2016
|
||||
|
||||
Author: Antonin Portelli <antonin.portelli@me.com>
|
||||
|
||||
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.
|
||||
*******************************************************************************/
|
||||
|
||||
#include <Hadrons/SrcPoint.hpp>
|
||||
|
||||
using namespace Grid;
|
||||
using namespace Hadrons;
|
||||
|
||||
/******************************************************************************
|
||||
* SrcPoint implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
SrcPoint::SrcPoint(const std::string name)
|
||||
: Module(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)
|
||||
{
|
||||
std::vector<std::string> in;
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
std::vector<std::string> SrcPoint::getOutput(void)
|
||||
{
|
||||
std::vector<std::string> out = {getName()};
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
// allocation //////////////////////////////////////////////////////////////////
|
||||
void SrcPoint::allocate(Environment &env)
|
||||
{
|
||||
env.createProp(getName());
|
||||
src_ = env.getProp(getName());
|
||||
}
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
void SrcPoint::execute(Environment &env)
|
||||
{
|
||||
std::vector<int> position = strToVec<int>(par_.position);
|
||||
SpinColourMatrix id;
|
||||
|
||||
LOG(Message) << "creating point source at position [" << par_.position
|
||||
<< "]" << std::endl;
|
||||
id = 1.;
|
||||
*src_ = zero;
|
||||
pokeSite(id, *src_, position);
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
/*******************************************************************************
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: programs/Hadrons/MSource.hpp
|
||||
Source file: programs/Hadrons/SrcPoint.hpp
|
||||
|
||||
Copyright (C) 2016
|
||||
|
||||
@ -25,66 +25,45 @@ See the full license in the file "LICENSE" in the top level distribution
|
||||
directory.
|
||||
*******************************************************************************/
|
||||
|
||||
/************
|
||||
* Sources *
|
||||
************
|
||||
|
||||
Description of all source types.
|
||||
Convention: the discrete Heavyside function verifies theta(0) = 1.
|
||||
|
||||
point: Point source
|
||||
-------------------
|
||||
* src(x) = delta_x,o
|
||||
|
||||
* arguments: o
|
||||
- o: origin, space-separated integer sequence (e.g. "0 1 1 0")
|
||||
|
||||
z2Band: Z_2 stochastic source
|
||||
-----------------------------
|
||||
* src(x) = eta_x * theta(x_0 - ta) * theta(tb - x_0)
|
||||
|
||||
* arguments: ta tb
|
||||
- ta: begin timeslice (integer)
|
||||
- tb: end timesilce (integer)
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#ifndef Hadrons_MSource_hpp_
|
||||
#define Hadrons_MSource_hpp_
|
||||
#ifndef Hadrons_SrcPoint_hpp_
|
||||
#define Hadrons_SrcPoint_hpp_
|
||||
|
||||
#include <Hadrons/Global.hpp>
|
||||
#include <Hadrons/Module.hpp>
|
||||
#include <Hadrons/ModuleFactory.hpp>
|
||||
|
||||
namespace Grid{
|
||||
GRID_SERIALIZABLE_ENUM(SourceType, undef,
|
||||
point, 1,
|
||||
z2Band, 2);
|
||||
}
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
/*
|
||||
|
||||
Point source
|
||||
------------
|
||||
* src_x = delta_x,o
|
||||
|
||||
* options: o
|
||||
- position: space-separated integer sequence (e.g. "0 1 1 0")
|
||||
|
||||
*/
|
||||
|
||||
/******************************************************************************
|
||||
* Source module *
|
||||
* SrcPoint *
|
||||
******************************************************************************/
|
||||
class MSource: public Module
|
||||
class SrcPoint: public Module
|
||||
{
|
||||
public:
|
||||
class Par: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(Par, SourceType, sourceType,
|
||||
std::vector<std::string>, arguments);
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(Par, std::string, position);
|
||||
};
|
||||
public:
|
||||
// constructor
|
||||
MSource(const std::string name);
|
||||
SrcPoint(const std::string name);
|
||||
// destructor
|
||||
virtual ~MSource(void) = default;
|
||||
virtual ~SrcPoint(void) = default;
|
||||
// parse parameters
|
||||
virtual void parseParameters(XmlReader &reader, const std::string name);
|
||||
// dependencies/products
|
||||
// dependency relation
|
||||
virtual std::vector<std::string> getInput(void);
|
||||
virtual std::vector<std::string> getOutput(void);
|
||||
// allocation
|
||||
@ -96,8 +75,8 @@ private:
|
||||
LatticePropagator *src_{nullptr};
|
||||
};
|
||||
|
||||
MODULE_REGISTER(MSource);
|
||||
MODULE_REGISTER(SrcPoint);
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_MSource_hpp_
|
||||
#endif // Hadrons_SrcPoint_hpp_
|
93
programs/Hadrons/SrcZ2.cc
Normal file
93
programs/Hadrons/SrcZ2.cc
Normal file
@ -0,0 +1,93 @@
|
||||
/*******************************************************************************
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: programs/Hadrons/SrcZ2.cc
|
||||
|
||||
Copyright (C) 2016
|
||||
|
||||
Author: Antonin Portelli <antonin.portelli@me.com>
|
||||
|
||||
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.
|
||||
*******************************************************************************/
|
||||
|
||||
#include <Hadrons/SrcZ2.hpp>
|
||||
|
||||
using namespace Grid;
|
||||
using namespace Hadrons;
|
||||
|
||||
/******************************************************************************
|
||||
* SrcZ2 implementation *
|
||||
******************************************************************************/
|
||||
// constructor /////////////////////////////////////////////////////////////////
|
||||
SrcZ2::SrcZ2(const std::string name)
|
||||
: Module(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)
|
||||
{
|
||||
std::vector<std::string> in;
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
std::vector<std::string> SrcZ2::getOutput(void)
|
||||
{
|
||||
std::vector<std::string> out = {getName()};
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
// allocation //////////////////////////////////////////////////////////////////
|
||||
void SrcZ2::allocate(Environment &env)
|
||||
{
|
||||
env.createProp(getName());
|
||||
src_ = env.getProp(getName());
|
||||
}
|
||||
|
||||
// execution ///////////////////////////////////////////////////////////////////
|
||||
void SrcZ2::execute(Environment &env)
|
||||
{
|
||||
Lattice<iScalar<vInteger>> t(env.getGrid());
|
||||
LatticeComplex eta(env.getGrid());
|
||||
LatticeFermion phi(env.getGrid());
|
||||
Complex shift(1., 1.);
|
||||
|
||||
if (par_.tA == par_.tB)
|
||||
{
|
||||
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;
|
||||
}
|
||||
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);
|
||||
*src_ = 1.;
|
||||
*src_ = (*src_)*eta;
|
||||
}
|
84
programs/Hadrons/SrcZ2.hpp
Normal file
84
programs/Hadrons/SrcZ2.hpp
Normal file
@ -0,0 +1,84 @@
|
||||
/*******************************************************************************
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: programs/Hadrons/SrcZ2.hpp
|
||||
|
||||
Copyright (C) 2016
|
||||
|
||||
Author: Antonin Portelli <antonin.portelli@me.com>
|
||||
|
||||
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.
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef Hadrons_SrcZ2_hpp_
|
||||
#define Hadrons_SrcZ2_hpp_
|
||||
|
||||
#include <Hadrons/Global.hpp>
|
||||
#include <Hadrons/Module.hpp>
|
||||
#include <Hadrons/ModuleFactory.hpp>
|
||||
|
||||
BEGIN_HADRONS_NAMESPACE
|
||||
|
||||
/*
|
||||
|
||||
Z_2 stochastic source
|
||||
-----------------------------
|
||||
* src_x = eta_x * theta(x_3 - ta) * theta(tb - x_3)
|
||||
|
||||
* options:
|
||||
- tA: begin timeslice (integer)
|
||||
- tB: end timesilce (integer)
|
||||
|
||||
*/
|
||||
|
||||
/******************************************************************************
|
||||
* SrcZ2 *
|
||||
******************************************************************************/
|
||||
class SrcZ2: public Module
|
||||
{
|
||||
public:
|
||||
class Par: Serializable
|
||||
{
|
||||
public:
|
||||
GRID_SERIALIZABLE_CLASS_MEMBERS(Par, unsigned int, tA,
|
||||
unsigned int, tB);
|
||||
};
|
||||
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);
|
||||
// allocation
|
||||
virtual void allocate(Environment &env);
|
||||
// execution
|
||||
virtual void execute(Environment &env);
|
||||
private:
|
||||
Par par_;
|
||||
LatticePropagator *src_;
|
||||
};
|
||||
|
||||
MODULE_REGISTER(SrcZ2);
|
||||
|
||||
END_HADRONS_NAMESPACE
|
||||
|
||||
#endif // Hadrons_SrcZ2_hpp_
|
Loading…
x
Reference in New Issue
Block a user