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-------------------------------------------------------------------------------
10License
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
33namespace Foam
34{
35namespace binModels
36{
39}
40}
41
42
43// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
44
46{
47 const polyBoundaryMesh& pbm = mesh_.boundaryMesh();
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;
154
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// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
static MinMax< T > ge(const T &minVal)
A semi-infinite range from minVal to the type max.
Definition: MinMaxI.H:31
virtual bool read()
Re-read model coefficients if they have changed.
Vector< Cmpt > & normalise(const scalar tol=ROOTVSMALL)
Inplace normalise the vector by its magnitude.
Definition: VectorI.H:123
Base class for bin models to handle general bin characteristics.
Definition: binModel.H:64
const fvMesh & mesh_
Reference to the mesh.
Definition: binModel.H:70
label nBin_
Total number of bins.
Definition: binModel.H:83
labelHashSet patchSet_
Indices of operand patches.
Definition: binModel.H:86
labelList cellZoneIDs_
Indices of operand cell zones.
Definition: binModel.H:92
Calculates binned data in a specified direction.
virtual void initialise()
Initialise bin properties.
virtual bool read(const dictionary &dict)
Read the dictionary.
scalar binDx_
Distance between bin divisions.
A subset of mesh cells.
Definition: cellZone.H:65
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
T getCheck(const word &keyword, const Predicate &pred, enum keyType::option matchOpt=keyType::REGEX) const
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:91
const volVectorField & C() const
Return cell centres as volVectorField.
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO.
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:456
const cellZoneMesh & cellZones() const noexcept
Return cell zone mesh.
Definition: polyMesh.H:504
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:75
const vectorField::subField faceCentres() const
Return face centres.
Definition: polyPatch.C:321
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
dynamicFvMesh & mesh
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:473
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
#define WarningInFunction
Report a warning using Foam::Warning.
Namespace for OpenFOAM.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
void reduce(const List< UPstream::commsStruct > &comms, T &value, const BinaryOp &bop, const int tag, const label comm)
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:33
IOerror FatalIOError
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
error FatalError
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333