mirror of
				https://github.com/paboyle/Grid.git
				synced 2025-11-04 14:04:32 +00:00 
			
		
		
		
	Hadrons: added tests for 3pt contractions.
This commit is contained in:
		@@ -269,6 +269,26 @@ inline void makeConservedSequentialSource(Application &application,
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*******************************************************************************
 | 
			
		||||
 * Name: makeNoiseSource
 | 
			
		||||
 * Parameters: application - main application that stores modules.
 | 
			
		||||
 *             srcName     - name of source module to create.
 | 
			
		||||
 *             tA          - lower source timeslice limit.
 | 
			
		||||
 *             tB          - upper source timeslice limit.
 | 
			
		||||
 * Returns: None.
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
inline void makeNoiseSource(Application &application, std::string &srcName,
 | 
			
		||||
                            unsigned int tA, unsigned int tB)
 | 
			
		||||
{
 | 
			
		||||
    if (!(Environment::getInstance().hasModule(srcName)))
 | 
			
		||||
    {
 | 
			
		||||
        MSource::Z2::Par noisePar;
 | 
			
		||||
        noisePar.tA = tA;
 | 
			
		||||
        noisePar.tB = tB;
 | 
			
		||||
        application.createModule<MSource::Z2>(srcName, noisePar);
 | 
			
		||||
    }
 | 
			
		||||
 }
 | 
			
		||||
 | 
			
		||||
/*******************************************************************************
 | 
			
		||||
 * Name: makeWallSource
 | 
			
		||||
 * Purpose: Construct wall source and add to application module.
 | 
			
		||||
@@ -292,26 +312,46 @@ inline void makeWallSource(Application &application, std::string &srcName,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*******************************************************************************
 | 
			
		||||
 * Name: makeWallSink
 | 
			
		||||
 * Purpose: Wall sink smearing of a propagator.
 | 
			
		||||
 * Name: makePointSink
 | 
			
		||||
 * Purpose: Create function for point sink smearing of a propagator.
 | 
			
		||||
 * Parameters: application - main application that stores modules.
 | 
			
		||||
 *             propName    - name of input propagator.
 | 
			
		||||
 *             wallName    - name of smeared propagator.
 | 
			
		||||
 *             sinkFnct    - name of output sink smearing module.
 | 
			
		||||
 *             mom         - momentum insertion (default is zero).
 | 
			
		||||
 * Returns: None.
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
inline void makeWallSink(Application &application, std::string &propName,
 | 
			
		||||
                         std::string &wallName, std::string mom = ZERO_MOM)
 | 
			
		||||
inline void makePointSink(Application &application, std::string &sinkFnct,
 | 
			
		||||
                          std::string mom = ZERO_MOM)
 | 
			
		||||
{
 | 
			
		||||
    // If the sink function already exists, don't make it again.
 | 
			
		||||
    if (!(Environment::getInstance().hasModule(sinkFnct)))
 | 
			
		||||
    {
 | 
			
		||||
        MSink::Point::Par pointPar;
 | 
			
		||||
        pointPar.mom = mom;
 | 
			
		||||
        application.createModule<MSink::Point>(sinkFnct, pointPar);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*******************************************************************************
 | 
			
		||||
 * Name: sinkSmear
 | 
			
		||||
 * Purpose: Perform sink smearing of a propagator.
 | 
			
		||||
 * Parameters: application - main application that stores modules.
 | 
			
		||||
 *             sinkFnct    - sink smearing module.
 | 
			
		||||
 *             propName    - propagator to smear.
 | 
			
		||||
 *             smearedProp - name of output smeared propagator.
 | 
			
		||||
 * Returns: None.
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
inline void sinkSmear(Application &application, std::string &sinkFnct,
 | 
			
		||||
                      std::string &propName, std::string &smearedProp)
 | 
			
		||||
{
 | 
			
		||||
    // If the propagator has already been smeared, don't smear it again.
 | 
			
		||||
    // Temporarily removed, strategy for sink smearing likely to change.
 | 
			
		||||
    /*if (!(Environment::getInstance().hasModule(wallName)))
 | 
			
		||||
    if (!(Environment::getInstance().hasModule(smearedProp)))
 | 
			
		||||
    {
 | 
			
		||||
        MSink::Wall::Par wallPar;
 | 
			
		||||
        wallPar.q   = propName;
 | 
			
		||||
        wallPar.mom = mom;
 | 
			
		||||
        application.createModule<MSink::Wall>(wallName, wallPar);
 | 
			
		||||
    }*/
 | 
			
		||||
        MSink::Smear::Par smearPar;
 | 
			
		||||
        smearPar.q    = propName;
 | 
			
		||||
        smearPar.sink = sinkFnct;
 | 
			
		||||
        application.createModule<MSink::Smear>(smearedProp, smearPar);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*******************************************************************************
 | 
			
		||||
@@ -398,16 +438,18 @@ inline void mesonContraction(Application &application,
 | 
			
		||||
 * Purpose: Create gamma3pt contraction module and add to application module.
 | 
			
		||||
 * Parameters: application - main application that stores modules.
 | 
			
		||||
 *             npt         - specify n-point correlator (for labelling).
 | 
			
		||||
 *             q1          - quark propagator 1.
 | 
			
		||||
 *             q1          - quark propagator 1, sink smeared.
 | 
			
		||||
 *             q2          - quark propagator 2.
 | 
			
		||||
 *             q3          - quark propagator 3.
 | 
			
		||||
 *             label       - unique label to construct module name.
 | 
			
		||||
 *             tSnk        - sink position of sink for q1.
 | 
			
		||||
 *             gamma       - gamma insertions between q2 and q3.
 | 
			
		||||
 * Returns: None.
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
inline void gamma3ptContraction(Application &application, unsigned int npt, 
 | 
			
		||||
                                std::string &q1, std::string &q2,
 | 
			
		||||
                                std::string &q3, std::string &label,
 | 
			
		||||
                                unsigned int tSnk = 0,
 | 
			
		||||
                                Gamma::Algebra gamma = Gamma::Algebra::Identity)
 | 
			
		||||
{
 | 
			
		||||
    std::string modName = std::to_string(npt) + "pt_" + label;
 | 
			
		||||
@@ -418,6 +460,7 @@ inline void gamma3ptContraction(Application &application, unsigned int npt,
 | 
			
		||||
        gamma3ptPar.q1 = q1;
 | 
			
		||||
        gamma3ptPar.q2 = q2;
 | 
			
		||||
        gamma3ptPar.q3 = q3;
 | 
			
		||||
        gamma3ptPar.tSnk = tSnk;
 | 
			
		||||
        gamma3ptPar.gamma = gamma;
 | 
			
		||||
        application.createModule<MContraction::Gamma3pt>(modName, gamma3ptPar);
 | 
			
		||||
    }
 | 
			
		||||
@@ -434,13 +477,14 @@ inline void gamma3ptContraction(Application &application, unsigned int npt,
 | 
			
		||||
 *             q3          - quark propagator 3.
 | 
			
		||||
 *             q4          - quark propagator 4.
 | 
			
		||||
 *             label       - unique label to construct module name.
 | 
			
		||||
 *             tSnk        - time position of sink (for sink smearing).
 | 
			
		||||
 * Returns: None.
 | 
			
		||||
 ******************************************************************************/
 | 
			
		||||
#define HW_CONTRACTION(top) \
 | 
			
		||||
inline void weakContraction##top(Application &application, unsigned int npt,\
 | 
			
		||||
                                 std::string &q1, std::string &q2, \
 | 
			
		||||
                                 std::string &q3, std::string &q4, \
 | 
			
		||||
                                 std::string &label)\
 | 
			
		||||
                                 std::string &label, unsigned int tSnk = 0)\
 | 
			
		||||
{\
 | 
			
		||||
    std::string modName = std::to_string(npt) + "pt_" + label;\
 | 
			
		||||
    if (!(Environment::getInstance().hasModule(modName)))\
 | 
			
		||||
@@ -451,6 +495,7 @@ inline void weakContraction##top(Application &application, unsigned int npt,\
 | 
			
		||||
        weakPar.q2 = q2;\
 | 
			
		||||
        weakPar.q3 = q3;\
 | 
			
		||||
        weakPar.q4 = q4;\
 | 
			
		||||
        weakPar.tSnk = tSnk;\
 | 
			
		||||
        application.createModule<MContraction::WeakHamiltonian##top>(modName, weakPar);\
 | 
			
		||||
    }\
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										122
									
								
								tests/hadrons/Test_hadrons_3pt_contractions.cc
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										122
									
								
								tests/hadrons/Test_hadrons_3pt_contractions.cc
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,122 @@
 | 
			
		||||
/*******************************************************************************
 | 
			
		||||
 Grid physics library, www.github.com/paboyle/Grid
 | 
			
		||||
 
 | 
			
		||||
 Source file: tests/hadrons/Test_hadrons_3pt_contractions.cc
 | 
			
		||||
 
 | 
			
		||||
 Copyright (C) 2017
 | 
			
		||||
 
 | 
			
		||||
 Author: Andrew Lawson <andrew.lawson1991@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.
 | 
			
		||||
 *******************************************************************************/
 | 
			
		||||
 | 
			
		||||
#include "Test_hadrons.hpp"
 | 
			
		||||
 | 
			
		||||
using namespace Grid;
 | 
			
		||||
using namespace Hadrons;
 | 
			
		||||
 | 
			
		||||
int main(int argc, char *argv[])
 | 
			
		||||
{
 | 
			
		||||
    // initialization //////////////////////////////////////////////////////////
 | 
			
		||||
    HADRONS_DEFAULT_INIT;
 | 
			
		||||
 | 
			
		||||
    // run setup ///////////////////////////////////////////////////////////////
 | 
			
		||||
    Application  application;
 | 
			
		||||
    double       mass = 0.04;
 | 
			
		||||
    double       M5   = 1.8;
 | 
			
		||||
    unsigned int Ls   = 12;
 | 
			
		||||
    unsigned int nt   = GridDefaultLatt()[Tp];
 | 
			
		||||
    unsigned int t_i  = 0;
 | 
			
		||||
    unsigned int t_f  = nt / 2;
 | 
			
		||||
    std::string  mom  = "1. 0. 0. 0.";
 | 
			
		||||
 | 
			
		||||
    // global parameters
 | 
			
		||||
    HADRONS_DEFAULT_GLOBALS(application);
 | 
			
		||||
 | 
			
		||||
    // gauge field
 | 
			
		||||
    std::string gaugeField = "gauge";
 | 
			
		||||
    application.createModule<MGauge::Unit>(gaugeField);
 | 
			
		||||
 | 
			
		||||
    // Action & solver setup.
 | 
			
		||||
    std::string action = "DWF";
 | 
			
		||||
    std::string solver = "CG";
 | 
			
		||||
    makeDWFAction(application, action, gaugeField, mass, M5, Ls);
 | 
			
		||||
    makeRBPrecCGSolver(application, solver, action);
 | 
			
		||||
 | 
			
		||||
    /***************************************************************************
 | 
			
		||||
     * Weak Contraction test: Non-Eye class.
 | 
			
		||||
     **************************************************************************/
 | 
			
		||||
    // Make wall source propagators for each leg of 4-quark vertex.
 | 
			
		||||
    std::string q_i_0 = "q_i_0";
 | 
			
		||||
    std::string q_i_p = "q_i_p";
 | 
			
		||||
    std::string q_f_0 = "q_f_0";
 | 
			
		||||
    std::string q_f_p = "q_f_p";
 | 
			
		||||
    MAKE_WALL_PROP(t_i, q_i_0, solver);
 | 
			
		||||
    MAKE_WALL_PROP(t_f, q_f_0, solver);
 | 
			
		||||
    MAKE_3MOM_WALL_PROP(t_i, mom, q_i_p, solver);
 | 
			
		||||
    MAKE_3MOM_WALL_PROP(t_f, mom, q_f_p, solver);
 | 
			
		||||
 | 
			
		||||
    // Perform contractions, zero and non-zero momentum.
 | 
			
		||||
    std::string HW_CW_0 = LABEL_3PT("HW_CW_0", t_i, t_f);
 | 
			
		||||
    std::string HW_CW_p = LABEL_3PT("HW_CW_p", t_i, t_f);
 | 
			
		||||
    weakContractionNonEye(application, 3, q_i_0, q_i_0, q_f_0, q_f_0, HW_CW_0);
 | 
			
		||||
    weakContractionNonEye(application, 3, q_i_0, q_i_p, q_f_p, q_f_0, HW_CW_p);
 | 
			
		||||
 | 
			
		||||
    /***************************************************************************
 | 
			
		||||
     * Weak Contraction test: Eye-class.
 | 
			
		||||
     **************************************************************************/
 | 
			
		||||
    // Create random propagator for loop.
 | 
			
		||||
    std::string eta = "noise_source";
 | 
			
		||||
    makeNoiseSource(application, eta, 0, nt - 1);
 | 
			
		||||
    std::string loopProp = "loop";
 | 
			
		||||
    std::string loopRes  = loopProp + "_res";
 | 
			
		||||
    makePropagator(application, loopRes, eta, solver);
 | 
			
		||||
    makeLoop(application, loopProp, eta, loopRes);
 | 
			
		||||
 | 
			
		||||
    // Wall sink smear the propagator directly connecting the source & sink.
 | 
			
		||||
    // (i.e. make point sink but smear before the contraction)
 | 
			
		||||
    std::string wallSink = "wall_sink";
 | 
			
		||||
    std::string qWall    = "q_wall";
 | 
			
		||||
    makePointSink(application, wallSink);
 | 
			
		||||
    sinkSmear(application, wallSink, q_i_0, qWall);
 | 
			
		||||
 | 
			
		||||
    // Perform contractions, zero and non-zero momentum.
 | 
			
		||||
    std::string HW_SE_0 = LABEL_3PT("HW_SE_0", t_i, t_f);
 | 
			
		||||
    std::string HW_SE_p = LABEL_3PT("HW_SE_p", t_i, t_f);
 | 
			
		||||
    weakContractionEye(application, 3, qWall, q_i_0, q_f_p, loopProp, HW_SE_0, t_f);
 | 
			
		||||
    weakContractionEye(application, 3, qWall, q_i_p, q_f_p, loopProp, HW_SE_p, t_f);
 | 
			
		||||
 | 
			
		||||
    /***************************************************************************
 | 
			
		||||
     * Gamma insertion test.
 | 
			
		||||
     **************************************************************************/
 | 
			
		||||
    Gamma::Algebra gamma = Gamma::Algebra::GammaT;
 | 
			
		||||
    std::string sd_0 = LABEL_3PT("sd_0", t_i, t_f);
 | 
			
		||||
    std::string sd_p = LABEL_3PT("sd_p", t_i, t_f);
 | 
			
		||||
    gamma3ptContraction(application, 3, qWall, q_i_0, q_f_0, sd_0, t_f, gamma);
 | 
			
		||||
    gamma3ptContraction(application, 3, qWall, q_i_p, q_f_p, sd_p, t_f, gamma);
 | 
			
		||||
 | 
			
		||||
    // execution
 | 
			
		||||
    application.saveParameterFile("ContractionTest3pt.xml");
 | 
			
		||||
    application.run();
 | 
			
		||||
 | 
			
		||||
    // epilogue
 | 
			
		||||
    LOG(Message) << "Grid is finalizing now" << std::endl;
 | 
			
		||||
    Grid_finalize();
 | 
			
		||||
 | 
			
		||||
    return EXIT_SUCCESS;
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user