gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
meshGEdgeExtruded.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 <set>
7 #include "GModel.h"
8 #include "MLine.h"
9 #include "ExtrudeParams.h"
10 #include "GmshMessage.h"
11 
12 static void createElements(GEdge *ge)
13 {
14  // create elements
15  for(std::size_t i = 0; i < ge->mesh_vertices.size() + 1; i++) {
16  MVertex *v0 = (i == 0) ? ge->getBeginVertex()->mesh_vertices[0] :
17  ge->mesh_vertices[i - 1];
18  MVertex *v1 = (i == ge->mesh_vertices.size()) ?
19  ge->getEndVertex()->mesh_vertices[0] :
20  ge->mesh_vertices[i];
21  MLine *newElem = new MLine(v0, v1);
22  ge->lines.push_back(newElem);
23  }
24 }
25 
26 static void extrudeMesh(GVertex *from, GEdge *to)
27 {
29 
30  MVertex *v = from->mesh_vertices[0];
31  for(int j = 0; j < ep->mesh.NbLayer; j++) {
32  for(int k = 0; k < ep->mesh.NbElmLayer[j]; k++) {
33  double x = v->x(), y = v->y(), z = v->z();
34  ep->Extrude(j, k + 1, x, y, z);
35  if(j != ep->mesh.NbLayer - 1 || k != ep->mesh.NbElmLayer[j] - 1) {
36  Range<double> r = to->parBounds(0);
37  double t = r.low() + ep->u(j, k + 1) * (r.high() - r.low());
38  MEdgeVertex *newv = new MEdgeVertex(x, y, z, to, t);
39  to->mesh_vertices.push_back(newv);
40  }
41  }
42  }
43  createElements(to);
44 }
45 
46 static void copyMesh(GEdge *from, GEdge *to)
47 {
49 
50  int direction = (ep->geo.Source > 0) ? 1 : -1;
51 
52  Range<double> u_bounds = from->parBounds(0);
53  double u_min = u_bounds.low();
54  double u_max = u_bounds.high();
55 
56 #if 0
57  // old version, which directly uses nodes; this can lead to unexpected results
58  // if the nodes in from->mesh_vertices.size() are not sorted, which can happen
59  // e.g. if createTopology() has been called
60  for(std::size_t i = 0; i < from->mesh_vertices.size(); i++) {
61  int index = (direction < 0) ? (from->mesh_vertices.size() - 1 - i) : i;
62  MVertex *v = from->mesh_vertices[index];
63  double x = v->x(), y = v->y(), z = v->z();
64  ep->Extrude(ep->mesh.NbLayer - 1, ep->mesh.NbElmLayer[ep->mesh.NbLayer - 1],
65  x, y, z);
66  double u;
67  v->getParameter(0, u);
68  double newu = (direction > 0) ? u : (u_max - u + u_min);
69  MEdgeVertex *newv = new MEdgeVertex(x, y, z, to, newu);
70  to->mesh_vertices.push_back(newv);
71  }
72 #else
73  // so it's better to go back to the elements, which are assumed to be stored
74  // in the correct order
75  for(int i = 0; i < (int)from->lines.size() - 1; i++) {
76  int index = (direction < 0) ? (from->lines.size() - i - 2) : i;
77  MVertex *v = from->lines[index]->getVertex(1);
78  double x = v->x(), y = v->y(), z = v->z();
79  ep->Extrude(ep->mesh.NbLayer - 1, ep->mesh.NbElmLayer[ep->mesh.NbLayer - 1],
80  x, y, z);
81  double u;
82  v->getParameter(0, u);
83  double newu = (direction > 0) ? u : (u_max - u + u_min);
84  MEdgeVertex *newv = new MEdgeVertex(x, y, z, to, newu);
85  to->mesh_vertices.push_back(newv);
86  }
87 #endif
88 
89  createElements(to);
90 }
91 
93 {
95 
96  if(!ep || !ep->mesh.ExtrudeMesh) return 0;
97 
98  if(!ge->getBeginVertex() || !ge->getEndVertex()) {
99  Msg::Error("Cannot extrude curve %d with no begin or end point", ge->tag());
100  return 0;
101  }
102 
103  Msg::Info("Meshing curve %d (Extruded)", ge->tag());
104 
105  if(ep->geo.Mode == EXTRUDED_ENTITY) {
106  // curve is extruded from a point
107  GVertex *from = ge->model()->getVertexByTag(std::abs(ep->geo.Source));
108  if(!from) {
109  Msg::Error("Unknown source point %d for extrusion", ep->geo.Source);
110  return 0;
111  }
112  extrudeMesh(from, ge);
113  }
114  else {
115  GEdge *from = ge->model()->getEdgeByTag(std::abs(ep->geo.Source));
116  // curve is a copy of another curve (the "top" of the extrusion)
117  if(!from) {
118  Msg::Error("Unknown source curve %d for extrusion", ep->geo.Source);
119  return 0;
120  }
121  else if(from->geomType() != GEntity::DiscreteCurve &&
122  from->meshStatistics.status != GEdge::DONE) {
123  // cannot mesh this edge yet: will do it later
124  return 1;
125  }
126  else if(ge->getMeshMaster() != ge) {
127  GEdge *gef = dynamic_cast<GEdge *>(ge->getMeshMaster());
128  if(gef->meshStatistics.status != GEdge::DONE) {
129  // there is a periodicity constraint, and the source has not been
130  // meshed: will do it later
131  return 1;
132  }
133  }
134 
135  copyMesh(from, ge);
136  if(ge->getMeshMaster() == from) {
137  // explicit periodic constraint, to store node correspondence
138  ge->setMeshMaster(from, ge->affineTransform);
139  }
140  }
141 
143  return 1;
144 }
GEdge::setMeshMaster
void setMeshMaster(GEdge *master, const std::vector< double > &)
Definition: GEdge.cpp:89
GEntity::affineTransform
std::vector< double > affineTransform
Definition: GEntity.h:403
createElements
static void createElements(GEdge *ge)
Definition: meshGEdgeExtruded.cpp:12
Msg::Info
static void Info(const char *fmt,...)
Definition: GmshMessage.cpp:587
GEdge::lines
std::vector< MLine * > lines
Definition: GEdge.h:42
GEntity::model
GModel * model() const
Definition: GEntity.h:277
MVertex
Definition: MVertex.h:24
Msg::Error
static void Error(const char *fmt,...)
Definition: GmshMessage.cpp:482
MVertex::z
double z() const
Definition: MVertex.h:62
Range::high
T high() const
Definition: Range.h:20
GEdge::extrude
ExtrudeParams * extrude
Definition: GEdge.h:257
GModel::getEdgeByTag
GEdge * getEdgeByTag(int n) const
Definition: GModel.cpp:336
GmshMessage.h
MLine.h
ExtrudeParams::geo
struct ExtrudeParams::@15 geo
GEntity::getMeshMaster
GEntity * getMeshMaster() const
Definition: GEntity.h:291
GEntity::DiscreteCurve
@ DiscreteCurve
Definition: GEntity.h:104
MLine
Definition: MLine.h:21
Range
Definition: Range.h:10
ExtrudeParams::mesh
struct ExtrudeParams::@14 mesh
GEntity::mesh_vertices
std::vector< MVertex * > mesh_vertices
Definition: GEntity.h:56
copyMesh
static void copyMesh(GEdge *from, GEdge *to)
Definition: meshGEdgeExtruded.cpp:46
MEdgeVertex
Definition: MVertex.h:137
EXTRUDED_ENTITY
#define EXTRUDED_ENTITY
Definition: ExtrudeParams.h:17
GVertex
Definition: GVertex.h:23
GEntity::DONE
@ DONE
Definition: GEntity.h:130
GEdge::getBeginVertex
virtual GVertex * getBeginVertex() const
Definition: GEdge.h:63
ExtrudeParams::NbLayer
int NbLayer
Definition: ExtrudeParams.h:39
ExtrudeParams.h
GEntity::geomType
virtual GeomType geomType() const
Definition: GEntity.h:238
GEdge::meshAttributes
struct GEdge::@16 meshAttributes
extrudeMesh
static void extrudeMesh(GVertex *from, GEdge *to)
Definition: meshGEdgeExtruded.cpp:26
ExtrudeParams::Mode
int Mode
Definition: ExtrudeParams.h:49
ExtrudeParams::NbElmLayer
std::vector< int > NbElmLayer
Definition: ExtrudeParams.h:40
GEntity::tag
int tag() const
Definition: GEntity.h:280
ExtrudeParams::Extrude
void Extrude(int iLayer, int iElemLayer, double &dx, double &dy, double &dz)
Definition: ExtrudeParams.cpp:51
ExtrudeParams::ExtrudeMesh
bool ExtrudeMesh
Definition: ExtrudeParams.h:36
ExtrudeParams::Source
int Source
Definition: ExtrudeParams.h:51
GEdge::status
GEntity::MeshGenerationStatus status
Definition: GEdge.h:263
MVertex::getParameter
virtual bool getParameter(int i, double &par) const
Definition: MVertex.h:97
GEdge::meshStatistics
struct GEdge::@17 meshStatistics
ExtrudeParams::u
double u(int iLayer, int iElemLayer)
Definition: ExtrudeParams.cpp:122
GEdge::parBounds
virtual Range< double > parBounds(int i) const =0
z
const double z
Definition: GaussQuadratureQuad.cpp:56
MeshExtrudedCurve
int MeshExtrudedCurve(GEdge *ge)
Definition: meshGEdgeExtruded.cpp:92
GEdge
Definition: GEdge.h:26
direction
static void direction(Vertex *v1, Vertex *v2, double d[3])
Definition: Geo.cpp:218
GModel.h
MVertex::y
double y() const
Definition: MVertex.h:61
GEdge::getEndVertex
virtual GVertex * getEndVertex() const
Definition: GEdge.h:64
Range::low
T low() const
Definition: Range.h:18
GModel::getVertexByTag
GVertex * getVertexByTag(int n) const
Definition: GModel.cpp:346
ExtrudeParams
Definition: ExtrudeParams.h:26
MVertex::x
double x() const
Definition: MVertex.h:60