diff --git a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedField.H b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedField.H index f521f7b42b..4d373ec3ca 100644 --- a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedField.H +++ b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedField.H @@ -89,7 +89,7 @@ public: //- Type of the field from which this DimensionedField is derived typedef Field FieldType; - //- Component type of the elements of the field + //- Component type of the field elements typedef typename Field::cmptType cmptType; @@ -351,13 +351,13 @@ public: ); //- Return mesh - inline const Mesh& mesh() const; + inline const Mesh& mesh() const noexcept; //- Return dimensions - inline const dimensionSet& dimensions() const; + inline const dimensionSet& dimensions() const noexcept; //- Return non-const access to dimensions - inline dimensionSet& dimensions(); + inline dimensionSet& dimensions() noexcept; //- Return oriented type inline const orientedType& oriented() const noexcept; @@ -368,11 +368,11 @@ public: //- Set the oriented flag inline void setOriented(const bool oriented = true) noexcept; - //- Return field - inline const Field& field() const; + //- Return const-reference to the field values + inline const Field& field() const noexcept; - //- Return field - inline Field& field(); + //- Return reference to the field values + inline Field& field() noexcept; //- Return a component field of the field tmp> component diff --git a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldI.H b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldI.H index ce0e36bc92..de4f0cc5b1 100644 --- a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldI.H +++ b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldI.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2017-2021 OpenCFD Ltd. + Copyright (C) 2017-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -38,7 +38,7 @@ Foam::DimensionedField::null() template inline const typename GeoMesh::Mesh& -Foam::DimensionedField::mesh() const +Foam::DimensionedField::mesh() const noexcept { return mesh_; } @@ -46,14 +46,15 @@ Foam::DimensionedField::mesh() const template inline const Foam::dimensionSet& -Foam::DimensionedField::dimensions() const +Foam::DimensionedField::dimensions() const noexcept { return dimensions_; } template -inline Foam::dimensionSet& Foam::DimensionedField::dimensions() +inline Foam::dimensionSet& +Foam::DimensionedField::dimensions() noexcept { return dimensions_; } @@ -87,7 +88,7 @@ inline void Foam::DimensionedField::setOriented template inline const Foam::Field& -Foam::DimensionedField::field() const +Foam::DimensionedField::field() const noexcept { return *this; } @@ -95,7 +96,7 @@ Foam::DimensionedField::field() const template inline Foam::Field& -Foam::DimensionedField::field() +Foam::DimensionedField::field() noexcept { return *this; } diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.C b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.C index ec8b662661..aed30fbe20 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.C +++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.C @@ -873,7 +873,7 @@ Foam::GeometricField::~GeometricField() template class PatchField, class GeoMesh> typename Foam::GeometricField::Internal& -Foam::GeometricField::ref +Foam::GeometricField::internalFieldRef ( const bool updateAccessTime ) @@ -1346,7 +1346,7 @@ void Foam::GeometricField::operator= // Only assign field contents not ID - ref() = gf(); + internalFieldRef() = gf.internalField(); boundaryFieldRef() = gf.boundaryField(); } @@ -1393,7 +1393,7 @@ void Foam::GeometricField::operator= const dimensioned& dt ) { - ref() = dt; + internalFieldRef() = dt; boundaryFieldRef() = dt.value(); } @@ -1410,7 +1410,7 @@ void Foam::GeometricField::operator== // Only assign field contents not ID - ref() = gf(); + internalFieldRef() = gf.internalField(); boundaryFieldRef() == gf.boundaryField(); tgf.clear(); @@ -1423,7 +1423,7 @@ void Foam::GeometricField::operator== const dimensioned& dt ) { - ref() = dt; + internalFieldRef() = dt; boundaryFieldRef() == dt.value(); } @@ -1438,7 +1438,7 @@ void Foam::GeometricField::operator op \ { \ checkField(*this, gf, #op); \ \ - ref() op gf(); \ + internalFieldRef() op gf.internalField(); \ boundaryFieldRef() op gf.boundaryField(); \ } \ \ @@ -1458,7 +1458,7 @@ void Foam::GeometricField::operator op \ const dimensioned& dt \ ) \ { \ - ref() op dt; \ + internalFieldRef() op dt; \ boundaryFieldRef() op dt.value(); \ } @@ -1479,7 +1479,7 @@ Foam::Ostream& Foam::operator<< const GeometricField& gf ) { - gf().writeData(os, "internalField"); + gf.internalField().writeData(os, "internalField"); os << nl; gf.boundaryField().writeEntry("boundaryField", os); diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.H b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.H index 1fbf2ebe94..6658d9ad3a 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.H +++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.H @@ -98,7 +98,7 @@ public: //- The patch field type for the GeometricBoundaryField typedef PatchField Patch; - //- The field component type + //- Component type of the field elements typedef typename Field::cmptType cmptType; @@ -470,15 +470,21 @@ public: // Member Functions - //- Return a reference to the dimensioned internal field + //- Return a const-reference to the dimensioned internal field. + inline const Internal& internalField() const noexcept; + + //- Return a reference to the dimensioned internal field. // \param updateAccessTime update event counter and check // old-time fields // // \note Should avoid using updateAccessTime = true within loops. - Internal& ref(const bool updateAccessTime = true); + Internal& internalFieldRef(const bool updateAccessTime = true); - //- Return a const-reference to the dimensioned internal field - inline const Internal& internalField() const; + //- Same as internalFieldRef() + Internal& ref(const bool updateAccessTime = true) + { + return this->internalFieldRef(updateAccessTime); + } //- Return a const-reference to the dimensioned internal field //- of a "vol" field. @@ -487,7 +493,11 @@ public: // \note definition in finiteVolume/fields/volFields/volFieldsI.H inline const Internal& v() const; - //- Return a reference to the internal field + //- Return a const-reference to the internal field values. + inline const typename Internal::FieldType& primitiveField() + const noexcept; + + //- Return a reference to the internal field values. // \param updateAccessTime update event counter and check // old-time fields // @@ -497,8 +507,8 @@ public: const bool updateAccessTime = true ); - //- Return a const-reference to the internal field - inline const typename Internal::FieldType& primitiveField() const; + //- Return const-reference to the boundary field + inline const Boundary& boundaryField() const noexcept; //- Return a reference to the boundary field // \param updateAccessTime update event counter and check @@ -507,14 +517,11 @@ public: // \note Should avoid using updateAccessTime = true within loops. Boundary& boundaryFieldRef(const bool updateAccessTime = true); - //- Return const-reference to the boundary field - inline const Boundary& boundaryField() const; - //- Return the time index of the field - inline label timeIndex() const; + inline label timeIndex() const noexcept; - //- Return the time index of the field - inline label& timeIndex(); + //- Write-access to the time index of the field + inline label& timeIndex() noexcept; //- Store the old-time fields void storeOldTimes() const; @@ -627,9 +634,10 @@ public: // Member Operators - //- Return a const-reference to the dimensioned internal field + //- Return a const-reference to the dimensioned internal field. + //- Same as internalField(). // Useful in the formulation of source-terms for FV equations - inline const Internal& operator()() const; + const Internal& operator()() const { return *this; } void operator=(const GeometricField&); void operator=(const tmp>&); diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldI.H b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldI.H index 9300a4f4ec..90b57d17a4 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldI.H +++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldI.H @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -36,30 +37,27 @@ Foam::GeometricField::null() template class PatchField, class GeoMesh> -inline -const typename +inline const typename Foam::GeometricField::Internal& -Foam::GeometricField:: -internalField() const +Foam::GeometricField::internalField() const noexcept { return *this; } template class PatchField, class GeoMesh> -inline -const typename +inline const typename Foam::GeometricField::Internal::FieldType& -Foam::GeometricField::primitiveField() const +Foam::GeometricField::primitiveField() const noexcept { return *this; } template class PatchField, class GeoMesh> -inline const typename Foam::GeometricField:: -Boundary& -Foam::GeometricField::boundaryField() const +inline const typename +Foam::GeometricField::Boundary& +Foam::GeometricField::boundaryField() const noexcept { return boundaryField_; } @@ -67,7 +65,7 @@ Foam::GeometricField::boundaryField() const template class PatchField, class GeoMesh> inline Foam::label -Foam::GeometricField::timeIndex() const +Foam::GeometricField::timeIndex() const noexcept { return timeIndex_; } @@ -75,23 +73,10 @@ Foam::GeometricField::timeIndex() const template class PatchField, class GeoMesh> inline Foam::label& -Foam::GeometricField::timeIndex() +Foam::GeometricField::timeIndex() noexcept { return timeIndex_; } -// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // - -template class PatchField, class GeoMesh> -inline -const typename -Foam::GeometricField::Internal& -Foam::GeometricField:: -operator()() const -{ - return *this; -} - - // ************************************************************************* // diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/MapGeometricFields.H b/src/OpenFOAM/fields/GeometricFields/GeometricField/MapGeometricFields.H index 1fbd23fd00..419bcbead2 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricField/MapGeometricFields.H +++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/MapGeometricFields.H @@ -113,10 +113,14 @@ void MapGeometricFields } // Map the internal field - MapInternalField()(field.ref(), mapper); + MapInternalField() + ( + field.internalFieldRef(), + mapper + ); // Map the patch fields - typename FieldType::Boundary& bfield = field.boundaryFieldRef(); + auto& bfield = field.boundaryFieldRef(); forAll(bfield, patchi) { diff --git a/src/OpenFOAM/fields/GeometricFields/geometricOneField/geometricOneField.H b/src/OpenFOAM/fields/GeometricFields/geometricOneField/geometricOneField.H index 7e2bf6320c..7287edffcf 100644 --- a/src/OpenFOAM/fields/GeometricFields/geometricOneField/geometricOneField.H +++ b/src/OpenFOAM/fields/GeometricFields/geometricOneField/geometricOneField.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2020 OpenCFD Ltd. + Copyright (C) 2020-2022 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -37,12 +37,11 @@ Description \*---------------------------------------------------------------------------*/ -#ifndef geometricOneField_H -#define geometricOneField_H +#ifndef Foam_geometricOneField_H +#define Foam_geometricOneField_H #include "oneFieldField.H" #include "dimensionSet.H" -#include "scalar.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -95,9 +94,9 @@ public: return Internal{}; } - Internal primitiveField() const noexcept + oneField primitiveField() const noexcept { - return Internal{}; + return oneField{}; } Boundary boundaryField() const noexcept diff --git a/src/OpenFOAM/fields/GeometricFields/geometricZeroField/geometricZeroField.H b/src/OpenFOAM/fields/GeometricFields/geometricZeroField/geometricZeroField.H index 957ed6f391..fdf8dc80c4 100644 --- a/src/OpenFOAM/fields/GeometricFields/geometricZeroField/geometricZeroField.H +++ b/src/OpenFOAM/fields/GeometricFields/geometricZeroField/geometricZeroField.H @@ -37,12 +37,11 @@ Description \*---------------------------------------------------------------------------*/ -#ifndef geometricZeroField_H -#define geometricZeroField_H +#ifndef Foam_geometricZeroField_H +#define Foam_geometricZeroField_H #include "zeroFieldField.H" #include "dimensionSet.H" -#include "scalar.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -95,9 +94,9 @@ public: return Internal{}; } - Internal primitiveField() const noexcept + zeroField primitiveField() const noexcept { - return Internal{}; + return zeroField{}; } Boundary boundaryField() const noexcept diff --git a/src/OpenFOAM/memory/refPtr/refPtr.H b/src/OpenFOAM/memory/refPtr/refPtr.H index c110ae3022..85f8c0875a 100644 --- a/src/OpenFOAM/memory/refPtr/refPtr.H +++ b/src/OpenFOAM/memory/refPtr/refPtr.H @@ -205,7 +205,7 @@ public: //- Return non-const reference to the object or to the contents //- of a (non-null) managed pointer, with an additional const_cast. // Fatal for a null managed pointer. - inline T& constCast() const; + T& constCast() const { return const_cast(cref()); } //- Return a shallow copy as a wrapped reference, preserving the //- const/non-const status. diff --git a/src/OpenFOAM/memory/refPtr/refPtrI.H b/src/OpenFOAM/memory/refPtr/refPtrI.H index 34511f3ffa..a496834ce9 100644 --- a/src/OpenFOAM/memory/refPtr/refPtrI.H +++ b/src/OpenFOAM/memory/refPtr/refPtrI.H @@ -232,13 +232,6 @@ inline T& Foam::refPtr::ref() const } -template -inline T& Foam::refPtr::constCast() const -{ - return const_cast(cref()); -} - - template inline Foam::refPtr Foam::refPtr::shallowClone() const noexcept { diff --git a/src/OpenFOAM/memory/tmp/tmp.H b/src/OpenFOAM/memory/tmp/tmp.H index c0157eb7cb..036b4d6ae5 100644 --- a/src/OpenFOAM/memory/tmp/tmp.H +++ b/src/OpenFOAM/memory/tmp/tmp.H @@ -221,7 +221,7 @@ public: //- Return non-const reference to the object or to the contents //- of a (non-null) managed pointer, with an additional const_cast. // Fatal for a null pointer. - inline T& constCast() const; + T& constCast() const { return const_cast(cref()); } // Edit diff --git a/src/OpenFOAM/memory/tmp/tmpI.H b/src/OpenFOAM/memory/tmp/tmpI.H index 9065831d0e..e753f5090c 100644 --- a/src/OpenFOAM/memory/tmp/tmpI.H +++ b/src/OpenFOAM/memory/tmp/tmpI.H @@ -234,13 +234,6 @@ inline T& Foam::tmp::ref() const } -template -inline T& Foam::tmp::constCast() const -{ - return const_cast(cref()); -} - - template inline T* Foam::tmp::ptr() const { diff --git a/src/finiteVolume/finiteVolume/ddtSchemes/CrankNicolsonDdtScheme/CrankNicolsonDdtScheme.C b/src/finiteVolume/finiteVolume/ddtSchemes/CrankNicolsonDdtScheme/CrankNicolsonDdtScheme.C index e3feba86eb..663a956f4f 100644 --- a/src/finiteVolume/finiteVolume/ddtSchemes/CrankNicolsonDdtScheme/CrankNicolsonDdtScheme.C +++ b/src/finiteVolume/finiteVolume/ddtSchemes/CrankNicolsonDdtScheme/CrankNicolsonDdtScheme.C @@ -381,14 +381,14 @@ CrankNicolsonDdtScheme::fvcDdt { dimensionedScalar rDtCoef0 = rDtCoef0_(ddt0); - ddt0.ref() = + ddt0.internalFieldRef() = ( (rDtCoef0*dt)*(mesh().V0() - mesh().V00()) - mesh().V00()*offCentre_(ddt0.internalField()) )/mesh().V0(); } - tdtdt.ref().ref() = + tdtdt.ref().internalFieldRef() = ( (rDtCoef*dt)*(mesh().V() - mesh().V0()) - mesh().V0()*offCentre_(ddt0.internalField()) diff --git a/src/finiteVolume/finiteVolume/snGradSchemes/skewCorrectedSnGrad/skewCorrectedSnGrad.C b/src/finiteVolume/finiteVolume/snGradSchemes/skewCorrectedSnGrad/skewCorrectedSnGrad.C index 5faffa76f5..6d1c26c514 100644 --- a/src/finiteVolume/finiteVolume/snGradSchemes/skewCorrectedSnGrad/skewCorrectedSnGrad.C +++ b/src/finiteVolume/finiteVolume/snGradSchemes/skewCorrectedSnGrad/skewCorrectedSnGrad.C @@ -92,7 +92,7 @@ Foam::fv::skewCorrectedSnGrad::fullGradCorrection mesh, dimensionedVector(dimLength, Zero) ); - vectorField& kPI = kP.ref().field(); + vectorField& kPI = kP.primitiveFieldRef(); surfaceVectorField kN ( @@ -107,7 +107,7 @@ Foam::fv::skewCorrectedSnGrad::fullGradCorrection mesh, dimensionedVector(dimLength, Zero) ); - vectorField& kNI = kN.ref().field(); + vectorField& kNI = kN.primitiveFieldRef(); kPI = Cf - vectorField(C, owner); kPI -= Sf*(Sf&kPI)/sqr(magSf); @@ -164,7 +164,7 @@ Foam::fv::skewCorrectedSnGrad::fullGradCorrection // Skewness and non-rothogonal correction { - ssf.ref().field().replace + ssf.primitiveFieldRef().replace ( cmpt, ( diff --git a/src/finiteVolume/interpolation/surfaceInterpolation/surfaceInterpolationScheme/surfaceInterpolationScheme.C b/src/finiteVolume/interpolation/surfaceInterpolation/surfaceInterpolationScheme/surfaceInterpolationScheme.C index a34888d71c..69a88da168 100644 --- a/src/finiteVolume/interpolation/surfaceInterpolation/surfaceInterpolationScheme/surfaceInterpolationScheme.C +++ b/src/finiteVolume/interpolation/surfaceInterpolation/surfaceInterpolationScheme/surfaceInterpolationScheme.C @@ -260,7 +260,7 @@ Foam::surfaceInterpolationScheme::dotInterpolate Field& sfi = sf.primitiveFieldRef(); - const typename SFType::Internal& Sfi = Sf(); + const typename SFType::Internal& Sfi = Sf.internalField(); for (label fi=0; fi