gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
MLine.cpp
Go to the documentation of this file.
1 // Gmsh - Copyright (C) 1997-2022 C. Geuzaine, J.-F. Remacle
2 //
3 // See the LICENSE.txt file in the Gmsh root directory for license information.
4 // Please report all issues on https://gitlab.onelab.info/gmsh/gmsh/issues.
5 
6 #include "GmshDefines.h"
7 #include "MLine.h"
8 #include "nodalBasis.h"
9 #include "BasisFactory.h"
10 #include "GaussLegendre1D.h"
11 #include "Context.h"
12 #include "decasteljau.h"
13 #include "bezierBasis.h"
14 
15 void MLine::getIntegrationPoints(int pOrder, int *npts, IntPt **pts)
16 {
17  *npts = getNGQLPts(pOrder);
18  *pts = getGQLPts(pOrder);
19 }
20 
21 double MLine::getInnerRadius() { return _v[0]->distance(_v[1]) * .5; }
22 
23 double MLine::getLength() { return _v[0]->distance(_v[1]); }
24 
25 double MLine::getVolume() { return getLength(); }
26 
27 int MLine3::getNumEdgesRep(bool curved)
28 {
29  return curved ? CTX::instance()->mesh.numSubEdges : 1;
30 }
31 
32 void MLine3::getEdgeRep(bool curved, int num, double *x, double *y, double *z,
33  SVector3 *n)
34 {
35  if(curved) {
36  int numSubEdges = CTX::instance()->mesh.numSubEdges;
37  SPoint3 pnt1, pnt2;
38  pnt(-1. + 2 * (double)num / numSubEdges, 0., 0., pnt1);
39  pnt(-1. + 2 * (double)(num + 1) / numSubEdges, 0., 0, pnt2);
40  x[0] = pnt1.x();
41  x[1] = pnt2.x();
42  y[0] = pnt1.y();
43  y[1] = pnt2.y();
44  z[0] = pnt1.z();
45  z[1] = pnt2.z();
46  n[0] = n[1] = MEdge(_v[0], _v[1]).normal();
47  }
48  else
49  MLine::getEdgeRep(false, num, x, y, z, n);
50 }
51 
52 int MLineN::getNumEdgesRep(bool curved)
53 {
54  return curved ? CTX::instance()->mesh.numSubEdges : 1;
55 }
56 
57 void MLineN::getEdgeRep(bool curved, int num, double *x, double *y, double *z,
58  SVector3 *n)
59 {
60  if(curved) {
61  int numSubEdges = CTX::instance()->mesh.numSubEdges;
62  SPoint3 pnt1, pnt2;
63  pnt(-1. + 2 * (double)num / numSubEdges, 0., 0., pnt1);
64  pnt(-1. + 2 * (double)(num + 1) / numSubEdges, 0., 0, pnt2);
65  x[0] = pnt1.x();
66  x[1] = pnt2.x();
67  y[0] = pnt1.y();
68  y[1] = pnt2.y();
69  z[0] = pnt1.z();
70  z[1] = pnt2.z();
71  n[0] = n[1] = MEdge(_v[0], _v[1]).normal();
72  }
73  else
74  MLine::getEdgeRep(false, num, x, y, z, n);
75 }
76 
77 void MLine::discretize(double tol, std::vector<SPoint3> &dpts,
78  std::vector<double> &ts)
79 {
80  ts.clear();
81  ts.push_back(-1);
82  ts.push_back(1);
83  dpts.clear();
84  dpts.push_back(getVertex(0)->point());
85  dpts.push_back(getVertex(1)->point());
86 }
87 
88 void MLine3::discretize(double tol, std::vector<SPoint3> &dpts,
89  std::vector<double> &ts)
90 {
91  SPoint3 p0 = getVertex(0)->point();
92  SPoint3 p2 = getVertex(1)->point();
93  SPoint3 p1 = getVertex(2)->point() * 2 - (p0 + p2) * 0.5;
94  decasteljau(tol, p0, p1, p2, dpts, ts);
95  for(size_t i = 0; i < ts.size(); ++i) ts[i] = -1 + 2 * ts[i];
96 }
97 
98 void MLineN::discretize(double tol, std::vector<SPoint3> &dpts,
99  std::vector<double> &ts)
100 {
101  int order = getPolynomialOrder();
102  if(order == 3) {
103  SPoint3 p0 = getVertex(0)->point();
104  SPoint3 p3 = getVertex(1)->point();
105  SPoint3 p1 = p0 * (-5. / 6) + p3 * (1. / 3) + getVertex(2)->point() * 3. -
106  getVertex(3)->point() * 1.5;
107  SPoint3 p2 = p0 * (1. / 3) + p3 * (-5. / 6) - getVertex(2)->point() * 1.5 +
108  getVertex(3)->point() * 3.;
109  decasteljau(tol, p0, p1, p2, p3, dpts, ts);
110  for(size_t i = 0; i < ts.size(); ++i) ts[i] = -1 + 2 * ts[i];
111  return;
112  }
113  fullMatrix<double> lagNodes(order + 1, 3), bezNodes(order + 1, 3);
114  for(int i = 0; i < order + 1; ++i) {
115  MVertex *v = getVertex(i);
116  lagNodes(i, 0) = v->x();
117  lagNodes(i, 1) = v->y();
118  lagNodes(i, 2) = v->z();
119  }
120 
121  std::vector<SPoint3> pts(bezNodes.size1());
122  pts[0][0] = bezNodes(0, 0);
123  pts[0][1] = bezNodes(0, 1);
124  pts[0][2] = bezNodes(0, 2);
125  pts[order][0] = bezNodes(1, 0);
126  pts[order][1] = bezNodes(1, 1);
127  pts[order][2] = bezNodes(1, 2);
128  for(int i = 0; i < order - 1; ++i) {
129  pts[i + 1][0] = bezNodes(i + 2, 0);
130  pts[i + 1][1] = bezNodes(i + 2, 1);
131  pts[i + 1][2] = bezNodes(i + 2, 2);
132  }
133  decasteljau(tol, pts, dpts, ts);
134  for(size_t i = 0; i < ts.size(); ++i) ts[i] = -1 + 2 * ts[i];
135 }
GaussLegendre1D.h
MEdge
Definition: MEdge.h:14
getGQLPts
IntPt * getGQLPts(int order)
Definition: GaussQuadratureLin.cpp:12
MLine::getVertex
virtual MVertex * getVertex(int num)
Definition: MLine.h:45
MLine::getVolume
virtual double getVolume()
Definition: MLine.cpp:25
MVertex
Definition: MVertex.h:24
decasteljau
static void decasteljau(double tol, discreteList &discrete, int pos, const SPoint3 &p0, const SPoint3 &p1, const SPoint3 &p2, const SPoint3 &p3, double t0, double t3)
Definition: gmshEdgeDiscretize.cpp:41
nodalBasis.h
MVertex::z
double z() const
Definition: MVertex.h:62
SPoint3
Definition: SPoint3.h:14
MLineN::getNumEdgesRep
virtual int getNumEdgesRep(bool curved)
Definition: MLine.cpp:52
SVector3
Definition: SVector3.h:16
MLineN::getEdgeRep
virtual void getEdgeRep(bool curved, int num, double *x, double *y, double *z, SVector3 *n)
Definition: MLine.cpp:57
MLineN::getPolynomialOrder
virtual int getPolynomialOrder() const
Definition: MLine.h:227
MVertex::point
SPoint3 point() const
Definition: MVertex.h:67
MLine.h
getNGQLPts
int getNGQLPts(int order)
Definition: GaussQuadratureLin.cpp:33
MLineN::discretize
virtual void discretize(double tol, std::vector< SPoint3 > &dpts, std::vector< double > &ts)
Definition: MLine.cpp:98
MLine::_v
MVertex * _v[2]
Definition: MLine.h:23
CTX::instance
static CTX * instance()
Definition: Context.cpp:122
SPoint3::x
double x(void) const
Definition: SPoint3.h:125
fullMatrix< double >
MLine3::getEdgeRep
virtual void getEdgeRep(bool curved, int num, double *x, double *y, double *z, SVector3 *n)
Definition: MLine.cpp:32
MLine3::discretize
virtual void discretize(double tol, std::vector< SPoint3 > &dpts, std::vector< double > &ts)
Definition: MLine.cpp:88
contextMeshOptions::numSubEdges
int numSubEdges
Definition: Context.h:85
MLine::getIntegrationPoints
virtual void getIntegrationPoints(int pOrder, int *npts, IntPt **pts)
Definition: MLine.cpp:15
MLine::getEdgeRep
virtual void getEdgeRep(bool curved, int num, double *x, double *y, double *z, SVector3 *n)
Definition: MLine.h:58
MLine3::getVertex
virtual MVertex * getVertex(int num)
Definition: MLine.h:148
MLine::discretize
virtual void discretize(double tol, std::vector< SPoint3 > &dpts, std::vector< double > &ts)
Definition: MLine.cpp:77
GmshDefines.h
MLine3::getNumEdgesRep
virtual int getNumEdgesRep(bool curved)
Definition: MLine.cpp:27
SPoint3::y
double y(void) const
Definition: SPoint3.h:127
CTX::mesh
contextMeshOptions mesh
Definition: Context.h:313
MLineN::getVertex
virtual MVertex * getVertex(int num)
Definition: MLine.h:229
MElement::pnt
virtual void pnt(double u, double v, double w, SPoint3 &p) const
Definition: MElement.cpp:1072
MLine::getInnerRadius
virtual double getInnerRadius()
Definition: MLine.cpp:21
Context.h
IntPt
Definition: GaussIntegration.h:12
fullMatrix::size1
int size1() const
Definition: fullMatrix.h:274
z
const double z
Definition: GaussQuadratureQuad.cpp:56
SPoint3::z
double z(void) const
Definition: SPoint3.h:129
MVertex::y
double y() const
Definition: MVertex.h:61
MVertex::distance
double distance(MVertex *const v)
Definition: MVertex.h:105
bezierBasis.h
decasteljau.h
MLine::getLength
virtual double getLength()
Definition: MLine.cpp:23
MVertex::x
double x() const
Definition: MVertex.h:60
MEdge::normal
SVector3 normal() const
Definition: MEdge.h:82
BasisFactory.h