ENH: writeObjects: add flag to report registered objects

Co-authored-by: Kutalmis Bercin <kutalmis.bercin@esi-group.com>
This commit is contained in:
Tobias Holzmann 2024-10-21 13:45:31 +01:00 committed by Andrew Heather
parent 5d0058bc85
commit c77cc498d7
4 changed files with 107 additions and 33 deletions

View File

@ -58,6 +58,7 @@ Foam::functionObjects::writeObjects::writeOptionNames_
{ writeOption::NO_WRITE, "noWrite" }, { writeOption::NO_WRITE, "noWrite" },
{ writeOption::AUTO_WRITE, "autoWrite" }, { writeOption::AUTO_WRITE, "autoWrite" },
{ writeOption::ANY_WRITE, "anyWrite" }, { writeOption::ANY_WRITE, "anyWrite" },
{ writeOption::LOG, "log" },
}); });
const Foam::objectRegistry& setRegistry const Foam::objectRegistry& setRegistry
@ -99,7 +100,10 @@ Foam::functionObjects::writeObjects::writeObjects
bool Foam::functionObjects::writeObjects::read(const dictionary& dict) bool Foam::functionObjects::writeObjects::read(const dictionary& dict)
{ {
functionObject::read(dict); if (!functionObject::read(dict))
{
return false;
}
if (dict.found("field")) if (dict.found("field"))
{ {
@ -134,6 +138,31 @@ bool Foam::functionObjects::writeObjects::execute()
bool Foam::functionObjects::writeObjects::write() bool Foam::functionObjects::writeObjects::write()
{ {
if (writeOption_ == writeOption::LOG)
{
const auto& classes = obr_.classes();
Log << "Registered objects:\n";
forAllConstIters(classes, classInfo)
{
const word& className = classInfo.key();
const wordHashSet& objectSet = classInfo();
Log << " " << className << ":\n";
for (const auto& objectName : objectSet)
{
Log << " " << objectName << "\n";
}
Log << nl;
}
Log << endl;
return true;
}
Log << type() << " " << name() << " write:" << nl; Log << type() << " " << name() << " write:" << nl;
if (!obr_.time().writeTime()) if (!obr_.time().writeTime())

View File

@ -34,49 +34,55 @@ Description
Allows specification of different writing frequency of objects registered Allows specification of different writing frequency of objects registered
to the database. 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:
\vartable
autoWrite | objects set to write at output time
noWrite | objects set to not write by default
anyWrite | any option of the previous two
\endvartable
Usage Usage
Example of function object specification: Minimal example by using \c system/controlDict.functions:
\verbatim \verbatim
writeObjects1 writeObjects1
{ {
type writeObjects; // Mandatory entries
libs (utilityFunctionObjects); type writeObjects;
libs (utilityFunctionObjects);
// Optional entries
writeOption <word>;
// Conditional entries
// Option-1
field <word>;
// Option-2
fields (<wordRes>);
// Option-3
objects (<wordRes>);
// Inherited entries
... ...
objects (obj1 obj2);
writeOption anyWrite;
} }
\endverbatim \endverbatim
Where the entries comprise: where the entries mean:
\table \table
Property | Description | Required | Default value Property | Description | Type | Reqd | Deflt
type | type name: writeObjects | yes | type | Type name: writeObjects | word | yes | -
objects | objects to write | yes | libs | Library name: utilityFunctionObjects | word | yes | -
writeOption | only those with this write option | no | anyWrite writeOption | Select objects with the specified write mode | no | anyWrite
field | Name of field to write | word | no | -
fields | Names of fields to write | wordRes | no | -
objects | Names of objects to write | wordRes | no | -
\endtable \endtable
Note: Regular expressions can also be used in \c objects. Options for the \c writeOption entry:
\vartable
autoWrite | Objects set to write at output time
noWrite | Objects set to not write by default
anyWrite | Any option of the previous two
log | Only report registered objects without writing objects
\endvartable
See also The inherited entries are elaborated in:
Foam::functionObject - \link functionObject.H \endlink
Foam::functionObjects::timeControl
SourceFiles SourceFiles
writeObjects.C writeObjects.C
@ -119,9 +125,11 @@ public:
{ {
NO_WRITE, NO_WRITE,
AUTO_WRITE, AUTO_WRITE,
ANY_WRITE ANY_WRITE,
LOG
}; };
//- Names for writeOption
static const Enum<writeOption> writeOptionNames_; static const Enum<writeOption> writeOptionNames_;
private: private:

View File

@ -0,0 +1,36 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2406 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
writeObjects1
{
// Mandatory entries
type writeObjects;
libs (utilityFunctionObjects);
// Optional entries
writeOption log;
// Conditional entries
// field U;
// fields ( ".*" );
objects ( ".*" );
// Inherited entries
region region0;
enabled true;
log true;
timeStart 0;
timeEnd 1000;
executeControl timeStep;
executeInterval -1;
writeControl onEnd;
writeInterval -1;
}
// ************************************************************************* //

View File

@ -94,6 +94,7 @@ functions
#include "FOs/FOwallShearStress" #include "FOs/FOwallShearStress"
#include "FOs/FOwriteCellCentres" #include "FOs/FOwriteCellCentres"
#include "FOs/FOwriteCellVolumes" #include "FOs/FOwriteCellVolumes"
#include "FOs/FOwriteObjects"
#include "FOs/FOyPlus" #include "FOs/FOyPlus"
#include "FOs/FOzeroGradient" #include "FOs/FOzeroGradient"
#include "FOs/FOnorm" #include "FOs/FOnorm"