mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: Multiple updates to function objects
Updated objects
- corrected Peclet number for compressible cases
- propagated log flag and resultName across objects
New function objects
- new fluxSummary:
- calculates positive, negative, absolute and net flux across face
zones
- new runTimeControl
- abort the calculation when a user-defined metric is achieved.
Available options include:
- average value remains unchanged wrt a given threshold
- equation initial residual exceeds a threshold - useful to abort
diverging cases
- equation max iterations exceeds a threshold - useful to abort
diverging cases
- min/max of a function object value
- min time step exceeds a threshold - useful to abort diverging
cases
- new valueAverage:
- average singular values from other function objects, e.g. Cd, Cl and
Cm from the forceCoeffs function object
This commit is contained in:
@ -1,4 +1,20 @@
|
||||
abortCalculation/abortCalculation.C
|
||||
abortCalculation/abortCalculationFunctionObject.C
|
||||
|
||||
runTimeControl/runTimeControl.C
|
||||
runTimeControl/runTimeControlFunctionObject.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
|
||||
|
||||
externalCoupled = externalCoupled
|
||||
$(externalCoupled)/externalCoupledFunctionObject.C
|
||||
$(externalCoupled)/externalCoupledMixed/externalCoupledMixedFvPatchFields.C
|
||||
$(externalCoupled)/externalCoupledTemperatureMixed/externalCoupledTemperatureMixedFvPatchScalarField.C
|
||||
|
||||
|
||||
LIB = $(FOAM_LIBBIN)/libjobControl
|
||||
|
||||
@ -0,0 +1,10 @@
|
||||
EXE_INC = \
|
||||
-I$(LIB_SRC)/finiteVolume/lnInclude \
|
||||
-I$(LIB_SRC)/TurbulenceModels/turbulenceModels/lnInclude \
|
||||
-I$(LIB_SRC)/TurbulenceModels/compressible/lnInclude \
|
||||
-I$(LIB_SRC)/thermophysicalModels/basic/lnInclude \
|
||||
-I$(LIB_SRC)/transportModels/compressible/lnInclude
|
||||
|
||||
LIB_LIBS = \
|
||||
-lfiniteVolume \
|
||||
-lcompressibleTurbulenceModels
|
||||
|
||||
@ -0,0 +1,947 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 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 "externalCoupledFunctionObject.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
#include "OSspecific.H"
|
||||
#include "IFstream.H"
|
||||
#include "OFstream.H"
|
||||
#include "volFields.H"
|
||||
#include "globalIndex.H"
|
||||
#include "fvMesh.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
defineTypeNameAndDebug(externalCoupledFunctionObject, 0);
|
||||
|
||||
addToRunTimeSelectionTable
|
||||
(
|
||||
functionObject,
|
||||
externalCoupledFunctionObject,
|
||||
dictionary
|
||||
);
|
||||
}
|
||||
|
||||
Foam::word Foam::externalCoupledFunctionObject::lockName = "OpenFOAM";
|
||||
|
||||
Foam::string Foam::externalCoupledFunctionObject::patchKey = "# Patch: ";
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
Foam::fileName Foam::externalCoupledFunctionObject::baseDir() const
|
||||
{
|
||||
fileName result(commsDir_);
|
||||
result.clean();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Foam::fileName Foam::externalCoupledFunctionObject::groupDir
|
||||
(
|
||||
const fileName& commsDir,
|
||||
const word& regionName,
|
||||
const wordRe& groupName
|
||||
)
|
||||
{
|
||||
fileName result(commsDir/regionName/string::validate<fileName>(groupName));
|
||||
result.clean();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Foam::fileName Foam::externalCoupledFunctionObject::lockFile() const
|
||||
{
|
||||
return fileName(baseDir()/(lockName + ".lock"));
|
||||
}
|
||||
|
||||
|
||||
void Foam::externalCoupledFunctionObject::createLockFile() const
|
||||
{
|
||||
if (!Pstream::master())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const fileName fName(lockFile());
|
||||
IFstream is(fName);
|
||||
|
||||
// Only create lock file if it doesn't already exist
|
||||
if (!is.good())
|
||||
{
|
||||
if (log_) Info<< type() << ": creating lock file" << endl;
|
||||
|
||||
OFstream os(fName);
|
||||
os << "lock file";
|
||||
os.flush();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::externalCoupledFunctionObject::removeLockFile() const
|
||||
{
|
||||
if (!Pstream::master())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (log_) Info<< type() << ": removing lock file" << endl;
|
||||
|
||||
rm(lockFile());
|
||||
}
|
||||
|
||||
|
||||
void Foam::externalCoupledFunctionObject::removeReadFiles() const
|
||||
{
|
||||
if (!Pstream::master())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (log_) Info<< type() << ": removing all read files" << endl;
|
||||
|
||||
forAll(regionNames_, regionI)
|
||||
{
|
||||
const word& regionName = regionNames_[regionI];
|
||||
const fvMesh& mesh = time_.lookupObject<fvMesh>(regionName);
|
||||
const labelList& groups = regionToGroups_[regionName];
|
||||
forAll(groups, i)
|
||||
{
|
||||
label groupI = groups[i];
|
||||
const wordRe& groupName = groupNames_[groupI];
|
||||
|
||||
forAll(groupReadFields_[groupI], fieldI)
|
||||
{
|
||||
const word& fieldName = groupReadFields_[groupI][fieldI];
|
||||
rm
|
||||
(
|
||||
groupDir(commsDir_, mesh.dbDir(), groupName)
|
||||
/ fieldName + ".in"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::externalCoupledFunctionObject::removeWriteFiles() const
|
||||
{
|
||||
if (!Pstream::master())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (log_) Info<< type() << ": removing all write files" << endl;
|
||||
|
||||
forAll(regionNames_, regionI)
|
||||
{
|
||||
const word& regionName = regionNames_[regionI];
|
||||
const fvMesh& mesh = time_.lookupObject<fvMesh>(regionName);
|
||||
const labelList& groups = regionToGroups_[regionName];
|
||||
forAll(groups, i)
|
||||
{
|
||||
label groupI = groups[i];
|
||||
const wordRe& groupName = groupNames_[groupI];
|
||||
|
||||
forAll(groupWriteFields_[groupI], fieldI)
|
||||
{
|
||||
const word& fieldName = groupWriteFields_[groupI][fieldI];
|
||||
rm
|
||||
(
|
||||
groupDir(commsDir_, mesh.dbDir(), groupName)
|
||||
/ fieldName + ".out"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::externalCoupledFunctionObject::wait() const
|
||||
{
|
||||
const fileName fName(lockFile());
|
||||
label found = 0;
|
||||
label totalTime = 0;
|
||||
|
||||
if (log_) Info<< type() << ": beginning wait for lock file " << fName << nl;
|
||||
|
||||
while (found == 0)
|
||||
{
|
||||
if (Pstream::master())
|
||||
{
|
||||
if (totalTime > timeOut_)
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"void "
|
||||
"Foam::externalCoupledFunctionObject::wait() "
|
||||
"const"
|
||||
)
|
||||
<< "Wait time exceeded time out time of " << timeOut_
|
||||
<< " s" << abort(FatalError);
|
||||
}
|
||||
|
||||
IFstream is(fName);
|
||||
|
||||
if (is.good())
|
||||
{
|
||||
found++;
|
||||
|
||||
if (log_)
|
||||
{
|
||||
Info<< type() << ": found lock file " << fName << endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sleep(waitInterval_);
|
||||
totalTime += waitInterval_;
|
||||
|
||||
if (log_)
|
||||
{
|
||||
Info<< type() << ": wait time = " << totalTime << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// prevent other procs from racing ahead
|
||||
reduce(found, sumOp<label>());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::externalCoupledFunctionObject::readColumns
|
||||
(
|
||||
const label nRows,
|
||||
const label nColumns,
|
||||
autoPtr<IFstream>& masterFilePtr,
|
||||
List<scalarField>& data
|
||||
) const
|
||||
{
|
||||
// Get sizes for all processors
|
||||
const globalIndex globalFaces(nRows);
|
||||
|
||||
PstreamBuffers pBufs(Pstream::nonBlocking);
|
||||
if (Pstream::master())
|
||||
{
|
||||
string line;
|
||||
|
||||
// Read data from file and send to destination processor
|
||||
|
||||
for (label procI = 0; procI < Pstream::nProcs(); procI++)
|
||||
{
|
||||
// Temporary storage
|
||||
List<scalarField> values(nColumns);
|
||||
|
||||
// Number of rows to read for processor procI
|
||||
label procNRows = globalFaces.localSize(procI);
|
||||
|
||||
forAll(values, columnI)
|
||||
{
|
||||
values[columnI].setSize(procNRows);
|
||||
}
|
||||
|
||||
for (label rowI = 0; rowI < procNRows; rowI++)
|
||||
{
|
||||
// Get a line
|
||||
do
|
||||
{
|
||||
if (!masterFilePtr().good())
|
||||
{
|
||||
FatalIOErrorIn
|
||||
(
|
||||
"externalCoupledFunctionObject::readColumns()",
|
||||
masterFilePtr()
|
||||
) << "Trying to read data for processor " << procI
|
||||
<< " row " << rowI
|
||||
<< ". Does your file have as many rows as there are"
|
||||
<< " patch faces (" << globalFaces.size()
|
||||
<< ") ?" << exit(FatalIOError);
|
||||
}
|
||||
|
||||
masterFilePtr().getLine(line);
|
||||
} while (line.empty() || line[0] == '#');
|
||||
|
||||
IStringStream lineStr(line);
|
||||
|
||||
for (label columnI = 0; columnI < nColumns; columnI++)
|
||||
{
|
||||
lineStr >> values[columnI][rowI];
|
||||
}
|
||||
}
|
||||
|
||||
// Send to procI
|
||||
UOPstream str(procI, pBufs);
|
||||
str << values;
|
||||
}
|
||||
}
|
||||
pBufs.finishedSends();
|
||||
|
||||
// Read from PstreamBuffers
|
||||
UIPstream str(Pstream::masterNo(), pBufs);
|
||||
str >> data;
|
||||
}
|
||||
|
||||
|
||||
void Foam::externalCoupledFunctionObject::readLines
|
||||
(
|
||||
const label nRows,
|
||||
autoPtr<IFstream>& masterFilePtr,
|
||||
OStringStream& lines
|
||||
) const
|
||||
{
|
||||
// Get sizes for all processors
|
||||
const globalIndex globalFaces(nRows);
|
||||
|
||||
PstreamBuffers pBufs(Pstream::nonBlocking);
|
||||
|
||||
if (Pstream::master())
|
||||
{
|
||||
string line;
|
||||
|
||||
// Read line from file and send to destination processor
|
||||
|
||||
for (label procI = 0; procI < Pstream::nProcs(); procI++)
|
||||
{
|
||||
// Number of rows to read for processor procI
|
||||
label procNRows = globalFaces.localSize(procI);
|
||||
|
||||
UOPstream toProc(procI, pBufs);
|
||||
|
||||
for (label rowI = 0; rowI < procNRows; rowI++)
|
||||
{
|
||||
// Get a line
|
||||
do
|
||||
{
|
||||
if (!masterFilePtr().good())
|
||||
{
|
||||
FatalIOErrorIn
|
||||
(
|
||||
"externalCoupledFunctionObject::readColumns()",
|
||||
masterFilePtr()
|
||||
) << "Trying to read data for processor " << procI
|
||||
<< " row " << rowI
|
||||
<< ". Does your file have as many rows as there are"
|
||||
<< " patch faces (" << globalFaces.size()
|
||||
<< ") ?" << exit(FatalIOError);
|
||||
}
|
||||
|
||||
masterFilePtr().getLine(line);
|
||||
} while (line.empty() || line[0] == '#');
|
||||
|
||||
// Send line to the destination processor
|
||||
toProc << line;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pBufs.finishedSends();
|
||||
|
||||
// Read lines from PstreamBuffers
|
||||
UIPstream str(Pstream::masterNo(), pBufs);
|
||||
for (label rowI = 0; rowI < nRows; rowI++)
|
||||
{
|
||||
string line(str);
|
||||
lines << line.c_str() << nl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::externalCoupledFunctionObject::writeGeometry
|
||||
(
|
||||
const fvMesh& mesh,
|
||||
const fileName& commsDir,
|
||||
const wordRe& groupName
|
||||
)
|
||||
{
|
||||
fileName dir(groupDir(commsDir, mesh.dbDir(), groupName));
|
||||
|
||||
//if (log_)
|
||||
{
|
||||
Info<< typeName << ": writing geometry to " << dir << endl;
|
||||
}
|
||||
|
||||
autoPtr<OFstream> osPointsPtr;
|
||||
autoPtr<OFstream> osFacesPtr;
|
||||
if (Pstream::master())
|
||||
{
|
||||
mkDir(dir);
|
||||
osPointsPtr.reset(new OFstream(dir/"patchPoints"));
|
||||
osFacesPtr.reset(new OFstream(dir/"patchFaces"));
|
||||
}
|
||||
|
||||
const labelList patchIDs
|
||||
(
|
||||
mesh.boundaryMesh().patchSet
|
||||
(
|
||||
List<wordRe>(1, groupName)
|
||||
).sortedToc()
|
||||
);
|
||||
|
||||
forAll(patchIDs, i)
|
||||
{
|
||||
label patchI = patchIDs[i];
|
||||
|
||||
const polyPatch& p = mesh.boundaryMesh()[patchI];
|
||||
|
||||
labelList pointToGlobal;
|
||||
labelList uniquePointIDs;
|
||||
mesh.globalData().mergePoints
|
||||
(
|
||||
p.meshPoints(),
|
||||
p.meshPointMap(),
|
||||
pointToGlobal,
|
||||
uniquePointIDs
|
||||
);
|
||||
|
||||
label procI = Pstream::myProcNo();
|
||||
|
||||
List<pointField> allPoints(Pstream::nProcs());
|
||||
allPoints[procI] = pointField(mesh.points(), uniquePointIDs);
|
||||
Pstream::gatherList(allPoints);
|
||||
|
||||
List<faceList> allFaces(Pstream::nProcs());
|
||||
faceList& patchFaces = allFaces[procI];
|
||||
patchFaces = p.localFaces();
|
||||
forAll(patchFaces, faceI)
|
||||
{
|
||||
inplaceRenumber(pointToGlobal, patchFaces[faceI]);
|
||||
}
|
||||
Pstream::gatherList(allFaces);
|
||||
|
||||
if (Pstream::master())
|
||||
{
|
||||
pointField pts
|
||||
(
|
||||
ListListOps::combine<pointField>
|
||||
(
|
||||
allPoints,
|
||||
accessOp<pointField>()
|
||||
)
|
||||
);
|
||||
|
||||
//if (log_)
|
||||
{
|
||||
Info<< typeName << ": for patch " << p.name()
|
||||
<< " writing " << pts.size() << " points to "
|
||||
<< osPointsPtr().name() << endl;
|
||||
}
|
||||
|
||||
// Write points
|
||||
osPointsPtr() << patchKey.c_str() << p.name() << pts << endl;
|
||||
|
||||
faceList fcs
|
||||
(
|
||||
ListListOps::combine<faceList>(allFaces, accessOp<faceList>())
|
||||
);
|
||||
|
||||
//if (log_)
|
||||
{
|
||||
Info<< typeName << ": for patch " << p.name()
|
||||
<< " writing " << fcs.size() << " faces to "
|
||||
<< osFacesPtr().name() << endl;
|
||||
}
|
||||
|
||||
// Write faces
|
||||
osFacesPtr() << patchKey.c_str() << p.name() << fcs << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::externalCoupledFunctionObject::readData()
|
||||
{
|
||||
forAll(regionNames_, regionI)
|
||||
{
|
||||
const word& regionName = regionNames_[regionI];
|
||||
const labelList& groups = regionToGroups_[regionName];
|
||||
|
||||
const fvMesh& mesh = time_.lookupObject<fvMesh>(regionName);
|
||||
|
||||
forAll(groups, i)
|
||||
{
|
||||
label groupI = groups[i];
|
||||
const wordRe& groupName = groupNames_[groupI];
|
||||
const labelList& patchIDs = groupPatchIDs_[groupI];
|
||||
const wordList& fieldNames = groupReadFields_[groupI];
|
||||
|
||||
forAll(fieldNames, fieldI)
|
||||
{
|
||||
const word& fieldName = fieldNames[fieldI];
|
||||
|
||||
bool ok = readData<scalar>
|
||||
(
|
||||
mesh,
|
||||
groupName,
|
||||
patchIDs,
|
||||
fieldName
|
||||
);
|
||||
ok = ok || readData<vector>
|
||||
(
|
||||
mesh,
|
||||
groupName,
|
||||
patchIDs,
|
||||
fieldName
|
||||
);
|
||||
ok = ok || readData<sphericalTensor>
|
||||
(
|
||||
mesh,
|
||||
groupName,
|
||||
patchIDs,
|
||||
fieldName
|
||||
);
|
||||
ok = ok || readData<symmTensor>
|
||||
(
|
||||
mesh,
|
||||
groupName,
|
||||
patchIDs,
|
||||
fieldName
|
||||
);
|
||||
ok = ok || readData<tensor>
|
||||
(
|
||||
mesh,
|
||||
groupName,
|
||||
patchIDs,
|
||||
fieldName
|
||||
);
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
WarningIn
|
||||
(
|
||||
"void Foam::externalCoupledFunctionObject::readData()"
|
||||
)
|
||||
<< "Field " << fieldName << " in region " << mesh.name()
|
||||
<< " was not found." << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::externalCoupledFunctionObject::writeData() const
|
||||
{
|
||||
forAll(regionNames_, regionI)
|
||||
{
|
||||
const word& regionName = regionNames_[regionI];
|
||||
const labelList& groups = regionToGroups_[regionName];
|
||||
|
||||
const fvMesh& mesh = time_.lookupObject<fvMesh>(regionName);
|
||||
|
||||
forAll(groups, i)
|
||||
{
|
||||
label groupI = groups[i];
|
||||
const wordRe& groupName = groupNames_[groupI];
|
||||
const labelList& patchIDs = groupPatchIDs_[groupI];
|
||||
const wordList& fieldNames = groupWriteFields_[groupI];
|
||||
|
||||
forAll(fieldNames, fieldI)
|
||||
{
|
||||
const word& fieldName = fieldNames[fieldI];
|
||||
bool ok = writeData<scalar>
|
||||
(
|
||||
mesh,
|
||||
groupName,
|
||||
patchIDs,
|
||||
fieldName
|
||||
);
|
||||
ok = ok || writeData<vector>
|
||||
(
|
||||
mesh,
|
||||
groupName,
|
||||
patchIDs,
|
||||
fieldName
|
||||
);
|
||||
ok = ok || writeData<sphericalTensor>
|
||||
(
|
||||
mesh,
|
||||
groupName,
|
||||
patchIDs,
|
||||
fieldName
|
||||
);
|
||||
ok = ok || writeData<symmTensor>
|
||||
(
|
||||
mesh,
|
||||
groupName,
|
||||
patchIDs,
|
||||
fieldName
|
||||
);
|
||||
ok = ok || writeData<tensor>
|
||||
(
|
||||
mesh,
|
||||
groupName,
|
||||
patchIDs,
|
||||
fieldName
|
||||
);
|
||||
|
||||
if (!ok)
|
||||
{
|
||||
WarningIn
|
||||
(
|
||||
"void Foam::externalCoupledFunctionObject::writeData()"
|
||||
)
|
||||
<< "Field " << fieldName << " in region " << mesh.name()
|
||||
<< " was not found." << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::externalCoupledFunctionObject::initialise()
|
||||
{
|
||||
if (initialised_)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Write the geometry if not already there
|
||||
forAll(regionNames_, regionI)
|
||||
{
|
||||
const word& regionName = regionNames_[regionI];
|
||||
const labelList& groups = regionToGroups_[regionName];
|
||||
|
||||
const fvMesh& mesh = time_.lookupObject<fvMesh>(regionName);
|
||||
|
||||
forAll(groups, i)
|
||||
{
|
||||
label groupI = groups[i];
|
||||
const wordRe& groupName = groupNames_[groupI];
|
||||
|
||||
bool exists = false;
|
||||
if (Pstream::master())
|
||||
{
|
||||
fileName dir(groupDir(commsDir_, mesh.dbDir(), groupName));
|
||||
|
||||
exists = isFile(dir/"patchPoints") || isFile(dir/"patchFaces");
|
||||
}
|
||||
|
||||
if (!returnReduce(exists, orOp<bool>()))
|
||||
{
|
||||
writeGeometry(mesh, commsDir_, groupName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (initByExternal_)
|
||||
{
|
||||
// Wait for initial data to be made available
|
||||
wait();
|
||||
|
||||
// Eead data passed back from external source
|
||||
readData();
|
||||
}
|
||||
|
||||
initialised_ = true;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::externalCoupledFunctionObject::externalCoupledFunctionObject
|
||||
(
|
||||
const word& name,
|
||||
const Time& runTime,
|
||||
const dictionary& dict
|
||||
)
|
||||
:
|
||||
functionObject(name),
|
||||
time_(runTime),
|
||||
enabled_(true),
|
||||
initialised_(false)
|
||||
{
|
||||
read(dict);
|
||||
|
||||
if (Pstream::master())
|
||||
{
|
||||
mkDir(baseDir());
|
||||
}
|
||||
|
||||
if (!initByExternal_)
|
||||
{
|
||||
createLockFile();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::externalCoupledFunctionObject::~externalCoupledFunctionObject()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::externalCoupledFunctionObject::on()
|
||||
{
|
||||
enabled_ = true;
|
||||
}
|
||||
|
||||
|
||||
void Foam::externalCoupledFunctionObject::off()
|
||||
{
|
||||
enabled_ = false;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::externalCoupledFunctionObject::start()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::externalCoupledFunctionObject::execute(const bool forceWrite)
|
||||
{
|
||||
if
|
||||
(
|
||||
enabled()
|
||||
&& (!initialised_ || time_.timeIndex() % calcFrequency_ == 0)
|
||||
)
|
||||
{
|
||||
// Initialise the coupling
|
||||
initialise();
|
||||
|
||||
// Write data for external source
|
||||
writeData();
|
||||
|
||||
// remove lock file, signalling external source to execute
|
||||
removeLockFile();
|
||||
|
||||
// Wait for response
|
||||
wait();
|
||||
|
||||
// Remove old data files from OpenFOAM
|
||||
removeWriteFiles();
|
||||
|
||||
// Read data passed back from external source
|
||||
readData();
|
||||
|
||||
// create lock file for external source
|
||||
createLockFile();
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool Foam::externalCoupledFunctionObject::end()
|
||||
{
|
||||
if (enabled())
|
||||
{
|
||||
// Remove old data files
|
||||
removeReadFiles();
|
||||
removeWriteFiles();
|
||||
removeLockFile();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::externalCoupledFunctionObject::timeSet()
|
||||
{
|
||||
// Do nothing - only valid on execute
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::externalCoupledFunctionObject::adjustTimeStep()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::externalCoupledFunctionObject::read(const dictionary& dict)
|
||||
{
|
||||
dict.readIfPresent("enabled", enabled_);
|
||||
|
||||
if (!enabled_)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
dict.lookup("commsDir") >> commsDir_;
|
||||
commsDir_.expand();
|
||||
|
||||
waitInterval_ = dict.lookupOrDefault("waitInterval", 1);
|
||||
timeOut_ = dict.lookupOrDefault("timeOut", 100*waitInterval_);
|
||||
calcFrequency_ = dict.lookupOrDefault("calcFrequency", 1);
|
||||
initByExternal_ = readBool(dict.lookup("initByExternal"));
|
||||
log_ = dict.lookupOrDefault("log", false);
|
||||
|
||||
const dictionary& allRegionsDict = dict.subDict("regions");
|
||||
|
||||
forAllConstIter(dictionary, allRegionsDict, iter)
|
||||
{
|
||||
if (!iter().isDict())
|
||||
{
|
||||
FatalIOErrorIn
|
||||
(
|
||||
"void Foam::externalCoupledFunctionObject::read"
|
||||
"(const dictionary&)",
|
||||
allRegionsDict
|
||||
)
|
||||
<< "Regions must be specified in dictionary format"
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
|
||||
const word& regionName = iter().keyword();
|
||||
const dictionary& regionDict = iter().dict();
|
||||
regionNames_.append(regionName);
|
||||
|
||||
forAllConstIter(dictionary, regionDict, regionIter)
|
||||
{
|
||||
if (!regionIter().isDict())
|
||||
{
|
||||
FatalIOErrorIn
|
||||
(
|
||||
"void Foam::externalCoupledFunctionObject::read"
|
||||
"(const dictionary&)",
|
||||
regionDict
|
||||
)
|
||||
<< "Regions must be specified in dictionary format"
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
const wordRe groupName(regionIter().keyword());
|
||||
const dictionary& groupDict = regionIter().dict();
|
||||
|
||||
label nGroups = groupNames_.size();
|
||||
const wordList readFields(groupDict.lookup("readFields"));
|
||||
const wordList writeFields(groupDict.lookup("writeFields"));
|
||||
|
||||
HashTable<labelList>::iterator fnd = regionToGroups_.find
|
||||
(
|
||||
regionName
|
||||
);
|
||||
if (fnd != regionToGroups_.end())
|
||||
{
|
||||
fnd().append(nGroups);
|
||||
}
|
||||
else
|
||||
{
|
||||
regionToGroups_.insert(regionName, labelList(1, nGroups));
|
||||
}
|
||||
groupNames_.append(groupName);
|
||||
groupReadFields_.append(readFields);
|
||||
groupWriteFields_.append(writeFields);
|
||||
|
||||
// Pre-calculate the patchIDs
|
||||
const fvMesh& mesh = time_.lookupObject<fvMesh>(regionName);
|
||||
groupPatchIDs_.append
|
||||
(
|
||||
mesh.boundaryMesh().patchSet
|
||||
(
|
||||
List<wordRe>(1, groupName)
|
||||
).sortedToc()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Print a bit
|
||||
if (log_)
|
||||
{
|
||||
Info<< type() << ": Communicating with regions:" << endl;
|
||||
forAll(regionNames_, regionI)
|
||||
{
|
||||
const word& regionName = regionNames_[regionI];
|
||||
const fvMesh& mesh = time_.lookupObject<fvMesh>(regionName);
|
||||
|
||||
Info<< "Region: " << mesh.name() << endl << incrIndent;
|
||||
const labelList& groups = regionToGroups_[regionName];
|
||||
forAll(groups, i)
|
||||
{
|
||||
label groupI = groups[i];
|
||||
const wordRe& groupName = groupNames_[groupI];
|
||||
const labelList& patchIDs = groupPatchIDs_[groupI];
|
||||
|
||||
Info<< indent << "Group: " << groupName << "\t"
|
||||
<< " patches: " << patchIDs << endl
|
||||
<< incrIndent
|
||||
<< indent << "Reading fields: " << groupReadFields_[groupI]
|
||||
<< endl
|
||||
<< indent << "Writing fields: " << groupWriteFields_[groupI]
|
||||
<< endl
|
||||
<< decrIndent;
|
||||
}
|
||||
Info<< decrIndent;
|
||||
}
|
||||
Info<< endl;
|
||||
}
|
||||
|
||||
|
||||
// Note: we should not have to make directories since the geometry
|
||||
// should already be written - but just make sure
|
||||
if (Pstream::master())
|
||||
{
|
||||
forAll(regionNames_, regionI)
|
||||
{
|
||||
const word& regionName = regionNames_[regionI];
|
||||
const fvMesh& mesh = time_.lookupObject<fvMesh>(regionName);
|
||||
const labelList& groups = regionToGroups_[regionName];
|
||||
forAll(groups, i)
|
||||
{
|
||||
label groupI = groups[i];
|
||||
const wordRe& groupName = groupNames_[groupI];
|
||||
|
||||
fileName dir(groupDir(commsDir_, mesh.dbDir(), groupName));
|
||||
if (!isDir(dir))
|
||||
{
|
||||
if (log_)
|
||||
{
|
||||
Info<< type() << ": creating communications directory "
|
||||
<< dir << endl;
|
||||
}
|
||||
|
||||
mkDir(dir);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void Foam::externalCoupledFunctionObject::updateMesh(const mapPolyMesh& mpm)
|
||||
{}
|
||||
|
||||
|
||||
void Foam::externalCoupledFunctionObject::movePoints(const polyMesh& mesh)
|
||||
{}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,383 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify i
|
||||
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::externalCoupledFunctionObject
|
||||
|
||||
Group
|
||||
grpJobControlFunctionObjects
|
||||
|
||||
Description
|
||||
This functionObject provides a simple interface for explicit coupling with
|
||||
an external application. The coupling is through plain text files
|
||||
where OpenFOAM boundary data is read/written as one line per face
|
||||
(data from all processors collated):
|
||||
|
||||
# Patch: <patch name>
|
||||
<fld1> <fld2> .. <fldn> //face0
|
||||
<fld1> <fld2> .. <fldn> //face1
|
||||
..
|
||||
<fld1> <fld2> .. <fldn> //faceN
|
||||
|
||||
where the actual entries depend on the bc type:
|
||||
- mixed: value, snGrad, refValue, refGrad, valueFraction
|
||||
- externalCoupledMixed: output of writeData
|
||||
- other: value, snGrad
|
||||
|
||||
These text files are located in a user specified communications directory
|
||||
which gets read/written on the master processor only. In the
|
||||
communications directory the structure will be
|
||||
|
||||
<regionName>/<patchGroup>/<fieldName>.[in|out]
|
||||
|
||||
At start-up, the boundary creates a lock file, i.e..
|
||||
|
||||
OpenFOAM.lock
|
||||
|
||||
... to signal the external source to wait. During the functionObject
|
||||
execution the boundary values are written to files (one per region,
|
||||
per patch(group), per field), e.g.
|
||||
|
||||
<regionName>/<patchGroup>/<fieldName>.out
|
||||
|
||||
The lock file is then removed, instructing the external source to take
|
||||
control of the program execution. When ready, the external program
|
||||
should create the return values, e.g. to files
|
||||
|
||||
<regionName>/<patchGroup>/<fieldName>.in
|
||||
|
||||
... and then re-instate the lock file. The functionObject will then
|
||||
read these values, apply them to the boundary conditions and pass
|
||||
program execution back to OpenFOAM.
|
||||
|
||||
Example of function object specification:
|
||||
\verbatim
|
||||
externalCoupled
|
||||
{
|
||||
type externalCoupled;
|
||||
...
|
||||
log yes;
|
||||
commsDir "${FOAM_CASE}/comms";
|
||||
initByExternal yes;
|
||||
|
||||
regions
|
||||
{
|
||||
region0
|
||||
{
|
||||
TPatchGroup // Name of patch(group)
|
||||
{
|
||||
readFields (p); // List of fields to read
|
||||
writeFields (T); // List of fields to write
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
\endverbatim
|
||||
|
||||
This reads/writes (on the master processor) the directory:
|
||||
comms/region0/TPatchGroup/
|
||||
with contents:
|
||||
patchPoints (collected points)
|
||||
patchFaces (collected faces)
|
||||
p.in (input file of p, written by external application)
|
||||
T.out (output file of T, written by OpenFOAM)
|
||||
|
||||
The patchPoints/patchFaces files denote the (collated) geometry
|
||||
which will be written if it does not exist yet or can be written as
|
||||
a preprocessing step using the createExternalCoupledPatchGeometry
|
||||
application.
|
||||
|
||||
SourceFiles
|
||||
externalCoupledFunctionObject.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef externalCoupledFunctionObject_H
|
||||
#define externalCoupledFunctionObject_H
|
||||
|
||||
#include "functionObject.H"
|
||||
#include "DynamicList.H"
|
||||
#include "wordReList.H"
|
||||
#include "scalarField.H"
|
||||
#include "Switch.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declaration of classes
|
||||
class dictionary;
|
||||
class polyMesh;
|
||||
class mapPolyMesh;
|
||||
class IFstream;
|
||||
class fvMesh;
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class externalCoupledFunctionObject Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class externalCoupledFunctionObject
|
||||
:
|
||||
public functionObject
|
||||
{
|
||||
// Private data
|
||||
|
||||
//- Reference to the time database
|
||||
const Time& time_;
|
||||
|
||||
//- Switch for the execution - defaults to 'yes/on'
|
||||
Switch enabled_;
|
||||
|
||||
//- Path to communications directory
|
||||
fileName commsDir_;
|
||||
|
||||
//- Interval time between checking for return data [s]
|
||||
label waitInterval_;
|
||||
|
||||
//- Time out time [s]
|
||||
label timeOut_;
|
||||
|
||||
//- Calculation frequency
|
||||
label calcFrequency_;
|
||||
|
||||
//- Flag to indicate values are initialised by external application
|
||||
bool initByExternal_;
|
||||
|
||||
//- Log flag
|
||||
bool log_;
|
||||
|
||||
//- Names of regions
|
||||
DynamicList<word> regionNames_;
|
||||
|
||||
// Per region the indices of the group information
|
||||
HashTable<labelList> regionToGroups_;
|
||||
|
||||
// Per group the names of the patches/patchGroups
|
||||
DynamicList<wordRe> groupNames_;
|
||||
|
||||
// Per group the indices of the patches
|
||||
DynamicList<labelList> groupPatchIDs_;
|
||||
|
||||
// Per group the names of the fields to read
|
||||
DynamicList<wordList> groupReadFields_;
|
||||
|
||||
// Per group the names of the fields to write
|
||||
DynamicList<wordList> groupWriteFields_;
|
||||
|
||||
//- Initialised flag
|
||||
bool initialised_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Return the file path to the communications directory for the region
|
||||
static fileName groupDir
|
||||
(
|
||||
const fileName& commsDir,
|
||||
const word& regionName,
|
||||
const wordRe& groupName
|
||||
);
|
||||
|
||||
//- Return the file path to the base communications directory
|
||||
fileName baseDir() const;
|
||||
|
||||
//- Return the file path to the lock file
|
||||
fileName lockFile() const;
|
||||
|
||||
//- Create lock file
|
||||
void createLockFile() const;
|
||||
|
||||
//- Remove lock file
|
||||
void removeLockFile() const;
|
||||
|
||||
//- Remove files written by OpenFOAM
|
||||
void removeWriteFiles() const;
|
||||
|
||||
//- Remove files written by external code
|
||||
void removeReadFiles() const;
|
||||
|
||||
//- Wait for response from external source
|
||||
void wait() const;
|
||||
|
||||
|
||||
//- Read data for a single region, single field
|
||||
template<class Type>
|
||||
bool readData
|
||||
(
|
||||
const fvMesh& mesh,
|
||||
const wordRe& groupName,
|
||||
const labelList& patchIDs,
|
||||
const word& fieldName
|
||||
);
|
||||
//- Read data for all regions, all fields
|
||||
void readData();
|
||||
|
||||
//- Write data for a single region, single field
|
||||
template<class Type>
|
||||
bool writeData
|
||||
(
|
||||
const fvMesh& mesh,
|
||||
const wordRe& groupName,
|
||||
const labelList& patchIDs,
|
||||
const word& fieldName
|
||||
) const;
|
||||
|
||||
//- Write data for all regions, all fields
|
||||
void writeData() const;
|
||||
|
||||
void initialise();
|
||||
|
||||
//- Read (and distribute) scalar columns from stream. Every processor
|
||||
// gets nRows (= patch size) of these. Note: could make its argument
|
||||
// ISstream& but then would need additional logic to construct valid
|
||||
// stream on all processors.
|
||||
void readColumns
|
||||
(
|
||||
const label nRows,
|
||||
const label nColumns,
|
||||
autoPtr<IFstream>& masterFilePtr,
|
||||
List<scalarField>& data
|
||||
) const;
|
||||
|
||||
//- Read (and distribute) lines from stream. Every processor
|
||||
// gets nRows (= patch size) of these. Data kept as stream (instead
|
||||
// of strings) for ease of interfacing to readData routines that take
|
||||
// an Istream.
|
||||
void readLines
|
||||
(
|
||||
const label nRows,
|
||||
autoPtr<IFstream>& masterFilePtr,
|
||||
OStringStream& data
|
||||
) const;
|
||||
|
||||
//- Helper: append data from all processors onto master
|
||||
template<class Type>
|
||||
static tmp<Field<Type> > gatherAndCombine(const Field<Type>& fld);
|
||||
|
||||
|
||||
//- Disallow default bitwise copy construc
|
||||
externalCoupledFunctionObject(const externalCoupledFunctionObject&);
|
||||
|
||||
//- Disallow default bitwise assignmen
|
||||
void operator=(const externalCoupledFunctionObject&);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("externalCoupled");
|
||||
|
||||
//- Name of lock file
|
||||
static word lockName;
|
||||
|
||||
//- Name of patch key, e.g. '# Patch:' when looking for start of patch data
|
||||
static string patchKey;
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct given time and dictionary
|
||||
externalCoupledFunctionObject
|
||||
(
|
||||
const word& name,
|
||||
const Time& runTime,
|
||||
const dictionary& dict
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~externalCoupledFunctionObject();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
// Access
|
||||
|
||||
//- Return the enabled flag
|
||||
virtual bool enabled() const
|
||||
{
|
||||
return enabled_;
|
||||
}
|
||||
|
||||
|
||||
// Function object control
|
||||
|
||||
//- Switch the function object on
|
||||
virtual void on();
|
||||
|
||||
//- Switch the function object off
|
||||
virtual void off();
|
||||
|
||||
//- Called at the start of the time-loop
|
||||
virtual bool start();
|
||||
|
||||
//- Called at each ++ or += of the time-loop
|
||||
virtual bool execute(const bool forceWrite);
|
||||
|
||||
//- Called when Time::run() determines that the time-loop exits
|
||||
virtual bool end();
|
||||
|
||||
//- Called when time was set at the end of the Time::operator++
|
||||
virtual bool timeSet();
|
||||
|
||||
//- 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&);
|
||||
|
||||
//- Update for changes of mesh
|
||||
virtual void updateMesh(const mapPolyMesh& mpm);
|
||||
|
||||
//- Update for changes of mesh
|
||||
virtual void movePoints(const polyMesh& mesh);
|
||||
|
||||
|
||||
// Other
|
||||
|
||||
//- Write geometry for the group/patch
|
||||
static void writeGeometry
|
||||
(
|
||||
const fvMesh& mesh,
|
||||
const fileName& commsDir,
|
||||
const wordRe& groupName
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef NoRepository
|
||||
# include "externalCoupledFunctionObjectTemplates.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,459 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify i
|
||||
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 "externalCoupledFunctionObject.H"
|
||||
#include "OSspecific.H"
|
||||
#include "IFstream.H"
|
||||
#include "OFstream.H"
|
||||
#include "volFields.H"
|
||||
#include "externalCoupledMixedFvPatchFields.H"
|
||||
#include "mixedFvPatchFields.H"
|
||||
#include "fixedGradientFvPatchFields.H"
|
||||
#include "fixedValueFvPatchFields.H"
|
||||
#include "OStringStream.H"
|
||||
#include "globalIndex.H"
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
bool Foam::externalCoupledFunctionObject::readData
|
||||
(
|
||||
const fvMesh& mesh,
|
||||
const wordRe& groupName,
|
||||
const labelList& patchIDs,
|
||||
const word& fieldName
|
||||
)
|
||||
{
|
||||
typedef GeometricField<Type, fvPatchField, volMesh> volFieldType;
|
||||
typedef externalCoupledMixedFvPatchField<Type> patchFieldType;
|
||||
|
||||
if (!mesh.foundObject<volFieldType>(fieldName))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const volFieldType& cvf = mesh.lookupObject<volFieldType>(fieldName);
|
||||
const typename volFieldType::GeometricBoundaryField& bf =
|
||||
cvf.boundaryField();
|
||||
|
||||
|
||||
// File only opened on master; contains data for all processors, for all
|
||||
// patchIDs.
|
||||
autoPtr<IFstream> masterFilePtr;
|
||||
if (Pstream::master())
|
||||
{
|
||||
const fileName transferFile
|
||||
(
|
||||
groupDir(commsDir_, mesh.dbDir(), groupName)
|
||||
/ fieldName + ".in"
|
||||
);
|
||||
|
||||
if (log_)
|
||||
{
|
||||
Info<< type() << ": reading data from " << transferFile << endl;
|
||||
}
|
||||
masterFilePtr.reset(new IFstream(transferFile));
|
||||
|
||||
if (!masterFilePtr().good())
|
||||
{
|
||||
FatalIOErrorIn
|
||||
(
|
||||
"void externalCoupledFunctionObject::readData"
|
||||
"("
|
||||
"const fvMesh&, "
|
||||
"const wordRe&, "
|
||||
"const labelList&, "
|
||||
"const word&"
|
||||
")",
|
||||
masterFilePtr()
|
||||
) << "Cannot open file for region " << mesh.name()
|
||||
<< ", field " << fieldName << ", patches " << patchIDs
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
}
|
||||
|
||||
// Handle column-wise reading of patch data. Supports most easy types
|
||||
forAll(patchIDs, i)
|
||||
{
|
||||
label patchI = patchIDs[i];
|
||||
|
||||
if (isA<patchFieldType>(bf[patchI]))
|
||||
{
|
||||
// Explicit handling of externalCoupledObjectMixed bcs - they have
|
||||
// specialised reading routines.
|
||||
|
||||
patchFieldType& pf = const_cast<patchFieldType&>
|
||||
(
|
||||
refCast<const patchFieldType>
|
||||
(
|
||||
bf[patchI]
|
||||
)
|
||||
);
|
||||
|
||||
// Read from master into local stream
|
||||
OStringStream os;
|
||||
readLines
|
||||
(
|
||||
bf[patchI].size(), // number of lines to read
|
||||
masterFilePtr,
|
||||
os
|
||||
);
|
||||
|
||||
// Pass responsability for all reading over to bc
|
||||
pf.readData(IStringStream(os.str())());
|
||||
|
||||
// Update the value from the read coefficicient. Bypass any
|
||||
// additional processing by derived type.
|
||||
pf.patchFieldType::evaluate();
|
||||
}
|
||||
else if (isA<mixedFvPatchField<Type> >(bf[patchI]))
|
||||
{
|
||||
// Read columns from file for
|
||||
// value, snGrad, refValue, refGrad, valueFraction
|
||||
List<scalarField> data;
|
||||
readColumns
|
||||
(
|
||||
bf[patchI].size(), // number of lines to read
|
||||
4*pTraits<Type>::nComponents+1, // nColumns: 4*Type + 1*scalar
|
||||
masterFilePtr,
|
||||
data
|
||||
);
|
||||
|
||||
mixedFvPatchField<Type>& pf = const_cast<mixedFvPatchField<Type>&>
|
||||
(
|
||||
refCast<const mixedFvPatchField<Type> >
|
||||
(
|
||||
bf[patchI]
|
||||
)
|
||||
);
|
||||
|
||||
// Transfer read data to bc.
|
||||
// Skip value, snGrad
|
||||
direction columnI = 2*pTraits<Type>::nComponents;
|
||||
|
||||
Field<Type>& refValue = pf.refValue();
|
||||
for (direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
|
||||
{
|
||||
refValue.replace(cmpt, data[columnI++]);
|
||||
}
|
||||
Field<Type>& refGrad = pf.refGrad();
|
||||
for (direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
|
||||
{
|
||||
refGrad.replace(cmpt, data[columnI++]);
|
||||
}
|
||||
pf.valueFraction() = data[columnI];
|
||||
|
||||
// Update the value from the read coefficicient. Bypass any
|
||||
// additional processing by derived type.
|
||||
pf.mixedFvPatchField<Type>::evaluate();
|
||||
}
|
||||
else if (isA<fixedGradientFvPatchField<Type> >(bf[patchI]))
|
||||
{
|
||||
// Read columns for value and gradient
|
||||
List<scalarField> data;
|
||||
readColumns
|
||||
(
|
||||
bf[patchI].size(), // number of lines to read
|
||||
2*pTraits<Type>::nComponents, // nColumns: Type
|
||||
masterFilePtr,
|
||||
data
|
||||
);
|
||||
|
||||
fixedGradientFvPatchField<Type>& pf =
|
||||
const_cast<fixedGradientFvPatchField<Type>&>
|
||||
(
|
||||
refCast<const fixedGradientFvPatchField<Type> >
|
||||
(
|
||||
bf[patchI]
|
||||
)
|
||||
);
|
||||
|
||||
// Transfer gradient to bc
|
||||
Field<Type>& gradient = pf.gradient();
|
||||
for (direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
|
||||
{
|
||||
gradient.replace(cmpt, data[pTraits<Type>::nComponents+cmpt]);
|
||||
}
|
||||
|
||||
// Update the value from the read coefficicient. Bypass any
|
||||
// additional processing by derived type.
|
||||
pf.fixedGradientFvPatchField<Type>::evaluate();
|
||||
}
|
||||
else if (isA<fixedValueFvPatchField<Type> >(bf[patchI]))
|
||||
{
|
||||
// Read columns for value only
|
||||
List<scalarField> data;
|
||||
readColumns
|
||||
(
|
||||
bf[patchI].size(), // number of lines to read
|
||||
pTraits<Type>::nComponents, // number of columns to read
|
||||
masterFilePtr,
|
||||
data
|
||||
);
|
||||
|
||||
// Transfer read value to bc
|
||||
Field<Type> value(bf[patchI].size());
|
||||
for (direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
|
||||
{
|
||||
value.replace(cmpt, data[cmpt]);
|
||||
}
|
||||
|
||||
fixedValueFvPatchField<Type>& pf =
|
||||
const_cast<fixedValueFvPatchField<Type>&>
|
||||
(
|
||||
refCast<const fixedValueFvPatchField<Type> >
|
||||
(
|
||||
bf[patchI]
|
||||
)
|
||||
);
|
||||
|
||||
pf == value;
|
||||
|
||||
// Update the value from the read coefficicient. Bypass any
|
||||
// additional processing by derived type.
|
||||
pf.fixedValueFvPatchField<Type>::evaluate();
|
||||
}
|
||||
else
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"void externalCoupledFunctionObject::readData"
|
||||
"("
|
||||
"const fvMesh&, "
|
||||
"const wordRe&, "
|
||||
"const labelList&, "
|
||||
"const word&"
|
||||
")"
|
||||
)
|
||||
<< "Unsupported boundary condition " << bf[patchI].type()
|
||||
<< " for patch " << bf[patchI].patch().name()
|
||||
<< " in region " << mesh.name()
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
initialised_ = true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
Foam::tmp<Foam::Field<Type> >
|
||||
Foam::externalCoupledFunctionObject::gatherAndCombine
|
||||
(
|
||||
const Field<Type>& fld
|
||||
)
|
||||
{
|
||||
// Collect values from all processors
|
||||
List<Field<Type> > gatheredValues(Pstream::nProcs());
|
||||
gatheredValues[Pstream::myProcNo()] = fld;
|
||||
Pstream::gatherList(gatheredValues);
|
||||
|
||||
|
||||
tmp<Field<Type> > tresult(new Field<Type>(0));
|
||||
Field<Type>& result = tresult();
|
||||
|
||||
if (Pstream::master())
|
||||
{
|
||||
// Combine values into single field
|
||||
label globalElemI = 0;
|
||||
|
||||
forAll(gatheredValues, lstI)
|
||||
{
|
||||
globalElemI += gatheredValues[lstI].size();
|
||||
}
|
||||
|
||||
result.setSize(globalElemI);
|
||||
|
||||
globalElemI = 0;
|
||||
|
||||
forAll(gatheredValues, lstI)
|
||||
{
|
||||
const Field<Type>& sub = gatheredValues[lstI];
|
||||
|
||||
forAll(sub, elemI)
|
||||
{
|
||||
result[globalElemI++] = sub[elemI];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return tresult;
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
bool Foam::externalCoupledFunctionObject::writeData
|
||||
(
|
||||
const fvMesh& mesh,
|
||||
const wordRe& groupName,
|
||||
const labelList& patchIDs,
|
||||
const word& fieldName
|
||||
) const
|
||||
{
|
||||
typedef GeometricField<Type, fvPatchField, volMesh> volFieldType;
|
||||
typedef externalCoupledMixedFvPatchField<Type> patchFieldType;
|
||||
|
||||
if (!mesh.foundObject<volFieldType>(fieldName))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const volFieldType& cvf = mesh.lookupObject<volFieldType>(fieldName);
|
||||
const typename volFieldType::GeometricBoundaryField& bf =
|
||||
cvf.boundaryField();
|
||||
|
||||
|
||||
// File only opened on master; contains data for all processors, for all
|
||||
// patchIDs
|
||||
autoPtr<OFstream> masterFilePtr;
|
||||
if (Pstream::master())
|
||||
{
|
||||
const fileName transferFile
|
||||
(
|
||||
groupDir(commsDir_, mesh.dbDir(), groupName)
|
||||
/ fieldName + ".out"
|
||||
);
|
||||
|
||||
if (log_)
|
||||
{
|
||||
Info<< type() << ": writing data to " << transferFile << endl;
|
||||
}
|
||||
masterFilePtr.reset(new OFstream(transferFile));
|
||||
|
||||
if (!masterFilePtr().good())
|
||||
{
|
||||
FatalIOErrorIn
|
||||
(
|
||||
"externalCoupledFunctionObject::writeData"
|
||||
"("
|
||||
"const fvMesh&, "
|
||||
"const wordRe&, "
|
||||
"const labelList&, "
|
||||
"const word&"
|
||||
") const",
|
||||
masterFilePtr()
|
||||
) << "Cannot open file for region " << mesh.name()
|
||||
<< ", field " << fieldName << ", patches " << patchIDs
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool headerDone = false;
|
||||
|
||||
// Handle column-wise writing of patch data. Supports most easy types
|
||||
forAll(patchIDs, i)
|
||||
{
|
||||
label patchI = patchIDs[i];
|
||||
|
||||
const globalIndex globalFaces(bf[patchI].size());
|
||||
|
||||
if (isA<patchFieldType>(bf[patchI]))
|
||||
{
|
||||
// Explicit handling of externalCoupledObjectMixed bcs - they have
|
||||
// specialised writing routines
|
||||
|
||||
const patchFieldType& pf = refCast<const patchFieldType>
|
||||
(
|
||||
bf[patchI]
|
||||
);
|
||||
OStringStream os;
|
||||
|
||||
// Pass responsibility for all writing over to bc
|
||||
pf.writeData(os);
|
||||
|
||||
// Collect contributions from all processors and output them on
|
||||
// master
|
||||
if (Pstream::master())
|
||||
{
|
||||
// Output master data first
|
||||
if (!headerDone)
|
||||
{
|
||||
pf.writeHeader(masterFilePtr());
|
||||
headerDone = true;
|
||||
}
|
||||
masterFilePtr() << os.str().c_str();
|
||||
|
||||
for (label procI = 1; procI < Pstream::nProcs(); procI++)
|
||||
{
|
||||
IPstream fromSlave(Pstream::scheduled, procI);
|
||||
string str(fromSlave);
|
||||
masterFilePtr() << str.c_str();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
|
||||
toMaster << os.str();
|
||||
}
|
||||
}
|
||||
else if (isA<mixedFvPatchField<Type> >(bf[patchI]))
|
||||
{
|
||||
const mixedFvPatchField<Type>& pf =
|
||||
refCast<const mixedFvPatchField<Type> >(bf[patchI]);
|
||||
|
||||
Field<Type> value(gatherAndCombine(pf));
|
||||
Field<Type> snGrad(gatherAndCombine(pf.snGrad()()));
|
||||
Field<Type> refValue(gatherAndCombine(pf.refValue()));
|
||||
Field<Type> refGrad(gatherAndCombine(pf.refGrad()));
|
||||
scalarField valueFraction(gatherAndCombine(pf.valueFraction()));
|
||||
|
||||
if (Pstream::master())
|
||||
{
|
||||
forAll(refValue, faceI)
|
||||
{
|
||||
masterFilePtr()
|
||||
<< value[faceI] << token::SPACE
|
||||
<< snGrad[faceI] << token::SPACE
|
||||
<< refValue[faceI] << token::SPACE
|
||||
<< refGrad[faceI] << token::SPACE
|
||||
<< valueFraction[faceI] << nl;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Output the value and snGrad
|
||||
Field<Type> value(gatherAndCombine(bf[patchI]));
|
||||
Field<Type> snGrad(gatherAndCombine(bf[patchI].snGrad()()));
|
||||
if (Pstream::master())
|
||||
{
|
||||
forAll(value, faceI)
|
||||
{
|
||||
masterFilePtr()
|
||||
<< value[faceI] << token::SPACE
|
||||
<< snGrad[faceI] << nl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,168 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2013-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 "externalCoupledMixedFvPatchField.H"
|
||||
#include "fvPatchFieldMapper.H"
|
||||
#include "ISstream.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
Foam::externalCoupledMixedFvPatchField<Type>::
|
||||
externalCoupledMixedFvPatchField
|
||||
(
|
||||
const fvPatch& p,
|
||||
const DimensionedField<Type, volMesh>& iF
|
||||
)
|
||||
:
|
||||
mixedFvPatchField<Type>(p, iF)
|
||||
{
|
||||
this->refValue() = pTraits<Type>::zero;
|
||||
this->refGrad() = pTraits<Type>::zero;
|
||||
this->valueFraction() = 0.0;
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
Foam::externalCoupledMixedFvPatchField<Type>::
|
||||
externalCoupledMixedFvPatchField
|
||||
(
|
||||
const externalCoupledMixedFvPatchField& ptf,
|
||||
const fvPatch& p,
|
||||
const DimensionedField<Type, volMesh>& iF,
|
||||
const fvPatchFieldMapper& mapper
|
||||
)
|
||||
:
|
||||
mixedFvPatchField<Type>(ptf, p, iF, mapper)
|
||||
{}
|
||||
|
||||
|
||||
template<class Type>
|
||||
Foam::externalCoupledMixedFvPatchField<Type>::
|
||||
externalCoupledMixedFvPatchField
|
||||
(
|
||||
const fvPatch& p,
|
||||
const DimensionedField<Type, volMesh>& iF,
|
||||
const dictionary& dict
|
||||
)
|
||||
:
|
||||
mixedFvPatchField<Type>(p, iF, dict)
|
||||
{}
|
||||
|
||||
|
||||
template<class Type>
|
||||
Foam::externalCoupledMixedFvPatchField<Type>::
|
||||
externalCoupledMixedFvPatchField
|
||||
(
|
||||
const externalCoupledMixedFvPatchField& ecmpf
|
||||
)
|
||||
:
|
||||
mixedFvPatchField<Type>(ecmpf)
|
||||
{}
|
||||
|
||||
|
||||
template<class Type>
|
||||
Foam::externalCoupledMixedFvPatchField<Type>::
|
||||
externalCoupledMixedFvPatchField
|
||||
(
|
||||
const externalCoupledMixedFvPatchField& ecmpf,
|
||||
const DimensionedField<Type, volMesh>& iF
|
||||
)
|
||||
:
|
||||
mixedFvPatchField<Type>(ecmpf, iF)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
Foam::externalCoupledMixedFvPatchField<Type>::
|
||||
~externalCoupledMixedFvPatchField()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
void Foam::externalCoupledMixedFvPatchField<Type>::writeHeader
|
||||
(
|
||||
Ostream& os
|
||||
) const
|
||||
{
|
||||
os << "# Values: value snGrad refValue refGrad valueFraction" << endl;
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
void Foam::externalCoupledMixedFvPatchField<Type>::writeData
|
||||
(
|
||||
Ostream& os
|
||||
) const
|
||||
{
|
||||
const Field<Type> snGrad(this->snGrad());
|
||||
const Field<Type>& refValue(this->refValue());
|
||||
const Field<Type>& refGrad(this->refGrad());
|
||||
const scalarField& valueFraction(this->valueFraction());
|
||||
|
||||
forAll(refValue, faceI)
|
||||
{
|
||||
os << this->operator[](faceI) << token::SPACE
|
||||
<< snGrad[faceI] << token::SPACE
|
||||
<< refValue[faceI] << token::SPACE
|
||||
<< refGrad[faceI] << token::SPACE
|
||||
<< valueFraction[faceI] << nl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
void Foam::externalCoupledMixedFvPatchField<Type>::readData(Istream& is)
|
||||
{
|
||||
// Assume generic input stream so we can do line-based format and skip
|
||||
// unused columns
|
||||
ISstream& iss = dynamic_cast<ISstream&>(is);
|
||||
|
||||
string line;
|
||||
|
||||
forAll(*this, faceI)
|
||||
{
|
||||
iss.getLine(line);
|
||||
IStringStream lineStr(line);
|
||||
|
||||
// For symmetry with writing ignore value, snGrad columns
|
||||
|
||||
Type value, snGrad;
|
||||
|
||||
lineStr
|
||||
>> value
|
||||
>> snGrad
|
||||
>> this->refValue()[faceI]
|
||||
>> this->refGrad()[faceI]
|
||||
>> this->valueFraction()[faceI];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,174 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2013-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::externalCoupledMixedFvPatchField
|
||||
|
||||
Group
|
||||
grpGenericBoundaryConditions grpCoupledBoundaryConditions
|
||||
|
||||
Description
|
||||
This boundary condition extends the mixed boundary condition with
|
||||
serialisation through
|
||||
- writeHeader
|
||||
- writeData
|
||||
- readData
|
||||
functions. It is used for coupling to external applications in combination
|
||||
with the externalCoupled functionObject. The default output is one
|
||||
line per face, with columns
|
||||
<value> <snGrad> <refValue> <refGrad> <valueFraction>
|
||||
|
||||
Notes
|
||||
readData,writeData are not callbacks for regIOobject (since fvPatchField
|
||||
not derived from it). They do however do exactly the same - streaming of
|
||||
data.
|
||||
|
||||
SeeAlso
|
||||
mixedFvPatchField
|
||||
externalCoupledFunctionObject
|
||||
|
||||
SourceFiles
|
||||
externalCoupledMixedFvPatchField.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef externalCoupledMixedFvPatchField_H
|
||||
#define externalCoupledMixedFvPatchField_H
|
||||
|
||||
#include "mixedFvPatchFields.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class externalCoupledMixedFvPatchField Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
template<class Type>
|
||||
class externalCoupledMixedFvPatchField
|
||||
:
|
||||
public mixedFvPatchField<Type>
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("externalCoupled");
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from patch and internal field
|
||||
externalCoupledMixedFvPatchField
|
||||
(
|
||||
const fvPatch&,
|
||||
const DimensionedField<Type, volMesh>&
|
||||
);
|
||||
|
||||
//- Construct from patch, internal field and dictionary
|
||||
externalCoupledMixedFvPatchField
|
||||
(
|
||||
const fvPatch&,
|
||||
const DimensionedField<Type, volMesh>&,
|
||||
const dictionary&
|
||||
);
|
||||
|
||||
//- Construct by mapping given externalCoupledMixedFvPatchField
|
||||
// onto a new patch
|
||||
externalCoupledMixedFvPatchField
|
||||
(
|
||||
const externalCoupledMixedFvPatchField<Type>&,
|
||||
const fvPatch&,
|
||||
const DimensionedField<Type, volMesh>&,
|
||||
const fvPatchFieldMapper&
|
||||
);
|
||||
|
||||
//- Construct as copy
|
||||
externalCoupledMixedFvPatchField
|
||||
(
|
||||
const externalCoupledMixedFvPatchField&
|
||||
);
|
||||
|
||||
//- Construct and return a clone
|
||||
virtual tmp<fvPatchField<Type> > clone() const
|
||||
{
|
||||
return tmp<fvPatchField<Type> >
|
||||
(
|
||||
new externalCoupledMixedFvPatchField<Type>(*this)
|
||||
);
|
||||
}
|
||||
|
||||
//- Construct as copy setting internal field reference
|
||||
externalCoupledMixedFvPatchField
|
||||
(
|
||||
const externalCoupledMixedFvPatchField&,
|
||||
const DimensionedField<Type, volMesh>&
|
||||
);
|
||||
|
||||
//- Construct and return a clone setting internal field reference
|
||||
virtual tmp<fvPatchField<Type> > clone
|
||||
(
|
||||
const DimensionedField<Type, volMesh>& iF
|
||||
) const
|
||||
{
|
||||
return tmp<fvPatchField<Type> >
|
||||
(
|
||||
new externalCoupledMixedFvPatchField<Type>(*this, iF)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~externalCoupledMixedFvPatchField();
|
||||
|
||||
|
||||
// Member functions
|
||||
|
||||
//- Write header
|
||||
virtual void writeHeader(Ostream&) const;
|
||||
|
||||
//- Write data
|
||||
virtual void writeData(Ostream&) const;
|
||||
|
||||
//- Read data
|
||||
virtual void readData(Istream&);
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef NoRepository
|
||||
# include "externalCoupledMixedFvPatchField.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,42 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2013-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 "externalCoupledMixedFvPatchFields.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
makePatchFields(externalCoupledMixed);
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,49 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2013-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/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef externalCoupledMixedFvPatchFields_H
|
||||
#define externalCoupledMixedFvPatchFields_H
|
||||
|
||||
#include "externalCoupledMixedFvPatchField.H"
|
||||
#include "fieldTypes.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
makePatchTypeFieldTypedefs(externalCoupledMixed);
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,50 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2013-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/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef externalCoupledMixedFvPatchFieldsFwd_H
|
||||
#define externalCoupledMixedFvPatchFieldsFwd_H
|
||||
|
||||
#include "fieldTypes.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
template<class Type> class externalCoupledMixedFvPatchField;
|
||||
|
||||
makePatchTypeFieldTypedefs(externalCoupledMixed);
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,256 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2013-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 "externalCoupledTemperatureMixedFvPatchScalarField.H"
|
||||
#include "turbulentFluidThermoModel.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
#include "fvPatchFieldMapper.H"
|
||||
#include "volFields.H"
|
||||
|
||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||
|
||||
void Foam::externalCoupledTemperatureMixedFvPatchScalarField::writeHeader
|
||||
(
|
||||
Ostream& os
|
||||
) const
|
||||
{
|
||||
os << "# Values: magSf T qDot htc" << endl;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::externalCoupledTemperatureMixedFvPatchScalarField::
|
||||
externalCoupledTemperatureMixedFvPatchScalarField
|
||||
(
|
||||
const fvPatch& p,
|
||||
const DimensionedField<scalar, volMesh>& iF
|
||||
)
|
||||
:
|
||||
externalCoupledMixedFvPatchField<scalar>(p, iF)
|
||||
{}
|
||||
|
||||
|
||||
Foam::externalCoupledTemperatureMixedFvPatchScalarField::
|
||||
externalCoupledTemperatureMixedFvPatchScalarField
|
||||
(
|
||||
const externalCoupledTemperatureMixedFvPatchScalarField& ptf,
|
||||
const fvPatch& p,
|
||||
const DimensionedField<scalar, volMesh>& iF,
|
||||
const fvPatchFieldMapper& mapper
|
||||
)
|
||||
:
|
||||
externalCoupledMixedFvPatchField<scalar>(ptf, p, iF, mapper)
|
||||
{}
|
||||
|
||||
|
||||
Foam::externalCoupledTemperatureMixedFvPatchScalarField::
|
||||
externalCoupledTemperatureMixedFvPatchScalarField
|
||||
(
|
||||
const fvPatch& p,
|
||||
const DimensionedField<scalar, volMesh>& iF,
|
||||
const dictionary& dict
|
||||
)
|
||||
:
|
||||
//externalCoupledMixedFvPatchField<scalar>(p, iF, dict)
|
||||
externalCoupledMixedFvPatchField<scalar>(p, iF)
|
||||
{
|
||||
if (dict.found("refValue"))
|
||||
{
|
||||
// Initialise same way as mixed
|
||||
this->refValue() = scalarField("refValue", dict, p.size());
|
||||
this->refGrad() = scalarField("refGradient", dict, p.size());
|
||||
this->valueFraction() = scalarField("valueFraction", dict, p.size());
|
||||
|
||||
evaluate();
|
||||
}
|
||||
else
|
||||
{
|
||||
// For convenience: initialise as fixedValue with either read value
|
||||
// or extrapolated value
|
||||
if (dict.found("value"))
|
||||
{
|
||||
fvPatchField<scalar>::operator=
|
||||
(
|
||||
scalarField("value", dict, p.size())
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
fvPatchField<scalar>::operator=(this->patchInternalField());
|
||||
}
|
||||
|
||||
// Initialise as a fixed value
|
||||
this->refValue() = *this;
|
||||
this->refGrad() = pTraits<scalar>::zero;
|
||||
this->valueFraction() = 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Foam::externalCoupledTemperatureMixedFvPatchScalarField::
|
||||
externalCoupledTemperatureMixedFvPatchScalarField
|
||||
(
|
||||
const externalCoupledTemperatureMixedFvPatchScalarField& ecmpf
|
||||
)
|
||||
:
|
||||
externalCoupledMixedFvPatchField<scalar>(ecmpf)
|
||||
{}
|
||||
|
||||
|
||||
Foam::externalCoupledTemperatureMixedFvPatchScalarField::
|
||||
externalCoupledTemperatureMixedFvPatchScalarField
|
||||
(
|
||||
const externalCoupledTemperatureMixedFvPatchScalarField& ecmpf,
|
||||
const DimensionedField<scalar, volMesh>& iF
|
||||
)
|
||||
:
|
||||
externalCoupledMixedFvPatchField<scalar>(ecmpf, iF)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::externalCoupledTemperatureMixedFvPatchScalarField::
|
||||
~externalCoupledTemperatureMixedFvPatchScalarField()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::externalCoupledTemperatureMixedFvPatchScalarField::writeData
|
||||
(
|
||||
Ostream& os
|
||||
) const
|
||||
{
|
||||
const label patchI = patch().index();
|
||||
|
||||
// Heat flux [W/m2]
|
||||
scalarField qDot(this->patch().size(), 0.0);
|
||||
|
||||
typedef compressible::turbulenceModel cmpTurbModelType;
|
||||
|
||||
static word turbName
|
||||
(
|
||||
IOobject::groupName
|
||||
(
|
||||
turbulenceModel::propertiesName,
|
||||
dimensionedInternalField().group()
|
||||
)
|
||||
);
|
||||
|
||||
static word thermoName("thermophysicalProperties");
|
||||
|
||||
if (db().foundObject<cmpTurbModelType>(turbName))
|
||||
{
|
||||
const cmpTurbModelType& turbModel =
|
||||
db().lookupObject<cmpTurbModelType>(turbName);
|
||||
|
||||
const basicThermo& thermo = turbModel.transport();
|
||||
|
||||
const fvPatchScalarField& hep = thermo.he().boundaryField()[patchI];
|
||||
|
||||
qDot = turbModel.alphaEff(patchI)*hep.snGrad();
|
||||
}
|
||||
else if (db().foundObject<basicThermo>(thermoName))
|
||||
{
|
||||
const basicThermo& thermo = db().lookupObject<basicThermo>(thermoName);
|
||||
|
||||
const fvPatchScalarField& hep = thermo.he().boundaryField()[patchI];
|
||||
|
||||
qDot = thermo.alpha().boundaryField()[patchI]*hep.snGrad();
|
||||
}
|
||||
else
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"void Foam::externalCoupledTemperatureMixedFvPatchScalarField::"
|
||||
"transferData"
|
||||
"("
|
||||
"Ostream&"
|
||||
") const"
|
||||
) << "Condition requires either compressible turbulence and/or "
|
||||
<< "thermo model to be available" << exit(FatalError);
|
||||
}
|
||||
|
||||
// Patch temperature [K]
|
||||
const scalarField& Tp(*this);
|
||||
|
||||
// Near wall cell temperature [K]
|
||||
const scalarField Tc(patchInternalField());
|
||||
|
||||
// Heat transfer coefficient [W/m2/K]
|
||||
const scalarField htc(qDot/(Tp - Tc + ROOTVSMALL));
|
||||
|
||||
const Field<scalar>& magSf(this->patch().magSf());
|
||||
|
||||
forAll(patch(), faceI)
|
||||
{
|
||||
os << magSf[faceI] << token::SPACE
|
||||
<< Tp[faceI] << token::SPACE
|
||||
<< qDot[faceI] << token::SPACE
|
||||
<< htc[faceI] << token::SPACE
|
||||
<< nl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::externalCoupledTemperatureMixedFvPatchScalarField::readData
|
||||
(
|
||||
Istream& is
|
||||
)
|
||||
{
|
||||
// Assume generic input stream so we can do line-based format and skip
|
||||
// unused columns
|
||||
ISstream& iss = dynamic_cast<ISstream&>(is);
|
||||
|
||||
string line;
|
||||
|
||||
forAll(*this, faceI)
|
||||
{
|
||||
iss.getLine(line);
|
||||
IStringStream lineStr(line);
|
||||
|
||||
lineStr
|
||||
>> this->refValue()[faceI]
|
||||
>> this->refGrad()[faceI]
|
||||
>> this->valueFraction()[faceI];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
makePatchTypeField
|
||||
(
|
||||
fvPatchScalarField,
|
||||
externalCoupledTemperatureMixedFvPatchScalarField
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,179 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2013-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::externalCoupledTemperatureMixedFvPatchScalarField
|
||||
|
||||
Group
|
||||
grpCoupledBoundaryConditions
|
||||
|
||||
Description
|
||||
This boundary condition provides a temperatue interface to an external
|
||||
application. Values are transferred as plain text files, where OpenFOAM
|
||||
data is written as:
|
||||
|
||||
# Patch: <patch name>
|
||||
<magSf1> <value1> <qDot1> <htc1>
|
||||
<magSf2> <value2> <qDot2> <htc2>
|
||||
<magSf3> <value3> <qDot3> <htc2>
|
||||
...
|
||||
<magSfN> <valueN> <qDotN> <htcN>
|
||||
|
||||
and received as the constituent pieces of the `mixed' condition, i.e.
|
||||
|
||||
# Patch: <patch name>
|
||||
<refValue1> <refGrad1> <valueFraction1>
|
||||
<refValue2> <refGrad2> <valueFraction2>
|
||||
<refValue3> <refGrad3> <valueFraction3>
|
||||
...
|
||||
<refValueN> <refGradN> <valueFractionN>
|
||||
|
||||
To be used in combination with the externalCoupled functionObject.
|
||||
|
||||
SeeAlso
|
||||
externalCoupledFunctionObject
|
||||
mixedFvPatchField
|
||||
externalCoupledMixedFvPatchField
|
||||
|
||||
SourceFiles
|
||||
externalCoupledTemperatureMixedFvPatchScalarField.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef externalCoupledTemperatureMixedFvPatchScalarField_H
|
||||
#define externalCoupledTemperatureMixedFvPatchScalarField_H
|
||||
|
||||
#include "externalCoupledMixedFvPatchFields.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class externalCoupledTemperatureMixedFvPatchScalarField Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class externalCoupledTemperatureMixedFvPatchScalarField
|
||||
:
|
||||
public externalCoupledMixedFvPatchField<scalar>
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("externalCoupledTemperature");
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from patch and internal field
|
||||
externalCoupledTemperatureMixedFvPatchScalarField
|
||||
(
|
||||
const fvPatch&,
|
||||
const DimensionedField<scalar, volMesh>&
|
||||
);
|
||||
|
||||
//- Construct from patch, internal field and dictionary
|
||||
externalCoupledTemperatureMixedFvPatchScalarField
|
||||
(
|
||||
const fvPatch&,
|
||||
const DimensionedField<scalar, volMesh>&,
|
||||
const dictionary&
|
||||
);
|
||||
|
||||
//- Construct by mapping given
|
||||
// externalCoupledTemperatureMixedFvPatchScalarField onto a new patch
|
||||
externalCoupledTemperatureMixedFvPatchScalarField
|
||||
(
|
||||
const externalCoupledTemperatureMixedFvPatchScalarField&,
|
||||
const fvPatch&,
|
||||
const DimensionedField<scalar, volMesh>&,
|
||||
const fvPatchFieldMapper&
|
||||
);
|
||||
|
||||
//- Construct as copy
|
||||
externalCoupledTemperatureMixedFvPatchScalarField
|
||||
(
|
||||
const externalCoupledTemperatureMixedFvPatchScalarField&
|
||||
);
|
||||
|
||||
//- Construct and return a clone
|
||||
virtual tmp<fvPatchField<scalar> > clone() const
|
||||
{
|
||||
return tmp<fvPatchField<scalar> >
|
||||
(
|
||||
new externalCoupledTemperatureMixedFvPatchScalarField(*this)
|
||||
);
|
||||
}
|
||||
|
||||
//- Construct as copy setting internal field reference
|
||||
externalCoupledTemperatureMixedFvPatchScalarField
|
||||
(
|
||||
const externalCoupledTemperatureMixedFvPatchScalarField&,
|
||||
const DimensionedField<scalar, volMesh>&
|
||||
);
|
||||
|
||||
//- Construct and return a clone setting internal field reference
|
||||
virtual tmp<fvPatchField<scalar> > clone
|
||||
(
|
||||
const DimensionedField<scalar, volMesh>& iF
|
||||
) const
|
||||
{
|
||||
return tmp<fvPatchField<scalar> >
|
||||
(
|
||||
new externalCoupledTemperatureMixedFvPatchScalarField
|
||||
(
|
||||
*this,
|
||||
iF
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~externalCoupledTemperatureMixedFvPatchScalarField();
|
||||
|
||||
|
||||
// Member functions
|
||||
|
||||
//- Write header
|
||||
virtual void writeHeader(Ostream&) const;
|
||||
|
||||
//- Write data
|
||||
virtual void writeData(Ostream&) const;
|
||||
|
||||
//- Read data
|
||||
virtual void readData(Istream&);
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,49 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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/>.
|
||||
|
||||
Typedef
|
||||
Foam::IOrunTimeControl
|
||||
|
||||
Description
|
||||
Instance of the generic IOOutputFilter for runTimeControl.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef IOrunTimeControl_H
|
||||
#define IOrunTimeControl_H
|
||||
|
||||
#include "runTimeControl.H"
|
||||
#include "IOOutputFilter.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
typedef IOOutputFilter<runTimeControl> IOrunTimeControl;
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,179 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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 "averageCondition.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
#include "Time.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
defineTypeNameAndDebug(averageCondition, 0);
|
||||
addToRunTimeSelectionTable(runTimeCondition, averageCondition, dictionary);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::averageCondition::averageCondition
|
||||
(
|
||||
const word& name,
|
||||
const objectRegistry& obr,
|
||||
const dictionary& dict,
|
||||
functionObjectState& 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::averageCondition::~averageCondition()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * //
|
||||
|
||||
bool Foam::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())
|
||||
{
|
||||
WarningIn("bool Foam::averageCondition::apply()")
|
||||
<< "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::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,136 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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::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
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
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,
|
||||
functionObjectState& state
|
||||
);
|
||||
|
||||
//- Destructor
|
||||
virtual ~averageCondition();
|
||||
|
||||
|
||||
// Public Member Functions
|
||||
|
||||
//- Apply the condition
|
||||
virtual bool apply();
|
||||
|
||||
//- Write
|
||||
virtual void write();
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // 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 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::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,222 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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 "equationInitialResidualCondition.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
#include "fvMesh.H"
|
||||
#include "Time.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
defineTypeNameAndDebug(equationInitialResidualCondition, 0);
|
||||
addToRunTimeSelectionTable
|
||||
(
|
||||
runTimeCondition,
|
||||
equationInitialResidualCondition,
|
||||
dictionary
|
||||
);
|
||||
|
||||
template<>
|
||||
const char* Foam::NamedEnum
|
||||
<
|
||||
equationInitialResidualCondition::operatingMode,
|
||||
2
|
||||
>::names[] =
|
||||
{
|
||||
"minimum",
|
||||
"maximum"
|
||||
};
|
||||
|
||||
const NamedEnum<Foam::equationInitialResidualCondition::operatingMode, 2>
|
||||
Foam::equationInitialResidualCondition::operatingModeNames;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::equationInitialResidualCondition::equationInitialResidualCondition
|
||||
(
|
||||
const word& name,
|
||||
const objectRegistry& obr,
|
||||
const dictionary& dict,
|
||||
functionObjectState& 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())
|
||||
{
|
||||
WarningIn
|
||||
(
|
||||
"Foam::equationInitialResidualCondition::"
|
||||
"equationInitialResidualCondition"
|
||||
"("
|
||||
"const word&, "
|
||||
"const objectRegistry&, "
|
||||
"const dictionary&, "
|
||||
"functionObjectState&"
|
||||
")"
|
||||
)
|
||||
<< "No fields supplied: deactivating" << endl;
|
||||
|
||||
active_ = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::equationInitialResidualCondition::
|
||||
~equationInitialResidualCondition()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * //
|
||||
|
||||
bool Foam::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:
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"bool Foam::equationInitialResidualCondition::apply()"
|
||||
)
|
||||
<< "Unhandled enumeration "
|
||||
<< operatingModeNames[mode_]
|
||||
<< abort(FatalError);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool valid = false;
|
||||
forAll(result, i)
|
||||
{
|
||||
if (result[i] < 0)
|
||||
{
|
||||
WarningIn("bool Foam::equationInitialResidualCondition::apply()")
|
||||
<< "Initial residual data not found for field "
|
||||
<< fieldNames_[i] << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
valid = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!valid)
|
||||
{
|
||||
WarningIn("bool Foam::equationInitialResidualCondition::apply()")
|
||||
<< "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::equationInitialResidualCondition::write()
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,119 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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::equationInitialResidualCondition
|
||||
|
||||
Description
|
||||
Minimum or maximum initial residual run time condition
|
||||
|
||||
SourceFiles
|
||||
equationInitialResidualCondition.H
|
||||
equationInitialResidualCondition.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef equationInitialResidualCondition_H
|
||||
#define equationInitialResidualCondition_H
|
||||
|
||||
#include "runTimeCondition.H"
|
||||
#include "NamedEnum.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class equationInitialResidualCondition Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class equationInitialResidualCondition
|
||||
:
|
||||
public runTimeCondition
|
||||
{
|
||||
public:
|
||||
|
||||
enum operatingMode
|
||||
{
|
||||
omMin,
|
||||
omMax
|
||||
};
|
||||
|
||||
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,
|
||||
functionObjectState& state
|
||||
);
|
||||
|
||||
//- Destructor
|
||||
virtual ~equationInitialResidualCondition();
|
||||
|
||||
|
||||
// Public Member Functions
|
||||
|
||||
//- Apply the condition
|
||||
virtual bool apply();
|
||||
|
||||
//- Write
|
||||
virtual void write();
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,183 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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 "equationMaxIterCondition.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
#include "fvMesh.H"
|
||||
#include "Time.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
defineTypeNameAndDebug(equationMaxIterCondition, 0);
|
||||
addToRunTimeSelectionTable
|
||||
(
|
||||
runTimeCondition,
|
||||
equationMaxIterCondition,
|
||||
dictionary
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::equationMaxIterCondition::equationMaxIterCondition
|
||||
(
|
||||
const word& name,
|
||||
const objectRegistry& obr,
|
||||
const dictionary& dict,
|
||||
functionObjectState& state
|
||||
)
|
||||
:
|
||||
runTimeCondition(name, obr, dict, state),
|
||||
fieldNames_(dict.lookup("fields")),
|
||||
threshold_(readLabel(dict.lookup("threshold"))),
|
||||
startIter_(dict.lookupOrDefault("startIter", 2))
|
||||
{
|
||||
if (!fieldNames_.size())
|
||||
{
|
||||
WarningIn
|
||||
(
|
||||
"Foam::equationMaxIterCondition::"
|
||||
"equationMaxIterCondition"
|
||||
"("
|
||||
"const word&, "
|
||||
"const objectRegistry&, "
|
||||
"const dictionary&, "
|
||||
"functionObjectState&"
|
||||
")"
|
||||
)
|
||||
<< "No fields supplied: deactivating" << endl;
|
||||
|
||||
active_ = false;
|
||||
}
|
||||
|
||||
startIter_ = max(startIter_, 2);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::equationMaxIterCondition::~equationMaxIterCondition()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * //
|
||||
|
||||
bool Foam::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)
|
||||
{
|
||||
WarningIn("bool Foam::equationMaxIterCondition::apply()")
|
||||
<< "Number of iterations data not found for field "
|
||||
<< fieldNames_[i] << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
valid = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!valid)
|
||||
{
|
||||
WarningIn("bool Foam::equationMaxIterCondition::apply()")
|
||||
<< "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::equationMaxIterCondition::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 |
|
||||
-------------------------------------------------------------------------------
|
||||
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::equationMaxIterCondition
|
||||
|
||||
Description
|
||||
Maximum number of equation iterations run time condition
|
||||
|
||||
SourceFiles
|
||||
equationMaxIterCondition.H
|
||||
equationMaxIterCondition.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef equationMaxIterCondition_H
|
||||
#define equationMaxIterCondition_H
|
||||
|
||||
#include "runTimeCondition.H"
|
||||
#include "NamedEnum.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
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,
|
||||
functionObjectState& state
|
||||
);
|
||||
|
||||
//- Destructor
|
||||
virtual ~equationMaxIterCondition();
|
||||
|
||||
|
||||
// Public Member Functions
|
||||
|
||||
//- Apply the condition
|
||||
virtual bool apply();
|
||||
|
||||
//- Write
|
||||
virtual void write();
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,165 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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 "minMaxCondition.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
#include "fieldTypes.H"
|
||||
|
||||
// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
|
||||
|
||||
template<>
|
||||
void Foam::minMaxCondition::setValue<Foam::scalar>
|
||||
(
|
||||
const word& valueType,
|
||||
const word& fieldName,
|
||||
scalar& value
|
||||
) const
|
||||
{
|
||||
state_.getObjectResult(functionObjectName_, fieldName, value);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
defineTypeNameAndDebug(minMaxCondition, 0);
|
||||
addToRunTimeSelectionTable(runTimeCondition, minMaxCondition, dictionary);
|
||||
|
||||
template<>
|
||||
const char* NamedEnum<minMaxCondition::modeType, 2>::names[] =
|
||||
{
|
||||
"minimum",
|
||||
"maximum"
|
||||
};
|
||||
}
|
||||
|
||||
const Foam::NamedEnum<Foam::minMaxCondition::modeType, 2>
|
||||
Foam::minMaxCondition::modeTypeNames_;
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::minMaxCondition::minMaxCondition
|
||||
(
|
||||
const word& name,
|
||||
const objectRegistry& obr,
|
||||
const dictionary& dict,
|
||||
functionObjectState& state
|
||||
)
|
||||
:
|
||||
runTimeCondition(name, obr, dict, state),
|
||||
functionObjectName_(dict.lookup("functionObjectName")),
|
||||
mode_(modeTypeNames_.read(dict.lookup("mode"))),
|
||||
fieldNames_(dict.lookup("fields")),
|
||||
value_(readScalar(dict.lookup("value")))
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::minMaxCondition::~minMaxCondition()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * //
|
||||
|
||||
bool Foam::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)
|
||||
{
|
||||
WarningIn("bool Foam::minMaxCondition::apply()")
|
||||
<< "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::minMaxCondition::write()
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,145 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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 minMaxCondition_H
|
||||
#define minMaxCondition_H
|
||||
|
||||
#include "runTimeCondition.H"
|
||||
#include "NamedEnum.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class minMaxCondition Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class minMaxCondition
|
||||
:
|
||||
public runTimeCondition
|
||||
{
|
||||
public:
|
||||
|
||||
// Public enumerations
|
||||
|
||||
// Mode type
|
||||
enum modeType
|
||||
{
|
||||
mdMin,
|
||||
mdMax
|
||||
};
|
||||
|
||||
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,
|
||||
functionObjectState& 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 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 |
|
||||
-------------------------------------------------------------------------------
|
||||
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::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,91 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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
|
||||
{
|
||||
defineTypeNameAndDebug(minTimeStepCondition, 0);
|
||||
addToRunTimeSelectionTable
|
||||
(
|
||||
runTimeCondition,
|
||||
minTimeStepCondition,
|
||||
dictionary
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::minTimeStepCondition::minTimeStepCondition
|
||||
(
|
||||
const word& name,
|
||||
const objectRegistry& obr,
|
||||
const dictionary& dict,
|
||||
functionObjectState& state
|
||||
)
|
||||
:
|
||||
runTimeCondition(name, obr, dict, state),
|
||||
minValue_(readScalar(dict.lookup("minValue")))
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::minTimeStepCondition::~minTimeStepCondition()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * //
|
||||
|
||||
bool Foam::minTimeStepCondition::apply()
|
||||
{
|
||||
bool satisfied = false;
|
||||
|
||||
if (!active_)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (obr_.time().deltaTValue() < minValue_)
|
||||
{
|
||||
satisfied = true;
|
||||
}
|
||||
|
||||
return satisfied;
|
||||
}
|
||||
|
||||
|
||||
void Foam::minTimeStepCondition::write()
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -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/>.
|
||||
|
||||
Class
|
||||
Foam::minTimeStepCondition
|
||||
|
||||
Description
|
||||
Initial residual run time condition
|
||||
|
||||
SourceFiles
|
||||
minTimeStepCondition.H
|
||||
minTimeStepCondition.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef minTimeStepCondition_H
|
||||
#define minTimeStepCondition_H
|
||||
|
||||
#include "runTimeCondition.H"
|
||||
#include "NamedEnum.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
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,
|
||||
functionObjectState& state
|
||||
);
|
||||
|
||||
//- Destructor
|
||||
virtual ~minTimeStepCondition();
|
||||
|
||||
|
||||
// Public Member Functions
|
||||
|
||||
//- Apply the condition
|
||||
virtual bool apply();
|
||||
|
||||
//- Write
|
||||
virtual void write();
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,110 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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 "runTimeCondition.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
defineTypeNameAndDebug(runTimeCondition, 0);
|
||||
defineRunTimeSelectionTable(runTimeCondition, dictionary);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
|
||||
|
||||
Foam::dictionary& Foam::runTimeCondition::setConditionDict()
|
||||
{
|
||||
dictionary& propertyDict = state_.propertyDict();
|
||||
|
||||
if (!propertyDict.found(name_))
|
||||
{
|
||||
propertyDict.add(name_, dictionary());
|
||||
}
|
||||
|
||||
return propertyDict.subDict(name_);
|
||||
}
|
||||
|
||||
|
||||
const Foam::dictionary& Foam::runTimeCondition::conditionDict() const
|
||||
{
|
||||
return conditionDict_;
|
||||
}
|
||||
|
||||
|
||||
Foam::dictionary& Foam::runTimeCondition::conditionDict()
|
||||
{
|
||||
return conditionDict_;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::runTimeCondition::runTimeCondition
|
||||
(
|
||||
const word& name,
|
||||
const objectRegistry& obr,
|
||||
const dictionary& dict,
|
||||
functionObjectState& 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::runTimeCondition::~runTimeCondition()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Public Member Functions * * * * * * * * * * * //
|
||||
|
||||
const Foam::word& Foam::runTimeCondition::name() const
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::runTimeCondition::active() const
|
||||
{
|
||||
return active_;
|
||||
}
|
||||
|
||||
|
||||
Foam::label Foam::runTimeCondition::groupID() const
|
||||
{
|
||||
return groupID_;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,167 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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::runTimeCondition
|
||||
|
||||
Description
|
||||
Base class for run time conditions
|
||||
|
||||
SourceFiles
|
||||
runTimeCondition.C
|
||||
runTimeConditionNew.C
|
||||
runTimeCondition.H
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef runTimeCondition_H
|
||||
#define runTimeCondition_H
|
||||
|
||||
#include "functionObjectState.H"
|
||||
#include "dictionary.H"
|
||||
#include "autoPtr.H"
|
||||
#include "runTimeSelectionTables.H"
|
||||
#include "Switch.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class runTimeCondition Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class runTimeCondition
|
||||
{
|
||||
|
||||
protected:
|
||||
|
||||
// Protected data
|
||||
|
||||
//- Condition name
|
||||
word name_;
|
||||
|
||||
//- Reference to the object registry
|
||||
const objectRegistry& obr_;
|
||||
|
||||
//- State
|
||||
functionObjectState& 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,
|
||||
functionObjectState& state
|
||||
),
|
||||
(name, obr, dict, state)
|
||||
);
|
||||
|
||||
|
||||
//- Constructor
|
||||
runTimeCondition
|
||||
(
|
||||
const word& name,
|
||||
const objectRegistry& obr,
|
||||
const dictionary& dict,
|
||||
functionObjectState& state
|
||||
);
|
||||
|
||||
//- Destructor
|
||||
virtual ~runTimeCondition();
|
||||
|
||||
//- Selector
|
||||
static autoPtr<runTimeCondition> New
|
||||
(
|
||||
const word& conditionName,
|
||||
const objectRegistry& obr,
|
||||
const dictionary& dict,
|
||||
functionObjectState& 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 Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,70 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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 "runTimeCondition.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::autoPtr<Foam::runTimeCondition> Foam::runTimeCondition::New
|
||||
(
|
||||
const word& conditionName,
|
||||
const objectRegistry& obr,
|
||||
const dictionary& dict,
|
||||
functionObjectState& state
|
||||
)
|
||||
{
|
||||
word conditionType(dict.lookup("type"));
|
||||
|
||||
Info<< "Selecting runTimeCondition " << conditionType << endl;
|
||||
|
||||
dictionaryConstructorTable::iterator cstrIter =
|
||||
dictionaryConstructorTablePtr_->find(conditionType);
|
||||
|
||||
if (cstrIter == dictionaryConstructorTablePtr_->end())
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"runTimeCondition::New"
|
||||
"("
|
||||
"const word&, "
|
||||
"const objectRegistry&, "
|
||||
"const dictionary&, "
|
||||
"functionObjectState&"
|
||||
")"
|
||||
) << "Unknown runTimeCondition type "
|
||||
<< conditionType << nl << nl
|
||||
<< "Valid runTimeCondition types are:" << nl
|
||||
<< dictionaryConstructorTablePtr_->sortedToc()
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
return autoPtr<runTimeCondition>
|
||||
(
|
||||
cstrIter()(conditionName, obr, dict, state)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,264 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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 "runTimeControl.H"
|
||||
#include "dictionary.H"
|
||||
#include "runTimeCondition.H"
|
||||
#include "fvMesh.H"
|
||||
#include "Time.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
defineTypeNameAndDebug(runTimeControl, 0);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::runTimeControl::runTimeControl
|
||||
(
|
||||
const word& name,
|
||||
const objectRegistry& obr,
|
||||
const dictionary& dict,
|
||||
const bool loadFromFiles
|
||||
)
|
||||
:
|
||||
functionObjectState(obr, name),
|
||||
obr_(obr),
|
||||
conditions_(),
|
||||
groupMap_(),
|
||||
nWriteStep_(0),
|
||||
writeStepI_(0)
|
||||
{
|
||||
// Check if the available mesh is an fvMesh, otherwise deactivate
|
||||
if (setActive<fvMesh>())
|
||||
{
|
||||
read(dict);
|
||||
|
||||
// Check that some conditions are set
|
||||
if (conditions_.empty())
|
||||
{
|
||||
Info<< type() << " " << name_ << " output:" << nl
|
||||
<< " No conditions present - deactivating" << nl
|
||||
<< endl;
|
||||
|
||||
active_ = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Check that at least one condition is active
|
||||
active_ = false;
|
||||
forAll(conditions_, conditionI)
|
||||
{
|
||||
if (conditions_[conditionI].active())
|
||||
{
|
||||
active_ = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!active_)
|
||||
{
|
||||
Info<< type() << " " << name_ << " output:" << nl
|
||||
<< " All conditions inactive - deactivating" << nl
|
||||
<< endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::runTimeControl::~runTimeControl()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::runTimeControl::read(const dictionary& dict)
|
||||
{
|
||||
if (active_)
|
||||
{
|
||||
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_);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::runTimeControl::execute()
|
||||
{
|
||||
if (!active_)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
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())
|
||||
{
|
||||
FatalErrorIn("void Foam::runTimeControl::execute()")
|
||||
<< "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&>(obr_.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;
|
||||
}
|
||||
|
||||
|
||||
void Foam::runTimeControl::end()
|
||||
{
|
||||
if (active_)
|
||||
{
|
||||
execute();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::runTimeControl::timeSet()
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
|
||||
void Foam::runTimeControl::write()
|
||||
{
|
||||
if (active_)
|
||||
{
|
||||
forAll(conditions_, conditionI)
|
||||
{
|
||||
conditions_[conditionI].write();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,161 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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::runTimeControl
|
||||
|
||||
Group
|
||||
grpJobControlFunctionObjects
|
||||
|
||||
Description
|
||||
This function object 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
|
||||
IOrunTimeControl.H
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef runTimeControl_H
|
||||
#define runTimeControl_H
|
||||
|
||||
#include "functionObjectState.H"
|
||||
#include "Map.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declaration of classes
|
||||
class objectRegistry;
|
||||
class dictionary;
|
||||
class polyMesh;
|
||||
class mapPolyMesh;
|
||||
class runTimeCondition;
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class runTimeControl Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class runTimeControl
|
||||
:
|
||||
public functionObjectState
|
||||
{
|
||||
// Private data
|
||||
|
||||
//- Reference to the database
|
||||
const objectRegistry& obr_;
|
||||
|
||||
//- 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 objectRegistry&,
|
||||
const dictionary&,
|
||||
const bool loadFromFiles = false
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~runTimeControl();
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Return name of the set of runTimeControl
|
||||
virtual const word& name() const
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
||||
//- Read the runTimeControl data
|
||||
virtual void read(const dictionary&);
|
||||
|
||||
//- Execute, currently does nothing
|
||||
virtual void execute();
|
||||
|
||||
//- Execute at the final time-loop, currently does nothing
|
||||
virtual void end();
|
||||
|
||||
//- Called when time was set at the end of the Time::operator++
|
||||
virtual void timeSet();
|
||||
|
||||
//- Calculate the runTimeControl and write
|
||||
virtual void write();
|
||||
|
||||
//- Update for changes of mesh
|
||||
virtual void updateMesh(const mapPolyMesh&)
|
||||
{}
|
||||
|
||||
//- Update for changes of mesh
|
||||
virtual void movePoints(const polyMesh&)
|
||||
{}
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,42 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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 "runTimeControlFunctionObject.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
defineNamedTemplateTypeNameAndDebug(runTimeControlFunctionObject, 0);
|
||||
|
||||
addToRunTimeSelectionTable
|
||||
(
|
||||
functionObject,
|
||||
runTimeControlFunctionObject,
|
||||
dictionary
|
||||
);
|
||||
}
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,54 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / 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/>.
|
||||
|
||||
Typedef
|
||||
Foam::runTimeControlFunctionObject
|
||||
|
||||
Description
|
||||
FunctionObject wrapper around runTimeControl to allow it to be created
|
||||
via the functions entry within controlDict.
|
||||
|
||||
SourceFiles
|
||||
runTimeControlFunctionObject.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef runTimeControlFunctionObject_H
|
||||
#define runTimeControlFunctionObject_H
|
||||
|
||||
#include "runTimeControl.H"
|
||||
#include "OutputFilterFunctionObject.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
typedef OutputFilterFunctionObject<runTimeControl>
|
||||
runTimeControlFunctionObject;
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
Reference in New Issue
Block a user