1
0
mirror of https://github.com/paboyle/Grid.git synced 2024-09-20 17:25:37 +01:00
Grid/extras/Hadrons/Global.hpp

217 lines
5.9 KiB
C++
Raw Normal View History

2016-12-15 18:26:39 +00:00
/*************************************************************************************
2016-02-25 12:07:21 +00:00
Grid physics library, www.github.com/paboyle/Grid
2016-12-15 18:26:39 +00:00
Source file: extras/Hadrons/Global.hpp
2016-02-25 12:07:21 +00:00
2017-12-26 13:16:47 +00:00
Copyright (C) 2015-2018
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 */
#ifndef Hadrons_Global_hpp_
#define Hadrons_Global_hpp_
#include <set>
2015-12-02 19:33:34 +00:00
#include <stack>
2016-08-03 17:14:32 +01:00
#include <Grid/Grid.h>
2016-12-14 18:02:18 +00:00
#include <cxxabi.h>
#ifndef SITE_SIZE_TYPE
#define SITE_SIZE_TYPE size_t
#endif
#ifndef DEFAULT_ASCII_PREC
#define DEFAULT_ASCII_PREC 16
#endif
#define BEGIN_HADRONS_NAMESPACE \
namespace Grid {\
using namespace QCD;\
namespace Hadrons {\
using Grid::operator<<;\
using Grid::operator>>;
#define END_HADRONS_NAMESPACE }}
#define BEGIN_MODULE_NAMESPACE(name)\
namespace name {\
using Grid::operator<<;\
using Grid::operator>>;
#define END_MODULE_NAMESPACE }
/* the 'using Grid::operator<<;' statement prevents a very nasty compilation
* error with GCC 5 (clang & GCC 6 compile fine without it).
*/
#ifndef FIMPL
#define FIMPL WilsonImplR
#endif
2018-02-27 19:32:19 +00:00
#ifndef ZFIMPL
#define ZFIMPL ZWilsonImplR
#endif
#ifndef SIMPL
#define SIMPL ScalarImplCR
#endif
2017-12-27 13:24:29 +00:00
#ifndef GIMPL
#define GIMPL GimplTypesR
#endif
BEGIN_HADRONS_NAMESPACE
// type aliases
#define FERM_TYPE_ALIASES(FImpl, suffix)\
typedef FermionOperator<FImpl> FMat##suffix; \
typedef typename FImpl::FermionField FermionField##suffix; \
typedef typename FImpl::PropagatorField PropagatorField##suffix; \
typedef typename FImpl::SitePropagator::scalar_object SitePropagator##suffix; \
typedef std::vector<SitePropagator##suffix> SlicedPropagator##suffix;
#define GAUGE_TYPE_ALIASES(FImpl, suffix)\
typedef typename FImpl::DoubledGaugeField DoubledGaugeField##suffix;
#define SCALAR_TYPE_ALIASES(SImpl, suffix)\
typedef typename SImpl::Field ScalarField##suffix;\
typedef typename SImpl::Field PropagatorField##suffix;
#define SOLVER_TYPE_ALIASES(FImpl, suffix)\
typedef std::function<void(FermionField##suffix &,\
const FermionField##suffix &)> SolverFn##suffix;
#define SINK_TYPE_ALIASES(suffix)\
2017-12-27 13:24:29 +00:00
typedef std::function<SlicedPropagator##suffix\
(const PropagatorField##suffix &)> SinkFn##suffix;
#define FGS_TYPE_ALIASES(FImpl, suffix)\
FERM_TYPE_ALIASES(FImpl, suffix)\
GAUGE_TYPE_ALIASES(FImpl, suffix)\
SOLVER_TYPE_ALIASES(FImpl, suffix)
// logger
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"){};
};
#define LOG(channel) std::cout << HadronsLog##channel
#define HADRONS_DEBUG_VAR(var) LOG(Debug) << #var << "= " << (var) << std::endl;
extern HadronsLogger HadronsLogError;
extern HadronsLogger HadronsLogWarning;
extern HadronsLogger HadronsLogMessage;
extern HadronsLogger HadronsLogIterative;
extern HadronsLogger HadronsLogDebug;
2018-02-27 13:46:59 +00:00
extern HadronsLogger HadronsLogIRL;
void initLogger(void);
// 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);
#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
template <typename T>
2016-12-14 18:02:18 +00:00
const std::type_info * typeIdPt(const T &x)
{
2016-12-14 18:02:18 +00:00
return &typeid(x);
}
2016-12-14 18:02:18 +00:00
std::string typeName(const std::type_info *info);
template <typename T>
2016-12-14 18:02:18 +00:00
const std::type_info * typeIdPt(void)
{
2016-12-14 18:02:18 +00:00
return &typeid(T);
}
template <typename T>
2016-12-14 18:02:18 +00:00
std::string typeName(const T &x)
{
2016-12-14 18:02:18 +00:00
return typeName(typeIdPt(x));
}
template <typename T>
2016-12-14 18:02:18 +00:00
std::string typeName(void)
{
2016-12-14 18:02:18 +00:00
return typeName(typeIdPt<T>());
}
2017-02-08 15:50:05 +00:00
// default writers/readers
extern const std::string resultFileExt;
2017-02-08 15:50:05 +00:00
#ifdef HAVE_HDF5
typedef Hdf5Reader ResultReader;
typedef Hdf5Writer ResultWriter;
2017-02-08 15:50:05 +00:00
#else
typedef XmlReader ResultReader;
typedef XmlWriter ResultWriter;
2017-02-08 15:50:05 +00:00
#endif
#define RESULT_FILE_NAME(name) \
name + "." + std::to_string(vm().getTrajectory()) + "." + resultFileExt
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);
std::string dirname(const std::string &s);
void makeFileDir(const std::string filename, GridBase *g);
2018-04-23 17:36:43 +01:00
// default Schur convention
#ifndef HADRONS_DEFAULT_SCHUR
#define HADRONS_DEFAULT_SCHUR DiagTwo
#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)
END_HADRONS_NAMESPACE
#include <Grid/Hadrons/Exceptions.hpp>
#endif // Hadrons_Global_hpp_