singleDirectionUniformBin.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2021-2023 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35 namespace binModels
36 {
39 }
40 }
41 
42 
43 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
44 
46 {
48 
49  // Use geometry limits if not specified by the user
50  const bool useGeomLimits
51  (
52  binLimits_.min() == GREAT
53  || binLimits_.max() == GREAT
54  );
55 
56  if (useGeomLimits)
57  {
58  // Determine extents of patches/cells in a given direction
59  scalarMinMax geomLimits;
60 
61  for (const label patchi : patchIDs_)
62  {
63  for (const vector& p : pbm[patchi].faceCentres())
64  {
65  geomLimits.add(p & binDir_);
66  }
67  }
68 
69  for (const label zonei : cellZoneIDs_)
70  {
71  for (const label celli : mesh_.cellZones()[zonei])
72  {
73  geomLimits.add(mesh_.C()[celli] & binDir_);
74  }
75  }
76 
77  // Globally consistent
78  reduce(geomLimits, minMaxOp<scalar>());
79 
80  if (!geomLimits.good())
81  {
83  << "No patches/cellZones provided"
84  << exit(FatalError);
85  }
86 
87  // Slightly boost max so that region of interest is fully within bounds
88  // TBD: also adjust min?
89  const scalar adjust(1e-4*geomLimits.span());
90  geomLimits.max() += adjust;
91 
92  // Use geometry limits if not specified by the user
93  if (binLimits_.min() == GREAT)
94  {
95  binLimits_.min() = geomLimits.min();
96  }
97  if (binLimits_.max() == GREAT)
98  {
99  binLimits_.max() = geomLimits.max();
100  }
101  }
102 
103  binWidth_ = binLimits_.span()/scalar(nBin_);
104 
105  if (binWidth_ <= 0)
106  {
108  << "Max bound must be greater than min bound" << nl
109  << " d = " << binWidth_ << nl
110  << " min = " << binLimits_.min() << nl
111  << " max = " << binLimits_.max() << nl
112  << exit(FatalError);
113  }
114 }
115 
116 
117 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
118 
120 (
121  const dictionary& dict,
122  const fvMesh& mesh,
123  const word& outputPrefix
124 )
125 :
126  binModel(dict, mesh, outputPrefix),
127  binWidth_(0),
128  binLimits_(GREAT),
129  binDir_(Zero)
130 {
131  read(dict);
132 }
133 
134 
135 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
136 
138 {
139  if (!binModel::read(dict))
140  {
141  return false;
142  }
143 
144  Info<< " Activating a set of single-direction bins" << endl;
145 
146  const dictionary& binDict = dict.subDict("binData");
147 
148  nBin_ = binDict.getCheck<label>("nBin", labelMinMax::ge(1));
149 
150  Info<< " Employing " << nBin_ << " bins" << nl;
151 
152  if (binDict.readIfPresent("min", binLimits_.min()))
153  {
154  Info<< " - min : " << binLimits_.min() << nl;
155  }
156  if (binDict.readIfPresent("max", binLimits_.max()))
157  {
158  Info<< " - max : " << binLimits_.max() << nl;
159  }
160 
161  cumulative_ = binDict.getOrDefault<bool>("cumulative", false);
162  Info<< " - cumulative : " << cumulative_ << nl
163  << " - decomposePatchValues : " << decomposePatchValues_ << nl;
164 
165  binDir_ = binDict.get<vector>("direction");
166  if (binDir_.mag() < SMALL)
167  {
169  << "Input direction should not be zero valued" << nl
170  << " direction = " << binDir_ << nl
171  << exit(FatalIOError);
172  }
173  binDir_.normalise();
174 
175  Info<< " - direction : " << binDir_ << nl << endl;
177  initialise();
178 
179  return true;
180 }
181 
182 
184 {
185  forAll(fieldNames_, i)
186  {
187  const bool ok =
188  (
189  processField<scalar>(i)
190  || processField<vector>(i)
191  || processField<sphericalTensor>(i)
192  || processField<symmTensor>(i)
193  || processField<tensor>(i)
194  );
195 
196  if (!ok)
197  {
199  << "Unable to find field " << fieldNames_[i]
200  << ". Avaliable objects are "
201  << mesh_.objectRegistry::sortedToc()
202  << endl;
203  }
204  }
205 
206  writtenHeader_ = true;
207 }
208 
209 
210 // ************************************************************************* //
const polyBoundaryMesh & pbm
dictionary dict
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
const fvMesh & mesh_
Reference to the mesh.
Definition: binModel.H:68
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:598
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
T getCheck(const word &keyword, const Predicate &pred, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T with additional checking FatalIOError if not found, or if the number of tokens is...
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
label nBin_
Total number of bins.
Definition: binModel.H:89
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T. FatalIOError if not found, or if the number of tokens is incorrect.
virtual bool read(const dictionary &dict)
Read the dictionary.
defineTypeNameAndDebug(singleDirectionUniformBin, 0)
Macros for easy insertion into run-time selection tables.
bool good() const
Range is non-inverted.
Definition: MinMaxI.H:165
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:127
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
Base class for bin models to handle general bin characteristics.
Definition: binModel.H:57
const T & min() const noexcept
The min value (first)
Definition: MinMaxI.H:107
const dimensionedScalar e
Elementary charge.
Definition: createFields.H:11
dynamicFvMesh & mesh
const polyBoundaryMesh & boundaryMesh() const noexcept
Return boundary mesh.
Definition: polyMesh.H:608
A class for handling words, derived from Foam::string.
Definition: word.H:63
labelList patchIDs_
Indices of operand patches.
Definition: binModel.H:94
Calculates binned data in a specified direction.
static MinMax< T > ge(const T &minVal)
A semi-infinite range from minVal to the type max.
Definition: MinMaxI.H:24
Vector< scalar > vector
Definition: vector.H:57
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO...
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
MinMax< T > & add(const MinMax &other)
Extend the range to include the other min/max range.
Definition: MinMaxI.H:250
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry if present, and assign to T val. FatalIOError if it is found and the number of tokens i...
addToRunTimeSelectionTable(binModel, singleDirectionUniformBin, dictionary)
scalar binWidth_
Distance between bin divisions.
#define WarningInFunction
Report a warning using Foam::Warning.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:627
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
virtual bool read(const dictionary &dict)
Read the dictionary.
Definition: binModel.C:125
const T & max() const noexcept
The max value (second)
Definition: MinMaxI.H:121
const cellZoneMesh & cellZones() const noexcept
Return cell zone mesh.
Definition: polyMesh.H:678
void reduce(const List< UPstream::commsStruct > &comms, T &value, const BinaryOp &bop, const int tag, const label comm)
Reduce inplace (cf. MPI Allreduce) using specified communication schedule.
T span() const
The min to max span. Zero if the range is invalid.
Definition: MinMaxI.H:143
messageStream Info
Information stream (stdout output on master, null elsewhere)
const volVectorField & C() const
Return cell centres as volVectorField.
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T, or return the given default value. FatalIOError if it is found and the number of...
volScalarField & p
virtual void initialise()
Initialise bin properties.
labelList cellZoneIDs_
Indices of operand cell zones.
Definition: binModel.H:104
singleDirectionUniformBin(const dictionary &dict, const fvMesh &mesh, const word &outputPrefix)
Construct from components.
MinMax< scalar > binLimits_
The min/max bounds for the bins.
Namespace for OpenFOAM.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL IO ERROR&#39; header text and ...
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127