objectRegistry: Added lookupObjectRef to obtain non-const access to objects
Allows simplification of BCs, functionObjects etc. which manipulate objects which are transferred to and held by the objectRegistry.
This commit is contained in:
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2016-2017 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -70,11 +70,11 @@ bool Foam::functionObjects::regionFunctionObject::clearObject
|
||||
{
|
||||
if (foundObject<regIOobject>(fieldName))
|
||||
{
|
||||
const regIOobject& resultObject = lookupObject<regIOobject>(fieldName);
|
||||
regIOobject& resultObject = lookupObjectRef<regIOobject>(fieldName);
|
||||
|
||||
if (resultObject.ownedByRegistry())
|
||||
{
|
||||
return const_cast<regIOobject&>(resultObject).checkOut();
|
||||
return resultObject.checkOut();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2016-2017 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -78,10 +78,14 @@ protected:
|
||||
template<class ObjectType>
|
||||
bool foundObject(const word& fieldName) const;
|
||||
|
||||
//- Lookup field from the objectRegistry
|
||||
//- Lookup object from the objectRegistry
|
||||
template<class ObjectType>
|
||||
const ObjectType& lookupObject(const word& fieldName) const;
|
||||
|
||||
//- Lookup non-const object reference from the objectRegistry
|
||||
template<class ObjectType>
|
||||
ObjectType& lookupObjectRef(const word& fieldName);
|
||||
|
||||
//- Store the given field in the objectRegistry under the given name
|
||||
template<class ObjectType>
|
||||
bool store
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2016-2017 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -48,6 +48,16 @@ const ObjectType& Foam::functionObjects::regionFunctionObject::lookupObject
|
||||
}
|
||||
|
||||
|
||||
template<class ObjectType>
|
||||
ObjectType& Foam::functionObjects::regionFunctionObject::lookupObjectRef
|
||||
(
|
||||
const word& fieldName
|
||||
)
|
||||
{
|
||||
return obr_.lookupObjectRef<ObjectType>(fieldName);
|
||||
}
|
||||
|
||||
|
||||
template<class ObjectType>
|
||||
bool Foam::functionObjects::regionFunctionObject::store
|
||||
(
|
||||
@ -74,17 +84,14 @@ bool Foam::functionObjects::regionFunctionObject::store
|
||||
&& obr_.foundObject<ObjectType>(fieldName)
|
||||
)
|
||||
{
|
||||
const ObjectType& field =
|
||||
(
|
||||
obr_.lookupObject<ObjectType>(fieldName)
|
||||
);
|
||||
ObjectType& field = obr_.lookupObjectRef<ObjectType>(fieldName);
|
||||
|
||||
// If there is a result field already registered assign to the new
|
||||
// result field otherwise transfer ownership of the new result field to
|
||||
// the object registry
|
||||
if (&field != &tfield())
|
||||
{
|
||||
const_cast<ObjectType&>(field) = tfield;
|
||||
field = tfield;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -180,6 +180,10 @@ public:
|
||||
template<class Type>
|
||||
const Type& lookupObject(const word& name) const;
|
||||
|
||||
//- Lookup and return the object reference of the given Type
|
||||
template<class Type>
|
||||
Type& lookupObjectRef(const word& name) const;
|
||||
|
||||
//- Return new event number.
|
||||
label getEvent() const;
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -204,4 +204,11 @@ const Type& Foam::objectRegistry::lookupObject(const word& name) const
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
Type& Foam::objectRegistry::lookupObjectRef(const word& name) const
|
||||
{
|
||||
return const_cast<Type&>(lookupObject<Type>(name));
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -119,14 +119,11 @@ void Foam::freestreamPressureFvPatchScalarField::updateCoeffs()
|
||||
patch().lookupPatchField<volVectorField, vector>(UName_)
|
||||
);
|
||||
|
||||
const surfaceScalarField& phi =
|
||||
db().lookupObject<surfaceScalarField>(phiName_);
|
||||
surfaceScalarField& phi =
|
||||
db().lookupObjectRef<surfaceScalarField>(phiName_);
|
||||
|
||||
fvsPatchField<scalar>& phip =
|
||||
const_cast<fvsPatchField<scalar>&>
|
||||
(
|
||||
patch().patchField<surfaceScalarField, scalar>(phi)
|
||||
);
|
||||
patch().patchField<surfaceScalarField, scalar>(phi);
|
||||
|
||||
if (phi.dimensions() == dimVelocity*dimArea)
|
||||
{
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -156,8 +156,8 @@ void Foam::mappedVelocityFluxFixedValueFvPatchField::updateCoeffs()
|
||||
const volVectorField& UField =
|
||||
nbrMesh.lookupObject<volVectorField>(fieldName);
|
||||
|
||||
const surfaceScalarField& phiField =
|
||||
nbrMesh.lookupObject<surfaceScalarField>(phiName_);
|
||||
surfaceScalarField& phiField =
|
||||
nbrMesh.lookupObjectRef<surfaceScalarField>(phiName_);
|
||||
|
||||
vectorField newUValues;
|
||||
scalarField newPhiValues;
|
||||
@ -215,10 +215,7 @@ void Foam::mappedVelocityFluxFixedValueFvPatchField::updateCoeffs()
|
||||
}
|
||||
|
||||
operator==(newUValues);
|
||||
const_cast<surfaceScalarField&>
|
||||
(
|
||||
phiField
|
||||
).boundaryFieldRef()[patch().index()] == newPhiValues;
|
||||
phiField.boundaryFieldRef()[patch().index()] == newPhiValues;
|
||||
|
||||
// Restore tag
|
||||
UPstream::msgType() = oldTag;
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -145,26 +145,22 @@ void Foam::waveSurfacePressureFvPatchScalarField::updateCoeffs()
|
||||
|
||||
const scalar dt = db().time().deltaTValue();
|
||||
|
||||
// retrieve non-const access to zeta field from the database
|
||||
volVectorField& zeta =
|
||||
const_cast<volVectorField&>
|
||||
(
|
||||
db().lookupObject<volVectorField>(zetaName_)
|
||||
);
|
||||
// Retrieve non-const access to zeta field from the database
|
||||
volVectorField& zeta = db().lookupObjectRef<volVectorField>(zetaName_);
|
||||
vectorField& zetap = zeta.boundaryFieldRef()[patchi];
|
||||
|
||||
// lookup d/dt scheme from database for zeta
|
||||
// Lookup d/dt scheme from database for zeta
|
||||
const word ddtSchemeName(zeta.mesh().ddtScheme(zeta.name()));
|
||||
ddtSchemeType ddtScheme(ddtSchemeTypeNames_[ddtSchemeName]);
|
||||
|
||||
// retrieve the flux field from the database
|
||||
// Retrieve the flux field from the database
|
||||
const surfaceScalarField& phi =
|
||||
db().lookupObject<surfaceScalarField>(phiName_);
|
||||
|
||||
// cache the patch face-normal vectors
|
||||
// Cache the patch face-normal vectors
|
||||
tmp<vectorField> nf(patch().nf());
|
||||
|
||||
// change in zeta due to flux
|
||||
// Change in zeta due to flux
|
||||
vectorField dZetap(dt*nf()*phi.boundaryField()[patchi]/patch().magSf());
|
||||
|
||||
if (phi.dimensions() == dimDensity*dimVelocity*dimArea)
|
||||
@ -218,7 +214,7 @@ void Foam::waveSurfacePressureFvPatchScalarField::updateCoeffs()
|
||||
Info<< "min/max zetap = " << gMin(zetap & nf()) << ", "
|
||||
<< gMax(zetap & nf()) << endl;
|
||||
|
||||
// update the surface pressure
|
||||
// Update the surface pressure
|
||||
const uniformDimensionedVectorField& g =
|
||||
db().lookupObject<uniformDimensionedVectorField>("g");
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -250,6 +250,13 @@ public:
|
||||
const GeometricField&
|
||||
) const;
|
||||
|
||||
//- Return the corresponding patchField reference of the named field
|
||||
template<class GeometricField, class Type>
|
||||
typename GeometricField::Patch& patchField
|
||||
(
|
||||
GeometricField&
|
||||
) const;
|
||||
|
||||
//- Lookup and return the patchField of the named field from the
|
||||
// local objectRegistry.
|
||||
// N.B. The dummy pointer arguments are used if this function is
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -75,4 +75,14 @@ const typename GeometricField::Patch& Foam::fvPatch::patchField
|
||||
}
|
||||
|
||||
|
||||
template<class GeometricField, class Type>
|
||||
typename GeometricField::Patch& Foam::fvPatch::patchField
|
||||
(
|
||||
GeometricField& gf
|
||||
) const
|
||||
{
|
||||
return gf.boundaryFieldRef()[index()];
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
Reference in New Issue
Block a user