cloudSurfaceDistribution.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) 2025 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::cloudSurfaceDistribution
26 
27 Description
28  Function to generate a plot of the distribution of the values of particles
29  that pass through a face-zone, face-set or patch
30 
31 Usage
32  \table
33  Property | Description | Required? | Default
34  cloud | Name of the cloud | yes |
35  select | The type of face selection; \
36  faceZone, faceSet or patch | if none or multiple \
37  selections specified |
38  faceZone | The face zone for which the \
39  PDF is calculated | if select is faceZone |
40  faceSet | The face set for which the \
41  PDF is calculated | if select is faceSet |
42  patch | The patch for which the \
43  PDF is calculated | is select is patch |
44  field | Field to operate on | if fields not specified |
45  fields | List of fields to operate on | if field not specified |
46  weightField | Field with which to weight the distribution | no | none
47  weightFields | List of fields with which to \
48  weight the distribution | no | none
49  nBins | The number of bins used in the plot(s) | yes |
50  setFormat | Format of the plot file | yes |
51  \endtable
52 
53  Example specification to generate the diameter distribution:
54  \verbatim
55  cloudSurfaceDistribution1
56  {
57  type cloudSurfaceDistribution;
58  libs ("libLagrangianCloudFunctionObjects.so");
59  cloud cloud;
60  patch outlet;
61  field d;
62  weightField number;
63  nBins 20;
64  setFormat raw;
65  }
66  \endverbatim
67 
68 SourceFiles
69  cloudSurfaceDistribution.C
70 
71 \*---------------------------------------------------------------------------*/
72 
73 #ifndef cloudSurfaceDistribution_functionObject_H
74 #define cloudSurfaceDistribution_functionObject_H
75 
76 #include "cloudFunctionObject.H"
77 #include "setWriter.H"
78 
79 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
80 
81 namespace Foam
82 {
83 namespace functionObjects
84 {
85 
86 /*---------------------------------------------------------------------------*\
87  Class cloudSurfaceDistribution Declaration
88 \*---------------------------------------------------------------------------*/
89 
90 class cloudSurfaceDistribution
91 :
92  public LagrangianMeshFunctionObject,
93  public cloudFunctionObject
94 {
95 public:
96 
97  // Public Data Types
98 
99  //- Selection type enumeration
100  enum class selectionType
101  {
102  faceZone,
103  faceSet,
104  patch
105  };
106 
107  //- Selection type names
108  static const NamedEnum<selectionType, 3> selectionTypeNames;
109 
110 
111 private:
112 
113  // Private Data
114 
115  //- List of fields
116  wordList fields_;
117 
118  //- List of weight fields
119  wordList weightFields_;
120 
121  //- Selection type
122  selectionType selectionType_;
123 
124  //- Name of face selection
125  word selectionName_;
126 
127  //- Stored set of selected faces. Used if the selection type is faceSet.
128  labelHashSet selectionSet_;
129 
130  //- Number of bins
131  label nBins_;
132 
133  //- File writer
134  autoPtr<setWriter> formatter_;
135 
136  //- Sums for each component of each field
137  List<List<scalarField>> sums_;
138 
139  //- The ranges of each component of each field
140  List<List<Pair<scalar>>> ranges_;
141 
142  //- Total number of samples taken for each field
143  labelList nSamples_;
144 
145 
146  // Private Member Functions
147 
148  //- Read a list of field names
149  static wordList readFields
150  (
151  const dictionary& dict,
152  const word& key,
153  const wordList& defaultValue = NullObjectRef<wordList>()
154  );
155 
156  //- Read the selection type
157  selectionType readSelectionType(const dictionary& dict);
158 
159  //- Get the component names for a given field
160  const char* const* componentNames(const label fieldi) const;
161 
162  //- Non-virtual read
163  void readCoeffs(const dictionary& dict, const bool props);
164 
165  //- Return the properties dictionary IO
166  IOobject propsDictIo(const IOobject::readOption r) const;
167 
168  //- Return a list of flags to indicate which particles in the sub-mesh
169  // should be included in the PDF calculation
170  boolList selected(const LagrangianSubScalarSubField& fraction) const;
171 
172  //- Multiply the given weight field to the current weight product
173  template<template<class> class GeoField>
174  bool multiplyWeight
175  (
176  const LagrangianSubMesh& subMesh,
177  const label weightFieldi,
178  scalarField& weight
179  ) const;
180 
181  //- Add a field to its PDF
182  template<template<class> class GeoField, class Type>
183  bool addField
184  (
185  const LagrangianSubMesh& subMesh,
186  const boolList& selected,
187  const scalarField& weight,
188  const label fieldi
189  );
190 
191  //- Write the distribution of the given scalar field
192  void writeDistribution
193  (
194  const word& fieldName,
195  const word& componentName,
196  const scalarField& x,
197  const scalarField& PDF,
198  const scalarField& CDF
199  ) const;
200 
201 
202 public:
203 
204  //- Runtime type information
205  TypeName("cloudSurfaceDistribution");
206 
207 
208  // Constructors
209 
210  //- Construct from Time and dictionary
212  (
213  const word& name,
214  const Time& runTime,
215  const dictionary& dict
216  );
217 
218  //- Disallow default bitwise copy construction
220 
221 
222  //- Destructor
223  virtual ~cloudSurfaceDistribution();
224 
225 
226  // Member Functions
227 
228  //- Read parameters
229  virtual bool read(const dictionary&);
230 
231  //- Return the list of fields required
232  virtual wordList fields() const;
233 
234  //- Return false so this function does not execute at the start
235  virtual bool executeAtStart() const;
236 
237  //- Do nothing. Everything happens in faces crossing hooks.
238  virtual bool execute();
239 
240  //- Hook before face crossings of a specific sub-mesh
241  virtual void preCrossFaces
242  (
243  const LagrangianSubScalarSubField& fraction
244  );
245 
246  //- Hook following face crossings of a specific sub-mesh
247  virtual void postCrossFaces
248  (
249  const LagrangianSubScalarSubField& fraction
250  );
251 
252  //- Write the number flux
253  virtual bool write();
254 
255  //- Clear the number flux
256  virtual bool clear();
257 
258  //- Update topology using the given map
259  virtual void topoChange(const polyTopoChangeMap& map);
260 
261  //- Update from another mesh using the given map
262  virtual void mapMesh(const polyMeshMap&);
263 
264  //- Redistribute or update using the given distribution map
265  virtual void distribute(const polyDistributionMap&);
266 
267 
268  // Member Operators
269 
270  //- Disallow default bitwise assignment
271  void operator=(const cloudSurfaceDistribution&) = delete;
272 };
273 
274 
275 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
276 
277 } // End namespace functionObjects
278 } // End namespace Foam
279 
280 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
281 
282 #endif
283 
284 // ************************************************************************* //
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
readOption
Enumeration defining the read options.
Definition: IOobject.H:117
Mesh that relates to a sub-section of a Lagrangian mesh. This is used to construct fields that relate...
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.
Function to generate a plot of the distribution of the values of particles that pass through a face-z...
cloudSurfaceDistribution(const word &name, const Time &runTime, const dictionary &dict)
Construct from Time and dictionary.
void operator=(const cloudSurfaceDistribution &)=delete
Disallow default bitwise assignment.
static const NamedEnum< selectionType, 3 > selectionTypeNames
Selection type names.
virtual wordList fields() const
Return the list of fields required.
virtual bool executeAtStart() const
Return false so this function does not execute at the start.
virtual void distribute(const polyDistributionMap &)
Redistribute or update using the given distribution map.
virtual void postCrossFaces(const LagrangianSubScalarSubField &fraction)
Hook following face crossings of a specific sub-mesh.
virtual void mapMesh(const polyMeshMap &)
Update from another mesh using the given map.
TypeName("cloudSurfaceDistribution")
Runtime type information.
virtual bool execute()
Do nothing. Everything happens in faces crossing hooks.
virtual void preCrossFaces(const LagrangianSubScalarSubField &fraction)
Hook before face crossings of a specific sub-mesh.
virtual void topoChange(const polyTopoChangeMap &map)
Update topology using the given map.
virtual bool read(const dictionary &)
Read parameters.
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
Class containing mesh-to-mesh mapping information.
Definition: polyMeshMap.H:51
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
A class for handling words, derived from string.
Definition: word.H:62
Namespace for OpenFOAM.
List< word > wordList
A List of words.
Definition: fileName.H:54
List< label > labelList
A List of labels.
Definition: labelList.H:56
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
HashSet< label, Hash< label > > labelHashSet
A HashSet with label keys.
Definition: HashSet.H:213
dictionary dict