22 #if defined(HAVE_LIBCGNS)
30 std::vector<SVector3> &points)
34 double ds = 1. / order;
35 for(
int i = 1; i < order; i++) {
37 points.push_back(p0 * (1. -
f) + p1 *
f);
41 std::vector<SVector3> generatePointsTriCGNS(
int order,
bool complete);
44 int order, std::vector<SVector3> &points)
48 std::vector<SVector3> triPoints = generatePointsTriCGNS(order - 3,
true);
50 double scale = double(order - 3) / double(order);
51 SVector3 offset(1. / order, 1. / order, 0);
53 for(
size_t i = 0; i < triPoints.size(); i++) {
55 double u = ip[0] *
scale + 1. / order;
56 double v = ip[1] *
scale + 1. / order;
57 SVector3 pt = (1. - u - v) * p0 + u * p1 + v * p2;
62 void addQuaPointsCGNS(
int order, std::vector<SVector3> &points)
65 double scale = double(order - 2) / double(order);
70 for(
int i = 0; i < 4; i++) {
73 double ds = 1. / (order - 2);
74 for(
int i = 0; i < order - 2; i++)
75 points.push_back((
c1 * (1. - i * ds) + c2 * (i * ds)) *
scale);
79 if(order == 2 || order == 4) points.push_back(
SVector3(0, 0, 0));
84 std::vector<SVector3> &points)
86 std::vector<SVector3> quaPoints;
88 addQuaPointsCGNS(order, quaPoints);
90 for(
size_t i = 0; i < quaPoints.size(); i++) {
94 SVector3 pt = ((1. - u) * (1. - v) * p0 + (1. + u) * (1. - v) * p1 +
95 (1. + u) * (1. + v) * p2 + (1. - u) * (1. + v) * p3) *
114 std::vector<SVector3> generatePointsEdgeCGNS(
int order)
116 std::vector<SVector3> pp;
128 addEdgePointsCGNS(pp[0], pp[1], order, pp);
133 std::vector<SVector3> generatePointsTriCGNS(
int order,
bool complete)
135 std::vector<SVector3> pp;
138 pp.push_back(
SVector3(1. / 3., 1. / 3., 0.));
148 for(
int i = 0; i < 3; i++) {
149 addEdgePointsCGNS(pp[i], pp[(i + 1) % 3], order, pp);
153 if(complete && order > 2) {
154 addTriPointsCGNS(pp[0], pp[1], pp[2], order, pp);
160 std::vector<SVector3> generatePointsQuaCGNS(
int order,
bool complete)
162 std::vector<SVector3> pp;
176 for(
int i = 0; i < 4; i++) {
177 addEdgePointsCGNS(pp[i], pp[(i + 1) % 4], order, pp);
181 if(complete && order > 1) {
182 addQuaPointsCGNS(pp[0], pp[1], pp[2], pp[3], order, pp);
188 std::vector<SVector3> generatePointsTetCGNS(
int order,
bool complete)
190 std::vector<SVector3> pp;
193 pp.push_back(
SVector3(1. / 4., 1. / 4., 1. / 4.));
204 for(
int i = 0; i < 3; i++)
205 addEdgePointsCGNS(pp[i], pp[(i + 1) % 3], order, pp);
208 for(
int i = 0; i < 3; i++) addEdgePointsCGNS(pp[i], pp[3], order, pp);
210 if(complete && order > 2) {
212 addTriPointsCGNS(pp[0], pp[1], pp[2], order, pp);
215 for(
int i = 0; i < 3; i++) {
216 addTriPointsCGNS(pp[i], pp[(i + 1) % 3], pp[3], order, pp);
221 std::vector<SVector3> tetPp = generatePointsTetCGNS(order - 4,
true);
223 double scale = (order - 4) / order;
224 SVector3 offset(1. / order, 1. / order, 1. / order);
225 for(
size_t i = 0; i < tetPp.size(); i++) {
227 volumePoint *=
scale;
228 volumePoint += offset;
229 pp.push_back(volumePoint);
237 std::vector<SVector3> generatePointsHexCGNS(
int order,
bool complete)
239 std::vector<SVector3> pp;
257 for(
int i = 0; i < 4; i++)
258 addEdgePointsCGNS(pp[i], pp[(i + 1) % 4], order, pp);
260 std::vector<SVector3> up[4];
262 for(
int i = 0; i < 4; i++) {
263 addEdgePointsCGNS(pp[i], pp[i + 4], order, up[i]);
264 pp.insert(pp.end(), up[i].begin(), up[i].end());
268 for(
int i = 0; i < 4; i++)
269 addEdgePointsCGNS(pp[i + 4], pp[(i + 1) % 4 + 4], order, pp);
271 if(complete && order > 1) {
273 addQuaPointsCGNS(pp[0], pp[1], pp[2], pp[3], order, pp);
276 for(
int i = 0; i < 4; i++) {
277 addQuaPointsCGNS(pp[i], pp[(i + 1) % 4], pp[(i + 1) % 4 + 4], pp[i + 4],
282 addQuaPointsCGNS(pp[4], pp[5], pp[6], pp[7], order, pp);
285 for(
int i = 0; i <= order - 2; i++) {
286 addQuaPointsCGNS(up[0][i], up[1][i], up[2][i], up[3][i], order, pp);
293 std::vector<SVector3> generatePointsPriCGNS(
int order,
bool complete)
295 std::vector<SVector3> pp;
298 pp.push_back(
SVector3(1. / 3., 1. / 3., 0.));
311 for(
int i = 0; i < 3; i++)
312 addEdgePointsCGNS(pp[i], pp[(i + 1) % 3], order, pp);
315 std::vector<SVector3> edge[3];
316 for(
int i = 0; i < 3; i++) {
317 addEdgePointsCGNS(pp[i], pp[i + 3], order, edge[i]);
318 pp.insert(pp.end(), edge[i].begin(), edge[i].end());
322 for(
int i = 0; i < 3; i++)
323 addEdgePointsCGNS(pp[i + 3], pp[(i + 1) % 3 + 3], order, pp);
327 addTriPointsCGNS(pp[0], pp[1], pp[2], order, pp);
330 for(
int i = 0; i < 3; i++) {
331 addQuaPointsCGNS(pp[i], pp[(i + 1) % 3], pp[(i + 1) % 3 + 3], pp[i + 3],
336 addTriPointsCGNS(pp[3], pp[4], pp[5], order, pp);
339 for(
int o = 0; o < order - 1; o++) {
340 addTriPointsCGNS(edge[0][o], edge[1][o], edge[2][o], order, pp);
348 std::vector<SVector3> generatePointsPyrCGNS(
int order,
bool complete)
350 std::vector<SVector3> pp;
365 for(
int i = 0; i < 4; i++)
366 addEdgePointsCGNS(pp[i], pp[(i + 1) % 4], order, pp);
369 for(
int i = 0; i < 4; i++) addEdgePointsCGNS(pp[i], pp[4], order, pp);
372 addQuaPointsCGNS(pp[0], pp[1], pp[2], pp[3], order, pp);
375 for(
int i = 0; i < 4; i++)
376 addTriPointsCGNS(pp[i], pp[(i + 1) % 4], pp[4], order, pp);
380 std::vector<SVector3> pyr = generatePointsPyrCGNS(order - 3,
true);
382 double scale = double(order - 3) / double(order);
383 for(
size_t i = 0; i < pyr.size(); ++i)
384 pp.push_back((pyr[i] *
scale) + offset);
393 std::vector<SVector3> pts;
396 case TYPE_LIN: pts = generatePointsEdgeCGNS(order);
break;
397 case TYPE_TRI: pts = generatePointsTriCGNS(order, complete);
break;
398 case TYPE_QUA: pts = generatePointsQuaCGNS(order, complete);
break;
399 case TYPE_TET: pts = generatePointsTetCGNS(order, complete);
break;
400 case TYPE_HEX: pts = generatePointsHexCGNS(order, complete);
break;
401 case TYPE_PRI: pts = generatePointsPriCGNS(order, complete);
break;
402 case TYPE_PYR: pts = generatePointsPyrCGNS(order, complete);
break;
404 Msg::Error(
"CGNS element %s of order %i not yet implemented",
422 for(
size_t i = 0; i < pts.size(); i++) {
423 for(
size_t d = 0; d < dim; d++) ptsCGNS(i, d) = pts[i][d];
429 std::vector<int> cgns2MshNodeIndexInit(
int mshTag)
434 std::vector<int> nodes(nNode);
445 for(
int i = 0; i < nNode; i++) nodes[i] = i;
452 const bool reorderOK = computeReordering(ptsCGNS, nb->
points, nodes);
454 Msg::Error(
"Could not compute reordering between Gmsh and CGNS element "
455 "nodes for MSH type %i", mshTag);
466 std::vector<CGNS_ENUMT(ElementType_t)> msh2CgnsEltTypeInit()
468 std::vector<CGNS_ENUMT(ElementType_t)> cgnsType(
472 cgnsType[
MSH_PNT] = CGNS_ENUMV(NODE);
477 cgnsType[
MSH_QUA_4] = CGNS_ENUMV(QUAD_4);
478 cgnsType[
MSH_TET_4] = CGNS_ENUMV(TETRA_4);
479 cgnsType[
MSH_PYR_5] = CGNS_ENUMV(PYRA_5);
480 cgnsType[
MSH_PRI_6] = CGNS_ENUMV(PENTA_6);
481 cgnsType[
MSH_HEX_8] = CGNS_ENUMV(HEXA_8);
486 cgnsType[
MSH_QUA_8] = CGNS_ENUMV(QUAD_8);
487 cgnsType[
MSH_QUA_9] = CGNS_ENUMV(QUAD_9);
536 std::vector<int> cgns2MshEltTypeInit()
538 std::vector<int> mshType(NofValidElementTypes, 0);
541 mshType[CGNS_ENUMV(NODE)] =
MSH_PNT;
547 mshType[CGNS_ENUMV(TETRA_4)] =
MSH_TET_4;
549 mshType[CGNS_ENUMV(PENTA_6)] =
MSH_PRI_6;
608 CGNS_ENUMT(ElementType_t) msh2CgnsEltType(
int mshTag)
610 static std::vector<CGNS_ENUMT(ElementType_t)> cgnsType =
611 msh2CgnsEltTypeInit();
613 if(mshTag >=
static_cast<int>(cgnsType.size()))
614 return CGNS_ENUMV(ElementTypeNull);
615 return cgnsType[mshTag];
619 int cgns2MshEltType(CGNS_ENUMT(ElementType_t) cgnsType)
621 static std::vector<int> mshType = cgns2MshEltTypeInit();
623 if(cgnsType >=
static_cast<int>(mshType.size()))
return 0;
624 return mshType[cgnsType];
628 std::vector<int> &cgns2MshNodeIndex(
int mshTag)
630 static std::vector<std::vector<int> > mshInd(
MSH_MAX_NUM + 1);
631 static std::vector<int> dumInd;
635 if(mshInd[mshTag].size() == 0) {
636 mshInd[mshTag] = cgns2MshNodeIndexInit(mshTag);
639 return mshInd[mshTag];
660 std::vector<double> &u, std::vector<double> &v,
661 std::vector<double> &w)
666 case TYPE_PNT: u[0] = mshPts(0, 0);
break;
668 for(
int i = 0; i < mshPts.
size1(); i++) { u[i] = mshPts(i, 0); }
671 for(
int i = 0; i < mshPts.
size1(); i++) {
677 for(
int i = 0; i < mshPts.
size1(); i++) {
684 for(
int i = 0; i < mshPts.
size1(); i++) {
685 u[i] = 2. * mshPts(i, 0) - 1.;
686 v[i] = 2. * mshPts(i, 1) - 1.;
690 for(
int i = 0; i < mshPts.
size1(); i++) {
691 u[i] = 2. * mshPts(i, 0) - 1.;
692 v[i] = 2. * mshPts(i, 1) - 1.;
693 w[i] = 2. * mshPts(i, 2) - 1.;
697 for(
int i = 0; i < mshPts.
size1(); i++) {
698 u[i] = 2. * mshPts(i, 0) - 1.;
699 v[i] = 2. * mshPts(i, 1) - 1.;
704 for(
int i = 0; i < mshPts.
size1(); i++) {
707 w[i] = 2. * mshPts(i, 2) - 1.;
711 Msg::Error(
"CGNS element %s not yet implemented",
717 std::vector<int> &ind)
719 static const double TOLSQ = 1e-10 * 1e-10;
721 const size_t nNode = src.
size1(), dim = src.
size2();
722 ind.resize(nNode, -1);
726 for(
size_t iSrc = 0; iSrc < nNode; iSrc++) {
727 for(
size_t iDest = 0; iDest < nNode; iDest++) {
728 const double xx = src(iSrc, 0) - dest(iDest, 0);
729 const double yy = (dim > 1) ? src(iSrc, 1) - dest(iDest, 1) : 0.;
730 const double zz = (dim > 2) ? src(iSrc, 2) - dest(iDest, 2) : 0.;
731 const double dd = xx * xx + yy * yy + zz * zz;
741 return (found.size() == nNode);
744 std::string cgnsString(
const std::string &s, std::string::size_type maxLength)
747 if(s2.size() > maxLength) s2.resize(maxLength);
751 #endif // HAVE_LIBCGNS