gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
MakeSimplex.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 "MakeSimplex.h"
7 
9  {GMSH_FULLRC, "View", nullptr, -1.}};
10 
11 extern "C" {
13 {
14  return new GMSH_MakeSimplexPlugin();
15 }
16 }
17 
19 {
20  return "Plugin(MakeSimplex) decomposes all non-simplectic "
21  "elements (quadrangles, prisms, hexahedra, pyramids) in the "
22  "view `View' into simplices (triangles, tetrahedra).\n\n"
23  "If `View' < 0, the plugin is run on the current view.\n\n"
24  "Plugin(MakeSimplex) is executed in-place.";
25 }
26 
28 {
29  return sizeof(MakeSimplexOptions_Number) / sizeof(StringXNumber);
30 }
31 
33 {
34  return &MakeSimplexOptions_Number[iopt];
35 }
36 
37 static void decomposeList(PViewDataList *data, int nbNod, int nbComp,
38  std::vector<double> &listIn, int *nbIn,
39  std::vector<double> &listOut, int *nbOut)
40 {
41  if(!(*nbIn)) return;
42 
43  double xNew[4], yNew[4], zNew[4];
44  double *valNew = new double[data->getNumTimeSteps() * nbComp * nbNod];
45  MakeSimplex dec(nbNod, nbComp, data->getNumTimeSteps());
46 
47  int nb = listIn.size() / (*nbIn);
48  for(std::size_t i = 0; i < listIn.size(); i += nb) {
49  double *x = &listIn[i];
50  double *y = &listIn[i + nbNod];
51  double *z = &listIn[i + 2 * nbNod];
52  double *val = &listIn[i + 3 * nbNod];
53  for(int j = 0; j < dec.numSimplices(); j++) {
54  dec.decompose(j, x, y, z, val, xNew, yNew, zNew, valNew);
55  for(int k = 0; k < dec.numSimplexNodes(); k++) listOut.push_back(xNew[k]);
56  for(int k = 0; k < dec.numSimplexNodes(); k++) listOut.push_back(yNew[k]);
57  for(int k = 0; k < dec.numSimplexNodes(); k++) listOut.push_back(zNew[k]);
58  for(int k = 0;
59  k < dec.numSimplexNodes() * data->getNumTimeSteps() * nbComp; k++)
60  listOut.push_back(valNew[k]);
61  (*nbOut)++;
62  }
63  }
64 
65  delete[] valNew;
66 
67  listIn.clear();
68  *nbIn = 0;
69 }
70 
72 {
73  int iView = (int)MakeSimplexOptions_Number[0].def;
74 
75  PView *v1 = getView(iView, v);
76  if(!v1) return v;
77 
78  PViewDataList *data1 = getDataList(v1);
79  if(!data1) return v;
80 
81  // quads
82  decomposeList(data1, 4, 1, data1->SQ, &data1->NbSQ, data1->ST, &data1->NbST);
83  decomposeList(data1, 4, 3, data1->VQ, &data1->NbVQ, data1->VT, &data1->NbVT);
84  decomposeList(data1, 4, 9, data1->TQ, &data1->NbTQ, data1->TT, &data1->NbTT);
85 
86  // hexas
87  decomposeList(data1, 8, 1, data1->SH, &data1->NbSH, data1->SS, &data1->NbSS);
88  decomposeList(data1, 8, 3, data1->VH, &data1->NbVH, data1->VS, &data1->NbVS);
89  decomposeList(data1, 8, 9, data1->TH, &data1->NbTH, data1->TS, &data1->NbTS);
90 
91  // prisms
92  decomposeList(data1, 6, 1, data1->SI, &data1->NbSI, data1->SS, &data1->NbSS);
93  decomposeList(data1, 6, 3, data1->VI, &data1->NbVI, data1->VS, &data1->NbVS);
94  decomposeList(data1, 6, 9, data1->TI, &data1->NbTI, data1->TS, &data1->NbTS);
95 
96  // pyramids
97  decomposeList(data1, 5, 1, data1->SY, &data1->NbSY, data1->SS, &data1->NbSS);
98  decomposeList(data1, 5, 3, data1->VY, &data1->NbVY, data1->VS, &data1->NbVS);
99  decomposeList(data1, 5, 9, data1->TY, &data1->NbTY, data1->TS, &data1->NbTS);
100 
101  data1->finalize();
102  v1->setChanged(true);
103 
104  return v1;
105 }
106 
107 // Utility class
108 
109 MakeSimplex::MakeSimplex(int numNodes, int numComponents, int numTimeSteps)
110  : _numNodes(numNodes), _numComponents(numComponents),
111  _numTimeSteps(numTimeSteps)
112 {
113  ;
114 }
115 
117 {
118  switch(_numNodes) {
119  case 4: return 2; // quad -> 2 tris
120  case 5: return 2; // pyramid -> 2 tets
121  case 6: return 3; // prism -> 3 tets
122  case 8: return 6; // hexa -> 6 tets
123  }
124  return 0;
125 }
126 
128 {
129  if(_numNodes == 4)
130  return 3; // quad -> tris
131  else
132  return 4; // all others -> tets
133 }
134 
135 void MakeSimplex::reorder(int map[4], int n, double *x, double *y, double *z,
136  double *val, double *xn, double *yn, double *zn,
137  double *valn)
138 {
139  for(int i = 0; i < n; i++) {
140  xn[i] = x[map[i]];
141  yn[i] = y[map[i]];
142  zn[i] = z[map[i]];
143  }
144 
145  int map2[4] = {map[0], map[1], map[2], map[3]};
146  for(int ts = 0; ts < _numTimeSteps; ts++)
147  for(int i = 0; i < n; i++) {
148  for(int j = 0; j < _numComponents; j++)
149  valn[ts * n * _numComponents + i * _numComponents + j] =
150  val[ts * _numNodes * _numComponents + map2[i] * _numComponents + j];
151  }
152 }
153 
154 void MakeSimplex::decompose(int num, double *x, double *y, double *z,
155  double *val, double *xn, double *yn, double *zn,
156  double *valn)
157 {
158  int quadTri[2][4] = {{0, 1, 2, -1}, {0, 2, 3, -1}};
159  int hexaTet[6][4] = {{0, 1, 3, 7}, {0, 4, 1, 7}, {1, 4, 5, 7},
160  {1, 2, 3, 7}, {1, 6, 2, 7}, {1, 5, 6, 7}};
161  int prisTet[3][4] = {{0, 1, 2, 4}, {0, 2, 4, 5}, {0, 3, 4, 5}};
162  int pyraTet[2][4] = {{0, 1, 3, 4}, {1, 2, 3, 4}};
163 
164  if(num < 0 || num > numSimplices() - 1) {
165  Msg::Error("Invalid decomposition");
166  num = 0;
167  }
168 
169  switch(_numNodes) {
170  case 4: reorder(quadTri[num], 3, x, y, z, val, xn, yn, zn, valn); break;
171  case 8: reorder(hexaTet[num], 4, x, y, z, val, xn, yn, zn, valn); break;
172  case 6: reorder(prisTet[num], 4, x, y, z, val, xn, yn, zn, valn); break;
173  case 5: reorder(pyraTet[num], 4, x, y, z, val, xn, yn, zn, valn); break;
174  }
175 }
PViewDataList::VQ
std::vector< double > VQ
Definition: PViewDataList.h:33
PViewDataList::TS
std::vector< double > TS
Definition: PViewDataList.h:37
PViewDataList::NbVY
int NbVY
Definition: PViewDataList.h:42
PView
Definition: PView.h:27
PViewDataList::TQ
std::vector< double > TQ
Definition: PViewDataList.h:33
PViewDataList::SS
std::vector< double > SS
Definition: PViewDataList.h:37
GMSH_Plugin
Definition: Plugin.h:26
MakeSimplex::numSimplexNodes
int numSimplexNodes()
Definition: MakeSimplex.cpp:127
PViewDataList::NbTT
int NbTT
Definition: PViewDataList.h:30
MakeSimplex::_numNodes
int _numNodes
Definition: MakeSimplex.h:32
PViewDataList
Definition: PViewDataList.h:17
Msg::Error
static void Error(const char *fmt,...)
Definition: GmshMessage.cpp:482
StringXNumber
Definition: Options.h:918
PViewDataList::TI
std::vector< double > TI
Definition: PViewDataList.h:41
PViewDataList::NbSQ
int NbSQ
Definition: PViewDataList.h:32
PViewDataList::SY
std::vector< double > SY
Definition: PViewDataList.h:43
MakeSimplex::decompose
void decompose(int num, double *x, double *y, double *z, double *val, double *xn, double *yn, double *zn, double *valn)
Definition: MakeSimplex.cpp:154
PViewDataList::NbSH
int NbSH
Definition: PViewDataList.h:38
GMSH_MakeSimplexPlugin::getHelp
std::string getHelp() const
Definition: MakeSimplex.cpp:18
PViewDataList::VY
std::vector< double > VY
Definition: PViewDataList.h:43
MakeSimplex
Definition: MakeSimplex.h:29
PViewDataList::NbVH
int NbVH
Definition: PViewDataList.h:38
PViewDataList::VH
std::vector< double > VH
Definition: PViewDataList.h:39
PView::setChanged
void setChanged(bool val)
Definition: PView.cpp:241
MakeSimplex.h
PViewDataList::TY
std::vector< double > TY
Definition: PViewDataList.h:43
PViewDataList::getNumTimeSteps
int getNumTimeSteps()
Definition: PViewDataList.h:79
MakeSimplex::reorder
void reorder(int map[4], int n, double *x, double *y, double *z, double *val, double *xn, double *yn, double *zn, double *valn)
Definition: MakeSimplex.cpp:135
PViewDataList::NbTH
int NbTH
Definition: PViewDataList.h:38
GMSH_MakeSimplexPlugin
Definition: MakeSimplex.h:15
GMSH_FULLRC
#define GMSH_FULLRC
Definition: Options.h:20
GMSH_MakeSimplexPlugin::getNbOptions
int getNbOptions() const
Definition: MakeSimplex.cpp:27
GMSH_MakeSimplexPlugin::execute
PView * execute(PView *)
Definition: MakeSimplex.cpp:71
PViewDataList::NbVS
int NbVS
Definition: PViewDataList.h:36
PViewDataList::finalize
bool finalize(bool computeMinMax=true, const std::string &interpolationScheme="")
Definition: PViewDataList.cpp:81
MakeSimplex::numSimplices
int numSimplices()
Definition: MakeSimplex.cpp:116
MakeSimplex::MakeSimplex
MakeSimplex(int numNodes, int numComponents, int numTimeSteps=1)
Definition: MakeSimplex.cpp:109
GMSH_RegisterMakeSimplexPlugin
GMSH_Plugin * GMSH_RegisterMakeSimplexPlugin()
Definition: MakeSimplex.cpp:12
PViewDataList::ST
std::vector< double > ST
Definition: PViewDataList.h:31
PViewDataList::TT
std::vector< double > TT
Definition: PViewDataList.h:31
PViewDataList::NbTS
int NbTS
Definition: PViewDataList.h:36
PViewDataList::TH
std::vector< double > TH
Definition: PViewDataList.h:39
PViewDataList::SH
std::vector< double > SH
Definition: PViewDataList.h:39
PViewDataList::NbTI
int NbTI
Definition: PViewDataList.h:40
MakeSimplex::_numComponents
int _numComponents
Definition: MakeSimplex.h:34
PViewDataList::NbSS
int NbSS
Definition: PViewDataList.h:36
PViewDataList::NbTY
int NbTY
Definition: PViewDataList.h:42
decomposeList
static void decomposeList(PViewDataList *data, int nbNod, int nbComp, std::vector< double > &listIn, int *nbIn, std::vector< double > &listOut, int *nbOut)
Definition: MakeSimplex.cpp:37
GMSH_MakeSimplexPlugin::getOption
StringXNumber * getOption(int iopt)
Definition: MakeSimplex.cpp:32
z
const double z
Definition: GaussQuadratureQuad.cpp:56
PViewDataList::NbSI
int NbSI
Definition: PViewDataList.h:40
GMSH_PostPlugin::getView
virtual PView * getView(int index, PView *view)
Definition: Plugin.cpp:81
PViewDataList::VS
std::vector< double > VS
Definition: PViewDataList.h:37
PViewDataList::NbTQ
int NbTQ
Definition: PViewDataList.h:32
PViewDataList::NbVI
int NbVI
Definition: PViewDataList.h:40
PViewDataList::SI
std::vector< double > SI
Definition: PViewDataList.h:41
PViewDataList::NbVT
int NbVT
Definition: PViewDataList.h:30
PViewDataList::NbVQ
int NbVQ
Definition: PViewDataList.h:32
MakeSimplexOptions_Number
StringXNumber MakeSimplexOptions_Number[]
Definition: MakeSimplex.cpp:8
PViewDataList::VI
std::vector< double > VI
Definition: PViewDataList.h:41
PViewDataList::VT
std::vector< double > VT
Definition: PViewDataList.h:31
MakeSimplex::_numTimeSteps
int _numTimeSteps
Definition: MakeSimplex.h:36
PViewDataList::SQ
std::vector< double > SQ
Definition: PViewDataList.h:33
PViewDataList::NbST
int NbST
Definition: PViewDataList.h:30
PViewDataList::NbSY
int NbSY
Definition: PViewDataList.h:42
GMSH_PostPlugin::getDataList
virtual PViewDataList * getDataList(PView *view, bool showError=true)
Definition: Plugin.cpp:107