mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: consistent autoPtr handling in PatchFunction1
This commit is contained in:
@ -108,21 +108,21 @@ ${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}
|
||||
(
|
||||
const ${typeName}PatchFunction1${FieldType}& ut,
|
||||
const ${typeName}PatchFunction1${FieldType}& rhs,
|
||||
const polyPatch& pp
|
||||
)
|
||||
:
|
||||
PatchFunction1<${TemplateType}>(ut, pp)
|
||||
PatchFunction1<${TemplateType}>(rhs, pp)
|
||||
{}
|
||||
|
||||
|
||||
@ -137,7 +137,6 @@ ${typeName}PatchFunction1${FieldType}::value
|
||||
//{{{ begin code
|
||||
${code}
|
||||
//}}} end code
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -81,13 +81,13 @@ public:
|
||||
const bool faceValues = true
|
||||
);
|
||||
|
||||
//- Construct as copy
|
||||
//- Copy construct
|
||||
${typeName}PatchFunction1${FieldType}
|
||||
(
|
||||
const ${typeName}PatchFunction1${FieldType}&
|
||||
);
|
||||
|
||||
//- Construct as copy, resetting patch
|
||||
//- Copy construct, resetting patch
|
||||
${typeName}PatchFunction1${FieldType}
|
||||
(
|
||||
const ${typeName}PatchFunction1${FieldType}&,
|
||||
|
||||
@ -105,13 +105,6 @@ Foam::PatchFunction1Types::CodedField<Type>::codeDict
|
||||
? dict
|
||||
: 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),
|
||||
codedBase(),
|
||||
dict_(dict),
|
||||
//name_(dict.getCompat<word>("name", {{"redirectType", 1706}}))
|
||||
name_(dict.lookupOrDefault<word>("name", entryName))
|
||||
name_(dict.getOrDefault<word>("name", entryName))
|
||||
{
|
||||
updateLibrary(name_);
|
||||
}
|
||||
@ -164,27 +156,27 @@ Foam::PatchFunction1Types::CodedField<Type>::CodedField
|
||||
template<class Type>
|
||||
Foam::PatchFunction1Types::CodedField<Type>::CodedField
|
||||
(
|
||||
const CodedField<Type>& ut
|
||||
const CodedField<Type>& rhs
|
||||
)
|
||||
:
|
||||
PatchFunction1<Type>(ut),
|
||||
PatchFunction1<Type>(rhs),
|
||||
codedBase(),
|
||||
dict_(ut.dict_),
|
||||
name_(ut.name_)
|
||||
dict_(rhs.dict_),
|
||||
name_(rhs.name_)
|
||||
{}
|
||||
|
||||
|
||||
template<class Type>
|
||||
Foam::PatchFunction1Types::CodedField<Type>::CodedField
|
||||
(
|
||||
const CodedField<Type>& ut,
|
||||
const CodedField<Type>& rhs,
|
||||
const polyPatch& pp
|
||||
)
|
||||
:
|
||||
PatchFunction1<Type>(ut, pp),
|
||||
PatchFunction1<Type>(rhs, pp),
|
||||
codedBase(),
|
||||
dict_(ut.dict_),
|
||||
name_(ut.name_)
|
||||
dict_(rhs.dict_),
|
||||
name_(rhs.name_)
|
||||
{}
|
||||
|
||||
|
||||
@ -194,7 +186,7 @@ template<class Type>
|
||||
const Foam::PatchFunction1<Type>&
|
||||
Foam::PatchFunction1Types::CodedField<Type>::redirectFunction() const
|
||||
{
|
||||
if (!redirectFunctionPtr_.valid())
|
||||
if (!redirectFunctionPtr_)
|
||||
{
|
||||
// Construct a PatchFunction1 containing the input code
|
||||
dictionary completeDict(dict_);
|
||||
@ -206,7 +198,7 @@ Foam::PatchFunction1Types::CodedField<Type>::redirectFunction() const
|
||||
dictionary dict;
|
||||
dict.add(name_, completeDict);
|
||||
|
||||
redirectFunctionPtr_.set
|
||||
redirectFunctionPtr_.reset
|
||||
(
|
||||
PatchFunction1<Type>::New
|
||||
(
|
||||
@ -214,7 +206,7 @@ Foam::PatchFunction1Types::CodedField<Type>::redirectFunction() const
|
||||
name_,
|
||||
dict,
|
||||
this->faceValues_
|
||||
).ptr()
|
||||
)
|
||||
);
|
||||
}
|
||||
return *redirectFunctionPtr_;
|
||||
@ -228,7 +220,7 @@ Foam::PatchFunction1Types::CodedField<Type>::value
|
||||
const scalar x
|
||||
) const
|
||||
{
|
||||
// Make sure library containing user-defined fvPatchField is up-to-date
|
||||
// Ensure library containing user-defined code is up-to-date
|
||||
updateLibrary(name_);
|
||||
|
||||
return redirectFunction().value(x);
|
||||
@ -243,7 +235,7 @@ Foam::PatchFunction1Types::CodedField<Type>::integrate
|
||||
const scalar x2
|
||||
) const
|
||||
{
|
||||
// Make sure library containing user-defined fvPatchField is up-to-date
|
||||
// Ensure library containing user-defined code is up-to-date
|
||||
updateLibrary(name_);
|
||||
|
||||
return redirectFunction().integrate(x1, x2);
|
||||
|
||||
@ -97,9 +97,9 @@ class CodedField
|
||||
public PatchFunction1<Type>,
|
||||
protected codedBase
|
||||
{
|
||||
// Private data
|
||||
// Private Data
|
||||
|
||||
//- Dictionary contents for the boundary condition
|
||||
//- Dictionary contents for the function
|
||||
const dictionary dict_;
|
||||
|
||||
const word name_;
|
||||
@ -136,7 +136,7 @@ class CodedField
|
||||
|
||||
public:
|
||||
|
||||
// Static data members
|
||||
// Static Data Members
|
||||
|
||||
//- Name of the C code template to be used
|
||||
static constexpr const char* const codeTemplateC
|
||||
@ -147,8 +147,7 @@ public:
|
||||
= "codedPatchFunction1Template.H";
|
||||
|
||||
|
||||
|
||||
// Runtime type information
|
||||
//- Runtime type information
|
||||
TypeName("coded");
|
||||
|
||||
|
||||
@ -164,13 +163,13 @@ public:
|
||||
const bool faceValues = true
|
||||
);
|
||||
|
||||
//- Copy constructor
|
||||
explicit CodedField(const CodedField<Type>& ut);
|
||||
//- Copy construct
|
||||
explicit CodedField(const CodedField<Type>& rhs);
|
||||
|
||||
//- Copy constructor setting patch
|
||||
//- Copy construct, setting patch
|
||||
explicit CodedField
|
||||
(
|
||||
const CodedField<Type>& ut,
|
||||
const CodedField<Type>& rhs,
|
||||
const polyPatch& pp
|
||||
);
|
||||
|
||||
|
||||
@ -60,7 +60,7 @@ class ConstantField
|
||||
:
|
||||
public PatchFunction1<Type>
|
||||
{
|
||||
// Private data
|
||||
// Private Data
|
||||
|
||||
//- Is uniform?
|
||||
bool isUniform_;
|
||||
@ -90,7 +90,7 @@ class ConstantField
|
||||
|
||||
public:
|
||||
|
||||
// Runtime type information
|
||||
//- Runtime type information
|
||||
TypeName("constant");
|
||||
|
||||
|
||||
@ -118,7 +118,7 @@ public:
|
||||
const bool faceValues = true
|
||||
);
|
||||
|
||||
//- Copy constructor
|
||||
//- Copy construct
|
||||
explicit ConstantField(const ConstantField<Type>& cnst);
|
||||
|
||||
//- Copy constructor setting patch
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2017 OpenFOAM Foundation
|
||||
Copyright (C) 2020 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -40,10 +41,8 @@ Foam::PatchFunction1Types::ConstantField<Type>::value
|
||||
{
|
||||
return this->transform(value_);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
return value_;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -57,12 +56,10 @@ Foam::PatchFunction1Types::ConstantField<Type>::integrate
|
||||
{
|
||||
if (this->coordSys_.active())
|
||||
{
|
||||
return (x2 - x1)* this->transform(value_);
|
||||
return (x2 - x1) * this->transform(value_);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
return (x2 - x1)*value_;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2020 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -40,11 +41,11 @@ Foam::AverageField<Type>::AverageField(const label size)
|
||||
template<class Type>
|
||||
Foam::AverageField<Type>::AverageField
|
||||
(
|
||||
const Field<Type>& f,
|
||||
const Field<Type>& fld,
|
||||
const Type& average
|
||||
)
|
||||
:
|
||||
Field<Type>(f),
|
||||
Field<Type>(fld),
|
||||
average_(average)
|
||||
{}
|
||||
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2020 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -53,7 +54,7 @@ class AverageField
|
||||
:
|
||||
public Field<Type>
|
||||
{
|
||||
// Private data
|
||||
// Private Data
|
||||
|
||||
//- The average of the field
|
||||
Type average_;
|
||||
@ -64,16 +65,16 @@ public:
|
||||
// Constructors
|
||||
|
||||
//- Construct from size (does not set values)
|
||||
AverageField(const label size);
|
||||
explicit AverageField(const label size);
|
||||
|
||||
//- Construct from components
|
||||
AverageField(const Field<Type>&, const Type& average);
|
||||
AverageField(const Field<Type>& fld, const Type& average);
|
||||
|
||||
//- Construct from Istream
|
||||
AverageField(Istream&);
|
||||
explicit AverageField(Istream& is);
|
||||
|
||||
|
||||
// Member functions
|
||||
// Member Functions
|
||||
|
||||
const Type& average() const;
|
||||
|
||||
|
||||
@ -45,7 +45,7 @@ Foam::PatchFunction1Types::MappedFile<Type>::MappedFile
|
||||
dictConstructed_(true),
|
||||
fieldTableName_(entryName),
|
||||
setAverage_(dict.lookupOrDefault("setAverage", false)),
|
||||
perturb_(dict.lookupOrDefault("perturb", 1e-5)),
|
||||
perturb_(dict.lookupOrDefault<scalar>("perturb", 1e-5)),
|
||||
pointsName_(dict.lookupOrDefault<word>("points", "points")),
|
||||
mapMethod_
|
||||
(
|
||||
@ -63,7 +63,7 @@ Foam::PatchFunction1Types::MappedFile<Type>::MappedFile
|
||||
endSampleTime_(-1),
|
||||
endSampledValues_(0),
|
||||
endAverage_(Zero),
|
||||
offset_()
|
||||
offset_(nullptr)
|
||||
{
|
||||
if (dict.found("offset"))
|
||||
{
|
||||
@ -99,7 +99,7 @@ Foam::PatchFunction1Types::MappedFile<Type>::MappedFile
|
||||
dictConstructed_(false),
|
||||
fieldTableName_(fieldTableName),
|
||||
setAverage_(dict.lookupOrDefault("setAverage", false)),
|
||||
perturb_(dict.lookupOrDefault("perturb", 1e-5)),
|
||||
perturb_(dict.lookupOrDefault<scalar>("perturb", 1e-5)),
|
||||
pointsName_(dict.lookupOrDefault<word>("points", "points")),
|
||||
mapMethod_
|
||||
(
|
||||
@ -117,7 +117,7 @@ Foam::PatchFunction1Types::MappedFile<Type>::MappedFile
|
||||
endSampleTime_(-1),
|
||||
endSampledValues_(0),
|
||||
endAverage_(Zero),
|
||||
offset_()
|
||||
offset_(nullptr)
|
||||
{
|
||||
if (dict.found("offset"))
|
||||
{
|
||||
@ -241,7 +241,7 @@ void Foam::PatchFunction1Types::MappedFile<Type>::checkTable
|
||||
const polyMesh& mesh = this->patch_.boundaryMesh().mesh();
|
||||
|
||||
// Initialise
|
||||
if (mapperPtr_.empty())
|
||||
if (!mapperPtr_)
|
||||
{
|
||||
// Reread values and interpolate
|
||||
fileName samplePointsFile
|
||||
@ -296,7 +296,6 @@ void Foam::PatchFunction1Types::MappedFile<Type>::checkTable
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Read the times for which data is available
|
||||
const fileName samplePointsDir = samplePointsFile.path();
|
||||
sampleTimes_ = Time::findTimes(samplePointsDir);
|
||||
@ -479,7 +478,7 @@ Foam::PatchFunction1Types::MappedFile<Type>::value
|
||||
checkTable(x);
|
||||
|
||||
auto tfld = tmp<Field<Type>>::New(startSampledValues_.size());
|
||||
Field<Type>& fld = tfld.ref();
|
||||
auto& fld = tfld.ref();
|
||||
Type wantedAverage;
|
||||
|
||||
if (endSampleTime_ == -1)
|
||||
@ -563,7 +562,7 @@ Foam::PatchFunction1Types::MappedFile<Type>::value
|
||||
}
|
||||
|
||||
// Apply offset to mapped values
|
||||
if (offset_.valid())
|
||||
if (offset_)
|
||||
{
|
||||
fld += offset_->value(x);
|
||||
}
|
||||
@ -600,8 +599,8 @@ void Foam::PatchFunction1Types::MappedFile<Type>::writeData
|
||||
{
|
||||
PatchFunction1<Type>::writeData(os);
|
||||
|
||||
// Check if field name explicitly provided (e.g. through timeVaryingMapped
|
||||
// bc)
|
||||
// Check if field name explicitly provided
|
||||
// (e.g. through timeVaryingMapped bc)
|
||||
if (dictConstructed_)
|
||||
{
|
||||
os.writeEntry(this->name(), type());
|
||||
@ -630,7 +629,7 @@ void Foam::PatchFunction1Types::MappedFile<Type>::writeData
|
||||
mapMethod_
|
||||
);
|
||||
|
||||
if (offset_.valid())
|
||||
if (offset_)
|
||||
{
|
||||
offset_->writeData(os);
|
||||
}
|
||||
|
||||
@ -5,8 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2018 OpenFOAM Foundation
|
||||
Copyright (C) 2018 OpenCFD Ltd.
|
||||
Copyright (C) 2018-2020 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -31,6 +30,8 @@ License
|
||||
template<class Type>
|
||||
Foam::coordinateScaling<Type>::coordinateScaling()
|
||||
:
|
||||
coordSys_(nullptr),
|
||||
scale_(),
|
||||
active_(false)
|
||||
{}
|
||||
|
||||
@ -49,9 +50,9 @@ Foam::coordinateScaling<Type>::coordinateScaling
|
||||
: nullptr
|
||||
),
|
||||
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));
|
||||
|
||||
@ -65,18 +66,11 @@ Foam::coordinateScaling<Type>::coordinateScaling
|
||||
|
||||
|
||||
template<class Type>
|
||||
Foam::coordinateScaling<Type>::coordinateScaling(const coordinateScaling& cs)
|
||||
Foam::coordinateScaling<Type>::coordinateScaling(const coordinateScaling& rhs)
|
||||
:
|
||||
coordSys_(cs.coordSys_.clone()),
|
||||
scale_(cs.scale_),
|
||||
active_(cs.active_)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
Foam::coordinateScaling<Type>::~coordinateScaling()
|
||||
coordSys_(rhs.coordSys_.clone()),
|
||||
scale_(rhs.scale_),
|
||||
active_(rhs.active_)
|
||||
{}
|
||||
|
||||
|
||||
@ -89,13 +83,13 @@ Foam::tmp<Foam::Field<Type>> Foam::coordinateScaling<Type>::transform
|
||||
const Field<Type>& p0
|
||||
) const
|
||||
{
|
||||
tmp<Field<Type>> tfld(new Field<Type>(p0));
|
||||
Field<Type>& fld = tfld.ref();
|
||||
auto tfld = tmp<Field<Type>>::New(p0);
|
||||
auto& fld = tfld.ref();
|
||||
|
||||
if (coordSys_.valid())
|
||||
if (coordSys_)
|
||||
{
|
||||
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))
|
||||
{
|
||||
@ -109,9 +103,9 @@ Foam::tmp<Foam::Field<Type>> Foam::coordinateScaling<Type>::transform
|
||||
|
||||
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))
|
||||
{
|
||||
@ -122,15 +116,16 @@ Foam::tmp<Foam::Field<Type>> Foam::coordinateScaling<Type>::transform
|
||||
);
|
||||
}
|
||||
}
|
||||
return fld;
|
||||
}
|
||||
|
||||
return tfld;
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
void Foam::coordinateScaling<Type>::writeEntry(Ostream& os) const
|
||||
{
|
||||
if (coordSys_.valid())
|
||||
if (coordSys_)
|
||||
{
|
||||
coordSys_->writeEntry(coordinateSystem::typeName_(), os);
|
||||
}
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2018 OpenCFD Ltd.
|
||||
Copyright (C) 2018-2020 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -55,15 +55,15 @@ namespace Foam
|
||||
template<class Type>
|
||||
class coordinateScaling
|
||||
{
|
||||
// Private data
|
||||
// Private Data
|
||||
|
||||
//- Local co-ordinate system
|
||||
//- Local coordinate system
|
||||
const autoPtr<coordinateSystem> coordSys_;
|
||||
|
||||
//- In local co-ordinate system component-wise scaling
|
||||
//- In local coordinate system component-wise scaling
|
||||
PtrList<Function1<Type>> scale_;
|
||||
|
||||
//- Cached whether any scaling or coordinate system
|
||||
//- Cache whether any scaling or coordinate system
|
||||
bool active_;
|
||||
|
||||
|
||||
@ -76,25 +76,25 @@ public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
//- Default construct
|
||||
coordinateScaling();
|
||||
|
||||
//- Construct from registry and dictionary
|
||||
coordinateScaling
|
||||
(
|
||||
const objectRegistry&,
|
||||
const dictionary&
|
||||
const objectRegistry& obr,
|
||||
const dictionary& dict
|
||||
);
|
||||
|
||||
//- Construct copy
|
||||
coordinateScaling(const coordinateScaling&);
|
||||
coordinateScaling(const coordinateScaling& rhs);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~coordinateScaling();
|
||||
virtual ~coordinateScaling() = default;
|
||||
|
||||
|
||||
// Member functions
|
||||
// Member Functions
|
||||
|
||||
//- Has any scaling or coordinate transformation
|
||||
bool active() const
|
||||
@ -116,12 +116,13 @@ public:
|
||||
) const;
|
||||
|
||||
//- Write dictionary entry
|
||||
virtual void writeEntry(Ostream&) const;
|
||||
virtual void writeEntry(Ostream& os) const;
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
// Template specializations
|
||||
template<>
|
||||
tmp<Field<label>> coordinateScaling<label>::transform
|
||||
(
|
||||
|
||||
Reference in New Issue
Block a user