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

#include <CurveMesh.h>

Collaboration diagram for Nektar::NekMeshUtils::CurveMesh:
Collaboration graph
[legend]

Public Member Functions

 CurveMesh (int id, MeshSharedPtr m, std::string expr="0.0")
 default constructor More...
 
 CurveMesh (int id, MeshSharedPtr m, std::vector< NodeSharedPtr > ns)
 
void Mesh ()
 execute meshing More...
 
NodeSharedPtr GetFirstPoint ()
 get id of first node More...
 
NodeSharedPtr GetLastPoint ()
 get id of last node More...
 
std::vector< NodeSharedPtrGetMeshPoints ()
 get list of mesh nodes More...
 
std::vector< EdgeSharedPtrGetMeshEdges ()
 
int GetNumPoints ()
 get the number of points in the curve More...
 
NekDouble GetLength ()
 get the length of the curve More...
 

Private Member Functions

void GetSampleFunction ()
 get node spacing sampling function More...
 
void GetPhiFunction ()
 get node spacing phi function More...
 
NekDouble EvaluateDS (NekDouble s)
 evaluate paramter ds at curve location s More...
 
NekDouble EvaluatePS (NekDouble s)
 evaluate paramter ps at curve location s More...
 

Private Attributes

CADCurveSharedPtr m_cadcurve
 CAD curve. More...
 
NekDouble m_curvelength
 length of the curve in real space More...
 
int m_numSamplePoints
 number of sampling points used in algorithm More...
 
Array< OneD, NekDoublem_bounds
 coords of the ends of the parametric curve More...
 
std::vector< std::vector
< NekDouble > > 
m_dst
 array of function ds evaluations More...
 
std::vector< std::vector
< NekDouble > > 
m_ps
 array of function ps evaluations More...
 
NekDouble Ae
 spacing function evaluation More...
 
NekDouble ds
 ds More...
 
int Ne
 number of edges to be made in the curve as defined by the spacing funtion More...
 
std::vector< NekDoublemeshsvalue
 paramteric coordiates of the mesh nodes More...
 
std::vector< EdgeSharedPtrm_meshedges
 list of mesh edges in the curvemesh More...
 
int m_id
 id of the curvemesh More...
 
MeshSharedPtr m_mesh
 
std::vector< NodeSharedPtrm_meshpoints
 ids of the mesh nodes More...
 
LibUtilities::AnalyticExpressionEvaluator m_bl
 
int m_blID
 

Friends

class MemoryManager< CurveMesh >
 

Detailed Description

Definition at line 57 of file CurveMesh.h.

Constructor & Destructor Documentation

Nektar::NekMeshUtils::CurveMesh::CurveMesh ( int  id,
MeshSharedPtr  m,
std::string  expr = "0.0" 
)
inline

default constructor

Definition at line 65 of file CurveMesh.h.

References Nektar::LibUtilities::AnalyticExpressionEvaluator::DefineFunction(), m_bl, m_blID, m_cadcurve, m_id, and m_mesh.

66  : m_id(id), m_mesh(m)
67  {
68  m_blID = m_bl.DefineFunction("x y z", expr);
69  m_cadcurve = m_mesh->m_cad->GetCurve(m_id);
70  }
LibUtilities::AnalyticExpressionEvaluator m_bl
Definition: CurveMesh.h:178
int m_id
id of the curvemesh
Definition: CurveMesh.h:173
CADCurveSharedPtr m_cadcurve
CAD curve.
Definition: CurveMesh.h:150
int DefineFunction(const std::string &vlist, const std::string &function)
This function allows one to define a function to evaluate. The first argument (vlist) is a list of va...
Nektar::NekMeshUtils::CurveMesh::CurveMesh ( int  id,
MeshSharedPtr  m,
std::vector< NodeSharedPtr ns 
)
inline

Definition at line 72 of file CurveMesh.h.

References m_cadcurve, m_id, and m_mesh.

73  : m_id(id), m_mesh(m), m_meshpoints(ns)
74  {
75  m_cadcurve = m_mesh->m_cad->GetCurve(m_id);
76  }
int m_id
id of the curvemesh
Definition: CurveMesh.h:173
std::vector< NodeSharedPtr > m_meshpoints
ids of the mesh nodes
Definition: CurveMesh.h:177
CADCurveSharedPtr m_cadcurve
CAD curve.
Definition: CurveMesh.h:150

Member Function Documentation

NekDouble Nektar::NekMeshUtils::CurveMesh::EvaluateDS ( NekDouble  s)
private

evaluate paramter ds at curve location s

Definition at line 212 of file CurveMesh.cpp.

References ASSERTL0, and ASSERTL1.

213 {
214  int a = 0;
215  int b = 0;
216 
217  ASSERTL1(!(s < 0) && !(s > m_curvelength),"s out of bounds");
218 
219  if (s == 0)
220  {
221  return m_dst[0][0];
222  }
223  else if (s == m_curvelength)
224  {
225  return m_dst[m_numSamplePoints - 1][0];
226  }
227 
228  for (int i = 0; i < m_numSamplePoints - 1; i++)
229  {
230  if (m_dst[i][1] < s && m_dst[i + 1][1] >= s)
231  {
232  a = i;
233  b = i + 1;
234  break;
235  }
236  }
237 
238  NekDouble s1 = m_dst[a][1];
239  NekDouble s2 = m_dst[b][1];
240  NekDouble d1 = m_dst[a][0];
241  NekDouble d2 = m_dst[b][0];
242 
243  NekDouble m = (d2 - d1) / (s2 - s1);
244  NekDouble c = d2 - m * s2;
245 
246  ASSERTL0(m * s + c == m * s + c, "DS"); // was getting nans here
247 
248  return m * s + c;
249 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:198
int m_numSamplePoints
number of sampling points used in algorithm
Definition: CurveMesh.h:154
double NekDouble
NekDouble m_curvelength
length of the curve in real space
Definition: CurveMesh.h:152
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode...
Definition: ErrorUtil.hpp:228
std::vector< std::vector< NekDouble > > m_dst
array of function ds evaluations
Definition: CurveMesh.h:158
NekDouble Nektar::NekMeshUtils::CurveMesh::EvaluatePS ( NekDouble  s)
private

evaluate paramter ps at curve location s

Definition at line 251 of file CurveMesh.cpp.

References ASSERTL0, and ASSERTL1.

252 {
253  int a = 0;
254  int b = 0;
255 
256  ASSERTL1(!(s < 0) && !(s > m_curvelength),"s out of bounds");
257 
258  if (s == 0)
259  {
260  return m_ps[0][0];
261  }
262  else if (s == m_curvelength)
263  {
264  return m_ps[m_numSamplePoints - 1][0];
265  }
266 
267  for (int i = 0; i < m_numSamplePoints - 1; i++)
268  {
269  if (m_ps[i][1] < s && m_ps[i + 1][1] >= s)
270  {
271  a = i;
272  b = i + 1;
273  break;
274  }
275  }
276 
277  if (a == b)
278  {
279  cout << endl;
280  cout << a << " " << b << endl;
281  cout << s << endl;
282  exit(-1);
283  }
284 
285  NekDouble s1 = m_ps[a][1];
286  NekDouble s2 = m_ps[b][1];
287  NekDouble d1 = m_ps[a][0];
288  NekDouble d2 = m_ps[b][0];
289 
290  NekDouble m = (d2 - d1) / (s2 - s1);
291  NekDouble c = d2 - m * s2;
292 
293  ASSERTL0(m * s + c == m * s + c, "PS");
294 
295  return m * s + c;
296 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:198
int m_numSamplePoints
number of sampling points used in algorithm
Definition: CurveMesh.h:154
std::vector< std::vector< NekDouble > > m_ps
array of function ps evaluations
Definition: CurveMesh.h:160
double NekDouble
NekDouble m_curvelength
length of the curve in real space
Definition: CurveMesh.h:152
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode...
Definition: ErrorUtil.hpp:228
NodeSharedPtr Nektar::NekMeshUtils::CurveMesh::GetFirstPoint ( )
inline

get id of first node

Definition at line 86 of file CurveMesh.h.

References m_meshpoints.

87  {
88  return m_meshpoints[0];
89  }
std::vector< NodeSharedPtr > m_meshpoints
ids of the mesh nodes
Definition: CurveMesh.h:177
NodeSharedPtr Nektar::NekMeshUtils::CurveMesh::GetLastPoint ( )
inline

get id of last node

Definition at line 94 of file CurveMesh.h.

References m_meshpoints.

95  {
96  return m_meshpoints.back();
97  }
std::vector< NodeSharedPtr > m_meshpoints
ids of the mesh nodes
Definition: CurveMesh.h:177
NekDouble Nektar::NekMeshUtils::CurveMesh::GetLength ( )
inline

get the length of the curve

Definition at line 123 of file CurveMesh.h.

References m_curvelength.

124  {
125  return m_curvelength;
126  }
NekDouble m_curvelength
length of the curve in real space
Definition: CurveMesh.h:152
std::vector<EdgeSharedPtr> Nektar::NekMeshUtils::CurveMesh::GetMeshEdges ( )
inline

Definition at line 107 of file CurveMesh.h.

References m_meshedges.

108  {
109  return m_meshedges;
110  }
std::vector< EdgeSharedPtr > m_meshedges
list of mesh edges in the curvemesh
Definition: CurveMesh.h:171
std::vector<NodeSharedPtr> Nektar::NekMeshUtils::CurveMesh::GetMeshPoints ( )
inline

get list of mesh nodes

Definition at line 102 of file CurveMesh.h.

References m_meshpoints.

103  {
104  return m_meshpoints;
105  }
std::vector< NodeSharedPtr > m_meshpoints
ids of the mesh nodes
Definition: CurveMesh.h:177
int Nektar::NekMeshUtils::CurveMesh::GetNumPoints ( )
inline

get the number of points in the curve

Definition at line 115 of file CurveMesh.h.

References m_meshpoints.

116  {
117  return m_meshpoints.size();
118  }
std::vector< NodeSharedPtr > m_meshpoints
ids of the mesh nodes
Definition: CurveMesh.h:177
void Nektar::NekMeshUtils::CurveMesh::GetPhiFunction ( )
private

get node spacing phi function

Definition at line 190 of file CurveMesh.cpp.

191 {
192  m_ps.resize(m_numSamplePoints);
193  vector<NekDouble> newPhi;
194  newPhi.resize(2);
195 
196  newPhi[0] = 0.0;
197  newPhi[1] = 0.0;
198 
199  m_ps[0] = newPhi;
200 
201  NekDouble runningInt = 0.0;
202 
203  for (int i = 1; i < m_numSamplePoints; i++)
204  {
205  runningInt += (1.0 / m_dst[i - 1][0] + 1.0 / m_dst[i][0]) / 2.0 * ds;
206  newPhi[0] = Ne / Ae * runningInt;
207  newPhi[1] = m_dst[i][1];
208  m_ps[i] = newPhi;
209  }
210 }
int m_numSamplePoints
number of sampling points used in algorithm
Definition: CurveMesh.h:154
std::vector< std::vector< NekDouble > > m_ps
array of function ps evaluations
Definition: CurveMesh.h:160
NekDouble Ae
spacing function evaluation
Definition: CurveMesh.h:162
int Ne
number of edges to be made in the curve as defined by the spacing funtion
Definition: CurveMesh.h:167
double NekDouble
std::vector< std::vector< NekDouble > > m_dst
array of function ds evaluations
Definition: CurveMesh.h:158
void Nektar::NekMeshUtils::CurveMesh::GetSampleFunction ( )
private

get node spacing sampling function

Definition at line 298 of file CurveMesh.cpp.

299 {
300  m_dst.resize(m_numSamplePoints);
301 
302  vector<NekDouble> dsti;
303  dsti.resize(3);
304 
305  for (int i = 0; i < m_numSamplePoints; i++)
306  {
307  dsti[1] = i * ds;
308  NekDouble t = m_cadcurve->tAtArcLength(dsti[1]);
309 
310  Array<OneD, NekDouble> loc = m_cadcurve->P(t);
311 
312  /*NekDouble ts =
313  m_bl.Evaluate(m_blID, loc[0], loc[1], loc[2], 0.0);
314 
315  if (ts > 0.0)
316  {
317  Array<OneD, NekDouble> N = m_cadcurve->N(t);
318  Array<OneD, NekDouble> Nwrt = m_cadcurve->NormalWRT(t, 0);
319 
320  if(N[0]*N[0] + N[1]*N[1] + N[2]*N[2] < 1e-6)
321  {
322  dsti[0] = m_mesh->m_octree->Query(loc);
323  }
324  else if ( N[0]*Nwrt[0] + N[1]*Nwrt[1] + N[2]*Nwrt[2] > 0)
325  {
326  //concave
327  dsti[0] = m_mesh->m_octree->Query(loc);
328  }
329  else
330  {
331  NekDouble R = 1.0 / m_cadcurve->Curvature(t);
332  if(R > 2.0*t)
333  {
334  R = 2.0*t;
335  }
336  Array<OneD, NekDouble> tloc(3);
337  tloc[0] = loc[0] + ts * Nwrt[0];
338  tloc[1] = loc[1] + ts * Nwrt[1];
339  tloc[2] = loc[2] + ts * Nwrt[2];
340 
341  NekDouble d = m_mesh->m_octree->Query(tloc);
342 
343  dsti[0] = d * R / (R + ts);
344  }
345  }
346  else
347  {*/
348  dsti[0] = m_mesh->m_octree->Query(loc);
349  //}
350 
351  dsti[2] = t;
352 
353  m_dst[i] = dsti;
354  }
355 }
int m_numSamplePoints
number of sampling points used in algorithm
Definition: CurveMesh.h:154
double NekDouble
CADCurveSharedPtr m_cadcurve
CAD curve.
Definition: CurveMesh.h:150
std::vector< std::vector< NekDouble > > m_dst
array of function ds evaluations
Definition: CurveMesh.h:158
void Nektar::NekMeshUtils::CurveMesh::Mesh ( )

execute meshing

Definition at line 45 of file CurveMesh.cpp.

References ASSERTL0, and class_topology::Node.

46 {
47  // this algorithm is mostly based on the work in chapter 19
48 
49  m_bounds = m_cadcurve->GetBounds();
50  m_curvelength = m_cadcurve->GetTotLength();
52  int(m_curvelength / m_mesh->m_octree->GetMinDelta()) + 10;
54 
56 
57  Ae = 0.0;
58 
59  for (int i = 0; i < m_numSamplePoints - 1; i++)
60  {
61  Ae += ds * (1.0 / m_dst[i][0] + 1.0 / m_dst[i + 1][0]) / 2.0;
62  }
63 
64  Ne = round(Ae);
65 
66  if (Ne + 1 < 2)
67  {
68  meshsvalue.resize(2);
69  meshsvalue[0] = 0.0;
71  Ne = 1;
72  }
73  else
74  {
75 
77 
78  meshsvalue.resize(Ne + 1);
79  meshsvalue[0] = 0.0;
81 
82  for (int i = 1; i < Ne; i++)
83  {
84  int iterationcounter = 0;
85  bool iterate = true;
86  int k = i;
87  NekDouble ski = meshsvalue[i - 1];
88  NekDouble lastSki;
89  while (iterate)
90  {
91  iterationcounter++;
92  NekDouble rhs = EvaluateDS(ski) / Ae * (EvaluatePS(ski) - k);
93  lastSki = ski;
94  ski = ski - rhs;
95  if (abs(lastSki - ski) < 1E-8)
96  {
97  iterate = false;
98  }
99 
100  ASSERTL0(iterationcounter < 1000000, "iteration failed");
101  }
102 
103  meshsvalue[i] = ski;
104  }
105  }
106 
107  NekDouble t;
108  Array<OneD, NekDouble> loc;
109 
110  vector<CADVertSharedPtr> verts = m_cadcurve->GetVertex();
111  vector<pair<CADSurfSharedPtr, CADOrientation::Orientation> > s = m_cadcurve->GetAdjSurf();
112 
113  NodeSharedPtr n = verts[0]->GetNode();
114  t = m_bounds[0];
115  n->SetCADCurve(m_id, m_cadcurve, t);
116  loc = n->GetLoc();
117  for (int j = 0; j < s.size(); j++)
118  {
119  if (verts[0]->IsDegen() == s[j].first->GetId())
120  {
121  // if the degen has been set for this node the node
122  // already knows its corrected location
123  continue;
124  }
125 
126  Array<OneD, NekDouble> uv = s[j].first->locuv(loc);
127  n->SetCADSurf(s[j].first->GetId(), s[j].first, uv);
128  }
129  m_meshpoints.push_back(n);
130 
131  for (int i = 1; i < meshsvalue.size() - 1; i++)
132  {
133  t = m_cadcurve->tAtArcLength(meshsvalue[i]);
134  loc = m_cadcurve->P(t);
135  NodeSharedPtr n2 = boost::shared_ptr<Node>(
136  new Node(m_mesh->m_numNodes++, loc[0], loc[1], loc[2]));
137  n2->SetCADCurve(m_id, m_cadcurve, t);
138  for (int j = 0; j < s.size(); j++)
139  {
140  Array<OneD, NekDouble> uv = s[j].first->locuv(loc);
141  n2->SetCADSurf(s[j].first->GetId(), s[j].first, uv);
142  }
143  m_meshpoints.push_back(n2);
144  }
145 
146  n = verts[1]->GetNode();
147  t = m_bounds[1];
148  n->SetCADCurve(m_id, m_cadcurve, t);
149  loc = n->GetLoc();
150  for (int j = 0; j < s.size(); j++)
151  {
152  if (verts[1]->IsDegen() == s[j].first->GetId())
153  {
154  // if the degen has been set for this node the node
155  // already knows its corrected location
156  continue;
157  }
158 
159  Array<OneD, NekDouble> uv = s[j].first->locuv(loc);
160  n->SetCADSurf(s[j].first->GetId(), s[j].first, uv);
161  }
162  m_meshpoints.push_back(n);
163 
164  ASSERTL0(Ne + 1 == m_meshpoints.size(),
165  "incorrect number of points in curve mesh");
166 
167  // make edges and add them to the edgeset for the face mesher to use
168  for (int i = 0; i < m_meshpoints.size() - 1; i++)
169  {
170  EdgeSharedPtr e = boost::shared_ptr<Edge>(
171  new Edge(m_meshpoints[i], m_meshpoints[i + 1]));
172  e->m_parentCAD = m_cadcurve;
173  m_mesh->m_edgeSet.insert(e);
174  m_meshedges.push_back(e);
175  }
176 
177  if (m_mesh->m_verbose)
178  {
179  cout << "\r "
180  " "
181  " ";
182  cout << scientific << "\r\t\tCurve " << m_id << endl
183  << "\t\t\tLength: " << m_curvelength << endl
184  << "\t\t\tNodes: " << m_meshpoints.size() << endl
185  << "\t\t\tSample points: " << m_numSamplePoints << endl
186  << endl;
187  }
188 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:198
void GetSampleFunction()
get node spacing sampling function
Definition: CurveMesh.cpp:298
Array< OneD, NekDouble > m_bounds
coords of the ends of the parametric curve
Definition: CurveMesh.h:156
int m_numSamplePoints
number of sampling points used in algorithm
Definition: CurveMesh.h:154
NekDouble Ae
spacing function evaluation
Definition: CurveMesh.h:162
std::vector< EdgeSharedPtr > m_meshedges
list of mesh edges in the curvemesh
Definition: CurveMesh.h:171
int m_id
id of the curvemesh
Definition: CurveMesh.h:173
int Ne
number of edges to be made in the curve as defined by the spacing funtion
Definition: CurveMesh.h:167
std::vector< NodeSharedPtr > m_meshpoints
ids of the mesh nodes
Definition: CurveMesh.h:177
boost::shared_ptr< Node > NodeSharedPtr
Definition: Node.h:50
double NekDouble
CADCurveSharedPtr m_cadcurve
CAD curve.
Definition: CurveMesh.h:150
boost::shared_ptr< Edge > EdgeSharedPtr
Shared pointer to an edge.
Definition: Edge.h:136
void GetPhiFunction()
get node spacing phi function
Definition: CurveMesh.cpp:190
NekDouble m_curvelength
length of the curve in real space
Definition: CurveMesh.h:152
NekDouble EvaluateDS(NekDouble s)
evaluate paramter ds at curve location s
Definition: CurveMesh.cpp:212
NekDouble EvaluatePS(NekDouble s)
evaluate paramter ps at curve location s
Definition: CurveMesh.cpp:251
std::vector< std::vector< NekDouble > > m_dst
array of function ds evaluations
Definition: CurveMesh.h:158
std::vector< NekDouble > meshsvalue
paramteric coordiates of the mesh nodes
Definition: CurveMesh.h:169

Friends And Related Function Documentation

friend class MemoryManager< CurveMesh >
friend

Definition at line 60 of file CurveMesh.h.

Member Data Documentation

NekDouble Nektar::NekMeshUtils::CurveMesh::Ae
private

spacing function evaluation

Definition at line 162 of file CurveMesh.h.

NekDouble Nektar::NekMeshUtils::CurveMesh::ds
private

ds

Definition at line 164 of file CurveMesh.h.

LibUtilities::AnalyticExpressionEvaluator Nektar::NekMeshUtils::CurveMesh::m_bl
private

Definition at line 178 of file CurveMesh.h.

Referenced by CurveMesh().

int Nektar::NekMeshUtils::CurveMesh::m_blID
private

Definition at line 179 of file CurveMesh.h.

Referenced by CurveMesh().

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

coords of the ends of the parametric curve

Definition at line 156 of file CurveMesh.h.

CADCurveSharedPtr Nektar::NekMeshUtils::CurveMesh::m_cadcurve
private

CAD curve.

Definition at line 150 of file CurveMesh.h.

Referenced by CurveMesh().

NekDouble Nektar::NekMeshUtils::CurveMesh::m_curvelength
private

length of the curve in real space

Definition at line 152 of file CurveMesh.h.

Referenced by GetLength().

std::vector<std::vector<NekDouble> > Nektar::NekMeshUtils::CurveMesh::m_dst
private

array of function ds evaluations

Definition at line 158 of file CurveMesh.h.

int Nektar::NekMeshUtils::CurveMesh::m_id
private

id of the curvemesh

Definition at line 173 of file CurveMesh.h.

Referenced by CurveMesh().

MeshSharedPtr Nektar::NekMeshUtils::CurveMesh::m_mesh
private

Definition at line 175 of file CurveMesh.h.

Referenced by CurveMesh().

std::vector<EdgeSharedPtr> Nektar::NekMeshUtils::CurveMesh::m_meshedges
private

list of mesh edges in the curvemesh

Definition at line 171 of file CurveMesh.h.

Referenced by GetMeshEdges().

std::vector<NodeSharedPtr> Nektar::NekMeshUtils::CurveMesh::m_meshpoints
private

ids of the mesh nodes

Definition at line 177 of file CurveMesh.h.

Referenced by GetFirstPoint(), GetLastPoint(), GetMeshPoints(), and GetNumPoints().

int Nektar::NekMeshUtils::CurveMesh::m_numSamplePoints
private

number of sampling points used in algorithm

Definition at line 154 of file CurveMesh.h.

std::vector<std::vector<NekDouble> > Nektar::NekMeshUtils::CurveMesh::m_ps
private

array of function ps evaluations

Definition at line 160 of file CurveMesh.h.

std::vector<NekDouble> Nektar::NekMeshUtils::CurveMesh::meshsvalue
private

paramteric coordiates of the mesh nodes

Definition at line 169 of file CurveMesh.h.

int Nektar::NekMeshUtils::CurveMesh::Ne
private

number of edges to be made in the curve as defined by the spacing funtion

Definition at line 167 of file CurveMesh.h.