gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
MeshSubEntities.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 "MeshSubEntities.h"
7 #include "GModel.h"
8 #include "discreteVertex.h"
9 #include "discreteEdge.h"
10 #include "discreteFace.h"
11 #include "MElement.h"
12 #include "MPoint.h"
13 #include "MLine.h"
14 #include "MTriangle.h"
15 #include "MQuadrangle.h"
16 #include "MEdge.h"
17 #include "MFace.h"
18 #include "Context.h"
19 
21  {GMSH_FULLRC, "InputDimension", nullptr, 1.},
22  {GMSH_FULLRC, "InputPhysicalGroup", nullptr, 1.},
23  {GMSH_FULLRC, "OuputDimension", nullptr, 0.},
24  {GMSH_FULLRC, "OuputPhysicalGroup", nullptr, 2000.},
25 };
26 
27 extern "C" {
29 {
30  return new GMSH_MeshSubEntitiesPlugin();
31 }
32 }
33 
35 {
36  return "Plugin(MeshSubEntities) creates mesh elements for the "
37  "entities of dimension `OutputDimension' (0 for vertices, "
38  "1 for edges, 2 for faces) of the `InputPhysicalGroup' of "
39  "dimension `InputDimension'. The plugin creates new elements "
40  "belonging to `OutputPhysicalGroup'.";
41 }
42 
44 {
45  return sizeof(MeshSubEntitiesOptions_Number) / sizeof(StringXNumber);
46 }
47 
49 {
50  return &MeshSubEntitiesOptions_Number[iopt];
51 }
52 
54 {
55  int inputdim = (int)MeshSubEntitiesOptions_Number[0].def;
56  int inputphysical = (int)MeshSubEntitiesOptions_Number[1].def;
57  int outputdim = (int)MeshSubEntitiesOptions_Number[2].def;
58  int outphysical = (int)MeshSubEntitiesOptions_Number[3].def;
59 
60  if(inputdim < 0 || inputdim > 3 || outputdim < 0 || outputdim > 3 ||
61  outputdim > inputdim) {
62  Msg::Error("Bad dimensions");
63  return view;
64  }
65 
66  GModel *m = GModel::current();
67  std::map<int, std::vector<GEntity *> > groups;
68  m->getPhysicalGroups(inputdim, groups);
69  std::vector<GEntity *> entities = groups[inputphysical];
70 
71  if(entities.empty()) {
72  Msg::Error("Physical group %d (dimension %d) is empty", inputphysical,
73  inputdim);
74  return view;
75  }
76 
77  // get input elements
78  std::vector<MElement *> elements;
79  for(std::size_t i = 0; i < entities.size(); i++)
80  for(std::size_t j = 0; j < entities[i]->getNumMeshElements(); j++)
81  elements.push_back(entities[i]->getMeshElement(j));
82 
83  if(outputdim == 0) { // create point elements for mesh vertices
84  std::set<MVertex *> vertices;
85  for(std::size_t i = 0; i < elements.size(); i++) {
86  for(std::size_t j = 0; j < elements[i]->getNumVertices(); j++) {
87  MVertex *v = elements[i]->getVertex(j);
88  vertices.insert(v);
89  }
90  }
91  for(auto it = vertices.begin(); it != vertices.end(); ++it) {
92  MVertex *v = *it;
93  GVertex *gv = nullptr;
94  if(v->onWhat() && v->onWhat()->dim() == 0) {
95  gv = (GVertex *)v->onWhat();
96  }
97  else {
98  gv = new discreteVertex(m, m->getMaxElementaryNumber(0) + 1);
99  v->setEntity(gv);
100  m->add(gv);
101  }
102  gv->physicals.push_back(outphysical);
103  if(gv->points.empty()) gv->points.push_back(new MPoint(v));
104  }
106  }
107  else if(outputdim == 1) { // create line elements for mesh edges
108  std::set<MEdge, MEdgeLessThan> edges;
109  for(std::size_t i = 0; i < elements.size(); i++) {
110  for(int j = 0; j < elements[i]->getNumEdges(); j++) {
111  MEdge e = elements[i]->getEdge(j);
112  edges.insert(e);
113  }
114  }
115  for(auto it = edges.begin(); it != edges.end(); ++it) {
116  const MEdge &e = *it;
117  GEdge *ge = nullptr;
118  MVertex *v0 = e.getVertex(0), *v1 = e.getVertex(1);
119  if(v0->onWhat() && v1->onWhat()) {
120  if(v0->onWhat()->dim() == 1 &&
121  ((v1->onWhat()->dim() == 1 && v0->onWhat() == v1->onWhat()) ||
122  v1->onWhat()->dim() == 0))
123  ge = (GEdge *)v0->onWhat();
124  else if(v1->onWhat()->dim() == 1 &&
125  ((v0->onWhat()->dim() == 1 && v0->onWhat() == v1->onWhat()) ||
126  v0->onWhat()->dim() == 0))
127  ge = (GEdge *)v1->onWhat();
128  }
129  if(!ge) {
130  ge = new discreteEdge(m, m->getMaxElementaryNumber(1) + 1, nullptr,
131  nullptr);
132  v0->setEntity(ge);
133  v1->setEntity(ge);
134  m->add(ge);
135  }
136  ge->physicals.push_back(outphysical);
137  if(ge->lines.empty()) ge->lines.push_back(new MLine(v0, v1));
138  }
139  }
140  else {
141  Msg::Error("Plugin(MeshSubEntities) not coded yet for output dim %d",
142  outputdim);
143  }
144 
146 
147  return view;
148 }
GMSH_MeshSubEntitiesPlugin::getOption
StringXNumber * getOption(int iopt)
Definition: MeshSubEntities.cpp:48
MTriangle.h
PView
Definition: PView.h:27
MEdge
Definition: MEdge.h:14
GModel::getMaxElementaryNumber
int getMaxElementaryNumber(int dim)
Definition: GModel.cpp:817
GMSH_MeshSubEntitiesPlugin::getNbOptions
int getNbOptions() const
Definition: MeshSubEntities.cpp:43
GMSH_Plugin
Definition: Plugin.h:26
GEdge::lines
std::vector< MLine * > lines
Definition: GEdge.h:42
discreteEdge
Definition: discreteEdge.h:12
MVertex
Definition: MVertex.h:24
Msg::Error
static void Error(const char *fmt,...)
Definition: GmshMessage.cpp:482
GMSH_MeshSubEntitiesPlugin::execute
PView * execute(PView *)
Definition: MeshSubEntities.cpp:53
GEntity::physicals
std::vector< int > physicals
Definition: GEntity.h:65
StringXNumber
Definition: Options.h:918
MVertex::onWhat
GEntity * onWhat() const
Definition: MVertex.h:82
MPoint.h
MLine.h
edges
static int edges[6][2]
Definition: meshGRegionLocalMeshMod.cpp:23
MeshSubEntitiesOptions_Number
StringXNumber MeshSubEntitiesOptions_Number[]
Definition: MeshSubEntities.cpp:20
discreteVertex.h
MLine
Definition: MLine.h:21
GVertex::points
std::vector< MPoint * > points
Definition: GVertex.h:120
CTX::instance
static CTX * instance()
Definition: Context.cpp:122
GModel::getPhysicalGroups
void getPhysicalGroups(std::map< int, std::vector< GEntity * > > groups[4]) const
Definition: GModel.cpp:837
discreteVertex
Definition: discreteVertex.h:15
MFace.h
MEdge::getVertex
MVertex * getVertex(std::size_t i) const
Definition: MEdge.h:39
GVertex
Definition: GVertex.h:23
GMSH_FULLRC
#define GMSH_FULLRC
Definition: Options.h:20
GMSH_MeshSubEntitiesPlugin::getHelp
std::string getHelp() const
Definition: MeshSubEntities.cpp:34
GMSH_RegisterMeshSubEntitiesPlugin
GMSH_Plugin * GMSH_RegisterMeshSubEntitiesPlugin()
Definition: MeshSubEntities.cpp:28
GModel
Definition: GModel.h:44
GModel::add
bool add(GRegion *r)
Definition: GModel.h:394
CTX::mesh
contextMeshOptions mesh
Definition: Context.h:313
discreteFace.h
contextMeshOptions::changed
int changed
Definition: Context.h:82
MeshSubEntities.h
MEdge.h
discreteEdge.h
ENT_ALL
#define ENT_ALL
Definition: GmshDefines.h:235
Context.h
GMSH_MeshSubEntitiesPlugin
Definition: MeshSubEntities.h:15
MQuadrangle.h
MElement.h
MPoint
Definition: MPoint.h:16
GEdge
Definition: GEdge.h:26
GModel::pruneMeshVertexAssociations
void pruneMeshVertexAssociations()
Definition: GModel.cpp:2527
GModel.h
GEntity::dim
virtual int dim() const
Definition: GEntity.h:196
MVertex::setEntity
void setEntity(GEntity *ge)
Definition: MVertex.h:83
GModel::current
static GModel * current(int index=-1)
Definition: GModel.cpp:136