diff --git a/src/functionObjects/field/binField/binModels/binModel/binModel.C b/src/functionObjects/field/binField/binModels/binModel/binModel.C index e610bada7f..b8fd5cbe65 100644 --- a/src/functionObjects/field/binField/binModels/binModel/binModel.C +++ b/src/functionObjects/field/binField/binModels/binModel/binModel.C @@ -174,7 +174,7 @@ bool Foam::binModel::read(const dictionary& dict) decomposePatchValues_ = dict.getOrDefault("decomposePatchValues", false); - filePtrs_.setSize(fieldNames_.size()); + filePtrs_.resize(fieldNames_.size()); forAll(filePtrs_, i) { filePtrs_.set(i, newFileAtStartTime(fieldNames_[i] + "Bin")); diff --git a/src/functionObjects/field/binField/binModels/singleDirectionUniformBin/singleDirectionUniformBin.C b/src/functionObjects/field/binField/binModels/singleDirectionUniformBin/singleDirectionUniformBin.C index e111827617..4d66960b97 100644 --- a/src/functionObjects/field/binField/binModels/singleDirectionUniformBin/singleDirectionUniformBin.C +++ b/src/functionObjects/field/binField/binModels/singleDirectionUniformBin/singleDirectionUniformBin.C @@ -46,46 +46,69 @@ void Foam::binModels::singleDirectionUniformBin::initialise() { const polyBoundaryMesh& pbm = mesh_.boundaryMesh(); - // Determine extents of patches in a given direction - scalar geomMin = GREAT; - scalar geomMax = -GREAT; - for (const label patchi : patchIDs_) - { - const polyPatch& pp = pbm[patchi]; - const scalarField d(pp.faceCentres() & binDir_); - geomMin = min(min(d), geomMin); - geomMax = max(max(d), geomMax); - } - - for (const label zonei : cellZoneIDs_) - { - const cellZone& cZone = mesh_.cellZones()[zonei]; - const vectorField cz(mesh_.C(), cZone); - const scalarField d(cz & binDir_); - - geomMin = min(min(d), geomMin); - geomMax = max(max(d), geomMax); - } - - reduce(geomMin, minOp()); - reduce(geomMax, maxOp()); - - // Slightly boost max so that region of interest is fully within bounds - geomMax = 1.0001*(geomMax - geomMin) + geomMin; - // Use geometry limits if not specified by the user - if (binMin_ == GREAT) binMin_ = geomMin; - if (binMax_ == GREAT) binMax_ = geomMax; + const bool useGeomLimits + ( + binLimits_.min() == GREAT + || binLimits_.max() == GREAT + ); - binDx_ = (binMax_ - binMin_)/scalar(nBin_); + if (useGeomLimits) + { + // Determine extents of patches/cells in a given direction + scalarMinMax geomLimits; - if (binDx_ <= 0) + for (const label patchi : patchIDs_) + { + for (const vector& p : pbm[patchi].faceCentres()) + { + geomLimits.add(p & binDir_); + } + } + + for (const label zonei : cellZoneIDs_) + { + for (const label celli : mesh_.cellZones()[zonei]) + { + geomLimits.add(mesh_.C()[celli] & binDir_); + } + } + + // Globally consistent + reduce(geomLimits, minMaxOp()); + + if (!geomLimits.good()) + { + FatalErrorInFunction + << "No patches/cellZones provided" + << exit(FatalError); + } + + // Slightly boost max so that region of interest is fully within bounds + // TBD: also adjust min? + const scalar adjust(1e-4*geomLimits.span()); + geomLimits.max() += adjust; + + // Use geometry limits if not specified by the user + if (binLimits_.min() == GREAT) + { + binLimits_.min() = geomLimits.min(); + } + if (binLimits_.max() == GREAT) + { + binLimits_.max() = geomLimits.max(); + } + } + + binWidth_ = binLimits_.span()/scalar(nBin_); + + if (binWidth_ <= 0) { FatalErrorInFunction << "Max bound must be greater than min bound" << nl - << " d = " << binDx_ << nl - << " min = " << binMin_ << nl - << " max = " << binMax_ << nl + << " d = " << binWidth_ << nl + << " min = " << binLimits_.min() << nl + << " max = " << binLimits_.max() << nl << exit(FatalError); } } @@ -101,9 +124,8 @@ Foam::binModels::singleDirectionUniformBin::singleDirectionUniformBin ) : binModel(dict, mesh, outputPrefix), - binDx_(0), - binMin_(GREAT), - binMax_(GREAT), + binWidth_(0), + binLimits_(GREAT), binDir_(Zero) { read(dict); @@ -125,30 +147,30 @@ bool Foam::binModels::singleDirectionUniformBin::read(const dictionary& dict) nBin_ = binDict.getCheck