Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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, CADCurveSharedPtr c, OctreeSharedPtr o)
 default constructor More...
 
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...
 
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...
 
OctreeSharedPtr m_octree
 Octree object. 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< NodeSharedPtrm_meshpoints
 ids of the mesh nodes More...
 
int m_id
 id of the curvemesh More...
 
MeshSharedPtr m_mesh
 

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,
CADCurveSharedPtr  c,
OctreeSharedPtr  o 
)
inline

default constructor

Definition at line 65 of file CurveMesh.h.

66  : m_cadcurve(c), m_octree(o), m_id(id), m_mesh(m){};
int m_id
id of the curvemesh
Definition: CurveMesh.h:160
OctreeSharedPtr m_octree
Octree object.
Definition: CurveMesh.h:137
CADCurveSharedPtr m_cadcurve
CAD curve.
Definition: CurveMesh.h:135

Member Function Documentation

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

evaluate paramter ds at curve location s

Definition at line 261 of file CurveMesh.cpp.

References ASSERTL0.

262 {
263  int a = 0;
264  int b = 0;
265 
266  if (s == 0)
267  {
268  return m_dst[0][0];
269  }
270  else if (s == m_curvelength)
271  {
272  return m_dst[m_numSamplePoints - 1][0];
273  }
274 
275  for (int i = 0; i < m_numSamplePoints - 1; i++)
276  {
277  if (m_dst[i][1] < s && m_dst[i + 1][1] >= s)
278  {
279  a = i;
280  b = i + 1;
281  break;
282  }
283  }
284 
285  NekDouble s1 = m_dst[a][1];
286  NekDouble s2 = m_dst[b][1];
287  NekDouble d1 = m_dst[a][0];
288  NekDouble d2 = m_dst[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, "DS"); // was getting nans here
294 
295  return m * s + c;
296 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161
int m_numSamplePoints
number of sampling points used in algorithm
Definition: CurveMesh.h:141
double NekDouble
NekDouble m_curvelength
length of the curve in real space
Definition: CurveMesh.h:139
std::vector< std::vector< NekDouble > > m_dst
array of function ds evaluations
Definition: CurveMesh.h:145
NekDouble Nektar::NekMeshUtils::CurveMesh::EvaluatePS ( NekDouble  s)
private

evaluate paramter ps at curve location s

Definition at line 298 of file CurveMesh.cpp.

References ASSERTL0.

299 {
300  int a = 0;
301  int b = 0;
302 
303  if (s == 0)
304  {
305  return m_ps[0][0];
306  }
307  else if (s == m_curvelength)
308  {
309  return m_ps[m_numSamplePoints - 1][0];
310  }
311 
312  for (int i = 0; i < m_numSamplePoints - 1; i++)
313  {
314  if (m_ps[i][1] < s && m_ps[i + 1][1] >= s)
315  {
316  a = i;
317  b = i + 1;
318  break;
319  }
320  }
321 
322  if (a == b)
323  {
324  cout << endl;
325  cout << a << " " << b << endl;
326  cout << s << endl;
327  exit(-1);
328  }
329 
330  NekDouble s1 = m_ps[a][1];
331  NekDouble s2 = m_ps[b][1];
332  NekDouble d1 = m_ps[a][0];
333  NekDouble d2 = m_ps[b][0];
334 
335  NekDouble m = (d2 - d1) / (s2 - s1);
336  NekDouble c = d2 - m * s2;
337 
338  ASSERTL0(m * s + c == m * s + c, "PS");
339 
340  return m * s + c;
341 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161
int m_numSamplePoints
number of sampling points used in algorithm
Definition: CurveMesh.h:141
std::vector< std::vector< NekDouble > > m_ps
array of function ps evaluations
Definition: CurveMesh.h:147
double NekDouble
NekDouble m_curvelength
length of the curve in real space
Definition: CurveMesh.h:139
NodeSharedPtr Nektar::NekMeshUtils::CurveMesh::GetFirstPoint ( )
inline

get id of first node

Definition at line 76 of file CurveMesh.h.

References m_meshpoints.

77  {
78  return m_meshpoints[0];
79  }
std::vector< NodeSharedPtr > m_meshpoints
ids of the mesh nodes
Definition: CurveMesh.h:158
NodeSharedPtr Nektar::NekMeshUtils::CurveMesh::GetLastPoint ( )
inline

get id of last node

Definition at line 84 of file CurveMesh.h.

References m_meshpoints.

85  {
86  return m_meshpoints.back();
87  }
std::vector< NodeSharedPtr > m_meshpoints
ids of the mesh nodes
Definition: CurveMesh.h:158
NekDouble Nektar::NekMeshUtils::CurveMesh::GetLength ( )
inline

get the length of the curve

Definition at line 108 of file CurveMesh.h.

References m_curvelength.

109  {
110  return m_curvelength;
111  }
NekDouble m_curvelength
length of the curve in real space
Definition: CurveMesh.h:139
std::vector<NodeSharedPtr> Nektar::NekMeshUtils::CurveMesh::GetMeshPoints ( )
inline

get list of mesh nodes

Definition at line 92 of file CurveMesh.h.

References m_meshpoints.

93  {
94  return m_meshpoints;
95  }
std::vector< NodeSharedPtr > m_meshpoints
ids of the mesh nodes
Definition: CurveMesh.h:158
int Nektar::NekMeshUtils::CurveMesh::GetNumPoints ( )
inline

get the number of points in the curve

Definition at line 100 of file CurveMesh.h.

References m_meshpoints.

101  {
102  return m_meshpoints.size();
103  }
std::vector< NodeSharedPtr > m_meshpoints
ids of the mesh nodes
Definition: CurveMesh.h:158
void Nektar::NekMeshUtils::CurveMesh::GetPhiFunction ( )
private

get node spacing phi function

Definition at line 239 of file CurveMesh.cpp.

240 {
241  m_ps.resize(m_numSamplePoints);
242  vector<NekDouble> newPhi;
243  newPhi.resize(2);
244 
245  newPhi[0] = 0.0;
246  newPhi[1] = 0.0;
247 
248  m_ps[0] = newPhi;
249 
250  NekDouble runningInt = 0.0;
251 
252  for (int i = 1; i < m_numSamplePoints; i++)
253  {
254  runningInt += (1.0 / m_dst[i - 1][0] + 1.0 / m_dst[i][0]) / 2.0 * ds;
255  newPhi[0] = Ne / Ae * runningInt;
256  newPhi[1] = m_dst[i][1];
257  m_ps[i] = newPhi;
258  }
259 }
int m_numSamplePoints
number of sampling points used in algorithm
Definition: CurveMesh.h:141
std::vector< std::vector< NekDouble > > m_ps
array of function ps evaluations
Definition: CurveMesh.h:147
NekDouble Ae
spacing function evaluation
Definition: CurveMesh.h:149
int Ne
number of edges to be made in the curve as defined by the spacing funtion
Definition: CurveMesh.h:154
double NekDouble
std::vector< std::vector< NekDouble > > m_dst
array of function ds evaluations
Definition: CurveMesh.h:145
void Nektar::NekMeshUtils::CurveMesh::GetSampleFunction ( )
private

get node spacing sampling function

Definition at line 343 of file CurveMesh.cpp.

344 {
345  m_dst.resize(m_numSamplePoints);
346  Array<OneD, NekDouble> loc = m_cadcurve->P(m_bounds[0]);
347 
348  vector<NekDouble> dsti;
349  dsti.resize(3);
350 
351  dsti[0] = m_octree->Query(loc);
352  dsti[1] = 0.0;
353  dsti[2] = m_bounds[0];
354 
355  m_dst[0] = dsti;
356 
357  for (int i = 1; i < m_numSamplePoints; i++)
358  {
359  dsti[1] = i * ds;
360  NekDouble t = m_cadcurve->tAtArcLength(dsti[1]);
361 
362  loc = m_cadcurve->P(t);
363 
364  dsti[0] = m_octree->Query(loc);
365  dsti[2] = t;
366 
367  m_dst[i] = dsti;
368  }
369 }
Array< OneD, NekDouble > m_bounds
coords of the ends of the parametric curve
Definition: CurveMesh.h:143
int m_numSamplePoints
number of sampling points used in algorithm
Definition: CurveMesh.h:141
OctreeSharedPtr m_octree
Octree object.
Definition: CurveMesh.h:137
double NekDouble
CADCurveSharedPtr m_cadcurve
CAD curve.
Definition: CurveMesh.h:135
std::vector< std::vector< NekDouble > > m_dst
array of function ds evaluations
Definition: CurveMesh.h:145
void Nektar::NekMeshUtils::CurveMesh::Mesh ( )

execute meshing

Definition at line 44 of file CurveMesh.cpp.

References ASSERTL0.

45 {
46  m_bounds = m_cadcurve->Bounds();
47  m_curvelength = m_cadcurve->GetTotLength();
48  m_numSamplePoints = int(m_curvelength / m_octree->GetMinDelta()) + 5;
50 
52 
53  Ae = 0.0;
54 
55  for (int i = 0; i < m_numSamplePoints - 1; i++)
56  {
57  Ae += ds * (1.0 / m_dst[i][0] + 1.0 / m_dst[i + 1][0]) / 2.0;
58  }
59 
60  Ne = round(Ae);
61 
62  if (Ne + 1 < 2)
63  {
64  meshsvalue.resize(2);
65  meshsvalue[0] = 0.0;
67  Ne = 1;
68  }
69  else
70  {
71 
73 
74  meshsvalue.resize(Ne + 1);
75  meshsvalue[0] = 0.0;
77 
78  for (int i = 1; i < Ne; i++)
79  {
80  int iterationcounter = 0;
81  bool iterate = true;
82  int k = i;
83  NekDouble ski = meshsvalue[i - 1];
84  NekDouble lastSki;
85  while (iterate)
86  {
87  iterationcounter++;
88  NekDouble rhs = EvaluateDS(ski) / Ae * (EvaluatePS(ski) - k);
89  lastSki = ski;
90  ski = ski - rhs;
91  if (abs(lastSki - ski) < 1E-10)
92  {
93  iterate = false;
94  }
95 
96  ASSERTL0(iterationcounter < 1000000, "iteration failed");
97  }
98 
99  meshsvalue[i] = ski;
100  }
101  }
102 
103  NekDouble t;
104  Array<OneD, NekDouble> loc;
105 
106  vector<CADVertSharedPtr> verts = m_cadcurve->GetVertex();
107  vector<CADSurfSharedPtr> s = m_cadcurve->GetAdjSurf();
108  ASSERTL0(s.size() == 2, "invalid curve");
109 
110  NodeSharedPtr n = verts[0]->GetNode();
111  t = m_bounds[0];
112  n->SetCADCurve(m_id, m_cadcurve, t);
113  loc = n->GetLoc();
114  for (int j = 0; j < 2; j++)
115  {
116  if (verts[0]->IsDegen() == s[j]->GetId()) // if the degen has been set
117  // for this node the node
118  // already knows its corrected
119  // location
120  continue;
121 
122  Array<OneD, NekDouble> uv = s[j]->locuv(loc);
123  n->SetCADSurf(s[j]->GetId(), s[j], uv);
124  }
125  m_meshpoints.push_back(n);
126 
127  for (int i = 1; i < meshsvalue.size() - 1; i++)
128  {
129  t = m_cadcurve->tAtArcLength(meshsvalue[i]);
130  loc = m_cadcurve->P(t);
131  NodeSharedPtr n2 = boost::shared_ptr<Node>(
132  new Node(m_mesh->m_numNodes++, loc[0], loc[1], loc[2]));
133  n2->SetCADCurve(m_id, m_cadcurve, t);
134  for (int j = 0; j < 2; j++)
135  {
136  Array<OneD, NekDouble> uv = s[j]->locuv(loc);
137  n2->SetCADSurf(s[j]->GetId(), s[j], uv);
138  }
139  m_meshpoints.push_back(n2);
140  }
141 
142  n = verts[1]->GetNode();
143  t = m_bounds[1];
144  n->SetCADCurve(m_id, m_cadcurve, t);
145  loc = n->GetLoc();
146  for (int j = 0; j < 2; j++)
147  {
148  if (verts[1]->IsDegen() == s[j]->GetId()) // if the degen has been set
149  // for this node the node
150  // already knows its corrected
151  // location
152  continue;
153 
154  Array<OneD, NekDouble> uv = s[j]->locuv(loc);
155  n->SetCADSurf(s[j]->GetId(), s[j], uv);
156  }
157  m_meshpoints.push_back(n);
158 
159  ASSERTL0(Ne + 1 == m_meshpoints.size(),
160  "incorrect number of points in curve mesh");
161 
162  for (int i = 0; i < m_meshpoints.size(); i++)
163  {
164  Array<OneD, NekDouble> loc = m_meshpoints[i]->GetLoc();
165  for (int j = 0; j < 2; j++)
166  {
167  Array<OneD, NekDouble> uv = s[j]->locuv(loc);
168  m_meshpoints[i]->SetCADSurf(s[j]->GetId(), s[j], uv);
169  }
170  }
171 
172  /*//post process the curve mesh to analyse for bad segments based on
173  high-order normals and split if needed
174  int ct = 1;
175  while(ct > 0)
176  {
177  ct = 0;
178  for(int i = 0; i < m_meshpoints.size() - 1; i++)
179  {
180  bool split = false;
181  for(int j = 0; j < 2; j++)
182  {
183  Array<OneD, NekDouble> uv1, uv2;
184  uv1 = m_meshpoints[i]->GetCADSurfInfo(s[j]->GetId());
185  uv2 = m_meshpoints[i+1]->GetCADSurfInfo(s[j]->GetId());
186  Array<OneD, NekDouble> N1, N2;
187  N1 = s[j]->N(uv1);
188  N2 = s[j]->N(uv2);
189  NekDouble dot = N1[0]*N2[0] + N1[1]*N2[1] + N1[2]*N2[2];
190  if(acos(dot) > 3.142/2.0-0.1)
191  {
192  split = true;
193  }
194  }
195 
196  if(split)
197  {
198  ct++;
199  NekDouble t1, t2;
200  t1 = m_meshpoints[i]->GetCADCurveInfo(m_id);
201  t2 = m_meshpoints[i+1]->GetCADCurveInfo(m_id);
202  NekDouble tn = (t1 + t2)/2.0;
203  Array<OneD, NekDouble> loc = m_cadcurve->P(tn);
204  NodeSharedPtr nn = boost::shared_ptr<Node>(new
205  Node(m_mesh->m_numNodes++,
206  loc[0],loc[1],loc[2]));
207  nn->SetCADCurve(m_id, m_cadcurve, tn);
208  for(int j = 0; j < 2; j++)
209  {
210  Array<OneD, NekDouble> uv = s[j]->locuv(loc);
211  nn->SetCADSurf(s[j]->GetId(), s[j], uv);
212  }
213  m_meshpoints.insert(m_meshpoints.begin() + i+1, nn);
214  break;
215  }
216  }
217  }*/
218 
219  // make edges and add them to the edgeset for the face mesher to use
220  for (int i = 0; i < m_meshpoints.size() - 1; i++)
221  {
222  EdgeSharedPtr e = boost::shared_ptr<Edge>(
223  new Edge(m_meshpoints[i], m_meshpoints[i + 1]));
224  e->CADCurveId = m_id;
225  e->CADCurve = m_cadcurve;
226  e->onCurve = true;
227  m_mesh->m_edgeSet.insert(e);
228  }
229 
230  cout << "\r "
231  " ";
232  cout << scientific << "\r\t\tCurve " << m_id << endl
233  << "\t\t\tLength: " << m_curvelength << endl
234  << "\t\t\tNodes: " << m_meshpoints.size() << endl
235  << "\t\t\tSample points: " << m_numSamplePoints << endl
236  << endl;
237 }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161
void GetSampleFunction()
get node spacing sampling function
Definition: CurveMesh.cpp:343
Array< OneD, NekDouble > m_bounds
coords of the ends of the parametric curve
Definition: CurveMesh.h:143
int m_numSamplePoints
number of sampling points used in algorithm
Definition: CurveMesh.h:141
NekDouble Ae
spacing function evaluation
Definition: CurveMesh.h:149
int m_id
id of the curvemesh
Definition: CurveMesh.h:160
OctreeSharedPtr m_octree
Octree object.
Definition: CurveMesh.h:137
int Ne
number of edges to be made in the curve as defined by the spacing funtion
Definition: CurveMesh.h:154
std::vector< NodeSharedPtr > m_meshpoints
ids of the mesh nodes
Definition: CurveMesh.h:158
boost::shared_ptr< Node > NodeSharedPtr
Definition: Node.h:50
double NekDouble
CADCurveSharedPtr m_cadcurve
CAD curve.
Definition: CurveMesh.h:135
boost::shared_ptr< Edge > EdgeSharedPtr
Shared pointer to an edge.
Definition: Edge.h:196
void GetPhiFunction()
get node spacing phi function
Definition: CurveMesh.cpp:239
NekDouble m_curvelength
length of the curve in real space
Definition: CurveMesh.h:139
NekDouble EvaluateDS(NekDouble s)
evaluate paramter ds at curve location s
Definition: CurveMesh.cpp:261
NekDouble EvaluatePS(NekDouble s)
evaluate paramter ps at curve location s
Definition: CurveMesh.cpp:298
std::vector< std::vector< NekDouble > > m_dst
array of function ds evaluations
Definition: CurveMesh.h:145
std::vector< NekDouble > meshsvalue
paramteric coordiates of the mesh nodes
Definition: CurveMesh.h:156

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 149 of file CurveMesh.h.

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

ds

Definition at line 151 of file CurveMesh.h.

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

coords of the ends of the parametric curve

Definition at line 143 of file CurveMesh.h.

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

CAD curve.

Definition at line 135 of file CurveMesh.h.

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

length of the curve in real space

Definition at line 139 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 145 of file CurveMesh.h.

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

id of the curvemesh

Definition at line 160 of file CurveMesh.h.

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

Definition at line 162 of file CurveMesh.h.

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

ids of the mesh nodes

Definition at line 158 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 141 of file CurveMesh.h.

OctreeSharedPtr Nektar::NekMeshUtils::CurveMesh::m_octree
private

Octree object.

Definition at line 137 of file CurveMesh.h.

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

array of function ps evaluations

Definition at line 147 of file CurveMesh.h.

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

paramteric coordiates of the mesh nodes

Definition at line 156 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 154 of file CurveMesh.h.