gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
GVertex.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 <sstream>
7 #include <algorithm>
8 #include "GModel.h"
9 #include "GVertex.h"
10 #include "GFace.h"
11 #include "MPoint.h"
12 #include "GmshMessage.h"
13 
14 GVertex::GVertex(GModel *m, int tag, double ms) : GEntity(m, tag), meshSize(ms)
15 {
16 }
17 
19 
21 {
22  for(std::size_t i = 0; i < mesh_vertices.size(); i++) delete mesh_vertices[i];
23  mesh_vertices.clear();
24  for(std::size_t i = 0; i < points.size(); i++) delete points[i];
25  points.clear();
28 }
29 
31 
33 {
34  Msg::Error("Cannot set position of this kind of point");
35 }
36 
38 {
39  if(std::find(l_edges.begin(), l_edges.end(), e) == l_edges.end())
40  l_edges.push_back(e);
41 }
42 
43 void GVertex::delEdge(GEdge *const e)
44 {
45  auto it = std::find(l_edges.begin(), l_edges.end(), e);
46  if(it != l_edges.end()) l_edges.erase(it);
47 }
48 
49 SPoint2 GVertex::reparamOnFace(const GFace *gf, int) const
50 {
51  return gf->parFromPoint(SPoint3(x(), y(), z()));
52 }
53 
54 std::string GVertex::getAdditionalInfoString(bool multline)
55 {
56  std::ostringstream sstream;
57  sstream.precision(12);
58  sstream << "Position (" << x() << ", " << y() << ", " << z() << ")";
59  if(multline)
60  sstream << "\n";
61  else
62  sstream << " ";
63 
64  if(l_edges.size()) {
65  sstream << "On boundary of curves: ";
66  for(auto it = l_edges.begin(); it != l_edges.end(); ++it) {
67  if(it != l_edges.begin()) sstream << ", ";
68  sstream << (*it)->tag();
69  }
70  if(multline)
71  sstream << "\n";
72  else
73  sstream << " ";
74  }
75 
76  double lc = prescribedMeshSizeAtVertex();
77  if(lc < MAX_LC) { sstream << "Mesh attributes: size " << lc; }
78 
79  std::string str = sstream.str();
80  if(str.size() && (str[str.size() - 1] == '\n' || str[str.size() - 1] == ' '))
81  str.resize(str.size() - 1);
82 
83  return str;
84 }
85 
86 void GVertex::writeGEO(FILE *fp, const std::string &meshSizeParameter)
87 {
88  if(meshSizeParameter.size())
89  fprintf(fp, "Point(%d) = {%.16g, %.16g, %.16g, %s};\n", tag(), x(), y(),
90  z(), meshSizeParameter.c_str());
92  fprintf(fp, "Point(%d) = {%.16g, %.16g, %.16g, %.16g};\n", tag(), x(), y(),
94  else
95  fprintf(fp, "Point(%d) = {%.16g, %.16g, %.16g};\n", tag(), x(), y(), z());
96 }
97 
98 void GVertex::writePY(FILE *fp, const std::string &meshSizeParameter)
99 {
100  const char *factory = getNativeType() == OpenCascadeModel ? "occ" : "geo";
101  if(meshSizeParameter.size())
102  fprintf(fp, "gmsh.model.%s.addPoint(%.16g, %.16g, %.16g, %s, %d)\n",
103  factory, x(), y(), z(), meshSizeParameter.c_str(), tag());
104  else if(prescribedMeshSizeAtVertex() != MAX_LC)
105  fprintf(fp, "gmsh.model.%s.addPoint(%.16g, %.16g, %.16g, %.16g, %d)\n",
106  factory, x(), y(), z(), prescribedMeshSizeAtVertex(), tag());
107  else
108  fprintf(fp, "gmsh.model.%s.addPoint(%.16g, %.16g, %.16g, tag=%d)\n",
109  factory, x(), y(), z(), tag());
110 }
111 
112 std::size_t GVertex::getNumMeshElementsByType(const int familyType) const
113 {
114  if(familyType == TYPE_PNT) return points.size();
115 
116  return 0;
117 }
118 
119 void GVertex::getNumMeshElements(unsigned *const c) const
120 {
121  c[0] += points.size();
122 }
123 
124 MElement *GVertex::getMeshElement(std::size_t index) const
125 {
126  if(index < points.size()) return points[index];
127  return nullptr;
128 }
129 
131  const std::size_t index) const
132 {
133  if(familyType == TYPE_PNT) return points[index];
134 
135  return nullptr;
136 }
137 
138 bool GVertex::isOnSeam(const GFace *gf) const
139 {
140  auto const location =
141  std::find_if(begin(l_edges), end(l_edges),
142  [&](GEdge *const edge) { return edge->isSeam(gf); });
143  return location != end(l_edges);
144 }
145 
146 // faces that bound this entity or that this entity bounds.
147 std::vector<GFace *> GVertex::faces() const
148 {
149  std::vector<GFace *> faces;
150 
151  for(auto it = l_edges.begin(); it != l_edges.end(); ++it) {
152  std::vector<GFace *> const &temp = (*it)->faces();
153  faces.insert(faces.end(), temp.begin(), temp.end());
154  }
155  std::sort(faces.begin(), faces.end());
156  faces.erase(std::unique(faces.begin(), faces.end()), faces.end());
157 
158  return faces;
159 }
160 
161 // regions that bound this entity or that this entity bounds.
162 std::list<GRegion *> GVertex::regions() const
163 {
164  std::vector<GFace *> const _faces = faces();
165  std::set<GRegion *> _r;
166  for(auto it = _faces.begin(); it != _faces.end(); ++it) {
167  std::list<GRegion *> temp = (*it)->regions();
168  _r.insert(temp.begin(), temp.end());
169  }
170  std::list<GRegion *> ret;
171  ret.insert(ret.begin(), _r.begin(), _r.end());
172  return ret;
173 }
174 
176 {
177  if(model()->getNumRegions())
178  return regions().empty();
179  else if(model()->getNumFaces())
180  return faces().empty();
181  else if(model()->getNumEdges())
182  return edges().empty();
183  return false;
184 }
185 
187 {
188  for(std::size_t i = 0; i < mesh_vertices.size(); i++) {
189  MVertex *v = mesh_vertices[i];
190  v->x() = x();
191  v->y() = y();
192  v->z() = z();
193  }
194 }
195 
196 void GVertex::addElement(int type, MElement *e)
197 {
198  switch(type) {
199  case TYPE_PNT: addPoint(reinterpret_cast<MPoint *>(e)); break;
200  default:
201  Msg::Error("Trying to add unsupported element in point %d", tag());
202  }
203 }
204 
206 {
207  switch(type) {
208  case TYPE_PNT: {
209  auto it =
210  std::find(points.begin(), points.end(), reinterpret_cast<MPoint *>(e));
211  if(it != points.end()) points.erase(it);
212  } break;
213  default:
214  Msg::Error("Trying to remove unsupported element in point %d", tag());
215  }
216 }
217 
219 {
220  switch(type) {
221  case TYPE_PNT: points.clear(); break;
222  default:
223  Msg::Error("Trying to remove unsupported elements in point %d", tag());
224  }
225 }
226 
227 bool GVertex::reorder(const int elementType,
228  const std::vector<std::size_t> &ordering)
229 {
230  if(points.size() != 0) {
231  if(points.front()->getTypeForMSH() == elementType) {
232  if(ordering.size() != points.size()) return false;
233 
234  for(auto it = ordering.begin(); it != ordering.end(); ++it) {
235  if(*it >= points.size()) return false;
236  }
237 
238  std::vector<MPoint *> newPointsOrder(points.size());
239  for(std::size_t i = 0; i < ordering.size(); i++) {
240  newPointsOrder[i] = points[ordering[i]];
241  }
242  points = std::move(newPointsOrder);
243  return true;
244  }
245  }
246 
247  return false;
248 }
GVertex::addEdge
void addEdge(GEdge *e)
Definition: GVertex.cpp:37
GVertex::z
virtual double z() const =0
GFace.h
GVertex::setPosition
virtual void setPosition(GPoint &p)
Definition: GVertex.cpp:32
GFace
Definition: GFace.h:33
GVertex::writeGEO
virtual void writeGEO(FILE *fp, const std::string &meshSizeParameter="")
Definition: GVertex.cpp:86
GEntity::model
GModel * model() const
Definition: GEntity.h:277
SPoint2
Definition: SPoint2.h:12
GVertex::resetMeshAttributes
virtual void resetMeshAttributes()
Definition: GVertex.cpp:30
GVertex::isOnSeam
bool isOnSeam(const GFace *gf) const
Definition: GVertex.cpp:138
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
GVertex::getNumMeshElementsByType
std::size_t getNumMeshElementsByType(const int familyType) const
Definition: GVertex.cpp:112
GVertex::~GVertex
virtual ~GVertex()
Definition: GVertex.cpp:18
MVertex
Definition: MVertex.h:24
GEntity::OpenCascadeModel
@ OpenCascadeModel
Definition: GEntity.h:82
Msg::Error
static void Error(const char *fmt,...)
Definition: GmshMessage.cpp:482
MVertex::z
double z() const
Definition: MVertex.h:62
SPoint3
Definition: SPoint3.h:14
TYPE_PNT
#define TYPE_PNT
Definition: GmshDefines.h:64
GVertex::addElement
void addElement(int type, MElement *e)
Definition: GVertex.cpp:196
GVertex::reorder
virtual bool reorder(const int elementType, const std::vector< std::size_t > &ordering)
Definition: GVertex.cpp:227
GVertex::edges
virtual std::vector< GEdge * > const & edges() const
Definition: GVertex.h:54
GEntity::getNativeType
virtual ModelType getNativeType() const
Definition: GEntity.h:268
MPoint.h
GVertex::addPoint
void addPoint(MPoint *p)
Definition: GVertex.h:122
GVertex::removeElement
void removeElement(int type, MElement *e)
Definition: GVertex.cpp:205
GVertex::getMeshElementByType
MElement * getMeshElementByType(const int familyType, const std::size_t index) const
Definition: GVertex.cpp:130
GModel::destroyMeshCaches
void destroyMeshCaches()
Definition: GModel.cpp:214
GVertex::faces
virtual std::vector< GFace * > faces() const
Definition: GVertex.cpp:147
GVertex::regions
virtual std::list< GRegion * > regions() const
Definition: GVertex.cpp:162
GmshMessage.h
MAX_LC
#define MAX_LC
Definition: GEntity.h:19
GEntity
Definition: GEntity.h:31
GPoint
Definition: GPoint.h:13
GVertex::writePY
virtual void writePY(FILE *fp, const std::string &meshSizeParameter="")
Definition: GVertex.cpp:98
GVertex::points
std::vector< MPoint * > points
Definition: GVertex.h:120
GVertex::deleteMesh
virtual void deleteMesh()
Definition: GVertex.cpp:20
GEntity::mesh_vertices
std::vector< MVertex * > mesh_vertices
Definition: GEntity.h:56
GVertex::getMeshElement
MElement * getMeshElement(std::size_t index) const
Definition: GVertex.cpp:124
GVertex::prescribedMeshSizeAtVertex
virtual double prescribedMeshSizeAtVertex() const
Definition: GVertex.h:75
GModel
Definition: GModel.h:44
GVertex::getNumMeshElements
std::size_t getNumMeshElements() const
Definition: GVertex.h:104
GFace::parFromPoint
virtual SPoint2 parFromPoint(const SPoint3 &, bool onSurface=true, bool convTestXYZ=false) const
Definition: GFace.cpp:1254
GVertex::relocateMeshVertices
void relocateMeshVertices()
Definition: GVertex.cpp:186
GVertex::isOrphan
virtual bool isOrphan()
Definition: GVertex.cpp:175
GEdge::isSeam
virtual bool isSeam(const GFace *face) const
Definition: GEdge.h:101
MElement
Definition: MElement.h:30
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
GVertex::getAdditionalInfoString
virtual std::string getAdditionalInfoString(bool multline=false)
Definition: GVertex.cpp:54
GVertex::x
virtual double x() const =0
GVertex::y
virtual double y() const =0
GVertex.h
GVertex::delEdge
void delEdge(GEdge *e)
Definition: GVertex.cpp:43
MPoint
Definition: MPoint.h:16
GEdge
Definition: GEdge.h:26
GVertex::reparamOnFace
virtual SPoint2 reparamOnFace(const GFace *gf, int) const
Definition: GVertex.cpp:49
GModel.h
MVertex::y
double y() const
Definition: MVertex.h:61
GVertex::removeElements
void removeElements(int type)
Definition: GVertex.cpp:218
GEntity::deleteVertexArrays
void deleteVertexArrays()
Definition: GEntity.cpp:27
GVertex::GVertex
GVertex(GModel *m, int tag, double ms=MAX_LC)
Definition: GVertex.cpp:14
MVertex::x
double x() const
Definition: MVertex.h:60