Added abortCalculation function object, exposed Time::stopAtControls

- still needs fine-tuning (testing) to see if it reacts as anticipated under
  various conditions.
This commit is contained in:
Mark Olesen 2009-11-06 17:18:32 +01:00
parent 33e936a34d
commit 3d9c822022
23 changed files with 522 additions and 24 deletions

View File

@ -532,6 +532,22 @@ bool Foam::Time::end() const
}
void Foam::Time::stopAt(const stopAtControls sa) const
{
stopAt_ = sa;
// adjust endTime
if (sa == saEndTime)
{
controlDict_.lookup("endTime") >> endTime_;
}
else
{
endTime_ = GREAT;
}
}
void Foam::Time::setTime(const Time& t)
{
value() = t.value();

View File

@ -90,17 +90,17 @@ public:
//- Stop-run control options
enum stopAtControls
{
saEndTime,
saNoWriteNow,
saWriteNow,
saNextWrite
saEndTime, /*!< stop when Time reaches the prescribed endTime */
saNoWriteNow, /*!< set endTime to stop immediately w/o writing */
saWriteNow, /*!< set endTime to stop immediately w/ writing */
saNextWrite /*!< stop the next time data are written */
};
//- Suported time directory name formats
//- Supported time directory name formats
enum fmtflags
{
general = 0,
fixed = ios_base::fixed,
general = 0,
fixed = ios_base::fixed,
scientific = ios_base::scientific
};
@ -111,10 +111,10 @@ protected:
label startTimeIndex_;
scalar startTime_;
scalar endTime_;
mutable scalar endTime_;
static const NamedEnum<stopAtControls, 4> stopAtControlNames_;
stopAtControls stopAt_;
mutable stopAtControls stopAt_;
static const NamedEnum<writeControls, 5> writeControlNames_;
writeControls writeControl_;
@ -390,6 +390,10 @@ public:
// Edit
//- Adjust the current stopAtControl. Note that this value
// only persists until the next time the dictionary is read.
virtual void stopAt(const stopAtControls) const;
//- Reset the time and time-index to those of the given time
virtual void setTime(const Time&);

View File

@ -27,7 +27,7 @@ Class
Description
A functionObject wrapper around OutputFilter to allow them to be
created via the functions list within controlDict.
created via the functions entry within controlDict.
Note
Since the timeIndex is used directly from Foam::Time, it is unaffected

View File

@ -27,7 +27,7 @@ Typedef
Description
FunctionObject wrapper around writeRegisteredObject to allow them to be
created via the functions list within controlDict.
created via the functions entry within controlDict.
SourceFiles
writeRegisteredObjectFunctionObject.C

View File

@ -27,7 +27,7 @@ Typedef
Description
FunctionObject wrapper around fieldAverage to allow them to be created
via the functions list within controlDict.
via the functions entry within controlDict.
SourceFiles
fieldAverageFunctionObject.C

View File

@ -27,7 +27,7 @@ Typedef
Description
FunctionObject wrapper around fieldMinMax to allow them to be created via
the functions list within controlDict.
the functions entry within controlDict.
SourceFiles
fieldMinMaxFunctionObject.C

View File

@ -27,7 +27,7 @@ Typedef
Description
FunctionObject wrapper around cellSource to allow it to be
created via the functions list within controlDict.
created via the functions entry within controlDict.
SourceFiles
cellSourceFunctionObject.C

View File

@ -27,7 +27,7 @@ Typedef
Description
FunctionObject wrapper around faceSource to allow it to be
created via the functions list within controlDict.
created via the functions entry within controlDict.
SourceFiles
faceSourceFunctionObject.C

View File

@ -27,7 +27,7 @@ Typedef
Description
FunctionObject wrapper around streamLines to allow them to be created via
the functions list within controlDict.
the functions entry within controlDict.
SourceFiles
streamLineFunctionObject.C

View File

@ -27,7 +27,7 @@ Typedef
Description
FunctionObject wrapper around forceCoeffs to allow them to be created via
the functions list within controlDict.
the functions entry within controlDict.
SourceFiles
forceCoeffsFunctionObject.C

View File

@ -27,7 +27,7 @@ Typedef
Description
FunctionObject wrapper around forces to allow them to be created via the
functions list within controlDict.
functions entry within controlDict.
SourceFiles
forcesFunctionObject.C

View File

@ -27,7 +27,7 @@ Typedef
Description
FunctionObject wrapper around systemCall to allow them to be created via
the functions list within controlDict.
the functions entry within controlDict.
SourceFiles
systemCallFunctionObject.C

View File

@ -1,3 +1,6 @@
abortCalculation/abortCalculation.C
abortCalculation/abortCalculationFunctionObject.C
staticPressure/staticPressure.C
staticPressure/staticPressureFunctionObject.C

View File

@ -0,0 +1,50 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2009-2009 OpenCFD Ltd.
\\/ 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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Typedef
Foam::IOabortCalculation
Description
Instance of the generic IOOutputFilter for abortCalculation.
\*---------------------------------------------------------------------------*/
#ifndef IOabortCalculation_H
#define IOabortCalculation_H
#include "abortCalculation.H"
#include "IOOutputFilter.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
typedef IOOutputFilter<abortCalculation> IOabortCalculation;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,159 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2009-2009 OpenCFD Ltd.
\\/ 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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "abortCalculation.H"
#include "dictionary.H"
#include "error.H"
#include "Time.H"
#include "OSspecific.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(abortCalculation, 0);
}
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
template<>
const char* Foam::NamedEnum<Foam::abortCalculation::actionType, 3>::names[] =
{
"noWriteNow",
"writeNow",
"nextWrite"
};
const Foam::NamedEnum<Foam::abortCalculation::actionType, 3>
Foam::abortCalculation::actionTypeNames_;
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::abortCalculation::removeFile() const
{
if (isFile(abortFile_))
{
rm(abortFile_);
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::abortCalculation::abortCalculation
(
const word& name,
const objectRegistry& obr,
const dictionary& dict,
const bool loadFromFiles
)
:
name_(name),
obr_(obr),
abortFile_("$FOAM_CASE/" + name),
action_(nextWrite)
{
abortFile_.expand();
read(dict);
// remove any old files from previous runs
removeFile();
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::abortCalculation::~abortCalculation()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::abortCalculation::read(const dictionary& dict)
{
word actionName;
if (dict.found("action"))
{
action_ = actionTypeNames_.read
(
dict.lookup("action")
);
}
else
{
action_ = nextWrite;
}
if (dict.readIfPresent("fileName", abortFile_))
{
abortFile_.expand();
}
}
void Foam::abortCalculation::execute()
{
if (isFile(abortFile_))
{
switch (action_)
{
case noWriteNow :
obr_.time().stopAt(Time::saNoWriteNow);
Info<< "user requested abort - "
"stop immediately without writing data" << endl;
break;
case writeNow :
obr_.time().stopAt(Time::saWriteNow);
Info<< "user requested abort - "
"stop immediately with writing data" << endl;
break;
case nextWrite :
obr_.time().stopAt(Time::saNextWrite);
Info<< "user requested abort - "
"stop after next data write" << endl;
break;
}
}
}
void Foam::abortCalculation::end()
{
removeFile();
}
void Foam::abortCalculation::write()
{
execute();
}
// ************************************************************************* //

View File

@ -0,0 +1,168 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2009-2009 OpenCFD Ltd.
\\/ 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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::abortCalculation
Description
Watches for presence of the named file in the $FOAM_CASE directory
and aborts the calculation if it is present.
Currently the following action types are supported:
- noWriteNow
- writeNow
- nextWrite
SourceFiles
abortCalculation.C
IOabortCalculation.H
\*---------------------------------------------------------------------------*/
#ifndef abortCalculation_H
#define abortCalculation_H
#include "pointFieldFwd.H"
#include "NamedEnum.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of classes
class objectRegistry;
class dictionary;
class mapPolyMesh;
/*---------------------------------------------------------------------------*\
Class abortCalculation Declaration
\*---------------------------------------------------------------------------*/
class abortCalculation
{
public:
// Public data
//- Enumeration defining the type of action
enum actionType
{
noWriteNow, /*!< stop immediately without writing data */
writeNow, /*!< write data and stop immediately */
nextWrite /*!< stop the next time data are written */
};
private:
// Private data
//- Name of the abort file unless otherwise specified
word name_;
const objectRegistry& obr_;
//- The fully-qualified name of the abort file
fileName abortFile_;
//- Action type names
static const NamedEnum<actionType, 3> actionTypeNames_;
//- The type of action
actionType action_;
// Private Member Functions
//- Remove abort file.
void removeFile() const;
//- Disallow default bitwise copy construct
abortCalculation(const abortCalculation&);
//- Disallow default bitwise assignment
void operator=(const abortCalculation&);
public:
//- Runtime type information
TypeName("abort");
// Constructors
//- Construct for given objectRegistry and dictionary.
abortCalculation
(
const word& name,
const objectRegistry&,
const dictionary&,
const bool loadFromFilesUnused = false
);
//- Destructor
virtual ~abortCalculation();
// Member Functions
//- Return name of the abort file
virtual const word& name() const
{
return name_;
}
//- Read the dictionary settings
virtual void read(const dictionary&);
//- Execute, check existence of abort file and take action
virtual void execute();
//- Execute at the final time-loop, used for cleanup
virtual void end();
//- Execute, check existence of abort file and take action
virtual void write();
//- Update for changes of mesh - does nothing
virtual void updateMesh(const mapPolyMesh&)
{}
//- Update for changes of mesh - does nothing
virtual void movePoints(const pointField&)
{}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,43 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2009-2009 OpenCFD Ltd.
\\/ 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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "abortCalculationFunctionObject.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineNamedTemplateTypeNameAndDebug(abortCalculationFunctionObject, 0);
addToRunTimeSelectionTable
(
functionObject,
abortCalculationFunctionObject,
dictionary
);
}
// ************************************************************************* //

View File

@ -0,0 +1,55 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2009-2009 OpenCFD Ltd.
\\/ 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 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Typedef
Foam::abortCalculationFunctionObject
Description
FunctionObject wrapper around abortCalculation to allow it to be created via
the functions entry within controlDict.
SourceFiles
abortCalculationFunctionObject.C
\*---------------------------------------------------------------------------*/
#ifndef abortCalculationFunctionObject_H
#define abortCalculationFunctionObject_H
#include "abortCalculation.H"
#include "OutputFilterFunctionObject.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
typedef OutputFilterFunctionObject<abortCalculation>
abortCalculationFunctionObject;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -27,7 +27,7 @@ Typedef
Description
FunctionObject wrapper around dsmcFields to allow it to be created via
the functions list within controlDict.
the functions entry within controlDict.
SourceFiles
dsmcFieldsFunctionObject.C

View File

@ -27,7 +27,7 @@ Typedef
Description
FunctionObject wrapper around staticPressure to allow it to be created via
the functions list within controlDict.
the functions entry within controlDict.
SourceFiles
staticPressureFunctionObject.C

View File

@ -27,7 +27,7 @@ Typedef
Description
FunctionObject wrapper around probes to allow them to be created via the
functions list within controlDict.
functions entry within controlDict.
SourceFiles
probesFunctionObject.C

View File

@ -27,7 +27,7 @@ Typedef
Description
FunctionObject wrapper around sets to allow them to be created via the
functions list within controlDict.
functions entry within controlDict.
SourceFiles
sampledSetsFunctionObject.C

View File

@ -27,7 +27,7 @@ Typedef
Description
FunctionObject wrapper around surfaces to allow them to be created via the
functions list within controlDict.
functions entry within controlDict.
SourceFiles
sampledSurfacesFunctionObject.C