/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org \\ / A nd | Copyright (C) 2011-2026 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License This file is part of OpenFOAM. OpenFOAM is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. OpenFOAM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenFOAM. If not, see . Class Foam::GeometricField Description Generic GeometricField class. SourceFiles GeometricFieldI.H GeometricField.C GeometricFieldExpression.H \*---------------------------------------------------------------------------*/ #ifndef GeometricField_H #define GeometricField_H #include "GeometricFieldFwd.H" #include "GeometricBoundaryField.H" #include "GeometricFieldSources.H" #include "expressionExpressionable.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { class dictionary; /*---------------------------------------------------------------------------*\ Class GeometricField Declaration \*---------------------------------------------------------------------------*/ template class PrimitiveField> class GeometricField : public DimensionedField, public OldTimeField> { public: // Public Types //- Value type using Type_ = Type; //- Geometric mesh type using GeoMesh_ = GeoMesh; //- Base mesh type from which GeoMesh is constructed using Mesh = typename GeoMesh::Mesh; //- Type of the internal field from which this GeometricField is derived using Internal = DimensionedField; //- Type of the field from which this GeometricField is derived using Base = DimensionedField; //- Type of the patch field of which the Boundary is composed using PatchField = typename GeoMesh::template PatchField; //- Type of the boundary field using BoundaryField = PtrField; //- Type of the boundary field using Boundary = GeometricBoundaryField; //- Type of the field source of which the Sources is composed using Source = typename GeoMesh::template FieldSource; //- Type of the field sources using Sources = GeometricFieldSources; //- Component type of the elements of the field using cmptType = typename PrimitiveField::cmptType; private: // Private Data //- Pointer to previous iteration (used for under-relaxation) mutable GeometricField* fieldPrevIterPtr_; //- Boundary Type field containing boundary field values Boundary boundaryField_; //- Type field sources containing field source values Sources sources_; // Private Member Functions //- Read the field from the dictionary void readFields(const dictionary&); //- Read the field - create the field dictionary on-the-fly void readFields(); //- Read from file if it is present bool readIfPresent(); //- Constructor given IOobject, mesh, dimensions and patch field types. // This allocates storage for the field but not values GeometricField ( const IOobject&, const GeoMesh&, const dimensionSet&, const wordList& wantedPatchTypes, const wordList& actualPatchTypes = wordList(), const HashTable& fieldSourceTypes = HashTable(), const IOerrorLocation& fieldSourceErrorLocation = IOerrorLocation() ); public: //- Runtime type information TypeName("GeometricField"); //- Declare friendship with other geometric fields template class PrimitiveField2> friend class GeometricField; // Static Member Functions //- Return a null geometric field inline static const GeometricField& null(); // Constructors //- Constructor given IOobject, mesh, dimensions and patch field type. // Warning: this allocates storage but does not set field values! GeometricField ( const IOobject&, const GeoMesh&, const dimensionSet&, const word& patchFieldType ); //- Constructor given IOobject, mesh, dimensioned // and optional patch field type. GeometricField ( const IOobject&, const GeoMesh&, const dimensioned&, const word& patchFieldType = PatchField::calculatedType() ); //- Constructor given IOobject, mesh, dimensioned // and patch field types. GeometricField ( const IOobject&, const GeoMesh&, const dimensioned&, const wordList& wantedPatchTypes, const wordList& actualPatchTypes = wordList(), const HashTable& fieldSourceTypes = HashTable(), const IOerrorLocation& fieldSourceErrorLocation = IOerrorLocation() ); //- Constructor from components GeometricField ( const IOobject&, const Internal&, const PtrField&, const HashPtrTable& = HashPtrTable() ); //- Constructor from component expressions template < class InternalExpression, class BoundaryExpression, class = EnableIfExpressionable > GeometricField ( const IOobject&, const InternalExpression&, const BoundaryExpression&, const HashPtrTable& = HashPtrTable() ); //- Constructor from components GeometricField ( const IOobject&, const GeoMesh&, const dimensionSet&, const PrimitiveField&, const PtrField&, const HashPtrTable& = HashPtrTable() ); //- Constructor from component expressions template < class InternalExpression, class BoundaryExpression, class = EnableIfExpressionable > GeometricField ( const IOobject&, const GeoMesh&, const dimensionSet&, const InternalExpression&, const BoundaryExpression&, const HashPtrTable& = HashPtrTable() ); //- Construct and read given IOobject GeometricField ( const IOobject&, const GeoMesh&, const dimensionSet& dims = dimensions::invalid ); //- Construct from dictionary GeometricField ( const IOobject&, const GeoMesh&, const dictionary&, const dimensionSet& dims = dimensions::invalid ); //- Copy constructor GeometricField(const GeometricField&); //- Copy constructor template class PrimitiveField2> explicit GeometricField ( const GeometricField& ); //- Move constructor GeometricField(GeometricField&&); //- Construct as copy of tmp GeometricField ( const tmp>& ); //- Construct from an expression template> GeometricField(const Expression& e); //- Construct as copy resetting IO parameters template class PrimitiveField2> GeometricField ( const IOobject&, const GeometricField& ); //- Construct as copy of tmp resetting IO parameters GeometricField ( const IOobject&, const tmp>& ); //- Construct as copy resetting name template class PrimitiveField2> GeometricField ( const word& newName, const GeometricField& ); //- Construct as copy of tmp resetting name GeometricField ( const word& newName, const tmp>& ); //- Construct as copy resetting IO parameters and patch field type template class PrimitiveField2> GeometricField ( const IOobject&, const GeometricField&, const word& patchFieldType ); //- Construct as copy of tmp resetting IO parameters // and patch field type GeometricField ( const IOobject&, const tmp>&, const word& patchFieldType ); //- Construct as copy of expression setting IO parameters // and patch field type template> GeometricField ( const IOobject&, const Expression& e, const word& patchFieldType ); //- Constructor from internal field and patch field type template class PrimitiveField2> GeometricField ( const IOobject&, const DimensionedField&, const word& patchFieldType ); //- Constructor from temporary internal field and patch field type GeometricField ( const IOobject&, const tmp&, const word& patchFieldType ); //- Construct as copy resetting IO parameters and patch field types template class PrimitiveField2> GeometricField ( const IOobject&, const GeometricField&, const wordList& patchFieldTypes, const wordList& actualPatchTypes = wordList(), const HashTable& fieldSourceTypes = HashTable(), const IOerrorLocation& fieldSourceErrorLocation = IOerrorLocation() ); //- Construct as copy of tmp resetting IO parameters // and patch field types GeometricField ( const IOobject&, const tmp>&, const wordList& patchFieldTypes, const wordList& actualPatchTypes = wordList(), const HashTable& fieldSourceTypes = HashTable(), const IOerrorLocation& fieldSourceErrorLocation = IOerrorLocation() ); //- Construct as copy of tmp resetting IO parameters // and patch field types template > GeometricField ( const IOobject&, const Expression&, const wordList& patchFieldTypes, const wordList& actualPatchTypes = wordList(), const HashTable& fieldSourceTypes = HashTable(), const IOerrorLocation& fieldSourceErrorLocation = IOerrorLocation() ); //- Construct from IOobject, internal field and patch field types template class PrimitiveField2> GeometricField ( const IOobject&, const DimensionedField&, const wordList& patchFieldTypes, const wordList& actualPatchTypes = wordList(), const HashTable& fieldSourceTypes = HashTable(), const IOerrorLocation& fieldSourceErrorLocation = IOerrorLocation() ); //- Construct from IOobject, tmp internal field and patch field types GeometricField ( const IOobject&, const tmp&, const wordList& patchFieldTypes, const wordList& actualPatchTypes = wordList(), const HashTable& fieldSourceTypes = HashTable(), const IOerrorLocation& fieldSourceErrorLocation = IOerrorLocation() ); //- Clone tmp> clone() const; //- Clone un-sliced tmp> cloneUnSliced() const; //- Return a temporary field constructed from name, // internal field and list of patch fields static tmp> New ( const word& name, const Internal&, const PtrField&, const HashPtrTable& = HashPtrTable() ); //- Return a temporary field constructed from name, // internal field and list of patch fields template < class InternalExpression, class BoundaryExpression, class = EnableIfExpressionable > static tmp> New ( const word& name, const InternalExpression&, const BoundaryExpression&, const HashPtrTable& = HashPtrTable() ); //- Return a temporary field constructed from name, mesh, dimensionSet // and patch field type static tmp> New ( const word& name, const GeoMesh&, const dimensionSet&, const word& patchFieldType = PatchField::calculatedType() ); //- Return a temporary field constructed from mesh, dimensioned // and patch field type static tmp> New ( const word& name, const GeoMesh&, const dimensioned&, const word& patchFieldType = PatchField::calculatedType() ); //- Return a temporary field constructed from mesh, dimensioned // and patch field types static tmp> New ( const word& name, const GeoMesh&, const dimensioned&, const wordList& patchFieldTypes, const wordList& actualPatchTypes = wordList(), const HashTable& fieldSourceTypes = HashTable(), const IOerrorLocation& fieldSourceErrorLocation = IOerrorLocation() ); //- Rename temporary field and return static tmp> New ( const word& newName, const tmp>& ); //- Rename field, reset patch field type and return template class PrimitiveField2> static tmp> New ( const word& newName, const GeometricField&, const word& patchFieldType ); //- Rename temporary field, reset patch field type and return static tmp> New ( const word& newName, const tmp>&, const word& patchFieldType ); //- Return a temporary field constructed from name, // internal field and patch field type template class PrimitiveField2> static tmp> New ( const word& name, const DimensionedField&, const word& patchFieldType ); //- Return a temporary field constructed from name, // temporary internal field and patch field type static tmp> New ( const word& name, const tmp&, const word& patchFieldType ); //- Return a temporary field constructed from name, // internal field expression and patch field type template> static tmp> New ( const word& name, const Expression& e, const word& patchFieldType ); //- Rename and reset patch fields types of field and return template class PrimitiveField2> static tmp> New ( const word& newName, const GeometricField&, const wordList& patchFieldTypes, const wordList& actualPatchTypes = wordList(), const HashTable& fieldSourceTypes = HashTable(), const IOerrorLocation& fieldSourceErrorLocation = IOerrorLocation() ); //- Rename and reset patch fields types of temporary field and return static tmp> New ( const word& newName, const tmp>&, const wordList& patchFieldTypes, const wordList& actualPatchTypes = wordList(), const HashTable& fieldSourceTypes = HashTable(), const IOerrorLocation& fieldSourceErrorLocation = IOerrorLocation() ); //- Return a temporary field constructed from IOobject, // internal field and patch field types template class PrimitiveField2> static tmp> New ( const word& newName, const DimensionedField&, const wordList& patchFieldTypes, const wordList& actualPatchTypes = wordList(), const HashTable& fieldSourceTypes = HashTable(), const IOerrorLocation& fieldSourceErrorLocation = IOerrorLocation() ); //- Return a temporary field constructed from IOobject, // temporary internal field and patch field types static tmp> New ( const word& newName, const tmp&, const wordList& patchFieldTypes, const wordList& actualPatchTypes = wordList(), const HashTable& fieldSourceTypes = HashTable(), const IOerrorLocation& fieldSourceErrorLocation = IOerrorLocation() ); //- Destructor virtual ~GeometricField(); // Member Functions //- Return a reference to the dimensioned internal field // Note: this increments the event counter and checks the // old-time fields; avoid in loops. Internal& internalFieldRef(); //- Return a const-reference to the dimensioned internal field inline const Internal& internalField() const; //- Return a reference to the primitive field // Note: this increments the event counter and checks the // old-time fields; avoid in loops. typename Internal::FieldType& primitiveFieldRef(); //- Return a const-reference to the primitive field inline const typename Internal::FieldType& primitiveField() const; //- Return a reference to the boundary field // Note: this increments the event counter and checks the // old-time fields; avoid in loops. Boundary& boundaryRef(); //- Return a reference to the boundary field without storing old times // Note: this increments the event counter; avoid in loops. Boundary& boundaryRefNoStoreOldTimes(); //- Return const-reference to the boundary field inline const Boundary& boundary() const; //- Return a reference to the boundary field // Note: this increments the event counter and checks the // old-time fields; avoid in loops. BoundaryField& boundaryFieldRef(); //- Return a reference to the boundary field without storing old times // Note: this increments the event counter; avoid in loops. BoundaryField& boundaryFieldRefNoStoreOldTimes(); //- Return const-reference to the boundary field inline const BoundaryField& boundaryField() const; //- Return a reference to the sources // Note: this increments the event counter and checks the // old-time fields; avoid in loops. Sources& sourcesRef(); //- Return const-reference to the sources inline const Sources& sources() const; //- Store the field as the previous iteration value void storePrevIter() const; //- Delete the previous iteration field void clearPrevIter(); //- Return previous iteration field const GeometricField& prevIter() const; //- Use old-time methods from the base class USING_OLD_TIME_FIELD(GeometricField); //- Correct boundary field void correctBoundaryConditions(); //- Reset the field contents to the given field // Used for mesh to mesh mapping template class PrimitiveField2> void reset(const GeometricField&); //- Reset the field contents to the given tmp-field // Used for mesh to mesh mapping void reset(const tmp>&); //- Reset the field contents to the given tmp-field // Used for mesh to mesh mapping template class PrimitiveField2> void reset(const tmp>&); //- Does the field need a reference level for solution bool needReference() const; //- Return a component field expression of the field inline auto component(const direction&) const; //- WriteData member function required by regIOobject bool writeData(Ostream&) const; //- Return transpose field expression // (only if it is a tensor field) inline auto T() const; //- Relax field (for steady-state solution). // alpha >= 1 : no relaxation // alpha < 1 : relaxation void relax(const scalar alpha); //- Return the field relaxation factor read from fvSolution // or 1 if not specified scalar relaxationFactor() const; //- Relax current field with respect to the cached previous iteration. // Relaxation factor is read from fvSolution void relax(); //- Relax given field with respect to the current field // and reset the field to the result template class PrimitiveField2> void relax ( const tmp>&, const scalar alpha ); //- Relax given field with respect to the current field // and reset the field to the result // Relaxation factor is read from fvSolution template class PrimitiveField2> void relax(const tmp>&); //- Select the final iteration parameters if `final' is true // by returning the field name + "Final" // otherwise the standard parameters by returning the field name word select(bool final) const; //- Helper function to write the min and max to an Ostream void writeMinMax(Ostream& os) const; // Member function *this operators void negate(); //- Replace a component field of the field template class PrimitiveField2> void replace ( const direction, const GeometricField& ); //- Replace a component field of the field template class PrimitiveField2> void replace ( const direction, const tmp>& ); //- Replace a component field of the field from the given expression template> void replace(const direction, const Expression&); //- Replace a component field of the field void replace(const direction, const dimensioned&); //- Bound the field to the given lower bound void boundLower(const dimensioned& lower); //- Bound the field to the given upper bound void boundUpper(const dimensioned& upper); //- Bound the field within the given lower and upper bounds void bound ( const dimensioned& lower, const dimensioned& upper ); // Member Operators //- Return a const-reference to the dimensioned internal field // Useful in the formulation of source-terms for FV equations inline const Internal& operator()() const; void operator=(const GeometricField&); void operator=(GeometricField&&); template class PrimitiveField2> void operator=(const GeometricField&); void operator= ( const tmp>& ); //- Assign to an expression template> void operator=(const Expression& e); template class PrimitiveField2> void operator= ( const tmp>& ); void operator=(const dimensioned&); void operator=(const zero&); template class PrimitiveField2> void operator==(const GeometricField&); void operator== ( const tmp>& ); template class PrimitiveField2> void operator== ( const tmp>& ); //- Assign to an expression template> void operator==(const Expression& e); void operator==(const dimensioned&); void operator==(const zero&); template class PrimitiveField2> void operator+= ( const GeometricField& ); template class PrimitiveField2> void operator+= ( const tmp>& ); //- Assign-add to an expression template> void operator+=(const Expression& e); void operator+=(const dimensioned&); template class PrimitiveField2> void operator-= ( const GeometricField& ); template class PrimitiveField2> void operator-= ( const tmp>& ); //- Assign-subtract to an expression template> void operator-=(const Expression& e); void operator-=(const dimensioned&); template class PrimitiveField2> void operator*= ( const GeometricField& ); template class PrimitiveField2> void operator*= ( const tmp>& ); //- Assign-multiply to an expression template> void operator*=(const Expression& e); void operator*=(const dimensioned&); template class PrimitiveField2> void operator/= ( const GeometricField& ); template class PrimitiveField2> void operator/= ( const tmp>& ); //- Assign-divide to an expression template> void operator/=(const Expression& e); void operator/=(const dimensioned&); }; template class PrimitiveField> Ostream& operator<< ( Ostream&, const GeometricField& ); template class PrimitiveField> bool reusable(const tmp>& tgf); template tmp> New ( const tmp>& tgf1, const word& name, const dimensionSet& dimensions, const bool initRet = false ); template class PrimitiveField> struct OldTimeFieldCopy> { using FieldType = GeometricField; using Field0Type = typename OldTimeField0Type::type; using Calculated = typename FieldType::PatchField::Calculated; tmp operator()(const IOobject& io, const FieldType& field) { return tmp(new Field0Type(io, field, Calculated::typeName)); } }; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #include "GeometricFieldI.H" #include "GeometricFieldExpression.H" #ifdef NoRepository #include "GeometricField.C" #endif // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #endif // ************************************************************************* //