61 for(
auto it = T::all.begin(); it != T::all.end(); ++it)
delete *it;
63 T::allVertices.clear();
71 for(
int i = 0; i < eexps->
size1(); i++) {
72 (*tmp)(i) = pow(u, (*eexps)(i, 0));
73 if(eexps->
size2() > 1) (*tmp)(i) *= pow(v, (*eexps)(i, 1));
74 if(eexps->
size2() > 2) (*tmp)(i) *= pow(w, (*eexps)(i, 2));
76 coeffs->
mult(*tmp, *sf);
96 double oneMinW = (w == 1) ? 1e-12 : 1 - w;
97 for(
int l = 0; l < eexps->
size1(); l++) {
98 int i = (*eexps)(l, 0);
99 int j = (*eexps)(l, 1);
100 int k = (*eexps)(l, 2);
101 int m = std::max(i, j);
102 (*tmp)(l) = pow(u, i);
103 (*tmp)(l) *= pow(v, j);
104 (*tmp)(l) *= pow(w, k);
105 (*tmp)(l) *= pow(oneMinW, m - i - j);
107 coeffs->
mult(*tmp, *sf);
111 std::set<adaptiveVertex> &allVertices)
117 auto it = allVertices.find(p);
118 if(it == allVertices.end()) {
119 allVertices.insert(p);
120 it = allVertices.find(p);
127 cleanElement<adaptivePoint>();
151 cleanElement<adaptiveLine>();
161 if(level++ >= maxlevel)
return;
190 double v1 =
e->
e[0]->
V();
191 double v2 =
e->
e[1]->
V();
194 if(fabs(v - vr) > AVG * tol) {
203 double v11 =
e->
e[0]->
e[0]->
V();
204 double v12 =
e->
e[0]->
e[1]->
V();
205 double v21 =
e->
e[1]->
e[0]->
V();
206 double v22 =
e->
e[1]->
e[1]->
V();
207 double vr1 = (v11 + v12) / 2.;
208 double vr2 = (v21 + v22) / 2.;
209 vr = (vr1 + vr2) / 2.;
210 if(fabs(
e->
e[0]->
V() - vr1) > AVG * tol ||
211 fabs(
e->
e[1]->
V() - vr2) > AVG * tol ||
212 fabs(
e->
V() - vr) > AVG * tol) {
225 cleanElement<adaptiveTriangle>();
236 if(level++ >= maxlevel)
return;
280 double v1 = t->
e[0]->
V();
281 double v2 = t->
e[1]->
V();
282 double v3 = t->
e[2]->
V();
283 double v4 = t->
e[3]->
V();
284 vr = (2 * v1 + 2 * v2 + 2 * v3 + v4) / 7.;
286 if(fabs(v - vr) > AVG * tol) {
297 double v11 = t->
e[0]->
e[0]->
V();
298 double v12 = t->
e[0]->
e[1]->
V();
299 double v13 = t->
e[0]->
e[2]->
V();
300 double v14 = t->
e[0]->
e[3]->
V();
301 double v21 = t->
e[1]->
e[0]->
V();
302 double v22 = t->
e[1]->
e[1]->
V();
303 double v23 = t->
e[1]->
e[2]->
V();
304 double v24 = t->
e[1]->
e[3]->
V();
305 double v31 = t->
e[2]->
e[0]->
V();
306 double v32 = t->
e[2]->
e[1]->
V();
307 double v33 = t->
e[2]->
e[2]->
V();
308 double v34 = t->
e[2]->
e[3]->
V();
309 double v41 = t->
e[3]->
e[0]->
V();
310 double v42 = t->
e[3]->
e[1]->
V();
311 double v43 = t->
e[3]->
e[2]->
V();
312 double v44 = t->
e[3]->
e[3]->
V();
313 double vr1 = (2 * v11 + 2 * v12 + 2 * v13 + v14) / 7.;
314 double vr2 = (2 * v21 + 2 * v22 + 2 * v23 + v24) / 7.;
315 double vr3 = (2 * v31 + 2 * v32 + 2 * v33 + v34) / 7.;
316 double vr4 = (2 * v41 + 2 * v42 + 2 * v43 + v44) / 7.;
317 vr = (2 * vr1 + 2 * vr2 + 2 * vr3 + vr4) / 7.;
318 if(fabs(t->
e[0]->
V() - vr1) > AVG * tol ||
319 fabs(t->
e[1]->
V() - vr2) > AVG * tol ||
320 fabs(t->
e[2]->
V() - vr3) > AVG * tol ||
321 fabs(t->
e[3]->
V() - vr4) > AVG * tol ||
322 fabs(t->
V() - vr) > AVG * tol) {
337 cleanElement<adaptiveQuadrangle>();
350 if(level++ >= maxlevel)
return;
373 (p1->
y + p2->
y + p3->
y + p4->
y) * 0.25,
402 double vd = (q->
p[0]->
val + q->
p[2]->
val) / 2.;
404 double v1 = q->
e[0]->
V();
405 double v2 = q->
e[1]->
V();
406 double v3 = q->
e[2]->
V();
407 double v4 = q->
e[3]->
V();
408 vr = (v1 + v2 + v3 + v4) / 4.;
410 if(fabs(v - vr) > AVG * tol || fabs(vd - vr) > AVG * tol) {
421 double v11 = q->
e[0]->
e[0]->
V();
422 double v12 = q->
e[0]->
e[1]->
V();
423 double v13 = q->
e[0]->
e[2]->
V();
424 double v14 = q->
e[0]->
e[3]->
V();
425 double v21 = q->
e[1]->
e[0]->
V();
426 double v22 = q->
e[1]->
e[1]->
V();
427 double v23 = q->
e[1]->
e[2]->
V();
428 double v24 = q->
e[1]->
e[3]->
V();
429 double v31 = q->
e[2]->
e[0]->
V();
430 double v32 = q->
e[2]->
e[1]->
V();
431 double v33 = q->
e[2]->
e[2]->
V();
432 double v34 = q->
e[2]->
e[3]->
V();
433 double v41 = q->
e[3]->
e[0]->
V();
434 double v42 = q->
e[3]->
e[1]->
V();
435 double v43 = q->
e[3]->
e[2]->
V();
436 double v44 = q->
e[3]->
e[3]->
V();
437 double vr1 = (v11 + v12 + v13 + v14) / 4.;
438 double vr2 = (v21 + v22 + v23 + v24) / 4.;
439 double vr3 = (v31 + v32 + v33 + v34) / 4.;
440 double vr4 = (v41 + v42 + v43 + v44) / 4.;
441 vr = (vr1 + vr2 + vr3 + vr4) / 4.;
442 if(fabs(q->
e[0]->
V() - vr1) > AVG * tol ||
443 fabs(q->
e[1]->
V() - vr2) > AVG * tol ||
444 fabs(q->
e[2]->
V() - vr3) > AVG * tol ||
445 fabs(q->
e[3]->
V() - vr4) > AVG * tol ||
446 fabs(q->
V() - vr) > AVG * tol || fabs(vd - vr) > AVG * tol) {
461 cleanElement<adaptiveTetrahedron>();
474 if(level++ >= maxlevel)
return;
536 const double v1 = t->
e[0]->
V();
537 const double v2 = t->
e[1]->
V();
538 const double v3 = t->
e[2]->
V();
539 const double v4 = t->
e[3]->
V();
540 const double v5 = t->
e[4]->
V();
541 const double v6 = t->
e[5]->
V();
542 const double v7 = t->
e[6]->
V();
543 const double v8 = t->
e[7]->
V();
544 const double vr = (v1 + v2 + v3 + v4 + v5 + v6 + v7 + v8) * .125;
545 const double v = t->
V();
547 if(fabs(v - vr) > AVG * tol) {
563 for(
int k = 0; k < 8; k++)
564 for(
int l = 0; l < 8; l++) vi[k][l] = t->
e[k]->
e[l]->
V();
566 for(
int k = 0; k < 8; k++) {
568 for(
int l = 0; l < 8; l++) { vri[k] += vi[k][l]; }
571 if(fabs(t->
e[0]->
V() - vri[0]) > AVG * tol ||
572 fabs(t->
e[1]->
V() - vri[1]) > AVG * tol ||
573 fabs(t->
e[2]->
V() - vri[2]) > AVG * tol ||
574 fabs(t->
e[3]->
V() - vri[3]) > AVG * tol ||
575 fabs(t->
e[4]->
V() - vri[4]) > AVG * tol ||
576 fabs(t->
e[5]->
V() - vri[5]) > AVG * tol ||
577 fabs(t->
e[6]->
V() - vri[6]) > AVG * tol ||
578 fabs(t->
e[7]->
V() - vri[7]) > AVG * tol || fabs(v - vr) > AVG * tol) {
597 cleanElement<adaptiveHexahedron>();
615 if(level++ >= maxlevel)
return;
680 (p0->
x + p1->
x + p2->
x + p3->
x + p4->
x + p5->
x + p6->
x + p7->
x) * 0.125,
681 (p0->
y + p1->
y + p2->
y + p3->
y + p4->
y + p5->
y + p6->
y + p7->
y) * 0.125,
682 (p0->
z + p1->
z + p2->
z + p3->
z + p4->
z + p5->
z + p6->
z + p7->
z) * 0.125,
731 const double v1 = h->
e[0]->
V();
732 const double v2 = h->
e[1]->
V();
733 const double v3 = h->
e[2]->
V();
734 const double v4 = h->
e[3]->
V();
735 const double v5 = h->
e[4]->
V();
736 const double v6 = h->
e[5]->
V();
737 const double v7 = h->
e[6]->
V();
738 const double v8 = h->
e[7]->
V();
739 const double vr = (v1 + v2 + v3 + v4 + v5 + v6 + v7 + v8) * .125;
740 const double v = h->
V();
742 const double vd = (h->
p[1]->
val + h->
p[7]->
val) / 2.;
744 if(fabs(v - vr) > AVG * tol || fabs(vd - vr) > AVG * tol) {
760 for(
int i = 0; i < 8; i++)
761 for(
int j = 0; j < 8; j++) vii[i][j] = h->
e[i]->
e[j]->
V();
763 for(
int k = 0; k < 8; k++) {
765 for(
int l = 0; l < 8; l++) { vri[k] += vii[k][l]; }
768 if(fabs(h->
e[0]->
V() - vri[0]) > AVG * tol ||
769 fabs(h->
e[1]->
V() - vri[1]) > AVG * tol ||
770 fabs(h->
e[2]->
V() - vri[2]) > AVG * tol ||
771 fabs(h->
e[3]->
V() - vri[3]) > AVG * tol ||
772 fabs(h->
e[4]->
V() - vri[4]) > AVG * tol ||
773 fabs(h->
e[5]->
V() - vri[5]) > AVG * tol ||
774 fabs(h->
e[6]->
V() - vri[6]) > AVG * tol ||
775 fabs(h->
e[7]->
V() - vri[7]) > AVG * tol || fabs(v - vr) > AVG * tol ||
776 fabs(vd - vr) > AVG * tol) {
795 cleanElement<adaptivePrism>();
809 if(level++ >= maxlevel)
return;
886 for(
int i = 0; i < 8; i++) vi[i] =
p->e[i]->V();
888 (vi[0] + vi[1] + vi[2] + vi[3] / 2 + vi[4] + vi[5] + vi[6] + vi[7] / 2) /
890 const double v =
p->V();
892 if(fabs(v - vr) > AVG * tol) {
908 for(
int i = 0; i < 8; i++) {
909 double vi1 =
p->e[i]->e[0]->V();
910 double vi2 =
p->e[i]->e[1]->V();
911 double vi3 =
p->e[i]->e[2]->V();
912 double vi4 =
p->e[i]->e[3]->V();
913 double vi5 =
p->e[i]->e[4]->V();
914 double vi6 =
p->e[i]->e[5]->V();
915 double vi7 =
p->e[i]->e[6]->V();
916 double vi8 =
p->e[i]->e[7]->V();
918 (vi1 + vi2 + vi3 + vi4 / 2 + vi5 + vi6 + vi7 + vi8 / 2) / 7;
919 err |= (fabs((vi[i] - vri)) > AVG * tol);
921 err |= (fabs((v - vr)) > AVG * tol);
924 for(
int i = 0; i < 8; i++)
recurError(
p->e[i], AVG, tol);
934 cleanElement<adaptivePyramid>();
947 if(level++ >= maxlevel)
return;
962 (p1->
y + p2->
y + p3->
y + p4->
y) * 0.25,
1044 for(
int i = 0; i < 10; i++) vi[i] =
p->e[i]->V();
1046 for(
int i = 0; i < 6; i++) vr += vi[i];
1047 for(
int i = 6; i < 10; i++)
1050 const double v =
p->V();
1051 if(!
p->e[0]->e[0]) {
1052 if(fabs(v - vr) > AVG * tol) {
1054 for(
int i = 0; i < 10; i++)
recurError(
p->e[i], AVG, tol);
1061 for(
int i = 0; i < 10; i++) {
1063 for(
int j = 0; j < 10; j++) vj[j] =
p->e[i]->e[j]->V();
1065 for(
int j = 0; j < 6; j++) vri += vj[j];
1066 for(
int j = 6; j < 10; j++) vri += vj[j] * 0.5;
1068 err |= (fabs((vi[i] - vri)) > AVG * tol);
1070 err |= (fabs((v - vr)) > AVG * tol);
1073 for(
int i = 0; i < 10; i++)
recurError(
p->e[i], AVG, tol);
1083 : _coeffsVal(nullptr), _eexpsVal(nullptr), _interpolVal(nullptr),
1084 _coeffsGeom(nullptr), _eexpsGeom(nullptr), _interpolGeom(nullptr)
1098 if(_interpolVal)
delete _interpolVal;
1099 if(_interpolGeom)
delete _interpolGeom;
1110 int numVals = _coeffsVal ? _coeffsVal->size1() : T::numNodes;
1111 int numNodes = _coeffsGeom ? _coeffsGeom->size1() : T::numNodes;
1113 if(_interpolVal)
delete _interpolVal;
1116 if(_interpolGeom)
delete _interpolGeom;
1125 for(
auto it = T::allVertices.begin(); it != T::allVertices.end(); ++it) {
1126 if(_coeffsVal && _eexpsVal)
1130 T::GSF(it->x, it->y, it->z, sfv);
1131 for(
int j = 0; j < numVals; j++) (*_interpolVal)(i, j) = sfv(j);
1133 if(_coeffsGeom && _eexpsGeom)
1137 T::GSF(it->x, it->y, it->z, sfg);
1138 for(
int j = 0; j < numNodes; j++) (*_interpolGeom)(i, j) = sfg(j);
1143 if(tmpv)
delete tmpv;
1144 if(tmpg)
delete tmpg;
1184 for(
int j = 0; j < numVals; j++) (*
_interpolVal)(i, j) = sfv(j);
1191 for(
int j = 0; j < numNodes; j++) (*
_interpolGeom)(i, j) = sfg(j);
1196 if(tmpv)
delete tmpv;
1197 if(tmpg)
delete tmpg;
1207 std::vector<PCoords> &coords,
1208 std::vector<PValues> &values,
double &minVal,
1210 bool onlyComputeMinMax)
1212 int numVertices = T::allVertices.size();
1219 int numVals = _coeffsVal ? _coeffsVal->size1() : T::numNodes;
1221 if(numVals != (
int)values.size()) {
1222 Msg::Warning(
"Wrong number of values in adaptation %d != %i", numVals,
1234 for(
int i = 0; i < numVals; i++) val(i) = values[i].v[0];
1239 for(
int i = 0; i < numVals; i++) {
1241 for(
int k = 0; k < numComp; k++)
1242 val(i) += values[i].v[k] * values[i].v[k];
1247 Msg::Error(
"Can only adapt scalar, vector or tensor data");
1252 _interpolVal->mult(val, res);
1256 for(
int i = 0; i < numVertices; i++) {
1257 minVal = std::min(minVal, res(i));
1258 maxVal = std::max(maxVal, res(i));
1260 if(onlyComputeMinMax)
return true;
1263 if(numComp == 3 || numComp == 9) {
1266 for(
int i = 0; i < numVals; i++) {
1267 for(
int k = 0; k < numComp; k++) { valxyz(i, k) = values[i].v[k]; }
1269 _interpolVal->
mult(valxyz, *resxyz);
1272 int numNodes = _coeffsGeom ? _coeffsGeom->size1() : T::numNodes;
1273 if(numNodes != (
int)coords.size()) {
1274 Msg::Error(
"Wrong number of nodes in adaptation %d != %i", numNodes,
1276 if(resxyz)
delete resxyz;
1281 for(
int i = 0; i < numNodes; i++) {
1282 xyz(i, 0) = coords[i].c[0];
1283 xyz(i, 1) = coords[i].c[1];
1284 xyz(i, 2) = coords[i].c[2];
1286 _interpolGeom->mult(xyz,
XYZ);
1294 for(
auto it = T::allVertices.begin(); it != T::allVertices.end(); ++it) {
1299 p->
val = (*resxyz)(i, 0);
1300 p->
valy = (*resxyz)(i, 1);
1301 p->
valz = (*resxyz)(i, 2);
1303 p->
valyx = (*resxyz)(i, 3);
1304 p->
valyy = (*resxyz)(i, 4);
1305 p->
valyz = (*resxyz)(i, 5);
1306 p->
valzx = (*resxyz)(i, 6);
1307 p->
valzy = (*resxyz)(i, 7);
1308 p->
valzz = (*resxyz)(i, 8);
1317 if(resxyz)
delete resxyz;
1319 for(
auto it = T::all.begin(); it != T::all.end(); it++)
1320 (*it)->visible =
false;
1322 if(!plug || tol != 0.) {
1323 double avg = fabs(maxVal - minVal);
1324 if(tol < 0) avg = 1.;
1332 for(
auto it = T::all.begin(); it != T::all.end(); it++) {
1333 if((*it)->visible) {
1335 for(
int i = 0; i < T::numNodes; i++) {
1336 coords.push_back(
PCoords(p[i]->X, p[i]->Y, p[i]->Z));
1338 case 1: values.push_back(
PValues(p[i]->val));
break;
1340 values.push_back(
PValues(p[i]->val, p[i]->valy, p[i]->valz));
1343 values.push_back(
PValues(p[i]->val, p[i]->valy, p[i]->valz,
1344 p[i]->valyx, p[i]->valyy, p[i]->valyz,
1345 p[i]->valzx, p[i]->valzy, p[i]->valzz));
1360 if(numComp != 1 && numComp != 3 && numComp != 9)
return;
1362 int numEle = 0, *outNb =
nullptr;
1363 std::vector<double> *outList =
nullptr;
1364 switch(T::numEdges) {
1368 (numComp == 1) ? &out->
NbSP : ((numComp == 3) ? &out->
NbVP : &out->
NbTP);
1370 (numComp == 1) ? &out->
SP : ((numComp == 3) ? &out->
VP : &out->
TP);
1375 (numComp == 1) ? &out->
NbSL : ((numComp == 3) ? &out->
NbVL : &out->
NbTL);
1377 (numComp == 1) ? &out->
SL : ((numComp == 3) ? &out->
VL : &out->
TL);
1382 (numComp == 1) ? &out->
NbST : ((numComp == 3) ? &out->
NbVT : &out->
NbTT);
1384 (numComp == 1) ? &out->
ST : ((numComp == 3) ? &out->
VT : &out->
TT);
1389 (numComp == 1) ? &out->
NbSQ : ((numComp == 3) ? &out->
NbVQ : &out->
NbTQ);
1391 (numComp == 1) ? &out->
SQ : ((numComp == 3) ? &out->
VQ : &out->
TQ);
1396 (numComp == 1) ? &out->
NbSS : ((numComp == 3) ? &out->
NbVS : &out->
NbTS);
1398 (numComp == 1) ? &out->
SS : ((numComp == 3) ? &out->
VS : &out->
TS);
1403 (numComp == 1) ? &out->
NbSI : ((numComp == 3) ? &out->
NbVI : &out->
NbTI);
1405 (numComp == 1) ? &out->
SI : ((numComp == 3) ? &out->
VI : &out->
TI);
1410 (numComp == 1) ? &out->
NbSY : ((numComp == 3) ? &out->
NbVY : &out->
NbTY);
1412 (numComp == 1) ? &out->
SY : ((numComp == 3) ? &out->
VY : &out->
TY);
1417 (numComp == 1) ? &out->
NbSH : ((numComp == 3) ? &out->
NbVH : &out->
NbTH);
1419 (numComp == 1) ? &out->
SH : ((numComp == 3) ? &out->
VH : &out->
TH);
1433 std::vector<PCoords> coords;
1434 for(
int i = 0; i < numNodes; i++) {
1436 in->
getNode(step, ent, ele, i, x, y,
z);
1437 coords.push_back(
PCoords(x, y,
z));
1440 std::vector<PValues> values;
1444 for(
int i = 0; i < numVal; i++) {
1446 in->
getValue(step, ent, ele, i, val);
1447 values.push_back(
PValues(val));
1451 for(
int i = 0; i < numVal / 3; i++) {
1453 in->
getValue(step, ent, ele, 3 * i + 0, vx);
1454 in->
getValue(step, ent, ele, 3 * i + 1, vy);
1455 in->
getValue(step, ent, ele, 3 * i + 2, vz);
1456 values.push_back(
PValues(vx, vy, vz));
1461 for(
int i = 0; i < numVal / 9; i++) {
1462 double vxx, vxy, vxz, vyx, vyy, vyz, vzx, vzy, vzz;
1463 in->
getValue(step, ent, ele, 9 * i + 0, vxx);
1464 in->
getValue(step, ent, ele, 9 * i + 1, vxy);
1465 in->
getValue(step, ent, ele, 9 * i + 2, vxz);
1466 in->
getValue(step, ent, ele, 9 * i + 3, vyx);
1467 in->
getValue(step, ent, ele, 9 * i + 4, vyy);
1468 in->
getValue(step, ent, ele, 9 * i + 5, vyz);
1469 in->
getValue(step, ent, ele, 9 * i + 6, vzx);
1470 in->
getValue(step, ent, ele, 9 * i + 7, vzy);
1471 in->
getValue(step, ent, ele, 9 * i + 8, vzz);
1473 PValues(vxx, vxy, vxz, vyx, vyy, vyz, vzx, vzy, vzz));
1478 if(adapt(tol, numComp, coords, values, out->
Min, out->
Max, plug)) {
1479 *outNb += coords.size() / T::numNodes;
1480 for(std::size_t i = 0; i < coords.size() / T::numNodes; i++) {
1481 for(
int k = 0; k < T::numNodes; ++k)
1482 outList->push_back(coords[T::numNodes * i + k].c[0]);
1483 for(
int k = 0; k < T::numNodes; ++k)
1484 outList->push_back(coords[T::numNodes * i + k].c[1]);
1485 for(
int k = 0; k < T::numNodes; ++k)
1486 outList->push_back(coords[T::numNodes * i + k].c[2]);
1487 for(
int k = 0; k < T::numNodes; ++k)
1488 for(
int l = 0; l < numComp; ++l)
1489 outList->push_back(values[T::numNodes * i + k].v[l]);
1497 : _step(-1), _level(-1), _tol(-1.), _inData(data), _points(nullptr),
1498 _lines(nullptr), _triangles(nullptr), _quadrangles(nullptr),
1499 _tetrahedra(nullptr), _hexahedra(nullptr), _prisms(nullptr),
1510 std::vector<fullMatrix<double> *> p;
1605 if(*(
char *)&num == 1)
1615 unsigned char *ucDst = (
unsigned char *)
array;
1617 for(i = 0; i < nItems; i++) {
1618 for(j = 0; j < (nbytes / 2); j++)
1619 std::swap(ucDst[j], ucDst[(nbytes - 1) - j]);
1664 for(
int i = 0; i <
vtkNumComp; i++) { darray[counter + i] = it->v[i]; }
1675 darray =
new double[3 * sizeArray];
1678 for(
int i = 0; i < 3; i++) { darray[counter + i] = (*it).c[i]; }
1682 fwrite(darray,
sizeof(
double), 3 * sizeArray,
vtkFileCoord);
1690 int cellSizeData = 0;
1695 cellSizeData += (int)it->size();
1700 int cellcounter = 0;
1701 i64array =
new uint64_t[cellSizeData];
1705 for(
auto jt = it->begin(); jt != it->end(); ++jt) {
1706 i64array[counter] = *jt;
1713 fwrite(i64array,
sizeof(uint64_t), cellSizeData,
vtkFileConnect);
1719 delete[] cellOffset;
1726 i8array[counter] = *it;
1745 fprintf(
vtkFileCoord,
"%23.16e %23.16e %23.16e ", (*it).c[0],
1746 (*it).c[1], (*it).c[2]);
1754 int cellcounter = 0;
1757 for(
auto jt = it->begin(); jt != it->end(); ++jt) {
1772 delete[] cellOffset;
1815 "_npart" + ToString<int>(
vtkNpart);
1819 std::size_t found =
vtkFileName.find_last_of(
'.');
1832 if(littleEndian ==
true)
1833 fprintf(
vtkFile,
"<VTKFile type=\"PUnstructuredGrid\" version=\"1.0\" "
1834 "byte_order=\"LittleEndian\">\n");
1836 fprintf(
vtkFile,
"<VTKFile type=\"PUnstructuredGrid\" version=\"1.0\" "
1837 "byte_order=\"BigEndian\">\n");
1839 fprintf(
vtkFile,
"<PUnstructuredGrid GhostLevel=\"0\">\n");
1840 fprintf(
vtkFile,
"<PPoints>\n");
1841 fprintf(
vtkFile,
"<DataArray type=\"Float64\" Name=\"Points\" "
1842 "NumberOfComponents=\"3\"/>\n");
1843 fprintf(
vtkFile,
"</PPoints>\n");
1845 fprintf(
vtkFile,
"<PCells>\n");
1846 fprintf(
vtkFile,
"<PDataArray type=\"Int64\" Name=\"connectivity\" "
1847 "NumberOfComponents=\"1\"/>\n");
1848 fprintf(
vtkFile,
"<PDataArray type=\"Int64\" Name=\"offsets\" "
1849 "NumberOfComponents=\"1\"/>\n");
1852 "<PDataArray type=\"UInt8\" Name=\"types\" NumberOfComponents=\"1\"/>\n");
1853 fprintf(
vtkFile,
"</PCells>\n");
1855 fprintf(
vtkFile,
"<PPointData>\n");
1858 "<PDataArray type=\"Float64\" Name=\"%s\" NumberOfComponents=\"%d\"/>\n",
1860 fprintf(
vtkFile,
"</PPointData>\n");
1862 fprintf(
vtkFile,
"<PCellData>\n");
1863 fprintf(
vtkFile,
"</PCellData>\n");
1866 fprintf(
vtkFile,
"<Piece Source=\"%s/data%d.vtu\"/>\n",
1868 fprintf(
vtkFile,
"</PUnstructuredGrid>\n");
1869 fprintf(
vtkFile,
"</VTKFile>\n");
1891 std::string filename;
1895 "Writing VTK data in %s: fieldname = %s - numElm = %d - "
1896 "numNod = %d nodes\n",
1907 vtkFile = fopen(filename.c_str(),
"wb");
1909 printf(
"Could not open file %s\n", filename.c_str());
1913 uint64_t byteoffset = 0;
1917 if(littleEndian ==
true)
1918 fprintf(
vtkFile,
"<VTKFile type=\"UnstructuredGrid\" version=\"1.0\" "
1919 "byte_order=\"LittleEndian\" "
1920 "header_type=\"UInt64\">\n");
1922 fprintf(
vtkFile,
"<VTKFile type=\"PUnstructuredGrid\" version=\"1.0\" "
1923 "byte_order=\"BigEndian\" header_type=\"UInt64\">\n");
1924 fprintf(
vtkFile,
"<UnstructuredGrid>\n");
1925 fprintf(
vtkFile,
"<Piece NumberOfPoints=\"%d\" NumberOfCells=\"%d\">\n",
1929 fprintf(
vtkFile,
"<PointData>\n");
1931 "<DataArray type=\"Float64\" Name=\"%s\" "
1932 "NumberOfComponents=\"%d\" format=\"appended\" offset=\"%" PRIu64
1935 fprintf(
vtkFile,
"</PointData>\n");
1940 fprintf(
vtkFile,
"<CellData>\n");
1945 fprintf(
vtkFile,
"<Points>\n");
1947 "<DataArray type=\"Float64\" Name=\"Points\" "
1948 "NumberOfComponents=\"3\" format=\"appended\" offset=\"%" PRIu64
1951 fprintf(
vtkFile,
"</Points>\n");
1956 fprintf(
vtkFile,
"<Cells>\n");
1958 "<DataArray type=\"Int64\" Name=\"connectivity\" "
1959 "format=\"appended\" offset=\"%" PRIu64
"\"/>\n",
1963 "<DataArray type=\"Int64\" Name=\"offsets\" format=\"appended\" "
1964 "offset=\"%" PRIu64
"\"/>\n",
1966 byteoffset = byteoffset + (
vtkCountTotElm + 1) *
sizeof(uint64_t);
1968 "<DataArray type=\"UInt8\" Name=\"types\" format=\"appended\" "
1969 "offset=\"%" PRIu64
"\"/>\n",
1971 byteoffset = byteoffset + (
vtkCountTotElm + 1) *
sizeof(uint8_t);
1972 fprintf(
vtkFile,
"</Cells>\n");
1974 fprintf(
vtkFile,
"</Piece>\n");
1975 fprintf(
vtkFile,
"</UnstructuredGrid>\n");
1977 fprintf(
vtkFile,
"<AppendedData encoding=\"raw\">\n");
1984 fwrite(&datasize,
sizeof(uint64_t), 1,
vtkFile);
1987 std::ifstream if_vtkNodeValue(
"vtkNodeValue.vtu", std::ios_base::binary);
1988 std::ofstream of_vtkfile(filename.c_str(),
1989 std::ios_base::binary | std::ios_base::app);
1990 of_vtkfile << if_vtkNodeValue.rdbuf();
1991 if_vtkNodeValue.close();
1995 vtkFile = fopen(filename.c_str(),
"ab");
1997 fwrite(&datasize,
sizeof(uint64_t), 1,
vtkFile);
2000 std::ifstream if_vtkCoords(
"vtkCoords.vtu", std::ios_base::binary);
2001 of_vtkfile.open(filename.c_str(),
2002 std::ios_base::binary | std::ios_base::app);
2003 of_vtkfile << if_vtkCoords.rdbuf();
2004 if_vtkCoords.close();
2009 vtkFile = fopen(filename.c_str(),
"ab");
2011 fwrite(&datasize,
sizeof(uint64_t), 1,
vtkFile);
2014 std::ifstream if_vtkConnectivity(
"vtkConnectivity.vtu",
2015 std::ios_base::binary);
2016 of_vtkfile.open(filename.c_str(),
2017 std::ios_base::binary | std::ios_base::app);
2018 of_vtkfile << if_vtkConnectivity.rdbuf();
2019 if_vtkConnectivity.close();
2023 vtkFile = fopen(filename.c_str(),
"ab");
2025 fwrite(&datasize,
sizeof(uint64_t), 1,
vtkFile);
2028 std::ifstream if_vtkCellOffset(
"vtkCellOffset.vtu",
2029 std::ios_base::binary);
2030 of_vtkfile.open(filename.c_str(),
2031 std::ios_base::binary | std::ios_base::app);
2032 of_vtkfile << if_vtkCellOffset.rdbuf();
2033 if_vtkCellOffset.close();
2037 vtkFile = fopen(filename.c_str(),
"ab");
2039 fwrite(&datasize,
sizeof(uint64_t), 1,
vtkFile);
2042 std::ifstream if_vtkCellType(
"vtkCellType.vtu", std::ios_base::binary);
2043 of_vtkfile.open(filename.c_str(),
2044 std::ios_base::binary | std::ios_base::app);
2045 of_vtkfile << if_vtkCellType.rdbuf();
2046 if_vtkCellType.close();
2049 vtkFile = fopen(filename.c_str(),
"ab");
2051 fprintf(
vtkFile,
"</AppendedData>\n");
2052 fprintf(
vtkFile,
"</VTKFile>\n");
2057 vtkFile = fopen(filename.c_str(),
"w");
2059 printf(
"Could not open file %s\n", filename.c_str());
2063 if(littleEndian ==
true)
2064 fprintf(
vtkFile,
"<VTKFile type=\"UnstructuredGrid\" version=\"1.0\" "
2065 "byte_order=\"LittleEndian\" "
2066 "header_type=\"UInt64\">\n");
2068 fprintf(
vtkFile,
"<VTKFile type=\"PUnstructuredGrid\" version=\"1.0\" "
2069 "byte_order=\"BigEndian\" header_type=\"UInt64\">\n");
2070 fprintf(
vtkFile,
"<UnstructuredGrid>\n");
2071 fprintf(
vtkFile,
"<Piece NumberOfPoints=\"%d\" NumberOfCells=\"%d\">\n",
2075 fprintf(
vtkFile,
"<PointData>\n");
2077 "<DataArray type=\"Float64\" Name=\"%s\" "
2078 "NumberOfComponents=\"%d\" format=\"ascii\">\n",
2082 std::ifstream if_vtkNodeValue(
"vtkNodeValue.vtu", std::ios_base::binary);
2083 std::ofstream of_vtkfile(filename.c_str(),
2084 std::ios_base::binary | std::ios_base::app);
2085 of_vtkfile << if_vtkNodeValue.rdbuf();
2086 if_vtkNodeValue.close();
2089 vtkFile = fopen(filename.c_str(),
"a");
2090 fprintf(
vtkFile,
"</DataArray>\n");
2091 fprintf(
vtkFile,
"</PointData>\n");
2094 fprintf(
vtkFile,
"<CellData>\n");
2095 fprintf(
vtkFile,
"</CellData>\n");
2098 fprintf(
vtkFile,
"<Points>\n");
2099 fprintf(
vtkFile,
"<DataArray type=\"Float64\" Name=\"Points\" "
2100 "NumberOfComponents=\"3\" format=\"ascii\">\n");
2103 of_vtkfile.open(filename.c_str(),
2104 std::ios_base::binary | std::ios_base::app);
2105 std::ifstream if_vtkCoords(
"vtkCoords.vtu", std::ios_base::binary);
2106 of_vtkfile << if_vtkCoords.rdbuf();
2107 if_vtkCoords.close();
2110 vtkFile = fopen(filename.c_str(),
"a");
2111 fprintf(
vtkFile,
"</DataArray>\n");
2112 fprintf(
vtkFile,
"</Points>\n");
2115 fprintf(
vtkFile,
"<Cells>\n");
2118 "<DataArray type=\"Int64\" Name=\"connectivity\" format=\"ascii\">\n");
2122 of_vtkfile.open(filename.c_str(),
2123 std::ios_base::binary | std::ios_base::app);
2124 std::ifstream if_vtkConnectivity(
"vtkConnectivity.vtu",
2125 std::ios_base::binary);
2126 of_vtkfile << if_vtkConnectivity.rdbuf();
2127 if_vtkConnectivity.close();
2130 vtkFile = fopen(filename.c_str(),
"a");
2131 fprintf(
vtkFile,
"</DataArray>\n");
2135 "<DataArray type=\"Int64\" Name=\"offsets\" format=\"ascii\">\n");
2138 of_vtkfile.open(filename.c_str(),
2139 std::ios_base::binary | std::ios_base::app);
2140 std::ifstream if_vtkCellOffset(
"vtkCellOffset.vtu",
2141 std::ios_base::binary);
2142 of_vtkfile << if_vtkCellOffset.rdbuf();
2143 if_vtkCellOffset.close();
2146 vtkFile = fopen(filename.c_str(),
"a");
2147 fprintf(
vtkFile,
"</DataArray>\n");
2151 "<DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">\n");
2154 of_vtkfile.open(filename.c_str(),
2155 std::ios_base::binary | std::ios_base::app);
2156 std::ifstream if_vtkCellType(
"vtkCellType.vtu", std::ios_base::binary);
2157 of_vtkfile << if_vtkCellType.rdbuf();
2158 if_vtkCellType.close();
2161 vtkFile = fopen(filename.c_str(),
"a");
2162 fprintf(
vtkFile,
"</DataArray>\n");
2163 fprintf(
vtkFile,
"</Cells>\n");
2165 fprintf(
vtkFile,
"</Piece>\n");
2166 fprintf(
vtkFile,
"</UnstructuredGrid>\n");
2168 fprintf(
vtkFile,
"</VTKFile>\n");
2173 if(remove(
"vtkCoords.vtu") != 0)
2174 printf(
"ERROR: Could not remove vtkCoords.vtu\n");
2175 if(remove(
"vtkConnectivity.vtu") != 0)
2176 printf(
"ERROR: Could not remove vtkConnectivity.vtu\n");
2177 if(remove(
"vtkCellOffset.vtu") != 0)
2178 printf(
"ERROR: Could not remove vtkCellOffset.vtu\n");
2179 if(remove(
"vtkCellType.vtu") != 0)
2180 printf(
"ERROR: Could not remove vtkCellType.vtu\n");
2181 if(remove(
"vtkNodeValue.vtu") != 0)
2182 printf(
"ERROR: Could not remove vtkNodeValue.vtu\n");
2204 "WARNING: Trying to write a node to the ParaView data base and file\n");
2209 "WARNING: Trying to write a node to the ParaView data base and file\n");
2231 printf(
"ERROR: No cell type was detected\n");
2241 std::vector<PCoords> &coords,
2242 std::vector<PValues> &values,
2243 double &minVal,
double &maxVal)
2245 int numVertices = T::allVertices.size();
2248 Msg::Error(
"No adapted vertices to interpolate");
2252 int numVals = _coeffsVal ? _coeffsVal->size1() : T::numNodes;
2253 if(numVals != (
int)values.size()) {
2254 Msg::Error(
"Wrong number of values in adaptation %d != %i", numVals,
2266 for(
int i = 0; i < numVals; i++) val(i) = values[i].v[0];
2271 for(
int i = 0; i < numVals; i++) {
2273 for(
int k = 0; k < numComp; k++)
2274 val(i) += values[i].v[k] * values[i].v[k];
2279 Msg::Error(
"Can only adapt scalar, vector or tensor data");
2284 _interpolVal->mult(val, res);
2286 for(
int i = 0; i < numVertices; i++) {
2287 minVal = std::min(minVal, res(i));
2288 maxVal = std::max(maxVal, res(i));
2292 if(numComp == 3 || numComp == 9) {
2295 for(
int i = 0; i < numVals; i++) {
2296 for(
int k = 0; k < numComp; k++) { valxyz(i, k) = values[i].v[k]; }
2298 _interpolVal->
mult(valxyz, *resxyz);
2301 int numNodes = _coeffsGeom ? _coeffsGeom->size1() : T::numNodes;
2302 if(numNodes != (
int)coords.size()) {
2303 Msg::Error(
"Wrong number of nodes in adaptation %d != %i", numNodes,
2305 if(resxyz)
delete resxyz;
2310 for(
int i = 0; i < numNodes; i++) {
2311 xyz(i, 0) = coords[i].c[0];
2312 xyz(i, 1) = coords[i].c[1];
2313 xyz(i, 2) = coords[i].c[2];
2315 _interpolGeom->mult(xyz,
XYZ);
2323 for(
auto it = T::allVertices.begin(); it != T::allVertices.end(); ++it) {
2328 p->
val = (*resxyz)(i, 0);
2329 p->
valy = (*resxyz)(i, 1);
2330 p->
valz = (*resxyz)(i, 2);
2332 p->
valyx = (*resxyz)(i, 3);
2333 p->
valyy = (*resxyz)(i, 4);
2334 p->
valyz = (*resxyz)(i, 5);
2335 p->
valzx = (*resxyz)(i, 6);
2336 p->
valzy = (*resxyz)(i, 7);
2337 p->
valzz = (*resxyz)(i, 8);
2346 if(resxyz)
delete resxyz;
2348 for(
auto it = T::all.begin(); it != T::all.end(); it++)
2349 (*it)->visible =
false;
2352 double avg = fabs(maxVal - minVal);
2353 if(tol < 0) avg = 1.;
2359 for(
auto it = T::all.begin(); it != T::all.end(); it++) {
2360 if((*it)->visible) {
2362 for(
int i = 0; i < T::numNodes; i++) {
2363 coords.push_back(
PCoords(p[i]->X, p[i]->Y, p[i]->Z));
2365 case 1: values.push_back(
PValues(p[i]->val));
break;
2367 values.push_back(
PValues(p[i]->val, p[i]->valy, p[i]->valz));
2370 values.push_back(
PValues(p[i]->val, p[i]->valy, p[i]->valz,
2371 p[i]->valyx, p[i]->valyy, p[i]->valyz,
2372 p[i]->valzx, p[i]->valzy, p[i]->valzz));
2384 if(tol > 0.0 || myNodMap.
getSize() == 0) {
2392 for(
auto itleaf = T::all.begin(); itleaf != T::all.end(); itleaf++) {
2395 if((*itleaf)->visible ==
true) {
2398 for(
int i = 0; i < T::numNodes; i++) {
2402 pquery.
x = (*itleaf)->p[i]->x;
2403 pquery.
y = (*itleaf)->p[i]->y;
2404 pquery.
z = (*itleaf)->p[i]->z;
2405 auto it = T::allVertices.find(pquery);
2406 if(it == T::allVertices.end()) {
2407 Msg::Error(
"Could not find adaptive Vertex in "
2408 "adaptiveElements<T>::buildMapping %f %f %f",
2409 pquery.
x, pquery.
y, pquery.
z);
2415 myNodMap.
mapping.push_back(dist);
2418 assert(it != T::allVertices.end());
2423 if(myNodMap.
mapping.size() == 0) {
2424 Msg::Error(
"Node mapping in buildMapping has zero size");
2430 std::set<int> uniqueNod;
2431 for(
auto it = myNodMap.
mapping.begin(); it != myNodMap.
mapping.end();
2433 uniqueNod.insert(*it);
2435 numNodInsert = (int)uniqueNod.size();
2442 for(
auto it = myNodMap.
mapping.begin(); it != myNodMap.
mapping.end();
2444 auto jt = uniqueNod.find(*it);
2453 VTKData &myVTKData,
bool writeVTK,
2454 bool buildStaticData)
2457 if(numComp != 1 && numComp != 3 && numComp != 9)
return;
2460 switch(T::numEdges) {
2473 int numNodInsert = 0;
2476 double minVal = in->
getMin(step);
2477 double maxVal = in->
getMax(step);
2485 std::vector<PCoords> coords;
2486 for(
int i = 0; i < numNodes; i++) {
2488 in->
getNode(step, ent, ele, i, x, y,
z);
2489 coords.push_back(
PCoords(x, y,
z));
2492 std::vector<PValues> values;
2496 for(
int i = 0; i < numVal; i++) {
2498 in->
getValue(step, ent, ele, i, val);
2499 values.push_back(
PValues(val));
2503 for(
int i = 0; i < numVal / 3; i++) {
2505 in->
getValue(step, ent, ele, 3 * i, vx);
2506 in->
getValue(step, ent, ele, 3 * i + 1, vy);
2507 in->
getValue(step, ent, ele, 3 * i + 2, vz);
2508 values.push_back(
PValues(vx, vy, vz));
2512 for(
int i = 0; i < numVal / 9; i++) {
2513 double vxx, vxy, vxz, vyx, vyy, vyz, vzx, vzy, vzz;
2514 in->
getValue(step, ent, ele, 9 * i + 0, vxx);
2515 in->
getValue(step, ent, ele, 9 * i + 1, vxy);
2516 in->
getValue(step, ent, ele, 9 * i + 2, vxz);
2517 in->
getValue(step, ent, ele, 9 * i + 3, vyx);
2518 in->
getValue(step, ent, ele, 9 * i + 4, vyy);
2519 in->
getValue(step, ent, ele, 9 * i + 5, vyz);
2520 in->
getValue(step, ent, ele, 9 * i + 6, vzx);
2521 in->
getValue(step, ent, ele, 9 * i + 7, vzy);
2522 in->
getValue(step, ent, ele, 9 * i + 8, vzz);
2524 PValues(vxx, vxy, vxz, vyx, vyy, vyz, vzx, vzy, vzz));
2529 adaptForVTK(myVTKData.
vtkTol, numComp, coords, values, minVal,
2536 buildMapping(myNodMap, myVTKData.
vtkTol, numNodInsert);
2544 for(std::size_t i = 0; i < coords.size() / T::numNodes; i++) {
2553 for(
int k = 0; k < T::numNodes; ++k) {
2555 int countTotNodloc = T::numNodes * i + k;
2558 vtkElmConnectivity.push_back(vtkNodeId);
2562 px = coords[T::numNodes * i + k].c[0];
2563 py = coords[T::numNodes * i + k].c[1];
2564 pz = coords[T::numNodes * i + k].c[2];
2571 values[T::numNodes * i + k];
2585 if(buildStaticData ==
true) {
2592 vtkElmConnectivity.clear();
2603 if(buildStaticData ==
true) {
2604 for(
int i = 0; i < numNodInsert; i++) {
2608 for(
int i = 0; i < numNodInsert; i++) {
2650 int npart,
bool isBinary,
2651 const std::string &guiFileName,
2658 step, level, tol, guiFileName, useDefaultName, npart,