gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
Tetrahedralize.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 <vector>
7 #include "GmshConfig.h"
8 #include "GModel.h"
9 #include "GmshMessage.h"
10 #include "Tetrahedralize.h"
11 
12 #if defined(HAVE_MESH)
14 #endif
15 
17  {GMSH_FULLRC, "View", nullptr, -1.}};
18 
19 extern "C" {
21 {
22  return new GMSH_TetrahedralizePlugin();
23 }
24 }
25 
27 {
28  return "Plugin(Tetrahedralize) tetrahedralizes the points in "
29  "the view `View'.\n\n"
30  "If `View' < 0, the plugin is run on the current view.\n\n"
31  "Plugin(Tetrahedralize) creates one new list-based view.";
32 }
33 
35 {
36  return sizeof(TetrahedralizeOptions_Number) / sizeof(StringXNumber);
37 }
38 
40 {
41  return &TetrahedralizeOptions_Number[iopt];
42 }
43 
44 #if defined(HAVE_MESH)
45 
46 namespace {
47  class PointData : public MVertex {
48  public:
49  std::vector<double> val;
50  PointData(double x, double y, double z, int numVal) : MVertex(x, y, z)
51  {
52  val.resize(numVal);
53  }
54  };
55 } // namespace
56 
58 {
59  int iView = (int)TetrahedralizeOptions_Number[0].def;
60 
61  PView *v1 = getView(iView, v);
62  if(!v1) return v;
63  PViewData *data1 = v1->getData();
64 
65  if(data1->hasMultipleMeshes()) {
66  Msg::Error("Tetrahedralize plugin cannot be applied to multi-mesh views");
67  return v1;
68  }
69 
70  // create list of points with associated data
71  std::vector<MVertex *> points;
72  int numSteps = data1->getNumTimeSteps();
73  for(int ent = 0; ent < data1->getNumEntities(0); ent++) {
74  for(int ele = 0; ele < data1->getNumElements(0, ent); ele++) {
75  if(data1->skipElement(0, ent, ele)) continue;
76  if(data1->getNumNodes(0, ent, ele) != 1) continue;
77  int numComp = data1->getNumComponents(0, ent, ele);
78  double x, y, z;
79  data1->getNode(0, ent, ele, 0, x, y, z);
80  PointData *p = new PointData(x, y, z, numComp * numSteps);
81  for(int step = 0; step < numSteps; step++)
82  for(int comp = 0; comp < numComp; comp++)
83  data1->getValue(step, ent, ele, 0, comp,
84  p->val[numComp * step + comp]);
85  points.push_back(p);
86  }
87  }
88 
89  if(points.size() < 4) {
90  Msg::Error("Need at least 4 points to tetrahedralize");
91  for(std::size_t i = 0; i < points.size(); i++) delete points[i];
92  return v1;
93  }
94 
95  std::vector<MTetrahedron *> tets;
96  delaunayMeshIn3D(points, tets); // adds 8 enclosing box vertices
97 
98  // create output
99  PView *v2 = new PView();
100  PViewDataList *data2 = getDataList(v2);
101  for(std::size_t i = 0; i < tets.size(); i++) {
102  bool ok = true;
103  PointData *p[4];
104  for(int j = 0; j < 4; j++) {
105  p[j] = dynamic_cast<PointData *>(tets[i]->getVertex(j));
106  if(!p[j]) { // tet connected to enclosing box
107  ok = false;
108  break;
109  }
110  }
111  if(!ok) continue;
112  int numComp = 0;
113  std::vector<double> *vec = nullptr;
114  if((int)p[0]->val.size() == 9 * numSteps &&
115  (int)p[1]->val.size() == 9 * numSteps &&
116  (int)p[2]->val.size() == 9 * numSteps &&
117  (int)p[3]->val.size() == 9 * numSteps) {
118  numComp = 9;
119  data2->NbTS++;
120  vec = &data2->TS;
121  }
122  else if((int)p[0]->val.size() == 3 * numSteps &&
123  (int)p[1]->val.size() == 3 * numSteps &&
124  (int)p[2]->val.size() == 3 * numSteps &&
125  (int)p[3]->val.size() == 3 * numSteps) {
126  numComp = 3;
127  data2->NbVS++;
128  vec = &data2->VS;
129  }
130  else if((int)p[0]->val.size() == numSteps &&
131  (int)p[1]->val.size() == numSteps &&
132  (int)p[2]->val.size() == numSteps &&
133  (int)p[3]->val.size() == numSteps) {
134  numComp = 1;
135  data2->NbSS++;
136  vec = &data2->SS;
137  }
138  else {
139  Msg::Warning("Skipping unknown type of data");
140  continue;
141  }
142  for(int nod = 0; nod < 4; nod++) vec->push_back(p[nod]->x());
143  for(int nod = 0; nod < 4; nod++) vec->push_back(p[nod]->y());
144  for(int nod = 0; nod < 4; nod++) vec->push_back(p[nod]->z());
145  for(int step = 0; step < numSteps; step++)
146  for(int nod = 0; nod < 4; nod++)
147  for(int comp = 0; comp < numComp; comp++)
148  vec->push_back(p[nod]->val[numComp * step + comp]);
149  }
150 
151  for(std::size_t i = 0; i < tets.size(); i++) delete tets[i];
152  for(std::size_t i = 0; i < points.size(); i++) delete points[i];
153 
154  for(int i = 0; i < data1->getNumTimeSteps(); i++)
155  data2->Time.push_back(data1->getTime(i));
156  data2->setName(data1->getName() + "_Tetrahedralize");
157  data2->setFileName(data1->getName() + "_Tetrahedralize.pos");
158  data2->finalize();
159  return v2;
160 }
161 
162 #else
163 
165 {
166  Msg::Error("Plugin(Tetrahedralize) requires mesh module");
167  return v;
168 }
169 
170 #endif
PViewDataList::TS
std::vector< double > TS
Definition: PViewDataList.h:37
PView
Definition: PView.h:27
meshGRegionDelaunayInsertion.h
PViewData::skipElement
virtual bool skipElement(int step, int ent, int ele, bool checkVisibility=false, int samplingRate=1)
Definition: PViewData.cpp:90
PViewDataList::SS
std::vector< double > SS
Definition: PViewDataList.h:37
GMSH_Plugin
Definition: Plugin.h:26
PViewData::getNumTimeSteps
virtual int getNumTimeSteps()=0
TetrahedralizeOptions_Number
StringXNumber TetrahedralizeOptions_Number[]
Definition: Tetrahedralize.cpp:16
PViewDataList
Definition: PViewDataList.h:17
MVertex
Definition: MVertex.h:24
Msg::Warning
static void Warning(const char *fmt,...)
Definition: GmshMessage.cpp:543
PViewData::getNode
virtual int getNode(int step, int ent, int ele, int nod, double &x, double &y, double &z)
Definition: PViewData.h:141
Msg::Error
static void Error(const char *fmt,...)
Definition: GmshMessage.cpp:482
StringXNumber
Definition: Options.h:918
PViewData::getValue
virtual void getValue(int step, int ent, int ele, int idx, double &val)
Definition: PViewData.h:159
PViewData::hasMultipleMeshes
virtual bool hasMultipleMeshes()
Definition: PViewData.h:216
GmshMessage.h
PViewData::getNumEntities
virtual int getNumEntities(int step=-1)
Definition: PViewData.h:127
GMSH_RegisterTetrahedralizePlugin
GMSH_Plugin * GMSH_RegisterTetrahedralizePlugin()
Definition: Tetrahedralize.cpp:20
PViewData::setFileName
virtual void setFileName(const std::string &val)
Definition: PViewData.h:75
GMSH_TetrahedralizePlugin::getNbOptions
int getNbOptions() const
Definition: Tetrahedralize.cpp:34
GMSH_TetrahedralizePlugin::execute
PView * execute(PView *)
Definition: Tetrahedralize.cpp:164
Tetrahedralize.h
PViewData::getTime
virtual double getTime(int step)
Definition: PViewData.h:94
delaunayMeshIn3D
void delaunayMeshIn3D(std::vector< MVertex * > &v, std::vector< MTetrahedron * > &result, bool removeBox)
Definition: meshGRegionDelaunayInsertion.cpp:1559
GMSH_FULLRC
#define GMSH_FULLRC
Definition: Options.h:20
PView::getData
PViewData * getData(bool useAdaptiveIfAvailable=false)
Definition: PView.cpp:233
PViewDataList::NbVS
int NbVS
Definition: PViewDataList.h:36
PViewData::getNumNodes
virtual int getNumNodes(int step, int ent, int ele)
Definition: PViewData.h:137
PViewDataList::finalize
bool finalize(bool computeMinMax=true, const std::string &interpolationScheme="")
Definition: PViewDataList.cpp:81
PViewData::setName
virtual void setName(const std::string &val)
Definition: PViewData.h:71
PViewDataList::NbTS
int NbTS
Definition: PViewDataList.h:36
PViewData
Definition: PViewData.h:29
GMSH_TetrahedralizePlugin::getHelp
std::string getHelp() const
Definition: Tetrahedralize.cpp:26
PViewDataList::NbSS
int NbSS
Definition: PViewDataList.h:36
PViewData::getNumComponents
virtual int getNumComponents(int step, int ent, int ele)
Definition: PViewData.h:152
z
const double z
Definition: GaussQuadratureQuad.cpp:56
GMSH_TetrahedralizePlugin::getOption
StringXNumber * getOption(int iopt)
Definition: Tetrahedralize.cpp:39
GMSH_PostPlugin::getView
virtual PView * getView(int index, PView *view)
Definition: Plugin.cpp:81
PViewDataList::Time
std::vector< double > Time
Definition: PViewDataList.h:25
PViewDataList::VS
std::vector< double > VS
Definition: PViewDataList.h:37
PViewData::getNumElements
virtual int getNumElements(int step=-1, int ent=-1)
Definition: PViewData.h:131
GModel.h
PViewData::getName
virtual std::string getName()
Definition: PViewData.h:70
GMSH_TetrahedralizePlugin
Definition: Tetrahedralize.h:15
GMSH_PostPlugin::getDataList
virtual PViewDataList * getDataList(PView *view, bool showError=true)
Definition: Plugin.cpp:107