mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: move residualControl and abortCalculation into common jobControl lib
This commit is contained in:
7
src/postProcessing/functionObjects/jobControl/Make/files
Normal file
7
src/postProcessing/functionObjects/jobControl/Make/files
Normal file
@ -0,0 +1,7 @@
|
||||
abortCalculation/abortCalculation.C
|
||||
abortCalculation/abortCalculationFunctionObject.C
|
||||
|
||||
residualControl/residualControl.C
|
||||
residualControl/residualControlFunctionObject.C
|
||||
|
||||
LIB = $(FOAM_LIBBIN)/libjobControl
|
||||
@ -0,0 +1,9 @@
|
||||
EXE_INC = \
|
||||
-I$(LIB_SRC)/finiteVolume/lnInclude \
|
||||
-I$(LIB_SRC)/meshTools/lnInclude \
|
||||
-I$(LIB_SRC)/sampling/lnInclude
|
||||
|
||||
LIB_LIBS = \
|
||||
-lfiniteVolume \
|
||||
-lmeshTools \
|
||||
-lsampling
|
||||
@ -0,0 +1,49 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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 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/>.
|
||||
|
||||
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
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,156 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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 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 "abortCalculation.H"
|
||||
#include "dictionary.H"
|
||||
#include "error.H"
|
||||
#include "Time.H"
|
||||
#include "OSspecific.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
defineTypeNameAndDebug(Foam::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();
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,167 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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 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::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
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,42 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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 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 "abortCalculationFunctionObject.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
defineNamedTemplateTypeNameAndDebug(abortCalculationFunctionObject, 0);
|
||||
|
||||
addToRunTimeSelectionTable
|
||||
(
|
||||
functionObject,
|
||||
abortCalculationFunctionObject,
|
||||
dictionary
|
||||
);
|
||||
}
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,54 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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 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/>.
|
||||
|
||||
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
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,49 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2010-2010 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 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/>.
|
||||
|
||||
Typedef
|
||||
Foam::IOresidualControl
|
||||
|
||||
Description
|
||||
Instance of the generic IOOutputFilter for residualControl.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef IOresidualControl_H
|
||||
#define IOresidualControl_H
|
||||
|
||||
#include "residualControl.H"
|
||||
#include "IOOutputFilter.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
typedef IOOutputFilter<residualControl> IOresidualControl;
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,68 @@
|
||||
/*--------------------------------*- C++ -*----------------------------------*\
|
||||
| ========= | |
|
||||
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
|
||||
| \\ / O peration | Version: 1.6 |
|
||||
| \\ / A nd | Web: www.OpenFOAM.org |
|
||||
| \\/ M anipulation | |
|
||||
\*---------------------------------------------------------------------------*/
|
||||
FoamFile
|
||||
{
|
||||
version 2.0;
|
||||
format ascii;
|
||||
class dictionary;
|
||||
location "system";
|
||||
object controlDict;
|
||||
}
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
application icoFoam;
|
||||
|
||||
startFrom startTime;
|
||||
|
||||
startTime 0;
|
||||
|
||||
stopAt endTime;
|
||||
|
||||
endTime 0.5;
|
||||
|
||||
deltaT 0.005;
|
||||
|
||||
writeControl timeStep;
|
||||
|
||||
writeInterval 20;
|
||||
|
||||
purgeWrite 0;
|
||||
|
||||
writeFormat ascii;
|
||||
|
||||
writePrecision 6;
|
||||
|
||||
writeCompression off;
|
||||
|
||||
timeFormat general;
|
||||
|
||||
timePrecision 6;
|
||||
|
||||
runTimeModifiable true;
|
||||
|
||||
functions
|
||||
{
|
||||
convergenceChecks
|
||||
{
|
||||
type residualControl;
|
||||
functionObjectLibs ( "libjobControl.so" );
|
||||
outputControl timeStep;
|
||||
outputInterval 1;
|
||||
|
||||
maxResiduals
|
||||
{
|
||||
p 5e-4;
|
||||
U 1e-3;
|
||||
|
||||
// possibly check turbulence fields
|
||||
"(k|epsilon|omega)" 1e-3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,169 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2010-2010 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 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 "residualControl.H"
|
||||
#include "fvMesh.H"
|
||||
#include "Time.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
defineTypeNameAndDebug(Foam::residualControl, 0);
|
||||
|
||||
|
||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||
|
||||
bool Foam::residualControl::checkCriteria(const bool verbose) const
|
||||
{
|
||||
bool achieved = true;
|
||||
const fvMesh& mesh = static_cast<const fvMesh&>(obr_);
|
||||
const dictionary& solverDict = mesh.solverPerformanceDict();
|
||||
|
||||
forAllConstIter(dictionary, solverDict, iter)
|
||||
{
|
||||
const word& variableName = iter().keyword();
|
||||
scalar maxResidual;
|
||||
|
||||
if (maxResiduals_.readIfPresent(variableName, maxResidual))
|
||||
{
|
||||
const scalar eqnResidual =
|
||||
lduMatrix::solverPerformance(iter().stream()).initialResidual();
|
||||
|
||||
achieved = achieved && (eqnResidual < maxResidual);
|
||||
|
||||
if (verbose)
|
||||
{
|
||||
Info<< " " << variableName
|
||||
<< ": requested max residual = " << maxResidual
|
||||
<< ", eqn residual = " << eqnResidual << nl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return achieved;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::residualControl::residualControl
|
||||
(
|
||||
const word& name,
|
||||
const objectRegistry& obr,
|
||||
const dictionary& dict,
|
||||
const bool
|
||||
)
|
||||
:
|
||||
name_(name),
|
||||
obr_(obr),
|
||||
active_(true),
|
||||
maxResiduals_(),
|
||||
criteriaSatisfied_(false)
|
||||
{
|
||||
// Only active if a fvMesh is available
|
||||
if (isA<fvMesh>(obr_))
|
||||
{
|
||||
read(dict);
|
||||
}
|
||||
else
|
||||
{
|
||||
active_ = false;
|
||||
WarningIn
|
||||
(
|
||||
"residualControl::residualControl"
|
||||
"("
|
||||
"const word&, "
|
||||
"const objectRegistry&, "
|
||||
"const dictionary&, "
|
||||
"const bool"
|
||||
")"
|
||||
) << "No fvMesh available, deactivating."
|
||||
<< nl << endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::residualControl::~residualControl()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::residualControl::read(const dictionary& dict)
|
||||
{
|
||||
if (active_)
|
||||
{
|
||||
maxResiduals_ = dict.subDict("maxResiduals");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::residualControl::execute()
|
||||
{
|
||||
if (active_)
|
||||
{
|
||||
criteriaSatisfied_ = checkCriteria(false);
|
||||
|
||||
if (criteriaSatisfied_)
|
||||
{
|
||||
Info<< "Convergence criteria satisfied - finalising run" << nl
|
||||
<< endl;
|
||||
|
||||
checkCriteria(true);
|
||||
|
||||
Info<< endl;
|
||||
|
||||
const fvMesh& mesh = static_cast<const fvMesh&>(obr_);
|
||||
Time& time = const_cast<Time&>(mesh.time());
|
||||
time.writeAndEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::residualControl::end()
|
||||
{
|
||||
if (active_)
|
||||
{
|
||||
if (criteriaSatisfied_)
|
||||
{
|
||||
Info<< "Residual control criteria satisfied" << nl;
|
||||
}
|
||||
else
|
||||
{
|
||||
Info<< "Residual control criteria not satisfied" << nl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::residualControl::write()
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,152 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2010-2010 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 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::residualControl
|
||||
|
||||
Description
|
||||
Function object that allows users to set target convergence criteria, and
|
||||
stop the run if the conditions are satisfied.
|
||||
|
||||
SourceFiles
|
||||
residualControl.C
|
||||
IOresidualControl.H
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef residualControl_H
|
||||
#define residualControl_H
|
||||
|
||||
#include "dictionary.H"
|
||||
#include "pointFieldFwd.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declaration of classes
|
||||
class objectRegistry;
|
||||
class dictionary;
|
||||
class mapPolyMesh;
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class residualControl Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class residualControl
|
||||
{
|
||||
protected:
|
||||
|
||||
// Private data
|
||||
|
||||
//- Name of this object
|
||||
word name_;
|
||||
|
||||
//- Reference to object registry
|
||||
const objectRegistry& obr_;
|
||||
|
||||
//- On/off switch - on if obr_ is an fvMesh object
|
||||
bool active_;
|
||||
|
||||
//- Dictionary of variable names vs max residual
|
||||
dictionary maxResiduals_;
|
||||
|
||||
//- Flag to indicate whether convergence criteria have been met
|
||||
bool criteriaSatisfied_;
|
||||
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
//- Perform residual control checks
|
||||
bool checkCriteria(const bool verbose) const;
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
residualControl(const residualControl&);
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const residualControl&);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("residualControl");
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct for given objectRegistry and dictionary.
|
||||
// Allow the possibility to load fields from files
|
||||
residualControl
|
||||
(
|
||||
const word& name,
|
||||
const objectRegistry& obr,
|
||||
const dictionary& dict,
|
||||
const bool loadFromFilesUnused = false
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~residualControl();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Return name of the residual criteria check name
|
||||
virtual const word& name() const
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
||||
//- Read the system calls
|
||||
virtual void read(const dictionary&);
|
||||
|
||||
//- Check the residual criteria at each time-step
|
||||
virtual void execute();
|
||||
|
||||
//- Report residual criteria check at the final time-loop
|
||||
virtual void end();
|
||||
|
||||
//- Write, not used
|
||||
virtual void write();
|
||||
|
||||
//- Update for changes of mesh
|
||||
virtual void updateMesh(const mapPolyMesh&)
|
||||
{}
|
||||
|
||||
//- Update for changes of mesh
|
||||
virtual void movePoints(const pointField&)
|
||||
{}
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,42 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2010-2010 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 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 "residualControlFunctionObject.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
defineNamedTemplateTypeNameAndDebug(residualControlFunctionObject, 0);
|
||||
|
||||
addToRunTimeSelectionTable
|
||||
(
|
||||
functionObject,
|
||||
residualControlFunctionObject,
|
||||
dictionary
|
||||
);
|
||||
}
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,54 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2010-2010 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 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/>.
|
||||
|
||||
Typedef
|
||||
Foam::residualControlFunctionObject
|
||||
|
||||
Description
|
||||
FunctionObject wrapper around residualControl to allow them to be created
|
||||
via the functions entry within controlDict.
|
||||
|
||||
SourceFiles
|
||||
residualControlFunctionObject.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef residualControlFunctionObject_H
|
||||
#define residualControlFunctionObject_H
|
||||
|
||||
#include "residualControl.H"
|
||||
#include "OutputFilterFunctionObject.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
typedef OutputFilterFunctionObject<residualControl>
|
||||
residualControlFunctionObject;
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
Reference in New Issue
Block a user