From 2f431ffd3d151d6dfb1486dd79206f7681385622 Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Thu, 13 Jul 2017 23:24:14 +0100 Subject: [PATCH] made the clone function pure virtual Avoids potential problems with derived classes which do not define a clone function. --- .../GeometricField/GeometricField.C | 11 +++++++ .../GeometricField/GeometricField.H | 3 ++ .../SlicedGeometricField.C | 29 ++++++++++++++++++- .../SlicedGeometricField.H | 6 +++- .../uniformFixedValuePointPatchField.C | 2 +- src/OpenFOAM/memory/tmp/tmpI.H | 4 +-- .../functions/Function1/Function1/Function1.H | 5 +--- .../uniformJump/uniformJumpFvPatchField.C | 4 +-- .../uniformJumpAMIFvPatchField.C | 4 +-- .../fvMatrices/fvMatrix/fvMatrix.C | 14 ++++++++- .../fvMatrices/fvMatrix/fvMatrix.H | 5 +++- 11 files changed, 72 insertions(+), 15 deletions(-) diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.C b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.C index cd0210b1ea..db2e29a7a5 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.C +++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.C @@ -721,6 +721,17 @@ Foam::GeometricField::GeometricField #endif +template class PatchField, class GeoMesh> +Foam::tmp> +Foam::GeometricField::clone() const +{ + return tmp> + ( + new GeometricField(*this) + ); +} + + // * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * * // template class PatchField, class GeoMesh> diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.H b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.H index c56bcd9a59..051df928c9 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.H +++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.H @@ -441,6 +441,9 @@ public: ); #endif + //- Clone + tmp> clone() const; + //- Destructor virtual ~GeometricField(); diff --git a/src/OpenFOAM/fields/GeometricFields/SlicedGeometricField/SlicedGeometricField.C b/src/OpenFOAM/fields/GeometricFields/SlicedGeometricField/SlicedGeometricField.C index f42c11ecdb..bfd24de2a0 100644 --- a/src/OpenFOAM/fields/GeometricFields/SlicedGeometricField/SlicedGeometricField.C +++ b/src/OpenFOAM/fields/GeometricFields/SlicedGeometricField/SlicedGeometricField.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -338,6 +338,33 @@ SlicedGeometricField } +template +< + class Type, + template class PatchField, + template class SlicedPatchField, + class GeoMesh +> +Foam::tmp +< + Foam::SlicedGeometricField +> +Foam::SlicedGeometricField:: +clone() const +{ + return tmp + < + SlicedGeometricField + > + ( + new SlicedGeometricField + ( + *this + ) + ); +} + + // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // template diff --git a/src/OpenFOAM/fields/GeometricFields/SlicedGeometricField/SlicedGeometricField.H b/src/OpenFOAM/fields/GeometricFields/SlicedGeometricField/SlicedGeometricField.H index 13279bf737..66b15b65b8 100644 --- a/src/OpenFOAM/fields/GeometricFields/SlicedGeometricField/SlicedGeometricField.H +++ b/src/OpenFOAM/fields/GeometricFields/SlicedGeometricField/SlicedGeometricField.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -159,6 +159,10 @@ public: >& ); + //- Clone + tmp> + clone() const; + //- Destructor ~SlicedGeometricField(); diff --git a/src/OpenFOAM/fields/pointPatchFields/derived/uniformFixedValue/uniformFixedValuePointPatchField.C b/src/OpenFOAM/fields/pointPatchFields/derived/uniformFixedValue/uniformFixedValuePointPatchField.C index 520f28e6ab..cd0b7ec418 100644 --- a/src/OpenFOAM/fields/pointPatchFields/derived/uniformFixedValue/uniformFixedValuePointPatchField.C +++ b/src/OpenFOAM/fields/pointPatchFields/derived/uniformFixedValue/uniformFixedValuePointPatchField.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License diff --git a/src/OpenFOAM/memory/tmp/tmpI.H b/src/OpenFOAM/memory/tmp/tmpI.H index c3fa708372..e773d708c3 100644 --- a/src/OpenFOAM/memory/tmp/tmpI.H +++ b/src/OpenFOAM/memory/tmp/tmpI.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -221,7 +221,7 @@ inline T* Foam::tmp::ptr() const } else { - return new T(*ptr_); + return ptr_->clone().ptr(); } } diff --git a/src/OpenFOAM/primitives/functions/Function1/Function1/Function1.H b/src/OpenFOAM/primitives/functions/Function1/Function1/Function1.H index a0492f66ee..3f364bdf6b 100644 --- a/src/OpenFOAM/primitives/functions/Function1/Function1/Function1.H +++ b/src/OpenFOAM/primitives/functions/Function1/Function1/Function1.H @@ -105,10 +105,7 @@ public: Function1(const Function1& de); //- Construct and return a clone - virtual tmp> clone() const - { - return tmp>(new Function1(*this)); - } + virtual tmp> clone() const = 0; //- Selector diff --git a/src/finiteVolume/fields/fvPatchFields/derived/uniformJump/uniformJumpFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/uniformJump/uniformJumpFvPatchField.C index 265bbf3ec4..31350e6230 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/uniformJump/uniformJumpFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/uniformJump/uniformJumpFvPatchField.C @@ -35,7 +35,7 @@ Foam::uniformJumpFvPatchField::uniformJumpFvPatchField ) : fixedJumpFvPatchField(p, iF), - jumpTable_(new Function1("jumpTable")) + jumpTable_() {} @@ -62,7 +62,7 @@ Foam::uniformJumpFvPatchField::uniformJumpFvPatchField ) : fixedJumpFvPatchField(p, iF), - jumpTable_(new Function1("jumpTable")) + jumpTable_() { if (this->cyclicPatch().owner()) { diff --git a/src/finiteVolume/fields/fvPatchFields/derived/uniformJumpAMI/uniformJumpAMIFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/uniformJumpAMI/uniformJumpAMIFvPatchField.C index 12857efacb..033afb572a 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/uniformJumpAMI/uniformJumpAMIFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/uniformJumpAMI/uniformJumpAMIFvPatchField.C @@ -35,7 +35,7 @@ Foam::uniformJumpAMIFvPatchField::uniformJumpAMIFvPatchField ) : fixedJumpAMIFvPatchField(p, iF), - jumpTable_(0) + jumpTable_() {} @@ -62,7 +62,7 @@ Foam::uniformJumpAMIFvPatchField::uniformJumpAMIFvPatchField ) : fixedJumpAMIFvPatchField(p, iF), - jumpTable_(new Function1("jumpTable")) + jumpTable_() { if (this->cyclicAMIPatch().owner()) { diff --git a/src/finiteVolume/fvMatrices/fvMatrix/fvMatrix.C b/src/finiteVolume/fvMatrices/fvMatrix/fvMatrix.C index 81ff46caa2..e720726d25 100644 --- a/src/finiteVolume/fvMatrices/fvMatrix/fvMatrix.C +++ b/src/finiteVolume/fvMatrices/fvMatrix/fvMatrix.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License @@ -451,6 +451,18 @@ Foam::fvMatrix::fvMatrix } +template +Foam::tmp> Foam::fvMatrix::clone() const +{ + return tmp> + ( + new fvMatrix(*this) + ); +} + + +// * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * * // + template Foam::fvMatrix::~fvMatrix() { diff --git a/src/finiteVolume/fvMatrices/fvMatrix/fvMatrix.H b/src/finiteVolume/fvMatrices/fvMatrix/fvMatrix.H index cb843f24fd..9bb0d91d2e 100644 --- a/src/finiteVolume/fvMatrices/fvMatrix/fvMatrix.H +++ b/src/finiteVolume/fvMatrices/fvMatrix/fvMatrix.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License @@ -270,6 +270,9 @@ public: //- Construct from Istream given field to solve for fvMatrix(const GeometricField&, Istream&); + //- Clone + tmp> clone() const; + //- Destructor virtual ~fvMatrix();