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-2019 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 passivePositionParticle_H
39 #define 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 
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  const point& cachedPosition() const
134  {
135  return cachedPosition_;
136  }
137 
138 
139  // Friend Operators
140 
141  friend Ostream& operator<<
142  (
143  Ostream& os,
144  const passivePositionParticle& ppi
145  )
146  {
147  // Copy data into old format structure. Exact opposite of
148  // particleIO.C reading old format.
150 
151  p.position = ppi.cachedPosition_;
152  p.celli = ppi.cell();
153  p.facei = ppi.face();
154  p.stepFraction = ppi.stepFraction();
155  p.tetFacei = ppi.tetFace();
156  p.tetPti = ppi.tetPt();
157  p.origProc = ppi.origProc();
158  p.origId = ppi.origId();
159 
160  if (os.format() == IOstream::ASCII)
161  {
162  os << p.position
163  << token::SPACE << p.celli
164  << token::SPACE << p.facei
165  << token::SPACE << p.stepFraction
166  << token::SPACE << p.tetFacei
167  << token::SPACE << p.tetPti
168  << token::SPACE << p.origProc
169  << token::SPACE << p.origId;
170  }
171  else
172  {
173  const std::size_t sizeofFields
174  (
177  );
178 
179  os.write
180  (
181  reinterpret_cast<const char*>(&p.position),
182  sizeofFields
183  );
184  }
185  return os;
186  }
187 };
188 
189 
190 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
191 
192 } // End namespace Foam
193 
194 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
195 
196 #endif
197 
198 // ************************************************************************* //
Foam::passivePositionParticle
Passive particle, transferring in old format (i.e. position instead of coordinates)....
Definition: passivePositionParticle.H:55
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::passivePositionParticle::iNew::iNew
iNew(const polyMesh &mesh)
Definition: passivePositionParticle.H:116
Foam::passivePositionParticle::clone
virtual autoPtr< particle > clone() const
Construct and return a clone.
Definition: passivePositionParticle.H:103
Foam::passiveParticle
Copy of base particle.
Definition: passiveParticle.H:53
Foam::particle::readFields
static void readFields(TrackCloudType &c)
Read the fields associated with the owner cloud.
Definition: particleTemplates.C:140
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::passivePositionParticle::passivePositionParticle
passivePositionParticle(const polyMesh &mesh, Istream &is, bool readFields, bool newFormat)
Construct from Istream in old format.
Definition: passivePositionParticle.H:71
Foam::passivePositionParticle::iNew
Factory class to read-construct particles (for parallel transfer)
Definition: passivePositionParticle.H:110
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::passivePositionParticle::cachedPosition
const point & cachedPosition() const
Definition: passivePositionParticle.H:132
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
passiveParticle.H
Foam::particle::position
vector position() const
Return current particle position.
Definition: particleI.H:314
Foam::particle::mesh
const polyMesh & mesh() const
Return the mesh database.
Definition: particleI.H:137
Foam::passivePositionParticle::iNew::operator()
autoPtr< passivePositionParticle > operator()(Istream &is) const
Definition: passivePositionParticle.H:121
os
OBJstream os(runTime.globalPath()/outputName)
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::passivePositionParticle::passivePositionParticle
passivePositionParticle(const passivePositionParticle &p)
Construct as copy.
Definition: passivePositionParticle.H:96
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::particle::positionsCompat1706
Old particle positions content for OpenFOAM-1706 and earlier.
Definition: particle.H:116
Foam::IOstreamOption::ASCII
"ascii" (normal default)
Definition: IOstreamOption.H:72
Foam::Vector< scalar >
Foam::token::SPACE
Space [isspace].
Definition: token.H:125
Foam::passiveParticle::passiveParticle
passiveParticle(const polyMesh &mesh, const barycentric &coordinates, const label celli, const label tetFacei, const label tetPti)
Construct from components.
Definition: passiveParticle.H:64
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56