From 083d7059fcf4cd19beaf0b0ed4a64a2642012357 Mon Sep 17 00:00:00 2001 From: Henry Date: Sun, 26 Apr 2015 16:32:19 +0100 Subject: [PATCH] faceSource: Writing the total area of the faceSource (sum(magSf)) for each time is now optional Previous behavior which may be useful for moving-mesh cases can be selected using the optional entry: writeTotalArea yes; The initial total area is written in the log and data file header e.g.: # Source : faceZone f0 # Faces : 8 # Area : 1.063860e-02 --- .../functionObjectFile/functionObjectFile.C | 4 +- src/fvOptions/fvOptions/fvOptionList.C | 4 +- .../field/fieldValues/faceSource/faceSource.C | 60 ++++++++++++------- .../field/fieldValues/faceSource/faceSource.H | 10 +++- .../oscillatingBox/extractHeightData | 2 +- .../oscillatingBox/system/controlDict | 1 + .../oscillatingBox/extractHeightData | 2 +- .../oscillatingBox/system/controlDict | 1 + 8 files changed, 56 insertions(+), 28 deletions(-) diff --git a/src/OpenFOAM/db/functionObjects/functionObjectFile/functionObjectFile.C b/src/OpenFOAM/db/functionObjects/functionObjectFile/functionObjectFile.C index a04fc522f5..77a9b00a86 100644 --- a/src/OpenFOAM/db/functionObjects/functionObjectFile/functionObjectFile.C +++ b/src/OpenFOAM/db/functionObjects/functionObjectFile/functionObjectFile.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2012-2014 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2012-2015 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -38,7 +38,7 @@ Foam::label Foam::functionObjectFile::addChars = 7; void Foam::functionObjectFile::initStream(Ostream& os) const { os.setf(ios_base::scientific, ios_base::floatfield); -// os.precision(IOstream::defaultPrecision()); + // os.precision(IOstream::defaultPrecision()); os.width(charWidth()); } diff --git a/src/fvOptions/fvOptions/fvOptionList.C b/src/fvOptions/fvOptions/fvOptionList.C index e9a022a32c..169a1acd75 100644 --- a/src/fvOptions/fvOptions/fvOptionList.C +++ b/src/fvOptions/fvOptions/fvOptionList.C @@ -107,13 +107,13 @@ Foam::fv::optionList::optionList(const fvMesh& mesh) void Foam::fv::optionList::reset(const dictionary& dict) { + // Count number of active fvOptions label count = 0; forAllConstIter(dictionary, dict, iter) { - // safety: if (iter().isDict()) { - count ++; + count++; } } diff --git a/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.C b/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.C index 83e56780c0..770d8bf3fc 100644 --- a/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.C +++ b/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.C @@ -378,6 +378,23 @@ void Foam::fieldValues::faceSource::combineSurfaceGeometry } +Foam::scalar Foam::fieldValues::faceSource::totalArea() const +{ + scalar totalArea; + + if (surfacePtr_.valid()) + { + totalArea = gSum(surfacePtr_().magSf()); + } + else + { + totalArea = gSum(filterField(mesh().magSf(), false)); + } + + return totalArea; +} + + // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // void Foam::fieldValues::faceSource::initialise(const dictionary& dict) @@ -423,22 +440,15 @@ void Foam::fieldValues::faceSource::initialise(const dictionary& dict) return; } - scalar totalArea; - if (surfacePtr_.valid()) { surfacePtr_().update(); - totalArea = gSum(surfacePtr_().magSf()); - } - else - { - totalArea = gSum(filterField(mesh().magSf(), false)); } Info<< type() << " " << name_ << ":" << nl << " total faces = " << nFaces_ << nl - << " total area = " << totalArea + << " total area = " << totalArea() << nl; if (dict.readIfPresent("weightField", weightFieldName_)) @@ -517,10 +527,18 @@ void Foam::fieldValues::faceSource::initialise(const dictionary& dict) void Foam::fieldValues::faceSource::writeFileHeader(const label i) { - file() - << "# Source : " << sourceTypeNames_[source_] << " " - << sourceName_ << nl << "# Faces : " << nFaces_ << nl - << "# Time" << tab << "sum(magSf)"; + writeCommented(file(), "Source : "); + file() << sourceTypeNames_[source_] << " " << sourceName_ << endl; + writeCommented(file(), "Faces : "); + file() << nFaces_ << endl; + writeCommented(file(), "Area : "); + file() << totalArea() << endl; + writeCommented(file(), "Time"); + + if (writeTotalArea_) + { + file() << tab << "Area"; + } forAll(fields_, i) { @@ -621,6 +639,7 @@ Foam::fieldValues::faceSource::faceSource : fieldValue(name, obr, dict, typeName, loadFromFiles), surfaceWriterPtr_(NULL), + writeTotalArea_(dict.lookupOrDefault("writeTotalArea", false)), source_(sourceTypeNames_.read(dict.lookup("source"))), operation_(operationTypeNames_.read(dict.lookup("operation"))), weightFieldName_("none"), @@ -661,21 +680,22 @@ void Foam::fieldValues::faceSource::write() if (active_) { - scalar totalArea; - if (surfacePtr_.valid()) { surfacePtr_().update(); - totalArea = gSum(surfacePtr_().magSf()); - } - else - { - totalArea = gSum(filterField(mesh().magSf(), false)); } if (Pstream::master()) { - file() << obr_.time().value() << tab << totalArea; + file() << obr_.time().value(); + } + + if (writeTotalArea_) + { + if (Pstream::master()) + { + file() << tab << totalArea(); + } } // construct weight field. Note: zero size means weight = 1 diff --git a/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.H b/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.H index a60e6f0ead..4750be190f 100644 --- a/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.H +++ b/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.H @@ -214,20 +214,23 @@ private: //- Set faces according to sampledSurface void sampledSurfaceFaces(const dictionary&); - //- Combine mesh faces and points from multiple processors + //- Combine mesh faces and points from multiple processors void combineMeshGeometry ( faceList& faces, pointField& points ) const; - //- Combine surface faces and points from multiple processors + //- Combine surface faces and points from multiple processors void combineSurfaceGeometry ( faceList& faces, pointField& points ) const; + //- Calculate and return total area of the faceSource: sum(magSf) + scalar totalArea() const; + protected: @@ -236,6 +239,9 @@ protected: //- Surface writer autoPtr surfaceWriterPtr_; + //- Optionally write the totalArea + bool writeTotalArea_; + //- Source type sourceType source_; diff --git a/tutorials/multiphase/potentialFreeSurfaceDyMFoam/oscillatingBox/extractHeightData b/tutorials/multiphase/potentialFreeSurfaceDyMFoam/oscillatingBox/extractHeightData index bc1a5b586c..65a0e38701 100755 --- a/tutorials/multiphase/potentialFreeSurfaceDyMFoam/oscillatingBox/extractHeightData +++ b/tutorials/multiphase/potentialFreeSurfaceDyMFoam/oscillatingBox/extractHeightData @@ -1,2 +1,2 @@ #!/bin/sh -awk '{print $1 " " $4}' postProcessing/poolHeight/0/faceSource.dat > poolHeight_vs_time +awk '{print $1 " " $3}' postProcessing/poolHeight/0/faceSource.dat > poolHeight_vs_time diff --git a/tutorials/multiphase/potentialFreeSurfaceDyMFoam/oscillatingBox/system/controlDict b/tutorials/multiphase/potentialFreeSurfaceDyMFoam/oscillatingBox/system/controlDict index 394002be33..dc617bd777 100644 --- a/tutorials/multiphase/potentialFreeSurfaceDyMFoam/oscillatingBox/system/controlDict +++ b/tutorials/multiphase/potentialFreeSurfaceDyMFoam/oscillatingBox/system/controlDict @@ -75,6 +75,7 @@ functions outputControl timeStep; outputInterval 1; log yes; + writeTotalArea no; valueOutput no; source faceZone; sourceName f0; diff --git a/tutorials/multiphase/potentialFreeSurfaceFoam/oscillatingBox/extractHeightData b/tutorials/multiphase/potentialFreeSurfaceFoam/oscillatingBox/extractHeightData index bc1a5b586c..65a0e38701 100755 --- a/tutorials/multiphase/potentialFreeSurfaceFoam/oscillatingBox/extractHeightData +++ b/tutorials/multiphase/potentialFreeSurfaceFoam/oscillatingBox/extractHeightData @@ -1,2 +1,2 @@ #!/bin/sh -awk '{print $1 " " $4}' postProcessing/poolHeight/0/faceSource.dat > poolHeight_vs_time +awk '{print $1 " " $3}' postProcessing/poolHeight/0/faceSource.dat > poolHeight_vs_time diff --git a/tutorials/multiphase/potentialFreeSurfaceFoam/oscillatingBox/system/controlDict b/tutorials/multiphase/potentialFreeSurfaceFoam/oscillatingBox/system/controlDict index 5155b313d4..de8547f454 100644 --- a/tutorials/multiphase/potentialFreeSurfaceFoam/oscillatingBox/system/controlDict +++ b/tutorials/multiphase/potentialFreeSurfaceFoam/oscillatingBox/system/controlDict @@ -75,6 +75,7 @@ functions outputControl timeStep; outputInterval 1; log yes; + writeTotalArea no; valueOutput no; source faceZone; sourceName f0;