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-------------------------------------------------------------------------------
10License
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
26Class
27 Foam::passivePositionParticle
28
29Description
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
36SourceFiles
37 passivePositionParticle.H
38
39\*---------------------------------------------------------------------------*/
40
41#ifndef passivePositionParticle_H
42#define passivePositionParticle_H
43
44#include "particle.H"
45#include "IOstream.H"
46#include "autoPtr.H"
47
48// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49
50namespace Foam
51{
52
53/*---------------------------------------------------------------------------*\
54 Class passivePositionParticle Declaration
55\*---------------------------------------------------------------------------*/
58:
59 public particle
60{
61 // Private Data
62
63 //- Raw location
64 point location_;
65
66
67public:
68
69 // Constructors
70
71 //- Construct from components (known location)
73 (
74 const polyMesh& mesh,
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
86 //- Construct from components (supplied location)
88 (
89 const polyMesh& mesh,
91 const label celli,
92 const label tetFacei,
93 const label tetPti,
94 const vector& position
95 )
96 :
97 particle(mesh, coordinates, celli, tetFacei, tetPti),
98 location_(position)
99 {}
100
101
102 //- Construct from Istream
104 (
105 const polyMesh& mesh,
106 Istream& is,
107 const bool readFields = true,
108 const bool newFormat = true
109 )
110 :
111 //particle(mesh, is, readFields, newFormat)
113 (
114 mesh,
115 Zero, // position
116 -1, // celli
117 -1, // tetFacei
118 -1, // tetPti
119 false // doLocate
120 )
121 {
123 (
124 is,
125 location_,
127 newFormat,
128 false //doLocate
129 );
130 }
131
132
133 //- Construct as copy
135 :
136 particle(p)
137 {}
138
139
140 //- Construct and return a clone
141 virtual autoPtr<particle> clone() const
142 {
144 }
145
146
147 //- Factory class to read-construct particles (for parallel transfer)
148 class iNew
149 {
150 const polyMesh& mesh_;
151
152 public:
154 iNew(const polyMesh& mesh)
155 :
156 mesh_(mesh)
157 {}
160 {
161 return autoPtr<passivePositionParticle>::New(mesh_, is, true);
162 }
163 };
164
165
166 // Member Functions
167
168 //- Return current particle position
169 inline const point& location() const
170 {
171 return location_;
172 }
173
174 //- Write the particle position and cell id
175 virtual void writePosition(Ostream& os) const
176 {
177 // Use cached location() instead of calculated position()
178 if (os.format() == IOstream::ASCII)
179 {
180 os << location() << token::SPACE << cell();
181 }
182 else
183 {
185
186 const size_t s =
187 (
188 offsetof(positionsCompat1706, facei)
189 - offsetof(positionsCompat1706, position)
190 );
191
192 p.position = location();
193 p.celli = cell();
194
195 os.write(reinterpret_cast<const char*>(&p.position), s);
196 }
197
198 // Check state of Ostream
200 }
201};
202
203
204// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
205
206} // End namespace Foam
207
208// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
209
210#endif
211
212// ************************************************************************* //
streamFormat format() const noexcept
Get the current stream format.
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:58
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
virtual Ostream & write(const char c)
Write character.
Definition: OBJstream.C:78
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
Definition: Time.C:717
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
Base particle class.
Definition: particle.H:79
vector position() const
Return current particle position.
Definition: particleI.H:314
static void readFields(TrackCloudType &c)
Read the fields associated with the owner cloud.
const polyMesh & mesh() const noexcept
Return the mesh database.
Definition: particleI.H:137
const barycentric & coordinates() const noexcept
Return current particle coordinates.
Definition: particleI.H:143
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:76
label cell() const noexcept
Return current cell particle is in.
Definition: particleI.H:149
Factory class to read-construct particles (for parallel transfer)
autoPtr< passivePositionParticle > operator()(Istream &is) const
Copy of base particle but without particle locating and preserving read location.
passivePositionParticle(const polyMesh &mesh, const barycentric &coordinates, const label celli, const label tetFacei, const label tetPti)
Construct from components (known location)
passivePositionParticle(const polyMesh &mesh, Istream &is, const bool readFields=true, const bool newFormat=true)
Construct from Istream.
virtual autoPtr< particle > clone() const
Construct and return a clone.
passivePositionParticle(const polyMesh &mesh, const barycentric &coordinates, const label celli, const label tetFacei, const label tetPti, const vector &position)
Construct from components (supplied location)
passivePositionParticle(const passivePositionParticle &p)
Construct as copy.
const point & location() const
Return current particle position.
virtual void writePosition(Ostream &os) const
Write the particle position and cell id.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
@ SPACE
Space [isspace].
Definition: token.H:125
volScalarField & p
OBJstream os(runTime.globalPath()/outputName)
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))
#define FUNCTION_NAME
Namespace for OpenFOAM.
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Old particle positions content for OpenFOAM-1706 and earlier.
Definition: particle.H:117