35#include <boost/algorithm/string.hpp>
46#define TIME_RESULT(verb, msg, timer) \
49 std::cout << " - " << msg << ": " << timer.TimePerTest(1) << "\n" \
98std::pair<size_t, size_t>
SplitWork(
size_t vecsize,
int rank,
int nprocs)
100 size_t div = vecsize / nprocs;
101 size_t rem = vecsize % nprocs;
104 return std::make_pair(rank * (div + 1), div + 1);
108 return std::make_pair((rank - rem) * div + rem * (div + 1), div);
112template <class T, typename std::enable_if<T::kDim == 0, int>::type = 0>
114 [[maybe_unused]] std::map<
int, std::shared_ptr<T>> &geomMap)
119template <class T, typename std::enable_if<T::kDim == 1, int>::type = 0>
121 [[maybe_unused]] std::map<
int, std::shared_ptr<T>> &geomMap)
126template <class T, typename std::enable_if<T::kDim == 2, int>::type = 0>
128 [[maybe_unused]] std::map<
int, std::shared_ptr<T>> &geomMap)
133template <class T, typename std::enable_if<T::kDim == 3, int>::type = 0>
135 [[maybe_unused]] std::map<
int, std::shared_ptr<T>> &geomMap)
141inline void UniqueValues([[maybe_unused]] std::unordered_set<int> &unique)
147 const std::vector<int> &input, T &...args)
159 "use-hdf5-node-comm",
"",
160 "Use a per-node communicator for HDF5 partitioning.");
173 const bool isRoot = comm->TreatAsRankZero();
180 session->InitSession();
185 m_xmlGeom = session->GetElement(
"NEKTAR/GEOMETRY");
186 TiXmlAttribute *attr =
m_xmlGeom->FirstAttribute();
187 int meshDimension = 3;
188 int spaceDimension = 3;
192 std::string attrName(attr->Name());
193 if (attrName ==
"DIM")
195 err = attr->QueryIntValue(&meshDimension);
196 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read mesh dimension.");
198 else if (attrName ==
"SPACE")
200 err = attr->QueryIntValue(&spaceDimension);
201 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read space dimension.");
203 else if (attrName ==
"PARTITION")
206 "PARTITION parameter should only be used in XML meshes");
208 else if (attrName ==
"HDF5FILE")
212 else if (attrName ==
"PARTITIONED")
215 "PARTITIONED parameter should only be used in XML meshes");
219 std::string errstr(
"Unknown attribute: ");
228 ASSERTL0(meshDimension <= spaceDimension,
229 "Mesh dimension greater than space dimension.");
238 if (commMesh->GetSize() > 1)
241 parallelProps = H5::PList::FileAccess();
242 parallelProps->SetMpio(commMesh);
244 m_readPL = H5::PList::DatasetXfer();
250 auto root =
m_file->OpenGroup(
"NEKTAR");
251 ASSERTL0(root,
"Cannot find NEKTAR group in HDF5 file.");
253 auto root2 = root->OpenGroup(
"GEOMETRY");
254 ASSERTL0(root2,
"Cannot find NEKTAR/GEOMETRY group in HDF5 file.");
259 for (; attrIt != attrEnd; ++attrIt)
261 if (*attrIt ==
"FORMAT_VERSION")
267 "Unable to determine Nektar++ geometry HDF5 file version.");
272 " is higher than supported in "
273 "this version of Nektar++");
275 m_mesh = root2->OpenGroup(
"MESH");
276 ASSERTL0(
m_mesh,
"Cannot find NEKTAR/GEOMETRY/MESH group in HDF5 file.");
277 m_maps = root2->OpenGroup(
"MAPS");
278 ASSERTL0(
m_mesh,
"Cannot find NEKTAR/GEOMETRY/MAPS group in HDF5 file.");
290 std::vector<std::tuple<std::string, int, LibUtilities::ShapeType>>>
301 const bool verbRoot = isRoot && session->DefinesCmdLineArgument(
"verbose");
305 std::cout <<
"Reading HDF5 geometry..." << std::endl;
313 int innerRank = 0, innerSize = 1,
314 interRank = interComm->GetRowComm()->GetRank(),
315 interSize = interComm->GetRowComm()->GetSize();
317 if (session->DefinesCmdLineArgument(
"use-hdf5-node-comm"))
319 ASSERTL0(comm->GetSize() == commMesh->GetSize(),
320 "--use-hdf5-node-comm not available with Parallel-in-Time")
322 auto splitComm = comm->SplitCommNode();
323 innerComm = splitComm.first;
324 interComm = splitComm.second;
325 innerRank = innerComm->GetRank();
326 innerSize = innerComm->GetSize();
330 interRank = interComm->GetRank();
331 interSize = interComm->GetSize();
337 std::unordered_set<int> toRead;
346 std::cout <<
" - beginning partitioning" << std::endl;
356 const bool verbRoot2 =
357 isRoot && session->DefinesCmdLineArgument(
"verbose");
360 std::vector<int> ids;
364 std::vector<MeshEntity> elmts;
365 std::unordered_map<int, int> row2id, id2row;
375 auto parallelProps = H5::PList::FileAccess();
376 parallelProps->SetMpio(interComm);
379 readPL = H5::PList::DatasetXfer();
380 readPL->SetDxMpioCollective();
381 file = H5::File::Open(
m_hdf5Name, H5F_ACC_RDONLY, parallelProps);
383 auto root = file->OpenGroup(
"NEKTAR");
384 auto root2 = root->OpenGroup(
"GEOMETRY");
385 mesh = root2->OpenGroup(
"MESH");
386 maps = root2->OpenGroup(
"MAPS");
390 for (
auto &it : dataSets[meshDimension])
392 std::string ds = std::get<0>(it);
394 if (!mesh->ContainsDataSet(ds))
402 vector<hsize_t> dims = space->GetDims();
406 vector<hsize_t> mdims = mspace->GetDims();
411 vector<int> tmpElmts, tmpIds;
412 mdata->Read(tmpIds, mspace, readPL);
413 data->Read(tmpElmts, space, readPL);
415 const int nGeomData = std::get<1>(it);
417 for (
int i = 0, cnt = 0; i < tmpIds.size(); ++i, ++rowCount)
420 row2id[rowCount] = tmpIds[i];
421 id2row[tmpIds[i]] = row2id[rowCount];
425 e.
list = std::vector<unsigned int>(&tmpElmts[cnt],
426 &tmpElmts[cnt + nGeomData]);
432 interComm->GetRowComm()->Block();
439 size_t numElmt = elmts.size();
440 ASSERTL0(commMesh->GetSize() <= numElmt,
441 "This mesh has more processors than elements!");
443 auto elRange =
SplitWork(numElmt, interRank, interSize);
446 std::map<int, MeshEntity> partElmts;
447 std::unordered_set<int> facetIDs;
451 for (
int el = elRange.first; el < elRange.first + elRange.second;
456 partElmts[el] = elmt;
458 for (
auto &facet : elmt.
list)
460 facetIDs.insert(facet);
467 for (
int i = 0; i < numElmt; ++i)
470 if (i >= elRange.first && i < elRange.first + elRange.second)
479 for (
auto &eId : elmt.
list)
481 if (facetIDs.find(eId) != facetIDs.end())
491 partElmts[elmt.
id] = elmt;
498 string partitionerName =
499 commMesh->GetSize() > 1 ?
"PtScotch" :
"Scotch";
502 partitionerName =
"ParMetis";
504 if (session->DefinesCmdLineArgument(
"use-parmetis"))
506 partitionerName =
"ParMetis";
508 if (session->DefinesCmdLineArgument(
"use-ptscotch"))
510 partitionerName =
"PtScotch";
515 partitionerName, session, interComm, meshDimension, partElmts,
519 TIME_RESULT(verbRoot2,
" - partitioner setup", t2);
522 partitioner->PartitionMesh(interSize,
true,
false, nLocal);
529 std::vector<unsigned int> nodeElmts;
530 partitioner->GetElementIDs(interRank, nodeElmts);
535 std::map<int, MeshEntity> partElmts;
536 std::unordered_map<int, int> row2elmtid, elmtid2row;
543 for (
auto &elmtRow : nodeElmts)
545 row2elmtid[vcnt] = elmts[elmtRow].origId;
546 elmtid2row[elmts[elmtRow].origId] = vcnt;
549 partElmts[vcnt++] = elmt;
558 "Scotch", session, tmpComm, meshDimension, partElmts,
562 TIME_RESULT(verbRoot2,
" - inner partition setup", t2);
565 partitioner->PartitionMesh(innerSize,
true,
false, 0);
568 TIME_RESULT(verbRoot2,
" - inner partitioning", t2);
572 for (
int i = 1; i < innerSize; ++i)
574 std::vector<unsigned int> tmp;
575 partitioner->GetElementIDs(i, tmp);
576 size_t tmpsize = tmp.size();
577 for (
int j = 0; j < tmpsize; ++j)
579 tmp[j] = row2elmtid[tmp[j]];
581 innerComm->Send(i, tmpsize);
582 innerComm->Send(i, tmp);
586 TIME_RESULT(verbRoot2,
" - inner partition scatter", t2);
588 std::vector<unsigned int> tmp;
589 partitioner->GetElementIDs(0, tmp);
591 for (
auto &tmpId : tmp)
593 toRead.insert(row2elmtid[tmpId]);
598 for (
auto &tmpId : nodeElmts)
600 toRead.insert(row2id[tmpId]);
609 innerComm->Recv(0, tmpSize);
610 std::vector<unsigned int> tmp(tmpSize);
611 innerComm->Recv(0, tmp);
613 for (
auto &tmpId : tmp)
615 toRead.insert(tmpId);
625 std::vector<int> vertIDs, segIDs, triIDs, quadIDs;
626 std::vector<int> tetIDs, prismIDs, pyrIDs, hexIDs;
627 std::vector<int> segData, triData, quadData, tetData;
628 std::vector<int> prismData, pyrData, hexData;
629 std::vector<NekDouble> vertData;
637 auto &prismGeoms =
m_meshGraph->GetAllPrismGeoms();
642 if (meshDimension == 3)
652 UniqueValues(toRead, hexData, pyrData, prismData, tetData);
657 if (meshDimension >= 2)
670 if (meshDimension >= 1)
693 if (meshDimension >= 1)
697 for (
auto &edge : segIDs)
704 FillGeomMap(segGeoms, curvedEdges, segIDs, segData);
709 if (meshDimension >= 2)
713 for (
auto &face : triIDs)
717 for (
auto &face : quadIDs)
724 FillGeomMap(triGeoms, curvedFaces, triIDs, triData);
725 FillGeomMap(quadGeoms, curvedFaces, quadIDs, quadData);
730 if (meshDimension >= 3)
742 if (session->DefinesElement(
"NEKTAR/CONDITIONS"))
744 std::set<int> vBndRegionIdList;
745 TiXmlElement *vConditions =
746 new TiXmlElement(*session->GetElement(
"Nektar/Conditions"));
747 TiXmlElement *vBndRegions =
748 vConditions->FirstChildElement(
"BOUNDARYREGIONS");
755 auto &graph_bndRegOrder =
m_meshGraph->GetBndRegionOrdering();
756 vItem = vBndRegions->FirstChildElement();
759 std::string vSeqStr = vItem->FirstChild()->ToText()->Value();
760 std::string::size_type indxBeg = vSeqStr.find_first_of(
'[') + 1;
761 std::string::size_type indxEnd = vSeqStr.find_last_of(
']') - 1;
762 vSeqStr = vSeqStr.substr(indxBeg, indxEnd - indxBeg + 1);
764 std::vector<unsigned int> vSeq;
767 int p = atoi(vItem->Attribute(
"ID"));
769 graph_bndRegOrder[
p] = vSeq;
770 vItem = vItem->NextSiblingElement();
779template <
class T,
typename DataType>
781 [[maybe_unused]] std::map<
int, std::shared_ptr<T>> &geomMap,
782 [[maybe_unused]]
int id, [[maybe_unused]] DataType *data,
789 std::map<
int, std::shared_ptr<PointGeom>> &geomMap,
int id,
NekDouble *data,
793 m_meshGraph->GetSpaceDimension(),
id, data[0], data[1], data[2]);
798 std::map<
int, std::shared_ptr<SegGeom>> &geomMap,
int id,
int *data,
809 std::map<
int, std::shared_ptr<TriGeom>> &geomMap,
int id,
int *data,
820 std::map<
int, std::shared_ptr<QuadGeom>> &geomMap,
int id,
int *data,
831 std::map<
int, std::shared_ptr<TetGeom>> &geomMap,
int id,
int *data,
835 std::static_pointer_cast<TriGeom>(
m_meshGraph->GetGeometry2D(data[0])),
836 std::static_pointer_cast<TriGeom>(
m_meshGraph->GetGeometry2D(data[1])),
837 std::static_pointer_cast<TriGeom>(
m_meshGraph->GetGeometry2D(data[2])),
838 std::static_pointer_cast<TriGeom>(
m_meshGraph->GetGeometry2D(data[3]))};
842 geomMap[id] = tetGeom;
847 std::map<
int, std::shared_ptr<PyrGeom>> &geomMap,
int id,
int *data,
858 geomMap[id] = pyrGeom;
863 std::map<
int, std::shared_ptr<PrismGeom>> &geomMap,
int id,
int *data,
874 geomMap[id] = prismGeom;
879 std::map<
int, std::shared_ptr<HexGeom>> &geomMap,
int id,
int *data,
883 std::static_pointer_cast<QuadGeom>(
m_meshGraph->GetGeometry2D(data[0])),
884 std::static_pointer_cast<QuadGeom>(
m_meshGraph->GetGeometry2D(data[1])),
885 std::static_pointer_cast<QuadGeom>(
m_meshGraph->GetGeometry2D(data[2])),
886 std::static_pointer_cast<QuadGeom>(
m_meshGraph->GetGeometry2D(data[3])),
887 std::static_pointer_cast<QuadGeom>(
m_meshGraph->GetGeometry2D(data[4])),
888 std::static_pointer_cast<QuadGeom>(
893 geomMap[id] = hexGeom;
896template <
class T,
typename DataType>
899 std::vector<int> &ids,
900 std::vector<DataType> &geomData)
903 const int nRows = geomData.size() / nGeomData;
907 if (curveMap.size() > 0)
909 for (
int i = 0, cnt = 0; i < nRows; i++, cnt += nGeomData)
911 auto cIt = curveMap.find(ids[i]);
913 cIt == curveMap.end() ? empty : cIt->second);
918 for (
int i = 0, cnt = 0; i < nRows; i++, cnt += nGeomData)
925template <
class T,
typename DataType>
927 std::map<
int, std::shared_ptr<T>> &geomMap, std::string dataSet,
928 const std::unordered_set<int> &readIds, std::vector<int> &ids,
929 std::vector<DataType> &geomData)
931 if (!
m_mesh->ContainsDataSet(dataSet))
939 vector<hsize_t> dims = space->GetDims();
944 vector<hsize_t> mdims = mspace->GetDims();
946 ASSERTL0(mdims[0] == dims[0],
"map and data set lengths do not match");
952 mdata->Read(allIds, mspace);
959 std::vector<hsize_t> coords;
960 for (
auto &
id : allIds)
962 if (readIds.find(
id) != readIds.end())
964 for (
int j = 0; j < nGeomData; ++j)
974 space->SetSelection(coords.size() / 2, coords);
977 data->Read(geomData, space,
m_readPL);
981 const std::unordered_set<int> &readIds)
984 if (!
m_mesh->ContainsDataSet(dsName))
998 vector<int> ids, newIds;
999 idData->Read(ids, idSpace);
1000 curveSpace->ClearRange();
1003 vector<hsize_t> curveSel;
1006 for (
auto &
id : ids)
1008 if (readIds.find(
id) != readIds.end())
1010 curveSel.push_back(cnt);
1011 curveSel.push_back(0);
1012 curveSel.push_back(cnt);
1013 curveSel.push_back(1);
1014 curveSel.push_back(cnt);
1015 curveSel.push_back(2);
1016 newIds.push_back(
id);
1023 auto toRead = newIds.size();
1024 m_session->GetComm()->GetRowComm()->AllReduce(toRead,
1033 vector<int> curveInfo;
1034 curveSpace->SetSelection(curveSel.size() / 2, curveSel);
1035 curveData->Read(curveInfo, curveSpace,
m_readPL);
1039 std::unordered_map<int, int> curvePtOffset;
1042 for (
int i = 0, cnt = 0, cnt2 = 0; i < curveInfo.size() / 3; ++i, cnt += 3)
1047 curve->m_points.resize(curveInfo[cnt]);
1049 const int ptOffset = curveInfo[cnt + 2];
1051 for (
int j = 0; j < curveInfo[cnt]; ++j)
1055 curveSel.push_back(ptOffset + j);
1056 curveSel.push_back(0);
1057 curveSel.push_back(ptOffset + j);
1058 curveSel.push_back(1);
1059 curveSel.push_back(ptOffset + j);
1060 curveSel.push_back(2);
1065 curvePtOffset[newIds[i]] = 3 * cnt2;
1066 cnt2 += curveInfo[cnt];
1068 curveMap[newIds[i]] = curve;
1077 nodeSpace->ClearRange();
1078 nodeSpace->SetSelection(curveSel.size() / 2, curveSel);
1080 vector<NekDouble> nodeRawData;
1081 nodeData->Read(nodeRawData, nodeSpace,
m_readPL);
1084 for (
auto &cIt : curvePtOffset)
1089 int cnt = cIt.second;
1090 for (
int i = 0; i < curve->m_points.size(); ++i, cnt += 3)
1093 0,
m_meshGraph->GetSpaceDimension(), nodeRawData[cnt],
1094 nodeRawData[cnt + 1], nodeRawData[cnt + 2]);
1105 map<int, CompositeSharedPtr> fullDomain;
1109 vector<string> data;
1110 dst->ReadVectorString(data, space,
m_readPL);
1111 m_meshGraph->GetCompositeList(data[0], fullDomain);
1112 domain[0] = fullDomain;
1117 std::vector<CompositeMap> fullDomain;
1121 vector<string> data;
1122 dst->ReadVectorString(data, space,
m_readPL);
1123 for (
auto &dIt : data)
1126 m_meshGraph->GetCompositeList(dIt, fullDomain.back());
1133 mdata->Read(ids, mspace);
1135 for (
int i = 0; i < ids.size(); ++i)
1137 domain[ids[i]] = fullDomain[i];
1153 string nm =
"COMPOSITE";
1157 vector<hsize_t> dims = space->GetDims();
1159 vector<string> comps;
1160 data->ReadVectorString(comps, space);
1164 vector<hsize_t> mdims = mspace->GetDims();
1167 mdata->Read(ids, mspace);
1169 auto &graph_compOrder =
m_meshGraph->GetCompositeOrdering();
1170 for (
int i = 0; i < dims[0]; i++)
1172 string compStr = comps[i];
1175 istringstream strm(compStr);
1181 string::size_type indxBeg = compStr.find_first_of(
'[') + 1;
1182 string::size_type indxEnd = compStr.find_last_of(
']') - 1;
1184 string indxStr = compStr.substr(indxBeg, indxEnd - indxBeg + 1);
1185 vector<unsigned int> seqVector;
1189 graph_compOrder[ids[i]] = seqVector;
1194 for (
auto &i : seqVector)
1196 auto it = vertSet.find(i);
1197 if (it != vertSet.end())
1199 comp->m_geomVec.push_back(it->second);
1205 for (
auto &i : seqVector)
1207 auto it = segGeoms.find(i);
1208 if (it != segGeoms.end())
1210 comp->m_geomVec.push_back(it->second);
1215 for (
auto &i : seqVector)
1217 auto it = quadGeoms.find(i);
1218 if (it != quadGeoms.end())
1222 comp->m_geomVec.push_back(it->second);
1228 for (
auto &i : seqVector)
1230 auto it = triGeoms.find(i);
1231 if (it != triGeoms.end())
1235 comp->m_geomVec.push_back(it->second);
1241 for (
auto &i : seqVector)
1243 auto it1 = quadGeoms.find(i);
1244 if (it1 != quadGeoms.end())
1248 comp->m_geomVec.push_back(it1->second);
1251 auto it2 = triGeoms.find(i);
1252 if (it2 != triGeoms.end())
1256 comp->m_geomVec.push_back(it2->second);
1262 for (
auto &i : seqVector)
1264 auto it = tetGeoms.find(i);
1265 if (it != tetGeoms.end())
1269 comp->m_geomVec.push_back(it->second);
1275 for (
auto &i : seqVector)
1277 auto it = pyrGeoms.find(i);
1278 if (it != pyrGeoms.end())
1282 comp->m_geomVec.push_back(it->second);
1288 for (
auto &i : seqVector)
1290 auto it = prismGeoms.find(i);
1291 if (it != prismGeoms.end())
1295 comp->m_geomVec.push_back(it->second);
1301 for (
auto &i : seqVector)
1303 auto it = hexGeoms.find(i);
1304 if (it != hexGeoms.end())
1308 comp->m_geomVec.push_back(it->second);
1315 if (comp->m_geomVec.size() > 0)
1317 meshComposites[ids[i]] = comp;
1323 std::unordered_map<int, int> &id2row)
1327 string nm =
"COMPOSITE";
1331 vector<hsize_t> dims = space->GetDims();
1333 vector<string> comps;
1334 data->ReadVectorString(comps, space);
1338 vector<hsize_t> mdims = mspace->GetDims();
1341 mdata->Read(ids, mspace);
1343 for (
int i = 0; i < dims[0]; i++)
1345 string compStr = comps[i];
1348 istringstream strm(compStr);
1352 string::size_type indxBeg = compStr.find_first_of(
'[') + 1;
1353 string::size_type indxEnd = compStr.find_last_of(
']') - 1;
1355 string indxStr = compStr.substr(indxBeg, indxEnd - indxBeg + 1);
1356 vector<unsigned int> seqVector;
1396 std::vector<int> filteredVector;
1397 for (
auto &compElmt : seqVector)
1399 if (id2row.find(compElmt) == id2row.end())
1404 filteredVector.push_back(compElmt);
1407 if (filteredVector.size() == 0)
1412 ret[ids[i]] = std::make_pair(shapeType, filteredVector);
1418template <class T, typename std::enable_if<T::kDim == 0, int>::type = 0>
1424template <class T, typename std::enable_if<T::kDim == 1, int>::type = 0>
1427 return geom->GetVid(i);
1430template <class T, typename std::enable_if<T::kDim == 2, int>::type = 0>
1431inline int GetGeomData(std::shared_ptr<T> &geom,
int i)
1433 return geom->GetEid(i);
1436template <class T, typename std::enable_if<T::kDim == 3, int>::type = 0>
1437inline int GetGeomData(std::shared_ptr<T> &geom,
int i)
1439 return geom->GetFid(i);
1444 std::map<
int, std::shared_ptr<T>> &geomMap, std::string datasetName)
1446 typedef typename std::conditional<std::is_same<T, PointGeom>::value,
1450 const size_t nGeom = geomMap.size();
1458 vector<int> idMap(nGeom);
1459 vector<DataType> data(nGeom * nGeomData);
1461 int cnt1 = 0, cnt2 = 0;
1462 for (
auto &it : geomMap)
1464 idMap[cnt1++] = it.first;
1466 for (
int j = 0; j < nGeomData; ++j)
1474 vector<hsize_t> dims = {
static_cast<hsize_t
>(nGeom),
1475 static_cast<hsize_t
>(nGeomData)};
1480 dst->Write(data, ds);
1482 tp = H5::DataType::OfObject(idMap[0]);
1484 ds = std::shared_ptr<H5::DataSpace>(
new H5::DataSpace(dims));
1485 dst =
m_maps->CreateDataSet(datasetName, tp, ds);
1486 dst->Write(idMap, ds);
1493 vector<int> data, map;
1496 for (
auto &c : curves)
1498 map.push_back(c.first);
1499 data.push_back(c.second->m_points.size());
1500 data.push_back(c.second->m_ptype);
1501 data.push_back(ptOffset);
1503 ptOffset += c.second->m_points.size();
1505 for (
auto &pt : c.second->m_points)
1509 pt->GetCoords(v.
x, v.
y, v.
z);
1510 curvedPts.
pts.push_back(v);
1511 curvedPts.
index.push_back(newIdx++);
1516 vector<hsize_t> dims = {data.size() / 3, 3};
1521 dst->Write(data, ds);
1523 tp = H5::DataType::OfObject(map[0]);
1524 dims = {map.size()};
1525 ds = std::shared_ptr<H5::DataSpace>(
new H5::DataSpace(dims));
1526 dst =
m_maps->CreateDataSet(dsName, tp, ds);
1527 dst->Write(map, ds);
1532 vector<double> vertData(curvedPts.
pts.size() * 3);
1535 for (
auto &pt : curvedPts.
pts)
1537 vertData[cnt++] = pt.x;
1538 vertData[cnt++] = pt.y;
1539 vertData[cnt++] = pt.z;
1542 vector<hsize_t> dims = {curvedPts.
pts.size(), 3};
1547 dst->Write(vertData, ds);
1552 vector<string> comps;
1559 for (
auto &cIt : composites)
1561 if (cIt.second->m_geomVec.size() == 0)
1567 c_map.push_back(cIt.first);
1573 dst->WriteVectorString(comps, ds, tp);
1575 tp = H5::DataType::OfObject(c_map[0]);
1576 ds = H5::DataSpace::OneD(c_map.size());
1577 dst =
m_maps->CreateDataSet(
"COMPOSITE", tp, ds);
1578 dst->Write(c_map, ds);
1587 std::vector<vector<unsigned int>> idxList;
1590 for (
auto &dIt : domain)
1592 idxList.push_back(std::vector<unsigned int>());
1593 for (
auto cIt = dIt.second.begin(); cIt != dIt.second.end(); ++cIt)
1595 idxList[cnt].push_back(cIt->first);
1599 d_map.push_back(dIt.first);
1602 stringstream domString;
1603 vector<string> doms;
1604 for (
auto &cIt : idxList)
1612 dst->WriteVectorString(doms, ds, tp);
1614 tp = H5::DataType::OfObject(d_map[0]);
1615 ds = H5::DataSpace::OneD(d_map.size());
1616 dst =
m_maps->CreateDataSet(
"DOMAIN", tp, ds);
1617 dst->Write(d_map, ds);
1621 const std::string &outfilename,
bool defaultExp,
1638 boost::split(tmp, outfilename, boost::is_any_of(
"."));
1639 string filenameXml = tmp[0] +
".xml";
1640 string filenameHdf5 = tmp[0] +
".nekg";
1649 TiXmlDocument *doc =
new TiXmlDocument;
1651 TiXmlElement *geomTag;
1653 if (fs::exists(filenameXml.c_str()))
1655 ifstream file(filenameXml.c_str());
1657 TiXmlHandle docHandle(doc);
1658 root = docHandle.FirstChildElement(
"NEKTAR").Element();
1659 ASSERTL0(root,
"Unable to find NEKTAR tag in file.");
1660 geomTag = root->FirstChildElement(
"GEOMETRY");
1665 TiXmlDeclaration *decl =
new TiXmlDeclaration(
"1.0",
"utf-8",
"");
1666 doc->LinkEndChild(decl);
1667 root =
new TiXmlElement(
"NEKTAR");
1668 doc->LinkEndChild(root);
1670 geomTag =
new TiXmlElement(
"GEOMETRY");
1671 root->LinkEndChild(geomTag);
1675 geomTag->SetAttribute(
"DIM",
m_meshGraph->GetMeshDimension());
1676 geomTag->SetAttribute(
"SPACE",
m_meshGraph->GetSpaceDimension());
1677 geomTag->SetAttribute(
"HDF5FILE", filenameHdf5);
1683 TiXmlElement *expTag =
new TiXmlElement(
"EXPANSIONS");
1685 for (
auto it = meshComposites.begin(); it != meshComposites.end(); it++)
1687 if (it->second->m_geomVec[0]->GetShapeDim() ==
1690 TiXmlElement *exp =
new TiXmlElement(
"E");
1693 "C[" + boost::lexical_cast<string>(it->first) +
"]");
1694 exp->SetAttribute(
"NUMMODES", 4);
1695 exp->SetAttribute(
"TYPE",
"MODIFIED");
1696 exp->SetAttribute(
"FIELDS",
"u");
1698 expTag->LinkEndChild(exp);
1701 root->LinkEndChild(expTag);
1707 movement->WriteMovement(root);
1710 doc->SaveFile(filenameXml);
1717 m_file = H5::File::Create(filenameHdf5, H5F_ACC_TRUNC);
1718 auto hdfRoot =
m_file->CreateGroup(
"NEKTAR");
1719 auto hdfRoot2 = hdfRoot->CreateGroup(
"GEOMETRY");
1725 m_mesh = hdfRoot2->CreateGroup(
"MESH");
1726 m_maps = hdfRoot2->CreateGroup(
"MAPS");
1744 int ptOffset = 0, newIdx = 0;
1746 WriteCurveMap(curvedEdges,
"CURVE_EDGE", curvePts, ptOffset, newIdx);
1747 WriteCurveMap(curvedFaces,
"CURVE_FACE", curvePts, ptOffset, newIdx);
#define ASSERTL0(condition, msg)
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
#define TIME_RESULT(verb, msg, timer)
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
static void GetXMLElementTimeLevel(TiXmlElement *&element, const size_t timeLevel, const bool enableCheck=true)
Get XML elment time level (Parallel-in-Time)
static std::string RegisterCmdLineFlag(const std::string &pName, const std::string &pShortName, const std::string &pDescription)
Registers a command-line flag with the session reader.
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
static std::string GenerateSeqString(const std::vector< T > &v)
Generate a compressed comma-separated string representation of a vector of unsigned integers.
static bool GenerateSeqVector(const std::string &str, std::vector< unsigned int > &out)
Takes a comma-separated compressed string and converts it to entries in a vector.
void v_PartitionMesh(LibUtilities::SessionReaderSharedPtr session) final
Partition the mesh.
LibUtilities::H5::GroupSharedPtr m_mesh
LibUtilities::H5::GroupSharedPtr m_maps
void FillGeomMap(std::map< int, std::shared_ptr< T > > &geomMap, const CurveMap &curveMap, std::vector< int > &ids, std::vector< DataType > &geomData)
static std::string cmdSwitch
void WriteDomain(std::map< int, CompositeMap > &domain)
void WriteGeometryMap(std::map< int, std::shared_ptr< T > > &geomMap, std::string datasetName)
void ConstructGeomObject(std::map< int, std::shared_ptr< T > > &geomMap, int id, DataType *data, CurveSharedPtr curve)
unsigned int m_inFormatVersion
void v_ReadGeometry(LibUtilities::DomainRangeShPtr rng, bool fillGraph) final
static const unsigned int FORMAT_VERSION
Version of the Nektar++ HDF5 geometry format, which is embedded into the main NEKTAR/GEOMETRY group a...
void ReadGeometryData(std::map< int, std::shared_ptr< T > > &geomMap, std::string dataSet, const std::unordered_set< int > &readIds, std::vector< int > &ids, std::vector< DataType > &geomData)
void WriteCurveMap(CurveMap &curves, std::string dsName, MeshCurvedPts &curvedPts, int &ptOffset, int &newIdx)
void v_WriteGeometry(const std::string &outfilename, bool defaultExp=false, const LibUtilities::FieldMetaDataMap &metadata=LibUtilities::NullFieldMetaDataMap) final
void WriteCurvePoints(MeshCurvedPts &curvedPts)
static std::string className
void WriteComposites(CompositeMap &comps)
LibUtilities::H5::FileSharedPtr m_file
void ReadCurveMap(CurveMap &curveMap, std::string dsName, const std::unordered_set< int > &readIds)
LibUtilities::H5::PListSharedPtr m_readPL
static MeshGraphIOSharedPtr create()
BndRegionOrdering m_bndRegOrder
LibUtilities::SessionReaderSharedPtr m_session
std::string GetCompositeString(CompositeSharedPtr comp)
Returns a string representation of a composite.
CompositeDescriptor CreateCompositeDescriptor()
MeshGraphSharedPtr m_meshGraph
CompositeOrdering m_compOrder
std::shared_ptr< DataSpace > DataSpaceSharedPtr
std::shared_ptr< PList > PListSharedPtr
std::shared_ptr< File > FileSharedPtr
std::shared_ptr< DataType > DataTypeSharedPtr
std::shared_ptr< Group > GroupSharedPtr
std::shared_ptr< DataSet > DataSetSharedPtr
std::map< std::string, std::string > FieldMetaDataMap
std::shared_ptr< SessionReader > SessionReaderSharedPtr
std::shared_ptr< DomainRange > DomainRangeShPtr
CommFactory & GetCommFactory()
std::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
std::map< int, TriGeomSharedPtr > TriGeomMap
NekDouble GetGeomData(std::shared_ptr< T > &geom, int i)
std::shared_ptr< QuadGeom > QuadGeomSharedPtr
std::map< int, PyrGeomSharedPtr > PyrGeomMap
int GetGeomDataDim(std::map< int, std::shared_ptr< T > > &geomMap)
std::map< int, QuadGeomSharedPtr > QuadGeomMap
std::map< int, std::pair< LibUtilities::ShapeType, std::vector< int > > > CompositeDescriptor
MeshPartitionFactory & GetMeshPartitionFactory()
std::pair< size_t, size_t > SplitWork(size_t vecsize, int rank, int nprocs)
Utility function to split a vector equally amongst a number of processors.
std::shared_ptr< Composite > CompositeSharedPtr
std::map< int, SegGeomSharedPtr > SegGeomMap
std::shared_ptr< Curve > CurveSharedPtr
std::unordered_map< int, CurveSharedPtr > CurveMap
std::shared_ptr< SegGeom > SegGeomSharedPtr
std::map< int, TetGeomSharedPtr > TetGeomMap
MeshGraphIOFactory & GetMeshGraphIOFactory()
std::map< int, PrismGeomSharedPtr > PrismGeomMap
std::shared_ptr< PointGeom > PointGeomSharedPtr
std::shared_ptr< Geometry2D > Geometry2DSharedPtr
std::shared_ptr< MeshPartition > MeshPartitionSharedPtr
std::shared_ptr< TriGeom > TriGeomSharedPtr
std::map< int, HexGeomSharedPtr > HexGeomMap
std::map< int, PointGeomSharedPtr > PointGeomMap
void UniqueValues(std::unordered_set< int > &unique)
std::map< int, CompositeSharedPtr > CompositeMap
std::vector< MeshVertex > pts
mapping to access pts value.
std::vector< NekInt64 > index
id of this Point set
std::vector< unsigned int > list