diff --git a/src/functionObjects/field/Make/files b/src/functionObjects/field/Make/files index 3fd56b2f79..bc8fe9634f 100644 --- a/src/functionObjects/field/Make/files +++ b/src/functionObjects/field/Make/files @@ -66,6 +66,10 @@ surfaceInterpolate/surfaceInterpolate.C regionSizeDistribution/regionSizeDistribution.C histogram/histogram.C +histogram/histogramModels/histogramModel/histogramModel.C +histogram/histogramModels/histogramModel/histogramModelNew.C +histogram/histogramModels/equalBinWidth/equalBinWidth.C +histogram/histogramModels/unequalBinWidth/unequalBinWidth.C fieldExpression/fieldExpression.C components/components.C diff --git a/src/functionObjects/field/histogram/histogram.C b/src/functionObjects/field/histogram/histogram.C index 90e2289cc1..4bafa9521c 100644 --- a/src/functionObjects/field/histogram/histogram.C +++ b/src/functionObjects/field/histogram/histogram.C @@ -27,8 +27,7 @@ License \*---------------------------------------------------------------------------*/ #include "histogram.H" -#include "volFields.H" -#include "ListOps.H" +#include "histogramModel.H" #include "addToRunTimeSelectionTable.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -52,11 +51,8 @@ Foam::functionObjects::histogram::histogram const dictionary& dict ) : - functionObjects::fvMeshFunctionObject(name, runTime, dict), - functionObjects::writeFile(obr_, name), - max_(-GREAT), - min_(GREAT), - setWriterPtr_(nullptr) + fvMeshFunctionObject(name, runTime, dict), + histogramModelPtr_(nullptr) { read(dict); } @@ -66,30 +62,14 @@ Foam::functionObjects::histogram::histogram bool Foam::functionObjects::histogram::read(const dictionary& dict) { - fvMeshFunctionObject::read(dict); - writeFile::read(dict); - - dict.readEntry("field", fieldName_); - - max_ = dict.getOrDefault("max", -GREAT); - min_ = dict.getOrDefault("min", GREAT); - dict.readEntry("nBins", nBins_); - - if (nBins_ < 1) + if (!fvMeshFunctionObject::read(dict)) { - FatalErrorInFunction - << "Number of histogram bins = " << nBins_ - << " cannot be negative or zero." - << abort(FatalError); + return false; } - const word writeType(dict.get("setFormat")); + Info<< type() << " " << name() << ":" << endl; - setWriterPtr_ = coordSetWriter::New - ( - writeType, - dict.subOrEmptyDict("formatOptions").optionalSubDict(writeType) - ); + histogramModelPtr_.reset(histogramModel::New(name(), mesh_, dict)); return true; } @@ -103,115 +83,13 @@ bool Foam::functionObjects::histogram::execute() bool Foam::functionObjects::histogram::write() { - Log << type() << " " << name() << " write:" << nl; + Log << type() << " " << name() << " write:" << endl; - tmp tfield; - tfield.cref(obr_.cfindObject(fieldName_)); - - if (tfield) + if (!histogramModelPtr_->write(log)) { - Log << " Looking up field " << fieldName_ << endl; - } - else - { - Log << " Reading field " << fieldName_ << endl; - tfield = tmp::New - ( - IOobject - ( - fieldName_, - mesh_.time().timeName(), - mesh_, - IOobject::MUST_READ, - IOobject::NO_WRITE - ), - mesh_ - ); - } - const auto& field = tfield(); - - scalar histMax = max_; - scalar histMin = min_; - - if (max_ == -GREAT) - { - // Determine current min and max - histMax = max(field).value(); - - if (min_ == GREAT) - { - histMin = min(field).value(); - } - Log << " Determined histogram bounds from field" - << " min/max(" << fieldName_ << ") = " - << histMin << ' ' << histMax << endl; - } - else if (min_ == GREAT) - { - histMin = 0; - } - - // Calculate the mid-points of bins for the graph axis - pointField xBin(nBins_, Zero); - const scalar delta = (histMax - histMin)/nBins_; - - { - scalar x = histMin + 0.5*delta; - for (point& p : xBin) - { - p.x() = x; - x += delta; - } - } - - scalarField dataNormalized(nBins_, Zero); - labelField dataCount(nBins_, Zero); - const scalarField& V = mesh_.V(); - - forAll(field, celli) - { - const label bini = (field[celli] - histMin)/delta; - if (bini >= 0 && bini < nBins_) - { - dataNormalized[bini] += V[celli]; - dataCount[bini]++; - } - } - - Pstream::listCombineGather(dataNormalized, plusEqOp()); - Pstream::listCombineGather(dataCount, plusEqOp