Nektar++
Loading...
Searching...
No Matches
CADSurf.h
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////////////
2//
3// File: CADSurf.h
4//
5// For more information, please see: http://www.nektar.info/
6//
7// The MIT License
8//
9// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10// Department of Aeronautics, Imperial College London (UK), and Scientific
11// Computing and Imaging Institute, University of Utah (USA).
12//
13// Permission is hereby granted, free of charge, to any person obtaining a
14// copy of this software and associated documentation files (the "Software"),
15// to deal in the Software without restriction, including without limitation
16// the rights to use, copy, modify, merge, publish, distribute, sublicense,
17// and/or sell copies of the Software, and to permit persons to whom the
18// Software is furnished to do so, subject to the following conditions:
19//
20// The above copyright notice and this permission notice shall be included
21// in all copies or substantial portions of the Software.
22//
23// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29// DEALINGS IN THE SOFTWARE.
30//
31// Description: CAD object surface.
32//
33////////////////////////////////////////////////////////////////////////////////
34
35#ifndef NEKTAR_SPATIALDOMAINS_CADSYSTEM_CADSURF
36#define NEKTAR_SPATIALDOMAINS_CADSYSTEM_CADSURF
37
40
41#include <array>
42
44{
45
46class CADCurve;
47typedef std::shared_ptr<CADCurve> CADCurveSharedPtr;
48class CADSurf;
49typedef std::shared_ptr<CADSurf> CADSurfSharedPtr;
50
51/**
52 * @brief struct which descibes a collection of cad edges which are a
53 * loop on the cad surface
54 */
56{
57 std::vector<CADCurveSharedPtr> edges;
58 std::vector<CADOrientation::Orientation> edgeo;
59 std::array<NekDouble, 2> center;
61};
62
63typedef std::shared_ptr<EdgeLoop> EdgeLoopSharedPtr;
64
65/**
66 * @brief base class for a cad surface
67 */
68
69class CADSurf : public CADObject
70{
71public:
72 friend class MemoryManager<CADSurf>;
73
74 /**
75 * @brief Default constructor.
76 */
82
83 ~CADSurf() override
84 {
85 }
86
87 /**
88 * @brief Static function which orientates the edge loop on a surface
89 */
90 static void OrientateEdges(CADSurfSharedPtr surf,
91 std::vector<EdgeLoopSharedPtr> &ein);
92
93 /**
94 * @brief Get the loop structures which bound the cad surface
95 */
96 std::vector<EdgeLoopSharedPtr> GetEdges()
97 {
98 return m_edges;
99 }
100
101 /**
102 * @brief Set the edge loop
103 */
104 void SetEdges(std::vector<EdgeLoopSharedPtr> ein)
105 {
106 m_edges = ein;
107 }
108
109 /**
110 * @brief Get the limits of the parametric space for the surface.
111 *
112 * @return Array of 4 entries with parametric umin,umax,vmin,vmax.
113 */
114 SPATIAL_DOMAINS_EXPORT virtual std::array<NekDouble, 4> GetBounds() = 0;
115
116 /**
117 * @brief Get the limits of the parametric space for the surface.
118 */
120 NekDouble &umax,
121 NekDouble &vmin,
122 NekDouble &vmax) = 0;
123
124 /**
125 * @brief Get the normal vector at parametric point u,v.
126 *
127 * @param uv Array of u and v parametric coords.
128 * @return Array of xyz components of normal vector.
129 */
130 SPATIAL_DOMAINS_EXPORT virtual std::array<NekDouble, 3> N(
131 std::array<NekDouble, 2> uv) = 0;
132
133 /**
134 * @brief Get the set of first derivatives at parametric point u,v
135 *
136 * @param uv Array of u and v parametric coords.
137 * @return Array of xyz copmonents of first derivatives.
138 */
139 SPATIAL_DOMAINS_EXPORT virtual std::array<NekDouble, 9> D1(
140 std::array<NekDouble, 2> uv) = 0;
141
142 /**
143 * @brief Get the set of second derivatives at parametric point u,v
144 *
145 * @param uv array of u and v parametric coords
146 * @return array of xyz copmonents of second derivatives
147 */
148 SPATIAL_DOMAINS_EXPORT virtual std::array<NekDouble, 18> D2(
149 std::array<NekDouble, 2> uv) = 0;
150
151 /**
152 * @brief Get the x,y,z at parametric point u,v.
153 *
154 * @param uv Array of u and v parametric coords.
155 * @return Array of x,y,z location.
156 */
157 SPATIAL_DOMAINS_EXPORT virtual std::array<NekDouble, 3> P(
158 std::array<NekDouble, 2> uv) = 0;
159
160 /**
161 * @brief Get the x,y,z at parametric point u,v.
162 *
163 * @param uv Array of u and v parametric coords.
164 */
165 SPATIAL_DOMAINS_EXPORT virtual void P(std::array<NekDouble, 2> uv,
166 NekDouble &x, NekDouble &y,
167 NekDouble &z) = 0;
168
169 /**
170 * @brief Performs a reverse look up to find u,v and x,y,z.
171 * if xyz is off the surface it will return the closest point
172 *
173 * @param p Array of xyz location
174 * @return The parametric location of xyz on this surface
175 */
176 SPATIAL_DOMAINS_EXPORT virtual std::array<NekDouble, 2> locuv(
177 std::array<NekDouble, 3> p, NekDouble &dist) = 0;
178
179 /**
180 * @brief overload function of locuv ommiting the dist parameter
181 * in this case if the projection is greater than a certain distance
182 * it will produce a warning. To do large distance projection use the other
183 * locuv method
184 */
185 std::array<NekDouble, 2> locuv(std::array<NekDouble, 3> p)
186 {
187 NekDouble dist;
188 auto uv = locuv(p, dist);
189 WARNINGL1(dist < 1e-3, "large locuv distance: " + std::to_string(dist));
190 return uv;
191 }
192
193 /**
194 * @brief Performs a reverse look up to find u,v and x,y,z.
195 * if xyz is off the surface it will return the closest point
196 *
197 * @param p Array of xyz location
198 * @return The parametric location of xyz on this surface
199 */
200 SPATIAL_DOMAINS_EXPORT virtual std::array<NekDouble, 2> locuv(
201 std::array<NekDouble, 3> p, NekDouble &dist, NekDouble Umin,
202 NekDouble Usup, NekDouble Vmin, NekDouble Vsup) = 0;
203
204 /**
205 * @brief Returns the bounding box of the surface
206 */
207 SPATIAL_DOMAINS_EXPORT virtual std::array<NekDouble, 6> BoundingBox() = 0;
208
209 /**
210 * @brief Returns the bounding box of the surface that scales the
211 * enlargement and the meshing parameters * scale
212 */
213 SPATIAL_DOMAINS_EXPORT virtual std::array<NekDouble, 6> BoundingBox(
214 NekDouble scale) = 0;
215
216 /**
217 * @brief returns curvature at point uv
218 */
220 std::array<NekDouble, 2> uv) = 0;
221
222 /**
223 * @brief Curvature and position at @p uv together.
224 *
225 * The octree wants both at every one of its curvature samples, of which
226 * there are millions, and a CAD engine that derives curvature from the
227 * surface's second derivatives has the position in hand already. This
228 * default asks twice, which is what the callers used to do; an engine
229 * that can do better overrides it.
230 */
231 /**
232 * @brief The @f$ (u,v) @f$ of the point at parameter @p t on @p curve,
233 * which must be one of this surface's bounding curves.
234 *
235 * Projecting a point back onto the surface it is already known to lie on
236 * is expensive and unnecessary where the CAD engine stores the curve's
237 * own representation in the surface's parameter plane. This default does
238 * the projection; an engine that keeps that representation overrides it.
239 */
240 /**
241 * @brief As locuv(), but starting the search from @p guess.
242 *
243 * Finding the parameters of a point on a surface is an iterative
244 * minimisation, and the cost of it depends strongly on where it starts.
245 * Callers placing a run of points that lie near one another -- the
246 * interior nodes of one high-order element, say -- can hand each the
247 * answer from the last. The default ignores the guess.
248 */
249 SPATIAL_DOMAINS_EXPORT virtual std::array<NekDouble, 2> locuvFrom(
250 std::array<NekDouble, 3> p, std::array<NekDouble, 2> guess,
251 NekDouble &dist)
252 {
253 (void)guess;
254 return locuv(p, dist);
255 }
256
257 SPATIAL_DOMAINS_EXPORT virtual std::array<NekDouble, 2> locuvOnCurve(
258 const CADCurveSharedPtr &curve, NekDouble t);
259
261 std::array<NekDouble, 2> uv, std::array<NekDouble, 3> &loc)
262 {
263 NekDouble curvature = Curvature(uv);
264 loc = P(uv);
265 return curvature;
266 }
267
268 /**
269 * @brief Is the surface defined by a planar surface (i.e not nurbs and is
270 * flat)
271 */
273
274 /**
275 * @brief query reversed normal
276 */
278 {
279 return m_orientation;
280 }
281
282protected:
283 /// List of bounding edges in loops with orientation.
284 std::vector<EdgeLoopSharedPtr> m_edges;
285
286 /// Function which tests the the value of uv used is within the surface
287 virtual void Test(std::array<NekDouble, 2> uv) = 0;
288};
289
290typedef std::shared_ptr<CADSurf> CADSurfSharedPtr;
291
293
295} // namespace Nektar::SpatialDomains
296
297#endif
#define WARNINGL1(condition, msg)
#define SPATIAL_DOMAINS_EXPORT
General purpose memory allocation routines with the ability to allocate from thread specific memory p...
CADType::cadType m_type
type of the cad object
Definition CADObject.h:148
CADOrientation::Orientation m_orientation
orientation of the CADObject
Definition CADObject.h:150
base class for a cad surface
Definition CADSurf.h:70
std::vector< EdgeLoopSharedPtr > GetEdges()
Get the loop structures which bound the cad surface.
Definition CADSurf.h:96
virtual NekDouble Curvature(std::array< NekDouble, 2 > uv)=0
returns curvature at point uv
virtual void Test(std::array< NekDouble, 2 > uv)=0
Function which tests the the value of uv used is within the surface.
virtual std::array< NekDouble, 2 > locuvOnCurve(const CADCurveSharedPtr &curve, NekDouble t)
Definition CADSurf.cpp:50
virtual std::array< NekDouble, 9 > D1(std::array< NekDouble, 2 > uv)=0
Get the set of first derivatives at parametric point u,v.
void SetEdges(std::vector< EdgeLoopSharedPtr > ein)
Set the edge loop.
Definition CADSurf.h:104
virtual bool IsPlanar()=0
Is the surface defined by a planar surface (i.e not nurbs and is flat)
static void OrientateEdges(CADSurfSharedPtr surf, std::vector< EdgeLoopSharedPtr > &ein)
Static function which orientates the edge loop on a surface.
Definition CADSurf.cpp:56
virtual std::array< NekDouble, 3 > P(std::array< NekDouble, 2 > uv)=0
Get the x,y,z at parametric point u,v.
virtual void P(std::array< NekDouble, 2 > uv, NekDouble &x, NekDouble &y, NekDouble &z)=0
Get the x,y,z at parametric point u,v.
CADOrientation::Orientation Orientation() override
query reversed normal
Definition CADSurf.h:277
virtual std::array< NekDouble, 6 > BoundingBox(NekDouble scale)=0
Returns the bounding box of the surface that scales the enlargement and the meshing parameters * scal...
virtual void GetBounds(NekDouble &umin, NekDouble &umax, NekDouble &vmin, NekDouble &vmax)=0
Get the limits of the parametric space for the surface.
std::vector< EdgeLoopSharedPtr > m_edges
List of bounding edges in loops with orientation.
Definition CADSurf.h:284
virtual std::array< NekDouble, 4 > GetBounds()=0
Get the limits of the parametric space for the surface.
CADSurf()
Default constructor.
Definition CADSurf.h:77
virtual std::array< NekDouble, 3 > N(std::array< NekDouble, 2 > uv)=0
Get the normal vector at parametric point u,v.
virtual std::array< NekDouble, 18 > D2(std::array< NekDouble, 2 > uv)=0
Get the set of second derivatives at parametric point u,v.
virtual std::array< NekDouble, 6 > BoundingBox()=0
Returns the bounding box of the surface.
virtual NekDouble CurvatureAndPosition(std::array< NekDouble, 2 > uv, std::array< NekDouble, 3 > &loc)
Definition CADSurf.h:260
virtual std::array< NekDouble, 2 > locuvFrom(std::array< NekDouble, 3 > p, std::array< NekDouble, 2 > guess, NekDouble &dist)
Curvature and position at uv together.
Definition CADSurf.h:249
std::array< NekDouble, 2 > locuv(std::array< NekDouble, 3 > p)
overload function of locuv ommiting the dist parameter in this case if the projection is greater than...
Definition CADSurf.h:185
virtual std::array< NekDouble, 2 > locuv(std::array< NekDouble, 3 > p, NekDouble &dist, NekDouble Umin, NekDouble Usup, NekDouble Vmin, NekDouble Vsup)=0
Performs a reverse look up to find u,v and x,y,z. if xyz is off the surface it will return the closes...
virtual std::array< NekDouble, 2 > locuv(std::array< NekDouble, 3 > p, NekDouble &dist)=0
Performs a reverse look up to find u,v and x,y,z. if xyz is off the surface it will return the closes...
std::shared_ptr< CADCurve > CADCurveSharedPtr
Definition CADCurve.h:247
CADSurfFactory & GetCADSurfFactory()
Definition CADSystem.cpp:60
std::shared_ptr< CADSurf > CADSurfSharedPtr
Definition CADCurve.h:51
LibUtilities::NekFactory< std::string, CADSurf > CADSurfFactory
Definition CADSurf.h:292
std::shared_ptr< EdgeLoop > EdgeLoopSharedPtr
Definition CADSurf.h:63
struct which descibes a collection of cad edges which are a loop on the cad surface
Definition CADSurf.h:56
std::array< NekDouble, 2 > center
Definition CADSurf.h:59
std::vector< CADCurveSharedPtr > edges
Definition CADSurf.h:57
std::vector< CADOrientation::Orientation > edgeo
Definition CADSurf.h:58