functionObjects::writeLocalObjects: Provides support for controlled writing of field

defined by functionObjects, e.g. wallHeatFlux, wallShearStress and yPlus.

Patch contributed by Bruno Santos
Resolves bug-report http://bugs.openfoam.org/view.php?id=2353
This commit is contained in:
Henry Weller
2016-12-09 21:54:13 +00:00
parent 3140cfa906
commit 249c09933e
13 changed files with 731 additions and 123 deletions

View File

@ -64,6 +64,62 @@ const Foam::NamedEnum
> Foam::functionObjects::writeObjects::writeOptionNames_;
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::functionObjects::writeObjects::writeObject
(
const regIOobject& obj
)
{
switch (writeOption_)
{
case AUTO_WRITE:
{
if(obj.writeOpt() != IOobject::AUTO_WRITE)
{
return;
}
break;
}
case NO_WRITE:
{
if(obj.writeOpt() != IOobject::NO_WRITE)
{
return;
}
break;
}
case ANY_WRITE:
{
break;
}
default:
{
FatalErrorInFunction
<< "Unknown writeOption "
<< writeOptionNames_[writeOption_]
<< ". Valid writeOption types are" << writeOptionNames_
<< exit(FatalError);
}
}
if
(
obj.writeOpt() == IOobject::AUTO_WRITE
&& writeObr_.time().writeTime()
)
{
Log << " automatically written object " << obj.name() << endl;
}
else
{
writeObjectsBase::writeObject(obj);
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::writeObjects::writeObjects
@ -74,15 +130,15 @@ Foam::functionObjects::writeObjects::writeObjects
)
:
functionObject(name),
obr_
writeObjectsBase
(
runTime.lookupObject<objectRegistry>
(
dict.lookupOrDefault("region", polyMesh::defaultRegion)
)
),
log
),
writeOption_(ANY_WRITE),
objectNames_()
writeOption_(ANY_WRITE)
{
read(dict);
}
@ -100,16 +156,16 @@ bool Foam::functionObjects::writeObjects::read(const dictionary& dict)
{
if (dict.found("field"))
{
objectNames_.setSize(1);
dict.lookup("field") >> objectNames_[0];
writeObjectNames_.setSize(1);
dict.lookup("field") >> writeObjectNames_[0];
}
else if (dict.found("fields"))
{
dict.lookup("fields") >> objectNames_;
dict.lookup("fields") >> writeObjectNames_;
}
else
{
dict.lookup("objects") >> objectNames_;
writeObjectsBase::read(dict);
}
if (dict.found("writeOption"))
@ -121,7 +177,7 @@ bool Foam::functionObjects::writeObjects::read(const dictionary& dict)
writeOption_ = ANY_WRITE;
}
return true;
return functionObject::read(dict);
}
@ -135,85 +191,9 @@ bool Foam::functionObjects::writeObjects::write()
{
Info<< type() << " " << name() << " write:" << nl;
if (!obr_.time().writeTime())
{
obr_.time().writeTimeDict();
}
writeObjectsBase::write();
DynamicList<word> allNames(obr_.toc().size());
forAll(objectNames_, i)
{
wordList names(obr_.names<regIOobject>(objectNames_[i]));
if (names.size())
{
allNames.append(names);
}
else
{
WarningInFunction
<< "Object " << objectNames_[i] << " not found in "
<< "database. Available objects:" << nl << obr_.sortedToc()
<< endl;
}
}
forAll(allNames, i)
{
regIOobject& obj = const_cast<regIOobject&>
(
obr_.lookupObject<regIOobject>(allNames[i])
);
switch (writeOption_)
{
case AUTO_WRITE:
{
if(obj.writeOpt() != IOobject::AUTO_WRITE)
{
continue;
}
break;
}
case NO_WRITE:
{
if(obj.writeOpt() != IOobject::NO_WRITE)
{
continue;
}
break;
}
case ANY_WRITE:
{
break;
}
default:
{
FatalErrorInFunction
<< "Unknown writeOption "
<< writeOptionNames_[writeOption_]
<< ". Valid writeOption types are" << writeOptionNames_
<< exit(FatalError);
}
}
if
(
obj.writeOpt() == IOobject::AUTO_WRITE
&& obr_.time().writeTime()
)
{
Info<< " automatically written object " << obj.name() << endl;
}
else
{
Info<< " writing object " << obj.name() << endl;
obj.write();
}
}
Log << endl;
return true;
}