Loading...
Searching...
No Matches
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\*---------------------------------------------------------------------------*/
53
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 good() const
119 return (surf_ || notNull(points_.get()));
120 }
121
122 //- Contains a valid reference?
123 bool valid() const { return good(); }
124
125 //- The original points used for the surface
126 const pointField& points0() const
127 {
128 return (surf_ ? surf_.cref().points() : points_.get());
129 }
130
131 //- The points used for the surface
132 virtual const pointField& points() const
133 {
134 return (newPoints_.empty() ? points0() : newPoints_);
135 }
136
137 //- The faces used for the surface
138 virtual const faceList& faces() const
140 return (surf_ ? surf_.cref().faces() : faces_.get());
141 }
142
143 //- Per-face zone/region information
144 virtual const labelList& zoneIds() const
145 {
146 return (surf_ ? surf_.cref().zoneIds() : zoneIds_.get());
148
149 //- Per-face identifier (eg, element Id)
150 virtual const labelList& faceIds() const
151 {
152 return (surf_ ? surf_.cref().faceIds() : faceIds_.get());
153 }
154
155 //- Invalid by redirecting to null objects
156 void clear()
157 {
158 surf_.reset();
159 points_ = std::cref<pointField>(pointField::null());
160 faces_ = std::cref<faceList>(faceList::null());
161 zoneIds_ = std::cref<labelList>(labelList::null());
162 faceIds_ = std::cref<labelList>(labelList::null());
163 newPoints_.clear();
164 }
165
166 //- Reset surface
167 void reset(const meshedSurf& s)
168 {
169 clear();
170 surf_.cref(s);
172
173 //- Reset components
174 void reset
175 (
176 const pointField& points,
177 const faceList& faces,
180 )
181 {
182 surf_.reset();
183 points_ = std::cref<pointField>(points);
184 faces_ = std::cref<faceList>(faces);
185 zoneIds_ = std::cref<labelList>(zoneIds);
186 faceIds_ = std::cref<labelList>(faceIds);
187 newPoints_.clear();
188 }
189
190
191 //- Reset changes in point positions
193 {
194 newPoints_.clear();
195 }
196
197 //- Change point positions
199 {
200 newPoints_.transfer(pts);
202
203 //- Change point positions
204 void movePoints(const tmp<pointField>& tpts)
205 {
206 newPoints_.clear();
207 if (tpts)
208 {
209 newPoints_ = tpts;
210 }
211 tpts.clear();
212 }
213
214 //- Scale points: ignore unity and non-positive factors
215 void scalePoints(const scalar scaleFactor)
216 {
217 if (scaleFactor > SMALL && !equal(scaleFactor, 1))
218 {
219 if (newPoints_.empty())
220 {
221 newPoints_ = points0();
222 }
223 newPoints_ *= scaleFactor;
224 }
225 }
226};
227
228
229// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
230
231} // End namespace Foam
232
233// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
234
235#endif
236
237// ************************************************************************* //
static const Field< vector > & null() noexcept
Definition Field.H:192
void transfer(List< T > &list)
Transfer the contents of the argument List into this list and annul the argument list.
Definition List.C:347
void clear()
Clear the list, i.e. set size to zero.
Definition ListI.H:133
static const List< label > & null() noexcept
Definition List.H:138
Implements a meshed surface by referencing another meshed surface or faces/points components.
meshedSurfRef()
Default construct.
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.
bool good() const
Contains a valid reference?
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.
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.
virtual ~meshedSurfRef()=default
Destructor.
Abstract definition of a meshed surface defined by faces and points.
Definition meshedSurf.H:44
constexpr meshedSurf() noexcept=default
Default construct.
A class for managing references or pointers (no reference counting).
Definition refPtr.H:54
const T & cref() const
Return const reference to the object or to the contents of a (non-null) managed pointer.
Definition refPtrI.H:216
A class for managing temporary objects.
Definition tmp.H:75
void clear() const noexcept
If object pointer points to valid object: delete object and set pointer to nullptr.
Definition tmpI.H:289
const pointField & points
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.
List< label > labelList
A List of labels.
Definition List.H:62
bool equal(const T &a, const T &b)
Compare two values for equality.
Definition label.H:180
List< face > faceList
List of faces.
Definition faceListFwd.H:41
bool notNull(const T *ptr) noexcept
True if ptr is not a pointer (of type T) to the nullObject.
Definition nullObject.H:267
vectorField pointField
pointField is a vectorField.
const pointField & pts