mirror of
https://github.com/paboyle/Grid.git
synced 2024-11-10 07:55:35 +00:00
Fixed memory leak ... without breaking semantics of prior code. Possibly should change the semantics? For Peter / Antonin to comment
This commit is contained in:
parent
5e6104e683
commit
63dc0fa7e9
@ -1,5 +1,34 @@
|
|||||||
|
/*************************************************************************************
|
||||||
|
|
||||||
|
Grid physics library, www.github.com/paboyle/Grid
|
||||||
|
|
||||||
|
Source file: ./lib/qcd/smearing/StoutSmearing.h
|
||||||
|
|
||||||
|
Copyright (C) 2019
|
||||||
|
|
||||||
|
Author: unknown
|
||||||
|
Author: Felix Erben <ferben@ed.ac.uk>
|
||||||
|
Author: Michael Marshall <Michael.Marshall@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
|
||||||
|
*************************************************************************************/
|
||||||
/*
|
/*
|
||||||
@file stoutSmear.hpp
|
@file StoutSmearing.h
|
||||||
@brief Declares Stout smearing class
|
@brief Declares Stout smearing class
|
||||||
*/
|
*/
|
||||||
#ifndef STOUT_SMEAR_
|
#ifndef STOUT_SMEAR_
|
||||||
@ -12,37 +41,42 @@ namespace QCD {
|
|||||||
template <class Gimpl>
|
template <class Gimpl>
|
||||||
class Smear_Stout : public Smear<Gimpl> {
|
class Smear_Stout : public Smear<Gimpl> {
|
||||||
private:
|
private:
|
||||||
const Smear<Gimpl>* SmearBase;
|
// Smear<Gimpl>* ownership semantics:
|
||||||
inline std::vector<double> rho3D(double rho, int orthogdim){
|
// Smear<Gimpl>* passed in to constructor are owned by caller, so we don't delete them here
|
||||||
|
// Smear<Gimpl>* created within constructor need to be deleted as part of the destructor
|
||||||
|
const Smear<Gimpl>* SmearBase; // Not owned by this object, so not deleted at destruction
|
||||||
|
const std::unique_ptr<Smear<Gimpl>> OwnedBase; // deleted at destruction
|
||||||
|
|
||||||
|
public:
|
||||||
|
INHERIT_GIMPL_TYPES(Gimpl)
|
||||||
|
|
||||||
|
// only anticipated to be used from default constructor, but might as well be visible
|
||||||
|
inline static std::vector<double> rho3D(double rho = 1.0, int orthogdim = -1){
|
||||||
std::vector<double> rho3d(Nd*Nd);
|
std::vector<double> rho3d(Nd*Nd);
|
||||||
for (int mu=0; mu<Nd; mu++)
|
for (int mu=0; mu<Nd; mu++)
|
||||||
for (int nu=0; nu<Nd; nu++)
|
for (int nu=0; nu<Nd; nu++)
|
||||||
rho3d[mu + Nd * nu] = (mu == orthogdim || nu == orthogdim) ? 0.0:rho;
|
rho3d[mu + Nd * nu] = (mu == orthogdim || nu == orthogdim) ? 0.0 : rho;
|
||||||
return rho3d;
|
return rho3d;
|
||||||
};
|
};
|
||||||
public:
|
|
||||||
INHERIT_GIMPL_TYPES(Gimpl)
|
|
||||||
|
|
||||||
Smear_Stout(Smear<Gimpl>* base) : SmearBase(base) {
|
/*! Stout smearing with base explicitly specified */
|
||||||
assert(Nc == 3);// "Stout smearing currently implemented only for Nc==3");
|
Smear_Stout(Smear<Gimpl>* base) : SmearBase{base} {
|
||||||
|
assert(Nc == 3 && "Stout smearing currently implemented only for Nc==3");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Default constructor */
|
/*! Construct stout smearing object from explicitly specified rho matrix */
|
||||||
/* Smear_Stout(double rho = 1.0) : SmearBase(new Smear_APE<Gimpl>(rho)) {
|
Smear_Stout(const std::vector<double>& rho_)
|
||||||
assert(Nc == 3);// "Stout smearing currently implemented only for Nc==3");
|
: OwnedBase{new Smear_APE<Gimpl>(rho_)}, SmearBase{OwnedBase.get()} {
|
||||||
} */
|
assert(Nc == 3 && "Stout smearing currently implemented only for Nc==3");
|
||||||
|
}
|
||||||
|
|
||||||
/*! general constructor */
|
/*! Default constructor. rho is constant in all directions, optionally except for orthogonal dimension */
|
||||||
Smear_Stout(std::vector<double>& rho_) : SmearBase(new Smear_APE<Gimpl>(rho_)) {
|
Smear_Stout(double rho = 1.0, int orthogdim = -1)
|
||||||
assert(Nc == 3 && "Stout smearing currently implemented only for Nc==3");
|
: OwnedBase{new Smear_APE<Gimpl>(rho3D(rho,orthogdim))}, SmearBase{OwnedBase.get()} {
|
||||||
}
|
assert(Nc == 3 && "Stout smearing currently implemented only for Nc==3");
|
||||||
|
}
|
||||||
|
|
||||||
/*! 3D constructor */
|
~Smear_Stout() {} // delete SmearBase...
|
||||||
Smear_Stout(double rho = 1.0, int orthogdim = -1) : SmearBase{new Smear_APE<Gimpl>(rho3D(rho,orthogdim))} {
|
|
||||||
assert(Nc == 3 && "Stout smearing currently implemented only for Nc==3");
|
|
||||||
}
|
|
||||||
|
|
||||||
~Smear_Stout() {delete SmearBase;}
|
|
||||||
|
|
||||||
void smear(GaugeField& u_smr, const GaugeField& U) const {
|
void smear(GaugeField& u_smr, const GaugeField& U) const {
|
||||||
GaugeField C(U._grid);
|
GaugeField C(U._grid);
|
||||||
|
Loading…
Reference in New Issue
Block a user