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-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::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 #include "autoPtr.H"
47 
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 
50 namespace Foam
51 {
52 
53 /*---------------------------------------------------------------------------*\
54  Class passivePositionParticle Declaration
55 \*---------------------------------------------------------------------------*/
56 
58 :
59  public particle
60 {
61  // Private Data
62 
63  //- Raw location
64  point location_;
65 
66 
67 public:
68 
69  // Constructors
70 
71  //- Construct from components (known location)
73  (
74  const polyMesh& mesh,
75  const barycentric& coordinates,
76  const label celli,
77  const label tetFacei,
78  const label tetPti
79  )
80  :
81  particle(mesh, coordinates, celli, tetFacei, tetPti),
82  location_(position())
83  {}
84 
85  //- Construct from components (supplied location)
87  (
88  const polyMesh& mesh,
89  const barycentric& coordinates,
90  const label celli,
91  const label tetFacei,
92  const label tetPti,
93  const vector& position
94  )
95  :
96  particle(mesh, coordinates, celli, tetFacei, tetPti),
97  location_(position)
98  {}
99 
100  //- Construct from Istream
102  (
103  const polyMesh& mesh,
104  Istream& is,
105  const bool readFields = true,
106  const bool newFormat = true
107  )
108  :
109  //particle(mesh, is, readFields, newFormat)
110  particle
111  (
112  mesh,
113  Zero, // position
114  -1, // celli
115  -1, // tetFacei
116  -1, // tetPti
117  false // doLocate
118  )
119  {
120  readData
121  (
122  is,
123  location_,
124  readFields,
125  newFormat,
126  false //doLocate
127  );
128  }
129 
130 
131  //- Construct as copy
133  :
134  particle(p)
135  {}
136 
138  //- Construct and return a clone
139  virtual autoPtr<particle> clone() const
140  {
141  return autoPtr<particle>(new passivePositionParticle(*this));
142  }
143 
144 
145  //- Factory class to read-construct particles (for parallel transfer)
146  class iNew
147  {
148  const polyMesh& mesh_;
149 
150  public:
151 
152  iNew(const polyMesh& mesh)
153  :
154  mesh_(mesh)
155  {}
156 
158  {
159  return autoPtr<passivePositionParticle>::New(mesh_, is, true);
160  }
161  };
162 
163 
164  // Member Functions
165 
166  //- The cached particle position
167  const point& location() const noexcept
168  {
169  return location_;
170  }
171 
172  //- Write the particle position and cell id
173  // Uses cached location() instead of calculated position()
174  virtual void writePosition(Ostream& os) const
175  {
176  if (os.format() == IOstreamOption::ASCII)
177  {
178  os << location() << token::SPACE << cell();
179  }
180  else
181  {
182  positionsCompat1706 p;
183 
184  const size_t s =
185  (
186  offsetof(positionsCompat1706, facei)
187  - offsetof(positionsCompat1706, position)
188  );
189 
190  p.position = location();
191  p.celli = cell();
192 
193  os.write(reinterpret_cast<const char*>(&p.position), s);
194  }
195 
196  // Check state of Ostream
197  os.check(FUNCTION_NAME);
198  }
199 };
200 
201 
202 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
203 
204 } // End namespace Foam
205 
206 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
207 
208 #endif
209 
210 // ************************************************************************* //
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
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
Construct and 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:74
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))
Factory class to read-construct particles (for parallel transfer)
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