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

@ -103,7 +103,7 @@ void Foam::writeRegisteredObject::write()
( (
"Foam::writeRegisteredObject::read(const dictionary&)" "Foam::writeRegisteredObject::read(const dictionary&)"
) << "Object " << objectNames_[i] << " not found in " ) << "Object " << objectNames_[i] << " not found in "
<< "database. Available objects are:" << nl << obr_.toc() << "database. Available objects:" << nl << obr_.sortedToc()
<< endl; << endl;
} }

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

View File

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

View File

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

View File

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