Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | List of all members
Nektar::NekMeshUtils::CADSurfOCE Class Reference

#include <CADSurfOCE.h>

Inheritance diagram for Nektar::NekMeshUtils::CADSurfOCE:
Inheritance graph
[legend]
Collaboration diagram for Nektar::NekMeshUtils::CADSurfOCE:
Collaboration graph
[legend]

Public Member Functions

 CADSurfOCE ()
 
 ~CADSurfOCE ()
 
void Initialise (int i, TopoDS_Shape in)
 
virtual Array< OneD, NekDoubleGetBounds ()
 Get the limits of the parametric space for the surface. More...
 
virtual Array< OneD, NekDoubleN (Array< OneD, NekDouble > uv)
 Get the normal vector at parametric point u,v. More...
 
virtual Array< OneD, NekDoubleD1 (Array< OneD, NekDouble > uv)
 Get the set of first derivatives at parametric point u,v. More...
 
virtual Array< OneD, NekDoubleD2 (Array< OneD, NekDouble > uv)
 Get the set of second derivatives at parametric point u,v. More...
 
virtual Array< OneD, NekDoubleP (Array< OneD, NekDouble > uv)
 Get the x,y,z at parametric point u,v. More...
 
virtual Array< OneD, NekDoublelocuv (Array< OneD, NekDouble > p)
 Performs a reverse look up to find u,v and x,y,z. More...
 
virtual NekDouble DistanceTo (Array< OneD, NekDouble > p)
 does unconstrained locuv to project point from anywhere and calculate the distance between the orthonormal projection to the surface and the point More...
 
virtual void ProjectTo (Array< OneD, NekDouble > &tp, Array< OneD, NekDouble > &uv)
 takes a point from anywhere find the nearest surface point and its uv More...
 
virtual NekDouble Curvature (Array< OneD, NekDouble > uv)
 returns curvature at point uv More...
 
- Public Member Functions inherited from Nektar::NekMeshUtils::CADSurf
 CADSurf ()
 Default constructor. More...
 
 ~CADSurf ()
 
std::vector
< CADSystem::EdgeLoopSharedPtr
GetEdges ()
 Get the loop structures which bound the cad surface. More...
 
void SetEdges (std::vector< CADSystem::EdgeLoopSharedPtr > ein)
 
CADOrientation::Orientation Orientation ()
 query reversed normal More...
 
- Public Member Functions inherited from Nektar::NekMeshUtils::CADObject
 CADObject ()
 Default constructor. More...
 
virtual ~CADObject ()
 
int GetId ()
 Return ID of the vertex. More...
 
CADType::cadType GetType ()
 

Static Public Member Functions

static CADSurfSharedPtr create ()
 
- Static Public Member Functions inherited from Nektar::NekMeshUtils::CADSurf
static void OrientateEdges (CADSurfSharedPtr surf, std::vector< CADSystem::EdgeLoopSharedPtr > &ein)
 

Static Public Attributes

static std::string key
 

Private Member Functions

void Test (Array< OneD, NekDouble > uv)
 Function which tests the the value of uv used is within the surface. More...
 
 Handle (Geom_Surface) m_s
 Alternate OpenCascade object for surface. Used by reverse lookup. More...
 

Private Attributes

BRepAdaptor_Surface m_occSurface
 OpenCascade object for surface. More...
 
Array< OneD, NekDoublem_bounds
 parametric bounds More...
 
ShapeAnalysis_Surface * m_sas
 locuv object (stored because it gets faster with stored information) More...
 

Additional Inherited Members

- Protected Attributes inherited from Nektar::NekMeshUtils::CADSurf
std::vector
< CADSystem::EdgeLoopSharedPtr
m_edges
 List of bounding edges in loops with orientation. More...
 
- Protected Attributes inherited from Nektar::NekMeshUtils::CADObject
int m_id
 ID of the vert. More...
 
CADType::cadType m_type
 type of the cad object More...
 
CADOrientation::Orientation m_orientation
 orientation of the CADObject More...
 

Detailed Description

Definition at line 47 of file CADSurfOCE.h.

Constructor & Destructor Documentation

Nektar::NekMeshUtils::CADSurfOCE::CADSurfOCE ( )
inline

Definition at line 58 of file CADSurfOCE.h.

59  {
60  }
Nektar::NekMeshUtils::CADSurfOCE::~CADSurfOCE ( )
inline

Definition at line 62 of file CADSurfOCE.h.

63  {
64  }

Member Function Documentation

static CADSurfSharedPtr Nektar::NekMeshUtils::CADSurfOCE::create ( )
inlinestatic

Definition at line 51 of file CADSurfOCE.h.

References Nektar::MemoryManager< DataType >::AllocateSharedPtr().

52  {
54  }
static boost::shared_ptr< DataType > AllocateSharedPtr()
Allocate a shared pointer from the memory pool.
NekDouble Nektar::NekMeshUtils::CADSurfOCE::Curvature ( Array< OneD, NekDouble uv)
virtual

returns curvature at point uv

Implements Nektar::NekMeshUtils::CADSurf.

Definition at line 127 of file CADSurfOCE.cpp.

128 {
129 #if defined(NEKTAR_DEBUG)
130  Test(uv);
131 #endif
132 
133  Array<OneD, NekDouble> n = N(uv);
134 
135  // a zero normal occurs at a signularity, CurvaturePoint
136  // cannot be sampled here
137  if (n[0] == 0 && n[1] == 0 && n[2] == 0)
138  {
139  return 0.0;
140  }
141 
142  Array<OneD, NekDouble> r = D2(uv);
143 
144  // metric and curvature tensors
145  NekDouble E = r[3] * r[3] + r[4] * r[4] + r[5] * r[5];
146  NekDouble F = r[3] * r[6] + r[4] * r[7] + r[5] * r[8];
147  NekDouble G = r[6] * r[6] + r[7] * r[7] + r[8] * r[8];
148  NekDouble e = n[0] * r[9] + n[1] * r[10] + n[2] * r[11];
149  NekDouble f = n[0] * r[15] + n[1] * r[16] + n[2] * r[17];
150  NekDouble g = n[0] * r[12] + n[1] * r[13] + n[2] * r[14];
151 
152  // if det is zero cannot invert matrix, R=0 so must skip
153  if (E * G - F * F < 1E-30)
154  {
155  return 0.0;
156  }
157 
158  NekDouble K, H;
159 
160  K = (e * g - f * f) / (E * G - F * F);
161  H = 0.5 * (e * G - 2 * f * F + g * E) / (E * G - F * F);
162 
163  NekDouble kv[2];
164  kv[0] = abs(H + sqrt(H * H - K));
165  kv[1] = abs(H - sqrt(H * H - K));
166 
167  return kv[0] > kv[1] ? kv[0] : kv[1];
168 }
virtual Array< OneD, NekDouble > N(Array< OneD, NekDouble > uv)
Get the normal vector at parametric point u,v.
Definition: CADSurfOCE.cpp:221
void Test(Array< OneD, NekDouble > uv)
Function which tests the the value of uv used is within the surface.
Definition: CADSurfOCE.cpp:308
double NekDouble
virtual Array< OneD, NekDouble > D2(Array< OneD, NekDouble > uv)
Get the set of second derivatives at parametric point u,v.
Definition: CADSurfOCE.cpp:275
Array< OneD, NekDouble > Nektar::NekMeshUtils::CADSurfOCE::D1 ( Array< OneD, NekDouble uv)
virtual

Get the set of first derivatives at parametric point u,v.

Parameters
uvArray of u and v parametric coords.
Returns
Array of xyz copmonents of first derivatives.

Implements Nektar::NekMeshUtils::CADSurf.

Definition at line 251 of file CADSurfOCE.cpp.

252 {
253 #if defined(NEKTAR_DEBUG)
254  Test(uv);
255 #endif
256 
257  Array<OneD, NekDouble> r(9);
258  gp_Pnt Loc;
259  gp_Vec D1U, D1V;
260  m_occSurface.D1(uv[0], uv[1], Loc, D1U, D1V);
261 
262  r[0] = Loc.X(); // x
263  r[1] = Loc.Y(); // y
264  r[2] = Loc.Z(); // z
265  r[3] = D1U.X(); // dx/du
266  r[4] = D1U.Y(); // dy/du
267  r[5] = D1U.Z(); // dz/du
268  r[6] = D1V.X(); // dx/dv
269  r[7] = D1V.Y(); // dy/dv
270  r[8] = D1V.Z(); // dz/dv
271 
272  return r;
273 }
void Test(Array< OneD, NekDouble > uv)
Function which tests the the value of uv used is within the surface.
Definition: CADSurfOCE.cpp:308
BRepAdaptor_Surface m_occSurface
OpenCascade object for surface.
Definition: CADSurfOCE.h:83
Array< OneD, NekDouble > Nektar::NekMeshUtils::CADSurfOCE::D2 ( Array< OneD, NekDouble uv)
virtual

Get the set of second derivatives at parametric point u,v.

Parameters
uvarray of u and v parametric coords
Returns
array of xyz copmonents of second derivatives

Implements Nektar::NekMeshUtils::CADSurf.

Definition at line 275 of file CADSurfOCE.cpp.

276 {
277 #if defined(NEKTAR_DEBUG)
278  Test(uv);
279 #endif
280 
281  Array<OneD, NekDouble> r(18);
282  gp_Pnt Loc;
283  gp_Vec D1U, D1V, D2U, D2V, D2UV;
284  m_occSurface.D2(uv[0], uv[1], Loc, D1U, D1V, D2U, D2V, D2UV);
285 
286  r[0] = Loc.X(); // x
287  r[1] = Loc.Y(); // y
288  r[2] = Loc.Z(); // z
289  r[3] = D1U.X(); // dx/dx
290  r[4] = D1U.Y(); // dy/dy
291  r[5] = D1U.Z(); // dz/dz
292  r[6] = D1V.X(); // dx/dx
293  r[7] = D1V.Y(); // dy/dy
294  r[8] = D1V.Z(); // dz/dz
295  r[9] = D2U.X(); // d2x/du2
296  r[10] = D2U.Y(); // d2y/du2
297  r[11] = D2U.Z(); // d2z/du2
298  r[12] = D2V.X(); // d2x/dv2
299  r[13] = D2V.Y(); // d2y/dv2
300  r[14] = D2V.Z(); // d2z/dv2
301  r[15] = D2UV.X(); // d2x/dudv
302  r[16] = D2UV.Y(); // d2y/dudv
303  r[17] = D2UV.Z(); // d2z/dudv
304 
305  return r;
306 }
void Test(Array< OneD, NekDouble > uv)
Function which tests the the value of uv used is within the surface.
Definition: CADSurfOCE.cpp:308
BRepAdaptor_Surface m_occSurface
OpenCascade object for surface.
Definition: CADSurfOCE.h:83
NekDouble Nektar::NekMeshUtils::CADSurfOCE::DistanceTo ( Array< OneD, NekDouble p)
virtual

does unconstrained locuv to project point from anywhere and calculate the distance between the orthonormal projection to the surface and the point

Implements Nektar::NekMeshUtils::CADSurf.

Definition at line 170 of file CADSurfOCE.cpp.

171 {
172  gp_Pnt loc(p[0] * 1000.0, p[1] * 1000.0, p[2] * 1000.0);
173 
174  // alternative locuv methods
175  ShapeAnalysis_Surface sas(m_s);
176  sas.SetDomain(m_bounds[0], m_bounds[1], m_bounds[2], m_bounds[3]);
177 
178  gp_Pnt2d p2 = sas.ValueOfUV(loc, 1e-7);
179 
180  gp_Pnt p3 = sas.Value(p2);
181 
182  return p3.Distance(loc);
183 }
Array< OneD, NekDouble > m_bounds
parametric bounds
Definition: CADSurfOCE.h:87
Array< OneD, NekDouble > Nektar::NekMeshUtils::CADSurfOCE::GetBounds ( )
virtual

Get the limits of the parametric space for the surface.

Returns
Array of 4 entries with parametric umin,umax,vmin,vmax.

Implements Nektar::NekMeshUtils::CADSurf.

Definition at line 76 of file CADSurfOCE.cpp.

77 {
78  return m_bounds;
79 }
Array< OneD, NekDouble > m_bounds
parametric bounds
Definition: CADSurfOCE.h:87
Nektar::NekMeshUtils::CADSurfOCE::Handle ( Geom_Surface  )
private

Alternate OpenCascade object for surface. Used by reverse lookup.

void Nektar::NekMeshUtils::CADSurfOCE::Initialise ( int  i,
TopoDS_Shape  in 
)

Definition at line 48 of file CADSurfOCE.cpp.

References Nektar::StdRegions::eBackwards.

49 {
50  // this bit of code changes the units of the cad from mm opencascade
51  // defualt to m
52 
53  m_s = BRep_Tool::Surface(TopoDS::Face(in));
54 
55  if (in.Orientation() == 1)
56  {
58  }
59 
60  gp_Trsf transform;
61  gp_Pnt ori(0.0, 0.0, 0.0);
62  transform.SetScale(ori, 1.0 / 1000.0);
63  TopLoc_Location mv(transform);
64 
65  in.Move(mv);
66  m_occSurface = BRepAdaptor_Surface(TopoDS::Face(in));
67  m_id = i;
68 
69  m_bounds = Array<OneD, NekDouble>(4);
70  BRepTools::UVBounds(TopoDS::Face(in), m_bounds[0], m_bounds[1], m_bounds[2],
71  m_bounds[3]);
72  m_sas = new ShapeAnalysis_Surface(m_s);
73  m_sas->SetDomain(m_bounds[0], m_bounds[1], m_bounds[2], m_bounds[3]);
74 }
CADOrientation::Orientation m_orientation
orientation of the CADObject
Definition: CADObject.h:109
Array< OneD, NekDouble > m_bounds
parametric bounds
Definition: CADSurfOCE.h:87
int m_id
ID of the vert.
Definition: CADObject.h:105
BRepAdaptor_Surface m_occSurface
OpenCascade object for surface.
Definition: CADSurfOCE.h:83
ShapeAnalysis_Surface * m_sas
locuv object (stored because it gets faster with stored information)
Definition: CADSurfOCE.h:89
Array< OneD, NekDouble > Nektar::NekMeshUtils::CADSurfOCE::locuv ( Array< OneD, NekDouble p)
virtual

Performs a reverse look up to find u,v and x,y,z.

Parameters
pArray of xyz location
Returns
The parametric location of xyz on this surface

Implements Nektar::NekMeshUtils::CADSurf.

Definition at line 81 of file CADSurfOCE.cpp.

References ASSERTL0, and WARNINGL2.

82 {
83  // has to transfer back to mm
84  gp_Pnt loc(p[0] * 1000.0, p[1] * 1000.0, p[2] * 1000.0);
85 
86  Array<OneD, NekDouble> uvr(2);
87 
88  gp_Pnt2d p2 = m_sas->ValueOfUV(loc, 1e-3);
89  uvr[0] = p2.X();
90  uvr[1] = p2.Y();
91 
92  gp_Pnt p3 = m_sas->Value(p2);
93  WARNINGL2(p3.Distance(loc) < 1e-3, "large locuv distance " +
94  boost::lexical_cast<string>(p3.Distance(loc)/1000.0) + " " +
95  boost::lexical_cast<string>(m_id));
96 
97  // if the uv returned is slightly off the surface
98  //(which ShapeAnalysis_Surface can do sometimes)
99  if (uvr[0] < m_bounds[0] || uvr[0] > m_bounds[1] || uvr[1] < m_bounds[2] ||
100  uvr[1] > m_bounds[3])
101  {
102  if (uvr[0] < m_bounds[0])
103  {
104  uvr[0] = m_bounds[0];
105  }
106  else if (uvr[0] > m_bounds[1])
107  {
108  uvr[0] = m_bounds[1];
109  }
110  else if (uvr[1] < m_bounds[2])
111  {
112  uvr[1] = m_bounds[2];
113  }
114  else if (uvr[1] > m_bounds[3])
115  {
116  uvr[1] = m_bounds[3];
117  }
118  else
119  {
120  ASSERTL0(false, "Cannot correct locuv");
121  }
122  }
123 
124  return uvr;
125 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:198
Array< OneD, NekDouble > m_bounds
parametric bounds
Definition: CADSurfOCE.h:87
int m_id
ID of the vert.
Definition: CADObject.h:105
#define WARNINGL2(condition, msg)
Definition: ErrorUtil.hpp:251
ShapeAnalysis_Surface * m_sas
locuv object (stored because it gets faster with stored information)
Definition: CADSurfOCE.h:89
Array< OneD, NekDouble > Nektar::NekMeshUtils::CADSurfOCE::N ( Array< OneD, NekDouble uv)
virtual

Get the normal vector at parametric point u,v.

Parameters
uvArray of u and v parametric coords.
Returns
Array of xyz components of normal vector.

Implements Nektar::NekMeshUtils::CADSurf.

Definition at line 221 of file CADSurfOCE.cpp.

References Nektar::StdRegions::eBackwards.

222 {
223 #if defined(NEKTAR_DEBUG)
224  Test(uv);
225 #endif
226 
227  BRepLProp_SLProps slp(m_occSurface, 2, 1e-6);
228  slp.SetParameters(uv[0], uv[1]);
229 
230  if (!slp.IsNormalDefined())
231  {
232  return Array<OneD, NekDouble>(3, 0.0);
233  }
234 
235  gp_Dir d = slp.Normal();
236 
237  Array<OneD, NekDouble> normal(3);
238 
240  {
241  d.Reverse();
242  }
243 
244  normal[0] = d.X();
245  normal[1] = d.Y();
246  normal[2] = d.Z();
247 
248  return normal;
249 }
CADOrientation::Orientation m_orientation
orientation of the CADObject
Definition: CADObject.h:109
void Test(Array< OneD, NekDouble > uv)
Function which tests the the value of uv used is within the surface.
Definition: CADSurfOCE.cpp:308
BRepAdaptor_Surface m_occSurface
OpenCascade object for surface.
Definition: CADSurfOCE.h:83
Array< OneD, NekDouble > Nektar::NekMeshUtils::CADSurfOCE::P ( Array< OneD, NekDouble uv)
virtual

Get the x,y,z at parametric point u,v.

Parameters
uvArray of u and v parametric coords.
Returns
Array of xyz location.

Implements Nektar::NekMeshUtils::CADSurf.

Definition at line 206 of file CADSurfOCE.cpp.

207 {
208 #if defined(NEKTAR_DEBUG)
209  Test(uv);
210 #endif
211 
212  Array<OneD, NekDouble> location(3);
213  gp_Pnt loc;
214  loc = m_occSurface.Value(uv[0], uv[1]);
215  location[0] = loc.X();
216  location[1] = loc.Y();
217  location[2] = loc.Z();
218  return location;
219 }
void Test(Array< OneD, NekDouble > uv)
Function which tests the the value of uv used is within the surface.
Definition: CADSurfOCE.cpp:308
BRepAdaptor_Surface m_occSurface
OpenCascade object for surface.
Definition: CADSurfOCE.h:83
void Nektar::NekMeshUtils::CADSurfOCE::ProjectTo ( Array< OneD, NekDouble > &  tp,
Array< OneD, NekDouble > &  uv 
)
virtual

takes a point from anywhere find the nearest surface point and its uv

Implements Nektar::NekMeshUtils::CADSurf.

Definition at line 185 of file CADSurfOCE.cpp.

187 {
188  gp_Pnt loc(tp[0] * 1000.0, tp[1] * 1000.0, tp[2] * 1000.0);
189 
190  // alternative locuv methods
191  ShapeAnalysis_Surface sas(m_s);
192  sas.SetDomain(m_bounds[0], m_bounds[1], m_bounds[2], m_bounds[3]);
193 
194  gp_Pnt2d p2 = sas.ValueOfUV(loc, 1e-7);
195 
196  gp_Pnt p3 = sas.Value(p2);
197 
198  tp[0] = p3.X() / 1000.0;
199  tp[1] = p3.Y() / 1000.0;
200  tp[2] = p3.Z() / 1000.0;
201 
202  uv[0] = p2.X();
203  uv[1] = p2.Y();
204 }
Array< OneD, NekDouble > m_bounds
parametric bounds
Definition: CADSurfOCE.h:87
void Nektar::NekMeshUtils::CADSurfOCE::Test ( Array< OneD, NekDouble uv)
privatevirtual

Function which tests the the value of uv used is within the surface.

Implements Nektar::NekMeshUtils::CADSurf.

Definition at line 308 of file CADSurfOCE.cpp.

References ASSERTL1.

309 {
310  stringstream error;
311 
312  error << "Point not within parameter plane: ";
313 
314  bool passed = true;
315 
316  if (uv[0] < m_bounds[0])
317  {
318  if (fabs(uv[0] - m_bounds[0]) > 1E-6)
319  {
320  error << "U(" << uv[0] << ") is less than Umin(" << m_bounds[0]
321  << ")";
322  passed = false;
323  }
324  }
325  else if (uv[0] > m_bounds[1])
326  {
327  if (fabs(uv[0] - m_bounds[1]) > 1E-6)
328  {
329  error << "U(" << uv[0] << ") is greater than Umax(" << m_bounds[1]
330  << ")";
331  passed = false;
332  }
333  }
334  else if (uv[1] < m_bounds[2])
335  {
336  if (fabs(uv[1] - m_bounds[2]) > 1E-6)
337  {
338  error << "V(" << uv[1] << ") is less than Vmin(" << m_bounds[2]
339  << ")";
340  passed = false;
341  }
342  }
343  else if (uv[1] > m_bounds[3])
344  {
345  if (fabs(uv[1] - m_bounds[3]) > 1E-6)
346  {
347  error << "V(" << uv[1] << ") is greater than Vmax(" << m_bounds[3]
348  << ")";
349  passed = false;
350  }
351  }
352 
353  error << " On Surface: " << GetId();
354  ASSERTL1(passed, "Warning: " + error.str());
355 }
int GetId()
Return ID of the vertex.
Definition: CADObject.h:87
Array< OneD, NekDouble > m_bounds
parametric bounds
Definition: CADSurfOCE.h:87
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode...
Definition: ErrorUtil.hpp:228

Member Data Documentation

std::string Nektar::NekMeshUtils::CADSurfOCE::key
static
Initial value:

Definition at line 56 of file CADSurfOCE.h.

Array<OneD, NekDouble> Nektar::NekMeshUtils::CADSurfOCE::m_bounds
private

parametric bounds

Definition at line 87 of file CADSurfOCE.h.

BRepAdaptor_Surface Nektar::NekMeshUtils::CADSurfOCE::m_occSurface
private

OpenCascade object for surface.

Definition at line 83 of file CADSurfOCE.h.

ShapeAnalysis_Surface* Nektar::NekMeshUtils::CADSurfOCE::m_sas
private

locuv object (stored because it gets faster with stored information)

Definition at line 89 of file CADSurfOCE.h.