mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: support DimensionedField construction with Xfer
- can be used to reduce copying
This commit is contained in:
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
|
\\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
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 * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
template<class Type, class GeoMesh>
|
template<class Type, class GeoMesh>
|
||||||
@ -61,14 +82,43 @@ DimensionedField<Type, GeoMesh>::DimensionedField
|
|||||||
mesh_(mesh),
|
mesh_(mesh),
|
||||||
dimensions_(dims)
|
dimensions_(dims)
|
||||||
{
|
{
|
||||||
if (field.size() && field.size() != GeoMesh::size(mesh))
|
checkFieldSize();
|
||||||
{
|
|
||||||
FatalErrorInFunction
|
|
||||||
<< "size of field = " << field.size()
|
|
||||||
<< " is not the same as the size of mesh = "
|
|
||||||
<< GeoMesh::size(mesh)
|
|
||||||
<< abort(FatalError);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||||
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
|
\\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -53,14 +53,14 @@ template<class Type, class GeoMesh> class DimensionedField;
|
|||||||
|
|
||||||
template<class Type, class GeoMesh> Ostream& operator<<
|
template<class Type, class GeoMesh> Ostream& operator<<
|
||||||
(
|
(
|
||||||
Ostream&,
|
Ostream& os,
|
||||||
const DimensionedField<Type, GeoMesh>&
|
const DimensionedField<Type, GeoMesh>& df
|
||||||
);
|
);
|
||||||
|
|
||||||
template<class Type, class GeoMesh> Ostream& operator<<
|
template<class Type, class GeoMesh> Ostream& operator<<
|
||||||
(
|
(
|
||||||
Ostream&,
|
Ostream& os,
|
||||||
const tmp<DimensionedField<Type, GeoMesh>>&
|
const tmp<DimensionedField<Type, GeoMesh>>& tdf
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
@ -102,6 +102,9 @@ private:
|
|||||||
|
|
||||||
// Private Member Functions
|
// Private Member Functions
|
||||||
|
|
||||||
|
//- Assert that non-zero field size == mesh size
|
||||||
|
void checkFieldSize() const;
|
||||||
|
|
||||||
void readIfPresent(const word& fieldDictEntry = "value");
|
void readIfPresent(const word& fieldDictEntry = "value");
|
||||||
|
|
||||||
|
|
||||||
@ -122,35 +125,53 @@ public:
|
|||||||
//- Construct from components
|
//- Construct from components
|
||||||
DimensionedField
|
DimensionedField
|
||||||
(
|
(
|
||||||
const IOobject&,
|
const IOobject& io,
|
||||||
const Mesh& mesh,
|
const Mesh& mesh,
|
||||||
const dimensionSet&,
|
const dimensionSet& dims,
|
||||||
const Field<Type>&
|
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
|
//- Construct from components
|
||||||
// Used for temporary fields which are initialised after construction
|
// Used for temporary fields which are initialised after construction
|
||||||
DimensionedField
|
DimensionedField
|
||||||
(
|
(
|
||||||
const IOobject&,
|
const IOobject& io,
|
||||||
const Mesh& mesh,
|
const Mesh& mesh,
|
||||||
const dimensionSet&,
|
const dimensionSet& dims,
|
||||||
const bool checkIOFlags = true
|
const bool checkIOFlags = true
|
||||||
);
|
);
|
||||||
|
|
||||||
//- Construct from components
|
//- Construct from components
|
||||||
DimensionedField
|
DimensionedField
|
||||||
(
|
(
|
||||||
const IOobject&,
|
const IOobject& io,
|
||||||
const Mesh& mesh,
|
const Mesh& mesh,
|
||||||
const dimensioned<Type>&,
|
const dimensioned<Type>& dt,
|
||||||
const bool checkIOFlags = true
|
const bool checkIOFlags = true
|
||||||
);
|
);
|
||||||
|
|
||||||
//- Construct from Istream
|
//- Construct from Istream
|
||||||
DimensionedField
|
DimensionedField
|
||||||
(
|
(
|
||||||
const IOobject&,
|
const IOobject& io,
|
||||||
const Mesh& mesh,
|
const Mesh& mesh,
|
||||||
const word& fieldDictEntry = "value"
|
const word& fieldDictEntry = "value"
|
||||||
);
|
);
|
||||||
@ -158,7 +179,7 @@ public:
|
|||||||
//- Construct from dictionary
|
//- Construct from dictionary
|
||||||
DimensionedField
|
DimensionedField
|
||||||
(
|
(
|
||||||
const IOobject&,
|
const IOobject& io,
|
||||||
const Mesh& mesh,
|
const Mesh& mesh,
|
||||||
const dictionary& fieldDict,
|
const dictionary& fieldDict,
|
||||||
const word& fieldDictEntry = "value"
|
const word& fieldDictEntry = "value"
|
||||||
@ -167,42 +188,42 @@ public:
|
|||||||
//- Construct as copy
|
//- Construct as copy
|
||||||
DimensionedField
|
DimensionedField
|
||||||
(
|
(
|
||||||
const DimensionedField<Type, GeoMesh>&
|
const DimensionedField<Type, GeoMesh>& df
|
||||||
);
|
);
|
||||||
|
|
||||||
//- Construct as copy or re-use as specified.
|
//- Construct as copy or re-use as specified.
|
||||||
DimensionedField
|
DimensionedField
|
||||||
(
|
(
|
||||||
DimensionedField<Type, GeoMesh>&,
|
DimensionedField<Type, GeoMesh>& df,
|
||||||
bool reuse
|
bool reuse
|
||||||
);
|
);
|
||||||
|
|
||||||
//- Construct by transferring the DimensionedField
|
//- Construct by transferring the DimensionedField
|
||||||
DimensionedField
|
DimensionedField
|
||||||
(
|
(
|
||||||
const Xfer<DimensionedField<Type, GeoMesh>>&
|
const Xfer<DimensionedField<Type, GeoMesh>>& df
|
||||||
);
|
);
|
||||||
|
|
||||||
//- Construct as copy of tmp<DimensionedField> deleting argument
|
//- Construct as copy of tmp<DimensionedField> deleting argument
|
||||||
#ifndef NoConstructFromTmp
|
#ifndef NoConstructFromTmp
|
||||||
DimensionedField
|
DimensionedField
|
||||||
(
|
(
|
||||||
const tmp<DimensionedField<Type, GeoMesh>>&
|
const tmp<DimensionedField<Type, GeoMesh>>& tdf
|
||||||
);
|
);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//- Construct as copy resetting IO parameters
|
//- Construct as copy resetting IO parameters
|
||||||
DimensionedField
|
DimensionedField
|
||||||
(
|
(
|
||||||
const IOobject&,
|
const IOobject& io,
|
||||||
const DimensionedField<Type, GeoMesh>&
|
const DimensionedField<Type, GeoMesh>& df
|
||||||
);
|
);
|
||||||
|
|
||||||
//- Construct as copy resetting IO parameters and re-use as specified.
|
//- Construct as copy resetting IO parameters and re-use as specified.
|
||||||
DimensionedField
|
DimensionedField
|
||||||
(
|
(
|
||||||
const IOobject&,
|
const IOobject& io,
|
||||||
DimensionedField<Type, GeoMesh>&,
|
DimensionedField<Type, GeoMesh>& df,
|
||||||
bool reuse
|
bool reuse
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -210,14 +231,14 @@ public:
|
|||||||
DimensionedField
|
DimensionedField
|
||||||
(
|
(
|
||||||
const word& newName,
|
const word& newName,
|
||||||
const DimensionedField<Type, GeoMesh>&
|
const DimensionedField<Type, GeoMesh>& df
|
||||||
);
|
);
|
||||||
|
|
||||||
//- Construct as copy resetting name and re-use as specified.
|
//- Construct as copy resetting name and re-use as specified.
|
||||||
DimensionedField
|
DimensionedField
|
||||||
(
|
(
|
||||||
const word& newName,
|
const word& newName,
|
||||||
DimensionedField<Type, GeoMesh>&,
|
DimensionedField<Type, GeoMesh>& df,
|
||||||
bool reuse
|
bool reuse
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -225,7 +246,7 @@ public:
|
|||||||
DimensionedField
|
DimensionedField
|
||||||
(
|
(
|
||||||
const word& newName,
|
const word& newName,
|
||||||
const Xfer<DimensionedField<Type, GeoMesh>>&
|
const Xfer<DimensionedField<Type, GeoMesh>>& df
|
||||||
);
|
);
|
||||||
|
|
||||||
//- Construct as copy resetting name
|
//- Construct as copy resetting name
|
||||||
@ -233,7 +254,7 @@ public:
|
|||||||
DimensionedField
|
DimensionedField
|
||||||
(
|
(
|
||||||
const word& newName,
|
const word& newName,
|
||||||
const tmp<DimensionedField<Type, GeoMesh>>&
|
const tmp<DimensionedField<Type, GeoMesh>>& tdf
|
||||||
);
|
);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -262,28 +283,30 @@ public:
|
|||||||
//- Return non-const access to dimensions
|
//- Return non-const access to dimensions
|
||||||
inline dimensionSet& dimensions();
|
inline dimensionSet& dimensions();
|
||||||
|
|
||||||
|
//- Return field
|
||||||
inline const Field<Type>& field() const;
|
inline const Field<Type>& field() const;
|
||||||
|
|
||||||
|
//- Return field
|
||||||
inline Field<Type>& field();
|
inline Field<Type>& field();
|
||||||
|
|
||||||
//- Return a component field of the field
|
//- Return a component field of the field
|
||||||
tmp<DimensionedField<cmptType, GeoMesh>> component
|
tmp<DimensionedField<cmptType, GeoMesh>> component
|
||||||
(
|
(
|
||||||
const direction
|
const direction d
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
//- Replace a component field of the field
|
//- Replace a component field of the field
|
||||||
void replace
|
void replace
|
||||||
(
|
(
|
||||||
const direction,
|
const direction d,
|
||||||
const DimensionedField<cmptType, GeoMesh>&
|
const DimensionedField<cmptType, GeoMesh>& df
|
||||||
);
|
);
|
||||||
|
|
||||||
//- Replace a component field of the field
|
//- Replace a component field of the field
|
||||||
void replace
|
void replace
|
||||||
(
|
(
|
||||||
const direction,
|
const direction d,
|
||||||
const tmp<DimensionedField<cmptType, GeoMesh>>&
|
const tmp<DimensionedField<cmptType, GeoMesh>>& tdf
|
||||||
);
|
);
|
||||||
|
|
||||||
//- Return the field transpose (only defined for second rank tensors)
|
//- Return the field transpose (only defined for second rank tensors)
|
||||||
@ -295,60 +318,60 @@ public:
|
|||||||
//- Calculate and return weighted average
|
//- Calculate and return weighted average
|
||||||
dimensioned<Type> weightedAverage
|
dimensioned<Type> weightedAverage
|
||||||
(
|
(
|
||||||
const DimensionedField<scalar, GeoMesh>&
|
const DimensionedField<scalar, GeoMesh>& weightField
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
//- Calculate and return weighted average
|
//- Calculate and return weighted average
|
||||||
dimensioned<Type> weightedAverage
|
dimensioned<Type> weightedAverage
|
||||||
(
|
(
|
||||||
const tmp<DimensionedField<scalar, GeoMesh>>&
|
const tmp<DimensionedField<scalar, GeoMesh>>& tweightField
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
|
|
||||||
// Write
|
// 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
|
// Member Operators
|
||||||
|
|
||||||
void operator=(const DimensionedField<Type, GeoMesh>&);
|
void operator=(const DimensionedField<Type, GeoMesh>& df);
|
||||||
void operator=(const tmp<DimensionedField<Type, GeoMesh>>&);
|
void operator=(const tmp<DimensionedField<Type, GeoMesh>>& tdf);
|
||||||
void operator=(const dimensioned<Type>&);
|
void operator=(const dimensioned<Type>& dt);
|
||||||
|
|
||||||
void operator+=(const DimensionedField<Type, GeoMesh>&);
|
void operator+=(const DimensionedField<Type, GeoMesh>& df);
|
||||||
void operator+=(const tmp<DimensionedField<Type, GeoMesh>>&);
|
void operator+=(const tmp<DimensionedField<Type, GeoMesh>>& tdf);
|
||||||
|
|
||||||
void operator-=(const DimensionedField<Type, GeoMesh>&);
|
void operator-=(const DimensionedField<Type, GeoMesh>& df);
|
||||||
void operator-=(const tmp<DimensionedField<Type, GeoMesh>>&);
|
void operator-=(const tmp<DimensionedField<Type, GeoMesh>>& tdf);
|
||||||
|
|
||||||
void operator*=(const DimensionedField<scalar, GeoMesh>&);
|
void operator*=(const DimensionedField<scalar, GeoMesh>& df);
|
||||||
void operator*=(const tmp<DimensionedField<scalar, GeoMesh>>&);
|
void operator*=(const tmp<DimensionedField<scalar, GeoMesh>>& tdf);
|
||||||
|
|
||||||
void operator/=(const DimensionedField<scalar, GeoMesh>&);
|
void operator/=(const DimensionedField<scalar, GeoMesh>& df);
|
||||||
void operator/=(const tmp<DimensionedField<scalar, GeoMesh>>&);
|
void operator/=(const tmp<DimensionedField<scalar, GeoMesh>>& tdf);
|
||||||
|
|
||||||
void operator+=(const dimensioned<Type>&);
|
void operator+=(const dimensioned<Type>& dt);
|
||||||
void operator-=(const dimensioned<Type>&);
|
void operator-=(const dimensioned<Type>& dt);
|
||||||
|
|
||||||
void operator*=(const dimensioned<scalar>&);
|
void operator*=(const dimensioned<scalar>& dt);
|
||||||
void operator/=(const dimensioned<scalar>&);
|
void operator/=(const dimensioned<scalar>& dt);
|
||||||
|
|
||||||
|
|
||||||
// Ostream Operators
|
// Ostream Operators
|
||||||
|
|
||||||
friend Ostream& operator<< <Type, GeoMesh>
|
friend Ostream& operator<< <Type, GeoMesh>
|
||||||
(
|
(
|
||||||
Ostream&,
|
Ostream& os,
|
||||||
const DimensionedField<Type, GeoMesh>&
|
const DimensionedField<Type, GeoMesh>& df
|
||||||
);
|
);
|
||||||
|
|
||||||
friend Ostream& operator<< <Type, GeoMesh>
|
friend Ostream& operator<< <Type, GeoMesh>
|
||||||
(
|
(
|
||||||
Ostream&,
|
Ostream& os,
|
||||||
const tmp<DimensionedField<Type, GeoMesh>>&
|
const tmp<DimensionedField<Type, GeoMesh>>& tdf
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -105,7 +105,7 @@ public:
|
|||||||
//- Return a component field of the field
|
//- Return a component field of the field
|
||||||
inline tmp<DimensionedField<cmptType, GeoMesh>> component
|
inline tmp<DimensionedField<cmptType, GeoMesh>> component
|
||||||
(
|
(
|
||||||
const direction
|
const direction d
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
//- Return the field transpose (only defined for second rank tensors)
|
//- Return the field transpose (only defined for second rank tensors)
|
||||||
@ -115,7 +115,7 @@ public:
|
|||||||
// Member operators
|
// Member operators
|
||||||
|
|
||||||
//- Assignment
|
//- Assignment
|
||||||
inline void operator=(const SubDimensionedField<Type, GeoMesh>&);
|
inline void operator=(const SubDimensionedField<Type, GeoMesh>& rhs);
|
||||||
|
|
||||||
//- Allow cast to a const DimensionedField<Type, GeoMesh>&
|
//- Allow cast to a const DimensionedField<Type, GeoMesh>&
|
||||||
inline operator const DimensionedField<Type, GeoMesh>&() const;
|
inline operator const DimensionedField<Type, GeoMesh>&() const;
|
||||||
|
|||||||
@ -93,20 +93,23 @@ class Xfer
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
typedef T Type;
|
||||||
|
|
||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
//- Store object pointer and manage its deletion
|
//- Store object pointer and manage its deletion
|
||||||
// Can also be used later to transfer by assignment
|
// 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
|
//- 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
|
//- Construct by copying the parameter contents
|
||||||
inline explicit Xfer(const T&);
|
inline explicit Xfer(const T& t);
|
||||||
|
|
||||||
//- Construct by transferring the contents
|
//- Construct by transferring the contents
|
||||||
inline Xfer(const Xfer<T>&);
|
inline Xfer(const Xfer<T>& t);
|
||||||
|
|
||||||
|
|
||||||
//- Destructor
|
//- Destructor
|
||||||
@ -122,10 +125,10 @@ public:
|
|||||||
// Member Operators
|
// Member Operators
|
||||||
|
|
||||||
//- Transfer the contents into the object
|
//- Transfer the contents into the object
|
||||||
inline void operator=(T&);
|
inline void operator=(T& t);
|
||||||
|
|
||||||
//- Transfer the contents into the object
|
//- Transfer the contents into the object
|
||||||
inline void operator=(const Xfer<T>&);
|
inline void operator=(const Xfer<T>& t);
|
||||||
|
|
||||||
//- Reference to the underlying datatype
|
//- Reference to the underlying datatype
|
||||||
inline T& operator()() const;
|
inline T& operator()() const;
|
||||||
|
|||||||
Reference in New Issue
Block a user