Replacing const_cast lookupObject to lookupObjectRef

This commit is contained in:
Henry Weller
2017-05-11 14:42:59 +01:00
parent e8f9d6a7fe
commit 9fbe68fca6
20 changed files with 70 additions and 144 deletions

View File

@ -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
@ -90,16 +90,13 @@ Foam::diameterModels::IATEsources::wallBoiling::R
);
const phaseCompressibleTurbulenceModel& turbulence =
const_cast<phaseCompressibleTurbulenceModel&>
(
phase().db().lookupObject<phaseCompressibleTurbulenceModel>
phase().db().lookupObjectRef<phaseCompressibleTurbulenceModel>
(
IOobject::groupName
(
turbulenceModel::propertiesName,
otherPhase().name()
)
)
);
const tmp<volScalarField> talphat(turbulence.alphat());

View File

@ -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
@ -91,8 +91,7 @@ void Foam::fvMotionSolverEngineMesh::move()
if (engineDB_.foundObject<surfaceScalarField>("phi"))
{
surfaceScalarField& phi =
const_cast<surfaceScalarField&>
(engineDB_.lookupObject<surfaceScalarField>("phi"));
engineDB_.lookupObjectRef<surfaceScalarField>("phi");
const volScalarField& rho =
engineDB_.lookupObject<volScalarField>("rho");

View File

@ -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-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -86,8 +86,7 @@ void Foam::layeredEngineMesh::move()
if (engineDB_.foundObject<surfaceScalarField>("phi"))
{
surfaceScalarField& phi =
const_cast<surfaceScalarField&>
(engineDB_.lookupObject<surfaceScalarField>("phi"));
engineDB_.lookupObjectRef<surfaceScalarField>("phi");
const volScalarField& rho =
engineDB_.lookupObject<volScalarField>("rho");

View File

@ -172,10 +172,7 @@ CrankNicolsonDdtScheme<Type>::ddt0_
DDt0Field<GeoField>& ddt0 = static_cast<DDt0Field<GeoField>&>
(
const_cast<GeoField&>
(
mesh().objectRegistry::template lookupObject<GeoField>(name)
)
mesh().objectRegistry::template lookupObjectRef<GeoField>(name)
);
return ddt0;

View File

@ -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
@ -109,9 +109,10 @@ Foam::fv::gradScheme<Type>::grad
}
solution::cachePrintMessage("Retrieving", name, vsf);
GradFieldType& gGrad = const_cast<GradFieldType&>
GradFieldType& gGrad =
mesh().objectRegistry::template lookupObjectRef<GradFieldType>
(
mesh().objectRegistry::template lookupObject<GradFieldType>(name)
name
);
if (gGrad.upToDate(vsf))
@ -129,12 +130,10 @@ Foam::fv::gradScheme<Type>::grad
solution::cachePrintMessage("Storing", name, vsf);
regIOobject::store(tgGrad.ptr());
GradFieldType& gGrad = const_cast<GradFieldType&>
(
mesh().objectRegistry::template lookupObject<GradFieldType>
GradFieldType& gGrad =
mesh().objectRegistry::template lookupObjectRef<GradFieldType>
(
name
)
);
return gGrad;
@ -144,12 +143,10 @@ Foam::fv::gradScheme<Type>::grad
{
if (mesh().objectRegistry::template foundObject<GradFieldType>(name))
{
GradFieldType& gGrad = const_cast<GradFieldType&>
(
mesh().objectRegistry::template lookupObject<GradFieldType>
GradFieldType& gGrad =
mesh().objectRegistry::template lookupObjectRef<GradFieldType>
(
name
)
);
if (gGrad.ownedByRegistry())

View File

@ -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
@ -169,12 +169,9 @@ Foam::LimitedScheme<Type, Limiter, LimitFunc>::limiter
}
surfaceScalarField& limiterField =
const_cast<surfaceScalarField&>
(
mesh.lookupObject<surfaceScalarField>
mesh.lookupObjectRef<surfaceScalarField>
(
limiterFieldName
)
);
calcLimiter(phi, limiterField);

View File

@ -372,9 +372,10 @@ Foam::volPointInterpolation::interpolate
// Delete any old occurences to avoid double registration
if (db.objectRegistry::template foundObject<PointFieldType>(name))
{
PointFieldType& pf = const_cast<PointFieldType&>
PointFieldType& pf =
db.objectRegistry::template lookupObjectRef<PointFieldType>
(
db.objectRegistry::template lookupObject<PointFieldType>(name)
name
);
if (pf.ownedByRegistry())
@ -417,9 +418,10 @@ Foam::volPointInterpolation::interpolate
}
else
{
PointFieldType& pf = const_cast<PointFieldType&>
PointFieldType& pf =
db.objectRegistry::template lookupObjectRef<PointFieldType>
(
db.objectRegistry::template lookupObject<PointFieldType>(name)
name
);
if (pf.upToDate(vf)) //TBD: , vf.mesh().points()))

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2013-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -85,13 +85,7 @@ bool Foam::functionObjects::CourantNo::calc()
if (foundObject<volScalarField>(resultName_))
{
volScalarField& Co
(
const_cast<volScalarField&>
(
lookupObject<volScalarField>(resultName_)
)
);
volScalarField& Co = lookupObjectRef<volScalarField>(resultName_);
Co.ref() = Coi();
Co.correctBoundaryConditions();

View File

@ -196,10 +196,8 @@ void Foam::functionObjects::fieldAverage::calculateMeanFieldType
{
const Type& baseField = obr_.lookupObject<Type>(fieldName);
Type& meanField = const_cast<Type&>
(
obr_.lookupObject<Type>(faItems_[fieldi].meanFieldName())
);
Type& meanField =
obr_.lookupObjectRef<Type>(faItems_[fieldi].meanFieldName());
scalar dt = obr_.time().deltaTValue();
scalar Dt = totalTime_[fieldi];
@ -258,10 +256,8 @@ void Foam::functionObjects::fieldAverage::calculatePrime2MeanFieldType
const Type1& meanField =
obr_.lookupObject<Type1>(faItems_[fieldi].meanFieldName());
Type2& prime2MeanField = const_cast<Type2&>
(
obr_.lookupObject<Type2>(faItems_[fieldi].prime2MeanFieldName())
);
Type2& prime2MeanField =
obr_.lookupObjectRef<Type2>(faItems_[fieldi].prime2MeanFieldName());
scalar dt = obr_.time().deltaTValue();
scalar Dt = totalTime_[fieldi];
@ -328,10 +324,8 @@ void Foam::functionObjects::fieldAverage::addMeanSqrToPrime2MeanType
const Type1& meanField =
obr_.lookupObject<Type1>(faItems_[fieldi].meanFieldName());
Type2& prime2MeanField = const_cast<Type2&>
(
obr_.lookupObject<Type2>(faItems_[fieldi].prime2MeanFieldName())
);
Type2& prime2MeanField =
obr_.lookupObjectRef<Type2>(faItems_[fieldi].prime2MeanFieldName());
prime2MeanField += sqr(meanField);
}

View File

@ -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
@ -91,10 +91,7 @@ bool Foam::functionObjects::processorField::read(const dictionary& dict)
bool Foam::functionObjects::processorField::execute()
{
const volScalarField& procField =
mesh_.lookupObject<volScalarField>("processorID");
const_cast<volScalarField&>(procField) ==
mesh_.lookupObjectRef<volScalarField>("processorID") ==
dimensionedScalar("proci", dimless, Pstream::myProcNo());
return true;
@ -103,10 +100,7 @@ bool Foam::functionObjects::processorField::execute()
bool Foam::functionObjects::processorField::write()
{
const volScalarField& procField =
mesh_.lookupObject<volScalarField>("processorID");
procField.write();
mesh_.lookupObject<volScalarField>("processorID").write();
return true;
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2013-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -193,10 +193,7 @@ bool Foam::functionObjects::wallShearStress::execute()
typedef incompressible::turbulenceModel icoModel;
volVectorField& wallShearStress =
const_cast<volVectorField&>
(
mesh_.lookupObject<volVectorField>(type())
);
mesh_.lookupObjectRef<volVectorField>(type());
tmp<volSymmTensorField> Reff;
if (mesh_.foundObject<cmpModel>(turbulenceModel::propertiesName))

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2013-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -169,10 +169,7 @@ bool Foam::functionObjects::yPlus::read(const dictionary& dict)
bool Foam::functionObjects::yPlus::execute()
{
volScalarField& yPlus =
const_cast<volScalarField&>
(
mesh_.lookupObject<volScalarField>(type())
);
mesh_.lookupObjectRef<volScalarField>(type());
if (mesh_.foundObject<turbulenceModel>(turbulenceModel::propertiesName))
{

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2013-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -91,8 +91,8 @@ bool Foam::functionObjects::removeRegisteredObject::execute()
{
if (obr_.foundObject<regIOobject>(objectNames_[i]))
{
const regIOobject& obj =
obr_.lookupObject<regIOobject>(objectNames_[i]);
regIOobject& obj =
obr_.lookupObjectRef<regIOobject>(objectNames_[i]);
if (obj.ownedByRegistry())
{
@ -100,7 +100,7 @@ bool Foam::functionObjects::removeRegisteredObject::execute()
<< " removing object " << obj.name() << nl
<< endl;
const_cast<regIOobject&>(obj).release();
obj.release();
delete &obj;
}
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2012-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -210,15 +210,8 @@ void uniformInterpolatedDisplacementPointPatchVectorField::updateCoeffs()
const objectRegistry&
>(*fieldsCacheIter());
pointVectorField& d = const_cast<pointVectorField&>
(
timeCache.lookupObject<pointVectorField>
(
fieldName_
)
);
d.correctBoundaryConditions();
timeCache.lookupObjectRef<pointVectorField>(fieldName_)
.correctBoundaryConditions();
}
}
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2015-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -44,10 +44,7 @@ void Foam::fv::tabulatedAccelerationSource::addSup
if (mesh_.foundObject<uniformDimensionedVectorField>("g"))
{
uniformDimensionedVectorField& g =
const_cast<uniformDimensionedVectorField&>
(
mesh_.lookupObject<uniformDimensionedVectorField>("g")
);
mesh_.lookupObjectRef<uniformDimensionedVectorField>("g");
const uniformDimensionedScalarField& hRef =
mesh_.lookupObject<uniformDimensionedScalarField>("hRef");
@ -61,15 +58,10 @@ void Foam::fv::tabulatedAccelerationSource::addSup
: dimensionedScalar("ghRef", g.dimensions()*dimLength, 0)
);
const_cast<volScalarField&>
(
mesh_.lookupObject<volScalarField>("gh")
) = (g & mesh_.C()) - ghRef;
mesh_.lookupObjectRef<volScalarField>("gh") = (g & mesh_.C()) - ghRef;
const_cast<surfaceScalarField&>
(
mesh_.lookupObject<surfaceScalarField>("ghf")
) = (g & mesh_.Cf()) - ghRef;
mesh_.lookupObjectRef<surfaceScalarField>("ghf") =
(g & mesh_.Cf()) - ghRef;
}
// ... otherwise include explicitly in the momentum equation
else

View File

@ -152,10 +152,7 @@ Foam::volScalarField& Foam::basicThermo::lookupOrConstruct
fPtr->store(fPtr);
}
return const_cast<volScalarField&>
(
mesh.objectRegistry::lookupObject<volScalarField>(name)
);
return mesh.objectRegistry::lookupObjectRef<volScalarField>(name);
}

View File

@ -133,12 +133,7 @@ Foam::radiation::greyMeanAbsorptionEmission::greyMeanAbsorptionEmission
}
else if (mesh.foundObject<volScalarField>(iter.key()))
{
volScalarField& Y =
const_cast<volScalarField&>
(
mesh.lookupObject<volScalarField>(iter.key())
);
Yj_.set(j, &Y);
Yj_.set(j, &mesh.lookupObjectRef<volScalarField>(iter.key()));
specieIndex_[iter()] = 0;
j++;
Info<< "specie: " << iter.key() << " is being solved" << endl;
@ -155,13 +150,7 @@ Foam::radiation::greyMeanAbsorptionEmission::greyMeanAbsorptionEmission
}
else if (mesh.foundObject<volScalarField>(iter.key()))
{
volScalarField& Y =
const_cast<volScalarField&>
(
mesh.lookupObject<volScalarField>(iter.key())
);
Yj_.set(j, &Y);
Yj_.set(j, &mesh.lookupObjectRef<volScalarField>(iter.key()));
specieIndex_[iter()] = 0;
j++;
}

View File

@ -121,10 +121,7 @@ Foam::radiation::wideBandAbsorptionEmission::wideBandAbsorptionEmission
}
else if (mesh.foundObject<volScalarField>(iter.key()))
{
volScalarField& Y = const_cast<volScalarField&>
(mesh.lookupObject<volScalarField>(iter.key()));
Yj_.set(j, &Y);
Yj_.set(j, &mesh.lookupObjectRef<volScalarField>(iter.key()));
specieIndex_[iter()] = 0.0;
j++;

View File

@ -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
@ -142,10 +142,7 @@ bool Foam::rawTopoChangerFvMesh::update()
Info<< "rawTopoChangerFvMesh :"
<< " recreating phi for unmapped boundary values." << endl;
const volVectorField& U = lookupObject<volVectorField>("U");
surfaceScalarField& phi = const_cast<surfaceScalarField&>
(
lookupObject<surfaceScalarField>("phi")
);
surfaceScalarField& phi = lookupObjectRef<surfaceScalarField>("phi");
setUnmappedValues
(
phi,

View File

@ -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,10 +75,7 @@ void Foam::rawTopoChangerFvMesh::zeroUnmappedValues
{
//Pout<< "Checking field " << fldNames[i] << endl;
FieldType& fld = const_cast<FieldType&>
(
lookupObject<FieldType>(fldNames[i])
);
FieldType& fld = lookupObjectRef<FieldType>(fldNames[i]);
setUnmappedValues
(