2016-12-15 18:26:39 +00:00
|
|
|
/*************************************************************************************
|
|
|
|
|
2016-02-25 12:07:21 +00:00
|
|
|
Grid physics library, www.github.com/paboyle/Grid
|
|
|
|
|
2018-09-01 21:30:30 +01:00
|
|
|
Source file: Hadrons/Global.hpp
|
2016-02-25 12:07:21 +00:00
|
|
|
|
2019-02-05 18:55:24 +00:00
|
|
|
Copyright (C) 2015-2019
|
2016-02-25 12:07:21 +00:00
|
|
|
|
|
|
|
Author: Antonin Portelli <antonin.portelli@me.com>
|
2017-12-26 13:16:47 +00:00
|
|
|
Author: Lanny91 <andrew.lawson@gmail.com>
|
2016-02-25 12:07:21 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
2016-12-15 18:26:39 +00:00
|
|
|
See the full license in the file "LICENSE" in the top level distribution directory
|
|
|
|
*************************************************************************************/
|
2016-12-15 18:21:52 +00:00
|
|
|
/* END LEGAL */
|
2015-10-27 17:33:18 +00:00
|
|
|
|
|
|
|
#ifndef Hadrons_Global_hpp_
|
|
|
|
#define Hadrons_Global_hpp_
|
|
|
|
|
2015-11-05 14:28:14 +00:00
|
|
|
#include <set>
|
2015-12-02 19:33:34 +00:00
|
|
|
#include <stack>
|
2018-10-17 20:26:48 +01:00
|
|
|
#include <regex>
|
2016-08-03 17:14:32 +01:00
|
|
|
#include <Grid/Grid.h>
|
2016-12-14 18:02:18 +00:00
|
|
|
#include <cxxabi.h>
|
2015-10-27 17:33:18 +00:00
|
|
|
|
2017-12-05 14:31:59 +00:00
|
|
|
#ifndef SITE_SIZE_TYPE
|
2017-12-12 19:32:58 +00:00
|
|
|
#define SITE_SIZE_TYPE size_t
|
2017-12-05 14:31:59 +00:00
|
|
|
#endif
|
|
|
|
|
2018-05-07 21:37:03 +01:00
|
|
|
#ifndef DEFAULT_ASCII_PREC
|
|
|
|
#define DEFAULT_ASCII_PREC 16
|
|
|
|
#endif
|
|
|
|
|
2019-02-04 21:21:51 +00:00
|
|
|
#define ARG(...) __VA_ARGS__
|
|
|
|
|
2018-06-25 19:08:22 +01:00
|
|
|
/* the 'using Grid::operator<<;' statement prevents a very nasty compilation
|
|
|
|
* error with GCC 5 (clang & GCC 6 compile fine without it).
|
|
|
|
*/
|
|
|
|
|
2015-10-27 17:33:18 +00:00
|
|
|
#define BEGIN_HADRONS_NAMESPACE \
|
2016-05-03 03:31:21 +01:00
|
|
|
namespace Grid {\
|
2015-10-27 17:33:18 +00:00
|
|
|
namespace Hadrons {\
|
2018-03-05 19:58:13 +00:00
|
|
|
using Grid::operator<<;\
|
|
|
|
using Grid::operator>>;
|
2016-05-03 03:31:21 +01:00
|
|
|
#define END_HADRONS_NAMESPACE }}
|
|
|
|
|
2016-12-05 05:29:32 +00:00
|
|
|
#define BEGIN_MODULE_NAMESPACE(name)\
|
|
|
|
namespace name {\
|
2018-03-05 19:58:13 +00:00
|
|
|
using Grid::operator<<;\
|
|
|
|
using Grid::operator>>;
|
|
|
|
|
2016-12-05 05:29:32 +00:00
|
|
|
#define END_MODULE_NAMESPACE }
|
|
|
|
|
2018-09-14 12:46:43 +01:00
|
|
|
#define _HADRONS_IMPL(impl, sub) impl##sub
|
|
|
|
#define HADRONS_IMPL(impl, sub) _HADRONS_IMPL(impl, sub)
|
|
|
|
|
|
|
|
#ifndef FIMPLBASE
|
|
|
|
#define FIMPLBASE WilsonImpl
|
2016-11-27 07:47:22 +00:00
|
|
|
#endif
|
2018-09-14 12:46:43 +01:00
|
|
|
#define FIMPL HADRONS_IMPL(FIMPLBASE, R)
|
|
|
|
#define FIMPLF HADRONS_IMPL(FIMPLBASE, F)
|
|
|
|
#define FIMPLD HADRONS_IMPL(FIMPLBASE, D)
|
|
|
|
|
|
|
|
#ifndef ZFIMPLBASE
|
|
|
|
#define ZFIMPLBASE ZWilsonImpl
|
2018-02-27 19:32:19 +00:00
|
|
|
#endif
|
2018-09-14 12:46:43 +01:00
|
|
|
#define ZFIMPL HADRONS_IMPL(ZFIMPLBASE, R)
|
|
|
|
#define ZFIMPLF HADRONS_IMPL(ZFIMPLBASE, F)
|
|
|
|
#define ZFIMPLD HADRONS_IMPL(ZFIMPLBASE, D)
|
|
|
|
|
|
|
|
#ifndef SIMPLBASE
|
|
|
|
#define SIMPLBASE ScalarImplC
|
2016-12-29 21:44:58 +00:00
|
|
|
#endif
|
2018-09-14 12:46:43 +01:00
|
|
|
#define SIMPL HADRONS_IMPL(SIMPLBASE, R)
|
|
|
|
#define SIMPLF HADRONS_IMPL(SIMPLBASE, F)
|
|
|
|
#define SIMPLD HADRONS_IMPL(SIMPLBASE, D)
|
|
|
|
|
|
|
|
#ifndef GIMPLBASE
|
|
|
|
#define GIMPLBASE PeriodicGimpl
|
2017-12-27 13:24:29 +00:00
|
|
|
#endif
|
2018-09-14 12:46:43 +01:00
|
|
|
#define GIMPL HADRONS_IMPL(GIMPLBASE, R)
|
|
|
|
#define GIMPLF HADRONS_IMPL(GIMPLBASE, F)
|
|
|
|
#define GIMPLD HADRONS_IMPL(GIMPLBASE, D)
|
2016-11-27 07:47:22 +00:00
|
|
|
|
2015-10-27 17:33:18 +00:00
|
|
|
BEGIN_HADRONS_NAMESPACE
|
|
|
|
|
2016-11-28 05:02:10 +00:00
|
|
|
// type aliases
|
2018-09-21 18:15:18 +01:00
|
|
|
#define BASIC_TYPE_ALIASES(Impl, suffix)\
|
|
|
|
typedef typename Impl::Field ScalarField##suffix;\
|
|
|
|
typedef typename Impl::PropagatorField PropagatorField##suffix;\
|
|
|
|
typedef typename Impl::SitePropagator::scalar_object SitePropagator##suffix;\
|
2019-02-04 21:21:51 +00:00
|
|
|
typedef typename Impl::ComplexField ComplexField##suffix;\
|
|
|
|
typedef std::vector<SitePropagator##suffix> SlicedPropagator##suffix;\
|
|
|
|
typedef std::vector<typename ComplexField##suffix::vector_object::scalar_object> SlicedComplex##suffix;
|
2016-12-29 21:44:58 +00:00
|
|
|
|
2018-09-21 18:15:18 +01:00
|
|
|
#define FERM_TYPE_ALIASES(FImpl, suffix)\
|
|
|
|
BASIC_TYPE_ALIASES(FImpl, suffix);\
|
2019-05-24 13:08:35 +01:00
|
|
|
typedef FermionOperator<FImpl> FMat##suffix;\
|
|
|
|
typedef typename FImpl::FermionField FermionField##suffix;\
|
|
|
|
typedef typename FImpl::GaugeField GaugeField##suffix;\
|
|
|
|
typedef typename FImpl::DoubledGaugeField DoubledGaugeField##suffix;\
|
|
|
|
typedef Lattice<iSpinMatrix<typename FImpl::Simd>> SpinMatrixField##suffix;
|
2016-12-29 21:44:58 +00:00
|
|
|
|
2018-09-21 18:15:18 +01:00
|
|
|
#define GAUGE_TYPE_ALIASES(GImpl, suffix)\
|
|
|
|
typedef typename GImpl::GaugeField GaugeField##suffix;
|
2016-12-29 21:44:58 +00:00
|
|
|
|
|
|
|
#define SOLVER_TYPE_ALIASES(FImpl, suffix)\
|
2018-06-22 11:14:37 +01:00
|
|
|
typedef Solver<FImpl> Solver##suffix;
|
2016-11-28 05:02:10 +00:00
|
|
|
|
2017-06-06 17:45:30 +01:00
|
|
|
#define SINK_TYPE_ALIASES(suffix)\
|
2017-12-27 13:24:29 +00:00
|
|
|
typedef std::function<SlicedPropagator##suffix\
|
|
|
|
(const PropagatorField##suffix &)> SinkFn##suffix;
|
2017-06-06 17:45:30 +01:00
|
|
|
|
2016-11-28 05:02:10 +00:00
|
|
|
// logger
|
2015-10-27 17:33:18 +00:00
|
|
|
class HadronsLogger: public Logger
|
|
|
|
{
|
|
|
|
public:
|
2016-02-23 16:21:45 +00:00
|
|
|
HadronsLogger(int on, std::string nm): Logger("Hadrons", on, nm,
|
2016-08-03 17:14:32 +01:00
|
|
|
GridLogColours, "BLACK"){};
|
2015-10-27 17:33:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define LOG(channel) std::cout << HadronsLog##channel
|
2018-04-25 16:49:14 +01:00
|
|
|
#define HADRONS_DEBUG_VAR(var) LOG(Debug) << #var << "= " << (var) << std::endl;
|
2015-10-27 17:33:18 +00:00
|
|
|
|
|
|
|
extern HadronsLogger HadronsLogError;
|
|
|
|
extern HadronsLogger HadronsLogWarning;
|
|
|
|
extern HadronsLogger HadronsLogMessage;
|
2016-05-09 14:49:06 +01:00
|
|
|
extern HadronsLogger HadronsLogIterative;
|
2015-10-27 17:33:18 +00:00
|
|
|
extern HadronsLogger HadronsLogDebug;
|
2018-02-27 13:46:59 +00:00
|
|
|
extern HadronsLogger HadronsLogIRL;
|
2015-10-27 17:33:18 +00:00
|
|
|
|
2017-12-29 15:58:23 +00:00
|
|
|
void initLogger(void);
|
|
|
|
|
2015-12-23 14:21:35 +00:00
|
|
|
// singleton pattern
|
|
|
|
#define SINGLETON(name)\
|
|
|
|
public:\
|
|
|
|
name(const name &e) = delete;\
|
|
|
|
void operator=(const name &e) = delete;\
|
|
|
|
static name & getInstance(void)\
|
|
|
|
{\
|
|
|
|
static name e;\
|
|
|
|
return e;\
|
|
|
|
}\
|
|
|
|
private:\
|
|
|
|
name(void);
|
|
|
|
|
2016-04-30 08:17:04 +01:00
|
|
|
#define SINGLETON_DEFCTOR(name)\
|
|
|
|
public:\
|
|
|
|
name(const name &e) = delete;\
|
|
|
|
void operator=(const name &e) = delete;\
|
|
|
|
static name & getInstance(void)\
|
|
|
|
{\
|
|
|
|
static name e;\
|
|
|
|
return e;\
|
|
|
|
}\
|
|
|
|
private:\
|
|
|
|
name(void) = default;
|
|
|
|
|
2016-12-14 18:02:18 +00:00
|
|
|
// type utilities
|
2016-05-10 19:07:41 +01:00
|
|
|
template <typename T>
|
2016-12-14 18:02:18 +00:00
|
|
|
const std::type_info * typeIdPt(const T &x)
|
2016-05-10 19:07:41 +01:00
|
|
|
{
|
2016-12-14 18:02:18 +00:00
|
|
|
return &typeid(x);
|
2016-05-10 19:07:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
2016-12-14 18:02:18 +00:00
|
|
|
const std::type_info * typeIdPt(void)
|
2016-05-10 19:07:41 +01:00
|
|
|
{
|
2016-12-14 18:02:18 +00:00
|
|
|
return &typeid(T);
|
2016-05-10 19:07:41 +01:00
|
|
|
}
|
|
|
|
|
2018-09-10 15:31:39 +01:00
|
|
|
size_t typeHash(const std::type_info *info);
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
size_t typeHash(const T &x)
|
|
|
|
{
|
|
|
|
return typeHash(typeIdPt(x));
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
size_t typeHash(void)
|
|
|
|
{
|
|
|
|
return typeHash(typeIdPt<T>());
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string typeName(const std::type_info *info);
|
|
|
|
|
2016-06-06 17:45:37 +01:00
|
|
|
template <typename T>
|
2016-12-14 18:02:18 +00:00
|
|
|
std::string typeName(const T &x)
|
2016-06-06 17:45:37 +01:00
|
|
|
{
|
2016-12-14 18:02:18 +00:00
|
|
|
return typeName(typeIdPt(x));
|
2016-06-06 17:45:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
2016-12-14 18:02:18 +00:00
|
|
|
std::string typeName(void)
|
2016-06-06 17:45:37 +01:00
|
|
|
{
|
2016-12-14 18:02:18 +00:00
|
|
|
return typeName(typeIdPt<T>());
|
2016-06-06 17:45:37 +01:00
|
|
|
}
|
|
|
|
|
2017-02-08 15:50:05 +00:00
|
|
|
// default writers/readers
|
2018-01-10 10:59:58 +00:00
|
|
|
extern const std::string resultFileExt;
|
|
|
|
|
2017-02-08 15:50:05 +00:00
|
|
|
#ifdef HAVE_HDF5
|
2018-01-10 10:59:58 +00:00
|
|
|
typedef Hdf5Reader ResultReader;
|
|
|
|
typedef Hdf5Writer ResultWriter;
|
2017-02-08 15:50:05 +00:00
|
|
|
#else
|
2018-01-10 10:59:58 +00:00
|
|
|
typedef XmlReader ResultReader;
|
|
|
|
typedef XmlWriter ResultWriter;
|
2017-02-08 15:50:05 +00:00
|
|
|
#endif
|
|
|
|
|
2018-11-19 15:45:04 +00:00
|
|
|
#define RESULT_FILE_NAME(name, traj) \
|
|
|
|
name + "." + std::to_string(traj) + "." + resultFileExt
|
2018-01-10 10:59:58 +00:00
|
|
|
|
2018-04-23 17:36:43 +01:00
|
|
|
// recursive mkdir
|
|
|
|
#define MAX_PATH_LENGTH 512u
|
|
|
|
int mkdir(const std::string dirName);
|
|
|
|
std::string basename(const std::string &s);
|
2018-04-23 18:45:39 +01:00
|
|
|
std::string dirname(const std::string &s);
|
2018-11-19 15:45:04 +00:00
|
|
|
void makeFileDir(const std::string filename, GridBase *g = nullptr);
|
2018-02-27 18:45:23 +00:00
|
|
|
|
2018-04-23 17:36:43 +01:00
|
|
|
// default Schur convention
|
2018-02-27 18:45:23 +00:00
|
|
|
#ifndef HADRONS_DEFAULT_SCHUR
|
2018-03-13 17:10:54 +00:00
|
|
|
#define HADRONS_DEFAULT_SCHUR DiagTwo
|
2018-02-27 18:45:23 +00:00
|
|
|
#endif
|
|
|
|
#define _HADRONS_SCHUR_OP_(conv) Schur##conv##Operator
|
|
|
|
#define HADRONS_SCHUR_OP(conv) _HADRONS_SCHUR_OP_(conv)
|
|
|
|
#define HADRONS_DEFAULT_SCHUR_OP HADRONS_SCHUR_OP(HADRONS_DEFAULT_SCHUR)
|
|
|
|
#define _HADRONS_SCHUR_SOLVE_(conv) SchurRedBlack##conv##Solve
|
|
|
|
#define HADRONS_SCHUR_SOLVE(conv) _HADRONS_SCHUR_SOLVE_(conv)
|
|
|
|
#define HADRONS_DEFAULT_SCHUR_SOLVE HADRONS_SCHUR_SOLVE(HADRONS_DEFAULT_SCHUR)
|
2018-08-09 00:38:17 +01:00
|
|
|
#define _HADRONS_SCHUR_A2A_(conv) A2AVectorsSchur##conv
|
|
|
|
#define HADRONS_SCHUR_A2A(conv) _HADRONS_SCHUR_A2A_(conv)
|
|
|
|
#define HADRONS_DEFAULT_SCHUR_A2A HADRONS_SCHUR_A2A(HADRONS_DEFAULT_SCHUR)
|
2018-02-27 18:45:23 +00:00
|
|
|
|
2018-06-25 19:08:22 +01:00
|
|
|
// stringify macro
|
|
|
|
#define _HADRONS_STR(x) #x
|
|
|
|
#define HADRONS_STR(x) _HADRONS_STR(x)
|
|
|
|
|
2018-08-10 16:07:30 +01:00
|
|
|
// pretty print time profile
|
|
|
|
void printTimeProfile(const std::map<std::string, GridTime> &timing, GridTime total);
|
|
|
|
|
2018-11-19 16:04:01 +00:00
|
|
|
// token replacement utility
|
|
|
|
template <typename T>
|
|
|
|
void tokenReplace(std::string &str, const std::string token,
|
|
|
|
const T &x, const std::string mark = "@")
|
|
|
|
{
|
|
|
|
std::string fullToken = mark + token + mark;
|
|
|
|
|
|
|
|
auto pos = str.find(fullToken);
|
|
|
|
if (pos != std::string::npos)
|
|
|
|
{
|
|
|
|
str.replace(pos, fullToken.size(), std::to_string(x));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-04 21:21:51 +00:00
|
|
|
// generic correlator class
|
|
|
|
template <typename Metadata, typename Scalar = Complex>
|
|
|
|
struct Correlator: Serializable
|
|
|
|
{
|
|
|
|
GRID_SERIALIZABLE_CLASS_MEMBERS(ARG(Correlator<Metadata, Scalar>),
|
|
|
|
Metadata, info,
|
2019-11-21 17:25:37 +00:00
|
|
|
std::vector<Scalar>, corr);
|
2019-02-04 21:21:51 +00:00
|
|
|
};
|
|
|
|
|
2015-10-27 17:33:18 +00:00
|
|
|
END_HADRONS_NAMESPACE
|
|
|
|
|
2018-08-28 15:00:40 +01:00
|
|
|
#include <Hadrons/Exceptions.hpp>
|
2017-12-12 14:04:28 +00:00
|
|
|
|
2015-10-27 17:33:18 +00:00
|
|
|
#endif // Hadrons_Global_hpp_
|