Commit a50d78ea authored by Sergio Ferraris's avatar Sergio Ferraris
Browse files

EMH: Adding a hook to functionObject called 'timeSet' at the

end of Time::operator++. This allows to know if the next timeIndex will be
a dumping time. The function object "partialWrite" modifyes the write option
of the those fields which will be written down at given intervals of the overall
outout times.
parent 2e1ccf40
......@@ -1220,6 +1220,7 @@ Foam::Time& Foam::Time::operator++()
writeOnce_ = false;
}
functionObjects_.timeSet();
}
return *this;
......
......@@ -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
......@@ -202,6 +202,18 @@ bool Foam::OutputFilterFunctionObject<OutputFilter>::end()
}
template<class OutputFilter>
bool Foam::OutputFilterFunctionObject<OutputFilter>::timeSet()
{
if (active())
{
ptr_->timeSet();
}
return true;
}
template<class OutputFilter>
bool Foam::OutputFilterFunctionObject<OutputFilter>::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
......@@ -201,6 +201,8 @@ public:
//- 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();
//- Read and set the function object if its data have changed
virtual bool read(const dictionary&);
......
......@@ -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
......@@ -120,6 +120,12 @@ bool Foam::functionObject::end()
}
bool Foam::functionObject::timeSet()
{
return false;
}
Foam::autoPtr<Foam::functionObject> Foam::functionObject::iNew::operator()
(
const word& name,
......
......@@ -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
......@@ -157,6 +157,9 @@ public:
// By default it simply calls execute().
virtual bool end();
//- Called when time was set at the end of the Time::operator++
virtual bool timeSet();
//- Read and set the function object if its data have changed
virtual bool read(const dictionary&) = 0;
......
......@@ -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
......@@ -190,6 +190,27 @@ bool Foam::functionObjectList::end()
}
bool Foam::functionObjectList::timeSet()
{
bool ok = true;
if (execution_)
{
if (!updated_)
{
read();
}
forAll(*this, objectI)
{
ok = operator[](objectI).timeSet() && ok;
}
}
return ok;
}
bool Foam::functionObjectList::read()
{
bool ok = true;
......
......@@ -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
......@@ -163,6 +163,9 @@ public:
//- 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();
//- 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 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2013 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -87,13 +87,33 @@ void Foam::partialWrite::read(const dictionary& dict)
<< ". It should be >= 1."
<< exit(FatalIOError);
}
// Clear out any previously loaded fields
vsf_.clear();
vvf_.clear();
vSpheretf_.clear();
vSymmtf_.clear();
vtf_.clear();
ssf_.clear();
svf_.clear();
sSpheretf_.clear();
sSymmtf_.clear();
stf_.clear();
forAllConstIter(HashSet<word>, objectNames_, iter)
{
loadField<scalar>(iter.key(), vsf_, ssf_);
loadField<vector>(iter.key(), vvf_, svf_);
loadField<sphericalTensor>(iter.key(), vSpheretf_, sSpheretf_);
loadField<symmTensor>(iter.key(), vSymmtf_, sSymmtf_);
loadField<tensor>(iter.key(), vtf_, stf_);
}
}
void Foam::partialWrite::execute()
{
//Pout<< "execute at time " << obr_.time().timeName()
// << " index:" << obr_.time().timeIndex() << endl;
}
......@@ -104,99 +124,61 @@ void Foam::partialWrite::end()
}
void Foam::partialWrite::write()
void Foam::partialWrite::timeSet()
{
//Pout<< "write at time " << obr_.time().timeName() << endl;
if (obr_.time().outputTime())
{
// Above check so it can be used both with
// outputControl timeStep;
// outputInterval 1;
// or with
// outputControl outputTime;
writeInstance_++;
if (writeInstance_ == writeInterval_)
{
// Normal dump
// Next overall dump corresponf to partial write. Change
// write options to AUTO_WRITE
writeInstance_ = 0;
changeWriteOptions<scalar>(vsf_, ssf_, IOobject::AUTO_WRITE);
changeWriteOptions<vector>(vvf_, svf_, IOobject::AUTO_WRITE);
changeWriteOptions<sphericalTensor>
(
vSpheretf_,
sSpheretf_,
IOobject::AUTO_WRITE
);
changeWriteOptions<symmTensor>
(
vSymmtf_,
sSymmtf_,
IOobject::AUTO_WRITE
);
changeWriteOptions<tensor>(vtf_, stf_, IOobject::AUTO_WRITE);
}
else
{
// Delete all but marked objects
fileName dbDir;
if (isA<polyMesh>(obr_))
{
dbDir = dynamic_cast<const polyMesh&>(obr_).dbDir();
}
IOobjectList objects(obr_, obr_.time().timeName());
if (debug)
{
Pout<< "For region:" << obr_.name() << endl;
}
forAllConstIter(IOobjectList, objects, iter)
{
if (!objectNames_.found(iter()->name()))
{
const fileName f =
obr_.time().timePath()
/dbDir
/iter()->name();
if (debug)
{
Pout<< " rm " << f << endl;
}
rm(f);
}
}
// Do the lagrangian files as well.
fileNameList cloudDirs
changeWriteOptions<scalar>(vsf_, ssf_, IOobject::NO_WRITE);
changeWriteOptions<vector>(vvf_, svf_, IOobject::NO_WRITE);
changeWriteOptions<sphericalTensor>
(
vSpheretf_,
sSpheretf_,
IOobject::NO_WRITE
);
changeWriteOptions<symmTensor>
(
readDir
(
obr_.time().timePath()/dbDir/cloud::prefix,
fileName::DIRECTORY
)
vSymmtf_,
sSymmtf_,
IOobject::NO_WRITE
);
forAll(cloudDirs, i)
{
if (debug)
{
Pout<< "For cloud:" << cloudDirs[i] << endl;
}
IOobjectList sprayObjs
(
obr_,
obr_.time().timeName(),
cloud::prefix/cloudDirs[i]
);
forAllConstIter(IOobjectList, sprayObjs, iter)
{
if (!objectNames_.found(iter()->name()))
{
const fileName f =
obr_.time().timePath()
/dbDir
/cloud::prefix
/cloudDirs[i]
/iter()->name();
if (debug)
{
Pout<< " rm " << f << endl;
}
rm(f);
}
}
}
changeWriteOptions<tensor>(vtf_, stf_, IOobject::NO_WRITE);
}
}
}
void Foam::partialWrite::write()
{
// Do nothing. The fields get written through the
// standard dump
}
// ************************************************************************* //
......@@ -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
......@@ -29,8 +29,8 @@ Group
Description
This function object allows user-selected fields/registered objects to be
written at a custom write interval. It operates by deleting all entries
except those selected after writing.
written at a custom write interval. The interval is given in terms of
number of overall dumps
Example of function object specification:
\verbatim
......@@ -66,8 +66,9 @@ SourceFiles
#define partialWrite_H
#include "HashSet.H"
#include "DynamicList.H"
#include "runTimeSelectionTables.H"
#include "volFields.H"
#include "surfaceFields.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -95,6 +96,18 @@ protected:
const objectRegistry& obr_;
//- Loaded fields
UPtrList<volScalarField> vsf_;
UPtrList<volVectorField> vvf_;
UPtrList<volSphericalTensorField> vSpheretf_;
UPtrList<volSymmTensorField> vSymmtf_;
UPtrList<volTensorField> vtf_;
UPtrList<surfaceScalarField> ssf_;
UPtrList<surfaceVectorField> svf_;
UPtrList<surfaceSphericalTensorField> sSpheretf_;
UPtrList<surfaceSymmTensorField> sSymmtf_;
UPtrList<surfaceTensorField> stf_;
// Read from dictionary
......@@ -105,6 +118,7 @@ protected:
label writeInterval_;
//- Current dump instance. If reaches writeInterval do a full write.
label writeInstance_;
......@@ -118,6 +132,24 @@ protected:
void operator=(const partialWrite&);
//- Load objects in the objectNames
template<class Type>
void loadField
(
const word&,
UPtrList<GeometricField<Type, fvPatchField, volMesh> >&,
UPtrList<GeometricField<Type, fvsPatchField, surfaceMesh> >&
) const;
template<class Type>
void changeWriteOptions
(
UPtrList<GeometricField<Type, fvPatchField, volMesh> >&,
UPtrList<GeometricField<Type, fvsPatchField, surfaceMesh> >&,
const IOobject::writeOption
) const;
public:
//- Runtime type information
......@@ -152,12 +184,15 @@ public:
//- Read the partialWrite data
virtual void read(const dictionary&);
//- Execute, currently does nothing
//- Execute
virtual void execute();
//- Execute at the final time-loop, currently does nothing
virtual void end();
//- Called when time was set at the end of the Time::operator++
virtual void timeSet();
//- Write the partialWrite
virtual void write();
......@@ -177,6 +212,12 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
# include "partialWriteTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2013 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -92,6 +92,12 @@ void Foam::removeRegisteredObject::end()
}
void Foam::removeRegisteredObject::timeSet()
{
// Do nothing - only valid on execute
}
void Foam::removeRegisteredObject::write()
{
// Do nothing - only valid on execute
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2013 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -146,6 +146,9 @@ public:
//- Execute at the final time-loop, currently does nothing
virtual void end();
//- Called when time was set at the end of the Time::operator++
virtual void timeSet();
//- Write the removeRegisteredObject
virtual void write();
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2013 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -199,6 +199,12 @@ void Foam::writeDictionary::end()
}
void Foam::writeDictionary::timeSet()
{
// do nothing
}
void Foam::writeDictionary::write()
{
// do nothing
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2013 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -134,6 +134,9 @@ public:
//- Execute at the final time-loop, currently does nothing
virtual void end();
//- Called when time was set at the end of the Time::operator++
virtual void timeSet();
//- Write the writeDictionary
virtual void write();
......
......@@ -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
......@@ -79,6 +79,12 @@ void Foam::writeRegisteredObject::end()
}
void Foam::writeRegisteredObject::timeSet()
{
// Do nothing - only valid on write
}
void Foam::writeRegisteredObject::write()
{
forAll(objectNames_, i)
......
......@@ -147,6 +147,9 @@ public:
//- Execute at the final time-loop, currently does nothing
virtual void end();
//- Called when time was set at the end of the Time::operator++
virtual void timeSet();
//- Write the writeRegisteredObject
virtual void write();
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2013 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -106,6 +106,12 @@ void Foam::cloudInfo::end()
}