mirror of
				https://github.com/paboyle/Grid.git
				synced 2025-11-04 05:54:32 +00:00 
			
		
		
		
	Hadrons: moving Hadrons to root directory, build system improvements
This commit is contained in:
		
							
								
								
									
										222
									
								
								Hadrons/A2AVectors.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										222
									
								
								Hadrons/A2AVectors.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,222 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/A2AVectors.hpp
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
Author: Antonin Portelli <antonin.portelli@me.com>
 | 
			
		||||
Author: fionnoh <fionnoh@gmail.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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
#ifndef A2A_Vectors_hpp_
 | 
			
		||||
#define A2A_Vectors_hpp_
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Global.hpp>
 | 
			
		||||
#include <Hadrons/Environment.hpp>
 | 
			
		||||
#include <Hadrons/Solver.hpp>
 | 
			
		||||
 | 
			
		||||
BEGIN_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *               Classes to generate V & W all-to-all vectors                 *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
class A2AVectorsSchurDiagTwo
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    FERM_TYPE_ALIASES(FImpl,);
 | 
			
		||||
    SOLVER_TYPE_ALIASES(FImpl,);
 | 
			
		||||
public:
 | 
			
		||||
    A2AVectorsSchurDiagTwo(FMat &action, Solver &solver);
 | 
			
		||||
    virtual ~A2AVectorsSchurDiagTwo(void) = default;
 | 
			
		||||
    void makeLowModeV(FermionField &vout, 
 | 
			
		||||
                      const FermionField &evec, const Real &eval);
 | 
			
		||||
    void makeLowModeV5D(FermionField &vout_4d, FermionField &vout_5d, 
 | 
			
		||||
                        const FermionField &evec, const Real &eval);
 | 
			
		||||
    void makeLowModeW(FermionField &wout, 
 | 
			
		||||
                      const FermionField &evec, const Real &eval);
 | 
			
		||||
    void makeLowModeW5D(FermionField &wout_4d, FermionField &wout_5d, 
 | 
			
		||||
                        const FermionField &evec, const Real &eval);
 | 
			
		||||
    void makeHighModeV(FermionField &vout, const FermionField &noise);
 | 
			
		||||
    void makeHighModeV5D(FermionField &vout_4d, FermionField &vout_5d, 
 | 
			
		||||
                         const FermionField &noise_5d);
 | 
			
		||||
    void makeHighModeW(FermionField &wout, const FermionField &noise);
 | 
			
		||||
    void makeHighModeW5D(FermionField &vout_5d, FermionField &wout_5d, 
 | 
			
		||||
                         const FermionField &noise_5d);
 | 
			
		||||
private:
 | 
			
		||||
    FMat                                     &action_;
 | 
			
		||||
    Solver                                   &solver_;
 | 
			
		||||
    GridBase                                 *fGrid_, *frbGrid_, *gGrid_;
 | 
			
		||||
    bool                                     is5d_;
 | 
			
		||||
    FermionField                             src_o_, sol_e_, sol_o_, tmp_, tmp5_;
 | 
			
		||||
    SchurDiagTwoOperator<FMat, FermionField> op_;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *               A2AVectorsSchurDiagTwo template implementation               *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
A2AVectorsSchurDiagTwo<FImpl>::A2AVectorsSchurDiagTwo(FMat &action, Solver &solver)
 | 
			
		||||
: action_(action)
 | 
			
		||||
, solver_(solver)
 | 
			
		||||
, fGrid_(action_.FermionGrid())
 | 
			
		||||
, frbGrid_(action_.FermionRedBlackGrid())
 | 
			
		||||
, gGrid_(action_.GaugeGrid())
 | 
			
		||||
, src_o_(frbGrid_)
 | 
			
		||||
, sol_e_(frbGrid_)
 | 
			
		||||
, sol_o_(frbGrid_)
 | 
			
		||||
, tmp_(frbGrid_)
 | 
			
		||||
, tmp5_(fGrid_)
 | 
			
		||||
, op_(action_)
 | 
			
		||||
{}
 | 
			
		||||
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
void A2AVectorsSchurDiagTwo<FImpl>::makeLowModeV(FermionField &vout, const FermionField &evec, const Real &eval)
 | 
			
		||||
{
 | 
			
		||||
    src_o_ = evec;
 | 
			
		||||
    src_o_.checkerboard = Odd;
 | 
			
		||||
    pickCheckerboard(Even, sol_e_, vout);
 | 
			
		||||
    pickCheckerboard(Odd, sol_o_, vout);
 | 
			
		||||
 | 
			
		||||
    /////////////////////////////////////////////////////
 | 
			
		||||
    // v_ie = -(1/eval_i) * MeeInv Meo MooInv evec_i
 | 
			
		||||
    /////////////////////////////////////////////////////
 | 
			
		||||
    action_.MooeeInv(src_o_, tmp_);
 | 
			
		||||
    assert(tmp_.checkerboard == Odd);
 | 
			
		||||
    action_.Meooe(tmp_, sol_e_);
 | 
			
		||||
    assert(sol_e_.checkerboard == Even);
 | 
			
		||||
    action_.MooeeInv(sol_e_, tmp_);
 | 
			
		||||
    assert(tmp_.checkerboard == Even);
 | 
			
		||||
    sol_e_ = (-1.0 / eval) * tmp_;
 | 
			
		||||
    assert(sol_e_.checkerboard == Even);
 | 
			
		||||
 | 
			
		||||
    /////////////////////////////////////////////////////
 | 
			
		||||
    // v_io = (1/eval_i) * MooInv evec_i
 | 
			
		||||
    /////////////////////////////////////////////////////
 | 
			
		||||
    action_.MooeeInv(src_o_, tmp_);
 | 
			
		||||
    assert(tmp_.checkerboard == Odd);
 | 
			
		||||
    sol_o_ = (1.0 / eval) * tmp_;
 | 
			
		||||
    assert(sol_o_.checkerboard == Odd);
 | 
			
		||||
    setCheckerboard(vout, sol_e_);
 | 
			
		||||
    assert(sol_e_.checkerboard == Even);
 | 
			
		||||
    setCheckerboard(vout, sol_o_);
 | 
			
		||||
    assert(sol_o_.checkerboard == Odd);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
void A2AVectorsSchurDiagTwo<FImpl>::makeLowModeV5D(FermionField &vout_4d, FermionField &vout_5d, const FermionField &evec, const Real &eval)
 | 
			
		||||
{
 | 
			
		||||
    makeLowModeV(vout_5d, evec, eval);
 | 
			
		||||
    action_.ExportPhysicalFermionSolution(vout_5d, vout_4d);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
void A2AVectorsSchurDiagTwo<FImpl>::makeLowModeW(FermionField &wout, const FermionField &evec, const Real &eval)
 | 
			
		||||
{
 | 
			
		||||
    src_o_ = evec;
 | 
			
		||||
    src_o_.checkerboard = Odd;
 | 
			
		||||
    pickCheckerboard(Even, sol_e_, wout);
 | 
			
		||||
    pickCheckerboard(Odd, sol_o_, wout);
 | 
			
		||||
 | 
			
		||||
    /////////////////////////////////////////////////////
 | 
			
		||||
    // w_ie = - MeeInvDag MoeDag Doo evec_i
 | 
			
		||||
    /////////////////////////////////////////////////////
 | 
			
		||||
    op_.Mpc(src_o_, tmp_);
 | 
			
		||||
    assert(tmp_.checkerboard == Odd);
 | 
			
		||||
    action_.MeooeDag(tmp_, sol_e_);
 | 
			
		||||
    assert(sol_e_.checkerboard == Even);
 | 
			
		||||
    action_.MooeeInvDag(sol_e_, tmp_);
 | 
			
		||||
    assert(tmp_.checkerboard == Even);
 | 
			
		||||
    sol_e_ = (-1.0) * tmp_;
 | 
			
		||||
 | 
			
		||||
    /////////////////////////////////////////////////////
 | 
			
		||||
    // w_io = Doo evec_i
 | 
			
		||||
    /////////////////////////////////////////////////////
 | 
			
		||||
    op_.Mpc(src_o_, sol_o_);
 | 
			
		||||
    assert(sol_o_.checkerboard == Odd);
 | 
			
		||||
    setCheckerboard(wout, sol_e_);
 | 
			
		||||
    assert(sol_e_.checkerboard == Even);
 | 
			
		||||
    setCheckerboard(wout, sol_o_);
 | 
			
		||||
    assert(sol_o_.checkerboard == Odd);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
void A2AVectorsSchurDiagTwo<FImpl>::makeLowModeW5D(FermionField &wout_4d, 
 | 
			
		||||
                                                   FermionField &wout_5d, 
 | 
			
		||||
                                                   const FermionField &evec, 
 | 
			
		||||
                                                   const Real &eval)
 | 
			
		||||
{
 | 
			
		||||
    makeLowModeW(tmp5_, evec, eval);
 | 
			
		||||
    action_.DminusDag(tmp5_, wout_5d);
 | 
			
		||||
    action_.ExportPhysicalFermionSource(wout_5d, wout_4d);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
void A2AVectorsSchurDiagTwo<FImpl>::makeHighModeV(FermionField &vout, 
 | 
			
		||||
                                                  const FermionField &noise)
 | 
			
		||||
{
 | 
			
		||||
    solver_(vout, noise);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
void A2AVectorsSchurDiagTwo<FImpl>::makeHighModeV5D(FermionField &vout_4d, 
 | 
			
		||||
                                                    FermionField &vout_5d, 
 | 
			
		||||
                                                    const FermionField &noise)
 | 
			
		||||
{
 | 
			
		||||
    if (noise._grid->Dimensions() == fGrid_->Dimensions() - 1)
 | 
			
		||||
    {
 | 
			
		||||
        action_.ImportPhysicalFermionSource(noise, tmp5_);
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        tmp5_ = noise;
 | 
			
		||||
    }
 | 
			
		||||
    makeHighModeV(vout_5d, tmp5_);
 | 
			
		||||
    action_.ExportPhysicalFermionSolution(vout_5d, vout_4d);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
void A2AVectorsSchurDiagTwo<FImpl>::makeHighModeW(FermionField &wout, 
 | 
			
		||||
                                                  const FermionField &noise)
 | 
			
		||||
{
 | 
			
		||||
    wout = noise;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
void A2AVectorsSchurDiagTwo<FImpl>::makeHighModeW5D(FermionField &wout_4d, 
 | 
			
		||||
                                                    FermionField &wout_5d, 
 | 
			
		||||
                                                    const FermionField &noise)
 | 
			
		||||
{
 | 
			
		||||
    if (noise._grid->Dimensions() == fGrid_->Dimensions() - 1)
 | 
			
		||||
    {
 | 
			
		||||
        action_.ImportUnphysicalFermion(noise, wout_5d);
 | 
			
		||||
        wout_4d = noise;
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        wout_5d = noise;
 | 
			
		||||
        action_.ExportPhysicalFermionSource(wout_5d, wout_4d);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
END_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
#endif // A2A_Vectors_hpp_
 | 
			
		||||
							
								
								
									
										265
									
								
								Hadrons/Application.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										265
									
								
								Hadrons/Application.cc
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,265 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Application.cc
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Application.hpp>
 | 
			
		||||
#include <Hadrons/GeneticScheduler.hpp>
 | 
			
		||||
#include <Hadrons/Modules.hpp>
 | 
			
		||||
 | 
			
		||||
using namespace Grid;
 | 
			
		||||
using namespace QCD;
 | 
			
		||||
using namespace Hadrons;
 | 
			
		||||
 | 
			
		||||
#define BIG_SEP "================"
 | 
			
		||||
#define SEP     "----------------"
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                       Application implementation                           *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
// constructors ////////////////////////////////////////////////////////////////
 | 
			
		||||
#define MACOUT(macro)    macro              << " (" << #macro << ")"
 | 
			
		||||
#define MACOUTS(macro) HADRONS_STR(macro) << " (" << #macro << ")"
 | 
			
		||||
 | 
			
		||||
Application::Application(void)
 | 
			
		||||
{
 | 
			
		||||
    initLogger();
 | 
			
		||||
    auto dim = GridDefaultLatt(), mpi = GridDefaultMpi(), loc(dim);
 | 
			
		||||
    locVol_ = 1;
 | 
			
		||||
    for (unsigned int d = 0; d < dim.size(); ++d)
 | 
			
		||||
    {
 | 
			
		||||
        loc[d]  /= mpi[d];
 | 
			
		||||
        locVol_ *= loc[d];
 | 
			
		||||
    }
 | 
			
		||||
    LOG(Message) << "====== HADRONS APPLICATION INITIALISATION ======" << std::endl;
 | 
			
		||||
    LOG(Message) << "** Dimensions" << std::endl;
 | 
			
		||||
    LOG(Message) << "Global lattice: " << dim << std::endl;
 | 
			
		||||
    LOG(Message) << "MPI partition : " << mpi << std::endl;
 | 
			
		||||
    LOG(Message) << "Local lattice : " << loc << std::endl;
 | 
			
		||||
    LOG(Message) << std::endl;
 | 
			
		||||
    LOG(Message) << "** Default parameters (and associated C macros)" << std::endl;
 | 
			
		||||
    LOG(Message) << "ASCII output precision  : " << MACOUT(DEFAULT_ASCII_PREC) << std::endl;
 | 
			
		||||
    LOG(Message) << "Fermion implementation  : " << MACOUTS(FIMPL) << std::endl;
 | 
			
		||||
    LOG(Message) << "z-Fermion implementation: " << MACOUTS(ZFIMPL) << std::endl;
 | 
			
		||||
    LOG(Message) << "Scalar implementation   : " << MACOUTS(SIMPL) << std::endl;
 | 
			
		||||
    LOG(Message) << "Gauge implementation    : " << MACOUTS(GIMPL) << std::endl;
 | 
			
		||||
    LOG(Message) << "Eigenvector base size   : " 
 | 
			
		||||
                 << MACOUT(HADRONS_DEFAULT_LANCZOS_NBASIS) << std::endl;
 | 
			
		||||
    LOG(Message) << "Schur decomposition     : " << MACOUTS(HADRONS_DEFAULT_SCHUR) << std::endl;
 | 
			
		||||
    LOG(Message) << std::endl;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Application::Application(const Application::GlobalPar &par)
 | 
			
		||||
: Application()
 | 
			
		||||
{
 | 
			
		||||
    setPar(par);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Application::Application(const std::string parameterFileName)
 | 
			
		||||
: Application()
 | 
			
		||||
{
 | 
			
		||||
    parameterFileName_ = parameterFileName;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// access //////////////////////////////////////////////////////////////////////
 | 
			
		||||
void Application::setPar(const Application::GlobalPar &par)
 | 
			
		||||
{
 | 
			
		||||
    par_ = par;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const Application::GlobalPar & Application::getPar(void)
 | 
			
		||||
{
 | 
			
		||||
    return par_;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// execute /////////////////////////////////////////////////////////////////////
 | 
			
		||||
void Application::run(void)
 | 
			
		||||
{
 | 
			
		||||
    LOG(Message) << "====== HADRONS APPLICATION START ======" << std::endl;
 | 
			
		||||
    if (!parameterFileName_.empty() and (vm().getNModule() == 0))
 | 
			
		||||
    {
 | 
			
		||||
        parseParameterFile(parameterFileName_);
 | 
			
		||||
    }
 | 
			
		||||
    if (getPar().runId.empty())
 | 
			
		||||
    {
 | 
			
		||||
        HADRONS_ERROR(Definition, "run id is empty");
 | 
			
		||||
    }
 | 
			
		||||
    LOG(Message) << "RUN ID '" << getPar().runId << "'" << std::endl;
 | 
			
		||||
    vm().setRunId(getPar().runId);
 | 
			
		||||
    vm().printContent();
 | 
			
		||||
    env().printContent();
 | 
			
		||||
    schedule();
 | 
			
		||||
    printSchedule();
 | 
			
		||||
    if (!getPar().graphFile.empty())
 | 
			
		||||
    {
 | 
			
		||||
        makeFileDir(getPar().graphFile, env().getGrid());
 | 
			
		||||
        vm().dumpModuleGraph(getPar().graphFile);
 | 
			
		||||
    }
 | 
			
		||||
    configLoop();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// parse parameter file ////////////////////////////////////////////////////////
 | 
			
		||||
class ObjectId: Serializable
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    GRID_SERIALIZABLE_CLASS_MEMBERS(ObjectId,
 | 
			
		||||
                                    std::string, name,
 | 
			
		||||
                                    std::string, type);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
void Application::parseParameterFile(const std::string parameterFileName)
 | 
			
		||||
{
 | 
			
		||||
    XmlReader reader(parameterFileName);
 | 
			
		||||
    GlobalPar par;
 | 
			
		||||
    ObjectId  id;
 | 
			
		||||
    
 | 
			
		||||
    LOG(Message) << "Building application from '" << parameterFileName << "'..." << std::endl;
 | 
			
		||||
    read(reader, "parameters", par);
 | 
			
		||||
    setPar(par);
 | 
			
		||||
    if (!push(reader, "modules"))
 | 
			
		||||
    {
 | 
			
		||||
        HADRONS_ERROR(Parsing, "Cannot open node 'modules' in parameter file '" 
 | 
			
		||||
                              + parameterFileName + "'");
 | 
			
		||||
    }
 | 
			
		||||
    if (!push(reader, "module"))
 | 
			
		||||
    {
 | 
			
		||||
        HADRONS_ERROR(Parsing, "Cannot open node 'modules/module' in parameter file '" 
 | 
			
		||||
                              + parameterFileName + "'");
 | 
			
		||||
    }
 | 
			
		||||
    do
 | 
			
		||||
    {
 | 
			
		||||
        read(reader, "id", id);
 | 
			
		||||
        vm().createModule(id.name, id.type, reader);
 | 
			
		||||
    } while (reader.nextElement("module"));
 | 
			
		||||
    pop(reader);
 | 
			
		||||
    pop(reader);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Application::saveParameterFile(const std::string parameterFileName)
 | 
			
		||||
{
 | 
			
		||||
    LOG(Message) << "Saving application to '" << parameterFileName << "'..." << std::endl;
 | 
			
		||||
    if (env().getGrid()->IsBoss())
 | 
			
		||||
    {
 | 
			
		||||
        XmlWriter          writer(parameterFileName);
 | 
			
		||||
        ObjectId           id;
 | 
			
		||||
        const unsigned int nMod = vm().getNModule();
 | 
			
		||||
 | 
			
		||||
        write(writer, "parameters", getPar());
 | 
			
		||||
        push(writer, "modules");
 | 
			
		||||
        for (unsigned int i = 0; i < nMod; ++i)
 | 
			
		||||
        {
 | 
			
		||||
            push(writer, "module");
 | 
			
		||||
            id.name = vm().getModuleName(i);
 | 
			
		||||
            id.type = vm().getModule(i)->getRegisteredName();
 | 
			
		||||
            write(writer, "id", id);
 | 
			
		||||
            vm().getModule(i)->saveParameters(writer, "options");
 | 
			
		||||
            pop(writer);
 | 
			
		||||
        }
 | 
			
		||||
        pop(writer);
 | 
			
		||||
        pop(writer);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// schedule computation ////////////////////////////////////////////////////////
 | 
			
		||||
void Application::schedule(void)
 | 
			
		||||
{
 | 
			
		||||
    if (!scheduled_ and !loadedSchedule_)
 | 
			
		||||
    {
 | 
			
		||||
        program_   = vm().schedule(par_.genetic);
 | 
			
		||||
        scheduled_ = true;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Application::saveSchedule(const std::string filename)
 | 
			
		||||
{
 | 
			
		||||
    LOG(Message) << "Saving current schedule to '" << filename << "'..."
 | 
			
		||||
                 << std::endl;
 | 
			
		||||
    if (env().getGrid()->IsBoss())
 | 
			
		||||
    {
 | 
			
		||||
        TextWriter               writer(filename);
 | 
			
		||||
        std::vector<std::string> program;
 | 
			
		||||
        
 | 
			
		||||
        if (!scheduled_)
 | 
			
		||||
        {
 | 
			
		||||
            HADRONS_ERROR(Definition, "Computation not scheduled");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        for (auto address: program_)
 | 
			
		||||
        {
 | 
			
		||||
            program.push_back(vm().getModuleName(address));
 | 
			
		||||
        }
 | 
			
		||||
        write(writer, "schedule", program);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Application::loadSchedule(const std::string filename)
 | 
			
		||||
{
 | 
			
		||||
    TextReader               reader(filename);
 | 
			
		||||
    std::vector<std::string> program;
 | 
			
		||||
    
 | 
			
		||||
    LOG(Message) << "Loading schedule from '" << filename << "'..."
 | 
			
		||||
                 << std::endl;
 | 
			
		||||
    read(reader, "schedule", program);
 | 
			
		||||
    program_.clear();
 | 
			
		||||
    for (auto &name: program)
 | 
			
		||||
    {
 | 
			
		||||
        program_.push_back(vm().getModuleAddress(name));
 | 
			
		||||
    }
 | 
			
		||||
    loadedSchedule_ = true;
 | 
			
		||||
    scheduled_      = true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Application::printSchedule(void)
 | 
			
		||||
{
 | 
			
		||||
    if (!scheduled_ and !loadedSchedule_)
 | 
			
		||||
    {
 | 
			
		||||
        HADRONS_ERROR(Definition, "Computation not scheduled");
 | 
			
		||||
    }
 | 
			
		||||
    auto peak = vm().memoryNeeded(program_);
 | 
			
		||||
    LOG(Message) << "Schedule (memory needed: " << sizeString(peak) << "):"
 | 
			
		||||
                 << std::endl;
 | 
			
		||||
    for (unsigned int i = 0; i < program_.size(); ++i)
 | 
			
		||||
    {
 | 
			
		||||
        LOG(Message) << std::setw(4) << i + 1 << ": "
 | 
			
		||||
                     << vm().getModuleName(program_[i]) << std::endl;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// loop on configurations //////////////////////////////////////////////////////
 | 
			
		||||
void Application::configLoop(void)
 | 
			
		||||
{
 | 
			
		||||
    auto range = par_.trajCounter;
 | 
			
		||||
    
 | 
			
		||||
    for (unsigned int t = range.start; t < range.end; t += range.step)
 | 
			
		||||
    {
 | 
			
		||||
        LOG(Message) << BIG_SEP << " Starting measurement for trajectory " << t
 | 
			
		||||
                     << " " << BIG_SEP << std::endl;
 | 
			
		||||
        vm().setTrajectory(t);
 | 
			
		||||
        vm().executeProgram(program_);
 | 
			
		||||
    }
 | 
			
		||||
    LOG(Message) << BIG_SEP << " End of measurement " << BIG_SEP << std::endl;
 | 
			
		||||
    env().freeAll();
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										122
									
								
								Hadrons/Application.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										122
									
								
								Hadrons/Application.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,122 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Application.hpp
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
 | 
			
		||||
#ifndef Hadrons_Application_hpp_
 | 
			
		||||
#define Hadrons_Application_hpp_
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Global.hpp>
 | 
			
		||||
#include <Hadrons/VirtualMachine.hpp>
 | 
			
		||||
#include <Hadrons/Module.hpp>
 | 
			
		||||
 | 
			
		||||
BEGIN_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                         Main program manager                               *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
class Application
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    class TrajRange: Serializable
 | 
			
		||||
    {
 | 
			
		||||
    public:
 | 
			
		||||
        GRID_SERIALIZABLE_CLASS_MEMBERS(TrajRange,
 | 
			
		||||
                                        unsigned int, start,
 | 
			
		||||
                                        unsigned int, end,
 | 
			
		||||
                                        unsigned int, step);
 | 
			
		||||
    };
 | 
			
		||||
    class GlobalPar: Serializable
 | 
			
		||||
    {
 | 
			
		||||
    public:
 | 
			
		||||
        GRID_SERIALIZABLE_CLASS_MEMBERS(GlobalPar,
 | 
			
		||||
                                        TrajRange,                  trajCounter,
 | 
			
		||||
                                        VirtualMachine::GeneticPar, genetic,
 | 
			
		||||
                                        std::string,                runId,
 | 
			
		||||
                                        std::string,                graphFile);
 | 
			
		||||
    };
 | 
			
		||||
public:
 | 
			
		||||
    // constructors
 | 
			
		||||
    Application(void);
 | 
			
		||||
    Application(const GlobalPar &par);
 | 
			
		||||
    Application(const std::string parameterFileName);
 | 
			
		||||
    // destructor
 | 
			
		||||
    virtual ~Application(void) = default;
 | 
			
		||||
    // access
 | 
			
		||||
    void              setPar(const GlobalPar &par);
 | 
			
		||||
    const GlobalPar & getPar(void);
 | 
			
		||||
    // module creation
 | 
			
		||||
    template <typename M>
 | 
			
		||||
    void createModule(const std::string name);
 | 
			
		||||
    template <typename M>
 | 
			
		||||
    void createModule(const std::string name, const typename M::Par &par);
 | 
			
		||||
    // execute
 | 
			
		||||
    void run(void);
 | 
			
		||||
    // XML parameter file I/O
 | 
			
		||||
    void parseParameterFile(const std::string parameterFileName);
 | 
			
		||||
    void saveParameterFile(const std::string parameterFileName);
 | 
			
		||||
    // schedule computation
 | 
			
		||||
    void schedule(void);
 | 
			
		||||
    void saveSchedule(const std::string filename);
 | 
			
		||||
    void loadSchedule(const std::string filename);
 | 
			
		||||
    void printSchedule(void);
 | 
			
		||||
    // loop on configurations
 | 
			
		||||
    void configLoop(void);
 | 
			
		||||
private:
 | 
			
		||||
    // environment shortcut
 | 
			
		||||
    DEFINE_ENV_ALIAS;
 | 
			
		||||
    // virtual machine shortcut
 | 
			
		||||
    DEFINE_VM_ALIAS;
 | 
			
		||||
private:
 | 
			
		||||
    long unsigned int       locVol_;
 | 
			
		||||
    std::string             parameterFileName_{""};
 | 
			
		||||
    GlobalPar               par_;
 | 
			
		||||
    VirtualMachine::Program program_;
 | 
			
		||||
    bool                    scheduled_{false}, loadedSchedule_{false};
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                     Application template implementation                    *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
// module creation /////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename M>
 | 
			
		||||
void Application::createModule(const std::string name)
 | 
			
		||||
{
 | 
			
		||||
    vm().createModule<M>(name);
 | 
			
		||||
    scheduled_ = false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename M>
 | 
			
		||||
void Application::createModule(const std::string name,
 | 
			
		||||
                               const typename M::Par &par)
 | 
			
		||||
{
 | 
			
		||||
    vm().createModule<M>(name, par);
 | 
			
		||||
    scheduled_ = false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
END_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
#endif // Hadrons_Application_hpp_
 | 
			
		||||
							
								
								
									
										191
									
								
								Hadrons/DilutedNoise.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										191
									
								
								Hadrons/DilutedNoise.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,191 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/DilutedNoise.hpp
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
#ifndef Hadrons_DilutedNoise_hpp_
 | 
			
		||||
#define Hadrons_DilutedNoise_hpp_
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Global.hpp>
 | 
			
		||||
 | 
			
		||||
BEGIN_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                   Abstract container for diluted noise                     *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
class DilutedNoise
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    typedef typename FImpl::FermionField FermionField;
 | 
			
		||||
public:
 | 
			
		||||
    // constructor/destructor
 | 
			
		||||
    DilutedNoise(GridCartesian *g);
 | 
			
		||||
    DilutedNoise(GridCartesian *g, const unsigned int nNoise);
 | 
			
		||||
    virtual ~DilutedNoise(void) = default;
 | 
			
		||||
    // access
 | 
			
		||||
    std::vector<FermionField> &       getNoise(void);
 | 
			
		||||
    const std::vector<FermionField> & getNoise(void) const;
 | 
			
		||||
    const FermionField &              operator[](const unsigned int i) const;
 | 
			
		||||
    FermionField &                    operator[](const unsigned int i);
 | 
			
		||||
    void                              resize(const unsigned int nNoise);
 | 
			
		||||
    unsigned int                      size(void) const;
 | 
			
		||||
    GridCartesian                     *getGrid(void) const;
 | 
			
		||||
    // generate noise (pure virtual)
 | 
			
		||||
    virtual void generateNoise(GridParallelRNG &rng) = 0;
 | 
			
		||||
private:
 | 
			
		||||
    std::vector<FermionField> noise_;
 | 
			
		||||
    GridCartesian             *grid_;
 | 
			
		||||
    unsigned int              nNoise_;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
class TimeDilutedSpinColorDiagonalNoise: public DilutedNoise<FImpl>
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    typedef typename FImpl::FermionField FermionField;
 | 
			
		||||
public:
 | 
			
		||||
    // constructor/destructor
 | 
			
		||||
    TimeDilutedSpinColorDiagonalNoise(GridCartesian *g);
 | 
			
		||||
    virtual ~TimeDilutedSpinColorDiagonalNoise(void) = default;
 | 
			
		||||
    // generate noise
 | 
			
		||||
    virtual void generateNoise(GridParallelRNG &rng);
 | 
			
		||||
private:
 | 
			
		||||
    unsigned int nt_;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                    DilutedNoise template implementation                    *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
DilutedNoise<FImpl>::DilutedNoise(GridCartesian *g)
 | 
			
		||||
: grid_(g)
 | 
			
		||||
{}
 | 
			
		||||
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
DilutedNoise<FImpl>::DilutedNoise(GridCartesian *g,
 | 
			
		||||
                                  const unsigned int nNoise)
 | 
			
		||||
: DilutedNoise(g)
 | 
			
		||||
{
 | 
			
		||||
    resize(nNoise);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
std::vector<typename DilutedNoise<FImpl>::FermionField> & DilutedNoise<FImpl>::
 | 
			
		||||
getNoise(void)
 | 
			
		||||
{
 | 
			
		||||
    return noise_;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
const std::vector<typename DilutedNoise<FImpl>::FermionField> & DilutedNoise<FImpl>::
 | 
			
		||||
getNoise(void) const
 | 
			
		||||
{
 | 
			
		||||
    return noise_;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
const typename DilutedNoise<FImpl>::FermionField & 
 | 
			
		||||
DilutedNoise<FImpl>::operator[](const unsigned int i) const
 | 
			
		||||
{
 | 
			
		||||
    return noise_[i];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
typename DilutedNoise<FImpl>::FermionField & 
 | 
			
		||||
DilutedNoise<FImpl>::operator[](const unsigned int i)
 | 
			
		||||
{
 | 
			
		||||
    return noise_[i];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
void DilutedNoise<FImpl>::resize(const unsigned int nNoise)
 | 
			
		||||
{
 | 
			
		||||
    nNoise_ = nNoise;
 | 
			
		||||
    noise_.resize(nNoise, grid_);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
unsigned int DilutedNoise<FImpl>::size(void) const
 | 
			
		||||
{  
 | 
			
		||||
    return noise_.size();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
GridCartesian * DilutedNoise<FImpl>::getGrid(void) const
 | 
			
		||||
{
 | 
			
		||||
    return grid_;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *        TimeDilutedSpinColorDiagonalNoise template implementation           *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
TimeDilutedSpinColorDiagonalNoise<FImpl>::
 | 
			
		||||
TimeDilutedSpinColorDiagonalNoise(GridCartesian *g)
 | 
			
		||||
: DilutedNoise<FImpl>(g)
 | 
			
		||||
{
 | 
			
		||||
    nt_ = this->getGrid()->GlobalDimensions().back();
 | 
			
		||||
    this->resize(nt_*Ns*FImpl::Dimension);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
void TimeDilutedSpinColorDiagonalNoise<FImpl>::generateNoise(GridParallelRNG &rng)
 | 
			
		||||
{
 | 
			
		||||
    typedef decltype(peekColour((*this)[0], 0)) SpinField;
 | 
			
		||||
 | 
			
		||||
    auto                       &noise = *this;
 | 
			
		||||
    auto                       g      = this->getGrid();
 | 
			
		||||
    auto                       nd     = g->GlobalDimensions().size();
 | 
			
		||||
    auto                       nc     = FImpl::Dimension;
 | 
			
		||||
    Complex                    shift(1., 1.);
 | 
			
		||||
    Lattice<iScalar<vInteger>> tLat(g);
 | 
			
		||||
    LatticeComplex             eta(g), etaCut(g);
 | 
			
		||||
    SpinField                  etas(g);
 | 
			
		||||
    unsigned int               i = 0;
 | 
			
		||||
 | 
			
		||||
    LatticeCoordinate(tLat, nd - 1);
 | 
			
		||||
    bernoulli(rng, eta);
 | 
			
		||||
    eta = (2.*eta - shift)*(1./::sqrt(2.));
 | 
			
		||||
    for (unsigned int t = 0; t < nt_; ++t)
 | 
			
		||||
    {
 | 
			
		||||
        etaCut = where((tLat == t), eta, 0.*eta);
 | 
			
		||||
        for (unsigned int s = 0; s < Ns; ++s)
 | 
			
		||||
        {
 | 
			
		||||
            etas = zero;
 | 
			
		||||
            pokeSpin(etas, etaCut, s);
 | 
			
		||||
            for (unsigned int c = 0; c < nc; ++c)
 | 
			
		||||
            {
 | 
			
		||||
                noise[i] = zero;
 | 
			
		||||
                pokeColour(noise[i], etas, c);
 | 
			
		||||
                i++;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
END_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
#endif // Hadrons_DilutedNoise_hpp_
 | 
			
		||||
							
								
								
									
										323
									
								
								Hadrons/EigenPack.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										323
									
								
								Hadrons/EigenPack.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,323 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/EigenPack.hpp
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
#ifndef Hadrons_EigenPack_hpp_
 | 
			
		||||
#define Hadrons_EigenPack_hpp_
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Global.hpp>
 | 
			
		||||
#include <Grid/algorithms/iterative/Deflation.h>
 | 
			
		||||
#include <Grid/algorithms/iterative/LocalCoherenceLanczos.h>
 | 
			
		||||
 | 
			
		||||
BEGIN_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
// Lanczos type
 | 
			
		||||
#ifndef HADRONS_DEFAULT_LANCZOS_NBASIS
 | 
			
		||||
#define HADRONS_DEFAULT_LANCZOS_NBASIS 60
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
template <typename F>
 | 
			
		||||
class EigenPack
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    typedef F Field;
 | 
			
		||||
    struct PackRecord
 | 
			
		||||
    {
 | 
			
		||||
        std::string operatorXml, solverXml;
 | 
			
		||||
    };
 | 
			
		||||
    struct VecRecord: Serializable
 | 
			
		||||
    {
 | 
			
		||||
        GRID_SERIALIZABLE_CLASS_MEMBERS(VecRecord,
 | 
			
		||||
                                        unsigned int, index,
 | 
			
		||||
                                        double,       eval);
 | 
			
		||||
        VecRecord(void): index(0), eval(0.) {}
 | 
			
		||||
    };
 | 
			
		||||
public:
 | 
			
		||||
    std::vector<Real> eval;
 | 
			
		||||
    std::vector<F>     evec;
 | 
			
		||||
    PackRecord         record;
 | 
			
		||||
public:
 | 
			
		||||
    EigenPack(void)          = default;
 | 
			
		||||
    virtual ~EigenPack(void) = default;
 | 
			
		||||
 | 
			
		||||
    EigenPack(const size_t size, GridBase *grid)
 | 
			
		||||
    {
 | 
			
		||||
        resize(size, grid);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void resize(const size_t size, GridBase *grid)
 | 
			
		||||
    {
 | 
			
		||||
        eval.resize(size);
 | 
			
		||||
        evec.resize(size, grid);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    virtual void read(const std::string fileStem, const bool multiFile, const int traj = -1)
 | 
			
		||||
    {
 | 
			
		||||
        if (multiFile)
 | 
			
		||||
        {
 | 
			
		||||
            for(int k = 0; k < evec.size(); ++k)
 | 
			
		||||
            {
 | 
			
		||||
                basicReadSingle(evec[k], eval[k], evecFilename(fileStem, k, traj), k);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            basicRead(evec, eval, evecFilename(fileStem, -1, traj), evec.size());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    virtual void write(const std::string fileStem, const bool multiFile, const int traj = -1)
 | 
			
		||||
    {
 | 
			
		||||
        if (multiFile)
 | 
			
		||||
        {
 | 
			
		||||
            for(int k = 0; k < evec.size(); ++k)
 | 
			
		||||
            {
 | 
			
		||||
                basicWriteSingle(evecFilename(fileStem, k, traj), evec[k], eval[k], k);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            basicWrite(evecFilename(fileStem, -1, traj), evec, eval, evec.size());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
protected:
 | 
			
		||||
    std::string evecFilename(const std::string stem, const int vec, const int traj)
 | 
			
		||||
    {
 | 
			
		||||
        std::string t = (traj < 0) ? "" : ("." + std::to_string(traj));
 | 
			
		||||
 | 
			
		||||
        if (vec == -1)
 | 
			
		||||
        {
 | 
			
		||||
            return stem + t + ".bin";
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            return stem + t + "/v" + std::to_string(vec) + ".bin";
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    template <typename T>
 | 
			
		||||
    void basicRead(std::vector<T> &evec, std::vector<double> &eval,
 | 
			
		||||
                   const std::string filename, const unsigned int size)
 | 
			
		||||
    {
 | 
			
		||||
        ScidacReader    binReader;
 | 
			
		||||
 | 
			
		||||
        binReader.open(filename);
 | 
			
		||||
        binReader.skipPastObjectRecord(SCIDAC_FILE_XML);
 | 
			
		||||
        for(int k = 0; k < size; ++k) 
 | 
			
		||||
        {
 | 
			
		||||
            VecRecord vecRecord;
 | 
			
		||||
 | 
			
		||||
            LOG(Message) << "Reading eigenvector " << k << std::endl;
 | 
			
		||||
            binReader.readScidacFieldRecord(evec[k], vecRecord);
 | 
			
		||||
            if (vecRecord.index != k)
 | 
			
		||||
            {
 | 
			
		||||
                HADRONS_ERROR(Io, "Eigenvector " + std::to_string(k) + " has a"
 | 
			
		||||
                              + " wrong index (expected " + std::to_string(vecRecord.index) 
 | 
			
		||||
                              + ") in file '" + filename + "'");
 | 
			
		||||
            }
 | 
			
		||||
            eval[k] = vecRecord.eval;
 | 
			
		||||
        }
 | 
			
		||||
        binReader.close();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    template <typename T>
 | 
			
		||||
    void basicReadSingle(T &evec, double &eval, const std::string filename, 
 | 
			
		||||
                         const unsigned int index)
 | 
			
		||||
    {
 | 
			
		||||
        ScidacReader binReader;
 | 
			
		||||
        VecRecord    vecRecord;
 | 
			
		||||
 | 
			
		||||
        binReader.open(filename);
 | 
			
		||||
        binReader.skipPastObjectRecord(SCIDAC_FILE_XML);
 | 
			
		||||
        LOG(Message) << "Reading eigenvector " << index << std::endl;
 | 
			
		||||
        binReader.readScidacFieldRecord(evec, vecRecord);
 | 
			
		||||
        if (vecRecord.index != index)
 | 
			
		||||
        {
 | 
			
		||||
            HADRONS_ERROR(Io, "Eigenvector " + std::to_string(index) + " has a"
 | 
			
		||||
                          + " wrong index (expected " + std::to_string(vecRecord.index) 
 | 
			
		||||
                          + ") in file '" + filename + "'");
 | 
			
		||||
        }
 | 
			
		||||
        eval = vecRecord.eval;
 | 
			
		||||
        binReader.close();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    template <typename T>
 | 
			
		||||
    void basicWrite(const std::string filename, std::vector<T> &evec, 
 | 
			
		||||
                    const std::vector<double> &eval, const unsigned int size)
 | 
			
		||||
    {
 | 
			
		||||
        ScidacWriter binWriter(evec[0]._grid->IsBoss());
 | 
			
		||||
        XmlWriter    xmlWriter("", "eigenPackPar");
 | 
			
		||||
 | 
			
		||||
        makeFileDir(filename, evec[0]._grid);
 | 
			
		||||
        xmlWriter.pushXmlString(record.operatorXml);
 | 
			
		||||
        xmlWriter.pushXmlString(record.solverXml);
 | 
			
		||||
        binWriter.open(filename);
 | 
			
		||||
        binWriter.writeLimeObject(1, 1, xmlWriter, "parameters", SCIDAC_FILE_XML);
 | 
			
		||||
        for(int k = 0; k < size; ++k) 
 | 
			
		||||
        {
 | 
			
		||||
            VecRecord vecRecord;
 | 
			
		||||
 | 
			
		||||
            vecRecord.index = k;
 | 
			
		||||
            vecRecord.eval  = eval[k];
 | 
			
		||||
            LOG(Message) << "Writing eigenvector " << k << std::endl;
 | 
			
		||||
            binWriter.writeScidacFieldRecord(evec[k], vecRecord, DEFAULT_ASCII_PREC);
 | 
			
		||||
        }
 | 
			
		||||
        binWriter.close();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    template <typename T>
 | 
			
		||||
    void basicWriteSingle(const std::string filename, T &evec, 
 | 
			
		||||
                          const double eval, const unsigned int index)
 | 
			
		||||
    {
 | 
			
		||||
        ScidacWriter binWriter(evec._grid->IsBoss());
 | 
			
		||||
        XmlWriter    xmlWriter("", "eigenPackPar");
 | 
			
		||||
        VecRecord    vecRecord;
 | 
			
		||||
 | 
			
		||||
        makeFileDir(filename, evec._grid);
 | 
			
		||||
        xmlWriter.pushXmlString(record.operatorXml);
 | 
			
		||||
        xmlWriter.pushXmlString(record.solverXml);
 | 
			
		||||
        binWriter.open(filename);
 | 
			
		||||
        binWriter.writeLimeObject(1, 1, xmlWriter, "parameters", SCIDAC_FILE_XML);
 | 
			
		||||
        vecRecord.index = index;
 | 
			
		||||
        vecRecord.eval  = eval;
 | 
			
		||||
        LOG(Message) << "Writing eigenvector " << index << std::endl;
 | 
			
		||||
        binWriter.writeScidacFieldRecord(evec, vecRecord, DEFAULT_ASCII_PREC);
 | 
			
		||||
        binWriter.close();
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
template <typename FineF, typename CoarseF>
 | 
			
		||||
class CoarseEigenPack: public EigenPack<FineF>
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    typedef CoarseF CoarseField;
 | 
			
		||||
public:
 | 
			
		||||
    std::vector<Real>   evalCoarse;
 | 
			
		||||
    std::vector<CoarseF> evecCoarse;
 | 
			
		||||
public:
 | 
			
		||||
    CoarseEigenPack(void)          = default;
 | 
			
		||||
    virtual ~CoarseEigenPack(void) = default;
 | 
			
		||||
 | 
			
		||||
    CoarseEigenPack(const size_t sizeFine, const size_t sizeCoarse, 
 | 
			
		||||
                    GridBase *gridFine, GridBase *gridCoarse)
 | 
			
		||||
    {
 | 
			
		||||
        resize(sizeFine, sizeCoarse, gridFine, gridCoarse);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void resize(const size_t sizeFine, const size_t sizeCoarse, 
 | 
			
		||||
                GridBase *gridFine, GridBase *gridCoarse)
 | 
			
		||||
    {
 | 
			
		||||
        EigenPack<FineF>::resize(sizeFine, gridFine);
 | 
			
		||||
        evalCoarse.resize(sizeCoarse);
 | 
			
		||||
        evecCoarse.resize(sizeCoarse, gridCoarse);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void readFine(const std::string fileStem, const bool multiFile, const int traj = -1)
 | 
			
		||||
    {
 | 
			
		||||
        if (multiFile)
 | 
			
		||||
        {
 | 
			
		||||
            for(int k = 0; k < this->evec.size(); ++k)
 | 
			
		||||
            {
 | 
			
		||||
                this->basicReadSingle(this->evec[k], this->eval[k], this->evecFilename(fileStem + "_fine", k, traj), k);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            this->basicRead(this->evec, this->eval, this->evecFilename(fileStem + "_fine", -1, traj), this->evec.size());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void readCoarse(const std::string fileStem, const bool multiFile, const int traj = -1)
 | 
			
		||||
    {
 | 
			
		||||
        if (multiFile)
 | 
			
		||||
        {
 | 
			
		||||
            for(int k = 0; k < evecCoarse.size(); ++k)
 | 
			
		||||
            {
 | 
			
		||||
                this->basicReadSingle(evecCoarse[k], evalCoarse[k], this->evecFilename(fileStem + "_coarse", k, traj), k);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            this->basicRead(evecCoarse, evalCoarse, this->evecFilename(fileStem + "_coarse", -1, traj), evecCoarse.size());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    virtual void read(const std::string fileStem, const bool multiFile, const int traj = -1)
 | 
			
		||||
    {
 | 
			
		||||
        readFine(fileStem, multiFile, traj);
 | 
			
		||||
        readCoarse(fileStem, multiFile, traj);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void writeFine(const std::string fileStem, const bool multiFile, const int traj = -1)
 | 
			
		||||
    {
 | 
			
		||||
        if (multiFile)
 | 
			
		||||
        {
 | 
			
		||||
            for(int k = 0; k < this->evec.size(); ++k)
 | 
			
		||||
            {
 | 
			
		||||
                this->basicWriteSingle(this->evecFilename(fileStem + "_fine", k, traj), this->evec[k], this->eval[k], k);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            this->basicWrite(this->evecFilename(fileStem + "_fine", -1, traj), this->evec, this->eval, this->evec.size());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void writeCoarse(const std::string fileStem, const bool multiFile, const int traj = -1)
 | 
			
		||||
    {
 | 
			
		||||
        if (multiFile)
 | 
			
		||||
        {
 | 
			
		||||
            for(int k = 0; k < evecCoarse.size(); ++k)
 | 
			
		||||
            {
 | 
			
		||||
                this->basicWriteSingle(this->evecFilename(fileStem + "_coarse", k, traj), evecCoarse[k], evalCoarse[k], k);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            this->basicWrite(this->evecFilename(fileStem + "_coarse", -1, traj), evecCoarse, evalCoarse, evecCoarse.size());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    virtual void write(const std::string fileStem, const bool multiFile, const int traj = -1)
 | 
			
		||||
    {
 | 
			
		||||
        writeFine(fileStem, multiFile, traj);
 | 
			
		||||
        writeCoarse(fileStem, multiFile, traj);
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
using FermionEigenPack = EigenPack<typename FImpl::FermionField>;
 | 
			
		||||
 | 
			
		||||
template <typename FImpl, int nBasis>
 | 
			
		||||
using CoarseFermionEigenPack = CoarseEigenPack<
 | 
			
		||||
    typename FImpl::FermionField,
 | 
			
		||||
    typename LocalCoherenceLanczos<typename FImpl::SiteSpinor, 
 | 
			
		||||
                                   typename FImpl::SiteComplex, 
 | 
			
		||||
                                   nBasis>::CoarseField>;
 | 
			
		||||
 | 
			
		||||
END_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
#endif // Hadrons_EigenPack_hpp_
 | 
			
		||||
							
								
								
									
										453
									
								
								Hadrons/Environment.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										453
									
								
								Hadrons/Environment.cc
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,453 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Environment.cc
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Environment.hpp>
 | 
			
		||||
#include <Hadrons/Module.hpp>
 | 
			
		||||
#include <Hadrons/ModuleFactory.hpp>
 | 
			
		||||
 | 
			
		||||
using namespace Grid;
 | 
			
		||||
using namespace QCD;
 | 
			
		||||
using namespace Hadrons;
 | 
			
		||||
 | 
			
		||||
#define ERROR_NO_ADDRESS(address)\
 | 
			
		||||
HADRONS_ERROR_REF(ObjectDefinition, "no object with address " + std::to_string(address), address);
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                       Environment implementation                           *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
// constructor /////////////////////////////////////////////////////////////////
 | 
			
		||||
Environment::Environment(void)
 | 
			
		||||
{
 | 
			
		||||
    dim_ = GridDefaultLatt();
 | 
			
		||||
    nd_  = dim_.size();
 | 
			
		||||
    grid4d_.reset(SpaceTimeGrid::makeFourDimGrid(
 | 
			
		||||
        dim_, GridDefaultSimd(nd_, vComplex::Nsimd()),
 | 
			
		||||
        GridDefaultMpi()));
 | 
			
		||||
    gridRb4d_.reset(SpaceTimeGrid::makeFourDimRedBlackGrid(grid4d_.get()));
 | 
			
		||||
    vol_ = 1.;
 | 
			
		||||
    for (auto d: dim_)
 | 
			
		||||
    {
 | 
			
		||||
        vol_ *= d;
 | 
			
		||||
    }
 | 
			
		||||
    rng4d_.reset(new GridParallelRNG(grid4d_.get()));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// grids ///////////////////////////////////////////////////////////////////////
 | 
			
		||||
void Environment::createGrid(const unsigned int Ls)
 | 
			
		||||
{
 | 
			
		||||
    if ((Ls > 1) and (grid5d_.find(Ls) == grid5d_.end()))
 | 
			
		||||
    {
 | 
			
		||||
        auto g = getGrid();
 | 
			
		||||
        
 | 
			
		||||
        grid5d_[Ls].reset(SpaceTimeGrid::makeFiveDimGrid(Ls, g));
 | 
			
		||||
        gridRb5d_[Ls].reset(SpaceTimeGrid::makeFiveDimRedBlackGrid(Ls, g));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Environment::createCoarseGrid(const std::vector<int> &blockSize, 
 | 
			
		||||
                                   const unsigned int Ls)
 | 
			
		||||
{
 | 
			
		||||
    int              nd      = getNd();
 | 
			
		||||
    std::vector<int> fineDim = getDim(), coarseDim;
 | 
			
		||||
    unsigned int     cLs;
 | 
			
		||||
    auto             key4d = blockSize, key5d = blockSize;
 | 
			
		||||
 | 
			
		||||
    createGrid(Ls);
 | 
			
		||||
    coarseDim.resize(nd);
 | 
			
		||||
    for (int d = 0; d < coarseDim.size(); d++)
 | 
			
		||||
    {
 | 
			
		||||
        coarseDim[d] = fineDim[d]/blockSize[d];
 | 
			
		||||
        if (coarseDim[d]*blockSize[d] != fineDim[d])
 | 
			
		||||
        {
 | 
			
		||||
            HADRONS_ERROR(Size, "Fine dimension " + std::to_string(d) 
 | 
			
		||||
                         + " (" + std::to_string(fineDim[d]) 
 | 
			
		||||
                         + ") not divisible by coarse dimension ("
 | 
			
		||||
                         + std::to_string(coarseDim[d]) + ")"); 
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    if (blockSize.size() > nd)
 | 
			
		||||
    {
 | 
			
		||||
        cLs = Ls/blockSize[nd];
 | 
			
		||||
        if (cLs*blockSize[nd] != Ls)
 | 
			
		||||
        {
 | 
			
		||||
            HADRONS_ERROR(Size, "Fine Ls (" + std::to_string(Ls) 
 | 
			
		||||
                         + ") not divisible by coarse Ls ("
 | 
			
		||||
                         + std::to_string(cLs) + ")");
 | 
			
		||||
        }
 | 
			
		||||
        key4d.resize(nd);
 | 
			
		||||
        key5d.push_back(Ls);
 | 
			
		||||
    }
 | 
			
		||||
    gridCoarse4d_[key4d].reset(
 | 
			
		||||
        SpaceTimeGrid::makeFourDimGrid(coarseDim, 
 | 
			
		||||
            GridDefaultSimd(nd, vComplex::Nsimd()), GridDefaultMpi()));
 | 
			
		||||
    if (Ls > 1)
 | 
			
		||||
    {
 | 
			
		||||
        gridCoarse5d_[key5d].reset(
 | 
			
		||||
            SpaceTimeGrid::makeFiveDimGrid(cLs, gridCoarse4d_[key4d].get()));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
GridCartesian * Environment::getGrid(const unsigned int Ls) const
 | 
			
		||||
{
 | 
			
		||||
    try
 | 
			
		||||
    {
 | 
			
		||||
        if (Ls == 1)
 | 
			
		||||
        {
 | 
			
		||||
            return grid4d_.get();
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            return grid5d_.at(Ls).get();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    catch(std::out_of_range &)
 | 
			
		||||
    {
 | 
			
		||||
        HADRONS_ERROR(Definition, "no grid with Ls= " + std::to_string(Ls));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
GridRedBlackCartesian * Environment::getRbGrid(const unsigned int Ls) const
 | 
			
		||||
{
 | 
			
		||||
    try
 | 
			
		||||
    {
 | 
			
		||||
        if (Ls == 1)
 | 
			
		||||
        {
 | 
			
		||||
            return gridRb4d_.get();
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            return gridRb5d_.at(Ls).get();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    catch(std::out_of_range &)
 | 
			
		||||
    {
 | 
			
		||||
        HADRONS_ERROR(Definition, "no red-black grid with Ls= " + std::to_string(Ls));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
GridCartesian * Environment::getCoarseGrid(
 | 
			
		||||
    const std::vector<int> &blockSize, const unsigned int Ls) const
 | 
			
		||||
{
 | 
			
		||||
    auto key = blockSize;
 | 
			
		||||
 | 
			
		||||
    try
 | 
			
		||||
    {
 | 
			
		||||
        if (Ls == 1)
 | 
			
		||||
        {
 | 
			
		||||
            key.resize(getNd());
 | 
			
		||||
            return gridCoarse4d_.at(key).get();
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            key.push_back(Ls);
 | 
			
		||||
            return gridCoarse5d_.at(key).get();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    catch(std::out_of_range &)
 | 
			
		||||
    {
 | 
			
		||||
        HADRONS_ERROR(Definition, "no coarse grid with Ls= " + std::to_string(Ls));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
unsigned int Environment::getNd(void) const
 | 
			
		||||
{
 | 
			
		||||
    return nd_;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::vector<int> Environment::getDim(void) const
 | 
			
		||||
{
 | 
			
		||||
    return dim_;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int Environment::getDim(const unsigned int mu) const
 | 
			
		||||
{
 | 
			
		||||
    return dim_[mu];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
double Environment::getVolume(void) const
 | 
			
		||||
{
 | 
			
		||||
    return vol_;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// random number generator /////////////////////////////////////////////////////
 | 
			
		||||
GridParallelRNG * Environment::get4dRng(void) const
 | 
			
		||||
{
 | 
			
		||||
    return rng4d_.get();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// general memory management ///////////////////////////////////////////////////
 | 
			
		||||
void Environment::addObject(const std::string name, const int moduleAddress)
 | 
			
		||||
{
 | 
			
		||||
    if (!hasObject(name))
 | 
			
		||||
    {
 | 
			
		||||
        ObjInfo info;
 | 
			
		||||
        
 | 
			
		||||
        info.name   = name;
 | 
			
		||||
        info.module = moduleAddress;
 | 
			
		||||
        info.data   = nullptr;
 | 
			
		||||
        object_.push_back(std::move(info));
 | 
			
		||||
        objectAddress_[name] = static_cast<unsigned int>(object_.size() - 1);
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        HADRONS_ERROR_REF(ObjectDefinition, "object '" + name + "' already exists",
 | 
			
		||||
                          getObjectAddress(name));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Environment::setObjectModule(const unsigned int objAddress,
 | 
			
		||||
                                  const int modAddress)
 | 
			
		||||
{
 | 
			
		||||
    object_[objAddress].module = modAddress;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
unsigned int Environment::getMaxAddress(void) const
 | 
			
		||||
{
 | 
			
		||||
    return object_.size();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
unsigned int Environment::getObjectAddress(const std::string name) const
 | 
			
		||||
{
 | 
			
		||||
    if (hasObject(name))
 | 
			
		||||
    {
 | 
			
		||||
        return objectAddress_.at(name);
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        HADRONS_ERROR(Definition, "no object with name '" + name + "'");
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::string Environment::getObjectName(const unsigned int address) const
 | 
			
		||||
{
 | 
			
		||||
    if (hasObject(address))
 | 
			
		||||
    {
 | 
			
		||||
        return object_[address].name;
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        ERROR_NO_ADDRESS(address);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::string Environment::getObjectType(const unsigned int address) const
 | 
			
		||||
{
 | 
			
		||||
    if (hasObject(address))
 | 
			
		||||
    {
 | 
			
		||||
        if (object_[address].type)
 | 
			
		||||
        {
 | 
			
		||||
            return typeName(object_[address].type);
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            return "<no type>";
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        ERROR_NO_ADDRESS(address);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::string Environment::getObjectType(const std::string name) const
 | 
			
		||||
{
 | 
			
		||||
    return getObjectType(getObjectAddress(name));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Environment::Size Environment::getObjectSize(const unsigned int address) const
 | 
			
		||||
{
 | 
			
		||||
    if (hasObject(address))
 | 
			
		||||
    {
 | 
			
		||||
        return object_[address].size;
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        ERROR_NO_ADDRESS(address);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Environment::Size Environment::getObjectSize(const std::string name) const
 | 
			
		||||
{
 | 
			
		||||
    return getObjectSize(getObjectAddress(name));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Environment::Storage Environment::getObjectStorage(const unsigned int address) const
 | 
			
		||||
{
 | 
			
		||||
    if (hasObject(address))
 | 
			
		||||
    {
 | 
			
		||||
        return object_[address].storage;
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        ERROR_NO_ADDRESS(address);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Environment::Storage Environment::getObjectStorage(const std::string name) const
 | 
			
		||||
{
 | 
			
		||||
    return getObjectStorage(getObjectAddress(name));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int Environment::getObjectModule(const unsigned int address) const
 | 
			
		||||
{
 | 
			
		||||
    if (hasObject(address))
 | 
			
		||||
    {
 | 
			
		||||
        return object_[address].module;
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        ERROR_NO_ADDRESS(address);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int Environment::getObjectModule(const std::string name) const
 | 
			
		||||
{
 | 
			
		||||
    return getObjectModule(getObjectAddress(name));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
unsigned int Environment::getObjectLs(const unsigned int address) const
 | 
			
		||||
{
 | 
			
		||||
    if (hasCreatedObject(address))
 | 
			
		||||
    {
 | 
			
		||||
        return object_[address].Ls;
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        ERROR_NO_ADDRESS(address);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
unsigned int Environment::getObjectLs(const std::string name) const
 | 
			
		||||
{
 | 
			
		||||
    return getObjectLs(getObjectAddress(name));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool Environment::hasObject(const unsigned int address) const
 | 
			
		||||
{
 | 
			
		||||
    return (address < object_.size());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool Environment::hasObject(const std::string name) const
 | 
			
		||||
{
 | 
			
		||||
    auto it = objectAddress_.find(name);
 | 
			
		||||
    
 | 
			
		||||
    return ((it != objectAddress_.end()) and hasObject(it->second));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool Environment::hasCreatedObject(const unsigned int address) const
 | 
			
		||||
{
 | 
			
		||||
    if (hasObject(address))
 | 
			
		||||
    {
 | 
			
		||||
        return (object_[address].data != nullptr);
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool Environment::hasCreatedObject(const std::string name) const
 | 
			
		||||
{
 | 
			
		||||
    if (hasObject(name))
 | 
			
		||||
    {
 | 
			
		||||
        return hasCreatedObject(getObjectAddress(name));
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool Environment::isObject5d(const unsigned int address) const
 | 
			
		||||
{
 | 
			
		||||
    return (getObjectLs(address) > 1);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool Environment::isObject5d(const std::string name) const
 | 
			
		||||
{
 | 
			
		||||
    return (getObjectLs(name) > 1);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Environment::Size Environment::getTotalSize(void) const
 | 
			
		||||
{
 | 
			
		||||
    Environment::Size size = 0;
 | 
			
		||||
    
 | 
			
		||||
    for (auto &o: object_)
 | 
			
		||||
    {
 | 
			
		||||
        size += o.size;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    return size;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Environment::freeObject(const unsigned int address)
 | 
			
		||||
{
 | 
			
		||||
    if (hasCreatedObject(address))
 | 
			
		||||
    {
 | 
			
		||||
        LOG(Message) << "Destroying object '" << object_[address].name
 | 
			
		||||
                     << "'" << std::endl;
 | 
			
		||||
    }
 | 
			
		||||
    object_[address].size = 0;
 | 
			
		||||
    object_[address].type = nullptr;
 | 
			
		||||
    object_[address].data.reset(nullptr);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Environment::freeObject(const std::string name)
 | 
			
		||||
{
 | 
			
		||||
    freeObject(getObjectAddress(name));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Environment::freeAll(void)
 | 
			
		||||
{
 | 
			
		||||
    for (unsigned int i = 0; i < object_.size(); ++i)
 | 
			
		||||
    {
 | 
			
		||||
        freeObject(i);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Environment::protectObjects(const bool protect)
 | 
			
		||||
{
 | 
			
		||||
    protect_ = protect;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool Environment::objectsProtected(void) const
 | 
			
		||||
{
 | 
			
		||||
    return protect_;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// print environment content ///////////////////////////////////////////////////
 | 
			
		||||
void Environment::printContent(void) const
 | 
			
		||||
{
 | 
			
		||||
    LOG(Debug) << "Objects: " << std::endl;
 | 
			
		||||
    for (unsigned int i = 0; i < object_.size(); ++i)
 | 
			
		||||
    {
 | 
			
		||||
        LOG(Debug) << std::setw(4) << i << ": "
 | 
			
		||||
                   << getObjectName(i) << " ("
 | 
			
		||||
                   << sizeString(getObjectSize(i)) << ")" << std::endl;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										356
									
								
								Hadrons/Environment.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										356
									
								
								Hadrons/Environment.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,356 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Environment.hpp
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
 | 
			
		||||
#ifndef Hadrons_Environment_hpp_
 | 
			
		||||
#define Hadrons_Environment_hpp_
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Global.hpp>
 | 
			
		||||
 | 
			
		||||
BEGIN_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                         Global environment                                 *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
class Object
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    Object(void) = default;
 | 
			
		||||
    virtual ~Object(void) = default;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
template <typename T>
 | 
			
		||||
class Holder: public Object
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    Holder(void) = default;
 | 
			
		||||
    Holder(T *pt);
 | 
			
		||||
    virtual ~Holder(void) = default;
 | 
			
		||||
    T &       get(void) const;
 | 
			
		||||
    T *       getPt(void) const;
 | 
			
		||||
    void      reset(T *pt);
 | 
			
		||||
private:
 | 
			
		||||
    std::unique_ptr<T> objPt_{nullptr};
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#define DEFINE_ENV_ALIAS \
 | 
			
		||||
inline Environment & env(void) const\
 | 
			
		||||
{\
 | 
			
		||||
    return Environment::getInstance();\
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class Environment
 | 
			
		||||
{
 | 
			
		||||
    SINGLETON(Environment);
 | 
			
		||||
public:
 | 
			
		||||
    typedef SITE_SIZE_TYPE                         Size;
 | 
			
		||||
    typedef std::unique_ptr<GridCartesian>         GridPt;
 | 
			
		||||
    typedef std::unique_ptr<GridRedBlackCartesian> GridRbPt;
 | 
			
		||||
    typedef std::unique_ptr<GridParallelRNG>       RngPt;
 | 
			
		||||
    enum class Storage {object, cache, temporary};
 | 
			
		||||
private:
 | 
			
		||||
    struct ObjInfo
 | 
			
		||||
    {
 | 
			
		||||
        Size                    size{0};
 | 
			
		||||
        Storage                 storage{Storage::object};
 | 
			
		||||
        unsigned int            Ls{0};
 | 
			
		||||
        const std::type_info    *type{nullptr}, *derivedType{nullptr};
 | 
			
		||||
        std::string             name;
 | 
			
		||||
        int                     module{-1};
 | 
			
		||||
        std::unique_ptr<Object> data{nullptr};
 | 
			
		||||
    };
 | 
			
		||||
public:
 | 
			
		||||
    // grids
 | 
			
		||||
    void                    createGrid(const unsigned int Ls);
 | 
			
		||||
    void                    createCoarseGrid(const std::vector<int> &blockSize,
 | 
			
		||||
                                             const unsigned int Ls = 1);
 | 
			
		||||
    GridCartesian *         getGrid(const unsigned int Ls = 1) const;
 | 
			
		||||
    GridRedBlackCartesian * getRbGrid(const unsigned int Ls = 1) const;
 | 
			
		||||
    GridCartesian *         getCoarseGrid(const std::vector<int> &blockSize,
 | 
			
		||||
                                          const unsigned int Ls = 1) const;
 | 
			
		||||
    std::vector<int>        getDim(void) const;
 | 
			
		||||
    int                     getDim(const unsigned int mu) const;
 | 
			
		||||
    unsigned int            getNd(void) const;
 | 
			
		||||
    double                  getVolume(void) const;
 | 
			
		||||
    // random number generator
 | 
			
		||||
    GridParallelRNG *       get4dRng(void) const;
 | 
			
		||||
    // general memory management
 | 
			
		||||
    void                    addObject(const std::string name,
 | 
			
		||||
                                      const int moduleAddress = -1);
 | 
			
		||||
    template <typename B, typename T, typename ... Ts>
 | 
			
		||||
    void                    createDerivedObject(const std::string name,
 | 
			
		||||
                                                const Environment::Storage storage,
 | 
			
		||||
                                                const unsigned int Ls,
 | 
			
		||||
                                                Ts && ... args);
 | 
			
		||||
    template <typename T, typename ... Ts>
 | 
			
		||||
    void                    createObject(const std::string name,
 | 
			
		||||
                                         const Environment::Storage storage,
 | 
			
		||||
                                         const unsigned int Ls,
 | 
			
		||||
                                         Ts && ... args);
 | 
			
		||||
    void                    setObjectModule(const unsigned int objAddress,
 | 
			
		||||
                                            const int modAddress);
 | 
			
		||||
    template <typename B, typename T>
 | 
			
		||||
    T *                     getDerivedObject(const unsigned int address) const;
 | 
			
		||||
    template <typename B, typename T>
 | 
			
		||||
    T *                     getDerivedObject(const std::string name) const;
 | 
			
		||||
    template <typename T>
 | 
			
		||||
    T *                     getObject(const unsigned int address) const;
 | 
			
		||||
    template <typename T>
 | 
			
		||||
    T *                     getObject(const std::string name) const;
 | 
			
		||||
    unsigned int            getMaxAddress(void) const;
 | 
			
		||||
    unsigned int            getObjectAddress(const std::string name) const;
 | 
			
		||||
    std::string             getObjectName(const unsigned int address) const;
 | 
			
		||||
    std::string             getObjectType(const unsigned int address) const;
 | 
			
		||||
    std::string             getObjectType(const std::string name) const;
 | 
			
		||||
    Size                    getObjectSize(const unsigned int address) const;
 | 
			
		||||
    Size                    getObjectSize(const std::string name) const;
 | 
			
		||||
    Storage                 getObjectStorage(const unsigned int address) const;
 | 
			
		||||
    Storage                 getObjectStorage(const std::string name) const;
 | 
			
		||||
    int                     getObjectModule(const unsigned int address) const;
 | 
			
		||||
    int                     getObjectModule(const std::string name) const;
 | 
			
		||||
    unsigned int            getObjectLs(const unsigned int address) const;
 | 
			
		||||
    unsigned int            getObjectLs(const std::string name) const;
 | 
			
		||||
    bool                    hasObject(const unsigned int address) const;
 | 
			
		||||
    bool                    hasObject(const std::string name) const;
 | 
			
		||||
    bool                    hasCreatedObject(const unsigned int address) const;
 | 
			
		||||
    bool                    hasCreatedObject(const std::string name) const;
 | 
			
		||||
    bool                    isObject5d(const unsigned int address) const;
 | 
			
		||||
    bool                    isObject5d(const std::string name) const;
 | 
			
		||||
    template <typename T>
 | 
			
		||||
    bool                    isObjectOfType(const unsigned int address) const;
 | 
			
		||||
    template <typename T>
 | 
			
		||||
    bool                    isObjectOfType(const std::string name) const;
 | 
			
		||||
    Environment::Size       getTotalSize(void) const;
 | 
			
		||||
    void                    freeObject(const unsigned int address);
 | 
			
		||||
    void                    freeObject(const std::string name);
 | 
			
		||||
    void                    freeAll(void);
 | 
			
		||||
    void                    protectObjects(const bool protect);
 | 
			
		||||
    bool                    objectsProtected(void) const;
 | 
			
		||||
    // print environment content
 | 
			
		||||
    void                    printContent(void) const;
 | 
			
		||||
private:
 | 
			
		||||
    // general
 | 
			
		||||
    double                                 vol_;
 | 
			
		||||
    bool                                   protect_{true};
 | 
			
		||||
    // grids
 | 
			
		||||
    std::vector<int>                       dim_;
 | 
			
		||||
    GridPt                                 grid4d_;
 | 
			
		||||
    std::map<unsigned int, GridPt>         grid5d_;
 | 
			
		||||
    GridRbPt                               gridRb4d_;
 | 
			
		||||
    std::map<unsigned int, GridRbPt>       gridRb5d_;
 | 
			
		||||
    std::map<std::vector<int>, GridPt>     gridCoarse4d_;
 | 
			
		||||
    std::map<std::vector<int>, GridPt>     gridCoarse5d_;
 | 
			
		||||
    unsigned int                           nd_;
 | 
			
		||||
    // random number generator
 | 
			
		||||
    RngPt                                  rng4d_;
 | 
			
		||||
    // object store
 | 
			
		||||
    std::vector<ObjInfo>                   object_;
 | 
			
		||||
    std::map<std::string, unsigned int>    objectAddress_;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                       Holder template implementation                       *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
// constructor /////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename T>
 | 
			
		||||
Holder<T>::Holder(T *pt)
 | 
			
		||||
: objPt_(pt)
 | 
			
		||||
{}
 | 
			
		||||
 | 
			
		||||
// access //////////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename T>
 | 
			
		||||
T & Holder<T>::get(void) const
 | 
			
		||||
{
 | 
			
		||||
    return *objPt_.get();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename T>
 | 
			
		||||
T * Holder<T>::getPt(void) const
 | 
			
		||||
{
 | 
			
		||||
    return objPt_.get();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename T>
 | 
			
		||||
void Holder<T>::reset(T *pt)
 | 
			
		||||
{
 | 
			
		||||
    objPt_.reset(pt);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                     Environment template implementation                    *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
// general memory management ///////////////////////////////////////////////////
 | 
			
		||||
template <typename B, typename T, typename ... Ts>
 | 
			
		||||
void Environment::createDerivedObject(const std::string name,
 | 
			
		||||
                                      const Environment::Storage storage,
 | 
			
		||||
                                      const unsigned int Ls,
 | 
			
		||||
                                      Ts && ... args)
 | 
			
		||||
{
 | 
			
		||||
    if (!hasObject(name))
 | 
			
		||||
    {
 | 
			
		||||
        addObject(name);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    unsigned int address = getObjectAddress(name);
 | 
			
		||||
    
 | 
			
		||||
    if (!object_[address].data or !objectsProtected())
 | 
			
		||||
    {
 | 
			
		||||
        MemoryStats memStats;
 | 
			
		||||
    
 | 
			
		||||
        if (!MemoryProfiler::stats)
 | 
			
		||||
        {
 | 
			
		||||
            MemoryProfiler::stats = &memStats;
 | 
			
		||||
        }
 | 
			
		||||
        size_t initMem               = MemoryProfiler::stats->currentlyAllocated;
 | 
			
		||||
        object_[address].storage     = storage;
 | 
			
		||||
        object_[address].Ls          = Ls;
 | 
			
		||||
        object_[address].data.reset(new Holder<B>(new T(std::forward<Ts>(args)...)));
 | 
			
		||||
        object_[address].size        = MemoryProfiler::stats->maxAllocated - initMem;
 | 
			
		||||
        object_[address].type        = &typeid(B);
 | 
			
		||||
        object_[address].derivedType = &typeid(T);
 | 
			
		||||
        if (MemoryProfiler::stats == &memStats)
 | 
			
		||||
        {
 | 
			
		||||
            MemoryProfiler::stats = nullptr;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    // object already exists, no error if it is a cache, error otherwise
 | 
			
		||||
    else if ((object_[address].storage     != Storage::cache) or 
 | 
			
		||||
             (object_[address].storage     != storage)        or
 | 
			
		||||
             (object_[address].name        != name)           or
 | 
			
		||||
             (object_[address].type        != &typeid(B))     or
 | 
			
		||||
             (object_[address].derivedType != &typeid(T)))
 | 
			
		||||
    {
 | 
			
		||||
        HADRONS_ERROR_REF(ObjectDefinition, "object '" + name + "' already allocated", address);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename T, typename ... Ts>
 | 
			
		||||
void Environment::createObject(const std::string name, 
 | 
			
		||||
                               const Environment::Storage storage,
 | 
			
		||||
                               const unsigned int Ls,
 | 
			
		||||
                               Ts && ... args)
 | 
			
		||||
{
 | 
			
		||||
    createDerivedObject<T, T>(name, storage, Ls, std::forward<Ts>(args)...);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename B, typename T>
 | 
			
		||||
T * Environment::getDerivedObject(const unsigned int address) const
 | 
			
		||||
{
 | 
			
		||||
    if (hasObject(address))
 | 
			
		||||
    {
 | 
			
		||||
        if (hasCreatedObject(address))
 | 
			
		||||
        {
 | 
			
		||||
            if (auto h = dynamic_cast<Holder<B> *>(object_[address].data.get()))
 | 
			
		||||
            {
 | 
			
		||||
                if (&typeid(T) == &typeid(B))
 | 
			
		||||
                {
 | 
			
		||||
                    return dynamic_cast<T *>(h->getPt());
 | 
			
		||||
                }
 | 
			
		||||
                else
 | 
			
		||||
                {
 | 
			
		||||
                    if (auto hder = dynamic_cast<T *>(h->getPt()))
 | 
			
		||||
                    {
 | 
			
		||||
                        return hder;
 | 
			
		||||
                    }
 | 
			
		||||
                    else
 | 
			
		||||
                    {
 | 
			
		||||
                        HADRONS_ERROR_REF(ObjectType, "object with address " +
 | 
			
		||||
                            std::to_string(address) +
 | 
			
		||||
                            " cannot be casted to '" + typeName(&typeid(T)) +
 | 
			
		||||
                            "' (has type '" + typeName(&typeid(h->get())) + "')", address);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
                HADRONS_ERROR_REF(ObjectType, "object with address " + 
 | 
			
		||||
                            std::to_string(address) +
 | 
			
		||||
                            " does not have type '" + typeName(&typeid(B)) +
 | 
			
		||||
                            "' (has type '" + getObjectType(address) + "')", address);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            HADRONS_ERROR_REF(ObjectDefinition, "object with address " + 
 | 
			
		||||
                              std::to_string(address) + " is empty", address);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        HADRONS_ERROR_REF(ObjectDefinition, "no object with address " + 
 | 
			
		||||
                          std::to_string(address), address);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename B, typename T>
 | 
			
		||||
T * Environment::getDerivedObject(const std::string name) const
 | 
			
		||||
{
 | 
			
		||||
    return getDerivedObject<B, T>(getObjectAddress(name));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename T>
 | 
			
		||||
T * Environment::getObject(const unsigned int address) const
 | 
			
		||||
{
 | 
			
		||||
    return getDerivedObject<T, T>(address);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename T>
 | 
			
		||||
T * Environment::getObject(const std::string name) const
 | 
			
		||||
{
 | 
			
		||||
    return getObject<T>(getObjectAddress(name));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename T>
 | 
			
		||||
bool Environment::isObjectOfType(const unsigned int address) const
 | 
			
		||||
{
 | 
			
		||||
    if (hasObject(address))
 | 
			
		||||
    {
 | 
			
		||||
        if (auto h = dynamic_cast<Holder<T> *>(object_[address].data.get()))
 | 
			
		||||
        {
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        HADRONS_ERROR_REF(ObjectDefinition, "no object with address " 
 | 
			
		||||
                          + std::to_string(address), address);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename T>
 | 
			
		||||
bool Environment::isObjectOfType(const std::string name) const
 | 
			
		||||
{
 | 
			
		||||
    return isObjectOfType<T>(getObjectAddress(name));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
END_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
#endif // Hadrons_Environment_hpp_
 | 
			
		||||
							
								
								
									
										102
									
								
								Hadrons/Exceptions.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										102
									
								
								Hadrons/Exceptions.cc
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,102 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Exceptions.cc
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Exceptions.hpp>
 | 
			
		||||
#include <Hadrons/VirtualMachine.hpp>
 | 
			
		||||
#include <Hadrons/Module.hpp>
 | 
			
		||||
 | 
			
		||||
#ifndef ERR_SUFF
 | 
			
		||||
#define ERR_SUFF " (" + loc + ")"
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#define CTOR_EXC(name, init) \
 | 
			
		||||
name::name(std::string msg, std::string loc)\
 | 
			
		||||
:init\
 | 
			
		||||
{}
 | 
			
		||||
 | 
			
		||||
#define CTOR_EXC_REF(name, init) \
 | 
			
		||||
name::name(std::string msg, std::string loc, const unsigned int address)\
 | 
			
		||||
:init\
 | 
			
		||||
{}
 | 
			
		||||
 | 
			
		||||
using namespace Grid;
 | 
			
		||||
using namespace Hadrons;
 | 
			
		||||
using namespace Exceptions;
 | 
			
		||||
 | 
			
		||||
// backtrace cache
 | 
			
		||||
std::vector<std::string> Grid::Hadrons::Exceptions::backtraceStr;
 | 
			
		||||
 | 
			
		||||
// logic errors
 | 
			
		||||
CTOR_EXC(Logic, logic_error(msg + ERR_SUFF))
 | 
			
		||||
CTOR_EXC(Definition, Logic("definition error: " + msg, loc))
 | 
			
		||||
CTOR_EXC(Implementation, Logic("implementation error: " + msg, loc))
 | 
			
		||||
CTOR_EXC(Range, Logic("range error: " + msg, loc))
 | 
			
		||||
CTOR_EXC(Size, Logic("size error: " + msg, loc))
 | 
			
		||||
 | 
			
		||||
// runtime errors
 | 
			
		||||
CTOR_EXC(Runtime, runtime_error(msg + ERR_SUFF))
 | 
			
		||||
CTOR_EXC(Argument, Runtime("argument error: " + msg, loc))
 | 
			
		||||
CTOR_EXC(Io, Runtime("IO error: " + msg, loc))
 | 
			
		||||
CTOR_EXC(Memory, Runtime("memory error: " + msg, loc))
 | 
			
		||||
CTOR_EXC(Parsing, Runtime("parsing error: " + msg, loc))
 | 
			
		||||
CTOR_EXC(Program, Runtime("program error: " + msg, loc))
 | 
			
		||||
CTOR_EXC(System, Runtime("system error: " + msg, loc))
 | 
			
		||||
 | 
			
		||||
// virtual machine errors
 | 
			
		||||
CTOR_EXC_REF(ObjectDefinition, RuntimeRef("object definition error: " + msg, loc, address));
 | 
			
		||||
CTOR_EXC_REF(ObjectType, RuntimeRef("object type error: " + msg, loc, address));
 | 
			
		||||
 | 
			
		||||
// abort functions
 | 
			
		||||
void Grid::Hadrons::Exceptions::abort(const std::exception& e)
 | 
			
		||||
{
 | 
			
		||||
    auto &vm = VirtualMachine::getInstance();
 | 
			
		||||
    int  mod = vm.getCurrentModule();
 | 
			
		||||
 | 
			
		||||
    LOG(Error) << "FATAL ERROR -- Exception " << typeName(&typeid(e)) 
 | 
			
		||||
               << std::endl;
 | 
			
		||||
    if (mod >= 0)
 | 
			
		||||
    {
 | 
			
		||||
        LOG(Error) << "During execution of module '"
 | 
			
		||||
                    << vm.getModuleName(mod) << "' (address " << mod << ")"
 | 
			
		||||
                    << std::endl;
 | 
			
		||||
    }
 | 
			
		||||
    LOG(Error) << e.what() << std::endl;
 | 
			
		||||
    if (!backtraceStr.empty())
 | 
			
		||||
    {
 | 
			
		||||
        LOG(Error) << "-- BACKTRACE --------------" << std::endl;
 | 
			
		||||
        for (auto &s: backtraceStr)
 | 
			
		||||
        {
 | 
			
		||||
            LOG(Error) << s << std::endl;
 | 
			
		||||
        }
 | 
			
		||||
        LOG(Error) << "---------------------------" << std::endl;
 | 
			
		||||
    }
 | 
			
		||||
    LOG(Error) << "Aborting program" << std::endl;
 | 
			
		||||
    Grid_finalize();
 | 
			
		||||
 | 
			
		||||
    exit(EXIT_FAILURE);
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										129
									
								
								Hadrons/Exceptions.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										129
									
								
								Hadrons/Exceptions.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,129 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Exceptions.hpp
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
 | 
			
		||||
#ifndef Hadrons_Exceptions_hpp_
 | 
			
		||||
#define Hadrons_Exceptions_hpp_
 | 
			
		||||
 | 
			
		||||
#include <stdexcept>
 | 
			
		||||
#include <execinfo.h>
 | 
			
		||||
#ifndef Hadrons_Global_hpp_
 | 
			
		||||
#include <Hadrons/Global.hpp>
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#define HADRONS_SRC_LOC std::string(__FUNCTION__) + " at " \
 | 
			
		||||
                        + std::string(__FILE__) + ":" + std::to_string(__LINE__)
 | 
			
		||||
#define HADRONS_BACKTRACE_MAX 128
 | 
			
		||||
#ifdef HAVE_EXECINFO_H
 | 
			
		||||
#define HADRONS_CACHE_BACKTRACE \
 | 
			
		||||
{\
 | 
			
		||||
    void* _callstack[HADRONS_BACKTRACE_MAX];\
 | 
			
		||||
    int _i, _frames = backtrace(_callstack, HADRONS_BACKTRACE_MAX);\
 | 
			
		||||
    char** _strs = backtrace_symbols(_callstack, _frames);\
 | 
			
		||||
    Grid::Hadrons::Exceptions::backtraceStr.clear();\
 | 
			
		||||
    for (_i = 0; _i < _frames; ++_i)\
 | 
			
		||||
    {\
 | 
			
		||||
        Hadrons::Exceptions::backtraceStr.push_back(std::string(_strs[_i]));\
 | 
			
		||||
    }\
 | 
			
		||||
    free(_strs);\
 | 
			
		||||
}
 | 
			
		||||
#else
 | 
			
		||||
#define HADRONS_CACHE_BACKTRACE \
 | 
			
		||||
Grid::Hadrons::Exceptions::backtraceStr.clear();\
 | 
			
		||||
Grid::Hadrons::Exceptions::backtraceStr.push_back("<backtrace not supported>");
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#define HADRONS_ERROR(exc, msg)\
 | 
			
		||||
HADRONS_CACHE_BACKTRACE \
 | 
			
		||||
throw(Exceptions::exc(msg, HADRONS_SRC_LOC));
 | 
			
		||||
 | 
			
		||||
#define HADRONS_ERROR_REF(exc, msg, address)\
 | 
			
		||||
HADRONS_CACHE_BACKTRACE \
 | 
			
		||||
throw(Exceptions::exc(msg, HADRONS_SRC_LOC, address));
 | 
			
		||||
 | 
			
		||||
#define DECL_EXC(name, base) \
 | 
			
		||||
class name: public base\
 | 
			
		||||
{\
 | 
			
		||||
public:\
 | 
			
		||||
    name(std::string msg, std::string loc);\
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#define DECL_EXC_REF(name, base) \
 | 
			
		||||
class name: public base\
 | 
			
		||||
{\
 | 
			
		||||
public:\
 | 
			
		||||
    name(std::string msg, std::string loc, const unsigned int address);\
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
BEGIN_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
namespace Exceptions
 | 
			
		||||
{
 | 
			
		||||
    // backtrace cache
 | 
			
		||||
    extern std::vector<std::string> backtraceStr;
 | 
			
		||||
 | 
			
		||||
    // logic errors
 | 
			
		||||
    DECL_EXC(Logic, std::logic_error);
 | 
			
		||||
    DECL_EXC(Definition, Logic);
 | 
			
		||||
    DECL_EXC(Implementation, Logic);
 | 
			
		||||
    DECL_EXC(Range, Logic);
 | 
			
		||||
    DECL_EXC(Size, Logic);
 | 
			
		||||
 | 
			
		||||
    // runtime errors
 | 
			
		||||
    DECL_EXC(Runtime, std::runtime_error);
 | 
			
		||||
    DECL_EXC(Argument, Runtime);
 | 
			
		||||
    DECL_EXC(Io, Runtime);
 | 
			
		||||
    DECL_EXC(Memory, Runtime);
 | 
			
		||||
    DECL_EXC(Parsing, Runtime);
 | 
			
		||||
    DECL_EXC(Program, Runtime);
 | 
			
		||||
    DECL_EXC(System, Runtime);
 | 
			
		||||
 | 
			
		||||
    // virtual machine errors
 | 
			
		||||
    class RuntimeRef: public Runtime
 | 
			
		||||
    {
 | 
			
		||||
    public:
 | 
			
		||||
        RuntimeRef(std::string msg, std::string loc, const unsigned int address)
 | 
			
		||||
        : Runtime(msg, loc), address_(address)
 | 
			
		||||
        {}
 | 
			
		||||
        unsigned int getAddress(void) const
 | 
			
		||||
        {
 | 
			
		||||
            return address_;
 | 
			
		||||
        }
 | 
			
		||||
    private:
 | 
			
		||||
        unsigned int address_;
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    DECL_EXC_REF(ObjectDefinition, RuntimeRef);
 | 
			
		||||
    DECL_EXC_REF(ObjectType, RuntimeRef);
 | 
			
		||||
 | 
			
		||||
    // abort functions
 | 
			
		||||
    void abort(const std::exception& e);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
END_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
#endif // Hadrons_Exceptions_hpp_
 | 
			
		||||
							
								
								
									
										105
									
								
								Hadrons/Factory.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										105
									
								
								Hadrons/Factory.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,105 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Factory.hpp
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
 | 
			
		||||
#ifndef Hadrons_Factory_hpp_
 | 
			
		||||
#define Hadrons_Factory_hpp_
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Global.hpp>
 | 
			
		||||
 | 
			
		||||
BEGIN_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                        abstract factory class                              *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
template <typename T>
 | 
			
		||||
class Factory
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    typedef std::function<std::unique_ptr<T>(const std::string)> Func;
 | 
			
		||||
public:
 | 
			
		||||
    // constructor
 | 
			
		||||
    Factory(void) = default;
 | 
			
		||||
    // destructor
 | 
			
		||||
    virtual ~Factory(void) = default;
 | 
			
		||||
    // registration
 | 
			
		||||
    void registerBuilder(const std::string type, const Func &f);
 | 
			
		||||
    // get builder list
 | 
			
		||||
    std::vector<std::string> getBuilderList(void) const;
 | 
			
		||||
    // factory
 | 
			
		||||
    std::unique_ptr<T> create(const std::string type,
 | 
			
		||||
                              const std::string name) const;
 | 
			
		||||
private:
 | 
			
		||||
    std::map<std::string, Func> builder_;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                         template implementation                            *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
// registration ////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename T>
 | 
			
		||||
void Factory<T>::registerBuilder(const std::string type, const Func &f)
 | 
			
		||||
{
 | 
			
		||||
    builder_[type] = f;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// get module list /////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename T>
 | 
			
		||||
std::vector<std::string> Factory<T>::getBuilderList(void) const
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> list;
 | 
			
		||||
    
 | 
			
		||||
    for (auto &b: builder_)
 | 
			
		||||
    {
 | 
			
		||||
        list.push_back(b.first);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    return list;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// factory /////////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename T>
 | 
			
		||||
std::unique_ptr<T> Factory<T>::create(const std::string type,
 | 
			
		||||
                                      const std::string name) const
 | 
			
		||||
{
 | 
			
		||||
    Func func;
 | 
			
		||||
    
 | 
			
		||||
    try
 | 
			
		||||
    {
 | 
			
		||||
        func = builder_.at(type);
 | 
			
		||||
    }
 | 
			
		||||
    catch (std::out_of_range &)
 | 
			
		||||
    {
 | 
			
		||||
        HADRONS_ERROR(Argument, "object of type '" + type + "' unknown");
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    return func(name);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
END_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
#endif // Hadrons_Factory_hpp_
 | 
			
		||||
							
								
								
									
										323
									
								
								Hadrons/GeneticScheduler.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										323
									
								
								Hadrons/GeneticScheduler.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,323 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/GeneticScheduler.hpp
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
 | 
			
		||||
#ifndef Hadrons_GeneticScheduler_hpp_
 | 
			
		||||
#define Hadrons_GeneticScheduler_hpp_
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Global.hpp>
 | 
			
		||||
#include <Hadrons/Graph.hpp>
 | 
			
		||||
 | 
			
		||||
BEGIN_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                   Scheduler based on a genetic algorithm                   *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
template <typename V, typename T>
 | 
			
		||||
class GeneticScheduler
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    typedef std::vector<T>                 Gene;
 | 
			
		||||
    typedef std::pair<Gene *, Gene *>      GenePair;
 | 
			
		||||
    typedef std::function<V(const Gene &)> ObjFunc;
 | 
			
		||||
    struct Parameters
 | 
			
		||||
    {
 | 
			
		||||
        double       mutationRate;
 | 
			
		||||
        unsigned int popSize, seed;
 | 
			
		||||
    };
 | 
			
		||||
public:
 | 
			
		||||
    // constructor
 | 
			
		||||
    GeneticScheduler(Graph<T> &graph, const ObjFunc &func,
 | 
			
		||||
                     const Parameters &par);
 | 
			
		||||
    // destructor
 | 
			
		||||
    virtual ~GeneticScheduler(void) = default;
 | 
			
		||||
    // access
 | 
			
		||||
    const Gene & getMinSchedule(void);
 | 
			
		||||
    V            getMinValue(void);
 | 
			
		||||
    // reset population
 | 
			
		||||
    void initPopulation(void);
 | 
			
		||||
    // breed a new generation
 | 
			
		||||
    void nextGeneration(void);
 | 
			
		||||
    // heuristic benchmarks
 | 
			
		||||
    void benchmarkCrossover(const unsigned int nIt);
 | 
			
		||||
    // print population
 | 
			
		||||
    friend std::ostream & operator<<(std::ostream &out,
 | 
			
		||||
                                     const GeneticScheduler<V, T> &s)
 | 
			
		||||
    {
 | 
			
		||||
        out << "[";
 | 
			
		||||
        for (auto &p: s.population_)
 | 
			
		||||
        {
 | 
			
		||||
            out << p.first << ", ";
 | 
			
		||||
        }
 | 
			
		||||
        out << "\b\b]";
 | 
			
		||||
        
 | 
			
		||||
        return out;
 | 
			
		||||
    }
 | 
			
		||||
private:
 | 
			
		||||
    void doCrossover(void);
 | 
			
		||||
    void doMutation(void);
 | 
			
		||||
    // genetic operators
 | 
			
		||||
    GenePair selectPair(void);
 | 
			
		||||
    void     crossover(Gene &c1, Gene &c2, const Gene &p1, const Gene &p2);
 | 
			
		||||
    void     mutation(Gene &m, const Gene &c);
 | 
			
		||||
    
 | 
			
		||||
private:
 | 
			
		||||
    Graph<T>               &graph_;
 | 
			
		||||
    const ObjFunc          &func_;
 | 
			
		||||
    const Parameters       par_;
 | 
			
		||||
    std::multimap<V, Gene> population_;
 | 
			
		||||
    std::mt19937           gen_;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                       template implementation                              *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
// constructor /////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename V, typename T>
 | 
			
		||||
GeneticScheduler<V, T>::GeneticScheduler(Graph<T> &graph, const ObjFunc &func,
 | 
			
		||||
                                      const Parameters &par)
 | 
			
		||||
: graph_(graph)
 | 
			
		||||
, func_(func)
 | 
			
		||||
, par_(par)
 | 
			
		||||
{
 | 
			
		||||
    gen_.seed(par_.seed);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// access //////////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename V, typename T>
 | 
			
		||||
const typename GeneticScheduler<V, T>::Gene &
 | 
			
		||||
GeneticScheduler<V, T>::getMinSchedule(void)
 | 
			
		||||
{
 | 
			
		||||
    return population_.begin()->second;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename V, typename T>
 | 
			
		||||
V GeneticScheduler<V, T>::getMinValue(void)
 | 
			
		||||
{
 | 
			
		||||
    return population_.begin()->first;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// breed a new generation //////////////////////////////////////////////////////
 | 
			
		||||
template <typename V, typename T>
 | 
			
		||||
void GeneticScheduler<V, T>::nextGeneration(void)
 | 
			
		||||
{
 | 
			
		||||
    // random initialization of the population if necessary
 | 
			
		||||
    if (population_.size() != par_.popSize)
 | 
			
		||||
    {
 | 
			
		||||
        initPopulation();
 | 
			
		||||
    }
 | 
			
		||||
    //LOG(Debug) << "Starting population:\n" << *this << std::endl;
 | 
			
		||||
    
 | 
			
		||||
    // random mutations
 | 
			
		||||
    //PARALLEL_FOR_LOOP
 | 
			
		||||
    for (unsigned int i = 0; i < par_.popSize; ++i)
 | 
			
		||||
    {
 | 
			
		||||
        doMutation();
 | 
			
		||||
    }
 | 
			
		||||
    //LOG(Debug) << "After mutations:\n" << *this << std::endl;
 | 
			
		||||
    
 | 
			
		||||
    // mating
 | 
			
		||||
    //PARALLEL_FOR_LOOP
 | 
			
		||||
    for (unsigned int i = 0; i < par_.popSize/2; ++i)
 | 
			
		||||
    {
 | 
			
		||||
        doCrossover();
 | 
			
		||||
    }
 | 
			
		||||
    //LOG(Debug) << "After mating:\n" << *this << std::endl;
 | 
			
		||||
    
 | 
			
		||||
    // grim reaper
 | 
			
		||||
    auto it = population_.begin();
 | 
			
		||||
    
 | 
			
		||||
    std::advance(it, par_.popSize);
 | 
			
		||||
    population_.erase(it, population_.end());
 | 
			
		||||
    //LOG(Debug) << "After grim reaper:\n" << *this << std::endl;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// evolution steps /////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename V, typename T>
 | 
			
		||||
void GeneticScheduler<V, T>::initPopulation(void)
 | 
			
		||||
{
 | 
			
		||||
    population_.clear();
 | 
			
		||||
    for (unsigned int i = 0; i < par_.popSize; ++i)
 | 
			
		||||
    {
 | 
			
		||||
        auto p = graph_.topoSort(gen_);
 | 
			
		||||
        
 | 
			
		||||
        population_.insert(std::make_pair(func_(p), p));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename V, typename T>
 | 
			
		||||
void GeneticScheduler<V, T>::doCrossover(void)
 | 
			
		||||
{
 | 
			
		||||
    auto p = selectPair();
 | 
			
		||||
    Gene &p1 = *(p.first), &p2 = *(p.second);
 | 
			
		||||
    Gene c1, c2;
 | 
			
		||||
    
 | 
			
		||||
    crossover(c1, c2, p1, p2);
 | 
			
		||||
    PARALLEL_CRITICAL
 | 
			
		||||
    {
 | 
			
		||||
        population_.insert(std::make_pair(func_(c1), c1));
 | 
			
		||||
        population_.insert(std::make_pair(func_(c2), c2));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename V, typename T>
 | 
			
		||||
void GeneticScheduler<V, T>::doMutation(void)
 | 
			
		||||
{
 | 
			
		||||
    std::uniform_real_distribution<double>      mdis(0., 1.);
 | 
			
		||||
    std::uniform_int_distribution<unsigned int> pdis(0, population_.size() - 1);
 | 
			
		||||
    
 | 
			
		||||
    if (mdis(gen_) < par_.mutationRate)
 | 
			
		||||
    {
 | 
			
		||||
        Gene m;
 | 
			
		||||
        auto it = population_.begin();
 | 
			
		||||
        
 | 
			
		||||
        std::advance(it, pdis(gen_));
 | 
			
		||||
        mutation(m, it->second);
 | 
			
		||||
        PARALLEL_CRITICAL
 | 
			
		||||
        {
 | 
			
		||||
            population_.insert(std::make_pair(func_(m), m));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// genetic operators ///////////////////////////////////////////////////////////
 | 
			
		||||
template <typename V, typename T>
 | 
			
		||||
typename GeneticScheduler<V, T>::GenePair GeneticScheduler<V, T>::selectPair(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<double> prob;
 | 
			
		||||
    unsigned int        ind;
 | 
			
		||||
    Gene                *p1, *p2;
 | 
			
		||||
    const double        max = population_.rbegin()->first;
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    for (auto &c: population_)
 | 
			
		||||
    {
 | 
			
		||||
        prob.push_back(std::exp((c.first-1.)/max));
 | 
			
		||||
    }        
 | 
			
		||||
    std::discrete_distribution<unsigned int> dis1(prob.begin(), prob.end());
 | 
			
		||||
    auto rIt = population_.begin();
 | 
			
		||||
    ind = dis1(gen_);
 | 
			
		||||
    std::advance(rIt, ind);
 | 
			
		||||
    p1 = &(rIt->second);
 | 
			
		||||
    prob[ind] = 0.;
 | 
			
		||||
    std::discrete_distribution<unsigned int> dis2(prob.begin(), prob.end());
 | 
			
		||||
    rIt = population_.begin();
 | 
			
		||||
    std::advance(rIt, dis2(gen_));
 | 
			
		||||
    p2 = &(rIt->second);
 | 
			
		||||
    
 | 
			
		||||
    return std::make_pair(p1, p2);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename V, typename T>
 | 
			
		||||
void GeneticScheduler<V, T>::crossover(Gene &c1, Gene &c2, const Gene &p1,
 | 
			
		||||
                                    const Gene &p2)
 | 
			
		||||
{
 | 
			
		||||
    Gene                                        buf;
 | 
			
		||||
    std::uniform_int_distribution<unsigned int> dis(0, p1.size() - 1);
 | 
			
		||||
    unsigned int                                cut = dis(gen_);
 | 
			
		||||
    
 | 
			
		||||
    c1.clear();
 | 
			
		||||
    buf = p2;
 | 
			
		||||
    for (unsigned int i = 0; i < cut; ++i)
 | 
			
		||||
    {
 | 
			
		||||
        c1.push_back(p1[i]);
 | 
			
		||||
        buf.erase(std::find(buf.begin(), buf.end(), p1[i]));
 | 
			
		||||
    }
 | 
			
		||||
    for (unsigned int i = 0; i < buf.size(); ++i)
 | 
			
		||||
    {
 | 
			
		||||
        c1.push_back(buf[i]);
 | 
			
		||||
    }
 | 
			
		||||
    c2.clear();
 | 
			
		||||
    buf = p2;
 | 
			
		||||
    for (unsigned int i = cut; i < p1.size(); ++i)
 | 
			
		||||
    {
 | 
			
		||||
        buf.erase(std::find(buf.begin(), buf.end(), p1[i]));
 | 
			
		||||
    }
 | 
			
		||||
    for (unsigned int i = 0; i < buf.size(); ++i)
 | 
			
		||||
    {
 | 
			
		||||
        c2.push_back(buf[i]);
 | 
			
		||||
    }
 | 
			
		||||
    for (unsigned int i = cut; i < p1.size(); ++i)
 | 
			
		||||
    {
 | 
			
		||||
        c2.push_back(p1[i]);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename V, typename T>
 | 
			
		||||
void GeneticScheduler<V, T>::mutation(Gene &m, const Gene &c)
 | 
			
		||||
{
 | 
			
		||||
    Gene                                        buf;
 | 
			
		||||
    std::uniform_int_distribution<unsigned int> dis(0, c.size() - 1);
 | 
			
		||||
    unsigned int                                cut = dis(gen_);
 | 
			
		||||
    Graph<T>                                    g1 = graph_, g2 = graph_;
 | 
			
		||||
    
 | 
			
		||||
    for (unsigned int i = 0; i < cut; ++i)
 | 
			
		||||
    {
 | 
			
		||||
        g1.removeVertex(c[i]);
 | 
			
		||||
    }
 | 
			
		||||
    for (unsigned int i = cut; i < c.size(); ++i)
 | 
			
		||||
    {
 | 
			
		||||
        g2.removeVertex(c[i]);
 | 
			
		||||
    }
 | 
			
		||||
    if (g1.size() > 0)
 | 
			
		||||
    {
 | 
			
		||||
        buf = g1.topoSort(gen_);
 | 
			
		||||
    }
 | 
			
		||||
    if (g2.size() > 0)
 | 
			
		||||
    {
 | 
			
		||||
        m = g2.topoSort(gen_);
 | 
			
		||||
    }
 | 
			
		||||
    for (unsigned int i = cut; i < c.size(); ++i)
 | 
			
		||||
    {
 | 
			
		||||
        m.push_back(buf[i - cut]);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename V, typename T>
 | 
			
		||||
void GeneticScheduler<V, T>::benchmarkCrossover(const unsigned int nIt)
 | 
			
		||||
{
 | 
			
		||||
    Gene   p1, p2, c1, c2;
 | 
			
		||||
    double neg = 0., eq = 0., pos = 0., total;
 | 
			
		||||
    int    improvement;
 | 
			
		||||
    
 | 
			
		||||
    LOG(Message) << "Benchmarking crossover..." << std::endl;
 | 
			
		||||
    for (unsigned int i = 0; i < nIt; ++i)
 | 
			
		||||
    {
 | 
			
		||||
        p1 = graph_.topoSort(gen_);
 | 
			
		||||
        p2 = graph_.topoSort(gen_);
 | 
			
		||||
        crossover(c1, c2, p1, p2);
 | 
			
		||||
        improvement = (func_(c1) + func_(c2) - func_(p1) - func_(p2))/2;
 | 
			
		||||
        if (improvement < 0) neg++; else if (improvement == 0) eq++; else pos++;
 | 
			
		||||
    }
 | 
			
		||||
    total = neg + eq + pos;
 | 
			
		||||
    LOG(Message) << "  -: " << neg/total << "  =: " << eq/total
 | 
			
		||||
                 << "  +: " << pos/total << std::endl;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
END_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
#endif // Hadrons_GeneticScheduler_hpp_
 | 
			
		||||
							
								
								
									
										203
									
								
								Hadrons/Global.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										203
									
								
								Hadrons/Global.cc
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,203 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Global.cc
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Global.hpp>
 | 
			
		||||
 | 
			
		||||
using namespace Grid;
 | 
			
		||||
using namespace QCD;
 | 
			
		||||
using namespace Hadrons;
 | 
			
		||||
 | 
			
		||||
HadronsLogger Hadrons::HadronsLogError(1,"Error");
 | 
			
		||||
HadronsLogger Hadrons::HadronsLogWarning(1,"Warning");
 | 
			
		||||
HadronsLogger Hadrons::HadronsLogMessage(1,"Message");
 | 
			
		||||
HadronsLogger Hadrons::HadronsLogIterative(1,"Iterative");
 | 
			
		||||
HadronsLogger Hadrons::HadronsLogDebug(1,"Debug");
 | 
			
		||||
HadronsLogger Hadrons::HadronsLogIRL(1,"IRL");
 | 
			
		||||
 | 
			
		||||
void Hadrons::initLogger(void)
 | 
			
		||||
{
 | 
			
		||||
    auto w  = std::string("Hadrons").length();
 | 
			
		||||
    int  cw = 8;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    GridLogError.setTopWidth(w);
 | 
			
		||||
    GridLogWarning.setTopWidth(w);
 | 
			
		||||
    GridLogMessage.setTopWidth(w);
 | 
			
		||||
    GridLogIterative.setTopWidth(w);
 | 
			
		||||
    GridLogDebug.setTopWidth(w);
 | 
			
		||||
    GridLogIRL.setTopWidth(w);
 | 
			
		||||
    GridLogError.setChanWidth(cw);
 | 
			
		||||
    GridLogWarning.setChanWidth(cw);
 | 
			
		||||
    GridLogMessage.setChanWidth(cw);
 | 
			
		||||
    GridLogIterative.setChanWidth(cw);
 | 
			
		||||
    GridLogDebug.setChanWidth(cw);
 | 
			
		||||
    GridLogIRL.setChanWidth(cw);
 | 
			
		||||
    HadronsLogError.Active(true);
 | 
			
		||||
    HadronsLogWarning.Active(true);
 | 
			
		||||
    HadronsLogMessage.Active(GridLogMessage.isActive());
 | 
			
		||||
    HadronsLogIterative.Active(GridLogIterative.isActive());
 | 
			
		||||
    HadronsLogDebug.Active(GridLogDebug.isActive());
 | 
			
		||||
    HadronsLogIRL.Active(GridLogIRL.isActive());
 | 
			
		||||
    HadronsLogError.setChanWidth(cw);
 | 
			
		||||
    HadronsLogWarning.setChanWidth(cw);
 | 
			
		||||
    HadronsLogMessage.setChanWidth(cw);
 | 
			
		||||
    HadronsLogIterative.setChanWidth(cw);
 | 
			
		||||
    HadronsLogDebug.setChanWidth(cw);
 | 
			
		||||
    HadronsLogIRL.setChanWidth(cw);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// type utilities //////////////////////////////////////////////////////////////
 | 
			
		||||
constexpr unsigned int maxNameSize = 1024u;
 | 
			
		||||
 | 
			
		||||
std::string Hadrons::typeName(const std::type_info *info)
 | 
			
		||||
{
 | 
			
		||||
    char        *buf;
 | 
			
		||||
    std::string name;
 | 
			
		||||
    
 | 
			
		||||
    buf  = abi::__cxa_demangle(info->name(), nullptr, nullptr, nullptr);
 | 
			
		||||
    name = buf;
 | 
			
		||||
    free(buf);
 | 
			
		||||
    
 | 
			
		||||
    return name;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// default writers/readers /////////////////////////////////////////////////////
 | 
			
		||||
#ifdef HAVE_HDF5
 | 
			
		||||
const std::string Hadrons::resultFileExt = "h5";
 | 
			
		||||
#else
 | 
			
		||||
const std::string Hadrons::resultFileExt = "xml";
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
// recursive mkdir /////////////////////////////////////////////////////////////
 | 
			
		||||
int Hadrons::mkdir(const std::string dirName)
 | 
			
		||||
{
 | 
			
		||||
    if (!dirName.empty() and access(dirName.c_str(), R_OK|W_OK|X_OK))
 | 
			
		||||
    {
 | 
			
		||||
        mode_t mode755;
 | 
			
		||||
        char   tmp[MAX_PATH_LENGTH];
 | 
			
		||||
        char   *p = NULL;
 | 
			
		||||
        size_t len;
 | 
			
		||||
 | 
			
		||||
        mode755 = S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH;
 | 
			
		||||
 | 
			
		||||
        snprintf(tmp, sizeof(tmp), "%s", dirName.c_str());
 | 
			
		||||
        len = strlen(tmp);
 | 
			
		||||
        if(tmp[len - 1] == '/')
 | 
			
		||||
        {
 | 
			
		||||
            tmp[len - 1] = 0;
 | 
			
		||||
        }
 | 
			
		||||
        for(p = tmp + 1; *p; p++)
 | 
			
		||||
        {
 | 
			
		||||
            if(*p == '/')
 | 
			
		||||
            {
 | 
			
		||||
                *p = 0;
 | 
			
		||||
                ::mkdir(tmp, mode755);
 | 
			
		||||
                *p = '/';
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return ::mkdir(tmp, mode755);
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        return 0;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::string Hadrons::basename(const std::string &s)
 | 
			
		||||
{
 | 
			
		||||
    constexpr char sep = '/';
 | 
			
		||||
    size_t         i   = s.rfind(sep, s.length());
 | 
			
		||||
    
 | 
			
		||||
    if (i != std::string::npos)
 | 
			
		||||
    {
 | 
			
		||||
        return s.substr(i+1, s.length() - i);
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        return s;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::string Hadrons::dirname(const std::string &s)
 | 
			
		||||
{
 | 
			
		||||
    constexpr char sep = '/';
 | 
			
		||||
    size_t         i   = s.rfind(sep, s.length());
 | 
			
		||||
    
 | 
			
		||||
    if (i != std::string::npos)
 | 
			
		||||
    {
 | 
			
		||||
        return s.substr(0, i);
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        return "";
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Hadrons::makeFileDir(const std::string filename, GridBase *g)
 | 
			
		||||
{
 | 
			
		||||
    if (g->IsBoss())
 | 
			
		||||
    {
 | 
			
		||||
        std::string dir    = dirname(filename);
 | 
			
		||||
        int         status = mkdir(dir);
 | 
			
		||||
 | 
			
		||||
        if (status)
 | 
			
		||||
        {
 | 
			
		||||
            HADRONS_ERROR(Io, "cannot create directory '" + dir
 | 
			
		||||
                          + "' ( " + std::strerror(errno) + ")");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Hadrons::printTimeProfile(const std::map<std::string, GridTime> &timing, 
 | 
			
		||||
                               GridTime total)
 | 
			
		||||
{
 | 
			
		||||
    typedef decltype(total.count()) Count;
 | 
			
		||||
 | 
			
		||||
    std::map<Count, std::string, std::greater<Count>> rtiming;
 | 
			
		||||
    const double dtotal = static_cast<double>(total.count());
 | 
			
		||||
    auto cf = std::cout.flags();
 | 
			
		||||
    auto p  = std::cout.precision();
 | 
			
		||||
    unsigned int width = 0;
 | 
			
		||||
 | 
			
		||||
    for (auto &t: timing)
 | 
			
		||||
    {
 | 
			
		||||
        width = std::max(width, static_cast<unsigned int>(t.first.length()));
 | 
			
		||||
        rtiming[t.second.count()] = t.first;
 | 
			
		||||
    }
 | 
			
		||||
    for (auto &rt: rtiming)
 | 
			
		||||
    {
 | 
			
		||||
        LOG(Message) << std::setw(width) << rt.second << ": " 
 | 
			
		||||
                     << rt.first << " us (" << std::fixed 
 | 
			
		||||
                     << std::setprecision(1) 
 | 
			
		||||
                     << static_cast<double>(rt.first)/dtotal*100 << "%)"
 | 
			
		||||
                     << std::endl;
 | 
			
		||||
    }
 | 
			
		||||
    std::cout.flags(cf);
 | 
			
		||||
    std::cout.precision(p);
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										224
									
								
								Hadrons/Global.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										224
									
								
								Hadrons/Global.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,224 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Global.hpp
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
Author: Antonin Portelli <antonin.portelli@me.com>
 | 
			
		||||
Author: Lanny91 <andrew.lawson@gmail.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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
 | 
			
		||||
#ifndef Hadrons_Global_hpp_
 | 
			
		||||
#define Hadrons_Global_hpp_
 | 
			
		||||
 | 
			
		||||
#include <set>
 | 
			
		||||
#include <stack>
 | 
			
		||||
#include <Grid/Grid.h>
 | 
			
		||||
#include <cxxabi.h>
 | 
			
		||||
 | 
			
		||||
#ifndef SITE_SIZE_TYPE
 | 
			
		||||
#define SITE_SIZE_TYPE size_t
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifndef DEFAULT_ASCII_PREC
 | 
			
		||||
#define DEFAULT_ASCII_PREC 16
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
/* the 'using Grid::operator<<;' statement prevents a very nasty compilation
 | 
			
		||||
 * error with GCC 5 (clang & GCC 6 compile fine without it).
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#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 }
 | 
			
		||||
 | 
			
		||||
#ifndef FIMPL
 | 
			
		||||
#define FIMPL WilsonImplR
 | 
			
		||||
#endif
 | 
			
		||||
#ifndef ZFIMPL
 | 
			
		||||
#define ZFIMPL ZWilsonImplR
 | 
			
		||||
#endif
 | 
			
		||||
#ifndef SIMPL
 | 
			
		||||
#define SIMPL ScalarImplCR
 | 
			
		||||
#endif
 | 
			
		||||
#ifndef GIMPL
 | 
			
		||||
#define GIMPL PeriodicGimplR
 | 
			
		||||
#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 Solver<FImpl> Solver##suffix;
 | 
			
		||||
 | 
			
		||||
#define SINK_TYPE_ALIASES(suffix)\
 | 
			
		||||
typedef std::function<SlicedPropagator##suffix\
 | 
			
		||||
                      (const PropagatorField##suffix &)> SinkFn##suffix;
 | 
			
		||||
 | 
			
		||||
#define FG_TYPE_ALIASES(FImpl, suffix)\
 | 
			
		||||
FERM_TYPE_ALIASES(FImpl, suffix)\
 | 
			
		||||
GAUGE_TYPE_ALIASES(FImpl, suffix)
 | 
			
		||||
 | 
			
		||||
// logger
 | 
			
		||||
class HadronsLogger: public Logger
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    HadronsLogger(int on, std::string nm): Logger("Hadrons", on, nm,
 | 
			
		||||
                                                  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;
 | 
			
		||||
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;
 | 
			
		||||
 | 
			
		||||
// type utilities
 | 
			
		||||
template <typename T>
 | 
			
		||||
const std::type_info * typeIdPt(const T &x)
 | 
			
		||||
{
 | 
			
		||||
    return &typeid(x);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::string typeName(const std::type_info *info);
 | 
			
		||||
 | 
			
		||||
template <typename T>
 | 
			
		||||
const std::type_info * typeIdPt(void)
 | 
			
		||||
{
 | 
			
		||||
    return &typeid(T);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename T>
 | 
			
		||||
std::string typeName(const T &x)
 | 
			
		||||
{
 | 
			
		||||
    return typeName(typeIdPt(x));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename T>
 | 
			
		||||
std::string typeName(void)
 | 
			
		||||
{
 | 
			
		||||
    return typeName(typeIdPt<T>());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// default writers/readers
 | 
			
		||||
extern const std::string resultFileExt;
 | 
			
		||||
 | 
			
		||||
#ifdef HAVE_HDF5
 | 
			
		||||
typedef Hdf5Reader ResultReader;
 | 
			
		||||
typedef Hdf5Writer ResultWriter;
 | 
			
		||||
#else
 | 
			
		||||
typedef XmlReader ResultReader;
 | 
			
		||||
typedef XmlWriter ResultWriter;
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#define RESULT_FILE_NAME(name) \
 | 
			
		||||
name + "." + std::to_string(vm().getTrajectory()) + "." + resultFileExt
 | 
			
		||||
 | 
			
		||||
// 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);
 | 
			
		||||
 | 
			
		||||
// 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)
 | 
			
		||||
#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)
 | 
			
		||||
 | 
			
		||||
// stringify macro
 | 
			
		||||
#define _HADRONS_STR(x) #x
 | 
			
		||||
#define HADRONS_STR(x) _HADRONS_STR(x)
 | 
			
		||||
 | 
			
		||||
// pretty print time profile
 | 
			
		||||
void printTimeProfile(const std::map<std::string, GridTime> &timing, GridTime total);
 | 
			
		||||
 | 
			
		||||
END_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Exceptions.hpp>
 | 
			
		||||
 | 
			
		||||
#endif // Hadrons_Global_hpp_
 | 
			
		||||
							
								
								
									
										759
									
								
								Hadrons/Graph.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										759
									
								
								Hadrons/Graph.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,759 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Graph.hpp
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
 | 
			
		||||
#ifndef Hadrons_Graph_hpp_
 | 
			
		||||
#define Hadrons_Graph_hpp_
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Global.hpp>
 | 
			
		||||
 | 
			
		||||
BEGIN_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                          Oriented graph class                              *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
// I/O for edges
 | 
			
		||||
template <typename T>
 | 
			
		||||
std::ostream & operator<<(std::ostream &out, const std::pair<T, T> &e)
 | 
			
		||||
{
 | 
			
		||||
    out << "\""  << e.first << "\" -> \"" << e.second << "\"";
 | 
			
		||||
    
 | 
			
		||||
    return out;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// main class
 | 
			
		||||
template <typename T>
 | 
			
		||||
class Graph
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    typedef std::pair<T, T> Edge;
 | 
			
		||||
public:
 | 
			
		||||
    // constructor
 | 
			
		||||
    Graph(void);
 | 
			
		||||
    // destructor
 | 
			
		||||
    virtual ~Graph(void) = default;
 | 
			
		||||
    // access
 | 
			
		||||
    void           addVertex(const T &value);
 | 
			
		||||
    void           addEdge(const Edge &e);
 | 
			
		||||
    void           addEdge(const T &start, const T &end);
 | 
			
		||||
    std::vector<T> getVertices(void) const;
 | 
			
		||||
    void           removeVertex(const T &value);
 | 
			
		||||
    void           removeEdge(const Edge &e);
 | 
			
		||||
    void           removeEdge(const T &start, const T &end);
 | 
			
		||||
    unsigned int   size(void) const;
 | 
			
		||||
    // tests
 | 
			
		||||
    bool gotValue(const T &value) const;
 | 
			
		||||
    // graph topological manipulations
 | 
			
		||||
    std::vector<T>              getAdjacentVertices(const T &value) const;
 | 
			
		||||
    std::vector<T>              getChildren(const T &value) const;
 | 
			
		||||
    std::vector<T>              getParents(const T &value) const;
 | 
			
		||||
    std::vector<T>              getRoots(void) const;
 | 
			
		||||
    std::vector<Graph<T>>       getConnectedComponents(void) const;
 | 
			
		||||
    std::vector<T>              topoSort(void);
 | 
			
		||||
    template <typename Gen>
 | 
			
		||||
    std::vector<T>              topoSort(Gen &gen);
 | 
			
		||||
    std::vector<std::vector<T>> allTopoSort(void);
 | 
			
		||||
    // I/O
 | 
			
		||||
    friend std::ostream & operator<<(std::ostream &out, const Graph<T> &g)
 | 
			
		||||
    {
 | 
			
		||||
        out << "{";
 | 
			
		||||
        for (auto &e: g.edgeSet_)
 | 
			
		||||
        {
 | 
			
		||||
            out << e << ", ";
 | 
			
		||||
        }
 | 
			
		||||
        if (g.edgeSet_.size() != 0)
 | 
			
		||||
        {
 | 
			
		||||
            out << "\b\b";
 | 
			
		||||
        }
 | 
			
		||||
        out << "}";
 | 
			
		||||
        
 | 
			
		||||
        return out;
 | 
			
		||||
    }
 | 
			
		||||
private:
 | 
			
		||||
    // vertex marking
 | 
			
		||||
    void      mark(const T &value, const bool doMark = true);
 | 
			
		||||
    void      markAll(const bool doMark = true);
 | 
			
		||||
    void      unmark(const T &value);
 | 
			
		||||
    void      unmarkAll(void);
 | 
			
		||||
    bool      isMarked(const T &value) const;
 | 
			
		||||
    const T * getFirstMarked(const bool isMarked = true) const;
 | 
			
		||||
    template <typename Gen>
 | 
			
		||||
    const T * getRandomMarked(const bool isMarked, Gen &gen);
 | 
			
		||||
    const T * getFirstUnmarked(void) const;
 | 
			
		||||
    template <typename Gen>
 | 
			
		||||
    const T * getRandomUnmarked(Gen &gen);
 | 
			
		||||
    // prune marked/unmarked vertices
 | 
			
		||||
    void removeMarked(const bool isMarked = true);
 | 
			
		||||
    void removeUnmarked(void);
 | 
			
		||||
    // depth-first search marking
 | 
			
		||||
    void depthFirstSearch(void);
 | 
			
		||||
    void depthFirstSearch(const T &root);
 | 
			
		||||
private:
 | 
			
		||||
    std::map<T, bool>  isMarked_;
 | 
			
		||||
    std::set<Edge>     edgeSet_;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// build depedency matrix from topological sorts
 | 
			
		||||
template <typename T>
 | 
			
		||||
std::map<T, std::map<T, bool>>
 | 
			
		||||
makeDependencyMatrix(const std::vector<std::vector<T>> &topSort);
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                       template implementation                              *
 | 
			
		||||
 ******************************************************************************
 | 
			
		||||
 * in all the following V is the number of vertex and E is the number of edge
 | 
			
		||||
 * in the worst case E = V^2
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
// constructor /////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename T>
 | 
			
		||||
Graph<T>::Graph(void)
 | 
			
		||||
{}
 | 
			
		||||
 | 
			
		||||
// access //////////////////////////////////////////////////////////////////////
 | 
			
		||||
// complexity: log(V)
 | 
			
		||||
template <typename T>
 | 
			
		||||
void Graph<T>::addVertex(const T &value)
 | 
			
		||||
{
 | 
			
		||||
    isMarked_[value] = false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// complexity: O(log(V))
 | 
			
		||||
template <typename T>
 | 
			
		||||
void Graph<T>::addEdge(const Edge &e)
 | 
			
		||||
{
 | 
			
		||||
    addVertex(e.first);
 | 
			
		||||
    addVertex(e.second);
 | 
			
		||||
    edgeSet_.insert(e);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// complexity: O(log(V))
 | 
			
		||||
template <typename T>
 | 
			
		||||
void Graph<T>::addEdge(const T &start, const T &end)
 | 
			
		||||
{
 | 
			
		||||
    addEdge(Edge(start, end));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename T>
 | 
			
		||||
std::vector<T> Graph<T>::getVertices(void) const
 | 
			
		||||
{
 | 
			
		||||
    std::vector<T> vertex;
 | 
			
		||||
    
 | 
			
		||||
    for (auto &v: isMarked_)
 | 
			
		||||
    {
 | 
			
		||||
        vertex.push_back(v.first);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    return vertex;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// complexity: O(V*log(V))
 | 
			
		||||
template <typename T>
 | 
			
		||||
void Graph<T>::removeVertex(const T &value)
 | 
			
		||||
{
 | 
			
		||||
    // remove vertex from the mark table
 | 
			
		||||
    auto vIt = isMarked_.find(value);
 | 
			
		||||
    
 | 
			
		||||
    if (vIt != isMarked_.end())
 | 
			
		||||
    {
 | 
			
		||||
        isMarked_.erase(vIt);
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        HADRONS_ERROR(Range, "vertex does not exists");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // remove all edges containing the vertex
 | 
			
		||||
    auto pred = [&value](const Edge &e)
 | 
			
		||||
    {
 | 
			
		||||
        return ((e.first == value) or (e.second == value));
 | 
			
		||||
    };
 | 
			
		||||
    auto eIt = find_if(edgeSet_.begin(), edgeSet_.end(), pred);
 | 
			
		||||
    
 | 
			
		||||
    while (eIt != edgeSet_.end())
 | 
			
		||||
    {
 | 
			
		||||
        edgeSet_.erase(eIt);
 | 
			
		||||
        eIt = find_if(edgeSet_.begin(), edgeSet_.end(), pred);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// complexity: O(log(V))
 | 
			
		||||
template <typename T>
 | 
			
		||||
void Graph<T>::removeEdge(const Edge &e)
 | 
			
		||||
{
 | 
			
		||||
    auto eIt = edgeSet_.find(e);
 | 
			
		||||
    
 | 
			
		||||
    if (eIt != edgeSet_.end())
 | 
			
		||||
    {
 | 
			
		||||
        edgeSet_.erase(eIt);
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        HADRONS_ERROR(Range, "edge does not exists");
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// complexity: O(log(V))
 | 
			
		||||
template <typename T>
 | 
			
		||||
void Graph<T>::removeEdge(const T &start, const T &end)
 | 
			
		||||
{
 | 
			
		||||
    removeEdge(Edge(start, end));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// complexity: O(1)
 | 
			
		||||
template <typename T>
 | 
			
		||||
unsigned int Graph<T>::size(void) const
 | 
			
		||||
{
 | 
			
		||||
    return isMarked_.size();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// tests ///////////////////////////////////////////////////////////////////////
 | 
			
		||||
// complexity: O(log(V))
 | 
			
		||||
template <typename T>
 | 
			
		||||
bool Graph<T>::gotValue(const T &value) const
 | 
			
		||||
{
 | 
			
		||||
    auto it = isMarked_.find(value);
 | 
			
		||||
    
 | 
			
		||||
    if (it == isMarked_.end())
 | 
			
		||||
    {
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// vertex marking //////////////////////////////////////////////////////////////
 | 
			
		||||
// complexity: O(log(V))
 | 
			
		||||
template <typename T>
 | 
			
		||||
void Graph<T>::mark(const T &value, const bool doMark)
 | 
			
		||||
{
 | 
			
		||||
    if (gotValue(value))
 | 
			
		||||
    {
 | 
			
		||||
        isMarked_[value] = doMark;
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        HADRONS_ERROR(Range, "vertex does not exists");
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// complexity: O(V*log(V))
 | 
			
		||||
template <typename T>
 | 
			
		||||
void Graph<T>::markAll(const bool doMark)
 | 
			
		||||
{
 | 
			
		||||
    for (auto &v: isMarked_)
 | 
			
		||||
    {
 | 
			
		||||
        mark(v.first, doMark);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// complexity: O(log(V))
 | 
			
		||||
template <typename T>
 | 
			
		||||
void Graph<T>::unmark(const T &value)
 | 
			
		||||
{
 | 
			
		||||
    mark(value, false);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// complexity: O(V*log(V))
 | 
			
		||||
template <typename T>
 | 
			
		||||
void Graph<T>::unmarkAll(void)
 | 
			
		||||
{
 | 
			
		||||
    markAll(false);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// complexity: O(log(V))
 | 
			
		||||
template <typename T>
 | 
			
		||||
bool Graph<T>::isMarked(const T &value) const
 | 
			
		||||
{
 | 
			
		||||
    if (gotValue(value))
 | 
			
		||||
    {
 | 
			
		||||
        return isMarked_.at(value);
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        HADRONS_ERROR(Range, "vertex does not exists");
 | 
			
		||||
        
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// complexity: O(log(V))
 | 
			
		||||
template <typename T>
 | 
			
		||||
const T * Graph<T>::getFirstMarked(const bool isMarked) const
 | 
			
		||||
{
 | 
			
		||||
    auto pred = [&isMarked](const std::pair<T, bool> &v)
 | 
			
		||||
    {
 | 
			
		||||
        return (v.second == isMarked);
 | 
			
		||||
    };
 | 
			
		||||
    auto vIt = std::find_if(isMarked_.begin(), isMarked_.end(), pred);
 | 
			
		||||
    
 | 
			
		||||
    if (vIt != isMarked_.end())
 | 
			
		||||
    {
 | 
			
		||||
        return &(vIt->first);
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        return nullptr;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// complexity: O(log(V))
 | 
			
		||||
template <typename T>
 | 
			
		||||
template <typename Gen>
 | 
			
		||||
const T * Graph<T>::getRandomMarked(const bool isMarked, Gen &gen)
 | 
			
		||||
{
 | 
			
		||||
    auto pred = [&isMarked](const std::pair<T, bool> &v)
 | 
			
		||||
    {
 | 
			
		||||
        return (v.second == isMarked);
 | 
			
		||||
    };
 | 
			
		||||
    std::uniform_int_distribution<unsigned int> dis(0, size() - 1);
 | 
			
		||||
    auto                                        rIt = isMarked_.begin();
 | 
			
		||||
    
 | 
			
		||||
    std::advance(rIt, dis(gen));
 | 
			
		||||
    auto vIt = std::find_if(rIt, isMarked_.end(), pred);
 | 
			
		||||
    if (vIt != isMarked_.end())
 | 
			
		||||
    {
 | 
			
		||||
        return &(vIt->first);
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        vIt = std::find_if(isMarked_.begin(), rIt, pred);
 | 
			
		||||
        if (vIt != rIt)
 | 
			
		||||
        {
 | 
			
		||||
            return &(vIt->first);
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            return nullptr;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// complexity: O(log(V))
 | 
			
		||||
template <typename T>
 | 
			
		||||
const T * Graph<T>::getFirstUnmarked(void) const
 | 
			
		||||
{
 | 
			
		||||
    return getFirstMarked(false);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// complexity: O(log(V))
 | 
			
		||||
template <typename T>
 | 
			
		||||
template <typename Gen>
 | 
			
		||||
const T * Graph<T>::getRandomUnmarked(Gen &gen)
 | 
			
		||||
{
 | 
			
		||||
    return getRandomMarked(false, gen);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// prune marked/unmarked vertices //////////////////////////////////////////////
 | 
			
		||||
// complexity: O(V^2*log(V))
 | 
			
		||||
template <typename T>
 | 
			
		||||
void Graph<T>::removeMarked(const bool isMarked)
 | 
			
		||||
{
 | 
			
		||||
    auto isMarkedCopy = isMarked_;
 | 
			
		||||
    
 | 
			
		||||
    for (auto &v: isMarkedCopy)
 | 
			
		||||
    {
 | 
			
		||||
        if (v.second == isMarked)
 | 
			
		||||
        {
 | 
			
		||||
            removeVertex(v.first);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// complexity: O(V^2*log(V))
 | 
			
		||||
template <typename T>
 | 
			
		||||
void Graph<T>::removeUnmarked(void)
 | 
			
		||||
{
 | 
			
		||||
    removeMarked(false);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// depth-first search marking //////////////////////////////////////////////////
 | 
			
		||||
// complexity: O(V*log(V))
 | 
			
		||||
template <typename T>
 | 
			
		||||
void Graph<T>::depthFirstSearch(void)
 | 
			
		||||
{
 | 
			
		||||
    depthFirstSearch(isMarked_.begin()->first);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// complexity: O(V*log(V))
 | 
			
		||||
template <typename T>
 | 
			
		||||
void Graph<T>::depthFirstSearch(const T &root)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<T> adjacentVertex;
 | 
			
		||||
    
 | 
			
		||||
    mark(root);
 | 
			
		||||
    adjacentVertex = getAdjacentVertices(root);
 | 
			
		||||
    for (auto &v: adjacentVertex)
 | 
			
		||||
    {
 | 
			
		||||
        if (!isMarked(v))
 | 
			
		||||
        {
 | 
			
		||||
            depthFirstSearch(v);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// graph topological manipulations /////////////////////////////////////////////
 | 
			
		||||
// complexity: O(V*log(V))
 | 
			
		||||
template <typename T>
 | 
			
		||||
std::vector<T> Graph<T>::getAdjacentVertices(const T &value) const
 | 
			
		||||
{
 | 
			
		||||
    std::vector<T> adjacentVertex;
 | 
			
		||||
    
 | 
			
		||||
    auto pred = [&value](const Edge &e)
 | 
			
		||||
    {
 | 
			
		||||
        return ((e.first == value) or (e.second == value));
 | 
			
		||||
    };
 | 
			
		||||
    auto eIt = std::find_if(edgeSet_.begin(), edgeSet_.end(), pred);
 | 
			
		||||
    
 | 
			
		||||
    while (eIt != edgeSet_.end())
 | 
			
		||||
    {
 | 
			
		||||
        if (eIt->first == value)
 | 
			
		||||
        {
 | 
			
		||||
            adjacentVertex.push_back((*eIt).second);
 | 
			
		||||
        }
 | 
			
		||||
        else if (eIt->second == value)
 | 
			
		||||
        {
 | 
			
		||||
            adjacentVertex.push_back((*eIt).first);
 | 
			
		||||
        }
 | 
			
		||||
        eIt = std::find_if(++eIt, edgeSet_.end(), pred);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    return adjacentVertex;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// complexity: O(V*log(V))
 | 
			
		||||
template <typename T>
 | 
			
		||||
std::vector<T> Graph<T>::getChildren(const T &value) const
 | 
			
		||||
{
 | 
			
		||||
    std::vector<T> child;
 | 
			
		||||
    
 | 
			
		||||
    auto pred = [&value](const Edge &e)
 | 
			
		||||
    {
 | 
			
		||||
        return (e.first == value);
 | 
			
		||||
    };
 | 
			
		||||
    auto eIt = std::find_if(edgeSet_.begin(), edgeSet_.end(), pred);
 | 
			
		||||
    
 | 
			
		||||
    while (eIt != edgeSet_.end())
 | 
			
		||||
    {
 | 
			
		||||
        child.push_back((*eIt).second);
 | 
			
		||||
        eIt = std::find_if(++eIt, edgeSet_.end(), pred);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    return child;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// complexity: O(V*log(V))
 | 
			
		||||
template <typename T>
 | 
			
		||||
std::vector<T> Graph<T>::getParents(const T &value) const
 | 
			
		||||
{
 | 
			
		||||
    std::vector<T> parent;
 | 
			
		||||
    
 | 
			
		||||
    auto pred = [&value](const Edge &e)
 | 
			
		||||
    {
 | 
			
		||||
        return (e.second == value);
 | 
			
		||||
    };
 | 
			
		||||
    auto eIt = std::find_if(edgeSet_.begin(), edgeSet_.end(), pred);
 | 
			
		||||
    
 | 
			
		||||
    while (eIt != edgeSet_.end())
 | 
			
		||||
    {
 | 
			
		||||
        parent.push_back((*eIt).first);
 | 
			
		||||
        eIt = std::find_if(++eIt, edgeSet_.end(), pred);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    return parent;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// complexity: O(V^2*log(V))
 | 
			
		||||
template <typename T>
 | 
			
		||||
std::vector<T> Graph<T>::getRoots(void) const
 | 
			
		||||
{
 | 
			
		||||
    std::vector<T> root;
 | 
			
		||||
    
 | 
			
		||||
    for (auto &v: isMarked_)
 | 
			
		||||
    {
 | 
			
		||||
        auto parent = getParents(v.first);
 | 
			
		||||
        
 | 
			
		||||
        if (parent.size() == 0)
 | 
			
		||||
        {
 | 
			
		||||
            root.push_back(v.first);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    return root;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// complexity: O(V^2*log(V))
 | 
			
		||||
template <typename T>
 | 
			
		||||
std::vector<Graph<T>> Graph<T>::getConnectedComponents(void) const
 | 
			
		||||
{
 | 
			
		||||
    std::vector<Graph<T>> res;
 | 
			
		||||
    Graph<T>              copy(*this);
 | 
			
		||||
    
 | 
			
		||||
    while (copy.size() > 0)
 | 
			
		||||
    {
 | 
			
		||||
        copy.depthFirstSearch();
 | 
			
		||||
        res.push_back(copy);
 | 
			
		||||
        res.back().removeUnmarked();
 | 
			
		||||
        res.back().unmarkAll();
 | 
			
		||||
        copy.removeMarked();
 | 
			
		||||
        copy.unmarkAll();
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    return res;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// topological sort using a directed DFS algorithm
 | 
			
		||||
// complexity: O(V*log(V))
 | 
			
		||||
template <typename T>
 | 
			
		||||
std::vector<T> Graph<T>::topoSort(void)
 | 
			
		||||
{
 | 
			
		||||
    std::stack<T>     buf;
 | 
			
		||||
    std::vector<T>    res;
 | 
			
		||||
    const T           *vPt;
 | 
			
		||||
    std::map<T, bool> tmpMarked(isMarked_);
 | 
			
		||||
 | 
			
		||||
    // visit function
 | 
			
		||||
    std::function<void(const T &)> visit = [&](const T &v)
 | 
			
		||||
    {
 | 
			
		||||
        if (tmpMarked.at(v))
 | 
			
		||||
        {
 | 
			
		||||
            HADRONS_ERROR(Range, "cannot topologically sort a cyclic graph");
 | 
			
		||||
        }
 | 
			
		||||
        if (!isMarked(v))
 | 
			
		||||
        {
 | 
			
		||||
            std::vector<T> child = getChildren(v);
 | 
			
		||||
 | 
			
		||||
            tmpMarked[v] = true;
 | 
			
		||||
            for (auto &c: child)
 | 
			
		||||
            {
 | 
			
		||||
                visit(c);
 | 
			
		||||
            }
 | 
			
		||||
            mark(v);
 | 
			
		||||
            tmpMarked[v] = false;
 | 
			
		||||
            buf.push(v);
 | 
			
		||||
        }
 | 
			
		||||
    };
 | 
			
		||||
    
 | 
			
		||||
    // reset temporary marks
 | 
			
		||||
    for (auto &v: tmpMarked)
 | 
			
		||||
    {
 | 
			
		||||
        tmpMarked.at(v.first) = false;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    // loop on unmarked vertices
 | 
			
		||||
    unmarkAll();
 | 
			
		||||
    vPt = getFirstUnmarked();
 | 
			
		||||
    while (vPt)
 | 
			
		||||
    {
 | 
			
		||||
        visit(*vPt);
 | 
			
		||||
        vPt = getFirstUnmarked();
 | 
			
		||||
    }
 | 
			
		||||
    unmarkAll();
 | 
			
		||||
    
 | 
			
		||||
    // create result vector
 | 
			
		||||
    while (!buf.empty())
 | 
			
		||||
    {
 | 
			
		||||
        res.push_back(buf.top());
 | 
			
		||||
        buf.pop();
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    return res;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// random version of the topological sort
 | 
			
		||||
// complexity: O(V*log(V))
 | 
			
		||||
template <typename T>
 | 
			
		||||
template <typename Gen>
 | 
			
		||||
std::vector<T> Graph<T>::topoSort(Gen &gen)
 | 
			
		||||
{
 | 
			
		||||
    std::stack<T>     buf;
 | 
			
		||||
    std::vector<T>    res;
 | 
			
		||||
    const T           *vPt;
 | 
			
		||||
    std::map<T, bool> tmpMarked(isMarked_);
 | 
			
		||||
    
 | 
			
		||||
    // visit function
 | 
			
		||||
    std::function<void(const T &)> visit = [&](const T &v)
 | 
			
		||||
    {
 | 
			
		||||
        if (tmpMarked.at(v))
 | 
			
		||||
        {
 | 
			
		||||
            HADRONS_ERROR(Range, "cannot topologically sort a cyclic graph");
 | 
			
		||||
        }
 | 
			
		||||
        if (!isMarked(v))
 | 
			
		||||
        {
 | 
			
		||||
            std::vector<T> child = getChildren(v);
 | 
			
		||||
            
 | 
			
		||||
            tmpMarked[v] = true;
 | 
			
		||||
            std::shuffle(child.begin(), child.end(), gen);
 | 
			
		||||
            for (auto &c: child)
 | 
			
		||||
            {
 | 
			
		||||
                visit(c);
 | 
			
		||||
            }
 | 
			
		||||
            mark(v);
 | 
			
		||||
            tmpMarked[v] = false;
 | 
			
		||||
            buf.push(v);
 | 
			
		||||
        }
 | 
			
		||||
    };
 | 
			
		||||
    
 | 
			
		||||
    // reset temporary marks
 | 
			
		||||
    for (auto &v: tmpMarked)
 | 
			
		||||
    {
 | 
			
		||||
        tmpMarked.at(v.first) = false;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    // loop on unmarked vertices
 | 
			
		||||
    unmarkAll();
 | 
			
		||||
    vPt = getRandomUnmarked(gen);
 | 
			
		||||
    while (vPt)
 | 
			
		||||
    {
 | 
			
		||||
        visit(*vPt);
 | 
			
		||||
        vPt = getRandomUnmarked(gen);
 | 
			
		||||
    }
 | 
			
		||||
    unmarkAll();
 | 
			
		||||
    
 | 
			
		||||
    // create result vector
 | 
			
		||||
    while (!buf.empty())
 | 
			
		||||
    {
 | 
			
		||||
        res.push_back(buf.top());
 | 
			
		||||
        buf.pop();
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    return res;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// generate all possible topological sorts
 | 
			
		||||
// Y. L. Varol & D. Rotem, Comput. J. 24(1), pp. 83–84, 1981
 | 
			
		||||
// http://comjnl.oupjournals.org/cgi/doi/10.1093/comjnl/24.1.83
 | 
			
		||||
// complexity: O(V*log(V)) (from the paper, but really ?)
 | 
			
		||||
template <typename T>
 | 
			
		||||
std::vector<std::vector<T>> Graph<T>::allTopoSort(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::vector<T>>    res;
 | 
			
		||||
    std::map<T, std::map<T, bool>> iMat;
 | 
			
		||||
    
 | 
			
		||||
    // create incidence matrix
 | 
			
		||||
    for (auto &v1: isMarked_)
 | 
			
		||||
    for (auto &v2: isMarked_)
 | 
			
		||||
    {
 | 
			
		||||
        iMat[v1.first][v2.first] = false;
 | 
			
		||||
    }
 | 
			
		||||
    for (auto &v: isMarked_)
 | 
			
		||||
    {
 | 
			
		||||
        auto cVec = getChildren(v.first);
 | 
			
		||||
        
 | 
			
		||||
        for (auto &c: cVec)
 | 
			
		||||
        {
 | 
			
		||||
            iMat[v.first][c] = true;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    // generate initial topological sort
 | 
			
		||||
    res.push_back(topoSort());
 | 
			
		||||
    
 | 
			
		||||
    // generate all other topological sorts by permutation
 | 
			
		||||
    std::vector<T>            p = res[0];
 | 
			
		||||
    const unsigned int        n = size();
 | 
			
		||||
    std::vector<unsigned int> loc(n);
 | 
			
		||||
    unsigned int              i, k, k1;
 | 
			
		||||
    T                         obj_k, obj_k1;
 | 
			
		||||
    bool                      isFinal;
 | 
			
		||||
    
 | 
			
		||||
    for (unsigned int j = 0; j < n; ++j)
 | 
			
		||||
    {
 | 
			
		||||
        loc[j] = j;
 | 
			
		||||
    }
 | 
			
		||||
    i = 0;
 | 
			
		||||
    while (i < n-1)
 | 
			
		||||
    {
 | 
			
		||||
        k      = loc[i];
 | 
			
		||||
        k1     = k + 1;
 | 
			
		||||
        obj_k  = p[k];
 | 
			
		||||
        if (k1 >= n)
 | 
			
		||||
        {
 | 
			
		||||
            isFinal = true;
 | 
			
		||||
            obj_k1  = obj_k;
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            isFinal = false;
 | 
			
		||||
            obj_k1  = p[k1];
 | 
			
		||||
        }
 | 
			
		||||
        if (iMat[res[0][i]][obj_k1] or isFinal)
 | 
			
		||||
        {
 | 
			
		||||
            for (unsigned int l = k; l >= i + 1; --l)
 | 
			
		||||
            {
 | 
			
		||||
                p[l]   = p[l-1];
 | 
			
		||||
            }
 | 
			
		||||
            p[i]   = obj_k;
 | 
			
		||||
            loc[i] = i;
 | 
			
		||||
            i++;
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            p[k]   = obj_k1;
 | 
			
		||||
            p[k1]  = obj_k;
 | 
			
		||||
            loc[i] = k1;
 | 
			
		||||
            i      = 0;
 | 
			
		||||
            res.push_back(p);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    return res;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// build depedency matrix from topological sorts ///////////////////////////////
 | 
			
		||||
// complexity: something like O(V^2*log(V!))
 | 
			
		||||
template <typename T>
 | 
			
		||||
std::map<T, std::map<T, bool>>
 | 
			
		||||
makeDependencyMatrix(const std::vector<std::vector<T>> &topSort)
 | 
			
		||||
{
 | 
			
		||||
    std::map<T, std::map<T, bool>> m;
 | 
			
		||||
    const std::vector<T>           &vList = topSort[0];
 | 
			
		||||
    
 | 
			
		||||
    for (auto &v1: vList)
 | 
			
		||||
    for (auto &v2: vList)
 | 
			
		||||
    {
 | 
			
		||||
        bool dep = true;
 | 
			
		||||
        
 | 
			
		||||
        for (auto &t: topSort)
 | 
			
		||||
        {
 | 
			
		||||
            auto i1 = std::find(t.begin(), t.end(), v1);
 | 
			
		||||
            auto i2 = std::find(t.begin(), t.end(), v2);
 | 
			
		||||
            
 | 
			
		||||
            dep = dep and (i1 - i2 > 0);
 | 
			
		||||
            if (!dep) break;
 | 
			
		||||
        }
 | 
			
		||||
        m[v1][v2] = dep;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    return m;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
END_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
#endif // Hadrons_Graph_hpp_
 | 
			
		||||
							
								
								
									
										80
									
								
								Hadrons/HadronsXmlRun.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										80
									
								
								Hadrons/HadronsXmlRun.cc
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,80 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/HadronsXmlRun.cc
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Application.hpp>
 | 
			
		||||
 | 
			
		||||
using namespace Grid;
 | 
			
		||||
using namespace QCD;
 | 
			
		||||
using namespace Hadrons;
 | 
			
		||||
 | 
			
		||||
int main(int argc, char *argv[])
 | 
			
		||||
{
 | 
			
		||||
    // parse command line
 | 
			
		||||
    std::string parameterFileName, scheduleFileName = "";
 | 
			
		||||
    
 | 
			
		||||
    if (argc < 2)
 | 
			
		||||
    {
 | 
			
		||||
        std::cerr << "usage: " << argv[0] << " <parameter file> [<precomputed schedule>] [Grid options]";
 | 
			
		||||
        std::cerr << std::endl;
 | 
			
		||||
        std::exit(EXIT_FAILURE);
 | 
			
		||||
    }
 | 
			
		||||
    parameterFileName = argv[1];
 | 
			
		||||
    if (argc > 2)
 | 
			
		||||
    {
 | 
			
		||||
        if (argv[2][0] != '-')
 | 
			
		||||
        {
 | 
			
		||||
            scheduleFileName = argv[2];
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    // initialization
 | 
			
		||||
    Grid_init(&argc, &argv);
 | 
			
		||||
    
 | 
			
		||||
    // execution
 | 
			
		||||
    try
 | 
			
		||||
    {
 | 
			
		||||
        Application application(parameterFileName);
 | 
			
		||||
        
 | 
			
		||||
        application.parseParameterFile(parameterFileName);
 | 
			
		||||
        if (!scheduleFileName.empty())
 | 
			
		||||
        {
 | 
			
		||||
            application.loadSchedule(scheduleFileName);
 | 
			
		||||
        }
 | 
			
		||||
        application.run();
 | 
			
		||||
    }
 | 
			
		||||
    catch (const std::exception& e)
 | 
			
		||||
    {
 | 
			
		||||
        Exceptions::abort(e);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    // epilogue
 | 
			
		||||
    LOG(Message) << "Grid is finalizing now" << std::endl;
 | 
			
		||||
    Grid_finalize();
 | 
			
		||||
    
 | 
			
		||||
    return EXIT_SUCCESS;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										33
									
								
								Hadrons/Makefile.am
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								Hadrons/Makefile.am
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,33 @@
 | 
			
		||||
lib_LIBRARIES = libHadrons.a
 | 
			
		||||
bin_PROGRAMS  = HadronsXmlRun
 | 
			
		||||
 | 
			
		||||
include modules.inc
 | 
			
		||||
 | 
			
		||||
libHadrons_a_SOURCES = \
 | 
			
		||||
    $(modules_cc)      \
 | 
			
		||||
    Application.cc     \
 | 
			
		||||
    Environment.cc     \
 | 
			
		||||
	Exceptions.cc      \
 | 
			
		||||
    Global.cc          \
 | 
			
		||||
    Module.cc		   \
 | 
			
		||||
	VirtualMachine.cc
 | 
			
		||||
libHadrons_adir = $(includedir)/Hadrons
 | 
			
		||||
nobase_libHadrons_a_HEADERS = \
 | 
			
		||||
	$(modules_hpp)            \
 | 
			
		||||
	A2AVectors.hpp            \
 | 
			
		||||
	Application.hpp           \
 | 
			
		||||
	EigenPack.hpp             \
 | 
			
		||||
	Environment.hpp           \
 | 
			
		||||
	Exceptions.hpp            \
 | 
			
		||||
	Factory.hpp               \
 | 
			
		||||
	GeneticScheduler.hpp      \
 | 
			
		||||
	Global.hpp                \
 | 
			
		||||
	Graph.hpp                 \
 | 
			
		||||
	Module.hpp                \
 | 
			
		||||
	Modules.hpp               \
 | 
			
		||||
	ModuleFactory.hpp         \
 | 
			
		||||
	Solver.hpp                \
 | 
			
		||||
	VirtualMachine.hpp
 | 
			
		||||
 | 
			
		||||
HadronsXmlRun_SOURCES = HadronsXmlRun.cc
 | 
			
		||||
HadronsXmlRun_LDADD   = libHadrons.a -lGrid
 | 
			
		||||
							
								
								
									
										190
									
								
								Hadrons/Module.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										190
									
								
								Hadrons/Module.cc
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,190 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Module.cc
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Module.hpp>
 | 
			
		||||
 | 
			
		||||
using namespace Grid;
 | 
			
		||||
using namespace QCD;
 | 
			
		||||
using namespace Hadrons;
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                       ModuleBase implementation                            *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
// constructor /////////////////////////////////////////////////////////////////
 | 
			
		||||
ModuleBase::ModuleBase(const std::string name)
 | 
			
		||||
: name_(name)
 | 
			
		||||
{}
 | 
			
		||||
 | 
			
		||||
// access //////////////////////////////////////////////////////////////////////
 | 
			
		||||
std::string ModuleBase::getName(void) const
 | 
			
		||||
{
 | 
			
		||||
    return name_;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// get factory registration name if available
 | 
			
		||||
std::string ModuleBase::getRegisteredName(void)
 | 
			
		||||
{
 | 
			
		||||
    HADRONS_ERROR(Definition, "module '" + getName() + "' has no registered type"
 | 
			
		||||
                 + " in the factory");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// execution ///////////////////////////////////////////////////////////////////
 | 
			
		||||
void ModuleBase::operator()(void)
 | 
			
		||||
{
 | 
			
		||||
    resetTimers();
 | 
			
		||||
    startTimer("_total");
 | 
			
		||||
    startTimer("_setup");
 | 
			
		||||
    setup();
 | 
			
		||||
    stopTimer("_setup");
 | 
			
		||||
    startTimer("_execute");
 | 
			
		||||
    execute();
 | 
			
		||||
    stopAllTimers();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// timers //////////////////////////////////////////////////////////////////////
 | 
			
		||||
void ModuleBase::startTimer(const std::string &name)
 | 
			
		||||
{
 | 
			
		||||
    if (!name.empty())
 | 
			
		||||
    {
 | 
			
		||||
        timer_[name].Start();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
GridTime ModuleBase::getTimer(const std::string &name)
 | 
			
		||||
{
 | 
			
		||||
    GridTime t;
 | 
			
		||||
    
 | 
			
		||||
    if (!name.empty())
 | 
			
		||||
    {
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            bool running = timer_.at(name).isRunning();
 | 
			
		||||
 | 
			
		||||
            if (running) stopTimer(name);
 | 
			
		||||
            t = timer_.at(name).Elapsed();
 | 
			
		||||
            if (running) startTimer(name);
 | 
			
		||||
        }
 | 
			
		||||
        catch (std::out_of_range &)
 | 
			
		||||
        {
 | 
			
		||||
            t = GridTime::zero();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        t = GridTime::zero();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return t;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
double ModuleBase::getDTimer(const std::string &name)
 | 
			
		||||
{
 | 
			
		||||
    return static_cast<double>(getTimer(name).count());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ModuleBase::startCurrentTimer(const std::string &name)
 | 
			
		||||
{
 | 
			
		||||
    if (!name.empty())
 | 
			
		||||
    {
 | 
			
		||||
        stopCurrentTimer();
 | 
			
		||||
        startTimer(name);
 | 
			
		||||
        currentTimer_ = name;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ModuleBase::stopTimer(const std::string &name)
 | 
			
		||||
{
 | 
			
		||||
    if (timer_.at(name).isRunning())
 | 
			
		||||
    {
 | 
			
		||||
        timer_.at(name).Stop();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ModuleBase::stopCurrentTimer(void)
 | 
			
		||||
{
 | 
			
		||||
    if (!currentTimer_.empty())
 | 
			
		||||
    {
 | 
			
		||||
        stopTimer(currentTimer_);
 | 
			
		||||
        currentTimer_ = "";
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ModuleBase::stopAllTimers(void)
 | 
			
		||||
{
 | 
			
		||||
    for (auto &t: timer_)
 | 
			
		||||
    {
 | 
			
		||||
        stopTimer(t.first);
 | 
			
		||||
    }
 | 
			
		||||
    currentTimer_ = "";
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ModuleBase::resetTimers(void)
 | 
			
		||||
{
 | 
			
		||||
    timer_.clear();
 | 
			
		||||
    currentTimer_ = "";
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::map<std::string, GridTime> ModuleBase::getTimings(void)
 | 
			
		||||
{
 | 
			
		||||
    std::map<std::string, GridTime> timing;
 | 
			
		||||
 | 
			
		||||
    for (auto &t: timer_)
 | 
			
		||||
    {
 | 
			
		||||
        timing[t.first] = t.second.Elapsed();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return timing;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::string ModuleBase::makeSeedString(void)
 | 
			
		||||
{
 | 
			
		||||
    std::string seed;
 | 
			
		||||
 | 
			
		||||
    if (!vm().getRunId().empty())
 | 
			
		||||
    {
 | 
			
		||||
        seed += vm().getRunId() + "-";
 | 
			
		||||
    }
 | 
			
		||||
    seed += getName() + "-" + std::to_string(vm().getTrajectory());
 | 
			
		||||
 | 
			
		||||
    return seed;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
GridParallelRNG & ModuleBase::rng4d(void)
 | 
			
		||||
{
 | 
			
		||||
    auto &r = *env().get4dRng();
 | 
			
		||||
 | 
			
		||||
    if (makeSeedString() != seed_)
 | 
			
		||||
    {
 | 
			
		||||
        seed_ = makeSeedString();
 | 
			
		||||
        LOG(Message) << "Seeding 4D RNG " << &r << " with string '" 
 | 
			
		||||
                     << seed_ << "'" << std::endl;
 | 
			
		||||
        r.SeedUniqueString(seed_);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return r;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										277
									
								
								Hadrons/Module.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										277
									
								
								Hadrons/Module.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,277 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Module.hpp
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
 | 
			
		||||
#ifndef Hadrons_Module_hpp_
 | 
			
		||||
#define Hadrons_Module_hpp_
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Global.hpp>
 | 
			
		||||
#include <Hadrons/VirtualMachine.hpp>
 | 
			
		||||
 | 
			
		||||
BEGIN_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
// module registration macros
 | 
			
		||||
#define MODULE_REGISTER(mod, base, ns)\
 | 
			
		||||
class mod: public base\
 | 
			
		||||
{\
 | 
			
		||||
public:\
 | 
			
		||||
    typedef base Base;\
 | 
			
		||||
    using Base::Base;\
 | 
			
		||||
    virtual std::string getRegisteredName(void)\
 | 
			
		||||
    {\
 | 
			
		||||
        return std::string(#ns "::" #mod);\
 | 
			
		||||
    }\
 | 
			
		||||
};\
 | 
			
		||||
class ns##mod##ModuleRegistrar\
 | 
			
		||||
{\
 | 
			
		||||
public:\
 | 
			
		||||
    ns##mod##ModuleRegistrar(void)\
 | 
			
		||||
    {\
 | 
			
		||||
        ModuleFactory &modFac = ModuleFactory::getInstance();\
 | 
			
		||||
        modFac.registerBuilder(#ns "::" #mod, [&](const std::string name)\
 | 
			
		||||
                              {\
 | 
			
		||||
                                  return std::unique_ptr<ns::mod>(new ns::mod(name));\
 | 
			
		||||
                              });\
 | 
			
		||||
    }\
 | 
			
		||||
};\
 | 
			
		||||
static ns##mod##ModuleRegistrar ns##mod##ModuleRegistrarInstance;
 | 
			
		||||
 | 
			
		||||
#define MODULE_REGISTER_TMP(mod, base, ns)\
 | 
			
		||||
extern template class base;\
 | 
			
		||||
MODULE_REGISTER(mod, ARG(base), ns);
 | 
			
		||||
 | 
			
		||||
#define ARG(...) __VA_ARGS__
 | 
			
		||||
#define MACRO_REDIRECT(arg1, arg2, arg3, macro, ...) macro
 | 
			
		||||
 | 
			
		||||
#define envGet(type, name)\
 | 
			
		||||
*env().template getObject<type>(name)
 | 
			
		||||
 | 
			
		||||
#define envGetDerived(base, type, name)\
 | 
			
		||||
*env().template getDerivedObject<base, type>(name)
 | 
			
		||||
 | 
			
		||||
#define envGetTmp(type, var)\
 | 
			
		||||
type &var = *env().template getObject<type>(getName() + "_tmp_" + #var)
 | 
			
		||||
 | 
			
		||||
#define envHasType(type, name)\
 | 
			
		||||
env().template isObjectOfType<type>(name)
 | 
			
		||||
 | 
			
		||||
#define envCreate(type, name, Ls, ...)\
 | 
			
		||||
env().template createObject<type>(name, Environment::Storage::object, Ls, __VA_ARGS__)
 | 
			
		||||
 | 
			
		||||
#define envCreateDerived(base, type, name, Ls, ...)\
 | 
			
		||||
env().template createDerivedObject<base, type>(name, Environment::Storage::object, Ls, __VA_ARGS__)
 | 
			
		||||
 | 
			
		||||
#define envCreateLat4(type, name)\
 | 
			
		||||
envCreate(type, name, 1, env().getGrid())
 | 
			
		||||
 | 
			
		||||
#define envCreateLat5(type, name, Ls)\
 | 
			
		||||
envCreate(type, name, Ls, env().getGrid(Ls))
 | 
			
		||||
 | 
			
		||||
#define envCreateLat(...)\
 | 
			
		||||
MACRO_REDIRECT(__VA_ARGS__, envCreateLat5, envCreateLat4)(__VA_ARGS__)
 | 
			
		||||
 | 
			
		||||
#define envCache(type, name, Ls, ...)\
 | 
			
		||||
env().template createObject<type>(name, Environment::Storage::cache, Ls, __VA_ARGS__)
 | 
			
		||||
 | 
			
		||||
#define envCacheLat4(type, name)\
 | 
			
		||||
envCache(type, name, 1, env().getGrid())
 | 
			
		||||
 | 
			
		||||
#define envCacheLat5(type, name, Ls)\
 | 
			
		||||
envCache(type, name, Ls, env().getGrid(Ls))
 | 
			
		||||
 | 
			
		||||
#define envCacheLat(...)\
 | 
			
		||||
MACRO_REDIRECT(__VA_ARGS__, envCacheLat5, envCacheLat4)(__VA_ARGS__)
 | 
			
		||||
 | 
			
		||||
#define envTmp(type, name, Ls, ...)\
 | 
			
		||||
env().template createObject<type>(getName() + "_tmp_" + name,         \
 | 
			
		||||
                                  Environment::Storage::temporary, Ls, __VA_ARGS__)
 | 
			
		||||
 | 
			
		||||
#define envTmpLat4(type, name)\
 | 
			
		||||
envTmp(type, name, 1, env().getGrid())
 | 
			
		||||
 | 
			
		||||
#define envTmpLat5(type, name, Ls)\
 | 
			
		||||
envTmp(type, name, Ls, env().getGrid(Ls))
 | 
			
		||||
 | 
			
		||||
#define envTmpLat(...)\
 | 
			
		||||
MACRO_REDIRECT(__VA_ARGS__, envTmpLat5, envTmpLat4)(__VA_ARGS__)
 | 
			
		||||
 | 
			
		||||
#define saveResult(ioStem, name, result)\
 | 
			
		||||
if (env().getGrid()->IsBoss() and !ioStem.empty())\
 | 
			
		||||
{\
 | 
			
		||||
    makeFileDir(ioStem, env().getGrid());\
 | 
			
		||||
    {\
 | 
			
		||||
        ResultWriter _writer(RESULT_FILE_NAME(ioStem));\
 | 
			
		||||
        write(_writer, name, result);\
 | 
			
		||||
    }\
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                            Module class                                    *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
// base class
 | 
			
		||||
class ModuleBase
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    // constructor
 | 
			
		||||
    ModuleBase(const std::string name);
 | 
			
		||||
    // destructor
 | 
			
		||||
    virtual ~ModuleBase(void) = default;
 | 
			
		||||
    // access
 | 
			
		||||
    std::string getName(void) const;
 | 
			
		||||
    // get factory registration name if available
 | 
			
		||||
    virtual std::string getRegisteredName(void);
 | 
			
		||||
    // dependencies/products
 | 
			
		||||
    virtual std::vector<std::string> getInput(void) = 0;
 | 
			
		||||
    virtual std::vector<std::string> getReference(void)
 | 
			
		||||
    {
 | 
			
		||||
        return std::vector<std::string>(0);
 | 
			
		||||
    };
 | 
			
		||||
    virtual std::vector<std::string> getOutput(void) = 0;
 | 
			
		||||
    // parse parameters
 | 
			
		||||
    virtual void parseParameters(XmlReader &reader, const std::string name) = 0;
 | 
			
		||||
    virtual void saveParameters(XmlWriter &writer, const std::string name) = 0;
 | 
			
		||||
    // parameter string
 | 
			
		||||
    virtual std::string parString(void) const = 0;
 | 
			
		||||
    // setup
 | 
			
		||||
    virtual void setup(void) {};
 | 
			
		||||
    virtual void execute(void) = 0;
 | 
			
		||||
    // execution
 | 
			
		||||
    void operator()(void);
 | 
			
		||||
    // timers
 | 
			
		||||
    void                            startTimer(const std::string &name);
 | 
			
		||||
    GridTime                        getTimer(const std::string &name);
 | 
			
		||||
    double                          getDTimer(const std::string &name);
 | 
			
		||||
    void                            startCurrentTimer(const std::string &name);
 | 
			
		||||
    void                            stopTimer(const std::string &name);
 | 
			
		||||
    void                            stopCurrentTimer(void);
 | 
			
		||||
    void                            stopAllTimers(void);
 | 
			
		||||
    void                            resetTimers(void);
 | 
			
		||||
    std::map<std::string, GridTime> getTimings(void);
 | 
			
		||||
protected:
 | 
			
		||||
    // environment shortcut
 | 
			
		||||
    DEFINE_ENV_ALIAS;
 | 
			
		||||
    // virtual machine shortcut
 | 
			
		||||
    DEFINE_VM_ALIAS;
 | 
			
		||||
    // RNG seeded from module string
 | 
			
		||||
    GridParallelRNG &rng4d(void);
 | 
			
		||||
private:
 | 
			
		||||
    std::string makeSeedString(void);
 | 
			
		||||
private:
 | 
			
		||||
    std::string                          name_, currentTimer_, seed_;
 | 
			
		||||
    std::map<std::string, GridStopWatch> timer_; 
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// derived class, templating the parameter class
 | 
			
		||||
template <typename P>
 | 
			
		||||
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);
 | 
			
		||||
    virtual void saveParameters(XmlWriter &writer, const std::string name);
 | 
			
		||||
    // parameter string
 | 
			
		||||
    virtual std::string parString(void) const;
 | 
			
		||||
    // parameter access
 | 
			
		||||
    const P &   par(void) const;
 | 
			
		||||
    void        setPar(const P &par);
 | 
			
		||||
private:
 | 
			
		||||
    P par_;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// no parameter type
 | 
			
		||||
class NoPar {};
 | 
			
		||||
 | 
			
		||||
template <>
 | 
			
		||||
class Module<NoPar>: public ModuleBase
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    // constructor
 | 
			
		||||
    Module(const std::string name): ModuleBase(name) {};
 | 
			
		||||
    // destructor
 | 
			
		||||
    virtual ~Module(void) = default;
 | 
			
		||||
    // parse parameters (do nothing)
 | 
			
		||||
    virtual void parseParameters(XmlReader &reader, const std::string name) {};
 | 
			
		||||
    virtual void saveParameters(XmlWriter &writer, const std::string name)
 | 
			
		||||
    {
 | 
			
		||||
        push(writer, "options");
 | 
			
		||||
        pop(writer);
 | 
			
		||||
    };
 | 
			
		||||
    // parameter string (empty)
 | 
			
		||||
    virtual std::string parString(void) const {return "";};
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                           Template implementation                          *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
template <typename P>
 | 
			
		||||
Module<P>::Module(const std::string name)
 | 
			
		||||
: ModuleBase(name)
 | 
			
		||||
{}
 | 
			
		||||
 | 
			
		||||
template <typename P>
 | 
			
		||||
void Module<P>::parseParameters(XmlReader &reader, const std::string name)
 | 
			
		||||
{
 | 
			
		||||
    read(reader, name, par_);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename P>
 | 
			
		||||
void Module<P>::saveParameters(XmlWriter &writer, const std::string name)
 | 
			
		||||
{
 | 
			
		||||
    write(writer, name, par_);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename P>
 | 
			
		||||
std::string Module<P>::parString(void) const
 | 
			
		||||
{
 | 
			
		||||
    XmlWriter writer("", "");
 | 
			
		||||
 | 
			
		||||
    write(writer, par_.SerialisableClassName(), par_);
 | 
			
		||||
 | 
			
		||||
    return writer.string();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename P>
 | 
			
		||||
const P & Module<P>::par(void) const
 | 
			
		||||
{
 | 
			
		||||
    return par_;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename P>
 | 
			
		||||
void Module<P>::setPar(const P &par)
 | 
			
		||||
{
 | 
			
		||||
    par_ = par;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
END_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
#endif // Hadrons_Module_hpp_
 | 
			
		||||
							
								
								
									
										48
									
								
								Hadrons/ModuleFactory.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								Hadrons/ModuleFactory.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,48 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/ModuleFactory.hpp
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
 | 
			
		||||
#ifndef Hadrons_ModuleFactory_hpp_
 | 
			
		||||
#define Hadrons_ModuleFactory_hpp_
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Global.hpp>
 | 
			
		||||
#include <Hadrons/Factory.hpp>
 | 
			
		||||
#include <Hadrons/Module.hpp>
 | 
			
		||||
 | 
			
		||||
BEGIN_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                            ModuleFactory                                   *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
class ModuleFactory: public Factory<ModuleBase>
 | 
			
		||||
{
 | 
			
		||||
    SINGLETON_DEFCTOR(ModuleFactory)
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
END_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
#endif // Hadrons_ModuleFactory_hpp_
 | 
			
		||||
							
								
								
									
										96
									
								
								Hadrons/Modules.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										96
									
								
								Hadrons/Modules.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,96 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules.hpp
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
Author: Antonin Portelli <antonin.portelli@me.com>
 | 
			
		||||
Author: Guido Cossu <guido.cossu@ed.ac.uk>
 | 
			
		||||
Author: James Harrison <jch1g10@soton.ac.uk>
 | 
			
		||||
Author: Lanny91 <andrew.lawson@gmail.com>
 | 
			
		||||
Author: Peter Boyle <paboyle@ph.ed.ac.uk>
 | 
			
		||||
Author: Vera Guelpers <vmg1n14@soton.ac.uk>
 | 
			
		||||
Author: fionnoh <fionnoh@gmail.com>
 | 
			
		||||
Author: pretidav <david.preti@csic.es>
 | 
			
		||||
 | 
			
		||||
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 */
 | 
			
		||||
#include <Hadrons/Modules/MContraction/Baryon.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MContraction/A2AMesonField.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MContraction/A2AMesonFieldKernels.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MContraction/Meson.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MContraction/WeakHamiltonian.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MContraction/WeakHamiltonianNonEye.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MContraction/DiscLoop.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MContraction/WeakNeutral4ptDisc.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MContraction/Gamma3pt.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MContraction/WardIdentity.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MContraction/WeakHamiltonianEye.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MFermion/FreeProp.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MFermion/GaugeProp.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MSource/SeqGamma.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MSource/Point.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MSource/Wall.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MSource/Z2.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MSource/SeqConserved.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MSink/Smear.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MSink/Point.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MSolver/LocalCoherenceLanczos.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MSolver/RBPrecCG.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MSolver/A2AVectors.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MGauge/UnitEm.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MGauge/StoutSmearing.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MGauge/Unit.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MGauge/Random.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MGauge/FundtoHirep.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MGauge/StochEm.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MNoise/TimeDilutedSpinColorDiagonal.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MUtilities/RandomVectors.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MUtilities/TestSeqGamma.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MUtilities/TestSeqConserved.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MLoop/NoiseLoop.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MScalar/FreeProp.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MScalar/VPCounterTerms.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MScalar/ScalarVP.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MScalar/Scalar.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MScalar/ChargedProp.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MAction/DWF.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MAction/MobiusDWF.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MAction/Wilson.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MAction/WilsonClover.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MAction/ZMobiusDWF.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MAction/ScaledDWF.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MScalarSUN/StochFreeField.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MScalarSUN/TwoPointNPR.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MScalarSUN/ShiftProbe.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MScalarSUN/Div.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MScalarSUN/TimeMomProbe.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MScalarSUN/TrMag.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MScalarSUN/EMT.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MScalarSUN/TwoPoint.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MScalarSUN/TrPhi.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MScalarSUN/Utils.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MScalarSUN/TransProj.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MScalarSUN/Grad.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MScalarSUN/TrKinetic.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MIO/LoadEigenPack.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MIO/LoadNersc.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MIO/LoadCoarseEigenPack.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MIO/LoadBinary.hpp>
 | 
			
		||||
							
								
								
									
										35
									
								
								Hadrons/Modules/MAction/DWF.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								Hadrons/Modules/MAction/DWF.cc
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,35 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MAction/DWF.cc
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
#include <Hadrons/Modules/MAction/DWF.hpp>
 | 
			
		||||
 | 
			
		||||
using namespace Grid;
 | 
			
		||||
using namespace Hadrons;
 | 
			
		||||
using namespace MAction;
 | 
			
		||||
 | 
			
		||||
template class Grid::Hadrons::MAction::TDWF<FIMPL>;
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										136
									
								
								Hadrons/Modules/MAction/DWF.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										136
									
								
								Hadrons/Modules/MAction/DWF.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,136 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MAction/DWF.hpp
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
Author: Antonin Portelli <antonin.portelli@me.com>
 | 
			
		||||
Author: Lanny91 <andrew.lawson@gmail.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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
 | 
			
		||||
#ifndef Hadrons_MAction_DWF_hpp_
 | 
			
		||||
#define Hadrons_MAction_DWF_hpp_
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Global.hpp>
 | 
			
		||||
#include <Hadrons/Module.hpp>
 | 
			
		||||
#include <Hadrons/ModuleFactory.hpp>
 | 
			
		||||
 | 
			
		||||
BEGIN_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                     Domain wall quark action                               *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
BEGIN_MODULE_NAMESPACE(MAction)
 | 
			
		||||
 | 
			
		||||
class DWFPar: Serializable
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    GRID_SERIALIZABLE_CLASS_MEMBERS(DWFPar,
 | 
			
		||||
                                    std::string, gauge,
 | 
			
		||||
                                    unsigned int, Ls,
 | 
			
		||||
                                    double      , mass,
 | 
			
		||||
                                    double      , M5,
 | 
			
		||||
                                    std::string , boundary);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
class TDWF: public Module<DWFPar>
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    FG_TYPE_ALIASES(FImpl,);
 | 
			
		||||
public:
 | 
			
		||||
    // constructor
 | 
			
		||||
    TDWF(const std::string name);
 | 
			
		||||
    // destructor
 | 
			
		||||
    virtual ~TDWF(void) {};
 | 
			
		||||
    // dependency relation
 | 
			
		||||
    virtual std::vector<std::string> getInput(void);
 | 
			
		||||
    virtual std::vector<std::string> getOutput(void);
 | 
			
		||||
protected:
 | 
			
		||||
    // setup
 | 
			
		||||
    virtual void setup(void);
 | 
			
		||||
    // execution
 | 
			
		||||
    virtual void execute(void);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
extern template class TDWF<FIMPL>;
 | 
			
		||||
MODULE_REGISTER_TMP(DWF, TDWF<FIMPL>, MAction);
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                        DWF template implementation                         *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
// constructor /////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
TDWF<FImpl>::TDWF(const std::string name)
 | 
			
		||||
: Module<DWFPar>(name)
 | 
			
		||||
{}
 | 
			
		||||
 | 
			
		||||
// dependencies/products ///////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
std::vector<std::string> TDWF<FImpl>::getInput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> in = {par().gauge};
 | 
			
		||||
    
 | 
			
		||||
    return in;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
std::vector<std::string> TDWF<FImpl>::getOutput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> out = {getName()};
 | 
			
		||||
    
 | 
			
		||||
    return out;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// setup ///////////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
void TDWF<FImpl>::setup(void)
 | 
			
		||||
{
 | 
			
		||||
    LOG(Message) << "Setting up domain wall fermion matrix with m= "
 | 
			
		||||
                 << par().mass << ", M5= " << par().M5 << " and Ls= "
 | 
			
		||||
                 << par().Ls << " using gauge field '" << par().gauge << "'"
 | 
			
		||||
                 << std::endl;
 | 
			
		||||
    LOG(Message) << "Fermion boundary conditions: " << par().boundary
 | 
			
		||||
                 << std::endl;
 | 
			
		||||
                 
 | 
			
		||||
    env().createGrid(par().Ls);
 | 
			
		||||
    auto &U    = envGet(LatticeGaugeField, par().gauge);
 | 
			
		||||
    auto &g4   = *env().getGrid();
 | 
			
		||||
    auto &grb4 = *env().getRbGrid();
 | 
			
		||||
    auto &g5   = *env().getGrid(par().Ls);
 | 
			
		||||
    auto &grb5 = *env().getRbGrid(par().Ls);
 | 
			
		||||
    std::vector<Complex> boundary = strToVec<Complex>(par().boundary);
 | 
			
		||||
    typename DomainWallFermion<FImpl>::ImplParams implParams(boundary);
 | 
			
		||||
    envCreateDerived(FMat, DomainWallFermion<FImpl>, getName(), par().Ls, U, g5,
 | 
			
		||||
                     grb5, g4, grb4, par().mass, par().M5, implParams);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// execution ///////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
void TDWF<FImpl>::execute(void)
 | 
			
		||||
{}
 | 
			
		||||
 | 
			
		||||
END_MODULE_NAMESPACE
 | 
			
		||||
 | 
			
		||||
END_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
#endif // Hadrons_MAction_DWF_hpp_
 | 
			
		||||
							
								
								
									
										34
									
								
								Hadrons/Modules/MAction/MobiusDWF.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								Hadrons/Modules/MAction/MobiusDWF.cc
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,34 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MAction/MobiusDWF.cc
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
#include <Hadrons/Modules/MAction/MobiusDWF.hpp>
 | 
			
		||||
 | 
			
		||||
using namespace Grid;
 | 
			
		||||
using namespace Hadrons;
 | 
			
		||||
using namespace MAction;
 | 
			
		||||
 | 
			
		||||
template class Grid::Hadrons::MAction::TMobiusDWF<FIMPL>;
 | 
			
		||||
							
								
								
									
										136
									
								
								Hadrons/Modules/MAction/MobiusDWF.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										136
									
								
								Hadrons/Modules/MAction/MobiusDWF.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,136 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MAction/MobiusDWF.hpp
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
#ifndef Hadrons_MAction_MobiusDWF_hpp_
 | 
			
		||||
#define Hadrons_MAction_MobiusDWF_hpp_
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Global.hpp>
 | 
			
		||||
#include <Hadrons/Module.hpp>
 | 
			
		||||
#include <Hadrons/ModuleFactory.hpp>
 | 
			
		||||
 | 
			
		||||
BEGIN_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                      Mobius domain-wall fermion action                     *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
BEGIN_MODULE_NAMESPACE(MAction)
 | 
			
		||||
 | 
			
		||||
class MobiusDWFPar: Serializable
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    GRID_SERIALIZABLE_CLASS_MEMBERS(MobiusDWFPar,
 | 
			
		||||
                                    std::string , gauge,
 | 
			
		||||
                                    unsigned int, Ls,
 | 
			
		||||
                                    double      , mass,
 | 
			
		||||
                                    double      , M5,
 | 
			
		||||
                                    double      , b,
 | 
			
		||||
                                    double      , c,
 | 
			
		||||
                                    std::string , boundary);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
class TMobiusDWF: public Module<MobiusDWFPar>
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    FG_TYPE_ALIASES(FImpl,);
 | 
			
		||||
public:
 | 
			
		||||
    // constructor
 | 
			
		||||
    TMobiusDWF(const std::string name);
 | 
			
		||||
    // destructor
 | 
			
		||||
    virtual ~TMobiusDWF(void) {};
 | 
			
		||||
    // dependency relation
 | 
			
		||||
    virtual std::vector<std::string> getInput(void);
 | 
			
		||||
    virtual std::vector<std::string> getOutput(void);
 | 
			
		||||
    // setup
 | 
			
		||||
    virtual void setup(void);
 | 
			
		||||
    // execution
 | 
			
		||||
    virtual void execute(void);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
MODULE_REGISTER_TMP(MobiusDWF, TMobiusDWF<FIMPL>, MAction);
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                      TMobiusDWF implementation                             *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
// constructor /////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
TMobiusDWF<FImpl>::TMobiusDWF(const std::string name)
 | 
			
		||||
: Module<MobiusDWFPar>(name)
 | 
			
		||||
{}
 | 
			
		||||
 | 
			
		||||
// dependencies/products ///////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
std::vector<std::string> TMobiusDWF<FImpl>::getInput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> in = {par().gauge};
 | 
			
		||||
    
 | 
			
		||||
    return in;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
std::vector<std::string> TMobiusDWF<FImpl>::getOutput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> out = {getName()};
 | 
			
		||||
    
 | 
			
		||||
    return out;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// setup ///////////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
void TMobiusDWF<FImpl>::setup(void)
 | 
			
		||||
{
 | 
			
		||||
    LOG(Message) << "Setting up Mobius domain wall fermion matrix with m= "
 | 
			
		||||
                 << par().mass << ", M5= " << par().M5 << ", Ls= " << par().Ls 
 | 
			
		||||
                 << ", b= " << par().b << ", c= " << par().c
 | 
			
		||||
                 << " using gauge field '" << par().gauge << "'"
 | 
			
		||||
                 << std::endl;
 | 
			
		||||
    LOG(Message) << "Fermion boundary conditions: " << par().boundary
 | 
			
		||||
                 << std::endl;
 | 
			
		||||
 | 
			
		||||
    env().createGrid(par().Ls);
 | 
			
		||||
    auto &U    = envGet(LatticeGaugeField, par().gauge);
 | 
			
		||||
    auto &g4   = *env().getGrid();
 | 
			
		||||
    auto &grb4 = *env().getRbGrid();
 | 
			
		||||
    auto &g5   = *env().getGrid(par().Ls);
 | 
			
		||||
    auto &grb5 = *env().getRbGrid(par().Ls);
 | 
			
		||||
    std::vector<Complex> boundary = strToVec<Complex>(par().boundary);
 | 
			
		||||
    typename MobiusFermion<FImpl>::ImplParams implParams(boundary);
 | 
			
		||||
    envCreateDerived(FMat, MobiusFermion<FImpl>, getName(), par().Ls, U, g5,
 | 
			
		||||
                     grb5, g4, grb4, par().mass, par().M5, par().b, par().c,
 | 
			
		||||
                     implParams);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// execution ///////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
void TMobiusDWF<FImpl>::execute(void)
 | 
			
		||||
{}
 | 
			
		||||
 | 
			
		||||
END_MODULE_NAMESPACE
 | 
			
		||||
 | 
			
		||||
END_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
#endif // Hadrons_MAction_MobiusDWF_hpp_
 | 
			
		||||
							
								
								
									
										34
									
								
								Hadrons/Modules/MAction/ScaledDWF.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								Hadrons/Modules/MAction/ScaledDWF.cc
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,34 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MAction/ScaledDWF.cc
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
#include <Hadrons/Modules/MAction/ScaledDWF.hpp>
 | 
			
		||||
 | 
			
		||||
using namespace Grid;
 | 
			
		||||
using namespace Hadrons;
 | 
			
		||||
using namespace MAction;
 | 
			
		||||
 | 
			
		||||
template class Grid::Hadrons::MAction::TScaledDWF<FIMPL>;
 | 
			
		||||
							
								
								
									
										135
									
								
								Hadrons/Modules/MAction/ScaledDWF.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										135
									
								
								Hadrons/Modules/MAction/ScaledDWF.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,135 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MAction/ScaledDWF.hpp
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
#ifndef Hadrons_MAction_ScaledDWF_hpp_
 | 
			
		||||
#define Hadrons_MAction_ScaledDWF_hpp_
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Global.hpp>
 | 
			
		||||
#include <Hadrons/Module.hpp>
 | 
			
		||||
#include <Hadrons/ModuleFactory.hpp>
 | 
			
		||||
 | 
			
		||||
BEGIN_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                      Scaled domain wall fermion                            *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
BEGIN_MODULE_NAMESPACE(MAction)
 | 
			
		||||
 | 
			
		||||
class ScaledDWFPar: Serializable
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    GRID_SERIALIZABLE_CLASS_MEMBERS(ScaledDWFPar,
 | 
			
		||||
                                    std::string , gauge,
 | 
			
		||||
                                    unsigned int, Ls,
 | 
			
		||||
                                    double      , mass,
 | 
			
		||||
                                    double      , M5,
 | 
			
		||||
                                    double      , scale,
 | 
			
		||||
                                    std::string , boundary);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
class TScaledDWF: public Module<ScaledDWFPar>
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    FG_TYPE_ALIASES(FImpl,);
 | 
			
		||||
public:
 | 
			
		||||
    // constructor
 | 
			
		||||
    TScaledDWF(const std::string name);
 | 
			
		||||
    // destructor
 | 
			
		||||
    virtual ~TScaledDWF(void) {};
 | 
			
		||||
    // dependency relation
 | 
			
		||||
    virtual std::vector<std::string> getInput(void);
 | 
			
		||||
    virtual std::vector<std::string> getOutput(void);
 | 
			
		||||
    // setup
 | 
			
		||||
    virtual void setup(void);
 | 
			
		||||
    // execution
 | 
			
		||||
    virtual void execute(void);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
MODULE_REGISTER_TMP(ScaledDWF, TScaledDWF<FIMPL>, MAction);
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                      TScaledDWF implementation                             *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
// constructor /////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
TScaledDWF<FImpl>::TScaledDWF(const std::string name)
 | 
			
		||||
: Module<ScaledDWFPar>(name)
 | 
			
		||||
{}
 | 
			
		||||
 | 
			
		||||
// dependencies/products ///////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
std::vector<std::string> TScaledDWF<FImpl>::getInput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> in = {par().gauge};
 | 
			
		||||
    
 | 
			
		||||
    return in;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
std::vector<std::string> TScaledDWF<FImpl>::getOutput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> out = {getName()};
 | 
			
		||||
    
 | 
			
		||||
    return out;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// setup ///////////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
void TScaledDWF<FImpl>::setup(void)
 | 
			
		||||
{
 | 
			
		||||
    LOG(Message) << "Setting up scaled domain wall fermion matrix with m= "
 | 
			
		||||
                 << par().mass << ", M5= " << par().M5 << ", Ls= " << par().Ls 
 | 
			
		||||
                 << ", scale= " << par().scale
 | 
			
		||||
                 << " using gauge field '" << par().gauge << "'"
 | 
			
		||||
                 << std::endl;
 | 
			
		||||
    LOG(Message) << "Fermion boundary conditions: " << par().boundary
 | 
			
		||||
                 << std::endl;
 | 
			
		||||
 | 
			
		||||
    env().createGrid(par().Ls);
 | 
			
		||||
    auto &U    = envGet(LatticeGaugeField, par().gauge);
 | 
			
		||||
    auto &g4   = *env().getGrid();
 | 
			
		||||
    auto &grb4 = *env().getRbGrid();
 | 
			
		||||
    auto &g5   = *env().getGrid(par().Ls);
 | 
			
		||||
    auto &grb5 = *env().getRbGrid(par().Ls);
 | 
			
		||||
    std::vector<Complex> boundary = strToVec<Complex>(par().boundary);
 | 
			
		||||
    typename MobiusFermion<FImpl>::ImplParams implParams(boundary);
 | 
			
		||||
    envCreateDerived(FMat, ScaledShamirFermion<FImpl>, getName(), par().Ls, U, g5,
 | 
			
		||||
                     grb5, g4, grb4, par().mass, par().M5, par().scale,
 | 
			
		||||
                     implParams);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// execution ///////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
void TScaledDWF<FImpl>::execute(void)
 | 
			
		||||
{}
 | 
			
		||||
 | 
			
		||||
END_MODULE_NAMESPACE
 | 
			
		||||
 | 
			
		||||
END_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
#endif // Hadrons_MAction_ScaledDWF_hpp_
 | 
			
		||||
							
								
								
									
										35
									
								
								Hadrons/Modules/MAction/Wilson.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								Hadrons/Modules/MAction/Wilson.cc
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,35 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MAction/Wilson.cc
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
#include <Hadrons/Modules/MAction/Wilson.hpp>
 | 
			
		||||
 | 
			
		||||
using namespace Grid;
 | 
			
		||||
using namespace Hadrons;
 | 
			
		||||
using namespace MAction;
 | 
			
		||||
 | 
			
		||||
template class Grid::Hadrons::MAction::TWilson<FIMPL>;
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										128
									
								
								Hadrons/Modules/MAction/Wilson.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										128
									
								
								Hadrons/Modules/MAction/Wilson.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,128 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MAction/Wilson.hpp
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
Author: Antonin Portelli <antonin.portelli@me.com>
 | 
			
		||||
Author: Lanny91 <andrew.lawson@gmail.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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
 | 
			
		||||
#ifndef Hadrons_MAction_Wilson_hpp_
 | 
			
		||||
#define Hadrons_MAction_Wilson_hpp_
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Global.hpp>
 | 
			
		||||
#include <Hadrons/Module.hpp>
 | 
			
		||||
#include <Hadrons/ModuleFactory.hpp>
 | 
			
		||||
 | 
			
		||||
BEGIN_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                            TWilson quark action                            *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
BEGIN_MODULE_NAMESPACE(MAction)
 | 
			
		||||
 | 
			
		||||
class WilsonPar: Serializable
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    GRID_SERIALIZABLE_CLASS_MEMBERS(WilsonPar,
 | 
			
		||||
                                    std::string, gauge,
 | 
			
		||||
                                    double     , mass,
 | 
			
		||||
                                    std::string, boundary);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
class TWilson: public Module<WilsonPar>
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    FG_TYPE_ALIASES(FImpl,);
 | 
			
		||||
public:
 | 
			
		||||
    // constructor
 | 
			
		||||
    TWilson(const std::string name);
 | 
			
		||||
    // destructor
 | 
			
		||||
    virtual ~TWilson(void) {};
 | 
			
		||||
    // dependencies/products
 | 
			
		||||
    virtual std::vector<std::string> getInput(void);
 | 
			
		||||
    virtual std::vector<std::string> getOutput(void);
 | 
			
		||||
protected:
 | 
			
		||||
    // setup
 | 
			
		||||
    virtual void setup(void);
 | 
			
		||||
    // execution
 | 
			
		||||
    virtual void execute(void);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
MODULE_REGISTER_TMP(Wilson, TWilson<FIMPL>, MAction);
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                     TWilson template implementation                        *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
// constructor /////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
TWilson<FImpl>::TWilson(const std::string name)
 | 
			
		||||
: Module<WilsonPar>(name)
 | 
			
		||||
{}
 | 
			
		||||
 | 
			
		||||
// dependencies/products ///////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
std::vector<std::string> TWilson<FImpl>::getInput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> in = {par().gauge};
 | 
			
		||||
    
 | 
			
		||||
    return in;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
std::vector<std::string> TWilson<FImpl>::getOutput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> out = {getName()};
 | 
			
		||||
    
 | 
			
		||||
    return out;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// setup ///////////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
void TWilson<FImpl>::setup(void)
 | 
			
		||||
{
 | 
			
		||||
    LOG(Message) << "Setting up Wilson fermion matrix with m= " << par().mass
 | 
			
		||||
                 << " using gauge field '" << par().gauge << "'" << std::endl;
 | 
			
		||||
    LOG(Message) << "Fermion boundary conditions: " << par().boundary
 | 
			
		||||
                 << std::endl;
 | 
			
		||||
                 
 | 
			
		||||
    auto &U      = envGet(LatticeGaugeField, par().gauge);
 | 
			
		||||
    auto &grid   = *env().getGrid();
 | 
			
		||||
    auto &gridRb = *env().getRbGrid();
 | 
			
		||||
    std::vector<Complex> boundary = strToVec<Complex>(par().boundary);
 | 
			
		||||
    typename WilsonFermion<FImpl>::ImplParams implParams(boundary);
 | 
			
		||||
    envCreateDerived(FMat, WilsonFermion<FImpl>, getName(), 1, U, grid, gridRb,
 | 
			
		||||
                     par().mass, implParams);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// execution ///////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
void TWilson<FImpl>::execute()
 | 
			
		||||
{}
 | 
			
		||||
 | 
			
		||||
END_MODULE_NAMESPACE
 | 
			
		||||
 | 
			
		||||
END_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
#endif // Hadrons_Wilson_hpp_
 | 
			
		||||
							
								
								
									
										35
									
								
								Hadrons/Modules/MAction/WilsonClover.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								Hadrons/Modules/MAction/WilsonClover.cc
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,35 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MAction/WilsonClover.cc
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
#include <Hadrons/Modules/MAction/WilsonClover.hpp>
 | 
			
		||||
 | 
			
		||||
using namespace Grid;
 | 
			
		||||
using namespace Hadrons;
 | 
			
		||||
using namespace MAction;
 | 
			
		||||
 | 
			
		||||
template class Grid::Hadrons::MAction::TWilsonClover<FIMPL>;
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										137
									
								
								Hadrons/Modules/MAction/WilsonClover.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										137
									
								
								Hadrons/Modules/MAction/WilsonClover.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,137 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MAction/WilsonClover.hpp
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
Author: Antonin Portelli <antonin.portelli@me.com>
 | 
			
		||||
Author: Guido Cossu <guido.cossu@ed.ac.uk>
 | 
			
		||||
Author: pretidav <david.preti@csic.es>
 | 
			
		||||
 | 
			
		||||
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 */
 | 
			
		||||
 | 
			
		||||
#ifndef Hadrons_MAction_WilsonClover_hpp_
 | 
			
		||||
#define Hadrons_MAction_WilsonClover_hpp_
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Global.hpp>
 | 
			
		||||
#include <Hadrons/Module.hpp>
 | 
			
		||||
#include <Hadrons/ModuleFactory.hpp>
 | 
			
		||||
 | 
			
		||||
BEGIN_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                         Wilson clover quark action                         *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
BEGIN_MODULE_NAMESPACE(MAction)
 | 
			
		||||
 | 
			
		||||
class WilsonCloverPar: Serializable
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    GRID_SERIALIZABLE_CLASS_MEMBERS(WilsonCloverPar,
 | 
			
		||||
                                    std::string, gauge,
 | 
			
		||||
                                    double     , mass,
 | 
			
		||||
				                    double     , csw_r,
 | 
			
		||||
				                    double     , csw_t,
 | 
			
		||||
				                    WilsonAnisotropyCoefficients ,clover_anisotropy,
 | 
			
		||||
                                    std::string, boundary
 | 
			
		||||
				    );
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
class TWilsonClover: public Module<WilsonCloverPar>
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    FG_TYPE_ALIASES(FImpl,);
 | 
			
		||||
public:
 | 
			
		||||
    // constructor
 | 
			
		||||
    TWilsonClover(const std::string name);
 | 
			
		||||
    // destructor
 | 
			
		||||
    virtual ~TWilsonClover(void) {};
 | 
			
		||||
    // dependencies/products
 | 
			
		||||
    virtual std::vector<std::string> getInput(void);
 | 
			
		||||
    virtual std::vector<std::string> getOutput(void);
 | 
			
		||||
    // setup
 | 
			
		||||
    virtual void setup(void);
 | 
			
		||||
    // execution
 | 
			
		||||
    virtual void execute(void);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
MODULE_REGISTER_TMP(WilsonClover, TWilsonClover<FIMPL>, MAction);
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                     TWilsonClover template implementation                        *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
// constructor /////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
TWilsonClover<FImpl>::TWilsonClover(const std::string name)
 | 
			
		||||
: Module<WilsonCloverPar>(name)
 | 
			
		||||
{}
 | 
			
		||||
 | 
			
		||||
// dependencies/products ///////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
std::vector<std::string> TWilsonClover<FImpl>::getInput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> in = {par().gauge};
 | 
			
		||||
 | 
			
		||||
    return in;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
std::vector<std::string> TWilsonClover<FImpl>::getOutput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> out = {getName()};
 | 
			
		||||
 | 
			
		||||
    return out;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// setup ///////////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
void TWilsonClover<FImpl>::setup(void)
 | 
			
		||||
{
 | 
			
		||||
    LOG(Message) << "Setting up Wilson clover fermion matrix with m= " << par().mass
 | 
			
		||||
                 << " using gauge field '" << par().gauge << "'" << std::endl;
 | 
			
		||||
    LOG(Message) << "Fermion boundary conditions: " << par().boundary 
 | 
			
		||||
                 << std::endl;
 | 
			
		||||
    LOG(Message) << "Clover term csw_r: " << par().csw_r
 | 
			
		||||
                 << " csw_t: " << par().csw_t
 | 
			
		||||
                 << std::endl;
 | 
			
		||||
    auto &U      = envGet(LatticeGaugeField, par().gauge);
 | 
			
		||||
    auto &grid   = *env().getGrid();
 | 
			
		||||
    auto &gridRb = *env().getRbGrid();
 | 
			
		||||
    std::vector<Complex> boundary = strToVec<Complex>(par().boundary);
 | 
			
		||||
    typename WilsonCloverFermion<FImpl>::ImplParams implParams(boundary);
 | 
			
		||||
    envCreateDerived(FMat, WilsonCloverFermion<FImpl>, getName(), 1, U, grid, gridRb, par().mass,
 | 
			
		||||
						  par().csw_r,
 | 
			
		||||
						  par().csw_t,
 | 
			
		||||
					      par().clover_anisotropy,
 | 
			
		||||
						  implParams); 
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// execution ///////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
void TWilsonClover<FImpl>::execute()
 | 
			
		||||
{}
 | 
			
		||||
 | 
			
		||||
END_MODULE_NAMESPACE
 | 
			
		||||
 | 
			
		||||
END_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
#endif // Hadrons_WilsonClover_hpp_
 | 
			
		||||
							
								
								
									
										35
									
								
								Hadrons/Modules/MAction/ZMobiusDWF.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								Hadrons/Modules/MAction/ZMobiusDWF.cc
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,35 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MAction/ZMobiusDWF.cc
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
#include <Hadrons/Modules/MAction/ZMobiusDWF.hpp>
 | 
			
		||||
 | 
			
		||||
using namespace Grid;
 | 
			
		||||
using namespace Hadrons;
 | 
			
		||||
using namespace MAction;
 | 
			
		||||
 | 
			
		||||
template class Grid::Hadrons::MAction::TZMobiusDWF<ZFIMPL>;
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										143
									
								
								Hadrons/Modules/MAction/ZMobiusDWF.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										143
									
								
								Hadrons/Modules/MAction/ZMobiusDWF.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,143 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MAction/ZMobiusDWF.hpp
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
#ifndef Hadrons_MAction_ZMobiusDWF_hpp_
 | 
			
		||||
#define Hadrons_MAction_ZMobiusDWF_hpp_
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Global.hpp>
 | 
			
		||||
#include <Hadrons/Module.hpp>
 | 
			
		||||
#include <Hadrons/ModuleFactory.hpp>
 | 
			
		||||
 | 
			
		||||
BEGIN_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                      z-Mobius domain-wall fermion action                   *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
BEGIN_MODULE_NAMESPACE(MAction)
 | 
			
		||||
 | 
			
		||||
class ZMobiusDWFPar: Serializable
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    GRID_SERIALIZABLE_CLASS_MEMBERS(ZMobiusDWFPar,
 | 
			
		||||
                                    std::string                      , gauge,
 | 
			
		||||
                                    unsigned int                     , Ls,
 | 
			
		||||
                                    double                           , mass,
 | 
			
		||||
                                    double                           , M5,
 | 
			
		||||
                                    double                           , b,
 | 
			
		||||
                                    double                           , c,
 | 
			
		||||
                                    std::vector<std::complex<double>>, omega,
 | 
			
		||||
                                    std::string                      , boundary);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
class TZMobiusDWF: public Module<ZMobiusDWFPar>
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    FG_TYPE_ALIASES(FImpl,);
 | 
			
		||||
public:
 | 
			
		||||
    // constructor
 | 
			
		||||
    TZMobiusDWF(const std::string name);
 | 
			
		||||
    // destructor
 | 
			
		||||
    virtual ~TZMobiusDWF(void) {};
 | 
			
		||||
    // dependency relation
 | 
			
		||||
    virtual std::vector<std::string> getInput(void);
 | 
			
		||||
    virtual std::vector<std::string> getOutput(void);
 | 
			
		||||
    // setup
 | 
			
		||||
    virtual void setup(void);
 | 
			
		||||
    // execution
 | 
			
		||||
    virtual void execute(void);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
MODULE_REGISTER_TMP(ZMobiusDWF, TZMobiusDWF<ZFIMPL>, MAction);
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                     TZMobiusDWF implementation                             *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
// constructor /////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
TZMobiusDWF<FImpl>::TZMobiusDWF(const std::string name)
 | 
			
		||||
: Module<ZMobiusDWFPar>(name)
 | 
			
		||||
{}
 | 
			
		||||
 | 
			
		||||
// dependencies/products ///////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
std::vector<std::string> TZMobiusDWF<FImpl>::getInput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> in = {par().gauge};
 | 
			
		||||
    
 | 
			
		||||
    return in;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
std::vector<std::string> TZMobiusDWF<FImpl>::getOutput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> out = {getName()};
 | 
			
		||||
    
 | 
			
		||||
    return out;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// setup ///////////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
void TZMobiusDWF<FImpl>::setup(void)
 | 
			
		||||
{
 | 
			
		||||
    LOG(Message) << "Setting up z-Mobius domain wall fermion matrix with m= "
 | 
			
		||||
                 << par().mass << ", M5= " << par().M5 << ", Ls= " << par().Ls 
 | 
			
		||||
                 << ", b= " << par().b << ", c= " << par().c
 | 
			
		||||
                 << " using gauge field '" << par().gauge << "'"
 | 
			
		||||
                 << std::endl;
 | 
			
		||||
    LOG(Message) << "Omegas: " << std::endl;
 | 
			
		||||
    for (unsigned int i = 0; i < par().omega.size(); ++i)
 | 
			
		||||
    {
 | 
			
		||||
        LOG(Message) << "  omega[" << i << "]= " << par().omega[i] << std::endl;
 | 
			
		||||
    }
 | 
			
		||||
    LOG(Message) << "Fermion boundary conditions: " << par().boundary
 | 
			
		||||
                 << std::endl;
 | 
			
		||||
 | 
			
		||||
    env().createGrid(par().Ls);
 | 
			
		||||
    auto &U    = envGet(LatticeGaugeField, par().gauge);
 | 
			
		||||
    auto &g4   = *env().getGrid();
 | 
			
		||||
    auto &grb4 = *env().getRbGrid();
 | 
			
		||||
    auto &g5   = *env().getGrid(par().Ls);
 | 
			
		||||
    auto &grb5 = *env().getRbGrid(par().Ls);
 | 
			
		||||
    auto omega = par().omega;
 | 
			
		||||
    std::vector<Complex> boundary = strToVec<Complex>(par().boundary);
 | 
			
		||||
    typename ZMobiusFermion<FImpl>::ImplParams implParams(boundary);
 | 
			
		||||
    envCreateDerived(FMat, ZMobiusFermion<FImpl>, getName(), par().Ls, U, g5,
 | 
			
		||||
                     grb5, g4, grb4, par().mass, par().M5, omega,
 | 
			
		||||
                     par().b, par().c, implParams);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// execution ///////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
void TZMobiusDWF<FImpl>::execute(void)
 | 
			
		||||
{}
 | 
			
		||||
 | 
			
		||||
END_MODULE_NAMESPACE
 | 
			
		||||
 | 
			
		||||
END_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
#endif // Hadrons_MAction_ZMobiusDWF_hpp_
 | 
			
		||||
							
								
								
									
										36
									
								
								Hadrons/Modules/MContraction/A2AMesonField.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								Hadrons/Modules/MContraction/A2AMesonField.cc
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,36 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MContraction/A2AMesonField.cc
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
Author: Antonin Portelli <antonin.portelli@me.com>
 | 
			
		||||
Author: paboyle <paboyle@ph.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 */
 | 
			
		||||
#include <Hadrons/Modules/MContraction/A2AMesonField.hpp>
 | 
			
		||||
 | 
			
		||||
using namespace Grid;
 | 
			
		||||
using namespace Hadrons;
 | 
			
		||||
using namespace MContraction;
 | 
			
		||||
 | 
			
		||||
template class Grid::Hadrons::MContraction::TA2AMesonField<FIMPL>;
 | 
			
		||||
template class Grid::Hadrons::MContraction::TA2AMesonField<ZFIMPL>;
 | 
			
		||||
							
								
								
									
										486
									
								
								Hadrons/Modules/MContraction/A2AMesonField.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										486
									
								
								Hadrons/Modules/MContraction/A2AMesonField.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,486 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MContraction/A2AMesonField.hpp
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
Author: Antonin Portelli <antonin.portelli@me.com>
 | 
			
		||||
Author: Peter Boyle <paboyle@ph.ed.ac.uk>
 | 
			
		||||
Author: paboyle <paboyle@ph.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 */
 | 
			
		||||
#ifndef Hadrons_MContraction_A2AMesonField_hpp_
 | 
			
		||||
#define Hadrons_MContraction_A2AMesonField_hpp_
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Global.hpp>
 | 
			
		||||
#include <Hadrons/Module.hpp>
 | 
			
		||||
#include <Hadrons/ModuleFactory.hpp>
 | 
			
		||||
#include <Hadrons/A2AVectors.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MSolver/A2AVectors.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MContraction/A2AMesonFieldKernels.hpp>
 | 
			
		||||
 | 
			
		||||
#define MF_PARALLEL_IO
 | 
			
		||||
#ifndef MF_IO_TYPE
 | 
			
		||||
#define MF_IO_TYPE ComplexF
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
BEGIN_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                     All-to-all meson field creation                        *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
BEGIN_MODULE_NAMESPACE(MContraction)
 | 
			
		||||
 | 
			
		||||
class A2AMesonFieldPar: Serializable
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
    GRID_SERIALIZABLE_CLASS_MEMBERS(A2AMesonFieldPar,
 | 
			
		||||
                                    int, cacheBlock,
 | 
			
		||||
                                    int, block,
 | 
			
		||||
                                    std::string, v,
 | 
			
		||||
                                    std::string, w,
 | 
			
		||||
                                    std::string, output,
 | 
			
		||||
                                    std::string, gammas,
 | 
			
		||||
                                    std::vector<std::string>, mom);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
class TA2AMesonField : public Module<A2AMesonFieldPar>
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    FERM_TYPE_ALIASES(FImpl,);
 | 
			
		||||
    SOLVER_TYPE_ALIASES(FImpl,);
 | 
			
		||||
    typedef Eigen::TensorMap<Eigen::Tensor<Complex, 5, Eigen::RowMajor>>    MesonField;
 | 
			
		||||
    typedef Eigen::TensorMap<Eigen::Tensor<MF_IO_TYPE, 5, Eigen::RowMajor>> MesonFieldIo;
 | 
			
		||||
public:
 | 
			
		||||
    // constructor
 | 
			
		||||
    TA2AMesonField(const std::string name);
 | 
			
		||||
    // destructor
 | 
			
		||||
    virtual ~TA2AMesonField(void){};
 | 
			
		||||
    // dependency relation
 | 
			
		||||
    virtual std::vector<std::string> getInput(void);
 | 
			
		||||
    virtual std::vector<std::string> getOutput(void);
 | 
			
		||||
    // setup
 | 
			
		||||
    virtual void setup(void);
 | 
			
		||||
    // execution
 | 
			
		||||
    virtual void execute(void);
 | 
			
		||||
private:
 | 
			
		||||
    // IO
 | 
			
		||||
    std::string ioname(unsigned int m, unsigned int g) const;
 | 
			
		||||
    std::string filename(unsigned int m, unsigned int g) const;
 | 
			
		||||
    void initFile(unsigned int m, unsigned int g);
 | 
			
		||||
    void saveBlock(const MesonFieldIo &mf,
 | 
			
		||||
                   unsigned int m, unsigned int g, 
 | 
			
		||||
                   unsigned int i, unsigned int j);
 | 
			
		||||
private:
 | 
			
		||||
    bool                                               hasPhase_{false};
 | 
			
		||||
    std::string                                        momphName_;
 | 
			
		||||
    std::vector<Gamma::Algebra>                        gamma_;
 | 
			
		||||
    std::vector<std::vector<double>>                   mom_;
 | 
			
		||||
    std::vector<std::pair<unsigned int, unsigned int>> nodeFile_;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
MODULE_REGISTER(A2AMesonField, ARG(TA2AMesonField<FIMPL>), MContraction);
 | 
			
		||||
MODULE_REGISTER(ZA2AMesonField, ARG(TA2AMesonField<ZFIMPL>), MContraction);
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
*                  TA2AMesonField implementation                             *
 | 
			
		||||
******************************************************************************/
 | 
			
		||||
// constructor /////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
TA2AMesonField<FImpl>::TA2AMesonField(const std::string name)
 | 
			
		||||
: Module<A2AMesonFieldPar>(name)
 | 
			
		||||
, momphName_(name + "_momph")
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// dependencies/products ///////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
std::vector<std::string> TA2AMesonField<FImpl>::getInput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> in = {par().v, par().w};
 | 
			
		||||
 | 
			
		||||
    return in;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
std::vector<std::string> TA2AMesonField<FImpl>::getOutput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> out = {};
 | 
			
		||||
 | 
			
		||||
    return out;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// setup ///////////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
void TA2AMesonField<FImpl>::setup(void)
 | 
			
		||||
{
 | 
			
		||||
    gamma_.clear();
 | 
			
		||||
    mom_.clear();
 | 
			
		||||
    if (par().gammas == "all")
 | 
			
		||||
    {
 | 
			
		||||
        gamma_ = {
 | 
			
		||||
            Gamma::Algebra::Gamma5,
 | 
			
		||||
            Gamma::Algebra::Identity,    
 | 
			
		||||
            Gamma::Algebra::GammaX,
 | 
			
		||||
            Gamma::Algebra::GammaY,
 | 
			
		||||
            Gamma::Algebra::GammaZ,
 | 
			
		||||
            Gamma::Algebra::GammaT,
 | 
			
		||||
            Gamma::Algebra::GammaXGamma5,
 | 
			
		||||
            Gamma::Algebra::GammaYGamma5,
 | 
			
		||||
            Gamma::Algebra::GammaZGamma5,
 | 
			
		||||
            Gamma::Algebra::GammaTGamma5,
 | 
			
		||||
            Gamma::Algebra::SigmaXY,
 | 
			
		||||
            Gamma::Algebra::SigmaXZ,
 | 
			
		||||
            Gamma::Algebra::SigmaXT,
 | 
			
		||||
            Gamma::Algebra::SigmaYZ,
 | 
			
		||||
            Gamma::Algebra::SigmaYT,
 | 
			
		||||
            Gamma::Algebra::SigmaZT
 | 
			
		||||
        };
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        gamma_ = strToVec<Gamma::Algebra>(par().gammas);
 | 
			
		||||
    }
 | 
			
		||||
    for (auto &pstr: par().mom)
 | 
			
		||||
    {
 | 
			
		||||
        auto p = strToVec<Real>(pstr);
 | 
			
		||||
 | 
			
		||||
        if (p.size() != env().getNd() - 1)
 | 
			
		||||
        {
 | 
			
		||||
            HADRONS_ERROR(Size, "Momentum has " + std::to_string(p.size())
 | 
			
		||||
                                + " components instead of " 
 | 
			
		||||
                                + std::to_string(env().getNd() - 1));
 | 
			
		||||
        }
 | 
			
		||||
        mom_.push_back(p);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    envCache(std::vector<LatticeComplex>, momphName_, 1, 
 | 
			
		||||
             par().mom.size(), env().getGrid());
 | 
			
		||||
    envTmpLat(LatticeComplex, "coor");
 | 
			
		||||
    // preallocate memory for meson field block
 | 
			
		||||
    auto tgp = env().getDim().back()*gamma_.size()*mom_.size();
 | 
			
		||||
 | 
			
		||||
    envTmp(Vector<MF_IO_TYPE>, "mfBuf", 1, tgp*par().block*par().block);
 | 
			
		||||
    envTmp(Vector<Complex>, "mfCache", 1, tgp*par().cacheBlock*par().cacheBlock);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// execution ///////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
void TA2AMesonField<FImpl>::execute(void)
 | 
			
		||||
{
 | 
			
		||||
    auto &v = envGet(std::vector<FermionField>, par().v);
 | 
			
		||||
    auto &w = envGet(std::vector<FermionField>, par().w);
 | 
			
		||||
 | 
			
		||||
    int nt         = env().getDim().back();
 | 
			
		||||
    int N_i        = w.size();
 | 
			
		||||
    int N_j        = v.size();
 | 
			
		||||
    int ngamma     = gamma_.size();
 | 
			
		||||
    int nmom       = mom_.size();
 | 
			
		||||
    int block      = par().block;
 | 
			
		||||
    int cacheBlock = par().cacheBlock;
 | 
			
		||||
 | 
			
		||||
    LOG(Message) << "Computing all-to-all meson fields" << std::endl;
 | 
			
		||||
    LOG(Message) << "W: '" << par().w << "' V: '" << par().v << "'" << std::endl;
 | 
			
		||||
    LOG(Message) << "Momenta:" << std::endl;
 | 
			
		||||
    for (auto &p: mom_)
 | 
			
		||||
    {
 | 
			
		||||
        LOG(Message) << "  " << p << std::endl;
 | 
			
		||||
    }
 | 
			
		||||
    LOG(Message) << "Spin bilinears:" << std::endl;
 | 
			
		||||
    for (auto &g: gamma_)
 | 
			
		||||
    {
 | 
			
		||||
        LOG(Message) << "  " << g << std::endl;
 | 
			
		||||
    }
 | 
			
		||||
    LOG(Message) << "Meson field size: " << nt << "*" << N_i << "*" << N_j 
 | 
			
		||||
                 << " (filesize " << sizeString(nt*N_i*N_j*sizeof(MF_IO_TYPE)) 
 | 
			
		||||
                 << "/momentum/bilinear)" << std::endl;
 | 
			
		||||
 | 
			
		||||
    ///////////////////////////////////////////////
 | 
			
		||||
    // Momentum setup
 | 
			
		||||
    ///////////////////////////////////////////////
 | 
			
		||||
    auto &ph = envGet(std::vector<LatticeComplex>, momphName_);
 | 
			
		||||
 | 
			
		||||
    if (!hasPhase_)
 | 
			
		||||
    {
 | 
			
		||||
        startTimer("Momentum phases");
 | 
			
		||||
        for (unsigned int j = 0; j < nmom; ++j)
 | 
			
		||||
        {
 | 
			
		||||
            Complex           i(0.0,1.0);
 | 
			
		||||
            std::vector<Real> p;
 | 
			
		||||
 | 
			
		||||
            envGetTmp(LatticeComplex, coor);
 | 
			
		||||
            ph[j] = zero;
 | 
			
		||||
            for(unsigned int mu = 0; mu < mom_[j].size(); mu++)
 | 
			
		||||
            {
 | 
			
		||||
                LatticeCoordinate(coor, mu);
 | 
			
		||||
                ph[j] = ph[j] + (mom_[j][mu]/env().getDim(mu))*coor;
 | 
			
		||||
            }
 | 
			
		||||
            ph[j] = exp((Real)(2*M_PI)*i*ph[j]);
 | 
			
		||||
        }
 | 
			
		||||
        hasPhase_ = true;
 | 
			
		||||
        stopTimer("Momentum phases");
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    //////////////////////////////////////////////////////////////////////////
 | 
			
		||||
    // i,j   is first  loop over SchurBlock factors reusing 5D matrices
 | 
			
		||||
    // ii,jj is second loop over cacheBlock factors for high perf contractoin
 | 
			
		||||
    // iii,jjj are loops within cacheBlock
 | 
			
		||||
    // Total index is sum of these  i+ii+iii etc...
 | 
			
		||||
    //////////////////////////////////////////////////////////////////////////
 | 
			
		||||
    
 | 
			
		||||
    double flops;
 | 
			
		||||
    double bytes;
 | 
			
		||||
    double vol      = env().getVolume();
 | 
			
		||||
    double t_kernel = 0.0;
 | 
			
		||||
    double nodes    = env().getGrid()->NodeCount();
 | 
			
		||||
    double tot_kernel;
 | 
			
		||||
 | 
			
		||||
    envGetTmp(Vector<MF_IO_TYPE>, mfBuf);
 | 
			
		||||
    envGetTmp(Vector<Complex>, mfCache);
 | 
			
		||||
    
 | 
			
		||||
    double t0    = usecond();
 | 
			
		||||
    int NBlock_i = N_i/block + (((N_i % block) != 0) ? 1 : 0);
 | 
			
		||||
    int NBlock_j = N_j/block + (((N_j % block) != 0) ? 1 : 0);
 | 
			
		||||
 | 
			
		||||
    for(int i=0;i<N_i;i+=block)
 | 
			
		||||
    for(int j=0;j<N_j;j+=block)
 | 
			
		||||
    {
 | 
			
		||||
        // Get the W and V vectors for this block^2 set of terms
 | 
			
		||||
        int N_ii = MIN(N_i-i,block);
 | 
			
		||||
        int N_jj = MIN(N_j-j,block);
 | 
			
		||||
 | 
			
		||||
        LOG(Message) << "Meson field block " 
 | 
			
		||||
                    << j/block + NBlock_j*i/block + 1 
 | 
			
		||||
                    << "/" << NBlock_i*NBlock_j << " [" << i <<" .. " 
 | 
			
		||||
                    << i+N_ii-1 << ", " << j <<" .. " << j+N_jj-1 << "]" 
 | 
			
		||||
                    << std::endl;
 | 
			
		||||
 | 
			
		||||
        MesonFieldIo mfBlock(mfBuf.data(),nmom,ngamma,nt,N_ii,N_jj);
 | 
			
		||||
 | 
			
		||||
        // Series of cache blocked chunks of the contractions within this block
 | 
			
		||||
        flops = 0.0;
 | 
			
		||||
        bytes = 0.0;
 | 
			
		||||
        for(int ii=0;ii<N_ii;ii+=cacheBlock)
 | 
			
		||||
        for(int jj=0;jj<N_jj;jj+=cacheBlock)
 | 
			
		||||
        {
 | 
			
		||||
            int N_iii = MIN(N_ii-ii,cacheBlock);
 | 
			
		||||
            int N_jjj = MIN(N_jj-jj,cacheBlock);
 | 
			
		||||
            MesonField mfCacheBlock(mfCache.data(),nmom,ngamma,nt,N_iii,N_jjj);    
 | 
			
		||||
 | 
			
		||||
            startTimer("contraction: total");
 | 
			
		||||
            makeMesonFieldBlock(mfCacheBlock, &w[i+ii], &v[j+jj], gamma_, ph, 
 | 
			
		||||
                                env().getNd() - 1, this);
 | 
			
		||||
            stopTimer("contraction: total");
 | 
			
		||||
            
 | 
			
		||||
            // flops for general N_c & N_s
 | 
			
		||||
            flops += vol * ( 2 * 8.0 + 6.0 + 8.0*nmom) * N_iii*N_jjj*ngamma;
 | 
			
		||||
            bytes += vol * (12.0 * sizeof(Complex) ) * N_iii*N_jjj
 | 
			
		||||
                     +  vol * ( 2.0 * sizeof(Complex) *nmom ) * N_iii*N_jjj* ngamma;
 | 
			
		||||
 | 
			
		||||
            startTimer("cache copy");
 | 
			
		||||
            parallel_for_nest5(int m =0;m< nmom;m++)
 | 
			
		||||
            for(int g =0;g< ngamma;g++)
 | 
			
		||||
            for(int t =0;t< nt;t++)
 | 
			
		||||
            for(int iii=0;iii< N_iii;iii++)
 | 
			
		||||
            for(int jjj=0;jjj< N_jjj;jjj++)
 | 
			
		||||
            {
 | 
			
		||||
                mfBlock(m,g,t,ii+iii,jj+jjj) = mfCacheBlock(m,g,t,iii,jjj);
 | 
			
		||||
            }
 | 
			
		||||
            stopTimer("cache copy");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // perf
 | 
			
		||||
        tot_kernel = getDTimer("contraction: colour trace & mom.")
 | 
			
		||||
                     + getDTimer("contraction: local space sum");
 | 
			
		||||
        t_kernel   = tot_kernel - t_kernel;
 | 
			
		||||
        LOG(Message) << "Kernel perf " << flops/t_kernel/1.0e3/nodes 
 | 
			
		||||
                     << " Gflop/s/node " << std::endl;
 | 
			
		||||
        LOG(Message) << "Kernel perf " << bytes/t_kernel*1.0e6/1024/1024/1024/nodes 
 | 
			
		||||
                     << " GB/s/node "  << std::endl;
 | 
			
		||||
        t_kernel = tot_kernel;
 | 
			
		||||
 | 
			
		||||
        // IO
 | 
			
		||||
        if (!par().output.empty())
 | 
			
		||||
        {
 | 
			
		||||
            double       blockSize, ioTime;
 | 
			
		||||
            unsigned int myRank = env().getGrid()->ThisRank(),
 | 
			
		||||
                         nRank  = env().getGrid()->RankCount();
 | 
			
		||||
        
 | 
			
		||||
            LOG(Message) << "Writing block to disk" << std::endl;
 | 
			
		||||
            ioTime = -getDTimer("IO: write block");
 | 
			
		||||
            startTimer("IO: total");
 | 
			
		||||
            makeFileDir(filename(0, 0), env().getGrid());
 | 
			
		||||
#ifdef MF_PARALLEL_IO
 | 
			
		||||
            env().getGrid()->Barrier();
 | 
			
		||||
            nodeFile_.clear();
 | 
			
		||||
            for(int f = myRank; f < nmom*ngamma; f += nRank)
 | 
			
		||||
            {
 | 
			
		||||
                std::pair<unsigned int, unsigned int> file;
 | 
			
		||||
 | 
			
		||||
                file.first  = f/ngamma;
 | 
			
		||||
                file.second = f % ngamma;
 | 
			
		||||
                nodeFile_.push_back(file);
 | 
			
		||||
            }
 | 
			
		||||
            // parallel IO
 | 
			
		||||
            for (auto &f: nodeFile_)
 | 
			
		||||
            {
 | 
			
		||||
                auto m = f.first, g = f.second;
 | 
			
		||||
 | 
			
		||||
                if ((i == 0) and (j == 0))
 | 
			
		||||
                {
 | 
			
		||||
                    startTimer("IO: file creation");
 | 
			
		||||
                    initFile(m, g);
 | 
			
		||||
                    stopTimer("IO: file creation");
 | 
			
		||||
                }
 | 
			
		||||
                startTimer("IO: write block");
 | 
			
		||||
                saveBlock(mfBlock, m, g, i, j);
 | 
			
		||||
                stopTimer("IO: write block");
 | 
			
		||||
            }
 | 
			
		||||
            env().getGrid()->Barrier();
 | 
			
		||||
#else
 | 
			
		||||
            // serial IO
 | 
			
		||||
            for(int m = 0; m < nmom; m++)
 | 
			
		||||
            for(int g = 0; g < ngamma; g++)
 | 
			
		||||
            {   
 | 
			
		||||
                if ((i == 0) and (j == 0))
 | 
			
		||||
                {
 | 
			
		||||
                    startTimer("IO: file creation");
 | 
			
		||||
                    if (env().getGrid()->IsBoss())
 | 
			
		||||
                    {
 | 
			
		||||
                        initFile(m, g);
 | 
			
		||||
                    }
 | 
			
		||||
                    stopTimer("IO: file creation");
 | 
			
		||||
                }
 | 
			
		||||
                startTimer("IO: write block");
 | 
			
		||||
                if (env().getGrid()->IsBoss())
 | 
			
		||||
                {
 | 
			
		||||
                    saveBlock(mfBlock, m, g, i, j);
 | 
			
		||||
                }
 | 
			
		||||
                stopTimer("IO: write block");
 | 
			
		||||
            }
 | 
			
		||||
#endif
 | 
			
		||||
            stopTimer("IO: total");
 | 
			
		||||
            blockSize  = static_cast<double>(nmom*ngamma*nt*N_ii*N_jj*sizeof(MF_IO_TYPE));
 | 
			
		||||
            ioTime    += getDTimer("IO: write block");
 | 
			
		||||
            LOG(Message) << "HDF5 IO done " << sizeString(blockSize) << " in "
 | 
			
		||||
                         << ioTime  << " us (" 
 | 
			
		||||
                         << blockSize/ioTime*1.0e6/1024/1024
 | 
			
		||||
                         << " MB/s)" << std::endl;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// IO
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
std::string TA2AMesonField<FImpl>::ioname(unsigned int m, unsigned int g) const
 | 
			
		||||
{
 | 
			
		||||
    std::stringstream ss;
 | 
			
		||||
 | 
			
		||||
    ss << gamma_[g] << "_";
 | 
			
		||||
    for (unsigned int mu = 0; mu < mom_[m].size(); ++mu)
 | 
			
		||||
    {
 | 
			
		||||
        ss << mom_[m][mu] << ((mu == mom_[m].size() - 1) ? "" : "_");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return ss.str();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
std::string TA2AMesonField<FImpl>::filename(unsigned int m, unsigned int g) const
 | 
			
		||||
{
 | 
			
		||||
    return par().output + "." + std::to_string(vm().getTrajectory()) 
 | 
			
		||||
           + "/" + ioname(m, g) + ".h5";
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
void TA2AMesonField<FImpl>::initFile(unsigned int m, unsigned int g)
 | 
			
		||||
{
 | 
			
		||||
#ifdef HAVE_HDF5
 | 
			
		||||
    std::string  f     = filename(m, g);
 | 
			
		||||
    auto         &v    = envGet(std::vector<FermionField>, par().v);
 | 
			
		||||
    auto         &w    = envGet(std::vector<FermionField>, par().w);
 | 
			
		||||
    int          nt    = env().getDim().back();
 | 
			
		||||
    int          N_i   = w.size();
 | 
			
		||||
    int          N_j   = v.size();
 | 
			
		||||
 | 
			
		||||
    Hdf5Writer              writer(f);
 | 
			
		||||
    std::vector<hsize_t>    dim = {static_cast<hsize_t>(nt), 
 | 
			
		||||
                                   static_cast<hsize_t>(N_i), 
 | 
			
		||||
                                   static_cast<hsize_t>(N_j)},
 | 
			
		||||
                            chunk = {static_cast<hsize_t>(nt), 
 | 
			
		||||
                                     static_cast<hsize_t>(par().block), 
 | 
			
		||||
                                     static_cast<hsize_t>(par().block)};
 | 
			
		||||
    H5NS::DataSpace         dataspace(dim.size(), dim.data());
 | 
			
		||||
    H5NS::DataSet           dataset;
 | 
			
		||||
    H5NS::DSetCreatPropList plist;
 | 
			
		||||
    
 | 
			
		||||
    push(writer, ioname(m, g));
 | 
			
		||||
    write(writer, "momentum", mom_[m]);
 | 
			
		||||
    write(writer, "gamma", gamma_[g]);
 | 
			
		||||
    auto &group = writer.getGroup();
 | 
			
		||||
    plist.setChunk(chunk.size(), chunk.data());
 | 
			
		||||
    dataset = group.createDataSet("mesonField", Hdf5Type<MF_IO_TYPE>::type(),
 | 
			
		||||
                                  dataspace, plist);
 | 
			
		||||
#else
 | 
			
		||||
    HADRONS_ERROR(Implementation, "meson field I/O needs HDF5 library");
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
void TA2AMesonField<FImpl>::saveBlock(const MesonFieldIo &mf,
 | 
			
		||||
                                      unsigned int m, unsigned int g, 
 | 
			
		||||
                                      unsigned int i, unsigned int j)
 | 
			
		||||
{
 | 
			
		||||
#ifdef HAVE_HDF5
 | 
			
		||||
    std::string          f = filename(m, g);
 | 
			
		||||
    Hdf5Reader           reader(f);
 | 
			
		||||
    hsize_t              nt = mf.dimension(2),
 | 
			
		||||
                         Ni = mf.dimension(3),
 | 
			
		||||
                         Nj = mf.dimension(4);
 | 
			
		||||
    std::vector<hsize_t> count = {nt, Ni, Nj},
 | 
			
		||||
                         offset = {0, static_cast<hsize_t>(i),
 | 
			
		||||
                                 static_cast<hsize_t>(j)},
 | 
			
		||||
                         stride = {1, 1, 1},
 | 
			
		||||
                         block  = {1, 1, 1}; 
 | 
			
		||||
    H5NS::DataSpace      memspace(count.size(), count.data()), dataspace;
 | 
			
		||||
    H5NS::DataSet        dataset;
 | 
			
		||||
    size_t               shift;
 | 
			
		||||
 | 
			
		||||
    push(reader, ioname(m, g));
 | 
			
		||||
    auto &group = reader.getGroup();
 | 
			
		||||
    dataset   = group.openDataSet("mesonField");
 | 
			
		||||
    dataspace = dataset.getSpace();
 | 
			
		||||
    dataspace.selectHyperslab(H5S_SELECT_SET, count.data(), offset.data(),
 | 
			
		||||
                              stride.data(), block.data());
 | 
			
		||||
    shift = (m*mf.dimension(1) + g)*nt*Ni*Nj;
 | 
			
		||||
    dataset.write(mf.data() + shift, Hdf5Type<MF_IO_TYPE>::type(), memspace, 
 | 
			
		||||
                  dataspace);
 | 
			
		||||
#else
 | 
			
		||||
    HADRONS_ERROR(Implementation, "meson field I/O needs HDF5 library");
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
END_MODULE_NAMESPACE
 | 
			
		||||
 | 
			
		||||
END_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
#endif // Hadrons_MContraction_A2AMesonField_hpp_
 | 
			
		||||
							
								
								
									
										224
									
								
								Hadrons/Modules/MContraction/A2AMesonFieldKernels.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										224
									
								
								Hadrons/Modules/MContraction/A2AMesonFieldKernels.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,224 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MContraction/A2AMesonFieldKernels.hpp
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
Author: Antonin Portelli <antonin.portelli@me.com>
 | 
			
		||||
Author: Peter Boyle <paboyle@ph.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 */
 | 
			
		||||
#ifndef Hadrons_MContraction_A2AMesonFieldKernels_hpp_
 | 
			
		||||
#define Hadrons_MContraction_A2AMesonFieldKernels_hpp_
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Global.hpp>
 | 
			
		||||
#include <Hadrons/Module.hpp>
 | 
			
		||||
#include <Grid/Eigen/unsupported/CXX11/Tensor>
 | 
			
		||||
 | 
			
		||||
BEGIN_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
BEGIN_MODULE_NAMESPACE(MContraction)
 | 
			
		||||
 | 
			
		||||
////////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
// Cache blocked arithmetic routine
 | 
			
		||||
// Could move to Grid ???
 | 
			
		||||
////////////////////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename Field, typename MesonField>
 | 
			
		||||
void makeMesonFieldBlock(MesonField &mat, 
 | 
			
		||||
                         const Field *lhs_wi,
 | 
			
		||||
                         const Field *rhs_vj,
 | 
			
		||||
                         std::vector<Gamma::Algebra> gamma,
 | 
			
		||||
                         const std::vector<LatticeComplex> &mom,
 | 
			
		||||
                         int orthogdim,
 | 
			
		||||
                         ModuleBase *caller = nullptr) 
 | 
			
		||||
{
 | 
			
		||||
    typedef typename Field::vector_object vobj;
 | 
			
		||||
    typedef typename vobj::scalar_object  sobj;
 | 
			
		||||
    typedef typename vobj::scalar_type    scalar_type;
 | 
			
		||||
    typedef typename vobj::vector_type    vector_type;
 | 
			
		||||
 | 
			
		||||
    typedef iSpinMatrix<vector_type> SpinMatrix_v;
 | 
			
		||||
    typedef iSpinMatrix<scalar_type> SpinMatrix_s;
 | 
			
		||||
    
 | 
			
		||||
    int Lblock = mat.dimension(3); 
 | 
			
		||||
    int Rblock = mat.dimension(4);
 | 
			
		||||
 | 
			
		||||
    GridBase *grid = lhs_wi[0]._grid;
 | 
			
		||||
    
 | 
			
		||||
    const int    Nd = grid->_ndimension;
 | 
			
		||||
    const int Nsimd = grid->Nsimd();
 | 
			
		||||
 | 
			
		||||
    int Nt     = grid->GlobalDimensions()[orthogdim];
 | 
			
		||||
    int Ngamma = gamma.size();
 | 
			
		||||
    int Nmom   = mom.size();
 | 
			
		||||
 | 
			
		||||
    int fd=grid->_fdimensions[orthogdim];
 | 
			
		||||
    int ld=grid->_ldimensions[orthogdim];
 | 
			
		||||
    int rd=grid->_rdimensions[orthogdim];
 | 
			
		||||
 | 
			
		||||
    // will locally sum vectors first
 | 
			
		||||
    // sum across these down to scalars
 | 
			
		||||
    // splitting the SIMD
 | 
			
		||||
    int MFrvol = rd*Lblock*Rblock*Nmom;
 | 
			
		||||
    int MFlvol = ld*Lblock*Rblock*Nmom;
 | 
			
		||||
 | 
			
		||||
    Vector<SpinMatrix_v > lvSum(MFrvol);
 | 
			
		||||
    parallel_for (int r = 0; r < MFrvol; r++)
 | 
			
		||||
    {
 | 
			
		||||
        lvSum[r] = zero;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    Vector<SpinMatrix_s > lsSum(MFlvol);             
 | 
			
		||||
    parallel_for (int r = 0; r < MFlvol; r++)
 | 
			
		||||
    {
 | 
			
		||||
        lsSum[r]=scalar_type(0.0);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    int e1=    grid->_slice_nblock[orthogdim];
 | 
			
		||||
    int e2=    grid->_slice_block [orthogdim];
 | 
			
		||||
    int stride=grid->_slice_stride[orthogdim];
 | 
			
		||||
 | 
			
		||||
    if (caller) caller->startTimer("contraction: colour trace & mom.");
 | 
			
		||||
    // Nested parallelism would be ok
 | 
			
		||||
    // Wasting cores here. Test case r
 | 
			
		||||
    parallel_for(int r=0;r<rd;r++)
 | 
			
		||||
    {
 | 
			
		||||
        int so=r*grid->_ostride[orthogdim]; // base offset for start of plane 
 | 
			
		||||
 | 
			
		||||
        for(int n=0;n<e1;n++)
 | 
			
		||||
        for(int b=0;b<e2;b++)
 | 
			
		||||
        {
 | 
			
		||||
            int ss= so+n*stride+b;
 | 
			
		||||
 | 
			
		||||
            for(int i=0;i<Lblock;i++)
 | 
			
		||||
            {
 | 
			
		||||
                auto left = conjugate(lhs_wi[i]._odata[ss]);
 | 
			
		||||
 | 
			
		||||
                for(int j=0;j<Rblock;j++)
 | 
			
		||||
                {
 | 
			
		||||
                    SpinMatrix_v vv;
 | 
			
		||||
                    auto right = rhs_vj[j]._odata[ss];
 | 
			
		||||
 | 
			
		||||
                    for(int s1=0;s1<Ns;s1++)
 | 
			
		||||
                    for(int s2=0;s2<Ns;s2++)
 | 
			
		||||
                    {
 | 
			
		||||
                        vv()(s1,s2)() = left()(s2)(0) * right()(s1)(0)
 | 
			
		||||
                                        + left()(s2)(1) * right()(s1)(1)
 | 
			
		||||
                                        + left()(s2)(2) * right()(s1)(2);
 | 
			
		||||
                    }
 | 
			
		||||
                    
 | 
			
		||||
                    // After getting the sitewise product do the mom phase loop
 | 
			
		||||
                    int base = Nmom*i+Nmom*Lblock*j+Nmom*Lblock*Rblock*r;
 | 
			
		||||
 | 
			
		||||
                    for ( int m=0;m<Nmom;m++)
 | 
			
		||||
                    {
 | 
			
		||||
                        int idx = m+base;
 | 
			
		||||
                        auto phase = mom[m]._odata[ss];
 | 
			
		||||
                        mac(&lvSum[idx],&vv,&phase);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    if (caller) caller->stopTimer("contraction: colour trace & mom.");
 | 
			
		||||
 | 
			
		||||
    // Sum across simd lanes in the plane, breaking out orthog dir.
 | 
			
		||||
    if (caller) caller->startTimer("contraction: local space sum");
 | 
			
		||||
    parallel_for(int rt=0;rt<rd;rt++)
 | 
			
		||||
    {
 | 
			
		||||
        std::vector<int> icoor(Nd);
 | 
			
		||||
        std::vector<SpinMatrix_s> extracted(Nsimd);               
 | 
			
		||||
 | 
			
		||||
        for(int i=0;i<Lblock;i++)
 | 
			
		||||
        for(int j=0;j<Rblock;j++)
 | 
			
		||||
        for(int m=0;m<Nmom;m++)
 | 
			
		||||
        {
 | 
			
		||||
 | 
			
		||||
            int ij_rdx = m+Nmom*i+Nmom*Lblock*j+Nmom*Lblock*Rblock*rt;
 | 
			
		||||
 | 
			
		||||
            extract(lvSum[ij_rdx],extracted);
 | 
			
		||||
            for(int idx=0;idx<Nsimd;idx++)
 | 
			
		||||
            {
 | 
			
		||||
                grid->iCoorFromIindex(icoor,idx);
 | 
			
		||||
 | 
			
		||||
                int ldx    = rt+icoor[orthogdim]*rd;
 | 
			
		||||
                int ij_ldx = m+Nmom*i+Nmom*Lblock*j+Nmom*Lblock*Rblock*ldx;
 | 
			
		||||
 | 
			
		||||
                lsSum[ij_ldx]=lsSum[ij_ldx]+extracted[idx];
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    if (caller) caller->stopTimer("contraction: local space sum");
 | 
			
		||||
 | 
			
		||||
    // ld loop and local only??
 | 
			
		||||
    if (caller) caller->startTimer("contraction: spin trace");
 | 
			
		||||
    int pd = grid->_processors[orthogdim];
 | 
			
		||||
    int pc = grid->_processor_coor[orthogdim];
 | 
			
		||||
    parallel_for_nest2(int lt=0;lt<ld;lt++)
 | 
			
		||||
    {
 | 
			
		||||
        for(int pt=0;pt<pd;pt++)
 | 
			
		||||
        {
 | 
			
		||||
            int t = lt + pt*ld;
 | 
			
		||||
            if (pt == pc)
 | 
			
		||||
            {
 | 
			
		||||
                for(int i=0;i<Lblock;i++)
 | 
			
		||||
                for(int j=0;j<Rblock;j++)
 | 
			
		||||
                for(int m=0;m<Nmom;m++)
 | 
			
		||||
                {
 | 
			
		||||
                    int ij_dx = m+Nmom*i + Nmom*Lblock * j + Nmom*Lblock * Rblock * lt;
 | 
			
		||||
 | 
			
		||||
                    for(int mu=0;mu<Ngamma;mu++)
 | 
			
		||||
                    {
 | 
			
		||||
                        // this is a bit slow
 | 
			
		||||
                        mat(m,mu,t,i,j) = trace(lsSum[ij_dx]*Gamma(gamma[mu]));
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            } 
 | 
			
		||||
            else 
 | 
			
		||||
            { 
 | 
			
		||||
                const scalar_type zz(0.0);
 | 
			
		||||
 | 
			
		||||
                for(int i=0;i<Lblock;i++)
 | 
			
		||||
                for(int j=0;j<Rblock;j++)
 | 
			
		||||
                for(int mu=0;mu<Ngamma;mu++)
 | 
			
		||||
                for(int m=0;m<Nmom;m++)
 | 
			
		||||
                {
 | 
			
		||||
                    mat(m,mu,t,i,j) =zz;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    if (caller) caller->stopTimer("contraction: spin trace");
 | 
			
		||||
    ////////////////////////////////////////////////////////////////////
 | 
			
		||||
    // This global sum is taking as much as 50% of time on 16 nodes
 | 
			
		||||
    // Vector size is 7 x 16 x 32 x 16 x 16 x sizeof(complex) = 2MB - 60MB depending on volume
 | 
			
		||||
    // Healthy size that should suffice
 | 
			
		||||
    ////////////////////////////////////////////////////////////////////
 | 
			
		||||
    if (caller) caller->startTimer("contraction: global sum");
 | 
			
		||||
    grid->GlobalSumVector(&mat(0,0,0,0,0),Nmom*Ngamma*Nt*Lblock*Rblock);
 | 
			
		||||
    if (caller) caller->stopTimer("contraction: global sum");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
END_MODULE_NAMESPACE
 | 
			
		||||
 | 
			
		||||
END_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
#endif //Hadrons_MContraction_A2AMesonField_hpp_
 | 
			
		||||
							
								
								
									
										35
									
								
								Hadrons/Modules/MContraction/Baryon.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								Hadrons/Modules/MContraction/Baryon.cc
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,35 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MContraction/Baryon.cc
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
#include <Hadrons/Modules/MContraction/Baryon.hpp>
 | 
			
		||||
 | 
			
		||||
using namespace Grid;
 | 
			
		||||
using namespace Hadrons;
 | 
			
		||||
using namespace MContraction;
 | 
			
		||||
 | 
			
		||||
template class Grid::Hadrons::MContraction::TBaryon<FIMPL,FIMPL,FIMPL>;
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										140
									
								
								Hadrons/Modules/MContraction/Baryon.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										140
									
								
								Hadrons/Modules/MContraction/Baryon.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,140 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MContraction/Baryon.hpp
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
Author: Antonin Portelli <antonin.portelli@me.com>
 | 
			
		||||
Author: Lanny91 <andrew.lawson@gmail.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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
 | 
			
		||||
#ifndef Hadrons_MContraction_Baryon_hpp_
 | 
			
		||||
#define Hadrons_MContraction_Baryon_hpp_
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Global.hpp>
 | 
			
		||||
#include <Hadrons/Module.hpp>
 | 
			
		||||
#include <Hadrons/ModuleFactory.hpp>
 | 
			
		||||
 | 
			
		||||
BEGIN_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                               Baryon                                       *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
BEGIN_MODULE_NAMESPACE(MContraction)
 | 
			
		||||
 | 
			
		||||
class BaryonPar: Serializable
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    GRID_SERIALIZABLE_CLASS_MEMBERS(BaryonPar,
 | 
			
		||||
                                    std::string, q1,
 | 
			
		||||
                                    std::string, q2,
 | 
			
		||||
                                    std::string, q3,
 | 
			
		||||
                                    std::string, output);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
template <typename FImpl1, typename FImpl2, typename FImpl3>
 | 
			
		||||
class TBaryon: public Module<BaryonPar>
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    FERM_TYPE_ALIASES(FImpl1, 1);
 | 
			
		||||
    FERM_TYPE_ALIASES(FImpl2, 2);
 | 
			
		||||
    FERM_TYPE_ALIASES(FImpl3, 3);
 | 
			
		||||
    class Result: Serializable
 | 
			
		||||
    {
 | 
			
		||||
    public:
 | 
			
		||||
        GRID_SERIALIZABLE_CLASS_MEMBERS(Result,
 | 
			
		||||
                                        std::vector<std::vector<std::vector<Complex>>>, corr);
 | 
			
		||||
    };
 | 
			
		||||
public:
 | 
			
		||||
    // constructor
 | 
			
		||||
    TBaryon(const std::string name);
 | 
			
		||||
    // destructor
 | 
			
		||||
    virtual ~TBaryon(void) {};
 | 
			
		||||
    // dependency relation
 | 
			
		||||
    virtual std::vector<std::string> getInput(void);
 | 
			
		||||
    virtual std::vector<std::string> getOutput(void);
 | 
			
		||||
protected:
 | 
			
		||||
    // setup
 | 
			
		||||
    virtual void setup(void);
 | 
			
		||||
    // execution
 | 
			
		||||
    virtual void execute(void);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
MODULE_REGISTER_TMP(Baryon, ARG(TBaryon<FIMPL, FIMPL, FIMPL>), MContraction);
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                         TBaryon implementation                             *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
// constructor /////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl1, typename FImpl2, typename FImpl3>
 | 
			
		||||
TBaryon<FImpl1, FImpl2, FImpl3>::TBaryon(const std::string name)
 | 
			
		||||
: Module<BaryonPar>(name)
 | 
			
		||||
{}
 | 
			
		||||
 | 
			
		||||
// dependencies/products ///////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl1, typename FImpl2, typename FImpl3>
 | 
			
		||||
std::vector<std::string> TBaryon<FImpl1, FImpl2, FImpl3>::getInput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> input = {par().q1, par().q2, par().q3};
 | 
			
		||||
    
 | 
			
		||||
    return input;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename FImpl1, typename FImpl2, typename FImpl3>
 | 
			
		||||
std::vector<std::string> TBaryon<FImpl1, FImpl2, FImpl3>::getOutput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> out = {};
 | 
			
		||||
    
 | 
			
		||||
    return out;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// setup ///////////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl1, typename FImpl2, typename FImpl3>
 | 
			
		||||
void TBaryon<FImpl1, FImpl2, FImpl3>::setup(void)
 | 
			
		||||
{
 | 
			
		||||
    envTmpLat(LatticeComplex, "c");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// execution ///////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl1, typename FImpl2, typename FImpl3>
 | 
			
		||||
void TBaryon<FImpl1, FImpl2, FImpl3>::execute(void)
 | 
			
		||||
{
 | 
			
		||||
    LOG(Message) << "Computing baryon contractions '" << getName() << "' using"
 | 
			
		||||
                 << " quarks '" << par().q1 << "', '" << par().q2 << "', and '"
 | 
			
		||||
                 << par().q3 << "'" << std::endl;
 | 
			
		||||
    
 | 
			
		||||
    auto       &q1 = envGet(PropagatorField1, par().q1);
 | 
			
		||||
    auto       &q2 = envGet(PropagatorField2, par().q2);
 | 
			
		||||
    auto       &q3 = envGet(PropagatorField3, par().q2);
 | 
			
		||||
    envGetTmp(LatticeComplex, c);
 | 
			
		||||
    Result     result;
 | 
			
		||||
    
 | 
			
		||||
    // FIXME: do contractions
 | 
			
		||||
    
 | 
			
		||||
    // saveResult(par().output, "meson", result);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
END_MODULE_NAMESPACE
 | 
			
		||||
 | 
			
		||||
END_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
#endif // Hadrons_MContraction_Baryon_hpp_
 | 
			
		||||
							
								
								
									
										35
									
								
								Hadrons/Modules/MContraction/DiscLoop.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								Hadrons/Modules/MContraction/DiscLoop.cc
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,35 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MContraction/DiscLoop.cc
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
#include <Hadrons/Modules/MContraction/DiscLoop.hpp>
 | 
			
		||||
 | 
			
		||||
using namespace Grid;
 | 
			
		||||
using namespace Hadrons;
 | 
			
		||||
using namespace MContraction;
 | 
			
		||||
 | 
			
		||||
template class Grid::Hadrons::MContraction::TDiscLoop<FIMPL>;
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										143
									
								
								Hadrons/Modules/MContraction/DiscLoop.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										143
									
								
								Hadrons/Modules/MContraction/DiscLoop.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,143 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MContraction/DiscLoop.hpp
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
Author: Antonin Portelli <antonin.portelli@me.com>
 | 
			
		||||
Author: Lanny91 <andrew.lawson@gmail.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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
 | 
			
		||||
#ifndef Hadrons_MContraction_DiscLoop_hpp_
 | 
			
		||||
#define Hadrons_MContraction_DiscLoop_hpp_
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Global.hpp>
 | 
			
		||||
#include <Hadrons/Module.hpp>
 | 
			
		||||
#include <Hadrons/ModuleFactory.hpp>
 | 
			
		||||
 | 
			
		||||
BEGIN_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                                DiscLoop                                    *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
BEGIN_MODULE_NAMESPACE(MContraction)
 | 
			
		||||
 | 
			
		||||
class DiscLoopPar: Serializable
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    GRID_SERIALIZABLE_CLASS_MEMBERS(DiscLoopPar,
 | 
			
		||||
                                    std::string,    q_loop,
 | 
			
		||||
                                    Gamma::Algebra, gamma,
 | 
			
		||||
                                    std::string,    output);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
class TDiscLoop: public Module<DiscLoopPar>
 | 
			
		||||
{
 | 
			
		||||
    FERM_TYPE_ALIASES(FImpl,);
 | 
			
		||||
    class Result: Serializable
 | 
			
		||||
    {
 | 
			
		||||
    public:
 | 
			
		||||
        GRID_SERIALIZABLE_CLASS_MEMBERS(Result,
 | 
			
		||||
                                        Gamma::Algebra, gamma,
 | 
			
		||||
                                        std::vector<Complex>, corr);
 | 
			
		||||
    };
 | 
			
		||||
public:
 | 
			
		||||
    // constructor
 | 
			
		||||
    TDiscLoop(const std::string name);
 | 
			
		||||
    // destructor
 | 
			
		||||
    virtual ~TDiscLoop(void) {};
 | 
			
		||||
    // dependency relation
 | 
			
		||||
    virtual std::vector<std::string> getInput(void);
 | 
			
		||||
    virtual std::vector<std::string> getOutput(void);
 | 
			
		||||
protected:
 | 
			
		||||
    // setup
 | 
			
		||||
    virtual void setup(void);
 | 
			
		||||
    // execution
 | 
			
		||||
    virtual void execute(void);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
MODULE_REGISTER_TMP(DiscLoop, TDiscLoop<FIMPL>, MContraction);
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                       TDiscLoop implementation                             *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
// constructor /////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
TDiscLoop<FImpl>::TDiscLoop(const std::string name)
 | 
			
		||||
: Module<DiscLoopPar>(name)
 | 
			
		||||
{}
 | 
			
		||||
 | 
			
		||||
// dependencies/products ///////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
std::vector<std::string> TDiscLoop<FImpl>::getInput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> in = {par().q_loop};
 | 
			
		||||
    
 | 
			
		||||
    return in;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
std::vector<std::string> TDiscLoop<FImpl>::getOutput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> out = {};
 | 
			
		||||
    
 | 
			
		||||
    return out;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// setup ///////////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
void TDiscLoop<FImpl>::setup(void)
 | 
			
		||||
{
 | 
			
		||||
    envTmpLat(LatticeComplex, "c");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// execution ///////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
void TDiscLoop<FImpl>::execute(void)
 | 
			
		||||
{
 | 
			
		||||
    LOG(Message) << "Computing disconnected loop contraction '" << getName() 
 | 
			
		||||
                 << "' using '" << par().q_loop << "' with " << par().gamma 
 | 
			
		||||
                 << " insertion." << std::endl;
 | 
			
		||||
 | 
			
		||||
    auto                  &q_loop = envGet(PropagatorField, par().q_loop);
 | 
			
		||||
    Gamma                 gamma(par().gamma);
 | 
			
		||||
    std::vector<TComplex> buf;
 | 
			
		||||
    Result                result;
 | 
			
		||||
 | 
			
		||||
    envGetTmp(LatticeComplex, c);
 | 
			
		||||
    c = trace(gamma*q_loop);
 | 
			
		||||
    sliceSum(c, buf, Tp);
 | 
			
		||||
    result.gamma = par().gamma;
 | 
			
		||||
    result.corr.resize(buf.size());
 | 
			
		||||
    for (unsigned int t = 0; t < buf.size(); ++t)
 | 
			
		||||
    {
 | 
			
		||||
        result.corr[t] = TensorRemove(buf[t]);
 | 
			
		||||
    }
 | 
			
		||||
    saveResult(par().output, "disc", result);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
END_MODULE_NAMESPACE
 | 
			
		||||
 | 
			
		||||
END_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
#endif // Hadrons_MContraction_DiscLoop_hpp_
 | 
			
		||||
							
								
								
									
										35
									
								
								Hadrons/Modules/MContraction/Gamma3pt.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								Hadrons/Modules/MContraction/Gamma3pt.cc
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,35 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MContraction/Gamma3pt.cc
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
#include <Hadrons/Modules/MContraction/Gamma3pt.hpp>
 | 
			
		||||
 | 
			
		||||
using namespace Grid;
 | 
			
		||||
using namespace Hadrons;
 | 
			
		||||
using namespace MContraction;
 | 
			
		||||
 | 
			
		||||
template class Grid::Hadrons::MContraction::TGamma3pt<FIMPL,FIMPL,FIMPL>;
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										184
									
								
								Hadrons/Modules/MContraction/Gamma3pt.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										184
									
								
								Hadrons/Modules/MContraction/Gamma3pt.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,184 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MContraction/Gamma3pt.hpp
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
Author: Antonin Portelli <antonin.portelli@me.com>
 | 
			
		||||
Author: Lanny91 <andrew.lawson@gmail.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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
 | 
			
		||||
#ifndef Hadrons_MContraction_Gamma3pt_hpp_
 | 
			
		||||
#define Hadrons_MContraction_Gamma3pt_hpp_
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Global.hpp>
 | 
			
		||||
#include <Hadrons/Module.hpp>
 | 
			
		||||
#include <Hadrons/ModuleFactory.hpp>
 | 
			
		||||
 | 
			
		||||
BEGIN_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * 3pt contraction with gamma matrix insertion.
 | 
			
		||||
 *
 | 
			
		||||
 * Schematic:
 | 
			
		||||
 *
 | 
			
		||||
 *             q2           q3
 | 
			
		||||
 *        /----<------*------<----¬
 | 
			
		||||
 *       /          gamma          \
 | 
			
		||||
 *      /                           \
 | 
			
		||||
 *   i *                            * f
 | 
			
		||||
 *      \                          /
 | 
			
		||||
 *       \                        /
 | 
			
		||||
 *        \----------->----------/
 | 
			
		||||
 *                   q1
 | 
			
		||||
 *
 | 
			
		||||
 *      trace(g5*q1*adj(q2)*g5*gamma*q3)
 | 
			
		||||
 * 
 | 
			
		||||
 *  options:
 | 
			
		||||
 *   - q1: sink smeared propagator, source at i
 | 
			
		||||
 *   - q2: propagator, source at i
 | 
			
		||||
 *   - q3: propagator, source at f
 | 
			
		||||
 *   - gamma: gamma matrix to insert
 | 
			
		||||
 *   - tSnk: sink position for propagator q1.
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                               Gamma3pt                                     *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
BEGIN_MODULE_NAMESPACE(MContraction)
 | 
			
		||||
 | 
			
		||||
class Gamma3ptPar: Serializable
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    GRID_SERIALIZABLE_CLASS_MEMBERS(Gamma3ptPar,
 | 
			
		||||
                                    std::string,    q1,
 | 
			
		||||
                                    std::string,    q2,
 | 
			
		||||
                                    std::string,    q3,
 | 
			
		||||
                                    Gamma::Algebra, gamma,
 | 
			
		||||
                                    unsigned int,   tSnk,
 | 
			
		||||
                                    std::string,    output);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
template <typename FImpl1, typename FImpl2, typename FImpl3>
 | 
			
		||||
class TGamma3pt: public Module<Gamma3ptPar>
 | 
			
		||||
{
 | 
			
		||||
    FERM_TYPE_ALIASES(FImpl1, 1);
 | 
			
		||||
    FERM_TYPE_ALIASES(FImpl2, 2);
 | 
			
		||||
    FERM_TYPE_ALIASES(FImpl3, 3);
 | 
			
		||||
    class Result: Serializable
 | 
			
		||||
    {
 | 
			
		||||
    public:
 | 
			
		||||
        GRID_SERIALIZABLE_CLASS_MEMBERS(Result,
 | 
			
		||||
                                        Gamma::Algebra, gamma,
 | 
			
		||||
                                        std::vector<Complex>, corr);
 | 
			
		||||
    };
 | 
			
		||||
public:
 | 
			
		||||
    // constructor
 | 
			
		||||
    TGamma3pt(const std::string name);
 | 
			
		||||
    // destructor
 | 
			
		||||
    virtual ~TGamma3pt(void) {};
 | 
			
		||||
    // dependency relation
 | 
			
		||||
    virtual std::vector<std::string> getInput(void);
 | 
			
		||||
    virtual std::vector<std::string> getOutput(void);
 | 
			
		||||
protected:
 | 
			
		||||
    // setup
 | 
			
		||||
    virtual void setup(void);
 | 
			
		||||
    // execution
 | 
			
		||||
    virtual void execute(void);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
MODULE_REGISTER_TMP(Gamma3pt, ARG(TGamma3pt<FIMPL, FIMPL, FIMPL>), MContraction);
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                       TGamma3pt implementation                             *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
// constructor /////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl1, typename FImpl2, typename FImpl3>
 | 
			
		||||
TGamma3pt<FImpl1, FImpl2, FImpl3>::TGamma3pt(const std::string name)
 | 
			
		||||
: Module<Gamma3ptPar>(name)
 | 
			
		||||
{}
 | 
			
		||||
 | 
			
		||||
// dependencies/products ///////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl1, typename FImpl2, typename FImpl3>
 | 
			
		||||
std::vector<std::string> TGamma3pt<FImpl1, FImpl2, FImpl3>::getInput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> in = {par().q1, par().q2, par().q3};
 | 
			
		||||
    
 | 
			
		||||
    return in;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename FImpl1, typename FImpl2, typename FImpl3>
 | 
			
		||||
std::vector<std::string> TGamma3pt<FImpl1, FImpl2, FImpl3>::getOutput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> out = {};
 | 
			
		||||
    
 | 
			
		||||
    return out;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// setup ///////////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl1, typename FImpl2, typename FImpl3>
 | 
			
		||||
void TGamma3pt<FImpl1, FImpl2, FImpl3>::setup(void)
 | 
			
		||||
{
 | 
			
		||||
    envTmpLat(LatticeComplex, "c");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// execution ///////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl1, typename FImpl2, typename FImpl3>
 | 
			
		||||
void TGamma3pt<FImpl1, FImpl2, FImpl3>::execute(void)
 | 
			
		||||
{
 | 
			
		||||
    LOG(Message) << "Computing 3pt contractions '" << getName() << "' using"
 | 
			
		||||
                 << " quarks '" << par().q1 << "', '" << par().q2 << "' and '"
 | 
			
		||||
                 << par().q3 << "', with " << par().gamma << " insertion." 
 | 
			
		||||
                 << std::endl;
 | 
			
		||||
 | 
			
		||||
    // Initialise variables. q2 and q3 are normal propagators, q1 may be 
 | 
			
		||||
    // sink smeared.
 | 
			
		||||
    auto                  &q1 = envGet(SlicedPropagator1, par().q1);
 | 
			
		||||
    auto                  &q2 = envGet(PropagatorField2, par().q2);
 | 
			
		||||
    auto                  &q3 = envGet(PropagatorField2, par().q3);
 | 
			
		||||
    Gamma                 g5(Gamma::Algebra::Gamma5);
 | 
			
		||||
    Gamma                 gamma(par().gamma);
 | 
			
		||||
    std::vector<TComplex> buf;
 | 
			
		||||
    Result                result;
 | 
			
		||||
    
 | 
			
		||||
    // Extract relevant timeslice of sinked propagator q1, then contract &
 | 
			
		||||
    // sum over all spacial positions of gamma insertion.
 | 
			
		||||
    SitePropagator1 q1Snk = q1[par().tSnk];
 | 
			
		||||
    envGetTmp(LatticeComplex, c);
 | 
			
		||||
    c = trace(g5*q1Snk*adj(q2)*(g5*gamma)*q3);
 | 
			
		||||
    sliceSum(c, buf, Tp);
 | 
			
		||||
 | 
			
		||||
    result.gamma = par().gamma;
 | 
			
		||||
    result.corr.resize(buf.size());
 | 
			
		||||
    for (unsigned int t = 0; t < buf.size(); ++t)
 | 
			
		||||
    {
 | 
			
		||||
        result.corr[t] = TensorRemove(buf[t]);
 | 
			
		||||
    }
 | 
			
		||||
    saveResult(par().output, "gamma3pt", result);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
END_MODULE_NAMESPACE
 | 
			
		||||
 | 
			
		||||
END_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
#endif // Hadrons_MContraction_Gamma3pt_hpp_
 | 
			
		||||
							
								
								
									
										35
									
								
								Hadrons/Modules/MContraction/Meson.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								Hadrons/Modules/MContraction/Meson.cc
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,35 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MContraction/Meson.cc
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
#include <Hadrons/Modules/MContraction/Meson.hpp>
 | 
			
		||||
 | 
			
		||||
using namespace Grid;
 | 
			
		||||
using namespace Hadrons;
 | 
			
		||||
using namespace MContraction;
 | 
			
		||||
 | 
			
		||||
template class Grid::Hadrons::MContraction::TMeson<FIMPL,FIMPL>;
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										249
									
								
								Hadrons/Modules/MContraction/Meson.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										249
									
								
								Hadrons/Modules/MContraction/Meson.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,249 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MContraction/Meson.hpp
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
Author: Antonin Portelli <antonin.portelli@me.com>
 | 
			
		||||
Author: Lanny91 <andrew.lawson@gmail.com>
 | 
			
		||||
Author: Vera Guelpers <vmg1n14@soton.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 */
 | 
			
		||||
 | 
			
		||||
#ifndef Hadrons_MContraction_Meson_hpp_
 | 
			
		||||
#define Hadrons_MContraction_Meson_hpp_
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Global.hpp>
 | 
			
		||||
#include <Hadrons/Module.hpp>
 | 
			
		||||
#include <Hadrons/ModuleFactory.hpp>
 | 
			
		||||
 | 
			
		||||
BEGIN_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 
 | 
			
		||||
 Meson contractions
 | 
			
		||||
 -----------------------------
 | 
			
		||||
 
 | 
			
		||||
 * options:
 | 
			
		||||
 - q1: input propagator 1 (string)
 | 
			
		||||
 - q2: input propagator 2 (string)
 | 
			
		||||
 - gammas: gamma products to insert at sink & source, pairs of gamma matrices 
 | 
			
		||||
           (space-separated strings) in round brackets (i.e. (g_sink g_src)),
 | 
			
		||||
           in a sequence (e.g. "(Gamma5 Gamma5)(Gamma5 GammaT)").
 | 
			
		||||
 | 
			
		||||
           Special values: "all" - perform all possible contractions.
 | 
			
		||||
 - sink: module to compute the sink to use in contraction (string).
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                                TMeson                                       *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
BEGIN_MODULE_NAMESPACE(MContraction)
 | 
			
		||||
 | 
			
		||||
typedef std::pair<Gamma::Algebra, Gamma::Algebra> GammaPair;
 | 
			
		||||
 | 
			
		||||
class MesonPar: Serializable
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    GRID_SERIALIZABLE_CLASS_MEMBERS(MesonPar,
 | 
			
		||||
                                    std::string, q1,
 | 
			
		||||
                                    std::string, q2,
 | 
			
		||||
                                    std::string, gammas,
 | 
			
		||||
                                    std::string, sink,
 | 
			
		||||
                                    std::string, output);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
template <typename FImpl1, typename FImpl2>
 | 
			
		||||
class TMeson: public Module<MesonPar>
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    FERM_TYPE_ALIASES(FImpl1, 1);
 | 
			
		||||
    FERM_TYPE_ALIASES(FImpl2, 2);
 | 
			
		||||
    FERM_TYPE_ALIASES(ScalarImplCR, Scalar);
 | 
			
		||||
    SINK_TYPE_ALIASES(Scalar);
 | 
			
		||||
    class Result: Serializable
 | 
			
		||||
    {
 | 
			
		||||
    public:
 | 
			
		||||
        GRID_SERIALIZABLE_CLASS_MEMBERS(Result,
 | 
			
		||||
                                        Gamma::Algebra, gamma_snk,
 | 
			
		||||
                                        Gamma::Algebra, gamma_src,
 | 
			
		||||
                                        std::vector<Complex>, corr);
 | 
			
		||||
    };
 | 
			
		||||
public:
 | 
			
		||||
    // constructor
 | 
			
		||||
    TMeson(const std::string name);
 | 
			
		||||
    // destructor
 | 
			
		||||
    virtual ~TMeson(void) {};
 | 
			
		||||
    // dependencies/products
 | 
			
		||||
    virtual std::vector<std::string> getInput(void);
 | 
			
		||||
    virtual std::vector<std::string> getOutput(void);
 | 
			
		||||
    virtual void parseGammaString(std::vector<GammaPair> &gammaList);
 | 
			
		||||
protected:
 | 
			
		||||
    // execution
 | 
			
		||||
    virtual void setup(void);
 | 
			
		||||
    // execution
 | 
			
		||||
    virtual void execute(void);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
MODULE_REGISTER_TMP(Meson, ARG(TMeson<FIMPL, FIMPL>), MContraction);
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                           TMeson implementation                            *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
// constructor /////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl1, typename FImpl2>
 | 
			
		||||
TMeson<FImpl1, FImpl2>::TMeson(const std::string name)
 | 
			
		||||
: Module<MesonPar>(name)
 | 
			
		||||
{}
 | 
			
		||||
 | 
			
		||||
// dependencies/products ///////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl1, typename FImpl2>
 | 
			
		||||
std::vector<std::string> TMeson<FImpl1, FImpl2>::getInput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> input = {par().q1, par().q2, par().sink};
 | 
			
		||||
    
 | 
			
		||||
    return input;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename FImpl1, typename FImpl2>
 | 
			
		||||
std::vector<std::string> TMeson<FImpl1, FImpl2>::getOutput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> output = {};
 | 
			
		||||
    
 | 
			
		||||
    return output;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename FImpl1, typename FImpl2>
 | 
			
		||||
void TMeson<FImpl1, FImpl2>::parseGammaString(std::vector<GammaPair> &gammaList)
 | 
			
		||||
{
 | 
			
		||||
    gammaList.clear();
 | 
			
		||||
    // Determine gamma matrices to insert at source/sink.
 | 
			
		||||
    if (par().gammas.compare("all") == 0)
 | 
			
		||||
    {
 | 
			
		||||
        // Do all contractions.
 | 
			
		||||
        for (unsigned int i = 1; i < Gamma::nGamma; i += 2)
 | 
			
		||||
        {
 | 
			
		||||
            for (unsigned int j = 1; j < Gamma::nGamma; j += 2)
 | 
			
		||||
            {
 | 
			
		||||
                gammaList.push_back(std::make_pair((Gamma::Algebra)i, 
 | 
			
		||||
                                                   (Gamma::Algebra)j));
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        // Parse individual contractions from input string.
 | 
			
		||||
        gammaList = strToVec<GammaPair>(par().gammas);
 | 
			
		||||
    } 
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// execution ///////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl1, typename FImpl2>
 | 
			
		||||
void TMeson<FImpl1, FImpl2>::setup(void)
 | 
			
		||||
{
 | 
			
		||||
    envTmpLat(LatticeComplex, "c");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// execution ///////////////////////////////////////////////////////////////////
 | 
			
		||||
#define mesonConnected(q1, q2, gSnk, gSrc) \
 | 
			
		||||
(g5*(gSnk))*(q1)*(adj(gSrc)*g5)*adj(q2)
 | 
			
		||||
 | 
			
		||||
template <typename FImpl1, typename FImpl2>
 | 
			
		||||
void TMeson<FImpl1, FImpl2>::execute(void)
 | 
			
		||||
{
 | 
			
		||||
    LOG(Message) << "Computing meson contractions '" << getName() << "' using"
 | 
			
		||||
                 << " quarks '" << par().q1 << "' and '" << par().q2 << "'"
 | 
			
		||||
                 << std::endl;
 | 
			
		||||
    
 | 
			
		||||
    std::vector<TComplex>  buf;
 | 
			
		||||
    std::vector<Result>    result;
 | 
			
		||||
    Gamma                  g5(Gamma::Algebra::Gamma5);
 | 
			
		||||
    std::vector<GammaPair> gammaList;
 | 
			
		||||
    int                    nt = env().getDim(Tp);
 | 
			
		||||
    
 | 
			
		||||
    parseGammaString(gammaList);
 | 
			
		||||
    result.resize(gammaList.size());
 | 
			
		||||
    for (unsigned int i = 0; i < result.size(); ++i)
 | 
			
		||||
    {
 | 
			
		||||
        result[i].gamma_snk = gammaList[i].first;
 | 
			
		||||
        result[i].gamma_src = gammaList[i].second;
 | 
			
		||||
        result[i].corr.resize(nt);
 | 
			
		||||
    }
 | 
			
		||||
    if (envHasType(SlicedPropagator1, par().q1) and
 | 
			
		||||
        envHasType(SlicedPropagator2, par().q2))
 | 
			
		||||
    {
 | 
			
		||||
        auto &q1 = envGet(SlicedPropagator1, par().q1);
 | 
			
		||||
        auto &q2 = envGet(SlicedPropagator2, par().q2);
 | 
			
		||||
        
 | 
			
		||||
        LOG(Message) << "(propagator already sinked)" << std::endl;
 | 
			
		||||
        for (unsigned int i = 0; i < result.size(); ++i)
 | 
			
		||||
        {
 | 
			
		||||
            Gamma gSnk(gammaList[i].first);
 | 
			
		||||
            Gamma gSrc(gammaList[i].second);
 | 
			
		||||
            
 | 
			
		||||
            for (unsigned int t = 0; t < buf.size(); ++t)
 | 
			
		||||
            {
 | 
			
		||||
                result[i].corr[t] = TensorRemove(trace(mesonConnected(q1[t], q2[t], gSnk, gSrc)));
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        auto &q1 = envGet(PropagatorField1, par().q1);
 | 
			
		||||
        auto &q2 = envGet(PropagatorField2, par().q2);
 | 
			
		||||
        
 | 
			
		||||
        envGetTmp(LatticeComplex, c);
 | 
			
		||||
        LOG(Message) << "(using sink '" << par().sink << "')" << std::endl;
 | 
			
		||||
        for (unsigned int i = 0; i < result.size(); ++i)
 | 
			
		||||
        {
 | 
			
		||||
            Gamma       gSnk(gammaList[i].first);
 | 
			
		||||
            Gamma       gSrc(gammaList[i].second);
 | 
			
		||||
            std::string ns;
 | 
			
		||||
                
 | 
			
		||||
            ns = vm().getModuleNamespace(env().getObjectModule(par().sink));
 | 
			
		||||
            if (ns == "MSource")
 | 
			
		||||
            {
 | 
			
		||||
                PropagatorField1 &sink = envGet(PropagatorField1, par().sink);
 | 
			
		||||
                
 | 
			
		||||
                c = trace(mesonConnected(q1, q2, gSnk, gSrc)*sink);
 | 
			
		||||
                sliceSum(c, buf, Tp);
 | 
			
		||||
            }
 | 
			
		||||
            else if (ns == "MSink")
 | 
			
		||||
            {
 | 
			
		||||
                SinkFnScalar &sink = envGet(SinkFnScalar, par().sink);
 | 
			
		||||
                
 | 
			
		||||
                c   = trace(mesonConnected(q1, q2, gSnk, gSrc));
 | 
			
		||||
                buf = sink(c);
 | 
			
		||||
            }
 | 
			
		||||
            for (unsigned int t = 0; t < buf.size(); ++t)
 | 
			
		||||
            {
 | 
			
		||||
                result[i].corr[t] = TensorRemove(buf[t]);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    saveResult(par().output, "meson", result);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
END_MODULE_NAMESPACE
 | 
			
		||||
 | 
			
		||||
END_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
#endif // Hadrons_MContraction_Meson_hpp_
 | 
			
		||||
							
								
								
									
										35
									
								
								Hadrons/Modules/MContraction/WardIdentity.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								Hadrons/Modules/MContraction/WardIdentity.cc
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,35 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MContraction/WardIdentity.cc
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
#include <Hadrons/Modules/MContraction/WardIdentity.hpp>
 | 
			
		||||
 | 
			
		||||
using namespace Grid;
 | 
			
		||||
using namespace Hadrons;
 | 
			
		||||
using namespace MContraction;
 | 
			
		||||
 | 
			
		||||
template class Grid::Hadrons::MContraction::TWardIdentity<FIMPL>;
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										224
									
								
								Hadrons/Modules/MContraction/WardIdentity.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										224
									
								
								Hadrons/Modules/MContraction/WardIdentity.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,224 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MContraction/WardIdentity.hpp
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
Author: Antonin Portelli <antonin.portelli@me.com>
 | 
			
		||||
Author: Lanny91 <andrew.lawson@gmail.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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
 | 
			
		||||
#ifndef Hadrons_MContraction_WardIdentity_hpp_
 | 
			
		||||
#define Hadrons_MContraction_WardIdentity_hpp_
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Global.hpp>
 | 
			
		||||
#include <Hadrons/Module.hpp>
 | 
			
		||||
#include <Hadrons/ModuleFactory.hpp>
 | 
			
		||||
 | 
			
		||||
BEGIN_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
  Ward Identity contractions
 | 
			
		||||
 -----------------------------
 | 
			
		||||
 
 | 
			
		||||
 * options:
 | 
			
		||||
 - q:          propagator, 5D if available (string)
 | 
			
		||||
 - action:     action module used for propagator solution (string)
 | 
			
		||||
 - mass:       mass of quark (double)
 | 
			
		||||
 - test_axial: whether or not to test PCAC relation.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                              WardIdentity                                  *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
BEGIN_MODULE_NAMESPACE(MContraction)
 | 
			
		||||
 | 
			
		||||
class WardIdentityPar: Serializable
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    GRID_SERIALIZABLE_CLASS_MEMBERS(WardIdentityPar,
 | 
			
		||||
                                    std::string, q,
 | 
			
		||||
                                    std::string, action,
 | 
			
		||||
                                    double,      mass,
 | 
			
		||||
                                    bool,        test_axial);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
class TWardIdentity: public Module<WardIdentityPar>
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    FERM_TYPE_ALIASES(FImpl,);
 | 
			
		||||
public:
 | 
			
		||||
    // constructor
 | 
			
		||||
    TWardIdentity(const std::string name);
 | 
			
		||||
    // destructor
 | 
			
		||||
    virtual ~TWardIdentity(void) {};
 | 
			
		||||
    // dependency relation
 | 
			
		||||
    virtual std::vector<std::string> getInput(void);
 | 
			
		||||
    virtual std::vector<std::string> getOutput(void);
 | 
			
		||||
protected:
 | 
			
		||||
    // setup
 | 
			
		||||
    virtual void setup(void);
 | 
			
		||||
    // execution
 | 
			
		||||
    virtual void execute(void);
 | 
			
		||||
private:
 | 
			
		||||
    unsigned int Ls_;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
MODULE_REGISTER_TMP(WardIdentity, TWardIdentity<FIMPL>, MContraction);
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                     TWardIdentity implementation                           *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
// constructor /////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
TWardIdentity<FImpl>::TWardIdentity(const std::string name)
 | 
			
		||||
: Module<WardIdentityPar>(name)
 | 
			
		||||
{}
 | 
			
		||||
 | 
			
		||||
// dependencies/products ///////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
std::vector<std::string> TWardIdentity<FImpl>::getInput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> in = {par().q, par().action};
 | 
			
		||||
    
 | 
			
		||||
    return in;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
std::vector<std::string> TWardIdentity<FImpl>::getOutput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> out = {};
 | 
			
		||||
    
 | 
			
		||||
    return out;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// setup ///////////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
void TWardIdentity<FImpl>::setup(void)
 | 
			
		||||
{
 | 
			
		||||
    Ls_ = env().getObjectLs(par().q);
 | 
			
		||||
    if (Ls_ != env().getObjectLs(par().action))
 | 
			
		||||
    {
 | 
			
		||||
        HADRONS_ERROR(Size, "Ls mismatch between quark action and propagator");
 | 
			
		||||
    }
 | 
			
		||||
    envTmpLat(PropagatorField, "tmp");
 | 
			
		||||
    envTmpLat(PropagatorField, "vector_WI");
 | 
			
		||||
    if (par().test_axial)
 | 
			
		||||
    {
 | 
			
		||||
        envTmpLat(PropagatorField, "psi");
 | 
			
		||||
        envTmpLat(LatticeComplex,  "PP");
 | 
			
		||||
        envTmpLat(LatticeComplex,  "axial_defect");
 | 
			
		||||
        envTmpLat(LatticeComplex,  "PJ5q");
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// execution ///////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
void TWardIdentity<FImpl>::execute(void)
 | 
			
		||||
{
 | 
			
		||||
    LOG(Message) << "Performing Ward Identity checks for quark '" << par().q
 | 
			
		||||
                 << "'." << std::endl;
 | 
			
		||||
 | 
			
		||||
    auto  &q   = envGet(PropagatorField, par().q);
 | 
			
		||||
    auto  &act = envGet(FMat, par().action);
 | 
			
		||||
    Gamma g5(Gamma::Algebra::Gamma5);
 | 
			
		||||
 | 
			
		||||
    // Compute D_mu V_mu, D here is backward derivative.
 | 
			
		||||
    envGetTmp(PropagatorField, tmp);
 | 
			
		||||
    envGetTmp(PropagatorField, vector_WI);
 | 
			
		||||
    vector_WI    = zero;
 | 
			
		||||
    for (unsigned int mu = 0; mu < Nd; ++mu)
 | 
			
		||||
    {
 | 
			
		||||
        act.ContractConservedCurrent(q, q, tmp, Current::Vector, mu);
 | 
			
		||||
        tmp -= Cshift(tmp, mu, -1);
 | 
			
		||||
        vector_WI += tmp;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Test ward identity D_mu V_mu = 0;
 | 
			
		||||
    LOG(Message) << "Vector Ward Identity check Delta_mu V_mu = " 
 | 
			
		||||
                 << norm2(vector_WI) << std::endl;
 | 
			
		||||
 | 
			
		||||
    if (par().test_axial)
 | 
			
		||||
    {
 | 
			
		||||
        envGetTmp(PropagatorField, psi);
 | 
			
		||||
        envGetTmp(LatticeComplex, PP);
 | 
			
		||||
        envGetTmp(LatticeComplex, axial_defect);
 | 
			
		||||
        envGetTmp(LatticeComplex, PJ5q);
 | 
			
		||||
        std::vector<TComplex> axial_buf;
 | 
			
		||||
 | 
			
		||||
        // Compute <P|D_mu A_mu>, D is backwards derivative.
 | 
			
		||||
        axial_defect = zero;
 | 
			
		||||
        for (unsigned int mu = 0; mu < Nd; ++mu)
 | 
			
		||||
        {
 | 
			
		||||
            act.ContractConservedCurrent(q, q, tmp, Current::Axial, mu);
 | 
			
		||||
            tmp -= Cshift(tmp, mu, -1);
 | 
			
		||||
            axial_defect += trace(g5*tmp);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Get <P|J5q> for 5D (zero for 4D) and <P|P>.
 | 
			
		||||
        PJ5q = zero;
 | 
			
		||||
        if (Ls_ > 1)
 | 
			
		||||
        {
 | 
			
		||||
            // <P|P>
 | 
			
		||||
            ExtractSlice(tmp, q, 0, 0);
 | 
			
		||||
            psi  = 0.5 * (tmp - g5*tmp);
 | 
			
		||||
            ExtractSlice(tmp, q, Ls_ - 1, 0);
 | 
			
		||||
            psi += 0.5 * (tmp + g5*tmp);
 | 
			
		||||
            PP = trace(adj(psi)*psi);
 | 
			
		||||
 | 
			
		||||
            // <P|5Jq>
 | 
			
		||||
            ExtractSlice(tmp, q, Ls_/2 - 1, 0);
 | 
			
		||||
            psi  = 0.5 * (tmp + g5*tmp);
 | 
			
		||||
            ExtractSlice(tmp, q, Ls_/2, 0);
 | 
			
		||||
            psi += 0.5 * (tmp - g5*tmp);
 | 
			
		||||
            PJ5q = trace(adj(psi)*psi);
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            PP = trace(adj(q)*q);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Test ward identity <P|D_mu A_mu> = 2m<P|P> + 2<P|J5q>
 | 
			
		||||
        LOG(Message) << "|D_mu A_mu|^2 = " << norm2(axial_defect) << std::endl;
 | 
			
		||||
        LOG(Message) << "|PP|^2        = " << norm2(PP) << std::endl;
 | 
			
		||||
        LOG(Message) << "|PJ5q|^2      = " << norm2(PJ5q) << std::endl;
 | 
			
		||||
        LOG(Message) << "Axial Ward Identity defect Delta_mu A_mu = "
 | 
			
		||||
                     << norm2(axial_defect) << std::endl;
 | 
			
		||||
    
 | 
			
		||||
        // Axial defect by timeslice.
 | 
			
		||||
        axial_defect -= 2.*(par().mass*PP + PJ5q);
 | 
			
		||||
        LOG(Message) << "Check Axial defect by timeslice" << std::endl;
 | 
			
		||||
        sliceSum(axial_defect, axial_buf, Tp);
 | 
			
		||||
        for (int t = 0; t < axial_buf.size(); ++t)
 | 
			
		||||
        {
 | 
			
		||||
            LOG(Message) << "t = " << t << ": " 
 | 
			
		||||
                         << TensorRemove(axial_buf[t]) << std::endl;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
END_MODULE_NAMESPACE
 | 
			
		||||
 | 
			
		||||
END_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
#endif // Hadrons_WardIdentity_hpp_
 | 
			
		||||
							
								
								
									
										118
									
								
								Hadrons/Modules/MContraction/WeakHamiltonian.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										118
									
								
								Hadrons/Modules/MContraction/WeakHamiltonian.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,118 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MContraction/WeakHamiltonian.hpp
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
Author: Antonin Portelli <antonin.portelli@me.com>
 | 
			
		||||
Author: Lanny91 <andrew.lawson@gmail.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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
 | 
			
		||||
#ifndef Hadrons_MContraction_WeakHamiltonian_hpp_
 | 
			
		||||
#define Hadrons_MContraction_WeakHamiltonian_hpp_
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Global.hpp>
 | 
			
		||||
#include <Hadrons/Module.hpp>
 | 
			
		||||
#include <Hadrons/ModuleFactory.hpp>
 | 
			
		||||
 | 
			
		||||
BEGIN_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                         WeakHamiltonian                                    *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
BEGIN_MODULE_NAMESPACE(MContraction)
 | 
			
		||||
 | 
			
		||||
/*******************************************************************************
 | 
			
		||||
 * Utilities for contractions involving the Weak Hamiltonian.
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
//// Sum and store correlator.
 | 
			
		||||
#define MAKE_DIAG(exp, buf, res, n)\
 | 
			
		||||
sliceSum(exp, buf, Tp);\
 | 
			
		||||
res.name = (n);\
 | 
			
		||||
res.corr.resize(buf.size());\
 | 
			
		||||
for (unsigned int t = 0; t < buf.size(); ++t)\
 | 
			
		||||
{\
 | 
			
		||||
    res.corr[t] = TensorRemove(buf[t]);\
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//// Contraction of mu index: use 'mu' variable in exp.
 | 
			
		||||
#define SUM_MU(buf,exp)\
 | 
			
		||||
buf = zero;\
 | 
			
		||||
for (unsigned int mu = 0; mu < ndim; ++mu)\
 | 
			
		||||
{\
 | 
			
		||||
    buf += exp;\
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
enum 
 | 
			
		||||
{
 | 
			
		||||
  i_V = 0,
 | 
			
		||||
  i_A = 1,
 | 
			
		||||
  n_i = 2
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class WeakHamiltonianPar: Serializable
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    GRID_SERIALIZABLE_CLASS_MEMBERS(WeakHamiltonianPar,
 | 
			
		||||
                                    std::string, q1,
 | 
			
		||||
                                    std::string, q2,
 | 
			
		||||
                                    std::string, q3,
 | 
			
		||||
                                    std::string, q4,
 | 
			
		||||
                                    unsigned int, tSnk,
 | 
			
		||||
                                    std::string, output);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#define MAKE_WEAK_MODULE(modname)\
 | 
			
		||||
class T##modname: public Module<WeakHamiltonianPar>\
 | 
			
		||||
{\
 | 
			
		||||
public:\
 | 
			
		||||
    FERM_TYPE_ALIASES(FIMPL,)\
 | 
			
		||||
    class Result: Serializable\
 | 
			
		||||
    {\
 | 
			
		||||
    public:\
 | 
			
		||||
        GRID_SERIALIZABLE_CLASS_MEMBERS(Result,\
 | 
			
		||||
                                        std::string, name,\
 | 
			
		||||
                                        std::vector<Complex>, corr);\
 | 
			
		||||
    };\
 | 
			
		||||
public:\
 | 
			
		||||
    /* constructor */ \
 | 
			
		||||
    T##modname(const std::string name);\
 | 
			
		||||
    /* destructor */ \
 | 
			
		||||
    virtual ~T##modname(void) {};\
 | 
			
		||||
    /* dependency relation */ \
 | 
			
		||||
    virtual std::vector<std::string> getInput(void);\
 | 
			
		||||
    virtual std::vector<std::string> getOutput(void);\
 | 
			
		||||
public:\
 | 
			
		||||
    std::vector<std::string> VA_label = {"V", "A"};\
 | 
			
		||||
protected:\
 | 
			
		||||
    /* setup */ \
 | 
			
		||||
    virtual void setup(void);\
 | 
			
		||||
    /* execution */ \
 | 
			
		||||
    virtual void execute(void);\
 | 
			
		||||
};\
 | 
			
		||||
MODULE_REGISTER(modname, T##modname, MContraction);
 | 
			
		||||
 | 
			
		||||
END_MODULE_NAMESPACE
 | 
			
		||||
 | 
			
		||||
END_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
#endif // Hadrons_MContraction_WeakHamiltonian_hpp_
 | 
			
		||||
							
								
								
									
										151
									
								
								Hadrons/Modules/MContraction/WeakHamiltonianEye.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										151
									
								
								Hadrons/Modules/MContraction/WeakHamiltonianEye.cc
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,151 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MContraction/WeakHamiltonianEye.cc
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
Author: Antonin Portelli <antonin.portelli@me.com>
 | 
			
		||||
Author: Lanny91 <andrew.lawson@gmail.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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Modules/MContraction/WeakHamiltonianEye.hpp>
 | 
			
		||||
 | 
			
		||||
using namespace Grid;
 | 
			
		||||
using namespace Hadrons;
 | 
			
		||||
using namespace MContraction;
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Weak Hamiltonian current-current contractions, Eye-type.
 | 
			
		||||
 * 
 | 
			
		||||
 * These contractions are generated by the Q1 and Q2 operators in the physical
 | 
			
		||||
 * basis (see e.g. Fig 3 of arXiv:1507.03094).
 | 
			
		||||
 * 
 | 
			
		||||
 * Schematics:        q4                 |                  
 | 
			
		||||
 *                  /-<-¬                |                             
 | 
			
		||||
 *                 /     \               |             q2           q3
 | 
			
		||||
 *                 \     /               |        /----<------*------<----¬                        
 | 
			
		||||
 *            q2    \   /    q3          |       /          /-*-¬          \
 | 
			
		||||
 *       /-----<-----* *-----<----¬      |      /          /     \          \
 | 
			
		||||
 *    i *            H_W           * f   |   i *           \     /  q4      * f
 | 
			
		||||
 *       \                        /      |      \           \->-/          /   
 | 
			
		||||
 *        \                      /       |       \                        /       
 | 
			
		||||
 *         \---------->---------/        |        \----------->----------/        
 | 
			
		||||
 *                   q1                  |                   q1                  
 | 
			
		||||
 *                                       |
 | 
			
		||||
 *                Saucer (S)             |                  Eye (E)
 | 
			
		||||
 * 
 | 
			
		||||
 * S: trace(q3*g5*q1*adj(q2)*g5*gL[mu][p_1]*q4*gL[mu][p_2])
 | 
			
		||||
 * E: trace(q3*g5*q1*adj(q2)*g5*gL[mu][p_1])*trace(q4*gL[mu][p_2])
 | 
			
		||||
 * 
 | 
			
		||||
 * Note q1 must be sink smeared.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                  TWeakHamiltonianEye implementation                        *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
// constructor /////////////////////////////////////////////////////////////////
 | 
			
		||||
TWeakHamiltonianEye::TWeakHamiltonianEye(const std::string name)
 | 
			
		||||
: Module<WeakHamiltonianPar>(name)
 | 
			
		||||
{}
 | 
			
		||||
 | 
			
		||||
// dependencies/products ///////////////////////////////////////////////////////
 | 
			
		||||
std::vector<std::string> TWeakHamiltonianEye::getInput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> in = {par().q1, par().q2, par().q3, par().q4};
 | 
			
		||||
    
 | 
			
		||||
    return in;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::vector<std::string> TWeakHamiltonianEye::getOutput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> out = {};
 | 
			
		||||
    
 | 
			
		||||
    return out;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// setup ///////////////////////////////////////////////////////////////////////
 | 
			
		||||
void TWeakHamiltonianEye::setup(void)
 | 
			
		||||
{
 | 
			
		||||
    unsigned int ndim = env().getNd();
 | 
			
		||||
 | 
			
		||||
    envTmpLat(LatticeComplex,  "expbuf");
 | 
			
		||||
    envTmpLat(PropagatorField, "tmp1");
 | 
			
		||||
    envTmpLat(LatticeComplex,  "tmp2");
 | 
			
		||||
    envTmp(std::vector<PropagatorField>, "S_body", 1, ndim, PropagatorField(env().getGrid()));
 | 
			
		||||
    envTmp(std::vector<PropagatorField>, "S_loop", 1, ndim, PropagatorField(env().getGrid()));
 | 
			
		||||
    envTmp(std::vector<LatticeComplex>,  "E_body", 1, ndim, LatticeComplex(env().getGrid()));
 | 
			
		||||
    envTmp(std::vector<LatticeComplex>,  "E_loop", 1, ndim, LatticeComplex(env().getGrid()));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// execution ///////////////////////////////////////////////////////////////////
 | 
			
		||||
void TWeakHamiltonianEye::execute(void)
 | 
			
		||||
{
 | 
			
		||||
    LOG(Message) << "Computing Weak Hamiltonian (Eye type) contractions '" 
 | 
			
		||||
                 << getName() << "' using quarks '" << par().q1 << "', '" 
 | 
			
		||||
                 << par().q2 << ", '" << par().q3 << "' and '" << par().q4 
 | 
			
		||||
                 << "'." << std::endl;
 | 
			
		||||
 | 
			
		||||
    auto                   &q1 = envGet(SlicedPropagator, par().q1);
 | 
			
		||||
    auto                   &q2 = envGet(PropagatorField, par().q2);
 | 
			
		||||
    auto                   &q3 = envGet(PropagatorField, par().q3);
 | 
			
		||||
    auto                   &q4 = envGet(PropagatorField, par().q4);
 | 
			
		||||
    Gamma                  g5  = Gamma(Gamma::Algebra::Gamma5);
 | 
			
		||||
    std::vector<TComplex>  corrbuf;
 | 
			
		||||
    std::vector<Result>    result(n_eye_diag);
 | 
			
		||||
    unsigned int ndim    = env().getNd();
 | 
			
		||||
 | 
			
		||||
    envGetTmp(LatticeComplex,               expbuf); 
 | 
			
		||||
    envGetTmp(PropagatorField,              tmp1);
 | 
			
		||||
    envGetTmp(LatticeComplex,               tmp2);
 | 
			
		||||
    envGetTmp(std::vector<PropagatorField>, S_body);
 | 
			
		||||
    envGetTmp(std::vector<PropagatorField>, S_loop);
 | 
			
		||||
    envGetTmp(std::vector<LatticeComplex>,  E_body);
 | 
			
		||||
    envGetTmp(std::vector<LatticeComplex>,  E_loop);
 | 
			
		||||
 | 
			
		||||
    // Get sink timeslice of q1.
 | 
			
		||||
    SitePropagator q1Snk = q1[par().tSnk];
 | 
			
		||||
 | 
			
		||||
    // Setup for S-type contractions.
 | 
			
		||||
    for (int mu = 0; mu < ndim; ++mu)
 | 
			
		||||
    {
 | 
			
		||||
        S_body[mu] = MAKE_SE_BODY(q1Snk, q2, q3, GammaL(Gamma::gmu[mu]));
 | 
			
		||||
        S_loop[mu] = MAKE_SE_LOOP(q4, GammaL(Gamma::gmu[mu]));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Perform S-type contractions.    
 | 
			
		||||
    SUM_MU(expbuf, trace(S_body[mu]*S_loop[mu]))
 | 
			
		||||
    MAKE_DIAG(expbuf, corrbuf, result[S_diag], "HW_S")
 | 
			
		||||
 | 
			
		||||
    // Recycle sub-expressions for E-type contractions.
 | 
			
		||||
    for (unsigned int mu = 0; mu < ndim; ++mu)
 | 
			
		||||
    {
 | 
			
		||||
        E_body[mu] = trace(S_body[mu]);
 | 
			
		||||
        E_loop[mu] = trace(S_loop[mu]);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Perform E-type contractions.
 | 
			
		||||
    SUM_MU(expbuf, E_body[mu]*E_loop[mu])
 | 
			
		||||
    MAKE_DIAG(expbuf, corrbuf, result[E_diag], "HW_E")
 | 
			
		||||
 | 
			
		||||
    // IO
 | 
			
		||||
    saveResult(par().output, "HW_Eye", result);
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										59
									
								
								Hadrons/Modules/MContraction/WeakHamiltonianEye.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										59
									
								
								Hadrons/Modules/MContraction/WeakHamiltonianEye.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,59 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MContraction/WeakHamiltonianEye.hpp
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
Author: Antonin Portelli <antonin.portelli@me.com>
 | 
			
		||||
Author: Lanny91 <andrew.lawson@gmail.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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
 | 
			
		||||
#ifndef Hadrons_MContraction_WeakHamiltonianEye_hpp_
 | 
			
		||||
#define Hadrons_MContraction_WeakHamiltonianEye_hpp_
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Modules/MContraction/WeakHamiltonian.hpp>
 | 
			
		||||
 | 
			
		||||
BEGIN_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                         WeakHamiltonianEye                                 *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
BEGIN_MODULE_NAMESPACE(MContraction)
 | 
			
		||||
 | 
			
		||||
enum
 | 
			
		||||
{
 | 
			
		||||
    S_diag = 0,
 | 
			
		||||
    E_diag = 1,
 | 
			
		||||
    n_eye_diag = 2
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// Saucer and Eye subdiagram contractions.
 | 
			
		||||
#define MAKE_SE_BODY(Q_1, Q_2, Q_3, gamma) (Q_3*g5*Q_1*adj(Q_2)*g5*gamma)
 | 
			
		||||
#define MAKE_SE_LOOP(Q_loop, gamma) (Q_loop*gamma)
 | 
			
		||||
 | 
			
		||||
MAKE_WEAK_MODULE(WeakHamiltonianEye)
 | 
			
		||||
 | 
			
		||||
END_MODULE_NAMESPACE
 | 
			
		||||
 | 
			
		||||
END_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
#endif // Hadrons_MContraction_WeakHamiltonianEye_hpp_
 | 
			
		||||
							
								
								
									
										148
									
								
								Hadrons/Modules/MContraction/WeakHamiltonianNonEye.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										148
									
								
								Hadrons/Modules/MContraction/WeakHamiltonianNonEye.cc
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,148 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MContraction/WeakHamiltonianNonEye.cc
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
Author: Antonin Portelli <antonin.portelli@me.com>
 | 
			
		||||
Author: Lanny91 <andrew.lawson@gmail.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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Modules/MContraction/WeakHamiltonianNonEye.hpp>
 | 
			
		||||
 | 
			
		||||
using namespace Grid;
 | 
			
		||||
using namespace Hadrons;
 | 
			
		||||
using namespace MContraction;
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Weak Hamiltonian current-current contractions, Non-Eye-type.
 | 
			
		||||
 * 
 | 
			
		||||
 * These contractions are generated by the Q1 and Q2 operators in the physical
 | 
			
		||||
 * basis (see e.g. Fig 3 of arXiv:1507.03094).
 | 
			
		||||
 * 
 | 
			
		||||
 * Schematic:     
 | 
			
		||||
 *            q2             q3          |           q2              q3
 | 
			
		||||
 *          /--<--¬       /--<--¬        |        /--<--¬         /--<--¬       
 | 
			
		||||
 *         /       \     /       \       |       /       \       /       \      
 | 
			
		||||
 *        /         \   /         \      |      /         \     /         \     
 | 
			
		||||
 *       /           \ /           \     |     /           \   /           \    
 | 
			
		||||
 *    i *             * H_W         *  f |  i *             * * H_W         * f 
 | 
			
		||||
 *      \             *             |    |     \           /   \           /
 | 
			
		||||
 *       \           / \           /     |      \         /     \         /    
 | 
			
		||||
 *        \         /   \         /      |       \       /       \       /  
 | 
			
		||||
 *         \       /     \       /       |        \-->--/         \-->--/      
 | 
			
		||||
 *          \-->--/       \-->--/        |          q1               q4 
 | 
			
		||||
 *            q1             q4          |
 | 
			
		||||
 *                Connected (C)          |                 Wing (W)
 | 
			
		||||
 *
 | 
			
		||||
 * C: trace(q1*adj(q2)*g5*gL[mu]*q3*adj(q4)*g5*gL[mu])
 | 
			
		||||
 * W: trace(q1*adj(q2)*g5*gL[mu])*trace(q3*adj(q4)*g5*gL[mu])
 | 
			
		||||
 * 
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                  TWeakHamiltonianNonEye implementation                     *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
// constructor /////////////////////////////////////////////////////////////////
 | 
			
		||||
TWeakHamiltonianNonEye::TWeakHamiltonianNonEye(const std::string name)
 | 
			
		||||
: Module<WeakHamiltonianPar>(name)
 | 
			
		||||
{}
 | 
			
		||||
 | 
			
		||||
// dependencies/products ///////////////////////////////////////////////////////
 | 
			
		||||
std::vector<std::string> TWeakHamiltonianNonEye::getInput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> in = {par().q1, par().q2, par().q3, par().q4};
 | 
			
		||||
    
 | 
			
		||||
    return in;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::vector<std::string> TWeakHamiltonianNonEye::getOutput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> out = {};
 | 
			
		||||
    
 | 
			
		||||
    return out;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// setup ///////////////////////////////////////////////////////////////////////
 | 
			
		||||
void TWeakHamiltonianNonEye::setup(void)
 | 
			
		||||
{
 | 
			
		||||
    unsigned int ndim = env().getNd();
 | 
			
		||||
 | 
			
		||||
    envTmpLat(LatticeComplex,  "expbuf");
 | 
			
		||||
    envTmpLat(PropagatorField, "tmp1");
 | 
			
		||||
    envTmpLat(LatticeComplex,  "tmp2");
 | 
			
		||||
    envTmp(std::vector<PropagatorField>, "C_i_side_loop", 1, ndim, PropagatorField(env().getGrid()));
 | 
			
		||||
    envTmp(std::vector<PropagatorField>, "C_f_side_loop", 1, ndim, PropagatorField(env().getGrid()));
 | 
			
		||||
    envTmp(std::vector<LatticeComplex>,  "W_i_side_loop", 1, ndim, LatticeComplex(env().getGrid()));
 | 
			
		||||
    envTmp(std::vector<LatticeComplex>,  "W_f_side_loop", 1, ndim, LatticeComplex(env().getGrid()));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// execution ///////////////////////////////////////////////////////////////////
 | 
			
		||||
void TWeakHamiltonianNonEye::execute(void)
 | 
			
		||||
{
 | 
			
		||||
    LOG(Message) << "Computing Weak Hamiltonian (Non-Eye type) contractions '" 
 | 
			
		||||
                 << getName() << "' using quarks '" << par().q1 << "', '" 
 | 
			
		||||
                 << par().q2 << ", '" << par().q3 << "' and '" << par().q4 
 | 
			
		||||
                 << "'." << std::endl;
 | 
			
		||||
    
 | 
			
		||||
    auto                  &q1 = envGet(PropagatorField, par().q1);
 | 
			
		||||
    auto                  &q2 = envGet(PropagatorField, par().q2);
 | 
			
		||||
    auto                  &q3 = envGet(PropagatorField, par().q3);
 | 
			
		||||
    auto                  &q4 = envGet(PropagatorField, par().q4);
 | 
			
		||||
    Gamma                 g5  = Gamma(Gamma::Algebra::Gamma5);
 | 
			
		||||
    std::vector<TComplex> corrbuf;
 | 
			
		||||
    std::vector<Result>   result(n_noneye_diag); 
 | 
			
		||||
    unsigned int          ndim = env().getNd();
 | 
			
		||||
 | 
			
		||||
    envGetTmp(LatticeComplex,               expbuf); 
 | 
			
		||||
    envGetTmp(PropagatorField,              tmp1);
 | 
			
		||||
    envGetTmp(LatticeComplex,               tmp2);
 | 
			
		||||
    envGetTmp(std::vector<PropagatorField>, C_i_side_loop);
 | 
			
		||||
    envGetTmp(std::vector<PropagatorField>, C_f_side_loop);
 | 
			
		||||
    envGetTmp(std::vector<LatticeComplex>,  W_i_side_loop);
 | 
			
		||||
    envGetTmp(std::vector<LatticeComplex>,  W_f_side_loop);
 | 
			
		||||
 | 
			
		||||
    // Setup for C-type contractions.
 | 
			
		||||
    for (int mu = 0; mu < ndim; ++mu)
 | 
			
		||||
    {
 | 
			
		||||
        C_i_side_loop[mu] = MAKE_CW_SUBDIAG(q1, q2, GammaL(Gamma::gmu[mu]));
 | 
			
		||||
        C_f_side_loop[mu] = MAKE_CW_SUBDIAG(q3, q4, GammaL(Gamma::gmu[mu]));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Perform C-type contractions.    
 | 
			
		||||
    SUM_MU(expbuf, trace(C_i_side_loop[mu]*C_f_side_loop[mu]))
 | 
			
		||||
    MAKE_DIAG(expbuf, corrbuf, result[C_diag], "HW_C")
 | 
			
		||||
 | 
			
		||||
    // Recycle sub-expressions for W-type contractions.
 | 
			
		||||
    for (unsigned int mu = 0; mu < ndim; ++mu)
 | 
			
		||||
    {
 | 
			
		||||
        W_i_side_loop[mu] = trace(C_i_side_loop[mu]);
 | 
			
		||||
        W_f_side_loop[mu] = trace(C_f_side_loop[mu]);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Perform W-type contractions.
 | 
			
		||||
    SUM_MU(expbuf, W_i_side_loop[mu]*W_f_side_loop[mu])
 | 
			
		||||
    MAKE_DIAG(expbuf, corrbuf, result[W_diag], "HW_W")
 | 
			
		||||
 | 
			
		||||
    // IO
 | 
			
		||||
    saveResult(par().output, "HW_NonEye", result);
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										58
									
								
								Hadrons/Modules/MContraction/WeakHamiltonianNonEye.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								Hadrons/Modules/MContraction/WeakHamiltonianNonEye.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,58 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MContraction/WeakHamiltonianNonEye.hpp
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
Author: Antonin Portelli <antonin.portelli@me.com>
 | 
			
		||||
Author: Lanny91 <andrew.lawson@gmail.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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
 | 
			
		||||
#ifndef Hadrons_MContraction_WeakHamiltonianNonEye_hpp_
 | 
			
		||||
#define Hadrons_MContraction_WeakHamiltonianNonEye_hpp_
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Modules/MContraction/WeakHamiltonian.hpp>
 | 
			
		||||
 | 
			
		||||
BEGIN_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                         WeakHamiltonianNonEye                              *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
BEGIN_MODULE_NAMESPACE(MContraction)
 | 
			
		||||
 | 
			
		||||
enum
 | 
			
		||||
{
 | 
			
		||||
    W_diag = 0,
 | 
			
		||||
    C_diag = 1,
 | 
			
		||||
    n_noneye_diag = 2
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// Wing and Connected subdiagram contractions
 | 
			
		||||
#define MAKE_CW_SUBDIAG(Q_1, Q_2, gamma) (Q_1*adj(Q_2)*g5*gamma)
 | 
			
		||||
 | 
			
		||||
MAKE_WEAK_MODULE(WeakHamiltonianNonEye)
 | 
			
		||||
 | 
			
		||||
END_MODULE_NAMESPACE
 | 
			
		||||
 | 
			
		||||
END_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
#endif // Hadrons_MContraction_WeakHamiltonianNonEye_hpp_
 | 
			
		||||
							
								
								
									
										142
									
								
								Hadrons/Modules/MContraction/WeakNeutral4ptDisc.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										142
									
								
								Hadrons/Modules/MContraction/WeakNeutral4ptDisc.cc
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,142 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MContraction/WeakNeutral4ptDisc.cc
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
Author: Antonin Portelli <antonin.portelli@me.com>
 | 
			
		||||
Author: Lanny91 <andrew.lawson@gmail.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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Modules/MContraction/WeakNeutral4ptDisc.hpp>
 | 
			
		||||
 | 
			
		||||
using namespace Grid;
 | 
			
		||||
using namespace Hadrons;
 | 
			
		||||
using namespace MContraction;
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Weak Hamiltonian + current contractions, disconnected topology for neutral 
 | 
			
		||||
 * mesons.
 | 
			
		||||
 * 
 | 
			
		||||
 * These contractions are generated by operators Q_1,...,10 of the dS=1 Weak
 | 
			
		||||
 * Hamiltonian in the physical basis and an additional current J (see e.g. 
 | 
			
		||||
 * Fig 11 of arXiv:1507.03094).
 | 
			
		||||
 * 
 | 
			
		||||
 * Schematic:
 | 
			
		||||
 *                        
 | 
			
		||||
 *           q2          q4             q3
 | 
			
		||||
 *       /--<--¬     /---<--¬       /---<--¬
 | 
			
		||||
 *     /         \ /         \     /        \
 | 
			
		||||
 *  i *           * H_W      |  J *          * f
 | 
			
		||||
 *     \         / \         /     \        /
 | 
			
		||||
 *      \--->---/   \-------/       \------/
 | 
			
		||||
 *          q1 
 | 
			
		||||
 * 
 | 
			
		||||
 * options
 | 
			
		||||
 * - q1: input propagator 1 (string)
 | 
			
		||||
 * - q2: input propagator 2 (string)
 | 
			
		||||
 * - q3: input propagator 3 (string), assumed to be sequential propagator 
 | 
			
		||||
 * - q4: input propagator 4 (string), assumed to be a loop
 | 
			
		||||
 * 
 | 
			
		||||
 * type 1: trace(q1*adj(q2)*g5*gL[mu])*trace(loop*gL[mu])*trace(q3*g5)
 | 
			
		||||
 * type 2: trace(q1*adj(q2)*g5*gL[mu]*loop*gL[mu])*trace(q3*g5)
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
/*******************************************************************************
 | 
			
		||||
 *                  TWeakNeutral4ptDisc implementation                         *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
// constructor /////////////////////////////////////////////////////////////////
 | 
			
		||||
TWeakNeutral4ptDisc::TWeakNeutral4ptDisc(const std::string name)
 | 
			
		||||
: Module<WeakHamiltonianPar>(name)
 | 
			
		||||
{}
 | 
			
		||||
 | 
			
		||||
// dependencies/products ///////////////////////////////////////////////////////
 | 
			
		||||
std::vector<std::string> TWeakNeutral4ptDisc::getInput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> in = {par().q1, par().q2, par().q3, par().q4};
 | 
			
		||||
    
 | 
			
		||||
    return in;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::vector<std::string> TWeakNeutral4ptDisc::getOutput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> out = {};
 | 
			
		||||
    
 | 
			
		||||
    return out;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// setup ///////////////////////////////////////////////////////////////////////
 | 
			
		||||
void TWeakNeutral4ptDisc::setup(void)
 | 
			
		||||
{
 | 
			
		||||
    unsigned int ndim = env().getNd();
 | 
			
		||||
 | 
			
		||||
    envTmpLat(LatticeComplex,  "expbuf");
 | 
			
		||||
    envTmpLat(PropagatorField, "tmp");
 | 
			
		||||
    envTmpLat(LatticeComplex,  "curr");
 | 
			
		||||
    envTmp(std::vector<PropagatorField>, "meson", 1, ndim, PropagatorField(env().getGrid()));
 | 
			
		||||
    envTmp(std::vector<PropagatorField>, "loop", 1, ndim,  PropagatorField(env().getGrid()));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// execution ///////////////////////////////////////////////////////////////////
 | 
			
		||||
void TWeakNeutral4ptDisc::execute(void)
 | 
			
		||||
{
 | 
			
		||||
    LOG(Message) << "Computing Weak Hamiltonian neutral disconnected contractions '" 
 | 
			
		||||
                 << getName() << "' using quarks '" << par().q1 << "', '" 
 | 
			
		||||
                 << par().q2 << ", '" << par().q3 << "' and '" << par().q4 
 | 
			
		||||
                 << "'." << std::endl;
 | 
			
		||||
 | 
			
		||||
    auto                  &q1 = envGet(PropagatorField, par().q1);
 | 
			
		||||
    auto                  &q2 = envGet(PropagatorField, par().q2);
 | 
			
		||||
    auto                  &q3 = envGet(PropagatorField, par().q3);
 | 
			
		||||
    auto                  &q4 = envGet(PropagatorField, par().q4);
 | 
			
		||||
    Gamma                 g5  = Gamma(Gamma::Algebra::Gamma5);
 | 
			
		||||
    std::vector<TComplex> corrbuf;
 | 
			
		||||
    std::vector<Result>   result(n_neut_disc_diag);
 | 
			
		||||
    unsigned int          ndim = env().getNd();
 | 
			
		||||
 | 
			
		||||
    envGetTmp(LatticeComplex,               expbuf); 
 | 
			
		||||
    envGetTmp(PropagatorField,              tmp);
 | 
			
		||||
    envGetTmp(LatticeComplex,               curr);
 | 
			
		||||
    envGetTmp(std::vector<PropagatorField>, meson);
 | 
			
		||||
    envGetTmp(std::vector<PropagatorField>, loop);
 | 
			
		||||
 | 
			
		||||
    // Setup for type 1 contractions.
 | 
			
		||||
    for (int mu = 0; mu < ndim; ++mu)
 | 
			
		||||
    {
 | 
			
		||||
        meson[mu] = MAKE_DISC_MESON(q1, q2, GammaL(Gamma::gmu[mu]));
 | 
			
		||||
        loop[mu] = MAKE_DISC_LOOP(q4, GammaL(Gamma::gmu[mu]));
 | 
			
		||||
    }
 | 
			
		||||
    curr = MAKE_DISC_CURR(q3, GammaL(Gamma::Algebra::Gamma5));
 | 
			
		||||
 | 
			
		||||
    // Perform type 1 contractions.    
 | 
			
		||||
    SUM_MU(expbuf, trace(meson[mu]*loop[mu]))
 | 
			
		||||
    expbuf *= curr;
 | 
			
		||||
    MAKE_DIAG(expbuf, corrbuf, result[neut_disc_1_diag], "HW_disc0_1")
 | 
			
		||||
 | 
			
		||||
    // Perform type 2 contractions.
 | 
			
		||||
    SUM_MU(expbuf, trace(meson[mu])*trace(loop[mu]))
 | 
			
		||||
    expbuf *= curr;
 | 
			
		||||
    MAKE_DIAG(expbuf, corrbuf, result[neut_disc_2_diag], "HW_disc0_2")
 | 
			
		||||
 | 
			
		||||
    // IO
 | 
			
		||||
    saveResult(par().output, "HW_disc0", result);
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										60
									
								
								Hadrons/Modules/MContraction/WeakNeutral4ptDisc.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										60
									
								
								Hadrons/Modules/MContraction/WeakNeutral4ptDisc.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,60 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MContraction/WeakNeutral4ptDisc.hpp
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
Author: Antonin Portelli <antonin.portelli@me.com>
 | 
			
		||||
Author: Lanny91 <andrew.lawson@gmail.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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
 | 
			
		||||
#ifndef Hadrons_MContraction_WeakNeutral4ptDisc_hpp_
 | 
			
		||||
#define Hadrons_MContraction_WeakNeutral4ptDisc_hpp_
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Modules/MContraction/WeakHamiltonian.hpp>
 | 
			
		||||
 | 
			
		||||
BEGIN_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                         WeakNeutral4ptDisc                                 *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
BEGIN_MODULE_NAMESPACE(MContraction)
 | 
			
		||||
 | 
			
		||||
enum
 | 
			
		||||
{
 | 
			
		||||
    neut_disc_1_diag = 0,
 | 
			
		||||
    neut_disc_2_diag = 1,
 | 
			
		||||
    n_neut_disc_diag = 2
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// Neutral 4pt disconnected subdiagram contractions.
 | 
			
		||||
#define MAKE_DISC_MESON(Q_1, Q_2, gamma) (Q_1*adj(Q_2)*g5*gamma)
 | 
			
		||||
#define MAKE_DISC_LOOP(Q_LOOP, gamma) (Q_LOOP*gamma)
 | 
			
		||||
#define MAKE_DISC_CURR(Q_c, gamma) (trace(Q_c*gamma))
 | 
			
		||||
 | 
			
		||||
MAKE_WEAK_MODULE(WeakNeutral4ptDisc)
 | 
			
		||||
 | 
			
		||||
END_MODULE_NAMESPACE
 | 
			
		||||
 | 
			
		||||
END_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
#endif // Hadrons_MContraction_WeakNeutral4ptDisc_hpp_
 | 
			
		||||
							
								
								
									
										36
									
								
								Hadrons/Modules/MFermion/FreeProp.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								Hadrons/Modules/MFermion/FreeProp.cc
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,36 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MFermion/FreeProp.cc
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
Author: Antonin Portelli <antonin.portelli@me.com>
 | 
			
		||||
Author: Vera Guelpers <vmg1n14@soton.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 */
 | 
			
		||||
#include <Hadrons/Modules/MFermion/FreeProp.hpp>
 | 
			
		||||
 | 
			
		||||
using namespace Grid;
 | 
			
		||||
using namespace Hadrons;
 | 
			
		||||
using namespace MFermion;
 | 
			
		||||
 | 
			
		||||
template class Grid::Hadrons::MFermion::TFreeProp<FIMPL>;
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										188
									
								
								Hadrons/Modules/MFermion/FreeProp.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										188
									
								
								Hadrons/Modules/MFermion/FreeProp.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,188 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MFermion/FreeProp.hpp
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
Author: Antonin Portelli <antonin.portelli@me.com>
 | 
			
		||||
Author: Vera Guelpers <vmg1n14@soton.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 */
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#ifndef Hadrons_MFermion_FreeProp_hpp_
 | 
			
		||||
#define Hadrons_MFermion_FreeProp_hpp_
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Global.hpp>
 | 
			
		||||
#include <Hadrons/Module.hpp>
 | 
			
		||||
#include <Hadrons/ModuleFactory.hpp>
 | 
			
		||||
 | 
			
		||||
BEGIN_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                         FreeProp                                 *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
BEGIN_MODULE_NAMESPACE(MFermion)
 | 
			
		||||
 | 
			
		||||
class FreePropPar: Serializable
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    GRID_SERIALIZABLE_CLASS_MEMBERS(FreePropPar,
 | 
			
		||||
                                    std::string, source,
 | 
			
		||||
				    std::string,  action,
 | 
			
		||||
				    double, mass,
 | 
			
		||||
				    std::string,  twist);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
class TFreeProp: public Module<FreePropPar>
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    FG_TYPE_ALIASES(FImpl,);
 | 
			
		||||
public:
 | 
			
		||||
    // constructor
 | 
			
		||||
    TFreeProp(const std::string name);
 | 
			
		||||
    // destructor
 | 
			
		||||
    virtual ~TFreeProp(void) {};
 | 
			
		||||
    // dependency relation
 | 
			
		||||
    virtual std::vector<std::string> getInput(void);
 | 
			
		||||
    virtual std::vector<std::string> getOutput(void);
 | 
			
		||||
protected:
 | 
			
		||||
    // setup
 | 
			
		||||
    virtual void setup(void);
 | 
			
		||||
    // execution
 | 
			
		||||
    virtual void execute(void);
 | 
			
		||||
private:
 | 
			
		||||
    unsigned int Ls_;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
MODULE_REGISTER_TMP(FreeProp, TFreeProp<FIMPL>, MFermion);
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                 TFreeProp implementation                             *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
// constructor /////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
TFreeProp<FImpl>::TFreeProp(const std::string name)
 | 
			
		||||
: Module<FreePropPar>(name)
 | 
			
		||||
{}
 | 
			
		||||
 | 
			
		||||
// dependencies/products ///////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
std::vector<std::string> TFreeProp<FImpl>::getInput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> in = {par().source, par().action};
 | 
			
		||||
    
 | 
			
		||||
    return in;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
std::vector<std::string> TFreeProp<FImpl>::getOutput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> out = {getName(), getName() + "_5d"};
 | 
			
		||||
    
 | 
			
		||||
    return out;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// setup ///////////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
void TFreeProp<FImpl>::setup(void)
 | 
			
		||||
{
 | 
			
		||||
    Ls_ = env().getObjectLs(par().action);
 | 
			
		||||
    envCreateLat(PropagatorField, getName());
 | 
			
		||||
    envTmpLat(FermionField, "source", Ls_);
 | 
			
		||||
    envTmpLat(FermionField, "sol", Ls_);
 | 
			
		||||
    envTmpLat(FermionField, "tmp");
 | 
			
		||||
    if (Ls_ > 1)
 | 
			
		||||
    {
 | 
			
		||||
        envCreateLat(PropagatorField, getName() + "_5d", Ls_);
 | 
			
		||||
    }    
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// execution ///////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
void TFreeProp<FImpl>::execute(void)
 | 
			
		||||
{
 | 
			
		||||
    LOG(Message) << "Computing free fermion propagator '" << getName() << "'"
 | 
			
		||||
                 << std::endl;
 | 
			
		||||
    
 | 
			
		||||
    std::string propName = (Ls_ == 1) ? getName() : (getName() + "_5d");
 | 
			
		||||
    auto        &prop    = envGet(PropagatorField, propName);
 | 
			
		||||
    auto        &fullSrc = envGet(PropagatorField, par().source);
 | 
			
		||||
    auto        &mat = envGet(FMat, par().action);
 | 
			
		||||
    RealD mass = par().mass;
 | 
			
		||||
    
 | 
			
		||||
    envGetTmp(FermionField, source);
 | 
			
		||||
    envGetTmp(FermionField, sol);
 | 
			
		||||
    envGetTmp(FermionField, tmp);
 | 
			
		||||
    LOG(Message) << "Calculating a free Propagator with mass " << mass 
 | 
			
		||||
		 << " using the action '" << par().action
 | 
			
		||||
                 << "' on source '" << par().source << "'" << std::endl;
 | 
			
		||||
    for (unsigned int s = 0; s < Ns; ++s)
 | 
			
		||||
      for (unsigned int c = 0; c < FImpl::Dimension; ++c)
 | 
			
		||||
    {
 | 
			
		||||
        LOG(Message) << "Calculation for spin= " << s << ", color= " << c
 | 
			
		||||
                     << std::endl;
 | 
			
		||||
        // source conversion for 4D sources
 | 
			
		||||
        if (!env().isObject5d(par().source))
 | 
			
		||||
        {
 | 
			
		||||
            if (Ls_ == 1)
 | 
			
		||||
            {
 | 
			
		||||
               PropToFerm<FImpl>(source, fullSrc, s, c);
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
                PropToFerm<FImpl>(tmp, fullSrc, s, c);
 | 
			
		||||
                mat.ImportPhysicalFermionSource(tmp, source);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        // source conversion for 5D sources
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            if (Ls_ != env().getObjectLs(par().source))
 | 
			
		||||
            {
 | 
			
		||||
                HADRONS_ERROR(Size, "Ls mismatch between quark action and source");
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
                PropToFerm<FImpl>(source, fullSrc, s, c);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        sol = zero;
 | 
			
		||||
	std::vector<double> twist = strToVec<double>(par().twist);
 | 
			
		||||
	if(twist.size() != Nd) HADRONS_ERROR(Size, "number of twist angles does not match number of dimensions");
 | 
			
		||||
	mat.FreePropagator(source,sol,mass,twist);
 | 
			
		||||
        FermToProp<FImpl>(prop, sol, s, c);
 | 
			
		||||
        // create 4D propagators from 5D one if necessary
 | 
			
		||||
        if (Ls_ > 1)
 | 
			
		||||
        {
 | 
			
		||||
            PropagatorField &p4d = envGet(PropagatorField, getName());
 | 
			
		||||
            mat.ExportPhysicalFermionSolution(sol, tmp);
 | 
			
		||||
            FermToProp<FImpl>(p4d, tmp, s, c);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
END_MODULE_NAMESPACE
 | 
			
		||||
 | 
			
		||||
END_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
#endif // Hadrons_MFermion_FreeProp_hpp_
 | 
			
		||||
							
								
								
									
										35
									
								
								Hadrons/Modules/MFermion/GaugeProp.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								Hadrons/Modules/MFermion/GaugeProp.cc
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,35 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MFermion/GaugeProp.cc
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
#include <Hadrons/Modules/MFermion/GaugeProp.hpp>
 | 
			
		||||
 | 
			
		||||
using namespace Grid;
 | 
			
		||||
using namespace Hadrons;
 | 
			
		||||
using namespace MFermion;
 | 
			
		||||
 | 
			
		||||
template class Grid::Hadrons::MFermion::TGaugeProp<FIMPL>;
 | 
			
		||||
template class Grid::Hadrons::MFermion::TGaugeProp<ZFIMPL>;
 | 
			
		||||
							
								
								
									
										191
									
								
								Hadrons/Modules/MFermion/GaugeProp.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										191
									
								
								Hadrons/Modules/MFermion/GaugeProp.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,191 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MFermion/GaugeProp.hpp
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
Author: Antonin Portelli <antonin.portelli@me.com>
 | 
			
		||||
Author: Guido Cossu <guido.cossu@ed.ac.uk>
 | 
			
		||||
Author: Lanny91 <andrew.lawson@gmail.com>
 | 
			
		||||
Author: pretidav <david.preti@csic.es>
 | 
			
		||||
 | 
			
		||||
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 */
 | 
			
		||||
 | 
			
		||||
#ifndef Hadrons_MFermion_GaugeProp_hpp_
 | 
			
		||||
#define Hadrons_MFermion_GaugeProp_hpp_
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Global.hpp>
 | 
			
		||||
#include <Hadrons/Module.hpp>
 | 
			
		||||
#include <Hadrons/ModuleFactory.hpp>
 | 
			
		||||
#include <Hadrons/Solver.hpp>
 | 
			
		||||
 | 
			
		||||
BEGIN_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                                GaugeProp                                   *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
BEGIN_MODULE_NAMESPACE(MFermion)
 | 
			
		||||
 | 
			
		||||
class GaugePropPar: Serializable
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    GRID_SERIALIZABLE_CLASS_MEMBERS(GaugePropPar,
 | 
			
		||||
                                    std::string, source,
 | 
			
		||||
                                    std::string, solver);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
class TGaugeProp: public Module<GaugePropPar>
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    FG_TYPE_ALIASES(FImpl,);
 | 
			
		||||
    SOLVER_TYPE_ALIASES(FImpl,);
 | 
			
		||||
public:
 | 
			
		||||
    // constructor
 | 
			
		||||
    TGaugeProp(const std::string name);
 | 
			
		||||
    // destructor
 | 
			
		||||
    virtual ~TGaugeProp(void) {};
 | 
			
		||||
    // dependency relation
 | 
			
		||||
    virtual std::vector<std::string> getInput(void);
 | 
			
		||||
    virtual std::vector<std::string> getOutput(void);
 | 
			
		||||
protected:
 | 
			
		||||
    // setup
 | 
			
		||||
    virtual void setup(void);
 | 
			
		||||
    // execution
 | 
			
		||||
    virtual void execute(void);
 | 
			
		||||
private:
 | 
			
		||||
    unsigned int Ls_;
 | 
			
		||||
    Solver       *solver_{nullptr};
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
MODULE_REGISTER_TMP(GaugeProp, TGaugeProp<FIMPL>, MFermion);
 | 
			
		||||
MODULE_REGISTER_TMP(ZGaugeProp, TGaugeProp<ZFIMPL>, MFermion);
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                      TGaugeProp implementation                             *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
// constructor /////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
TGaugeProp<FImpl>::TGaugeProp(const std::string name)
 | 
			
		||||
: Module<GaugePropPar>(name)
 | 
			
		||||
{}
 | 
			
		||||
 | 
			
		||||
// dependencies/products ///////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
std::vector<std::string> TGaugeProp<FImpl>::getInput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> in = {par().source, par().solver};
 | 
			
		||||
    
 | 
			
		||||
    return in;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
std::vector<std::string> TGaugeProp<FImpl>::getOutput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> out = {getName(), getName() + "_5d"};
 | 
			
		||||
    
 | 
			
		||||
    return out;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// setup ///////////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
void TGaugeProp<FImpl>::setup(void)
 | 
			
		||||
{
 | 
			
		||||
    Ls_ = env().getObjectLs(par().solver);
 | 
			
		||||
    envCreateLat(PropagatorField, getName());
 | 
			
		||||
    envTmpLat(FermionField, "source", Ls_);
 | 
			
		||||
    envTmpLat(FermionField, "sol", Ls_);
 | 
			
		||||
    envTmpLat(FermionField, "tmp");
 | 
			
		||||
    if (Ls_ > 1)
 | 
			
		||||
    {
 | 
			
		||||
        envCreateLat(PropagatorField, getName() + "_5d", Ls_);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// execution ///////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
void TGaugeProp<FImpl>::execute(void)
 | 
			
		||||
{
 | 
			
		||||
    LOG(Message) << "Computing quark propagator '" << getName() << "'"
 | 
			
		||||
                 << std::endl;
 | 
			
		||||
    
 | 
			
		||||
    std::string propName = (Ls_ == 1) ? getName() : (getName() + "_5d");
 | 
			
		||||
    auto        &prop    = envGet(PropagatorField, propName);
 | 
			
		||||
    auto        &fullSrc = envGet(PropagatorField, par().source);
 | 
			
		||||
    auto        &solver  = envGet(Solver, par().solver);
 | 
			
		||||
    auto        &mat     = solver.getFMat();
 | 
			
		||||
    
 | 
			
		||||
    envGetTmp(FermionField, source);
 | 
			
		||||
    envGetTmp(FermionField, sol);
 | 
			
		||||
    envGetTmp(FermionField, tmp);
 | 
			
		||||
    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 < FImpl::Dimension; ++c)
 | 
			
		||||
    {
 | 
			
		||||
        LOG(Message) << "Inversion for spin= " << s << ", color= " << c
 | 
			
		||||
                     << std::endl;
 | 
			
		||||
        // source conversion for 4D sources
 | 
			
		||||
        LOG(Message) << "Import source" << std::endl;
 | 
			
		||||
        if (!env().isObject5d(par().source))
 | 
			
		||||
        {
 | 
			
		||||
            if (Ls_ == 1)
 | 
			
		||||
            {
 | 
			
		||||
               PropToFerm<FImpl>(source, fullSrc, s, c);
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
                PropToFerm<FImpl>(tmp, fullSrc, s, c);
 | 
			
		||||
                mat.ImportPhysicalFermionSource(tmp, source);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        // source conversion for 5D sources
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            if (Ls_ != env().getObjectLs(par().source))
 | 
			
		||||
            {
 | 
			
		||||
                HADRONS_ERROR(Size, "Ls mismatch between quark action and source");
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
                PropToFerm<FImpl>(source, fullSrc, s, c);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        LOG(Message) << "Solve" << std::endl;
 | 
			
		||||
        sol = zero;
 | 
			
		||||
        solver(sol, source);
 | 
			
		||||
        LOG(Message) << "Export solution" << std::endl;
 | 
			
		||||
        FermToProp<FImpl>(prop, sol, s, c);
 | 
			
		||||
        // create 4D propagators from 5D one if necessary
 | 
			
		||||
        if (Ls_ > 1)
 | 
			
		||||
        {
 | 
			
		||||
            PropagatorField &p4d = envGet(PropagatorField, getName());
 | 
			
		||||
            mat.ExportPhysicalFermionSolution(sol, tmp);
 | 
			
		||||
            FermToProp<FImpl>(p4d, tmp, s, c);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
END_MODULE_NAMESPACE
 | 
			
		||||
 | 
			
		||||
END_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
#endif // Hadrons_MFermion_GaugeProp_hpp_
 | 
			
		||||
							
								
								
									
										79
									
								
								Hadrons/Modules/MGauge/FundtoHirep.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										79
									
								
								Hadrons/Modules/MGauge/FundtoHirep.cc
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,79 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MGauge/FundtoHirep.cc
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
Author: Antonin Portelli <antonin.portelli@me.com>
 | 
			
		||||
Author: Guido Cossu <guido.cossu@ed.ac.uk>
 | 
			
		||||
Author: pretidav <david.preti@csic.es>
 | 
			
		||||
 | 
			
		||||
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 */
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Modules/MGauge/FundtoHirep.hpp>
 | 
			
		||||
 | 
			
		||||
using namespace Grid;
 | 
			
		||||
using namespace Hadrons;
 | 
			
		||||
using namespace MGauge;
 | 
			
		||||
 | 
			
		||||
// constructor /////////////////////////////////////////////////////////////////
 | 
			
		||||
template <class Rep>
 | 
			
		||||
TFundtoHirep<Rep>::TFundtoHirep(const std::string name)
 | 
			
		||||
: Module<FundtoHirepPar>(name)
 | 
			
		||||
{}
 | 
			
		||||
 | 
			
		||||
// dependencies/products ///////////////////////////////////////////////////////
 | 
			
		||||
template <class Rep>
 | 
			
		||||
std::vector<std::string> TFundtoHirep<Rep>::getInput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> in = {par().gaugeconf};
 | 
			
		||||
 | 
			
		||||
    return in;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <class Rep>
 | 
			
		||||
std::vector<std::string> TFundtoHirep<Rep>::getOutput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> out = {getName()};
 | 
			
		||||
 | 
			
		||||
    return out;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// setup ///////////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename Rep>
 | 
			
		||||
void TFundtoHirep<Rep>::setup(void)
 | 
			
		||||
{
 | 
			
		||||
    envCreateLat(Rep::LatticeField, getName());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// execution ///////////////////////////////////////////////////////////////////
 | 
			
		||||
template <class Rep>
 | 
			
		||||
void TFundtoHirep<Rep>::execute(void)
 | 
			
		||||
{
 | 
			
		||||
    LOG(Message) << "Transforming Representation" << std::endl;
 | 
			
		||||
 | 
			
		||||
    auto &U    = envGet(LatticeGaugeField, par().gaugeconf);
 | 
			
		||||
    auto &URep = envGet(Rep::LatticeField, getName());
 | 
			
		||||
 | 
			
		||||
    Rep TargetRepresentation(U._grid);
 | 
			
		||||
    TargetRepresentation.update_representation(U);
 | 
			
		||||
    URep = TargetRepresentation.U;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										76
									
								
								Hadrons/Modules/MGauge/FundtoHirep.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										76
									
								
								Hadrons/Modules/MGauge/FundtoHirep.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,76 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MGauge/FundtoHirep.hpp
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
Author: Antonin Portelli <antonin.portelli@me.com>
 | 
			
		||||
Author: pretidav <david.preti@csic.es>
 | 
			
		||||
 | 
			
		||||
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 */
 | 
			
		||||
 | 
			
		||||
#ifndef Hadrons_MGauge_FundtoHirep_hpp_
 | 
			
		||||
#define Hadrons_MGauge_FundtoHirep_hpp_
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Global.hpp>
 | 
			
		||||
#include <Hadrons/Module.hpp>
 | 
			
		||||
#include <Hadrons/ModuleFactory.hpp>
 | 
			
		||||
 | 
			
		||||
BEGIN_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                         Load a NERSC configuration                         *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
BEGIN_MODULE_NAMESPACE(MGauge)
 | 
			
		||||
 | 
			
		||||
class FundtoHirepPar: Serializable
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    GRID_SERIALIZABLE_CLASS_MEMBERS(FundtoHirepPar,
 | 
			
		||||
                                    std::string, gaugeconf);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
template <class Rep>
 | 
			
		||||
class TFundtoHirep: public Module<FundtoHirepPar>
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    // constructor
 | 
			
		||||
    TFundtoHirep(const std::string name);
 | 
			
		||||
    // destructor
 | 
			
		||||
    virtual ~TFundtoHirep(void) {};
 | 
			
		||||
    // dependency relation
 | 
			
		||||
    virtual std::vector<std::string> getInput(void);
 | 
			
		||||
    virtual std::vector<std::string> getOutput(void);
 | 
			
		||||
    // setup
 | 
			
		||||
    void setup(void);
 | 
			
		||||
    // execution
 | 
			
		||||
    void execute(void);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
//MODULE_REGISTER_TMP(FundtoAdjoint,   TFundtoHirep<AdjointRepresentation>, MGauge);
 | 
			
		||||
//MODULE_REGISTER_TMP(FundtoTwoIndexSym, TFundtoHirep<TwoIndexSymmetricRepresentation>, MGauge);
 | 
			
		||||
//MODULE_REGISTER_TMP(FundtoTwoIndexAsym, TFundtoHirep<TwoIndexAntiSymmetricRepresentation>, MGauge);
 | 
			
		||||
 | 
			
		||||
END_MODULE_NAMESPACE
 | 
			
		||||
 | 
			
		||||
END_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
#endif // Hadrons_MGauge_FundtoHirep_hpp_
 | 
			
		||||
							
								
								
									
										71
									
								
								Hadrons/Modules/MGauge/Random.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										71
									
								
								Hadrons/Modules/MGauge/Random.cc
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,71 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MGauge/Random.cc
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Modules/MGauge/Random.hpp>
 | 
			
		||||
 | 
			
		||||
using namespace Grid;
 | 
			
		||||
using namespace Hadrons;
 | 
			
		||||
using namespace MGauge;
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
*                           TRandom implementation                            *
 | 
			
		||||
******************************************************************************/
 | 
			
		||||
// constructor /////////////////////////////////////////////////////////////////
 | 
			
		||||
TRandom::TRandom(const std::string name)
 | 
			
		||||
: Module<NoPar>(name)
 | 
			
		||||
{}
 | 
			
		||||
 | 
			
		||||
// dependencies/products ///////////////////////////////////////////////////////
 | 
			
		||||
std::vector<std::string> TRandom::getInput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> in;
 | 
			
		||||
    
 | 
			
		||||
    return in;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::vector<std::string> TRandom::getOutput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> out = {getName()};
 | 
			
		||||
    
 | 
			
		||||
    return out;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// setup ///////////////////////////////////////////////////////////////////////
 | 
			
		||||
void TRandom::setup(void)
 | 
			
		||||
{
 | 
			
		||||
    envCreateLat(LatticeGaugeField, getName());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// execution ///////////////////////////////////////////////////////////////////
 | 
			
		||||
void TRandom::execute(void)
 | 
			
		||||
{
 | 
			
		||||
    LOG(Message) << "Generating random gauge configuration" << std::endl;
 | 
			
		||||
    
 | 
			
		||||
    auto &U = envGet(LatticeGaugeField, getName());
 | 
			
		||||
    SU3::HotConfiguration(rng4d(), U);
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										66
									
								
								Hadrons/Modules/MGauge/Random.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										66
									
								
								Hadrons/Modules/MGauge/Random.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,66 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MGauge/Random.hpp
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
 | 
			
		||||
#ifndef Hadrons_MGauge_Random_hpp_
 | 
			
		||||
#define Hadrons_MGauge_Random_hpp_
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Global.hpp>
 | 
			
		||||
#include <Hadrons/Module.hpp>
 | 
			
		||||
#include <Hadrons/ModuleFactory.hpp>
 | 
			
		||||
 | 
			
		||||
BEGIN_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                             Random gauge                                   *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
BEGIN_MODULE_NAMESPACE(MGauge)
 | 
			
		||||
 | 
			
		||||
class TRandom: public Module<NoPar>
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    // constructor
 | 
			
		||||
    TRandom(const std::string name);
 | 
			
		||||
    // destructor
 | 
			
		||||
    virtual ~TRandom(void) {};
 | 
			
		||||
    // dependency relation
 | 
			
		||||
    virtual std::vector<std::string> getInput(void);
 | 
			
		||||
    virtual std::vector<std::string> getOutput(void);
 | 
			
		||||
protected:
 | 
			
		||||
    // setup
 | 
			
		||||
    virtual void setup(void);
 | 
			
		||||
    // execution
 | 
			
		||||
    virtual void execute(void);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
MODULE_REGISTER(Random, TRandom, MGauge);
 | 
			
		||||
 | 
			
		||||
END_MODULE_NAMESPACE
 | 
			
		||||
 | 
			
		||||
END_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
#endif // Hadrons_MGauge_Random_hpp_
 | 
			
		||||
							
								
								
									
										85
									
								
								Hadrons/Modules/MGauge/StochEm.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										85
									
								
								Hadrons/Modules/MGauge/StochEm.cc
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,85 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MGauge/StochEm.cc
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
Author: Antonin Portelli <antonin.portelli@me.com>
 | 
			
		||||
Author: James Harrison <jch1g10@soton.ac.uk>
 | 
			
		||||
Author: Vera Guelpers <vmg1n14@soton.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 */
 | 
			
		||||
#include <Hadrons/Modules/MGauge/StochEm.hpp>
 | 
			
		||||
 | 
			
		||||
using namespace Grid;
 | 
			
		||||
using namespace Hadrons;
 | 
			
		||||
using namespace MGauge;
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
*                  TStochEm implementation                             *
 | 
			
		||||
******************************************************************************/
 | 
			
		||||
// constructor /////////////////////////////////////////////////////////////////
 | 
			
		||||
TStochEm::TStochEm(const std::string name)
 | 
			
		||||
: Module<StochEmPar>(name)
 | 
			
		||||
{}
 | 
			
		||||
 | 
			
		||||
// dependencies/products ///////////////////////////////////////////////////////
 | 
			
		||||
std::vector<std::string> TStochEm::getInput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> in;
 | 
			
		||||
    
 | 
			
		||||
    return in;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::vector<std::string> TStochEm::getOutput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> out = {getName()};
 | 
			
		||||
    
 | 
			
		||||
    return out;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// setup ///////////////////////////////////////////////////////////////////////
 | 
			
		||||
void TStochEm::setup(void)
 | 
			
		||||
{
 | 
			
		||||
    weightDone_ = env().hasCreatedObject("_" + getName() + "_weight");
 | 
			
		||||
    envCacheLat(EmComp, "_" + getName() + "_weight");
 | 
			
		||||
    envCreateLat(EmField, getName());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// execution ///////////////////////////////////////////////////////////////////
 | 
			
		||||
void TStochEm::execute(void)
 | 
			
		||||
{
 | 
			
		||||
    LOG(Message) << "Generating stochastic EM potential..." << std::endl;
 | 
			
		||||
 | 
			
		||||
    std::vector<Real> improvements = strToVec<Real>(par().improvement);
 | 
			
		||||
    PhotonR photon(par().gauge, par().zmScheme, improvements, par().G0_qedInf);
 | 
			
		||||
    auto    &a = envGet(EmField, getName());
 | 
			
		||||
    auto    &w = envGet(EmComp, "_" + getName() + "_weight");
 | 
			
		||||
    
 | 
			
		||||
    if (!weightDone_)
 | 
			
		||||
    {
 | 
			
		||||
        LOG(Message) << "Caching stochastic EM potential weight (gauge: "
 | 
			
		||||
                     << par().gauge << ", zero-mode scheme: "
 | 
			
		||||
                     << par().zmScheme << ")..." << std::endl;
 | 
			
		||||
        photon.StochasticWeight(w);
 | 
			
		||||
    }
 | 
			
		||||
    photon.StochasticField(a, rng4d(), w);
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										82
									
								
								Hadrons/Modules/MGauge/StochEm.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										82
									
								
								Hadrons/Modules/MGauge/StochEm.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,82 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MGauge/StochEm.hpp
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
Author: Antonin Portelli <antonin.portelli@me.com>
 | 
			
		||||
Author: James Harrison <jch1g10@soton.ac.uk>
 | 
			
		||||
Author: Vera Guelpers <vmg1n14@soton.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 */
 | 
			
		||||
#ifndef Hadrons_MGauge_StochEm_hpp_
 | 
			
		||||
#define Hadrons_MGauge_StochEm_hpp_
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Global.hpp>
 | 
			
		||||
#include <Hadrons/Module.hpp>
 | 
			
		||||
#include <Hadrons/ModuleFactory.hpp>
 | 
			
		||||
 | 
			
		||||
BEGIN_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                         StochEm                                 *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
BEGIN_MODULE_NAMESPACE(MGauge)
 | 
			
		||||
 | 
			
		||||
class StochEmPar: Serializable
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    GRID_SERIALIZABLE_CLASS_MEMBERS(StochEmPar,
 | 
			
		||||
                                    PhotonR::Gauge,    gauge,
 | 
			
		||||
                                    PhotonR::ZmScheme, zmScheme,
 | 
			
		||||
                                    std::string,       improvement,
 | 
			
		||||
                                    Real,              G0_qedInf);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class TStochEm: public Module<StochEmPar>
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    typedef PhotonR::GaugeField     EmField;
 | 
			
		||||
    typedef PhotonR::GaugeLinkField EmComp;
 | 
			
		||||
public:
 | 
			
		||||
    // constructor
 | 
			
		||||
    TStochEm(const std::string name);
 | 
			
		||||
    // destructor
 | 
			
		||||
    virtual ~TStochEm(void) {};
 | 
			
		||||
    // dependency relation
 | 
			
		||||
    virtual std::vector<std::string> getInput(void);
 | 
			
		||||
    virtual std::vector<std::string> getOutput(void);
 | 
			
		||||
protected:
 | 
			
		||||
    // setup
 | 
			
		||||
    virtual void setup(void);
 | 
			
		||||
    // execution
 | 
			
		||||
    virtual void execute(void);
 | 
			
		||||
private:
 | 
			
		||||
    bool    weightDone_;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
MODULE_REGISTER(StochEm, TStochEm, MGauge);
 | 
			
		||||
 | 
			
		||||
END_MODULE_NAMESPACE
 | 
			
		||||
 | 
			
		||||
END_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
#endif // Hadrons_MGauge_StochEm_hpp_
 | 
			
		||||
							
								
								
									
										34
									
								
								Hadrons/Modules/MGauge/StoutSmearing.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								Hadrons/Modules/MGauge/StoutSmearing.cc
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,34 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MGauge/StoutSmearing.cc
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
#include <Hadrons/Modules/MGauge/StoutSmearing.hpp>
 | 
			
		||||
 | 
			
		||||
using namespace Grid;
 | 
			
		||||
using namespace Hadrons;
 | 
			
		||||
using namespace MGauge;
 | 
			
		||||
 | 
			
		||||
template class Grid::Hadrons::MGauge::TStoutSmearing<GIMPL>;
 | 
			
		||||
							
								
								
									
										131
									
								
								Hadrons/Modules/MGauge/StoutSmearing.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										131
									
								
								Hadrons/Modules/MGauge/StoutSmearing.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,131 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MGauge/StoutSmearing.hpp
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
#ifndef Hadrons_MGauge_StoutSmearing_hpp_
 | 
			
		||||
#define Hadrons_MGauge_StoutSmearing_hpp_
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Global.hpp>
 | 
			
		||||
#include <Hadrons/Module.hpp>
 | 
			
		||||
#include <Hadrons/ModuleFactory.hpp>
 | 
			
		||||
 | 
			
		||||
BEGIN_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                            Stout smearing                                  *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
BEGIN_MODULE_NAMESPACE(MGauge)
 | 
			
		||||
 | 
			
		||||
class StoutSmearingPar: Serializable
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    GRID_SERIALIZABLE_CLASS_MEMBERS(StoutSmearingPar,
 | 
			
		||||
                                    std::string, gauge,
 | 
			
		||||
                                    unsigned int, steps,
 | 
			
		||||
                                    double, rho);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
template <typename GImpl>
 | 
			
		||||
class TStoutSmearing: public Module<StoutSmearingPar>
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    typedef typename GImpl::Field GaugeField;
 | 
			
		||||
public:
 | 
			
		||||
    // constructor
 | 
			
		||||
    TStoutSmearing(const std::string name);
 | 
			
		||||
    // destructor
 | 
			
		||||
    virtual ~TStoutSmearing(void) {};
 | 
			
		||||
    // dependency relation
 | 
			
		||||
    virtual std::vector<std::string> getInput(void);
 | 
			
		||||
    virtual std::vector<std::string> getOutput(void);
 | 
			
		||||
    // setup
 | 
			
		||||
    virtual void setup(void);
 | 
			
		||||
    // execution
 | 
			
		||||
    virtual void execute(void);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
MODULE_REGISTER_TMP(StoutSmearing, TStoutSmearing<GIMPL>, MGauge);
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                     TStoutSmearing implementation                          *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
// constructor /////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename GImpl>
 | 
			
		||||
TStoutSmearing<GImpl>::TStoutSmearing(const std::string name)
 | 
			
		||||
: Module<StoutSmearingPar>(name)
 | 
			
		||||
{}
 | 
			
		||||
 | 
			
		||||
// dependencies/products ///////////////////////////////////////////////////////
 | 
			
		||||
template <typename GImpl>
 | 
			
		||||
std::vector<std::string> TStoutSmearing<GImpl>::getInput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> in = {par().gauge};
 | 
			
		||||
    
 | 
			
		||||
    return in;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename GImpl>
 | 
			
		||||
std::vector<std::string> TStoutSmearing<GImpl>::getOutput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> out = {getName()};
 | 
			
		||||
    
 | 
			
		||||
    return out;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// setup ///////////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename GImpl>
 | 
			
		||||
void TStoutSmearing<GImpl>::setup(void)
 | 
			
		||||
{
 | 
			
		||||
    envCreateLat(GaugeField, getName());
 | 
			
		||||
    envTmpLat(GaugeField, "buf");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// execution ///////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename GImpl>
 | 
			
		||||
void TStoutSmearing<GImpl>::execute(void)
 | 
			
		||||
{
 | 
			
		||||
    LOG(Message) << "Smearing '" << par().gauge << "' with " << par().steps
 | 
			
		||||
                 << " step" << ((par().steps > 1) ? "s" : "") 
 | 
			
		||||
                 << " of stout smearing and rho= " << par().rho << std::endl;
 | 
			
		||||
 | 
			
		||||
    Smear_Stout<GImpl> smearer(par().rho);
 | 
			
		||||
    auto               &U    = envGet(GaugeField, par().gauge);
 | 
			
		||||
    auto               &Usmr = envGet(GaugeField, getName());
 | 
			
		||||
 | 
			
		||||
    envGetTmp(GaugeField, buf);
 | 
			
		||||
    buf = U;
 | 
			
		||||
    for (unsigned int n = 0; n < par().steps; ++n)
 | 
			
		||||
    {
 | 
			
		||||
        smearer.smear(Usmr, buf);
 | 
			
		||||
        buf = Usmr;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
END_MODULE_NAMESPACE
 | 
			
		||||
 | 
			
		||||
END_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
#endif // Hadrons_MGauge_StoutSmearing_hpp_
 | 
			
		||||
							
								
								
									
										69
									
								
								Hadrons/Modules/MGauge/Unit.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										69
									
								
								Hadrons/Modules/MGauge/Unit.cc
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,69 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MGauge/Unit.cc
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Modules/MGauge/Unit.hpp>
 | 
			
		||||
 | 
			
		||||
using namespace Grid;
 | 
			
		||||
using namespace Hadrons;
 | 
			
		||||
using namespace MGauge;
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
*                            TUnit implementation                             *
 | 
			
		||||
******************************************************************************/
 | 
			
		||||
// constructor /////////////////////////////////////////////////////////////////
 | 
			
		||||
TUnit::TUnit(const std::string name)
 | 
			
		||||
: Module<NoPar>(name)
 | 
			
		||||
{}
 | 
			
		||||
 | 
			
		||||
// dependencies/products ///////////////////////////////////////////////////////
 | 
			
		||||
std::vector<std::string> TUnit::getInput(void)
 | 
			
		||||
{
 | 
			
		||||
    return std::vector<std::string>();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::vector<std::string> TUnit::getOutput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> out = {getName()};
 | 
			
		||||
    
 | 
			
		||||
    return out;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// setup ///////////////////////////////////////////////////////////////////////
 | 
			
		||||
void TUnit::setup(void)
 | 
			
		||||
{
 | 
			
		||||
    envCreateLat(LatticeGaugeField, getName());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// execution ///////////////////////////////////////////////////////////////////
 | 
			
		||||
void TUnit::execute(void)
 | 
			
		||||
{
 | 
			
		||||
    LOG(Message) << "Creating unit gauge configuration" << std::endl;
 | 
			
		||||
    
 | 
			
		||||
    auto &U = envGet(LatticeGaugeField, getName());
 | 
			
		||||
    SU3::ColdConfiguration(rng4d(), U);
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										66
									
								
								Hadrons/Modules/MGauge/Unit.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										66
									
								
								Hadrons/Modules/MGauge/Unit.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,66 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MGauge/Unit.hpp
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
 | 
			
		||||
#ifndef Hadrons_MGauge_Unit_hpp_
 | 
			
		||||
#define Hadrons_MGauge_Unit_hpp_
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Global.hpp>
 | 
			
		||||
#include <Hadrons/Module.hpp>
 | 
			
		||||
#include <Hadrons/ModuleFactory.hpp>
 | 
			
		||||
 | 
			
		||||
BEGIN_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                              Unit gauge                                    *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
BEGIN_MODULE_NAMESPACE(MGauge)
 | 
			
		||||
 | 
			
		||||
class TUnit: public Module<NoPar>
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    // constructor
 | 
			
		||||
    TUnit(const std::string name);
 | 
			
		||||
    // destructor
 | 
			
		||||
    virtual ~TUnit(void) {};
 | 
			
		||||
    // dependencies/products
 | 
			
		||||
    virtual std::vector<std::string> getInput(void);
 | 
			
		||||
    virtual std::vector<std::string> getOutput(void);
 | 
			
		||||
protected:
 | 
			
		||||
    // setup
 | 
			
		||||
    virtual void setup(void);
 | 
			
		||||
    // execution
 | 
			
		||||
    virtual void execute(void);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
MODULE_REGISTER(Unit, TUnit, MGauge);
 | 
			
		||||
 | 
			
		||||
END_MODULE_NAMESPACE
 | 
			
		||||
 | 
			
		||||
END_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
#endif // Hadrons_MGauge_Unit_hpp_
 | 
			
		||||
							
								
								
									
										69
									
								
								Hadrons/Modules/MGauge/UnitEm.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										69
									
								
								Hadrons/Modules/MGauge/UnitEm.cc
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,69 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MGauge/UnitEm.cc
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
Author: Antonin Portelli <antonin.portelli@me.com>
 | 
			
		||||
Author: James Harrison <jch1g10@soton.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 */
 | 
			
		||||
#include <Hadrons/Modules/MGauge/UnitEm.hpp>
 | 
			
		||||
 | 
			
		||||
using namespace Grid;
 | 
			
		||||
using namespace Hadrons;
 | 
			
		||||
using namespace MGauge;
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
*                  TStochEm implementation                             *
 | 
			
		||||
******************************************************************************/
 | 
			
		||||
// constructor /////////////////////////////////////////////////////////////////
 | 
			
		||||
TUnitEm::TUnitEm(const std::string name)
 | 
			
		||||
: Module<NoPar>(name)
 | 
			
		||||
{}
 | 
			
		||||
 | 
			
		||||
// dependencies/products ///////////////////////////////////////////////////////
 | 
			
		||||
std::vector<std::string> TUnitEm::getInput(void)
 | 
			
		||||
{
 | 
			
		||||
    return std::vector<std::string>();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::vector<std::string> TUnitEm::getOutput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> out = {getName()};
 | 
			
		||||
    
 | 
			
		||||
    return out;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// setup ///////////////////////////////////////////////////////////////////////
 | 
			
		||||
void TUnitEm::setup(void)
 | 
			
		||||
{
 | 
			
		||||
    envCreateLat(EmField, getName());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// execution ///////////////////////////////////////////////////////////////////
 | 
			
		||||
void TUnitEm::execute(void)
 | 
			
		||||
{
 | 
			
		||||
    PhotonR photon(0, 0); // Just chose arbitrary input values here
 | 
			
		||||
    auto    &a = envGet(EmField, getName());
 | 
			
		||||
    LOG(Message) << "Generating unit EM potential..." << std::endl;
 | 
			
		||||
    photon.UnitField(a);
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										69
									
								
								Hadrons/Modules/MGauge/UnitEm.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										69
									
								
								Hadrons/Modules/MGauge/UnitEm.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,69 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MGauge/UnitEm.hpp
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
Author: Antonin Portelli <antonin.portelli@me.com>
 | 
			
		||||
Author: James Harrison <jch1g10@soton.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 */
 | 
			
		||||
#ifndef Hadrons_MGauge_UnitEm_hpp_
 | 
			
		||||
#define Hadrons_MGauge_UnitEm_hpp_
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Global.hpp>
 | 
			
		||||
#include <Hadrons/Module.hpp>
 | 
			
		||||
#include <Hadrons/ModuleFactory.hpp>
 | 
			
		||||
 | 
			
		||||
BEGIN_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                         StochEm                                 *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
BEGIN_MODULE_NAMESPACE(MGauge)
 | 
			
		||||
 | 
			
		||||
class TUnitEm: public Module<NoPar>
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    typedef PhotonR::GaugeField     EmField;
 | 
			
		||||
    typedef PhotonR::GaugeLinkField EmComp;
 | 
			
		||||
public:
 | 
			
		||||
    // constructor
 | 
			
		||||
    TUnitEm(const std::string name);
 | 
			
		||||
    // destructor
 | 
			
		||||
    virtual ~TUnitEm(void) {};
 | 
			
		||||
    // dependency relation
 | 
			
		||||
    virtual std::vector<std::string> getInput(void);
 | 
			
		||||
    virtual std::vector<std::string> getOutput(void);
 | 
			
		||||
protected:
 | 
			
		||||
    // setup
 | 
			
		||||
    virtual void setup(void);
 | 
			
		||||
    // execution
 | 
			
		||||
    virtual void execute(void);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
MODULE_REGISTER(UnitEm, TUnitEm, MGauge);
 | 
			
		||||
 | 
			
		||||
END_MODULE_NAMESPACE
 | 
			
		||||
 | 
			
		||||
END_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
#endif // Hadrons_MGauge_UnitEm_hpp_
 | 
			
		||||
							
								
								
									
										40
									
								
								Hadrons/Modules/MIO/LoadBinary.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								Hadrons/Modules/MIO/LoadBinary.cc
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,40 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MIO/LoadBinary.cc
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
#include <Hadrons/Modules/MIO/LoadBinary.hpp>
 | 
			
		||||
 | 
			
		||||
using namespace Grid;
 | 
			
		||||
using namespace Hadrons;
 | 
			
		||||
using namespace MIO;
 | 
			
		||||
 | 
			
		||||
template class Grid::Hadrons::MIO::TLoadBinary<GIMPL>;
 | 
			
		||||
template class Grid::Hadrons::MIO::TLoadBinary<ScalarNxNAdjImplR<2>>;
 | 
			
		||||
template class Grid::Hadrons::MIO::TLoadBinary<ScalarNxNAdjImplR<3>>;
 | 
			
		||||
template class Grid::Hadrons::MIO::TLoadBinary<ScalarNxNAdjImplR<4>>;
 | 
			
		||||
template class Grid::Hadrons::MIO::TLoadBinary<ScalarNxNAdjImplR<5>>;
 | 
			
		||||
template class Grid::Hadrons::MIO::TLoadBinary<ScalarNxNAdjImplR<6>>;
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										140
									
								
								Hadrons/Modules/MIO/LoadBinary.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										140
									
								
								Hadrons/Modules/MIO/LoadBinary.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,140 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MIO/LoadBinary.hpp
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
#ifndef Hadrons_MIO_LoadBinary_hpp_
 | 
			
		||||
#define Hadrons_MIO_LoadBinary_hpp_
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Global.hpp>
 | 
			
		||||
#include <Hadrons/Module.hpp>
 | 
			
		||||
#include <Hadrons/ModuleFactory.hpp>
 | 
			
		||||
 | 
			
		||||
BEGIN_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                       Load a binary configurations                         *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
BEGIN_MODULE_NAMESPACE(MIO)
 | 
			
		||||
 | 
			
		||||
class LoadBinaryPar: Serializable
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    GRID_SERIALIZABLE_CLASS_MEMBERS(LoadBinaryPar,
 | 
			
		||||
                                    std::string, file,
 | 
			
		||||
                                    std::string, format);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
template <typename Impl>
 | 
			
		||||
class TLoadBinary: public Module<LoadBinaryPar>
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    typedef typename Impl::Field                  Field;
 | 
			
		||||
    typedef typename Impl::Simd                   Simd;
 | 
			
		||||
    typedef typename Field::vector_object         vobj;
 | 
			
		||||
    typedef typename vobj::scalar_object          sobj;
 | 
			
		||||
    typedef typename sobj::DoublePrecision        sobj_double;
 | 
			
		||||
    typedef BinarySimpleMunger<sobj_double, sobj> Munger;
 | 
			
		||||
public:
 | 
			
		||||
    // constructor
 | 
			
		||||
    TLoadBinary(const std::string name);
 | 
			
		||||
    // destructor
 | 
			
		||||
    virtual ~TLoadBinary(void) {};
 | 
			
		||||
    // dependency relation
 | 
			
		||||
    virtual std::vector<std::string> getInput(void);
 | 
			
		||||
    virtual std::vector<std::string> getOutput(void);
 | 
			
		||||
    // setup
 | 
			
		||||
    virtual void setup(void);
 | 
			
		||||
    // execution
 | 
			
		||||
    virtual void execute(void);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
MODULE_REGISTER_TMP(LoadBinary, TLoadBinary<GIMPL>, MIO);
 | 
			
		||||
MODULE_REGISTER_TMP(LoadBinaryScalarSU2, TLoadBinary<ScalarNxNAdjImplR<2>>, MIO);
 | 
			
		||||
MODULE_REGISTER_TMP(LoadBinaryScalarSU3, TLoadBinary<ScalarNxNAdjImplR<3>>, MIO);
 | 
			
		||||
MODULE_REGISTER_TMP(LoadBinaryScalarSU4, TLoadBinary<ScalarNxNAdjImplR<4>>, MIO);
 | 
			
		||||
MODULE_REGISTER_TMP(LoadBinaryScalarSU5, TLoadBinary<ScalarNxNAdjImplR<5>>, MIO);
 | 
			
		||||
MODULE_REGISTER_TMP(LoadBinaryScalarSU6, TLoadBinary<ScalarNxNAdjImplR<6>>, MIO);
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                         TLoadBinary implementation                         *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
// constructor /////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename Impl>
 | 
			
		||||
TLoadBinary<Impl>::TLoadBinary(const std::string name)
 | 
			
		||||
: Module<LoadBinaryPar>(name)
 | 
			
		||||
{}
 | 
			
		||||
 | 
			
		||||
// dependencies/products ///////////////////////////////////////////////////////
 | 
			
		||||
template <typename Impl>
 | 
			
		||||
std::vector<std::string> TLoadBinary<Impl>::getInput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> in;
 | 
			
		||||
    
 | 
			
		||||
    return in;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename Impl>
 | 
			
		||||
std::vector<std::string> TLoadBinary<Impl>::getOutput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> out = {getName()};
 | 
			
		||||
    
 | 
			
		||||
    return out;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// setup ///////////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename Impl>
 | 
			
		||||
void TLoadBinary<Impl>::setup(void)
 | 
			
		||||
{
 | 
			
		||||
    envCreateLat(Field, getName());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// execution ///////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename Impl>
 | 
			
		||||
void TLoadBinary<Impl>::execute(void)
 | 
			
		||||
{
 | 
			
		||||
    Munger      munge;
 | 
			
		||||
    uint32_t    nersc_csum, scidac_csuma, scidac_csumb;
 | 
			
		||||
    auto        &U = envGet(Field, getName());
 | 
			
		||||
    std::string filename = par().file + "."
 | 
			
		||||
                           + std::to_string(vm().getTrajectory());
 | 
			
		||||
 | 
			
		||||
    LOG(Message) << "Loading " << par().format 
 | 
			
		||||
                 << " binary configuration from file '" << filename
 | 
			
		||||
                 << "'" << std::endl;
 | 
			
		||||
    BinaryIO::readLatticeObject<vobj, sobj_double>(U, filename, munge, 0, 
 | 
			
		||||
                                                   par().format, nersc_csum,
 | 
			
		||||
                                                   scidac_csuma, scidac_csumb);
 | 
			
		||||
    LOG(Message) << "Checksums:" << std::endl;
 | 
			
		||||
    LOG(Message) << "  NERSC    " << nersc_csum << std::endl;
 | 
			
		||||
    LOG(Message) << "  SciDAC A " << scidac_csuma << std::endl;
 | 
			
		||||
    LOG(Message) << "  SciDAC B " << scidac_csumb << std::endl;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
END_MODULE_NAMESPACE
 | 
			
		||||
 | 
			
		||||
END_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
#endif // Hadrons_MIO_LoadBinary_hpp_
 | 
			
		||||
							
								
								
									
										35
									
								
								Hadrons/Modules/MIO/LoadCoarseEigenPack.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								Hadrons/Modules/MIO/LoadCoarseEigenPack.cc
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,35 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MIO/LoadCoarseEigenPack.cc
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
#include <Hadrons/Modules/MIO/LoadCoarseEigenPack.hpp>
 | 
			
		||||
 | 
			
		||||
using namespace Grid;
 | 
			
		||||
using namespace Hadrons;
 | 
			
		||||
using namespace MIO;
 | 
			
		||||
 | 
			
		||||
template class Grid::Hadrons::MIO::TLoadCoarseEigenPack<CoarseFermionEigenPack<FIMPL,HADRONS_DEFAULT_LANCZOS_NBASIS>>;
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										135
									
								
								Hadrons/Modules/MIO/LoadCoarseEigenPack.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										135
									
								
								Hadrons/Modules/MIO/LoadCoarseEigenPack.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,135 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MIO/LoadCoarseEigenPack.hpp
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
#ifndef Hadrons_MIO_LoadCoarseEigenPack_hpp_
 | 
			
		||||
#define Hadrons_MIO_LoadCoarseEigenPack_hpp_
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Global.hpp>
 | 
			
		||||
#include <Hadrons/Module.hpp>
 | 
			
		||||
#include <Hadrons/ModuleFactory.hpp>
 | 
			
		||||
#include <Hadrons/EigenPack.hpp>
 | 
			
		||||
 | 
			
		||||
BEGIN_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *              Load local coherence eigen vectors/values package             *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
BEGIN_MODULE_NAMESPACE(MIO)
 | 
			
		||||
 | 
			
		||||
class LoadCoarseEigenPackPar: Serializable
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    GRID_SERIALIZABLE_CLASS_MEMBERS(LoadCoarseEigenPackPar,
 | 
			
		||||
                                    std::string, filestem,
 | 
			
		||||
                                    bool,         multiFile,
 | 
			
		||||
                                    unsigned int, sizeFine,
 | 
			
		||||
                                    unsigned int, sizeCoarse,
 | 
			
		||||
                                    unsigned int, Ls,
 | 
			
		||||
                                    std::vector<int>, blockSize);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
template <typename Pack>
 | 
			
		||||
class TLoadCoarseEigenPack: public Module<LoadCoarseEigenPackPar>
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    typedef CoarseEigenPack<typename Pack::Field, typename Pack::CoarseField> BasePack;
 | 
			
		||||
    template <typename vtype> 
 | 
			
		||||
    using iImplScalar = iScalar<iScalar<iScalar<vtype>>>;
 | 
			
		||||
    typedef iImplScalar<typename Pack::Field::vector_type> SiteComplex;
 | 
			
		||||
public:
 | 
			
		||||
    // constructor
 | 
			
		||||
    TLoadCoarseEigenPack(const std::string name);
 | 
			
		||||
    // destructor
 | 
			
		||||
    virtual ~TLoadCoarseEigenPack(void) {};
 | 
			
		||||
    // dependency relation
 | 
			
		||||
    virtual std::vector<std::string> getInput(void);
 | 
			
		||||
    virtual std::vector<std::string> getOutput(void);
 | 
			
		||||
    // setup
 | 
			
		||||
    virtual void setup(void);
 | 
			
		||||
    // execution
 | 
			
		||||
    virtual void execute(void);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
MODULE_REGISTER_TMP(LoadCoarseFermionEigenPack, ARG(TLoadCoarseEigenPack<CoarseFermionEigenPack<FIMPL, HADRONS_DEFAULT_LANCZOS_NBASIS>>), MIO);
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                 TLoadCoarseEigenPack implementation                             *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
// constructor /////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename Pack>
 | 
			
		||||
TLoadCoarseEigenPack<Pack>::TLoadCoarseEigenPack(const std::string name)
 | 
			
		||||
: Module<LoadCoarseEigenPackPar>(name)
 | 
			
		||||
{}
 | 
			
		||||
 | 
			
		||||
// dependencies/products ///////////////////////////////////////////////////////
 | 
			
		||||
template <typename Pack>
 | 
			
		||||
std::vector<std::string> TLoadCoarseEigenPack<Pack>::getInput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> in;
 | 
			
		||||
    
 | 
			
		||||
    return in;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename Pack>
 | 
			
		||||
std::vector<std::string> TLoadCoarseEigenPack<Pack>::getOutput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> out = {getName()};
 | 
			
		||||
    
 | 
			
		||||
    return out;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// setup ///////////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename Pack>
 | 
			
		||||
void TLoadCoarseEigenPack<Pack>::setup(void)
 | 
			
		||||
{
 | 
			
		||||
    env().createGrid(par().Ls);
 | 
			
		||||
    env().createCoarseGrid(par().blockSize, par().Ls);
 | 
			
		||||
    envCreateDerived(BasePack, Pack, getName(), par().Ls, par().sizeFine,
 | 
			
		||||
                     par().sizeCoarse, env().getRbGrid(par().Ls), 
 | 
			
		||||
                     env().getCoarseGrid(par().blockSize, par().Ls));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// execution ///////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename Pack>
 | 
			
		||||
void TLoadCoarseEigenPack<Pack>::execute(void)
 | 
			
		||||
{
 | 
			
		||||
    auto                 cg     = env().getCoarseGrid(par().blockSize, par().Ls);
 | 
			
		||||
    auto                 &epack = envGetDerived(BasePack, Pack, getName());
 | 
			
		||||
    Lattice<SiteComplex> dummy(cg);
 | 
			
		||||
 | 
			
		||||
    epack.read(par().filestem, par().multiFile, vm().getTrajectory());
 | 
			
		||||
    LOG(Message) << "Block Gramm-Schmidt pass 1"<< std::endl;
 | 
			
		||||
    blockOrthogonalise(dummy, epack.evec);
 | 
			
		||||
    LOG(Message) << "Block Gramm-Schmidt pass 2"<< std::endl;
 | 
			
		||||
    blockOrthogonalise(dummy, epack.evec);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
END_MODULE_NAMESPACE
 | 
			
		||||
 | 
			
		||||
END_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
#endif // Hadrons_MIO_LoadCoarseEigenPack_hpp_
 | 
			
		||||
							
								
								
									
										35
									
								
								Hadrons/Modules/MIO/LoadEigenPack.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								Hadrons/Modules/MIO/LoadEigenPack.cc
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,35 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MIO/LoadEigenPack.cc
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
#include <Hadrons/Modules/MIO/LoadEigenPack.hpp>
 | 
			
		||||
 | 
			
		||||
using namespace Grid;
 | 
			
		||||
using namespace Hadrons;
 | 
			
		||||
using namespace MIO;
 | 
			
		||||
 | 
			
		||||
template class Grid::Hadrons::MIO::TLoadEigenPack<FermionEigenPack<FIMPL>>;
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										123
									
								
								Hadrons/Modules/MIO/LoadEigenPack.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										123
									
								
								Hadrons/Modules/MIO/LoadEigenPack.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,123 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MIO/LoadEigenPack.hpp
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
#ifndef Hadrons_MIO_LoadEigenPack_hpp_
 | 
			
		||||
#define Hadrons_MIO_LoadEigenPack_hpp_
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Global.hpp>
 | 
			
		||||
#include <Hadrons/Module.hpp>
 | 
			
		||||
#include <Hadrons/ModuleFactory.hpp>
 | 
			
		||||
#include <Hadrons/EigenPack.hpp>
 | 
			
		||||
 | 
			
		||||
BEGIN_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                   Load eigen vectors/values package                        *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
BEGIN_MODULE_NAMESPACE(MIO)
 | 
			
		||||
 | 
			
		||||
class LoadEigenPackPar: Serializable
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    GRID_SERIALIZABLE_CLASS_MEMBERS(LoadEigenPackPar,
 | 
			
		||||
                                    std::string, filestem,
 | 
			
		||||
                                    bool, multiFile,
 | 
			
		||||
                                    unsigned int, size,
 | 
			
		||||
                                    unsigned int, Ls);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
template <typename Pack>
 | 
			
		||||
class TLoadEigenPack: public Module<LoadEigenPackPar>
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    typedef EigenPack<typename Pack::Field> BasePack;
 | 
			
		||||
public:
 | 
			
		||||
    // constructor
 | 
			
		||||
    TLoadEigenPack(const std::string name);
 | 
			
		||||
    // destructor
 | 
			
		||||
    virtual ~TLoadEigenPack(void) {};
 | 
			
		||||
    // dependency relation
 | 
			
		||||
    virtual std::vector<std::string> getInput(void);
 | 
			
		||||
    virtual std::vector<std::string> getOutput(void);
 | 
			
		||||
    // setup
 | 
			
		||||
    virtual void setup(void);
 | 
			
		||||
    // execution
 | 
			
		||||
    virtual void execute(void);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
MODULE_REGISTER_TMP(LoadFermionEigenPack, TLoadEigenPack<FermionEigenPack<FIMPL>>, MIO);
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                    TLoadEigenPack implementation                           *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
// constructor /////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename Pack>
 | 
			
		||||
TLoadEigenPack<Pack>::TLoadEigenPack(const std::string name)
 | 
			
		||||
: Module<LoadEigenPackPar>(name)
 | 
			
		||||
{}
 | 
			
		||||
 | 
			
		||||
// dependencies/products ///////////////////////////////////////////////////////
 | 
			
		||||
template <typename Pack>
 | 
			
		||||
std::vector<std::string> TLoadEigenPack<Pack>::getInput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> in;
 | 
			
		||||
    
 | 
			
		||||
    return in;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename Pack>
 | 
			
		||||
std::vector<std::string> TLoadEigenPack<Pack>::getOutput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> out = {getName()};
 | 
			
		||||
    
 | 
			
		||||
    return out;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// setup ///////////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename Pack>
 | 
			
		||||
void TLoadEigenPack<Pack>::setup(void)
 | 
			
		||||
{
 | 
			
		||||
    env().createGrid(par().Ls);
 | 
			
		||||
    envCreateDerived(BasePack, Pack, getName(), par().Ls, par().size, 
 | 
			
		||||
                     env().getRbGrid(par().Ls));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// execution ///////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename Pack>
 | 
			
		||||
void TLoadEigenPack<Pack>::execute(void)
 | 
			
		||||
{
 | 
			
		||||
    auto &epack = envGetDerived(BasePack, Pack, getName());
 | 
			
		||||
 | 
			
		||||
    epack.read(par().filestem, par().multiFile, vm().getTrajectory());
 | 
			
		||||
    epack.eval.resize(par().size);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
END_MODULE_NAMESPACE
 | 
			
		||||
 | 
			
		||||
END_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
#endif // Hadrons_MIO_LoadEigenPack_hpp_
 | 
			
		||||
							
								
								
									
										74
									
								
								Hadrons/Modules/MIO/LoadNersc.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										74
									
								
								Hadrons/Modules/MIO/LoadNersc.cc
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,74 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MIO/LoadNersc.cc
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
#include <Hadrons/Modules/MIO/LoadNersc.hpp>
 | 
			
		||||
 | 
			
		||||
using namespace Grid;
 | 
			
		||||
using namespace Hadrons;
 | 
			
		||||
using namespace MIO;
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
*                       TLoadNersc implementation                             *
 | 
			
		||||
******************************************************************************/
 | 
			
		||||
// constructor /////////////////////////////////////////////////////////////////
 | 
			
		||||
TLoadNersc::TLoadNersc(const std::string name)
 | 
			
		||||
: Module<LoadNerscPar>(name)
 | 
			
		||||
{}
 | 
			
		||||
 | 
			
		||||
// dependencies/products ///////////////////////////////////////////////////////
 | 
			
		||||
std::vector<std::string> TLoadNersc::getInput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> in;
 | 
			
		||||
    
 | 
			
		||||
    return in;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::vector<std::string> TLoadNersc::getOutput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> out = {getName()};
 | 
			
		||||
    
 | 
			
		||||
    return out;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// setup ///////////////////////////////////////////////////////////////////////
 | 
			
		||||
void TLoadNersc::setup(void)
 | 
			
		||||
{
 | 
			
		||||
    envCreateLat(LatticeGaugeField, getName());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// execution ///////////////////////////////////////////////////////////////////
 | 
			
		||||
void TLoadNersc::execute(void)
 | 
			
		||||
{
 | 
			
		||||
    FieldMetaData header;
 | 
			
		||||
    std::string   fileName = par().file + "."
 | 
			
		||||
                             + std::to_string(vm().getTrajectory());
 | 
			
		||||
    LOG(Message) << "Loading NERSC configuration from file '" << fileName
 | 
			
		||||
                 << "'" << std::endl;
 | 
			
		||||
 | 
			
		||||
    auto &U = envGet(LatticeGaugeField, getName());
 | 
			
		||||
    NerscIO::readConfiguration(U, header, fileName);
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										71
									
								
								Hadrons/Modules/MIO/LoadNersc.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										71
									
								
								Hadrons/Modules/MIO/LoadNersc.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,71 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MIO/LoadNersc.hpp
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
#ifndef Hadrons_MIO_LoadNersc_hpp_
 | 
			
		||||
#define Hadrons_MIO_LoadNersc_hpp_
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Global.hpp>
 | 
			
		||||
#include <Hadrons/Module.hpp>
 | 
			
		||||
#include <Hadrons/ModuleFactory.hpp>
 | 
			
		||||
 | 
			
		||||
BEGIN_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                       Load a NERSC configuration                           *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
BEGIN_MODULE_NAMESPACE(MIO)
 | 
			
		||||
 | 
			
		||||
class LoadNerscPar: Serializable
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    GRID_SERIALIZABLE_CLASS_MEMBERS(LoadNerscPar,
 | 
			
		||||
                                    std::string, file);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class TLoadNersc: public Module<LoadNerscPar>
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    // constructor
 | 
			
		||||
    TLoadNersc(const std::string name);
 | 
			
		||||
    // destructor
 | 
			
		||||
    virtual ~TLoadNersc(void) {};
 | 
			
		||||
    // dependency relation
 | 
			
		||||
    virtual std::vector<std::string> getInput(void);
 | 
			
		||||
    virtual std::vector<std::string> getOutput(void);
 | 
			
		||||
    // setup
 | 
			
		||||
    virtual void setup(void);
 | 
			
		||||
    // execution
 | 
			
		||||
    virtual void execute(void);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
MODULE_REGISTER(LoadNersc, TLoadNersc, MIO);
 | 
			
		||||
 | 
			
		||||
END_MODULE_NAMESPACE
 | 
			
		||||
 | 
			
		||||
END_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
#endif // Hadrons_MIO_LoadNersc_hpp_
 | 
			
		||||
							
								
								
									
										35
									
								
								Hadrons/Modules/MLoop/NoiseLoop.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								Hadrons/Modules/MLoop/NoiseLoop.cc
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,35 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MLoop/NoiseLoop.cc
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
#include <Hadrons/Modules/MLoop/NoiseLoop.hpp>
 | 
			
		||||
 | 
			
		||||
using namespace Grid;
 | 
			
		||||
using namespace Hadrons;
 | 
			
		||||
using namespace MLoop;
 | 
			
		||||
 | 
			
		||||
template class Grid::Hadrons::MLoop::TNoiseLoop<FIMPL>;
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										134
									
								
								Hadrons/Modules/MLoop/NoiseLoop.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										134
									
								
								Hadrons/Modules/MLoop/NoiseLoop.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,134 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MLoop/NoiseLoop.hpp
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
Author: Antonin Portelli <antonin.portelli@me.com>
 | 
			
		||||
Author: Lanny91 <andrew.lawson@gmail.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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
 | 
			
		||||
#ifndef Hadrons_MLoop_NoiseLoop_hpp_
 | 
			
		||||
#define Hadrons_MLoop_NoiseLoop_hpp_
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Global.hpp>
 | 
			
		||||
#include <Hadrons/Module.hpp>
 | 
			
		||||
#include <Hadrons/ModuleFactory.hpp>
 | 
			
		||||
 | 
			
		||||
BEGIN_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 
 | 
			
		||||
 Noise loop propagator
 | 
			
		||||
 -----------------------------
 | 
			
		||||
 * loop_x = q_x * adj(eta_x)
 | 
			
		||||
 
 | 
			
		||||
 * options:
 | 
			
		||||
 - q = Result of inversion on noise source.
 | 
			
		||||
 - eta = noise source.
 | 
			
		||||
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                         NoiseLoop                                          *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
BEGIN_MODULE_NAMESPACE(MLoop)
 | 
			
		||||
 | 
			
		||||
class NoiseLoopPar: Serializable
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    GRID_SERIALIZABLE_CLASS_MEMBERS(NoiseLoopPar,
 | 
			
		||||
                                    std::string, q,
 | 
			
		||||
                                    std::string, eta);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
class TNoiseLoop: public Module<NoiseLoopPar>
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    FERM_TYPE_ALIASES(FImpl,);
 | 
			
		||||
public:
 | 
			
		||||
    // constructor
 | 
			
		||||
    TNoiseLoop(const std::string name);
 | 
			
		||||
    // destructor
 | 
			
		||||
    virtual ~TNoiseLoop(void) {};
 | 
			
		||||
    // dependency relation
 | 
			
		||||
    virtual std::vector<std::string> getInput(void);
 | 
			
		||||
    virtual std::vector<std::string> getOutput(void);
 | 
			
		||||
protected:
 | 
			
		||||
    // setup
 | 
			
		||||
    virtual void setup(void);
 | 
			
		||||
    // execution
 | 
			
		||||
    virtual void execute(void);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
MODULE_REGISTER_TMP(NoiseLoop, TNoiseLoop<FIMPL>, MLoop);
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                 TNoiseLoop implementation                                  *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
// constructor /////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
TNoiseLoop<FImpl>::TNoiseLoop(const std::string name)
 | 
			
		||||
: Module<NoiseLoopPar>(name)
 | 
			
		||||
{}
 | 
			
		||||
 | 
			
		||||
// dependencies/products ///////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
std::vector<std::string> TNoiseLoop<FImpl>::getInput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> in = {par().q, par().eta};
 | 
			
		||||
    
 | 
			
		||||
    return in;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
std::vector<std::string> TNoiseLoop<FImpl>::getOutput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> out = {getName()};
 | 
			
		||||
    
 | 
			
		||||
    return out;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// setup ///////////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
void TNoiseLoop<FImpl>::setup(void)
 | 
			
		||||
{
 | 
			
		||||
    envCreateLat(PropagatorField, getName());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// execution ///////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
void TNoiseLoop<FImpl>::execute(void)
 | 
			
		||||
{
 | 
			
		||||
    auto &loop = envGet(PropagatorField, getName());
 | 
			
		||||
    auto &q    = envGet(PropagatorField, par().q);
 | 
			
		||||
    auto &eta  = envGet(PropagatorField, par().eta);
 | 
			
		||||
    loop = q*adj(eta);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
END_MODULE_NAMESPACE
 | 
			
		||||
 | 
			
		||||
END_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
#endif // Hadrons_MLoop_NoiseLoop_hpp_
 | 
			
		||||
							
								
								
									
										35
									
								
								Hadrons/Modules/MNoise/TimeDilutedSpinColorDiagonal.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								Hadrons/Modules/MNoise/TimeDilutedSpinColorDiagonal.cc
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,35 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MNoise/TimeDilutedSpinColorDiagonal.cc
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
#include <Hadrons/Modules/MNoise/TimeDilutedSpinColorDiagonal.hpp>
 | 
			
		||||
 | 
			
		||||
using namespace Grid;
 | 
			
		||||
using namespace Hadrons;
 | 
			
		||||
using namespace MNoise;
 | 
			
		||||
 | 
			
		||||
template class Grid::Hadrons::MNoise::TTimeDilutedSpinColorDiagonal<FIMPL>;
 | 
			
		||||
template class Grid::Hadrons::MNoise::TTimeDilutedSpinColorDiagonal<ZFIMPL>;
 | 
			
		||||
							
								
								
									
										112
									
								
								Hadrons/Modules/MNoise/TimeDilutedSpinColorDiagonal.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										112
									
								
								Hadrons/Modules/MNoise/TimeDilutedSpinColorDiagonal.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,112 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MNoise/TimeDilutedSpinColorDiagonal.hpp
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
#ifndef Hadrons_MNoise_TimeDilutedSpinColorDiagonal_hpp_
 | 
			
		||||
#define Hadrons_MNoise_TimeDilutedSpinColorDiagonal_hpp_
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Global.hpp>
 | 
			
		||||
#include <Hadrons/Module.hpp>
 | 
			
		||||
#include <Hadrons/ModuleFactory.hpp>
 | 
			
		||||
#include <Hadrons/DilutedNoise.hpp>
 | 
			
		||||
 | 
			
		||||
BEGIN_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *             Generate time diluted spin-color diagonal noise                *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
BEGIN_MODULE_NAMESPACE(MNoise)
 | 
			
		||||
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
class TTimeDilutedSpinColorDiagonal: public Module<NoPar>
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    // constructor
 | 
			
		||||
    TTimeDilutedSpinColorDiagonal(const std::string name);
 | 
			
		||||
    // destructor
 | 
			
		||||
    virtual ~TTimeDilutedSpinColorDiagonal(void) {};
 | 
			
		||||
    // dependency relation
 | 
			
		||||
    virtual std::vector<std::string> getInput(void);
 | 
			
		||||
    virtual std::vector<std::string> getOutput(void);
 | 
			
		||||
    // setup
 | 
			
		||||
    virtual void setup(void);
 | 
			
		||||
    // execution
 | 
			
		||||
    virtual void execute(void);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
MODULE_REGISTER_TMP(TimeDilutedSpinColorDiagonal, TTimeDilutedSpinColorDiagonal<FIMPL>, MNoise);
 | 
			
		||||
MODULE_REGISTER_TMP(ZTimeDilutedSpinColorDiagonal, TTimeDilutedSpinColorDiagonal<ZFIMPL>, MNoise);
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *              TTimeDilutedSpinColorDiagonal implementation                  *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
// constructor /////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
TTimeDilutedSpinColorDiagonal<FImpl>::TTimeDilutedSpinColorDiagonal(const std::string name)
 | 
			
		||||
: Module<NoPar>(name)
 | 
			
		||||
{}
 | 
			
		||||
 | 
			
		||||
// dependencies/products ///////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
std::vector<std::string> TTimeDilutedSpinColorDiagonal<FImpl>::getInput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> in;
 | 
			
		||||
    
 | 
			
		||||
    return in;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
std::vector<std::string> TTimeDilutedSpinColorDiagonal<FImpl>::getOutput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> out = {getName()};
 | 
			
		||||
    
 | 
			
		||||
    return out;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// setup ///////////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
void TTimeDilutedSpinColorDiagonal<FImpl>::setup(void)
 | 
			
		||||
{
 | 
			
		||||
    envCreateDerived(DilutedNoise<FImpl>, 
 | 
			
		||||
                     TimeDilutedSpinColorDiagonalNoise<FImpl>,
 | 
			
		||||
                     getName(), 1, env().getGrid());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// execution ///////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename FImpl>
 | 
			
		||||
void TTimeDilutedSpinColorDiagonal<FImpl>::execute(void)
 | 
			
		||||
{
 | 
			
		||||
    auto &noise = envGet(DilutedNoise<FImpl>, getName());
 | 
			
		||||
 | 
			
		||||
    LOG(Message) << "Generating time-diluted, spin-color diagonal noise" << std::endl;
 | 
			
		||||
    noise.generateNoise(rng4d());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
END_MODULE_NAMESPACE
 | 
			
		||||
 | 
			
		||||
END_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
#endif // Hadrons_MNoise_TimeDilutedSpinColorDiagonal_hpp_
 | 
			
		||||
							
								
								
									
										312
									
								
								Hadrons/Modules/MScalar/ChargedProp.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										312
									
								
								Hadrons/Modules/MScalar/ChargedProp.cc
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,312 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MScalar/ChargedProp.cc
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
Author: Antonin Portelli <antonin.portelli@me.com>
 | 
			
		||||
Author: James Harrison <jch1g10@soton.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 */
 | 
			
		||||
#include <Hadrons/Modules/MScalar/ChargedProp.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MScalar/Scalar.hpp>
 | 
			
		||||
 | 
			
		||||
using namespace Grid;
 | 
			
		||||
using namespace Hadrons;
 | 
			
		||||
using namespace MScalar;
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
*                     TChargedProp implementation                             *
 | 
			
		||||
******************************************************************************/
 | 
			
		||||
// constructor /////////////////////////////////////////////////////////////////
 | 
			
		||||
TChargedProp::TChargedProp(const std::string name)
 | 
			
		||||
: Module<ChargedPropPar>(name)
 | 
			
		||||
{}
 | 
			
		||||
 | 
			
		||||
// dependencies/products ///////////////////////////////////////////////////////
 | 
			
		||||
std::vector<std::string> TChargedProp::getInput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> in = {par().source, par().emField};
 | 
			
		||||
    
 | 
			
		||||
    return in;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::vector<std::string> TChargedProp::getOutput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> out = {getName(), getName()+"_0", getName()+"_Q",
 | 
			
		||||
                                    getName()+"_Sun", getName()+"_Tad"};
 | 
			
		||||
    
 | 
			
		||||
    return out;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// setup ///////////////////////////////////////////////////////////////////////
 | 
			
		||||
void TChargedProp::setup(void)
 | 
			
		||||
{
 | 
			
		||||
    freeMomPropName_ = FREEMOMPROP(par().mass);
 | 
			
		||||
    phaseName_.clear();
 | 
			
		||||
    for (unsigned int mu = 0; mu < env().getNd(); ++mu)
 | 
			
		||||
    {
 | 
			
		||||
        phaseName_.push_back("_shiftphase_" + std::to_string(mu));
 | 
			
		||||
    }
 | 
			
		||||
    GFSrcName_ = getName() + "_DinvSrc";
 | 
			
		||||
	prop0Name_ = getName() + "_0";
 | 
			
		||||
    propQName_ = getName() + "_Q";
 | 
			
		||||
    propSunName_ = getName() + "_Sun";
 | 
			
		||||
    propTadName_ = getName() + "_Tad";
 | 
			
		||||
    fftName_   = getName() + "_fft";
 | 
			
		||||
 | 
			
		||||
    freeMomPropDone_ = env().hasCreatedObject(freeMomPropName_);
 | 
			
		||||
    GFSrcDone_       = env().hasCreatedObject(GFSrcName_);
 | 
			
		||||
    phasesDone_      = env().hasCreatedObject(phaseName_[0]);
 | 
			
		||||
	prop0Done_		 = env().hasCreatedObject(prop0Name_);
 | 
			
		||||
    envCacheLat(ScalarField, freeMomPropName_);
 | 
			
		||||
    for (unsigned int mu = 0; mu < env().getNd(); ++mu)
 | 
			
		||||
    {
 | 
			
		||||
        envCacheLat(ScalarField, phaseName_[mu]);
 | 
			
		||||
    }
 | 
			
		||||
    envCacheLat(ScalarField, GFSrcName_);
 | 
			
		||||
	envCacheLat(ScalarField, prop0Name_);
 | 
			
		||||
    envCreateLat(ScalarField, getName());
 | 
			
		||||
    envCreateLat(ScalarField, propQName_);
 | 
			
		||||
    envCreateLat(ScalarField, propSunName_);
 | 
			
		||||
    envCreateLat(ScalarField, propTadName_);
 | 
			
		||||
    envTmpLat(ScalarField, "buf");
 | 
			
		||||
    envTmpLat(ScalarField, "result");
 | 
			
		||||
    envTmpLat(ScalarField, "Amu");
 | 
			
		||||
    envCache(FFT, fftName_, 1, env().getGrid());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// execution ///////////////////////////////////////////////////////////////////
 | 
			
		||||
void TChargedProp::execute(void)
 | 
			
		||||
{
 | 
			
		||||
    // CACHING ANALYTIC EXPRESSIONS
 | 
			
		||||
    makeCaches();
 | 
			
		||||
 | 
			
		||||
    // PROPAGATOR CALCULATION
 | 
			
		||||
    LOG(Message) << "Computing charged scalar propagator"
 | 
			
		||||
                 << " (mass= " << par().mass
 | 
			
		||||
                 << ", charge= " << par().charge << ")..." << std::endl;
 | 
			
		||||
    
 | 
			
		||||
    auto   &prop    = envGet(ScalarField, getName());
 | 
			
		||||
	auto   &prop0   = envGet(ScalarField, prop0Name_);
 | 
			
		||||
	auto   &propQ   = envGet(ScalarField, propQName_);
 | 
			
		||||
	auto   &propSun = envGet(ScalarField, propSunName_);
 | 
			
		||||
	auto   &propTad = envGet(ScalarField, propTadName_);
 | 
			
		||||
    auto   &GFSrc   = envGet(ScalarField, GFSrcName_);
 | 
			
		||||
    auto   &G       = envGet(ScalarField, freeMomPropName_);
 | 
			
		||||
    auto   &fft     = envGet(FFT, fftName_);
 | 
			
		||||
    double q        = par().charge;
 | 
			
		||||
    envGetTmp(ScalarField, buf);
 | 
			
		||||
 | 
			
		||||
    // -G*momD1*G*F*Src (momD1 = F*D1*Finv)
 | 
			
		||||
    propQ = GFSrc;
 | 
			
		||||
    momD1(propQ, fft);
 | 
			
		||||
    propQ = -G*propQ;
 | 
			
		||||
    propSun = -propQ;
 | 
			
		||||
    fft.FFT_dim(propQ, propQ, env().getNd()-1, FFT::backward);
 | 
			
		||||
 | 
			
		||||
    // G*momD1*G*momD1*G*F*Src (here buf = G*momD1*G*F*Src)
 | 
			
		||||
    momD1(propSun, fft);
 | 
			
		||||
    propSun = G*propSun;
 | 
			
		||||
    fft.FFT_dim(propSun, propSun, env().getNd()-1, FFT::backward);
 | 
			
		||||
 | 
			
		||||
    // -G*momD2*G*F*Src (momD2 = F*D2*Finv)
 | 
			
		||||
    propTad = GFSrc;
 | 
			
		||||
    momD2(propTad, fft);
 | 
			
		||||
    propTad = -G*propTad;
 | 
			
		||||
    fft.FFT_dim(propTad, propTad, env().getNd()-1, FFT::backward);
 | 
			
		||||
    
 | 
			
		||||
    // full charged scalar propagator
 | 
			
		||||
    fft.FFT_dim(buf, GFSrc, env().getNd()-1, FFT::backward);
 | 
			
		||||
    prop = buf + q*propQ + q*q*propSun + q*q*propTad;
 | 
			
		||||
 | 
			
		||||
    // OUTPUT IF NECESSARY
 | 
			
		||||
    if (!par().output.empty())
 | 
			
		||||
    {
 | 
			
		||||
        Result result;
 | 
			
		||||
        TComplex            site;
 | 
			
		||||
        std::vector<int>    siteCoor;
 | 
			
		||||
 | 
			
		||||
        LOG(Message) << "Saving momentum-projected propagator to '"
 | 
			
		||||
                     << RESULT_FILE_NAME(par().output) << "'..."
 | 
			
		||||
                     << std::endl;
 | 
			
		||||
        result.projection.resize(par().outputMom.size());
 | 
			
		||||
        result.lattice_size = env().getGrid()->_fdimensions;
 | 
			
		||||
        result.mass = par().mass;
 | 
			
		||||
        result.charge = q;
 | 
			
		||||
        siteCoor.resize(env().getNd());
 | 
			
		||||
        for (unsigned int i_p = 0; i_p < par().outputMom.size(); ++i_p)
 | 
			
		||||
        {
 | 
			
		||||
            result.projection[i_p].momentum = strToVec<int>(par().outputMom[i_p]);
 | 
			
		||||
 | 
			
		||||
            LOG(Message) << "Calculating (" << par().outputMom[i_p]
 | 
			
		||||
                         << ") momentum projection" << std::endl;
 | 
			
		||||
 | 
			
		||||
            result.projection[i_p].corr_0.resize(env().getGrid()->_fdimensions[env().getNd()-1]);
 | 
			
		||||
            result.projection[i_p].corr.resize(env().getGrid()->_fdimensions[env().getNd()-1]);
 | 
			
		||||
            result.projection[i_p].corr_Q.resize(env().getGrid()->_fdimensions[env().getNd()-1]);
 | 
			
		||||
            result.projection[i_p].corr_Sun.resize(env().getGrid()->_fdimensions[env().getNd()-1]);
 | 
			
		||||
            result.projection[i_p].corr_Tad.resize(env().getGrid()->_fdimensions[env().getNd()-1]);
 | 
			
		||||
 | 
			
		||||
            for (unsigned int j = 0; j < env().getNd()-1; ++j)
 | 
			
		||||
            {
 | 
			
		||||
                siteCoor[j] = result.projection[i_p].momentum[j];
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            for (unsigned int t = 0; t < result.projection[i_p].corr.size(); ++t)
 | 
			
		||||
            {
 | 
			
		||||
                siteCoor[env().getNd()-1] = t;
 | 
			
		||||
                peekSite(site, prop, siteCoor);
 | 
			
		||||
                result.projection[i_p].corr[t]=TensorRemove(site);
 | 
			
		||||
                peekSite(site, buf, siteCoor);
 | 
			
		||||
                result.projection[i_p].corr_0[t]=TensorRemove(site);
 | 
			
		||||
                peekSite(site, propQ, siteCoor);
 | 
			
		||||
                result.projection[i_p].corr_Q[t]=TensorRemove(site);
 | 
			
		||||
                peekSite(site, propSun, siteCoor);
 | 
			
		||||
                result.projection[i_p].corr_Sun[t]=TensorRemove(site);
 | 
			
		||||
                peekSite(site, propTad, siteCoor);
 | 
			
		||||
                result.projection[i_p].corr_Tad[t]=TensorRemove(site);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        saveResult(par().output, "prop", result);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    std::vector<int> mask(env().getNd(),1);
 | 
			
		||||
    mask[env().getNd()-1] = 0;
 | 
			
		||||
    fft.FFT_dim_mask(prop, prop, mask, FFT::backward);
 | 
			
		||||
    fft.FFT_dim_mask(propQ, propQ, mask, FFT::backward);
 | 
			
		||||
    fft.FFT_dim_mask(propSun, propSun, mask, FFT::backward);
 | 
			
		||||
    fft.FFT_dim_mask(propTad, propTad, mask, FFT::backward);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TChargedProp::makeCaches(void)
 | 
			
		||||
{
 | 
			
		||||
    auto &freeMomProp = envGet(ScalarField, freeMomPropName_);
 | 
			
		||||
    auto &GFSrc       = envGet(ScalarField, GFSrcName_);
 | 
			
		||||
	auto &prop0		  = envGet(ScalarField, prop0Name_);
 | 
			
		||||
    auto &fft         = envGet(FFT, fftName_);
 | 
			
		||||
 | 
			
		||||
    if (!freeMomPropDone_)
 | 
			
		||||
    {
 | 
			
		||||
        LOG(Message) << "Caching momentum-space free scalar propagator"
 | 
			
		||||
                     << " (mass= " << par().mass << ")..." << std::endl;
 | 
			
		||||
        SIMPL::MomentumSpacePropagator(freeMomProp, par().mass);
 | 
			
		||||
    }
 | 
			
		||||
    if (!GFSrcDone_)
 | 
			
		||||
    {   
 | 
			
		||||
        auto &source = envGet(ScalarField, par().source);
 | 
			
		||||
        
 | 
			
		||||
        LOG(Message) << "Caching G*F*src..." << std::endl;
 | 
			
		||||
        fft.FFT_all_dim(GFSrc, source, FFT::forward);
 | 
			
		||||
        GFSrc = freeMomProp*GFSrc;
 | 
			
		||||
    }
 | 
			
		||||
	if (!prop0Done_)
 | 
			
		||||
	{
 | 
			
		||||
		LOG(Message) << "Caching position-space free scalar propagator..."
 | 
			
		||||
                     << std::endl;
 | 
			
		||||
		fft.FFT_all_dim(prop0, GFSrc, FFT::backward);
 | 
			
		||||
	}
 | 
			
		||||
    if (!phasesDone_)
 | 
			
		||||
    {
 | 
			
		||||
        std::vector<int> &l = env().getGrid()->_fdimensions;
 | 
			
		||||
        Complex          ci(0.0,1.0);
 | 
			
		||||
        
 | 
			
		||||
        LOG(Message) << "Caching shift phases..." << std::endl;
 | 
			
		||||
        for (unsigned int mu = 0; mu < env().getNd(); ++mu)
 | 
			
		||||
        {
 | 
			
		||||
            Real twoPiL = M_PI*2./l[mu];
 | 
			
		||||
            auto &phmu  = envGet(ScalarField, phaseName_[mu]);
 | 
			
		||||
            
 | 
			
		||||
            LatticeCoordinate(phmu, mu);
 | 
			
		||||
            phmu = exp(ci*twoPiL*phmu);
 | 
			
		||||
            phase_.push_back(&phmu);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        phase_.clear();
 | 
			
		||||
        for (unsigned int mu = 0; mu < env().getNd(); ++mu)
 | 
			
		||||
        {
 | 
			
		||||
            phase_.push_back(env().getObject<ScalarField>(phaseName_[mu]));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TChargedProp::momD1(ScalarField &s, FFT &fft)
 | 
			
		||||
{
 | 
			
		||||
    auto        &A = envGet(EmField, par().emField);
 | 
			
		||||
    Complex     ci(0.0,1.0);
 | 
			
		||||
 | 
			
		||||
    envGetTmp(ScalarField, buf);
 | 
			
		||||
    envGetTmp(ScalarField, result);
 | 
			
		||||
    envGetTmp(ScalarField, Amu);
 | 
			
		||||
 | 
			
		||||
    result = zero;
 | 
			
		||||
    for (unsigned int mu = 0; mu < env().getNd(); ++mu)
 | 
			
		||||
    {
 | 
			
		||||
        Amu = peekLorentz(A, mu);
 | 
			
		||||
        buf = (*phase_[mu])*s;
 | 
			
		||||
        fft.FFT_all_dim(buf, buf, FFT::backward);
 | 
			
		||||
        buf = Amu*buf;
 | 
			
		||||
        fft.FFT_all_dim(buf, buf, FFT::forward);
 | 
			
		||||
        result = result - ci*buf;
 | 
			
		||||
    }
 | 
			
		||||
    fft.FFT_all_dim(s, s, FFT::backward);
 | 
			
		||||
    for (unsigned int mu = 0; mu < env().getNd(); ++mu)
 | 
			
		||||
    {
 | 
			
		||||
        Amu = peekLorentz(A, mu);
 | 
			
		||||
        buf = Amu*s;
 | 
			
		||||
        fft.FFT_all_dim(buf, buf, FFT::forward);
 | 
			
		||||
        result = result + ci*adj(*phase_[mu])*buf;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    s = result;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TChargedProp::momD2(ScalarField &s, FFT &fft)
 | 
			
		||||
{
 | 
			
		||||
    auto &A = envGet(EmField, par().emField);
 | 
			
		||||
 | 
			
		||||
    envGetTmp(ScalarField, buf);
 | 
			
		||||
    envGetTmp(ScalarField, result);
 | 
			
		||||
    envGetTmp(ScalarField, Amu);
 | 
			
		||||
 | 
			
		||||
    result = zero;
 | 
			
		||||
    for (unsigned int mu = 0; mu < env().getNd(); ++mu)
 | 
			
		||||
    {
 | 
			
		||||
        Amu = peekLorentz(A, mu);
 | 
			
		||||
        buf = (*phase_[mu])*s;
 | 
			
		||||
        fft.FFT_all_dim(buf, buf, FFT::backward);
 | 
			
		||||
        buf = Amu*Amu*buf;
 | 
			
		||||
        fft.FFT_all_dim(buf, buf, FFT::forward);
 | 
			
		||||
        result = result + .5*buf;
 | 
			
		||||
    }
 | 
			
		||||
    fft.FFT_all_dim(s, s, FFT::backward);
 | 
			
		||||
    for (unsigned int mu = 0; mu < env().getNd(); ++mu)
 | 
			
		||||
    {
 | 
			
		||||
        Amu = peekLorentz(A, mu);        
 | 
			
		||||
        buf = Amu*Amu*s;
 | 
			
		||||
        fft.FFT_all_dim(buf, buf, FFT::forward);
 | 
			
		||||
        result = result + .5*adj(*phase_[mu])*buf;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    s = result;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										113
									
								
								Hadrons/Modules/MScalar/ChargedProp.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										113
									
								
								Hadrons/Modules/MScalar/ChargedProp.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,113 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MScalar/ChargedProp.hpp
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
Author: Antonin Portelli <antonin.portelli@me.com>
 | 
			
		||||
Author: James Harrison <jch1g10@soton.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 */
 | 
			
		||||
#ifndef Hadrons_MScalar_ChargedProp_hpp_
 | 
			
		||||
#define Hadrons_MScalar_ChargedProp_hpp_
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Global.hpp>
 | 
			
		||||
#include <Hadrons/Module.hpp>
 | 
			
		||||
#include <Hadrons/ModuleFactory.hpp>
 | 
			
		||||
 | 
			
		||||
BEGIN_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                       Charged scalar propagator                            *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
BEGIN_MODULE_NAMESPACE(MScalar)
 | 
			
		||||
 | 
			
		||||
class ChargedPropPar: Serializable
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    GRID_SERIALIZABLE_CLASS_MEMBERS(ChargedPropPar,
 | 
			
		||||
                                    std::string, emField,
 | 
			
		||||
                                    std::string, source,
 | 
			
		||||
                                    double,      mass,
 | 
			
		||||
                                    double,      charge,
 | 
			
		||||
                                    std::string, output,
 | 
			
		||||
                                    std::vector<std::string>, outputMom);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class TChargedProp: public Module<ChargedPropPar>
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    SCALAR_TYPE_ALIASES(SIMPL,);
 | 
			
		||||
    typedef PhotonR::GaugeField     EmField;
 | 
			
		||||
    typedef PhotonR::GaugeLinkField EmComp;
 | 
			
		||||
    class Result: Serializable
 | 
			
		||||
    {
 | 
			
		||||
    public:
 | 
			
		||||
        class Projection: Serializable
 | 
			
		||||
        {
 | 
			
		||||
        public:
 | 
			
		||||
            GRID_SERIALIZABLE_CLASS_MEMBERS(Projection,
 | 
			
		||||
                                            std::vector<int>,     momentum,
 | 
			
		||||
                                            std::vector<Complex>, corr,
 | 
			
		||||
                                            std::vector<Complex>, corr_0,
 | 
			
		||||
                                            std::vector<Complex>, corr_Q,
 | 
			
		||||
                                            std::vector<Complex>, corr_Sun,
 | 
			
		||||
                                            std::vector<Complex>, corr_Tad);
 | 
			
		||||
        };
 | 
			
		||||
        GRID_SERIALIZABLE_CLASS_MEMBERS(Result,
 | 
			
		||||
                                        std::vector<int>,        lattice_size,
 | 
			
		||||
                                        double,                  mass,
 | 
			
		||||
                                        double,                  charge,
 | 
			
		||||
                                        std::vector<Projection>, projection);
 | 
			
		||||
    };
 | 
			
		||||
public:
 | 
			
		||||
    // constructor
 | 
			
		||||
    TChargedProp(const std::string name);
 | 
			
		||||
    // destructor
 | 
			
		||||
    virtual ~TChargedProp(void) {};
 | 
			
		||||
    // dependency relation
 | 
			
		||||
    virtual std::vector<std::string> getInput(void);
 | 
			
		||||
    virtual std::vector<std::string> getOutput(void);
 | 
			
		||||
protected:
 | 
			
		||||
    // setup
 | 
			
		||||
    virtual void setup(void);
 | 
			
		||||
    // execution
 | 
			
		||||
    virtual void execute(void);
 | 
			
		||||
private:
 | 
			
		||||
    void makeCaches(void);
 | 
			
		||||
    void momD1(ScalarField &s, FFT &fft);
 | 
			
		||||
    void momD2(ScalarField &s, FFT &fft);
 | 
			
		||||
private:
 | 
			
		||||
    bool                       freeMomPropDone_, GFSrcDone_, prop0Done_,
 | 
			
		||||
                               phasesDone_;
 | 
			
		||||
    std::string                freeMomPropName_, GFSrcName_, prop0Name_,
 | 
			
		||||
                               propQName_, propSunName_, propTadName_, fftName_;
 | 
			
		||||
    std::vector<std::string>   phaseName_;
 | 
			
		||||
    std::vector<ScalarField *> phase_;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
MODULE_REGISTER(ChargedProp, TChargedProp, MScalar);
 | 
			
		||||
 | 
			
		||||
END_MODULE_NAMESPACE
 | 
			
		||||
 | 
			
		||||
END_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
#endif // Hadrons_MScalar_ChargedProp_hpp_
 | 
			
		||||
							
								
								
									
										97
									
								
								Hadrons/Modules/MScalar/FreeProp.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										97
									
								
								Hadrons/Modules/MScalar/FreeProp.cc
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,97 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MScalar/FreeProp.cc
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
#include <Hadrons/Modules/MScalar/FreeProp.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MScalar/Scalar.hpp>
 | 
			
		||||
 | 
			
		||||
using namespace Grid;
 | 
			
		||||
using namespace Hadrons;
 | 
			
		||||
using namespace MScalar;
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
*                        TFreeProp implementation                             *
 | 
			
		||||
******************************************************************************/
 | 
			
		||||
// constructor /////////////////////////////////////////////////////////////////
 | 
			
		||||
TFreeProp::TFreeProp(const std::string name)
 | 
			
		||||
: Module<FreePropPar>(name)
 | 
			
		||||
{}
 | 
			
		||||
 | 
			
		||||
// dependencies/products ///////////////////////////////////////////////////////
 | 
			
		||||
std::vector<std::string> TFreeProp::getInput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> in = {par().source};
 | 
			
		||||
    
 | 
			
		||||
    return in;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::vector<std::string> TFreeProp::getOutput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> out = {getName()};
 | 
			
		||||
    
 | 
			
		||||
    return out;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// setup ///////////////////////////////////////////////////////////////////////
 | 
			
		||||
void TFreeProp::setup(void)
 | 
			
		||||
{
 | 
			
		||||
    freeMomPropName_ = FREEMOMPROP(par().mass);
 | 
			
		||||
    
 | 
			
		||||
    freePropDone_ = env().hasCreatedObject(freeMomPropName_);
 | 
			
		||||
    envCacheLat(ScalarField, freeMomPropName_);
 | 
			
		||||
    envCreateLat(ScalarField, getName());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// execution ///////////////////////////////////////////////////////////////////
 | 
			
		||||
void TFreeProp::execute(void)
 | 
			
		||||
{
 | 
			
		||||
    auto &freeMomProp = envGet(ScalarField, freeMomPropName_);
 | 
			
		||||
    auto &prop        = envGet(ScalarField, getName());
 | 
			
		||||
    auto &source      = envGet(ScalarField, par().source);
 | 
			
		||||
 | 
			
		||||
    if (!freePropDone_)
 | 
			
		||||
    {
 | 
			
		||||
        LOG(Message) << "Caching momentum space free scalar propagator"
 | 
			
		||||
                     << " (mass= " << par().mass << ")..." << std::endl;
 | 
			
		||||
        SIMPL::MomentumSpacePropagator(freeMomProp, par().mass);
 | 
			
		||||
    }
 | 
			
		||||
    LOG(Message) << "Computing free scalar propagator..." << std::endl;
 | 
			
		||||
    SIMPL::FreePropagator(source, prop, freeMomProp);
 | 
			
		||||
    
 | 
			
		||||
    if (!par().output.empty())
 | 
			
		||||
    {
 | 
			
		||||
        std::vector<TComplex> buf;
 | 
			
		||||
        std::vector<Complex>  result;
 | 
			
		||||
        
 | 
			
		||||
        sliceSum(prop, buf, Tp);
 | 
			
		||||
        result.resize(buf.size());
 | 
			
		||||
        for (unsigned int t = 0; t < buf.size(); ++t)
 | 
			
		||||
        {
 | 
			
		||||
            result[t] = TensorRemove(buf[t]);
 | 
			
		||||
        }
 | 
			
		||||
        saveResult(par().output, "freeprop", result);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										79
									
								
								Hadrons/Modules/MScalar/FreeProp.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										79
									
								
								Hadrons/Modules/MScalar/FreeProp.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,79 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MScalar/FreeProp.hpp
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
#ifndef Hadrons_MScalar_FreeProp_hpp_
 | 
			
		||||
#define Hadrons_MScalar_FreeProp_hpp_
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Global.hpp>
 | 
			
		||||
#include <Hadrons/Module.hpp>
 | 
			
		||||
#include <Hadrons/ModuleFactory.hpp>
 | 
			
		||||
 | 
			
		||||
BEGIN_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                               FreeProp                                     *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
BEGIN_MODULE_NAMESPACE(MScalar)
 | 
			
		||||
 | 
			
		||||
class FreePropPar: Serializable
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    GRID_SERIALIZABLE_CLASS_MEMBERS(FreePropPar,
 | 
			
		||||
                                    std::string, source,
 | 
			
		||||
                                    double,      mass,
 | 
			
		||||
                                    std::string, output);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class TFreeProp: public Module<FreePropPar>
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    SCALAR_TYPE_ALIASES(SIMPL,);
 | 
			
		||||
public:
 | 
			
		||||
    // constructor
 | 
			
		||||
    TFreeProp(const std::string name);
 | 
			
		||||
    // destructor
 | 
			
		||||
    virtual ~TFreeProp(void) {};
 | 
			
		||||
    // dependency relation
 | 
			
		||||
    virtual std::vector<std::string> getInput(void);
 | 
			
		||||
    virtual std::vector<std::string> getOutput(void);
 | 
			
		||||
protected:
 | 
			
		||||
    // setup
 | 
			
		||||
    virtual void setup(void);
 | 
			
		||||
    // execution
 | 
			
		||||
    virtual void execute(void);
 | 
			
		||||
private:
 | 
			
		||||
    std::string freeMomPropName_;
 | 
			
		||||
    bool        freePropDone_;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
MODULE_REGISTER(FreeProp, TFreeProp, MScalar);
 | 
			
		||||
 | 
			
		||||
END_MODULE_NAMESPACE
 | 
			
		||||
 | 
			
		||||
END_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
#endif // Hadrons_MScalar_FreeProp_hpp_
 | 
			
		||||
							
								
								
									
										33
									
								
								Hadrons/Modules/MScalar/Scalar.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								Hadrons/Modules/MScalar/Scalar.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,33 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MScalar/Scalar.hpp
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
#ifndef Hadrons_Scalar_hpp_
 | 
			
		||||
#define Hadrons_Scalar_hpp_
 | 
			
		||||
 | 
			
		||||
#define FREEMOMPROP(m) "_scalar_mom_prop_" + std::to_string(m)
 | 
			
		||||
 | 
			
		||||
#endif // Hadrons_Scalar_hpp_
 | 
			
		||||
							
								
								
									
										564
									
								
								Hadrons/Modules/MScalar/ScalarVP.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										564
									
								
								Hadrons/Modules/MScalar/ScalarVP.cc
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,564 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MScalar/ScalarVP.cc
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
Author: Antonin Portelli <antonin.portelli@me.com>
 | 
			
		||||
Author: James Harrison <jch1g10@soton.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 */
 | 
			
		||||
#include <Hadrons/Modules/MScalar/ChargedProp.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MScalar/ScalarVP.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MScalar/Scalar.hpp>
 | 
			
		||||
 | 
			
		||||
using namespace Grid;
 | 
			
		||||
using namespace Hadrons;
 | 
			
		||||
using namespace MScalar;
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Scalar QED vacuum polarisation up to O(alpha)
 | 
			
		||||
 *
 | 
			
		||||
 * Conserved vector 2-point function diagram notation:
 | 
			
		||||
 *        _______
 | 
			
		||||
 *       /       \
 | 
			
		||||
 * U_nu *         * U_mu
 | 
			
		||||
 *       \_______/
 | 
			
		||||
 *
 | 
			
		||||
 *                (   adj(S(a\hat{nu}|x)) U_mu(x) S(0|x+a\hat{mu}) U_nu(0)    )
 | 
			
		||||
 *          = 2 Re(                             -                             )
 | 
			
		||||
 *                ( adj(S(a\hat{nu}|x+a\hat{mu})) adj(U_mu(x)) S(0|x) U_nu(0) )
 | 
			
		||||
 *  
 | 
			
		||||
 *
 | 
			
		||||
 *            _______
 | 
			
		||||
 *           /       \
 | 
			
		||||
 * free = 1 *         * 1
 | 
			
		||||
 *           \_______/
 | 
			
		||||
 *
 | 
			
		||||
 *
 | 
			
		||||
 *
 | 
			
		||||
 *             _______
 | 
			
		||||
 *            /       \
 | 
			
		||||
 * S = iA_nu *         * iA_mu
 | 
			
		||||
 *            \_______/
 | 
			
		||||
 *
 | 
			
		||||
 *
 | 
			
		||||
 *         Delta_1
 | 
			
		||||
 *         ___*___
 | 
			
		||||
 *        /       \
 | 
			
		||||
 * X = 1 *         * 1
 | 
			
		||||
 *        \___*___/
 | 
			
		||||
 *         Delta_1
 | 
			
		||||
 *
 | 
			
		||||
 *          Delta_1                     Delta_1
 | 
			
		||||
 *          ___*___                     ___*___
 | 
			
		||||
 *         /       \                   /       \
 | 
			
		||||
 *      1 *         * iA_mu  +  iA_nu *         * 1
 | 
			
		||||
 *         \_______/                   \_______/
 | 
			
		||||
 * 4C =        _______                     _______
 | 
			
		||||
 *            /       \                   /       \
 | 
			
		||||
 *      +  1 *         * iA_mu  +  iA_nu *         * 1
 | 
			
		||||
 *            \___*___/                   \___*___/
 | 
			
		||||
 *             Delta_1                     Delta_1
 | 
			
		||||
 *
 | 
			
		||||
 *     Delta_1   Delta_1
 | 
			
		||||
 *          _*___*_             _______
 | 
			
		||||
 *         /       \           /       \
 | 
			
		||||
 * 2E = 1 *         * 1  +  1 *         * 1
 | 
			
		||||
 *         \_______/           \_*___*_/
 | 
			
		||||
 *                         Delta_1   Delta_1
 | 
			
		||||
 *
 | 
			
		||||
 *          Delta_2
 | 
			
		||||
 *          ___*___             _______
 | 
			
		||||
 *         /       \           /       \
 | 
			
		||||
 * 2T = 1 *         * 1  +  1 *         * 1
 | 
			
		||||
 *         \_______/           \___*___/
 | 
			
		||||
 *                              Delta_2
 | 
			
		||||
 *
 | 
			
		||||
 *
 | 
			
		||||
 *                    _______
 | 
			
		||||
 *                   /       \
 | 
			
		||||
 * srcT = -A_nu^2/2 *         * 1
 | 
			
		||||
 *                   \_______/
 | 
			
		||||
 *
 | 
			
		||||
 *
 | 
			
		||||
 *
 | 
			
		||||
 *            _______
 | 
			
		||||
 *           /       \
 | 
			
		||||
 * snkT = 1 *         * -A_mu^2/2
 | 
			
		||||
 *           \_______/
 | 
			
		||||
 *
 | 
			
		||||
 * Full VP to O(alpha) = free + q^2*(S+X+4C+2E+2T+srcT+snkT)
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
*                  TScalarVP implementation                             *
 | 
			
		||||
******************************************************************************/
 | 
			
		||||
// constructor /////////////////////////////////////////////////////////////////
 | 
			
		||||
TScalarVP::TScalarVP(const std::string name)
 | 
			
		||||
: Module<ScalarVPPar>(name)
 | 
			
		||||
{}
 | 
			
		||||
 | 
			
		||||
// dependencies/products ///////////////////////////////////////////////////////
 | 
			
		||||
std::vector<std::string> TScalarVP::getInput(void)
 | 
			
		||||
{
 | 
			
		||||
    prop0Name_ = par().scalarProp + "_0";
 | 
			
		||||
    propQName_ = par().scalarProp + "_Q";
 | 
			
		||||
    propSunName_ = par().scalarProp + "_Sun";
 | 
			
		||||
    propTadName_ = par().scalarProp + "_Tad";
 | 
			
		||||
 | 
			
		||||
	std::vector<std::string> in = {par().emField, prop0Name_, propQName_,
 | 
			
		||||
                                   propSunName_, propTadName_};
 | 
			
		||||
    
 | 
			
		||||
    return in;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::vector<std::string> TScalarVP::getOutput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> out;
 | 
			
		||||
    
 | 
			
		||||
    for (unsigned int mu = 0; mu < env().getNd(); ++mu)
 | 
			
		||||
    {
 | 
			
		||||
        // out.push_back(getName() + "_propQ_" + std::to_string(mu));
 | 
			
		||||
 | 
			
		||||
        for (unsigned int nu = 0; nu < env().getNd(); ++nu)
 | 
			
		||||
        {
 | 
			
		||||
            out.push_back(getName() + "_" + std::to_string(mu)
 | 
			
		||||
                          + "_" + std::to_string(nu));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return out;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// setup ///////////////////////////////////////////////////////////////////////
 | 
			
		||||
void TScalarVP::setup(void)
 | 
			
		||||
{
 | 
			
		||||
	freeMomPropName_ = FREEMOMPROP(static_cast<TChargedProp *>(vm().getModule(par().scalarProp))->par().mass);
 | 
			
		||||
	GFSrcName_ = par().scalarProp + "_DinvSrc";
 | 
			
		||||
    fftName_   = par().scalarProp + "_fft";
 | 
			
		||||
	phaseName_.clear();
 | 
			
		||||
	muPropQName_.clear();
 | 
			
		||||
    vpTensorName_.clear();
 | 
			
		||||
    momPhaseName_.clear();
 | 
			
		||||
	for (unsigned int mu = 0; mu < env().getNd(); ++mu)
 | 
			
		||||
    {
 | 
			
		||||
        phaseName_.push_back("_shiftphase_" + std::to_string(mu));
 | 
			
		||||
        muPropQName_.push_back(getName() + "_propQ_" + std::to_string(mu));
 | 
			
		||||
 | 
			
		||||
        std::vector<std::string> vpTensorName_mu;
 | 
			
		||||
        for (unsigned int nu = 0; nu < env().getNd(); ++nu)
 | 
			
		||||
        {
 | 
			
		||||
            vpTensorName_mu.push_back(getName() + "_" + std::to_string(mu)
 | 
			
		||||
                                      + "_" + std::to_string(nu));
 | 
			
		||||
        }
 | 
			
		||||
        vpTensorName_.push_back(vpTensorName_mu);
 | 
			
		||||
    }
 | 
			
		||||
    if (!par().output.empty())
 | 
			
		||||
    {
 | 
			
		||||
        for (unsigned int i_p = 0; i_p < par().outputMom.size(); ++i_p)
 | 
			
		||||
        {
 | 
			
		||||
            momPhaseName_.push_back("_momentumphase_" + std::to_string(i_p));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    for (unsigned int mu = 0; mu < env().getNd(); ++mu)
 | 
			
		||||
	{
 | 
			
		||||
	    envCreateLat(ScalarField, muPropQName_[mu]);
 | 
			
		||||
 | 
			
		||||
        for (unsigned int nu = 0; nu < env().getNd(); ++nu)
 | 
			
		||||
        {
 | 
			
		||||
            envCreateLat(ScalarField, vpTensorName_[mu][nu]);
 | 
			
		||||
        }
 | 
			
		||||
	}
 | 
			
		||||
    if (!par().output.empty())
 | 
			
		||||
    {
 | 
			
		||||
        momPhasesDone_ = env().hasCreatedObject(momPhaseName_[0]);
 | 
			
		||||
        for (unsigned int i_p = 0; i_p < par().outputMom.size(); ++i_p)
 | 
			
		||||
        {
 | 
			
		||||
            envCacheLat(ScalarField, momPhaseName_[i_p]);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    envTmpLat(ScalarField, "buf");
 | 
			
		||||
    envTmpLat(ScalarField, "result");
 | 
			
		||||
    envTmpLat(ScalarField, "Amu");
 | 
			
		||||
    envTmpLat(ScalarField, "Usnk");
 | 
			
		||||
    envTmpLat(ScalarField, "tmpProp");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// execution ///////////////////////////////////////////////////////////////////
 | 
			
		||||
void TScalarVP::execute(void)
 | 
			
		||||
{
 | 
			
		||||
    // CACHING ANALYTIC EXPRESSIONS
 | 
			
		||||
    makeCaches();
 | 
			
		||||
 | 
			
		||||
    Complex ci(0.0,1.0);
 | 
			
		||||
    Real    q        = static_cast<TChargedProp *>(vm().getModule(par().scalarProp))->par().charge;
 | 
			
		||||
    auto    &prop0   = envGet(ScalarField, prop0Name_);
 | 
			
		||||
    auto    &propQ   = envGet(ScalarField, propQName_);
 | 
			
		||||
    auto    &propSun = envGet(ScalarField, propSunName_);
 | 
			
		||||
    auto    &propTad = envGet(ScalarField, propTadName_);
 | 
			
		||||
    auto    &GFSrc   = envGet(ScalarField, GFSrcName_);
 | 
			
		||||
    auto    &G       = envGet(ScalarField, freeMomPropName_);
 | 
			
		||||
    auto    &fft     = envGet(FFT, fftName_);
 | 
			
		||||
    phase_.clear();
 | 
			
		||||
    for (unsigned int mu = 0; mu < env().getNd(); ++mu)
 | 
			
		||||
    {
 | 
			
		||||
        auto &phmu = envGet(ScalarField, phaseName_[mu]);
 | 
			
		||||
        phase_.push_back(&phmu);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    // PROPAGATORS FROM SHIFTED SOURCES
 | 
			
		||||
    LOG(Message) << "Computing O(q) charged scalar propagators..."
 | 
			
		||||
                 << std::endl;
 | 
			
		||||
    std::vector<ScalarField *> muPropQ;
 | 
			
		||||
    for (unsigned int mu = 0; mu < env().getNd(); ++mu)
 | 
			
		||||
    {
 | 
			
		||||
        auto &propmu = envGet(ScalarField, muPropQName_[mu]);
 | 
			
		||||
 | 
			
		||||
        // -G*momD1*G*F*tau_mu*Src (momD1 = F*D1*Finv)
 | 
			
		||||
        propmu = adj(*phase_[mu])*GFSrc;
 | 
			
		||||
        momD1(propmu, fft);
 | 
			
		||||
        propmu = -G*propmu;
 | 
			
		||||
        fft.FFT_all_dim(propmu, propmu, FFT::backward);
 | 
			
		||||
 | 
			
		||||
        muPropQ.push_back(&propmu);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // CONTRACTIONS
 | 
			
		||||
    auto        &A = envGet(EmField, par().emField);
 | 
			
		||||
    envGetTmp(ScalarField, buf);
 | 
			
		||||
    envGetTmp(ScalarField, result);
 | 
			
		||||
    envGetTmp(ScalarField, Amu);
 | 
			
		||||
    envGetTmp(ScalarField, Usnk);
 | 
			
		||||
    envGetTmp(ScalarField, tmpProp);
 | 
			
		||||
    TComplex    Anu0, Usrc;
 | 
			
		||||
    std::vector<int> coor0 = {0, 0, 0, 0};
 | 
			
		||||
    std::vector<std::vector<ScalarField *> > vpTensor;
 | 
			
		||||
    for (unsigned int mu = 0; mu < env().getNd(); ++mu)
 | 
			
		||||
    {
 | 
			
		||||
        std::vector<ScalarField *> vpTensor_mu;
 | 
			
		||||
        for (unsigned int nu = 0; nu < env().getNd(); ++nu)
 | 
			
		||||
        {
 | 
			
		||||
            auto &vpmunu = envGet(ScalarField, vpTensorName_[mu][nu]);
 | 
			
		||||
            vpTensor_mu.push_back(&vpmunu);
 | 
			
		||||
        }
 | 
			
		||||
        vpTensor.push_back(vpTensor_mu);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Prepare output data structure if necessary
 | 
			
		||||
    Result outputData;
 | 
			
		||||
    if (!par().output.empty())
 | 
			
		||||
    {
 | 
			
		||||
        outputData.projection.resize(par().outputMom.size());
 | 
			
		||||
        outputData.lattice_size = env().getGrid()->_fdimensions;
 | 
			
		||||
        outputData.mass = static_cast<TChargedProp *>(vm().getModule(par().scalarProp))->par().mass;
 | 
			
		||||
        outputData.charge = q;
 | 
			
		||||
        for (unsigned int i_p = 0; i_p < par().outputMom.size(); ++i_p)
 | 
			
		||||
        {
 | 
			
		||||
            outputData.projection[i_p].momentum = strToVec<int>(par().outputMom[i_p]);
 | 
			
		||||
            outputData.projection[i_p].pi.resize(env().getNd());
 | 
			
		||||
            outputData.projection[i_p].pi_free.resize(env().getNd());
 | 
			
		||||
            outputData.projection[i_p].pi_2E.resize(env().getNd());
 | 
			
		||||
            outputData.projection[i_p].pi_2T.resize(env().getNd());
 | 
			
		||||
            outputData.projection[i_p].pi_S.resize(env().getNd());
 | 
			
		||||
            outputData.projection[i_p].pi_4C.resize(env().getNd());
 | 
			
		||||
            outputData.projection[i_p].pi_X.resize(env().getNd());
 | 
			
		||||
            outputData.projection[i_p].pi_srcT.resize(env().getNd());
 | 
			
		||||
            outputData.projection[i_p].pi_snkT.resize(env().getNd());
 | 
			
		||||
            for (unsigned int nu = 0; nu < env().getNd(); ++nu)
 | 
			
		||||
            {
 | 
			
		||||
                outputData.projection[i_p].pi[nu].resize(env().getNd());
 | 
			
		||||
                outputData.projection[i_p].pi_free[nu].resize(env().getNd());
 | 
			
		||||
                outputData.projection[i_p].pi_2E[nu].resize(env().getNd());
 | 
			
		||||
                outputData.projection[i_p].pi_2T[nu].resize(env().getNd());
 | 
			
		||||
                outputData.projection[i_p].pi_S[nu].resize(env().getNd());
 | 
			
		||||
                outputData.projection[i_p].pi_4C[nu].resize(env().getNd());
 | 
			
		||||
                outputData.projection[i_p].pi_X[nu].resize(env().getNd());
 | 
			
		||||
                outputData.projection[i_p].pi_srcT[nu].resize(env().getNd());
 | 
			
		||||
                outputData.projection[i_p].pi_snkT[nu].resize(env().getNd());
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Do contractions
 | 
			
		||||
    for (unsigned int nu = 0; nu < env().getNd(); ++nu)
 | 
			
		||||
    {
 | 
			
		||||
        peekSite(Anu0, peekLorentz(A, nu), coor0);
 | 
			
		||||
 | 
			
		||||
        for (unsigned int mu = 0; mu < env().getNd(); ++mu)
 | 
			
		||||
        {
 | 
			
		||||
            LOG(Message) << "Computing Pi[" << mu << "][" << nu << "]..."
 | 
			
		||||
                         << std::endl;
 | 
			
		||||
            Amu = peekLorentz(A, mu);
 | 
			
		||||
 | 
			
		||||
            // free
 | 
			
		||||
            tmpProp = Cshift(prop0, nu, -1);     // S_0(0|x-a\hat{\nu})
 | 
			
		||||
                                                 // = S_0(a\hat{\nu}|x)
 | 
			
		||||
            Usrc    = Complex(1.0,0.0);
 | 
			
		||||
            vpContraction(result, prop0, tmpProp, Usrc, mu);
 | 
			
		||||
            *vpTensor[mu][nu] = result;
 | 
			
		||||
            // Do momentum projections if necessary
 | 
			
		||||
            if (!par().output.empty())
 | 
			
		||||
            {
 | 
			
		||||
                for (unsigned int i_p = 0; i_p < par().outputMom.size(); ++i_p)
 | 
			
		||||
                {
 | 
			
		||||
                    project(outputData.projection[i_p].pi_free[mu][nu], result,
 | 
			
		||||
                            i_p);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            tmpProp = result; // Just using tmpProp as a temporary ScalarField
 | 
			
		||||
                              // here (buf is modified by calls to writeVP())
 | 
			
		||||
 | 
			
		||||
            // srcT
 | 
			
		||||
            result = tmpProp * (-0.5)*Anu0*Anu0;
 | 
			
		||||
            *vpTensor[mu][nu] += q*q*result;
 | 
			
		||||
            // Do momentum projections if necessary
 | 
			
		||||
            if (!par().output.empty())
 | 
			
		||||
            {
 | 
			
		||||
                for (unsigned int i_p = 0; i_p < par().outputMom.size(); ++i_p)
 | 
			
		||||
                {
 | 
			
		||||
                    project(outputData.projection[i_p].pi_srcT[mu][nu], result,
 | 
			
		||||
                            i_p);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // snkT
 | 
			
		||||
            result = tmpProp * (-0.5)*Amu*Amu;
 | 
			
		||||
            *vpTensor[mu][nu] += q*q*result;
 | 
			
		||||
            // Do momentum projections if necessary
 | 
			
		||||
            if (!par().output.empty())
 | 
			
		||||
            {
 | 
			
		||||
                for (unsigned int i_p = 0; i_p < par().outputMom.size(); ++i_p)
 | 
			
		||||
                {
 | 
			
		||||
                    project(outputData.projection[i_p].pi_snkT[mu][nu], result,
 | 
			
		||||
                            i_p);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // S
 | 
			
		||||
            tmpProp = Cshift(prop0, nu, -1);     // S_0(a\hat{\nu}|x)
 | 
			
		||||
            Usrc    = ci*Anu0;
 | 
			
		||||
            Usnk    = ci*Amu;
 | 
			
		||||
            vpContraction(result, prop0, tmpProp, Usrc, Usnk, mu);
 | 
			
		||||
            *vpTensor[mu][nu] += q*q*result;
 | 
			
		||||
            // Do momentum projections if necessary
 | 
			
		||||
            if (!par().output.empty())
 | 
			
		||||
            {
 | 
			
		||||
                for (unsigned int i_p = 0; i_p < par().outputMom.size(); ++i_p)
 | 
			
		||||
                {
 | 
			
		||||
                    project(outputData.projection[i_p].pi_S[mu][nu], result,
 | 
			
		||||
                            i_p);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // 4C
 | 
			
		||||
            tmpProp = Cshift(prop0, nu, -1);     // S_0(a\hat{\nu}|x)
 | 
			
		||||
            Usrc    = Complex(1.0,0.0);
 | 
			
		||||
            Usnk    = ci*Amu;
 | 
			
		||||
            vpContraction(result, propQ, tmpProp, Usrc, Usnk, mu);
 | 
			
		||||
            Usrc    = ci*Anu0;
 | 
			
		||||
            vpContraction(buf, propQ, tmpProp, Usrc, mu);
 | 
			
		||||
            result += buf;
 | 
			
		||||
            vpContraction(buf, prop0, *muPropQ[nu], Usrc, mu);
 | 
			
		||||
            result += buf;
 | 
			
		||||
            Usrc = Complex(1.0,0.0);
 | 
			
		||||
            Usnk = ci*Amu;
 | 
			
		||||
            vpContraction(buf, prop0, *muPropQ[nu], Usrc, Usnk, mu);
 | 
			
		||||
            result += buf;
 | 
			
		||||
            *vpTensor[mu][nu] += q*q*result;
 | 
			
		||||
            // Do momentum projections if necessary
 | 
			
		||||
            if (!par().output.empty())
 | 
			
		||||
            {
 | 
			
		||||
                for (unsigned int i_p = 0; i_p < par().outputMom.size(); ++i_p)
 | 
			
		||||
                {
 | 
			
		||||
                    project(outputData.projection[i_p].pi_4C[mu][nu], result,
 | 
			
		||||
                            i_p);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // X
 | 
			
		||||
            Usrc = Complex(1.0,0.0);
 | 
			
		||||
            vpContraction(result, propQ, *muPropQ[nu], Usrc, mu);
 | 
			
		||||
            *vpTensor[mu][nu] += q*q*result;
 | 
			
		||||
            // Do momentum projections if necessary
 | 
			
		||||
            if (!par().output.empty())
 | 
			
		||||
            {
 | 
			
		||||
                for (unsigned int i_p = 0; i_p < par().outputMom.size(); ++i_p)
 | 
			
		||||
                {
 | 
			
		||||
                    project(outputData.projection[i_p].pi_X[mu][nu], result,
 | 
			
		||||
                            i_p);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // 2E
 | 
			
		||||
            tmpProp = Cshift(prop0, nu, -1);     // S_0(a\hat{\nu}|x)
 | 
			
		||||
            Usrc    = Complex(1.0,0.0);
 | 
			
		||||
            vpContraction(result, propSun, tmpProp, Usrc, mu);
 | 
			
		||||
            tmpProp = Cshift(propSun, nu, -1);     // S_\Sigma(0|x-a\hat{\nu})
 | 
			
		||||
                               //(Note: <S(0|x-a\hat{\nu})> = <S(a\hat{\nu}|x)>)
 | 
			
		||||
            vpContraction(buf, prop0, tmpProp, Usrc, mu);
 | 
			
		||||
            result += buf;
 | 
			
		||||
            *vpTensor[mu][nu] += q*q*result;
 | 
			
		||||
            // Do momentum projections if necessary
 | 
			
		||||
            if (!par().output.empty())
 | 
			
		||||
            {
 | 
			
		||||
                for (unsigned int i_p = 0; i_p < par().outputMom.size(); ++i_p)
 | 
			
		||||
                {
 | 
			
		||||
                    project(outputData.projection[i_p].pi_2E[mu][nu], result,
 | 
			
		||||
                            i_p);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // 2T
 | 
			
		||||
            tmpProp = Cshift(prop0, nu, -1);     // S_0(a\hat{\nu}|x)
 | 
			
		||||
            Usrc    = Complex(1.0,0.0);
 | 
			
		||||
            vpContraction(result, propTad, tmpProp, Usrc, mu);
 | 
			
		||||
            tmpProp = Cshift(propTad, nu, -1);     // S_T(0|x-a\hat{\nu})
 | 
			
		||||
            vpContraction(buf, prop0, tmpProp, Usrc, mu);
 | 
			
		||||
            result += buf;
 | 
			
		||||
            *vpTensor[mu][nu] += q*q*result;
 | 
			
		||||
            // Do momentum projections if necessary
 | 
			
		||||
            if (!par().output.empty())
 | 
			
		||||
            {
 | 
			
		||||
                for (unsigned int i_p = 0; i_p < par().outputMom.size(); ++i_p)
 | 
			
		||||
                {
 | 
			
		||||
                    project(outputData.projection[i_p].pi_2T[mu][nu], result,
 | 
			
		||||
                            i_p);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // Do momentum projections of full VP if necessary
 | 
			
		||||
            if (!par().output.empty())
 | 
			
		||||
            {
 | 
			
		||||
                for (unsigned int i_p = 0; i_p < par().outputMom.size(); ++i_p)
 | 
			
		||||
                {
 | 
			
		||||
                    project(outputData.projection[i_p].pi[mu][nu],
 | 
			
		||||
                            *vpTensor[mu][nu], i_p);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // OUTPUT IF NECESSARY
 | 
			
		||||
    if (!par().output.empty())
 | 
			
		||||
    {
 | 
			
		||||
        LOG(Message) << "Saving momentum-projected HVP to '"
 | 
			
		||||
                     << RESULT_FILE_NAME(par().output) << "'..."
 | 
			
		||||
                     << std::endl;
 | 
			
		||||
        saveResult(par().output, "HVP", outputData);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TScalarVP::makeCaches(void)
 | 
			
		||||
{
 | 
			
		||||
    envGetTmp(ScalarField, buf);
 | 
			
		||||
 | 
			
		||||
    if ( (!par().output.empty()) && (!momPhasesDone_) )
 | 
			
		||||
    {
 | 
			
		||||
        LOG(Message) << "Caching phases for momentum projections..."
 | 
			
		||||
                     << std::endl;
 | 
			
		||||
        std::vector<int> &l = env().getGrid()->_fdimensions;
 | 
			
		||||
        Complex          ci(0.0,1.0);
 | 
			
		||||
 | 
			
		||||
        // Calculate phase factors
 | 
			
		||||
        for (unsigned int i_p = 0; i_p < par().outputMom.size(); ++i_p)
 | 
			
		||||
        {
 | 
			
		||||
            std::vector<int> mom = strToVec<int>(par().outputMom[i_p]);
 | 
			
		||||
            auto &momph_ip = envGet(ScalarField, momPhaseName_[i_p]);
 | 
			
		||||
            momph_ip = zero;
 | 
			
		||||
            for (unsigned int j = 0; j < env().getNd()-1; ++j)
 | 
			
		||||
            {
 | 
			
		||||
                Real twoPiL = M_PI*2./l[j];
 | 
			
		||||
                LatticeCoordinate(buf, j);
 | 
			
		||||
                buf = mom[j]*twoPiL*buf;
 | 
			
		||||
                momph_ip = momph_ip + buf;
 | 
			
		||||
            }
 | 
			
		||||
            momph_ip = exp(-ci*momph_ip);
 | 
			
		||||
            momPhase_.push_back(&momph_ip);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TScalarVP::vpContraction(ScalarField &vp,
 | 
			
		||||
                   ScalarField &prop_0_x, ScalarField &prop_nu_x,
 | 
			
		||||
                   TComplex u_src, ScalarField &u_snk, int mu)
 | 
			
		||||
{
 | 
			
		||||
    // Note: this function assumes a point source is used.
 | 
			
		||||
    vp = adj(prop_nu_x) * u_snk * Cshift(prop_0_x, mu, 1) * u_src;
 | 
			
		||||
    vp -= Cshift(adj(prop_nu_x), mu, 1) * adj(u_snk) * prop_0_x * u_src;
 | 
			
		||||
    vp = 2.0*real(vp);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TScalarVP::vpContraction(ScalarField &vp,
 | 
			
		||||
                   ScalarField &prop_0_x, ScalarField &prop_nu_x,
 | 
			
		||||
                   TComplex u_src, int mu)
 | 
			
		||||
{
 | 
			
		||||
    // Note: this function assumes a point source is used.
 | 
			
		||||
    vp = adj(prop_nu_x) * Cshift(prop_0_x, mu, 1) * u_src;
 | 
			
		||||
    vp -= Cshift(adj(prop_nu_x), mu, 1) * prop_0_x * u_src;
 | 
			
		||||
    vp = 2.0*real(vp);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TScalarVP::project(std::vector<Complex> &projection, const ScalarField &vp, int i_p)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<TComplex>   vecBuf;
 | 
			
		||||
    envGetTmp(ScalarField, buf);
 | 
			
		||||
 | 
			
		||||
    buf = vp*(*momPhase_[i_p]);
 | 
			
		||||
    sliceSum(buf, vecBuf, Tp);
 | 
			
		||||
    projection.resize(vecBuf.size());
 | 
			
		||||
    for (unsigned int t = 0; t < vecBuf.size(); ++t)
 | 
			
		||||
    {
 | 
			
		||||
        projection[t] = TensorRemove(vecBuf[t]);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TScalarVP::momD1(ScalarField &s, FFT &fft)
 | 
			
		||||
{
 | 
			
		||||
    auto        &A = envGet(EmField, par().emField);
 | 
			
		||||
    Complex     ci(0.0,1.0);
 | 
			
		||||
 | 
			
		||||
    envGetTmp(ScalarField, buf);
 | 
			
		||||
    envGetTmp(ScalarField, result);
 | 
			
		||||
    envGetTmp(ScalarField, Amu);
 | 
			
		||||
 | 
			
		||||
    result = zero;
 | 
			
		||||
    for (unsigned int mu = 0; mu < env().getNd(); ++mu)
 | 
			
		||||
    {
 | 
			
		||||
        Amu = peekLorentz(A, mu);
 | 
			
		||||
        buf = (*phase_[mu])*s;
 | 
			
		||||
        fft.FFT_all_dim(buf, buf, FFT::backward);
 | 
			
		||||
        buf = Amu*buf;
 | 
			
		||||
        fft.FFT_all_dim(buf, buf, FFT::forward);
 | 
			
		||||
        result = result - ci*buf;
 | 
			
		||||
    }
 | 
			
		||||
    fft.FFT_all_dim(s, s, FFT::backward);
 | 
			
		||||
    for (unsigned int mu = 0; mu < env().getNd(); ++mu)
 | 
			
		||||
    {
 | 
			
		||||
        Amu = peekLorentz(A, mu);
 | 
			
		||||
        buf = Amu*s;
 | 
			
		||||
        fft.FFT_all_dim(buf, buf, FFT::forward);
 | 
			
		||||
        result = result + ci*adj(*phase_[mu])*buf;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    s = result;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										129
									
								
								Hadrons/Modules/MScalar/ScalarVP.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										129
									
								
								Hadrons/Modules/MScalar/ScalarVP.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,129 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MScalar/ScalarVP.hpp
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
Author: Antonin Portelli <antonin.portelli@me.com>
 | 
			
		||||
Author: James Harrison <jch1g10@soton.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 */
 | 
			
		||||
#ifndef Hadrons_MScalar_ScalarVP_hpp_
 | 
			
		||||
#define Hadrons_MScalar_ScalarVP_hpp_
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Global.hpp>
 | 
			
		||||
#include <Hadrons/Module.hpp>
 | 
			
		||||
#include <Hadrons/ModuleFactory.hpp>
 | 
			
		||||
 | 
			
		||||
BEGIN_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                         Scalar vacuum polarisation                         *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
BEGIN_MODULE_NAMESPACE(MScalar)
 | 
			
		||||
 | 
			
		||||
class ScalarVPPar: Serializable
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    GRID_SERIALIZABLE_CLASS_MEMBERS(ScalarVPPar,
 | 
			
		||||
                                    std::string, emField,
 | 
			
		||||
                                    std::string, scalarProp,
 | 
			
		||||
                                    std::string, output,
 | 
			
		||||
                                    std::vector<std::string>, outputMom);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class TScalarVP: public Module<ScalarVPPar>
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    SCALAR_TYPE_ALIASES(SIMPL,);
 | 
			
		||||
    typedef PhotonR::GaugeField     EmField;
 | 
			
		||||
    typedef PhotonR::GaugeLinkField EmComp;
 | 
			
		||||
    class Result: Serializable
 | 
			
		||||
    {
 | 
			
		||||
    public:
 | 
			
		||||
        class Projection: Serializable
 | 
			
		||||
        {
 | 
			
		||||
        public:
 | 
			
		||||
            GRID_SERIALIZABLE_CLASS_MEMBERS(Projection,
 | 
			
		||||
                                            std::vector<int>,     momentum,
 | 
			
		||||
                                            std::vector<std::vector<std::vector<Complex>>>, pi,
 | 
			
		||||
                                            std::vector<std::vector<std::vector<Complex>>>, pi_free,
 | 
			
		||||
                                            std::vector<std::vector<std::vector<Complex>>>, pi_2E,
 | 
			
		||||
                                            std::vector<std::vector<std::vector<Complex>>>, pi_2T,
 | 
			
		||||
                                            std::vector<std::vector<std::vector<Complex>>>, pi_S,
 | 
			
		||||
                                            std::vector<std::vector<std::vector<Complex>>>, pi_4C,
 | 
			
		||||
                                            std::vector<std::vector<std::vector<Complex>>>, pi_X,
 | 
			
		||||
                                            std::vector<std::vector<std::vector<Complex>>>, pi_srcT,
 | 
			
		||||
                                            std::vector<std::vector<std::vector<Complex>>>, pi_snkT);
 | 
			
		||||
        };
 | 
			
		||||
        GRID_SERIALIZABLE_CLASS_MEMBERS(Result,
 | 
			
		||||
                                        std::vector<int>,        lattice_size,
 | 
			
		||||
                                        double,                  mass,
 | 
			
		||||
                                        double,                  charge,
 | 
			
		||||
                                        std::vector<Projection>, projection);
 | 
			
		||||
    };
 | 
			
		||||
public:
 | 
			
		||||
    // constructor
 | 
			
		||||
    TScalarVP(const std::string name);
 | 
			
		||||
    // destructor
 | 
			
		||||
    virtual ~TScalarVP(void) {};
 | 
			
		||||
    // dependency relation
 | 
			
		||||
    virtual std::vector<std::string> getInput(void);
 | 
			
		||||
    virtual std::vector<std::string> getOutput(void);
 | 
			
		||||
protected:
 | 
			
		||||
    // setup
 | 
			
		||||
    virtual void setup(void);
 | 
			
		||||
    // execution
 | 
			
		||||
    virtual void execute(void);
 | 
			
		||||
private:
 | 
			
		||||
    void makeCaches(void);
 | 
			
		||||
    // conserved vector two-point contraction
 | 
			
		||||
    void vpContraction(ScalarField &vp,
 | 
			
		||||
                       ScalarField &prop_0_x, ScalarField &prop_nu_x,
 | 
			
		||||
                       TComplex u_src, ScalarField &u_snk, int mu);
 | 
			
		||||
    // conserved vector two-point contraction with unit gauge link at sink
 | 
			
		||||
    void vpContraction(ScalarField &vp,
 | 
			
		||||
                       ScalarField &prop_0_x, ScalarField &prop_nu_x,
 | 
			
		||||
                       TComplex u_src, int mu);
 | 
			
		||||
    // write momentum-projected vacuum polarisation to file(s)
 | 
			
		||||
    void project(std::vector<Complex> &projection, const ScalarField &vp,
 | 
			
		||||
                 int i_p);
 | 
			
		||||
    // momentum-space Delta_1 insertion
 | 
			
		||||
    void momD1(ScalarField &s, FFT &fft);
 | 
			
		||||
private:
 | 
			
		||||
    bool                                        momPhasesDone_;
 | 
			
		||||
    std::string                                 freeMomPropName_, GFSrcName_,
 | 
			
		||||
                                                prop0Name_, propQName_,
 | 
			
		||||
                                                propSunName_, propTadName_,
 | 
			
		||||
                                                fftName_;
 | 
			
		||||
    std::vector<std::string>                    phaseName_, muPropQName_,
 | 
			
		||||
                                                momPhaseName_;
 | 
			
		||||
    std::vector<std::vector<std::string> >      vpTensorName_;
 | 
			
		||||
    std::vector<ScalarField *>                  phase_, momPhase_;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
MODULE_REGISTER(ScalarVP, TScalarVP, MScalar);
 | 
			
		||||
 | 
			
		||||
END_MODULE_NAMESPACE
 | 
			
		||||
 | 
			
		||||
END_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
#endif // Hadrons_MScalar_ScalarVP_hpp_
 | 
			
		||||
							
								
								
									
										260
									
								
								Hadrons/Modules/MScalar/VPCounterTerms.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										260
									
								
								Hadrons/Modules/MScalar/VPCounterTerms.cc
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,260 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MScalar/VPCounterTerms.cc
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
Author: Antonin Portelli <antonin.portelli@me.com>
 | 
			
		||||
Author: James Harrison <jch1g10@soton.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 */
 | 
			
		||||
#include <Hadrons/Modules/MScalar/VPCounterTerms.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MScalar/Scalar.hpp>
 | 
			
		||||
 | 
			
		||||
using namespace Grid;
 | 
			
		||||
using namespace Hadrons;
 | 
			
		||||
using namespace MScalar;
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
*                  TVPCounterTerms implementation                             *
 | 
			
		||||
******************************************************************************/
 | 
			
		||||
// constructor /////////////////////////////////////////////////////////////////
 | 
			
		||||
TVPCounterTerms::TVPCounterTerms(const std::string name)
 | 
			
		||||
: Module<VPCounterTermsPar>(name)
 | 
			
		||||
{}
 | 
			
		||||
 | 
			
		||||
// dependencies/products ///////////////////////////////////////////////////////
 | 
			
		||||
std::vector<std::string> TVPCounterTerms::getInput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> in = {par().source};
 | 
			
		||||
    
 | 
			
		||||
    return in;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::vector<std::string> TVPCounterTerms::getOutput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> out;
 | 
			
		||||
    
 | 
			
		||||
    return out;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// setup ///////////////////////////////////////////////////////////////////////
 | 
			
		||||
void TVPCounterTerms::setup(void)
 | 
			
		||||
{
 | 
			
		||||
	freeMomPropName_ = FREEMOMPROP(par().mass);
 | 
			
		||||
    phaseName_.clear();
 | 
			
		||||
    for (unsigned int mu = 0; mu < env().getNd(); ++mu)
 | 
			
		||||
    {
 | 
			
		||||
        phaseName_.push_back("_shiftphase_" + std::to_string(mu));
 | 
			
		||||
    }
 | 
			
		||||
    GFSrcName_ = getName() + "_DinvSrc";
 | 
			
		||||
    phatsqName_ = getName() + "_pHatSquared";
 | 
			
		||||
    prop0Name_ = getName() + "_freeProp";
 | 
			
		||||
    twoscalarName_ = getName() + "_2scalarProp";
 | 
			
		||||
    psquaredName_ = getName() + "_psquaredProp";
 | 
			
		||||
    if (!par().output.empty())
 | 
			
		||||
    {
 | 
			
		||||
        for (unsigned int i_p = 0; i_p < par().outputMom.size(); ++i_p)
 | 
			
		||||
        {
 | 
			
		||||
            momPhaseName_.push_back("_momentumphase_" + std::to_string(i_p));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    envCreateLat(ScalarField, freeMomPropName_);
 | 
			
		||||
    for (unsigned int mu = 0; mu < env().getNd(); ++mu)
 | 
			
		||||
    {
 | 
			
		||||
        envCreateLat(ScalarField, phaseName_[mu]);
 | 
			
		||||
    }
 | 
			
		||||
    envCreateLat(ScalarField, phatsqName_);
 | 
			
		||||
    envCreateLat(ScalarField, GFSrcName_);
 | 
			
		||||
    envCreateLat(ScalarField, prop0Name_);
 | 
			
		||||
    envCreateLat(ScalarField, twoscalarName_);
 | 
			
		||||
    envCreateLat(ScalarField, psquaredName_);
 | 
			
		||||
    if (!par().output.empty())
 | 
			
		||||
    {
 | 
			
		||||
        for (unsigned int i_p = 0; i_p < par().outputMom.size(); ++i_p)
 | 
			
		||||
        {
 | 
			
		||||
            envCacheLat(ScalarField, momPhaseName_[i_p]);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    envTmpLat(ScalarField, "buf");
 | 
			
		||||
    envTmpLat(ScalarField, "tmp_vp");
 | 
			
		||||
    envTmpLat(ScalarField, "vpPhase");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// execution ///////////////////////////////////////////////////////////////////
 | 
			
		||||
void TVPCounterTerms::execute(void)
 | 
			
		||||
{
 | 
			
		||||
	auto &source = envGet(ScalarField, par().source);
 | 
			
		||||
    Complex     ci(0.0,1.0);
 | 
			
		||||
    FFT         fft(env().getGrid());
 | 
			
		||||
    envGetTmp(ScalarField, buf);
 | 
			
		||||
    envGetTmp(ScalarField, tmp_vp);
 | 
			
		||||
    
 | 
			
		||||
    // Momentum-space free scalar propagator
 | 
			
		||||
    auto &G = envGet(ScalarField, freeMomPropName_);
 | 
			
		||||
    SIMPL::MomentumSpacePropagator(G, par().mass);
 | 
			
		||||
 | 
			
		||||
    // Phases and hat{p}^2
 | 
			
		||||
    auto &phatsq = envGet(ScalarField, phatsqName_);
 | 
			
		||||
    std::vector<int> &l = env().getGrid()->_fdimensions;
 | 
			
		||||
    
 | 
			
		||||
    LOG(Message) << "Calculating shift phases..." << std::endl;
 | 
			
		||||
    phatsq = zero;
 | 
			
		||||
    for (unsigned int mu = 0; mu < env().getNd(); ++mu)
 | 
			
		||||
    {
 | 
			
		||||
        Real    twoPiL = M_PI*2./l[mu];
 | 
			
		||||
        auto &phmu  = envGet(ScalarField, phaseName_[mu]);
 | 
			
		||||
 | 
			
		||||
        LatticeCoordinate(buf, mu);
 | 
			
		||||
        phmu = exp(ci*twoPiL*buf);
 | 
			
		||||
        phase_.push_back(&phmu);
 | 
			
		||||
        buf = 2.*sin(.5*twoPiL*buf);
 | 
			
		||||
		phatsq = phatsq + buf*buf;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // G*F*src
 | 
			
		||||
    auto &GFSrc       = envGet(ScalarField, GFSrcName_);
 | 
			
		||||
    fft.FFT_all_dim(GFSrc, source, FFT::forward);
 | 
			
		||||
    GFSrc = G*GFSrc;
 | 
			
		||||
 | 
			
		||||
    // Position-space free scalar propagator
 | 
			
		||||
    auto &prop0       = envGet(ScalarField, prop0Name_);
 | 
			
		||||
    prop0 = GFSrc;
 | 
			
		||||
    fft.FFT_all_dim(prop0, prop0, FFT::backward);
 | 
			
		||||
 | 
			
		||||
    // Propagators for counter-terms
 | 
			
		||||
    auto &twoscalarProp        = envGet(ScalarField, twoscalarName_);
 | 
			
		||||
    auto &psquaredProp         = envGet(ScalarField, psquaredName_);
 | 
			
		||||
 | 
			
		||||
    twoscalarProp = G*GFSrc;
 | 
			
		||||
    fft.FFT_all_dim(twoscalarProp, twoscalarProp, FFT::backward);
 | 
			
		||||
 | 
			
		||||
    psquaredProp = G*phatsq*GFSrc;
 | 
			
		||||
    fft.FFT_all_dim(psquaredProp, psquaredProp, FFT::backward);
 | 
			
		||||
 | 
			
		||||
    // Prepare output data structure if necessary
 | 
			
		||||
    Result outputData;
 | 
			
		||||
    if (!par().output.empty())
 | 
			
		||||
    {
 | 
			
		||||
        outputData.projection.resize(par().outputMom.size());
 | 
			
		||||
        outputData.lattice_size = env().getGrid()->_fdimensions;
 | 
			
		||||
        outputData.mass = par().mass;
 | 
			
		||||
        for (unsigned int i_p = 0; i_p < par().outputMom.size(); ++i_p)
 | 
			
		||||
        {
 | 
			
		||||
            outputData.projection[i_p].momentum = strToVec<int>(par().outputMom[i_p]);
 | 
			
		||||
            outputData.projection[i_p].twoScalar.resize(env().getNd());
 | 
			
		||||
            outputData.projection[i_p].threeScalar.resize(env().getNd());
 | 
			
		||||
            outputData.projection[i_p].pSquaredInsertion.resize(env().getNd());
 | 
			
		||||
            for (unsigned int nu = 0; nu < env().getNd(); ++nu)
 | 
			
		||||
            {
 | 
			
		||||
                outputData.projection[i_p].twoScalar[nu].resize(env().getNd());
 | 
			
		||||
                outputData.projection[i_p].threeScalar[nu].resize(env().getNd());
 | 
			
		||||
                outputData.projection[i_p].pSquaredInsertion[nu].resize(env().getNd());
 | 
			
		||||
            }
 | 
			
		||||
            // Calculate phase factors
 | 
			
		||||
            auto &momph_ip = envGet(ScalarField, momPhaseName_[i_p]);
 | 
			
		||||
            momph_ip = zero;
 | 
			
		||||
            for (unsigned int j = 0; j < env().getNd()-1; ++j)
 | 
			
		||||
            {
 | 
			
		||||
                Real twoPiL = M_PI*2./l[j];
 | 
			
		||||
                LatticeCoordinate(buf, j);
 | 
			
		||||
                buf = outputData.projection[i_p].momentum[j]*twoPiL*buf;
 | 
			
		||||
                momph_ip = momph_ip + buf;
 | 
			
		||||
            }
 | 
			
		||||
            momph_ip = exp(-ci*momph_ip);
 | 
			
		||||
            momPhase_.push_back(&momph_ip);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Contractions
 | 
			
		||||
    for (unsigned int nu = 0; nu < env().getNd(); ++nu)
 | 
			
		||||
    {
 | 
			
		||||
    	buf = adj(Cshift(prop0, nu, -1));
 | 
			
		||||
        for (unsigned int mu = 0; mu < env().getNd(); ++mu)
 | 
			
		||||
        {
 | 
			
		||||
            // Two-scalar loop
 | 
			
		||||
            tmp_vp = buf * Cshift(prop0, mu, 1);
 | 
			
		||||
            tmp_vp -= Cshift(buf, mu, 1) * prop0;
 | 
			
		||||
            tmp_vp = 2.0*real(tmp_vp);
 | 
			
		||||
            // Output if necessary
 | 
			
		||||
            if (!par().output.empty())
 | 
			
		||||
            {
 | 
			
		||||
                for (unsigned int i_p = 0; i_p < par().outputMom.size(); ++i_p)
 | 
			
		||||
                {
 | 
			
		||||
                    project(outputData.projection[i_p].twoScalar[mu][nu],
 | 
			
		||||
                            tmp_vp, i_p);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
        	// Three-scalar loop (no vertex)
 | 
			
		||||
    		tmp_vp = buf * Cshift(twoscalarProp, mu, 1);
 | 
			
		||||
            tmp_vp -= Cshift(buf, mu, 1) * twoscalarProp;
 | 
			
		||||
            tmp_vp = 2.0*real(tmp_vp);
 | 
			
		||||
            // Output if necessary
 | 
			
		||||
            if (!par().output.empty())
 | 
			
		||||
            {
 | 
			
		||||
                for (unsigned int i_p = 0; i_p < par().outputMom.size(); ++i_p)
 | 
			
		||||
                {
 | 
			
		||||
                    project(outputData.projection[i_p].threeScalar[mu][nu],
 | 
			
		||||
                            tmp_vp, i_p);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // Three-scalar loop (hat{p}^2 insertion)
 | 
			
		||||
    		tmp_vp = buf * Cshift(psquaredProp, mu, 1);
 | 
			
		||||
            tmp_vp -= Cshift(buf, mu, 1) * psquaredProp;
 | 
			
		||||
            tmp_vp = 2.0*real(tmp_vp);
 | 
			
		||||
            // Output if necessary
 | 
			
		||||
            if (!par().output.empty())
 | 
			
		||||
            {
 | 
			
		||||
                for (unsigned int i_p = 0; i_p < par().outputMom.size(); ++i_p)
 | 
			
		||||
                {
 | 
			
		||||
                    project(outputData.projection[i_p].pSquaredInsertion[mu][nu],
 | 
			
		||||
                            tmp_vp, i_p);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // OUTPUT IF NECESSARY
 | 
			
		||||
    if (!par().output.empty())
 | 
			
		||||
    {
 | 
			
		||||
        LOG(Message) << "Saving momentum-projected correlators to '"
 | 
			
		||||
                     << RESULT_FILE_NAME(par().output) << "'..."
 | 
			
		||||
                     << std::endl;
 | 
			
		||||
        saveResult(par().output, "scalar_loops", outputData);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TVPCounterTerms::project(std::vector<Complex> &projection, const ScalarField &vp, int i_p)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<TComplex>   vecBuf;
 | 
			
		||||
    envGetTmp(ScalarField, vpPhase);
 | 
			
		||||
 | 
			
		||||
    vpPhase = vp*(*momPhase_[i_p]);
 | 
			
		||||
    sliceSum(vpPhase, vecBuf, Tp);
 | 
			
		||||
    projection.resize(vecBuf.size());
 | 
			
		||||
    for (unsigned int t = 0; t < vecBuf.size(); ++t)
 | 
			
		||||
    {
 | 
			
		||||
        projection[t] = TensorRemove(vecBuf[t]);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										103
									
								
								Hadrons/Modules/MScalar/VPCounterTerms.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										103
									
								
								Hadrons/Modules/MScalar/VPCounterTerms.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,103 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MScalar/VPCounterTerms.hpp
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
Author: Antonin Portelli <antonin.portelli@me.com>
 | 
			
		||||
Author: James Harrison <jch1g10@soton.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 */
 | 
			
		||||
#ifndef Hadrons_MScalar_VPCounterTerms_hpp_
 | 
			
		||||
#define Hadrons_MScalar_VPCounterTerms_hpp_
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Global.hpp>
 | 
			
		||||
#include <Hadrons/Module.hpp>
 | 
			
		||||
#include <Hadrons/ModuleFactory.hpp>
 | 
			
		||||
 | 
			
		||||
BEGIN_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                         VPCounterTerms                                 *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
BEGIN_MODULE_NAMESPACE(MScalar)
 | 
			
		||||
 | 
			
		||||
class VPCounterTermsPar: Serializable
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    GRID_SERIALIZABLE_CLASS_MEMBERS(VPCounterTermsPar,
 | 
			
		||||
                                    std::string, source,
 | 
			
		||||
                                    double,      mass,
 | 
			
		||||
                                    std::string, output,
 | 
			
		||||
                                    std::vector<std::string>, outputMom);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class TVPCounterTerms: public Module<VPCounterTermsPar>
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    SCALAR_TYPE_ALIASES(SIMPL,);
 | 
			
		||||
    class Result: Serializable
 | 
			
		||||
    {
 | 
			
		||||
    public:
 | 
			
		||||
        class Projection: Serializable
 | 
			
		||||
        {
 | 
			
		||||
        public:
 | 
			
		||||
            GRID_SERIALIZABLE_CLASS_MEMBERS(Projection,
 | 
			
		||||
                                            std::vector<int>,     momentum,
 | 
			
		||||
                                            std::vector<std::vector<std::vector<Complex>>>, twoScalar,
 | 
			
		||||
                                            std::vector<std::vector<std::vector<Complex>>>, threeScalar,
 | 
			
		||||
                                            std::vector<std::vector<std::vector<Complex>>>, pSquaredInsertion);
 | 
			
		||||
        };
 | 
			
		||||
        GRID_SERIALIZABLE_CLASS_MEMBERS(Result,
 | 
			
		||||
                                        std::vector<int>,        lattice_size,
 | 
			
		||||
                                        double,                  mass,
 | 
			
		||||
                                        std::vector<Projection>, projection);
 | 
			
		||||
    };
 | 
			
		||||
public:
 | 
			
		||||
    // constructor
 | 
			
		||||
    TVPCounterTerms(const std::string name);
 | 
			
		||||
    // destructor
 | 
			
		||||
    virtual ~TVPCounterTerms(void) {};
 | 
			
		||||
    // dependency relation
 | 
			
		||||
    virtual std::vector<std::string> getInput(void);
 | 
			
		||||
    virtual std::vector<std::string> getOutput(void);
 | 
			
		||||
protected:
 | 
			
		||||
    // setup
 | 
			
		||||
    virtual void setup(void);
 | 
			
		||||
    // execution
 | 
			
		||||
    virtual void execute(void);
 | 
			
		||||
private:
 | 
			
		||||
    void project(std::vector<Complex> &projection, const ScalarField &vp, int i_p);
 | 
			
		||||
private:
 | 
			
		||||
    std::string                freeMomPropName_, GFSrcName_, phatsqName_, prop0Name_,
 | 
			
		||||
                               twoscalarName_, twoscalarVertexName_,
 | 
			
		||||
                               psquaredName_, psquaredVertexName_;
 | 
			
		||||
    std::vector<std::string>   phaseName_, momPhaseName_;
 | 
			
		||||
    std::vector<ScalarField *> phase_, momPhase_;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
MODULE_REGISTER(VPCounterTerms, TVPCounterTerms, MScalar);
 | 
			
		||||
 | 
			
		||||
END_MODULE_NAMESPACE
 | 
			
		||||
 | 
			
		||||
END_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
#endif // Hadrons_MScalar_VPCounterTerms_hpp_
 | 
			
		||||
							
								
								
									
										39
									
								
								Hadrons/Modules/MScalarSUN/Div.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								Hadrons/Modules/MScalarSUN/Div.cc
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,39 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MScalarSUN/Div.cc
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
#include <Hadrons/Modules/MScalarSUN/Div.hpp>
 | 
			
		||||
 | 
			
		||||
using namespace Grid;
 | 
			
		||||
using namespace Hadrons;
 | 
			
		||||
using namespace MScalarSUN;
 | 
			
		||||
 | 
			
		||||
template class Grid::Hadrons::MScalarSUN::TDiv<ScalarNxNAdjImplR<2>>;
 | 
			
		||||
template class Grid::Hadrons::MScalarSUN::TDiv<ScalarNxNAdjImplR<3>>;
 | 
			
		||||
template class Grid::Hadrons::MScalarSUN::TDiv<ScalarNxNAdjImplR<4>>;
 | 
			
		||||
template class Grid::Hadrons::MScalarSUN::TDiv<ScalarNxNAdjImplR<5>>;
 | 
			
		||||
template class Grid::Hadrons::MScalarSUN::TDiv<ScalarNxNAdjImplR<6>>;
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										155
									
								
								Hadrons/Modules/MScalarSUN/Div.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										155
									
								
								Hadrons/Modules/MScalarSUN/Div.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,155 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MScalarSUN/Div.hpp
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
#ifndef Hadrons_MScalarSUN_Div_hpp_
 | 
			
		||||
#define Hadrons_MScalarSUN_Div_hpp_
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Global.hpp>
 | 
			
		||||
#include <Hadrons/Module.hpp>
 | 
			
		||||
#include <Hadrons/ModuleFactory.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MScalarSUN/Utils.hpp>
 | 
			
		||||
 | 
			
		||||
BEGIN_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                       Divergence of a vector field                         *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
BEGIN_MODULE_NAMESPACE(MScalarSUN)
 | 
			
		||||
 | 
			
		||||
class DivPar: Serializable
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    GRID_SERIALIZABLE_CLASS_MEMBERS(DivPar,
 | 
			
		||||
                                    std::vector<std::string>, op,
 | 
			
		||||
                                    DiffType,                 type,
 | 
			
		||||
                                    std::string,              output);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class DivResult: Serializable
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    GRID_SERIALIZABLE_CLASS_MEMBERS(DivResult,
 | 
			
		||||
                                    DiffType, type,
 | 
			
		||||
                                    Complex,  value);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
template <typename SImpl>
 | 
			
		||||
class TDiv: public Module<DivPar>
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    typedef typename SImpl::Field        Field;
 | 
			
		||||
    typedef typename SImpl::ComplexField ComplexField;
 | 
			
		||||
public:
 | 
			
		||||
    // constructor
 | 
			
		||||
    TDiv(const std::string name);
 | 
			
		||||
    // destructor
 | 
			
		||||
    virtual ~TDiv(void) {};
 | 
			
		||||
    // dependency relation
 | 
			
		||||
    virtual std::vector<std::string> getInput(void);
 | 
			
		||||
    virtual std::vector<std::string> getOutput(void);
 | 
			
		||||
    // setup
 | 
			
		||||
    virtual void setup(void);
 | 
			
		||||
    // execution
 | 
			
		||||
    virtual void execute(void);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
MODULE_REGISTER_TMP(DivSU2, TDiv<ScalarNxNAdjImplR<2>>, MScalarSUN);
 | 
			
		||||
MODULE_REGISTER_TMP(DivSU3, TDiv<ScalarNxNAdjImplR<3>>, MScalarSUN);
 | 
			
		||||
MODULE_REGISTER_TMP(DivSU4, TDiv<ScalarNxNAdjImplR<4>>, MScalarSUN);
 | 
			
		||||
MODULE_REGISTER_TMP(DivSU5, TDiv<ScalarNxNAdjImplR<5>>, MScalarSUN);
 | 
			
		||||
MODULE_REGISTER_TMP(DivSU6, TDiv<ScalarNxNAdjImplR<6>>, MScalarSUN);
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                           TDiv implementation                              *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
// constructor /////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename SImpl>
 | 
			
		||||
TDiv<SImpl>::TDiv(const std::string name)
 | 
			
		||||
: Module<DivPar>(name)
 | 
			
		||||
{}
 | 
			
		||||
 | 
			
		||||
// dependencies/products ///////////////////////////////////////////////////////
 | 
			
		||||
template <typename SImpl>
 | 
			
		||||
std::vector<std::string> TDiv<SImpl>::getInput(void)
 | 
			
		||||
{
 | 
			
		||||
    return par().op;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename SImpl>
 | 
			
		||||
std::vector<std::string> TDiv<SImpl>::getOutput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> out = {getName()};
 | 
			
		||||
 | 
			
		||||
    return out;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// setup ///////////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename SImpl>
 | 
			
		||||
void TDiv<SImpl>::setup(void)
 | 
			
		||||
{
 | 
			
		||||
    if (par().op.size() != env().getNd())
 | 
			
		||||
    {
 | 
			
		||||
        HADRONS_ERROR(Size, "the number of components differs from number of dimensions");
 | 
			
		||||
    }
 | 
			
		||||
    envCreateLat(ComplexField, getName());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// execution ///////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename SImpl>
 | 
			
		||||
void TDiv<SImpl>::execute(void)
 | 
			
		||||
{
 | 
			
		||||
    const auto nd = env().getNd();
 | 
			
		||||
 | 
			
		||||
    LOG(Message) << "Computing the " << par().type << " divergence of [";
 | 
			
		||||
    for (unsigned int mu = 0; mu < nd; ++mu)
 | 
			
		||||
    {
 | 
			
		||||
        std::cout << "'" << par().op[mu] << ((mu == nd - 1) ? "']" : "', ");
 | 
			
		||||
    }
 | 
			
		||||
    std::cout << std::endl;
 | 
			
		||||
 | 
			
		||||
    auto &div = envGet(ComplexField, getName());
 | 
			
		||||
    div = zero;
 | 
			
		||||
    for (unsigned int mu = 0; mu < nd; ++mu)
 | 
			
		||||
    {
 | 
			
		||||
        auto &op = envGet(ComplexField, par().op[mu]);
 | 
			
		||||
        dmuAcc(div, op, mu, par().type);
 | 
			
		||||
    }
 | 
			
		||||
    if (!par().output.empty())
 | 
			
		||||
    {
 | 
			
		||||
        DivResult r;
 | 
			
		||||
 | 
			
		||||
        r.type  = par().type;
 | 
			
		||||
        r.value = TensorRemove(sum(div));
 | 
			
		||||
        saveResult(par().output, "div", r);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
END_MODULE_NAMESPACE
 | 
			
		||||
 | 
			
		||||
END_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
#endif // Hadrons_MScalarSUN_Div_hpp_
 | 
			
		||||
							
								
								
									
										39
									
								
								Hadrons/Modules/MScalarSUN/EMT.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								Hadrons/Modules/MScalarSUN/EMT.cc
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,39 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MScalarSUN/EMT.cc
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
#include <Hadrons/Modules/MScalarSUN/EMT.hpp>
 | 
			
		||||
 | 
			
		||||
using namespace Grid;
 | 
			
		||||
using namespace Hadrons;
 | 
			
		||||
using namespace MScalarSUN;
 | 
			
		||||
 | 
			
		||||
template class Grid::Hadrons::MScalarSUN::TEMT<ScalarNxNAdjImplR<2>>;
 | 
			
		||||
template class Grid::Hadrons::MScalarSUN::TEMT<ScalarNxNAdjImplR<3>>;
 | 
			
		||||
template class Grid::Hadrons::MScalarSUN::TEMT<ScalarNxNAdjImplR<4>>;
 | 
			
		||||
template class Grid::Hadrons::MScalarSUN::TEMT<ScalarNxNAdjImplR<5>>;
 | 
			
		||||
template class Grid::Hadrons::MScalarSUN::TEMT<ScalarNxNAdjImplR<6>>;
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										217
									
								
								Hadrons/Modules/MScalarSUN/EMT.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										217
									
								
								Hadrons/Modules/MScalarSUN/EMT.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,217 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MScalarSUN/EMT.hpp
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
#ifndef Hadrons_MScalarSUN_EMT_hpp_
 | 
			
		||||
#define Hadrons_MScalarSUN_EMT_hpp_
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Global.hpp>
 | 
			
		||||
#include <Hadrons/Module.hpp>
 | 
			
		||||
#include <Hadrons/ModuleFactory.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MScalarSUN/Utils.hpp>
 | 
			
		||||
 | 
			
		||||
BEGIN_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                         Energy-momentum tensor                             *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
BEGIN_MODULE_NAMESPACE(MScalarSUN)
 | 
			
		||||
 | 
			
		||||
class EMTPar: Serializable
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    GRID_SERIALIZABLE_CLASS_MEMBERS(EMTPar,
 | 
			
		||||
                                    std::string, kinetic,
 | 
			
		||||
                                    std::string, phiPow,
 | 
			
		||||
                                    std::string, improvement,
 | 
			
		||||
                                    double     , m2,
 | 
			
		||||
                                    double     , lambda,
 | 
			
		||||
                                    double     , g,
 | 
			
		||||
                                    double     , xi,
 | 
			
		||||
                                    std::string, output);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class EMTResult: Serializable
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    GRID_SERIALIZABLE_CLASS_MEMBERS(EMTResult,
 | 
			
		||||
                                    std::vector<std::vector<Complex>>, value,
 | 
			
		||||
                                    double,                            m2,
 | 
			
		||||
                                    double,                            lambda,
 | 
			
		||||
                                    double,                            g,
 | 
			
		||||
                                    double,                            xi);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
template <typename SImpl>
 | 
			
		||||
class TEMT: public Module<EMTPar>
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    typedef typename SImpl::Field        Field;
 | 
			
		||||
    typedef typename SImpl::ComplexField ComplexField;
 | 
			
		||||
public:
 | 
			
		||||
    // constructor
 | 
			
		||||
    TEMT(const std::string name);
 | 
			
		||||
    // destructor
 | 
			
		||||
    virtual ~TEMT(void) {};
 | 
			
		||||
    // dependency relation
 | 
			
		||||
    virtual std::vector<std::string> getInput(void);
 | 
			
		||||
    virtual std::vector<std::string> getOutput(void);
 | 
			
		||||
    // setup
 | 
			
		||||
    virtual void setup(void);
 | 
			
		||||
    // execution
 | 
			
		||||
    virtual void execute(void);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
MODULE_REGISTER_TMP(EMTSU2, TEMT<ScalarNxNAdjImplR<2>>, MScalarSUN);
 | 
			
		||||
MODULE_REGISTER_TMP(EMTSU3, TEMT<ScalarNxNAdjImplR<3>>, MScalarSUN);
 | 
			
		||||
MODULE_REGISTER_TMP(EMTSU4, TEMT<ScalarNxNAdjImplR<4>>, MScalarSUN);
 | 
			
		||||
MODULE_REGISTER_TMP(EMTSU5, TEMT<ScalarNxNAdjImplR<5>>, MScalarSUN);
 | 
			
		||||
MODULE_REGISTER_TMP(EMTSU6, TEMT<ScalarNxNAdjImplR<6>>, MScalarSUN);
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                           TEMT implementation                              *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
// constructor /////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename SImpl>
 | 
			
		||||
TEMT<SImpl>::TEMT(const std::string name)
 | 
			
		||||
: Module<EMTPar>(name)
 | 
			
		||||
{}
 | 
			
		||||
 | 
			
		||||
// dependencies/products ///////////////////////////////////////////////////////
 | 
			
		||||
template <typename SImpl>
 | 
			
		||||
std::vector<std::string> TEMT<SImpl>::getInput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> in;
 | 
			
		||||
    
 | 
			
		||||
    for (unsigned int mu = 0; mu < env().getNd(); ++mu)
 | 
			
		||||
    for (unsigned int nu = mu; nu < env().getNd(); ++nu)
 | 
			
		||||
    {
 | 
			
		||||
        in.push_back(varName(par().kinetic, mu, nu));
 | 
			
		||||
        if (!par().improvement.empty())
 | 
			
		||||
        {
 | 
			
		||||
            in.push_back(varName(par().improvement, mu, nu));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    in.push_back(varName(par().kinetic, "sum"));
 | 
			
		||||
    in.push_back(varName(par().phiPow, 2));
 | 
			
		||||
    in.push_back(varName(par().phiPow, 4));
 | 
			
		||||
 | 
			
		||||
    return in;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename SImpl>
 | 
			
		||||
std::vector<std::string> TEMT<SImpl>::getOutput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> out;
 | 
			
		||||
    
 | 
			
		||||
    for (unsigned int mu = 0; mu < env().getNd(); ++mu)
 | 
			
		||||
    for (unsigned int nu = mu; nu < env().getNd(); ++nu)
 | 
			
		||||
    {
 | 
			
		||||
        out.push_back(varName(getName(), mu, nu));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return out;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// setup ///////////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename SImpl>
 | 
			
		||||
void TEMT<SImpl>::setup(void)
 | 
			
		||||
{
 | 
			
		||||
    for (unsigned int mu = 0; mu < env().getNd(); ++mu)
 | 
			
		||||
    for (unsigned int nu = mu; nu < env().getNd(); ++nu)
 | 
			
		||||
    {
 | 
			
		||||
        envCreateLat(ComplexField, varName(getName(), mu, nu));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// execution ///////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename SImpl>
 | 
			
		||||
void TEMT<SImpl>::execute(void)
 | 
			
		||||
{
 | 
			
		||||
    LOG(Message) << "Computing energy-momentum tensor" << std::endl;
 | 
			
		||||
    LOG(Message) << "  kinetic terms: '" << par().kinetic << "'" << std::endl;
 | 
			
		||||
    LOG(Message) << "      tr(phi^n): '" << par().phiPow << "'" << std::endl;
 | 
			
		||||
    if (!par().improvement.empty())
 | 
			
		||||
    {
 | 
			
		||||
        LOG(Message) << "    improvement: '" << par().improvement << "'" << std::endl;
 | 
			
		||||
    }
 | 
			
		||||
    LOG(Message) << "            m^2= " << par().m2 << std::endl;
 | 
			
		||||
    LOG(Message) << "         lambda= " << par().lambda << std::endl;
 | 
			
		||||
    LOG(Message) << "              g= " << par().g << std::endl;
 | 
			
		||||
    if (!par().improvement.empty())
 | 
			
		||||
    {
 | 
			
		||||
        LOG(Message) << "             xi= " << par().xi << std::endl;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    const unsigned int N = SImpl::Group::Dimension, nd = env().getNd();
 | 
			
		||||
    auto               &trphi2 = envGet(ComplexField, varName(par().phiPow, 2));
 | 
			
		||||
    auto               &trphi4 = envGet(ComplexField, varName(par().phiPow, 4));
 | 
			
		||||
    auto               &sumkin = envGet(ComplexField, varName(par().kinetic, "sum"));
 | 
			
		||||
    EMTResult          result;
 | 
			
		||||
 | 
			
		||||
    if (!par().output.empty())
 | 
			
		||||
    {
 | 
			
		||||
        result.m2     = par().m2;
 | 
			
		||||
        result.g      = par().g;
 | 
			
		||||
        result.lambda = par().lambda;
 | 
			
		||||
        result.xi     = par().xi;
 | 
			
		||||
        result.value.resize(nd, std::vector<Complex>(nd));
 | 
			
		||||
    }
 | 
			
		||||
    for (unsigned int mu = 0; mu < nd; ++mu)
 | 
			
		||||
    for (unsigned int nu = mu; nu < nd; ++nu)
 | 
			
		||||
    {
 | 
			
		||||
        auto &out   = envGet(ComplexField, varName(getName(), mu, nu));
 | 
			
		||||
        auto &trkin = envGet(ComplexField, varName(par().kinetic, mu, nu));
 | 
			
		||||
        
 | 
			
		||||
        out = 2.*trkin;
 | 
			
		||||
        if (!par().improvement.empty())
 | 
			
		||||
        {
 | 
			
		||||
            auto &imp = envGet(ComplexField, varName(par().improvement, mu, nu));
 | 
			
		||||
 | 
			
		||||
            out += par().xi*imp;
 | 
			
		||||
        }
 | 
			
		||||
        if (mu == nu)
 | 
			
		||||
        {
 | 
			
		||||
            out -= sumkin + par().m2*trphi2 + par().lambda*trphi4;
 | 
			
		||||
        }
 | 
			
		||||
        out *= N/par().g;
 | 
			
		||||
        if (!par().output.empty())
 | 
			
		||||
        {
 | 
			
		||||
            result.value[mu][nu] = TensorRemove(sum(out));
 | 
			
		||||
            result.value[mu][nu] = result.value[nu][mu];
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    if (!par().output.empty())
 | 
			
		||||
    {
 | 
			
		||||
        saveResult(par().output, "emt", result);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
END_MODULE_NAMESPACE
 | 
			
		||||
 | 
			
		||||
END_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
#endif // Hadrons_MScalarSUN_EMT_hpp_
 | 
			
		||||
							
								
								
									
										38
									
								
								Hadrons/Modules/MScalarSUN/Grad.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								Hadrons/Modules/MScalarSUN/Grad.cc
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,38 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MScalarSUN/Grad.cc
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
#include <Hadrons/Modules/MScalarSUN/Grad.hpp>
 | 
			
		||||
 | 
			
		||||
using namespace Grid;
 | 
			
		||||
using namespace Hadrons;
 | 
			
		||||
using namespace MScalarSUN;
 | 
			
		||||
 | 
			
		||||
template class Grid::Hadrons::MScalarSUN::TGrad<ScalarNxNAdjImplR<2>>;
 | 
			
		||||
template class Grid::Hadrons::MScalarSUN::TGrad<ScalarNxNAdjImplR<3>>;
 | 
			
		||||
template class Grid::Hadrons::MScalarSUN::TGrad<ScalarNxNAdjImplR<4>>;
 | 
			
		||||
template class Grid::Hadrons::MScalarSUN::TGrad<ScalarNxNAdjImplR<5>>;
 | 
			
		||||
template class Grid::Hadrons::MScalarSUN::TGrad<ScalarNxNAdjImplR<6>>;
 | 
			
		||||
							
								
								
									
										166
									
								
								Hadrons/Modules/MScalarSUN/Grad.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										166
									
								
								Hadrons/Modules/MScalarSUN/Grad.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,166 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MScalarSUN/Grad.hpp
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
#ifndef Hadrons_MScalarSUN_Grad_hpp_
 | 
			
		||||
#define Hadrons_MScalarSUN_Grad_hpp_
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Global.hpp>
 | 
			
		||||
#include <Hadrons/Module.hpp>
 | 
			
		||||
#include <Hadrons/ModuleFactory.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MScalarSUN/Utils.hpp>
 | 
			
		||||
 | 
			
		||||
BEGIN_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                       Gradient of a complex field                          *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
BEGIN_MODULE_NAMESPACE(MScalarSUN)
 | 
			
		||||
 | 
			
		||||
class GradPar: Serializable
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    GRID_SERIALIZABLE_CLASS_MEMBERS(GradPar,
 | 
			
		||||
                                    std::string, op,
 | 
			
		||||
                                    DiffType,    type,
 | 
			
		||||
                                    std::string, output);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class GradResult: Serializable
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    GRID_SERIALIZABLE_CLASS_MEMBERS(GradResult,
 | 
			
		||||
                                    DiffType,              type,
 | 
			
		||||
                                    std::vector<Complex>,  value);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
template <typename SImpl>
 | 
			
		||||
class TGrad: public Module<GradPar>
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    typedef typename SImpl::Field        Field;
 | 
			
		||||
    typedef typename SImpl::ComplexField ComplexField;
 | 
			
		||||
public:
 | 
			
		||||
    // constructor
 | 
			
		||||
    TGrad(const std::string name);
 | 
			
		||||
    // destructor
 | 
			
		||||
    virtual ~TGrad(void) {};
 | 
			
		||||
    // dependency relation
 | 
			
		||||
    virtual std::vector<std::string> getInput(void);
 | 
			
		||||
    virtual std::vector<std::string> getOutput(void);
 | 
			
		||||
    // setup
 | 
			
		||||
    virtual void setup(void);
 | 
			
		||||
    // execution
 | 
			
		||||
    virtual void execute(void);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
MODULE_REGISTER_TMP(GradSU2, TGrad<ScalarNxNAdjImplR<2>>, MScalarSUN);
 | 
			
		||||
MODULE_REGISTER_TMP(GradSU3, TGrad<ScalarNxNAdjImplR<3>>, MScalarSUN);
 | 
			
		||||
MODULE_REGISTER_TMP(GradSU4, TGrad<ScalarNxNAdjImplR<4>>, MScalarSUN);
 | 
			
		||||
MODULE_REGISTER_TMP(GradSU5, TGrad<ScalarNxNAdjImplR<5>>, MScalarSUN);
 | 
			
		||||
MODULE_REGISTER_TMP(GradSU6, TGrad<ScalarNxNAdjImplR<6>>, MScalarSUN);
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                         TGrad implementation                               *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
// constructor /////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename SImpl>
 | 
			
		||||
TGrad<SImpl>::TGrad(const std::string name)
 | 
			
		||||
: Module<GradPar>(name)
 | 
			
		||||
{}
 | 
			
		||||
 | 
			
		||||
// dependencies/products ///////////////////////////////////////////////////////
 | 
			
		||||
template <typename SImpl>
 | 
			
		||||
std::vector<std::string> TGrad<SImpl>::getInput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> in = {par().op};
 | 
			
		||||
    
 | 
			
		||||
    return in;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename SImpl>
 | 
			
		||||
std::vector<std::string> TGrad<SImpl>::getOutput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> out;
 | 
			
		||||
    const auto               nd = env().getNd();
 | 
			
		||||
 | 
			
		||||
    for (unsigned int mu = 0; mu < nd; ++mu)
 | 
			
		||||
    {
 | 
			
		||||
        out.push_back(varName(getName(), mu));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return out;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// setup ///////////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename SImpl>
 | 
			
		||||
void TGrad<SImpl>::setup(void)
 | 
			
		||||
{
 | 
			
		||||
    const auto nd = env().getNd();
 | 
			
		||||
 | 
			
		||||
    for (unsigned int mu = 0; mu < nd; ++mu)
 | 
			
		||||
    {
 | 
			
		||||
        envCreateLat(ComplexField, varName(getName(), mu));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// execution ///////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename SImpl>
 | 
			
		||||
void TGrad<SImpl>::execute(void)
 | 
			
		||||
{
 | 
			
		||||
    LOG(Message) << "Computing the " << par().type << " gradient of '"
 | 
			
		||||
                 << par().op << "'" << std::endl;
 | 
			
		||||
 | 
			
		||||
    const unsigned int nd = env().getNd();
 | 
			
		||||
    GradResult         result;
 | 
			
		||||
    auto               &op = envGet(ComplexField, par().op);
 | 
			
		||||
 | 
			
		||||
    if (!par().output.empty())
 | 
			
		||||
    {
 | 
			
		||||
        result.type = par().type;
 | 
			
		||||
        result.value.resize(nd);
 | 
			
		||||
    }
 | 
			
		||||
    for (unsigned int mu = 0; mu < nd; ++mu)
 | 
			
		||||
    {
 | 
			
		||||
        auto &der = envGet(ComplexField, varName(getName(), mu));
 | 
			
		||||
 | 
			
		||||
        dmu(der, op, mu, par().type);
 | 
			
		||||
        if (!par().output.empty())
 | 
			
		||||
        {
 | 
			
		||||
            result.value[mu] = TensorRemove(sum(der));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    if (!par().output.empty())
 | 
			
		||||
    {
 | 
			
		||||
        saveResult(par().output, "grad", result);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
END_MODULE_NAMESPACE
 | 
			
		||||
 | 
			
		||||
END_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
#endif // Hadrons_MScalarSUN_Grad_hpp_
 | 
			
		||||
							
								
								
									
										39
									
								
								Hadrons/Modules/MScalarSUN/ShiftProbe.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								Hadrons/Modules/MScalarSUN/ShiftProbe.cc
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,39 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MScalarSUN/ShiftProbe.cc
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
#include <Hadrons/Modules/MScalarSUN/ShiftProbe.hpp>
 | 
			
		||||
 | 
			
		||||
using namespace Grid;
 | 
			
		||||
using namespace Hadrons;
 | 
			
		||||
using namespace MScalarSUN;
 | 
			
		||||
 | 
			
		||||
template class Grid::Hadrons::MScalarSUN::TShiftProbe<ScalarNxNAdjImplR<2>>;
 | 
			
		||||
template class Grid::Hadrons::MScalarSUN::TShiftProbe<ScalarNxNAdjImplR<3>>;
 | 
			
		||||
template class Grid::Hadrons::MScalarSUN::TShiftProbe<ScalarNxNAdjImplR<4>>;
 | 
			
		||||
template class Grid::Hadrons::MScalarSUN::TShiftProbe<ScalarNxNAdjImplR<5>>;
 | 
			
		||||
template class Grid::Hadrons::MScalarSUN::TShiftProbe<ScalarNxNAdjImplR<6>>;
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										177
									
								
								Hadrons/Modules/MScalarSUN/ShiftProbe.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										177
									
								
								Hadrons/Modules/MScalarSUN/ShiftProbe.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,177 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MScalarSUN/ShiftProbe.hpp
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
#ifndef Hadrons_MScalarSUN_ShiftProbe_hpp_
 | 
			
		||||
#define Hadrons_MScalarSUN_ShiftProbe_hpp_
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Global.hpp>
 | 
			
		||||
#include <Hadrons/Module.hpp>
 | 
			
		||||
#include <Hadrons/ModuleFactory.hpp>
 | 
			
		||||
#include <Hadrons/Modules/MScalarSUN/Utils.hpp>
 | 
			
		||||
 | 
			
		||||
BEGIN_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *         Ward identity phi^n probe with fields at different positions       *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
BEGIN_MODULE_NAMESPACE(MScalarSUN)
 | 
			
		||||
 | 
			
		||||
typedef std::pair<int, int> ShiftPair;
 | 
			
		||||
 | 
			
		||||
class ShiftProbePar: Serializable
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    GRID_SERIALIZABLE_CLASS_MEMBERS(ShiftProbePar,
 | 
			
		||||
                                    std::string, field,
 | 
			
		||||
                                    std::string, shifts,
 | 
			
		||||
                                    std::string, output);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class ShiftProbeResult: Serializable
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    GRID_SERIALIZABLE_CLASS_MEMBERS(ShiftProbeResult,
 | 
			
		||||
                                    std::string, shifts,
 | 
			
		||||
                                    Complex,     value);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
template <typename SImpl>
 | 
			
		||||
class TShiftProbe: public Module<ShiftProbePar>
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    typedef typename SImpl::Field                          Field;
 | 
			
		||||
    typedef typename SImpl::ComplexField                   ComplexField;
 | 
			
		||||
public:
 | 
			
		||||
    // constructor
 | 
			
		||||
    TShiftProbe(const std::string name);
 | 
			
		||||
    // destructor
 | 
			
		||||
    virtual ~TShiftProbe(void) {};
 | 
			
		||||
    // dependency relation
 | 
			
		||||
    virtual std::vector<std::string> getInput(void);
 | 
			
		||||
    virtual std::vector<std::string> getOutput(void);
 | 
			
		||||
    // setup
 | 
			
		||||
    virtual void setup(void);
 | 
			
		||||
    // execution
 | 
			
		||||
    virtual void execute(void);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
MODULE_REGISTER_TMP(ShiftProbeSU2, TShiftProbe<ScalarNxNAdjImplR<2>>, MScalarSUN);
 | 
			
		||||
MODULE_REGISTER_TMP(ShiftProbeSU3, TShiftProbe<ScalarNxNAdjImplR<3>>, MScalarSUN);
 | 
			
		||||
MODULE_REGISTER_TMP(ShiftProbeSU4, TShiftProbe<ScalarNxNAdjImplR<4>>, MScalarSUN);
 | 
			
		||||
MODULE_REGISTER_TMP(ShiftProbeSU5, TShiftProbe<ScalarNxNAdjImplR<5>>, MScalarSUN);
 | 
			
		||||
MODULE_REGISTER_TMP(ShiftProbeSU6, TShiftProbe<ScalarNxNAdjImplR<6>>, MScalarSUN);
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                        TShiftProbe implementation                          *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
// constructor /////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename SImpl>
 | 
			
		||||
TShiftProbe<SImpl>::TShiftProbe(const std::string name)
 | 
			
		||||
: Module<ShiftProbePar>(name)
 | 
			
		||||
{}
 | 
			
		||||
 | 
			
		||||
// dependencies/products ///////////////////////////////////////////////////////
 | 
			
		||||
template <typename SImpl>
 | 
			
		||||
std::vector<std::string> TShiftProbe<SImpl>::getInput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> in = {par().field};
 | 
			
		||||
    
 | 
			
		||||
    return in;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename SImpl>
 | 
			
		||||
std::vector<std::string> TShiftProbe<SImpl>::getOutput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> out = {getName()};
 | 
			
		||||
    
 | 
			
		||||
    return out;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// setup ///////////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename SImpl>
 | 
			
		||||
void TShiftProbe<SImpl>::setup(void)
 | 
			
		||||
{
 | 
			
		||||
    envTmpLat(Field, "acc");
 | 
			
		||||
    envCreateLat(ComplexField, getName());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// execution ///////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename SImpl>
 | 
			
		||||
void TShiftProbe<SImpl>::execute(void)
 | 
			
		||||
{
 | 
			
		||||
    LOG(Message) << "Creating shift probe for shifts " << par().shifts
 | 
			
		||||
                 << std::endl;
 | 
			
		||||
 | 
			
		||||
    std::vector<ShiftPair> shift;
 | 
			
		||||
    double                 sign;
 | 
			
		||||
    auto                   &phi   = envGet(Field, par().field);
 | 
			
		||||
    auto                   &probe = envGet(ComplexField, getName());
 | 
			
		||||
 | 
			
		||||
    shift = strToVec<ShiftPair>(par().shifts);
 | 
			
		||||
    if (shift.size() % 2 != 0)
 | 
			
		||||
    {
 | 
			
		||||
        HADRONS_ERROR(Size, "the number of shifts is odd");
 | 
			
		||||
    }
 | 
			
		||||
    sign = (shift.size() % 4 == 0) ? 1. : -1.;
 | 
			
		||||
    for (auto &s: shift)
 | 
			
		||||
    {
 | 
			
		||||
        if (s.first >= env().getNd())
 | 
			
		||||
        {
 | 
			
		||||
            HADRONS_ERROR(Size, "dimension to large for shift <" 
 | 
			
		||||
                               + std::to_string(s.first) + " " 
 | 
			
		||||
                               + std::to_string(s.second) + ">" );
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    envGetTmp(Field, acc);
 | 
			
		||||
    acc = 1.;
 | 
			
		||||
    for (unsigned int i = 0; i < shift.size(); ++i)
 | 
			
		||||
    {
 | 
			
		||||
        if (shift[i].second == 0)
 | 
			
		||||
        {
 | 
			
		||||
            acc *= phi;
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            acc *= Cshift(phi, shift[i].first, shift[i].second);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    probe = sign*trace(acc);
 | 
			
		||||
    if (!par().output.empty())
 | 
			
		||||
    {
 | 
			
		||||
        ShiftProbeResult r;
 | 
			
		||||
 | 
			
		||||
        r.shifts = par().shifts;
 | 
			
		||||
        r.value  = TensorRemove(sum(probe));
 | 
			
		||||
        saveResult(par().output, "probe", r);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
END_MODULE_NAMESPACE
 | 
			
		||||
 | 
			
		||||
END_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
#endif // Hadrons_MScalarSUN_ShiftProbe_hpp_
 | 
			
		||||
							
								
								
									
										38
									
								
								Hadrons/Modules/MScalarSUN/StochFreeField.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								Hadrons/Modules/MScalarSUN/StochFreeField.cc
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,38 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MScalarSUN/StochFreeField.cc
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
#include <Hadrons/Modules/MScalarSUN/StochFreeField.hpp>
 | 
			
		||||
 | 
			
		||||
using namespace Grid;
 | 
			
		||||
using namespace Hadrons;
 | 
			
		||||
using namespace MScalarSUN;
 | 
			
		||||
 | 
			
		||||
template class Grid::Hadrons::MScalarSUN::TStochFreeField<ScalarNxNAdjImplR<2>>;
 | 
			
		||||
template class Grid::Hadrons::MScalarSUN::TStochFreeField<ScalarNxNAdjImplR<3>>;
 | 
			
		||||
template class Grid::Hadrons::MScalarSUN::TStochFreeField<ScalarNxNAdjImplR<4>>;
 | 
			
		||||
template class Grid::Hadrons::MScalarSUN::TStochFreeField<ScalarNxNAdjImplR<5>>;
 | 
			
		||||
template class Grid::Hadrons::MScalarSUN::TStochFreeField<ScalarNxNAdjImplR<6>>;
 | 
			
		||||
							
								
								
									
										178
									
								
								Hadrons/Modules/MScalarSUN/StochFreeField.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										178
									
								
								Hadrons/Modules/MScalarSUN/StochFreeField.hpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,178 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MScalarSUN/StochFreeField.hpp
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
#ifndef Hadrons_MScalarSUN_StochFreeField_hpp_
 | 
			
		||||
#define Hadrons_MScalarSUN_StochFreeField_hpp_
 | 
			
		||||
 | 
			
		||||
#include <Hadrons/Global.hpp>
 | 
			
		||||
#include <Hadrons/Module.hpp>
 | 
			
		||||
#include <Hadrons/ModuleFactory.hpp>
 | 
			
		||||
 | 
			
		||||
BEGIN_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                      stochastic free SU(N) scalar field                    *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
BEGIN_MODULE_NAMESPACE(MScalarSUN)
 | 
			
		||||
 | 
			
		||||
class StochFreeFieldPar: Serializable
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    GRID_SERIALIZABLE_CLASS_MEMBERS(StochFreeFieldPar,
 | 
			
		||||
                                    double, m2,
 | 
			
		||||
                                    double, g);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
template <typename SImpl>
 | 
			
		||||
class TStochFreeField: public Module<StochFreeFieldPar>
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    typedef typename SImpl::Field                    Field;
 | 
			
		||||
    typedef typename SImpl::ComplexField             ComplexField;
 | 
			
		||||
    typedef typename SImpl::Group                    Group;
 | 
			
		||||
    typedef typename SImpl::SiteField::scalar_object Site;
 | 
			
		||||
public:
 | 
			
		||||
    // constructor
 | 
			
		||||
    TStochFreeField(const std::string name);
 | 
			
		||||
    // destructor
 | 
			
		||||
    virtual ~TStochFreeField(void) {};
 | 
			
		||||
    // dependency relation
 | 
			
		||||
    virtual std::vector<std::string> getInput(void);
 | 
			
		||||
    virtual std::vector<std::string> getOutput(void);
 | 
			
		||||
    // setup
 | 
			
		||||
    virtual void setup(void);
 | 
			
		||||
    // execution
 | 
			
		||||
    virtual void execute(void);
 | 
			
		||||
private:
 | 
			
		||||
    bool create_weight;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
MODULE_REGISTER_TMP(StochFreeFieldSU2, TStochFreeField<ScalarNxNAdjImplR<2>>, MScalarSUN);
 | 
			
		||||
MODULE_REGISTER_TMP(StochFreeFieldSU3, TStochFreeField<ScalarNxNAdjImplR<3>>, MScalarSUN);
 | 
			
		||||
MODULE_REGISTER_TMP(StochFreeFieldSU4, TStochFreeField<ScalarNxNAdjImplR<4>>, MScalarSUN);
 | 
			
		||||
MODULE_REGISTER_TMP(StochFreeFieldSU5, TStochFreeField<ScalarNxNAdjImplR<5>>, MScalarSUN);
 | 
			
		||||
MODULE_REGISTER_TMP(StochFreeFieldSU6, TStochFreeField<ScalarNxNAdjImplR<6>>, MScalarSUN);
 | 
			
		||||
 | 
			
		||||
/******************************************************************************
 | 
			
		||||
 *                 TStochFreeField implementation                             *
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
// constructor /////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename SImpl>
 | 
			
		||||
TStochFreeField<SImpl>::TStochFreeField(const std::string name)
 | 
			
		||||
: Module<StochFreeFieldPar>(name)
 | 
			
		||||
{}
 | 
			
		||||
 | 
			
		||||
// dependencies/products ///////////////////////////////////////////////////////
 | 
			
		||||
template <typename SImpl>
 | 
			
		||||
std::vector<std::string> TStochFreeField<SImpl>::getInput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> in;
 | 
			
		||||
    
 | 
			
		||||
    return in;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename SImpl>
 | 
			
		||||
std::vector<std::string> TStochFreeField<SImpl>::getOutput(void)
 | 
			
		||||
{
 | 
			
		||||
    std::vector<std::string> out = {getName()};
 | 
			
		||||
    
 | 
			
		||||
    return out;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// setup ///////////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename SImpl>
 | 
			
		||||
void TStochFreeField<SImpl>::setup(void)
 | 
			
		||||
{
 | 
			
		||||
    create_weight = false; 
 | 
			
		||||
    if (!env().hasCreatedObject("_" + getName() + "_weight"))
 | 
			
		||||
    {
 | 
			
		||||
        envCacheLat(ComplexField, "_" + getName() + "_weight");
 | 
			
		||||
        create_weight = true;
 | 
			
		||||
    }
 | 
			
		||||
    envTmpLat(Field, "phift");
 | 
			
		||||
    envTmpLat(ComplexField, "ca");
 | 
			
		||||
    envCreateLat(Field, getName());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// execution ///////////////////////////////////////////////////////////////////
 | 
			
		||||
template <typename SImpl>
 | 
			
		||||
void TStochFreeField<SImpl>::execute(void)
 | 
			
		||||
{
 | 
			
		||||
    LOG(Message) << "Generating stochastic scalar field" << std::endl;
 | 
			
		||||
    
 | 
			
		||||
    const   unsigned int N    = Group::Dimension;
 | 
			
		||||
    const   unsigned int Nadj = Group::AdjointDimension;
 | 
			
		||||
    auto    &phi              = envGet(Field, getName());
 | 
			
		||||
    auto    &w                = envGet(ComplexField, "_" + getName() + "_weight");
 | 
			
		||||
    auto    &rng              = rng4d();
 | 
			
		||||
    double  trphi2;
 | 
			
		||||
    FFT     fft(env().getGrid());
 | 
			
		||||
    Integer vol;
 | 
			
		||||
 | 
			
		||||
    vol = 1;
 | 
			
		||||
    for(int d = 0; d < env().getNd(); d++)
 | 
			
		||||
    {
 | 
			
		||||
        vol = vol*env().getDim(d);
 | 
			
		||||
    }
 | 
			
		||||
    if (create_weight)
 | 
			
		||||
    {
 | 
			
		||||
        LOG(Message) << "Caching momentum-space scalar action" << std::endl;
 | 
			
		||||
        
 | 
			
		||||
        SImpl::MomentumSpacePropagator(w, sqrt(par().m2));
 | 
			
		||||
        w *= par().g/N;
 | 
			
		||||
        w  = sqrt(vol)*sqrt(w);
 | 
			
		||||
    }
 | 
			
		||||
    LOG(Message) << "Generating random momentum-space field" << std::endl;
 | 
			
		||||
    envGetTmp(Field, phift);
 | 
			
		||||
    envGetTmp(ComplexField, ca);
 | 
			
		||||
    phift = zero;
 | 
			
		||||
    for (int a = 0; a < Nadj; ++a) 
 | 
			
		||||
    {
 | 
			
		||||
        Site ta;
 | 
			
		||||
 | 
			
		||||
        gaussian(rng, ca);
 | 
			
		||||
        Group::generator(a, ta);
 | 
			
		||||
        phift += ca*ta;
 | 
			
		||||
    }
 | 
			
		||||
    phift *= w;
 | 
			
		||||
    LOG(Message) << "Field Fourier transform" << std::endl;
 | 
			
		||||
    fft.FFT_all_dim(phi, phift, FFT::backward);
 | 
			
		||||
    phi = 0.5*(phi - adj(phi));
 | 
			
		||||
    trphi2 = -TensorRemove(sum(trace(phi*phi))).real()/vol;
 | 
			
		||||
    LOG(Message) << "tr(phi^2)= " << trphi2 << std::endl;
 | 
			
		||||
 | 
			
		||||
    // ComplexField phi2(env().getGrid());
 | 
			
		||||
 | 
			
		||||
    // phi2=trace(phi*phi);
 | 
			
		||||
    // std::cout << phi2 << std::endl;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
END_MODULE_NAMESPACE
 | 
			
		||||
 | 
			
		||||
END_HADRONS_NAMESPACE
 | 
			
		||||
 | 
			
		||||
#endif // Hadrons_MScalarSUN_StochFreeField_hpp_
 | 
			
		||||
							
								
								
									
										38
									
								
								Hadrons/Modules/MScalarSUN/TimeMomProbe.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								Hadrons/Modules/MScalarSUN/TimeMomProbe.cc
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,38 @@
 | 
			
		||||
/*************************************************************************************
 | 
			
		||||
 | 
			
		||||
Grid physics library, www.github.com/paboyle/Grid 
 | 
			
		||||
 | 
			
		||||
Source file: extras/Hadrons/Modules/MScalarSUN/TimeMomProbe.cc
 | 
			
		||||
 | 
			
		||||
Copyright (C) 2015-2018
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
*************************************************************************************/
 | 
			
		||||
/*  END LEGAL */
 | 
			
		||||
#include <Hadrons/Modules/MScalarSUN/TimeMomProbe.hpp>
 | 
			
		||||
 | 
			
		||||
using namespace Grid;
 | 
			
		||||
using namespace Hadrons;
 | 
			
		||||
using namespace MScalarSUN;
 | 
			
		||||
 | 
			
		||||
template class Grid::Hadrons::MScalarSUN::TTimeMomProbe<ScalarNxNAdjImplR<2>>;
 | 
			
		||||
template class Grid::Hadrons::MScalarSUN::TTimeMomProbe<ScalarNxNAdjImplR<3>>;
 | 
			
		||||
template class Grid::Hadrons::MScalarSUN::TTimeMomProbe<ScalarNxNAdjImplR<4>>;
 | 
			
		||||
template class Grid::Hadrons::MScalarSUN::TTimeMomProbe<ScalarNxNAdjImplR<5>>;
 | 
			
		||||
template class Grid::Hadrons::MScalarSUN::TTimeMomProbe<ScalarNxNAdjImplR<6>>;
 | 
			
		||||
Some files were not shown because too many files have changed in this diff Show More
		Reference in New Issue
	
	Block a user