diff --git a/src/OpenFOAM/db/functionObjects/regionFunctionObject/regionFunctionObject.C b/src/OpenFOAM/db/functionObjects/regionFunctionObject/regionFunctionObject.C index c010855bc..5da0d2bb1 100644 --- a/src/OpenFOAM/db/functionObjects/regionFunctionObject/regionFunctionObject.C +++ b/src/OpenFOAM/db/functionObjects/regionFunctionObject/regionFunctionObject.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2016-2017 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -70,11 +70,11 @@ bool Foam::functionObjects::regionFunctionObject::clearObject { if (foundObject(fieldName)) { - const regIOobject& resultObject = lookupObject(fieldName); + regIOobject& resultObject = lookupObjectRef(fieldName); if (resultObject.ownedByRegistry()) { - return const_cast(resultObject).checkOut(); + return resultObject.checkOut(); } else { diff --git a/src/OpenFOAM/db/functionObjects/regionFunctionObject/regionFunctionObject.H b/src/OpenFOAM/db/functionObjects/regionFunctionObject/regionFunctionObject.H index a7872e478..95cb2f221 100644 --- a/src/OpenFOAM/db/functionObjects/regionFunctionObject/regionFunctionObject.H +++ b/src/OpenFOAM/db/functionObjects/regionFunctionObject/regionFunctionObject.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2016-2017 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -78,10 +78,14 @@ protected: template bool foundObject(const word& fieldName) const; - //- Lookup field from the objectRegistry + //- Lookup object from the objectRegistry template const ObjectType& lookupObject(const word& fieldName) const; + //- Lookup non-const object reference from the objectRegistry + template + ObjectType& lookupObjectRef(const word& fieldName); + //- Store the given field in the objectRegistry under the given name template bool store diff --git a/src/OpenFOAM/db/functionObjects/regionFunctionObject/regionFunctionObjectTemplates.C b/src/OpenFOAM/db/functionObjects/regionFunctionObject/regionFunctionObjectTemplates.C index 1e2387121..0aa2593fa 100644 --- a/src/OpenFOAM/db/functionObjects/regionFunctionObject/regionFunctionObjectTemplates.C +++ b/src/OpenFOAM/db/functionObjects/regionFunctionObject/regionFunctionObjectTemplates.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2016-2017 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -48,6 +48,16 @@ const ObjectType& Foam::functionObjects::regionFunctionObject::lookupObject } +template +ObjectType& Foam::functionObjects::regionFunctionObject::lookupObjectRef +( + const word& fieldName +) +{ + return obr_.lookupObjectRef(fieldName); +} + + template bool Foam::functionObjects::regionFunctionObject::store ( @@ -74,17 +84,14 @@ bool Foam::functionObjects::regionFunctionObject::store && obr_.foundObject(fieldName) ) { - const ObjectType& field = - ( - obr_.lookupObject(fieldName) - ); + ObjectType& field = obr_.lookupObjectRef(fieldName); // If there is a result field already registered assign to the new // result field otherwise transfer ownership of the new result field to // the object registry if (&field != &tfield()) { - const_cast(field) = tfield; + field = tfield; } else { diff --git a/src/OpenFOAM/db/objectRegistry/objectRegistry.H b/src/OpenFOAM/db/objectRegistry/objectRegistry.H index bae145b04..97627c687 100644 --- a/src/OpenFOAM/db/objectRegistry/objectRegistry.H +++ b/src/OpenFOAM/db/objectRegistry/objectRegistry.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 @@ -180,6 +180,10 @@ public: template const Type& lookupObject(const word& name) const; + //- Lookup and return the object reference of the given Type + template + Type& lookupObjectRef(const word& name) const; + //- Return new event number. label getEvent() const; diff --git a/src/OpenFOAM/db/objectRegistry/objectRegistryTemplates.C b/src/OpenFOAM/db/objectRegistry/objectRegistryTemplates.C index 0c2600948..c2ac8f0bc 100644 --- a/src/OpenFOAM/db/objectRegistry/objectRegistryTemplates.C +++ b/src/OpenFOAM/db/objectRegistry/objectRegistryTemplates.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-2017 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -204,4 +204,11 @@ const Type& Foam::objectRegistry::lookupObject(const word& name) const } +template +Type& Foam::objectRegistry::lookupObjectRef(const word& name) const +{ + return const_cast(lookupObject(name)); +} + + // ************************************************************************* // diff --git a/src/finiteVolume/fields/fvPatchFields/derived/freestreamPressure/freestreamPressureFvPatchScalarField.C b/src/finiteVolume/fields/fvPatchFields/derived/freestreamPressure/freestreamPressureFvPatchScalarField.C index 1c8787e5e..414f59c40 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/freestreamPressure/freestreamPressureFvPatchScalarField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/freestreamPressure/freestreamPressureFvPatchScalarField.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 @@ -119,14 +119,11 @@ void Foam::freestreamPressureFvPatchScalarField::updateCoeffs() patch().lookupPatchField(UName_) ); - const surfaceScalarField& phi = - db().lookupObject(phiName_); + surfaceScalarField& phi = + db().lookupObjectRef(phiName_); fvsPatchField& phip = - const_cast&> - ( - patch().patchField(phi) - ); + patch().patchField(phi); if (phi.dimensions() == dimVelocity*dimArea) { diff --git a/src/finiteVolume/fields/fvPatchFields/derived/mappedVelocityFluxFixedValue/mappedVelocityFluxFixedValueFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/mappedVelocityFluxFixedValue/mappedVelocityFluxFixedValueFvPatchField.C index 89c0c11bf..933d9da9c 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/mappedVelocityFluxFixedValue/mappedVelocityFluxFixedValueFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/mappedVelocityFluxFixedValue/mappedVelocityFluxFixedValueFvPatchField.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 @@ -156,8 +156,8 @@ void Foam::mappedVelocityFluxFixedValueFvPatchField::updateCoeffs() const volVectorField& UField = nbrMesh.lookupObject(fieldName); - const surfaceScalarField& phiField = - nbrMesh.lookupObject(phiName_); + surfaceScalarField& phiField = + nbrMesh.lookupObjectRef(phiName_); vectorField newUValues; scalarField newPhiValues; @@ -215,10 +215,7 @@ void Foam::mappedVelocityFluxFixedValueFvPatchField::updateCoeffs() } operator==(newUValues); - const_cast - ( - phiField - ).boundaryFieldRef()[patch().index()] == newPhiValues; + phiField.boundaryFieldRef()[patch().index()] == newPhiValues; // Restore tag UPstream::msgType() = oldTag; diff --git a/src/finiteVolume/fields/fvPatchFields/derived/waveSurfacePressure/waveSurfacePressureFvPatchScalarField.C b/src/finiteVolume/fields/fvPatchFields/derived/waveSurfacePressure/waveSurfacePressureFvPatchScalarField.C index 4b25603ce..221d8daf0 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/waveSurfacePressure/waveSurfacePressureFvPatchScalarField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/waveSurfacePressure/waveSurfacePressureFvPatchScalarField.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 @@ -145,26 +145,22 @@ void Foam::waveSurfacePressureFvPatchScalarField::updateCoeffs() const scalar dt = db().time().deltaTValue(); - // retrieve non-const access to zeta field from the database - volVectorField& zeta = - const_cast - ( - db().lookupObject(zetaName_) - ); + // Retrieve non-const access to zeta field from the database + volVectorField& zeta = db().lookupObjectRef(zetaName_); vectorField& zetap = zeta.boundaryFieldRef()[patchi]; - // lookup d/dt scheme from database for zeta + // Lookup d/dt scheme from database for zeta const word ddtSchemeName(zeta.mesh().ddtScheme(zeta.name())); ddtSchemeType ddtScheme(ddtSchemeTypeNames_[ddtSchemeName]); - // retrieve the flux field from the database + // Retrieve the flux field from the database const surfaceScalarField& phi = db().lookupObject(phiName_); - // cache the patch face-normal vectors + // Cache the patch face-normal vectors tmp nf(patch().nf()); - // change in zeta due to flux + // Change in zeta due to flux vectorField dZetap(dt*nf()*phi.boundaryField()[patchi]/patch().magSf()); if (phi.dimensions() == dimDensity*dimVelocity*dimArea) @@ -218,7 +214,7 @@ void Foam::waveSurfacePressureFvPatchScalarField::updateCoeffs() Info<< "min/max zetap = " << gMin(zetap & nf()) << ", " << gMax(zetap & nf()) << endl; - // update the surface pressure + // Update the surface pressure const uniformDimensionedVectorField& g = db().lookupObject("g"); diff --git a/src/finiteVolume/fvMesh/fvPatches/fvPatch/fvPatch.H b/src/finiteVolume/fvMesh/fvPatches/fvPatch/fvPatch.H index 6dc1716e6..1f27a35c9 100644 --- a/src/finiteVolume/fvMesh/fvPatches/fvPatch/fvPatch.H +++ b/src/finiteVolume/fvMesh/fvPatches/fvPatch/fvPatch.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 @@ -250,6 +250,13 @@ public: const GeometricField& ) const; + //- Return the corresponding patchField reference of the named field + template + typename GeometricField::Patch& patchField + ( + GeometricField& + ) const; + //- Lookup and return the patchField of the named field from the // local objectRegistry. // N.B. The dummy pointer arguments are used if this function is diff --git a/src/finiteVolume/fvMesh/fvPatches/fvPatch/fvPatchTemplates.C b/src/finiteVolume/fvMesh/fvPatches/fvPatch/fvPatchTemplates.C index 067ac5f00..2f2c0a965 100644 --- a/src/finiteVolume/fvMesh/fvPatches/fvPatch/fvPatchTemplates.C +++ b/src/finiteVolume/fvMesh/fvPatches/fvPatch/fvPatchTemplates.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 @@ -75,4 +75,14 @@ const typename GeometricField::Patch& Foam::fvPatch::patchField } +template +typename GeometricField::Patch& Foam::fvPatch::patchField +( + GeometricField& gf +) const +{ + return gf.boundaryFieldRef()[index()]; +} + + // ************************************************************************* //