Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
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 Foam_passivePositionParticle_H
42#define Foam_passivePositionParticle_H
43
44#include "particle.H"
45#include "IOstream.H"
46
47// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48
49namespace Foam
50{
52/*---------------------------------------------------------------------------*\
53 Class passivePositionParticle Declaration
54\*---------------------------------------------------------------------------*/
55
57:
58 public particle
59{
60 // Private Data
61
62 //- Raw location
63 point location_;
64
65
66public:
67
68 // Constructors
69
70 //- Construct from components (known location)
72 (
73 const polyMesh& mesh,
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,
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,
104 const bool readFields = true,
105 const bool newFormat = true
106 )
107 :
108 //particle(mesh, is, readFields, newFormat)
110 (
111 mesh,
112 Zero, // position
113 -1, // celli
114 -1, // tetFacei
115 -1, // tetPti
116 false // doLocate
117 )
118 {
120 (
121 is,
122 location_,
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
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 {
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// ************************************************************************* //
@ ASCII
"ascii" (normal default)
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition autoPtr.H:65
static autoPtr< T > New(Args &&... args)
Construct autoPtr with forwarding arguments.
Definition autoPtr.H:178
Base particle class.
Definition particle.H:72
vector position() const
Return current particle position.
Definition particleI.H:283
static void readFields(TrackCloudType &c)
Read the fields associated with the owner cloud.
static autoPtr< particle > Clone(const Derived &p)
Clone a particle.
Definition particle.H:552
const polyMesh & mesh() const noexcept
Return the mesh database.
Definition particleI.H:110
const barycentric & coordinates() const noexcept
Return current particle coordinates.
Definition particleI.H:116
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
label cell() const noexcept
Return current cell particle is in.
Definition particleI.H:122
particle(const polyMesh &mesh, const barycentric &coordinates, const label celli, const label tetFacei, const label tetPti)
Construct from components.
Definition particle.C:507
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).
const point & location() const noexcept
The cached particle position.
passivePositionParticle(const polyMesh &mesh, Istream &is, const bool readFields=true, const bool newFormat=true)
Construct from Istream.
virtual autoPtr< particle > clone() const
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.
virtual void writePosition(Ostream &os) const
Write the particle position and cell id.
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
@ SPACE
Space [isspace].
Definition token.H:144
volScalarField & p
dynamicFvMesh & mesh
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.
vector point
Point is a vector.
Definition point.H:37
static constexpr const zero Zero
Global zero (0).
Definition zero.H:127
const direction noexcept
Definition scalarImpl.H:265
Barycentric< scalar > barycentric
A scalar version of the templated Barycentric.
Definition barycentric.H:45
Vector< scalar > vector
Definition vector.H:57
Old particle positions content for OpenFOAM-1706 and earlier.
Definition particle.H:123