regionSizeDistribution.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2013-2026 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::functionObjects::regionSizeDistribution
26 
27 Description
28  Creates a size distribution via interrogating a continuous phase fraction
29  field.
30 
31  Looks up a phase-fraction (alpha) field and splits the mesh into regions
32  based on where the field is below the threshold value. These
33  regions ("droplets") can now be analysed.
34 
35  Regions:
36  - print the regions connected to a user-defined set of patches.
37  (in spray calculation these form the liquid core)
38  - print the regions with too large volume. These are the 'background'
39  regions.
40  - (debug) write regions as a volScalarField
41  - (debug) print for all regions the sum of volume and alpha*volume
42 
43  Output (volume scalar) fields include:
44  - alpha_liquidCore : alpha with outside liquid core set to 0
45  - alpha_background : alpha with outside background set to 0.
46 
47  %Histogram:
48  - determine histogram of diameter (given minDiameter, maxDiameter, nBins)
49  - write graph of number of droplets per bin
50  - write graph of sum, average and deviation of droplet volume per bin
51  - write graph of sum, average and deviation of user-defined fields. For
52  volVectorFields these are those of the 3 components and the magnitude.
53 
54  Example of function object specification:
55  \verbatim
56  regionSizeDistribution1
57  {
58  type regionSizeDistribution;
59  libs ("libfieldFunctionObjects.so");
60  ...
61  alpha alpha;
62  patches (inlet);
63  threshold 0.4;
64  fields (p U);
65  nBins 100;
66  maxDiameter 0.5e-4;
67  minDiameter 0;
68  setFormat gnuplot;
69  }
70  \endverbatim
71 
72 Usage
73  \table
74  Property | Description | Required | Default value
75  type | type name: regionSizeDistribution |yes|
76  alpha | phase field to interrogate | yes |
77  patches | patches from which the liquid core is identified | yes|
78  threshold | phase fraction applied to delimit regions | yes |
79  fields | fields to sample | yes |
80  nBins | number of bins for histogram | yes |
81  maxDiameter | maximum region equivalent diameter | yes |
82  minDiameter | minimum region equivalent diameter | no | 0
83  setFormat | writing format | yes |
84  \endtable
85 
86 See also
87  Foam::functionObject
88  Foam::functionObjects::fvMeshFunctionObject
89  Foam::functionObjects::writeFile
90 
91 SourceFiles
92  regionSizeDistribution.C
93 
94 \*---------------------------------------------------------------------------*/
95 
96 #ifndef regionSizeDistribution_functionObject_H
97 #define regionSizeDistribution_functionObject_H
98 
99 #include "fvMeshFunctionObject.H"
100 #include "writeFile.H"
101 #include "setWriter.H"
102 #include "Map.H"
103 #include "volFieldsFwd.H"
104 #include "wordReList.H"
105 #include "coordinateSystem.H"
106 
107 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
108 
109 namespace Foam
110 {
111 
112 // Forward declaration of classes
113 class regionSplit;
114 
115 namespace functionObjects
116 {
117 
118 /*---------------------------------------------------------------------------*\
119  Class regionSizeDistribution Declaration
120 \*---------------------------------------------------------------------------*/
121 
122 class regionSizeDistribution
123 :
124  public fvMeshFunctionObject
125 {
126  // Private Data
127 
128  writeFile file_;
129 
130  //- Name of field
131  word alphaName_;
132 
133  //- Patches to walk from
134  wordReList patchNames_;
135 
136  //- Clip value
137  scalar threshold_;
138 
139  //- Maximum droplet diameter
140  scalar maxDiam_;
141 
142  //- Minimum droplet diameter
143  scalar minDiam_;
144 
145  //- Number of bins
146  label nBins_;
147 
148  //- Names of fields to sample on regions
149  wordList fields_;
150 
151  //- Output formatter to write
152  autoPtr<setWriter> formatterPtr_;
153 
154 
155  // Private Member Functions
156 
157  template<class Type>
158  Map<Type> regionSum(const regionSplit&, const Field<Type>&) const;
159 
160  //- Get data in order
161  template<class Type>
162  tmp<Field<Type>> extractData
163  (
164  const UList<label>& keys,
165  const Map<Type>&
166  ) const;
167 
168  //- Write volfields with the parts of alpha which are not
169  // droplets (liquidCore, backGround)
170  void writeAlphaFields
171  (
172  const regionSplit& regions,
173  const Map<label>& keepRegions,
174  const Map<scalar>& regionVolume,
175  const volScalarField& alpha
176  ) const;
177 
178  //- Mark all regions starting at patches
179  Map<label> findPatchRegions(const regionSplit&) const;
180 
181  //- Helper: divide if denom != 0
182  template<class Type>
183  static tmp<Field<Type>> divide(const Field<Type>&, const scalarField&);
184 
185  //- Generate fields for writing
186  template<class Type>
187  void generateFields
188  (
189  const word& fieldName, // name of field
190  const labelList& indices, // index of bin for each region
191  const Field<Type>& sortedField, // per region field data
192  const scalarField& binCount, // per bin number of regions
195  ) const;
196 
197  //- Generate fields for writing. Scalar overload. It is possible to
198  // generate more fields for scalar input.
199  void generateFields
200  (
201  const word& fieldName, // name of field
202  const labelList& indices, // index of bin for each region
203  const scalarField& sortedField, // per region field data
204  const scalarField& binCount, // per bin number of regions
207  ) const;
208 
209  //- Generate fields for writing
210  template<class Type>
211  void generateFields
212  (
213  const word& fieldName, // name of field
214  const Field<Type>& cellField, // per cell field data
215  const regionSplit& regions, // per cell the region(=droplet)
216  const labelList& sortedRegions, // valid regions in sorted order
217  const scalarField& sortedNormalisation,
218  const labelList& indices, // index of bin for each region
219  const scalarField& binCount, // per bin number of regions
222  ) const;
223 
224 
225 public:
226 
227  //- Runtime type information
228  TypeName("regionSizeDistribution");
229 
230 
231  // Constructors
232 
233  //- Construct for given objectRegistry and dictionary.
234  // Allow the possibility to load fields from files
236  (
237  const word& name,
238  const Time& runTime,
239  const dictionary&
240  );
241 
242  //- Disallow default bitwise copy construction
244 
245 
246  // Destructor
247 
248  virtual ~regionSizeDistribution();
249 
250 
251  // Member Functions
252 
253  //- Read the regionSizeDistribution data
254  virtual bool read(const dictionary&);
255 
256  //- Return the list of fields required
257  virtual wordList fields() const;
258 
259  //- Do nothing
260  virtual bool execute();
261 
262  //- Calculate the regionSizeDistribution and write
263  virtual bool write();
264 
265 
266  // Member Operators
267 
268  //- Disallow default bitwise assignment
269  void operator=(const regionSizeDistribution&) = delete;
270 };
271 
272 
273 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
274 
275 } // End namespace functionObjects
276 } // End namespace Foam
277 
278 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
279 
280 #ifdef NoRepository
282 #endif
283 
284 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
285 
286 #endif
287 
288 // ************************************************************************* //
Pre-declare SubField and related Field type.
Definition: Field.H:83
Generic GeometricField class.
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: PtrList.H:75
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:76
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
const word & name() const
Return the name of this functionObject.
Divide a list of fields.
Definition: divide.H:73
Creates a size distribution via interrogating a continuous phase fraction field.
TypeName("regionSizeDistribution")
Runtime type information.
regionSizeDistribution(const word &name, const Time &runTime, const dictionary &)
Construct for given objectRegistry and dictionary.
virtual wordList fields() const
Return the list of fields required.
void operator=(const regionSizeDistribution &)=delete
Disallow default bitwise assignment.
virtual bool write()
Calculate the regionSizeDistribution and write.
virtual bool read(const dictionary &)
Read the regionSizeDistribution data.
This class separates the mesh into distinct unconnected regions, each of which is then given a label ...
Definition: regionSplit.H:118
A class for managing temporary objects.
Definition: tmp.H:55
A class for handling words, derived from string.
Definition: word.H:63
static List< word > fieldNames
Definition: globalFoam.H:46
volScalarField alpha(IOobject("alpha", runTime.name(), mesh, IOobject::READ_IF_PRESENT, IOobject::AUTO_WRITE), lambda *max(Ua &U, zeroSensitivity))
Namespace for OpenFOAM.
List< word > wordList
A List of words.
Definition: fileName.H:54
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
List< wordRe > wordReList
A List of wordRe (word or regular expression)
Definition: wordReList.H:50