mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
MRG: Resolve conflict when merging branch merge-foundation
This commit is contained in:
30
src/functionObjects/utilities/Make/files
Normal file
30
src/functionObjects/utilities/Make/files
Normal file
@ -0,0 +1,30 @@
|
||||
abort/abort.C
|
||||
|
||||
codedFunctionObject/codedFunctionObject.C
|
||||
|
||||
removeRegisteredObject/removeRegisteredObject.C
|
||||
|
||||
residuals/residuals.C
|
||||
|
||||
runTimeControl/runTimeControl.C
|
||||
runTimeControl/runTimeCondition/runTimeCondition/runTimeCondition.C
|
||||
runTimeControl/runTimeCondition/runTimeCondition/runTimeConditionNew.C
|
||||
runTimeControl/runTimeCondition/equationMaxIterCondition/equationMaxIterCondition.C
|
||||
runTimeControl/runTimeCondition/equationInitialResidualCondition/equationInitialResidualCondition.C
|
||||
runTimeControl/runTimeCondition/minMaxCondition/minMaxCondition.C
|
||||
runTimeControl/runTimeCondition/averageCondition/averageCondition.C
|
||||
runTimeControl/runTimeCondition/minTimeStepCondition/minTimeStepCondition.C
|
||||
|
||||
setTimeStep/setTimeStepFunctionObject.C
|
||||
|
||||
systemCall/systemCall.C
|
||||
|
||||
timeActivatedFileUpdate/timeActivatedFileUpdate.C
|
||||
|
||||
writeDictionary/writeDictionary.C
|
||||
|
||||
writeObjects/writeObjects.C
|
||||
|
||||
thermoCoupleProbes/thermoCoupleProbes.C
|
||||
|
||||
LIB = $(FOAM_LIBBIN)/libutilityFunctionObjects
|
||||
12
src/functionObjects/utilities/Make/options
Normal file
12
src/functionObjects/utilities/Make/options
Normal file
@ -0,0 +1,12 @@
|
||||
EXE_INC = \
|
||||
-I$(LIB_SRC)/finiteVolume/lnInclude \
|
||||
-I$(LIB_SRC)/sampling/lnInclude \
|
||||
-I$(LIB_SRC)/ODE/lnInclude \
|
||||
-I$(LIB_SRC)/thermophysicalModels/basic/lnInclude \
|
||||
-I$(LIB_SRC)/transportModels/compressible/lnInclude
|
||||
|
||||
LIB_LIBS = \
|
||||
-lfiniteVolume \
|
||||
-lfluidThermophysicalModels \
|
||||
-lcompressibleTransportModels \
|
||||
-lODE
|
||||
201
src/functionObjects/utilities/abort/abort.C
Normal file
201
src/functionObjects/utilities/abort/abort.C
Normal file
@ -0,0 +1,201 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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 "abort.H"
|
||||
#include "dictionary.H"
|
||||
#include "error.H"
|
||||
#include "Time.H"
|
||||
#include "OSspecific.H"
|
||||
#include "PstreamReduceOps.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
defineTypeNameAndDebug(abort, 0);
|
||||
|
||||
addToRunTimeSelectionTable
|
||||
(
|
||||
functionObject,
|
||||
abort,
|
||||
dictionary
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
template<>
|
||||
const char* Foam::NamedEnum
|
||||
<
|
||||
Foam::functionObjects::abort::actionType,
|
||||
3
|
||||
>::names[] =
|
||||
{
|
||||
"noWriteNow",
|
||||
"writeNow",
|
||||
"nextWrite"
|
||||
};
|
||||
|
||||
const Foam::NamedEnum
|
||||
<
|
||||
Foam::functionObjects::abort::actionType,
|
||||
3
|
||||
> Foam::functionObjects::abort::actionTypeNames_;
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
void Foam::functionObjects::abort::removeFile() const
|
||||
{
|
||||
bool hasAbort = isFile(abortFile_);
|
||||
reduce(hasAbort, orOp<bool>());
|
||||
|
||||
if (hasAbort && Pstream::master())
|
||||
{
|
||||
// Cleanup ABORT file (on master only)
|
||||
rm(abortFile_);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::abort::abort
|
||||
(
|
||||
const word& name,
|
||||
const Time& runTime,
|
||||
const dictionary& dict
|
||||
)
|
||||
:
|
||||
functionObject(name),
|
||||
time_(runTime),
|
||||
abortFile_("$FOAM_CASE/" + name),
|
||||
action_(nextWrite)
|
||||
{
|
||||
abortFile_.expand();
|
||||
read(dict);
|
||||
|
||||
// Remove any old files from previous runs
|
||||
removeFile();
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::abort::~abort()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::abort::read(const dictionary& dict)
|
||||
{
|
||||
functionObject::read(dict);
|
||||
|
||||
if (dict.found("action"))
|
||||
{
|
||||
action_ = actionTypeNames_.read(dict.lookup("action"));
|
||||
}
|
||||
else
|
||||
{
|
||||
action_ = nextWrite;
|
||||
}
|
||||
|
||||
if (dict.readIfPresent("fileName", abortFile_))
|
||||
{
|
||||
abortFile_.expand();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::abort::execute()
|
||||
{
|
||||
bool hasAbort = isFile(abortFile_);
|
||||
reduce(hasAbort, orOp<bool>());
|
||||
|
||||
if (hasAbort)
|
||||
{
|
||||
switch (action_)
|
||||
{
|
||||
case noWriteNow :
|
||||
{
|
||||
if (time_.stopAt(Time::saNoWriteNow))
|
||||
{
|
||||
Info<< "USER REQUESTED ABORT (timeIndex="
|
||||
<< time_.timeIndex()
|
||||
<< "): stop without writing data"
|
||||
<< endl;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case writeNow :
|
||||
{
|
||||
if (time_.stopAt(Time::saWriteNow))
|
||||
{
|
||||
Info<< "USER REQUESTED ABORT (timeIndex="
|
||||
<< time_.timeIndex()
|
||||
<< "): stop+write data"
|
||||
<< endl;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case nextWrite :
|
||||
{
|
||||
if (time_.stopAt(Time::saNextWrite))
|
||||
{
|
||||
Info<< "USER REQUESTED ABORT (timeIndex="
|
||||
<< time_.timeIndex()
|
||||
<< "): stop after next data write"
|
||||
<< endl;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::abort::write()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::abort::end()
|
||||
{
|
||||
removeFile();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
152
src/functionObjects/utilities/abort/abort.H
Normal file
152
src/functionObjects/utilities/abort/abort.H
Normal file
@ -0,0 +1,152 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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::functionObjects::abort
|
||||
|
||||
Group
|
||||
grpUtilitiesFunctionObjects
|
||||
|
||||
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
|
||||
abort.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_abort_H
|
||||
#define functionObjects_abort_H
|
||||
|
||||
#include "functionObject.H"
|
||||
#include "NamedEnum.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class abort Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class abort
|
||||
:
|
||||
public functionObject
|
||||
{
|
||||
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
|
||||
|
||||
//- Reference to the Time
|
||||
const Time& time_;
|
||||
|
||||
//- 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
|
||||
abort(const abort&);
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const abort&);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("abort");
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from Time and dictionary
|
||||
abort
|
||||
(
|
||||
const word& name,
|
||||
const Time& runTime,
|
||||
const dictionary&
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~abort();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Read the dictionary settings
|
||||
virtual bool read(const dictionary&);
|
||||
|
||||
//- Execute, check existence of abort file and take action
|
||||
virtual bool execute();
|
||||
|
||||
//- Execute, check existence of abort file and take action
|
||||
virtual bool write();
|
||||
|
||||
//- Execute at the final time-loop, used for cleanup
|
||||
virtual bool end();
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,299 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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 "codedFunctionObject.H"
|
||||
#include "volFields.H"
|
||||
#include "dictionary.H"
|
||||
#include "Time.H"
|
||||
#include "SHA1Digest.H"
|
||||
#include "dynamicCode.H"
|
||||
#include "dynamicCodeContext.H"
|
||||
#include "stringOps.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
defineTypeNameAndDebug(codedFunctionObject, 0);
|
||||
|
||||
addToRunTimeSelectionTable
|
||||
(
|
||||
functionObject,
|
||||
codedFunctionObject,
|
||||
dictionary
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
void Foam::functionObjects::codedFunctionObject::prepare
|
||||
(
|
||||
dynamicCode& dynCode,
|
||||
const dynamicCodeContext& context
|
||||
) const
|
||||
{
|
||||
// Set additional rewrite rules
|
||||
dynCode.setFilterVariable("typeName", name_);
|
||||
dynCode.setFilterVariable("codeData", codeData_);
|
||||
dynCode.setFilterVariable("codeRead", codeRead_);
|
||||
dynCode.setFilterVariable("codeExecute", codeExecute_);
|
||||
dynCode.setFilterVariable("codeWrite", codeWrite_);
|
||||
dynCode.setFilterVariable("codeEnd", codeEnd_);
|
||||
|
||||
// Compile filtered C template
|
||||
dynCode.addCompileFile("functionObjectTemplate.C");
|
||||
|
||||
// Copy filtered H template
|
||||
dynCode.addCopyFile("functionObjectTemplate.H");
|
||||
|
||||
// Debugging: make BC verbose
|
||||
// dynCode.setFilterVariable("verbose", "true");
|
||||
// Info<<"compile " << name_ << " sha1: "
|
||||
// << context.sha1() << endl;
|
||||
|
||||
// Define Make/options
|
||||
dynCode.setMakeOptions
|
||||
(
|
||||
"EXE_INC = -g \\\n"
|
||||
"-I$(LIB_SRC)/finiteVolume/lnInclude \\\n"
|
||||
"-I$(LIB_SRC)/meshTools/lnInclude \\\n"
|
||||
+ context.options()
|
||||
+ "\n\nLIB_LIBS = \\\n"
|
||||
+ " -lOpenFOAM \\\n"
|
||||
+ " -lfiniteVolume \\\n"
|
||||
+ " -lmeshTools \\\n"
|
||||
+ context.libs()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Foam::dlLibraryTable& Foam::functionObjects::codedFunctionObject::libs() const
|
||||
{
|
||||
return const_cast<Time&>(time_).libs();
|
||||
}
|
||||
|
||||
|
||||
Foam::string Foam::functionObjects::codedFunctionObject::description() const
|
||||
{
|
||||
return "functionObject " + name();
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::codedFunctionObject::clearRedirect() const
|
||||
{
|
||||
redirectFunctionObjectPtr_.clear();
|
||||
}
|
||||
|
||||
|
||||
const Foam::dictionary&
|
||||
Foam::functionObjects::codedFunctionObject::codeDict() const
|
||||
{
|
||||
return dict_;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::codedFunctionObject::codedFunctionObject
|
||||
(
|
||||
const word& name,
|
||||
const Time& time,
|
||||
const dictionary& dict
|
||||
)
|
||||
:
|
||||
functionObject(name),
|
||||
codedBase(),
|
||||
time_(time),
|
||||
dict_(dict)
|
||||
{
|
||||
read(dict_);
|
||||
|
||||
updateLibrary(name_);
|
||||
redirectFunctionObject();
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::codedFunctionObject::~codedFunctionObject()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObject&
|
||||
Foam::functionObjects::codedFunctionObject::redirectFunctionObject() const
|
||||
{
|
||||
if (!redirectFunctionObjectPtr_.valid())
|
||||
{
|
||||
dictionary constructDict(dict_);
|
||||
constructDict.set("type", name_);
|
||||
|
||||
redirectFunctionObjectPtr_ = functionObject::New
|
||||
(
|
||||
name_,
|
||||
time_,
|
||||
constructDict
|
||||
);
|
||||
}
|
||||
return redirectFunctionObjectPtr_();
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::codedFunctionObject::execute()
|
||||
{
|
||||
updateLibrary(name_);
|
||||
return redirectFunctionObject().execute();
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::codedFunctionObject::write()
|
||||
{
|
||||
updateLibrary(name_);
|
||||
return redirectFunctionObject().write();
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::codedFunctionObject::end()
|
||||
{
|
||||
updateLibrary(name_);
|
||||
return redirectFunctionObject().end();
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::codedFunctionObject::read(const dictionary& dict)
|
||||
{
|
||||
functionObject::read(dict);
|
||||
|
||||
// Backward compatibility
|
||||
if (dict.found("redirectType"))
|
||||
{
|
||||
dict.lookup("redirectType") >> name_;
|
||||
}
|
||||
else
|
||||
{
|
||||
dict.lookup("name") >> name_;
|
||||
}
|
||||
|
||||
const entry* dataPtr = dict.lookupEntryPtr
|
||||
(
|
||||
"codeData",
|
||||
false,
|
||||
false
|
||||
);
|
||||
if (dataPtr)
|
||||
{
|
||||
codeData_ = stringOps::trim(dataPtr->stream());
|
||||
stringOps::inplaceExpand(codeData_, dict);
|
||||
dynamicCodeContext::addLineDirective
|
||||
(
|
||||
codeData_,
|
||||
dataPtr->startLineNumber(),
|
||||
dict.name()
|
||||
);
|
||||
}
|
||||
|
||||
const entry* readPtr = dict.lookupEntryPtr
|
||||
(
|
||||
"codeRead",
|
||||
false,
|
||||
false
|
||||
);
|
||||
if (readPtr)
|
||||
{
|
||||
codeRead_ = stringOps::trim(readPtr->stream());
|
||||
stringOps::inplaceExpand(codeRead_, dict);
|
||||
dynamicCodeContext::addLineDirective
|
||||
(
|
||||
codeRead_,
|
||||
readPtr->startLineNumber(),
|
||||
dict.name()
|
||||
);
|
||||
}
|
||||
|
||||
const entry* execPtr = dict.lookupEntryPtr
|
||||
(
|
||||
"codeExecute",
|
||||
false,
|
||||
false
|
||||
);
|
||||
if (execPtr)
|
||||
{
|
||||
codeExecute_ = stringOps::trim(execPtr->stream());
|
||||
stringOps::inplaceExpand(codeExecute_, dict);
|
||||
dynamicCodeContext::addLineDirective
|
||||
(
|
||||
codeExecute_,
|
||||
execPtr->startLineNumber(),
|
||||
dict.name()
|
||||
);
|
||||
}
|
||||
|
||||
const entry* writePtr = dict.lookupEntryPtr
|
||||
(
|
||||
"codeWrite",
|
||||
false,
|
||||
false
|
||||
);
|
||||
if (writePtr)
|
||||
{
|
||||
codeWrite_ = stringOps::trim(writePtr->stream());
|
||||
stringOps::inplaceExpand(codeWrite_, dict);
|
||||
dynamicCodeContext::addLineDirective
|
||||
(
|
||||
codeWrite_,
|
||||
writePtr->startLineNumber(),
|
||||
dict.name()
|
||||
);
|
||||
}
|
||||
|
||||
const entry* endPtr = dict.lookupEntryPtr
|
||||
(
|
||||
"codeEnd",
|
||||
false,
|
||||
false
|
||||
);
|
||||
if (endPtr)
|
||||
{
|
||||
codeEnd_ = stringOps::trim(endPtr->stream());
|
||||
stringOps::inplaceExpand(codeEnd_, dict);
|
||||
dynamicCodeContext::addLineDirective
|
||||
(
|
||||
codeEnd_,
|
||||
endPtr->startLineNumber(),
|
||||
dict.name()
|
||||
);
|
||||
}
|
||||
|
||||
updateLibrary(name_);
|
||||
return redirectFunctionObject().read(dict);
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,199 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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::functionObjects::codedFunctionObject
|
||||
|
||||
Group
|
||||
grpUtilitiesFunctionObjects
|
||||
|
||||
Description
|
||||
Provides a general interface to enable dynamic code compilation.
|
||||
|
||||
The entries are
|
||||
codeInclude : include files
|
||||
codeOptions : include paths; inserted into EXE_INC in Make/options
|
||||
codeLibs : link line; inserted into LIB_LIBS in Make/options
|
||||
codeData : c++; local member data (null constructed);
|
||||
localCode : c++; local static functions
|
||||
codeRead : c++; upon functionObject::read();
|
||||
codeExecute : c++;upon functionObject::execute();
|
||||
codeWrite : c++; upon functionObject::write()
|
||||
codeEnd : c++; upon functionObject::end();
|
||||
|
||||
Usage
|
||||
Example of function object specification:
|
||||
\verbatim
|
||||
difference
|
||||
{
|
||||
libs ("libutilityFunctionObjects.so");
|
||||
|
||||
type coded;
|
||||
// Name of on-the-fly generated functionObject
|
||||
name writeMagU;
|
||||
codeWrite
|
||||
#{
|
||||
// Lookup U
|
||||
const volVectorField& U = mesh().lookupObject<volVectorField>("U");
|
||||
// Write
|
||||
mag(U).write();
|
||||
}
|
||||
}
|
||||
\endverbatim
|
||||
|
||||
|
||||
See also
|
||||
Foam::functionObject
|
||||
Foam::codedBase
|
||||
|
||||
SourceFiles
|
||||
codedFunctionObject.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_codedFunctionObject_H
|
||||
#define functionObjects_codedFunctionObject_H
|
||||
|
||||
#include "functionObject.H"
|
||||
#include "codedBase.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class codedFunctionObject Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class codedFunctionObject
|
||||
:
|
||||
public functionObject,
|
||||
public codedBase
|
||||
{
|
||||
protected:
|
||||
|
||||
// Protected data
|
||||
|
||||
//- Reference to the time database
|
||||
const Time& time_;
|
||||
|
||||
//- Input dictionary
|
||||
dictionary dict_;
|
||||
|
||||
word name_;
|
||||
|
||||
string codeData_;
|
||||
string codeRead_;
|
||||
string codeExecute_;
|
||||
string codeWrite_;
|
||||
string codeEnd_;
|
||||
|
||||
//- Underlying functionObject
|
||||
mutable autoPtr<functionObject> redirectFunctionObjectPtr_;
|
||||
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
//- Get the loaded dynamic libraries
|
||||
virtual dlLibraryTable& libs() const;
|
||||
|
||||
//- Adapt the context for the current object
|
||||
virtual void prepare(dynamicCode&, const dynamicCodeContext&) const;
|
||||
|
||||
// Return a description (type + name) for the output
|
||||
virtual string description() const;
|
||||
|
||||
// Clear any redirected objects
|
||||
virtual void clearRedirect() const;
|
||||
|
||||
// Get the dictionary to initialize the codeContext
|
||||
virtual const dictionary& codeDict() const;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
codedFunctionObject(const codedFunctionObject&);
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const codedFunctionObject&);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("coded");
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from Time and dictionary
|
||||
codedFunctionObject
|
||||
(
|
||||
const word& name,
|
||||
const Time& time,
|
||||
const dictionary& dict
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~codedFunctionObject();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Dynamically compiled functionObject
|
||||
functionObject& redirectFunctionObject() const;
|
||||
|
||||
//- 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();
|
||||
|
||||
//- Called at each ++ or += of the time-loop.
|
||||
// postProcess overrides the usual writeControl behaviour and
|
||||
// forces writing always (used in post-processing mode)
|
||||
virtual bool write();
|
||||
|
||||
//- Called when Time::run() determines that the time-loop exits.
|
||||
// By default it simply calls execute().
|
||||
virtual bool end();
|
||||
|
||||
//- Read and set the function object if its data have changed
|
||||
virtual bool read(const dictionary&);
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,33 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2012-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/>.
|
||||
|
||||
\defgroup grpUtilitiesFunctionObjects Utility function objects
|
||||
@{
|
||||
\ingroup grpFunctionObjects
|
||||
This group contains utility-based function objects
|
||||
|
||||
Function objects in this group are packaged into the
|
||||
libutilityFunctionObjects.so library.
|
||||
@}
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
@ -0,0 +1,114 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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 "removeRegisteredObject.H"
|
||||
#include "Time.H"
|
||||
#include "polyMesh.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
defineTypeNameAndDebug(removeRegisteredObject, 0);
|
||||
|
||||
addToRunTimeSelectionTable
|
||||
(
|
||||
functionObject,
|
||||
removeRegisteredObject,
|
||||
dictionary
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::removeRegisteredObject::removeRegisteredObject
|
||||
(
|
||||
const word& name,
|
||||
const Time& runTime,
|
||||
const dictionary& dict
|
||||
)
|
||||
:
|
||||
regionFunctionObject(name, runTime, dict),
|
||||
objectNames_()
|
||||
{
|
||||
read(dict);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::removeRegisteredObject::~removeRegisteredObject()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::removeRegisteredObject::read(const dictionary& dict)
|
||||
{
|
||||
regionFunctionObject::read(dict);
|
||||
|
||||
dict.lookup("objects") >> objectNames_;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::removeRegisteredObject::execute()
|
||||
{
|
||||
forAll(objectNames_, i)
|
||||
{
|
||||
if (foundObject<regIOobject>(objectNames_[i]))
|
||||
{
|
||||
const regIOobject& obj =
|
||||
lookupObject<regIOobject>(objectNames_[i]);
|
||||
|
||||
if (obj.ownedByRegistry())
|
||||
{
|
||||
Log << type() << " " << name() << " output:" << nl
|
||||
<< " removing object " << obj.name() << nl
|
||||
<< endl;
|
||||
|
||||
const_cast<regIOobject&>(obj).release();
|
||||
delete &obj;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::removeRegisteredObject::write()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,139 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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::functionObjects::removeRegisteredObject
|
||||
|
||||
Group
|
||||
grpUtilitiesFunctionObjects
|
||||
|
||||
Description
|
||||
Removes registered objects if present in the database.
|
||||
|
||||
Usage
|
||||
Example of function object specification:
|
||||
\verbatim
|
||||
removeRegisteredObject1
|
||||
{
|
||||
type removeRegisteredObject;
|
||||
libs ("libutilityFunctionObjects.so");
|
||||
...
|
||||
objects (obj1 obj2);
|
||||
}
|
||||
\endverbatim
|
||||
|
||||
Where the entries comprise:
|
||||
\table
|
||||
Property | Description | Required | Default value
|
||||
type | type name: removeRegisteredObject | yes |
|
||||
objects | objects to remove | yes |
|
||||
\endtable
|
||||
|
||||
See also
|
||||
Foam::functionObject
|
||||
|
||||
SourceFiles
|
||||
removeRegisteredObject.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_removeRegisteredObject_H
|
||||
#define functionObjects_removeRegisteredObject_H
|
||||
|
||||
#include "regionFunctionObject.H"
|
||||
#include "wordList.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class removeRegisteredObject Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class removeRegisteredObject
|
||||
:
|
||||
public regionFunctionObject
|
||||
{
|
||||
// Private data
|
||||
|
||||
//- Names of objects to control
|
||||
wordList objectNames_;
|
||||
|
||||
|
||||
// Private member functions
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
removeRegisteredObject(const removeRegisteredObject&);
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const removeRegisteredObject&);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("removeRegisteredObject");
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from Time and dictionary
|
||||
removeRegisteredObject
|
||||
(
|
||||
const word& name,
|
||||
const Time& runTime,
|
||||
const dictionary& dict
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~removeRegisteredObject();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Read the removeRegisteredObject data
|
||||
virtual bool read(const dictionary&);
|
||||
|
||||
//- Remove the registered objects
|
||||
virtual bool execute();
|
||||
|
||||
//- Do nothing
|
||||
virtual bool write();
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
137
src/functionObjects/utilities/residuals/residuals.C
Normal file
137
src/functionObjects/utilities/residuals/residuals.C
Normal file
@ -0,0 +1,137 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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 "residuals.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
defineTypeNameAndDebug(residuals, 0);
|
||||
|
||||
addToRunTimeSelectionTable
|
||||
(
|
||||
functionObject,
|
||||
residuals,
|
||||
dictionary
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
|
||||
|
||||
void Foam::functionObjects::residuals::writeFileHeader(Ostream& os) const
|
||||
{
|
||||
writeHeader(os, "Residuals");
|
||||
writeCommented(os, "Time");
|
||||
|
||||
forAll(fieldSet_, fieldi)
|
||||
{
|
||||
const word& fieldName = fieldSet_[fieldi];
|
||||
|
||||
writeFileHeader<scalar>(os, fieldName);
|
||||
writeFileHeader<vector>(os, fieldName);
|
||||
writeFileHeader<sphericalTensor>(os, fieldName);
|
||||
writeFileHeader<symmTensor>(os, fieldName);
|
||||
writeFileHeader<tensor>(os, fieldName);
|
||||
}
|
||||
|
||||
os << endl;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::residuals::residuals
|
||||
(
|
||||
const word& name,
|
||||
const Time& runTime,
|
||||
const dictionary& dict
|
||||
)
|
||||
:
|
||||
fvMeshFunctionObject(name, runTime, dict),
|
||||
writeFile(obr_, name, typeName, dict),
|
||||
fieldSet_()
|
||||
{
|
||||
read(dict);
|
||||
writeFileHeader(file());
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::residuals::~residuals()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::residuals::read(const dictionary& dict)
|
||||
{
|
||||
fvMeshFunctionObject::read(dict);
|
||||
|
||||
wordList allFields(dict.lookup("fields"));
|
||||
wordHashSet uniqueFields(allFields);
|
||||
fieldSet_ = uniqueFields.toc();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::residuals::execute()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::residuals::write()
|
||||
{
|
||||
if (Pstream::master())
|
||||
{
|
||||
writeTime(file());
|
||||
|
||||
forAll(fieldSet_, fieldi)
|
||||
{
|
||||
const word& fieldName = fieldSet_[fieldi];
|
||||
|
||||
writeResidual<scalar>(fieldName);
|
||||
writeResidual<vector>(fieldName);
|
||||
writeResidual<sphericalTensor>(fieldName);
|
||||
writeResidual<symmTensor>(fieldName);
|
||||
writeResidual<tensor>(fieldName);
|
||||
}
|
||||
|
||||
file() << endl;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
164
src/functionObjects/utilities/residuals/residuals.H
Normal file
164
src/functionObjects/utilities/residuals/residuals.H
Normal file
@ -0,0 +1,164 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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::functionObjects::residuals
|
||||
|
||||
Group
|
||||
grpUtilitiesFunctionObjects
|
||||
|
||||
Description
|
||||
Writes out the initial residual for specified fields.
|
||||
|
||||
Usage
|
||||
Example of function object specification:
|
||||
\verbatim
|
||||
residuals
|
||||
{
|
||||
type residuals;
|
||||
libs ("libutilityFunctionObjects.so");
|
||||
...
|
||||
fields (U p);
|
||||
}
|
||||
\endverbatim
|
||||
|
||||
Output data is written to the dir postProcessing/residuals/\<timeDir\>/
|
||||
For vector/tensor fields, e.g. U, where an equation is solved for each
|
||||
component, the largest residual of each component is written out.
|
||||
|
||||
See also
|
||||
Foam::functionObject
|
||||
Foam::functionObjects::fvMeshFunctionObject
|
||||
Foam::functionObjects::writeFiles
|
||||
Foam::functionObjects::timeControl
|
||||
|
||||
SourceFiles
|
||||
residuals.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_residuals_H
|
||||
#define functionObjects_residuals_H
|
||||
|
||||
#include "fvMeshFunctionObject.H"
|
||||
#include "logFiles.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class residuals Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class residuals
|
||||
:
|
||||
public fvMeshFunctionObject,
|
||||
public writeFile
|
||||
{
|
||||
protected:
|
||||
|
||||
// Protected data
|
||||
|
||||
//- Fields to write residuals
|
||||
wordList fieldSet_;
|
||||
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
//- Output file header information
|
||||
void writeFileHeader(Ostream& os) const;
|
||||
|
||||
//- Output file header information per primitive type value
|
||||
template<class Type>
|
||||
void writeFileHeader(Ostream& os, const word& fileName) const;
|
||||
|
||||
//- Calculate the field min/max
|
||||
template<class Type>
|
||||
void writeResidual(const word& fieldName);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
// Private member functions
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
residuals(const residuals&) = delete;
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const residuals&) = delete;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("residuals");
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from Time and dictionary
|
||||
residuals
|
||||
(
|
||||
const word& name,
|
||||
const Time& runTime,
|
||||
const dictionary& dict
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~residuals();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Read the controls
|
||||
virtual bool read(const dictionary&);
|
||||
|
||||
//- Execute, currently does nothing
|
||||
virtual bool execute();
|
||||
|
||||
//- Write the residuals
|
||||
virtual bool write();
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef NoRepository
|
||||
#include "residualsTemplates.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
104
src/functionObjects/utilities/residuals/residualsTemplates.C
Normal file
104
src/functionObjects/utilities/residuals/residualsTemplates.C
Normal file
@ -0,0 +1,104 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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 "residuals.H"
|
||||
#include "volFields.H"
|
||||
#include "ListOps.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
void Foam::functionObjects::residuals::writeFileHeader
|
||||
(
|
||||
Ostream& os,
|
||||
const word& fieldName
|
||||
) const
|
||||
{
|
||||
typedef GeometricField<Type, fvPatchField, volMesh> fieldType;
|
||||
|
||||
if (foundObject<fieldType>(fieldName))
|
||||
{
|
||||
typename pTraits<Type>::labelType validComponents
|
||||
(
|
||||
mesh_.validComponents<Type>()
|
||||
);
|
||||
|
||||
for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++)
|
||||
{
|
||||
if (component(validComponents, cmpt) != -1)
|
||||
{
|
||||
writeTabbed
|
||||
(
|
||||
os,
|
||||
fieldName + word(pTraits<Type>::componentNames[cmpt])
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
void Foam::functionObjects::residuals::writeResidual(const word& fieldName)
|
||||
{
|
||||
typedef GeometricField<Type, fvPatchField, volMesh> fieldType;
|
||||
|
||||
if (foundObject<fieldType>(fieldName))
|
||||
{
|
||||
const Foam::dictionary& solverDict = mesh_.solverPerformanceDict();
|
||||
|
||||
if (solverDict.found(fieldName))
|
||||
{
|
||||
const List<SolverPerformance<Type>> sp
|
||||
(
|
||||
solverDict.lookup(fieldName)
|
||||
);
|
||||
|
||||
const Type& residual = sp.first().initialResidual();
|
||||
|
||||
typename pTraits<Type>::labelType validComponents
|
||||
(
|
||||
mesh_.validComponents<Type>()
|
||||
);
|
||||
|
||||
for (direction cmpt=0; cmpt<pTraits<Type>::nComponents; cmpt++)
|
||||
{
|
||||
if (component(validComponents, cmpt) != -1)
|
||||
{
|
||||
const scalar r = component(residual, cmpt);
|
||||
|
||||
file() << token::TAB << r;
|
||||
|
||||
const word resultName =
|
||||
fieldName + word(pTraits<Type>::componentNames[cmpt]);
|
||||
setResult(resultName, r);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,185 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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 "averageCondition.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
#include "Time.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace runTimeControls
|
||||
{
|
||||
defineTypeNameAndDebug(averageCondition, 0);
|
||||
addToRunTimeSelectionTable(runTimeCondition, averageCondition, dictionary);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimeControls::averageCondition::averageCondition
|
||||
(
|
||||
const word& name,
|
||||
const objectRegistry& obr,
|
||||
const dictionary& dict,
|
||||
stateFunctionObject& state
|
||||
)
|
||||
:
|
||||
runTimeCondition(name, obr, dict, state),
|
||||
functionObjectName_(dict.lookup("functionObjectName")),
|
||||
fieldNames_(dict.lookup("fields")),
|
||||
tolerance_(readScalar(dict.lookup("tolerance"))),
|
||||
window_(dict.lookupOrDefault<scalar>("window", -1)),
|
||||
totalTime_(fieldNames_.size(), obr_.time().deltaTValue()),
|
||||
resetOnRestart_(false)
|
||||
{
|
||||
if (resetOnRestart_)
|
||||
{
|
||||
const dictionary& dict = conditionDict();
|
||||
|
||||
forAll(fieldNames_, fieldi)
|
||||
{
|
||||
const word& fieldName = fieldNames_[fieldi];
|
||||
|
||||
if (dict.found(fieldName))
|
||||
{
|
||||
const dictionary& valueDict = dict.subDict(fieldName);
|
||||
totalTime_[fieldi] = readScalar(valueDict.lookup("totalTime"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimeControls::averageCondition::~averageCondition()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::runTimeControls::averageCondition::apply()
|
||||
{
|
||||
bool satisfied = true;
|
||||
|
||||
if (!active_)
|
||||
{
|
||||
return satisfied;
|
||||
}
|
||||
|
||||
scalar dt = obr_.time().deltaTValue();
|
||||
|
||||
if (log_) Info<< " " << type() << ": " << name_ << " averages:" << nl;
|
||||
|
||||
DynamicList<label> unprocessedFields(fieldNames_.size());
|
||||
|
||||
forAll(fieldNames_, fieldi)
|
||||
{
|
||||
const word& fieldName(fieldNames_[fieldi]);
|
||||
|
||||
scalar Dt = totalTime_[fieldi];
|
||||
scalar alpha = (Dt - dt)/Dt;
|
||||
scalar beta = dt/Dt;
|
||||
|
||||
if (window_ > 0)
|
||||
{
|
||||
if (Dt - dt >= window_)
|
||||
{
|
||||
alpha = (window_ - dt)/window_;
|
||||
beta = dt/window_;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Ensure that averaging is performed over window time
|
||||
// before condition can be satisfied
|
||||
satisfied = false;
|
||||
}
|
||||
}
|
||||
|
||||
bool processed = false;
|
||||
calc<scalar>(fieldName, alpha, beta, satisfied, processed);
|
||||
calc<vector>(fieldName, alpha, beta, satisfied, processed);
|
||||
calc<sphericalTensor>(fieldName, alpha, beta, satisfied, processed);
|
||||
calc<symmTensor>(fieldName, alpha, beta, satisfied, processed);
|
||||
calc<tensor>(fieldName, alpha, beta, satisfied, processed);
|
||||
|
||||
if (!processed)
|
||||
{
|
||||
unprocessedFields.append(fieldi);
|
||||
}
|
||||
|
||||
totalTime_[fieldi] += dt;
|
||||
}
|
||||
|
||||
if (unprocessedFields.size())
|
||||
{
|
||||
WarningInFunction
|
||||
<< "From function object: " << functionObjectName_ << nl
|
||||
<< "Unprocessed fields:" << nl;
|
||||
|
||||
forAll(unprocessedFields, i)
|
||||
{
|
||||
label fieldi = unprocessedFields[i];
|
||||
Info<< " " << fieldNames_[fieldi] << nl;
|
||||
}
|
||||
}
|
||||
|
||||
if (log_) Info<< endl;
|
||||
|
||||
return satisfied;
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::runTimeControls::averageCondition::write()
|
||||
{
|
||||
dictionary& conditionDict = this->conditionDict();
|
||||
|
||||
forAll(fieldNames_, fieldi)
|
||||
{
|
||||
const word& fieldName = fieldNames_[fieldi];
|
||||
|
||||
// value dictionary should be present - mean values are written there
|
||||
if (conditionDict.found(fieldName))
|
||||
{
|
||||
dictionary& valueDict = conditionDict.subDict(fieldName);
|
||||
valueDict.add("totalTime", totalTime_[fieldi], true);
|
||||
}
|
||||
else
|
||||
{
|
||||
dictionary valueDict;
|
||||
valueDict.add("totalTime", totalTime_[fieldi], true);
|
||||
conditionDict.add(fieldName, valueDict);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,142 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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::functionObjects::runTimeControls::averageCondition
|
||||
|
||||
Description
|
||||
Average run time condition - satisfied when average does not change by
|
||||
more than a given value.
|
||||
|
||||
SourceFiles
|
||||
averageCondition.H
|
||||
averageCondition.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef averageCondition_H
|
||||
#define averageCondition_H
|
||||
|
||||
#include "runTimeCondition.H"
|
||||
#include "Switch.H"
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace runTimeControls
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class averageCondition Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class averageCondition
|
||||
:
|
||||
public runTimeCondition
|
||||
{
|
||||
protected:
|
||||
|
||||
// Protected data
|
||||
|
||||
//- Name of function object to retrueve data from
|
||||
word functionObjectName_;
|
||||
|
||||
//- List of fields on which to operate
|
||||
wordList fieldNames_;
|
||||
|
||||
//- Satisfied when difference in mean values is less than this value
|
||||
const scalar tolerance_;
|
||||
|
||||
//- Averaging window
|
||||
const scalar window_;
|
||||
|
||||
//- Average time per field
|
||||
List<scalar> totalTime_;
|
||||
|
||||
//- Reset the averaging process on restart flag
|
||||
Switch resetOnRestart_;
|
||||
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
//- Templated function to calculate the average
|
||||
template<class Type>
|
||||
void calc
|
||||
(
|
||||
const word& fieldName,
|
||||
const scalar alpha,
|
||||
const scalar beta,
|
||||
bool& satisfied,
|
||||
bool& processed
|
||||
);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("average");
|
||||
|
||||
//- Constructor
|
||||
averageCondition
|
||||
(
|
||||
const word& name,
|
||||
const objectRegistry& obr,
|
||||
const dictionary& dict,
|
||||
stateFunctionObject& state
|
||||
);
|
||||
|
||||
//- Destructor
|
||||
virtual ~averageCondition();
|
||||
|
||||
|
||||
// Public Member Functions
|
||||
|
||||
//- Apply the condition
|
||||
virtual bool apply();
|
||||
|
||||
//- Write
|
||||
virtual void write();
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace runTimeControls
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef NoRepository
|
||||
#include "averageConditionTemplates.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,73 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
void Foam::functionObjects::runTimeControls::averageCondition::calc
|
||||
(
|
||||
const word& fieldName,
|
||||
const scalar alpha,
|
||||
const scalar beta,
|
||||
bool& satisfied,
|
||||
bool& processed
|
||||
)
|
||||
{
|
||||
const word valueType =
|
||||
state_.objectResultType(functionObjectName_, fieldName);
|
||||
|
||||
if (pTraits<Type>::typeName != valueType)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Type currentValue =
|
||||
state_.getObjectResult<Type>(functionObjectName_, fieldName);
|
||||
|
||||
const word meanName(fieldName + "Mean");
|
||||
|
||||
Type meanValue = state_.getResult<Type>(meanName);
|
||||
meanValue = alpha*meanValue + beta*currentValue;
|
||||
|
||||
scalar delta = mag(meanValue - currentValue);
|
||||
|
||||
if (log_)
|
||||
{
|
||||
Info<< " " << meanName << ": " << meanValue
|
||||
<< ", delta: " << delta << nl;
|
||||
}
|
||||
|
||||
state_.setResult(meanName, meanValue);
|
||||
|
||||
if (delta > tolerance_)
|
||||
{
|
||||
satisfied = false;
|
||||
}
|
||||
|
||||
processed = true;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,231 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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 "equationInitialResidualCondition.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
#include "fvMesh.H"
|
||||
#include "Time.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace runTimeControls
|
||||
{
|
||||
defineTypeNameAndDebug(equationInitialResidualCondition, 0);
|
||||
addToRunTimeSelectionTable
|
||||
(
|
||||
runTimeCondition,
|
||||
equationInitialResidualCondition,
|
||||
dictionary
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
template<>
|
||||
const char* Foam::NamedEnum
|
||||
<
|
||||
Foam
|
||||
::functionObjects
|
||||
::runTimeControls
|
||||
::equationInitialResidualCondition
|
||||
::operatingMode,
|
||||
2
|
||||
>::names[] =
|
||||
{
|
||||
"minimum",
|
||||
"maximum"
|
||||
};
|
||||
|
||||
const Foam::NamedEnum
|
||||
<
|
||||
Foam
|
||||
::functionObjects
|
||||
::runTimeControls
|
||||
::equationInitialResidualCondition
|
||||
::operatingMode,
|
||||
2
|
||||
>
|
||||
Foam::functionObjects::runTimeControls::equationInitialResidualCondition::
|
||||
operatingModeNames;
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimeControls::equationInitialResidualCondition::
|
||||
equationInitialResidualCondition
|
||||
(
|
||||
const word& name,
|
||||
const objectRegistry& obr,
|
||||
const dictionary& dict,
|
||||
stateFunctionObject& state
|
||||
)
|
||||
:
|
||||
runTimeCondition(name, obr, dict, state),
|
||||
fieldNames_(dict.lookup("fields")),
|
||||
value_(readScalar(dict.lookup("value"))),
|
||||
timeStart_(dict.lookupOrDefault("timeStart", -GREAT)),
|
||||
mode_(operatingModeNames.read(dict.lookup("mode")))
|
||||
{
|
||||
if (!fieldNames_.size())
|
||||
{
|
||||
WarningInFunction
|
||||
<< "No fields supplied: deactivating" << endl;
|
||||
|
||||
active_ = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimeControls::equationInitialResidualCondition::
|
||||
~equationInitialResidualCondition()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::runTimeControls::equationInitialResidualCondition::
|
||||
apply()
|
||||
{
|
||||
bool satisfied = false;
|
||||
|
||||
if (!active_)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((obr_.time().timeIndex() < 3) || (obr_.time().value() < timeStart_))
|
||||
{
|
||||
// Do not start checking until reached start time
|
||||
return false;
|
||||
}
|
||||
|
||||
const fvMesh& mesh = refCast<const fvMesh>(obr_);
|
||||
const dictionary& solverDict = mesh.solverPerformanceDict();
|
||||
|
||||
List<scalar> result(fieldNames_.size(), -VGREAT);
|
||||
|
||||
forAll(fieldNames_, fieldi)
|
||||
{
|
||||
const word& fieldName = fieldNames_[fieldi];
|
||||
|
||||
if (solverDict.found(fieldName))
|
||||
{
|
||||
const List<solverPerformance> sp(solverDict.lookup(fieldName));
|
||||
const scalar residual = sp.first().initialResidual();
|
||||
result[fieldi] = residual;
|
||||
|
||||
switch (mode_)
|
||||
{
|
||||
case omMin:
|
||||
{
|
||||
if (residual < value_)
|
||||
{
|
||||
satisfied = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case omMax:
|
||||
{
|
||||
if (residual > value_)
|
||||
{
|
||||
satisfied = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Unhandled enumeration "
|
||||
<< operatingModeNames[mode_]
|
||||
<< abort(FatalError);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool valid = false;
|
||||
forAll(result, i)
|
||||
{
|
||||
if (result[i] < 0)
|
||||
{
|
||||
WarningInFunction
|
||||
<< "Initial residual data not found for field "
|
||||
<< fieldNames_[i] << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
valid = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!valid)
|
||||
{
|
||||
WarningInFunction
|
||||
<< "Initial residual data not found for any fields: "
|
||||
<< "deactivating" << endl;
|
||||
|
||||
active_ = false;
|
||||
}
|
||||
|
||||
if (satisfied && valid)
|
||||
{
|
||||
if (log_)
|
||||
{
|
||||
Info<< type() << ": " << name_
|
||||
<< ": satisfied using threshold value: " << value_ << nl;
|
||||
}
|
||||
|
||||
forAll(result, resulti)
|
||||
{
|
||||
if (result[resulti] > 0)
|
||||
{
|
||||
if (log_)
|
||||
{
|
||||
Info<< " field: " << fieldNames_[resulti]
|
||||
<< ", residual: " << result[resulti] << nl;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (log_) Info<< endl;
|
||||
}
|
||||
|
||||
return satisfied;
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::runTimeControls::equationInitialResidualCondition::
|
||||
write()
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,125 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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::functionObjects::runTimeControls::equationInitialResidualCondition
|
||||
|
||||
Description
|
||||
Minimum or maximum initial residual run time condition
|
||||
|
||||
SourceFiles
|
||||
equationInitialResidualCondition.H
|
||||
equationInitialResidualCondition.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_runTimeControls_equationInitialResidualCondition_H
|
||||
#define functionObjects_runTimeControls_equationInitialResidualCondition_H
|
||||
|
||||
#include "runTimeCondition.H"
|
||||
#include "NamedEnum.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace runTimeControls
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class equationInitialResidualCondition Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class equationInitialResidualCondition
|
||||
:
|
||||
public runTimeCondition
|
||||
{
|
||||
public:
|
||||
|
||||
enum operatingMode
|
||||
{
|
||||
omMin, //!< Minimum
|
||||
omMax //!< Maximum
|
||||
};
|
||||
|
||||
static const NamedEnum<operatingMode, 2> operatingModeNames;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// Protected data
|
||||
|
||||
//- Field name
|
||||
const wordList fieldNames_;
|
||||
|
||||
//- Value to compare
|
||||
const scalar value_;
|
||||
|
||||
//- Start checking from time - always skips first iteration
|
||||
scalar timeStart_;
|
||||
|
||||
//- Operating mode
|
||||
operatingMode mode_;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("equationInitialResidual");
|
||||
|
||||
//- Constructor
|
||||
equationInitialResidualCondition
|
||||
(
|
||||
const word& name,
|
||||
const objectRegistry& obr,
|
||||
const dictionary& dict,
|
||||
stateFunctionObject& state
|
||||
);
|
||||
|
||||
//- Destructor
|
||||
virtual ~equationInitialResidualCondition();
|
||||
|
||||
|
||||
// Public Member Functions
|
||||
|
||||
//- Apply the condition
|
||||
virtual bool apply();
|
||||
|
||||
//- Write
|
||||
virtual void write();
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace runTimeControls
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,181 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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 "equationMaxIterCondition.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
#include "fvMesh.H"
|
||||
#include "Time.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace runTimeControls
|
||||
{
|
||||
defineTypeNameAndDebug(equationMaxIterCondition, 0);
|
||||
addToRunTimeSelectionTable
|
||||
(
|
||||
runTimeCondition,
|
||||
equationMaxIterCondition,
|
||||
dictionary
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimeControls::equationMaxIterCondition::
|
||||
equationMaxIterCondition
|
||||
(
|
||||
const word& name,
|
||||
const objectRegistry& obr,
|
||||
const dictionary& dict,
|
||||
stateFunctionObject& state
|
||||
)
|
||||
:
|
||||
runTimeCondition(name, obr, dict, state),
|
||||
fieldNames_(dict.lookup("fields")),
|
||||
threshold_(readLabel(dict.lookup("threshold"))),
|
||||
startIter_(dict.lookupOrDefault("startIter", 2))
|
||||
{
|
||||
if (!fieldNames_.size())
|
||||
{
|
||||
WarningInFunction
|
||||
<< "No fields supplied: deactivating" << endl;
|
||||
|
||||
active_ = false;
|
||||
}
|
||||
|
||||
startIter_ = max(startIter_, 2);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimeControls::equationMaxIterCondition::
|
||||
~equationMaxIterCondition()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::runTimeControls::equationMaxIterCondition::apply()
|
||||
{
|
||||
bool satisfied = false;
|
||||
|
||||
if (!active_)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (obr_.time().timeIndex() < startIter_)
|
||||
{
|
||||
// Do not start checking until start iter
|
||||
return false;
|
||||
}
|
||||
|
||||
const fvMesh& mesh = refCast<const fvMesh>(obr_);
|
||||
const dictionary& solverDict = mesh.solverPerformanceDict();
|
||||
|
||||
List<label> result(fieldNames_.size(), -1);
|
||||
|
||||
forAll(fieldNames_, fieldi)
|
||||
{
|
||||
const word& fieldName = fieldNames_[fieldi];
|
||||
|
||||
if (solverDict.found(fieldName))
|
||||
{
|
||||
const List<solverPerformance> sp(solverDict.lookup(fieldName));
|
||||
const label nIterations = sp.first().nIterations();
|
||||
result[fieldi] = nIterations;
|
||||
|
||||
if (nIterations > threshold_)
|
||||
{
|
||||
satisfied = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool valid = false;
|
||||
forAll(result, i)
|
||||
{
|
||||
if (result[i] < 0)
|
||||
{
|
||||
WarningInFunction
|
||||
<< "Number of iterations data not found for field "
|
||||
<< fieldNames_[i] << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
valid = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!valid)
|
||||
{
|
||||
WarningInFunction
|
||||
<< "Number of iterations data not found for any fields: "
|
||||
<< "deactivating" << endl;
|
||||
|
||||
active_ = false;
|
||||
}
|
||||
|
||||
if (satisfied && valid)
|
||||
{
|
||||
if (log_)
|
||||
{
|
||||
Info<< type() << ": " << name_
|
||||
<< ": satisfied using threshold value: " << threshold_ << nl;
|
||||
}
|
||||
|
||||
forAll(result, resulti)
|
||||
{
|
||||
if (result[resulti] != -1)
|
||||
{
|
||||
if (log_)
|
||||
{
|
||||
Info<< " field: " << fieldNames_[resulti]
|
||||
<< ", iterations: " << result[resulti] << nl;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (log_) Info<< endl;
|
||||
}
|
||||
|
||||
return satisfied;
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::runTimeControls::equationMaxIterCondition::write()
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,110 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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::functionObjects::runTimeControls::equationMaxIterCondition
|
||||
|
||||
Description
|
||||
Maximum number of equation iterations run time condition
|
||||
|
||||
SourceFiles
|
||||
equationMaxIterCondition.H
|
||||
equationMaxIterCondition.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_runTimeConditions_equationMaxIterCondition_H
|
||||
#define functionObjects_runTimeConditions_equationMaxIterCondition_H
|
||||
|
||||
#include "runTimeCondition.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace runTimeControls
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class equationMaxIterCondition Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class equationMaxIterCondition
|
||||
:
|
||||
public runTimeCondition
|
||||
{
|
||||
protected:
|
||||
|
||||
// Protected data
|
||||
|
||||
//- Field name
|
||||
const wordList fieldNames_;
|
||||
|
||||
//- Threshold for maximum number of iterations
|
||||
const label threshold_;
|
||||
|
||||
//- Start checking from iteration - always skips first iteration
|
||||
label startIter_;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("equationMaxIter");
|
||||
|
||||
//- Constructor
|
||||
equationMaxIterCondition
|
||||
(
|
||||
const word& name,
|
||||
const objectRegistry& obr,
|
||||
const dictionary& dict,
|
||||
stateFunctionObject& state
|
||||
);
|
||||
|
||||
//- Destructor
|
||||
virtual ~equationMaxIterCondition();
|
||||
|
||||
|
||||
// Public Member Functions
|
||||
|
||||
//- Apply the condition
|
||||
virtual bool apply();
|
||||
|
||||
//- Write
|
||||
virtual void write();
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace runTimeControls
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,185 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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 "minMaxCondition.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
#include "fieldTypes.H"
|
||||
|
||||
// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
|
||||
|
||||
template<>
|
||||
void Foam::functionObjects::runTimeControls::minMaxCondition::
|
||||
setValue<Foam::scalar>
|
||||
(
|
||||
const word& valueType,
|
||||
const word& fieldName,
|
||||
scalar& value
|
||||
) const
|
||||
{
|
||||
state_.getObjectResult(functionObjectName_, fieldName, value);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace runTimeControls
|
||||
{
|
||||
defineTypeNameAndDebug(minMaxCondition, 0);
|
||||
addToRunTimeSelectionTable(runTimeCondition, minMaxCondition, dictionary);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<>
|
||||
const char* Foam::NamedEnum
|
||||
<
|
||||
Foam::functionObjects::runTimeControls::minMaxCondition::modeType,
|
||||
2
|
||||
>::names[] =
|
||||
{
|
||||
"minimum",
|
||||
"maximum"
|
||||
};
|
||||
|
||||
const Foam::NamedEnum
|
||||
<
|
||||
Foam
|
||||
::functionObjects
|
||||
::runTimeControls
|
||||
::minMaxCondition
|
||||
::modeType,
|
||||
2
|
||||
>
|
||||
Foam::functionObjects::runTimeControls::minMaxCondition::modeTypeNames_;
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimeControls::minMaxCondition::minMaxCondition
|
||||
(
|
||||
const word& name,
|
||||
const objectRegistry& obr,
|
||||
const dictionary& dict,
|
||||
stateFunctionObject& state
|
||||
)
|
||||
:
|
||||
runTimeCondition(name, obr, dict, state),
|
||||
functionObjectName_(dict.lookup("functionObject")),
|
||||
mode_(modeTypeNames_.read(dict.lookup("mode"))),
|
||||
fieldNames_(dict.lookup("fields")),
|
||||
value_(readScalar(dict.lookup("value")))
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimeControls::minMaxCondition::~minMaxCondition()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::runTimeControls::minMaxCondition::apply()
|
||||
{
|
||||
bool satisfied = true;
|
||||
|
||||
if (!active_)
|
||||
{
|
||||
return satisfied;
|
||||
}
|
||||
|
||||
forAll(fieldNames_, fieldi)
|
||||
{
|
||||
const word& fieldName = fieldNames_[fieldi];
|
||||
|
||||
const word valueType =
|
||||
state_.objectResultType(functionObjectName_, fieldName);
|
||||
|
||||
if (valueType == word::null)
|
||||
{
|
||||
WarningInFunction
|
||||
<< "Unable to find entry " << fieldName
|
||||
<< " for function object " << functionObjectName_
|
||||
<< ". Condition will not be applied."
|
||||
<< endl;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
scalar v = 0;
|
||||
setValue<scalar>(valueType, fieldName, v);
|
||||
setValue<vector>(valueType, fieldName, v);
|
||||
setValue<sphericalTensor>(valueType, fieldName, v);
|
||||
setValue<symmTensor>(valueType, fieldName, v);
|
||||
setValue<tensor>(valueType, fieldName, v);
|
||||
|
||||
Switch ok = false;
|
||||
switch (mode_)
|
||||
{
|
||||
case mdMin:
|
||||
{
|
||||
if (v < value_)
|
||||
{
|
||||
ok = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case mdMax:
|
||||
{
|
||||
if (v > value_)
|
||||
{
|
||||
ok = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (log_)
|
||||
{
|
||||
Info<< " " << type() << ": " << modeTypeNames_[mode_] << " "
|
||||
<< fieldName << ": value = " << v
|
||||
<< ", threshold value = " << value_
|
||||
<< ", satisfied = " << ok << endl;
|
||||
}
|
||||
|
||||
satisfied = satisfied && ok;
|
||||
}
|
||||
|
||||
return satisfied;
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::runTimeControls::minMaxCondition::write()
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,151 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 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::minMaxCondition
|
||||
|
||||
Description
|
||||
Minimum/maximum run time conditions. If the value type is not scalar,
|
||||
the magnitude of the value is used in the evaluation.
|
||||
|
||||
SourceFiles
|
||||
minMaxCondition.H
|
||||
minMaxCondition.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_runTimeControls_minMaxCondition_H
|
||||
#define functionObjects_runTimeControls_minMaxCondition_H
|
||||
|
||||
#include "runTimeCondition.H"
|
||||
#include "NamedEnum.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace runTimeControls
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class minMaxCondition Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class minMaxCondition
|
||||
:
|
||||
public runTimeCondition
|
||||
{
|
||||
public:
|
||||
|
||||
// Public enumerations
|
||||
|
||||
// Mode type
|
||||
enum modeType
|
||||
{
|
||||
mdMin, //!< Minimum
|
||||
mdMax //!< Maximum
|
||||
};
|
||||
|
||||
static const NamedEnum<modeType, 2> modeTypeNames_;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// Protected data
|
||||
|
||||
//- Name of function object to retrueve data from
|
||||
word functionObjectName_;
|
||||
|
||||
//- Mode
|
||||
modeType mode_;
|
||||
|
||||
//- Field names
|
||||
const wordList fieldNames_;
|
||||
|
||||
//- Value to compare
|
||||
const scalar value_;
|
||||
|
||||
//- Helper function to retrieve the value from the state dictionary
|
||||
template<class Type>
|
||||
void setValue
|
||||
(
|
||||
const word& valueType,
|
||||
const word& fieldName,
|
||||
scalar& value
|
||||
) const;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("minMax");
|
||||
|
||||
//- Constructor
|
||||
minMaxCondition
|
||||
(
|
||||
const word& name,
|
||||
const objectRegistry& obr,
|
||||
const dictionary& dict,
|
||||
stateFunctionObject& state
|
||||
);
|
||||
|
||||
//- Destructor
|
||||
virtual ~minMaxCondition();
|
||||
|
||||
|
||||
// Public Member Functions
|
||||
|
||||
//- Apply the condition
|
||||
virtual bool apply();
|
||||
|
||||
//- Write
|
||||
virtual void write();
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
template<>
|
||||
void minMaxCondition::setValue<Foam::scalar>
|
||||
(
|
||||
const word& valueType,
|
||||
const word& fieldName,
|
||||
scalar& value
|
||||
) const;
|
||||
|
||||
} // End namespace runTimeControls
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef NoRepository
|
||||
#include "minMaxConditionTemplates.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,46 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
void Foam::functionObjects::runTimeControls::minMaxCondition::setValue
|
||||
(
|
||||
const word& valueType,
|
||||
const word& fieldName,
|
||||
scalar& value
|
||||
) const
|
||||
{
|
||||
if (pTraits<Type>::typeName != valueType)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Type v = state_.getObjectResult<Type>(functionObjectName_, fieldName);
|
||||
value = mag(v);
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,99 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 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 "minTimeStepCondition.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
#include "Time.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace runTimeControls
|
||||
{
|
||||
defineTypeNameAndDebug(minTimeStepCondition, 0);
|
||||
addToRunTimeSelectionTable
|
||||
(
|
||||
runTimeCondition,
|
||||
minTimeStepCondition,
|
||||
dictionary
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimeControls::minTimeStepCondition::
|
||||
minTimeStepCondition
|
||||
(
|
||||
const word& name,
|
||||
const objectRegistry& obr,
|
||||
const dictionary& dict,
|
||||
stateFunctionObject& state
|
||||
)
|
||||
:
|
||||
runTimeCondition(name, obr, dict, state),
|
||||
minValue_(readScalar(dict.lookup("minValue")))
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimeControls::minTimeStepCondition::
|
||||
~minTimeStepCondition()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::runTimeControls::minTimeStepCondition::apply()
|
||||
{
|
||||
bool satisfied = false;
|
||||
|
||||
if (!active_)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (obr_.time().deltaTValue() < minValue_)
|
||||
{
|
||||
satisfied = true;
|
||||
}
|
||||
|
||||
return satisfied;
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::runTimeControls::minTimeStepCondition::write()
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,105 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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::functionObjects::runTimeControls::minTimeStepCondition
|
||||
|
||||
Description
|
||||
Minimum time step condition
|
||||
|
||||
SourceFiles
|
||||
minTimeStepCondition.H
|
||||
minTimeStepCondition.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_runTimeConditions_minTimeStepCondition_H
|
||||
#define functionObjects_runTimeConditions_minTimeStepCondition_H
|
||||
|
||||
#include "runTimeCondition.H"
|
||||
#include "NamedEnum.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace runTimeControls
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class minTimeStepCondition Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class minTimeStepCondition
|
||||
:
|
||||
public runTimeCondition
|
||||
{
|
||||
protected:
|
||||
|
||||
// Protected data
|
||||
|
||||
//- Minumim time step value to compare
|
||||
const scalar minValue_;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("minTimeStep");
|
||||
|
||||
//- Constructor
|
||||
minTimeStepCondition
|
||||
(
|
||||
const word& name,
|
||||
const objectRegistry& obr,
|
||||
const dictionary& dict,
|
||||
stateFunctionObject& state
|
||||
);
|
||||
|
||||
//- Destructor
|
||||
virtual ~minTimeStepCondition();
|
||||
|
||||
|
||||
// Public Member Functions
|
||||
|
||||
//- Apply the condition
|
||||
virtual bool apply();
|
||||
|
||||
//- Write
|
||||
virtual void write();
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace runTimeControls
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,120 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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 "runTimeCondition.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace runTimeControls
|
||||
{
|
||||
defineTypeNameAndDebug(runTimeCondition, 0);
|
||||
defineRunTimeSelectionTable(runTimeCondition, dictionary);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
|
||||
|
||||
Foam::dictionary&
|
||||
Foam::functionObjects::runTimeControls::runTimeCondition::setConditionDict()
|
||||
{
|
||||
dictionary& propertyDict = state_.propertyDict();
|
||||
|
||||
if (!propertyDict.found(name_))
|
||||
{
|
||||
propertyDict.add(name_, dictionary());
|
||||
}
|
||||
|
||||
return propertyDict.subDict(name_);
|
||||
}
|
||||
|
||||
|
||||
const Foam::dictionary&
|
||||
Foam::functionObjects::runTimeControls::runTimeCondition::conditionDict() const
|
||||
{
|
||||
return conditionDict_;
|
||||
}
|
||||
|
||||
|
||||
Foam::dictionary&
|
||||
Foam::functionObjects::runTimeControls::runTimeCondition::conditionDict()
|
||||
{
|
||||
return conditionDict_;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimeControls::runTimeCondition::runTimeCondition
|
||||
(
|
||||
const word& name,
|
||||
const objectRegistry& obr,
|
||||
const dictionary& dict,
|
||||
stateFunctionObject& state
|
||||
)
|
||||
:
|
||||
name_(name),
|
||||
obr_(obr),
|
||||
state_(state),
|
||||
active_(dict.lookupOrDefault<bool>("active", true)),
|
||||
conditionDict_(setConditionDict()),
|
||||
log_(dict.lookupOrDefault("log", true)),
|
||||
groupID_(dict.lookupOrDefault("groupID", -1))
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimeControls::runTimeCondition::~runTimeCondition()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * //
|
||||
|
||||
const Foam::word&
|
||||
Foam::functionObjects::runTimeControls::runTimeCondition::name() const
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::runTimeControls::runTimeCondition::active() const
|
||||
{
|
||||
return active_;
|
||||
}
|
||||
|
||||
|
||||
Foam::label
|
||||
Foam::functionObjects::runTimeControls::runTimeCondition::groupID() const
|
||||
{
|
||||
return groupID_;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,173 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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::functionObjects::runTimeControls::runTimeCondition
|
||||
|
||||
Description
|
||||
Base class for run time conditions
|
||||
|
||||
SourceFiles
|
||||
runTimeCondition.C
|
||||
runTimeConditionNew.C
|
||||
runTimeCondition.H
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_runTimeControls_runTimeCondition_H
|
||||
#define functionObjects_runTimeControls_runTimeCondition_H
|
||||
|
||||
#include "stateFunctionObject.H"
|
||||
#include "dictionary.H"
|
||||
#include "autoPtr.H"
|
||||
#include "runTimeSelectionTables.H"
|
||||
#include "Switch.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace runTimeControls
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class runTimeCondition Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class runTimeCondition
|
||||
{
|
||||
|
||||
protected:
|
||||
|
||||
// Protected data
|
||||
|
||||
//- Condition name
|
||||
word name_;
|
||||
|
||||
//- Reference to the object registry
|
||||
const objectRegistry& obr_;
|
||||
|
||||
//- State
|
||||
stateFunctionObject& state_;
|
||||
|
||||
//- On/off switch
|
||||
bool active_;
|
||||
|
||||
//- Reference to the condition dictionary
|
||||
dictionary& conditionDict_;
|
||||
|
||||
//- Switch to send output to Info
|
||||
Switch log_;
|
||||
|
||||
//- Group index - if applied, all conditions in a group must be
|
||||
// satisfield before condition is met
|
||||
label groupID_;
|
||||
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
//- Set the condition dictionary (create if necessary)
|
||||
dictionary& setConditionDict();
|
||||
|
||||
//- Return const access to the conditions dictionary
|
||||
const dictionary& conditionDict() const;
|
||||
|
||||
//- Return non-const access to the conditions dictionary
|
||||
dictionary& conditionDict();
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("runTimeCondition");
|
||||
|
||||
//- Declare runtime constructor selection table
|
||||
declareRunTimeSelectionTable
|
||||
(
|
||||
autoPtr,
|
||||
runTimeCondition,
|
||||
dictionary,
|
||||
(
|
||||
const word& name,
|
||||
const objectRegistry& obr,
|
||||
const dictionary& dict,
|
||||
stateFunctionObject& state
|
||||
),
|
||||
(name, obr, dict, state)
|
||||
);
|
||||
|
||||
|
||||
//- Constructor
|
||||
runTimeCondition
|
||||
(
|
||||
const word& name,
|
||||
const objectRegistry& obr,
|
||||
const dictionary& dict,
|
||||
stateFunctionObject& state
|
||||
);
|
||||
|
||||
//- Destructor
|
||||
virtual ~runTimeCondition();
|
||||
|
||||
//- Selector
|
||||
static autoPtr<runTimeCondition> New
|
||||
(
|
||||
const word& conditionName,
|
||||
const objectRegistry& obr,
|
||||
const dictionary& dict,
|
||||
stateFunctionObject& state
|
||||
);
|
||||
|
||||
|
||||
// Public Member Functions
|
||||
|
||||
//- Return the condition name
|
||||
virtual const word& name() const;
|
||||
|
||||
//- Return the active flag
|
||||
virtual bool active() const;
|
||||
|
||||
//- Return the group index
|
||||
virtual label groupID() const;
|
||||
|
||||
//- Apply the condition
|
||||
virtual bool apply() = 0;
|
||||
|
||||
//- Write
|
||||
virtual void write() = 0;
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace runTimeControls
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,63 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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 "runTimeCondition.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::autoPtr<Foam::functionObjects::runTimeControls::runTimeCondition>
|
||||
Foam::functionObjects::runTimeControls::runTimeCondition::New
|
||||
(
|
||||
const word& conditionName,
|
||||
const objectRegistry& obr,
|
||||
const dictionary& dict,
|
||||
stateFunctionObject& state
|
||||
)
|
||||
{
|
||||
word conditionType(dict.lookup("type"));
|
||||
|
||||
Info<< "Selecting runTimeCondition " << conditionType << endl;
|
||||
|
||||
dictionaryConstructorTable::iterator cstrIter =
|
||||
dictionaryConstructorTablePtr_->find(conditionType);
|
||||
|
||||
if (cstrIter == dictionaryConstructorTablePtr_->end())
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Unknown runTimeCondition type "
|
||||
<< conditionType << nl << nl
|
||||
<< "Valid runTimeCondition types are:" << nl
|
||||
<< dictionaryConstructorTablePtr_->sortedToc()
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
return autoPtr<runTimeCondition>
|
||||
(
|
||||
cstrIter()(conditionName, obr, dict, state)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
249
src/functionObjects/utilities/runTimeControl/runTimeControl.C
Normal file
249
src/functionObjects/utilities/runTimeControl/runTimeControl.C
Normal file
@ -0,0 +1,249 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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 "runTimeControl.H"
|
||||
#include "dictionary.H"
|
||||
#include "runTimeCondition.H"
|
||||
#include "fvMesh.H"
|
||||
#include "Time.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace runTimeControls
|
||||
{
|
||||
defineTypeNameAndDebug(runTimeControl, 0);
|
||||
addToRunTimeSelectionTable(functionObject, runTimeControl, dictionary);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimeControls::runTimeControl::runTimeControl
|
||||
(
|
||||
const word& name,
|
||||
const Time& runTime,
|
||||
const dictionary& dict
|
||||
)
|
||||
:
|
||||
fvMeshFunctionObject(name, runTime, dict),
|
||||
conditions_(),
|
||||
groupMap_(),
|
||||
nWriteStep_(0),
|
||||
writeStepI_(0)
|
||||
{
|
||||
read(dict);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::runTimeControls::runTimeControl::~runTimeControl()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::runTimeControls::runTimeControl::read
|
||||
(
|
||||
const dictionary& dict
|
||||
)
|
||||
{
|
||||
fvMeshFunctionObject::read(dict);
|
||||
|
||||
const dictionary& conditionsDict = dict.subDict("conditions");
|
||||
const wordList conditionNames(conditionsDict.toc());
|
||||
conditions_.setSize(conditionNames.size());
|
||||
|
||||
label uniqueGroupi = 0;
|
||||
forAll(conditionNames, conditioni)
|
||||
{
|
||||
const word& conditionName = conditionNames[conditioni];
|
||||
const dictionary& dict = conditionsDict.subDict(conditionName);
|
||||
|
||||
conditions_.set
|
||||
(
|
||||
conditioni,
|
||||
runTimeCondition::New(conditionName, obr_, dict, *this)
|
||||
);
|
||||
|
||||
label groupi = conditions_[conditioni].groupID();
|
||||
|
||||
if (groupMap_.insert(groupi, uniqueGroupi))
|
||||
{
|
||||
uniqueGroupi++;
|
||||
}
|
||||
}
|
||||
|
||||
dict.readIfPresent("nWriteStep", nWriteStep_);
|
||||
|
||||
// Check that some conditions are set
|
||||
if (conditions_.empty())
|
||||
{
|
||||
Info<< type() << " " << name() << " output:" << nl
|
||||
<< " No conditions present" << nl
|
||||
<< endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Check that at least one condition is active
|
||||
bool active = false;
|
||||
forAll(conditions_, conditioni)
|
||||
{
|
||||
if (conditions_[conditioni].active())
|
||||
{
|
||||
active = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!active)
|
||||
{
|
||||
Info<< type() << " " << name() << " output:" << nl
|
||||
<< " All conditions are inactive" << nl
|
||||
<< endl;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::runTimeControls::runTimeControl::execute()
|
||||
{
|
||||
Info<< type() << " " << name() << " output:" << nl;
|
||||
|
||||
// IDs of satisfied conditions
|
||||
DynamicList<label> IDs(conditions_.size());
|
||||
|
||||
// Run stops only if all conditions within a group are satisfied
|
||||
List<bool> groupSatisfied(groupMap_.size(), true);
|
||||
List<bool> groupActive(groupMap_.size(), false);
|
||||
|
||||
forAll(conditions_, conditioni)
|
||||
{
|
||||
runTimeCondition& condition = conditions_[conditioni];
|
||||
|
||||
if (condition.active())
|
||||
{
|
||||
bool conditionSatisfied = condition.apply();
|
||||
|
||||
label groupi = condition.groupID();
|
||||
|
||||
Map<label>::const_iterator conditionIter = groupMap_.find(groupi);
|
||||
|
||||
if (conditionIter == groupMap_.end())
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "group " << groupi << " not found in map"
|
||||
<< abort(FatalError);
|
||||
}
|
||||
|
||||
if (conditionSatisfied)
|
||||
{
|
||||
IDs.append(conditioni);
|
||||
|
||||
groupActive[conditionIter()] = true;
|
||||
|
||||
if (groupi == -1)
|
||||
{
|
||||
// Condition not part of a group - only requires this to be
|
||||
// satisfied for completion flag to be set
|
||||
groupSatisfied[conditionIter()] = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
groupSatisfied[conditionIter()] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool done = false;
|
||||
forAll(groupSatisfied, groupi)
|
||||
{
|
||||
if (groupSatisfied[groupi] && groupActive[groupi])
|
||||
{
|
||||
done = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (done)
|
||||
{
|
||||
forAll(IDs, conditioni)
|
||||
{
|
||||
Info<< " " << conditions_[conditioni].type() << ": "
|
||||
<< conditions_[conditioni].name()
|
||||
<< " condition satisfied" << nl;
|
||||
}
|
||||
|
||||
|
||||
// Set to write a data dump or finalise the calculation
|
||||
Time& time = const_cast<Time&>(time_);
|
||||
|
||||
if (writeStepI_ < nWriteStep_ - 1)
|
||||
{
|
||||
writeStepI_++;
|
||||
Info<< " Writing fields - step " << writeStepI_ << nl;
|
||||
time.writeNow();
|
||||
}
|
||||
else
|
||||
{
|
||||
Info<< " Stopping calculation" << nl
|
||||
<< " Writing fields - final step" << nl;
|
||||
time.writeAndEnd();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Info<< " Conditions not met - calculations proceeding" << nl;
|
||||
}
|
||||
|
||||
Info<< endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::runTimeControls::runTimeControl::write()
|
||||
{
|
||||
forAll(conditions_, conditioni)
|
||||
{
|
||||
conditions_[conditioni].write();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
138
src/functionObjects/utilities/runTimeControl/runTimeControl.H
Normal file
138
src/functionObjects/utilities/runTimeControl/runTimeControl.H
Normal file
@ -0,0 +1,138 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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::functionObjects::runTimeControl
|
||||
|
||||
Group
|
||||
grpUtilitiesFunctionObjects
|
||||
|
||||
Description
|
||||
Controls when the calculation is terminated based on satisfying
|
||||
user-specified conditions.
|
||||
|
||||
Optionally specify a number of write steps before the calculation is
|
||||
terminated. Here, a write is performed each time that all conditons are
|
||||
satisfied.
|
||||
|
||||
SourceFiles
|
||||
runTimeControl.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_runTimeControl_H
|
||||
#define functionObjects_runTimeControl_H
|
||||
|
||||
#include "fvMeshFunctionObject.H"
|
||||
#include "Map.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
namespace runTimeControls
|
||||
{
|
||||
|
||||
// Forward declaration of classes
|
||||
class runTimeCondition;
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class runTimeControl Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class runTimeControl
|
||||
:
|
||||
public fvMeshFunctionObject
|
||||
{
|
||||
// Private data
|
||||
|
||||
//- List of conditions to satisfy
|
||||
PtrList<runTimeCondition> conditions_;
|
||||
|
||||
//- Map to define group IDs
|
||||
Map<label> groupMap_;
|
||||
|
||||
//- Number of write steps before exiting
|
||||
label nWriteStep_;
|
||||
|
||||
//- Current number of steps written
|
||||
label writeStepI_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
runTimeControl(const runTimeControl&);
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const runTimeControl&);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("runTimeControl");
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct for given objectRegistry and dictionary.
|
||||
// Allow the possibility to load fields from files
|
||||
runTimeControl
|
||||
(
|
||||
const word& name,
|
||||
const Time& runTime,
|
||||
const dictionary& dict
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~runTimeControl();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Read the runTimeControl data
|
||||
virtual bool read(const dictionary&);
|
||||
|
||||
//- Execute, currently does nothing
|
||||
virtual bool execute();
|
||||
|
||||
//- Calculate the runTimeControl and write
|
||||
virtual bool write();
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace runTimeControls
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,139 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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 "setTimeStepFunctionObject.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
defineTypeNameAndDebug(setTimeStepFunctionObject, 0);
|
||||
|
||||
addToRunTimeSelectionTable
|
||||
(
|
||||
functionObject,
|
||||
setTimeStepFunctionObject,
|
||||
dictionary
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::setTimeStepFunctionObject::setTimeStepFunctionObject
|
||||
(
|
||||
const word& name,
|
||||
const Time& runTime,
|
||||
const dictionary& dict
|
||||
)
|
||||
:
|
||||
functionObject(name),
|
||||
time_(runTime)
|
||||
{
|
||||
read(dict);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::setTimeStepFunctionObject::~setTimeStepFunctionObject()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
const Foam::Time&
|
||||
Foam::functionObjects::setTimeStepFunctionObject::time() const
|
||||
{
|
||||
return time_;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::setTimeStepFunctionObject::adjustTimeStep()
|
||||
{
|
||||
// Wanted timestep
|
||||
scalar newDeltaT = timeStepPtr_().value(time_.timeOutputValue());
|
||||
|
||||
static label index = -1;
|
||||
|
||||
if (time_.timeIndex() != index)
|
||||
{
|
||||
// Store current time so we don't get infinite recursion (since
|
||||
// setDeltaT calls adjustTimeStep() again)
|
||||
index = time_.timeIndex();
|
||||
|
||||
// Set time, allow deltaT to be adjusted for writeInterval purposes
|
||||
const_cast<Time&>(time_).setDeltaT(newDeltaT, true);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::setTimeStepFunctionObject::read
|
||||
(
|
||||
const dictionary& dict
|
||||
)
|
||||
{
|
||||
functionObject::read(dict);
|
||||
|
||||
timeStepPtr_ = Function1<scalar>::New("deltaT", dict);
|
||||
|
||||
// Check that adjustTimeStep is active
|
||||
const dictionary& controlDict = time_.controlDict();
|
||||
|
||||
Switch adjust;
|
||||
if
|
||||
(
|
||||
!controlDict.readIfPresent<Switch>("adjustTimeStep", adjust)
|
||||
|| !adjust
|
||||
)
|
||||
{
|
||||
FatalIOErrorInFunction(dict)
|
||||
<< "Need to set 'adjustTimeStep' true to allow timestep control"
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::setTimeStepFunctionObject::execute()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::setTimeStepFunctionObject::write()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,152 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2013-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::functionObjects::setTimeStepFunctionObject
|
||||
|
||||
Group
|
||||
grpUtilitiesFunctionObjects
|
||||
|
||||
Description
|
||||
This function object overrides the calculation time step. Can only be used
|
||||
with solvers with adjustTimeStep control (e.g. pimpleFoam). It makes no
|
||||
attempt to co-operate with other time step 'controllers', e.g. maxCo, other
|
||||
functionObjects. Supports 'enabled' flag but none of the other options
|
||||
'timeStart', 'timeEnd', 'writeControl' etc.
|
||||
|
||||
Usage
|
||||
Example of function object specification to manipulate the time step:
|
||||
\verbatim
|
||||
setTimeStep1
|
||||
{
|
||||
type setTimeStep;
|
||||
libs ("libutilityFunctionObjects.so");
|
||||
...
|
||||
}
|
||||
\endverbatim
|
||||
|
||||
Where the entries comprise:
|
||||
\table
|
||||
Property | Description | Required | Default value
|
||||
type | Type name: setTimeStep | yes |
|
||||
enabled | On/off switch | no | yes
|
||||
\endtable
|
||||
|
||||
SourceFiles
|
||||
setTimeStepFunctionObject.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_setTimeStepFunctionObject_H
|
||||
#define functionObjects_setTimeStepFunctionObject_H
|
||||
|
||||
#include "functionObject.H"
|
||||
#include "Function1.H"
|
||||
#include "Switch.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class setTimeStepFunctionObject Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class setTimeStepFunctionObject
|
||||
:
|
||||
public functionObject
|
||||
{
|
||||
// Private data
|
||||
|
||||
//- Reference to the time database
|
||||
const Time& time_;
|
||||
|
||||
//- Time step function/table
|
||||
autoPtr<Function1<scalar>> timeStepPtr_;
|
||||
|
||||
|
||||
// Private member functions
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
setTimeStepFunctionObject(const setTimeStepFunctionObject&);
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const setTimeStepFunctionObject&);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("setTimeStep");
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from components
|
||||
setTimeStepFunctionObject
|
||||
(
|
||||
const word& name,
|
||||
const Time& runTime,
|
||||
const dictionary& dict
|
||||
);
|
||||
|
||||
|
||||
// Destructor
|
||||
virtual ~setTimeStepFunctionObject();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Return time database
|
||||
const Time& time() const;
|
||||
|
||||
//- 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&);
|
||||
|
||||
//- 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();
|
||||
//- Called at each ++ or += of the time-loop.
|
||||
// postProcess overrides the usual writeControl behaviour and
|
||||
// forces writing always (used in post-processing mode)
|
||||
virtual bool write();
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
4
src/functionObjects/utilities/systemCall/Make/files
Normal file
4
src/functionObjects/utilities/systemCall/Make/files
Normal file
@ -0,0 +1,4 @@
|
||||
systemCall.C
|
||||
systemCallFunctionObject.C
|
||||
|
||||
LIB = $(FOAM_LIBBIN)/libsystemCall
|
||||
143
src/functionObjects/utilities/systemCall/systemCall.C
Normal file
143
src/functionObjects/utilities/systemCall/systemCall.C
Normal file
@ -0,0 +1,143 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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 "systemCall.H"
|
||||
#include "Time.H"
|
||||
#include "dynamicCode.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
defineTypeNameAndDebug(systemCall, 0);
|
||||
|
||||
addToRunTimeSelectionTable
|
||||
(
|
||||
functionObject,
|
||||
systemCall,
|
||||
dictionary
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::systemCall::systemCall
|
||||
(
|
||||
const word& name,
|
||||
const Time&,
|
||||
const dictionary& dict
|
||||
)
|
||||
:
|
||||
functionObject(name),
|
||||
executeCalls_(),
|
||||
endCalls_(),
|
||||
writeCalls_()
|
||||
{
|
||||
read(dict);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::systemCall::~systemCall()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::systemCall::read(const dictionary& dict)
|
||||
{
|
||||
functionObject::read(dict);
|
||||
|
||||
dict.readIfPresent("executeCalls", executeCalls_);
|
||||
dict.readIfPresent("endCalls", endCalls_);
|
||||
dict.readIfPresent("writeCalls", writeCalls_);
|
||||
|
||||
if (executeCalls_.empty() && endCalls_.empty() && writeCalls_.empty())
|
||||
{
|
||||
WarningInFunction
|
||||
<< "no executeCalls, endCalls or writeCalls defined."
|
||||
<< endl;
|
||||
}
|
||||
else if (!dynamicCode::allowSystemOperations)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Executing user-supplied system calls is not enabled by "
|
||||
<< "default because of " << nl
|
||||
<< "security issues. If you trust the case you can enable this "
|
||||
<< "facility by " << nl
|
||||
<< "adding to the InfoSwitches setting in the system controlDict:"
|
||||
<< nl << nl
|
||||
<< " allowSystemOperations 1" << nl << nl
|
||||
<< "The system controlDict is either" << nl << nl
|
||||
<< " ~/.OpenFOAM/$WM_PROJECT_VERSION/controlDict" << nl << nl
|
||||
<< "or" << nl << nl
|
||||
<< " $WM_PROJECT_DIR/etc/controlDict" << nl << nl
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::systemCall::execute()
|
||||
{
|
||||
forAll(executeCalls_, calli)
|
||||
{
|
||||
Foam::system(executeCalls_[calli]);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::systemCall::end()
|
||||
{
|
||||
forAll(endCalls_, calli)
|
||||
{
|
||||
Foam::system(endCalls_[calli]);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::systemCall::write()
|
||||
{
|
||||
forAll(writeCalls_, calli)
|
||||
{
|
||||
Foam::system(writeCalls_[calli]);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
179
src/functionObjects/utilities/systemCall/systemCall.H
Normal file
179
src/functionObjects/utilities/systemCall/systemCall.H
Normal file
@ -0,0 +1,179 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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::functionObjects::systemCall
|
||||
|
||||
Group
|
||||
grpUtilitiesFunctionObjects
|
||||
|
||||
Description
|
||||
Executes system calls, entered in the form of a string lists.
|
||||
|
||||
Calls can be made at the following points in the calculation:
|
||||
- every time step
|
||||
- every output time
|
||||
- end of the calculation
|
||||
|
||||
Usage
|
||||
Example of function object specification:
|
||||
\verbatim
|
||||
systemCall1
|
||||
{
|
||||
type systemCall;
|
||||
libs ("libutilityFunctionObjects.so");
|
||||
...
|
||||
executeCalls
|
||||
(
|
||||
"echo execute"
|
||||
);
|
||||
writeCalls
|
||||
(
|
||||
"echo \*\*\* writing data \*\*\*"
|
||||
);
|
||||
endCalls
|
||||
(
|
||||
"echo \*\*\* writing .bashrc \*\*\*"
|
||||
"cat ~/.bashrc"
|
||||
"echo \*\*\* done \*\*\*"
|
||||
);
|
||||
}
|
||||
\endverbatim
|
||||
|
||||
Where the entries comprise:
|
||||
\table
|
||||
Property | Description | Required | Default value
|
||||
type | type name: systemCall | yes |
|
||||
executeCalls | list of calls on execute | yes |
|
||||
writeCalls | list of calls on write | yes |
|
||||
endCalls | list of calls on end | yes |
|
||||
\endtable
|
||||
|
||||
Note
|
||||
Since this function object executes system calls, there is a potential
|
||||
security risk. In order to use the \c systemCall function object, the
|
||||
\c allowSystemOperations must be set to '1'; otherwise, system calls will
|
||||
not be allowed.
|
||||
|
||||
See also
|
||||
Foam::functionObject
|
||||
Foam::functionObjects::timeControl
|
||||
|
||||
SourceFiles
|
||||
systemCall.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_systemCall_H
|
||||
#define functionObjects_systemCall_H
|
||||
|
||||
#include "functionObject.H"
|
||||
#include "stringList.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class systemCall Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class systemCall
|
||||
:
|
||||
public functionObject
|
||||
{
|
||||
protected:
|
||||
|
||||
// Private data
|
||||
|
||||
//- List of calls to execute - every step
|
||||
stringList executeCalls_;
|
||||
|
||||
//- List of calls to execute when exiting the time-loop
|
||||
stringList endCalls_;
|
||||
|
||||
//- List of calls to execute - write steps
|
||||
stringList writeCalls_;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
// Private member functions
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
systemCall(const systemCall&);
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const systemCall&);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("systemCall");
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from Time and dictionary
|
||||
systemCall
|
||||
(
|
||||
const word& name,
|
||||
const Time& runTime,
|
||||
const dictionary& dict
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~systemCall();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Read the system calls
|
||||
virtual bool read(const dictionary&);
|
||||
|
||||
//- Execute the "executeCalls" at each time-step
|
||||
virtual bool execute();
|
||||
|
||||
//- Execute the "endCalls" at the final time-loop
|
||||
virtual bool end();
|
||||
|
||||
//- Write, execute the "writeCalls"
|
||||
virtual bool write();
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,207 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2016 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 "thermoCoupleProbes.H"
|
||||
#include "mathematicalConstants.H"
|
||||
#include "constants.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
|
||||
using namespace Foam::constant;
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
defineTypeNameAndDebug(thermoCoupleProbes, 0);
|
||||
addToRunTimeSelectionTable(functionObject, thermoCoupleProbes, dictionary);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::thermoCoupleProbes::thermoCoupleProbes
|
||||
(
|
||||
const word& name,
|
||||
const Time& runTime,
|
||||
const dictionary& dict,
|
||||
const bool loadFromFiles,
|
||||
const bool readFields
|
||||
)
|
||||
:
|
||||
probes(name, runTime, dict, loadFromFiles, false),
|
||||
ODESystem(),
|
||||
UName_(dict.lookupOrDefault<word>("U", "U")),
|
||||
radiationFieldName_(dict.lookup("radiationField")),
|
||||
thermo_(mesh_.lookupObject<fluidThermo>(basicThermo::dictName)),
|
||||
odeSolver_(nullptr),
|
||||
Ttc_()
|
||||
{
|
||||
if (readFields)
|
||||
{
|
||||
read(dict);
|
||||
}
|
||||
|
||||
// Check if the property exist (resume old calculation)
|
||||
// or of it is new.
|
||||
if (!getProperty("Tc", Ttc_))
|
||||
{
|
||||
Ttc_ = probes::sample(thermo_.T());
|
||||
}
|
||||
|
||||
// Note: can only create the solver once all samples have been found
|
||||
// - the number of samples is used to set the size of the ODE system
|
||||
odeSolver_ = ODESolver::New(*this, dict);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::thermoCoupleProbes::~thermoCoupleProbes()
|
||||
{}
|
||||
|
||||
|
||||
Foam::label Foam::functionObjects::thermoCoupleProbes::nEqns() const
|
||||
{
|
||||
return this->size();
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::thermoCoupleProbes::derivatives
|
||||
(
|
||||
const scalar x,
|
||||
const scalarField& y,
|
||||
scalarField& dydx
|
||||
) const
|
||||
{
|
||||
scalarField G(y.size(), 0.0);
|
||||
scalarField Tc(y.size(), 0.0);
|
||||
scalarField Uc(y.size(), 0.0);
|
||||
scalarField rhoc(y.size(), 0.0);
|
||||
scalarField muc(y.size(), 0.0);
|
||||
scalarField Cpc(y.size(), 0.0);
|
||||
scalarField kappac(y.size(), 0.0);
|
||||
|
||||
if (radiationFieldName_ != "none")
|
||||
{
|
||||
G = sample(mesh_.lookupObject<volScalarField>(radiationFieldName_));
|
||||
}
|
||||
|
||||
Tc = probes::sample(thermo_.T());
|
||||
|
||||
Uc = mag(this->sample(mesh_.lookupObject<volVectorField>(UName_)));
|
||||
|
||||
rhoc = this->sample(thermo_.rho()());
|
||||
kappac = this->sample(thermo_.kappa()());
|
||||
muc = this->sample(thermo_.mu()());
|
||||
Cpc = this->sample(thermo_.Cp()());
|
||||
|
||||
scalarField Re(rhoc*Uc*d_/(muc + ROOTVSMALL));
|
||||
scalarField Pr(Cpc*muc/(kappac + ROOTVSMALL));
|
||||
//scalarField Nu(2.0 + 0.6*sqrt(Re)*cbrt(Pr));
|
||||
scalarField Nu(2.0 + (0.4*sqrt(Re) + 0.06*pow(Re, 2/3))*pow(Pr, 0.4));
|
||||
scalarField htc(Nu*kappac/d_);
|
||||
|
||||
const scalar sigma = physicoChemical::sigma.value();
|
||||
|
||||
scalar area = 4*constant::mathematical::pi*sqr(0.5*d_);
|
||||
scalar volume = (4/3)*constant::mathematical::pi*pow3(0.5*d_);
|
||||
|
||||
dydx =
|
||||
(epsilon_*(G/4 - sigma*pow4(y))*area + htc*(Tc - y)*area)
|
||||
/ (rho_*Cp_*volume);
|
||||
}
|
||||
|
||||
|
||||
void Foam::functionObjects::thermoCoupleProbes::jacobian
|
||||
(
|
||||
const scalar x,
|
||||
const scalarField& y,
|
||||
scalarField& dfdt,
|
||||
scalarSquareMatrix& dfdy
|
||||
) const
|
||||
{
|
||||
derivatives(x, y, dfdt);
|
||||
|
||||
const label n = nEqns();
|
||||
|
||||
for (label i=0; i<n; i++)
|
||||
{
|
||||
for (label j=0; j<n; j++)
|
||||
{
|
||||
dfdy(i, j) = 0.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::thermoCoupleProbes::write()
|
||||
{
|
||||
if (this->size())
|
||||
{
|
||||
sampleAndWrite<scalar>(thermo_.T());
|
||||
|
||||
dictionary probeDict;
|
||||
probeDict.add("Tc", Ttc_);
|
||||
setProperty(typeName, probeDict);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::thermoCoupleProbes::execute()
|
||||
{
|
||||
if (this->size())
|
||||
{
|
||||
scalar dt = mesh_.time().deltaTValue();
|
||||
scalar t = mesh_.time().value();
|
||||
odeSolver_->solve(t, t+dt, Ttc_, dt);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::thermoCoupleProbes::read(const dictionary& dict)
|
||||
{
|
||||
if (probes::read(dict))
|
||||
{
|
||||
rho_ = readScalar(dict.lookup("rho"));
|
||||
Cp_ = readScalar(dict.lookup("Cp"));
|
||||
d_ = readScalar(dict.lookup("d"));
|
||||
epsilon_ = readScalar(dict.lookup("epsilon"));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,229 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2016 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::functionObjects::thermoCoupleProbes
|
||||
|
||||
Group
|
||||
grpUtilitiesFunctionObjects
|
||||
|
||||
Description
|
||||
Sample probe for temperature using a thermocouple.
|
||||
|
||||
Uses the correlation:
|
||||
|
||||
\f[
|
||||
Nu = 2.0 + \left(0.4 Re^{0.5} + 0.06 Re^{2/3}\right)*Pr^{0.4}
|
||||
\f]
|
||||
|
||||
Usage
|
||||
Example of function object specification:
|
||||
\verbatim
|
||||
probes
|
||||
{
|
||||
type thermoCoupleProbes;
|
||||
libs ("libutilityFunctionObjects.so");
|
||||
writeControl timeStep;
|
||||
writeInterval 1;
|
||||
|
||||
solver rodas23;
|
||||
absTol 1e-12;
|
||||
relTol 1e-8;
|
||||
|
||||
interpolationScheme cellPoint;
|
||||
|
||||
// thermocouple properties
|
||||
rho 8908;
|
||||
Cp 440;
|
||||
d 1e-3;
|
||||
epsilon 0.85;
|
||||
|
||||
radiationField G;
|
||||
|
||||
probeLocations
|
||||
(
|
||||
(0.5 0.5 0.5)
|
||||
);
|
||||
fields
|
||||
(
|
||||
T
|
||||
);
|
||||
}
|
||||
\endverbatim
|
||||
|
||||
|
||||
SourceFiles
|
||||
thermoCoupleProbes.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_thermoCoupleProbes_H
|
||||
#define functionObjects_thermoCoupleProbes_H
|
||||
|
||||
#include "probes.H"
|
||||
#include "ODESystem.H"
|
||||
#include "ODESolver.H"
|
||||
#include "basicThermo.H"
|
||||
#include "fluidThermo.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class thermoCoupleProbes Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class thermoCoupleProbes
|
||||
:
|
||||
public probes,
|
||||
public ODESystem
|
||||
{
|
||||
protected:
|
||||
|
||||
// Protected data
|
||||
|
||||
//- Thermocouple density
|
||||
scalar rho_;
|
||||
|
||||
//- Thermocouple heat capacity
|
||||
scalar Cp_;
|
||||
|
||||
//- Thermocouple diameter
|
||||
scalar d_;
|
||||
|
||||
//- Thermocouple emissivity
|
||||
scalar epsilon_;
|
||||
|
||||
//- Name of the velocity field
|
||||
word UName_;
|
||||
|
||||
//- Name of the incident radiation field
|
||||
word radiationFieldName_;
|
||||
|
||||
//- Fluid thermo reference
|
||||
const fluidThermo& thermo_;
|
||||
|
||||
//- ODESolver
|
||||
autoPtr<ODESolver> odeSolver_;
|
||||
|
||||
//- Cached thermocouple temperature
|
||||
scalarField Ttc_;
|
||||
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
//- Sample and write a particular volume field
|
||||
template<class Type>
|
||||
void sampleAndWrite
|
||||
(
|
||||
const GeometricField<Type, fvPatchField, volMesh>&
|
||||
);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
thermoCoupleProbes(const thermoCoupleProbes&);
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const thermoCoupleProbes&);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("thermoCoupleProbes");
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct for given objectRegistry and dictionary.
|
||||
// Allow the possibility to load fields from files
|
||||
thermoCoupleProbes
|
||||
(
|
||||
const word& name,
|
||||
const Time& runTime,
|
||||
const dictionary& dict,
|
||||
const bool loadFromFiles = false,
|
||||
const bool readFields = true
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~thermoCoupleProbes();
|
||||
|
||||
|
||||
// ODE functions (overriding abstract functions in ODE.H)
|
||||
|
||||
//- Number of ODE's to solve
|
||||
virtual label nEqns() const;
|
||||
|
||||
virtual void derivatives
|
||||
(
|
||||
const scalar x,
|
||||
const scalarField& y,
|
||||
scalarField& dydx
|
||||
) const;
|
||||
|
||||
virtual void jacobian
|
||||
(
|
||||
const scalar t,
|
||||
const scalarField& y,
|
||||
scalarField& dfdt,
|
||||
scalarSquareMatrix& dfdy
|
||||
) const;
|
||||
|
||||
|
||||
// Public Member Functions
|
||||
|
||||
//- Sample and write
|
||||
virtual bool write();
|
||||
|
||||
//- Execute, currently does nothing
|
||||
virtual bool execute();
|
||||
|
||||
//- Read
|
||||
virtual bool read(const dictionary&);
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef NoRepository
|
||||
#include "thermoCoupleProbesTemplates.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,52 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2016 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/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
void Foam::functionObjects::thermoCoupleProbes::sampleAndWrite
|
||||
(
|
||||
const GeometricField<Type, fvPatchField, volMesh>& vField
|
||||
)
|
||||
{
|
||||
if (Pstream::master())
|
||||
{
|
||||
unsigned int w = IOstream::defaultPrecision() + 7;
|
||||
OFstream& probeStream = *probeFilePtrs_[vField.name()];
|
||||
|
||||
probeStream
|
||||
<< setw(w)
|
||||
<< vField.time().timeToUserTime(vField.time().value());
|
||||
|
||||
forAll(*this, probeI)
|
||||
{
|
||||
probeStream << ' ' << setw(w) << Ttc_[probeI];
|
||||
}
|
||||
probeStream << endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,151 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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 "timeActivatedFileUpdate.H"
|
||||
#include "Time.H"
|
||||
#include "polyMesh.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
defineTypeNameAndDebug(timeActivatedFileUpdate, 0);
|
||||
|
||||
addToRunTimeSelectionTable
|
||||
(
|
||||
functionObject,
|
||||
timeActivatedFileUpdate,
|
||||
dictionary
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
void Foam::functionObjects::timeActivatedFileUpdate::updateFile()
|
||||
{
|
||||
label i = lastIndex_;
|
||||
while
|
||||
(
|
||||
i < timeVsFile_.size()-1
|
||||
&& timeVsFile_[i+1].first() < time_.value()
|
||||
)
|
||||
{
|
||||
i++;
|
||||
}
|
||||
|
||||
if (i > lastIndex_)
|
||||
{
|
||||
Log << nl << type() << ": copying file" << nl << timeVsFile_[i].second()
|
||||
<< nl << "to:" << nl << fileToUpdate_ << nl << endl;
|
||||
|
||||
cp(timeVsFile_[i].second(), fileToUpdate_);
|
||||
lastIndex_ = i;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::timeActivatedFileUpdate::timeActivatedFileUpdate
|
||||
(
|
||||
const word& name,
|
||||
const Time& runTime,
|
||||
const dictionary& dict
|
||||
)
|
||||
:
|
||||
functionObject(name),
|
||||
time_(runTime),
|
||||
fileToUpdate_("unknown-fileToUpdate"),
|
||||
timeVsFile_(),
|
||||
lastIndex_(-1)
|
||||
{
|
||||
read(dict);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::timeActivatedFileUpdate::~timeActivatedFileUpdate()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::timeActivatedFileUpdate::read
|
||||
(
|
||||
const dictionary& dict
|
||||
)
|
||||
{
|
||||
functionObject::read(dict);
|
||||
|
||||
dict.lookup("fileToUpdate") >> fileToUpdate_;
|
||||
dict.lookup("timeVsFile") >> timeVsFile_;
|
||||
|
||||
lastIndex_ = -1;
|
||||
fileToUpdate_.expand();
|
||||
|
||||
Log << type() << " " << name() << " output:" << nl
|
||||
<< " time vs file list:" << endl;
|
||||
|
||||
forAll(timeVsFile_, i)
|
||||
{
|
||||
timeVsFile_[i].second() = timeVsFile_[i].second().expand();
|
||||
if (!isFile(timeVsFile_[i].second()))
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "File: " << timeVsFile_[i].second() << " not found"
|
||||
<< nl << exit(FatalError);
|
||||
}
|
||||
|
||||
Log << " " << timeVsFile_[i].first() << tab
|
||||
<< timeVsFile_[i].second() << endl;
|
||||
}
|
||||
|
||||
updateFile();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::timeActivatedFileUpdate::execute()
|
||||
{
|
||||
updateFile();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::timeActivatedFileUpdate::write()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,165 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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::functionObjects::timeActivatedFileUpdate
|
||||
|
||||
Group
|
||||
grpUtilitiesFunctionObjects
|
||||
|
||||
Description
|
||||
Performs a file copy/replacement once a specified time has been reached.
|
||||
|
||||
Usage
|
||||
Example usage to update the fvSolution dictionary at various times
|
||||
throughout the calculation:
|
||||
\verbatim
|
||||
fileUpdate1
|
||||
{
|
||||
type timeActivatedFileUpdate;
|
||||
libs ("libutilityFunctionObjects.so");
|
||||
writeControl timeStep;
|
||||
writeInterval 1;
|
||||
fileToUpdate "$FOAM_CASE/system/fvSolution";
|
||||
timeVsFile
|
||||
(
|
||||
(-1 "$FOAM_CASE/system/fvSolution.0")
|
||||
(0.10 "$FOAM_CASE/system/fvSolution.10")
|
||||
(0.20 "$FOAM_CASE/system/fvSolution.20")
|
||||
(0.35 "$FOAM_CASE/system/fvSolution.35")
|
||||
);
|
||||
...
|
||||
}
|
||||
\endverbatim
|
||||
|
||||
Where the entries comprise:
|
||||
\table
|
||||
Property | Description | Required | Default value
|
||||
type | Type name: timeActivatedFileUpdate | yes |
|
||||
fileToUpdate | Name of file to update | yes |
|
||||
timeVsFile | List of time vs file | yes |
|
||||
\endtable
|
||||
|
||||
|
||||
SourceFiles
|
||||
timeActivatedFileUpdate.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_timeActivatedFileUpdate_H
|
||||
#define functionObjects_timeActivatedFileUpdate_H
|
||||
|
||||
#include "functionObject.H"
|
||||
#include "Tuple2.H"
|
||||
#include "Switch.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declaration of classes
|
||||
class Time;
|
||||
|
||||
namespace functionObjects
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class timeActivatedFileUpdate Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class timeActivatedFileUpdate
|
||||
:
|
||||
public functionObject
|
||||
{
|
||||
// Private data
|
||||
|
||||
//- Reference to Time
|
||||
const Time& time_;
|
||||
|
||||
//- Name of file to update
|
||||
fileName fileToUpdate_;
|
||||
|
||||
//- List of times vs filenames
|
||||
List<Tuple2<scalar, fileName>> timeVsFile_;
|
||||
|
||||
//- Index of last file copied
|
||||
label lastIndex_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Update file
|
||||
void updateFile();
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
timeActivatedFileUpdate(const timeActivatedFileUpdate&);
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const timeActivatedFileUpdate&);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("timeActivatedFileUpdate");
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from Time and dictionary
|
||||
timeActivatedFileUpdate
|
||||
(
|
||||
const word& name,
|
||||
const Time& runTime,
|
||||
const dictionary& dict
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~timeActivatedFileUpdate();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Read the timeActivatedFileUpdate data
|
||||
virtual bool read(const dictionary&);
|
||||
|
||||
//- Execute file updates
|
||||
virtual bool execute();
|
||||
|
||||
//- Do nothing
|
||||
virtual bool write();
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
215
src/functionObjects/utilities/writeDictionary/writeDictionary.C
Normal file
215
src/functionObjects/utilities/writeDictionary/writeDictionary.C
Normal file
@ -0,0 +1,215 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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 "writeDictionary.H"
|
||||
#include "Time.H"
|
||||
#include "polyMesh.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
defineTypeNameAndDebug(writeDictionary, 0);
|
||||
|
||||
addToRunTimeSelectionTable
|
||||
(
|
||||
functionObject,
|
||||
writeDictionary,
|
||||
dictionary
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::writeDictionary::tryDirectory
|
||||
(
|
||||
const label dicti,
|
||||
const word& location,
|
||||
bool& firstDict
|
||||
)
|
||||
{
|
||||
IOobject dictIO
|
||||
(
|
||||
dictNames_[dicti],
|
||||
location,
|
||||
obr_,
|
||||
IOobject::MUST_READ,
|
||||
IOobject::NO_WRITE,
|
||||
false
|
||||
);
|
||||
|
||||
if (dictIO.typeHeaderOk<IOdictionary>(false))
|
||||
{
|
||||
IOdictionary dict(dictIO);
|
||||
|
||||
if (dict.digest() != digests_[dicti])
|
||||
{
|
||||
if (firstDict)
|
||||
{
|
||||
Info<< type() << " " << name() << " write:" << nl << endl;
|
||||
|
||||
IOobject::writeDivider(Info);
|
||||
Info<< endl;
|
||||
firstDict = false;
|
||||
}
|
||||
|
||||
Info<< dict.dictName() << dict << nl;
|
||||
|
||||
IOobject::writeDivider(Info);
|
||||
|
||||
digests_[dicti] = dict.digest();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::writeDictionary::writeDictionary
|
||||
(
|
||||
const word& name,
|
||||
const Time& runTime,
|
||||
const dictionary& dict
|
||||
)
|
||||
:
|
||||
regionFunctionObject(name, runTime, dict),
|
||||
dictNames_(),
|
||||
digests_()
|
||||
{
|
||||
read(dict);
|
||||
execute();
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::writeDictionary::~writeDictionary()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::writeDictionary::read(const dictionary& dict)
|
||||
{
|
||||
regionFunctionObject::read(dict);
|
||||
|
||||
wordList dictNames(dict.lookup("dictNames"));
|
||||
HashSet<word> uniqueNames(dictNames);
|
||||
dictNames_ = uniqueNames.toc();
|
||||
|
||||
digests_.setSize(dictNames_.size(), SHA1Digest());
|
||||
|
||||
Info<< type() << " " << name() << ": monitoring dictionaries:" << nl;
|
||||
if (dictNames_.size())
|
||||
{
|
||||
forAll(dictNames_, i)
|
||||
{
|
||||
Info<< " " << dictNames_[i] << endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Info<< " none" << nl;
|
||||
}
|
||||
Info<< endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::writeDictionary::execute()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::writeDictionary::write()
|
||||
{
|
||||
bool firstDict = true;
|
||||
forAll(dictNames_, i)
|
||||
{
|
||||
if (obr_.foundObject<dictionary>(dictNames_[i]))
|
||||
{
|
||||
const dictionary& dict =
|
||||
obr_.lookupObject<dictionary>(dictNames_[i]);
|
||||
|
||||
if (dict.digest() != digests_[i])
|
||||
{
|
||||
if (firstDict)
|
||||
{
|
||||
Info<< type() << " " << name() << " write:" << nl << endl;
|
||||
|
||||
IOobject::writeDivider(Info);
|
||||
Info<< endl;
|
||||
firstDict = false;
|
||||
}
|
||||
|
||||
digests_[i] = dict.digest();
|
||||
|
||||
Info<< dict.dictName() << dict << nl;
|
||||
IOobject::writeDivider(Info);
|
||||
Info<< endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
bool processed = tryDirectory(i, obr_.time().timeName(), firstDict);
|
||||
|
||||
if (!processed)
|
||||
{
|
||||
processed = tryDirectory(i, obr_.time().constant(), firstDict);
|
||||
}
|
||||
|
||||
if (!processed)
|
||||
{
|
||||
processed = tryDirectory(i, obr_.time().system(), firstDict);
|
||||
}
|
||||
|
||||
if (!processed)
|
||||
{
|
||||
Info<< " Unable to locate dictionary " << dictNames_[i]
|
||||
<< nl << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
Info<< endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
134
src/functionObjects/utilities/writeDictionary/writeDictionary.H
Normal file
134
src/functionObjects/utilities/writeDictionary/writeDictionary.H
Normal file
@ -0,0 +1,134 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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::functionObjects::writeDictionary
|
||||
|
||||
Group
|
||||
grpUtilitiesFunctionObjects
|
||||
|
||||
Description
|
||||
Writes dictionaries on start-up and on change.
|
||||
|
||||
SourceFiles
|
||||
writeDictionary.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_writeDictionary_H
|
||||
#define functionObjects_writeDictionary_H
|
||||
|
||||
#include "regionFunctionObject.H"
|
||||
#include "wordList.H"
|
||||
#include "SHA1Digest.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class writeDictionary Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class writeDictionary
|
||||
:
|
||||
public regionFunctionObject
|
||||
{
|
||||
// Private data
|
||||
|
||||
//- Names of dictionaries to monitor
|
||||
wordList dictNames_;
|
||||
|
||||
//- List of changed dictionaries (only those registered to database)
|
||||
List<SHA1Digest> digests_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Helper function to write the dictionary if found at location
|
||||
bool tryDirectory
|
||||
(
|
||||
const label dicti,
|
||||
const word& location,
|
||||
bool& firstDict
|
||||
);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
// Private member functions
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
writeDictionary(const writeDictionary&);
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const writeDictionary&);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("writeDictionary");
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from Time and dictionary
|
||||
writeDictionary
|
||||
(
|
||||
const word& name,
|
||||
const Time& runTime,
|
||||
const dictionary& dict
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~writeDictionary();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Read the writeDictionary data
|
||||
virtual bool read(const dictionary&);
|
||||
|
||||
//- Execute, currently does nothing
|
||||
virtual bool execute();
|
||||
|
||||
//- Write the selected dictionaries
|
||||
virtual bool write();
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
224
src/functionObjects/utilities/writeObjects/writeObjects.C
Normal file
224
src/functionObjects/utilities/writeObjects/writeObjects.C
Normal file
@ -0,0 +1,224 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
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 "writeObjects.H"
|
||||
#include "Time.H"
|
||||
#include "polyMesh.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace functionObjects
|
||||
{
|
||||
defineTypeNameAndDebug(writeObjects, 0);
|
||||
|
||||
addToRunTimeSelectionTable
|
||||
(
|
||||
functionObject,
|
||||
writeObjects,
|
||||
dictionary
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
template<>
|
||||
const char* Foam::NamedEnum
|
||||
<
|
||||
Foam::functionObjects::writeObjects::writeOption,
|
||||
3
|
||||
>::names[] =
|
||||
{
|
||||
"autoWrite",
|
||||
"noWrite",
|
||||
"anyWrite"
|
||||
};
|
||||
|
||||
const Foam::NamedEnum
|
||||
<
|
||||
Foam::functionObjects::writeObjects::writeOption,
|
||||
3
|
||||
> Foam::functionObjects::writeObjects::writeOptionNames_;
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::writeObjects::writeObjects
|
||||
(
|
||||
const word& name,
|
||||
const Time& runTime,
|
||||
const dictionary& dict
|
||||
)
|
||||
:
|
||||
functionObject(name),
|
||||
obr_
|
||||
(
|
||||
runTime.lookupObject<objectRegistry>
|
||||
(
|
||||
dict.lookupOrDefault("region", polyMesh::defaultRegion)
|
||||
)
|
||||
),
|
||||
writeOption_(ANY_WRITE),
|
||||
objectNames_()
|
||||
{
|
||||
read(dict);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::functionObjects::writeObjects::~writeObjects()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::functionObjects::writeObjects::read(const dictionary& dict)
|
||||
{
|
||||
functionObject::read(dict);
|
||||
|
||||
if (dict.found("field"))
|
||||
{
|
||||
objectNames_.setSize(1);
|
||||
dict.lookup("field") >> objectNames_[0];
|
||||
}
|
||||
else if (dict.found("fields"))
|
||||
{
|
||||
dict.lookup("fields") >> objectNames_;
|
||||
}
|
||||
else
|
||||
{
|
||||
dict.lookup("objects") >> objectNames_;
|
||||
}
|
||||
|
||||
if (dict.found("writeOption"))
|
||||
{
|
||||
writeOption_ = writeOptionNames_.read(dict.lookup("writeOption"));
|
||||
}
|
||||
else
|
||||
{
|
||||
writeOption_ = ANY_WRITE;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::writeObjects::execute()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::functionObjects::writeObjects::write()
|
||||
{
|
||||
Log << type() << " " << name() << " write:" << nl;
|
||||
|
||||
if (!obr_.time().writeTime())
|
||||
{
|
||||
obr_.time().writeTimeDict();
|
||||
}
|
||||
|
||||
DynamicList<word> allNames(obr_.toc().size());
|
||||
forAll(objectNames_, i)
|
||||
{
|
||||
wordList names(obr_.names<regIOobject>(objectNames_[i]));
|
||||
|
||||
if (names.size())
|
||||
{
|
||||
allNames.append(names);
|
||||
}
|
||||
else
|
||||
{
|
||||
WarningInFunction
|
||||
<< "Object " << objectNames_[i] << " not found in "
|
||||
<< "database. Available objects:" << nl << obr_.sortedToc()
|
||||
<< endl;
|
||||
}
|
||||
}
|
||||
|
||||
forAll(allNames, i)
|
||||
{
|
||||
regIOobject& obj = const_cast<regIOobject&>
|
||||
(
|
||||
obr_.lookupObject<regIOobject>(allNames[i])
|
||||
);
|
||||
|
||||
switch (writeOption_)
|
||||
{
|
||||
case AUTO_WRITE:
|
||||
{
|
||||
if (obj.writeOpt() != IOobject::AUTO_WRITE)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case NO_WRITE:
|
||||
{
|
||||
if (obj.writeOpt() != IOobject::NO_WRITE)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case ANY_WRITE:
|
||||
{
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Unknown writeOption "
|
||||
<< writeOptionNames_[writeOption_]
|
||||
<< ". Valid writeOption types are" << writeOptionNames_
|
||||
<< exit(FatalError);
|
||||
}
|
||||
}
|
||||
|
||||
if
|
||||
(
|
||||
obj.writeOpt() == IOobject::AUTO_WRITE
|
||||
&& obr_.time().writeTime()
|
||||
)
|
||||
{
|
||||
Log << " automatically written object " << obj.name() << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log << " writing object " << obj.name() << endl;
|
||||
|
||||
obj.write();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
190
src/functionObjects/utilities/writeObjects/writeObjects.H
Normal file
190
src/functionObjects/utilities/writeObjects/writeObjects.H
Normal file
@ -0,0 +1,190 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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::functionObjects::writeObjects
|
||||
|
||||
Group
|
||||
grpUtilitiesFunctionObjects
|
||||
|
||||
Description
|
||||
Allows specification of different writing frequency of objects registered
|
||||
to the database.
|
||||
|
||||
It has similar functionality as the main time database through the
|
||||
\c writeControl setting:
|
||||
- timeStep
|
||||
- writeTime
|
||||
- adjustableRunTime
|
||||
- runTime
|
||||
- clockTime
|
||||
- cpuTime
|
||||
|
||||
It also has the ability to write the selected objects that were defined
|
||||
with the respective write mode for the requested \c writeOption, namely:
|
||||
\vartable
|
||||
autoWrite | objects set to write at output time
|
||||
noWrite | objects set to not write by default
|
||||
anyWrite | any option of the previous two
|
||||
\endvartable
|
||||
|
||||
Usage
|
||||
Example of function object specification:
|
||||
\verbatim
|
||||
writeObjects1
|
||||
{
|
||||
type writeObjects;
|
||||
libs ("libutilityFunctionObjects.so");
|
||||
...
|
||||
objects (obj1 obj2);
|
||||
writeOption anyWrite;
|
||||
}
|
||||
\endverbatim
|
||||
|
||||
Where the entries comprise:
|
||||
\table
|
||||
Property | Description | Required | Default value
|
||||
type | type name: writeObjects | yes |
|
||||
objects | objects to write | yes |
|
||||
writeOption | only those with this write option | no | anyWrite
|
||||
\endtable
|
||||
|
||||
Note: Regular expressions can also be used in \c objects.
|
||||
|
||||
See also
|
||||
Foam::functionObject
|
||||
Foam::functionObjects::timeControl
|
||||
|
||||
SourceFiles
|
||||
writeObjects.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef functionObjects_writeObjects_H
|
||||
#define functionObjects_writeObjects_H
|
||||
|
||||
#include "functionObject.H"
|
||||
#include "wordReList.H"
|
||||
#include "NamedEnum.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declaration of classes
|
||||
class objectRegistry;
|
||||
|
||||
namespace functionObjects
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class writeObjects Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class writeObjects
|
||||
:
|
||||
public functionObject
|
||||
{
|
||||
public:
|
||||
|
||||
// Public data types
|
||||
|
||||
//- Re-enumeration defining the write options, based on the original
|
||||
// ones at IOobject::writeOption
|
||||
enum writeOption
|
||||
{
|
||||
AUTO_WRITE,
|
||||
NO_WRITE,
|
||||
ANY_WRITE
|
||||
};
|
||||
|
||||
static const NamedEnum<writeOption, 3> writeOptionNames_;
|
||||
|
||||
private:
|
||||
|
||||
// Private data
|
||||
|
||||
//- Reference to Db
|
||||
const objectRegistry& obr_;
|
||||
|
||||
//- To only write objects of defined writeOption
|
||||
writeOption writeOption_;
|
||||
|
||||
//- Names of objects to control
|
||||
wordReList objectNames_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
writeObjects(const writeObjects&);
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const writeObjects&);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("writeObjects");
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from Time and dictionary
|
||||
writeObjects
|
||||
(
|
||||
const word& name,
|
||||
const Time& runTime,
|
||||
const dictionary& dict
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~writeObjects();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Read the writeObjects data
|
||||
virtual bool read(const dictionary&);
|
||||
|
||||
//- Do nothing
|
||||
virtual bool execute();
|
||||
|
||||
//- Write the registered objects
|
||||
virtual bool write();
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace functionObjects
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
Reference in New Issue
Block a user