18 #if defined(HAVE_LIBCGNS)
21 std::vector<std::vector<MVertex *> > &vertPerZone,
22 std::vector<std::vector<MElement *> > &eltPerZone)
28 cgnsErr = cg_open(name.c_str(), CG_MODE_READ, &fileIndex);
29 if(cgnsErr != CG_OK)
return cgnsError(__FILE__, __LINE__, fileIndex);
32 const int baseIndex = 1;
33 int dim = 0, meshDim = 0;
34 char baseName[CGNS_MAX_STR_LEN];
35 cgnsErr = cg_base_read(fileIndex, baseIndex, baseName, &meshDim, &dim);
36 if(cgnsErr != CG_OK)
return cgnsError(__FILE__, __LINE__, fileIndex);
40 int scaleErr = readScale(fileIndex, baseIndex,
scale);
41 if(scaleErr == 0)
return 0;
44 Family2EltNodeTransfo allEltNodeTransfo;
45 readEltNodeTransfo(fileIndex, baseIndex, allEltNodeTransfo);
49 std::vector<std::string> allGeomName(2,
"");
53 cgnsErr = cg_nzones(fileIndex, baseIndex, &nbZone);
54 if(cgnsErr != CG_OK)
return cgnsError(__FILE__, __LINE__, fileIndex);
57 std::vector<CGNSZone *> allZones(nbZone + 1);
58 std::map<std::string, int> name2Zone;
60 createZones(fileIndex, baseIndex, meshDim, allEltNodeTransfo, allZones,
64 std::vector<MVertex *> allVert;
65 std::map<int, std::vector<MElement *> > allElt[10];
68 vertPerZone.resize(nbZone + 1);
69 eltPerZone.resize(nbZone + 1);
72 for(
int iZone = 1; iZone <= nbZone; iZone++) {
73 CGNSZone *zone = allZones[iZone];
75 zone->readMesh(dim,
scale, allZones, allVert, allElt, vertPerZone[iZone],
76 eltPerZone[iZone], allGeomName);
78 vertPerZone[iZone].clear();
79 eltPerZone[iZone].clear();
81 if(err == 0)
return 0;
85 for(
int iZone = 1; iZone <= nbZone; iZone++) {
86 allZones[iZone]->setPeriodicVertices(allZones, allVert);
90 std::multimap<std::string, int> geomName2Phys;
91 std::vector<std::string> allPhysName(1,
"");
92 int errPhys = readPhysicals(fileIndex, baseIndex, allPhysName, geomName2Phys);
93 if(errPhys == 0)
return 0;
96 cgnsErr = cg_close(fileIndex);
97 if(cgnsErr != CG_OK)
return cgnsError(__FILE__, __LINE__);
105 setPeriodicityInEntities(allZones);
113 setGeomAndPhysicalEntities(
this, meshDim, allGeomName, allPhysName,
116 for(std::size_t iZone = 0; iZone < allZones.size(); iZone++) {
117 if(allZones[iZone] !=
nullptr)
delete allZones[iZone];
123 return postpro ? 2 : 1;
127 double scalingFactor,
bool structured)
132 cgnsErr = cg_open(name.c_str(), CG_MODE_WRITE, &cgIndexFile);
133 if(cgnsErr != CG_OK)
return cgnsError(__FILE__, __LINE__, cgIndexFile);
136 int meshDim =
getMeshDim(), dim = 3, cgIndexBase = 0;
137 size_t posStartName = name.find_last_of(
"/\\");
138 if(posStartName == std::string::npos)
142 std::string baseName = cgnsString(name.substr(posStartName));
144 cg_base_write(cgIndexFile, baseName.c_str(), meshDim, dim, &cgIndexBase);
145 if(cgnsErr != CG_OK)
return cgnsError(__FILE__, __LINE__, cgIndexFile);
148 cgnsErr = cg_goto(cgIndexFile, cgIndexBase,
"end");
149 if(cgnsErr != CG_OK)
return cgnsError(__FILE__, __LINE__, cgIndexFile);
150 cgnsErr = cg_descriptor_write(
"About",
"Created by Gmsh");
151 if(cgnsErr != CG_OK)
return cgnsError(__FILE__, __LINE__, cgIndexFile);
155 writeZonesStruct(
this, scalingFactor, cgIndexFile, cgIndexBase)) {
156 cgnsErr = cg_close(cgIndexFile);
157 if(cgnsErr != CG_OK)
return cgnsError(__FILE__, __LINE__);
163 std::vector<std::string> zoneName(numPart + 1);
170 std::vector<GEntity *> allEntities, entities, entitiesPer, entitiesInterf;
173 getPeriodicEntities(allEntities, entitiesPer);
175 getPartitionInterfaceEntities(allEntities, saveAll, entitiesInterf);
176 if(entitiesInterf.size() == 0) {
183 Vertex2LocalData interfVert2Local;
184 initInterfVertex2LocalData(entitiesPer, entitiesInterf, interfVert2Local);
185 Msg::Info(
"%lu periodic/interface nodes", interfVert2Local.size());
188 std::set<int> eleMshTypes;
189 std::map<GEntity *, std::string> geomEntities;
191 int err = writeZone(
this, saveAll, scalingFactor, meshDim, numNodes, 0,
192 entities, cgIndexFile, cgIndexBase, zoneName,
193 interfVert2Local, eleMshTypes, geomEntities);
194 if(err == 0)
return 0;
195 if(entitiesPer.size() > 0) {
196 err = writePeriodic(entitiesPer, cgIndexFile, cgIndexBase, zoneName,
198 if(err == 0)
return 0;
202 std::vector<std::vector<GEntity *> > entitiesPart;
203 entitiesPart.resize(numPart + 1);
204 getEntitiesInPartitions(entities, entitiesPart);
205 for(std::size_t iPart = 1; iPart <= numPart; iPart++) {
206 printProgress(
"Writing partition", iPart, numPart);
208 writeZone(
this, saveAll, scalingFactor, meshDim, numNodes, iPart,
209 entitiesPart[iPart], cgIndexFile, cgIndexBase, zoneName,
210 interfVert2Local, eleMshTypes, geomEntities);
211 if(err == 0)
return 0;
213 if(entitiesPer.size() > 0) {
214 int err = writePeriodic(entitiesPer, cgIndexFile, cgIndexBase, zoneName,
216 if(err == 0)
return 0;
218 if(entitiesInterf.size() > 0) {
219 int err = writeInterfaces(entitiesInterf, cgIndexFile, cgIndexBase,
220 zoneName, interfVert2Local);
221 if(err == 0)
return 0;
226 if(geomEntities.size() > 0) {
227 writeGeomEntities(geomEntities, cgIndexFile, cgIndexBase);
232 int err = writeHOPointInfo(eleMshTypes, cgIndexFile, cgIndexBase);
233 if(err == 0)
return 0;
236 cgnsErr = cg_close(cgIndexFile);
237 if(cgnsErr != CG_OK)
return cgnsError(__FILE__, __LINE__);
245 std::vector<std::vector<MVertex *> > &vertPerZone,
246 std::vector<std::vector<MElement *> > &eltPerZone)
248 Msg::Error(
"This version of Gmsh was compiled without CGNS support");
253 double scalingFactor,
bool structured)
255 Msg::Error(
"This version of Gmsh was compiled without CGNS support");