functionObjects::writeObjects: Added option "writeOption"

Description
    Allows specification of different writing frequency of objects registered
    to the database.

    It has similar functionality as the main time database through the
    \c writeControl setting:
      - timeStep
      - writeTime
      - adjustableRunTime
      - runTime
      - clockTime
      - cpuTime

    It also has the ability to write the selected objects that were defined
    with the respective write mode for the requested \c writeOption, namely:
      - \c autoWrite - objects set to write at output time
      - \c noWrite   - objects set to not write by default
      - \c anyWrite  - any option of the previous two

    Example of function object specification:
    \verbatim
    writeObjects1
    {
        type        writeObjects;
        libs        ("libutilityFunctionObjects.so");
        ...
        objects     (obj1 obj2);
        writeOption anyWrite;
    }
    \endverbatim

Patch contributed by Bruno Santos
Resolves bug-report http://bugs.openfoam.org/view.php?id=2090
This commit is contained in:
Henry Weller
2016-08-16 23:41:22 +01:00
parent 63010615ae
commit 9a739863e5
2 changed files with 96 additions and 17 deletions

View File

@ -42,9 +42,24 @@ namespace functionObjects
writeObjects,
dictionary
);
template<>
const char* Foam::NamedEnum
<
Foam::functionObjects::writeObjects::writeOption,
3
>::names[] =
{
"autoWrite",
"noWrite",
"anyWrite"
};
}
}
const Foam::NamedEnum<Foam::functionObjects::writeObjects::writeOption, 3>
Foam::functionObjects::writeObjects::writeOptionNames;
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
@ -63,7 +78,7 @@ Foam::functionObjects::writeObjects::writeObjects
dict.lookupOrDefault("region", polyMesh::defaultRegion)
)
),
exclusiveWriting_(false),
writeOption_(ANY_WRITE),
objectNames_()
{
read(dict);
@ -94,7 +109,14 @@ bool Foam::functionObjects::writeObjects::read(const dictionary& dict)
dict.lookup("objects") >> objectNames_;
}
dict.readIfPresent("exclusiveWriting", exclusiveWriting_);
if (dict.found("writeOption"))
{
writeOption_ = writeOptionNames.read(dict.lookup("writeOption"));
}
else
{
writeOption_ = ANY_WRITE;
}
return true;
}
@ -140,15 +162,49 @@ bool Foam::functionObjects::writeObjects::write()
obr_.lookupObject<regIOobject>(allNames[i])
);
if (exclusiveWriting_)
switch(writeOption_)
{
// Switch off automatic writing to prevent double write
obj.writeOpt() = IOobject::NO_WRITE;
case AUTO_WRITE:
if (obj.writeOpt() != IOobject::AUTO_WRITE)
{
continue;
}
else
{
break;
}
case NO_WRITE:
if (obj.writeOpt() != IOobject::NO_WRITE)
{
continue;
}
else
{
break;
}
case ANY_WRITE:
break;
default:
continue;
}
Info<< " writing object " << obj.name() << endl;
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();
obj.write();
}
}
return true;