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 -------------------------------------------------------------------------------
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::meshedSurfRef
28 
29 Description
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 
47 namespace Foam
48 {
49 
50 /*---------------------------------------------------------------------------*\
51  Class meshedSurfRef Declaration
52 \*---------------------------------------------------------------------------*/
53 
54 class meshedSurfRef
55 :
56  public meshedSurf
57 {
58  // Private Data
59 
60  //- An external surface reference
61  refPtr<meshedSurf> surf_;
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 
73 public:
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
118  {
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
139  {
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());
147  }
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);
171  }
172 
173  //- Reset components
174  void reset
175  (
176  const pointField& points,
177  const faceList& faces,
178  const labelList& zoneIds = labelList::null(),
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
192  void resetPoints()
193  {
194  newPoints_.clear();
195  }
196 
197  //- Change point positions
198  void movePoints(pointField&& pts)
199  {
200  newPoints_.transfer(pts);
201  }
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 // ************************************************************************* //
virtual const pointField & points() const
The points used for the surface.
void transfer(List< T > &list)
Transfer the contents of the argument List into this list and annul the argument list.
Definition: List.C:326
bool equal(const T &a, const T &b)
Compare two values for equality.
Definition: label.H:164
bool empty() const noexcept
True if List is empty (ie, size() is zero)
Definition: UList.H:666
void movePoints(pointField &&pts)
Change point positions.
static const List< label > & null()
Return a null List.
Definition: ListI.H:130
const T & cref() const
Return const reference to the object or to the contents of a (non-null) managed pointer.
Definition: refPtrI.H:216
virtual const labelList & faceIds() const
Per-face identifier (eg, element Id)
A class for managing references or pointers (no reference counting)
Definition: HashPtrTable.H:49
void reset(const meshedSurf &s)
Reset surface.
Abstract definition of a meshed surface defined by faces and points.
Definition: meshedSurf.H:43
virtual ~meshedSurfRef()=default
Destructor.
Implements a meshed surface by referencing another meshed surface or faces/points components...
Definition: meshedSurfRef.H:47
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:137
void scalePoints(const scalar scaleFactor)
Scale points: ignore unity and non-positive factors.
virtual const faceList & faces() const
The faces used for the surface.
bool valid() const
Contains a valid reference?
static const Field< vector > & null()
Return nullObject reference Field.
Definition: FieldI.H:24
bool good() const
Contains a valid reference?
virtual const labelList & zoneIds() const
Per-face zone/region information.
void clear() const noexcept
If object pointer points to valid object: delete object and set pointer to nullptr.
Definition: tmpI.H:289
A class for managing temporary objects.
Definition: HashPtrTable.H:50
void resetPoints()
Reset changes in point positions.
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))
meshedSurfRef()
Default construct.
Definition: meshedSurfRef.H:79
bool notNull(const T *ptr)
True if ptr is not a pointer (of type T) to the nullObject.
Definition: nullObject.H:246
void clear()
Invalid by redirecting to null objects.
Namespace for OpenFOAM.
void reset(T *p=nullptr) noexcept
Delete managed pointer and set to new given pointer.
Definition: refPtrI.H:314
const pointField & pts
const pointField & points0() const
The original points used for the surface.