From 182afc27bafd634bb3a06a71772fc53042c148da Mon Sep 17 00:00:00 2001 From: Mark Olesen <Mark.Olesen@esi-group.com> Date: Thu, 25 Jan 2024 10:02:52 +0100 Subject: [PATCH] STYLE: noexcept for nullObject functions STYLE: use nullObject for return values of NotImplemented STYLE: shallowCopy(nullptr) shortcut --- .../twoPhaseMixtureThermo.H | 8 ++-- .../multiphaseMixtureThermo.H | 8 ++-- .../twoPhaseMixtureEThermo.H | 8 ++-- .../test/nullObject/Test-nullObject.C | 22 +++++------ src/OpenFOAM/containers/Bits/bitSet/bitSet.H | 7 +++- src/OpenFOAM/containers/Bits/bitSet/bitSetI.H | 6 --- .../CompactListList/CompactListList.H | 7 +++- .../CompactListList/CompactListListI.H | 9 ----- .../containers/Lists/FixedList/FixedList.H | 11 ++++-- .../containers/Lists/FixedList/FixedListI.H | 9 ----- src/OpenFOAM/containers/Lists/List/List.H | 8 +++- src/OpenFOAM/containers/Lists/List/ListI.H | 7 ---- src/OpenFOAM/containers/Lists/List/SubList.H | 8 +++- src/OpenFOAM/containers/Lists/List/SubListI.H | 11 +----- src/OpenFOAM/containers/Lists/List/UList.H | 11 +++++- src/OpenFOAM/containers/Lists/List/UListI.H | 15 ++++---- .../containers/Lists/ListOps/ListOps.C | 2 +- .../Lists/ListOps/ListOpsTemplates.C | 2 +- .../Function1/Function1Expression.C | 2 +- .../DimensionedField/DimensionedField.H | 7 +++- .../DimensionedField/DimensionedFieldI.H | 8 ---- .../DimensionedField/SlicedDimensionedField.H | 2 +- .../fields/Fields/DynamicField/DynamicField.H | 4 +- src/OpenFOAM/fields/Fields/Field/Field.H | 8 +++- src/OpenFOAM/fields/Fields/Field/FieldI.H | 9 ----- src/OpenFOAM/fields/Fields/Field/SubField.H | 8 +++- src/OpenFOAM/fields/Fields/Field/SubFieldI.H | 9 ----- .../GeometricField/GeometricField.H | 7 +++- .../GeometricField/GeometricFieldI.H | 8 ---- .../SlicedGeometricField.C | 2 +- src/OpenFOAM/matrices/Matrix/Matrix.H | 8 +++- src/OpenFOAM/matrices/Matrix/MatrixI.H | 7 ---- .../processorCyclicGAMGInterfaceField.H | 2 +- src/OpenFOAM/meshes/lduMesh/lduMesh.C | 3 +- .../primitives/nullObject/nullObject.H | 37 ++++++++++++++----- .../primitives/strings/wordRes/wordRes.H | 8 +++- .../primitives/strings/wordRes/wordResI.H | 6 --- src/fileFormats/ensight/file/ensightFile.H | 2 +- src/fileFormats/ensight/file/ensightGeoFile.H | 2 +- .../basic/sliced/slicedFaPatchField.C | 2 +- .../basic/sliced/slicedFaePatchField.C | 2 +- .../basic/sliced/slicedFvPatchField.C | 2 +- .../basic/sliced/slicedFvsPatchField.C | 2 +- .../ddtSchemes/ddtScheme/ddtScheme.C | 21 ++--------- .../fvMatrices/fvMatrix/fvMatrix.C | 12 +++--- src/mesh/blockMesh/PDRblockMesh/PDRblock.C | 6 --- src/mesh/blockMesh/PDRblockMesh/PDRblock.H | 7 +++- .../boundaryAdjointContribution.C | 2 +- .../calculatedProcessorGAMGInterfaceField.H | 2 +- .../oversetGAMGInterfaceField.H | 2 +- .../multiphaseInterSystem.H | 2 +- .../PurePhaseModel/PurePhaseModel.C | 2 +- .../basicSolidChemistryModel.C | 18 ++------- .../reaction/Reactions/Reaction/Reaction.C | 4 +- 54 files changed, 170 insertions(+), 224 deletions(-) diff --git a/applications/solvers/multiphase/compressibleInterFoam/twoPhaseMixtureThermo/twoPhaseMixtureThermo.H b/applications/solvers/multiphase/compressibleInterFoam/twoPhaseMixtureThermo/twoPhaseMixtureThermo.H index c712e5a47fe..9209cc41d27 100644 --- a/applications/solvers/multiphase/compressibleInterFoam/twoPhaseMixtureThermo/twoPhaseMixtureThermo.H +++ b/applications/solvers/multiphase/compressibleInterFoam/twoPhaseMixtureThermo/twoPhaseMixtureThermo.H @@ -135,14 +135,14 @@ public: virtual volScalarField& he() { NotImplemented; - return thermo1_->he(); + return const_cast<volScalarField&>(volScalarField::null()); } //- Enthalpy/Internal energy [J/kg] virtual const volScalarField& he() const { NotImplemented; - return thermo1_->he(); + return volScalarField::null(); } //- Enthalpy/Internal energy @@ -213,7 +213,7 @@ public: ) const { NotImplemented; - return tmp<scalarField>::New(p); + return nullptr; } //- Heat capacity at constant volume [J/kg/K] @@ -236,7 +236,7 @@ public: ) const { NotImplemented; - return tmp<scalarField>::New(p); + return nullptr; } //- Gamma = Cp/Cv [] diff --git a/applications/solvers/multiphase/compressibleMultiphaseInterFoam/multiphaseMixtureThermo/multiphaseMixtureThermo.H b/applications/solvers/multiphase/compressibleMultiphaseInterFoam/multiphaseMixtureThermo/multiphaseMixtureThermo.H index 472bd285aaa..c5e90dada57 100644 --- a/applications/solvers/multiphase/compressibleMultiphaseInterFoam/multiphaseMixtureThermo/multiphaseMixtureThermo.H +++ b/applications/solvers/multiphase/compressibleMultiphaseInterFoam/multiphaseMixtureThermo/multiphaseMixtureThermo.H @@ -243,14 +243,14 @@ public: virtual volScalarField& he() { NotImplemented; - return phases_[0].thermo().he(); + return const_cast<volScalarField&>(volScalarField::null()); } //- Enthalpy/Internal energy [J/kg] virtual const volScalarField& he() const { NotImplemented; - return phases_[0].thermo().he(); + return volScalarField::null(); } //- Enthalpy/Internal energy @@ -327,7 +327,7 @@ public: ) const { NotImplemented; - return tmp<scalarField>::New(p); + return nullptr; } //- Heat capacity at constant volume [J/kg/K] @@ -350,7 +350,7 @@ public: ) const { NotImplemented; - return tmp<scalarField>::New(p); + return nullptr; } //- Gamma = Cp/Cv [] diff --git a/applications/solvers/multiphase/interCondensatingEvaporatingFoam/temperaturePhaseChangeTwoPhaseMixtures/twoPhaseMixtureEThermo/twoPhaseMixtureEThermo.H b/applications/solvers/multiphase/interCondensatingEvaporatingFoam/temperaturePhaseChangeTwoPhaseMixtures/twoPhaseMixtureEThermo/twoPhaseMixtureEThermo.H index cedad45329b..ab5b58febe3 100644 --- a/applications/solvers/multiphase/interCondensatingEvaporatingFoam/temperaturePhaseChangeTwoPhaseMixtures/twoPhaseMixtureEThermo/twoPhaseMixtureEThermo.H +++ b/applications/solvers/multiphase/interCondensatingEvaporatingFoam/temperaturePhaseChangeTwoPhaseMixtures/twoPhaseMixtureEThermo/twoPhaseMixtureEThermo.H @@ -86,14 +86,14 @@ public: virtual volScalarField& he() { NotImplemented; - return p(); + return const_cast<volScalarField&>(volScalarField::null()); } //- Return access to the internal energy field [J/Kg] virtual const volScalarField& he() const { NotImplemented; - return p(); + return volScalarField::null(); } //- Enthalpy/Internal energy @@ -182,7 +182,7 @@ public: ) const { NotImplemented; - return tmp<scalarField>::New(p); + return nullptr; } //- Return Cv of the mixture @@ -205,7 +205,7 @@ public: ) const { NotImplemented; - return tmp<scalarField>::New(p); + return nullptr; } //- Gamma = Cp/Cv [] diff --git a/applications/test/nullObject/Test-nullObject.C b/applications/test/nullObject/Test-nullObject.C index 5c86e4e5005..0f7cd10dad0 100644 --- a/applications/test/nullObject/Test-nullObject.C +++ b/applications/test/nullObject/Test-nullObject.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2014 OpenFOAM Foundation - Copyright (C) 2019-2020 OpenCFD Ltd. + Copyright (C) 2019-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -48,7 +48,7 @@ class SimpleClass public: //- Default construct - SimpleClass() {} + SimpleClass() = default; }; @@ -73,9 +73,8 @@ void printInfo(const UList<T>& list) int main() { // Test pointer and reference to a class - - SimpleClass* ptrToClass = new SimpleClass; - SimpleClass& refToClass(*ptrToClass); + auto ptrToClass = autoPtr<SimpleClass>::New(); + auto& refToClass = ptrToClass.ref(); std::cout << "nullObject addr=" << name(&(nullObjectPtr)) << nl @@ -89,13 +88,13 @@ int main() << " pointer:" << name(nullObjectPtr->pointer()) << nl << " value:" << nullObjectPtr->value() << nl << nl; - if (notNull(ptrToClass)) + if (notNull(ptrToClass.get())) { Info<< "Pass: ptrToClass is not null" << nl; } else { - Info<< "FAIL: refToClass is null" << nl; + Info<< "FAIL: ptrToClass is null" << nl; } if (notNull(refToClass)) @@ -110,8 +109,8 @@ int main() // Test pointer and reference to the nullObject - const SimpleClass* ptrToNull(NullObjectPtr<SimpleClass>()); - const SimpleClass& refToNull(*ptrToNull); + const SimpleClass* ptrToNull = NullObjectPtr<SimpleClass>(); + const SimpleClass& refToNull = (*ptrToNull); if (isNull(ptrToNull)) { @@ -131,9 +130,6 @@ int main() Info<< "FAIL: refToNull is not null" << nl; } - // Clean-up - delete ptrToClass; - // Test List casting { @@ -152,7 +148,7 @@ int main() // Looks pretty ugly though! NullObject::nullObject = "hello world"; - NullObject::nullObject = labelList({1, 2, 3}); + NullObject::nullObject = Foam::identity(5); Info<< nl; diff --git a/src/OpenFOAM/containers/Bits/bitSet/bitSet.H b/src/OpenFOAM/containers/Bits/bitSet/bitSet.H index 31d08d570fc..b1e4c7fdd48 100644 --- a/src/OpenFOAM/containers/Bits/bitSet/bitSet.H +++ b/src/OpenFOAM/containers/Bits/bitSet/bitSet.H @@ -120,8 +120,11 @@ public: // Static Member Functions - //- Return a null bitSet reference - inline static const bitSet& null(); + //- Return a null bitSet (reference to a nullObject). + static const bitSet& null() noexcept + { + return NullObjectRef<bitSet>(); + } //- Declare type-name (with debug switch) diff --git a/src/OpenFOAM/containers/Bits/bitSet/bitSetI.H b/src/OpenFOAM/containers/Bits/bitSet/bitSetI.H index 7e9eed87394..f035d0c99fc 100644 --- a/src/OpenFOAM/containers/Bits/bitSet/bitSetI.H +++ b/src/OpenFOAM/containers/Bits/bitSet/bitSetI.H @@ -405,12 +405,6 @@ inline Foam::label Foam::bitSet::find_next(label pos) const // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -inline const Foam::bitSet& Foam::bitSet::null() -{ - return NullObjectRef<bitSet>(); -} - - inline bool Foam::bitSet::all() const { if (empty()) return true; // SIC. boost convention diff --git a/src/OpenFOAM/containers/CompactLists/CompactListList/CompactListList.H b/src/OpenFOAM/containers/CompactLists/CompactListList/CompactListList.H index 34011791162..7935b876a24 100644 --- a/src/OpenFOAM/containers/CompactLists/CompactListList/CompactListList.H +++ b/src/OpenFOAM/containers/CompactLists/CompactListList/CompactListList.H @@ -138,8 +138,11 @@ public: // Static Member Functions - //- Return a CompactListList reference to a nullObject - inline static const CompactListList<T>& null(); + //- Return a null CompactListList (reference to a nullObject). + static const CompactListList<T>& null() noexcept + { + return NullObjectRef<CompactListList<T>>(); + } //- Construct by packing together the list of lists template<class SubListType = List<T>> diff --git a/src/OpenFOAM/containers/CompactLists/CompactListList/CompactListListI.H b/src/OpenFOAM/containers/CompactLists/CompactListList/CompactListListI.H index f5a17ba86d5..5e5209fcb95 100644 --- a/src/OpenFOAM/containers/CompactLists/CompactListList/CompactListListI.H +++ b/src/OpenFOAM/containers/CompactLists/CompactListList/CompactListListI.H @@ -29,15 +29,6 @@ License #include "ListOps.H" #include "SubList.H" -// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // - -template<class T> -inline const Foam::CompactListList<T>& Foam::CompactListList<T>::null() -{ - return NullObjectRef<CompactListList<T>>(); -} - - // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // template<class T> diff --git a/src/OpenFOAM/containers/Lists/FixedList/FixedList.H b/src/OpenFOAM/containers/Lists/FixedList/FixedList.H index 59e1188bee9..1c1f8c8476a 100644 --- a/src/OpenFOAM/containers/Lists/FixedList/FixedList.H +++ b/src/OpenFOAM/containers/Lists/FixedList/FixedList.H @@ -46,9 +46,10 @@ SourceFiles #include "zero.H" #include "contiguous.H" #include "stdFoam.H" -#include "autoPtr.H" +#include "nullObject.H" #include "Hash.H" #include "ListPolicy.H" +#include "autoPtr.H" // <algorithm> already included by stdFoam.H #include <iterator> @@ -139,8 +140,12 @@ public: // Static Functions - //- Return a null FixedList - inline static const FixedList<T, N>& null(); + //- Return a null FixedList (reference to a nullObject). + //- Read/write access is questionable + static const FixedList<T, N>& null() noexcept + { + return NullObjectRef<FixedList<T, N>>(); + } // Constructors diff --git a/src/OpenFOAM/containers/Lists/FixedList/FixedListI.H b/src/OpenFOAM/containers/Lists/FixedList/FixedListI.H index 4bef6f07b30..7d590c37994 100644 --- a/src/OpenFOAM/containers/Lists/FixedList/FixedListI.H +++ b/src/OpenFOAM/containers/Lists/FixedList/FixedListI.H @@ -28,15 +28,6 @@ License #include "UList.H" -// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // - -template<class T, unsigned N> -inline const Foam::FixedList<T, N>& Foam::FixedList<T, N>::null() -{ - return NullObjectRef<FixedList<T, N>>(); -} - - // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template<class T, unsigned N> diff --git a/src/OpenFOAM/containers/Lists/List/List.H b/src/OpenFOAM/containers/Lists/List/List.H index 65caab9fd8b..87b9bf9019b 100644 --- a/src/OpenFOAM/containers/Lists/List/List.H +++ b/src/OpenFOAM/containers/Lists/List/List.H @@ -129,8 +129,12 @@ public: // Static Member Functions - //- Return a null List - inline static const List<T>& null(); + //- Return a null List (reference to a nullObject). + //- Behaves like an empty List. + static const List<T>& null() noexcept + { + return NullObjectRef<List<T>>(); + } // Constructors diff --git a/src/OpenFOAM/containers/Lists/List/ListI.H b/src/OpenFOAM/containers/Lists/List/ListI.H index 6bab28191b2..5bac2f0ee4b 100644 --- a/src/OpenFOAM/containers/Lists/List/ListI.H +++ b/src/OpenFOAM/containers/Lists/List/ListI.H @@ -133,13 +133,6 @@ inline Foam::autoPtr<Foam::List<T>> Foam::List<T>::clone() const // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -template<class T> -inline const Foam::List<T>& Foam::List<T>::null() -{ - return NullObjectRef<List<T>>(); -} - - template<class T> inline void Foam::List<T>::clear() { diff --git a/src/OpenFOAM/containers/Lists/List/SubList.H b/src/OpenFOAM/containers/Lists/List/SubList.H index e34f27fcd09..42f2a1dcd64 100644 --- a/src/OpenFOAM/containers/Lists/List/SubList.H +++ b/src/OpenFOAM/containers/Lists/List/SubList.H @@ -73,8 +73,12 @@ public: // Static Functions - //- Return a null SubList - inline static const SubList<T>& null(); + //- Return a null SubList (reference to a nullObject). + //- Behaves like an empty SubList. + static const SubList<T>& null() noexcept + { + return NullObjectRef<SubList<T>>(); + } // Generated Methods diff --git a/src/OpenFOAM/containers/Lists/List/SubListI.H b/src/OpenFOAM/containers/Lists/List/SubListI.H index 3b15f4c9e13..f18c31646bb 100644 --- a/src/OpenFOAM/containers/Lists/List/SubListI.H +++ b/src/OpenFOAM/containers/Lists/List/SubListI.H @@ -28,15 +28,6 @@ License #include "FixedList.H" -// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // - -template<class T> -inline const Foam::SubList<T>& Foam::SubList<T>::null() -{ - return NullObjectRef<SubList<T>>(); -} - - // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template<class T> @@ -124,7 +115,7 @@ inline Foam::SubList<T>::SubList template<class T> inline Foam::UList<T>& Foam::SubList<T>::reset(std::nullptr_t) noexcept { - UList<T>::shallowCopy(nullptr, 0); + UList<T>::shallowCopy(nullptr); return *this; } diff --git a/src/OpenFOAM/containers/Lists/List/UList.H b/src/OpenFOAM/containers/Lists/List/UList.H index 252ec61cc34..ceb50199c5a 100644 --- a/src/OpenFOAM/containers/Lists/List/UList.H +++ b/src/OpenFOAM/containers/Lists/List/UList.H @@ -183,8 +183,12 @@ public: // Static Functions - //- Return a UList reference to a nullObject - inline static const UList<T>& null(); + //- Return a null UList (reference to a nullObject). + //- Behaves like an empty UList. + static const UList<T>& null() noexcept + { + return NullObjectRef<UList<T>>(); + } // Public Classes @@ -367,6 +371,9 @@ public: //- Copy the pointer and size inline void shallowCopy(T* __restrict__ ptr, const label len) noexcept; + //- Copy nullptr and zero size + inline void shallowCopy(std::nullptr_t) noexcept; + //- Copy the pointer and size held by the given UList inline void shallowCopy(const UList<T>& list) noexcept; diff --git a/src/OpenFOAM/containers/Lists/List/UListI.H b/src/OpenFOAM/containers/Lists/List/UListI.H index b143475599a..74cd4c3bbe0 100644 --- a/src/OpenFOAM/containers/Lists/List/UListI.H +++ b/src/OpenFOAM/containers/Lists/List/UListI.H @@ -93,13 +93,6 @@ inline void Foam::UList<T>::fill_uniform(const Foam::zero) // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -template<class T> -inline const Foam::UList<T>& Foam::UList<T>::null() -{ - return NullObjectRef<UList<T>>(); -} - - template<class T> inline Foam::label Foam::UList<T>::fcIndex(const label i) const noexcept { @@ -330,6 +323,14 @@ inline void Foam::UList<T>::shallowCopy } +template<class T> +inline void Foam::UList<T>::shallowCopy(std::nullptr_t) noexcept +{ + size_ = 0; + v_ = nullptr; +} + + template<class T> inline void Foam::UList<T>::shallowCopy(const UList<T>& list) noexcept { diff --git a/src/OpenFOAM/containers/Lists/ListOps/ListOps.C b/src/OpenFOAM/containers/Lists/ListOps/ListOps.C index 9e4dbd83b7d..dd73a696863 100644 --- a/src/OpenFOAM/containers/Lists/ListOps/ListOps.C +++ b/src/OpenFOAM/containers/Lists/ListOps/ListOps.C @@ -116,7 +116,7 @@ Foam::labelListList Foam::invertOneToMany const labelUList& map ) { - labelList sizes(len, Zero); + labelList sizes(len, Foam::zero{}); for (const label newIdx : map) { diff --git a/src/OpenFOAM/containers/Lists/ListOps/ListOpsTemplates.C b/src/OpenFOAM/containers/Lists/ListOps/ListOpsTemplates.C index 4c70358920e..e1914040e3e 100644 --- a/src/OpenFOAM/containers/Lists/ListOps/ListOpsTemplates.C +++ b/src/OpenFOAM/containers/Lists/ListOps/ListOpsTemplates.C @@ -707,7 +707,7 @@ void Foam::invertManyToMany ) { // The output list sizes - labelList sizes(len, Zero); + labelList sizes(len, Foam::zero{}); for (const InputIntListType& sublist : input) { diff --git a/src/OpenFOAM/expressions/Function1/Function1Expression.C b/src/OpenFOAM/expressions/Function1/Function1Expression.C index dd45c913e74..532344efa86 100644 --- a/src/OpenFOAM/expressions/Function1/Function1Expression.C +++ b/src/OpenFOAM/expressions/Function1/Function1Expression.C @@ -115,7 +115,7 @@ Type Foam::Function1Types::Function1Expression<Type>::integrate ) const { NotImplemented; - return Zero; + return Type(); } diff --git a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedField.H b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedField.H index c193f7e1766..e7b4d21c6f1 100644 --- a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedField.H +++ b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedField.H @@ -137,8 +137,11 @@ public: // Static Member Functions - //- Return a NullObjectRef DimensionedField - inline static const DimensionedField<Type, GeoMesh>& null(); + //- Return a null DimensionedField (reference to a nullObject). + static const DimensionedField<Type, GeoMesh>& null() noexcept + { + return NullObjectRef<DimensionedField<Type, GeoMesh>>(); + } // Constructors diff --git a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldI.H b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldI.H index 5f898c1e6b1..3391dc32f46 100644 --- a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldI.H +++ b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/DimensionedFieldI.H @@ -28,14 +28,6 @@ License // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -template<class Type, class GeoMesh> -inline const Foam::DimensionedField<Type, GeoMesh>& -Foam::DimensionedField<Type, GeoMesh>::null() -{ - return NullObjectRef<DimensionedField<Type, GeoMesh>>(); -} - - template<class Type, class GeoMesh> inline const typename GeoMesh::Mesh& Foam::DimensionedField<Type, GeoMesh>::mesh() const noexcept diff --git a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/SlicedDimensionedField.H b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/SlicedDimensionedField.H index 9f6df361ac9..de0eb8a6ccb 100644 --- a/src/OpenFOAM/fields/DimensionedFields/DimensionedField/SlicedDimensionedField.H +++ b/src/OpenFOAM/fields/DimensionedFields/DimensionedField/SlicedDimensionedField.H @@ -85,7 +85,7 @@ public: ~SlicedDimensionedField() { // Set internalField to nullptr to avoid deletion of underlying field - UList<Type>::shallowCopy(UList<Type>()); + UList<Type>::shallowCopy(nullptr); } }; diff --git a/src/OpenFOAM/fields/Fields/DynamicField/DynamicField.H b/src/OpenFOAM/fields/Fields/DynamicField/DynamicField.H index 7debed435ba..602e6f1cce0 100644 --- a/src/OpenFOAM/fields/Fields/DynamicField/DynamicField.H +++ b/src/OpenFOAM/fields/Fields/DynamicField/DynamicField.H @@ -97,8 +97,8 @@ public: // Static Member Functions - //- Return a null field - inline static const DynamicField<T, SizeMin>& null() + //- Return a null DynamicField (reference to a nullObject). + static const DynamicField<T, SizeMin>& null() noexcept { return NullObjectRef<DynamicField<T, SizeMin>>(); } diff --git a/src/OpenFOAM/fields/Fields/Field/Field.H b/src/OpenFOAM/fields/Fields/Field/Field.H index 9a2d17c7a44..fb7851edc6d 100644 --- a/src/OpenFOAM/fields/Fields/Field/Field.H +++ b/src/OpenFOAM/fields/Fields/Field/Field.H @@ -122,8 +122,12 @@ public: // Static Member Functions - //- Return nullObject reference Field - inline static const Field<Type>& null(); + //- Return a null Field (reference to a nullObject). + //- Behaves like an empty Field. + static const Field<Type>& null() noexcept + { + return NullObjectRef<Field<Type>>(); + } // Constructors diff --git a/src/OpenFOAM/fields/Fields/Field/FieldI.H b/src/OpenFOAM/fields/Fields/Field/FieldI.H index a5c37b841b0..4c34df88b14 100644 --- a/src/OpenFOAM/fields/Fields/Field/FieldI.H +++ b/src/OpenFOAM/fields/Fields/Field/FieldI.H @@ -25,15 +25,6 @@ License \*---------------------------------------------------------------------------*/ -// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // - -template<class Type> -inline const Foam::Field<Type>& Foam::Field<Type>::null() -{ - return NullObjectRef<Field<Type>>(); -} - - // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template<class Type> diff --git a/src/OpenFOAM/fields/Fields/Field/SubField.H b/src/OpenFOAM/fields/Fields/Field/SubField.H index 48cc8530ffa..15e09522a71 100644 --- a/src/OpenFOAM/fields/Fields/Field/SubField.H +++ b/src/OpenFOAM/fields/Fields/Field/SubField.H @@ -69,8 +69,12 @@ public: // Static Member Functions - //- Return nullObject reference SubField - inline static const SubField<Type>& null(); + //- Return a null SubField (reference to a nullObject). + //- Behaves like an empty SubField. + static const SubField<Type>& null() noexcept + { + return NullObjectRef<SubField<Type>>(); + } // Constructors diff --git a/src/OpenFOAM/fields/Fields/Field/SubFieldI.H b/src/OpenFOAM/fields/Fields/Field/SubFieldI.H index 738096e0396..235f981da7e 100644 --- a/src/OpenFOAM/fields/Fields/Field/SubFieldI.H +++ b/src/OpenFOAM/fields/Fields/Field/SubFieldI.H @@ -26,15 +26,6 @@ License \*---------------------------------------------------------------------------*/ -// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // - -template<class Type> -inline const Foam::SubField<Type>& Foam::SubField<Type>::null() -{ - return NullObjectRef<SubField<Type>>(); -} - - // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template<class Type> diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.H b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.H index 8c66779bf2f..427009b2455 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.H +++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.H @@ -154,8 +154,11 @@ public: // Static Member Functions - //- Return a null geometric field - inline static const GeometricField<Type, PatchField, GeoMesh>& null(); + //- Return a null GeometricField (reference to a nullObject). + static const GeometricField<Type, PatchField, GeoMesh>& null() noexcept + { + return NullObjectRef<GeometricField<Type, PatchField, GeoMesh>>(); + } // Constructors diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldI.H b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldI.H index 90b57d17a4a..0f3083ae48b 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldI.H +++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricFieldI.H @@ -28,14 +28,6 @@ License // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -template<class Type, template<class> class PatchField, class GeoMesh> -inline const Foam::GeometricField<Type, PatchField, GeoMesh>& -Foam::GeometricField<Type, PatchField, GeoMesh>::null() -{ - return NullObjectRef<GeometricField<Type, PatchField, GeoMesh>>(); -} - - template<class Type, template<class> class PatchField, class GeoMesh> inline const typename Foam::GeometricField<Type, PatchField, GeoMesh>::Internal& diff --git a/src/OpenFOAM/fields/GeometricFields/SlicedGeometricField/SlicedGeometricField.C b/src/OpenFOAM/fields/GeometricFields/SlicedGeometricField/SlicedGeometricField.C index 2b378137fd4..f77ccd0bfab 100644 --- a/src/OpenFOAM/fields/GeometricFields/SlicedGeometricField/SlicedGeometricField.C +++ b/src/OpenFOAM/fields/GeometricFields/SlicedGeometricField/SlicedGeometricField.C @@ -368,7 +368,7 @@ Foam::SlicedGeometricField<Type, PatchField, SlicedPatchField, GeoMesh>:: ~SlicedGeometricField() { // Set internalField to nullptr to avoid deletion of underlying field - UList<Type>::shallowCopy(UList<Type>()); + UList<Type>::shallowCopy(nullptr); } diff --git a/src/OpenFOAM/matrices/Matrix/Matrix.H b/src/OpenFOAM/matrices/Matrix/Matrix.H index 7bff0b2a773..cdfa892253b 100644 --- a/src/OpenFOAM/matrices/Matrix/Matrix.H +++ b/src/OpenFOAM/matrices/Matrix/Matrix.H @@ -114,8 +114,12 @@ public: // Static Member Functions - //- Return a null Matrix - inline static const Matrix<Form, Type>& null(); + //- Return a null Matrix (reference to a nullObject). + //- Behaves like a empty Matrix. + static const Matrix<Form, Type>& null() noexcept + { + return NullObjectRef<Matrix<Form, Type>>(); + } // Iterators diff --git a/src/OpenFOAM/matrices/Matrix/MatrixI.H b/src/OpenFOAM/matrices/Matrix/MatrixI.H index 17f35969ccc..b1dc3b1267c 100644 --- a/src/OpenFOAM/matrices/Matrix/MatrixI.H +++ b/src/OpenFOAM/matrices/Matrix/MatrixI.H @@ -85,13 +85,6 @@ Foam::Matrix<Form, Type>::clone() const // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -template<class Form, class Type> -inline const Foam::Matrix<Form, Type>& Foam::Matrix<Form, Type>::null() -{ - return NullObjectRef<Matrix<Form, Type>>(); -} - - template<class Form, class Type> inline Foam::label Foam::Matrix<Form, Type>::size() const { diff --git a/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/interfaceFields/processorCyclicGAMGInterfaceField/processorCyclicGAMGInterfaceField.H b/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/interfaceFields/processorCyclicGAMGInterfaceField/processorCyclicGAMGInterfaceField.H index 376631dd7d2..5096b8cfbbb 100644 --- a/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/interfaceFields/processorCyclicGAMGInterfaceField/processorCyclicGAMGInterfaceField.H +++ b/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/interfaceFields/processorCyclicGAMGInterfaceField/processorCyclicGAMGInterfaceField.H @@ -102,7 +102,7 @@ public: ) const { NotImplemented; - return autoPtr<GAMGInterfaceField>(nullptr); + return nullptr; } diff --git a/src/OpenFOAM/meshes/lduMesh/lduMesh.C b/src/OpenFOAM/meshes/lduMesh/lduMesh.C index 16e73ddf7c1..a6c62c3811b 100644 --- a/src/OpenFOAM/meshes/lduMesh/lduMesh.C +++ b/src/OpenFOAM/meshes/lduMesh/lduMesh.C @@ -42,8 +42,7 @@ namespace Foam const Foam::objectRegistry& Foam::lduMesh::thisDb() const { NotImplemented; - const objectRegistry* orPtr_ = nullptr; - return *orPtr_; + return NullObjectRef<objectRegistry>(); } diff --git a/src/OpenFOAM/primitives/nullObject/nullObject.H b/src/OpenFOAM/primitives/nullObject/nullObject.H index 8d3793f50c9..f8d1fc269e6 100644 --- a/src/OpenFOAM/primitives/nullObject/nullObject.H +++ b/src/OpenFOAM/primitives/nullObject/nullObject.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2014 OpenFOAM Foundation - Copyright (C) 2017-2020 OpenCFD Ltd. + Copyright (C) 2017-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -158,7 +158,7 @@ extern const NullObject* nullObjectPtr; // IOstream Operators -//- Read from Istream consumes no content +//- Read from Istream consumes no content, does not change NullObject inline Istream& operator>>(Istream& is, const NullObject&) noexcept { return is; @@ -173,31 +173,48 @@ inline Ostream& operator<<(Ostream& os, const NullObject&) noexcept // Global Functions -//- Pointer (of type T) to the nullObject +//- Const pointer (of type T) to the nullObject template<class T> -inline const T* NullObjectPtr() +inline const T* NullObjectPtr() noexcept { return reinterpret_cast<const T*>(nullObjectPtr); } -//- Reference (of type T) to the nullObject +//- Non-const pointer (of type T) to the nullObject. +//- Only use when nothing will be written into it! template<class T> -inline const T& NullObjectRef() +inline T* NullObjectPtr_constCast() noexcept +{ + return reinterpret_cast<T*>(const_cast<NullObject*>(nullObjectPtr)); +} + + +//- Const reference (of type T) to the nullObject +template<class T> +inline const T& NullObjectRef() noexcept { return *reinterpret_cast<const T*>(nullObjectPtr); } +//- Non-const reference (of type T) to the nullObject +//- Only use when nothing will be written into it! +template<class T> +inline T& NullObjectRef_constCast() noexcept +{ + return *reinterpret_cast<T*>(const_cast<NullObject*>(nullObjectPtr)); +} + //- True if ptr is a pointer (of type T) to the nullObject template<class T> -inline bool isNull(const T* ptr) +inline bool isNull(const T* ptr) noexcept { return ptr == NullObjectPtr<T>(); } //- True if obj is a reference (of type T) to the nullObject template<class T> -inline bool isNull(const T& obj) +inline bool isNull(const T& obj) noexcept { return &obj == NullObjectPtr<T>(); } @@ -205,14 +222,14 @@ inline bool isNull(const T& obj) //- True if ptr is not a pointer (of type T) to the nullObject template<class T> -inline bool notNull(const T* ptr) +inline bool notNull(const T* ptr) noexcept { return ptr != NullObjectPtr<T>(); } //- True if obj is not a reference (of type T) to the nullObject template<class T> -inline bool notNull(const T& obj) +inline bool notNull(const T& obj) noexcept { return &obj != NullObjectPtr<T>(); } diff --git a/src/OpenFOAM/primitives/strings/wordRes/wordRes.H b/src/OpenFOAM/primitives/strings/wordRes/wordRes.H index de7c5d56aaa..e665f4d52dc 100644 --- a/src/OpenFOAM/primitives/strings/wordRes/wordRes.H +++ b/src/OpenFOAM/primitives/strings/wordRes/wordRes.H @@ -86,8 +86,12 @@ public: // Static Data / Methods - //- Return a null wordRes - a reference to the NullObject - inline static const wordRes& null(); + //- Return a null wordRes (reference to a nullObject). + //- Behaves like a empty wordRes. + static const wordRes& null() noexcept + { + return NullObjectRef<wordRes>(); + } //- Return a wordRes with duplicate entries filtered out. // No distinction made between literals and regular expressions. diff --git a/src/OpenFOAM/primitives/strings/wordRes/wordResI.H b/src/OpenFOAM/primitives/strings/wordRes/wordResI.H index e82a49c89f6..2b72076d961 100644 --- a/src/OpenFOAM/primitives/strings/wordRes/wordResI.H +++ b/src/OpenFOAM/primitives/strings/wordRes/wordResI.H @@ -27,12 +27,6 @@ License // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // -inline const Foam::wordRes& Foam::wordRes::null() -{ - return NullObjectRef<wordRes>(); -} - - inline Foam::label Foam::wordRes::first_match ( const UList<wordRe>& selectors, diff --git a/src/fileFormats/ensight/file/ensightFile.H b/src/fileFormats/ensight/file/ensightFile.H index e565f3eb2cb..2e16f0e95d2 100644 --- a/src/fileFormats/ensight/file/ensightFile.H +++ b/src/fileFormats/ensight/file/ensightFile.H @@ -92,7 +92,7 @@ public: // Static Functions //- Return a null ensightFile - static const ensightFile& null() + static const ensightFile& null() noexcept { return NullObjectRef<ensightFile>(); } diff --git a/src/fileFormats/ensight/file/ensightGeoFile.H b/src/fileFormats/ensight/file/ensightGeoFile.H index 86d2d9beed7..54c8078a6a7 100644 --- a/src/fileFormats/ensight/file/ensightGeoFile.H +++ b/src/fileFormats/ensight/file/ensightGeoFile.H @@ -72,7 +72,7 @@ public: // Static Functions //- Return a null ensightGeoFile - static const ensightGeoFile& null() + static const ensightGeoFile& null() noexcept { return NullObjectRef<ensightGeoFile>(); } diff --git a/src/finiteArea/fields/faPatchFields/basic/sliced/slicedFaPatchField.C b/src/finiteArea/fields/faPatchFields/basic/sliced/slicedFaPatchField.C index fb9846b1482..650beb7daa8 100644 --- a/src/finiteArea/fields/faPatchFields/basic/sliced/slicedFaPatchField.C +++ b/src/finiteArea/fields/faPatchFields/basic/sliced/slicedFaPatchField.C @@ -127,7 +127,7 @@ template<class Type> Foam::slicedFaPatchField<Type>::~slicedFaPatchField() { // Set to nullptr to avoid deletion of underlying field - UList<Type>::shallowCopy(UList<Type>()); + UList<Type>::shallowCopy(nullptr); } diff --git a/src/finiteArea/fields/faePatchFields/basic/sliced/slicedFaePatchField.C b/src/finiteArea/fields/faePatchFields/basic/sliced/slicedFaePatchField.C index fd746a305e8..9f0e1818aba 100644 --- a/src/finiteArea/fields/faePatchFields/basic/sliced/slicedFaePatchField.C +++ b/src/finiteArea/fields/faePatchFields/basic/sliced/slicedFaePatchField.C @@ -127,7 +127,7 @@ template<class Type> Foam::slicedFaePatchField<Type>::~slicedFaePatchField() { // Set to nullptr to avoid deletion of underlying field - UList<Type>::shallowCopy(UList<Type>()); + UList<Type>::shallowCopy(nullptr); } diff --git a/src/finiteVolume/fields/fvPatchFields/basic/sliced/slicedFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/basic/sliced/slicedFvPatchField.C index a15239c2bb3..c053c9b9344 100644 --- a/src/finiteVolume/fields/fvPatchFields/basic/sliced/slicedFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/basic/sliced/slicedFvPatchField.C @@ -127,7 +127,7 @@ template<class Type> Foam::slicedFvPatchField<Type>::~slicedFvPatchField() { // Set to nullptr to avoid deletion of underlying field - UList<Type>::shallowCopy(UList<Type>()); + UList<Type>::shallowCopy(nullptr); } diff --git a/src/finiteVolume/fields/fvsPatchFields/basic/sliced/slicedFvsPatchField.C b/src/finiteVolume/fields/fvsPatchFields/basic/sliced/slicedFvsPatchField.C index 08179b72e84..717918883f4 100644 --- a/src/finiteVolume/fields/fvsPatchFields/basic/sliced/slicedFvsPatchField.C +++ b/src/finiteVolume/fields/fvsPatchFields/basic/sliced/slicedFvsPatchField.C @@ -127,7 +127,7 @@ template<class Type> Foam::slicedFvsPatchField<Type>::~slicedFvsPatchField() { // Set to nullptr to avoid deletion of underlying field - UList<Type>::shallowCopy(UList<Type>()); + UList<Type>::shallowCopy(nullptr); } diff --git a/src/finiteVolume/finiteVolume/ddtSchemes/ddtScheme/ddtScheme.C b/src/finiteVolume/finiteVolume/ddtSchemes/ddtScheme/ddtScheme.C index 94a00c2a683..06209c1334c 100644 --- a/src/finiteVolume/finiteVolume/ddtSchemes/ddtScheme/ddtScheme.C +++ b/src/finiteVolume/finiteVolume/ddtSchemes/ddtScheme/ddtScheme.C @@ -96,11 +96,7 @@ tmp<GeometricField<Type, fvPatchField, volMesh>> ddtScheme<Type>::fvcDdt ) { NotImplemented; - - return tmp<GeometricField<Type, fvPatchField, volMesh>> - ( - GeometricField<Type, fvPatchField, volMesh>::null() - ); + return nullptr; } @@ -113,13 +109,7 @@ tmp<fvMatrix<Type>> ddtScheme<Type>::fvmDdt ) { NotImplemented; - - return tmp<fvMatrix<Type>>::New - ( - vf, - alpha.dimensions()*rho.dimensions() - *vf.dimensions()*dimVol/dimTime - ); + return nullptr; } @@ -130,15 +120,10 @@ tmp<GeometricField<Type, fvsPatchField, surfaceMesh>> ddtScheme<Type>::fvcDdt ) { NotImplemented; - - return tmp<GeometricField<Type, fvsPatchField, surfaceMesh>> - ( - GeometricField<Type, fvsPatchField, surfaceMesh>::null() - ); + return nullptr; } - template<class Type> tmp<surfaceScalarField> ddtScheme<Type>::fvcDdtPhiCoeff ( diff --git a/src/finiteVolume/fvMatrices/fvMatrix/fvMatrix.C b/src/finiteVolume/fvMatrices/fvMatrix/fvMatrix.C index 6b15f83645a..716a2b18960 100644 --- a/src/finiteVolume/fvMatrices/fvMatrix/fvMatrix.C +++ b/src/finiteVolume/fvMatrices/fvMatrix/fvMatrix.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2016-2023 OpenCFD Ltd. + Copyright (C) 2016-2024 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -894,13 +894,13 @@ void Foam::fvMatrix<Type>::transferFvMatrixCoeffs() template<class Type> Foam::lduPrimitiveMeshAssembly* Foam::fvMatrix<Type>::lduMeshPtr() { - const lduPrimitiveMeshAssembly* lduAssemMeshPtr = - psi_.mesh().thisDb().objectRegistry::template findObject + return + ( + psi_.mesh().thisDb().objectRegistry::template getObjectPtr < lduPrimitiveMeshAssembly - > (lduAssemblyName_); - - return const_cast<lduPrimitiveMeshAssembly*>(lduAssemMeshPtr); + > (lduAssemblyName_) + ); } diff --git a/src/mesh/blockMesh/PDRblockMesh/PDRblock.C b/src/mesh/blockMesh/PDRblockMesh/PDRblock.C index 5e27e500751..10db4aeb8af 100644 --- a/src/mesh/blockMesh/PDRblockMesh/PDRblock.C +++ b/src/mesh/blockMesh/PDRblockMesh/PDRblock.C @@ -106,12 +106,6 @@ bool Foam::PDRblock::checkMonotonic } -const Foam::PDRblock& Foam::PDRblock::null() -{ - return NullObjectRef<PDRblock>(); -} - - // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // void Foam::PDRblock::addDefaultPatches() diff --git a/src/mesh/blockMesh/PDRblockMesh/PDRblock.H b/src/mesh/blockMesh/PDRblockMesh/PDRblock.H index 8df077c4f44..d0302b075b5 100644 --- a/src/mesh/blockMesh/PDRblockMesh/PDRblock.H +++ b/src/mesh/blockMesh/PDRblockMesh/PDRblock.H @@ -429,8 +429,11 @@ public: // Static Member Functions - //- Return a PDRblock reference to a nullObject - static const PDRblock& null(); + //- Return a null PDRblock (reference to a nullObject). + static const PDRblock& null() noexcept + { + return NullObjectRef<PDRblock>(); + } // Constructors diff --git a/src/optimisation/adjointOptimisation/adjoint/boundaryAdjointContributions/boundaryAdjointContribution/boundaryAdjointContribution.C b/src/optimisation/adjointOptimisation/adjoint/boundaryAdjointContributions/boundaryAdjointContribution/boundaryAdjointContribution.C index a8220f2639d..a36d646dff2 100644 --- a/src/optimisation/adjointOptimisation/adjoint/boundaryAdjointContributions/boundaryAdjointContribution/boundaryAdjointContribution.C +++ b/src/optimisation/adjointOptimisation/adjoint/boundaryAdjointContributions/boundaryAdjointContribution/boundaryAdjointContribution.C @@ -144,7 +144,7 @@ tmp<fvPatchScalarField> boundaryAdjointContribution::turbulentDiffusivity() const { NotImplemented; - return tmp<fvPatchScalarField>(nullptr); + return nullptr; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/overset/lduPrimitiveProcessorInterface/GAMG/calculatedProcessorGAMGInterfaceField.H b/src/overset/lduPrimitiveProcessorInterface/GAMG/calculatedProcessorGAMGInterfaceField.H index d1e78eed35c..f06a90edb86 100644 --- a/src/overset/lduPrimitiveProcessorInterface/GAMG/calculatedProcessorGAMGInterfaceField.H +++ b/src/overset/lduPrimitiveProcessorInterface/GAMG/calculatedProcessorGAMGInterfaceField.H @@ -133,7 +133,7 @@ public: ) const { NotImplemented; - return autoPtr<GAMGInterfaceField>(nullptr); + return nullptr; } diff --git a/src/overset/oversetCoupledPolyPatch/oversetGAMGInterfaceField/oversetGAMGInterfaceField.H b/src/overset/oversetCoupledPolyPatch/oversetGAMGInterfaceField/oversetGAMGInterfaceField.H index 5edbd651f61..640a9940a26 100644 --- a/src/overset/oversetCoupledPolyPatch/oversetGAMGInterfaceField/oversetGAMGInterfaceField.H +++ b/src/overset/oversetCoupledPolyPatch/oversetGAMGInterfaceField/oversetGAMGInterfaceField.H @@ -105,7 +105,7 @@ public: ) const { NotImplemented; - return autoPtr<GAMGInterfaceField>(nullptr); + return nullptr; } diff --git a/src/phaseSystemModels/multiphaseInter/phasesSystem/multiphaseInterSystem/multiphaseInterSystem.H b/src/phaseSystemModels/multiphaseInter/phasesSystem/multiphaseInterSystem/multiphaseInterSystem.H index fbcacaefbc2..b9dfffb4a45 100644 --- a/src/phaseSystemModels/multiphaseInter/phasesSystem/multiphaseInterSystem/multiphaseInterSystem.H +++ b/src/phaseSystemModels/multiphaseInter/phasesSystem/multiphaseInterSystem/multiphaseInterSystem.H @@ -367,7 +367,7 @@ public: ) const { NotImplemented; - return tmp<scalarField>::New(p); + return nullptr; } //- Return Cv of the mixture diff --git a/src/phaseSystemModels/reactingEuler/multiphaseSystem/phaseModel/PurePhaseModel/PurePhaseModel.C b/src/phaseSystemModels/reactingEuler/multiphaseSystem/phaseModel/PurePhaseModel/PurePhaseModel.C index 6279a080a45..de620d523a1 100644 --- a/src/phaseSystemModels/reactingEuler/multiphaseSystem/phaseModel/PurePhaseModel/PurePhaseModel.C +++ b/src/phaseSystemModels/reactingEuler/multiphaseSystem/phaseModel/PurePhaseModel/PurePhaseModel.C @@ -88,7 +88,7 @@ Foam::PurePhaseModel<BasePhaseModel>::Y(const word& name) const << "Cannot get a species fraction by name from a pure phase" << exit(FatalError); - return NullObjectRef<volScalarField>(); + return volScalarField::null(); } diff --git a/src/thermophysicalModels/solidChemistryModel/basicSolidChemistryModel/basicSolidChemistryModel.C b/src/thermophysicalModels/solidChemistryModel/basicSolidChemistryModel/basicSolidChemistryModel.C index 5076b34ca88..2653f238cef 100644 --- a/src/thermophysicalModels/solidChemistryModel/basicSolidChemistryModel/basicSolidChemistryModel.C +++ b/src/thermophysicalModels/solidChemistryModel/basicSolidChemistryModel/basicSolidChemistryModel.C @@ -59,7 +59,7 @@ const Foam::DimensionedField<Foam::scalar, Foam::volMesh>& Foam::basicSolidChemistryModel::RR(const label i) const { NotImplemented; - return (volScalarField::Internal::null()); + return volScalarField::Internal::null(); } @@ -67,14 +67,11 @@ Foam::DimensionedField<Foam::scalar, Foam::volMesh>& Foam::basicSolidChemistryModel::RR(const label i) { NotImplemented; - - return dynamic_cast<volScalarField::Internal&> - ( + return const_cast<volScalarField::Internal&> ( volScalarField::Internal::null() - ) - ); + ); } @@ -86,14 +83,7 @@ Foam::basicSolidChemistryModel::calculateRR ) const { NotImplemented; - - return dynamic_cast<tmp<volScalarField::Internal>&> - ( - const_cast<volScalarField::Internal&> - ( - volScalarField::Internal::null() - ) - ); + return nullptr; } diff --git a/src/thermophysicalModels/specie/reaction/Reactions/Reaction/Reaction.C b/src/thermophysicalModels/specie/reaction/Reactions/Reaction/Reaction.C index 89b9fa51e23..ad096ee103a 100644 --- a/src/thermophysicalModels/specie/reaction/Reactions/Reaction/Reaction.C +++ b/src/thermophysicalModels/specie/reaction/Reactions/Reaction/Reaction.C @@ -441,7 +441,7 @@ const Foam::List<typename Foam::Reaction<ReactionThermo>::specieCoeffs>& Foam::Reaction<ReactionThermo>::glhs() const { NotImplemented; - return NullObjectRef<List<specieCoeffs>>(); + return List<specieCoeffs>::null(); } @@ -450,7 +450,7 @@ const Foam::List<typename Foam::Reaction<ReactionThermo>::specieCoeffs>& Foam::Reaction<ReactionThermo>::grhs() const { NotImplemented; - return NullObjectRef<List<specieCoeffs>>(); + return List<specieCoeffs>::null(); } -- GitLab