gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
GEdge.h
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 #ifndef GEDGE_H
7 #define GEDGE_H
8 
9 #include <string>
10 #include <vector>
11 #include <stdio.h>
12 #include "GmshMessage.h"
13 #include "GmshDefines.h"
14 #include "GEntity.h"
15 #include "GVertex.h"
16 #include "SVector3.h"
17 #include "SPoint3.h"
18 #include "SPoint2.h"
19 
20 class MElement;
21 class MLine;
22 class ExtrudeParams;
23 class closestPointFinder;
24 
25 // A model edge.
26 class GEdge : public GEntity {
27 private:
28  double _length;
29  bool _tooSmall;
31  // prescribed mesh size (_lc) at parametric points (_u_lc) (sorted by _u_lc)
32  std::vector<double> _u_lc, _lc;
33 
34 protected:
36  std::vector<GFace *> _faces;
37 
38 public:
39  // same or opposite direction to the master
41 
42  std::vector<MLine *> lines;
43 
44  // when a compound of curves is created, both meshes should be kept alive
45  // (because the 2D meshing procedure will need to access the mesh of each of
46  // the original curves, in addition to the mesh of the compound curve)
48 
49  // the STL discretization
50  std::vector<SPoint3> stl_vertices_xyz;
51 
52 public:
53  GEdge(GModel *model, int tag, GVertex *v0, GVertex *v1);
54  GEdge(GModel *model, int tag);
55  virtual ~GEdge();
56 
57  // delete mesh data
58  virtual void deleteMesh();
59 
60  // get the start/end vertices of the edge
61  void setBeginVertex(GVertex *gv) { _v0 = gv; gv->addEdge(this); }
62  void setEndVertex(GVertex *gv) { _v1 = gv; gv->addEdge(this); }
63  virtual GVertex *getBeginVertex() const { return _v0; }
64  virtual GVertex *getEndVertex() const { return _v1; }
65  void setVertex(GVertex *const f, const int orientation)
66  {
67  if(orientation > 0)
68  _v0 = f;
69  else if(orientation < 0)
70  _v1 = f;
71  }
72 
73  // specify mesh master with transformation, deduce edgeCounterparts
74  void setMeshMaster(GEdge *master, const std::vector<double> &);
75 
76  // specify mesh master and edgeCounterparts, deduce transformation
77  void setMeshMaster(GEdge *master, int sign);
78 
79  void reverse();
80 
81  // add/delete a face bounded by this edge
82  void addFace(GFace *f);
83  virtual void delFace(GFace *f);
84 
85  // get the dimension of the edge (1)
86  virtual int dim() const { return 1; }
87 
88  // returns the parent entity for partitioned entities
89  virtual GEntity *getParentEntity() { return nullptr; }
90 
91  // get the list of vertices
92  virtual std::vector<GVertex *> vertices() const;
93 
94  // set the visibility flag
95  virtual void setVisibility(char val, bool recursive = false);
96 
97  // set color
98  virtual void setColor(unsigned int val, bool recursive = false);
99 
100  // true if the edge is a seam for the given face.
101  virtual bool isSeam(const GFace *face) const { return false; }
102 
103  // get the bounding box
104  virtual SBoundingBox3d bounds(bool fast = false);
105 
106  // get the oriented bounding box
107  virtual SOrientedBoundingBox getOBB();
108 
109  // regions that are bounded by this entity
110  virtual std::list<GRegion *> regions() const;
111 
112  // faces that this entity bounds
113  virtual std::vector<GFace *> faces() const { return _faces; }
114 
115  // get number of faces
116  virtual std::size_t numFaces() const { return _faces.size(); }
117 
118  // is this entity an orphan?
119  virtual bool isOrphan();
120 
121  // get the point for the given parameter location
122  virtual GPoint point(double p) const = 0;
123 
124  // true if the edge contains the given parameter
125  virtual bool containsParam(double pt) const;
126 
127  // get the position for the given parameter location
128  virtual SVector3 position(double p) const
129  {
130  GPoint gp = point(p);
131  return SVector3(gp.x(), gp.y(), gp.z());
132  }
133 
134  // get first derivative of edge at the given parameter
135  virtual SVector3 firstDer(double par) const = 0;
136 
137  // get second derivative of edge at the given parameter (default
138  // implentation using central differences)
139  virtual SVector3 secondDer(double par) const;
140 
141  // get the curvature
142  virtual double curvature(double par) const;
143 
144  // reparmaterize the point onto the given face
145  virtual SPoint2 reparamOnFace(const GFace *face, double epar, int dir) const;
146 
147  // return the minimum number of segments used for meshing the edge
148  virtual int minimumMeshSegments() const { return 1; }
149 
150  // return the minimum number of segments used for drawing the edge
151  virtual int minimumDrawSegments() const { return 1; }
152 
153  // return a type-specific additional information string
154  virtual std::string getAdditionalInfoString(bool multline = false);
155 
156  // export in GEO format
157  virtual void writeGEO(FILE *fp);
158 
159  // export in Python
160  virtual void writePY(FILE *fp);
161 
162  // store the STL triangulation as the mesh of the surface
163  bool storeSTLAsMesh();
164 
165  // tell if the edge is a 3D edge (in opposition with a trimmed curve on a
166  // surface)
167  virtual bool is3D() const { return true; }
168 
169  // get/set/compute the length of the model edge
170  double length() const { return _length; }
171  void setLength(const double l) { _length = l; }
172  double length(const double &u0, const double &u1, const int nbQuadPoints = 4);
173 
174  // get the prescribed mesh size on the edge
175  double prescribedMeshSizeAtVertex() const { return meshAttributes.meshSize; }
176 
177  double prescribedMeshSizeAtParam(double u);
178 
179  void setMeshSizeParametric(const std::vector<double> u,
180  const std::vector<double> lc);
181 
182  // true if start == end and no more than 2 segments
183  void setTooSmall(bool const b) { _tooSmall = b; }
184  virtual bool isMeshDegenerated() const
185  {
186  if(_tooSmall) Msg::Debug("Degenerated mesh on curve %d: too small", tag());
187  if(_v0 && _v0 == _v1 && mesh_vertices.size() < 2)
188  Msg::Debug("Degenerated mesh on curve %d: %d mesh nodes", tag(),
189  (int)mesh_vertices.size());
190  return _tooSmall || (_v0 && _v0 == _v1 && mesh_vertices.size() < 2);
191  }
192 
193  // types of elements
194  virtual void getElementTypes(std::vector<int> &types) const
195  {
196  types.clear();
197  types.push_back(TYPE_LIN);
198  };
199 
200  // get total/by-type number of elements in the mesh
201  std::size_t getNumMeshElements() const { return lines.size(); }
202  std::size_t getNumMeshElementsByType(const int familyType) const;
203  std::size_t getNumMeshParentElements();
204  void getNumMeshElements(unsigned *const c) const;
205 
206  // get the start of the array of a type of element
207  MElement *const *getStartElementType(int type) const;
208 
209  // get the element at the given index
210  MElement *getMeshElement(std::size_t index) const;
211  // get the element at the given index for a given familyType
212  MElement *getMeshElementByType(const int familyType,
213  const std::size_t index) const;
214 
215  // reset the mesh attributes to default values
216  virtual void resetMeshAttributes();
217 
218  // true if entity is periodic in the "dim" direction.
219  virtual bool periodic(int dim) const { return _v0 == _v1; }
220 
221  // get bounds of parametric coordinate
222  virtual Range<double> parBounds(int i) const = 0;
223  virtual Range<double> parBoundsOnFace(GFace *face = nullptr) const
224  {
225  return parBounds(0);
226  }
227  double getLowerBound() const { return parBounds(0).low(); };
228  double getUpperBound() const { return parBounds(0).high(); };
229 
230  // true if the entity contains the given point to within tolerance.
231  virtual bool containsPoint(const SPoint3 &pt) const;
232 
233  // return the point on the face closest to the given point
234  virtual GPoint closestPoint(const SPoint3 &queryPoint, double &param) const;
235 
236  // return the parmater location on the edge given a point in space
237  // that is on the edge
238  virtual double parFromPoint(const SPoint3 &P) const;
239  virtual bool refineProjection(const SVector3 &Q, double &u, int MaxIter,
240  double relax, double tol, double &err) const;
241 
242  // compute the parameter U from a point XYZ
243  virtual bool XYZToU(const double X, const double Y, const double Z, double &U,
244  const double relax = 1, bool first = true) const;
245 
246  // relocate mesh vertices using parametric coordinates
247  void relocateMeshVertices();
248 
249  struct {
250  char method;
256  // the extrusion parameters (if any)
258  // reverse mesh orientation
261 
262  struct {
265 
266  void addLine(MLine *line) { lines.push_back(line); }
267  void addElement(int type, MElement *e);
268  void removeElement(int type, MElement *e);
269  void removeElements(int type);
270 
271  virtual void discretize(double tol, std::vector<SPoint3> &dpts,
272  std::vector<double> &ts);
274  virtual void mesh(bool verbose);
275 
276  virtual bool reorder(const int elementType,
277  const std::vector<std::size_t> &ordering);
278 };
279 
280 #endif
GEdge::minimumMeshSegments
virtual int minimumMeshSegments() const
Definition: GEdge.h:148
GVertex::addEdge
void addEdge(GEdge *e)
Definition: GVertex.cpp:37
GEdge::getStartElementType
MElement *const * getStartElementType(int type) const
Definition: GEdge.cpp:167
GEdge::setMeshMaster
void setMeshMaster(GEdge *master, const std::vector< double > &)
Definition: GEdge.cpp:89
GEdge::periodic
virtual bool periodic(int dim) const
Definition: GEdge.h:219
GEdge::setLength
void setLength(const double l)
Definition: GEdge.h:171
GEdge::setVisibility
virtual void setVisibility(char val, bool recursive=false)
Definition: GEdge.cpp:277
GEdge::regions
virtual std::list< GRegion * > regions() const
Definition: GEdge.cpp:692
GEdge::getMeshElement
MElement * getMeshElement(std::size_t index) const
Definition: GEdge.cpp:173
GEdge::reparamOnFace
virtual SPoint2 reparamOnFace(const GFace *face, double epar, int dir) const
Definition: GEdge.cpp:482
GPoint::y
double y() const
Definition: GPoint.h:22
GEdge::setMeshSizeParametric
void setMeshSizeParametric(const std::vector< double > u, const std::vector< double > lc)
Definition: GEdge.cpp:998
TYPE_LIN
#define TYPE_LIN
Definition: GmshDefines.h:65
GEdge::resetMeshAttributes
virtual void resetMeshAttributes()
Definition: GEdge.cpp:187
GFace
Definition: GFace.h:33
GEdge::lines
std::vector< MLine * > lines
Definition: GEdge.h:42
GEntity::model
GModel * model() const
Definition: GEntity.h:277
SPoint2
Definition: SPoint2.h:12
GEdge::minimumDrawSegments
virtual int minimumDrawSegments() const
Definition: GEdge.h:151
GEntity.h
Msg::Debug
static void Debug(const char *fmt,...)
Definition: GmshMessage.cpp:752
GEdge::_faces
std::vector< GFace * > _faces
Definition: GEdge.h:36
GEdge::~GEdge
virtual ~GEdge()
Definition: GEdge.cpp:44
GEdge::meshSize
double meshSize
Definition: GEdge.h:252
c
static double c(int i, int j, fullMatrix< double > &CA, const std::vector< SPoint3 > &P, const std::vector< SPoint3 > &Q)
Definition: discreteFrechetDistance.cpp:15
GEdge::reverseMesh
bool reverseMesh
Definition: GEdge.h:259
GEdge::setEndVertex
void setEndVertex(GVertex *gv)
Definition: GEdge.h:62
SPoint3
Definition: SPoint3.h:14
LegendrePolynomials::f
void f(int n, double u, double *val)
Definition: orthogonalBasis.cpp:77
GEdge::XYZToU
virtual bool XYZToU(const double X, const double Y, const double Z, double &U, const double relax=1, bool first=true) const
Definition: GEdge.cpp:640
GEdge::writeGEO
virtual void writeGEO(FILE *fp)
Definition: GEdge.cpp:354
SVector3
Definition: SVector3.h:16
SOrientedBoundingBox
Definition: SOrientedBoundingBox.h:33
GEdge::numFaces
virtual std::size_t numFaces() const
Definition: GEdge.h:116
GEdge::setVertex
void setVertex(GVertex *const f, const int orientation)
Definition: GEdge.h:65
SVector3.h
GEdge::length
double length() const
Definition: GEdge.h:170
GEdge::extrude
ExtrudeParams * extrude
Definition: GEdge.h:257
GEdge::addLine
void addLine(MLine *line)
Definition: GEdge.h:266
GEdge::_cp
closestPointFinder * _cp
Definition: GEdge.h:30
GmshMessage.h
GEntity
Definition: GEntity.h:31
GPoint
Definition: GPoint.h:13
GEdge::prescribedMeshSizeAtParam
double prescribedMeshSizeAtParam(double u)
Definition: GEdge.cpp:979
GEdge::discretize
virtual void discretize(double tol, std::vector< SPoint3 > &dpts, std::vector< double > &ts)
Definition: GEdge.cpp:806
GEdge::dim
virtual int dim() const
Definition: GEdge.h:86
GEdge::getNumMeshParentElements
std::size_t getNumMeshParentElements()
Definition: GEdge.cpp:155
GEdge::prescribedMeshSizeAtVertex
double prescribedMeshSizeAtVertex() const
Definition: GEdge.h:175
GEdge::getElementTypes
virtual void getElementTypes(std::vector< int > &types) const
Definition: GEdge.h:194
GEdge::addFace
void addFace(GFace *f)
Definition: GEdge.cpp:200
MLine
Definition: MLine.h:21
GPoint::z
double z() const
Definition: GPoint.h:23
GEdge::getLowerBound
double getLowerBound() const
Definition: GEdge.h:227
GEdge::setTooSmall
void setTooSmall(bool const b)
Definition: GEdge.h:183
GEdge::getAdditionalInfoString
virtual std::string getAdditionalInfoString(bool multline=false)
Definition: GEdge.cpp:295
GEdge::getNumMeshElementsByType
std::size_t getNumMeshElementsByType(const int familyType) const
Definition: GEdge.cpp:148
GEdge::delFace
virtual void delFace(GFace *f)
Definition: GEdge.cpp:206
GEdge::firstDer
virtual SVector3 firstDer(double par) const =0
GEdge::storeSTLAsMesh
bool storeSTLAsMesh()
Definition: GEdge.cpp:425
Range
Definition: Range.h:10
GEdge::getOBB
virtual SOrientedBoundingBox getOBB()
Definition: GEdge.cpp:234
GEntity::mesh_vertices
std::vector< MVertex * > mesh_vertices
Definition: GEntity.h:56
GVertex
Definition: GVertex.h:23
closestPointFinder
Definition: closestPoint.h:18
GModel
Definition: GModel.h:44
GEdge::getBeginVertex
virtual GVertex * getBeginVertex() const
Definition: GEdge.h:63
GEdge::closestPointWithTol
SPoint3 closestPointWithTol(SPoint3 &p, double tolerance)
Definition: GEdge.cpp:728
GmshDefines.h
GEdge::meshAttributes
struct GEdge::@16 meshAttributes
GEdge::refineProjection
virtual bool refineProjection(const SVector3 &Q, double &u, int MaxIter, double relax, double tol, double &err) const
Definition: GEdge.cpp:604
GEdge::is3D
virtual bool is3D() const
Definition: GEdge.h:167
GEdge::isSeam
virtual bool isSeam(const GFace *face) const
Definition: GEdge.h:101
GEntity::tolerance
virtual double tolerance() const
Definition: GEntity.h:262
MElement
Definition: MElement.h:30
GEdge::masterOrientation
int masterOrientation
Definition: GEdge.h:40
GEntity::tag
int tag() const
Definition: GEntity.h:280
GEdge::position
virtual SVector3 position(double p) const
Definition: GEdge.h:128
GEdge::coeffTransfinite
double coeffTransfinite
Definition: GEdge.h:251
GEdge::_length
double _length
Definition: GEdge.h:28
GEdge::parBoundsOnFace
virtual Range< double > parBoundsOnFace(GFace *face=nullptr) const
Definition: GEdge.h:223
GEdge::isOrphan
virtual bool isOrphan()
Definition: GEdge.cpp:705
GEdge::writePY
virtual void writePY(FILE *fp)
Definition: GEdge.cpp:405
GEdge::stl_vertices_xyz
std::vector< SPoint3 > stl_vertices_xyz
Definition: GEdge.h:50
GEdge::vertices
virtual std::vector< GVertex * > vertices() const
Definition: GEdge.cpp:971
GEdge::faces
virtual std::vector< GFace * > faces() const
Definition: GEdge.h:113
GEdge::typeTransfinite
int typeTransfinite
Definition: GEdge.h:254
GEdge::curvature
virtual double curvature(double par) const
Definition: GEdge.cpp:492
GEdge::_u_lc
std::vector< double > _u_lc
Definition: GEdge.h:32
GEdge::containsPoint
virtual bool containsPoint(const SPoint3 &pt) const
Definition: GEdge.cpp:445
GEdge::status
GEntity::MeshGenerationStatus status
Definition: GEdge.h:263
GEdge::bounds
virtual SBoundingBox3d bounds(bool fast=false)
Definition: GEdge.cpp:212
GEdge::meshStatistics
struct GEdge::@17 meshStatistics
GEdge::closestPoint
virtual GPoint closestPoint(const SPoint3 &queryPoint, double &param) const
Definition: GEdge.cpp:552
GEdge::reorder
virtual bool reorder(const int elementType, const std::vector< std::size_t > &ordering)
Definition: GEdge.cpp:947
GEdge::parBounds
virtual Range< double > parBounds(int i) const =0
GEdge::isMeshDegenerated
virtual bool isMeshDegenerated() const
Definition: GEdge.h:184
GEdge::meshSizeFactor
double meshSizeFactor
Definition: GEdge.h:252
GEdge::containsParam
virtual bool containsParam(double pt) const
Definition: GEdge.cpp:453
GEdge::_v0
GVertex * _v0
Definition: GEdge.h:35
GVertex.h
GEdge::compoundCurve
GEdge * compoundCurve
Definition: GEdge.h:47
GEdge::point
virtual GPoint point(double p) const =0
GEdge::deleteMesh
virtual void deleteMesh()
Definition: GEdge.cpp:53
GEdge::_v1
GVertex * _v1
Definition: GEdge.h:35
GEdge::relocateMeshVertices
void relocateMeshVertices()
Definition: GEdge.cpp:714
GEdge
Definition: GEdge.h:26
GEdge::reverse
void reverse()
Definition: GEdge.cpp:140
GEdge::setBeginVertex
void setBeginVertex(GVertex *gv)
Definition: GEdge.h:61
GEdge::removeElement
void removeElement(int type, MElement *e)
Definition: GEdge.cpp:784
GEdge::getParentEntity
virtual GEntity * getParentEntity()
Definition: GEdge.h:89
GEdge::setColor
virtual void setColor(unsigned int val, bool recursive=false)
Definition: GEdge.cpp:286
GEdge::getNumMeshElements
std::size_t getNumMeshElements() const
Definition: GEdge.h:201
GEdge::getMeshElementByType
MElement * getMeshElementByType(const int familyType, const std::size_t index) const
Definition: GEdge.cpp:179
GEdge::_tooSmall
bool _tooSmall
Definition: GEdge.h:29
GEdge::getEndVertex
virtual GVertex * getEndVertex() const
Definition: GEdge.h:64
GEdge::nbPointsTransfinite
int nbPointsTransfinite
Definition: GEdge.h:253
GEdge::_lc
std::vector< double > _lc
Definition: GEdge.h:32
line
Definition: shapeFunctions.h:342
GEntity::MeshGenerationStatus
MeshGenerationStatus
Definition: GEntity.h:130
GEdge::secondDer
virtual SVector3 secondDer(double par) const
Definition: GEdge.cpp:460
GEdge::addElement
void addElement(int type, MElement *e)
Definition: GEdge.cpp:775
GEdge::getUpperBound
double getUpperBound() const
Definition: GEdge.h:228
SPoint3.h
GEdge::GEdge
GEdge(GModel *model, int tag, GVertex *v0, GVertex *v1)
Definition: GEdge.cpp:26
ExtrudeParams
Definition: ExtrudeParams.h:26
GPoint::x
double x() const
Definition: GPoint.h:21
GEdge::parFromPoint
virtual double parFromPoint(const SPoint3 &P) const
Definition: GEdge.cpp:595
SBoundingBox3d
Definition: SBoundingBox3d.h:21
GEdge::minimumMeshSegments
int minimumMeshSegments
Definition: GEdge.h:255
GEdge::mesh
virtual void mesh(bool verbose)
Definition: GEdge.cpp:918
GEdge::method
char method
Definition: GEdge.h:250
GEdge::removeElements
void removeElements(int type)
Definition: GEdge.cpp:797
SPoint2.h