cellSource: Writing the volume of the cellSource (sum(V)) for each time is now optional

Previous behavior which may be useful for moving-mesh cases can be
selected using the optional entry:
    writeVolume  yes;

The initial volume is written in the log and data file header e.g.:

 #   Source : all
 #   Cells  : 3829
 #   Volume : 9.943164e-01

Also added
    sumMag        | sum of component magnitudes
This commit is contained in:
Henry
2015-04-26 21:35:25 +01:00
parent e393bbbaca
commit ef3ba43cf4
4 changed files with 58 additions and 21 deletions

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) 2011-2014 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -41,10 +41,11 @@ namespace Foam
template<> template<>
const char* NamedEnum<fieldValues::cellSource::operationType, 9>::names[] = const char* NamedEnum<fieldValues::cellSource::operationType, 10>::names[] =
{ {
"none", "none",
"sum", "sum",
"sumMag",
"average", "average",
"weightedAverage", "weightedAverage",
"volAverage", "volAverage",
@ -65,7 +66,7 @@ namespace Foam
const Foam::NamedEnum<Foam::fieldValues::cellSource::sourceType, 2> const Foam::NamedEnum<Foam::fieldValues::cellSource::sourceType, 2>
Foam::fieldValues::cellSource::sourceTypeNames_; Foam::fieldValues::cellSource::sourceTypeNames_;
const Foam::NamedEnum<Foam::fieldValues::cellSource::operationType, 9> const Foam::NamedEnum<Foam::fieldValues::cellSource::operationType, 10>
Foam::fieldValues::cellSource::operationTypeNames_; Foam::fieldValues::cellSource::operationTypeNames_;
@ -77,6 +78,8 @@ void Foam::fieldValues::cellSource::setCellZoneCells()
{ {
case stCellZone: case stCellZone:
{ {
dict().lookup("sourceName") >> sourceName_;
label zoneId = mesh().cellZones().findZoneID(sourceName_); label zoneId = mesh().cellZones().findZoneID(sourceName_);
if (zoneId < 0) if (zoneId < 0)
@ -114,6 +117,12 @@ void Foam::fieldValues::cellSource::setCellZoneCells()
} }
Foam::scalar Foam::fieldValues::cellSource::volume() const
{
return gSum(filterField(mesh().V()));
}
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
void Foam::fieldValues::cellSource::initialise(const dictionary& dict) void Foam::fieldValues::cellSource::initialise(const dictionary& dict)
@ -125,8 +134,7 @@ void Foam::fieldValues::cellSource::initialise(const dictionary& dict)
WarningIn WarningIn
( (
"Foam::fieldValues::cellSource::initialise(const dictionary&)" "Foam::fieldValues::cellSource::initialise(const dictionary&)"
) ) << type() << " " << name_ << ": "
<< type() << " " << name_ << ": "
<< sourceTypeNames_[source_] << "(" << sourceName_ << "):" << nl << sourceTypeNames_[source_] << "(" << sourceName_ << "):" << nl
<< " Source has no cells - deactivating" << endl; << " Source has no cells - deactivating" << endl;
@ -151,10 +159,18 @@ void Foam::fieldValues::cellSource::initialise(const dictionary& dict)
void Foam::fieldValues::cellSource::writeFileHeader(const label i) void Foam::fieldValues::cellSource::writeFileHeader(const label i)
{ {
file() writeCommented(file(), "Source : ");
<< "# Source : " << sourceTypeNames_[source_] << " " file() << sourceTypeNames_[source_] << " " << sourceName_ << endl;
<< sourceName_ << nl << "# Cells : " << nCells_ << nl writeCommented(file(), "Cells : ");
<< "# Time" << tab << "sum(V)"; file() << nCells_ << endl;
writeCommented(file(), "Volume : ");
file() << volume() << endl;
writeCommented(file(), "Time");
if (writeVolume_)
{
file() << tab << "Volume";
}
forAll(fields_, i) forAll(fields_, i)
{ {
@ -182,7 +198,8 @@ Foam::fieldValues::cellSource::cellSource
operation_(operationTypeNames_.read(dict.lookup("operation"))), operation_(operationTypeNames_.read(dict.lookup("operation"))),
nCells_(0), nCells_(0),
cellId_(), cellId_(),
weightFieldName_("none") weightFieldName_("none"),
writeVolume_(dict.lookupOrDefault("writeVolume", false))
{ {
read(dict); read(dict);
} }
@ -214,10 +231,17 @@ void Foam::fieldValues::cellSource::write()
if (active_) if (active_)
{ {
scalar totalVolume = gSum(filterField(mesh().V()));
if (Pstream::master()) if (Pstream::master())
{ {
file() << obr_.time().value() << tab << totalVolume; file() << obr_.time().value();
}
if (writeVolume_)
{
if (Pstream::master())
{
file() << tab << volume();
}
} }
forAll(fields_, i) forAll(fields_, i)

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) 2011-2012 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -58,9 +58,10 @@ Description
\heading Function object usage \heading Function object usage
\table \table
Property | Description | Required | Default value Property | Description | Required | Default value
type | type name: cellSource | yes | type | Type name: cellSource | yes |
log | write data to standard output | no | no log | Write data to standard output | no | no
valueOutput | write the raw output values | yes | valueOutput | Write the raw output values | yes |
writeVolume | Write the volume of the cellSource | no |
source | cell source: see below | yes | source | cell source: see below | yes |
sourceName | name of cell source if required | no | sourceName | name of cell source if required | no |
operation | operation to perform | yes | operation | operation to perform | yes |
@ -80,6 +81,7 @@ Description
\plaintable \plaintable
none | no operation none | no operation
sum | sum sum | sum
sumMag | sum of component magnitudes
average | ensemble average average | ensemble average
weightedAverage | weighted average weightedAverage | weighted average
volAverage | volume weighted average volAverage | volume weighted average
@ -143,6 +145,7 @@ public:
{ {
opNone, opNone,
opSum, opSum,
opSumMag,
opAverage, opAverage,
opWeightedAverage, opWeightedAverage,
opVolAverage, opVolAverage,
@ -153,7 +156,7 @@ public:
}; };
//- Operation type names //- Operation type names
static const NamedEnum<operationType, 9> operationTypeNames_; static const NamedEnum<operationType, 10> operationTypeNames_;
private: private:
@ -166,6 +169,9 @@ private:
//- Set cells to evaluate based on a patch //- Set cells to evaluate based on a patch
void setPatchCells(); void setPatchCells();
//- Calculate and return volume of the cellSource: sum(V)
scalar volume() const;
protected: protected:
@ -186,6 +192,9 @@ protected:
//- Weight field name - only used for opWeightedAverage mode //- Weight field name - only used for opWeightedAverage mode
word weightFieldName_; word weightFieldName_;
//- Optionally write the volume of the cellSource
bool writeVolume_;
// Protected Member Functions // Protected Member Functions

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) 2011-2014 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -90,6 +90,11 @@ Type Foam::fieldValues::cellSource::processValues
result = sum(values); result = sum(values);
break; break;
} }
case opSumMag:
{
result = sum(cmptMag(values));
break;
}
case opAverage: case opAverage:
{ {
result = sum(values)/values.size(); result = sum(values)/values.size();
@ -201,7 +206,7 @@ bool Foam::fieldValues::cellSource::writeValues(const word& fieldName)
file()<< tab << result; file()<< tab << result;
Info(log_)<< " " << operationTypeNames_[operation_] Info(log_)<< " " << operationTypeNames_[operation_]
<< "(" << sourceName_ << ") for " << fieldName << "(" << sourceName_ << ") of " << fieldName
<< " = " << result << endl; << " = " << result << endl;
} }
} }
@ -221,4 +226,3 @@ Foam::tmp<Foam::Field<Type> > Foam::fieldValues::cellSource::filterField
// ************************************************************************* // // ************************************************************************* //

View File

@ -80,7 +80,7 @@ Foam::fieldValue::fieldValue
dict_(dict), dict_(dict),
active_(true), active_(true),
log_(true), log_(true),
sourceName_(dict.lookupOrDefault<word>("sourceName", "sampledSurface")), sourceName_(word::null),
fields_(dict.lookup("fields")), fields_(dict.lookup("fields")),
valueOutput_(dict.lookup("valueOutput")), valueOutput_(dict.lookup("valueOutput")),
resultDict_(fileName("name"), dictionary::null) resultDict_(fileName("name"), dictionary::null)