mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
functionObjects: rewritten to all be derived from 'functionObject'
- Avoids the need for the 'OutputFilterFunctionObject' wrapper
- Time-control for execution and writing is now provided by the
'timeControlFunctionObject' which instantiates the processing
'functionObject' and controls its operation.
- Alternative time-control functionObjects can now be written and
selected at run-time without the need to compile wrapped version of
EVERY existing functionObject which would have been required in the
old structure.
- The separation of 'execute' and 'write' functions is now formalized in the
'functionObject' base-class and all derived classes implement the
two functions.
- Unnecessary implementations of functions with appropriate defaults
in the 'functionObject' base-class have been removed reducing
clutter and simplifying implementation of new functionObjects.
- The 'coded' 'functionObject' has also been updated, simplified and tested.
- Further simplification is now possible by creating some general
intermediate classes derived from 'functionObject'.
This commit is contained in:
@ -1,245 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "OutputFilterFunctionObject.H"
|
||||
#include "polyMesh.H"
|
||||
#include "mapPolyMesh.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * Private Members * * * * * * * * * * * * * * //
|
||||
|
||||
template<class OutputFilter>
|
||||
void Foam::OutputFilterFunctionObject<OutputFilter>::readControls()
|
||||
{
|
||||
dict_.readIfPresent("timeStart", timeStart_);
|
||||
dict_.readIfPresent("timeEnd", timeEnd_);
|
||||
dict_.readIfPresent("nStepsToStartTimeChange", nStepsToStartTimeChange_);
|
||||
}
|
||||
|
||||
|
||||
template<class OutputFilter>
|
||||
bool Foam::OutputFilterFunctionObject<OutputFilter>::active() const
|
||||
{
|
||||
return
|
||||
time_.value() >= timeStart_
|
||||
&& time_.value() <= timeEnd_;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
template<class OutputFilter>
|
||||
Foam::OutputFilterFunctionObject<OutputFilter>::OutputFilterFunctionObject
|
||||
(
|
||||
const word& name,
|
||||
const Time& t,
|
||||
const dictionary& dict
|
||||
)
|
||||
:
|
||||
functionObject(name),
|
||||
time_(t),
|
||||
dict_(dict),
|
||||
timeStart_(-VGREAT),
|
||||
timeEnd_(VGREAT),
|
||||
nStepsToStartTimeChange_
|
||||
(
|
||||
dict.lookupOrDefault("nStepsToStartTimeChange", 3)
|
||||
),
|
||||
writeControl_(t, dict, "write"),
|
||||
evaluateControl_(t, dict, "evaluate"),
|
||||
filter_
|
||||
(
|
||||
name,
|
||||
time_.lookupObject<objectRegistry>
|
||||
(
|
||||
dict.lookupOrDefault("region", polyMesh::defaultRegion)
|
||||
),
|
||||
dict_
|
||||
)
|
||||
{
|
||||
readControls();
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class OutputFilter>
|
||||
bool Foam::OutputFilterFunctionObject<OutputFilter>::execute
|
||||
(
|
||||
const bool postProcess
|
||||
)
|
||||
{
|
||||
if (active())
|
||||
{
|
||||
if (postProcess || evaluateControl_.execute())
|
||||
{
|
||||
filter_.execute();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template<class OutputFilter>
|
||||
bool Foam::OutputFilterFunctionObject<OutputFilter>::write
|
||||
(
|
||||
const bool postProcess
|
||||
)
|
||||
{
|
||||
if (active())
|
||||
{
|
||||
if (postProcess || writeControl_.execute())
|
||||
{
|
||||
filter_.write();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template<class OutputFilter>
|
||||
bool Foam::OutputFilterFunctionObject<OutputFilter>::end()
|
||||
{
|
||||
filter_.end();
|
||||
|
||||
if (writeControl_.execute())
|
||||
{
|
||||
filter_.write();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template<class OutputFilter>
|
||||
bool Foam::OutputFilterFunctionObject<OutputFilter>::timeSet()
|
||||
{
|
||||
if (active())
|
||||
{
|
||||
filter_.timeSet();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template<class OutputFilter>
|
||||
bool Foam::OutputFilterFunctionObject<OutputFilter>::adjustTimeStep()
|
||||
{
|
||||
if
|
||||
(
|
||||
active()
|
||||
&& writeControl_.control()
|
||||
== timeControl::ocAdjustableRunTime
|
||||
)
|
||||
{
|
||||
const label writeTimeIndex = writeControl_.executionIndex();
|
||||
const scalar writeInterval = writeControl_.interval();
|
||||
|
||||
scalar timeToNextWrite = max
|
||||
(
|
||||
0.0,
|
||||
(writeTimeIndex + 1)*writeInterval
|
||||
- (time_.value() - time_.startTime().value())
|
||||
);
|
||||
|
||||
scalar deltaT = time_.deltaTValue();
|
||||
|
||||
scalar nSteps = timeToNextWrite/deltaT - SMALL;
|
||||
|
||||
// functionObjects modify deltaT within nStepsToStartTimeChange
|
||||
// NOTE: Potential problems arise if two function objects dump within
|
||||
// the same interval
|
||||
if (nSteps < nStepsToStartTimeChange_)
|
||||
{
|
||||
label nStepsToNextWrite = label(nSteps) + 1;
|
||||
|
||||
scalar newDeltaT = timeToNextWrite/nStepsToNextWrite;
|
||||
|
||||
// Adjust time step
|
||||
if (newDeltaT < deltaT)
|
||||
{
|
||||
deltaT = max(newDeltaT, 0.2*deltaT);
|
||||
const_cast<Time&>(time_).setDeltaT(deltaT, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template<class OutputFilter>
|
||||
bool Foam::OutputFilterFunctionObject<OutputFilter>::read
|
||||
(
|
||||
const dictionary& dict
|
||||
)
|
||||
{
|
||||
if (dict != dict_)
|
||||
{
|
||||
dict_ = dict;
|
||||
|
||||
writeControl_.read(dict);
|
||||
evaluateControl_.read(dict);
|
||||
readControls();
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class OutputFilter>
|
||||
void Foam::OutputFilterFunctionObject<OutputFilter>::updateMesh
|
||||
(
|
||||
const mapPolyMesh& mpm
|
||||
)
|
||||
{
|
||||
if (active())
|
||||
{
|
||||
filter_.updateMesh(mpm);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class OutputFilter>
|
||||
void Foam::OutputFilterFunctionObject<OutputFilter>::movePoints
|
||||
(
|
||||
const polyMesh& mesh
|
||||
)
|
||||
{
|
||||
if (active())
|
||||
{
|
||||
filter_.movePoints(mesh);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -1,197 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Class
|
||||
Foam::OutputFilterFunctionObject
|
||||
|
||||
Description
|
||||
A functionObject wrapper around OutputFilter to allow them to be
|
||||
created via the functions entry within controlDict.
|
||||
|
||||
Note
|
||||
Since the timeIndex is used directly from Foam::Time, it is unaffected
|
||||
by user-time conversions. For example, Foam::engineTime might cause \a
|
||||
writeInterval to be degrees crank angle, but the functionObject
|
||||
execution \a interval would still be in timestep.
|
||||
|
||||
SourceFiles
|
||||
OutputFilterFunctionObject.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef OutputFilterFunctionObject_H
|
||||
#define OutputFilterFunctionObject_H
|
||||
|
||||
#include "functionObject.H"
|
||||
#include "dictionary.H"
|
||||
#include "timeControl.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class OutputFilterFunctionObject Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
template<class OutputFilter>
|
||||
class OutputFilterFunctionObject
|
||||
:
|
||||
public functionObject
|
||||
{
|
||||
// Private data
|
||||
|
||||
//- Reference to the time database
|
||||
const Time& time_;
|
||||
|
||||
//- Input dictionary
|
||||
dictionary dict_;
|
||||
|
||||
|
||||
// Optional user inputs
|
||||
|
||||
//- Activation time - defaults to -VGREAT
|
||||
scalar timeStart_;
|
||||
|
||||
//- De-activation time - defaults to VGREAT
|
||||
scalar timeEnd_;
|
||||
|
||||
//- Number of steps before the dump-time during which deltaT
|
||||
// may be changed (valid for adjustableRunTime)
|
||||
label nStepsToStartTimeChange_;
|
||||
|
||||
|
||||
//- Output controls
|
||||
timeControl writeControl_;
|
||||
|
||||
//- Evaluate controls
|
||||
timeControl evaluateControl_;
|
||||
|
||||
//- The output filter
|
||||
OutputFilter filter_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Read relevant dictionary entries
|
||||
void readControls();
|
||||
|
||||
//- Returns true if within time bounds
|
||||
bool active() const;
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
OutputFilterFunctionObject(const OutputFilterFunctionObject&);
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const OutputFilterFunctionObject&);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName(OutputFilter::typeName_());
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from components
|
||||
OutputFilterFunctionObject
|
||||
(
|
||||
const word& name,
|
||||
const Time&,
|
||||
const dictionary&
|
||||
);
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
// Access
|
||||
|
||||
//- Return time database
|
||||
inline const Time& time() const;
|
||||
|
||||
//- Return the input dictionary
|
||||
inline const dictionary& dict() const;
|
||||
|
||||
//- Return the region name
|
||||
inline const word& regionName() const;
|
||||
|
||||
//- Return the output control object
|
||||
inline const timeControl& writeControl() const;
|
||||
|
||||
//- Return the output filter
|
||||
inline const OutputFilter& outputFilter() const;
|
||||
|
||||
|
||||
// Function object control
|
||||
|
||||
//- Called at each ++ or += of the time-loop.
|
||||
// postProcess overrides the usual executeControl behaviour and
|
||||
// forces execution (used in post-processing mode)
|
||||
virtual bool execute(const bool postProcess = false);
|
||||
|
||||
//- Called at each ++ or += of the time-loop.
|
||||
// postProcess overrides the usual writeControl behaviour and
|
||||
// forces writing (used in post-processing mode)
|
||||
virtual bool write(const bool postProcess = false);
|
||||
|
||||
//- Called when Time::run() determines that the time-loop exits
|
||||
virtual bool end();
|
||||
|
||||
//- Called when time was set at the end of the Time::operator++
|
||||
virtual bool timeSet();
|
||||
|
||||
//- Called at the end of Time::adjustDeltaT() if adjustTime is true
|
||||
virtual bool adjustTimeStep();
|
||||
|
||||
//- Read and set the function object if its data have changed
|
||||
virtual bool read(const dictionary&);
|
||||
|
||||
//- Update for changes of mesh
|
||||
virtual void updateMesh(const mapPolyMesh& mpm);
|
||||
|
||||
//- Update for changes of mesh
|
||||
virtual void movePoints(const polyMesh& mesh);
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#include "OutputFilterFunctionObjectI.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef NoRepository
|
||||
#include "OutputFilterFunctionObject.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -1,60 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class OutputFilter>
|
||||
inline const Foam::Time&
|
||||
Foam::OutputFilterFunctionObject<OutputFilter>::time() const
|
||||
{
|
||||
return time_;
|
||||
}
|
||||
|
||||
|
||||
template<class OutputFilter>
|
||||
inline const Foam::dictionary&
|
||||
Foam::OutputFilterFunctionObject<OutputFilter>::dict() const
|
||||
{
|
||||
return dict_;
|
||||
}
|
||||
|
||||
|
||||
template<class OutputFilter>
|
||||
inline const Foam::timeControl&
|
||||
Foam::OutputFilterFunctionObject<OutputFilter>::writeControl() const
|
||||
{
|
||||
return writeControl_;
|
||||
}
|
||||
|
||||
|
||||
template<class OutputFilter>
|
||||
inline const OutputFilter&
|
||||
Foam::OutputFilterFunctionObject<OutputFilter>::outputFilter() const
|
||||
{
|
||||
return filter_;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -51,10 +51,10 @@ Foam::autoPtr<Foam::functionObject> Foam::functionObject::New
|
||||
(
|
||||
const word& name,
|
||||
const Time& t,
|
||||
const dictionary& functionDict
|
||||
const dictionary& dict
|
||||
)
|
||||
{
|
||||
const word functionType(functionDict.lookup("type"));
|
||||
const word functionType(dict.lookup("type"));
|
||||
|
||||
if (debug)
|
||||
{
|
||||
@ -63,7 +63,7 @@ Foam::autoPtr<Foam::functionObject> Foam::functionObject::New
|
||||
|
||||
const_cast<Time&>(t).libs().open
|
||||
(
|
||||
functionDict,
|
||||
dict,
|
||||
"functionObjectLibs",
|
||||
dictionaryConstructorTablePtr_
|
||||
);
|
||||
@ -90,7 +90,7 @@ Foam::autoPtr<Foam::functionObject> Foam::functionObject::New
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
return autoPtr<functionObject>(cstrIter()(name, t, functionDict));
|
||||
return autoPtr<functionObject>(cstrIter()(name, t, dict));
|
||||
}
|
||||
|
||||
|
||||
@ -126,4 +126,12 @@ bool Foam::functionObject::adjustTimeStep()
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObject::updateMesh(const mapPolyMesh&)
|
||||
{}
|
||||
|
||||
|
||||
void Foam::functionObject::movePoints(const polyMesh&)
|
||||
{}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -99,7 +99,8 @@ Description
|
||||
Abstract base-class for Time/database function objects.
|
||||
|
||||
See Also
|
||||
Foam::OutputFilterFunctionObject
|
||||
Foam::functionObjectList
|
||||
Foam::functionObjects::timeControl
|
||||
|
||||
SourceFiles
|
||||
functionObject.C
|
||||
@ -194,8 +195,11 @@ public:
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Name
|
||||
virtual const word& name() const;
|
||||
//- Return the name of this functionObject
|
||||
const word& name() const;
|
||||
|
||||
//- Read and set the function object if its data have changed
|
||||
virtual bool read(const dictionary&) = 0;
|
||||
|
||||
//- Called at each ++ or += of the time-loop.
|
||||
// postProcess overrides the usual executeControl behaviour and
|
||||
@ -217,14 +221,11 @@ public:
|
||||
//- Called at the end of Time::adjustDeltaT() if adjustTime is true
|
||||
virtual bool adjustTimeStep();
|
||||
|
||||
//- Read and set the function object if its data have changed
|
||||
virtual bool read(const dictionary&) = 0;
|
||||
//- Update for changes of mesh
|
||||
virtual void updateMesh(const mapPolyMesh& mpm);
|
||||
|
||||
//- Update for changes of mesh
|
||||
virtual void updateMesh(const mapPolyMesh& mpm) = 0;
|
||||
|
||||
//- Update for changes of mesh
|
||||
virtual void movePoints(const polyMesh& mesh) = 0;
|
||||
virtual void movePoints(const polyMesh& mesh);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -27,6 +27,7 @@ License
|
||||
#include "Time.H"
|
||||
#include "mapPolyMesh.H"
|
||||
#include "argList.H"
|
||||
#include "timeControlFunctionObject.H"
|
||||
|
||||
// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
|
||||
|
||||
@ -354,7 +355,21 @@ bool Foam::functionObjectList::read()
|
||||
FatalIOError.throwExceptions();
|
||||
try
|
||||
{
|
||||
foPtr = functionObject::New(key, time_, dict);
|
||||
if
|
||||
(
|
||||
dict.found("writeControl")
|
||||
|| dict.found("outputControl")
|
||||
)
|
||||
{
|
||||
foPtr.set
|
||||
(
|
||||
new functionObjects::timeControl(key, time_, dict)
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
foPtr = functionObject::New(key, time_, dict);
|
||||
}
|
||||
}
|
||||
catch (Foam::IOerror& ioErr)
|
||||
{
|
||||
|
||||
@ -29,7 +29,8 @@ Description
|
||||
that is called for each object.
|
||||
|
||||
See Also
|
||||
Foam::functionObject and Foam::OutputFilterFunctionObject
|
||||
Foam::functionObject
|
||||
Foam::functionObjects::timeControl
|
||||
|
||||
SourceFiles
|
||||
functionObjectList.C
|
||||
@ -158,6 +159,9 @@ public:
|
||||
//- Find the ID of a given function object by name
|
||||
label findObjectID(const word& name) const;
|
||||
|
||||
//- Read and set the function objects if their data have changed
|
||||
bool read();
|
||||
|
||||
//- Switch the function objects on
|
||||
void on();
|
||||
|
||||
@ -184,9 +188,6 @@ public:
|
||||
//- Called at the end of Time::adjustDeltaT() if adjustTime is true
|
||||
bool adjustTimeStep();
|
||||
|
||||
//- Read and set the function objects if their data have changed
|
||||
bool read();
|
||||
|
||||
//- Update for changes of mesh
|
||||
void updateMesh(const mapPolyMesh& mpm);
|
||||
|
||||
|
||||
@ -23,27 +23,31 @@ License
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "functionObjectFile.H"
|
||||
#include "writeFile.H"
|
||||
#include "Time.H"
|
||||
#include "polyMesh.H"
|
||||
#include "IOmanip.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
const Foam::word Foam::functionObjectFile::outputPrefix = "postProcessing";
|
||||
Foam::label Foam::functionObjectFile::addChars = 7;
|
||||
const Foam::word Foam::functionObjects::writeFile::outputPrefix
|
||||
(
|
||||
"postProcessing"
|
||||
);
|
||||
|
||||
Foam::label Foam::functionObjects::writeFile::addChars = 7;
|
||||
|
||||
|
||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||
|
||||
void Foam::functionObjectFile::initStream(Ostream& os) const
|
||||
void Foam::functionObjects::writeFile::initStream(Ostream& os) const
|
||||
{
|
||||
os.setf(ios_base::scientific, ios_base::floatfield);
|
||||
os.width(charWidth());
|
||||
}
|
||||
|
||||
|
||||
Foam::fileName Foam::functionObjectFile::baseFileDir() const
|
||||
Foam::fileName Foam::functionObjects::writeFile::baseFileDir() const
|
||||
{
|
||||
fileName baseDir = obr_.time().path();
|
||||
|
||||
@ -72,17 +76,20 @@ Foam::fileName Foam::functionObjectFile::baseFileDir() const
|
||||
}
|
||||
|
||||
|
||||
Foam::fileName Foam::functionObjectFile::baseTimeDir() const
|
||||
Foam::fileName Foam::functionObjects::writeFile::baseTimeDir() const
|
||||
{
|
||||
return baseFileDir()/prefix_/obr_.time().timeName();
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjectFile::writeFileHeader(const label i)
|
||||
void Foam::functionObjects::writeFile::writeFileHeader(const label i)
|
||||
{}
|
||||
|
||||
|
||||
Foam::Omanip<int> Foam::functionObjectFile::valueWidth(const label offset) const
|
||||
Foam::Omanip<int> Foam::functionObjects::writeFile::valueWidth
|
||||
(
|
||||
const label offset
|
||||
) const
|
||||
{
|
||||
return setw(IOstream::defaultPrecision() + addChars + offset);
|
||||
}
|
||||
@ -90,32 +97,67 @@ Foam::Omanip<int> Foam::functionObjectFile::valueWidth(const label offset) const
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjectFile::functionObjectFile
|
||||
Foam::functionObjects::writeFile::writeFile
|
||||
(
|
||||
const objectRegistry& obr,
|
||||
const word& name,
|
||||
const Time& t,
|
||||
const dictionary& dict,
|
||||
const word& prefix
|
||||
)
|
||||
:
|
||||
functionObject(name),
|
||||
time_(t),
|
||||
obr_
|
||||
(
|
||||
time_.lookupObject<objectRegistry>
|
||||
(
|
||||
dict.lookupOrDefault("region", polyMesh::defaultRegion)
|
||||
)
|
||||
),
|
||||
prefix_(prefix),
|
||||
log_(true)
|
||||
{}
|
||||
|
||||
|
||||
Foam::functionObjects::writeFile::writeFile
|
||||
(
|
||||
const word& name,
|
||||
const objectRegistry& obr,
|
||||
const dictionary& dict,
|
||||
const word& prefix
|
||||
)
|
||||
:
|
||||
functionObject(name),
|
||||
time_(obr.time()),
|
||||
obr_(obr),
|
||||
prefix_(prefix)
|
||||
prefix_(prefix),
|
||||
log_(true)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjectFile::~functionObjectFile()
|
||||
Foam::functionObjects::writeFile::~writeFile()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
Foam::label Foam::functionObjectFile::charWidth() const
|
||||
bool Foam::functionObjects::writeFile::read(const dictionary& dict)
|
||||
{
|
||||
log_ = dict.lookupOrDefault<Switch>("log", true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Foam::label Foam::functionObjects::writeFile::charWidth() const
|
||||
{
|
||||
return IOstream::defaultPrecision() + addChars;
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjectFile::writeCommented
|
||||
void Foam::functionObjects::writeFile::writeCommented
|
||||
(
|
||||
Ostream& os,
|
||||
const string& str
|
||||
@ -126,7 +168,7 @@ void Foam::functionObjectFile::writeCommented
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjectFile::writeTabbed
|
||||
void Foam::functionObjects::writeFile::writeTabbed
|
||||
(
|
||||
Ostream& os,
|
||||
const string& str
|
||||
@ -136,7 +178,7 @@ void Foam::functionObjectFile::writeTabbed
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjectFile::writeHeader
|
||||
void Foam::functionObjects::writeFile::writeHeader
|
||||
(
|
||||
Ostream& os,
|
||||
const string& str
|
||||
@ -147,7 +189,7 @@ void Foam::functionObjectFile::writeHeader
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjectFile::writeTime(Ostream& os) const
|
||||
void Foam::functionObjects::writeFile::writeTime(Ostream& os) const
|
||||
{
|
||||
os << setw(charWidth()) << obr_.time().timeName();
|
||||
}
|
||||
@ -22,10 +22,10 @@ License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Class
|
||||
Foam::functionObjectFile
|
||||
Foam::functionObjects::writeFile
|
||||
|
||||
Description
|
||||
Base class for output file data handling
|
||||
functionObject base class for writing single files
|
||||
|
||||
See Also
|
||||
Foam::functionObject
|
||||
@ -36,34 +36,45 @@ SourceFiles
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjectFile_H
|
||||
#define functionObjectFile_H
|
||||
#ifndef functionObjects_writeFile_H
|
||||
#define functionObjects_writeFile_H
|
||||
|
||||
#include "objectRegistry.H"
|
||||
#include "functionObject.H"
|
||||
#include "Time.H"
|
||||
#include "IOmanip.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class functionObjectFile Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class functionObjectFile
|
||||
class writeFile
|
||||
:
|
||||
public functionObject
|
||||
{
|
||||
|
||||
protected:
|
||||
|
||||
// Protected data
|
||||
|
||||
//- Reference to the Time
|
||||
const Time& time_;
|
||||
|
||||
//- Reference to the objectRegistry
|
||||
const objectRegistry& obr_;
|
||||
|
||||
//- Prefix
|
||||
const word prefix_;
|
||||
|
||||
//- Switch to send output to Info as well as to file
|
||||
Switch log_;
|
||||
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
@ -83,10 +94,10 @@ protected:
|
||||
virtual Omanip<int> valueWidth(const label offset = 0) const;
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
functionObjectFile(const functionObjectFile&);
|
||||
writeFile(const writeFile&);
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const functionObjectFile&);
|
||||
void operator=(const writeFile&);
|
||||
|
||||
|
||||
public:
|
||||
@ -100,36 +111,42 @@ public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from objectRegistry
|
||||
functionObjectFile(const objectRegistry& obr, const word& prefix);
|
||||
//- Construct from name, Time, dictionary and prefix
|
||||
writeFile
|
||||
(
|
||||
const word& name,
|
||||
const Time& t,
|
||||
const dictionary& dict,
|
||||
const word& prefix
|
||||
);
|
||||
|
||||
//- Construct from name, objectRegistry, dictionary and prefix
|
||||
writeFile
|
||||
(
|
||||
const word& name,
|
||||
const objectRegistry& obr,
|
||||
const dictionary& dict,
|
||||
const word& prefix
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~functionObjectFile();
|
||||
virtual ~writeFile();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Read optional controls
|
||||
virtual bool read(const dictionary&);
|
||||
|
||||
//- Write a commented string to stream
|
||||
void writeCommented
|
||||
(
|
||||
Ostream& os,
|
||||
const string& str
|
||||
) const;
|
||||
void writeCommented(Ostream& os, const string& str) const;
|
||||
|
||||
//- Write a tabbed string to stream
|
||||
void writeTabbed
|
||||
(
|
||||
Ostream& os,
|
||||
const string& str
|
||||
) const;
|
||||
void writeTabbed(Ostream& os, const string& str) const;
|
||||
|
||||
//- Write a commented header to stream
|
||||
void writeHeader
|
||||
(
|
||||
Ostream& os,
|
||||
const string& str
|
||||
) const;
|
||||
void writeHeader(Ostream& os, const string& str) const;
|
||||
|
||||
//- Write the current time to stream
|
||||
void writeTime(Ostream& os) const;
|
||||
@ -150,12 +167,13 @@ public:
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef NoRepository
|
||||
#include "functionObjectFileTemplates.C"
|
||||
#include "writeFileTemplates.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
@ -26,7 +26,7 @@ License
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
void Foam::functionObjectFile::writeHeaderValue
|
||||
void Foam::functionObjects::writeFile::writeHeaderValue
|
||||
(
|
||||
Ostream& os,
|
||||
const string& property,
|
||||
@ -23,13 +23,13 @@ License
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "functionObjectFiles.H"
|
||||
#include "writeFiles.H"
|
||||
#include "Time.H"
|
||||
#include "IFstream.H"
|
||||
|
||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||
|
||||
void Foam::functionObjectFiles::createFiles()
|
||||
void Foam::functionObjects::writeFiles::createFiles()
|
||||
{
|
||||
if (Pstream::master())
|
||||
{
|
||||
@ -64,13 +64,13 @@ void Foam::functionObjectFiles::createFiles()
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjectFiles::write()
|
||||
void Foam::functionObjects::writeFiles::write()
|
||||
{
|
||||
createFiles();
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjectFiles::resetNames(const wordList& names)
|
||||
void Foam::functionObjects::writeFiles::resetNames(const wordList& names)
|
||||
{
|
||||
names_.clear();
|
||||
names_.append(names);
|
||||
@ -79,13 +79,11 @@ void Foam::functionObjectFiles::resetNames(const wordList& names)
|
||||
{
|
||||
filePtrs_.clear();
|
||||
filePtrs_.setSize(names_.size());
|
||||
|
||||
createFiles();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjectFiles::resetName(const word& name)
|
||||
void Foam::functionObjects::writeFiles::resetName(const word& name)
|
||||
{
|
||||
names_.clear();
|
||||
names_.append(name);
|
||||
@ -94,87 +92,55 @@ void Foam::functionObjectFiles::resetName(const word& name)
|
||||
{
|
||||
filePtrs_.clear();
|
||||
filePtrs_.setSize(1);
|
||||
|
||||
createFiles();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjectFiles::functionObjectFiles
|
||||
Foam::functionObjects::writeFiles::writeFiles
|
||||
(
|
||||
const objectRegistry& obr,
|
||||
const word& name,
|
||||
const Time& time,
|
||||
const dictionary& dict,
|
||||
const word& prefix
|
||||
)
|
||||
:
|
||||
functionObjectFile(obr, prefix),
|
||||
writeFile(name, time, dict, prefix),
|
||||
names_(),
|
||||
filePtrs_()
|
||||
{}
|
||||
|
||||
|
||||
Foam::functionObjectFiles::functionObjectFiles
|
||||
Foam::functionObjects::writeFiles::writeFiles
|
||||
(
|
||||
const word& name,
|
||||
const objectRegistry& obr,
|
||||
const word& prefix,
|
||||
const word& name
|
||||
const dictionary& dict,
|
||||
const word& prefix
|
||||
)
|
||||
:
|
||||
functionObjectFile(obr, prefix),
|
||||
writeFile(name, obr, dict, prefix),
|
||||
names_(),
|
||||
filePtrs_()
|
||||
{
|
||||
names_.clear();
|
||||
names_.append(name);
|
||||
if (Pstream::master())
|
||||
{
|
||||
filePtrs_.clear();
|
||||
filePtrs_.setSize(1);
|
||||
|
||||
// Cannot create files - need to access virtual function
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Foam::functionObjectFiles::functionObjectFiles
|
||||
(
|
||||
const objectRegistry& obr,
|
||||
const word& prefix,
|
||||
const wordList& names
|
||||
)
|
||||
:
|
||||
functionObjectFile(obr, prefix),
|
||||
names_(names),
|
||||
filePtrs_()
|
||||
{
|
||||
names_.clear();
|
||||
names_.append(names);
|
||||
if (Pstream::master())
|
||||
{
|
||||
filePtrs_.clear();
|
||||
filePtrs_.setSize(names_.size());
|
||||
|
||||
// Cannot create files - need to access virtual function
|
||||
}
|
||||
}
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjectFiles::~functionObjectFiles()
|
||||
Foam::functionObjects::writeFiles::~writeFiles()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
const Foam::wordList& Foam::functionObjectFiles::names() const
|
||||
const Foam::wordList& Foam::functionObjects::writeFiles::names() const
|
||||
{
|
||||
return names_;
|
||||
}
|
||||
|
||||
|
||||
Foam::OFstream& Foam::functionObjectFiles::file()
|
||||
Foam::OFstream& Foam::functionObjects::writeFiles::file()
|
||||
{
|
||||
if (!Pstream::master())
|
||||
{
|
||||
@ -201,7 +167,7 @@ Foam::OFstream& Foam::functionObjectFiles::file()
|
||||
}
|
||||
|
||||
|
||||
Foam::PtrList<Foam::OFstream>& Foam::functionObjectFiles::files()
|
||||
Foam::PtrList<Foam::OFstream>& Foam::functionObjects::writeFiles::files()
|
||||
{
|
||||
if (!Pstream::master())
|
||||
{
|
||||
@ -214,7 +180,7 @@ Foam::PtrList<Foam::OFstream>& Foam::functionObjectFiles::files()
|
||||
}
|
||||
|
||||
|
||||
Foam::OFstream& Foam::functionObjectFiles::file(const label i)
|
||||
Foam::OFstream& Foam::functionObjects::writeFiles::file(const label i)
|
||||
{
|
||||
if (!Pstream::master())
|
||||
{
|
||||
@ -22,10 +22,10 @@ License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Class
|
||||
Foam::functionObjectFiles
|
||||
Foam::functionObjects::writeFiles
|
||||
|
||||
Description
|
||||
Base class for output file data handling
|
||||
functionObject base class for writing files
|
||||
|
||||
See Also
|
||||
Foam::functionObject
|
||||
@ -36,10 +36,10 @@ SourceFiles
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjectFiles_H
|
||||
#define functionObjectFiles_H
|
||||
#ifndef functionObjects_writeFiles_H
|
||||
#define functionObjects_writeFiles_H
|
||||
|
||||
#include "functionObjectFile.H"
|
||||
#include "writeFile.H"
|
||||
#include "OFstream.H"
|
||||
#include "PtrList.H"
|
||||
|
||||
@ -47,15 +47,16 @@ SourceFiles
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
namespace functionObjects
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class functionObjectFiles Declaration
|
||||
Class writeFiles Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class functionObjectFiles
|
||||
class writeFiles
|
||||
:
|
||||
public functionObjectFile
|
||||
public writeFile
|
||||
{
|
||||
// Private data
|
||||
|
||||
@ -83,38 +84,37 @@ protected:
|
||||
virtual void resetName(const word& name);
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
functionObjectFiles(const functionObjectFiles&);
|
||||
writeFiles(const writeFiles&);
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const functionObjectFiles&);
|
||||
void operator=(const writeFiles&);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from objectRegistry
|
||||
functionObjectFiles(const objectRegistry& obr, const word& prefix);
|
||||
|
||||
//- Construct from components
|
||||
functionObjectFiles
|
||||
//- Construct from name, Time, dictionary and prefix
|
||||
writeFiles
|
||||
(
|
||||
const objectRegistry& obr,
|
||||
const word& prefix,
|
||||
const word& name
|
||||
const word& name,
|
||||
const Time& time,
|
||||
const dictionary& dict,
|
||||
const word& prefix
|
||||
);
|
||||
|
||||
//- Construct from components
|
||||
functionObjectFiles
|
||||
//- Construct from name, objectRegistry, dictionary and prefix
|
||||
writeFiles
|
||||
(
|
||||
const word& name,
|
||||
const objectRegistry& obr,
|
||||
const word& prefix,
|
||||
const wordList& names
|
||||
const dictionary& dict,
|
||||
const word& prefix
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~functionObjectFiles();
|
||||
virtual ~writeFiles();
|
||||
|
||||
|
||||
// Member Functions
|
||||
@ -135,6 +135,7 @@ public:
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
Reference in New Issue
Block a user