Commit 2d773bc0 authored by Sergio Ferraris's avatar Sergio Ferraris
Browse files

ENH: adding hook adjustTimeStep to function objects. The hook is called in

    Time::adjustDeltaT(). It allows function objects to manipulate the time step to
    dump at adjustable times. The following options are available for output in
    function objects: timeStep, outputTime, adjustableTime, runTime, clockTime
    and cpuTime.
parent 470553c6
......@@ -129,6 +129,8 @@ void Foam::Time::adjustDeltaT()
}
}
}
functionObjects_.adjustTimeStep();
}
......@@ -941,17 +943,25 @@ void Foam::Time::setEndTime(const scalar endTime)
}
void Foam::Time::setDeltaT(const dimensionedScalar& deltaT)
void Foam::Time::setDeltaT
(
const dimensionedScalar& deltaT,
const bool bAdjustDeltaT
)
{
setDeltaT(deltaT.value());
setDeltaT(deltaT.value(), bAdjustDeltaT);
}
void Foam::Time::setDeltaT(const scalar deltaT)
void Foam::Time::setDeltaT(const scalar deltaT, const bool bAdjustDeltaT)
{
deltaT_ = deltaT;
deltaTchanged_ = true;
adjustDeltaT();
if (bAdjustDeltaT)
{
adjustDeltaT();
}
}
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -527,10 +527,18 @@ public:
virtual void setEndTime(const scalar);
//- Reset time step
virtual void setDeltaT(const dimensionedScalar&);
virtual void setDeltaT
(
const dimensionedScalar&,
const bool adjustDeltaT = true
);
//- Reset time step
virtual void setDeltaT(const scalar);
virtual void setDeltaT
(
const scalar,
const bool adjustDeltaT = true
);
//- Set time to sub-cycle for the given number of steps
virtual TimeState subCycle(const label nSubCycles);
......
......@@ -40,6 +40,7 @@ void Foam::OutputFilterFunctionObject<OutputFilter>::readDict()
dict_.readIfPresent("storeFilter", storeFilter_);
dict_.readIfPresent("timeStart", timeStart_);
dict_.readIfPresent("timeEnd", timeEnd_);
dict_.readIfPresent("nStepsToStartTimeChange", nStepsToStartTimeChange_);
}
......@@ -214,6 +215,52 @@ bool Foam::OutputFilterFunctionObject<OutputFilter>::timeSet()
}
template<class OutputFilter>
bool Foam::OutputFilterFunctionObject<OutputFilter>::adjustTimeStep()
{
if
(
active()
&& outputControl_.outputControl()
== outputFilterOutputControl::ocAdjustableTime
)
{
const label outputTimeIndex = outputControl_.outputTimeLastDump();
const scalar writeInterval = outputControl_.writeInterval();
scalar timeToNextWrite = max
(
0.0,
(outputTimeIndex + 1)*writeInterval
- (time_.value() - time_.startTime().value())
);
scalar deltaT = time_.deltaTValue();
scalar nSteps = timeToNextWrite/deltaT - SMALL;
// function objects modify deltaT inside nStepsToStartTimeChange range
// NOTE: Potential problem if two function objects dump inside 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
(
......
......@@ -90,6 +90,10 @@ class OutputFilterFunctionObject
//- De-activation time - defaults to VGREAT
scalar timeEnd_;
//- Number of steps before the dumping time in which the deltaT
// will start to change (valid for ocAdjustableTime)
label nStepsToStartTimeChange_;
//- Output controls
outputFilterOutputControl outputControl_;
......@@ -204,6 +208,9 @@ public:
//- 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&);
......
......@@ -126,6 +126,12 @@ bool Foam::functionObject::timeSet()
}
bool Foam::functionObject::adjustTimeStep()
{
return false;
}
Foam::autoPtr<Foam::functionObject> Foam::functionObject::iNew::operator()
(
const word& name,
......
......@@ -160,6 +160,9 @@ public:
//- 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&) = 0;
......
......@@ -211,6 +211,27 @@ bool Foam::functionObjectList::timeSet()
}
bool Foam::functionObjectList::adjustTimeStep()
{
bool ok = true;
if (execution_)
{
if (!updated_)
{
read();
}
forAll(*this, objectI)
{
ok = operator[](objectI).adjustTimeStep() && ok;
}
}
return ok;
}
bool Foam::functionObjectList::read()
{
bool ok = true;
......
......@@ -166,6 +166,9 @@ public:
//- 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 objects if their data have changed
virtual bool read();
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -24,21 +24,26 @@ License
\*---------------------------------------------------------------------------*/
#include "outputFilterOutputControl.H"
#include "PstreamReduceOps.H"
// * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * * //
namespace Foam
{
template<>
const char* NamedEnum<outputFilterOutputControl::outputControls, 2>::
const char* NamedEnum<outputFilterOutputControl::outputControls, 6>::
names[] =
{
"timeStep",
"outputTime"
"outputTime",
"adjustableTime",
"runTime",
"clockTime",
"cpuTime"
};
}
const Foam::NamedEnum<Foam::outputFilterOutputControl::outputControls, 2>
const Foam::NamedEnum<Foam::outputFilterOutputControl::outputControls, 6>
Foam::outputFilterOutputControl::outputControlNames_;
......@@ -53,7 +58,8 @@ Foam::outputFilterOutputControl::outputFilterOutputControl
time_(t),
outputControl_(ocTimeStep),
outputInterval_(0),
outputTimeLastDump_(0)
outputTimeLastDump_(0),
writeInterval_(-1)
{
read(dict);
}
......@@ -92,6 +98,15 @@ void Foam::outputFilterOutputControl::read(const dictionary& dict)
break;
}
case ocClockTime:
case ocRunTime:
case ocCpuTime:
case ocAdjustableTime:
{
writeInterval_ = readScalar(dict.lookup("writeInterval"));
break;
}
default:
{
// do nothing
......@@ -125,6 +140,56 @@ bool Foam::outputFilterOutputControl::output()
break;
}
case ocRunTime:
case ocAdjustableTime:
{
label outputIndex = label
(
(
(time_.value() - time_.startTime().value())
+ 0.5*time_.deltaTValue()
)
/ writeInterval_
);
if (outputIndex > outputTimeLastDump_)
{
outputTimeLastDump_ = outputIndex;
return true;
}
break;
}
case ocCpuTime:
{
label outputIndex = label
(
returnReduce(time_.elapsedCpuTime(), maxOp<double>())
/ writeInterval_
);
if (outputIndex > outputTimeLastDump_)
{
outputTimeLastDump_ = outputIndex;
return true;
}
break;
}
case ocClockTime:
{
label outputIndex = label
(
returnReduce(label(time_.elapsedClockTime()), maxOp<label>())
/ writeInterval_
);
if (outputIndex > outputTimeLastDump_)
{
outputTimeLastDump_ = outputIndex;
return true;
}
break;
}
default:
{
// this error should not actually be possible
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -56,8 +56,12 @@ public:
//- The output control options
enum outputControls
{
ocTimeStep, /*!< execution is coupled to the time-step */
ocOutputTime /*!< execution is coupled to the output-time */
ocTimeStep, /*!< execution is coupled to the time-step */
ocOutputTime, /*!< execution is coupled to the output-time */
ocAdjustableTime, /*!< Adjust time step for dumping */
ocRunTime, /*!< run time for dumping */
ocClockTime, /*!< clock time for dumping */
ocCpuTime /*!< cpu time for dumping */
};
......@@ -69,7 +73,7 @@ private:
const Time& time_;
//- String representation of outputControls enums
static const NamedEnum<outputControls, 2> outputControlNames_;
static const NamedEnum<outputControls, 6> outputControlNames_;
//- Type of output
outputControls outputControl_;
......@@ -81,6 +85,9 @@ private:
//- Dumping counter for ocOutputTime
label outputTimeLastDump_;
//- Dump each deltaT (adjust Ttime)
scalar writeInterval_;
// Private Member Functions
......@@ -114,6 +121,24 @@ public:
//- Flag to indicate whether to output
bool output();
//- Return outputControl
outputControls outputControl()
{
return outputControl_;
}
//- Return writeInterval
scalar writeInterval()
{
return writeInterval_;
}
//- Return outputTimeLastDump
label outputTimeLastDump()
{
return outputTimeLastDump_;
}
};
......
......@@ -64,14 +64,24 @@ functions
// region allowed.
region wallFilmRegion;
// Execute upon outputTime
// Execute upon options:
// timeStep
// outputTime
// adjustableTime
// runTime
// clockTime
// cpuTime
outputControl outputTime;
// Objects (fields or lagrangian fields in any of the clouds)
// to write every outputTime
objectNames (p positions nParticle);
// Write as normal every writeInterval'th outputTime.
writeInterval 3;
outputInterval 1; // (timeStep, outputTime)
// Interval of time (sec) to write down(
writeInterval 10.5 //(adjustableTime, runTime, clockTime, cpuTime)
}
dumpObjects
......@@ -84,9 +94,24 @@ functions
// Where to load it from
functionObjectLibs ("libIOFunctionObjects.so");
// Execute upon outputTime
// Execute upon outputTime:
// timeStep
// outputTime
// adjustableTime
// runTime
// clockTime
// cpuTime
outputControl outputTime;
// Is the object written by this function Object alone
exclusiveWriting true;
// Interval of time (sec) to write down(
writeInterval 10.5 //(adjustableTime, runTime, clockTime, cpuTime)
// Write as normal every writeInterval'th outputTime.
outputInterval 1; // (timeStep, outputTime)
// Objects to write
objectNames ();
}
......
......@@ -46,6 +46,7 @@ Foam::writeRegisteredObject::writeRegisteredObject
)
:
name_(name),
exclusiveWriting_(true),
obr_(obr),
objectNames_()
{
......@@ -64,6 +65,7 @@ Foam::writeRegisteredObject::~writeRegisteredObject()
void Foam::writeRegisteredObject::read(const dictionary& dict)
{
dict.lookup("objectNames") >> objectNames_;
dict.readIfPresent("exclusiveWriting", exclusiveWriting_);
}
......@@ -96,12 +98,12 @@ void Foam::writeRegisteredObject::write()
(
obr_.lookupObject<regIOobject>(objectNames_[i])
);
// Switch off automatic writing to prevent double write
obj.writeOpt() = IOobject::NO_WRITE;
Info<< type() << " " << name_ << " output:" << nl
<< " writing object " << obj.name() << nl
<< endl;
if (exclusiveWriting_)
{
// Switch off automatic writing to prevent double write
obj.writeOpt() = IOobject::NO_WRITE;
}
obj.write();
}
......
......@@ -28,8 +28,15 @@ Group
grpIOFunctionObjects
Description
This function object takes-over the writing of objects registered to the
database.
This function object allows specification of different writing frequency
of objects registered to the database. It has similar functionality
as the main time database through the outputControl setting:
timeStep
outputTime
adjustableTime
runTime
clockTime
cpuTime
Example of function object specification:
\verbatim
......@@ -37,6 +44,7 @@ Description
{
type writeRegisteredObject;
functionObjectLibs ("libIOFunctionObjects.so");
exclusiveWriting true;
...
objectNames (obj1 obj2);
}
......@@ -47,8 +55,12 @@ Description
Property | Description | Required | Default value
type | type name: writeRegisteredObject | yes |
objectNames | objects to write | yes |
exclusiveWriting | Takes over object writing | no | yes
\endtable
exclusiveWriting disables automatic writing (i.e through database) of the
objects to avoid duplicate writing.
SeeAlso
Foam::functionObject
Foam::OutputFilterFunctionObject
......@@ -89,6 +101,9 @@ protected:
//- Name of this set of writeRegisteredObject
word name_;
//- Takes over the writing from Db
bool exclusiveWriting_;
const objectRegistry& obr_;
// Read from dictionary
......
......@@ -70,7 +70,7 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef compressibleSpalartAllmaras_H
#define combressibleSpalartAllmaras_H
#define compressibleSpalartAllmaras_H
#include "RASModel.H"
#include "wallDist.H"
......
Markdown is supported
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