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-2022 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  // Determine extents of patches in a given direction
50  scalar geomMin = GREAT;
51  scalar geomMax = -GREAT;
52  for (const label patchi : patchSet_)
53  {
54  const polyPatch& pp = pbm[patchi];
55  const scalarField d(pp.faceCentres() & binDir_);
56  geomMin = min(min(d), geomMin);
57  geomMax = max(max(d), geomMax);
58  }
59 
60  for (const label zonei : cellZoneIDs_)
61  {
62  const cellZone& cZone = mesh_.cellZones()[zonei];
63  const vectorField cz(mesh_.C(), cZone);
64  const scalarField d(cz & binDir_);
65 
66  geomMin = min(min(d), geomMin);
67  geomMax = max(max(d), geomMax);
68  }
69 
70  reduce(geomMin, minOp<scalar>());
71  reduce(geomMax, maxOp<scalar>());
72 
73  // Slightly boost max so that region of interest is fully within bounds
74  geomMax = 1.0001*(geomMax - geomMin) + geomMin;
75 
76  // Use geometry limits if not specified by the user
77  if (binMin_ == GREAT) binMin_ = geomMin;
78  if (binMax_ == GREAT) binMax_ = geomMax;
79 
80  binDx_ = (binMax_ - binMin_)/scalar(nBin_);
81 
82  if (binDx_ <= 0)
83  {
85  << "Max bound must be greater than min bound" << nl
86  << " d = " << binDx_ << nl
87  << " min = " << binMin_ << nl
88  << " max = " << binMax_ << nl
89  << exit(FatalError);
90  }
91 }
92 
93 
94 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
95 
97 (
98  const dictionary& dict,
99  const fvMesh& mesh,
100  const word& outputPrefix
101 )
102 :
103  binModel(dict, mesh, outputPrefix),
104  binDx_(0),
105  binMin_(GREAT),
106  binMax_(GREAT),
107  binDir_(Zero)
108 {
109  read(dict);
110 }
111 
112 
113 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
114 
116 {
117  if (!binModel::read(dict))
118  {
119  return false;
120  }
121 
122  Info<< " Activating a set of single-direction bins" << endl;
123 
124  const dictionary& binDict = dict.subDict("binData");
125 
126  nBin_ = binDict.getCheck<label>("nBin", labelMinMax::ge(1));
127 
128  Info<< " Employing " << nBin_ << " bins" << endl;
129  if (binDict.readIfPresent("min", binMin_))
130  {
131  Info<< " - min : " << binMin_ << endl;
132  }
133  if (binDict.readIfPresent("max", binMax_))
134  {
135  Info<< " - max : " << binMax_ << endl;
136  }
137 
138  cumulative_ = binDict.getOrDefault<bool>("cumulative", false);
139  Info<< " - cumulative : " << cumulative_ << endl;
140  Info<< " - decomposePatchValues : " << decomposePatchValues_ << endl;
141 
142  binDir_ = binDict.get<vector>("direction");
143  binDir_.normalise();
144 
145  if (mag(binDir_) == 0)
146  {
148  << "Input direction should not be zero valued" << nl
149  << " direction = " << binDir_ << nl
150  << exit(FatalIOError);
151  }
152 
153  Info<< " - direction : " << binDir_ << nl << endl;
155  initialise();
156 
157  return true;
158 }
159 
160 
162 {
163  forAll(fieldNames_, i)
164  {
165  const bool ok =
166  processField<scalar>(i)
167  || processField<vector>(i)
168  || processField<sphericalTensor>(i)
169  || processField<symmTensor>(i)
170  || processField<tensor>(i);
171 
172  if (!ok)
173  {
175  << "Unable to find field " << fieldNames_[i]
176  << ". Avaliable objects are "
177  << mesh_.objectRegistry::sortedToc()
178  << endl;
179  }
180  }
181 
182  writtenHeader_ = true;
183 }
184 
185 
186 // ************************************************************************* //
const polyBoundaryMesh & pbm
dictionary dict
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
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:120
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:578
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:40
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:49
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:487
label nBin_
Total number of bins.
Definition: binModel.H:89
Vector< Cmpt > & normalise(const scalar tol=ROOTVSMALL)
Inplace normalise the vector by its magnitude.
Definition: VectorI.H:114
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.
labelHashSet patchSet_
Indices of operand patches.
Definition: binModel.H:94
defineTypeNameAndDebug(singleDirectionUniformBin, 0)
Macros for easy insertion into run-time selection tables.
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:414
Base class for bin models to handle general bin characteristics.
Definition: binModel.H:57
dynamicFvMesh & mesh
const polyBoundaryMesh & boundaryMesh() const noexcept
Return boundary mesh.
Definition: polyMesh.H:584
A class for handling words, derived from Foam::string.
Definition: word.H:63
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
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
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:26
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO...
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)
#define WarningInFunction
Report a warning using Foam::Warning.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:607
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:79
virtual bool read(const dictionary &dict)
Read the dictionary.
Definition: binModel.C:129
const cellZoneMesh & cellZones() const noexcept
Return cell zone mesh.
Definition: polyMesh.H:654
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.
messageStream Info
Information stream (stdout output on master, null elsewhere)
Field< vector > vectorField
Specialisation of Field<T> for vector.
scalar binDx_
Distance between bin divisions.
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...
virtual void initialise()
Initialise bin properties.
labelList cellZoneIDs_
Indices of operand cell zones.
Definition: binModel.H:104
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:69
singleDirectionUniformBin(const dictionary &dict, const fvMesh &mesh, const word &outputPrefix)
Construct from components.
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
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:133