ENH: consistent autoPtr handling in PatchFunction1

This commit is contained in:
Mark Olesen
2020-05-20 14:47:16 +02:00
parent 2659c48f36
commit 09d9c5cc03
11 changed files with 99 additions and 115 deletions

View File

@ -108,21 +108,21 @@ ${typeName}PatchFunction1${FieldType}
${typeName}PatchFunction1${FieldType}:: ${typeName}PatchFunction1${FieldType}::
${typeName}PatchFunction1${FieldType} ${typeName}PatchFunction1${FieldType}
( (
const ${typeName}PatchFunction1${FieldType}& ut const ${typeName}PatchFunction1${FieldType}& rhs
) )
: :
PatchFunction1<${TemplateType}>(ut) PatchFunction1<${TemplateType}>(rhs)
{} {}
${typeName}PatchFunction1${FieldType}:: ${typeName}PatchFunction1${FieldType}::
${typeName}PatchFunction1${FieldType} ${typeName}PatchFunction1${FieldType}
( (
const ${typeName}PatchFunction1${FieldType}& ut, const ${typeName}PatchFunction1${FieldType}& rhs,
const polyPatch& pp const polyPatch& pp
) )
: :
PatchFunction1<${TemplateType}>(ut, pp) PatchFunction1<${TemplateType}>(rhs, pp)
{} {}
@ -137,7 +137,6 @@ ${typeName}PatchFunction1${FieldType}::value
//{{{ begin code //{{{ begin code
${code} ${code}
//}}} end code //}}} end code
} }

View File

@ -81,13 +81,13 @@ public:
const bool faceValues = true const bool faceValues = true
); );
//- Construct as copy //- Copy construct
${typeName}PatchFunction1${FieldType} ${typeName}PatchFunction1${FieldType}
( (
const ${typeName}PatchFunction1${FieldType}& const ${typeName}PatchFunction1${FieldType}&
); );
//- Construct as copy, resetting patch //- Copy construct, resetting patch
${typeName}PatchFunction1${FieldType} ${typeName}PatchFunction1${FieldType}
( (
const ${typeName}PatchFunction1${FieldType}&, const ${typeName}PatchFunction1${FieldType}&,

View File

@ -105,13 +105,6 @@ Foam::PatchFunction1Types::CodedField<Type>::codeDict
? dict ? dict
: dict.subDict(name_) : dict.subDict(name_)
); );
//return
//(
// dict.found(name_)
// ? dict.subDict(name_)
// : dict
//);
} }
@ -154,8 +147,7 @@ Foam::PatchFunction1Types::CodedField<Type>::CodedField
PatchFunction1<Type>(pp, entryName, dict, faceValues), PatchFunction1<Type>(pp, entryName, dict, faceValues),
codedBase(), codedBase(),
dict_(dict), dict_(dict),
//name_(dict.getCompat<word>("name", {{"redirectType", 1706}})) name_(dict.getOrDefault<word>("name", entryName))
name_(dict.lookupOrDefault<word>("name", entryName))
{ {
updateLibrary(name_); updateLibrary(name_);
} }
@ -164,27 +156,27 @@ Foam::PatchFunction1Types::CodedField<Type>::CodedField
template<class Type> template<class Type>
Foam::PatchFunction1Types::CodedField<Type>::CodedField Foam::PatchFunction1Types::CodedField<Type>::CodedField
( (
const CodedField<Type>& ut const CodedField<Type>& rhs
) )
: :
PatchFunction1<Type>(ut), PatchFunction1<Type>(rhs),
codedBase(), codedBase(),
dict_(ut.dict_), dict_(rhs.dict_),
name_(ut.name_) name_(rhs.name_)
{} {}
template<class Type> template<class Type>
Foam::PatchFunction1Types::CodedField<Type>::CodedField Foam::PatchFunction1Types::CodedField<Type>::CodedField
( (
const CodedField<Type>& ut, const CodedField<Type>& rhs,
const polyPatch& pp const polyPatch& pp
) )
: :
PatchFunction1<Type>(ut, pp), PatchFunction1<Type>(rhs, pp),
codedBase(), codedBase(),
dict_(ut.dict_), dict_(rhs.dict_),
name_(ut.name_) name_(rhs.name_)
{} {}
@ -194,7 +186,7 @@ template<class Type>
const Foam::PatchFunction1<Type>& const Foam::PatchFunction1<Type>&
Foam::PatchFunction1Types::CodedField<Type>::redirectFunction() const Foam::PatchFunction1Types::CodedField<Type>::redirectFunction() const
{ {
if (!redirectFunctionPtr_.valid()) if (!redirectFunctionPtr_)
{ {
// Construct a PatchFunction1 containing the input code // Construct a PatchFunction1 containing the input code
dictionary completeDict(dict_); dictionary completeDict(dict_);
@ -206,7 +198,7 @@ Foam::PatchFunction1Types::CodedField<Type>::redirectFunction() const
dictionary dict; dictionary dict;
dict.add(name_, completeDict); dict.add(name_, completeDict);
redirectFunctionPtr_.set redirectFunctionPtr_.reset
( (
PatchFunction1<Type>::New PatchFunction1<Type>::New
( (
@ -214,7 +206,7 @@ Foam::PatchFunction1Types::CodedField<Type>::redirectFunction() const
name_, name_,
dict, dict,
this->faceValues_ this->faceValues_
).ptr() )
); );
} }
return *redirectFunctionPtr_; return *redirectFunctionPtr_;
@ -228,7 +220,7 @@ Foam::PatchFunction1Types::CodedField<Type>::value
const scalar x const scalar x
) const ) const
{ {
// Make sure library containing user-defined fvPatchField is up-to-date // Ensure library containing user-defined code is up-to-date
updateLibrary(name_); updateLibrary(name_);
return redirectFunction().value(x); return redirectFunction().value(x);
@ -243,7 +235,7 @@ Foam::PatchFunction1Types::CodedField<Type>::integrate
const scalar x2 const scalar x2
) const ) const
{ {
// Make sure library containing user-defined fvPatchField is up-to-date // Ensure library containing user-defined code is up-to-date
updateLibrary(name_); updateLibrary(name_);
return redirectFunction().integrate(x1, x2); return redirectFunction().integrate(x1, x2);

View File

@ -97,9 +97,9 @@ class CodedField
public PatchFunction1<Type>, public PatchFunction1<Type>,
protected codedBase protected codedBase
{ {
// Private data // Private Data
//- Dictionary contents for the boundary condition //- Dictionary contents for the function
const dictionary dict_; const dictionary dict_;
const word name_; const word name_;
@ -136,7 +136,7 @@ class CodedField
public: public:
// Static data members // Static Data Members
//- Name of the C code template to be used //- Name of the C code template to be used
static constexpr const char* const codeTemplateC static constexpr const char* const codeTemplateC
@ -147,8 +147,7 @@ public:
= "codedPatchFunction1Template.H"; = "codedPatchFunction1Template.H";
//- Runtime type information
// Runtime type information
TypeName("coded"); TypeName("coded");
@ -164,13 +163,13 @@ public:
const bool faceValues = true const bool faceValues = true
); );
//- Copy constructor //- Copy construct
explicit CodedField(const CodedField<Type>& ut); explicit CodedField(const CodedField<Type>& rhs);
//- Copy constructor setting patch //- Copy construct, setting patch
explicit CodedField explicit CodedField
( (
const CodedField<Type>& ut, const CodedField<Type>& rhs,
const polyPatch& pp const polyPatch& pp
); );

View File

@ -60,7 +60,7 @@ class ConstantField
: :
public PatchFunction1<Type> public PatchFunction1<Type>
{ {
// Private data // Private Data
//- Is uniform? //- Is uniform?
bool isUniform_; bool isUniform_;
@ -90,7 +90,7 @@ class ConstantField
public: public:
// Runtime type information //- Runtime type information
TypeName("constant"); TypeName("constant");
@ -118,7 +118,7 @@ public:
const bool faceValues = true const bool faceValues = true
); );
//- Copy constructor //- Copy construct
explicit ConstantField(const ConstantField<Type>& cnst); explicit ConstantField(const ConstantField<Type>& cnst);
//- Copy constructor setting patch //- Copy constructor setting patch

View File

@ -6,6 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2017 OpenFOAM Foundation Copyright (C) 2017 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -40,10 +41,8 @@ Foam::PatchFunction1Types::ConstantField<Type>::value
{ {
return this->transform(value_); return this->transform(value_);
} }
else
{
return value_; return value_;
}
} }
@ -57,12 +56,10 @@ Foam::PatchFunction1Types::ConstantField<Type>::integrate
{ {
if (this->coordSys_.active()) if (this->coordSys_.active())
{ {
return (x2 - x1)* this->transform(value_); return (x2 - x1) * this->transform(value_);
} }
else
{
return (x2 - x1)*value_; return (x2 - x1)*value_;
}
} }

View File

@ -6,6 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -40,11 +41,11 @@ Foam::AverageField<Type>::AverageField(const label size)
template<class Type> template<class Type>
Foam::AverageField<Type>::AverageField Foam::AverageField<Type>::AverageField
( (
const Field<Type>& f, const Field<Type>& fld,
const Type& average const Type& average
) )
: :
Field<Type>(f), Field<Type>(fld),
average_(average) average_(average)
{} {}

View File

@ -6,6 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -53,7 +54,7 @@ class AverageField
: :
public Field<Type> public Field<Type>
{ {
// Private data // Private Data
//- The average of the field //- The average of the field
Type average_; Type average_;
@ -64,16 +65,16 @@ public:
// Constructors // Constructors
//- Construct from size (does not set values) //- Construct from size (does not set values)
AverageField(const label size); explicit AverageField(const label size);
//- Construct from components //- Construct from components
AverageField(const Field<Type>&, const Type& average); AverageField(const Field<Type>& fld, const Type& average);
//- Construct from Istream //- Construct from Istream
AverageField(Istream&); explicit AverageField(Istream& is);
// Member functions // Member Functions
const Type& average() const; const Type& average() const;

View File

@ -45,7 +45,7 @@ Foam::PatchFunction1Types::MappedFile<Type>::MappedFile
dictConstructed_(true), dictConstructed_(true),
fieldTableName_(entryName), fieldTableName_(entryName),
setAverage_(dict.lookupOrDefault("setAverage", false)), setAverage_(dict.lookupOrDefault("setAverage", false)),
perturb_(dict.lookupOrDefault("perturb", 1e-5)), perturb_(dict.lookupOrDefault<scalar>("perturb", 1e-5)),
pointsName_(dict.lookupOrDefault<word>("points", "points")), pointsName_(dict.lookupOrDefault<word>("points", "points")),
mapMethod_ mapMethod_
( (
@ -63,7 +63,7 @@ Foam::PatchFunction1Types::MappedFile<Type>::MappedFile
endSampleTime_(-1), endSampleTime_(-1),
endSampledValues_(0), endSampledValues_(0),
endAverage_(Zero), endAverage_(Zero),
offset_() offset_(nullptr)
{ {
if (dict.found("offset")) if (dict.found("offset"))
{ {
@ -99,7 +99,7 @@ Foam::PatchFunction1Types::MappedFile<Type>::MappedFile
dictConstructed_(false), dictConstructed_(false),
fieldTableName_(fieldTableName), fieldTableName_(fieldTableName),
setAverage_(dict.lookupOrDefault("setAverage", false)), setAverage_(dict.lookupOrDefault("setAverage", false)),
perturb_(dict.lookupOrDefault("perturb", 1e-5)), perturb_(dict.lookupOrDefault<scalar>("perturb", 1e-5)),
pointsName_(dict.lookupOrDefault<word>("points", "points")), pointsName_(dict.lookupOrDefault<word>("points", "points")),
mapMethod_ mapMethod_
( (
@ -117,7 +117,7 @@ Foam::PatchFunction1Types::MappedFile<Type>::MappedFile
endSampleTime_(-1), endSampleTime_(-1),
endSampledValues_(0), endSampledValues_(0),
endAverage_(Zero), endAverage_(Zero),
offset_() offset_(nullptr)
{ {
if (dict.found("offset")) if (dict.found("offset"))
{ {
@ -241,7 +241,7 @@ void Foam::PatchFunction1Types::MappedFile<Type>::checkTable
const polyMesh& mesh = this->patch_.boundaryMesh().mesh(); const polyMesh& mesh = this->patch_.boundaryMesh().mesh();
// Initialise // Initialise
if (mapperPtr_.empty()) if (!mapperPtr_)
{ {
// Reread values and interpolate // Reread values and interpolate
fileName samplePointsFile fileName samplePointsFile
@ -296,7 +296,6 @@ void Foam::PatchFunction1Types::MappedFile<Type>::checkTable
} }
// Read the times for which data is available // Read the times for which data is available
const fileName samplePointsDir = samplePointsFile.path(); const fileName samplePointsDir = samplePointsFile.path();
sampleTimes_ = Time::findTimes(samplePointsDir); sampleTimes_ = Time::findTimes(samplePointsDir);
@ -479,7 +478,7 @@ Foam::PatchFunction1Types::MappedFile<Type>::value
checkTable(x); checkTable(x);
auto tfld = tmp<Field<Type>>::New(startSampledValues_.size()); auto tfld = tmp<Field<Type>>::New(startSampledValues_.size());
Field<Type>& fld = tfld.ref(); auto& fld = tfld.ref();
Type wantedAverage; Type wantedAverage;
if (endSampleTime_ == -1) if (endSampleTime_ == -1)
@ -563,7 +562,7 @@ Foam::PatchFunction1Types::MappedFile<Type>::value
} }
// Apply offset to mapped values // Apply offset to mapped values
if (offset_.valid()) if (offset_)
{ {
fld += offset_->value(x); fld += offset_->value(x);
} }
@ -600,8 +599,8 @@ void Foam::PatchFunction1Types::MappedFile<Type>::writeData
{ {
PatchFunction1<Type>::writeData(os); PatchFunction1<Type>::writeData(os);
// Check if field name explicitly provided (e.g. through timeVaryingMapped // Check if field name explicitly provided
// bc) // (e.g. through timeVaryingMapped bc)
if (dictConstructed_) if (dictConstructed_)
{ {
os.writeEntry(this->name(), type()); os.writeEntry(this->name(), type());
@ -630,7 +629,7 @@ void Foam::PatchFunction1Types::MappedFile<Type>::writeData
mapMethod_ mapMethod_
); );
if (offset_.valid()) if (offset_)
{ {
offset_->writeData(os); offset_->writeData(os);
} }

View File

@ -5,8 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2018 OpenFOAM Foundation Copyright (C) 2018-2020 OpenCFD Ltd.
Copyright (C) 2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -31,6 +30,8 @@ License
template<class Type> template<class Type>
Foam::coordinateScaling<Type>::coordinateScaling() Foam::coordinateScaling<Type>::coordinateScaling()
: :
coordSys_(nullptr),
scale_(),
active_(false) active_(false)
{} {}
@ -49,9 +50,9 @@ Foam::coordinateScaling<Type>::coordinateScaling
: nullptr : nullptr
), ),
scale_(3), scale_(3),
active_(coordSys_.valid()) active_(bool(coordSys_))
{ {
for (direction dir = 0; dir < vector::nComponents; dir++) for (direction dir = 0; dir < vector::nComponents; ++dir)
{ {
const word key("scale" + Foam::name(dir+1)); const word key("scale" + Foam::name(dir+1));
@ -65,18 +66,11 @@ Foam::coordinateScaling<Type>::coordinateScaling
template<class Type> template<class Type>
Foam::coordinateScaling<Type>::coordinateScaling(const coordinateScaling& cs) Foam::coordinateScaling<Type>::coordinateScaling(const coordinateScaling& rhs)
: :
coordSys_(cs.coordSys_.clone()), coordSys_(rhs.coordSys_.clone()),
scale_(cs.scale_), scale_(rhs.scale_),
active_(cs.active_) active_(rhs.active_)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class Type>
Foam::coordinateScaling<Type>::~coordinateScaling()
{} {}
@ -89,13 +83,13 @@ Foam::tmp<Foam::Field<Type>> Foam::coordinateScaling<Type>::transform
const Field<Type>& p0 const Field<Type>& p0
) const ) const
{ {
tmp<Field<Type>> tfld(new Field<Type>(p0)); auto tfld = tmp<Field<Type>>::New(p0);
Field<Type>& fld = tfld.ref(); auto& fld = tfld.ref();
if (coordSys_.valid()) if (coordSys_)
{ {
const vectorField local(coordSys_->localPosition(pos)); const vectorField local(coordSys_->localPosition(pos));
for (direction dir = 0; dir < vector::nComponents; dir++) for (direction dir = 0; dir < vector::nComponents; ++dir)
{ {
if (scale_.set(dir)) if (scale_.set(dir))
{ {
@ -109,9 +103,9 @@ Foam::tmp<Foam::Field<Type>> Foam::coordinateScaling<Type>::transform
return coordSys_->transform(pos, fld); return coordSys_->transform(pos, fld);
} }
else else if (scale_.size())
{ {
for (direction dir = 0; dir < vector::nComponents; dir++) for (direction dir = 0; dir < vector::nComponents; ++dir)
{ {
if (scale_.set(dir)) if (scale_.set(dir))
{ {
@ -122,15 +116,16 @@ Foam::tmp<Foam::Field<Type>> Foam::coordinateScaling<Type>::transform
); );
} }
} }
return fld;
} }
return tfld;
} }
template<class Type> template<class Type>
void Foam::coordinateScaling<Type>::writeEntry(Ostream& os) const void Foam::coordinateScaling<Type>::writeEntry(Ostream& os) const
{ {
if (coordSys_.valid()) if (coordSys_)
{ {
coordSys_->writeEntry(coordinateSystem::typeName_(), os); coordSys_->writeEntry(coordinateSystem::typeName_(), os);
} }

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2018 OpenCFD Ltd. Copyright (C) 2018-2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -55,15 +55,15 @@ namespace Foam
template<class Type> template<class Type>
class coordinateScaling class coordinateScaling
{ {
// Private data // Private Data
//- Local co-ordinate system //- Local coordinate system
const autoPtr<coordinateSystem> coordSys_; const autoPtr<coordinateSystem> coordSys_;
//- In local co-ordinate system component-wise scaling //- In local coordinate system component-wise scaling
PtrList<Function1<Type>> scale_; PtrList<Function1<Type>> scale_;
//- Cached whether any scaling or coordinate system //- Cache whether any scaling or coordinate system
bool active_; bool active_;
@ -76,25 +76,25 @@ public:
// Constructors // Constructors
//- Construct null //- Default construct
coordinateScaling(); coordinateScaling();
//- Construct from registry and dictionary //- Construct from registry and dictionary
coordinateScaling coordinateScaling
( (
const objectRegistry&, const objectRegistry& obr,
const dictionary& const dictionary& dict
); );
//- Construct copy //- Construct copy
coordinateScaling(const coordinateScaling&); coordinateScaling(const coordinateScaling& rhs);
//- Destructor //- Destructor
virtual ~coordinateScaling(); virtual ~coordinateScaling() = default;
// Member functions // Member Functions
//- Has any scaling or coordinate transformation //- Has any scaling or coordinate transformation
bool active() const bool active() const
@ -116,12 +116,13 @@ public:
) const; ) const;
//- Write dictionary entry //- Write dictionary entry
virtual void writeEntry(Ostream&) const; virtual void writeEntry(Ostream& os) const;
}; };
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Template specializations
template<> template<>
tmp<Field<label>> coordinateScaling<label>::transform tmp<Field<label>> coordinateScaling<label>::transform
( (