From 94a2a645bd67bff1cc9ec9ed9927b5136e8c9b63 Mon Sep 17 00:00:00 2001 From: Peter Boyle Date: Tue, 11 May 2021 13:54:15 -0400 Subject: [PATCH] Dirichlet BC wrapper for any Fermion Operator --- .../action/fermion/DirichletFermionOperator.h | 171 ++++++++++++++++++ 1 file changed, 171 insertions(+) create mode 100644 Grid/qcd/action/fermion/DirichletFermionOperator.h diff --git a/Grid/qcd/action/fermion/DirichletFermionOperator.h b/Grid/qcd/action/fermion/DirichletFermionOperator.h new file mode 100644 index 00000000..47268cc8 --- /dev/null +++ b/Grid/qcd/action/fermion/DirichletFermionOperator.h @@ -0,0 +1,171 @@ +/************************************************************************************* + + Grid physics library, www.github.com/paboyle/Grid + + Source file: ./lib/qcd/action/fermion/DirichletFermionOperator.h + + Copyright (C) 2021 + +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 + +NAMESPACE_BEGIN(Grid); + +//////////////////////////////////////////////////////////////// +// Wrap a fermion operator in Dirichlet BC's at node boundary +//////////////////////////////////////////////////////////////// + +template +class DirichletFermionOperator : public FermionOperator +{ +public: + + INHERIT_IMPL_TYPES(Impl); + + // Data members + int CommsMode; + Coordinate Block; + DirichletFilter Filter; + FermionOperator & FermOp; + + // Constructor / bespoke + DirichletFermionOperator(FermionOperator & _FermOp, Coordinate _Block) : FermOp(_FermOp), Block(_Block), Filter(_Block) + { + // Save what the comms mode should be under normal BCs + CommsMode = WilsonKernelsStatic::Comms; + assert((WilsonKernelsStatic::Comms = WilsonKernelsStatic::CommsAndCompute) + ||(WilsonKernelsStatic::Comms = WilsonKernelsStatic::CommsThenCompute)); + + // Check the block size divides local lattice + GridBase *grid = FermOp.GaugeGrid(); + + int blocks_per_rank = 1; + Coordinate LocalDims = grid->LocalDimensions(); + assert(Block.size()==LocalDims.size()); + for(int d=0;d &out) {FermOp.MdirAll(in,out);}; + + /////////////////////////////////////////////// + // Updates gauge field during HMC + /////////////////////////////////////////////// + virtual void ImportGauge(const GaugeField & _U) + { + GaugeField U = _U; + // Filter gauge field to apply Dirichlet + Filter.applyFilter(U); + FermOp.ImportGauge(U); + } + /////////////////////////////////////////////// + // Physical field import/export + /////////////////////////////////////////////// + virtual void Dminus(const FermionField &psi, FermionField &chi) { FermOp.Dminus(psi,chi); } + virtual void DminusDag(const FermionField &psi, FermionField &chi) { FermOp.DminusDag(psi,chi); } + virtual void ImportFourDimPseudoFermion(const FermionField &input,FermionField &imported) { FermOp.ImportFourDimPseudoFermion(input,imported);} + virtual void ExportFourDimPseudoFermion(const FermionField &solution,FermionField &exported){ FermOp.ExportFourDimPseudoFermion(solution,exported);} + virtual void ImportPhysicalFermionSource(const FermionField &input,FermionField &imported) { FermOp.ImportPhysicalFermionSource(input,imported);} + virtual void ImportUnphysicalFermion(const FermionField &input,FermionField &imported) { FermOp.ImportUnphysicalFermion(input,imported);} + virtual void ExportPhysicalFermionSolution(const FermionField &solution,FermionField &exported) {FermOp.ExportPhysicalFermionSolution(solution,exported);} + virtual void ExportPhysicalFermionSource(const FermionField &solution,FermionField &exported) {FermOp.ExportPhysicalFermionSource(solution,exported);} + ////////////////////////////////////////////////////////////////////// + // Should never be used + ////////////////////////////////////////////////////////////////////// + virtual void MomentumSpacePropagator(FermionField &out,const FermionField &in,RealD _m,std::vector twist) { assert(0);}; + virtual void FreePropagator(const FermionField &in,FermionField &out,RealD mass,std::vector boundary,std::vector twist) {assert(0);} + virtual void FreePropagator(const FermionField &in,FermionField &out,RealD mass) { assert(0);} + virtual void ContractConservedCurrent(PropagatorField &q_in_1, + PropagatorField &q_in_2, + PropagatorField &q_out, + PropagatorField &phys_src, + Current curr_type, + unsigned int mu) + {assert(0);}; + virtual void SeqConservedCurrent(PropagatorField &q_in, + PropagatorField &q_out, + PropagatorField &phys_src, + Current curr_type, + unsigned int mu, + unsigned int tmin, + unsigned int tmax, + ComplexField &lattice_cmplx) + {assert(0);}; + // Only reimplemented in Wilson5D + // Default to just a zero correlation function + virtual void ContractJ5q(FermionField &q_in ,ComplexField &J5q) { J5q=Zero(); }; + virtual void ContractJ5q(PropagatorField &q_in,ComplexField &J5q) { J5q=Zero(); }; + +}; + + +NAMESPACE_END(Grid); +