meshedSurfRef.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) 2016-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::meshedSurfRef
28
29Description
30 Implements a meshed surface by referencing another meshed surface
31 or faces/points components.
32
33 In addition to the referencing, supports simple moving/scaling
34 of points (uses a deep-copy).
35
36\*---------------------------------------------------------------------------*/
37
38#ifndef Foam_meshedSurfRef_H
39#define Foam_meshedSurfRef_H
40
41#include "meshedSurf.H"
42#include "refPtr.H"
43#include <functional>
44
45// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46
47namespace Foam
48{
49
50/*---------------------------------------------------------------------------*\
51 Class meshedSurfRef Declaration
52\*---------------------------------------------------------------------------*/
54class meshedSurfRef
55:
56 public meshedSurf
57{
58 // Private Data
59
60 //- An external surface reference
62
63 //- Components
64 std::reference_wrapper<const pointField> points_;
65 std::reference_wrapper<const faceList> faces_;
66 std::reference_wrapper<const labelList> zoneIds_;
67 std::reference_wrapper<const labelList> faceIds_;
68
69 //- Locations of moved/scaled points (if any)
70 pointField newPoints_;
71
72
73public:
74
75 // Constructors
76
77 //- Default construct
79 :
80 points_(std::cref<pointField>(pointField::null())),
81 faces_(std::cref<faceList>(faceList::null())),
82 zoneIds_(std::cref<labelList>(labelList::null())),
83 faceIds_(std::cref<labelList>(labelList::null()))
84 {}
85
86 //- Construct as reference to a meshedSurf
87 explicit meshedSurfRef(const meshedSurf& s)
88 :
90 {
91 surf_.cref(s);
92 }
93
94 //- Construct from components
96 (
97 const pointField& points,
98 const faceList& faces,
101 )
102 :
103 points_(std::cref<pointField>(points)),
104 faces_(std::cref<faceList>(faces)),
105 zoneIds_(std::cref<labelList>(zoneIds)),
106 faceIds_(std::cref<labelList>(faceIds))
107 {}
108
109
110 //- Destructor
111 virtual ~meshedSurfRef() = default;
112
113
114 // Member Functions
115
116 //- Contains a valid reference?
117 bool valid() const
118 {
119 return (surf_ || notNull(points_.get()));
120 }
121
122 //- The original points used for the surface
123 const pointField& points0() const
124 {
125 return (surf_ ? surf_.cref().points() : points_.get());
126 }
127
128 //- The points used for the surface
129 virtual const pointField& points() const
130 {
131 return (newPoints_.empty() ? points0() : newPoints_);
132 }
133
134 //- The faces used for the surface
135 virtual const faceList& faces() const
136 {
137 return (surf_ ? surf_.cref().faces() : faces_.get());
138 }
139
140 //- Per-face zone/region information
141 virtual const labelList& zoneIds() const
142 {
143 return (surf_ ? surf_.cref().zoneIds() : zoneIds_.get());
144 }
145
146 //- Per-face identifier (eg, element Id)
147 virtual const labelList& faceIds() const
148 {
149 return (surf_ ? surf_.cref().faceIds() : faceIds_.get());
150 }
151
152 //- Invalid by redirecting to null objects
153 void clear()
154 {
155 surf_.reset();
156 points_ = std::cref<pointField>(pointField::null());
157 faces_ = std::cref<faceList>(faceList::null());
158 zoneIds_ = std::cref<labelList>(labelList::null());
159 faceIds_ = std::cref<labelList>(labelList::null());
160 newPoints_.clear();
161 }
162
163 //- Reset surface
164 void reset(const meshedSurf& s)
165 {
166 clear();
167 surf_.cref(s);
168 }
169
170 //- Reset components
171 void reset
172 (
173 const pointField& points,
174 const faceList& faces,
177 )
178 {
179 surf_.reset();
180 points_ = std::cref<pointField>(points);
181 faces_ = std::cref<faceList>(faces);
182 zoneIds_ = std::cref<labelList>(zoneIds);
183 faceIds_ = std::cref<labelList>(faceIds);
184 newPoints_.clear();
185 }
186
187
188 //- Reset changes in point positions
189 void resetPoints()
190 {
191 newPoints_.clear();
192 }
193
194 //- Change point positions
195 void movePoints(pointField&& pts)
196 {
197 newPoints_.transfer(pts);
198 }
199
200 //- Change point positions
201 void movePoints(const tmp<pointField>& tpts)
202 {
203 newPoints_.clear();
204 if (tpts)
205 {
206 newPoints_ = tpts;
207 }
208 tpts.clear();
209 }
210
211 //- Scale points: ignore unity and non-positive factors
212 void scalePoints(const scalar scaleFactor)
213 {
214 if (scaleFactor > SMALL && !equal(scaleFactor, 1))
215 {
216 if (newPoints_.empty())
217 {
218 newPoints_ = points0();
219 }
220 newPoints_ *= scaleFactor;
221 }
222 }
223};
224
225
226// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
227
228} // End namespace Foam
229
230// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
231
232#endif
233
234// ************************************************************************* //
void transfer(List< T > &list)
Definition: List.C:447
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:116
bool empty() const noexcept
True if the UList is empty (ie, size() is zero)
Definition: UListI.H:427
Implements a meshed surface by referencing another meshed surface or faces/points components.
Definition: meshedSurfRef.H:56
meshedSurfRef()
Default construct.
Definition: meshedSurfRef.H:77
virtual const pointField & points() const
The points used for the surface.
void reset(const pointField &points, const faceList &faces, const labelList &zoneIds=labelList::null(), const labelList &faceIds=labelList::null())
Reset components.
void movePoints(pointField &&pts)
Change point positions.
bool valid() const
Contains a valid reference?
void movePoints(const tmp< pointField > &tpts)
Change point positions.
virtual const labelList & faceIds() const
Per-face identifier (eg, element Id)
virtual const faceList & faces() const
The faces used for the surface.
virtual const labelList & zoneIds() const
Per-face zone/region information.
void reset(const meshedSurf &s)
Reset surface.
void resetPoints()
Reset changes in point positions.
void clear()
Invalid by redirecting to null objects.
meshedSurfRef(const pointField &points, const faceList &faces, const labelList &zoneIds=labelList::null(), const labelList &faceIds=labelList::null())
Construct from components.
Definition: meshedSurfRef.H:95
const pointField & points0() const
The original points used for the surface.
void scalePoints(const scalar scaleFactor)
Scale points: ignore unity and non-positive factors.
meshedSurfRef(const meshedSurf &s)
Construct as reference to a meshedSurf.
Definition: meshedSurfRef.H:86
virtual ~meshedSurfRef()=default
Destructor.
Abstract definition of a meshed surface defined by faces and points.
Definition: meshedSurf.H:50
A class for managing references or pointers (no reference counting)
Definition: refPtr.H:58
const T & cref() const
Definition: refPtrI.H:189
void reset(refPtr< T > &&other) noexcept
Clear existing and transfer ownership.
Definition: refPtrI.H:303
A class for managing temporary objects.
Definition: tmp.H:65
void clear() const noexcept
Definition: tmpI.H:287
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))
Namespace for OpenFOAM.
bool equal(const T &s1, const T &s2)
Compare two values for equality.
Definition: doubleFloat.H:46
bool notNull(const T *ptr)
True if ptr is not a pointer (of type T) to the nullObject.
Definition: nullObject.H:207