/************************************************************************************* Grid physics library, www.github.com/paboyle/Grid Source file: ./tests/forces/ForceTest.h Copyright (C) 2022 Author: Peter Boyle 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 */ #pragma once ///////////////////////////////////////////////////////////////////////////////////////////// // Finite-difference check of an action's force: refresh, S1 = S(U), step the links by eps // along a random momentum P, take the force at the midpoint, step again, S2 = S(U''). // The force predicts S2 - S1 to O(eps^3). // // Runs on a copy of U, so the caller's field is unchanged. Returns S2 - S1 - dSpred for // the caller to assert on; halving eps should reduce it by about 8. ///////////////////////////////////////////////////////////////////////////////////////////// template RealD ForceTest(Action &action,LatticeGaugeField & Uin,MomentumFilterBase &Filter,RealD eps=0.005) { GridBase *UGrid = Uin.Grid(); std::vector seeds({1,2,3,5}); GridSerialRNG sRNG; sRNG.SeedFixedIntegers(seeds); GridParallelRNG RNG4(UGrid); RNG4.SeedFixedIntegers(seeds); LatticeColourMatrix Pmu(UGrid); LatticeGaugeField P(UGrid); LatticeGaugeField UdSdU(UGrid); LatticeGaugeField U(UGrid); U = Uin; std::cout << GridLogMessage << "*********************************************************"<(UdSdU,mu); Pmu= PeekIndex(P,mu); dS = dS - trace(Pmu*UdSdUmu)*eps*2.0*2.0; } ComplexD dSpred = sum(dS); RealD diff = S2-S1-dSpred.real(); std::cout<< GridLogMessage << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++"< RealD ForceTestScaling(Action &action,LatticeGaugeField &U,MomentumFilterBase &Filter,const std::string &name, RealD eps0=0.01,int neps=4) { std::vector eps(neps); std::vector d(neps); for(int i=0;i(action,U,Filter,eps[i]); } for(int i=0;i 0 ) { std::cout << " ratio to previous " << d[i-1]/d[i]; } std::cout << std::endl; } RealD scale = d[neps-2]/d[neps-1]; std::cout << GridLogMessage << name << ": smallest-eps ratio " << scale << " (expect ~8)" << std::endl; return scale; }