Skip to content
Snippets Groups Projects
Commit 9a739863 authored by Henry Weller's avatar Henry Weller
Browse files

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
parent 63010615
No related merge requests found
...@@ -42,9 +42,24 @@ namespace functionObjects ...@@ -42,9 +42,24 @@ namespace functionObjects
writeObjects, writeObjects,
dictionary 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 * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
...@@ -63,7 +78,7 @@ Foam::functionObjects::writeObjects::writeObjects ...@@ -63,7 +78,7 @@ Foam::functionObjects::writeObjects::writeObjects
dict.lookupOrDefault("region", polyMesh::defaultRegion) dict.lookupOrDefault("region", polyMesh::defaultRegion)
) )
), ),
exclusiveWriting_(false), writeOption_(ANY_WRITE),
objectNames_() objectNames_()
{ {
read(dict); read(dict);
...@@ -94,7 +109,14 @@ bool Foam::functionObjects::writeObjects::read(const dictionary& dict) ...@@ -94,7 +109,14 @@ bool Foam::functionObjects::writeObjects::read(const dictionary& dict)
dict.lookup("objects") >> objectNames_; dict.lookup("objects") >> objectNames_;
} }
dict.readIfPresent("exclusiveWriting", exclusiveWriting_); if (dict.found("writeOption"))
{
writeOption_ = writeOptionNames.read(dict.lookup("writeOption"));
}
else
{
writeOption_ = ANY_WRITE;
}
return true; return true;
} }
...@@ -140,15 +162,49 @@ bool Foam::functionObjects::writeObjects::write() ...@@ -140,15 +162,49 @@ bool Foam::functionObjects::writeObjects::write()
obr_.lookupObject<regIOobject>(allNames[i]) obr_.lookupObject<regIOobject>(allNames[i])
); );
if (exclusiveWriting_) switch(writeOption_)
{ {
// Switch off automatic writing to prevent double write case AUTO_WRITE:
obj.writeOpt() = IOobject::NO_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; return true;
......
...@@ -28,11 +28,11 @@ Group ...@@ -28,11 +28,11 @@ Group
grpUtilitiesFunctionObjects grpUtilitiesFunctionObjects
Description Description
Allows specification of different writing frequency of objects registered to Allows specification of different writing frequency of objects registered
the database. to the database.
It has similar functionality as the main time database through the It has similar functionality as the main time database through the
writeControl setting: \c writeControl setting:
- timeStep - timeStep
- writeTime - writeTime
- adjustableRunTime - adjustableRunTime
...@@ -40,28 +40,33 @@ Description ...@@ -40,28 +40,33 @@ Description
- clockTime - clockTime
- cpuTime - 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: Example of function object specification:
\verbatim \verbatim
writeObjects1 writeObjects1
{ {
type writeObjects; type writeObjects;
libs ("libutilityFunctionObjects.so"); libs ("libutilityFunctionObjects.so");
exclusiveWriting true;
... ...
objects (obj1 obj2); objects (obj1 obj2);
writeOption anyWrite;
} }
\endverbatim \endverbatim
Usage Usage
\table \table
Property | Description | Required | Default value Property | Description | Required | Default value
type | type name: writeObjects | yes | type | type name: writeObjects | yes |
objects | objects to write | yes | objects | objects to write | yes |
exclusiveWriting | Takes over object writing | no | yes writeOption | only those with this write option | no | any
\endtable \endtable
\c exclusiveWriting disables automatic writing (i.e through database) of the Note: Regular expressions can also be used in \c objects.
objects to avoid duplicate writing.
See also See also
Foam::functionObject Foam::functionObject
...@@ -77,6 +82,7 @@ SourceFiles ...@@ -77,6 +82,7 @@ SourceFiles
#include "functionObject.H" #include "functionObject.H"
#include "wordReList.H" #include "wordReList.H"
#include "NamedEnum.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
...@@ -97,13 +103,30 @@ class writeObjects ...@@ -97,13 +103,30 @@ class writeObjects
: :
public functionObject public functionObject
{ {
public:
// Public data types
//- Re-enumeration defining the write options, based on the original
// ones at IOobject::writeOption
enum writeOption
{
AUTO_WRITE,
NO_WRITE,
ANY_WRITE
};
static const NamedEnum<writeOption, 3> writeOptionNames;
private:
// Private data // Private data
//- Refererence to Db //- Reference to Db
const objectRegistry& obr_; const objectRegistry& obr_;
//- Takes over the writing from Db //- Takes over the writing from Db
bool exclusiveWriting_; writeOption writeOption_;
//- Names of objects to control //- Names of objects to control
wordReList objectNames_; wordReList objectNames_;
......
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