ParticleZoneInfo.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2022 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
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 Class
27  Foam::ParticleZoneInfo
28 
29 Group
30  grpLagrangianIntermediateFunctionObjects
31 
32 Description
33  Reports cloud information for particles passing through a specified cell
34  zone.
35 
36 Usage
37  Example usage:
38  \verbatim
39  cloudFunctions
40  {
41  particleZoneInfo1
42  {
43  // Mandatory entries
44  type particleZoneInfo;
45  cellZone leftFluid;
46 
47  // Optional entries
48  writer vtk;
49  }
50  }
51  \endverbatim
52 
53  Results are written to file:
54  - <case>/postProcessing/lagrangian/<cloudName>/<functionName>/<time>
55 
56  \verbatim
57  # cellZone : leftFluid
58  # time : 1.0000000000e+00
59  #
60  # origID origProc (x y z) time0 age d0 d mass0 mass
61  \endverbatim
62 
63  Where
64  - origID : particle ID
65  - origProc : processor ID
66  - (x y z) : Cartesian co-ordinates
67  - time0 : time particle enters the cellZone
68  - age : time spent in the cellZone
69  - d0 : diameter on entry to the cellZone
70  - d : current diameter
71  - mass0 : mass on entry to the cellZone
72  - mass : current mass
73 
74  If the optional \c writer entry is supplied, cloud data is written in the
75  specified format.
76 
77  During the run, output statistics are reported after the cloud solution,
78  e.g.:
79 
80  \verbatim
81  particleZoneInfo:
82  Cell zone = leftFluid
83  Contributions = 257
84  \endverbatim
85 
86  Here, 'Contributions' refers to the number of incremental particle-move
87  contributions recorded during this time step. At write times, the output
88  is extended, e.g.:
89 
90  \verbatim
91  particleZoneInfo:
92  Cell zone = leftFluid
93  Contributions = 822
94  Number of particles = 199
95  Written data to "postProcessing/lagrangian/reactingCloud1/
96  \endverbatim
97 
98 SourceFiles
99  ParticleZoneInfo.C
100 
101 \*---------------------------------------------------------------------------*/
102 
103 #ifndef ParticleZoneInfo_H
104 #define ParticleZoneInfo_H
105 
106 #include "CloudFunctionObject.H"
107 #include "writeFile.H"
108 #include "coordSetWriter.H"
109 
110 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
111 
112 namespace Foam
113 {
115 /*---------------------------------------------------------------------------*\
116  struct particleInfo Declaration
117 \*---------------------------------------------------------------------------*/
120 {
121  label origID = -1;
122  label origProc = -1;
124  scalar time0 = 0;
125  scalar age = 0;
126  scalar d0 = 0;
127  scalar d = 0;
128  scalar mass0 = 0;
129  scalar mass = 0;
130 
131  void operator+=(const particleInfo& p)
132  {
133  // Increment age
134  age += p.age;
135 
136  // Set current values
137  position = p.position;
138  d = p.d;
139  mass = p.mass;
140  }
141 
142  scalar isOlderThan(const particleInfo& p) const
143  {
144  // Cannot just use time0 - particle may leave/re-enter and
145  // so age is decoupled
146  return (p.time0 + p.age) < (time0 + age);
147  }
148 
149  friend bool operator==(const particleInfo& a, const particleInfo& b)
150  {
151  return
152  a.origID == b.origID
153  && a.origProc == b.origProc
154  && a.position == b.position
155  && a.time0 == b.time0
156  && a.age == b.age
157  && a.d0 == b.d0
158  && a.d == b.d
159  && a.mass0 == b.mass0
160  && a.mass == b.mass;
161  }
162 
163  friend bool operator!=(const particleInfo& a, const particleInfo& b)
164  {
165  return !(a == b);
166  }
167 
168 
169 // IOstream Operators
170 
171  friend Istream& operator>>(Istream& is, particleInfo& pi)
172  {
173  is >> pi.origID
174  >> pi.origProc
175  >> pi.position
176  >> pi.time0
177  >> pi.age
178  >> pi.d0
179  >> pi.d
180  >> pi.mass0
181  >> pi.mass;
182 
183  return is;
184  }
185 
186  friend Ostream& operator<<(Ostream& os, const particleInfo& pi)
187  {
188  os << pi.origID
189  << " " << pi.origProc
190  << " " << pi.position
191  << " " << pi.time0
192  << " " << pi.age
193  << " " << pi.d0
194  << " " << pi.d
195  << " " << pi.mass0
196  << " " << pi.mass;
197 
198  return os;
199  }
200 };
201 
202 /*---------------------------------------------------------------------------*\
203  Class ParticleZoneInfo Declaration
204 \*---------------------------------------------------------------------------*/
205 
206 template<class CloudType>
207 class ParticleZoneInfo
208 :
209  public CloudFunctionObject<CloudType>,
211 
212 {
213  // Private Data
214 
215  // Typedefs
216 
217  //- Convenience typedef for parcel type
218  typedef typename CloudType::parcelType parcelType;
219 
220 
221  //- Cell zone name
222  word cellZoneName_;
223 
224  //- Cell zone index
225  label cellZoneId_;
226 
227  //- Stored data
229 
230  //- Work storage
231  DynamicList<particleInfo> movedParticles_;
232 
233  //- Maximum particle ID per processor
234  labelList maxIDs_;
235 
236  //- Set writer
237  autoPtr<coordSetWriter> writerPtr_;
238 
239 
240  // Private Member Functions
241 
242  //- Write output file header
243  void writeFileHeader(Ostream& os) const;
244 
245  //- Return true if celli is in the cellZone
246  bool inZone(const label celli) const;
247 
248  //- Return the index of the particle in the storage (data_)
249  //- Returns -1 if not found
250  label getParticleID(const particleInfo& p) const;
251 
252  //- Write fields using writerPtr_
253  void writeWriter(const UList<particleInfo>& data);
254 
255 
256 public:
257 
258  //- Runtime type information
259  TypeName("particleZoneInfo");
260 
261 
262  // Constructors
263 
264  //- Construct from dictionary
266  (
267  const dictionary& dict,
268  CloudType& owner,
269  const word& modelName
270  );
271 
272  //- Construct copy
274 
275  //- Construct and return a clone
277  {
279  (
280  new ParticleZoneInfo<CloudType>(*this)
281  );
282  }
283 
284 
285  //- Destructor
286  virtual ~ParticleZoneInfo() = default;
287 
288 
289  // Member Functions
290 
291  //- Pre-evolve hook
292  virtual void preEvolve
293  (
294  const typename parcelType::trackingData& td
295  );
296 
297  //- Post-evolve hook
298  virtual void postEvolve
299  (
300  const typename parcelType::trackingData& td
301  );
302 
303  //- Post-move hook
304  virtual bool postMove
305  (
306  parcelType& p,
307  const scalar dt,
308  const point& position0,
309  const typename parcelType::trackingData& td
310  );
311 
312  //- Write
313  virtual void write();
314 };
315 
316 
317 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
318 
319 } // End namespace Foam
320 
321 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
322 
323 #ifdef NoRepository
324  #include "ParticleZoneInfo.C"
325 #endif
326 
327 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
328 
329 #endif
330 
331 // ************************************************************************* //
friend bool operator==(const particleInfo &a, const particleInfo &b)
virtual ~ParticleZoneInfo()=default
Destructor.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
TypeName("particleZoneInfo")
Runtime type information.
ParticleZoneInfo(const dictionary &dict, CloudType &owner, const word &modelName)
Construct from dictionary.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
friend Ostream & operator<<(Ostream &os, const particleInfo &pi)
friend bool operator!=(const particleInfo &a, const particleInfo &b)
const word & modelName() const
Return const access to the name of the sub-model.
Definition: subModelBase.C:98
const dictionary & dict() const
Return const access to the cloud dictionary.
Definition: subModelBase.C:104
virtual void postEvolve(const typename parcelType::trackingData &td)
Post-evolve hook.
virtual autoPtr< CloudFunctionObject< CloudType > > clone() const
Construct and return a clone.
const CloudType & owner() const
Return const access to the owner cloud.
virtual void preEvolve(const typename parcelType::trackingData &td)
Pre-evolve hook.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:51
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:27
A class for handling words, derived from Foam::string.
Definition: word.H:63
virtual void write()
Write.
scalar isOlderThan(const particleInfo &p) const
constexpr scalar pi(M_PI)
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:105
ParcelType parcelType
Type of parcel the cloud was instantiated for.
Definition: DSMCCloud.H:290
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
virtual bool postMove(parcelType &p, const scalar dt, const point &position0, const typename parcelType::trackingData &td)
Post-move hook.
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
OBJstream os(runTime.globalPath()/outputName)
Reports cloud information for particles passing through a specified cell zone.
void operator+=(const particleInfo &p)
friend Istream & operator>>(Istream &is, particleInfo &pi)
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
volScalarField & p
Base class for writing single files from the function objects.
Definition: writeFile.H:112
Templated base class for dsmc cloud.
Definition: DSMCCloud.H:67
Templated cloud function object base class.
Namespace for OpenFOAM.
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127