diff --git a/applications/utilities/postProcessing/sampling/fieldAverage/Make/files b/applications/utilities/postProcessing/sampling/fieldAverage/Make/files new file mode 100644 index 0000000000..fa6148a012 --- /dev/null +++ b/applications/utilities/postProcessing/sampling/fieldAverage/Make/files @@ -0,0 +1,6 @@ +fieldAverage/fieldAverage.C +fieldAverageItem/fieldAverageItem.C +fieldAverageItem/fieldAverageItemIO.C +fieldAverageFunctionObject/fieldAverageFunctionObject.C + +LIB = $(FOAM_LIBBIN)/libfieldAverage diff --git a/applications/utilities/postProcessing/sampling/fieldAverage/Make/options b/applications/utilities/postProcessing/sampling/fieldAverage/Make/options new file mode 100644 index 0000000000..3ec0599e21 --- /dev/null +++ b/applications/utilities/postProcessing/sampling/fieldAverage/Make/options @@ -0,0 +1,9 @@ +EXE_INC = \ + -I$(LIB_SRC)/finiteVolume/lnInclude \ + -I$(LIB_SRC)/OpenFOAM/lnInclude \ + -I$(LIB_SRC)/sampling/lnInclude + +LIB_LIBS = \ + -lfiniteVolume \ + -lOpenFOAM \ + -lsampling diff --git a/applications/utilities/postProcessing/sampling/fieldAverage/controlDict b/applications/utilities/postProcessing/sampling/fieldAverage/controlDict new file mode 100644 index 0000000000..b20a0d1fdb --- /dev/null +++ b/applications/utilities/postProcessing/sampling/fieldAverage/controlDict @@ -0,0 +1,84 @@ +/*---------------------------------------------------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: 1.4 | +| \\ / A nd | Web: http://www.openfoam.org | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ + +FoamFile +{ + version 2.0; + format ascii; + + root ""; + case ""; + instance ""; + local ""; + + class dictionary; + object controlDict; +} + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +application oodles; + +startFrom latestTime; + +startTime 0; + +stopAt endTime; + +endTime 0.1; + +deltaT 1e-05; + +writeControl timeStep; + +writeInterval 10; + +purgeWrite 0; + +writeFormat ascii; + +writePrecision 6; + +writeCompression uncompressed; + +timeFormat general; + +timePrecision 6; + +runTimeModifiable yes; + +functions +( + fieldAverage1 + { + // Type of functionObject + type fieldAverage; + + // Where to load it from (if not already in solver) + functionObjectLibs ("libfieldAverage.so"); + + // Fields to be probed. runTime modifiable! + fields + ( + U + { + mean on; + prime2Mean on; + base time; + } + p + { + mean on; + prime2Mean on; + base time; + } + ); + } +); + +// ************************************************************************* // diff --git a/applications/utilities/postProcessing/sampling/fieldAverage/fieldAverage/IOFieldAverage.H b/applications/utilities/postProcessing/sampling/fieldAverage/fieldAverage/IOFieldAverage.H new file mode 100644 index 0000000000..32fdcb2b5e --- /dev/null +++ b/applications/utilities/postProcessing/sampling/fieldAverage/fieldAverage/IOFieldAverage.H @@ -0,0 +1,50 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2007 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Typedef + IOfieldAverage + +Description + Instance of the generic IOOutputFilter for fieldAverage. + +\*---------------------------------------------------------------------------*/ + +#ifndef IOfieldAverage_H +#define IOfieldAverage_H + +#include "fieldAverage.H" +#include "IOOutputFilter.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + typedef IOOutputFilter IOFieldAverage; +} + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/applications/utilities/postProcessing/sampling/fieldAverage/fieldAverage/fieldAverage.C b/applications/utilities/postProcessing/sampling/fieldAverage/fieldAverage/fieldAverage.C new file mode 100644 index 0000000000..72dfc00201 --- /dev/null +++ b/applications/utilities/postProcessing/sampling/fieldAverage/fieldAverage/fieldAverage.C @@ -0,0 +1,339 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2007 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +#include "fieldAverage.H" +#include "volFields.H" +#include "dictionary.H" +#include "Time.H" +#include "IFstream.H" +#include "OFstream.H" + +#include "fieldAverageItem.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineTypeNameAndDebug(fieldAverage, 0); +} + +const Foam::word Foam::fieldAverage::EXT_MEAN = "Mean"; +const Foam::word Foam::fieldAverage::EXT_PRIME2MEAN = "Prime2Mean"; + + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +void Foam::fieldAverage::resetLists(const label nItems) +{ + meanScalarFields_.clear(); + meanScalarFields_.setSize(nItems); + + meanVectorFields_.clear(); + meanVectorFields_.setSize(nItems); + + meanSymmTensorFields_.clear(); + meanSymmTensorFields_.setSize(nItems); + + meanSphericalTensorFields_.clear(); + meanSphericalTensorFields_.setSize(nItems); + + prime2MeanScalarFields_.clear(); + prime2MeanScalarFields_.setSize(nItems); + + prime2MeanSymmTensorFields_.clear(); + prime2MeanSymmTensorFields_.setSize(nItems); + + nSteps_.clear(); + nSteps_.setSize(nItems, 1); + + totalTime_.clear(); + totalTime_.setSize(nItems, obr_.time().deltaT().value()); +} + + +void Foam::fieldAverage::initialise() +{ + // Add mean fields to the field lists + forAll(faItems_, i) + { + const word fieldName = faItems_[i].fieldName(); + if (obr_.foundObject(fieldName)) + { + addMeanFields(i, meanScalarFields_); + } + else if (obr_.foundObject(fieldName)) + { + addMeanFields(i, meanVectorFields_); + } + else if (obr_.foundObject(fieldName)) + { + addMeanFields(i, meanSymmTensorFields_); + } + else if (obr_.foundObject(fieldName)) + { + addMeanFields(i, meanSphericalTensorFields_); + } + else + { + FatalErrorIn("Foam::fieldAverage::initialise()") + << "Requested field " << faItems_[i].fieldName() + << " does not exist in the database" << nl + << exit(FatalError); + } + } + + // Add prime-squared mean fields to the field lists + forAll(faItems_, i) + { + if (faItems_[i].prime2Mean()) + { + const word fieldName = faItems_[i].fieldName(); + if (obr_.foundObject(fieldName)) + { + if (!faItems_[i].mean()) + { + FatalErrorIn("Foam::fieldAverage::initialise()") + << "To calculate the prime-squared average, the " + << "mean average must also be selected for field " + << fieldName << nl << exit(FatalError); + } + addPrime2MeanFields(i, prime2MeanScalarFields_); + } + else if (obr_.foundObject(fieldName)) + { + if (!faItems_[i].mean()) + { + FatalErrorIn("Foam::fieldAverage::initialise()") + << "To calculate the prime-squared average, the " + << "mean average must also be selected for field " + << fieldName << nl << exit(FatalError); + } + addPrime2MeanFields + ( + i, + prime2MeanSymmTensorFields_ + ); + } + else + { + FatalErrorIn("Foam::fieldAverage::initialise()") + << "prime2Mean average can only be applied to " + << "volScalarFields and volVectorFields" + << nl << " Field: " << fieldName << nl + << exit(FatalError); + } + } + } +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::fieldAverage::fieldAverage +( + const word& name, + const objectRegistry& obr, + const dictionary& dict, + const bool loadFromFiles +) +: + name_(name), + obr_(obr), + active_(true), + faItems_(dict.lookup("fields")), + meanScalarFields_(faItems_.size()), + meanVectorFields_(faItems_.size()), + meanSymmTensorFields_(faItems_.size()), + meanSphericalTensorFields_(faItems_.size()), + prime2MeanScalarFields_(faItems_.size()), + prime2MeanSymmTensorFields_(faItems_.size()), + nSteps_(faItems_.size(), 1), + totalTime_(faItems_.size(), obr_.time().deltaT().value()) +{ + // Check if the available mesh is an fvMesh otherise deactivate + if (!isA(obr_)) + { + active_ = false; + WarningIn + ( + "fieldAverage::fieldAverage" + "(" + "const word&," + "const objectRegistry&," + "const dictionary&," + "const bool" + ")" + ) << "No fvMesh available, deactivating." + << nl << endl; + } + + read(dict); +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::fieldAverage::~fieldAverage() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +void Foam::fieldAverage::read(const dictionary& dict) +{ + if (active_) + { + faItems_.clear(); + faItems_ = List(dict.lookup("fields")); + + resetLists(faItems_.size()); + + initialise(); + + readAveragingProperties(); + } +} + + +void Foam::fieldAverage::write() +{ + if (active_) + { + calcAverages(); + + if (obr_.time().outputTime()) + { + writeAverages(); + + writeAveragingProperties(); + } + } +} + + +void Foam::fieldAverage::calcAverages() +{ + Info<< "Calculating averages" << nl << endl; + forAll(faItems_, i) + { + nSteps_[i]++; + totalTime_[i] += obr_.time().deltaT().value(); + } + + addMeanSqrToPrime2Mean(prime2MeanScalarFields_); + addMeanSqrToPrime2Mean(prime2MeanSymmTensorFields_); + + calculateMeanFields(meanScalarFields_); + calculateMeanFields(meanVectorFields_); + calculateMeanFields(meanSymmTensorFields_); + calculateMeanFields(meanSphericalTensorFields_); + + calculatePrime2MeanFields(prime2MeanScalarFields_); + calculatePrime2MeanFields(prime2MeanSymmTensorFields_); +} + + +void Foam::fieldAverage::writeAverages() const +{ + writeFieldList(meanScalarFields_); + writeFieldList(meanVectorFields_); + writeFieldList(meanSymmTensorFields_); + writeFieldList(meanSphericalTensorFields_); + + writeFieldList(prime2MeanScalarFields_); + writeFieldList(prime2MeanSymmTensorFields_); +} + + +void Foam::fieldAverage::writeAveragingProperties() const +{ + IOdictionary propsDict + ( + IOobject + ( + "fieldAveragingProperties", + obr_.time().timeName(), + "uniform", + obr_, + IOobject::NO_READ, + IOobject::NO_WRITE + ) + ); + + forAll(faItems_, i) + { + const word fieldName = faItems_[i].fieldName(); + propsDict.add(fieldName, dictionary()); + propsDict.subDict(fieldName).add("nSteps", nSteps_[i]); + propsDict.subDict(fieldName).add("totalTime", totalTime_[i]); + } + + propsDict.regIOobject::write(); +} + + +void Foam::fieldAverage::readAveragingProperties() +{ + IFstream propsFile + ( + obr_.time().path()/obr_.time().timeName() + /"uniform"/"fieldAveragingProperties" + ); + + if (!propsFile.good()) + { + return; + } + + dictionary propsDict(dictionary::null, propsFile); + + forAll(faItems_, i) + { + const word& fieldName = faItems_[i].fieldName(); + if (propsDict.found(fieldName)) + { + dictionary fieldDict(propsDict.subDict(fieldName)); + + nSteps_[i] = readLabel(fieldDict.lookup("nSteps")); + totalTime_[i] = readScalar(fieldDict.lookup("totalTime")); + } + } +} + + +void Foam::fieldAverage::updateMesh(const mapPolyMesh&) +{ + // Do nothing +} + + +void Foam::fieldAverage::movePoints(const pointField&) +{ + // Do nothing +} + + +// ************************************************************************* // diff --git a/applications/utilities/postProcessing/sampling/fieldAverage/fieldAverage/fieldAverage.H b/applications/utilities/postProcessing/sampling/fieldAverage/fieldAverage/fieldAverage.H new file mode 100644 index 0000000000..8fbad3dea6 --- /dev/null +++ b/applications/utilities/postProcessing/sampling/fieldAverage/fieldAverage/fieldAverage.H @@ -0,0 +1,293 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2007 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Class + Foam::fieldAverage + +Description + Calculates the field averages given list of fieldAverageItems, e.g. + + @verbatim + fields + ( + U + { + mean on; + prime2Mean on; + base time; // ensemble + } + p + { + mean on; + prime2Mean on; + base time; // ensemble + } + ); + @endverbatim + + Member function calcAverages() calculates the averages. + + Member function fieldAverage::write() calls calcAverages(). Average + field names are constructed by concatenating the base field with the + averaging type, e.g. + - base field, U + - arithmetic mean field, UMean + - prime-squared field, UPrime2Mean + + Information regarding the number of averaging steps, and total averaging + time are written on a (base) per-field basis to the + fieldAveragingProperties dictionary, located in