Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
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
31// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32
33namespace Foam
34{
35namespace 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, sumOp<scalarMinMax>());
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
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)
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 << ". Available objects are "
201 << mesh_.objectRegistry::sortedToc()
202 << endl;
203 }
204 }
205
206 writtenHeader_ = true;
207}
208
209
210// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
const polyBoundaryMesh & pbm
const T & max() const noexcept
The max value.
Definition MinMax.H:217
const T & min() const noexcept
The min value.
Definition MinMax.H:207
static MinMax< label > ge(const label &minVal)
bool good() const
Range is non-inverted.
Definition MinMaxI.H:153
T span() const
The min to max span. Zero for invalid range.
Definition MinMaxI.H:131
MinMax< T > & add(const MinMax &other)
Extend the range to include the other min/max range.
Definition MinMaxI.H:240
Vector< Cmpt > & normalise(const scalar tol=ROOTVSMALL)
Inplace normalise the vector by its magnitude.
Definition VectorI.H:114
Base class for bin models to handle general bin characteristics.
Definition binModel.H:60
const fvMesh & mesh_
Reference to the mesh.
Definition binModel.H:68
wordList fieldNames_
Names of operand fields.
Definition binModel.H:99
label nBin_
Total number of bins.
Definition binModel.H:89
virtual bool read(const dictionary &dict)
Read the function-object dictionary.
Definition binModel.C:125
bool decomposePatchValues_
Decompose patch values into normal and tangential components.
Definition binModel.H:73
labelList cellZoneIDs_
Indices of operand cell zones.
Definition binModel.H:104
bool cumulative_
Flag to accumulate bin data with increasing distance in binning direction.
Definition binModel.H:79
binModel(const dictionary &dict, const fvMesh &mesh, const word &outputPrefix)
Construct from components.
Definition binModel.C:108
labelList patchIDs_
Indices of operand patches.
Definition binModel.H:94
Calculates binned data in a specified direction.
virtual void initialise()
Initialise bin properties.
singleDirectionUniformBin(const dictionary &dict, const fvMesh &mesh, const word &outputPrefix)
Construct from components.
virtual bool read(const dictionary &dict)
Read the function-object dictionary.
MinMax< scalar > binLimits_
The min/max bounds for the bins.
scalar binWidth_
Distance between bin divisions.
bool processField(const label fieldi)
Apply the binning to field fieldi.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
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.
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...
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...
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...
bool writtenHeader_
Flag to identify whether the header has been written.
Definition writeFile.H:157
Mesh data needed to do the Finite Volume discretisation.
Definition fvMesh.H:85
A polyBoundaryMesh is a polyPatch list with registered IO, a reference to the associated polyMesh,...
const polyBoundaryMesh & boundaryMesh() const noexcept
Return boundary mesh.
Definition polyMesh.H:609
A class for handling words, derived from Foam::string.
Definition word.H:66
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
volScalarField & p
dynamicFvMesh & mesh
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition error.H:629
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
#define WarningInFunction
Report a warning using Foam::Warning.
Namespace for OpenFOAM.
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition int32.H:127
messageStream Info
Information stream (stdout output on master, null elsewhere).
MinMax< scalar > scalarMinMax
A scalar min/max range.
Definition MinMax.H:97
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
void reduce(T &value, BinaryOp bop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Reduce inplace (cf. MPI Allreduce).
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
static constexpr const zero Zero
Global zero (0).
Definition zero.H:127
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
Vector< scalar > vector
Definition vector.H:57
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
dictionary dict
volScalarField & e
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299