From a741e7b9baf09cf450c28df074aa670202eb7e1f Mon Sep 17 00:00:00 2001 From: Guido Cossu Date: Wed, 2 May 2018 11:05:47 +0100 Subject: [PATCH] Added ExpScalar observable --- lib/qcd/QCD.h | 2 +- lib/qcd/modules/ObservableModules.h | 14 +++++ lib/qcd/observables/exp_scalar.h | 80 ++++++++++++++++++++++++++++ lib/qcd/observables/hmc_observable.h | 2 +- lib/version.h | 1 + tests/hmc/Test_hmc_shGordonAction.cc | 6 +++ 6 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 lib/qcd/observables/exp_scalar.h create mode 100644 lib/version.h diff --git a/lib/qcd/QCD.h b/lib/qcd/QCD.h index e1e38e82..16f82af1 100644 --- a/lib/qcd/QCD.h +++ b/lib/qcd/QCD.h @@ -51,7 +51,7 @@ namespace QCD { static const int Nc=3; static const int Ns=4; - static const int Nd=4; + static const int Nd=2; static const int Nhs=2; // half spinor static const int Nds=8; // double stored gauge field static const int Ngp=2; // gparity index range diff --git a/lib/qcd/modules/ObservableModules.h b/lib/qcd/modules/ObservableModules.h index fbffc236..3a092e72 100644 --- a/lib/qcd/modules/ObservableModules.h +++ b/lib/qcd/modules/ObservableModules.h @@ -92,6 +92,20 @@ class PlaquetteMod: public ObservableModule, NoParameters> PlaquetteMod(): ObsBase(NoParameters()){} }; +template < class Impl > +class ExpScalarMod: public ObservableModule, ExpScalarParameters>{ + typedef ObservableModule, ExpScalarParameters> ObsBase; + using ObsBase::ObsBase; // for constructors + + // acquire resource + virtual void initialize(){ + this->ObservablePtr.reset(new ExpScalarLogger(this->Par_)); + } + public: + ExpScalarMod(ExpScalarParameters P): ObsBase(P){} + ExpScalarMod():ObsBase(){}; +}; + template < class Impl > class PolyakovMod: public ObservableModule, NoParameters>{ typedef ObservableModule, NoParameters> ObsBase; diff --git a/lib/qcd/observables/exp_scalar.h b/lib/qcd/observables/exp_scalar.h new file mode 100644 index 00000000..cc41d563 --- /dev/null +++ b/lib/qcd/observables/exp_scalar.h @@ -0,0 +1,80 @@ +/************************************************************************************* + +Grid physics library, www.github.com/paboyle/Grid + +Source file: ./lib/qcd/modules/exp_scalar.h + +Copyright (C) 2018 + +Author: Guido Cossu + +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 HMC_EXP_SCALAR_H +#define HMC_EXP_SCALAR_H + +namespace Grid { +namespace QCD { + +struct ExpScalarParameters : Serializable { + GRID_SERIALIZABLE_CLASS_MEMBERS(ExpScalarParameters, + double, a) + + ExpScalarParameters(double _a = 0.0):a(_a){} + + template < class ReaderClass > + ExpScalarParameters(Reader& Reader){ + read(Reader, "ExpScalar", *this); + } +}; + +template +class ExpScalarLogger : public HmcObservable { + ExpScalarParameters Pars; + public: + + // necessary for HmcObservable compatibility + typedef typename Impl::Field Field; + + ExpScalarLogger(double _a):Pars(_a){} + + ExpScalarLogger(ExpScalarParameters P):Pars(P){} + + void TrajectoryComplete(int traj, typename Impl::Field &U, + GridSerialRNG &sRNG, + GridParallelRNG &pRNG) { + + double e = sum(trace(exp(Pars.a*U))); + + int def_prec = std::cout.precision(); + + std::cout << GridLogMessage + << std::setprecision(std::numeric_limits::digits10 + 1) + << "ExpScalar: [ " << traj << " ] "<< e << std::endl; + + std::cout.precision(def_prec); + + } +}; + +} // namespace QCD +} // namespace Grid + +#endif // HMC_PLAQUETTE_H diff --git a/lib/qcd/observables/hmc_observable.h b/lib/qcd/observables/hmc_observable.h index fcf11774..222e0ff1 100644 --- a/lib/qcd/observables/hmc_observable.h +++ b/lib/qcd/observables/hmc_observable.h @@ -46,6 +46,6 @@ class HmcObservable { #include "plaquette.h" #include "topological_charge.h" #include "polyakov_loop.h" - +#include "exp_scalar.h" #endif // HMC_OBSERVABLE_H diff --git a/lib/version.h b/lib/version.h new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/lib/version.h @@ -0,0 +1 @@ + diff --git a/tests/hmc/Test_hmc_shGordonAction.cc b/tests/hmc/Test_hmc_shGordonAction.cc index ada82c1f..7cbb758e 100644 --- a/tests/hmc/Test_hmc_shGordonAction.cc +++ b/tests/hmc/Test_hmc_shGordonAction.cc @@ -91,6 +91,12 @@ int main(int argc, char **argv) { RNGModuleParameters RNGpar(Reader); TheHMC.Resources.SetRNGSeeds(RNGpar); + // Some online observable measurements + typedef ExpScalarMod ExpObs; + ExpScalarParameters ExpParams(Reader); + TheHMC.Resources.AddObservable(ExpParams); + /////////////////////////////////////////// + // Real Scalar sh-Gordon action ScalarActionParameters SPar(Reader); shGordonActionR Saction(SPar.mass_squared, SPar.g);