From 09d9c5cc038ab8a29fb5fb89e00c7b0da85eb150 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Wed, 20 May 2020 14:47:16 +0200 Subject: [PATCH] ENH: consistent autoPtr handling in PatchFunction1 --- .../dynamicCode/codedPatchFunction1Template.C | 9 ++-- .../dynamicCode/codedPatchFunction1Template.H | 28 ++++++------- .../PatchFunction1/CodedField/CodedField.C | 36 +++++++--------- .../PatchFunction1/CodedField/CodedField.H | 17 ++++---- .../ConstantField/ConstantField.H | 6 +-- .../ConstantField/ConstantFieldI.H | 15 +++---- .../PatchFunction1/MappedFile/AverageField.C | 5 ++- .../PatchFunction1/MappedFile/AverageField.H | 11 ++--- .../PatchFunction1/MappedFile/MappedFile.C | 21 +++++----- .../PatchFunction1/coordinateScaling.C | 41 ++++++++----------- .../PatchFunction1/coordinateScaling.H | 25 +++++------ 11 files changed, 99 insertions(+), 115 deletions(-) diff --git a/etc/codeTemplates/dynamicCode/codedPatchFunction1Template.C b/etc/codeTemplates/dynamicCode/codedPatchFunction1Template.C index 42e1d58288..de80fee7a3 100644 --- a/etc/codeTemplates/dynamicCode/codedPatchFunction1Template.C +++ b/etc/codeTemplates/dynamicCode/codedPatchFunction1Template.C @@ -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 - } diff --git a/etc/codeTemplates/dynamicCode/codedPatchFunction1Template.H b/etc/codeTemplates/dynamicCode/codedPatchFunction1Template.H index cde6199bf6..af479f3344 100644 --- a/etc/codeTemplates/dynamicCode/codedPatchFunction1Template.H +++ b/etc/codeTemplates/dynamicCode/codedPatchFunction1Template.H @@ -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}&, @@ -122,20 +122,20 @@ public: // Member Functions - //- Return value as a function of (scalar) independent variable - virtual tmp> value(const scalar x) const; + //- Return value as a function of (scalar) independent variable + virtual tmp> value(const scalar x) const; - //- Is value constant (i.e. independent of x) - virtual bool constant() const - { - return false; - } + //- Is value constant (i.e. independent of x) + virtual bool constant() const + { + return false; + } - //- Is value uniform (i.e. independent of coordinate) - virtual bool uniform() const - { - return false; - } + //- Is value uniform (i.e. independent of coordinate) + virtual bool uniform() const + { + return false; + } }; diff --git a/src/meshTools/PatchFunction1/CodedField/CodedField.C b/src/meshTools/PatchFunction1/CodedField/CodedField.C index 60d2aab052..0ab0fc4b17 100644 --- a/src/meshTools/PatchFunction1/CodedField/CodedField.C +++ b/src/meshTools/PatchFunction1/CodedField/CodedField.C @@ -105,13 +105,6 @@ Foam::PatchFunction1Types::CodedField::codeDict ? dict : dict.subDict(name_) ); - - //return - //( - // dict.found(name_) - // ? dict.subDict(name_) - // : dict - //); } @@ -154,8 +147,7 @@ Foam::PatchFunction1Types::CodedField::CodedField PatchFunction1(pp, entryName, dict, faceValues), codedBase(), dict_(dict), - //name_(dict.getCompat("name", {{"redirectType", 1706}})) - name_(dict.lookupOrDefault("name", entryName)) + name_(dict.getOrDefault("name", entryName)) { updateLibrary(name_); } @@ -164,27 +156,27 @@ Foam::PatchFunction1Types::CodedField::CodedField template Foam::PatchFunction1Types::CodedField::CodedField ( - const CodedField& ut + const CodedField& rhs ) : - PatchFunction1(ut), + PatchFunction1(rhs), codedBase(), - dict_(ut.dict_), - name_(ut.name_) + dict_(rhs.dict_), + name_(rhs.name_) {} template Foam::PatchFunction1Types::CodedField::CodedField ( - const CodedField& ut, + const CodedField& rhs, const polyPatch& pp ) : - PatchFunction1(ut, pp), + PatchFunction1(rhs, pp), codedBase(), - dict_(ut.dict_), - name_(ut.name_) + dict_(rhs.dict_), + name_(rhs.name_) {} @@ -194,7 +186,7 @@ template const Foam::PatchFunction1& Foam::PatchFunction1Types::CodedField::redirectFunction() const { - if (!redirectFunctionPtr_.valid()) + if (!redirectFunctionPtr_) { // Construct a PatchFunction1 containing the input code dictionary completeDict(dict_); @@ -206,7 +198,7 @@ Foam::PatchFunction1Types::CodedField::redirectFunction() const dictionary dict; dict.add(name_, completeDict); - redirectFunctionPtr_.set + redirectFunctionPtr_.reset ( PatchFunction1::New ( @@ -214,7 +206,7 @@ Foam::PatchFunction1Types::CodedField::redirectFunction() const name_, dict, this->faceValues_ - ).ptr() + ) ); } return *redirectFunctionPtr_; @@ -228,7 +220,7 @@ Foam::PatchFunction1Types::CodedField::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::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); diff --git a/src/meshTools/PatchFunction1/CodedField/CodedField.H b/src/meshTools/PatchFunction1/CodedField/CodedField.H index 9202edfce7..d79bfc605f 100644 --- a/src/meshTools/PatchFunction1/CodedField/CodedField.H +++ b/src/meshTools/PatchFunction1/CodedField/CodedField.H @@ -97,9 +97,9 @@ class CodedField public PatchFunction1, 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& ut); + //- Copy construct + explicit CodedField(const CodedField& rhs); - //- Copy constructor setting patch + //- Copy construct, setting patch explicit CodedField ( - const CodedField& ut, + const CodedField& rhs, const polyPatch& pp ); diff --git a/src/meshTools/PatchFunction1/ConstantField/ConstantField.H b/src/meshTools/PatchFunction1/ConstantField/ConstantField.H index e2a43c40f9..0cdae26d18 100644 --- a/src/meshTools/PatchFunction1/ConstantField/ConstantField.H +++ b/src/meshTools/PatchFunction1/ConstantField/ConstantField.H @@ -60,7 +60,7 @@ class ConstantField : public PatchFunction1 { - // 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& cnst); //- Copy constructor setting patch diff --git a/src/meshTools/PatchFunction1/ConstantField/ConstantFieldI.H b/src/meshTools/PatchFunction1/ConstantField/ConstantFieldI.H index db54efe556..7ed9ffff02 100644 --- a/src/meshTools/PatchFunction1/ConstantField/ConstantFieldI.H +++ b/src/meshTools/PatchFunction1/ConstantField/ConstantFieldI.H @@ -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::value { return this->transform(value_); } - else - { - return value_; - } + + return value_; } @@ -57,12 +56,10 @@ Foam::PatchFunction1Types::ConstantField::integrate { if (this->coordSys_.active()) { - return (x2 - x1)* this->transform(value_); - } - else - { - return (x2 - x1)*value_; + return (x2 - x1) * this->transform(value_); } + + return (x2 - x1)*value_; } diff --git a/src/meshTools/PatchFunction1/MappedFile/AverageField.C b/src/meshTools/PatchFunction1/MappedFile/AverageField.C index 9968abbd53..b441922542 100644 --- a/src/meshTools/PatchFunction1/MappedFile/AverageField.C +++ b/src/meshTools/PatchFunction1/MappedFile/AverageField.C @@ -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::AverageField(const label size) template Foam::AverageField::AverageField ( - const Field& f, + const Field& fld, const Type& average ) : - Field(f), + Field(fld), average_(average) {} diff --git a/src/meshTools/PatchFunction1/MappedFile/AverageField.H b/src/meshTools/PatchFunction1/MappedFile/AverageField.H index b0c35021a4..43ee0d405e 100644 --- a/src/meshTools/PatchFunction1/MappedFile/AverageField.H +++ b/src/meshTools/PatchFunction1/MappedFile/AverageField.H @@ -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 { - // 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&, const Type& average); + AverageField(const Field& fld, const Type& average); //- Construct from Istream - AverageField(Istream&); + explicit AverageField(Istream& is); - // Member functions + // Member Functions const Type& average() const; diff --git a/src/meshTools/PatchFunction1/MappedFile/MappedFile.C b/src/meshTools/PatchFunction1/MappedFile/MappedFile.C index 92e57be142..afa2db529d 100644 --- a/src/meshTools/PatchFunction1/MappedFile/MappedFile.C +++ b/src/meshTools/PatchFunction1/MappedFile/MappedFile.C @@ -45,7 +45,7 @@ Foam::PatchFunction1Types::MappedFile::MappedFile dictConstructed_(true), fieldTableName_(entryName), setAverage_(dict.lookupOrDefault("setAverage", false)), - perturb_(dict.lookupOrDefault("perturb", 1e-5)), + perturb_(dict.lookupOrDefault("perturb", 1e-5)), pointsName_(dict.lookupOrDefault("points", "points")), mapMethod_ ( @@ -63,7 +63,7 @@ Foam::PatchFunction1Types::MappedFile::MappedFile endSampleTime_(-1), endSampledValues_(0), endAverage_(Zero), - offset_() + offset_(nullptr) { if (dict.found("offset")) { @@ -99,7 +99,7 @@ Foam::PatchFunction1Types::MappedFile::MappedFile dictConstructed_(false), fieldTableName_(fieldTableName), setAverage_(dict.lookupOrDefault("setAverage", false)), - perturb_(dict.lookupOrDefault("perturb", 1e-5)), + perturb_(dict.lookupOrDefault("perturb", 1e-5)), pointsName_(dict.lookupOrDefault("points", "points")), mapMethod_ ( @@ -117,7 +117,7 @@ Foam::PatchFunction1Types::MappedFile::MappedFile endSampleTime_(-1), endSampledValues_(0), endAverage_(Zero), - offset_() + offset_(nullptr) { if (dict.found("offset")) { @@ -241,7 +241,7 @@ void Foam::PatchFunction1Types::MappedFile::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::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::value checkTable(x); auto tfld = tmp>::New(startSampledValues_.size()); - Field& fld = tfld.ref(); + auto& fld = tfld.ref(); Type wantedAverage; if (endSampleTime_ == -1) @@ -563,7 +562,7 @@ Foam::PatchFunction1Types::MappedFile::value } // Apply offset to mapped values - if (offset_.valid()) + if (offset_) { fld += offset_->value(x); } @@ -600,8 +599,8 @@ void Foam::PatchFunction1Types::MappedFile::writeData { PatchFunction1::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::writeData mapMethod_ ); - if (offset_.valid()) + if (offset_) { offset_->writeData(os); } diff --git a/src/meshTools/PatchFunction1/coordinateScaling.C b/src/meshTools/PatchFunction1/coordinateScaling.C index 0e9ba16440..5d5b6b3d77 100644 --- a/src/meshTools/PatchFunction1/coordinateScaling.C +++ b/src/meshTools/PatchFunction1/coordinateScaling.C @@ -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 Foam::coordinateScaling::coordinateScaling() : + coordSys_(nullptr), + scale_(), active_(false) {} @@ -49,9 +50,9 @@ Foam::coordinateScaling::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::coordinateScaling template -Foam::coordinateScaling::coordinateScaling(const coordinateScaling& cs) +Foam::coordinateScaling::coordinateScaling(const coordinateScaling& rhs) : - coordSys_(cs.coordSys_.clone()), - scale_(cs.scale_), - active_(cs.active_) -{} - - -// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // - -template -Foam::coordinateScaling::~coordinateScaling() + coordSys_(rhs.coordSys_.clone()), + scale_(rhs.scale_), + active_(rhs.active_) {} @@ -89,13 +83,13 @@ Foam::tmp> Foam::coordinateScaling::transform const Field& p0 ) const { - tmp> tfld(new Field(p0)); - Field& fld = tfld.ref(); + auto tfld = tmp>::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::coordinateScaling::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::coordinateScaling::transform ); } } - return fld; } + + return tfld; } template void Foam::coordinateScaling::writeEntry(Ostream& os) const { - if (coordSys_.valid()) + if (coordSys_) { coordSys_->writeEntry(coordinateSystem::typeName_(), os); } diff --git a/src/meshTools/PatchFunction1/coordinateScaling.H b/src/meshTools/PatchFunction1/coordinateScaling.H index 39cace6a7b..3804207e49 100644 --- a/src/meshTools/PatchFunction1/coordinateScaling.H +++ b/src/meshTools/PatchFunction1/coordinateScaling.H @@ -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 coordinateScaling { - // Private data + // Private Data - //- Local co-ordinate system + //- Local coordinate system const autoPtr coordSys_; - //- In local co-ordinate system component-wise scaling + //- In local coordinate system component-wise scaling PtrList> 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> coordinateScaling