16 #if defined(HAVE_LIBCGNS)
20 MElement *createElement(CGNS_ENUMT(ElementType_t) sectEltType,
21 std::size_t vertShift,
int entity,
22 const std::vector<MVertex *> &allVert,
23 std::map<
int, std::vector<MElement *> > *allElt,
24 const std::vector<cgsize_t> §Data,
25 const ZoneEltNodeTransfo *eltNodeTransfo,
26 const std::vector<SPoint3> &rawNode,
27 std::size_t &iSectData)
30 CGNS_ENUMT(ElementType_t) eltType;
31 if(sectEltType == CGNS_ENUMV(MIXED)) {
32 eltType =
static_cast<CGNS_ENUMT(ElementType_t)
>(sectData[iSectData]);
36 eltType = sectEltType;
39 int mshEltType = cgns2MshEltType(eltType);
44 const std::vector<int> *nodeTransfo =
nullptr;
45 if((mshEltType !=
MSH_PNT) && (eltNodeTransfo !=
nullptr) &&
46 (eltNodeTransfo->size() > 0)) {
47 nodeTransfo = &((*eltNodeTransfo)[mshEltType]);
50 nodeTransfo = &(cgns2MshNodeIndex(mshEltType));
53 std::vector<MVertex *> eltVert(nbEltNode);
54 for(
int iEltNode = 0; iEltNode < nbEltNode; iEltNode++, iSectData++) {
55 const int indNode = vertShift + sectData[iSectData] - 1;
56 eltVert[(*nodeTransfo)[iEltNode]] = allVert[indNode];
65 case TYPE_PNT: allElt[0][entity].push_back(e);
break;
66 case TYPE_LIN: allElt[1][entity].push_back(e);
break;
67 case TYPE_TRI: allElt[2][entity].push_back(e);
break;
68 case TYPE_QUA: allElt[3][entity].push_back(e);
break;
69 case TYPE_TET: allElt[4][entity].push_back(e);
break;
70 case TYPE_HEX: allElt[5][entity].push_back(e);
break;
71 case TYPE_PRI: allElt[6][entity].push_back(e);
break;
72 case TYPE_PYR: allElt[7][entity].push_back(e);
break;
73 case TYPE_POLYG: allElt[8][entity].push_back(e);
break;
74 case TYPE_POLYH: allElt[9][entity].push_back(e);
break;
83 CGNSZoneUnstruct::CGNSZoneUnstruct(
84 int fileIndex,
int baseIndex,
int zoneIndex,
int meshDim, cgsize_t startNode,
85 const Family2EltNodeTransfo &allEltNodeTransfo,
int &err)
86 : CGNSZone(fileIndex, baseIndex, zoneIndex, CGNS_ENUMV(Unstructured), meshDim,
87 startNode, allEltNodeTransfo, err)
95 interfaceNode_.resize(nbNode());
98 int CGNSZoneUnstruct::readSection(
99 int iSect,
const std::vector<MVertex *> &allVert,
100 const std::vector<SPoint3> &rawNode,
101 std::map<
int, std::vector<MElement *> > *allElt,
102 std::vector<MElement *> &zoneElt)
107 char sectName[CGNS_MAX_STR_LEN];
108 CGNS_ENUMT(ElementType_t) sectEltType;
109 cgsize_t startElt, endElt;
110 int nbBnd, parentFlag;
112 cg_section_read(fileIndex(), baseIndex(), index(), iSect, sectName,
113 §EltType, &startElt, &endElt, &nbBnd, &parentFlag);
114 if(cgnsErr != CG_OK)
return cgnsError(__FILE__, __LINE__, fileIndex());
117 #if CGNS_VERSION < 4000
118 if(sectEltType == CGNS_ENUMV(MIXED)) {
119 Msg::Error(
"Reading 'MIXED' element sections requires CGNS library "
128 cg_ElementDataSize(fileIndex(), baseIndex(), index(), iSect, &dataSize);
129 if(cgnsErr != CG_OK)
return cgnsError(__FILE__, __LINE__, fileIndex());
132 std::vector<cgsize_t> sectData(dataSize), offsetData(endElt - startElt + 2);
133 if(sectEltType == CGNS_ENUMV(MIXED)) {
134 #if CGNS_VERSION >= 4000
136 cg_poly_elements_read(fileIndex(), baseIndex(), index(), iSect,
137 sectData.data(), offsetData.data(),
nullptr);
141 cgnsErr = cg_elements_read(fileIndex(), baseIndex(), index(), iSect,
142 sectData.data(),
nullptr);
144 if(cgnsErr != CG_OK)
return cgnsError(__FILE__, __LINE__, fileIndex());
147 std::size_t iSectData = 0;
148 if(endElt > (cgsize_t)zoneElt.size()) zoneElt.resize(endElt);
149 const cgsize_t iStartElt = startElt - 1, iEndElt = endElt - 1;
150 for(
int iElt = iStartElt; iElt <= iEndElt; iElt++) {
151 const auto it = elt2Geom().find(iElt);
152 const int entity = (it == elt2Geom().end()) ? 1 : it->second;
154 createElement(sectEltType, startNode(), entity, allVert, allElt, sectData,
155 eltNodeTransfo(), rawNode, iSectData);
162 int CGNSZoneUnstruct::readElements(
163 std::vector<MVertex *> &allVert,
164 std::map<
int, std::vector<MElement *> > *allElt,
165 std::vector<MElement *> &zoneElt, std::vector<std::string> &allGeomName)
171 std::vector<SPoint3> rawNode;
172 if(eltNodeTransfo() !=
nullptr) {
174 rawNode.resize(nbNode());
175 for(
int iN = 0; iN < nbNode(); iN++) {
176 rawNode[iN] = allVert[startNode() + iN]->point();
182 cgnsErr = cg_nsections(fileIndex(), baseIndex(), index(), &nbSect);
183 if(cgnsErr != CG_OK)
return cgnsError(__FILE__, __LINE__, fileIndex());
186 zoneElt.reserve(nbElt());
187 for(
int iSect = 1; iSect <= nbSect; iSect++) {
188 int err = readSection(iSect, allVert, rawNode, allElt, zoneElt);
189 if(err == 0)
return 0;
195 #endif // HAVE_LIBCGNS