/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2021-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
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 3 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, see .
\*---------------------------------------------------------------------------*/
#include "uniformBin.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace binModels
{
defineTypeNameAndDebug(uniformBin, 0);
addToRunTimeSelectionTable(binModel, uniformBin, dictionary);
}
}
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
void Foam::binModels::uniformBin::initialise()
{
const polyBoundaryMesh& pbm = mesh_.boundaryMesh();
// Use geometry limits if not specified by the user
{
// Determine extents of patches/cells
boundBox geomLimits;
for (const label patchi : patchIDs_)
{
vectorField pts
(
coordSysPtr_->localPosition(pbm[patchi].faceCentres())
);
MinMax limits(pts);
geomLimits.add(limits.min(), limits.max());
}
for (const label zonei : cellZoneIDs_)
{
const cellZone& cZone = mesh_.cellZones()[zonei];
const vectorField pts
(
coordSysPtr_->localPosition(vectorField(mesh_.C(), cZone))
);
MinMax limits(pts);
geomLimits.add(limits.min(), limits.max());
}
// Globally consistent
geomLimits.reduce();
// Slightly boost max so that region of interest is fully within bounds
// TBD: could also adjust min?
const vector adjust(1e-4*geomLimits.span());
geomLimits.max() += adjust;
for (direction cmpt = 0; cmpt < vector::nComponents; ++cmpt)
{
// Use geometry limits if not specified by the user
if (binLimits_.min()[cmpt] == GREAT)
{
binLimits_.min()[cmpt] = geomLimits.min()[cmpt];
}
if (binLimits_.max()[cmpt] == GREAT)
{
binLimits_.max()[cmpt] = geomLimits.max()[cmpt];
}
}
}
for (direction cmpt = 0; cmpt < vector::nComponents; ++cmpt)
{
if (binLimits_.min()[cmpt] > binLimits_.max()[cmpt])
{
FatalErrorInFunction
<< "Max bounds must be greater than min bounds" << nl
<< " direction = " << cmpt << nl
<< " min = " << binLimits_.min()[cmpt] << nl
<< " max = " << binLimits_.max()[cmpt] << nl
<< exit(FatalError);
}
//- Compute bin widths in binning directions
binWidth_[cmpt] =
(
(binLimits_.max()[cmpt] - binLimits_.min()[cmpt])
/ scalar(nBins_[cmpt])
);
if (binWidth_[cmpt] <= 0)
{
FatalErrorInFunction
<< "Bin widths must be greater than zero" << nl
<< " direction = " << cmpt << nl
<< " min bound = " << binLimits_.min()[cmpt] << nl
<< " max bound = " << binLimits_.max()[cmpt] << nl
<< " bin width = " << binWidth_[cmpt] << nl
<< exit(FatalError);
}
}
setBinsAddressing();
}
Foam::labelList Foam::binModels::uniformBin::binAddr(const vectorField& d) const
{
labelList binIndices(d.size(), -1);
forAll(d, i)
{
// Avoid elements outside of the bin
bool faceInside = true;
for (direction cmpt = 0; cmpt < vector::nComponents; ++cmpt)
{
if
(
d[i][cmpt] < binLimits_.min()[cmpt]
|| d[i][cmpt] > binLimits_.max()[cmpt]
)
{
faceInside = false;
break;
}
}
if (faceInside)
{
// Find the bin division corresponding to the element
Vector