passivePositionParticle.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) 2021-2024 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::passivePositionParticle
28 
29 Description
30  Copy of base particle but without particle locating and preserving
31  read location.
32 
33  Used in reconstructing lagrangian positions generated outside the
34  mesh domain (can happen in extractEulerianParticles functionObject)
35 
36 SourceFiles
37  passivePositionParticle.H
38 
39 \*---------------------------------------------------------------------------*/
40 
41 #ifndef Foam_passivePositionParticle_H
42 #define Foam_passivePositionParticle_H
43 
44 #include "particle.H"
45 #include "IOstream.H"
46 
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 
49 namespace Foam
50 {
51 
52 /*---------------------------------------------------------------------------*\
53  Class passivePositionParticle Declaration
54 \*---------------------------------------------------------------------------*/
55 
57 :
58  public particle
59 {
60  // Private Data
61 
62  //- Raw location
63  point location_;
64 
65 
66 public:
67 
68  // Constructors
69 
70  //- Construct from components (known location)
72  (
73  const polyMesh& mesh,
74  const barycentric& coordinates,
75  const label celli,
76  const label tetFacei,
77  const label tetPti
78  )
79  :
80  particle(mesh, coordinates, celli, tetFacei, tetPti),
81  location_(position())
82  {}
83 
84  //- Construct from components (supplied location)
86  (
87  const polyMesh& mesh,
88  const barycentric& coordinates,
89  const label celli,
90  const label tetFacei,
91  const label tetPti,
92  const vector& position
93  )
94  :
95  particle(mesh, coordinates, celli, tetFacei, tetPti),
96  location_(position)
97  {}
98 
99  //- Construct from Istream
101  (
102  const polyMesh& mesh,
103  Istream& is,
104  const bool readFields = true,
105  const bool newFormat = true
106  )
107  :
108  //particle(mesh, is, readFields, newFormat)
109  particle
110  (
111  mesh,
112  Zero, // position
113  -1, // celli
114  -1, // tetFacei
115  -1, // tetPti
116  false // doLocate
117  )
118  {
119  readData
120  (
121  is,
122  location_,
123  readFields,
124  newFormat,
125  false //doLocate
126  );
127  }
128 
129 
130  //- Construct as copy
132  :
133  particle(p),
134  location_(p.location_)
135  {}
137 
138  //- Return a clone
139  virtual autoPtr<particle> clone() const
140  {
141  return particle::Clone(*this);
142  }
143 
144  //- Factory class to read-construct particles (for parallel transfer)
145  class iNew
146  {
147  const polyMesh& mesh_;
148 
149  public:
150 
151  iNew(const polyMesh& mesh)
152  :
153  mesh_(mesh)
154  {}
155 
157  {
158  return autoPtr<passivePositionParticle>::New(mesh_, is, true);
159  }
160  };
161 
162 
163  // Member Functions
164 
165  //- The cached particle position
166  const point& location() const noexcept
167  {
168  return location_;
169  }
170 
171  //- Write the particle position and cell id
172  // Uses cached location() instead of calculated position()
173  virtual void writePosition(Ostream& os) const
174  {
175  if (os.format() == IOstreamOption::ASCII)
176  {
177  os << location() << token::SPACE << cell();
178  }
179  else
180  {
181  positionsCompat1706 p;
182 
183  const size_t s =
184  (
185  offsetof(positionsCompat1706, facei)
186  - offsetof(positionsCompat1706, position)
187  );
188 
189  p.position = location();
190  p.celli = cell();
191 
192  os.write(reinterpret_cast<const char*>(&p.position), s);
193  }
194 
195  // Check state of Ostream
196  os.check(FUNCTION_NAME);
197  }
198 };
199 
200 
201 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
202 
203 } // End namespace Foam
204 
205 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
206 
207 #endif
208 
209 // ************************************************************************* //
passivePositionParticle(const polyMesh &mesh, const barycentric &coordinates, const label celli, const label tetFacei, const label tetPti)
Construct from components (known location)
const barycentric & coordinates() const noexcept
Return current particle coordinates.
Definition: particleI.H:116
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
"ascii" (normal default)
Base particle class.
Definition: particle.H:69
autoPtr< passivePositionParticle > operator()(Istream &is) const
void readData(Istream &is, point &position, const bool readFields, const bool newFormat, const bool doLocate)
Read particle from stream. Optionally (for old format) return.
Definition: particleIO.C:69
const point & location() const noexcept
The cached particle position.
Space [isspace].
Definition: token.H:131
static autoPtr< particle > Clone(const Derived &p)
Clone a particle.
Definition: particle.H:552
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
const direction noexcept
Definition: Scalar.H:258
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
OBJstream os(runTime.globalPath()/outputName)
#define FUNCTION_NAME
virtual autoPtr< particle > clone() const
Return a clone.
label cell() const noexcept
Return current cell particle is in.
Definition: particleI.H:122
const polyMesh & mesh() const noexcept
Return the mesh database.
Definition: particleI.H:110
static void readFields(TrackCloudType &c)
Read the fields associated with the owner cloud.
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:75
volScalarField & p
static autoPtr< T > New(Args &&... args)
Construct autoPtr with forwarding arguments.
Definition: autoPtr.H:178
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
vector position() const
Return current particle position.
Definition: particleI.H:283
Copy of base particle but without particle locating and preserving read location. ...
virtual void writePosition(Ostream &os) const
Write the particle position and cell id.
Namespace for OpenFOAM.
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127