regionSizeDistribution.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2013 OpenFOAM Foundation
6  \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
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::regionSizeDistribution
26 
27 Group
28  grpFieldFunctionObjects
29 
30 Description
31  This function object creates a size distribution via interrogating a
32  continuous phase fraction field.
33 
34  Looks up a phase-fraction (alpha) field and splits the mesh into regions
35  based on where the field is below the threshold value. These
36  regions ("droplets") can now be analysed.
37 
38  Regions:
39  - print the regions connected to a user-defined set of patches.
40  (in spray calculation these form the liquid core)
41  - print the regions with too large volume. These are the 'background'
42  regions.
43  - (debug) write regions as a volScalarField
44  - (debug) print for all regions the sum of volume and alpha*volume
45 
46  Output (volume scalar) fields include:
47  - alpha_liquidCore : alpha with outside liquid core set to 0
48  - alpha_background : alpha with outside background set to 0.
49 
50  %Histogram:
51  - determine histogram of diameter (given minDiameter, maxDiameter, nBins)
52  - write graph of number of droplets per bin
53  - write graph of sum, average and deviation of droplet volume per bin
54  - write graph of sum, average and deviation of user-defined fields. For
55  volVectorFields these are those of the 3 components and the magnitude.
56 
57  Example of function object specification:
58  \verbatim
59  regionSizeDistribution1
60  {
61  type regionSizeDistribution;
62  functionObjectLibs ("libfieldFunctionObjects.so");
63  ...
64  field alpha;
65  patches (inlet);
66  threshold 0.4;
67  fields (p U);
68  nBins 100;
69  maxDiameter 0.5e-4;
70  minDiameter 0;
71  setFormat gnuplot;
72  coordinateSystem
73  {
74  type cartesian;
75  origin (0 0 0);
76  e3 (0 1 1);
77  e1 (1 0 0);
78  }
79  }
80  \endverbatim
81 
82  \heading Function object usage
83  \table
84  Property | Description | Required | Default value
85  type | type name: regionSizeDistribution |yes|
86  field | phase field to interrogate | yes |
87  patches | patches from which the liquid core is identified | yes|
88  threshold | phase fraction applied to delimit regions | yes |
89  fields | fields to sample | yes |
90  nBins | number of bins for histogram | yes |
91  maxDiameter | maximum region equivalent diameter | yes |
92  minDiameter | minimum region equivalent diameter | no | 0
93  setFormat | writing format | yes |
94  coordinateSystem | transformation for vector fields | no |
95  log | Log to standard output | no | yes
96  \endtable
97 
98 SeeAlso
99  Foam::functionObject
100  Foam::OutputFilterFunctionObject
101 
102 SourceFiles
103  regionSizeDistribution.C
104 
105 \*---------------------------------------------------------------------------*/
106 
107 #ifndef regionSizeDistribution_H
108 #define regionSizeDistribution_H
109 
110 #include "functionObjectFile.H"
111 #include "pointFieldFwd.H"
112 #include "writer.H"
113 #include "Map.H"
114 #include "volFieldsFwd.H"
115 #include "wordReList.H"
116 #include "coordinateSystem.H"
117 #include "Switch.H"
118 
119 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
120 
121 namespace Foam
122 {
123 
124 // Forward declaration of classes
125 class objectRegistry;
126 class dictionary;
127 class mapPolyMesh;
128 class regionSplit;
129 class polyMesh;
130 
131 /*---------------------------------------------------------------------------*\
132  Class regionSizeDistribution Declaration
133 \*---------------------------------------------------------------------------*/
134 
135 class regionSizeDistribution
136 :
137  public functionObjectFile
138 {
139  // Private data
140 
141  //- Name of this set of regionSizeDistribution objects
142  word name_;
143 
144  const objectRegistry& obr_;
145 
146  //- on/off switch
147  bool active_;
148 
149  //- Name of field
150  word alphaName_;
151 
152  //- Patches to walk from
154 
155  //- Switch to send output to Info as well as to file
156  Switch log_;
157 
158  //- Clip value
159  scalar threshold_;
160 
161  //- Maximum droplet diameter
162  scalar maxDiam_;
163 
164  //- Minimum droplet diameter
165  scalar minDiam_;
166 
167  //- Mumber of bins
168  label nBins_;
169 
170  //- Names of fields to sample on regions
172 
173  //- Output formatter to write
174  autoPtr<writer<scalar> > formatterPtr_;
175 
176  //- Optional coordinate system
177  autoPtr<coordinateSystem> coordSysPtr_;
178 
179 
180  // Private Member Functions
181 
182  template<class Type>
183  Map<Type> regionSum(const regionSplit&, const Field<Type>&) const;
184 
185  //- Get data in order
186  template<class Type>
187  List<Type> extractData(const UList<label>& keys, const Map<Type>&)
188  const;
189 
190  void writeGraph
191  (
192  const coordSet& coords,
193  const word& valueName,
194  const scalarField& values
195  ) const;
196 
197  //- Write volfields with the parts of alpha which are not
198  // droplets (liquidCore, backGround)
199  void writeAlphaFields
200  (
201  const regionSplit& regions,
202  const Map<label>& keepRegions,
203  const Map<scalar>& regionVolume,
204  const volScalarField& alpha
205  ) const;
206 
207  //- Mark all regions starting at patches
208  Map<label> findPatchRegions(const polyMesh&, const regionSplit&) const;
209 
210  //- Helper: divide if denom != 0
211  static tmp<scalarField> divide(const scalarField&, const scalarField&);
212 
213  //- Given per-region data calculate per-bin average/deviation and graph
214  void writeGraphs
215  (
216  const word& fieldName, // name of field
217  const labelList& indices, // index of bin for each region
218  const scalarField& sortedField, // per region field data
219  const scalarField& binCount, // per bin number of regions
220  const coordSet& coords // graph data for bins
221  ) const;
222 
223  //- Given per-cell data calculate per-bin average/deviation and graph
225  (
226  const word& fieldName, // name of field
227  const scalarField& cellField, // per cell field data
228 
229  const regionSplit& regions, // per cell the region(=droplet)
230  const labelList& sortedRegions, // valid regions in sorted order
231  const scalarField& sortedNormalisation,
232 
233  const labelList& indices, // index of bin for each region
234  const scalarField& binCount, // per bin number of regions
235  const coordSet& coords // graph data for bins
236  ) const;
237 
238  //- Disallow default bitwise copy construct
240 
241  //- Disallow default bitwise assignment
242  void operator=(const regionSizeDistribution&);
243 
244 
245 public:
246 
247  //- Runtime type information
248  TypeName("regionSizeDistribution");
249 
250 
251  // Constructors
252 
253  //- Construct for given objectRegistry and dictionary.
254  // Allow the possibility to load fields from files
256  (
257  const word& name,
258  const objectRegistry&,
259  const dictionary&,
260  const bool loadFromFiles = false
261  );
262 
263 
264  // Destructor
265 
266  virtual ~regionSizeDistribution();
267 
268 
269  // Member Functions
270 
271  //- Return name of the set of regionSizeDistribution
272  virtual const word& name() const
273  {
274  return name_;
275  }
276 
277  //- Read the regionSizeDistribution data
278  virtual void read(const dictionary&);
279 
280  //- Execute, currently does nothing
281  virtual void execute();
282 
283  //- Execute at the final time-loop, currently does nothing
284  virtual void end();
285 
286  //- Called when time was set at the end of the Time::operator++
287  virtual void timeSet();
288 
289  //- Calculate the regionSizeDistribution and write
290  virtual void write();
291 
292  //- Update for changes of mesh
293  virtual void updateMesh(const mapPolyMesh&)
294  {}
295 
296  //- Update for changes of mesh
297  virtual void movePoints(const polyMesh&)
298  {}
299 };
300 
301 
302 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
303 
304 } // End namespace Foam
305 
306 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
307 
308 #ifdef NoRepository
310 #endif
311 
312 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
313 
314 #endif
315 
316 // ************************************************************************* //
Foam::regionSizeDistribution::findPatchRegions
Map< label > findPatchRegions(const polyMesh &, const regionSplit &) const
Mark all regions starting at patches.
Definition: regionSizeDistribution.C:174
volFieldsFwd.H
Foam::regionSizeDistribution::regionSizeDistribution
regionSizeDistribution(const regionSizeDistribution &)
Disallow default bitwise copy construct.
Foam::Switch
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Definition: Switch.H:60
Foam::regionSizeDistribution::regionSum
Map< Type > regionSum(const regionSplit &, const Field< Type > &) const
Foam::regionSizeDistribution::threshold_
scalar threshold_
Clip value.
Definition: regionSizeDistribution.H:218
Foam::regionSizeDistribution::divide
static tmp< scalarField > divide(const scalarField &, const scalarField &)
Helper: divide if denom != 0.
Definition: regionSizeDistribution.C:220
Foam::regionSizeDistribution::obr_
const objectRegistry & obr_
Definition: regionSizeDistribution.H:203
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::regionSizeDistribution::coordSysPtr_
autoPtr< coordinateSystem > coordSysPtr_
Optional coordinate system.
Definition: regionSizeDistribution.H:236
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:118
Foam::constant::atomic::alpha
const dimensionedScalar alpha
Fine-structure constant: default SI units: [].
Definition: readThermalProperties.H:216
Foam::regionSizeDistribution::name_
word name_
Name of this set of regionSizeDistribution objects.
Definition: regionSizeDistribution.H:201
Foam::regionSizeDistribution::writeGraphs
void writeGraphs(const word &fieldName, const labelList &indices, const scalarField &sortedField, const scalarField &binCount, const coordSet &coords) const
Given per-region data calculate per-bin average/deviation and graph.
Definition: regionSizeDistribution.C:244
Foam::wordReList
List< wordRe > wordReList
A List of wordRe (word or regular expression)
Definition: wordReList.H:50
Foam::Map
A HashTable to objects of type <T> with a label key.
Definition: PrimitivePatchTemplate.H:68
Foam::regionSizeDistribution::timeSet
virtual void timeSet()
Called when time was set at the end of the Time::operator++.
Definition: regionSizeDistribution.C:407
Foam::regionSizeDistribution::~regionSizeDistribution
virtual ~regionSizeDistribution()
Definition: regionSizeDistribution.C:357
coordinateSystem.H
Foam::regionSizeDistribution::writeAlphaFields
void writeAlphaFields(const regionSplit &regions, const Map< label > &keepRegions, const Map< scalar > &regionVolume, const volScalarField &alpha) const
Write volfields with the parts of alpha which are not.
Definition: regionSizeDistribution.C:86
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Foam::regionSizeDistribution::nBins_
label nBins_
Mumber of bins.
Definition: regionSizeDistribution.H:227
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:50
Foam::regionSizeDistribution::operator=
void operator=(const regionSizeDistribution &)
Disallow default bitwise assignment.
Foam::regionSizeDistribution::execute
virtual void execute()
Execute, currently does nothing.
Definition: regionSizeDistribution.C:395
Foam::regionSizeDistribution::TypeName
TypeName("regionSizeDistribution")
Runtime type information.
Map.H
Foam::label
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
Foam::Field< Type >
regionSizeDistributionTemplates.C
Foam::regionSizeDistribution::updateMesh
virtual void updateMesh(const mapPolyMesh &)
Update for changes of mesh.
Definition: regionSizeDistribution.H:352
pointFieldFwd.H
Switch.H
Foam::regionSizeDistribution::formatterPtr_
autoPtr< writer< scalar > > formatterPtr_
Output formatter to write.
Definition: regionSizeDistribution.H:233
Foam::regionSplit
This class separates the mesh into distinct unconnected regions, each of which is then given a label ...
Definition: regionSplit.H:119
Foam::regionSizeDistribution::movePoints
virtual void movePoints(const polyMesh &)
Update for changes of mesh.
Definition: regionSizeDistribution.H:356
Foam::regionSizeDistribution::patchNames_
wordReList patchNames_
Patches to walk from.
Definition: regionSizeDistribution.H:212
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam::regionSizeDistribution::fields_
wordReList fields_
Names of fields to sample on regions.
Definition: regionSizeDistribution.H:230
Foam::coordSet
Holds list of sampling positions.
Definition: coordSet.H:49
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::regionSizeDistribution::end
virtual void end()
Execute at the final time-loop, currently does nothing.
Definition: regionSizeDistribution.C:401
Foam::regionSizeDistribution::name
virtual const word & name() const
Return name of the set of regionSizeDistribution.
Definition: regionSizeDistribution.H:331
Foam::regionSizeDistribution::active_
bool active_
on/off switch
Definition: regionSizeDistribution.H:206
Foam::regionSizeDistribution::maxDiam_
scalar maxDiam_
Maximum droplet diameter.
Definition: regionSizeDistribution.H:221
Foam::autoPtr
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117
functionObjectFile.H
wordReList.H
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::functionObjectFile
Base class for output file data handling.
Definition: functionObjectFile.H:57
Foam::regionSizeDistribution::read
virtual void read(const dictionary &)
Read the regionSizeDistribution data.
Definition: regionSizeDistribution.C:363
Foam::UList
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:60
Foam::regionSizeDistribution::minDiam_
scalar minDiam_
Minimum droplet diameter.
Definition: regionSizeDistribution.H:224
Foam::mapPolyMesh
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:158
List
Definition: Test.C:19
Foam::regionSizeDistribution::alphaName_
word alphaName_
Name of field.
Definition: regionSizeDistribution.H:209
writer.H
Foam::regionSizeDistribution::write
virtual void write()
Calculate the regionSizeDistribution and write.
Definition: regionSizeDistribution.C:413
Foam::regionSizeDistribution
This function object creates a size distribution via interrogating a continuous phase fraction field.
Definition: regionSizeDistribution.H:194
Foam::GeometricField
Generic GeometricField class.
Definition: surfaceFieldsFwd.H:52
Foam::regionSizeDistribution::log_
Switch log_
Switch to send output to Info as well as to file.
Definition: regionSizeDistribution.H:215
Foam::regionSizeDistribution::writeGraph
void writeGraph(const coordSet &coords, const word &valueName, const scalarField &values) const
Definition: regionSizeDistribution.C:62
Foam::regionSizeDistribution::extractData
List< Type > extractData(const UList< label > &keys, const Map< Type > &) const
Get data in order.