From 15b7e87da76e1e9042147695042383210e28d784 Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Mon, 22 Feb 2016 16:23:21 +0000 Subject: [PATCH] tmp: Updated to store and preserve the const-ness of the reference to a constant object This change requires that the de-reference operator '()' returns a const-reference to the object stored irrespective of the const-ness of object stored and the new member function 'ref()' is provided to return an non-const reference to stored object which throws a fatal error if the stored object is const. In order to smooth the transition to this new safer 'tmp' the now deprecated and unsafe non-const de-reference operator '()' is still provided by default but may be switched-off with the compilation switch 'CONST_TMP'. The main OpenFOAM library has already been upgraded and '-DCONST_TMP' option specified in the 'options' file to switch to the new 'tmp' behavior. The rest of OpenFOAM-dev will be upgraded over the following few weeks. Henry G. Weller CFD Direct --- .../BlendedInterfacialModel.C | 4 +- src/OpenFOAM/Make/options | 2 +- src/OpenFOAM/fields/Fields/Field/Field.C | 2 +- .../fields/Fields/Field/FieldFunctions.C | 52 ++--- .../fields/Fields/Field/FieldFunctionsM.C | 40 ++-- .../fields/Fields/Field/FieldReuseFunctions.H | 2 +- .../fields/Fields/scalarField/scalarField.C | 8 +- .../Fields/symmTensorField/symmTensorField.C | 4 +- .../symmTransformField/symmTransformField.C | 12 +- .../fields/Fields/tensorField/tensorField.C | 6 +- .../Fields/transformField/transformField.C | 10 +- .../transformField/transformFieldTemplates.C | 12 +- .../LduMatrix/LduMatrix/LduMatrixATmul.C | 2 +- .../processorLduInterfaceTemplates.C | 4 +- .../lduMatrix/lduMatrix/lduMatrixATmul.C | 6 +- .../pairGAMGAgglomerate.C | 4 +- .../procFacesGAMGProcAgglomeration.C | 2 +- .../interfaces/GAMGInterface/GAMGInterface.C | 4 +- .../GAMGInterface/GAMGInterfaceTemplates.C | 2 +- .../cyclicGAMGInterface/cyclicGAMGInterface.C | 2 +- src/OpenFOAM/memory/tmp/tmp.H | 32 ++- src/OpenFOAM/memory/tmp/tmpI.H | 193 +++++++++++++----- src/OpenFOAM/meshes/boundBox/boundBox.C | 4 +- src/OpenFOAM/meshes/meshShapes/face/face.C | 4 +- .../polyMesh/polyMeshCheck/polyMeshCheck.C | 10 +- .../polyMesh/polyMeshCheck/polyMeshTools.C | 10 +- .../polyPatches/polyPatch/polyPatch.C | 4 +- .../meshes/primitiveMesh/primitiveMesh.C | 4 +- .../primitiveMeshCheck/primitiveMeshTools.C | 10 +- .../meshes/treeBoundBox/treeBoundBox.C | 5 +- .../functions/Function1/Function1/Function1.C | 4 +- .../functions/Function1/Table/TableBase.C | 4 +- .../DispersionRASModel/DispersionRASModel.C | 6 +- .../BrownianMotion/BrownianMotionForce.C | 4 +- 34 files changed, 291 insertions(+), 183 deletions(-) diff --git a/applications/solvers/multiphase/reactingEulerFoam/phaseSystems/BlendedInterfacialModel/BlendedInterfacialModel.C b/applications/solvers/multiphase/reactingEulerFoam/phaseSystems/BlendedInterfacialModel/BlendedInterfacialModel.C index 64d2e63ae8..3cb567273f 100644 --- a/applications/solvers/multiphase/reactingEulerFoam/phaseSystems/BlendedInterfacialModel/BlendedInterfacialModel.C +++ b/applications/solvers/multiphase/reactingEulerFoam/phaseSystems/BlendedInterfacialModel/BlendedInterfacialModel.C @@ -36,13 +36,13 @@ void Foam::BlendedInterfacialModel::correctFixedFluxBCs GeometricField& field ) const { - forAll(phase1_.phi()->boundaryField(), patchI) + forAll(phase1_.phi()().boundaryField(), patchI) { if ( isA ( - phase1_.phi()->boundaryField()[patchI] + phase1_.phi()().boundaryField()[patchI] ) ) { diff --git a/src/OpenFOAM/Make/options b/src/OpenFOAM/Make/options index b1cc1a2d10..9543b9ae27 100644 --- a/src/OpenFOAM/Make/options +++ b/src/OpenFOAM/Make/options @@ -1,4 +1,4 @@ -EXE_INC = -I$(OBJECTS_DIR) +EXE_INC = -DCONST_TMP -I$(OBJECTS_DIR) LIB_LIBS = \ $(FOAM_LIBBIN)/libOSspecific.o \ diff --git a/src/OpenFOAM/fields/Fields/Field/Field.C b/src/OpenFOAM/fields/Fields/Field/Field.C index e3f17b61a1..9f8f3da081 100644 --- a/src/OpenFOAM/fields/Fields/Field/Field.C +++ b/src/OpenFOAM/fields/Fields/Field/Field.C @@ -564,7 +564,7 @@ Foam::Field::component ) const { tmp> Component(new Field(this->size())); - ::Foam::component(Component(), *this, d); + ::Foam::component(Component.ref(), *this, d); return Component; } diff --git a/src/OpenFOAM/fields/Fields/Field/FieldFunctions.C b/src/OpenFOAM/fields/Fields/Field/FieldFunctions.C index c581ba2362..f927266195 100644 --- a/src/OpenFOAM/fields/Fields/Field/FieldFunctions.C +++ b/src/OpenFOAM/fields/Fields/Field/FieldFunctions.C @@ -87,7 +87,7 @@ pow ( new Field(f.size()) ); - pow(tRes(), f); + pow(tRes.ref(), f); return tRes; } @@ -101,7 +101,7 @@ pow { typedef typename powProduct::type powProductType; tmp> tRes = reuseTmp::New(tf); - pow(tRes(), tf()); + pow(tRes.ref(), tf()); reuseTmp::clear(tf); return tRes; } @@ -127,7 +127,7 @@ sqr(const UList& f) ( new Field(f.size()) ); - sqr(tRes(), f); + sqr(tRes.ref(), f); return tRes; } @@ -138,7 +138,7 @@ sqr(const tmp>& tf) typedef typename outerProduct::type outerProductType; tmp> tRes = reuseTmp::New(tf); - sqr(tRes(), tf()); + sqr(tRes.ref(), tf()); reuseTmp::clear(tf); return tRes; } @@ -154,7 +154,7 @@ template tmp> magSqr(const UList& f) { tmp> tRes(new Field(f.size())); - magSqr(tRes(), f); + magSqr(tRes.ref(), f); return tRes; } @@ -162,7 +162,7 @@ template tmp> magSqr(const tmp>& tf) { tmp> tRes = reuseTmp::New(tf); - magSqr(tRes(), tf()); + magSqr(tRes.ref(), tf()); reuseTmp::clear(tf); return tRes; } @@ -178,7 +178,7 @@ template tmp> mag(const UList& f) { tmp> tRes(new Field(f.size())); - mag(tRes(), f); + mag(tRes.ref(), f); return tRes; } @@ -186,7 +186,7 @@ template tmp> mag(const tmp>& tf) { tmp> tRes = reuseTmp::New(tf); - mag(tRes(), tf()); + mag(tRes.ref(), tf()); reuseTmp::clear(tf); return tRes; } @@ -204,7 +204,7 @@ tmp::cmptType>> cmptMax(const UList& f) { typedef typename Field::cmptType cmptType; tmp> tRes(new Field(f.size())); - cmptMax(tRes(), f); + cmptMax(tRes.ref(), f); return tRes; } @@ -213,7 +213,7 @@ tmp::cmptType>> cmptMax(const tmp>& tf) { typedef typename Field::cmptType cmptType; tmp> tRes = reuseTmp::New(tf); - cmptMax(tRes(), tf()); + cmptMax(tRes.ref(), tf()); reuseTmp::clear(tf); return tRes; } @@ -231,7 +231,7 @@ tmp::cmptType>> cmptMin(const UList& f) { typedef typename Field::cmptType cmptType; tmp> tRes(new Field(f.size())); - cmptMin(tRes(), f); + cmptMin(tRes.ref(), f); return tRes; } @@ -240,7 +240,7 @@ tmp::cmptType>> cmptMin(const tmp>& tf) { typedef typename Field::cmptType cmptType; tmp> tRes = reuseTmp::New(tf); - cmptMin(tRes(), tf()); + cmptMin(tRes.ref(), tf()); reuseTmp::clear(tf); return tRes; } @@ -258,7 +258,7 @@ tmp::cmptType>> cmptAv(const UList& f) { typedef typename Field::cmptType cmptType; tmp> tRes(new Field(f.size())); - cmptAv(tRes(), f); + cmptAv(tRes.ref(), f); return tRes; } @@ -267,7 +267,7 @@ tmp::cmptType>> cmptAv(const tmp>& tf) { typedef typename Field::cmptType cmptType; tmp> tRes = reuseTmp::New(tf); - cmptAv(tRes(), tf()); + cmptAv(tRes.ref(), tf()); reuseTmp::clear(tf); return tRes; } @@ -283,7 +283,7 @@ template tmp> cmptMag(const UList& f) { tmp> tRes(new Field(f.size())); - cmptMag(tRes(), f); + cmptMag(tRes.ref(), f); return tRes; } @@ -291,7 +291,7 @@ template tmp> cmptMag(const tmp>& tf) { tmp> tRes = reuseTmp::New(tf); - cmptMag(tRes(), tf()); + cmptMag(tRes.ref(), tf()); reuseTmp::clear(tf); return tRes; } @@ -653,7 +653,7 @@ operator Op(const UList& f1, const UList& f2) \ { \ typedef typename product::type productType; \ tmp> tRes(new Field(f1.size())); \ - OpFunc(tRes(), f1, f2); \ + OpFunc(tRes.ref(), f1, f2); \ return tRes; \ } \ \ @@ -663,7 +663,7 @@ operator Op(const UList& f1, const tmp>& tf2) \ { \ typedef typename product::type productType; \ tmp> tRes = reuseTmp::New(tf2); \ - OpFunc(tRes(), f1, tf2()); \ + OpFunc(tRes.ref(), f1, tf2()); \ reuseTmp::clear(tf2); \ return tRes; \ } \ @@ -674,7 +674,7 @@ operator Op(const tmp>& tf1, const UList& f2) \ { \ typedef typename product::type productType; \ tmp> tRes = reuseTmp::New(tf1); \ - OpFunc(tRes(), tf1(), f2); \ + OpFunc(tRes.ref(), tf1(), f2); \ reuseTmp::clear(tf1); \ return tRes; \ } \ @@ -686,7 +686,7 @@ operator Op(const tmp>& tf1, const tmp>& tf2) \ typedef typename product::type productType; \ tmp> tRes = \ reuseTmpTmp::New(tf1, tf2); \ - OpFunc(tRes(), tf1(), tf2()); \ + OpFunc(tRes.ref(), tf1(), tf2()); \ reuseTmpTmp::clear(tf1, tf2); \ return tRes; \ } \ @@ -701,7 +701,7 @@ void OpFunc \ { \ typedef typename product::type productType; \ TFOR_ALL_F_OP_F_OP_S \ - (productType, res, =,Type, f1, Op, Form, static_cast(vs))\ + (productType, res, =,Type, f1, Op, Form, static_cast(vs)) \ } \ \ template \ @@ -710,7 +710,7 @@ operator Op(const UList& f1, const VectorSpace& vs) \ { \ typedef typename product::type productType; \ tmp> tRes(new Field(f1.size())); \ - OpFunc(tRes(), f1, static_cast(vs)); \ + OpFunc(tRes.ref(), f1, static_cast(vs)); \ return tRes; \ } \ \ @@ -724,7 +724,7 @@ operator Op \ { \ typedef typename product::type productType; \ tmp> tRes = reuseTmp::New(tf1); \ - OpFunc(tRes(), tf1(), static_cast(vs)); \ + OpFunc(tRes.ref(), tf1(), static_cast(vs)); \ reuseTmp::clear(tf1); \ return tRes; \ } \ @@ -739,7 +739,7 @@ void OpFunc \ { \ typedef typename product::type productType; \ TFOR_ALL_F_OP_S_OP_F \ - (productType, res, =,Form,static_cast(vs), Op, Type, f1) \ + (productType, res, =,Form,static_cast(vs), Op, Type, f1) \ } \ \ template \ @@ -748,7 +748,7 @@ operator Op(const VectorSpace& vs, const UList& f1) \ { \ typedef typename product::type productType; \ tmp> tRes(new Field(f1.size())); \ - OpFunc(tRes(), static_cast(vs), f1); \ + OpFunc(tRes.ref(), static_cast(vs), f1); \ return tRes; \ } \ \ @@ -761,7 +761,7 @@ operator Op \ { \ typedef typename product::type productType; \ tmp> tRes = reuseTmp::New(tf1); \ - OpFunc(tRes(), static_cast(vs), tf1()); \ + OpFunc(tRes.ref(), static_cast(vs), tf1()); \ reuseTmp::clear(tf1); \ return tRes; \ } diff --git a/src/OpenFOAM/fields/Fields/Field/FieldFunctionsM.C b/src/OpenFOAM/fields/Fields/Field/FieldFunctionsM.C index e9b20528f3..c4a7ff6c03 100644 --- a/src/OpenFOAM/fields/Fields/Field/FieldFunctionsM.C +++ b/src/OpenFOAM/fields/Fields/Field/FieldFunctionsM.C @@ -40,7 +40,7 @@ TEMPLATE \ tmp> Func(const UList& f) \ { \ tmp> tRes(new Field(f.size())); \ - Func(tRes(), f); \ + Func(tRes.ref(), f); \ return tRes; \ } \ \ @@ -48,7 +48,7 @@ TEMPLATE \ tmp> Func(const tmp>& tf) \ { \ tmp> tRes = reuseTmp::New(tf); \ - Func(tRes(), tf()); \ + Func(tRes.ref(), tf()); \ reuseTmp::clear(tf); \ return tRes; \ } @@ -68,7 +68,7 @@ TEMPLATE \ tmp> operator Op(const UList& f) \ { \ tmp> tRes(new Field(f.size())); \ - OpFunc(tRes(), f); \ + OpFunc(tRes.ref(), f); \ return tRes; \ } \ \ @@ -76,7 +76,7 @@ TEMPLATE \ tmp> operator Op(const tmp>& tf) \ { \ tmp> tRes = reuseTmp::New(tf); \ - OpFunc(tRes(), tf()); \ + OpFunc(tRes.ref(), tf()); \ reuseTmp::clear(tf); \ return tRes; \ } @@ -108,7 +108,7 @@ tmp> Func \ ) \ { \ tmp> tRes(new Field(f1.size())); \ - Func(tRes(), f1, f2); \ + Func(tRes.ref(), f1, f2); \ return tRes; \ } \ \ @@ -120,7 +120,7 @@ tmp> Func \ ) \ { \ tmp> tRes = reuseTmp::New(tf2); \ - Func(tRes(), f1, tf2()); \ + Func(tRes.ref(), f1, tf2()); \ reuseTmp::clear(tf2); \ return tRes; \ } \ @@ -133,7 +133,7 @@ tmp> Func \ ) \ { \ tmp> tRes = reuseTmp::New(tf1); \ - Func(tRes(), tf1(), f2); \ + Func(tRes.ref(), tf1(), f2); \ reuseTmp::clear(tf1); \ return tRes; \ } \ @@ -147,7 +147,7 @@ tmp> Func \ { \ tmp> tRes = \ reuseTmpTmp::New(tf1, tf2); \ - Func(tRes(), tf1(), tf2()); \ + Func(tRes.ref(), tf1(), tf2()); \ reuseTmpTmp::clear(tf1, tf2); \ return tRes; \ } @@ -179,7 +179,7 @@ tmp> Func \ ) \ { \ tmp> tRes(new Field(f2.size())); \ - Func(tRes(), s1, f2); \ + Func(tRes.ref(), s1, f2); \ return tRes; \ } \ \ @@ -191,7 +191,7 @@ tmp> Func \ ) \ { \ tmp> tRes = reuseTmp::New(tf2); \ - Func(tRes(), s1, tf2()); \ + Func(tRes.ref(), s1, tf2()); \ reuseTmp::clear(tf2); \ return tRes; \ } @@ -221,7 +221,7 @@ tmp> Func \ ) \ { \ tmp> tRes(new Field(f1.size())); \ - Func(tRes(), f1, s2); \ + Func(tRes.ref(), f1, s2); \ return tRes; \ } \ \ @@ -233,7 +233,7 @@ tmp> Func \ ) \ { \ tmp> tRes = reuseTmp::New(tf1); \ - Func(tRes(), tf1(), s2); \ + Func(tRes.ref(), tf1(), s2); \ reuseTmp::clear(tf1); \ return tRes; \ } @@ -267,7 +267,7 @@ tmp> operator Op \ ) \ { \ tmp> tRes(new Field(f1.size())); \ - OpFunc(tRes(), f1, f2); \ + OpFunc(tRes.ref(), f1, f2); \ return tRes; \ } \ \ @@ -279,7 +279,7 @@ tmp> operator Op \ ) \ { \ tmp> tRes = reuseTmp::New(tf2); \ - OpFunc(tRes(), f1, tf2()); \ + OpFunc(tRes.ref(), f1, tf2()); \ reuseTmp::clear(tf2); \ return tRes; \ } \ @@ -292,7 +292,7 @@ tmp> operator Op \ ) \ { \ tmp> tRes = reuseTmp::New(tf1); \ - OpFunc(tRes(), tf1(), f2); \ + OpFunc(tRes.ref(), tf1(), f2); \ reuseTmp::clear(tf1); \ return tRes; \ } \ @@ -306,7 +306,7 @@ tmp> operator Op \ { \ tmp> tRes = \ reuseTmpTmp::New(tf1, tf2); \ - OpFunc(tRes(), tf1(), tf2()); \ + OpFunc(tRes.ref(), tf1(), tf2()); \ reuseTmpTmp::clear(tf1, tf2); \ return tRes; \ } @@ -335,7 +335,7 @@ tmp> operator Op \ ) \ { \ tmp> tRes(new Field(f2.size())); \ - OpFunc(tRes(), s1, f2); \ + OpFunc(tRes.ref(), s1, f2); \ return tRes; \ } \ \ @@ -347,7 +347,7 @@ tmp> operator Op \ ) \ { \ tmp> tRes = reuseTmp::New(tf2); \ - OpFunc(tRes(), s1, tf2()); \ + OpFunc(tRes.ref(), s1, tf2()); \ reuseTmp::clear(tf2); \ return tRes; \ } @@ -374,7 +374,7 @@ tmp> operator Op \ ) \ { \ tmp> tRes(new Field(f1.size())); \ - OpFunc(tRes(), f1, s2); \ + OpFunc(tRes.ref(), f1, s2); \ return tRes; \ } \ \ @@ -386,7 +386,7 @@ tmp> operator Op \ ) \ { \ tmp> tRes = reuseTmp::New(tf1); \ - OpFunc(tRes(), tf1(), s2); \ + OpFunc(tRes.ref(), tf1(), s2); \ reuseTmp::clear(tf1); \ return tRes; \ } diff --git a/src/OpenFOAM/fields/Fields/Field/FieldReuseFunctions.H b/src/OpenFOAM/fields/Fields/Field/FieldReuseFunctions.H index 1d3c39859c..8bceb6885a 100644 --- a/src/OpenFOAM/fields/Fields/Field/FieldReuseFunctions.H +++ b/src/OpenFOAM/fields/Fields/Field/FieldReuseFunctions.H @@ -71,7 +71,7 @@ public: if (initRet) { - rtf() = tf1(); + rtf.ref() = tf1(); } return rtf; diff --git a/src/OpenFOAM/fields/Fields/scalarField/scalarField.C b/src/OpenFOAM/fields/Fields/scalarField/scalarField.C index 654a2b4f3d..875e610cb7 100644 --- a/src/OpenFOAM/fields/Fields/scalarField/scalarField.C +++ b/src/OpenFOAM/fields/Fields/scalarField/scalarField.C @@ -74,14 +74,14 @@ void stabilise(scalarField& res, const UList& sf, const scalar s) tmp stabilise(const UList& sf, const scalar s) { tmp tRes(new scalarField(sf.size())); - stabilise(tRes(), sf, s); + stabilise(tRes.ref(), sf, s); return tRes; } tmp stabilise(const tmp& tsf, const scalar s) { tmp tRes = reuseTmp::New(tsf); - stabilise(tRes(), tsf(), s); + stabilise(tRes.ref(), tsf(), s); reuseTmp::clear(tsf); return tRes; } @@ -173,14 +173,14 @@ void func(scalarField& res, const int n, const UList& sf) \ tmp func(const int n, const UList& sf) \ { \ tmp tRes(new scalarField(sf.size())); \ - func(tRes(), n, sf); \ + func(tRes.ref(), n, sf); \ return tRes; \ } \ \ tmp func(const int n, const tmp& tsf) \ { \ tmp tRes = reuseTmp::New(tsf); \ - func(tRes(), n, tsf()); \ + func(tRes.ref(), n, tsf()); \ reuseTmp::clear(tsf); \ return tRes; \ } diff --git a/src/OpenFOAM/fields/Fields/symmTensorField/symmTensorField.C b/src/OpenFOAM/fields/Fields/symmTensorField/symmTensorField.C index f99fcb5e6a..6304130a71 100644 --- a/src/OpenFOAM/fields/Fields/symmTensorField/symmTensorField.C +++ b/src/OpenFOAM/fields/Fields/symmTensorField/symmTensorField.C @@ -108,14 +108,14 @@ void inv(Field& tf, const UList& tf1) tmp inv(const UList& tf) { tmp result(new symmTensorField(tf.size())); - inv(result(), tf); + inv(result.ref(), tf); return result; } tmp inv(const tmp& tf) { tmp tRes = reuseTmp::New(tf); - inv(tRes(), tf()); + inv(tRes.ref(), tf()); reuseTmp::clear(tf); return tRes; } diff --git a/src/OpenFOAM/fields/Fields/symmTransformField/symmTransformField.C b/src/OpenFOAM/fields/Fields/symmTransformField/symmTransformField.C index ab8f395201..1b6c52bb14 100644 --- a/src/OpenFOAM/fields/Fields/symmTransformField/symmTransformField.C +++ b/src/OpenFOAM/fields/Fields/symmTransformField/symmTransformField.C @@ -63,7 +63,7 @@ tmp> transform ) { tmp> tranf(new Field (tf.size())); - transform(tranf(), trf, tf); + transform(tranf.ref(), trf, tf); return tranf; } @@ -76,7 +76,7 @@ tmp> transform ) { tmp> tranf = reuseTmp::New(ttf); - transform(tranf(), trf, ttf()); + transform(tranf.ref(), trf, ttf()); reuseTmp::clear(ttf); return tranf; } @@ -90,7 +90,7 @@ tmp> transform ) { tmp> tranf(new Field (tf.size())); - transform(tranf(), ttrf(), tf); + transform(tranf.ref(), ttrf(), tf); ttrf.clear(); return tranf; } @@ -104,7 +104,7 @@ tmp> transform ) { tmp> tranf = reuseTmp::New(ttf); - transform(tranf(), ttrf(), ttf()); + transform(tranf.ref(), ttrf(), ttf()); reuseTmp::clear(ttf); ttrf.clear(); return tranf; @@ -131,7 +131,7 @@ tmp> transform ) { tmp> tranf(new Field(tf.size())); - transform(tranf(), t, tf); + transform(tranf.ref(), t, tf); return tranf; } @@ -144,7 +144,7 @@ tmp> transform ) { tmp> tranf = reuseTmp::New(ttf); - transform(tranf(), t, ttf()); + transform(tranf.ref(), t, ttf()); reuseTmp::clear(ttf); return tranf; } diff --git a/src/OpenFOAM/fields/Fields/tensorField/tensorField.C b/src/OpenFOAM/fields/Fields/tensorField/tensorField.C index 91197660f6..a85f6052ea 100644 --- a/src/OpenFOAM/fields/Fields/tensorField/tensorField.C +++ b/src/OpenFOAM/fields/Fields/tensorField/tensorField.C @@ -106,14 +106,14 @@ void inv(Field& tf, const UList& tf1) tmp inv(const UList& tf) { tmp result(new tensorField(tf.size())); - inv(result(), tf); + inv(result.ref(), tf); return result; } tmp inv(const tmp& tf) { tmp tRes = reuseTmp::New(tf); - inv(tRes(), tf()); + inv(tRes.ref(), tf()); reuseTmp::clear(tf); return tRes; } @@ -132,7 +132,7 @@ tmp> transformFieldMask ) { tmp tRes(new tensorField(stf.size())); - tensorField& res = tRes(); + tensorField& res = tRes.ref(); TFOR_ALL_F_OP_F(tensor, res, =, symmTensor, stf) return tRes; } diff --git a/src/OpenFOAM/fields/Fields/transformField/transformField.C b/src/OpenFOAM/fields/Fields/transformField/transformField.C index 362ef156ca..d548c90260 100644 --- a/src/OpenFOAM/fields/Fields/transformField/transformField.C +++ b/src/OpenFOAM/fields/Fields/transformField/transformField.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -48,7 +48,7 @@ Foam::tmp Foam::transform ) { tmp tranf(new vectorField(tf.size())); - transform(tranf(), q, tf); + transform(tranf.ref(), q, tf); return tranf; } @@ -60,7 +60,7 @@ Foam::tmp Foam::transform ) { tmp tranf = reuseTmp::New(ttf); - transform(tranf(), q, ttf()); + transform(tranf.ref(), q, ttf()); reuseTmp::clear(ttf); return tranf; } @@ -106,7 +106,7 @@ Foam::tmp Foam::transform ) { tmp tranf(new vectorField(tf.size())); - transform(tranf(), tr, tf); + transform(tranf.ref(), tr, tf); return tranf; } @@ -118,7 +118,7 @@ Foam::tmp Foam::transform ) { tmp tranf = reuseTmp::New(ttf); - transform(tranf(), tr, ttf()); + transform(tranf.ref(), tr, ttf()); reuseTmp::clear(ttf); return tranf; } diff --git a/src/OpenFOAM/fields/Fields/transformField/transformFieldTemplates.C b/src/OpenFOAM/fields/Fields/transformField/transformFieldTemplates.C index 792df9ce10..985054bede 100644 --- a/src/OpenFOAM/fields/Fields/transformField/transformFieldTemplates.C +++ b/src/OpenFOAM/fields/Fields/transformField/transformFieldTemplates.C @@ -63,7 +63,7 @@ tmp> transform ) { tmp> tranf(new Field (tf.size())); - transform(tranf(), trf, tf); + transform(tranf.ref(), trf, tf); return tranf; } @@ -76,7 +76,7 @@ tmp> transform ) { tmp> tranf = reuseTmp::New(ttf); - transform(tranf(), trf, ttf()); + transform(tranf.ref(), trf, ttf()); reuseTmp::clear(ttf); return tranf; } @@ -90,7 +90,7 @@ tmp> transform ) { tmp> tranf(new Field (tf.size())); - transform(tranf(), ttrf(), tf); + transform(tranf.ref(), ttrf(), tf); ttrf.clear(); return tranf; } @@ -104,7 +104,7 @@ tmp> transform ) { tmp> tranf = reuseTmp::New(ttf); - transform(tranf(), ttrf(), ttf()); + transform(tranf.ref(), ttrf(), ttf()); reuseTmp::clear(ttf); ttrf.clear(); return tranf; @@ -131,7 +131,7 @@ tmp> transform ) { tmp> tranf(new Field(tf.size())); - transform(tranf(), t, tf); + transform(tranf.ref(), t, tf); return tranf; } @@ -144,7 +144,7 @@ tmp> transform ) { tmp> tranf = reuseTmp::New(ttf); - transform(tranf(), t, ttf()); + transform(tranf.ref(), t, ttf()); reuseTmp::clear(ttf); return tranf; } diff --git a/src/OpenFOAM/matrices/LduMatrix/LduMatrix/LduMatrixATmul.C b/src/OpenFOAM/matrices/LduMatrix/LduMatrix/LduMatrixATmul.C index 73a0af2c66..4c06f84e21 100644 --- a/src/OpenFOAM/matrices/LduMatrix/LduMatrix/LduMatrixATmul.C +++ b/src/OpenFOAM/matrices/LduMatrix/LduMatrix/LduMatrixATmul.C @@ -286,7 +286,7 @@ Foam::tmp> Foam::LduMatrix::residual ) const { tmp> trA(new Field(psi.size())); - residual(trA(), psi); + residual(trA.ref(), psi); return trA; } diff --git a/src/OpenFOAM/matrices/lduMatrix/lduAddressing/lduInterface/processorLduInterfaceTemplates.C b/src/OpenFOAM/matrices/lduMatrix/lduAddressing/lduInterface/processorLduInterfaceTemplates.C index bcbc3385f8..8ba519430a 100644 --- a/src/OpenFOAM/matrices/lduMatrix/lduAddressing/lduInterface/processorLduInterfaceTemplates.C +++ b/src/OpenFOAM/matrices/lduMatrix/lduAddressing/lduInterface/processorLduInterfaceTemplates.C @@ -126,7 +126,7 @@ Foam::tmp> Foam::processorLduInterface::receive ) const { tmp> tf(new Field(size)); - receive(commsType, tf()); + receive(commsType, tf.ref()); return tf; } @@ -268,7 +268,7 @@ Foam::tmp> Foam::processorLduInterface::compressedReceive ) const { tmp> tf(new Field(size)); - compressedReceive(commsType, tf()); + compressedReceive(commsType, tf.ref()); return tf; } diff --git a/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrixATmul.C b/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrixATmul.C index aa6230ca19..537746ed20 100644 --- a/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrixATmul.C +++ b/src/OpenFOAM/matrices/lduMatrix/lduMatrix/lduMatrixATmul.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -290,7 +290,7 @@ Foam::tmp Foam::lduMatrix::residual ) const { tmp trA(new scalarField(psi.size())); - residual(trA(), psi, source, interfaceBouCoeffs, interfaces, cmpt); + residual(trA.ref(), psi, source, interfaceBouCoeffs, interfaces, cmpt); return trA; } @@ -304,7 +304,7 @@ Foam::tmp Foam::lduMatrix::H1() const if (lowerPtr_ || upperPtr_) { - scalarField& H1_ = tH1(); + scalarField& H1_ = tH1.ref(); scalar* __restrict__ H1Ptr = H1_.begin(); diff --git a/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGAgglomerations/pairGAMGAgglomeration/pairGAMGAgglomerate.C b/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGAgglomerations/pairGAMGAgglomeration/pairGAMGAgglomerate.C index 508c0c3f94..bf4c695bda 100644 --- a/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGAgglomerations/pairGAMGAgglomeration/pairGAMGAgglomerate.C +++ b/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGAgglomerations/pairGAMGAgglomeration/pairGAMGAgglomerate.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -181,7 +181,7 @@ Foam::tmp Foam::pairGAMGAgglomeration::agglomerate // go through the faces and create clusters tmp tcoarseCellMap(new labelField(nFineCells, -1)); - labelField& coarseCellMap = tcoarseCellMap(); + labelField& coarseCellMap = tcoarseCellMap.ref(); nCoarseCells = 0; label celli; diff --git a/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGProcAgglomerations/procFacesGAMGProcAgglomeration/procFacesGAMGProcAgglomeration.C b/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGProcAgglomerations/procFacesGAMGProcAgglomeration/procFacesGAMGProcAgglomeration.C index c34040c27d..31eb6fdc88 100644 --- a/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGProcAgglomerations/procFacesGAMGProcAgglomeration/procFacesGAMGProcAgglomeration.C +++ b/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGProcAgglomerations/procFacesGAMGProcAgglomeration/procFacesGAMGProcAgglomeration.C @@ -166,7 +166,7 @@ Foam::procFacesGAMGProcAgglomeration::processorAgglomeration ); tmp tfineToCoarse(new labelField(0)); - labelField& fineToCoarse = tfineToCoarse(); + labelField& fineToCoarse = tfineToCoarse.ref(); if (singleCellMeshPtr.valid()) { diff --git a/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/interfaces/GAMGInterface/GAMGInterface.C b/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/interfaces/GAMGInterface/GAMGInterface.C index cd30d03c75..2151fa3005 100644 --- a/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/interfaces/GAMGInterface/GAMGInterface.C +++ b/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/interfaces/GAMGInterface/GAMGInterface.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -81,7 +81,7 @@ Foam::tmp Foam::GAMGInterface::agglomerateCoeffs ) const { tmp tcoarseCoeffs(new scalarField(size(), 0.0)); - scalarField& coarseCoeffs = tcoarseCoeffs(); + scalarField& coarseCoeffs = tcoarseCoeffs.ref(); if (fineCoeffs.size() != faceRestrictAddressing_.size()) { diff --git a/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/interfaces/GAMGInterface/GAMGInterfaceTemplates.C b/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/interfaces/GAMGInterface/GAMGInterfaceTemplates.C index 2f55a362ee..bcf21c1dd3 100644 --- a/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/interfaces/GAMGInterface/GAMGInterfaceTemplates.C +++ b/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/interfaces/GAMGInterface/GAMGInterfaceTemplates.C @@ -34,7 +34,7 @@ Foam::tmp> Foam::GAMGInterface::interfaceInternalField ) const { tmp> tresult(new Field(size())); - interfaceInternalField(iF, tresult()); + interfaceInternalField(iF, tresult.ref()); return tresult; } diff --git a/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/interfaces/cyclicGAMGInterface/cyclicGAMGInterface.C b/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/interfaces/cyclicGAMGInterface/cyclicGAMGInterface.C index 94e3e03dc9..7f884c205b 100644 --- a/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/interfaces/cyclicGAMGInterface/cyclicGAMGInterface.C +++ b/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/interfaces/cyclicGAMGInterface/cyclicGAMGInterface.C @@ -182,7 +182,7 @@ Foam::tmp Foam::cyclicGAMGInterface::internalFieldTransfer const labelUList& nbrFaceCells = nbr.faceCells(); tmp tpnf(new labelField(size())); - labelField& pnf = tpnf(); + labelField& pnf = tpnf.ref(); forAll(pnf, facei) { diff --git a/src/OpenFOAM/memory/tmp/tmp.H b/src/OpenFOAM/memory/tmp/tmp.H index 24700bfad4..a842500af4 100644 --- a/src/OpenFOAM/memory/tmp/tmp.H +++ b/src/OpenFOAM/memory/tmp/tmp.H @@ -52,15 +52,20 @@ class tmp { // Private data - //- Flag for whether object is a temporary or a constant object - bool isTmp_; + //- Object types + enum type + { + TMP, + REF, + CONST_REF + }; - //- Pointer to temporary object + //- Type of object + type type_; + + //- Pointer to object mutable T* ptr_; - //- Const reference to constant object - const T& ref_; - public: @@ -69,9 +74,15 @@ public: //- Store object pointer inline explicit tmp(T* = 0); + //- Store object rvalue reference + inline tmp(T&&); + //- Store object const reference inline tmp(const T&); + //- Construct copy and increment reference count + inline tmp(tmp&&); + //- Construct copy and increment reference count inline tmp(const tmp&); @@ -100,6 +111,10 @@ public: // Edit + //- Return non-const reference or generate a fatal error + // if the object is const. + inline T& ref(); + //- Return tmp pointer for reuse. // Returns a clone if the object is not a temporary inline T* ptr() const; @@ -111,8 +126,11 @@ public: // Member operators - //- Dereference operator + #ifndef CONST_TMP + //- Deprecated non-const dereference operator. + // Use ref() where non-const access is required inline T& operator()(); + #endif //- Const dereference operator inline const T& operator()() const; diff --git a/src/OpenFOAM/memory/tmp/tmpI.H b/src/OpenFOAM/memory/tmp/tmpI.H index 490ac76e3f..bb6fdbe902 100644 --- a/src/OpenFOAM/memory/tmp/tmpI.H +++ b/src/OpenFOAM/memory/tmp/tmpI.H @@ -31,29 +31,34 @@ License template inline Foam::tmp::tmp(T* tPtr) : - isTmp_(true), - ptr_(tPtr), - ref_(*tPtr) + type_(TMP), + ptr_(tPtr) +{} + + +template +inline Foam::tmp::tmp(T&& tRef) +: + type_(REF), + ptr_(&tRef) {} template inline Foam::tmp::tmp(const T& tRef) : - isTmp_(false), - ptr_(0), - ref_(tRef) + type_(CONST_REF), + ptr_(const_cast(&tRef)) {} template -inline Foam::tmp::tmp(const tmp& t) +inline Foam::tmp::tmp(tmp&& t) : - isTmp_(t.isTmp_), - ptr_(t.ptr_), - ref_(t.ref_) + type_(t.type_), + ptr_(t.ptr_) { - if (isTmp_) + if (isTmp()) { if (ptr_) { @@ -62,7 +67,7 @@ inline Foam::tmp::tmp(const tmp& t) else { FatalErrorInFunction - << "attempted copy of a deallocated temporary" + << "Attempted copy of a deallocated temporary" << " of type " << typeid(T).name() << abort(FatalError); } @@ -70,14 +75,40 @@ inline Foam::tmp::tmp(const tmp& t) } +template +inline Foam::tmp::tmp(const tmp& t) +: + type_(t.type_), + ptr_(t.ptr_) +{ + if (isTmp()) + { + if (ptr_) + { + ptr_->operator++(); + } + else + { + FatalErrorInFunction + << "Attempted copy of a deallocated temporary" + << " of type " << typeid(T).name() + << abort(FatalError); + } + } + else if (type_ == REF) + { + type_ = CONST_REF; + } +} + + template inline Foam::tmp::tmp(const tmp& t, bool allowTransfer) : - isTmp_(t.isTmp_), - ptr_(t.ptr_), - ref_(t.ref_) + type_(t.type_), + ptr_(t.ptr_) { - if (isTmp_) + if (isTmp()) { if (allowTransfer) { @@ -92,7 +123,7 @@ inline Foam::tmp::tmp(const tmp& t, bool allowTransfer) else { FatalErrorInFunction - << "attempted copy of a deallocated temporary" + << "Attempted copy of a deallocated temporary" << " of type " << typeid(T).name() << abort(FatalError); } @@ -104,7 +135,7 @@ inline Foam::tmp::tmp(const tmp& t, bool allowTransfer) template inline Foam::tmp::~tmp() { - if (isTmp_ && ptr_) + if (isTmp() && ptr_) { if (ptr_->okToDelete()) { @@ -124,33 +155,60 @@ inline Foam::tmp::~tmp() template inline bool Foam::tmp::isTmp() const { - return isTmp_; + return type_ == TMP; } template inline bool Foam::tmp::empty() const { - return (isTmp_ && !ptr_); + return (isTmp() && !ptr_); } template inline bool Foam::tmp::valid() const { - return (!isTmp_ || (isTmp_ && ptr_)); + return (!isTmp() || (isTmp() && ptr_)); +} + + +template +inline T& Foam::tmp::ref() +{ + if (type_ == TMP) + { + if (!ptr_) + { + FatalErrorInFunction + << "Temporary of type " << typeid(T).name() << " deallocated" + << abort(FatalError); + } + + return *ptr_; + } + else if (type_ == REF) + { + return *ptr_; + } + else + { + FatalErrorInFunction << "Const object cast to non-const" + << abort(FatalError); + return *ptr_; + } } template inline T* Foam::tmp::ptr() const { - if (isTmp_) + if (isTmp()) { if (!ptr_) { FatalErrorInFunction - << "temporary of type " << typeid(T).name() << " deallocated" + << "Temporary of type " << typeid(T).name() << " deallocated" << abort(FatalError); } @@ -163,7 +221,7 @@ inline T* Foam::tmp::ptr() const } else { - return new T(ref_); + return new T(*ptr_); } } @@ -171,7 +229,7 @@ inline T* Foam::tmp::ptr() const template inline void Foam::tmp::clear() const { - if (isTmp_ && ptr_) // Skip this bit: && ptr_->okToDelete()) + if (isTmp() && ptr_) // Skip this bit: && ptr_->okToDelete()) { delete ptr_; ptr_ = 0; @@ -181,15 +239,16 @@ inline void Foam::tmp::clear() const // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // +#ifndef CONST_TMP template inline T& Foam::tmp::operator()() { - if (isTmp_) + if (type_ == TMP) { if (!ptr_) { FatalErrorInFunction - << "temporary of type " << typeid(T).name() << " deallocated" + << "Temporary of type " << typeid(T).name() << " deallocated" << abort(FatalError); } @@ -197,28 +256,23 @@ inline T& Foam::tmp::operator()() } else { - // Note: const is cast away! - // Perhaps there should be two refs, one for const and one for non const - // and if the ref is actually const then you cannot return it here. - // - // Another possibility would be to store a const ref and a flag to say - // whether the tmp was constructed with a const or a non-const argument. - // - // eg, enum refType { POINTER = 0, REF = 1, CONSTREF = 2 }; - return const_cast(ref_); + // Const-ness is automatically cast-away which is why this operator is + // deprecated. Use ref() where non-const access is required. + return *ptr_; } } +#endif template inline const T& Foam::tmp::operator()() const { - if (isTmp_) + if (type_ == TMP) { if (!ptr_) { FatalErrorInFunction - << "temporary of type " << typeid(T).name() << " deallocated" + << "Temporary of type " << typeid(T).name() << " deallocated" << abort(FatalError); } @@ -226,7 +280,8 @@ inline const T& Foam::tmp::operator()() const } else { - return ref_; + // Return const reference + return *ptr_; } } @@ -241,20 +296,26 @@ inline Foam::tmp::operator const T&() const template inline T* Foam::tmp::operator->() { - if (isTmp_) + if (isTmp()) { if (!ptr_) { FatalErrorInFunction - << "temporary of type " << typeid(T).name() << " deallocated" + << "Temporary of type " << typeid(T).name() << " deallocated" << abort(FatalError); } return ptr_; } + else if (type_ == REF) + { + return ptr_; + } else { - return &const_cast(ref_); + FatalErrorInFunction << "Const object cast to non-const" + << abort(FatalError); + return ptr_; } } @@ -262,14 +323,28 @@ inline T* Foam::tmp::operator->() template inline const T* Foam::tmp::operator->() const { - return const_cast&>(*this).operator->(); + if (isTmp()) + { + if (!ptr_) + { + FatalErrorInFunction + << "Temporary of type " << typeid(T).name() << " deallocated" + << abort(FatalError); + } + + return ptr_; + } + else + { + return ptr_; + } } template inline void Foam::tmp::operator=(T* tPtr) { - if (isTmp_ && ptr_) + if (isTmp() && ptr_) { if (ptr_->okToDelete()) { @@ -282,12 +357,12 @@ inline void Foam::tmp::operator=(T* tPtr) } } - isTmp_ = true; + type_ = TMP; if (!tPtr) { FatalErrorInFunction - << "attempted copy of a deallocated temporary" + << "Attempted copy of a deallocated temporary" << " of type " << typeid(T).name() << abort(FatalError); } @@ -300,7 +375,7 @@ inline void Foam::tmp::operator=(T* tPtr) template inline void Foam::tmp::operator=(const tmp& t) { - if (isTmp_ && ptr_) + if (isTmp() && ptr_) { if (ptr_->okToDelete()) { @@ -313,14 +388,14 @@ inline void Foam::tmp::operator=(const tmp& t) } } - if (t.isTmp_) + if (t.isTmp()) { - isTmp_ = true; + type_ = TMP; if (!t.ptr_) { FatalErrorInFunction - << "attempted assignment to a deallocated temporary" + << "Attempted assignment to a deallocated temporary" << " of type " << typeid(T).name() << abort(FatalError); } @@ -332,11 +407,27 @@ inline void Foam::tmp::operator=(const tmp& t) else { FatalErrorInFunction - << "attempted assignment to a const reference to constant object" + << "Attempted assignment to a const reference to constant object" << " of type " << typeid(T).name() << abort(FatalError); } } +//- Return the const reference of the non-const reference argument +template +inline const T& Const(T& t) +{ + return t; +} + + +//- Return the const reference of the non-const rvalue reference argument +template +inline const T& Const(T&& t) +{ + return t; +} + + // ************************************************************************* // diff --git a/src/OpenFOAM/meshes/boundBox/boundBox.C b/src/OpenFOAM/meshes/boundBox/boundBox.C index 168d43c342..e75389a6f0 100644 --- a/src/OpenFOAM/meshes/boundBox/boundBox.C +++ b/src/OpenFOAM/meshes/boundBox/boundBox.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -149,7 +149,7 @@ Foam::boundBox::boundBox Foam::tmp Foam::boundBox::points() const { tmp tPts = tmp(new pointField(8)); - pointField& pt = tPts(); + pointField& pt = tPts.ref(); pt[0] = min_; // min-x, min-y, min-z pt[1] = point(max_.x(), min_.y(), min_.z()); // max-x, min-y, min-z diff --git a/src/OpenFOAM/meshes/meshShapes/face/face.C b/src/OpenFOAM/meshes/meshShapes/face/face.C index b4dd451c90..4e9abeb033 100644 --- a/src/OpenFOAM/meshes/meshShapes/face/face.C +++ b/src/OpenFOAM/meshes/meshShapes/face/face.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -41,7 +41,7 @@ Foam::tmp Foam::face::calcEdges(const pointField& points) const { tmp tedges(new vectorField(size())); - vectorField& edges = tedges(); + vectorField& edges = tedges.ref(); forAll(*this, i) { diff --git a/src/OpenFOAM/meshes/polyMesh/polyMeshCheck/polyMeshCheck.C b/src/OpenFOAM/meshes/polyMesh/polyMeshCheck/polyMeshCheck.C index e75191e340..302afd7b49 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyMeshCheck/polyMeshCheck.C +++ b/src/OpenFOAM/meshes/polyMesh/polyMeshCheck/polyMeshCheck.C @@ -55,7 +55,7 @@ bool Foam::polyMesh::checkFaceOrthogonality fAreas, cellCtrs ); - const scalarField& ortho = tortho(); + const scalarField& ortho = tortho.ref(); // Severe nonorthogonality threshold const scalar severeNonorthogonalityThreshold = @@ -197,7 +197,7 @@ bool Foam::polyMesh::checkFaceSkewness fAreas, cellCtrs ); - const scalarField& skew = tskew(); + const scalarField& skew = tskew.ref(); scalar maxSkew = max(skew); label nWarnSkew = 0; @@ -426,7 +426,7 @@ bool Foam::polyMesh::checkCellDeterminant faceAreas, syncTools::getInternalOrCoupledFaces(*this) ); - scalarField& cellDeterminant = tcellDeterminant(); + scalarField& cellDeterminant = tcellDeterminant.ref(); label nErrorCells = 0; @@ -508,7 +508,7 @@ bool Foam::polyMesh::checkFaceWeight fAreas, cellCtrs ); - scalarField& faceWght = tfaceWght(); + scalarField& faceWght = tfaceWght.ref(); label nErrorFaces = 0; @@ -595,7 +595,7 @@ bool Foam::polyMesh::checkVolRatio } tmp tvolRatio = polyMeshTools::volRatio(*this, cellVols); - scalarField& volRatio = tvolRatio(); + scalarField& volRatio = tvolRatio.ref(); label nErrorFaces = 0; diff --git a/src/OpenFOAM/meshes/polyMesh/polyMeshCheck/polyMeshTools.C b/src/OpenFOAM/meshes/polyMesh/polyMeshCheck/polyMeshTools.C index 4945eb0b09..3cde2db292 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyMeshCheck/polyMeshTools.C +++ b/src/OpenFOAM/meshes/polyMesh/polyMeshCheck/polyMeshTools.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2012-2013 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2012-2016 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -43,7 +43,7 @@ Foam::tmp Foam::polyMeshTools::faceOrthogonality const polyBoundaryMesh& pbm = mesh.boundaryMesh(); tmp tortho(new scalarField(mesh.nFaces(), 1.0)); - scalarField& ortho = tortho(); + scalarField& ortho = tortho.ref(); // Internal faces forAll(nei, faceI) @@ -100,7 +100,7 @@ Foam::tmp Foam::polyMeshTools::faceSkewness const polyBoundaryMesh& pbm = mesh.boundaryMesh(); tmp tskew(new scalarField(mesh.nFaces())); - scalarField& skew = tskew(); + scalarField& skew = tskew.ref(); forAll(nei, faceI) { @@ -184,7 +184,7 @@ Foam::tmp Foam::polyMeshTools::faceWeights const polyBoundaryMesh& pbm = mesh.boundaryMesh(); tmp tweight(new scalarField(mesh.nFaces(), 1.0)); - scalarField& weight = tweight(); + scalarField& weight = tweight.ref(); // Internal faces forAll(nei, faceI) @@ -240,7 +240,7 @@ Foam::tmp Foam::polyMeshTools::volRatio const polyBoundaryMesh& pbm = mesh.boundaryMesh(); tmp tratio(new scalarField(mesh.nFaces(), 1.0)); - scalarField& ratio = tratio(); + scalarField& ratio = tratio.ref(); // Internal faces forAll(nei, faceI) diff --git a/src/OpenFOAM/meshes/polyMesh/polyPatches/polyPatch/polyPatch.C b/src/OpenFOAM/meshes/polyMesh/polyPatches/polyPatch/polyPatch.C index d7508c3d94..fcfb9d6c64 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyPatches/polyPatch/polyPatch.C +++ b/src/OpenFOAM/meshes/polyMesh/polyPatches/polyPatch/polyPatch.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -297,7 +297,7 @@ const Foam::vectorField::subField Foam::polyPatch::faceAreas() const Foam::tmp Foam::polyPatch::faceCellCentres() const { tmp tcc(new vectorField(size())); - vectorField& cc = tcc(); + vectorField& cc = tcc.ref(); // get reference to global cell centres const vectorField& gcc = boundaryMesh_.mesh().cellCentres(); diff --git a/src/OpenFOAM/meshes/primitiveMesh/primitiveMesh.C b/src/OpenFOAM/meshes/primitiveMesh/primitiveMesh.C index 0e5beeeb03..a55421d5e8 100644 --- a/src/OpenFOAM/meshes/primitiveMesh/primitiveMesh.C +++ b/src/OpenFOAM/meshes/primitiveMesh/primitiveMesh.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -320,7 +320,7 @@ Foam::tmp Foam::primitiveMesh::movePoints const faceList& f = faces(); tmp tsweptVols(new scalarField(f.size())); - scalarField& sweptVols = tsweptVols(); + scalarField& sweptVols = tsweptVols.ref(); forAll(f, faceI) { diff --git a/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCheck/primitiveMeshTools.C b/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCheck/primitiveMeshTools.C index 2845ca262b..6f8b8b83f4 100644 --- a/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCheck/primitiveMeshTools.C +++ b/src/OpenFOAM/meshes/primitiveMesh/primitiveMeshCheck/primitiveMeshTools.C @@ -130,7 +130,7 @@ Foam::tmp Foam::primitiveMeshTools::faceOrthogonality const labelList& nei = mesh.faceNeighbour(); tmp tortho(new scalarField(mesh.nInternalFaces())); - scalarField& ortho = tortho(); + scalarField& ortho = tortho.ref(); // Internal faces forAll(nei, faceI) @@ -160,7 +160,7 @@ Foam::tmp Foam::primitiveMeshTools::faceSkewness const labelList& nei = mesh.faceNeighbour(); tmp tskew(new scalarField(mesh.nFaces())); - scalarField& skew = tskew(); + scalarField& skew = tskew.ref(); forAll(nei, faceI) { @@ -345,7 +345,7 @@ Foam::tmp Foam::primitiveMeshTools::faceConcavity faceNormals /= mag(faceNormals) + ROOTVSMALL; tmp tfaceAngles(new scalarField(mesh.nFaces())); - scalarField& faceAngles = tfaceAngles(); + scalarField& faceAngles = tfaceAngles.ref(); forAll(fcs, faceI) @@ -416,7 +416,7 @@ Foam::tmp Foam::primitiveMeshTools::faceFlatness scalarField magAreas(mag(faceAreas)); tmp tfaceFlatness(new scalarField(mesh.nFaces(), 1.0)); - scalarField& faceFlatness = tfaceFlatness(); + scalarField& faceFlatness = tfaceFlatness.ref(); forAll(fcs, faceI) @@ -474,7 +474,7 @@ Foam::tmp Foam::primitiveMeshTools::cellDeterminant } tmp tcellDeterminant(new scalarField(mesh.nCells())); - scalarField& cellDeterminant = tcellDeterminant(); + scalarField& cellDeterminant = tcellDeterminant.ref(); const cellList& c = mesh.cells(); diff --git a/src/OpenFOAM/meshes/treeBoundBox/treeBoundBox.C b/src/OpenFOAM/meshes/treeBoundBox/treeBoundBox.C index 9dfb3e9094..766aa50727 100644 --- a/src/OpenFOAM/meshes/treeBoundBox/treeBoundBox.C +++ b/src/OpenFOAM/meshes/treeBoundBox/treeBoundBox.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -163,8 +163,7 @@ Foam::treeBoundBox::treeBoundBox Foam::tmp Foam::treeBoundBox::points() const { tmp tPts = tmp(new pointField(8)); - - pointField& points = tPts(); + pointField& points = tPts.ref(); forAll(points, octant) { diff --git a/src/OpenFOAM/primitives/functions/Function1/Function1/Function1.C b/src/OpenFOAM/primitives/functions/Function1/Function1/Function1.C index b65c908f67..5b7cdafc0f 100644 --- a/src/OpenFOAM/primitives/functions/Function1/Function1/Function1.C +++ b/src/OpenFOAM/primitives/functions/Function1/Function1/Function1.C @@ -92,7 +92,7 @@ Foam::tmp> Foam::Function1::value ) const { tmp> tfld(new Field(x.size())); - Field& fld = tfld(); + Field& fld = tfld.ref(); forAll(x, i) { @@ -110,7 +110,7 @@ Foam::tmp> Foam::Function1::integrate ) const { tmp> tfld(new Field(x1.size())); - Field& fld = tfld(); + Field& fld = tfld.ref(); forAll(x1, i) { diff --git a/src/OpenFOAM/primitives/functions/Function1/Table/TableBase.C b/src/OpenFOAM/primitives/functions/Function1/Table/TableBase.C index 0d38c9f049..8217c6ca18 100644 --- a/src/OpenFOAM/primitives/functions/Function1/Table/TableBase.C +++ b/src/OpenFOAM/primitives/functions/Function1/Table/TableBase.C @@ -380,7 +380,7 @@ template Foam::tmp Foam::Function1Types::TableBase::x() const { tmp tfld(new scalarField(table_.size(), 0.0)); - scalarField& fld = tfld(); + scalarField& fld = tfld.ref(); forAll(table_, i) { @@ -395,7 +395,7 @@ template Foam::tmp> Foam::Function1Types::TableBase::y() const { tmp> tfld(new Field(table_.size(), pTraits::zero)); - Field& fld = tfld(); + Field& fld = tfld.ref(); forAll(table_, i) { diff --git a/src/lagrangian/turbulence/submodels/Kinematic/DispersionModel/DispersionRASModel/DispersionRASModel.C b/src/lagrangian/turbulence/submodels/Kinematic/DispersionModel/DispersionRASModel/DispersionRASModel.C index b86451b145..cccba17a2c 100644 --- a/src/lagrangian/turbulence/submodels/Kinematic/DispersionModel/DispersionRASModel/DispersionRASModel.C +++ b/src/lagrangian/turbulence/submodels/Kinematic/DispersionModel/DispersionRASModel/DispersionRASModel.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -147,7 +147,7 @@ void Foam::DispersionRASModel::cacheFields(const bool store) } else { - kPtr_ = tk.operator->(); + kPtr_ = &tk(); ownK_ = false; } @@ -159,7 +159,7 @@ void Foam::DispersionRASModel::cacheFields(const bool store) } else { - epsilonPtr_ = tepsilon.operator->(); + epsilonPtr_ = &tepsilon(); ownEpsilon_ = false; } } diff --git a/src/lagrangian/turbulence/submodels/Thermodynamic/ParticleForces/BrownianMotion/BrownianMotionForce.C b/src/lagrangian/turbulence/submodels/Thermodynamic/ParticleForces/BrownianMotion/BrownianMotionForce.C index 563ab8c736..4c2059e0a9 100644 --- a/src/lagrangian/turbulence/submodels/Thermodynamic/ParticleForces/BrownianMotion/BrownianMotionForce.C +++ b/src/lagrangian/turbulence/submodels/Thermodynamic/ParticleForces/BrownianMotion/BrownianMotionForce.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -139,7 +139,7 @@ void Foam::BrownianMotionForce::cacheFields(const bool store) } else { - kPtr_ = tk.operator->(); + kPtr_ = &tk(); ownK_ = false; } }