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) 2017-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  Passive particle, transferring in old format (i.e. position instead of
31  coordinates). Used for e.g. redistributePar.
32 
33 SourceFiles
34  passivePositionParticle.H
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef Foam_passivePositionParticle_H
39 #define Foam_passivePositionParticle_H
40 
41 #include "passiveParticle.H"
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
45 namespace Foam
46 {
47 
48 // Forward Declarations
49 class passivePositionParticle;
50 Ostream& operator<<(Ostream& os, const passivePositionParticle& ppi);
51 
52 /*---------------------------------------------------------------------------*\
53  Class passivePositionParticle Declaration
54 \*---------------------------------------------------------------------------*/
55 
56 class passivePositionParticle
57 :
58  public passiveParticle
59 {
60  // Private Member Data
61 
62  //- Cached position
63  point cachedPosition_;
64 
65 
66 public:
67 
68  // Constructors
69 
70  //- Construct from Istream in old format
72  (
73  const polyMesh& mesh,
74  Istream& is,
75  bool readFields,
76  bool newFormat
77  )
78  :
79  passiveParticle(mesh, is, readFields, newFormat),
80  cachedPosition_(position())
81  {}
82 
83  //- Construct from a position and a cell.
84  // Searches for the rest of the required topology.
86  (
87  const polyMesh& mesh,
88  const vector& position,
89  const label celli = -1
90  )
91  :
92  passiveParticle(mesh, position, celli),
93  cachedPosition_(position)
94  {}
95 
96  //- Construct as copy
98  :
100  cachedPosition_(p.cachedPosition_)
101  {}
102 
103  //- Construct and return a clone
104  virtual autoPtr<particle> clone() const
105  {
106  return autoPtr<particle>(new passivePositionParticle(*this));
107  }
108 
109 
110  //- Factory class to read-construct particles (for parallel transfer)
111  class iNew
112  {
113  const polyMesh& mesh_;
114 
115  public:
116 
117  iNew(const polyMesh& mesh)
118  :
119  mesh_(mesh)
120  {}
121 
123  {
125  (
126  // Read in old format
127  new passivePositionParticle(mesh_, is, true, false)
128  );
129  }
130  };
131 
132 
133  // Member Functions
134 
135  const point& cachedPosition() const noexcept
136  {
137  return cachedPosition_;
138  }
139 
140 
141  // Friend Operators
142 
143  friend Ostream& operator<<
144  (
145  Ostream& os,
146  const passivePositionParticle& ppi
147  )
148  {
149  // Copy data into old format structure. Exact opposite of
150  // particleIO.C reading old format.
153  p.position = ppi.cachedPosition_;
154  p.celli = ppi.cell();
155  p.facei = ppi.face();
156  p.stepFraction = ppi.stepFraction();
157  p.tetFacei = ppi.tetFace();
158  p.tetPti = ppi.tetPt();
159  p.origProc = ppi.origProc();
160  p.origId = ppi.origId();
161 
162  if (os.format() == IOstreamOption::ASCII)
163  {
164  os << p.position
165  << token::SPACE << p.celli
166  << token::SPACE << p.facei
167  << token::SPACE << p.stepFraction
168  << token::SPACE << p.tetFacei
169  << token::SPACE << p.tetPti
170  << token::SPACE << p.origProc
171  << token::SPACE << p.origId;
172  }
173  else
174  {
175  const std::size_t sizeofFields
176  (
177  sizeof(particle::positionsCompat1706)
178  - offsetof(particle::positionsCompat1706, position)
179  );
180 
181  os.write
182  (
183  reinterpret_cast<const char*>(&p.position),
184  sizeofFields
185  );
186  }
187  return os;
188  }
189 };
190 
191 
192 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
193 
194 } // End namespace Foam
195 
196 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
197 
198 #endif
199 
200 // ************************************************************************* //
passivePositionParticle(const polyMesh &mesh, const barycentric &coordinates, const label celli, const label tetFacei, const label tetPti)
Construct from components (known location)
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
"ascii" (normal default)
Old particle positions content for OpenFOAM-1706 and earlier.
Definition: particle.H:122
autoPtr< passivePositionParticle > operator()(Istream &is) const
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)
virtual autoPtr< particle > clone() const
Construct and return a clone.
const point & cachedPosition() const noexcept
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:77
const polyMesh & mesh() const noexcept
Return the mesh database.
Definition: particleI.H:110
vector point
Point is a vector.
Definition: point.H:37
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
Factory class to read-construct particles (for parallel transfer)
Copy of base particle.
vector position() const
Return current particle position.
Definition: particleI.H:283
Copy of base particle but without particle locating and preserving read location. ...
Namespace for OpenFOAM.