diff --git a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedField.C b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedField.C index 166f7941faa2c92e160742415550ecc4c4112602..5823ee3f57c1ea360c962e4119788cf50acd18d4 100644 --- a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedField.C +++ b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedField.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -45,6 +45,27 @@ if (&(df1).mesh() != &(df2).mesh()) \ } +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +template<class Type, class GeoMesh> +void Foam::DimensionedField<Type, GeoMesh>::checkFieldSize() const +{ + const label fieldSize = this->size(); + if (fieldSize) + { + const label meshSize = GeoMesh::size(this->mesh_); + if (fieldSize != meshSize) + { + FatalErrorInFunction + << "size of field = " << fieldSize + << " is not the same as the size of mesh = " + << meshSize + << abort(FatalError); + } + } +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template<class Type, class GeoMesh> @@ -61,14 +82,43 @@ DimensionedField<Type, GeoMesh>::DimensionedField mesh_(mesh), dimensions_(dims) { - if (field.size() && field.size() != GeoMesh::size(mesh)) - { - FatalErrorInFunction - << "size of field = " << field.size() - << " is not the same as the size of mesh = " - << GeoMesh::size(mesh) - << abort(FatalError); - } + checkFieldSize(); +} + + +template<class Type, class GeoMesh> +DimensionedField<Type, GeoMesh>::DimensionedField +( + const IOobject& io, + const Mesh& mesh, + const dimensionSet& dims, + const Xfer<Field<Type>>& field +) +: + regIOobject(io), + Field<Type>(field), + mesh_(mesh), + dimensions_(dims) +{ + checkFieldSize(); +} + + +template<class Type, class GeoMesh> +DimensionedField<Type, GeoMesh>::DimensionedField +( + const IOobject& io, + const Mesh& mesh, + const dimensionSet& dims, + const Xfer<List<Type>>& field +) +: + regIOobject(io), + Field<Type>(field), + mesh_(mesh), + dimensions_(dims) +{ + checkFieldSize(); } diff --git a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedField.H b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedField.H index a302e5417109f12547e40f8c15d1768e3115953b..b37c63724fcc35b71d80e2f131b78ede67087687 100644 --- a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedField.H +++ b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedField.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -53,14 +53,14 @@ template<class Type, class GeoMesh> class DimensionedField; template<class Type, class GeoMesh> Ostream& operator<< ( - Ostream&, - const DimensionedField<Type, GeoMesh>& + Ostream& os, + const DimensionedField<Type, GeoMesh>& df ); template<class Type, class GeoMesh> Ostream& operator<< ( - Ostream&, - const tmp<DimensionedField<Type, GeoMesh>>& + Ostream& os, + const tmp<DimensionedField<Type, GeoMesh>>& tdf ); @@ -102,6 +102,9 @@ private: // Private Member Functions + //- Assert that non-zero field size == mesh size + void checkFieldSize() const; + void readIfPresent(const word& fieldDictEntry = "value"); @@ -122,87 +125,105 @@ public: //- Construct from components DimensionedField ( - const IOobject&, + const IOobject& io, const Mesh& mesh, - const dimensionSet&, - const Field<Type>& + const dimensionSet& dims, + const Field<Type>& field + ); + + //- Construct from components, transferring the initial field content + DimensionedField + ( + const IOobject& io, + const Mesh& mesh, + const dimensionSet& dims, + const Xfer<Field<Type>>& field + ); + + //- Construct from components, transferring the initial field content + DimensionedField + ( + const IOobject& io, + const Mesh& mesh, + const dimensionSet& dims, + const Xfer<List<Type>>& field ); //- Construct from components // Used for temporary fields which are initialised after construction DimensionedField ( - const IOobject&, + const IOobject& io, const Mesh& mesh, - const dimensionSet&, + const dimensionSet& dims, const bool checkIOFlags = true ); //- Construct from components DimensionedField ( - const IOobject&, + const IOobject& io, const Mesh& mesh, - const dimensioned<Type>&, + const dimensioned<Type>& dt, const bool checkIOFlags = true ); //- Construct from Istream DimensionedField ( - const IOobject&, + const IOobject& io, const Mesh& mesh, - const word& fieldDictEntry="value" + const word& fieldDictEntry = "value" ); //- Construct from dictionary DimensionedField ( - const IOobject&, + const IOobject& io, const Mesh& mesh, const dictionary& fieldDict, - const word& fieldDictEntry="value" + const word& fieldDictEntry = "value" ); //- Construct as copy DimensionedField ( - const DimensionedField<Type, GeoMesh>& + const DimensionedField<Type, GeoMesh>& df ); //- Construct as copy or re-use as specified. DimensionedField ( - DimensionedField<Type, GeoMesh>&, + DimensionedField<Type, GeoMesh>& df, bool reuse ); //- Construct by transferring the DimensionedField DimensionedField ( - const Xfer<DimensionedField<Type, GeoMesh>>& + const Xfer<DimensionedField<Type, GeoMesh>>& df ); //- Construct as copy of tmp<DimensionedField> deleting argument #ifndef NoConstructFromTmp DimensionedField ( - const tmp<DimensionedField<Type, GeoMesh>>& + const tmp<DimensionedField<Type, GeoMesh>>& tdf ); #endif //- Construct as copy resetting IO parameters DimensionedField ( - const IOobject&, - const DimensionedField<Type, GeoMesh>& + const IOobject& io, + const DimensionedField<Type, GeoMesh>& df ); //- Construct as copy resetting IO parameters and re-use as specified. DimensionedField ( - const IOobject&, - DimensionedField<Type, GeoMesh>&, + const IOobject& io, + DimensionedField<Type, GeoMesh>& df, bool reuse ); @@ -210,14 +231,14 @@ public: DimensionedField ( const word& newName, - const DimensionedField<Type, GeoMesh>& + const DimensionedField<Type, GeoMesh>& df ); //- Construct as copy resetting name and re-use as specified. DimensionedField ( const word& newName, - DimensionedField<Type, GeoMesh>&, + DimensionedField<Type, GeoMesh>& df, bool reuse ); @@ -225,7 +246,7 @@ public: DimensionedField ( const word& newName, - const Xfer<DimensionedField<Type, GeoMesh>>& + const Xfer<DimensionedField<Type, GeoMesh>>& df ); //- Construct as copy resetting name @@ -233,7 +254,7 @@ public: DimensionedField ( const word& newName, - const tmp<DimensionedField<Type, GeoMesh>>& + const tmp<DimensionedField<Type, GeoMesh>>& tdf ); #endif @@ -262,28 +283,30 @@ public: //- Return non-const access to dimensions inline dimensionSet& dimensions(); + //- Return field inline const Field<Type>& field() const; + //- Return field inline Field<Type>& field(); //- Return a component field of the field tmp<DimensionedField<cmptType, GeoMesh>> component ( - const direction + const direction d ) const; //- Replace a component field of the field void replace ( - const direction, - const DimensionedField<cmptType, GeoMesh>& + const direction d, + const DimensionedField<cmptType, GeoMesh>& df ); //- Replace a component field of the field void replace ( - const direction, - const tmp<DimensionedField<cmptType, GeoMesh>>& + const direction d, + const tmp<DimensionedField<cmptType, GeoMesh>>& tdf ); //- Return the field transpose (only defined for second rank tensors) @@ -295,60 +318,60 @@ public: //- Calculate and return weighted average dimensioned<Type> weightedAverage ( - const DimensionedField<scalar, GeoMesh>& + const DimensionedField<scalar, GeoMesh>& weightField ) const; //- Calculate and return weighted average dimensioned<Type> weightedAverage ( - const tmp<DimensionedField<scalar, GeoMesh>>& + const tmp<DimensionedField<scalar, GeoMesh>>& tweightField ) const; // Write - bool writeData(Ostream&, const word& fieldDictEntry) const; + bool writeData(Ostream& os, const word& fieldDictEntry) const; - bool writeData(Ostream&) const; + bool writeData(Ostream& os) const; // Member Operators - void operator=(const DimensionedField<Type, GeoMesh>&); - void operator=(const tmp<DimensionedField<Type, GeoMesh>>&); - void operator=(const dimensioned<Type>&); + void operator=(const DimensionedField<Type, GeoMesh>& df); + void operator=(const tmp<DimensionedField<Type, GeoMesh>>& tdf); + void operator=(const dimensioned<Type>& dt); - void operator+=(const DimensionedField<Type, GeoMesh>&); - void operator+=(const tmp<DimensionedField<Type, GeoMesh>>&); + void operator+=(const DimensionedField<Type, GeoMesh>& df); + void operator+=(const tmp<DimensionedField<Type, GeoMesh>>& tdf); - void operator-=(const DimensionedField<Type, GeoMesh>&); - void operator-=(const tmp<DimensionedField<Type, GeoMesh>>&); + void operator-=(const DimensionedField<Type, GeoMesh>& df); + void operator-=(const tmp<DimensionedField<Type, GeoMesh>>& tdf); - void operator*=(const DimensionedField<scalar, GeoMesh>&); - void operator*=(const tmp<DimensionedField<scalar, GeoMesh>>&); + void operator*=(const DimensionedField<scalar, GeoMesh>& df); + void operator*=(const tmp<DimensionedField<scalar, GeoMesh>>& tdf); - void operator/=(const DimensionedField<scalar, GeoMesh>&); - void operator/=(const tmp<DimensionedField<scalar, GeoMesh>>&); + void operator/=(const DimensionedField<scalar, GeoMesh>& df); + void operator/=(const tmp<DimensionedField<scalar, GeoMesh>>& tdf); - void operator+=(const dimensioned<Type>&); - void operator-=(const dimensioned<Type>&); + void operator+=(const dimensioned<Type>& dt); + void operator-=(const dimensioned<Type>& dt); - void operator*=(const dimensioned<scalar>&); - void operator/=(const dimensioned<scalar>&); + void operator*=(const dimensioned<scalar>& dt); + void operator/=(const dimensioned<scalar>& dt); // Ostream Operators friend Ostream& operator<< <Type, GeoMesh> ( - Ostream&, - const DimensionedField<Type, GeoMesh>& + Ostream& os, + const DimensionedField<Type, GeoMesh>& df ); friend Ostream& operator<< <Type, GeoMesh> ( - Ostream&, - const tmp<DimensionedField<Type, GeoMesh>>& + Ostream& os, + const tmp<DimensionedField<Type, GeoMesh>>& tdf ); }; diff --git a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldFunctionsM.H b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldFunctionsM.H index 444192f399af9f316cd8041a99eb9a80545d497a..5932562ebf660c9e0c6753d27e5717b51a07fcd7 100644 --- a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldFunctionsM.H +++ b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldFunctionsM.H @@ -194,7 +194,7 @@ tmp<DimensionedField<ReturnType, GeoMesh>> operator Op \ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -#define BINARY_TYPE_OPERATOR_SF(ReturnType, Type1, Type2, Op, OpName, OpFunc) \ +#define BINARY_TYPE_OPERATOR_SF(ReturnType, Type1, Type2, Op, OpName, OpFunc) \ \ TEMPLATE \ tmp<DimensionedField<ReturnType, GeoMesh>> operator Op \ @@ -225,7 +225,7 @@ tmp<DimensionedField<ReturnType, GeoMesh>> operator Op \ ); -#define BINARY_TYPE_OPERATOR_FS(ReturnType, Type1, Type2, Op, OpName, OpFunc) \ +#define BINARY_TYPE_OPERATOR_FS(ReturnType, Type1, Type2, Op, OpName, OpFunc) \ \ TEMPLATE \ tmp<DimensionedField<ReturnType, GeoMesh>> operator Op \ diff --git a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/SubDimensionedField.H b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/SubDimensionedField.H index e0e4282fb4f0757a7eafda10c4532d9968c2c118..1f90a784ab2a3e8bf4926bf8c90dcfcd21e49a82 100644 --- a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/SubDimensionedField.H +++ b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/SubDimensionedField.H @@ -105,7 +105,7 @@ public: //- Return a component field of the field inline tmp<DimensionedField<cmptType, GeoMesh>> component ( - const direction + const direction d ) const; //- Return the field transpose (only defined for second rank tensors) @@ -115,7 +115,7 @@ public: // Member operators //- Assignment - inline void operator=(const SubDimensionedField<Type, GeoMesh>&); + inline void operator=(const SubDimensionedField<Type, GeoMesh>& rhs); //- Allow cast to a const DimensionedField<Type, GeoMesh>& inline operator const DimensionedField<Type, GeoMesh>&() const; diff --git a/src/OpenFOAM/memory/Xfer/Xfer.H b/src/OpenFOAM/memory/Xfer/Xfer.H index 0c5e8e8cff0fd789779625335c5f11aa5fc49871..615712d610158e7e7e204fa44d78fa71be1b7a6e 100644 --- a/src/OpenFOAM/memory/Xfer/Xfer.H +++ b/src/OpenFOAM/memory/Xfer/Xfer.H @@ -93,20 +93,23 @@ class Xfer public: + typedef T Type; + + // Constructors //- Store object pointer and manage its deletion // Can also be used later to transfer by assignment - inline explicit Xfer(T* = 0); + inline explicit Xfer(T* p = 0); //- Construct by copying or by transferring the parameter contents - inline explicit Xfer(T&, bool allowTransfer=false); + inline explicit Xfer(T& t, bool allowTransfer=false); //- Construct by copying the parameter contents - inline explicit Xfer(const T&); + inline explicit Xfer(const T& t); //- Construct by transferring the contents - inline Xfer(const Xfer<T>&); + inline Xfer(const Xfer<T>& t); //- Destructor @@ -122,10 +125,10 @@ public: // Member Operators //- Transfer the contents into the object - inline void operator=(T&); + inline void operator=(T& t); //- Transfer the contents into the object - inline void operator=(const Xfer<T>&); + inline void operator=(const Xfer<T>& t); //- Reference to the underlying datatype inline T& operator()() const;