mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
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:
@ -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;
|
||||
}
|
||||
|
||||
@ -72,6 +72,7 @@ Usage
|
||||
|
||||
See also
|
||||
Foam::functionObject
|
||||
Foam::functionObjects::writeObjectsBase
|
||||
Foam::functionObjects::timeControl
|
||||
|
||||
SourceFiles
|
||||
@ -83,7 +84,7 @@ SourceFiles
|
||||
#define functionObjects_writeObjects_H
|
||||
|
||||
#include "functionObject.H"
|
||||
#include "wordReList.H"
|
||||
#include "writeObjectsBase.H"
|
||||
#include "NamedEnum.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
@ -91,9 +92,6 @@ SourceFiles
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declaration of classes
|
||||
class objectRegistry;
|
||||
|
||||
namespace functionObjects
|
||||
{
|
||||
|
||||
@ -103,7 +101,8 @@ namespace functionObjects
|
||||
|
||||
class writeObjects
|
||||
:
|
||||
public functionObject
|
||||
public functionObject,
|
||||
public writeObjectsBase
|
||||
{
|
||||
public:
|
||||
|
||||
@ -124,18 +123,15 @@ private:
|
||||
|
||||
// Private data
|
||||
|
||||
//- Reference to Db
|
||||
const objectRegistry& obr_;
|
||||
|
||||
//- To only write objects of defined writeOption
|
||||
writeOption writeOption_;
|
||||
|
||||
//- Names of objects to control
|
||||
wordReList objectNames_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Write the requested registered IO object
|
||||
virtual void writeObject(const regIOobject& obj);
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
writeObjects(const writeObjects&);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user