ENH: add optional write flag to fieldMinMax

- allows logging min/max without creating any files
This commit is contained in:
Mark Olesen
2010-06-08 12:51:55 +02:00
parent 6dbc3b9f92
commit aaf1674de2
6 changed files with 120 additions and 27 deletions

View File

@ -0,0 +1,75 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 1.6 |
| \\ / A nd | Web: www.OpenFOAM.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object controlDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
application XXX;
startFrom latestTime;
startTime 0;
stopAt endTime;
endTime 0.1;
deltaT 1e-05;
writeControl timeStep;
writeInterval 10;
purgeWrite 0;
writeFormat ascii;
writePrecision 6;
writeCompression off;
timeFormat general;
timePrecision 6;
runTimeModifiable true;
functions
{
minMax
{
// Type of functionObject
type fieldMinMax;
// Where to load it from (if not already in solver)
functionObjectLibs ("libfieldAverage.so");
// Function object enabled flag
enabled true;
// Log to output (default: false)
log false;
// Write information to file (default: true)
write true;
// Fields to be monitored - runTime modifiable
fields
(
U
p
);
}
}
// ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2008-2009 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2008-2010 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -59,6 +59,7 @@ Foam::fieldMinMax::fieldMinMax
name_(name),
obr_(obr),
active_(true),
write_(true),
log_(false),
mode_(mdMag),
fieldSet_(),
@ -92,9 +93,10 @@ void Foam::fieldMinMax::read(const dictionary& dict)
{
if (active_)
{
write_ = dict.lookupOrDefault<Switch>("write", true);
log_ = dict.lookupOrDefault<Switch>("log", false);
mode_ = modeTypeNames_[dict.lookup("mode")];
mode_ = modeTypeNames_[dict.lookupOrDefault<word>("mode", "magnitude")];
dict.lookup("fields") >> fieldSet_;
}
}
@ -171,7 +173,10 @@ void Foam::fieldMinMax::write()
if (active_)
{
// Create the fieldMinMax file if not already created
makeFile();
if (write_)
{
makeFile();
}
forAll(fieldSet_, fieldI)
{
@ -195,13 +200,17 @@ void Foam::fieldMinMax::calcMinMaxFields<Foam::scalar>
{
const volScalarField& field =
obr_.lookupObject<volScalarField>(fieldName);
scalar minValue = min(field).value();
scalar maxValue = max(field).value();
const scalar minValue = min(field).value();
const scalar maxValue = max(field).value();
if (Pstream::master())
{
fieldMinMaxFilePtr_() << obr_.time().value() << tab
<< fieldName << tab << minValue << tab << maxValue << endl;
if (write_)
{
fieldMinMaxFilePtr_()
<< obr_.time().value() << tab
<< fieldName << tab << minValue << tab << maxValue << endl;
}
if (log_)
{

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2008-2009 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2008-2010 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -74,11 +74,13 @@ public:
mdCmpt
};
protected:
// Protected data
//- Mode type names
static const NamedEnum<modeType, 2> modeTypeNames_;
//- Name of this set of field min/max.
// Also used as the name of the output directory.
word name_;
@ -88,11 +90,11 @@ protected:
//- on/off switch
bool active_;
//- Switch to send output to Info as well as to file
Switch log_;
//- Switch to enable/disable writing to file
Switch write_;
//- Mode type names
static const NamedEnum<modeType, 2> modeTypeNames_;
//- Switch to send output to Info as well
Switch log_;
//- Mode for min/max - only applicable for ranks > 0
modeType mode_;
@ -100,7 +102,6 @@ protected:
//- Fields to assess min/max
wordList fieldSet_;
//- Min/max file ptr
autoPtr<OFstream> fieldMinMaxFilePtr_;

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2008-2009 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2008-2010 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -42,14 +42,18 @@ void Foam::fieldMinMax::calcMinMaxFields(const word& fieldName)
{
case mdMag:
{
scalar minValue = min(mag(field)).value();
scalar maxValue = max(mag(field)).value();
const scalar minValue = min(mag(field)).value();
const scalar maxValue = max(mag(field)).value();
if (Pstream::master())
{
fieldMinMaxFilePtr_() << obr_.time().value() << tab
<< fieldName << tab << minValue << tab << maxValue
<< endl;
if (write_)
{
fieldMinMaxFilePtr_()
<< obr_.time().value() << tab
<< fieldName << tab << minValue << tab << maxValue
<< endl;
}
if (log_)
{
@ -65,14 +69,18 @@ void Foam::fieldMinMax::calcMinMaxFields(const word& fieldName)
}
case mdCmpt:
{
Type minValue = min(field).value();
Type maxValue = max(field).value();
const Type minValue = min(field).value();
const Type maxValue = max(field).value();
if (Pstream::master())
{
fieldMinMaxFilePtr_() << obr_.time().value() << tab
<< fieldName << tab << minValue << tab << maxValue
<< endl;
if (write_)
{
fieldMinMaxFilePtr_()
<< obr_.time().value() << tab
<< fieldName << tab << minValue << tab << maxValue
<< endl;
}
if (log_)
{

View File

@ -61,7 +61,7 @@ protected:
// Protected data
//- Name of this fieldValue object
//- Name of this fieldValue object
word name_;
//- Database this class is registered to