diff --git a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedField.C b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedField.C index 305768d711e338f33a0c9422ef03a1c261070670..09e89bc28a9c5fc8a96ff75252c536f0a28d6281 100644 --- a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedField.C +++ b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedField.C @@ -28,12 +28,7 @@ License // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -namespace Foam -{ - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -// check mesh for two fields +// Check mesh for two fields #define checkField(df1, df2, op) \ if (&(df1).mesh() != &(df2).mesh()) \ { \ @@ -69,7 +64,7 @@ void Foam::DimensionedField<Type, GeoMesh>::checkFieldSize() const // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template<class Type, class GeoMesh> -DimensionedField<Type, GeoMesh>::DimensionedField +Foam::DimensionedField<Type, GeoMesh>::DimensionedField ( const IOobject& io, const Mesh& mesh, @@ -88,7 +83,26 @@ DimensionedField<Type, GeoMesh>::DimensionedField template<class Type, class GeoMesh> -DimensionedField<Type, GeoMesh>::DimensionedField +Foam::DimensionedField<Type, GeoMesh>::DimensionedField +( + const IOobject& io, + const Mesh& mesh, + const dimensionSet& dims, + Field<Type>&& field +) +: + regIOobject(io), + Field<Type>(std::move(field)), + mesh_(mesh), + dimensions_(dims) +{ + //Info<<"Move construct dimensioned for " << io.name() << nl; + checkFieldSize(); +} + + +template<class Type, class GeoMesh> +Foam::DimensionedField<Type, GeoMesh>::DimensionedField ( const IOobject& io, const Mesh& mesh, @@ -101,12 +115,13 @@ DimensionedField<Type, GeoMesh>::DimensionedField mesh_(mesh), dimensions_(dims) { + //Info<<"Move construct dimensioned for " << io.name() << nl; checkFieldSize(); } template<class Type, class GeoMesh> -DimensionedField<Type, GeoMesh>::DimensionedField +Foam::DimensionedField<Type, GeoMesh>::DimensionedField ( const IOobject& io, const Mesh& mesh, @@ -128,7 +143,7 @@ DimensionedField<Type, GeoMesh>::DimensionedField template<class Type, class GeoMesh> -DimensionedField<Type, GeoMesh>::DimensionedField +Foam::DimensionedField<Type, GeoMesh>::DimensionedField ( const IOobject& io, const Mesh& mesh, @@ -150,7 +165,7 @@ DimensionedField<Type, GeoMesh>::DimensionedField template<class Type, class GeoMesh> -DimensionedField<Type, GeoMesh>::DimensionedField +Foam::DimensionedField<Type, GeoMesh>::DimensionedField ( const DimensionedField<Type, GeoMesh>& df ) @@ -164,7 +179,7 @@ DimensionedField<Type, GeoMesh>::DimensionedField template<class Type, class GeoMesh> -DimensionedField<Type, GeoMesh>::DimensionedField +Foam::DimensionedField<Type, GeoMesh>::DimensionedField ( DimensionedField<Type, GeoMesh>& df, bool reuse @@ -179,7 +194,7 @@ DimensionedField<Type, GeoMesh>::DimensionedField template<class Type, class GeoMesh> -DimensionedField<Type, GeoMesh>::DimensionedField +Foam::DimensionedField<Type, GeoMesh>::DimensionedField ( DimensionedField<Type, GeoMesh>&& df ) @@ -194,7 +209,7 @@ DimensionedField<Type, GeoMesh>::DimensionedField #ifndef NoConstructFromTmp template<class Type, class GeoMesh> -DimensionedField<Type, GeoMesh>::DimensionedField +Foam::DimensionedField<Type, GeoMesh>::DimensionedField ( const tmp<DimensionedField<Type, GeoMesh>>& tdf ) @@ -211,7 +226,7 @@ DimensionedField<Type, GeoMesh>::DimensionedField template<class Type, class GeoMesh> -DimensionedField<Type, GeoMesh>::DimensionedField +Foam::DimensionedField<Type, GeoMesh>::DimensionedField ( const IOobject& io, const DimensionedField<Type, GeoMesh>& df @@ -226,7 +241,7 @@ DimensionedField<Type, GeoMesh>::DimensionedField template<class Type, class GeoMesh> -DimensionedField<Type, GeoMesh>::DimensionedField +Foam::DimensionedField<Type, GeoMesh>::DimensionedField ( const IOobject& io, DimensionedField<Type, GeoMesh>& df, @@ -242,7 +257,7 @@ DimensionedField<Type, GeoMesh>::DimensionedField template<class Type, class GeoMesh> -DimensionedField<Type, GeoMesh>::DimensionedField +Foam::DimensionedField<Type, GeoMesh>::DimensionedField ( const word& newName, const DimensionedField<Type, GeoMesh>& df @@ -257,7 +272,7 @@ DimensionedField<Type, GeoMesh>::DimensionedField template<class Type, class GeoMesh> -DimensionedField<Type, GeoMesh>::DimensionedField +Foam::DimensionedField<Type, GeoMesh>::DimensionedField ( const word& newName, DimensionedField<Type, GeoMesh>& df, @@ -273,7 +288,7 @@ DimensionedField<Type, GeoMesh>::DimensionedField template<class Type, class GeoMesh> -DimensionedField<Type, GeoMesh>::DimensionedField +Foam::DimensionedField<Type, GeoMesh>::DimensionedField ( const word& newName, DimensionedField<Type, GeoMesh>&& df @@ -289,7 +304,7 @@ DimensionedField<Type, GeoMesh>::DimensionedField #ifndef NoConstructFromTmp template<class Type, class GeoMesh> -DimensionedField<Type, GeoMesh>::DimensionedField +Foam::DimensionedField<Type, GeoMesh>::DimensionedField ( const word& newName, const tmp<DimensionedField<Type, GeoMesh>>& tdf @@ -307,63 +322,54 @@ DimensionedField<Type, GeoMesh>::DimensionedField template<class Type, class GeoMesh> -tmp<DimensionedField<Type, GeoMesh>> -DimensionedField<Type, GeoMesh>::clone() const +Foam::tmp<Foam::DimensionedField<Type, GeoMesh>> +Foam::DimensionedField<Type, GeoMesh>::clone() const { - return tmp<DimensionedField<Type, GeoMesh>> - ( - new DimensionedField<Type, GeoMesh>(*this) - ); + return tmp<DimensionedField<Type, GeoMesh>>::New(*this); } -// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // - -template<class Type, class GeoMesh> -DimensionedField<Type, GeoMesh>::~DimensionedField() -{} - - // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template<class Type, class GeoMesh> -tmp +Foam::tmp < - DimensionedField - <typename DimensionedField<Type, GeoMesh>::cmptType, GeoMesh> + Foam::DimensionedField + < + typename Foam::DimensionedField<Type, GeoMesh>::cmptType, GeoMesh + > > -DimensionedField<Type, GeoMesh>::component +Foam::DimensionedField<Type, GeoMesh>::component ( const direction d ) const { - tmp<DimensionedField<cmptType, GeoMesh>> result + auto tresult = tmp<DimensionedField<cmptType, GeoMesh>>::New ( - new DimensionedField<cmptType, GeoMesh> + IOobject ( - IOobject - ( - name() + ".component(" + ::Foam::name(d) + ')', - instance(), - db() - ), - mesh_, - dimensions_ - ) + name() + ".component(" + ::Foam::name(d) + ')', + instance(), + db() + ), + mesh_, + dimensions_ ); - Foam::component(result(), *this, d); + Foam::component(tresult(), *this, d); - return result; + return tresult; } template<class Type, class GeoMesh> -void DimensionedField<Type, GeoMesh>::replace +void Foam::DimensionedField<Type, GeoMesh>::replace ( const direction d, const DimensionedField - <typename DimensionedField<Type, GeoMesh>::cmptType, GeoMesh>& df + < + typename DimensionedField<Type, GeoMesh>::cmptType, GeoMesh + >& df ) { Field<Type>::replace(d, df); @@ -371,13 +377,15 @@ void DimensionedField<Type, GeoMesh>::replace template<class Type, class GeoMesh> -void DimensionedField<Type, GeoMesh>::replace +void Foam::DimensionedField<Type, GeoMesh>::replace ( const direction d, const tmp < DimensionedField - <typename DimensionedField<Type, GeoMesh>::cmptType, GeoMesh> + < + typename DimensionedField<Type, GeoMesh>::cmptType, GeoMesh + > >& tdf ) { @@ -387,78 +395,72 @@ void DimensionedField<Type, GeoMesh>::replace template<class Type, class GeoMesh> -tmp<DimensionedField<Type, GeoMesh>> -DimensionedField<Type, GeoMesh>::T() const +Foam::tmp<Foam::DimensionedField<Type, GeoMesh>> +Foam::DimensionedField<Type, GeoMesh>::T() const { - tmp<DimensionedField<Type, GeoMesh>> result + auto tresult = tmp<DimensionedField<Type, GeoMesh>>::New ( - new DimensionedField<Type, GeoMesh> + IOobject ( - IOobject - ( - name() + ".T()", - instance(), - db() - ), - mesh_, - dimensions_ - ) + name() + ".T()", + instance(), + db() + ), + mesh_, + dimensions_ ); - Foam::T(result(), *this); + Foam::T(tresult(), *this); - return result; + return tresult; } template<class Type, class GeoMesh> -dimensioned<Type> DimensionedField<Type, GeoMesh>::average() const +Foam::dimensioned<Type> Foam::DimensionedField<Type, GeoMesh>::average() const { - dimensioned<Type> Average - ( - this->name() + ".average()", - this->dimensions(), - gAverage(field()) - ); - - return Average; + return + dimensioned<Type> + ( + this->name() + ".average()", + this->dimensions(), + gAverage(field()) + ); } template<class Type, class GeoMesh> -dimensioned<Type> DimensionedField<Type, GeoMesh>::weightedAverage +Foam::dimensioned<Type> Foam::DimensionedField<Type, GeoMesh>::weightedAverage ( const DimensionedField<scalar, GeoMesh>& weightField ) const { return - ( dimensioned<Type> ( this->name() + ".weightedAverage(weights)", this->dimensions(), gSum(weightField*field())/gSum(weightField) - ) - ); + ); } template<class Type, class GeoMesh> -dimensioned<Type> DimensionedField<Type, GeoMesh>::weightedAverage +Foam::dimensioned<Type> Foam::DimensionedField<Type, GeoMesh>::weightedAverage ( const tmp<DimensionedField<scalar, GeoMesh>>& tweightField ) const { - dimensioned<Type> wa = weightedAverage(tweightField()); + dimensioned<Type> result = weightedAverage(tweightField()); tweightField.clear(); - return wa; + return result; } // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // template<class Type, class GeoMesh> -void DimensionedField<Type, GeoMesh>::operator= +void Foam::DimensionedField<Type, GeoMesh>::operator= ( const DimensionedField<Type, GeoMesh>& df ) @@ -480,7 +482,7 @@ void DimensionedField<Type, GeoMesh>::operator= template<class Type, class GeoMesh> -void DimensionedField<Type, GeoMesh>::operator= +void Foam::DimensionedField<Type, GeoMesh>::operator= ( const tmp<DimensionedField<Type, GeoMesh>>& tdf ) @@ -505,7 +507,7 @@ void DimensionedField<Type, GeoMesh>::operator= template<class Type, class GeoMesh> -void DimensionedField<Type, GeoMesh>::operator= +void Foam::DimensionedField<Type, GeoMesh>::operator= ( const dimensioned<Type>& dt ) @@ -518,7 +520,7 @@ void DimensionedField<Type, GeoMesh>::operator= #define COMPUTED_ASSIGNMENT(TYPE, op) \ \ template<class Type, class GeoMesh> \ -void DimensionedField<Type, GeoMesh>::operator op \ +void Foam::DimensionedField<Type, GeoMesh>::operator op \ ( \ const DimensionedField<TYPE, GeoMesh>& df \ ) \ @@ -531,7 +533,7 @@ void DimensionedField<Type, GeoMesh>::operator op \ } \ \ template<class Type, class GeoMesh> \ -void DimensionedField<Type, GeoMesh>::operator op \ +void Foam::DimensionedField<Type, GeoMesh>::operator op \ ( \ const tmp<DimensionedField<TYPE, GeoMesh>>& tdf \ ) \ @@ -541,7 +543,7 @@ void DimensionedField<Type, GeoMesh>::operator op \ } \ \ template<class Type, class GeoMesh> \ -void DimensionedField<Type, GeoMesh>::operator op \ +void Foam::DimensionedField<Type, GeoMesh>::operator op \ ( \ const dimensioned<TYPE>& dt \ ) \ @@ -557,17 +559,12 @@ COMPUTED_ASSIGNMENT(scalar, /=) #undef COMPUTED_ASSIGNMENT - // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #undef checkField // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -} // End namespace Foam - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - #include "DimensionedFieldIO.C" #include "DimensionedFieldFunctions.C" diff --git a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedField.H b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedField.H index 6fbeeb80ac87f66ff0bad46a6e57e2a29c8db970..23d721f203005b63389b900dac1db0d717a28c01 100644 --- a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedField.H +++ b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedField.H @@ -75,10 +75,9 @@ class DimensionedField public regIOobject, public Field<Type> { - public: - // Public typedefs + // Public Typedefs //- Type of mesh on which this DimensionedField is instantiated typedef typename GeoMesh::Mesh Mesh; @@ -120,7 +119,7 @@ public: // Static Member Functions - //- Return a null DimensionedField + //- Return a NullObjectRef DimensionedField inline static const DimensionedField<Type, GeoMesh>& null(); @@ -135,7 +134,16 @@ public: const Field<Type>& field ); - //- Construct from components, transferring the initial field content + //- Construct from components, transferring initial field content + DimensionedField + ( + const IOobject& io, + const Mesh& mesh, + const dimensionSet& dims, + Field<Type>&& field + ); + + //- Construct from components, transferring initial field content DimensionedField ( const IOobject& io, @@ -261,7 +269,7 @@ public: //- Destructor - virtual ~DimensionedField(); + virtual ~DimensionedField() = default; // Member Functions diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.C b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.C index ba6c8d1c391c06549eb8de8ccb462ff091f35a1b..d6fbc678db75a10bfc7e38f7c6b4b703478280b2 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.C +++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.C @@ -159,11 +159,8 @@ bool Foam::GeometricField<Type, PatchField, GeoMesh>::readOldTimeIfPresent() ) ) { - if (debug) - { - InfoInFunction << "Reading old time level for field" - << endl << this->info() << endl; - } + DebugInFunction + << "Reading old time level for field" << nl << this->info() << endl; field0Ptr_ = new GeometricField<Type, PatchField, GeoMesh> ( @@ -207,10 +204,8 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField fieldPrevIterPtr_(nullptr), boundaryField_(mesh.boundary(), *this, patchFieldType) { - if (debug) - { - InfoInFunction << "Creating temporary" << endl << this->info() << endl; - } + DebugInFunction + << "Creating temporary" << nl << this->info() << endl; readIfPresent(); } @@ -232,10 +227,8 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField fieldPrevIterPtr_(nullptr), boundaryField_(mesh.boundary(), *this, patchFieldTypes, actualPatchTypes) { - if (debug) - { - InfoInFunction << "Creating temporary" << endl << this->info() << endl; - } + DebugInFunction + << "Creating temporary" << nl << this->info() << endl; readIfPresent(); } @@ -256,10 +249,8 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField fieldPrevIterPtr_(nullptr), boundaryField_(mesh.boundary(), *this, patchFieldType) { - if (debug) - { - InfoInFunction << "Creating temporary" << endl << this->info() << endl; - } + DebugInFunction + << "Creating temporary" << nl << this->info() << endl; boundaryField_ == dt.value(); @@ -283,10 +274,8 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField fieldPrevIterPtr_(nullptr), boundaryField_(mesh.boundary(), *this, patchFieldTypes, actualPatchTypes) { - if (debug) - { - InfoInFunction << "Creating temporary" << endl << this->info() << endl; - } + DebugInFunction + << "Creating temporary" << nl << this->info() << endl; boundaryField_ == dt.value(); @@ -308,11 +297,8 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField fieldPrevIterPtr_(nullptr), boundaryField_(this->mesh().boundary(), *this, ptfl) { - if (debug) - { - InfoInFunction - << "Constructing from components" << endl << this->info() << endl; - } + DebugInFunction + << "Copy construct from components" << nl << this->info() << endl; readIfPresent(); } @@ -334,11 +320,54 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField fieldPrevIterPtr_(nullptr), boundaryField_(mesh.boundary(), *this, ptfl) { - if (debug) - { - InfoInFunction - << "Constructing from components" << endl << this->info() << endl; - } + DebugInFunction + << "Copy construct from components" << nl << this->info() << endl; + + readIfPresent(); +} + + +template<class Type, template<class> class PatchField, class GeoMesh> +Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField +( + const IOobject& io, + const Mesh& mesh, + const dimensionSet& ds, + Field<Type>&& iField, + const PtrList<PatchField<Type>>& ptfl +) +: + Internal(io, mesh, ds, std::move(iField)), + timeIndex_(this->time().timeIndex()), + field0Ptr_(nullptr), + fieldPrevIterPtr_(nullptr), + boundaryField_(mesh.boundary(), *this, ptfl) +{ + DebugInFunction + << "Move construct from components" << nl << this->info() << endl; + + readIfPresent(); +} + + +template<class Type, template<class> class PatchField, class GeoMesh> +Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField +( + const IOobject& io, + const Mesh& mesh, + const dimensionSet& ds, + List<Type>&& iField, + const PtrList<PatchField<Type>>& ptfl +) +: + Internal(io, mesh, ds, std::move(iField)), + timeIndex_(this->time().timeIndex()), + field0Ptr_(nullptr), + fieldPrevIterPtr_(nullptr), + boundaryField_(mesh.boundary(), *this, ptfl) +{ + DebugInFunction + << "Move construct from components" << nl << this->info() << endl; readIfPresent(); } @@ -375,11 +404,8 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField readOldTimeIfPresent(); } - if (debug) - { - InfoInFunction - << "Finishing read-construction of" << endl << this->info() << endl; - } + DebugInFunction + << "Finishing read-construction" << nl << this->info() << endl; } @@ -409,12 +435,8 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField << exit(FatalIOError); } - if (debug) - { - InfoInFunction - << "Finishing dictionary-construct of " - << endl << this->info() << endl; - } + DebugInFunction + << "Finishing dictionary-construct" << nl << this->info() << endl; } @@ -430,11 +452,8 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField fieldPrevIterPtr_(nullptr), boundaryField_(*this, gf.boundaryField_) { - if (debug) - { - InfoInFunction - << "Constructing as copy" << endl << this->info() << endl; - } + DebugInFunction + << "Copy construct" << nl << this->info() << endl; if (gf.field0Ptr_) { @@ -461,11 +480,8 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField fieldPrevIterPtr_(nullptr), boundaryField_(*this, tgf().boundaryField_) { - if (debug) - { - InfoInFunction - << "Constructing from tmp" << endl << this->info() << endl; - } + DebugInFunction + << "Constructing from tmp" << nl << this->info() << endl; this->writeOpt() = IOobject::NO_WRITE; @@ -487,12 +503,9 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField fieldPrevIterPtr_(nullptr), boundaryField_(*this, gf.boundaryField_) { - if (debug) - { - InfoInFunction - << "Constructing as copy resetting IO params" - << endl << this->info() << endl; - } + DebugInFunction + << "Copy construct, resetting IO params" << nl + << this->info() << endl; if (!readIfPresent() && gf.field0Ptr_) { @@ -519,12 +532,9 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField fieldPrevIterPtr_(nullptr), boundaryField_(*this, tgf().boundaryField_) { - if (debug) - { - InfoInFunction - << "Constructing from tmp resetting IO params" - << endl << this->info() << endl; - } + DebugInFunction + << "Constructing from tmp resetting IO params" << nl + << this->info() << endl; tgf.clear(); @@ -546,12 +556,9 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField fieldPrevIterPtr_(nullptr), boundaryField_(*this, gf.boundaryField_) { - if (debug) - { - InfoInFunction - << "Constructing as copy resetting name" - << endl << this->info() << endl; - } + DebugInFunction + << "Copy construct, resetting name" << nl + << this->info() << endl; if (!readIfPresent() && gf.field0Ptr_) { @@ -578,12 +585,9 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField fieldPrevIterPtr_(nullptr), boundaryField_(*this, tgf().boundaryField_) { - if (debug) - { - InfoInFunction - << "Constructing from tmp resetting name" - << endl << this->info() << endl; - } + DebugInFunction + << "Constructing from tmp resetting name" << nl + << this->info() << endl; tgf.clear(); } @@ -604,12 +608,9 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField fieldPrevIterPtr_(nullptr), boundaryField_(this->mesh().boundary(), *this, patchFieldType) { - if (debug) - { - InfoInFunction - << "Constructing as copy resetting IO params" - << endl << this->info() << endl; - } + DebugInFunction + << "Copy construct, resetting IO params" << nl + << this->info() << endl; boundaryField_ == gf.boundaryField_; @@ -645,12 +646,9 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField actualPatchTypes ) { - if (debug) - { - InfoInFunction - << "Constructing as copy resetting IO params and patch types" - << endl << this->info() << endl; - } + DebugInFunction + << "Copy construct, resetting IO params and patch types" << nl + << this->info() << endl; boundaryField_ == gf.boundaryField_; @@ -687,12 +685,9 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField actualPatchTypes ) { - if (debug) - { - InfoInFunction - << "Constructing from tmp resetting IO params and patch types" - << endl << this->info() << endl; - } + DebugInFunction + << "Constructing from tmp resetting IO params and patch types" << nl + << this->info() << endl; boundaryField_ == tgf().boundaryField_; @@ -705,10 +700,7 @@ template<class Type, template<class> class PatchField, class GeoMesh> Foam::tmp<Foam::GeometricField<Type, PatchField, GeoMesh>> Foam::GeometricField<Type, PatchField, GeoMesh>::clone() const { - return tmp<GeometricField<Type, PatchField, GeoMesh>> - ( - new GeometricField<Type, PatchField, GeoMesh>(*this) - ); + return tmp<GeometricField<Type, PatchField, GeoMesh>>::New(*this); } @@ -783,12 +775,8 @@ void Foam::GeometricField<Type, PatchField, GeoMesh>::storeOldTime() const { field0Ptr_->storeOldTime(); - if (debug) - { - InfoInFunction - << "Storing old time field for field" << endl - << this->info() << endl; - } + DebugInFunction + << "Storing old time field for field" << nl << this->info() << endl; *field0Ptr_ == *this; field0Ptr_->timeIndex_ = timeIndex_; @@ -871,12 +859,9 @@ void Foam::GeometricField<Type, PatchField, GeoMesh>::storePrevIter() const { if (!fieldPrevIterPtr_) { - if (debug) - { - InfoInFunction - << "Allocating previous iteration field" << endl - << this->info() << endl; - } + DebugInFunction + << "Allocating previous iteration field" << nl + << this->info() << endl; fieldPrevIterPtr_ = new GeometricField<Type, PatchField, GeoMesh> ( @@ -944,11 +929,8 @@ bool Foam::GeometricField<Type, PatchField, GeoMesh>::needReference() const template<class Type, template<class> class PatchField, class GeoMesh> void Foam::GeometricField<Type, PatchField, GeoMesh>::relax(const scalar alpha) { - if (debug) - { - InfoInFunction - << "Relaxing" << endl << this->info() << " by " << alpha << endl; - } + DebugInFunction + << "Relaxing" << nl << this->info() << " by " << alpha << endl; operator==(prevIter() + alpha*(*this - prevIter())); } @@ -1185,15 +1167,15 @@ void Foam::GeometricField<Type, PatchField, GeoMesh>::operator= const tmp<GeometricField<Type, PatchField, GeoMesh>>& tgf ) { - if (this == &(tgf())) + const auto& gf = tgf(); + + if (this == &gf) { FatalErrorInFunction << "attempted assignment to self" << abort(FatalError); } - const GeometricField<Type, PatchField, GeoMesh>& gf = tgf(); - checkField(*this, gf, "="); // Only assign field contents not ID @@ -1203,11 +1185,8 @@ void Foam::GeometricField<Type, PatchField, GeoMesh>::operator= if (tgf.movable()) { - // Transfer the storage from the tmp - primitiveFieldRef().transfer - ( - const_cast<Field<Type>&>(gf.primitiveField()) - ); + // Transfer storage from the tmp + primitiveFieldRef().transfer(tgf.constCast().primitiveFieldRef()); } else { @@ -1237,7 +1216,7 @@ void Foam::GeometricField<Type, PatchField, GeoMesh>::operator== const tmp<GeometricField<Type, PatchField, GeoMesh>>& tgf ) { - const GeometricField<Type, PatchField, GeoMesh>& gf = tgf(); + const auto& gf = tgf(); checkField(*this, gf, "=="); diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.H b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.H index 202065d2a8f69e4c358389e3ba662b370888620c..b847f01c8bf40278e36d64d216aa02f2bb561376 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.H +++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.H @@ -298,7 +298,7 @@ public: const IOobject& io, const Mesh& mesh, const dimensionSet& ds, - const word& patchFieldType=PatchField<Type>::calculatedType() + const word& patchFieldType = PatchField<Type>::calculatedType() ); //- Construct given IOobject, mesh, dimensions and patch types. @@ -321,7 +321,7 @@ public: const IOobject& io, const Mesh& mesh, const dimensioned<Type>& dt, - const word& patchFieldType=PatchField<Type>::calculatedType() + const word& patchFieldType = PatchField<Type>::calculatedType() ); //- Construct given IOobject, mesh, dimensioned<Type> and patch types. @@ -336,7 +336,7 @@ public: const wordList& actualPatchTypes = wordList() ); - //- Constructor from components + //- Copy construct from components GeometricField ( const IOobject& io, @@ -344,7 +344,7 @@ public: const PtrList<PatchField<Type>>& ptfl ); - //- Constructor from components + //- Copy construct from components GeometricField ( const IOobject& io, @@ -354,6 +354,26 @@ public: const PtrList<PatchField<Type>>& ptfl ); + //- Construct from components, moving initial internal field + GeometricField + ( + const IOobject& io, + const Mesh& mesh, + const dimensionSet& ds, + Field<Type>&& iField, + const PtrList<PatchField<Type>>& ptfl + ); + + //- Construct from components, moving initial internal field + GeometricField + ( + const IOobject& io, + const Mesh& mesh, + const dimensionSet& ds, + List<Type>&& iField, + const PtrList<PatchField<Type>>& ptfl + ); + //- Construct and read given IOobject GeometricField ( diff --git a/src/dynamicMesh/fvMeshSubset/fvMeshSubsetInterpolate.C b/src/dynamicMesh/fvMeshSubset/fvMeshSubsetInterpolate.C index df9ec2aacfb622cc2a12ef892f2b0a8103731cc9..b65dbea1dcd573b3084773f6d26efac9c5891ca0 100644 --- a/src/dynamicMesh/fvMeshSubset/fvMeshSubsetInterpolate.C +++ b/src/dynamicMesh/fvMeshSubset/fvMeshSubsetInterpolate.C @@ -96,6 +96,7 @@ fvMeshSubset::interpolate ), sMesh, vf.dimensions(), + // Move construct for internal field Field<Type>(vf.primitiveField(), cellMap), patchFields ); @@ -231,14 +232,11 @@ fvMeshSubset::interpolate ), sMesh, vf.dimensions(), + // Move construct for internal field Field<Type> ( vf.primitiveField(), - SubList<label> - ( - faceMap, - sMesh.nInternalFaces() - ) + SubList<label>(faceMap, sMesh.nInternalFaces()) ), patchFields ); @@ -411,6 +409,7 @@ fvMeshSubset::interpolate ), sMesh, vf.dimensions(), + // Move construct for internal field Field<Type>(vf.primitiveField(), pointMap), patchFields );