STYLE: provide GeometricField internalFieldRef()

- similar to boundaryFieldRef(), primitiveFieldRef() for providing
  write access. Complimentary naming to internalField(). Identical to
  ref() but more explicitly named, and less likely to be confused with
  a tmp::ref(), for example.

- prefer .primitiveFieldRef() over .ref().field()

- mark some access methods noexcept
This commit is contained in:
Mark Olesen
2022-09-23 11:33:30 +02:00
parent 4710528448
commit 3c7088b6c0
17 changed files with 82 additions and 100 deletions

View File

@ -89,7 +89,7 @@ public:
//- Type of the field from which this DimensionedField is derived
typedef Field<Type> FieldType;
//- Component type of the elements of the field
//- Component type of the field elements
typedef typename Field<Type>::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<Type>& field() const;
//- Return const-reference to the field values
inline const Field<Type>& field() const noexcept;
//- Return field
inline Field<Type>& field();
//- Return reference to the field values
inline Field<Type>& field() noexcept;
//- Return a component field of the field
tmp<DimensionedField<cmptType, GeoMesh>> component

View File

@ -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<Type, GeoMesh>::null()
template<class Type, class GeoMesh>
inline const typename GeoMesh::Mesh&
Foam::DimensionedField<Type, GeoMesh>::mesh() const
Foam::DimensionedField<Type, GeoMesh>::mesh() const noexcept
{
return mesh_;
}
@ -46,14 +46,15 @@ Foam::DimensionedField<Type, GeoMesh>::mesh() const
template<class Type, class GeoMesh>
inline const Foam::dimensionSet&
Foam::DimensionedField<Type, GeoMesh>::dimensions() const
Foam::DimensionedField<Type, GeoMesh>::dimensions() const noexcept
{
return dimensions_;
}
template<class Type, class GeoMesh>
inline Foam::dimensionSet& Foam::DimensionedField<Type, GeoMesh>::dimensions()
inline Foam::dimensionSet&
Foam::DimensionedField<Type, GeoMesh>::dimensions() noexcept
{
return dimensions_;
}
@ -87,7 +88,7 @@ inline void Foam::DimensionedField<Type, GeoMesh>::setOriented
template<class Type, class GeoMesh>
inline const Foam::Field<Type>&
Foam::DimensionedField<Type, GeoMesh>::field() const
Foam::DimensionedField<Type, GeoMesh>::field() const noexcept
{
return *this;
}
@ -95,7 +96,7 @@ Foam::DimensionedField<Type, GeoMesh>::field() const
template<class Type, class GeoMesh>
inline Foam::Field<Type>&
Foam::DimensionedField<Type, GeoMesh>::field()
Foam::DimensionedField<Type, GeoMesh>::field() noexcept
{
return *this;
}

View File

@ -873,7 +873,7 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::~GeometricField()
template<class Type, template<class> class PatchField, class GeoMesh>
typename
Foam::GeometricField<Type, PatchField, GeoMesh>::Internal&
Foam::GeometricField<Type, PatchField, GeoMesh>::ref
Foam::GeometricField<Type, PatchField, GeoMesh>::internalFieldRef
(
const bool updateAccessTime
)
@ -1346,7 +1346,7 @@ void Foam::GeometricField<Type, PatchField, GeoMesh>::operator=
// Only assign field contents not ID
ref() = gf();
internalFieldRef() = gf.internalField();
boundaryFieldRef() = gf.boundaryField();
}
@ -1393,7 +1393,7 @@ void Foam::GeometricField<Type, PatchField, GeoMesh>::operator=
const dimensioned<Type>& dt
)
{
ref() = dt;
internalFieldRef() = dt;
boundaryFieldRef() = dt.value();
}
@ -1410,7 +1410,7 @@ void Foam::GeometricField<Type, PatchField, GeoMesh>::operator==
// Only assign field contents not ID
ref() = gf();
internalFieldRef() = gf.internalField();
boundaryFieldRef() == gf.boundaryField();
tgf.clear();
@ -1423,7 +1423,7 @@ void Foam::GeometricField<Type, PatchField, GeoMesh>::operator==
const dimensioned<Type>& dt
)
{
ref() = dt;
internalFieldRef() = dt;
boundaryFieldRef() == dt.value();
}
@ -1438,7 +1438,7 @@ void Foam::GeometricField<Type, PatchField, GeoMesh>::operator op \
{ \
checkField(*this, gf, #op); \
\
ref() op gf(); \
internalFieldRef() op gf.internalField(); \
boundaryFieldRef() op gf.boundaryField(); \
} \
\
@ -1458,7 +1458,7 @@ void Foam::GeometricField<Type, PatchField, GeoMesh>::operator op \
const dimensioned<TYPE>& dt \
) \
{ \
ref() op dt; \
internalFieldRef() op dt; \
boundaryFieldRef() op dt.value(); \
}
@ -1479,7 +1479,7 @@ Foam::Ostream& Foam::operator<<
const GeometricField<Type, PatchField, GeoMesh>& gf
)
{
gf().writeData(os, "internalField");
gf.internalField().writeData(os, "internalField");
os << nl;
gf.boundaryField().writeEntry("boundaryField", os);

View File

@ -98,7 +98,7 @@ public:
//- The patch field type for the GeometricBoundaryField
typedef PatchField<Type> Patch;
//- The field component type
//- Component type of the field elements
typedef typename Field<Type>::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<Type, PatchField, GeoMesh>&);
void operator=(const tmp<GeometricField<Type, PatchField, GeoMesh>>&);

View File

@ -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<Type, PatchField, GeoMesh>::null()
template<class Type, template<class> class PatchField, class GeoMesh>
inline
const typename
inline const typename
Foam::GeometricField<Type, PatchField, GeoMesh>::Internal&
Foam::GeometricField<Type, PatchField, GeoMesh>::
internalField() const
Foam::GeometricField<Type, PatchField, GeoMesh>::internalField() const noexcept
{
return *this;
}
template<class Type, template<class> class PatchField, class GeoMesh>
inline
const typename
inline const typename
Foam::GeometricField<Type, PatchField, GeoMesh>::Internal::FieldType&
Foam::GeometricField<Type, PatchField, GeoMesh>::primitiveField() const
Foam::GeometricField<Type, PatchField, GeoMesh>::primitiveField() const noexcept
{
return *this;
}
template<class Type, template<class> class PatchField, class GeoMesh>
inline const typename Foam::GeometricField<Type, PatchField, GeoMesh>::
Boundary&
Foam::GeometricField<Type, PatchField, GeoMesh>::boundaryField() const
inline const typename
Foam::GeometricField<Type, PatchField, GeoMesh>::Boundary&
Foam::GeometricField<Type, PatchField, GeoMesh>::boundaryField() const noexcept
{
return boundaryField_;
}
@ -67,7 +65,7 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::boundaryField() const
template<class Type, template<class> class PatchField, class GeoMesh>
inline Foam::label
Foam::GeometricField<Type, PatchField, GeoMesh>::timeIndex() const
Foam::GeometricField<Type, PatchField, GeoMesh>::timeIndex() const noexcept
{
return timeIndex_;
}
@ -75,23 +73,10 @@ Foam::GeometricField<Type, PatchField, GeoMesh>::timeIndex() const
template<class Type, template<class> class PatchField, class GeoMesh>
inline Foam::label&
Foam::GeometricField<Type, PatchField, GeoMesh>::timeIndex()
Foam::GeometricField<Type, PatchField, GeoMesh>::timeIndex() noexcept
{
return timeIndex_;
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class Type, template<class> class PatchField, class GeoMesh>
inline
const typename
Foam::GeometricField<Type, PatchField, GeoMesh>::Internal&
Foam::GeometricField<Type, PatchField, GeoMesh>::
operator()() const
{
return *this;
}
// ************************************************************************* //

View File

@ -113,10 +113,14 @@ void MapGeometricFields
}
// Map the internal field
MapInternalField<Type, MeshMapper, GeoMesh>()(field.ref(), mapper);
MapInternalField<Type, MeshMapper, GeoMesh>()
(
field.internalFieldRef(),
mapper
);
// Map the patch fields
typename FieldType::Boundary& bfield = field.boundaryFieldRef();
auto& bfield = field.boundaryFieldRef();
forAll(bfield, patchi)
{

View File

@ -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

View File

@ -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

View File

@ -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<T&>(cref()); }
//- Return a shallow copy as a wrapped reference, preserving the
//- const/non-const status.

View File

@ -232,13 +232,6 @@ inline T& Foam::refPtr<T>::ref() const
}
template<class T>
inline T& Foam::refPtr<T>::constCast() const
{
return const_cast<T&>(cref());
}
template<class T>
inline Foam::refPtr<T> Foam::refPtr<T>::shallowClone() const noexcept
{

View File

@ -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<T&>(cref()); }
// Edit

View File

@ -234,13 +234,6 @@ inline T& Foam::tmp<T>::ref() const
}
template<class T>
inline T& Foam::tmp<T>::constCast() const
{
return const_cast<T&>(cref());
}
template<class T>
inline T* Foam::tmp<T>::ptr() const
{

View File

@ -381,14 +381,14 @@ CrankNicolsonDdtScheme<Type>::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())

View File

@ -92,7 +92,7 @@ Foam::fv::skewCorrectedSnGrad<Type>::fullGradCorrection
mesh,
dimensionedVector(dimLength, Zero)
);
vectorField& kPI = kP.ref().field();
vectorField& kPI = kP.primitiveFieldRef();
surfaceVectorField kN
(
@ -107,7 +107,7 @@ Foam::fv::skewCorrectedSnGrad<Type>::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<Type>::fullGradCorrection
// Skewness and non-rothogonal correction
{
ssf.ref().field().replace
ssf.primitiveFieldRef().replace
(
cmpt,
(

View File

@ -260,7 +260,7 @@ Foam::surfaceInterpolationScheme<Type>::dotInterpolate
Field<RetType>& sfi = sf.primitiveFieldRef();
const typename SFType::Internal& Sfi = Sf();
const typename SFType::Internal& Sfi = Sf.internalField();
for (label fi=0; fi<P.size(); fi++)
{

View File

@ -89,7 +89,7 @@ void Foam::volPointInterpolation::addSeparated
Pout<< "volPointInterpolation::addSeparated" << endl;
}
auto& pfi = pf.ref();
auto& pfi = pf.internalFieldRef();
auto& pfbf = pf.boundaryFieldRef();
const label startOfRequests = UPstream::nRequests();

View File

@ -62,7 +62,7 @@ Foam::isoAdvection::isoAdvection
mesh_(alpha1.mesh()),
dict_(mesh_.solverDict(alpha1.name())),
alpha1_(alpha1),
alpha1In_(alpha1.ref()),
alpha1In_(alpha1.primitiveFieldRef()),
phi_(phi),
U_(U),
dVf_