ENH: simplify objectRegistry access names (issue #322)

New name:  findObject(), cfindObject()
  Old name:  lookupObjectPtr()

      Return a const pointer or nullptr on failure.

  New name:  findObject()
  Old name:  --

      Return a non-const pointer or nullptr on failure.

  New name:  getObjectPtr()
  Old name:  lookupObjectRefPtr()

      Return a non-const pointer or nullptr on failure.
      Can be called on a const object and it will perform a
      const_cast.

- use these updated names and functionality in more places

NB: The older methods names are deprecated, but continue to be defined.
This commit is contained in:
Mark Olesen
2018-10-17 16:44:10 +02:00
parent e0255cfff2
commit 8fabc32539
94 changed files with 918 additions and 952 deletions

View File

@ -260,13 +260,7 @@ public:
virtual volScalarField& he()
{
NotImplemented;
return
(
const_cast<volScalarField&>
(
volScalarField::null()
)
);
return const_cast<volScalarField&>(volScalarField::null());
}
//- Return access to the inernal energy field [J/Kg]
@ -274,10 +268,7 @@ public:
virtual const volScalarField& he() const
{
NotImplemented;
return
(
volScalarField::null()
);
return volScalarField::null();
}
//- Enthalpy/Internal energy

View File

@ -131,20 +131,16 @@ Foam::ThermalPhaseChangePhaseSystem<BasePhaseSystem>::heatTransfer() const
dimensionedScalar(dimensionSet(1,-1,-3,0,0), Zero)
);
if
(
otherPhase.mesh().foundObject<volScalarField>
(
"alphat." + otherPhase.name()
)
)
{
const volScalarField& alphat =
otherPhase.mesh().lookupObject<volScalarField>
const volScalarField* alphatPtr =
otherPhase.mesh().findObject<volScalarField>
(
"alphat." + otherPhase.name()
);
if (alphatPtr)
{
const volScalarField& alphat = *alphatPtr;
const fvPatchList& patches = this->mesh().boundary();
forAll(patches, patchi)
{
@ -427,20 +423,16 @@ void Foam::ThermalPhaseChangePhaseSystem<BasePhaseSystem>::correctThermo()
dimensionedScalar(dimDensity/dimTime, Zero)
);
if
(
phase2.mesh().foundObject<volScalarField>
(
"alphat." + phase2.name()
)
)
{
const volScalarField& alphat =
phase2.mesh().lookupObject<volScalarField>
const volScalarField* alphatPtr =
phase2.mesh().findObject<volScalarField>
(
"alphat." + phase2.name()
);
if (alphatPtr)
{
const volScalarField& alphat = *alphatPtr;
const fvPatchList& patches = this->mesh().boundary();
forAll(patches, patchi)
{

View File

@ -52,10 +52,8 @@ Foam::functionObjects::regionFunctionObject::whichSubRegistry
{
return obr.lookupObject<objectRegistry>(subName);
}
else
{
return obr;
}
}
@ -71,22 +69,19 @@ bool Foam::functionObjects::regionFunctionObject::writeObject
const word& fieldName
)
{
const regIOobject* objPtr =
this->lookupObjectPtr<regIOobject>(fieldName);
const regIOobject* obj = this->findObject<regIOobject>(fieldName);
if (objPtr)
if (obj)
{
Log << " functionObjects::" << type() << " " << name()
<< " writing field: " << objPtr->name() << endl;
<< " writing field: " << obj->name() << endl;
objPtr->write();
obj->write();
return true;
}
else
{
return false;
}
}
@ -95,12 +90,14 @@ bool Foam::functionObjects::regionFunctionObject::clearObject
const word& fieldName
)
{
regIOobject* objPtr = lookupObjectRefPtr<regIOobject>(fieldName);
if (objPtr)
// Same as getObjectPtr, since the object is already non-const
regIOobject* obj = this->findObject<regIOobject>(fieldName);
if (obj)
{
if (objPtr->ownedByRegistry())
if (obj->ownedByRegistry())
{
return objPtr->checkOut();
return obj->checkOut();
}
else
{

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -94,6 +94,35 @@ protected:
template<class ObjectType>
bool foundObject(const word& fieldName) const;
//- Return const pointer to the object (eg, a field) in the
//- (sub) objectRegistry.
//
// \return nullptr if the object was not found or had incorrect type.
template<class ObjectType>
const ObjectType* cfindObject(const word& fieldName) const;
//- Return const pointer to the object (eg, a field) in the
//- (sub) objectRegistry.
//
// \return nullptr if the object was not found or had incorrect type.
template<class ObjectType>
const ObjectType* findObject(const word& fieldName) const;
//- Return non-const pointer to the object of the given Type,
//- (sub) objectRegistry.
//
// \return nullptr if the object was not found or had incorrect type.
template<class ObjectType>
ObjectType* findObject(const word& fieldName);
//- Return non-const pointer to the object of the given Type,
//- using a const-cast to have it behave like a mutable.
// Exercise caution when using.
//
// \return nullptr if the object was not found or had incorrect type.
template<class ObjectType>
ObjectType* getObjectPtr(const word& fieldName) const;
//- Lookup and return object (eg, a field) from the (sub) objectRegistry
template<class ObjectType>
const ObjectType& lookupObject(const word& fieldName) const;
@ -102,18 +131,6 @@ protected:
template<class ObjectType>
ObjectType& lookupObjectRef(const word& fieldName) const;
//- Lookup and return pointer to the object,
// otherwise nullptr if the object was not found,
// or had the incorrect type.
template<class ObjectType>
const ObjectType* lookupObjectPtr(const word& fieldName) const;
//- Lookup and return non-const pointer to the object,
// otherwise nullptr if the object was not found,
// or had the incorrect type.
template<class ObjectType>
ObjectType* lookupObjectRefPtr(const word& fieldName) const;
//- Store the field in the (sub) objectRegistry under the given name
// Note: sets the fieldName to tfield().name() if not already set
template<class ObjectType>
@ -177,6 +194,25 @@ public:
//- Read optional controls
virtual bool read(const dictionary& dict);
// Housekeeping
//- Same as findObject
// \deprecated use findObject (OCT-2018)
template<class ObjectType>
const ObjectType* lookupObjectPtr(const word& fieldName) const
{
return this->cfindObject<ObjectType>(fieldName);
}
//- Same as getObjectPtr
// \deprecated use getObjectPtr (OCT-2018)
template<class ObjectType>
ObjectType* lookupObjectRefPtr(const word& fieldName) const
{
return this->getObjectPtr<ObjectType>(fieldName);
}
};

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -38,6 +38,47 @@ bool Foam::functionObjects::regionFunctionObject::foundObject
}
template<class ObjectType>
const ObjectType* Foam::functionObjects::regionFunctionObject::cfindObject
(
const word& fieldName
) const
{
return obr().cfindObject<ObjectType>(fieldName);
}
template<class ObjectType>
const ObjectType* Foam::functionObjects::regionFunctionObject::findObject
(
const word& fieldName
) const
{
return obr().findObject<ObjectType>(fieldName);
}
template<class ObjectType>
ObjectType* Foam::functionObjects::regionFunctionObject::findObject
(
const word& fieldName
)
{
// Need getObjectPtr to bypass const access on the objectRegistry
return obr().getObjectPtr<ObjectType>(fieldName);
}
template<class ObjectType>
ObjectType* Foam::functionObjects::regionFunctionObject::getObjectPtr
(
const word& fieldName
) const
{
return obr().getObjectPtr<ObjectType>(fieldName);
}
template<class ObjectType>
const ObjectType& Foam::functionObjects::regionFunctionObject::lookupObject
(
@ -58,26 +99,6 @@ ObjectType& Foam::functionObjects::regionFunctionObject::lookupObjectRef
}
template<class ObjectType>
const ObjectType* Foam::functionObjects::regionFunctionObject::lookupObjectPtr
(
const word& fieldName
) const
{
return obr().lookupObjectPtr<ObjectType>(fieldName);
}
template<class ObjectType>
ObjectType* Foam::functionObjects::regionFunctionObject::lookupObjectRefPtr
(
const word& fieldName
) const
{
return obr().lookupObjectRefPtr<ObjectType>(fieldName);
}
template<class ObjectType>
bool Foam::functionObjects::regionFunctionObject::store
(

View File

@ -231,8 +231,9 @@ public:
// Lookup
//- Lookup and return a const sub-objectRegistry.
// Optionally create it if it does not exist.
// If recursive, search parent registries.
//
// \param forceCreate create it if it does not exist.
// \param recursive search parent registries.
const objectRegistry& subRegistry
(
const word& name,
@ -250,7 +251,8 @@ public:
HashTable<Type*> lookupClass(const bool strict = false);
//- Is the named Type found?
// If recursive, search parent registries.
//
// \param recursive search parent registries
template<class Type>
bool foundObject
(
@ -258,8 +260,60 @@ public:
const bool recursive = false
) const;
//- Lookup and return the object of the given Type.
// If recursive, search parent registries.
//- Find const pointer to the object of the given Type.
//
// \param recursive search parent registries
//
// \return nullptr if the object was not found or had incorrect type.
template<class Type>
const Type* cfindObject
(
const word& name,
const bool recursive = false
) const;
//- Return const pointer to the object of the given Type.
//
// \param recursive search parent registries
//
// \return nullptr if the object was not found or had incorrect type.
template<class Type>
const Type* findObject
(
const word& name,
const bool recursive = false
) const;
//- Return non-const pointer to the object of the given Type.
//
// \param recursive search parent registries
//
// \return nullptr if the object was not found or had incorrect type.
template<class Type>
Type* findObject
(
const word& name,
const bool recursive = false
);
//- Return non-const pointer to the object of the given Type,
//- using a const-cast to have it behave like a mutable.
// Exercise caution when using.
//
// \param recursive search parent registries.
//
// \return nullptr if the object was not found or had incorrect type.
template<class Type>
Type* getObjectPtr
(
const word& name,
const bool recursive = false
) const;
//- Lookup and return const reference to the object
//- of the given Type. Fatal if not found or the wrong type.
//
// \param recursive search parent registries.
template<class Type>
const Type& lookupObject
(
@ -267,8 +321,10 @@ public:
const bool recursive = false
) const;
//- Lookup and return the object of the given Type.
// If recursive, search parent registries.
//- Lookup and return non-const reference to the object
//- of the given Type. Fatal if not found or the wrong type.
//
// \param recursive search parent registries.
template<class Type>
Type& lookupObjectRef
(
@ -276,30 +332,6 @@ public:
const bool recursive = false
) const;
//- Lookup and return pointer to the object of the given Type,
// otherwise nullptr if the object was not found,
// or had the incorrect type.
// If recursive, search parent registries.
template<class Type>
const Type* lookupObjectPtr
(
const word& name,
const bool recursive = false
) const;
//- Lookup and return non-const pointer to the object
// of the given Type,
// otherwise nullptr if the object was not found,
// or had the incorrect type.
// If recursive, search parent registries.
template<class Type>
Type* lookupObjectRefPtr
(
const word& name,
const bool recursive = false
) const;
// Events
@ -349,6 +381,34 @@ public:
IOstream::compressionType cmp,
const bool valid
) const;
// Housekeeping
//- Same as findObject
// \deprecated use findObject (OCT-2018)
template<class Type>
const Type* lookupObjectPtr
(
const word& name,
bool recursive = false
) const
{
return this->cfindObject<Type>(name, recursive);
}
//- Same as getObjectPtr
//
// \deprecated use getObjectPtr (OCT-2018)
template<class Type>
Type* lookupObjectRefPtr
(
const word& name,
bool recursive = false
) const
{
return this->getObjectPtr<Type>(name, recursive);
}
};

View File

@ -156,7 +156,7 @@ Foam::HashTable<const Type*> Foam::objectRegistry::lookupClass
forAllConstIters(*this, iter)
{
if (strict ? isType<Type>(*iter()) : isA<Type>(*iter()))
if (strict ? isType<Type>(*iter()) : bool(isA<Type>(*iter())))
{
objectsOfClass.insert
(
@ -180,7 +180,7 @@ Foam::HashTable<Type*> Foam::objectRegistry::lookupClass
forAllIters(*this, iter)
{
if (strict ? isType<Type>(*iter()) : isA<Type>(*iter()))
if (strict ? isType<Type>(*iter()) : bool(isA<Type>(*iter())))
{
objectsOfClass.insert
(
@ -201,14 +201,71 @@ bool Foam::objectRegistry::foundObject
const bool recursive
) const
{
const Type* ptr = this->lookupObjectPtr<Type>(name, recursive);
return this->cfindObject<Type>(name, recursive);
}
template<class Type>
const Type* Foam::objectRegistry::cfindObject
(
const word& name,
const bool recursive
) const
{
const_iterator iter = cfind(name);
if (iter.found())
{
const Type* ptr = dynamic_cast<const Type*>(iter());
if (ptr)
{
return true;
return ptr;
}
}
else if (recursive && this->parentNotTime())
{
return parent_.cfindObject<Type>(name, recursive);
}
return false;
return nullptr;
}
template<class Type>
const Type* Foam::objectRegistry::findObject
(
const word& name,
const bool recursive
) const
{
return this->cfindObject<Type>(name, recursive);
}
template<class Type>
Type* Foam::objectRegistry::findObject
(
const word& name,
const bool recursive
)
{
const Type* ptr = this->cfindObject<Type>(name, recursive);
return const_cast<Type*>(ptr);
}
template<class Type>
Type* Foam::objectRegistry::getObjectPtr
(
const word& name,
const bool recursive
) const
{
const Type* ptr = this->cfindObject<Type>(name, recursive);
return const_cast<Type*>(ptr);
}
@ -219,7 +276,7 @@ const Type& Foam::objectRegistry::lookupObject
const bool recursive
) const
{
const_iterator iter = find(name);
const_iterator iter = cfind(name);
if (iter.found())
{
@ -270,44 +327,4 @@ Type& Foam::objectRegistry::lookupObjectRef
}
template<class Type>
const Type* Foam::objectRegistry::lookupObjectPtr
(
const word& name,
const bool recursive
) const
{
const_iterator iter = find(name);
if (iter.found())
{
const Type* ptr = dynamic_cast<const Type*>(iter());
if (ptr)
{
return ptr;
}
}
else if (recursive && this->parentNotTime())
{
return parent_.lookupObjectPtr<Type>(name, recursive);
}
return nullptr;
}
template<class Type>
Type* Foam::objectRegistry::lookupObjectRefPtr
(
const word& name,
const bool recursive
) const
{
const Type* ptr = this->lookupObjectPtr<Type>(name, recursive);
return const_cast<Type*>(ptr);
}
// ************************************************************************* //

View File

@ -338,12 +338,12 @@ void Foam::lduMatrix::setResidualField
}
IOField<scalar>* residualPtr =
lduMesh_.thisDb().lookupObjectRefPtr<IOField<scalar>>(lookupName);
lduMesh_.thisDb().getObjectPtr<IOField<scalar>>(lookupName);
if (residualPtr)
{
const IOdictionary* dataPtr =
lduMesh_.thisDb().lookupObjectPtr<IOdictionary>("data");
lduMesh_.thisDb().findObject<IOdictionary>("data");
if (dataPtr)
{

View File

@ -165,7 +165,7 @@ void Foam::outletMachNumberPressureFvPatchScalarField::updateCoeffs()
}
const fluidThermo* thermoPtr =
db().lookupObjectPtr<fluidThermo>(basicThermo::dictName);
db().findObject<fluidThermo>(basicThermo::dictName);
const volVectorField& U = db().lookupObject<volVectorField>(UName_);

View File

@ -240,7 +240,7 @@ void turbulentTemperatureRadCoupledMixedFvPatchScalarField::updateCoeffs()
{
const basicThermo* thermo =
nbrMesh.lookupObjectPtr<basicThermo>(basicThermo::dictName);
nbrMesh.findObject<basicThermo>(basicThermo::dictName);
if (thermo)
{
@ -269,7 +269,7 @@ void turbulentTemperatureRadCoupledMixedFvPatchScalarField::updateCoeffs()
// Local inertia therm
{
const basicThermo* thermo =
mesh.lookupObjectPtr<basicThermo>(basicThermo::dictName);
mesh.findObject<basicThermo>(basicThermo::dictName);
if (thermo)
{

View File

@ -448,11 +448,7 @@ void Foam::epsilonWallFunctionFvPatchScalarField::updateCoeffs()
typedef DimensionedField<scalar, volMesh> FieldType;
FieldType& G =
const_cast<FieldType&>
(
db().lookupObject<FieldType>(turbModel.GName())
);
FieldType& G = db().lookupObjectRef<FieldType>(turbModel.GName());
FieldType& epsilon = const_cast<FieldType&>(internalField());

View File

@ -117,9 +117,7 @@ bool Foam::dynamicInkJetFvMesh::update()
fvMesh::movePoints(newPoints);
volVectorField& U =
const_cast<volVectorField&>(lookupObject<volVectorField>("U"));
U.correctBoundaryConditions();
lookupObjectRef<volVectorField>("U").correctBoundaryConditions();
return true;
}

View File

@ -91,10 +91,11 @@ bool Foam::dynamicMotionSolverListFvMesh::update()
fvMesh::movePoints(points() + disp);
if (foundObject<volVectorField>("U"))
volVectorField* Uptr = getObjectPtr<volVectorField>("U");
if (Uptr)
{
const_cast<volVectorField&>(lookupObject<volVectorField>("U"))
.correctBoundaryConditions();
Uptr->correctBoundaryConditions();
}
}

View File

@ -182,8 +182,7 @@ bool Foam::dynamicMultiMotionSolverFvMesh::update()
if (foundObject<volVectorField>("U"))
{
const_cast<volVectorField&>(lookupObject<volVectorField>("U"))
.correctBoundaryConditions();
lookupObjectRef<volVectorField>("U").correctBoundaryConditions();
}
else if (!hasWarned)
{

View File

@ -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

@ -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

@ -37,27 +37,19 @@ License
const Foam::surfaceScalarField&
Foam::pressurePIDControlInletVelocityFvPatchVectorField::facePressure() const
{
const volScalarField& p(db().lookupObject<volScalarField>(pName_));
const word pfName(pName_ + "f");
if (!db().foundObject<surfaceScalarField>(pfName))
{
surfaceScalarField* pfPtr
(
new surfaceScalarField(pfName, linearInterpolate(p))
);
const volScalarField& p = db().lookupObject<volScalarField>(pName_);
surfaceScalarField* pfPtr = db().getObjectPtr<surfaceScalarField>(pfName);
if (!pfPtr)
{
pfPtr = new surfaceScalarField(pfName, linearInterpolate(p));
pfPtr->store();
}
surfaceScalarField& pf
(
const_cast<surfaceScalarField&>
(
db().lookupObject<surfaceScalarField>(pfName)
)
);
surfaceScalarField& pf = *pfPtr;
if (!pf.upToDate(p))
{

View File

@ -144,11 +144,7 @@ void Foam::waveSurfacePressureFvPatchScalarField::updateCoeffs()
const scalar dt = db().time().deltaTValue();
// retrieve non-const access to zeta field from the database
volVectorField& zeta =
const_cast<volVectorField&>
(
db().lookupObject<volVectorField>(zetaName_)
);
volVectorField& zeta = db().lookupObjectRef<volVectorField>(zetaName_);
vectorField& zetap = zeta.boundaryFieldRef()[patchi];
// lookup d/dt scheme from database for zeta

View File

@ -171,10 +171,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

@ -103,9 +103,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))
@ -123,12 +124,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;
@ -138,12 +137,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

@ -171,13 +171,7 @@ Foam::LimitedScheme<Type, Limiter, LimitFunc>::limiter
}
surfaceScalarField& limiterField =
const_cast<surfaceScalarField&>
(
mesh.lookupObject<surfaceScalarField>
(
limiterFieldName
)
);
mesh.lookupObjectRef<surfaceScalarField>(limiterFieldName);
calcLimiter(phi, limiterField);

View File

@ -372,9 +372,7 @@ Foam::volPointInterpolation::interpolate
const pointMesh& pm = pointMesh::New(vf.mesh());
// Construct tmp<pointField>
tmp<GeometricField<Type, pointPatchField, pointMesh>> tpf
(
new GeometricField<Type, pointPatchField, pointMesh>
auto tpf = tmp<GeometricField<Type, pointPatchField, pointMesh>>::New
(
IOobject
(
@ -385,7 +383,6 @@ Foam::volPointInterpolation::interpolate
pm,
vf.dimensions(),
patchFieldTypes
)
);
interpolateInternalField(vf, tpf.ref());
@ -427,28 +424,20 @@ Foam::volPointInterpolation::interpolate
const pointMesh& pm = pointMesh::New(vf.mesh());
const objectRegistry& db = pm.thisDb();
PointFieldType* pfPtr =
db.objectRegistry::template getObjectPtr<PointFieldType>(name);
if (!cache || vf.mesh().changing())
{
// Delete any old occurrences to avoid double registration
if (db.objectRegistry::template foundObject<PointFieldType>(name))
{
PointFieldType& pf = const_cast<PointFieldType&>
(
db.objectRegistry::template lookupObject<PointFieldType>(name)
);
if (pf.ownedByRegistry())
if (pfPtr && pfPtr->ownedByRegistry())
{
solution::cachePrintMessage("Deleting", name, vf);
pf.release();
delete &pf;
}
pfPtr->release();
delete pfPtr;
}
tmp<GeometricField<Type, pointPatchField, pointMesh>> tpf
(
new GeometricField<Type, pointPatchField, pointMesh>
auto tpf = tmp<GeometricField<Type, pointPatchField, pointMesh>>::New
(
IOobject
(
@ -458,29 +447,24 @@ Foam::volPointInterpolation::interpolate
),
pm,
vf.dimensions()
)
);
interpolate(vf, tpf.ref());
return tpf;
}
else
{
if (!db.objectRegistry::template foundObject<PointFieldType>(name))
if (!pfPtr)
{
solution::cachePrintMessage("Calculating and caching", name, vf);
tmp<PointFieldType> tpf = interpolate(vf, name, false);
PointFieldType* pfPtr = tpf.ptr();
pfPtr = interpolate(vf, name, false).ptr();
regIOobject::store(pfPtr);
return *pfPtr;
}
else
{
PointFieldType& pf = const_cast<PointFieldType&>
(
db.objectRegistry::template lookupObject<PointFieldType>(name)
);
PointFieldType& pf = *pfPtr;
if (pf.upToDate(vf)) //TBD: , vf.mesh().points()))
{
@ -491,9 +475,9 @@ Foam::volPointInterpolation::interpolate
solution::cachePrintMessage("Updating", name, vf);
interpolate(vf, pf);
}
return pf;
}
}
return *pfPtr;
}
@ -537,28 +521,21 @@ Foam::volPointInterpolation::interpolate
const pointMesh& pm = pointMesh::New(vf.mesh());
const objectRegistry& db = pm.thisDb();
PointFieldType* pfPtr =
db.objectRegistry::template getObjectPtr<PointFieldType>(name);
if (!cache || vf.mesh().changing())
{
// Delete any old occurrences to avoid double registration
if (db.objectRegistry::template foundObject<PointFieldType>(name))
{
PointFieldType& pf = const_cast<PointFieldType&>
(
db.objectRegistry::template lookupObject<PointFieldType>(name)
);
if (pf.ownedByRegistry())
if (pfPtr && pfPtr->ownedByRegistry())
{
solution::cachePrintMessage("Deleting", name, vf);
pf.release();
delete &pf;
}
pfPtr->release();
delete pfPtr;
}
tmp<DimensionedField<Type, pointMesh>> tpf
(
new DimensionedField<Type, pointMesh>
auto tpf = tmp<DimensionedField<Type, pointMesh>>::New
(
IOobject
(
@ -568,29 +545,24 @@ Foam::volPointInterpolation::interpolate
),
pm,
vf.dimensions()
)
);
interpolateDimensionedInternalField(vf, tpf.ref());
return tpf;
}
else
{
if (!db.objectRegistry::template foundObject<PointFieldType>(name))
if (!pfPtr)
{
solution::cachePrintMessage("Calculating and caching", name, vf);
tmp<PointFieldType> tpf = interpolate(vf, name, false);
PointFieldType* pfPtr = tpf.ptr();
pfPtr = interpolate(vf, name, false).ptr();
regIOobject::store(pfPtr);
return *pfPtr;
}
else
{
PointFieldType& pf = const_cast<PointFieldType&>
(
db.objectRegistry::template lookupObject<PointFieldType>(name)
);
PointFieldType& pf = *pfPtr;
if (pf.upToDate(vf)) //TBD: , vf.mesh().points()))
{
@ -601,10 +573,9 @@ Foam::volPointInterpolation::interpolate
solution::cachePrintMessage("Updating", name, vf);
interpolateDimensionedInternalField(vf, pf);
}
}
return pf;
}
}
return *pfPtr;
}

View File

@ -415,7 +415,7 @@ void Foam::functionObjects::externalCoupled::initCoupling()
UPtrList<const fvMesh> meshes(regionNames.size());
forAll(regionNames, regi)
{
meshes.set(regi, time_.lookupObjectPtr<fvMesh>(regionNames[regi]));
meshes.set(regi, time_.findObject<fvMesh>(regionNames[regi]));
}
const labelList& groups = regionToGroups_[compName];
@ -692,7 +692,7 @@ void Foam::functionObjects::externalCoupled::readDataMaster()
UPtrList<const fvMesh> meshes(regionNames.size());
forAll(regionNames, regi)
{
meshes.set(regi, time_.lookupObjectPtr<fvMesh>(regionNames[regi]));
meshes.set(regi, time_.findObject<fvMesh>(regionNames[regi]));
}
const labelList& groups = regionToGroups_[compName];
@ -736,7 +736,7 @@ void Foam::functionObjects::externalCoupled::writeDataMaster() const
UPtrList<const fvMesh> meshes(regionNames.size());
forAll(regionNames, regi)
{
meshes.set(regi, time_.lookupObjectPtr<fvMesh>(regionNames[regi]));
meshes.set(regi, time_.findObject<fvMesh>(regionNames[regi]));
}
const labelList& groups = regionToGroups_[compName];

View File

@ -82,8 +82,7 @@ bool Foam::functionObjects::externalCoupled::readData
label nFound = 0;
for (const fvMesh& mesh : meshes)
{
const volFieldType* vfptr =
mesh.lookupObjectPtr<volFieldType>(fieldName);
const volFieldType* vfptr = mesh.findObject<volFieldType>(fieldName);
if (!vfptr)
{
@ -358,8 +357,7 @@ bool Foam::functionObjects::externalCoupled::writeData
for (const fvMesh& mesh : meshes)
{
const volFieldType* vfptr =
mesh.lookupObjectPtr<volFieldType>(fieldName);
const volFieldType* vfptr = mesh.findObject<volFieldType>(fieldName);
if (!vfptr)
{

View File

@ -37,7 +37,7 @@ bool Foam::functionObjects::fieldAverageItem::calculateMeanField
return false;
}
const Type* baseFieldPtr = obr.lookupObjectPtr<Type>(fieldName_);
const Type* baseFieldPtr = obr.findObject<Type>(fieldName_);
if (!baseFieldPtr)
{
@ -122,7 +122,7 @@ bool Foam::functionObjects::fieldAverageItem::calculateMeanField
{
const word& fieldName = nameIter();
const scalar dt = timeIter();
const Type* w = obr.lookupObjectPtr<Type>(fieldName);
const Type* w = obr.findObject<Type>(fieldName);
meanField += dt*(*w);
@ -173,7 +173,7 @@ bool Foam::functionObjects::fieldAverageItem::calculatePrime2MeanField
return false;
}
const Type1* baseFieldPtr = obr.lookupObjectPtr<Type1>(fieldName_);
const Type1* baseFieldPtr = obr.findObject<Type1>(fieldName_);
if (!baseFieldPtr)
{
@ -258,7 +258,7 @@ bool Foam::functionObjects::fieldAverageItem::calculatePrime2MeanField
{
const word& fieldName = nameIter();
const scalar dt = timeIter();
const Type1* w = obr.lookupObjectPtr<Type1>(fieldName);
const Type1* w = obr.findObject<Type1>(fieldName);
prime2MeanField += dt*(sqr((*w) - meanField));

View File

@ -119,7 +119,7 @@ void Foam::functionObjects::fieldAverage::restoreWindowFieldsType
const word& fieldName = item.fieldName();
const Type* fieldPtr = lookupObjectPtr<Type>(fieldName);
const Type* fieldPtr = findObject<Type>(fieldName);
if (!fieldPtr)
{

View File

@ -54,7 +54,7 @@ void Foam::functionObjects::fieldExtents::calcFieldExtents
typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
const VolFieldType* fieldPtr =
obr_.lookupObjectPtr<VolFieldType>(fieldName);
obr_.findObject<VolFieldType>(fieldName);
if (!fieldPtr)
{

View File

@ -129,7 +129,7 @@ void Foam::functionObjects::fluxSummary::initialiseSurface
DynamicList<boolList>& faceFlip
) const
{
const surfMesh* sPtr = mesh_.lookupObjectPtr<surfMesh>(surfName);
const surfMesh* sPtr = mesh_.findObject<surfMesh>(surfName);
if (!sPtr)
{
FatalErrorInFunction
@ -154,7 +154,7 @@ void Foam::functionObjects::fluxSummary::initialiseSurfaceAndDirection
DynamicList<boolList>& faceFlip
) const
{
const surfMesh* sPtr = mesh_.lookupObjectPtr<surfMesh>(surfName);
const surfMesh* sPtr = mesh_.findObject<surfMesh>(surfName);
if (!sPtr)
{
FatalErrorInFunction

View File

@ -47,13 +47,15 @@ bool Foam::functionObjects::readFields::loadField(const word& fieldName)
}
else if (foundObject<SurfaceFieldType>(fieldName))
{
DebugInfo<< "readFields: " << SurfaceFieldType::typeName
DebugInfo
<< "readFields: " << SurfaceFieldType::typeName
<< " " << fieldName << " already exists in database"
<< " already in database" << endl;
}
else if (foundObject<SurfFieldType>(fieldName))
{
DebugInfo<< "readFields: " << SurfFieldType::typeName
DebugInfo
<< "readFields: " << SurfFieldType::typeName
<< " " << fieldName << " already exists in database"
<< " already in database" << endl;
}

View File

@ -30,7 +30,7 @@ bool Foam::functionObjects::reference::calcType()
{
typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
const VolFieldType* vfPtr = lookupObjectPtr<VolFieldType>(fieldName_);
const VolFieldType* vfPtr = findObject<VolFieldType>(fieldName_);
if (vfPtr)
{

View File

@ -66,7 +66,7 @@ Foam::functionObjects::setFlow::modeTypeNames
void Foam::functionObjects::setFlow::setPhi(const volVectorField& U)
{
surfaceScalarField* phiptr =
mesh_.lookupObjectRefPtr<surfaceScalarField>(phiName_);
mesh_.getObjectPtr<surfaceScalarField>(phiName_);
if (!phiptr)
{
@ -76,7 +76,7 @@ void Foam::functionObjects::setFlow::setPhi(const volVectorField& U)
if (rhoName_ != "none")
{
const volScalarField* rhoptr =
mesh_.lookupObjectPtr<volScalarField>(rhoName_);
mesh_.findObject<volScalarField>(rhoName_);
if (rhoptr)
{
@ -207,10 +207,11 @@ bool Foam::functionObjects::setFlow::read(const dictionary& dict)
bool Foam::functionObjects::setFlow::execute()
{
volVectorField* Uptr = mesh_.lookupObjectRefPtr<volVectorField>(UName_);
volVectorField* Uptr =
mesh_.getObjectPtr<volVectorField>(UName_);
surfaceScalarField* phiptr =
mesh_.lookupObjectRefPtr<surfaceScalarField>(phiName_);
mesh_.getObjectPtr<surfaceScalarField>(phiName_);
Log << nl << name() << ":" << nl;
@ -431,13 +432,13 @@ bool Foam::functionObjects::setFlow::execute()
bool Foam::functionObjects::setFlow::write()
{
const auto& Uptr = mesh_.lookupObjectRefPtr<volVectorField>(UName_);
const auto* Uptr = mesh_.findObject<volVectorField>(UName_);
if (Uptr)
{
Uptr->write();
}
const auto& phiptr = mesh_.lookupObjectRefPtr<surfaceScalarField>(phiName_);
const auto* phiptr = mesh_.findObject<surfaceScalarField>(phiName_);
if (phiptr)
{
phiptr->write();

View File

@ -102,8 +102,7 @@ bool Foam::functionObjects::stabilityBlendingFactor::calc()
bool Foam::functionObjects::stabilityBlendingFactor::init(bool first)
{
const IOField<scalar>* residualPtr =
mesh_.lookupObjectPtr<IOField<scalar>>(residualName_);
const auto* residualPtr = mesh_.findObject<IOField<scalar>>(residualName_);
if (residuals_)
{
@ -164,7 +163,7 @@ bool Foam::functionObjects::stabilityBlendingFactor::init(bool first)
}
const volScalarField* nonOrthPtr =
mesh_.lookupObjectPtr<volScalarField>(nonOrthogonalityName_);
mesh_.findObject<volScalarField>(nonOrthogonalityName_);
if (nonOrthogonality_)
{
@ -200,7 +199,7 @@ bool Foam::functionObjects::stabilityBlendingFactor::init(bool first)
}
const volScalarField* skewnessPtr =
mesh_.lookupObjectPtr<volScalarField>(skewnessName_);
mesh_.findObject<volScalarField>(skewnessName_);
if (skewness_)
{
@ -235,7 +234,7 @@ bool Foam::functionObjects::stabilityBlendingFactor::init(bool first)
}
const volScalarField* faceWeightsPtr =
mesh_.lookupObjectPtr<volScalarField>(faceWeightName_);
mesh_.findObject<volScalarField>(faceWeightName_);
if (faceWeight_)
{
@ -342,7 +341,7 @@ bool Foam::functionObjects::stabilityBlendingFactor::init(bool first)
const volVectorField* UNamePtr =
mesh_.lookupObjectPtr<volVectorField>(UName_);
mesh_.findObject<volVectorField>(UName_);
if (Co_)
{
@ -520,7 +519,7 @@ Foam::functionObjects::stabilityBlendingFactor::stabilityBlendingFactor
store(resultName_, faceBlendedPtr);
const volScalarField* nonOrthPtr =
mesh_.lookupObjectPtr<volScalarField>(nonOrthogonalityName_);
mesh_.findObject<volScalarField>(nonOrthogonalityName_);
if (nonOrthogonality_)
{
@ -552,7 +551,7 @@ Foam::functionObjects::stabilityBlendingFactor::stabilityBlendingFactor
const volScalarField* faceWeightsPtr =
mesh_.lookupObjectPtr<volScalarField>(faceWeightName_);
mesh_.findObject<volScalarField>(faceWeightName_);
if (faceWeight_)
{
@ -583,7 +582,7 @@ Foam::functionObjects::stabilityBlendingFactor::stabilityBlendingFactor
}
const volScalarField* skewnessPtr =
mesh_.lookupObjectPtr<volScalarField>(skewnessName_);
mesh_.findObject<volScalarField>(skewnessName_);
if (skewness_)
{

View File

@ -107,14 +107,12 @@ bool Foam::functionObjects::surfaceInterpolate::write()
{
const word& fieldName = fieldSet_[i].second();
if (mesh_.foundObject<regIOobject>(fieldName))
const regIOobject* ioptr = obr_.findObject<regIOobject>(fieldName);
if (ioptr)
{
Log << " " << fieldName << nl;
const regIOobject& field =
obr_.lookupObject<regIOobject>(fieldName);
field.write();
ioptr->write();
}
else
{

View File

@ -103,12 +103,10 @@ bool Foam::functionObjects::turbulenceFields::compressible()
{
return false;
}
else
{
FatalErrorInFunction
<< "Turbulence model not found in database, deactivating"
<< exit(FatalError);
}
return false;
}

View File

@ -38,10 +38,11 @@ void Foam::functionObjects::turbulenceFields::processField
const word scopedName = modelName + ':' + fieldName;
if (obr_.foundObject<FieldType>(scopedName))
FieldType* fldPtr = obr_.getObjectPtr<FieldType>(scopedName);
if (fldPtr)
{
FieldType& fld = obr_.lookupObjectRef<FieldType>(scopedName);
fld == tvalue();
(*fldPtr) == tvalue();
}
else if (obr_.found(scopedName))
{

View File

@ -57,12 +57,8 @@ bool Foam::functionObjects::vorticity::calc()
fvc::curl(lookupObject<volVectorField>(fieldName_))
);
}
else
{
return false;
}
return true;
return false;
}

View File

@ -183,28 +183,48 @@ bool Foam::functionObjects::wallShearStress::execute()
volVectorField& wallShearStress =
mesh_.lookupObjectRef<volVectorField>(type());
const word& turbModelName = turbulenceModel::propertiesName;
auto cmpModelPtr =
mesh_.lookupObjectPtr<compressible::turbulenceModel>(turbModelName);
auto icoModelPtr =
mesh_.lookupObjectPtr<incompressible::turbulenceModel>(turbModelName);
bool ok = false;
if (cmpModelPtr)
// compressible
if (!ok)
{
calcShearStress(cmpModelPtr->devRhoReff(), wallShearStress);
}
else if (icoModelPtr)
typedef compressible::turbulenceModel turbType;
const turbType* modelPtr =
findObject<turbType>(turbulenceModel::propertiesName);
ok = modelPtr;
if (ok)
{
calcShearStress(icoModelPtr->devReff(), wallShearStress);
calcShearStress(modelPtr->devRhoReff(), wallShearStress);
}
else
}
// incompressible
if (!ok)
{
typedef incompressible::turbulenceModel turbType;
const turbType* modelPtr =
findObject<turbType>(turbulenceModel::propertiesName);
ok = modelPtr;
if (ok)
{
calcShearStress(modelPtr->devReff(), wallShearStress);
}
}
if (!ok)
{
FatalErrorInFunction
<< "Unable to find turbulence model in the "
<< "database" << exit(FatalError);
}
return true;
return ok;
}

View File

@ -176,16 +176,15 @@ bool Foam::functionObjects::zeroGradient::write()
}
// Consistent output order
const wordList outputList = results_.sortedToc();
for (const word& fieldName : outputList)
for (const word& fieldName : results_.sortedToc())
{
if (foundObject<regIOobject>(fieldName))
{
const regIOobject& io = lookupObject<regIOobject>(fieldName);
const regIOobject* ioptr = findObject<regIOobject>(fieldName);
if (ioptr)
{
Log << " " << fieldName << endl;
io.write();
ioptr->write();
}
}

View File

@ -106,7 +106,7 @@ bool Foam::functionObjects::vtkCloud::writeCloud
const word& cloudName
)
{
const auto* objPtr = mesh_.lookupObjectPtr<cloud>(cloudName);
const auto* objPtr = mesh_.findObject<cloud>(cloudName);
if (!objPtr)
{
return false;
@ -127,7 +127,7 @@ bool Foam::functionObjects::vtkCloud::writeCloud
objPtr->writeObjects(obrTmp);
const auto* pointsPtr = obrTmp.lookupObjectPtr<vectorField>("position");
const auto* pointsPtr = obrTmp.findObject<vectorField>("position");
if (!pointsPtr)
{

View File

@ -52,7 +52,7 @@ Foam::wordList Foam::functionObjects::vtkCloud::writeFields
for (const word& fieldName : fieldNames)
{
const auto* fldPtr = obrTmp.lookupObjectPtr<IOField<Type>>(fieldName);
const auto* fldPtr = obrTmp.findObject<IOField<Type>>(fieldName);
if (Pstream::master())
{

View File

@ -83,7 +83,7 @@ Foam::functionObjects::energyTransport::kappaEff() const
{
typedef incompressible::turbulenceModel turbType;
const turbType* turbPtr = lookupObjectPtr<turbType>
const turbType* turbPtr = findObject<turbType>
(
turbulenceModel::propertiesName
);
@ -305,7 +305,7 @@ Foam::functionObjects::energyTransport::energyTransport
phases_.set
(
i,
mesh_.lookupObjectRefPtr<volScalarField>(phaseNames_[i])
mesh_.getObjectPtr<volScalarField>(phaseNames_[i])
);
}

View File

@ -88,10 +88,7 @@ Foam::tmp<Foam::volScalarField> Foam::functionObjects::scalarTransport::D
const surfaceScalarField& phi
) const
{
typedef incompressible::turbulenceModel icoModel;
typedef compressible::turbulenceModel cmpModel;
word Dname("D" + s.name());
const word Dname("D" + s.name());
if (constantD_)
{
@ -109,39 +106,50 @@ Foam::tmp<Foam::volScalarField> Foam::functionObjects::scalarTransport::D
dimensionedScalar(Dname, phi.dimensions()/dimLength, D_)
);
}
else if (nutName_ != "none")
if (nutName_ != "none")
{
const volScalarField& nutMean =
mesh_.lookupObject<volScalarField>(nutName_);
return tmp<volScalarField>::New(Dname, nutMean);
}
else if (foundObject<icoModel>(turbulenceModel::propertiesName))
// Incompressible
{
const icoModel& model = lookupObject<icoModel>
const auto* turb =
findObject<incompressible::turbulenceModel>
(
turbulenceModel::propertiesName
);
if (turb)
{
return tmp<volScalarField>::New
(
Dname,
alphaD_*model.nu() + alphaDt_*model.nut()
alphaD_ * turb->nu() + alphaDt_ * turb->nut()
);
}
else if (foundObject<cmpModel>(turbulenceModel::propertiesName))
}
// Compressible
{
const cmpModel& model = lookupObject<cmpModel>
const auto* turb =
findObject<compressible::turbulenceModel>
(
turbulenceModel::propertiesName
);
if (turb)
{
return tmp<volScalarField>::New
(
Dname,
alphaD_*model.mu() + alphaDt_*model.mut()
alphaD_ * turb->mu() + alphaDt_ * turb->mut()
);
}
}
return tmp<volScalarField>::New

View File

@ -38,10 +38,16 @@ int Foam::functionObjects::ensightWrite::writeVolField
// State: return 0 (not-processed), -1 (skip), +1 ok
typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
const VolFieldType* fldPtr;
// Already done
if (state)
{
return state;
}
// Already done, or not available
if (state || !(fldPtr = lookupObjectPtr<VolFieldType>(inputName)))
const VolFieldType* fldPtr = findObject<VolFieldType>(inputName);
// Not available
if (!fldPtr)
{
return state;
}

View File

@ -82,22 +82,18 @@ bool Foam::functionObjects::removeRegisteredObject::read(const dictionary& dict)
bool Foam::functionObjects::removeRegisteredObject::execute()
{
forAll(objectNames_, i)
for (const word& objName : objectNames_)
{
if (foundObject<regIOobject>(objectNames_[i]))
{
const regIOobject& obj =
lookupObject<regIOobject>(objectNames_[i]);
regIOobject* ptr = getObjectPtr<regIOobject>(objName);
if (obj.ownedByRegistry())
if (ptr && ptr->ownedByRegistry())
{
Log << type() << " " << name() << " output:" << nl
<< " removing object " << obj.name() << nl
<< " removing object " << ptr->name() << nl
<< endl;
const_cast<regIOobject&>(obj).release();
delete &obj;
}
ptr->release();
delete ptr;
}
}

View File

@ -113,8 +113,7 @@ void Foam::functionObjects::residuals::writeField(const word& fieldName) const
{
const word residualName("initialResidual:" + fieldName);
const IOField<scalar>* residualPtr =
mesh_.lookupObjectPtr<IOField<scalar>>(residualName);
const auto* residualPtr = mesh_.findObject<IOField<scalar>>(residualName);
if (residualPtr)
{

View File

@ -160,10 +160,12 @@ bool Foam::functionObjects::writeDictionary::write()
bool firstDict = true;
forAll(dictNames_, i)
{
if (obr_.foundObject<dictionary>(dictNames_[i]))
const dictionary* dictptr =
obr_.findObject<dictionary>(dictNames_[i]);
if (dictptr)
{
const dictionary& dict =
obr_.lookupObject<dictionary>(dictNames_[i]);
const dictionary& dict = *dictptr;
if (dict.digest() != digests_[i])
{

View File

@ -211,13 +211,9 @@ void uniformInterpolatedDisplacementPointPatchVectorField::updateCoeffs()
>(*fieldsCacheIter());
pointVectorField& d = const_cast<pointVectorField&>
(
timeCache.lookupObject<pointVectorField>
(
fieldName_
)
);
pointVectorField& d =
timeCache.lookupObjectRef<pointVectorField>(fieldName_);
d.correctBoundaryConditions();
}
}

View File

@ -106,7 +106,7 @@ Foam::fv::viscousDissipation::viscousDissipation
)
{
const basicThermo* thermoPtr =
mesh_.lookupObjectPtr<basicThermo>(basicThermo::dictName);
mesh_.findObject<basicThermo>(basicThermo::dictName);
if (thermoPtr)
{
@ -136,7 +136,7 @@ Foam::fv::viscousDissipation::devRhoReff() const
// Incompressible
{
const auto* turbPtr =
mesh_.lookupObjectPtr<incompressible::turbulenceModel>
mesh_.findObject<incompressible::turbulenceModel>
(
turbulenceModel::propertiesName
);
@ -150,7 +150,7 @@ Foam::fv::viscousDissipation::devRhoReff() const
// Compressible
{
const auto* turbPtr =
mesh_.lookupObjectPtr<compressible::turbulenceModel>
mesh_.findObject<compressible::turbulenceModel>
(
turbulenceModel::propertiesName
);
@ -196,8 +196,7 @@ void Foam::fv::viscousDissipation::addSup
);
// Cached?
const GradFieldType* gradUPtr =
mesh_.lookupObjectPtr<GradFieldType>(gradUName);
const GradFieldType* gradUPtr = mesh_.findObject<GradFieldType>(gradUName);
if (gradUPtr)
{

View File

@ -206,10 +206,12 @@ void Foam::fv::interRegionHeatTransferModel::addSup
{
if (he.dimensions() == dimEnergy/dimMass)
{
if (mesh_.foundObject<basicThermo>(basicThermo::dictName))
const basicThermo* thermoPtr =
mesh_.findObject<basicThermo>(basicThermo::dictName);
if (thermoPtr)
{
const basicThermo& thermo =
mesh_.lookupObject<basicThermo>(basicThermo::dictName);
const basicThermo& thermo = *thermoPtr;
volScalarField htcByCpv(htc_/thermo.Cpv());

View File

@ -101,10 +101,10 @@ void Foam::InterfaceForce<CloudType>::cacheFields(const bool store)
if (fieldExists)
{
const volVectorField& gradInterForce = this->mesh().template
lookupObject<volVectorField>(fName);
volVectorField& gradInterForce =
this->mesh().template lookupObjectRef<volVectorField>(fName);
const_cast<volVectorField&>(gradInterForce).checkOut();
gradInterForce.checkOut();
}
}
}

View File

@ -116,10 +116,10 @@ void Foam::LiftForce<CloudType>::cacheFields(const bool store)
if (fieldExists)
{
const volVectorField& curlUc = this->mesh().template
lookupObject<volVectorField>(fName);
volVectorField& curlUc =
this->mesh().template lookupObjectRef<volVectorField>(fName);
const_cast<volVectorField&>(curlUc).checkOut();
curlUc.checkOut();
}
}
}

View File

@ -106,10 +106,10 @@ void Foam::PressureGradientForce<CloudType>::cacheFields(const bool store)
if (fieldExists)
{
const volVectorField& DUcDt = this->mesh().template
lookupObject<volVectorField>(fName);
volVectorField& DUcDt =
this->mesh().template lookupObjectRef<volVectorField>(fName);
const_cast<volVectorField&>(DUcDt).checkOut();
DUcDt.checkOut();
}
}
}

View File

@ -41,11 +41,11 @@ Foam::DispersionRASModel<CloudType>::kModel() const
this->owner().U().group()
);
if (obr.foundObject<turbulenceModel>(turbName))
const turbulenceModel* turb = obr.findObject<turbulenceModel>(turbName);
if (turb)
{
const turbulenceModel& model =
obr.lookupObject<turbulenceModel>(turbName);
return model.k();
return turb->k();
}
FatalErrorInFunction
@ -69,11 +69,11 @@ Foam::DispersionRASModel<CloudType>::epsilonModel() const
this->owner().U().group()
);
if (obr.foundObject<turbulenceModel>(turbName))
const turbulenceModel* turb = obr.findObject<turbulenceModel>(turbName);
if (turb)
{
const turbulenceModel& model =
obr.lookupObject<turbulenceModel>(turbName);
return model.epsilon();
return turb->epsilon();
}
FatalErrorInFunction

View File

@ -64,11 +64,11 @@ Foam::BrownianMotionForce<CloudType>::kModel() const
this->owner().U().group()
);
if (obr.foundObject<turbulenceModel>(turbName))
const turbulenceModel* turb = obr.findObject<turbulenceModel>(turbName);
if (turb)
{
const turbulenceModel& model =
obr.lookupObject<turbulenceModel>(turbName);
return model.k();
return turb->k();
}
FatalErrorInFunction

View File

@ -39,7 +39,7 @@ namespace Foam
const Foam::lumpedPointIOMovement*
Foam::lumpedPointIOMovement::lookupInRegistry(const objectRegistry& obr)
{
return obr.lookupObjectPtr<lumpedPointIOMovement>
return obr.findObject<lumpedPointIOMovement>
(
lumpedPointMovement::canonicalName
);

View File

@ -495,7 +495,7 @@ bool Foam::lumpedPointMovement::forcesAndMoments
// Calculated force per patch - cache
PtrMap<vectorField> forceOnPatches;
const volScalarField* pPtr = pmesh.lookupObjectPtr<volScalarField>(pName);
const volScalarField* pPtr = pmesh.findObject<volScalarField>(pName);
// fvMesh and has pressure field
if (isA<fvMesh>(pmesh) && pPtr)

View File

@ -240,8 +240,7 @@ const Foam::coordinateSystems& Foam::coordinateSystems::New
{
// Previously registered?
const coordinateSystems* ptr =
obr.lookupObjectPtr<coordinateSystems>(typeName);
const coordinateSystems* ptr = obr.findObject<coordinateSystems>(typeName);
if (ptr)
{

View File

@ -100,19 +100,16 @@ Foam::regionCoupledBaseGAMGInterface::regionCoupledBaseGAMGInterface
const polyMesh& nbrMesh =
fineRegionCoupledLduInterface_.nbrMesh();
if
(
nbrMesh.foundObject<GAMGAgglomeration>(GAMGAgglomeration::typeName)
)
{
const GAMGAgglomeration& nbrAgg = nbrMesh.thisDb().lookupObject
<
GAMGAgglomeration
>
const GAMGAgglomeration* nbrAggPtr = nbrMesh.thisDb().findObject
<GAMGAgglomeration>
(
GAMGAgglomeration::typeName
);
if (nbrAggPtr)
{
const GAMGAgglomeration& nbrAgg = *nbrAggPtr;
label nbrLevel(-1);
if (nbrAgg.size() > fineLevelIndex)
{

View File

@ -187,20 +187,16 @@ Foam::label Foam::regionCoupledBase::neighbPatchID() const
{
if (nbrPatchID_ == -1)
{
if
(
patch_.boundaryMesh().mesh().time().foundObject<polyMesh>
(
nbrRegionName_
)
)
{
const polyMesh& mesh =
patch_.boundaryMesh().mesh().time().lookupObject<polyMesh>
const polyMesh* meshPtr =
patch_.boundaryMesh().mesh().time().findObject<polyMesh>
(
nbrRegionName_
);
if (meshPtr)
{
const polyMesh& mesh = *meshPtr;
nbrPatchID_ = mesh.boundaryMesh().findPatchID(nbrPatchName_);
if (nbrPatchID_ == -1)

View File

@ -205,8 +205,8 @@ Foam::searchableSurfaceCollection::searchableSurfaceCollection
const word subGeomName(subDict.get<word>("surface"));
//Pout<< "Trying to find " << subGeomName << endl;
const searchableSurface& s =
io.db().lookupObject<searchableSurface>(subGeomName);
searchableSurface& s =
io.db().lookupObjectRef<searchableSurface>(subGeomName);
// I don't know yet how to handle the globalSize combined with
// regionOffset. Would cause non-consecutive indices locally
@ -218,7 +218,7 @@ Foam::searchableSurfaceCollection::searchableSurfaceCollection
<< exit(FatalError);
}
subGeom_.set(surfI, &(const_cast<searchableSurface&>(s)));
subGeom_.set(surfI, &s);
indexOffset_[surfI] = startIndex;
startIndex += subGeom_[surfI].size();

View File

@ -189,7 +189,7 @@ Foam::searchableSurfaceWithGaps::searchableSurfaceWithGaps
subGeom_.set
(
0,
io.db().lookupObjectRefPtr<searchableSurface>(subGeomName)
io.db().getObjectPtr<searchableSurface>(subGeomName)
);
bounds() = subGeom_[0].bounds();

View File

@ -803,14 +803,15 @@ void Foam::triSurfaceMesh::getNormal
void Foam::triSurfaceMesh::setField(const labelList& values)
{
auto* fldPtr = getObjectPtr<triSurfaceLabelField>("values");
if (foundObject<triSurfaceLabelField>("values"))
if (fldPtr)
{
lookupObjectRef<triSurfaceLabelField>("values").field() = values;
(*fldPtr).field() = values;
}
else
{
auto fldPtr = autoPtr<triSurfaceLabelField>::New
fldPtr = new triSurfaceLabelField
(
IOobject
(
@ -827,7 +828,7 @@ void Foam::triSurfaceMesh::setField(const labelList& values)
);
// Store field on triMesh
fldPtr.ptr()->store();
fldPtr->store();
}
}
@ -838,9 +839,11 @@ void Foam::triSurfaceMesh::getField
labelList& values
) const
{
if (foundObject<triSurfaceLabelField>("values"))
const auto* fldPtr = getObjectPtr<triSurfaceLabelField>("values");
if (fldPtr)
{
const auto& fld = lookupObject<triSurfaceLabelField>("values");
const auto& fld = *fldPtr;
values.setSize(info.size());

View File

@ -84,24 +84,13 @@ void Foam::refinementHistoryConstraint::add
List<labelPair>& explicitConnections
) const
{
autoPtr<const refinementHistory> storagePtr;
refinementHistory const* refPtr = nullptr;
const refinementHistory* refPtr =
mesh.findObject<refinementHistory>("refinementHistory");
if (mesh.foundObject<refinementHistory>("refinementHistory"))
autoPtr<const refinementHistory> storagePtr;
if (!refPtr)
{
if (decompositionConstraint::debug)
{
Info<< type() << " : found refinementHistory" << endl;
}
refPtr = &mesh.lookupObject<refinementHistory>("refinementHistory");
}
else
{
if (decompositionConstraint::debug)
{
Info<< type() << " : reading refinementHistory from time "
<< mesh.facesInstance() << endl;
}
storagePtr.reset
(
new refinementHistory
@ -120,6 +109,19 @@ void Foam::refinementHistoryConstraint::add
);
}
if (decompositionConstraint::debug)
{
if (refPtr)
{
Info<< type() << " : found refinementHistory" << nl;
}
else
{
Info<< type() << " : reading refinementHistory from time "
<< mesh.facesInstance() << nl;
}
}
const refinementHistory& history =
(
storagePtr.valid()
@ -151,24 +153,13 @@ void Foam::refinementHistoryConstraint::apply
labelList& decomposition
) const
{
autoPtr<const refinementHistory> storagePtr;
refinementHistory const* refPtr = nullptr;
const refinementHistory* refPtr =
mesh.findObject<refinementHistory>("refinementHistory");
if (mesh.foundObject<refinementHistory>("refinementHistory"))
autoPtr<const refinementHistory> storagePtr;
if (!refPtr)
{
//if (decompositionConstraint::debug)
//{
// Info<< type() << " : found refinementHistory" << endl;
//}
refPtr = &mesh.lookupObject<refinementHistory>("refinementHistory");
}
else
{
//if (decompositionConstraint::debug)
//{
// Info<< type() << " : reading refinementHistory from time "
// << mesh.facesInstance() << endl;
//}
storagePtr.reset
(
new refinementHistory

View File

@ -808,7 +808,7 @@ Foam::distributedTriSurfaceMesh::independentlyDistributedBbs
// here since we've only got Time and not a mesh.
const auto* dictPtr =
searchableSurface::time().lookupObjectPtr<IOdictionary>
searchableSurface::time().findObject<IOdictionary>
(
// == decompositionModel::canonicalName
"decomposeParDict"
@ -1914,13 +1914,11 @@ void Foam::distributedTriSurfaceMesh::getField
return;
}
if (foundObject<triSurfaceLabelField>("values"))
{
const triSurfaceLabelField& fld = lookupObject<triSurfaceLabelField>
(
"values"
);
const auto* fldPtr = findObject<triSurfaceLabelField>("values");
if (fldPtr)
{
const triSurfaceLabelField& fld = *fldPtr;
// Get query data (= local index of triangle)
// ~~~~~~~~~~~~~~

View File

@ -67,22 +67,18 @@ void Foam::energyRegionCoupledFvPatchScalarField::setMethod() const
if (!nbrThermoPtr_)
{
nbrThermoPtr_ =
(
&regionCoupledPatch_.nbrMesh().lookupObject<basicThermo>
regionCoupledPatch_.nbrMesh().findObject<basicThermo>
(
basicThermo::dictName
)
);
}
if (!thermoPtr_)
{
thermoPtr_ =
(
&this->db().lookupObject<basicThermo>
this->db().findObject<basicThermo>
(
basicThermo::dictName
)
);
}
}

View File

@ -123,35 +123,37 @@ void Foam::filmPyrolysisTemperatureCoupledFvPatchScalarField::updateCoeffs()
return;
}
typedef regionModels::surfaceFilmModels::surfaceFilmRegionModel
filmModelType;
// Film model
const auto* filmModelPtr = db().time().findObject
<regionModels::surfaceFilmModels::surfaceFilmRegionModel>
(filmRegionName_);
// Pyrolysis model
const auto* pyrModelPtr = db().time().findObject
<regionModels::pyrolysisModels::pyrolysisModel>
(pyrolysisRegionName_);
if (!filmModelPtr || !pyrModelPtr)
{
// Do nothing on construction - film model doesn't exist yet
return;
}
const auto& filmModel = *filmModelPtr;
const auto& pyrModel = *pyrModelPtr;
typedef regionModels::pyrolysisModels::pyrolysisModel pyrModelType;
// Since we're inside initEvaluate/evaluate there might be processor
// comms underway. Change the tag we use.
int oldTag = UPstream::msgType();
UPstream::msgType() = oldTag+1;
bool filmOk = db().time().foundObject<filmModelType>(filmRegionName_);
bool pyrOk = db().time().foundObject<pyrModelType>(pyrolysisRegionName_);
if (!filmOk || !pyrOk)
{
// Do nothing on construction - film model doesn't exist yet
return;
}
scalarField& Tp = *this;
const label patchi = patch().index();
// Retrieve film model
const filmModelType& filmModel =
db().time().lookupObject<filmModelType>(filmRegionName_);
// The film model
const label filmPatchi = filmModel.regionPatchID(patchi);
scalarField alphaFilm = filmModel.alpha().boundaryField()[filmPatchi];
@ -160,10 +162,7 @@ void Foam::filmPyrolysisTemperatureCoupledFvPatchScalarField::updateCoeffs()
scalarField TFilm = filmModel.Ts().boundaryField()[filmPatchi];
filmModel.toPrimary(filmPatchi, TFilm);
// Retrieve pyrolysis model
const pyrModelType& pyrModel =
db().time().lookupObject<pyrModelType>(pyrolysisRegionName_);
// The pyrolysis model
const label pyrPatchi = pyrModel.regionPatchID(patchi);
scalarField TPyr = pyrModel.T().boundaryField()[pyrPatchi];

View File

@ -123,35 +123,38 @@ void Foam::filmPyrolysisVelocityCoupledFvPatchVectorField::updateCoeffs()
return;
}
typedef regionModels::surfaceFilmModels::surfaceFilmRegionModel
filmModelType;
// Film model
const auto* filmModelPtr = db().time().findObject
<regionModels::surfaceFilmModels::surfaceFilmRegionModel>
(filmRegionName_);
// Pyrolysis model
const auto* pyrModelPtr = db().time().findObject
<regionModels::pyrolysisModels::pyrolysisModel>
(pyrolysisRegionName_);
if (!filmModelPtr || !pyrModelPtr)
{
// Do nothing on construction - film model doesn't exist yet
return;
}
const auto& filmModel = *filmModelPtr;
const auto& pyrModel = *pyrModelPtr;
typedef regionModels::pyrolysisModels::pyrolysisModel pyrModelType;
// Since we're inside initEvaluate/evaluate there might be processor
// comms underway. Change the tag we use.
int oldTag = UPstream::msgType();
UPstream::msgType() = oldTag+1;
bool foundFilm = db().time().foundObject<filmModelType>(filmRegionName_);
bool foundPyrolysis =
db().time().foundObject<pyrModelType>(pyrolysisRegionName_);
if (!foundFilm || !foundPyrolysis)
{
// Do nothing on construction - film model doesn't exist yet
return;
}
vectorField& Up = *this;
const label patchi = patch().index();
// Retrieve film model
const filmModelType& filmModel =
db().time().lookupObject<filmModelType>(filmRegionName_);
// The film model
const label filmPatchi = filmModel.regionPatchID(patchi);
scalarField alphaFilm = filmModel.alpha().boundaryField()[filmPatchi];
@ -160,10 +163,7 @@ void Foam::filmPyrolysisVelocityCoupledFvPatchVectorField::updateCoeffs()
vectorField UFilm = filmModel.Us().boundaryField()[filmPatchi];
filmModel.toPrimary(filmPatchi, UFilm);
// Retrieve pyrolysis model
const pyrModelType& pyrModel =
db().time().lookupObject<pyrModelType>(pyrolysisRegionName_);
// The pyrolysis model
const label pyrPatchi = pyrModel.regionPatchID(patchi);
scalarField phiPyr = pyrModel.phiGas().boundaryField()[pyrPatchi];

View File

@ -60,9 +60,11 @@ inline const Foam::word& Foam::regionModels::regionModel::modelName() const
inline const Foam::fvMesh& Foam::regionModels::regionModel::regionMesh() const
{
if (time_.foundObject<fvMesh>(regionName_))
const fvMesh* regionPtr = time_.findObject<fvMesh>(regionName_);
if (regionPtr)
{
return time_.lookupObject<fvMesh>(regionName_);
return *regionPtr;
}
else if (!regionMeshPtr_.valid())
{
@ -76,12 +78,11 @@ inline const Foam::fvMesh& Foam::regionModels::regionModel::regionMesh() const
inline Foam::fvMesh& Foam::regionModels::regionModel::regionMesh()
{
if (time_.foundObject<fvMesh>(regionName_))
fvMesh* regionPtr = time_.getObjectPtr<fvMesh>(regionName_);
if (regionPtr)
{
return const_cast<fvMesh&>
(
time_.lookupObject<fvMesh>(regionName_)
);
return *regionPtr;
}
else if (!regionMeshPtr_.valid())
{

View File

@ -87,15 +87,7 @@ Foam::regionModels::regionModel::mapRegionPatchField
{
const polyPatch& p = regionMesh().boundaryMesh()[regionPatchi];
return
tmp<Field<Type>>
(
new Field<Type>
(
p.size(),
Zero
)
);
return tmp<Field<Type>>::New(p.size(), Zero);
}
}
@ -143,15 +135,7 @@ Foam::regionModels::regionModel::mapRegionPatchInternalField
{
const polyPatch& p = regionMesh().boundaryMesh()[regionPatchi];
return
tmp<Field<Type>>
(
new Field<Type>
(
p.size(),
Zero
)
);
return tmp<Field<Type>>::New(p.size(), Zero);
}
}

View File

@ -142,27 +142,27 @@ void alphatFilmWallFunctionFvPatchScalarField::updateCoeffs()
return;
}
typedef regionModels::surfaceFilmModels::surfaceFilmRegionModel modelType;
const auto* filmModelPtr = db().time().findObject
<regionModels::surfaceFilmModels::surfaceFilmRegionModel>
(filmRegionName_);
if (!filmModelPtr)
{
// Do nothing on construction - film model doesn't exist yet
return;
}
const auto& filmModel = *filmModelPtr;
// Since we're inside initEvaluate/evaluate there might be processor
// comms underway. Change the tag we use.
int oldTag = UPstream::msgType();
UPstream::msgType() = oldTag+1;
bool foundFilm = db().time().foundObject<modelType>(filmRegionName_);
if (!foundFilm)
{
// Do nothing on construction - film model doesn't exist yet
return;
}
const label patchi = patch().index();
// Retrieve phase change mass from surface film model
const modelType& filmModel =
db().time().lookupObject<modelType>(filmRegionName_);
const label filmPatchi = filmModel.regionPatchID(patchi);
tmp<volScalarField> mDotFilm(filmModel.primaryMassTrans());

View File

@ -48,14 +48,14 @@ tmp<scalarField> nutkFilmWallFunctionFvPatchScalarField::calcUTau
const scalarField& magGradU
) const
{
tmp<scalarField> tuTau(new scalarField(patch().size(), 0.0));
tmp<scalarField> tuTau(new scalarField(patch().size(), Zero));
scalarField& uTau = tuTau.ref();
typedef regionModels::surfaceFilmModels::surfaceFilmRegionModel modelType;
const auto* filmModelPtr = db().time().findObject
<regionModels::surfaceFilmModels::surfaceFilmRegionModel>
(filmRegionName_);
bool foundFilm = db().time().foundObject<modelType>(filmRegionName_);
if (!foundFilm)
if (!filmModelPtr)
{
// Do nothing on construction - film model doesn't exist yet
return tuTau;
@ -64,8 +64,7 @@ tmp<scalarField> nutkFilmWallFunctionFvPatchScalarField::calcUTau
const label patchi = patch().index();
// Retrieve phase change mass from surface film model
const modelType& filmModel =
db().time().lookupObject<modelType>(filmRegionName_);
const auto& filmModel = *filmModelPtr;
const label filmPatchi = filmModel.regionPatchID(patchi);

View File

@ -78,19 +78,23 @@ void liquidFilmThermo::initLiquid(const dictionary& dict)
dict.readEntry("liquid", name_);
if (filmModel_.primaryMesh().foundObject<SLGThermo>("SLGThermo"))
const SLGThermo* thermoPtr =
filmModel_.primaryMesh().findObject<SLGThermo>("SLGThermo");
if (thermoPtr)
{
// retrieve from film thermo
// Retrieve from film thermo
ownLiquid_ = false;
const SLGThermo& thermo =
filmModel_.primaryMesh().lookupObject<SLGThermo>("SLGThermo");
label id = thermo.liquidId(name_);
const SLGThermo& thermo = *thermoPtr;
const label id = thermo.liquidId(name_);
liquidPtr_ = &thermo.liquids().properties()[id];
}
else
{
// new liquid create
// New liquid create
ownLiquid_ = true;
liquidPtr_ =

View File

@ -52,27 +52,22 @@ void Foam::sampledIsoSurface::getIsoFields() const
// Get volField
// ~~~~~~~~~~~~
if (fvm.foundObject<volScalarField>(isoField_))
volFieldPtr_ = fvm.getObjectPtr<volScalarField>(isoField_);
if (volFieldPtr_)
{
if (debug)
{
InfoInFunction
DebugInFunction
<< "Lookup volField " << isoField_ << endl;
}
storedVolFieldPtr_.clear();
volFieldPtr_ = &fvm.lookupObject<volScalarField>(isoField_);
}
else
{
// Bit of a hack. Read field and store.
if (debug)
{
InfoInFunction
DebugInFunction
<< "Checking " << isoField_
<< " for same time " << fvm.time().timeName()
<< endl;
}
<< " for same time " << fvm.time().timeName() << endl;
if
(
@ -80,13 +75,9 @@ void Foam::sampledIsoSurface::getIsoFields() const
|| (fvm.time().timeName() != storedVolFieldPtr_().instance())
)
{
if (debug)
{
InfoInFunction
DebugInFunction
<< "Reading volField " << isoField_
<< " from time " << fvm.time().timeName()
<< endl;
}
<< " from time " << fvm.time().timeName() << endl;
IOobject vfHeader
(
@ -141,61 +132,45 @@ void Foam::sampledIsoSurface::getIsoFields() const
+ isoField_
+ ')';
if (fvm.foundObject<pointScalarField>(pointFldName))
{
if (debug)
{
InfoInFunction
<< "lookup pointField " << pointFldName << endl;
}
const pointScalarField& pfld = fvm.lookupObject<pointScalarField>
(
pointFldName
);
if (!pfld.upToDate(*volFieldPtr_))
pointFieldPtr_ = fvm.getObjectPtr<pointScalarField>(pointFldName);
if (pointFieldPtr_)
{
if (debug)
DebugInFunction
<< "lookup pointField " << pointFldName << endl;
if (!pointFieldPtr_->upToDate(*volFieldPtr_))
{
InfoInFunction
<< "updating pointField "
<< pointFldName << endl;
}
DebugInFunction
<< "updating pointField " << pointFldName << endl;
// Update the interpolated value
volPointInterpolation::New(fvm).interpolate
(
*volFieldPtr_,
const_cast<pointScalarField&>(pfld)
const_cast<pointScalarField&>(*pointFieldPtr_)
);
}
pointFieldPtr_ = &pfld;
}
else
{
// Not in registry. Interpolate.
if (debug)
{
InfoInFunction
<< "Checking pointField " << pointFldName
<< " for same time " << fvm.time().timeName()
<< endl;
}
DebugInFunction
<< "creating pointField " << pointFldName << endl;
// Interpolate without cache. Note that we're registering it
// below so next time round it goes into the condition
// above.
tmp<pointScalarField> tpfld
(
pointFieldPtr_ =
volPointInterpolation::New(fvm).interpolate
(
*volFieldPtr_,
pointFldName,
false
)
);
pointFieldPtr_ = tpfld.ptr();
).ptr();
const_cast<pointScalarField*>(pointFieldPtr_)->store();
}
@ -212,18 +187,14 @@ void Foam::sampledIsoSurface::getIsoFields() const
}
if (debug)
{
InfoInFunction
DebugInFunction
<< "volField " << volFieldPtr_->name()
<< " min:" << min(*volFieldPtr_).value()
<< " max:" << max(*volFieldPtr_).value() << endl;
InfoInFunction
<< " max:" << max(*volFieldPtr_).value() << nl
<< "pointField " << pointFieldPtr_->name()
<< " min:" << gMin(pointFieldPtr_->primitiveField())
<< " max:" << gMax(pointFieldPtr_->primitiveField()) << endl;
}
}
else
{
// Get subMesh variants
@ -231,24 +202,20 @@ void Foam::sampledIsoSurface::getIsoFields() const
// Either lookup on the submesh or subset the whole-mesh volField
if (subFvm.foundObject<volScalarField>(isoField_))
volSubFieldPtr_ = subFvm.getObjectPtr<volScalarField>(isoField_);
if (volSubFieldPtr_)
{
if (debug)
{
InfoInFunction
<< "Sub-mesh lookup volField "
<< isoField_ << endl;
}
DebugInFunction
<< "Sub-mesh lookup volField " << isoField_ << endl;
storedVolSubFieldPtr_.clear();
volSubFieldPtr_ = &subFvm.lookupObject<volScalarField>(isoField_);
}
else
{
if (debug)
{
InfoInFunction
DebugInFunction
<< "Sub-setting volField " << isoField_ << endl;
}
storedVolSubFieldPtr_.reset
(
subMeshPtr_().interpolate
@ -270,53 +237,40 @@ void Foam::sampledIsoSurface::getIsoFields() const
+ volSubFieldPtr_->name()
+ ')';
if (subFvm.foundObject<pointScalarField>(pointFldName))
{
if (debug)
{
InfoInFunction
<< "Sub-mesh lookup pointField " << pointFldName << endl;
}
const pointScalarField& pfld = subFvm.lookupObject<pointScalarField>
(
pointFldName
);
if (!pfld.upToDate(*volSubFieldPtr_))
pointFieldPtr_ = subFvm.getObjectPtr<pointScalarField>(pointFldName);
if (pointFieldPtr_)
{
if (debug)
DebugInFunction
<< "Sub-mesh lookup pointField " << pointFldName << endl;
if (!pointFieldPtr_->upToDate(*volSubFieldPtr_))
{
Info<< "sampledIsoSurface::getIsoFields() :"
<< " updating submesh pointField "
<< pointFldName << endl;
}
DebugInFunction
<< "Updating submesh pointField " << pointFldName << endl;
// Update the interpolated value
volPointInterpolation::New(subFvm).interpolate
(
*volSubFieldPtr_,
const_cast<pointScalarField&>(pfld)
const_cast<pointScalarField&>(*pointFieldPtr_)
);
}
pointFieldPtr_ = &pfld;
}
else
{
if (debug)
{
InfoInFunction
DebugInFunction
<< "Interpolating submesh volField "
<< volSubFieldPtr_->name()
<< " to get submesh pointField " << pointFldName << endl;
}
tmp<pointScalarField> tpfld
(
pointSubFieldPtr_ =
volPointInterpolation::New
(
subFvm
).interpolate(*volSubFieldPtr_)
);
pointSubFieldPtr_ = tpfld.ptr();
).interpolate(*volSubFieldPtr_).ptr();
const_cast<pointScalarField*>(pointSubFieldPtr_)->store();
}
@ -333,20 +287,16 @@ void Foam::sampledIsoSurface::getIsoFields() const
}
if (debug)
{
InfoInFunction
DebugInFunction
<< "volSubField "
<< volSubFieldPtr_->name()
<< " min:" << min(*volSubFieldPtr_).value()
<< " max:" << max(*volSubFieldPtr_).value() << endl;
InfoInFunction
<< " max:" << max(*volSubFieldPtr_).value() << nl
<< "pointSubField "
<< pointSubFieldPtr_->name()
<< " min:" << gMin(pointSubFieldPtr_->primitiveField())
<< " max:" << gMax(pointSubFieldPtr_->primitiveField()) << endl;
}
}
}

View File

@ -64,7 +64,7 @@ bool Foam::sampledIsoSurfaceCell::updateGeometry() const
// Use field from database, or try to read it in
const auto* cellFldPtr = fvm.lookupObjectPtr<volScalarField>(isoField_);
const auto* cellFldPtr = fvm.findObject<volScalarField>(isoField_);
if (debug)
{

View File

@ -61,7 +61,7 @@ bool Foam::sampledThresholdCellFaces::updateGeometry() const
// Use volField from database, or try to read it in
const auto* cellFldPtr = fvm.lookupObjectPtr<volScalarField>(fieldName_);
const auto* cellFldPtr = fvm.findObject<volScalarField>(fieldName_);
if (debug)
{

View File

@ -53,7 +53,7 @@ bool Foam::surfMeshSampleDistanceSurface::sampleType
{
typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
const auto* volFldPtr = mesh().lookupObjectPtr<VolFieldType>(fieldName);
const auto* volFldPtr = mesh().findObject<VolFieldType>(fieldName);
if (!volFldPtr)
{

View File

@ -53,7 +53,7 @@ bool Foam::surfMeshSamplePlane::sampleType
{
typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
const auto* volFldPtr = mesh().lookupObjectPtr<VolFieldType>(fieldName);
const auto* volFldPtr = mesh().findObject<VolFieldType>(fieldName);
if (!volFldPtr)
{

View File

@ -76,7 +76,7 @@ Foam::surfMeshSample::getOrCreateSurfField
const surfMesh& surf = surface();
const word& fieldName = vField.name();
SurfFieldType* ptr = surf.lookupObjectRefPtr<SurfFieldType>(fieldName);
SurfFieldType* ptr = surf.getObjectPtr<SurfFieldType>(fieldName);
if (!ptr)
{
ptr = new SurfFieldType

View File

@ -109,7 +109,7 @@ bool Foam::surfMeshSamplers::add_rhoU(const word& derivedName)
// rhoU = rho * U
const auto* rhoPtr = mesh_.lookupObjectPtr<volScalarField>("rho");
const auto* rhoPtr = mesh_.findObject<volScalarField>("rho");
const volVectorField& U = mesh_.lookupObject<volVectorField>("U");
tmp<volVectorField> tresult;
@ -152,7 +152,7 @@ bool Foam::surfMeshSamplers::add_pTotal(const word& derivedName)
// pTotal = p + rho * U^2 / 2
const auto* rhoPtr = mesh_.lookupObjectPtr<volScalarField>("rho");
const auto* rhoPtr = mesh_.findObject<volScalarField>("rho");
const volScalarField& p = mesh_.lookupObject<volScalarField>("p");
const volVectorField& U = mesh_.lookupObject<volVectorField>("U");

View File

@ -60,7 +60,7 @@ bool Foam::surfMeshSampleDiscrete::sampleType
typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
const auto* volFldPtr =
SurfaceSource::mesh().lookupObjectPtr<VolFieldType>(fieldName);
SurfaceSource::mesh().findObject<VolFieldType>(fieldName);
if (!volFldPtr)
{

View File

@ -40,7 +40,7 @@ bool Foam::discreteSurface::sampleType
typedef DimensionedField<Type, surfGeoMesh> SurfFieldType;
typedef IOField<Type> TmpFieldType;
const auto* volFldPtr = mesh().lookupObjectPtr<VolFieldType>(fieldName);
const auto* volFldPtr = mesh().findObject<VolFieldType>(fieldName);
if (!volFldPtr)
{
@ -57,7 +57,7 @@ bool Foam::discreteSurface::sampleType
{
const surfMesh& surf = dynamicCast<const surfMesh>(obr);
SurfFieldType* ptr = surf.lookupObjectRefPtr<SurfFieldType>(fieldName);
SurfFieldType* ptr = surf.getObjectPtr<SurfFieldType>(fieldName);
if (!ptr)
{
// Doesn't exist or the wrong type
@ -83,7 +83,7 @@ bool Foam::discreteSurface::sampleType
}
else
{
TmpFieldType* ptr = obr.lookupObjectRefPtr<TmpFieldType>(fieldName);
TmpFieldType* ptr = obr.getObjectPtr<TmpFieldType>(fieldName);
if (!ptr)
{
// Doesn't exist or the wrong type
@ -121,7 +121,7 @@ Foam::discreteSurface::sampleType
{
typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
const auto* volFldPtr = mesh().lookupObjectPtr<VolFieldType>(fieldName);
const auto* volFldPtr = mesh().findObject<VolFieldType>(fieldName);
if (volFldPtr)
{

View File

@ -147,7 +147,7 @@ bool Foam::fileFormats::VTKsurfaceFormat<Face>::read
for (auto fieldName : { "region", "STLSolidLabeling" })
{
const labelIOField* lptr =
reader.cellData().lookupObjectPtr<labelIOField>(fieldName);
reader.cellData().findObject<labelIOField>(fieldName);
if (lptr)
{
@ -160,7 +160,7 @@ bool Foam::fileFormats::VTKsurfaceFormat<Face>::read
}
const scalarIOField* sptr =
reader.cellData().lookupObjectPtr<scalarIOField>(fieldName);
reader.cellData().findObject<scalarIOField>(fieldName);
if (sptr)
{

View File

@ -130,16 +130,14 @@ Foam::volScalarField& Foam::basicThermo::lookupOrConstruct
bool& isOwner
)
{
const volScalarField* p =
mesh.objectRegistry::lookupObjectPtr<volScalarField>(name);
volScalarField* ptr =
mesh.objectRegistry::getObjectPtr<volScalarField>(name);
isOwner = !p;
isOwner = !ptr;
if (!p)
if (!ptr)
{
volScalarField* fPtr
(
new volScalarField
ptr = new volScalarField
(
IOobject
(
@ -150,17 +148,13 @@ Foam::volScalarField& Foam::basicThermo::lookupOrConstruct
IOobject::AUTO_WRITE
),
mesh
)
);
// Transfer ownership of this object to the objectRegistry
fPtr->store(fPtr);
return *fPtr;
}
else
{
return const_cast<volScalarField&>(*p);
ptr->store(ptr);
}
return *ptr;
}
@ -341,21 +335,17 @@ const Foam::basicThermo& Foam::basicThermo::lookupThermo
const fvPatchScalarField& pf
)
{
if (pf.db().foundObject<basicThermo>(dictName))
const basicThermo* thermo = pf.db().findObject<basicThermo>(dictName);
if (thermo)
{
return pf.db().lookupObject<basicThermo>(dictName);
return *thermo;
}
else
{
HashTable<const basicThermo*> thermos =
pf.db().lookupClass<basicThermo>();
for
(
HashTable<const basicThermo*>::iterator iter = thermos.begin();
iter != thermos.end();
++iter
)
forAllConstIters(thermos, iter)
{
if
(
@ -366,7 +356,6 @@ const Foam::basicThermo& Foam::basicThermo::lookupThermo
return *iter();
}
}
}
return pf.db().lookupObject<basicThermo>(dictName);
}

View File

@ -118,58 +118,53 @@ Foam::radiation::greyMeanAbsorptionEmission::greyMeanAbsorptionEmission
// look-up table and save the corresponding indices of the look-up table
label j = 0;
forAllConstIter(HashTable<label>, speciesNames_, iter)
forAllConstIters(speciesNames_, iter)
{
const word& specieName = iter.key();
const label index = iter.object();
volScalarField* fldPtr = mesh.getObjectPtr<volScalarField>(specieName);
if (!lookUpTablePtr_.empty())
{
if (lookUpTablePtr_().found(iter.key()))
if (lookUpTablePtr_().found(specieName))
{
label index = lookUpTablePtr_().findFieldIndex(iter.key());
const label fieldIndex =
lookUpTablePtr_().findFieldIndex(specieName);
Info<< "specie: " << iter.key() << " found on look-up table "
<< " with index: " << index << endl;
Info<< "specie: " << specieName << " found on look-up table "
<< " with index: " << fieldIndex << endl;
specieIndex_[iter()] = index;
specieIndex_[index] = fieldIndex;
}
else if (mesh.foundObject<volScalarField>(iter.key()))
else if (fldPtr)
{
volScalarField& Y =
const_cast<volScalarField&>
(
mesh.lookupObject<volScalarField>(iter.key())
);
Yj_.set(j, &Y);
specieIndex_[iter()] = 0;
Yj_.set(j, fldPtr);
specieIndex_[index] = 0;
j++;
Info<< "specie: " << iter.key() << " is being solved" << endl;
}
else
{
FatalErrorInFunction
<< "specie: " << iter.key()
<< "specie: " << specieName
<< " is neither in look-up table: "
<< lookUpTablePtr_().tableName()
<< " nor is being solved" << nl
<< exit(FatalError);
}
}
else if (mesh.foundObject<volScalarField>(iter.key()))
else if (fldPtr)
{
volScalarField& Y =
const_cast<volScalarField&>
(
mesh.lookupObject<volScalarField>(iter.key())
);
Yj_.set(j, &Y);
specieIndex_[iter()] = 0;
Yj_.set(j, fldPtr);
specieIndex_[index] = 0;
j++;
}
else
{
FatalErrorInFunction
<< " there is not lookup table and the specie" << nl
<< iter.key() << nl
<< "There is no lookup table and the specie" << nl
<< specieName << nl
<< " is not found " << nl
<< exit(FatalError);
}
@ -292,10 +287,11 @@ Foam::radiation::greyMeanAbsorptionEmission::ECont(const label bandI) const
)
);
if (mesh_.foundObject<volScalarField>("Qdot"))
const volScalarField* QdotPtr = mesh_.findObject<volScalarField>("Qdot");
if (QdotPtr)
{
const volScalarField& Qdot =
mesh_.lookupObject<volScalarField>("Qdot");
const volScalarField& Qdot = *QdotPtr;
if (Qdot.dimensions() == dimEnergy/dimTime)
{

View File

@ -132,48 +132,53 @@ Foam::radiation::wideBandAbsorptionEmission::wideBandAbsorptionEmission
// look-up table and save the corresponding indices of the look-up table
label j = 0;
forAllConstIter(HashTable<label>, speciesNames_, iter)
forAllConstIters(speciesNames_, iter)
{
const word& specieName = iter.key();
const label index = iter.object();
volScalarField* fldPtr = mesh.getObjectPtr<volScalarField>(specieName);
if (!lookUpTablePtr_.empty())
{
if (lookUpTablePtr_().found(iter.key()))
if (lookUpTablePtr_().found(specieName))
{
const label index =
lookUpTablePtr_().findFieldIndex(iter.key());
const label fieldIndex =
lookUpTablePtr_().findFieldIndex(specieName);
Info<< "specie: " << iter.key() << " found on look-up table "
<< " with index: " << index << endl;
Info<< "specie: " << specieName << " found on look-up table "
<< " with index: " << fieldIndex << endl;
specieIndex_[iter()] = index;
specieIndex_[index] = fieldIndex;
}
else if (mesh.foundObject<volScalarField>(iter.key()))
else if (fldPtr)
{
Yj_.set(j, &mesh.lookupObjectRef<volScalarField>(iter.key()));
specieIndex_[iter()] = 0;
Yj_.set(j, fldPtr);
specieIndex_[index] = 0;
j++;
Info<< "specie: " << iter.key() << " is being solved" << endl;
Info<< "specie: " << specieName << " is being solved" << endl;
}
else
{
FatalErrorInFunction
<< "specie: " << iter.key()
<< "specie: " << specieName
<< " is neither in look-up table: "
<< lookUpTablePtr_().tableName()
<< " nor is being solved" << nl
<< exit(FatalError);
}
}
else if (mesh.foundObject<volScalarField>(iter.key()))
else if (fldPtr)
{
Yj_.set(j, &mesh.lookupObjectRef<volScalarField>(iter.key()));
specieIndex_[iter()] = 0;
Yj_.set(j, fldPtr);
specieIndex_[index] = 0;
j++;
}
else
{
FatalErrorInFunction
<< " there is no lookup table and the specie" << nl
<< iter.key() << nl
<< "There is no lookup table and the specie" << nl
<< specieName << nl
<< " is not found " << nl
<< exit(FatalError);
@ -300,10 +305,11 @@ Foam::radiation::wideBandAbsorptionEmission::ECont(const label bandi) const
)
);
if (mesh().foundObject<volScalarField>("Qdot"))
const volScalarField* QdotPtr = mesh().findObject<volScalarField>("Qdot");
if (QdotPtr)
{
const volScalarField& Qdot =
mesh().lookupObject<volScalarField>("Qdot");
const volScalarField& Qdot = *QdotPtr;
if (Qdot.dimensions() == dimEnergy/dimTime)
{

View File

@ -64,12 +64,12 @@ Foam::moleFractions<ThermoType>::moleFractions
:
fvMeshFunctionObject(name, runTime, dict)
{
if (mesh_.foundObject<ThermoType>(basicThermo::dictName))
{
const ThermoType& thermo =
mesh_.lookupObject<ThermoType>(basicThermo::dictName);
const ThermoType* thermo =
mesh_.findObject<ThermoType>(basicThermo::dictName);
const PtrList<volScalarField>& Y = thermo.composition().Y();
if (thermo)
{
const PtrList<volScalarField>& Y = thermo->composition().Y();
X_.setSize(Y.size());

View File

@ -93,11 +93,11 @@ Foam::humidityTemperatureCoupledMixedFvPatchScalarField::thicknessField
const fvMesh& mesh
)
{
if (!mesh.foundObject<volScalarField>(fieldName))
volScalarField* ptr = mesh.getObjectPtr<volScalarField>(fieldName);
if (!ptr)
{
tmp<volScalarField> tField
(
new volScalarField
ptr = new volScalarField
(
IOobject
(
@ -109,17 +109,12 @@ Foam::humidityTemperatureCoupledMixedFvPatchScalarField::thicknessField
),
mesh,
dimensionedScalar(dimLength, Zero)
)
);
tField.ptr()->store();
ptr->store();
}
return
const_cast<volScalarField&>
(
mesh.lookupObject<volScalarField>(fieldName)
);
return *ptr;
}

View File

@ -141,11 +141,10 @@ bool Foam::rawTopoChangerFvMesh::update()
// Special handling for phi: set unmapped faces to recreated phi
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

@ -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
(

View File

@ -60,12 +60,11 @@ Foam::viscosityModels::Arrhenius<ViscousModel>::Arrhenius
fieldName_(ArrheniusCoeffs_.lookupOrDefault<word>("field","T")),
mesh_(U.mesh())
{
const volScalarField* fieldPtr =
mesh_.lookupObjectPtr<volScalarField>(fieldName_);
const auto* fldPtr = mesh_.findObject<volScalarField>(fieldName_);
if (fieldPtr)
if (fldPtr)
{
this->nu_ *= calcNu(*fieldPtr);
this->nu_ *= calcNu(*fldPtr);
}
}

View File

@ -113,12 +113,11 @@ public:
{
ViscousModel::correct();
const volScalarField* fieldPtr =
mesh_.lookupObjectPtr<volScalarField>(fieldName_);
const auto* fldPtr = mesh_.findObject<volScalarField>(fieldName_);
if (fieldPtr)
if (fldPtr)
{
this->nu_ *= calcNu(*fieldPtr);
this->nu_ *= calcNu(*fldPtr);
}
}

View File

@ -87,15 +87,16 @@ Foam::tmp<Foam::waveModel> Foam::waveModel::lookupOrCreate
{
const word modelName = waveModel::modelName(patch.name());
if (!mesh.foundObject<waveModel>(modelName))
waveModel* modelPtr = mesh.getObjectPtr<waveModel>(modelName);
if (!modelPtr)
{
autoPtr<waveModel> model(waveModel::New(waveDictName, mesh, patch));
waveModel* waveModelPtr = model.ptr();
waveModelPtr->store();
waveModelPtr->info(Info);
modelPtr = waveModel::New(waveDictName, mesh, patch).ptr();
modelPtr->store();
modelPtr->info(Info);
}
return mesh.lookupObject<waveModel>(modelName);
return *modelPtr;
}

View File

@ -38,8 +38,7 @@ functions
scalar gamma = 1.4;
scalar A = -0.3*D*UInf;
const dimensionedScalar rhoRef("rhoRef", dimDensity, 1);
const volScalarField& rho =
mesh().lookupObject<volScalarField>("rho");
const auto& rho = mesh().lookupObject<volScalarField>("rho");
const vectorField& C = mesh().C();
const scalarField x(C.component(0));
@ -47,19 +46,15 @@ functions
const scalar r2 = sqr(0.5*D/(Foam::sqrt(Foam::log(10.0))));
const scalarField Psi(A*exp(-0.5/r2*(sqr(x) + sqr(y))));
volVectorField* Uptr =
mesh().lookupObjectRefPtr<volVectorField>("U");
volScalarField* pPtr =
mesh().lookupObjectRefPtr<volScalarField>("p");
volScalarField* TPtr =
mesh().lookupObjectRefPtr<volScalarField>("T");
auto* Uptr = mesh().getObjectPtr<volVectorField>("U");
auto* pPtr = mesh().getObjectPtr<volScalarField>("p");
auto* TPtr = mesh().getObjectPtr<volScalarField>("T");
if (Uptr && pPtr && TPtr)
{
volVectorField& U = *Uptr;
volScalarField& p = *pPtr;
volScalarField& T = *TPtr;
auto& U = *Uptr;
auto& p = *pPtr;
auto& T = *TPtr;
vectorField& Uc = U.primitiveFieldRef();
Uc.replace(0, UInf - rhoRef/rho()*Psi/r2*y);