mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: initial support for handling subRegions in regionFunctionObject
- propagate updated objectRegistry methods (eg, lookupObjectRef etc) into regionFunctionObject
This commit is contained in:
@ -3,7 +3,7 @@
|
|||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -40,19 +40,46 @@ namespace functionObjects
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
|
// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
|
||||||
|
|
||||||
|
const Foam::objectRegistry&
|
||||||
|
Foam::functionObjects::regionFunctionObject::whichSubRegistry
|
||||||
|
(
|
||||||
|
const objectRegistry& obr,
|
||||||
|
const dictionary& dict
|
||||||
|
)
|
||||||
|
{
|
||||||
|
word subName;
|
||||||
|
if (dict.readIfPresent("subRegion", subName))
|
||||||
|
{
|
||||||
|
return obr.lookupObject<objectRegistry>(subName);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return obr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const Foam::objectRegistry&
|
||||||
|
Foam::functionObjects::regionFunctionObject::obr() const
|
||||||
|
{
|
||||||
|
return subObr_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Foam::functionObjects::regionFunctionObject::writeObject
|
bool Foam::functionObjects::regionFunctionObject::writeObject
|
||||||
(
|
(
|
||||||
const word& fieldName
|
const word& fieldName
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (obr_.foundObject<regIOobject>(fieldName))
|
const regIOobject* objPtr =
|
||||||
|
this->lookupObjectPtr<regIOobject>(fieldName);
|
||||||
|
|
||||||
|
if (objPtr)
|
||||||
{
|
{
|
||||||
const regIOobject& field = obr_.lookupObject<regIOobject>(fieldName);
|
|
||||||
|
|
||||||
Log << " functionObjects::" << type() << " " << name()
|
Log << " functionObjects::" << type() << " " << name()
|
||||||
<< " writing field: " << field.name() << endl;
|
<< " writing field: " << objPtr->name() << endl;
|
||||||
|
|
||||||
field.write();
|
objPtr->write();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -68,13 +95,12 @@ bool Foam::functionObjects::regionFunctionObject::clearObject
|
|||||||
const word& fieldName
|
const word& fieldName
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (foundObject<regIOobject>(fieldName))
|
regIOobject* objPtr = lookupObjectRefPtr<regIOobject>(fieldName);
|
||||||
|
if (objPtr)
|
||||||
{
|
{
|
||||||
const regIOobject& resultObject = lookupObject<regIOobject>(fieldName);
|
if (objPtr->ownedByRegistry())
|
||||||
|
|
||||||
if (resultObject.ownedByRegistry())
|
|
||||||
{
|
{
|
||||||
return const_cast<regIOobject&>(resultObject).checkOut();
|
return objPtr->checkOut();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -104,7 +130,8 @@ Foam::functionObjects::regionFunctionObject::regionFunctionObject
|
|||||||
(
|
(
|
||||||
dict.lookupOrDefault("region", polyMesh::defaultRegion)
|
dict.lookupOrDefault("region", polyMesh::defaultRegion)
|
||||||
)
|
)
|
||||||
)
|
),
|
||||||
|
subObr_(whichSubRegistry(obr_, dict))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
@ -116,7 +143,8 @@ Foam::functionObjects::regionFunctionObject::regionFunctionObject
|
|||||||
)
|
)
|
||||||
:
|
:
|
||||||
stateFunctionObject(name, obr.time()),
|
stateFunctionObject(name, obr.time()),
|
||||||
obr_(obr)
|
obr_(obr),
|
||||||
|
subObr_(whichSubRegistry(obr_, dict))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -27,6 +27,8 @@ Class
|
|||||||
Description
|
Description
|
||||||
Specialization of Foam::functionObject for a region and providing a
|
Specialization of Foam::functionObject for a region and providing a
|
||||||
reference to the region Foam::objectRegistry.
|
reference to the region Foam::objectRegistry.
|
||||||
|
Also provides support for referencing a sub-region, which is typically
|
||||||
|
needed when dealing with surfMesh and their fields.
|
||||||
|
|
||||||
See also
|
See also
|
||||||
Foam::functionObjects::stateFunctionObject
|
Foam::functionObjects::stateFunctionObject
|
||||||
@ -68,18 +70,51 @@ protected:
|
|||||||
//- Reference to the region objectRegistry
|
//- Reference to the region objectRegistry
|
||||||
const objectRegistry& obr_;
|
const objectRegistry& obr_;
|
||||||
|
|
||||||
|
//- Optional reference to the sub-region objectRegistry.
|
||||||
|
// If a sub-region is not in effect, this reference is identical
|
||||||
|
// to the usual region objectRegistry.
|
||||||
|
const objectRegistry& subObr_;
|
||||||
|
|
||||||
|
|
||||||
// Protected member functions
|
// Protected member functions
|
||||||
|
|
||||||
//- Find field in the objectRegistry
|
//- Selector for alternative sub-registry,
|
||||||
|
// when the keyword %subRegion is present in the dictionary
|
||||||
|
static const objectRegistry& whichSubRegistry
|
||||||
|
(
|
||||||
|
const objectRegistry& obr,
|
||||||
|
const dictionary& dict
|
||||||
|
);
|
||||||
|
|
||||||
|
//- The region or sub-region registry being used
|
||||||
|
const objectRegistry& obr() const;
|
||||||
|
|
||||||
|
|
||||||
|
//- Find object (eg, a field) in the (sub) objectRegistry
|
||||||
template<class ObjectType>
|
template<class ObjectType>
|
||||||
bool foundObject(const word& fieldName) const;
|
bool foundObject(const word& fieldName) const;
|
||||||
|
|
||||||
//- Lookup field from the objectRegistry
|
//- Lookup and return object (eg, a field) from the (sub) objectRegistry
|
||||||
template<class ObjectType>
|
template<class ObjectType>
|
||||||
const ObjectType& lookupObject(const word& fieldName) const;
|
const ObjectType& lookupObject(const word& fieldName) const;
|
||||||
|
|
||||||
//- Store the given field in the objectRegistry under the given name
|
//- Lookup and return object (eg, a field) from the (sub) objectRegistry
|
||||||
|
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 given field in the (sub) objectRegistry under the given name
|
||||||
// Note: sets the fieldName to tfield().name() if not already set
|
// Note: sets the fieldName to tfield().name() if not already set
|
||||||
template<class ObjectType>
|
template<class ObjectType>
|
||||||
bool store
|
bool store
|
||||||
@ -89,10 +124,10 @@ protected:
|
|||||||
bool cacheable = false
|
bool cacheable = false
|
||||||
);
|
);
|
||||||
|
|
||||||
//- Write field if present in objectRegistry
|
//- Write field if present in the (sub) objectRegistry
|
||||||
bool writeObject(const word& fieldName);
|
bool writeObject(const word& fieldName);
|
||||||
|
|
||||||
//- Clear field from the objectRegistry if present
|
//- Clear field from the (sub) objectRegistry if present
|
||||||
bool clearObject(const word& fieldName);
|
bool clearObject(const word& fieldName);
|
||||||
|
|
||||||
|
|
||||||
@ -101,10 +136,10 @@ private:
|
|||||||
// Private Member Functions
|
// Private Member Functions
|
||||||
|
|
||||||
//- Disallow default bitwise copy construct
|
//- Disallow default bitwise copy construct
|
||||||
regionFunctionObject(const regionFunctionObject&);
|
regionFunctionObject(const regionFunctionObject&) = delete;
|
||||||
|
|
||||||
//- Disallow default bitwise assignment
|
//- Disallow default bitwise assignment
|
||||||
void operator=(const regionFunctionObject&);
|
void operator=(const regionFunctionObject&) = delete;
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
@ -34,7 +34,7 @@ bool Foam::functionObjects::regionFunctionObject::foundObject
|
|||||||
const word& fieldName
|
const word& fieldName
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
return obr_.foundObject<ObjectType>(fieldName);
|
return obr().foundObject<ObjectType>(fieldName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -44,7 +44,37 @@ const ObjectType& Foam::functionObjects::regionFunctionObject::lookupObject
|
|||||||
const word& fieldName
|
const word& fieldName
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
return obr_.lookupObject<ObjectType>(fieldName);
|
return obr().lookupObject<ObjectType>(fieldName);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class ObjectType>
|
||||||
|
ObjectType& Foam::functionObjects::regionFunctionObject::lookupObjectRef
|
||||||
|
(
|
||||||
|
const word& fieldName
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
return obr().lookupObjectRef<ObjectType>(fieldName);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -72,8 +102,8 @@ bool Foam::functionObjects::regionFunctionObject::store
|
|||||||
{
|
{
|
||||||
const ObjectType& field = lookupObject<ObjectType>(fieldName);
|
const ObjectType& field = lookupObject<ObjectType>(fieldName);
|
||||||
|
|
||||||
// If there is a result field already registered assign to the new
|
// If there is a result field already registered, assign to the new
|
||||||
// result field otherwise transfer ownership of the new result field to
|
// result field. Otherwise transfer ownership of the new result field to
|
||||||
// the object registry
|
// the object registry
|
||||||
if (&field != &tfield())
|
if (&field != &tfield())
|
||||||
{
|
{
|
||||||
@ -81,7 +111,7 @@ bool Foam::functionObjects::regionFunctionObject::store
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
obr_.objectRegistry::store(tfield.ptr());
|
obr().objectRegistry::store(tfield.ptr());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -95,7 +125,7 @@ bool Foam::functionObjects::regionFunctionObject::store
|
|||||||
fieldName = tfield().name();
|
fieldName = tfield().name();
|
||||||
}
|
}
|
||||||
|
|
||||||
obr_.objectRegistry::store(tfield.ptr());
|
obr().objectRegistry::store(tfield.ptr());
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user