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