gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
gmshVertex.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 "GFace.h"
7 #include "GEdge.h"
8 #include "gmshVertex.h"
9 #include "Geo.h"
10 #include "GeoInterpolation.h"
11 #include "GmshMessage.h"
12 #include "MVertex.h"
13 #include "MPoint.h"
14 
15 gmshVertex::gmshVertex(GModel *m, Vertex *v) : GVertex(m, v->Num, v->lc), _v(v)
16 {
18 }
19 
21 
23 
25 {
26  return GPoint(_v->Pos.X, _v->Pos.Y, _v->Pos.Z, this);
27 }
28 
29 double gmshVertex::x() const { return _v->Pos.X; }
30 
31 double gmshVertex::y() const { return _v->Pos.Y; }
32 
33 double gmshVertex::z() const { return _v->Pos.Z; }
34 
36 {
37  _v->Pos.X = p.x();
38  _v->Pos.Y = p.y();
39  _v->Pos.Z = p.z();
40  if(mesh_vertices.size()) {
41  mesh_vertices[0]->x() = p.x();
42  mesh_vertices[0]->y() = p.y();
43  mesh_vertices[0]->z() = p.z();
44  }
45 }
46 
48 {
49  if(_v->Typ == MSH_POINT_BND_LAYER)
50  return BoundaryLayerPoint;
51  else
52  return Point;
53 }
54 
56 {
57  meshSize = l;
58  _v->lc = meshSize;
59 }
60 
61 SPoint2 gmshVertex::reparamOnFace(const GFace *face, int dir) const
62 {
63  Surface *s = (Surface *)face->getNativePtr();
64 
65  if(s->geometry) {
66  // It is not always right if it is periodic.
67  if(l_edges.size() == 1 && (*l_edges.begin())->getBeginVertex() ==
68  (*l_edges.begin())->getEndVertex()) {
69  Range<double> bb = (*l_edges.begin())->parBounds(0);
70  return (*l_edges.begin())->reparamOnFace(face, bb.low(), dir);
71  }
72  return _v->pntOnGeometry;
73  }
74 
75  if(s->Typ == MSH_SURF_REGL) {
76  Curve *C[4];
77  for(int i = 0; i < 4; i++) List_Read(s->Generatrices, i, &C[i]);
78 
79  double U, V;
80  if((C[0]->beg == _v && C[3]->beg == _v) ||
81  (C[0]->end == _v && C[3]->beg == _v) ||
82  (C[0]->beg == _v && C[3]->end == _v) ||
83  (C[0]->end == _v && C[3]->end == _v)) {
84  U = V = 0;
85  }
86  else if((C[0]->beg == _v && C[1]->beg == _v) ||
87  (C[0]->end == _v && C[1]->beg == _v) ||
88  (C[0]->beg == _v && C[1]->end == _v) ||
89  (C[0]->end == _v && C[1]->end == _v)) {
90  U = 1;
91  V = 0;
92  }
93  else if((C[2]->beg == _v && C[1]->beg == _v) ||
94  (C[2]->end == _v && C[1]->beg == _v) ||
95  (C[2]->beg == _v && C[1]->end == _v) ||
96  (C[2]->end == _v && C[1]->end == _v)) {
97  U = 1;
98  V = 1;
99  }
100  else if((C[2]->beg == _v && C[3]->beg == _v) ||
101  (C[2]->end == _v && C[3]->beg == _v) ||
102  (C[2]->beg == _v && C[3]->end == _v) ||
103  (C[2]->end == _v && C[3]->end == _v)) {
104  U = 0;
105  V = 1;
106  }
107  else {
108  Msg::Info("Reparameterizing point %d on face %d", _v->Num, s->Num);
109  return GVertex::reparamOnFace(face, dir);
110  }
111  return SPoint2(U, V);
112  }
113  else if(s->Typ == MSH_SURF_TRIC) {
114  Curve *C[3];
115  for(int i = 0; i < 3; i++) List_Read(s->Generatrices, i, &C[i]);
116 
117  double U, V;
118  if((C[0]->beg == _v && C[2]->beg == _v) ||
119  (C[0]->end == _v && C[2]->beg == _v) ||
120  (C[0]->beg == _v && C[2]->end == _v) ||
121  (C[0]->end == _v && C[2]->end == _v)) {
122  U = V = 0;
123  }
124  else if((C[0]->beg == _v && C[1]->beg == _v) ||
125  (C[0]->end == _v && C[1]->beg == _v) ||
126  (C[0]->beg == _v && C[1]->end == _v) ||
127  (C[0]->end == _v && C[1]->end == _v)) {
128  U = 1;
129  V = 0;
130  }
131  else if((C[2]->beg == _v && C[1]->beg == _v) ||
132  (C[2]->end == _v && C[1]->beg == _v) ||
133  (C[2]->beg == _v && C[1]->end == _v) ||
134  (C[2]->end == _v && C[1]->end == _v)) {
135  U = 1;
136  V = 1;
137  }
138  else {
139  Msg::Info("Reparameterizing point %d on face %d", _v->Num, s->Num);
140  return GVertex::reparamOnFace(face, dir);
141  }
142  return SPoint2(U, V);
143  }
144  else {
145  return GVertex::reparamOnFace(face, dir);
146  }
147 }
148 
149 void gmshVertex::writeGEO(FILE *fp, const std::string &meshSizeParameter)
150 {
151  double xx, yy, zz;
152  if(_v->geometry) {
153  xx = _v->pntOnGeometry.x();
154  yy = _v->pntOnGeometry.y();
155  zz = 0.;
156  }
157  else {
158  xx = x();
159  yy = y();
160  zz = z();
161  }
162 
163  if(meshSizeParameter.size())
164  fprintf(fp, "Point(%d) = {%.16g, %.16g, %.16g, %s};\n", tag(),
165  xx, yy, zz, meshSizeParameter.c_str());
166  else if(_v->lc != MAX_LC)
167  fprintf(fp, "Point(%d) = {%.16g, %.16g, %.16g, %.16g};\n", tag(),
168  xx, yy, zz, _v->lc);
169  else
170  fprintf(fp, "Point(%d) = {%.16g, %.16g, %.16g};\n", tag(),
171  xx, yy, zz);
172 }
173 
174 void gmshVertex::writePY(FILE *fp, const std::string &meshSizeParameter)
175 {
176  double xx, yy, zz;
177  const char *fct;
178  if(_v->geometry) {
179  xx = _v->pntOnGeometry.x();
180  yy = _v->pntOnGeometry.y();
181  zz = 0.;
182  fct = "gmsh.model.geo.addPointOnGeometry(1, "; // TODO geometryTag
183  }
184  else {
185  xx = x();
186  yy = y();
187  zz = z();
188  fct = "gmsh.model.geo.addPoint(";
189  }
190 
191  if(meshSizeParameter.size())
192  fprintf(fp, "%s%.16g, %.16g, %.16g, %s, %d)\n",
193  fct, xx, yy, zz, meshSizeParameter.c_str(), tag());
194  else if(prescribedMeshSizeAtVertex() != MAX_LC)
195  fprintf(fp, "%s%.16g, %.16g, %.16g, %.16g, %d)\n",
196  fct, xx, yy, zz, prescribedMeshSizeAtVertex(), tag());
197  else
198  fprintf(fp, "%s%.16g, %.16g, %.16g, tag=%d)\n",
199  fct, xx, yy, zz, tag());
200 }
gmshVertex::_v
Vertex * _v
Definition: gmshVertex.h:15
Surface::Num
int Num
Definition: Geo.h:113
gmshVertex::geomType
virtual GeomType geomType() const
Definition: gmshVertex.cpp:47
Geo.h
GeoInterpolation.h
gmshVertex::x
virtual double x() const
Definition: gmshVertex.cpp:29
Vertex::pntOnGeometry
SPoint2 pntOnGeometry
Definition: Geo.h:40
GPoint::y
double y() const
Definition: GPoint.h:22
GFace.h
gmshVertex::writePY
virtual void writePY(FILE *fp, const std::string &meshSizeParameter="")
Definition: gmshVertex.cpp:174
Curve
Definition: Geo.h:74
gmshVertex.h
Surface::Typ
int Typ
Definition: Geo.h:114
GFace
Definition: GFace.h:33
Msg::Info
static void Info(const char *fmt,...)
Definition: GmshMessage.cpp:587
SPoint2
Definition: SPoint2.h:12
Curve::end
Vertex * end
Definition: Geo.h:85
gmshVertex::setPrescribedMeshSizeAtVertex
virtual void setPrescribedMeshSizeAtVertex(double l)
Definition: gmshVertex.cpp:55
Vertex
Definition: Geo.h:29
MPoint.h
GmshMessage.h
MAX_LC
#define MAX_LC
Definition: GEntity.h:19
GPoint
Definition: GPoint.h:13
gmshVertex::resetMeshAttributes
virtual void resetMeshAttributes()
Definition: gmshVertex.cpp:22
Vertex::Num
int Num
Definition: Geo.h:31
GPoint::z
double z() const
Definition: GPoint.h:23
GEntity::getNativePtr
virtual void * getNativePtr() const
Definition: GEntity.h:271
GEdge.h
Range
Definition: Range.h:10
GEntity::mesh_vertices
std::vector< MVertex * > mesh_vertices
Definition: GEntity.h:56
GVertex
Definition: GVertex.h:23
GVertex::prescribedMeshSizeAtVertex
virtual double prescribedMeshSizeAtVertex() const
Definition: GVertex.h:75
MVertex.h
gmshVertex::setPosition
virtual void setPosition(GPoint &p)
Definition: gmshVertex.cpp:35
GModel
Definition: GModel.h:44
gmshVertex::writeGEO
virtual void writeGEO(FILE *fp, const std::string &meshSizeParameter="")
Definition: gmshVertex.cpp:149
Curve::beg
Vertex * beg
Definition: Geo.h:85
Vertex::Typ
int Typ
Definition: Geo.h:32
gmshVertex::y
virtual double y() const
Definition: gmshVertex.cpp:31
Surface
Definition: Geo.h:111
gmshVertex::gmshVertex
gmshVertex(GModel *m, Vertex *v)
Definition: gmshVertex.cpp:15
Vertex::lc
double lc
Definition: Geo.h:33
MSH_SURF_REGL
#define MSH_SURF_REGL
Definition: GeoDefines.h:34
GEntity::tag
int tag() const
Definition: GEntity.h:280
GVertex::l_edges
std::vector< GEdge * > l_edges
Definition: GVertex.h:25
GVertex::meshSize
double meshSize
Definition: GVertex.h:26
gmshVertex::resetNativePtr
void resetNativePtr(Vertex *v)
Definition: gmshVertex.cpp:20
GEntity::GeomType
GeomType
Definition: GEntity.h:88
GEntity::parBounds
virtual Range< double > parBounds(int i) const
Definition: GEntity.h:259
MSH_SURF_TRIC
#define MSH_SURF_TRIC
Definition: GeoDefines.h:35
SPoint2::x
double x(void) const
Definition: SPoint2.h:86
Coord::X
double X
Definition: Geo.h:26
GEntity::Point
@ Point
Definition: GEntity.h:90
MSH_POINT_BND_LAYER
#define MSH_POINT_BND_LAYER
Definition: GeoDefines.h:17
Vertex::geometry
gmshSurface * geometry
Definition: Geo.h:39
Coord::Z
double Z
Definition: Geo.h:26
GEntity::BoundaryLayerPoint
@ BoundaryLayerPoint
Definition: GEntity.h:91
gmshVertex::reparamOnFace
virtual SPoint2 reparamOnFace(const GFace *gf, int) const
Definition: gmshVertex.cpp:61
Coord::Y
double Y
Definition: Geo.h:26
Vertex::Pos
Coord Pos
Definition: Geo.h:34
gmshVertex::point
virtual GPoint point() const
Definition: gmshVertex.cpp:24
Surface::Generatrices
List_T * Generatrices
Definition: Geo.h:120
GVertex::reparamOnFace
virtual SPoint2 reparamOnFace(const GFace *gf, int) const
Definition: GVertex.cpp:49
gmshVertex::z
virtual double z() const
Definition: gmshVertex.cpp:33
Surface::geometry
gmshSurface * geometry
Definition: Geo.h:129
Range::low
T low() const
Definition: Range.h:18
GPoint::x
double x() const
Definition: GPoint.h:21
List_Read
void List_Read(List_T *liste, int index, void *data)
Definition: ListUtils.cpp:111
SPoint2::y
double y(void) const
Definition: SPoint2.h:88