gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
DiscretizationError.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 "DiscretizationError.h"
7 #include "Numeric.h"
8 #include <GEntity.h>
9 #include <GModel.h>
10 #include <Context.h>
11 
12 // only temp for syntax higlighting
13 #include <MQuadrangle.h>
14 #include <MTriangle.h>
15 
17  {GMSH_FULLRC, "SuperSamplingNodes", nullptr, 10.}};
18 
19 extern "C" {
21 {
22  return new GMSH_DiscretizationErrorPlugin();
23 }
24 }
25 
27 {
28  return "Plugin(DiscretizationError) computes the error between the mesh "
29  "and the geometry. It does so by supersampling the elements and "
30  "computing "
31  "the distance between the supersampled points dans their projection "
32  "on "
33  "the geometry.";
34 }
35 
37 {
38  return sizeof(DiscretizationErrorOptions_Number) / sizeof(StringXNumber);
39 }
40 
42 {
44 }
45 
47 {
48  double tol = CTX::instance()->geom.tolerance;
49  int nEdgeNodes = (int)DiscretizationErrorOptions_Number[0].def;
50  double paramQuandt = 1.0 / (nEdgeNodes - 1) - 10 * tol;
51  double paramQuandtQuad = 2.0 / (nEdgeNodes - 1) - 10 * tol;
52  int i, j, k, counter;
53  // used as a start estimate for u,v when performing an orthogonal projection
54  double startEstimate[2] = {0.5, 0.5};
55  double dx, dy, dz;
56 
57  std::vector<std::pair<SPoint3, double> > quadDist(nEdgeNodes * nEdgeNodes);
58  std::vector<std::pair<SPoint3, double> > triDist((nEdgeNodes + 1) *
59  nEdgeNodes / 2);
60 
61  PView *v2 = new PView();
62  PViewDataList *data2 = getDataList(v2);
63 
64  for(auto itFace = GModel::current()->firstFace();
65  itFace != GModel::current()->lastFace(); ++itFace) {
66  // sample quadrangles
67  /* 13 14 15 16
68  * 9 10 11 12
69  * 5 6 7 8
70  * 1 2 3 4
71  */
72  for(auto itQuad = (*itFace)->quadrangles.begin();
73  itQuad != (*itFace)->quadrangles.end(); ++itQuad) {
74  for(j = 0; j < nEdgeNodes; j++) { // u
75  for(i = 0; i < nEdgeNodes; i++) { // v
76  (*itQuad)->pnt(-1 + 5 * tol + paramQuandtQuad * i,
77  -1 + 5 * tol + paramQuandtQuad * j, 0.0,
78  quadDist[j * (nEdgeNodes) + i].first);
79  SPoint3 *point = &quadDist[j * (nEdgeNodes) + i].first;
80  GPoint closest = (*itFace)->closestPoint(*point, startEstimate);
81  dx = closest.x() - point->x();
82  dy = closest.y() - point->y();
83  dz = closest.z() - point->z();
84  quadDist[j * (nEdgeNodes) + i].second =
85  sqrt(dx * dx + dy * dy + dz * dz);
86  }
87  }
88  for(j = 0; j < nEdgeNodes - 1; j++) {
89  for(i = 0; i < nEdgeNodes - 1; i++) {
90  std::vector<double> *out = data2->incrementList(1, TYPE_QUA);
91  int indices[4] = {i + j * nEdgeNodes, i + j * nEdgeNodes + 1,
92  i + (j + 1) * nEdgeNodes + 1,
93  i + (j + 1) * nEdgeNodes};
94  for(k = 0; k < 4; k++) out->push_back(quadDist[indices[k]].first.x());
95  for(k = 0; k < 4; k++) out->push_back(quadDist[indices[k]].first.y());
96  for(k = 0; k < 4; k++) out->push_back(quadDist[indices[k]].first.z());
97  for(k = 0; k < 4; k++) out->push_back(quadDist[indices[k]].second);
98  }
99  }
100  }
101 
102  // sample triangles
103  /* 10
104  * 6 9
105  * 3 5 8
106  * 1 2 4 7
107  */
108  for(auto itTri = (*itFace)->triangles.begin();
109  itTri != (*itFace)->triangles.end(); ++itTri) {
110  counter = 0;
111  for(i = 0; i < nEdgeNodes; i++) {
112  for(j = 0; j < (i + 1); j++) {
113  (*itTri)->pnt(5 * tol + paramQuandt * (i - j),
114  5 * tol + paramQuandt * j, 0.0, triDist[counter].first);
115  SPoint3 *point =
116  &triDist[counter].first; // Check : the points are good
117  GPoint closest = (*itFace)->closestPoint(*point, startEstimate);
118  dx = (closest.x() - point->x());
119  dy = (closest.y() - point->y());
120  dz = (closest.z() - point->z());
121  triDist[counter].second = sqrt(dx * dx + dy * dy + dz * dz);
122  counter++;
123  }
124  }
125 
126  int indices[3];
127  for(j = 0; j < nEdgeNodes - 1; j++) { // row in the triangle
128  bool odd = false;
129  for(i = 0; i < j * 2 + 1; i++) { // small tri in the row
130  if(!odd) {
131  indices[0] = i / 2 + (j + 1) * j / 2;
132  indices[1] = i / 2 + (j + 1) * j / 2 + j + 1;
133  indices[2] = i / 2 + (j + 1) * j / 2 + j + 2;
134  }
135  else {
136  indices[0] = (i - 1) / 2 + (j + 1) * j / 2;
137  indices[1] = (i - 1) / 2 + (j + 1) * j / 2 + j + 2;
138  indices[2] = (i - 1) / 2 + (j + 1) * j / 2 + 1;
139  }
140  std::vector<double> *out = data2->incrementList(1, TYPE_TRI);
141  for(k = 0; k < 3; k++) out->push_back(triDist[indices[k]].first.x());
142  for(k = 0; k < 3; k++) out->push_back(triDist[indices[k]].first.y());
143  for(k = 0; k < 3; k++) out->push_back(triDist[indices[k]].first.z());
144  for(k = 0; k < 3; k++) out->push_back(triDist[indices[k]].second);
145  odd = !odd;
146  }
147  }
148  }
149 
150  // viusalize stuff
151  }
152 
153  data2->setName("Discretization Error");
154  data2->setFileName("discretization_err.pos");
155  data2->finalize();
156 
157  return v2;
158 }
MTriangle.h
contextGeometryOptions::tolerance
double tolerance
Definition: Context.h:99
PView
Definition: PView.h:27
GMSH_DiscretizationErrorPlugin::getNbOptions
int getNbOptions() const
Definition: DiscretizationError.cpp:36
GMSH_Plugin
Definition: Plugin.h:26
GEntity.h
PViewDataList
Definition: PViewDataList.h:17
PViewDataList::incrementList
std::vector< double > * incrementList(int numComp, int type, int numNodes=0)
Definition: PViewDataList.cpp:1243
SPoint3
Definition: SPoint3.h:14
StringXNumber
Definition: Options.h:918
TYPE_TRI
#define TYPE_TRI
Definition: GmshDefines.h:66
DiscretizationErrorOptions_Number
StringXNumber DiscretizationErrorOptions_Number[]
Definition: DiscretizationError.cpp:16
GMSH_DiscretizationErrorPlugin::getHelp
std::string getHelp() const
Definition: DiscretizationError.cpp:26
GPoint
Definition: GPoint.h:13
PViewData::setFileName
virtual void setFileName(const std::string &val)
Definition: PViewData.h:75
closest
static double closest(double t, double u)
Definition: meshGFacePack.cpp:177
CTX::instance
static CTX * instance()
Definition: Context.cpp:122
SPoint3::x
double x(void) const
Definition: SPoint3.h:125
GModel::lastFace
fiter lastFace()
Definition: GModel.h:359
GMSH_FULLRC
#define GMSH_FULLRC
Definition: Options.h:20
Numeric.h
SPoint3::y
double y(void) const
Definition: SPoint3.h:127
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
CTX::geom
contextGeometryOptions geom
Definition: Context.h:311
GMSH_DiscretizationErrorPlugin::getOption
StringXNumber * getOption(int iopt)
Definition: DiscretizationError.cpp:41
GMSH_DiscretizationErrorPlugin
Definition: DiscretizationError.h:15
DiscretizationError.h
GMSH_RegisterDiscretizationErrorPlugin
GMSH_Plugin * GMSH_RegisterDiscretizationErrorPlugin()
Definition: DiscretizationError.cpp:20
TYPE_QUA
#define TYPE_QUA
Definition: GmshDefines.h:67
Context.h
GMSH_DiscretizationErrorPlugin::execute
PView * execute(PView *)
Definition: DiscretizationError.cpp:46
MQuadrangle.h
SPoint3::z
double z(void) const
Definition: SPoint3.h:129
GModel.h
GModel::current
static GModel * current(int index=-1)
Definition: GModel.cpp:136
GMSH_PostPlugin::getDataList
virtual PViewDataList * getDataList(PView *view, bool showError=true)
Definition: Plugin.cpp:107