Skip to content
Snippets Groups Projects
Commit 8321f1ff authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: initial support for handling subRegions in regionFunctionObject

- propagate updated objectRegistry methods (eg, lookupObjectRef etc)
  into regionFunctionObject
parent eb00c802
Branches
Tags
No related merge requests found
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -40,19 +40,46 @@ namespace functionObjects
// * * * * * * * * * * * * * 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
(
const word& fieldName
)
{
if (obr_.foundObject<regIOobject>(fieldName))
{
const regIOobject& field = obr_.lookupObject<regIOobject>(fieldName);
const regIOobject* objPtr =
this->lookupObjectPtr<regIOobject>(fieldName);
if (objPtr)
{
Log << " functionObjects::" << type() << " " << name()
<< " writing field: " << field.name() << endl;
<< " writing field: " << objPtr->name() << endl;
field.write();
objPtr->write();
return true;
}
......@@ -68,13 +95,12 @@ bool Foam::functionObjects::regionFunctionObject::clearObject
const word& fieldName
)
{
if (foundObject<regIOobject>(fieldName))
regIOobject* objPtr = lookupObjectRefPtr<regIOobject>(fieldName);
if (objPtr)
{
const regIOobject& resultObject = lookupObject<regIOobject>(fieldName);
if (resultObject.ownedByRegistry())
if (objPtr->ownedByRegistry())
{
return const_cast<regIOobject&>(resultObject).checkOut();
return objPtr->checkOut();
}
else
{
......@@ -104,7 +130,8 @@ Foam::functionObjects::regionFunctionObject::regionFunctionObject
(
dict.lookupOrDefault("region", polyMesh::defaultRegion)
)
)
),
subObr_(whichSubRegistry(obr_, dict))
{}
......@@ -116,7 +143,8 @@ Foam::functionObjects::regionFunctionObject::regionFunctionObject
)
:
stateFunctionObject(name, obr.time()),
obr_(obr)
obr_(obr),
subObr_(whichSubRegistry(obr_, dict))
{}
......
......@@ -27,6 +27,8 @@ Class
Description
Specialization of Foam::functionObject for a region and providing a
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
Foam::functionObjects::stateFunctionObject
......@@ -68,18 +70,51 @@ protected:
//- Reference to the region objectRegistry
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
//- 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>
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>
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
template<class ObjectType>
bool store
......@@ -89,10 +124,10 @@ protected:
bool cacheable = false
);
//- Write field if present in objectRegistry
//- Write field if present in the (sub) objectRegistry
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);
......@@ -101,10 +136,10 @@ private:
// Private Member Functions
//- Disallow default bitwise copy construct
regionFunctionObject(const regionFunctionObject&);
regionFunctionObject(const regionFunctionObject&) = delete;
//- Disallow default bitwise assignment
void operator=(const regionFunctionObject&);
void operator=(const regionFunctionObject&) = delete;
public:
......
......@@ -34,7 +34,7 @@ bool Foam::functionObjects::regionFunctionObject::foundObject
const word& fieldName
) 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
{
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);
// If there is a result field already registered assign to the new
// result field otherwise transfer ownership of the new result field to
// 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())
{
......@@ -81,7 +111,7 @@ bool Foam::functionObjects::regionFunctionObject::store
}
else
{
obr_.objectRegistry::store(tfield.ptr());
obr().objectRegistry::store(tfield.ptr());
}
}
else
......@@ -95,7 +125,7 @@ bool Foam::functionObjects::regionFunctionObject::store
fieldName = tfield().name();
}
obr_.objectRegistry::store(tfield.ptr());
obr().objectRegistry::store(tfield.ptr());
}
return true;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment