35 #include <type_traits> 37 #include <boost/core/ignore_unused.hpp> 38 #include <boost/algorithm/string.hpp> 39 #include <boost/filesystem.hpp> 46 #define TIME_RESULT(verb, msg, timer) \ 49 std::cout << " - " << msg << ": " \ 50 << timer.TimePerTest(1) << std::endl; \ 58 namespace SpatialDomains
63 const unsigned int MeshGraphHDF5::FORMAT_VERSION = 1;
65 std::string MeshGraphHDF5::className =
67 "HDF5", MeshGraphHDF5::create,
"IO with HDF5 geometry");
69 void MeshGraphHDF5::ReadGeometry(
73 boost::ignore_unused(rng);
86 MeshGraph::FillGraph();
101 std::pair<size_t, size_t>
SplitWork(
size_t vecsize,
int rank,
int nprocs)
103 size_t div = vecsize / nprocs;
104 size_t rem = vecsize % nprocs;
107 return std::make_pair(rank * (div + 1), div + 1);
111 return std::make_pair((rank - rem) * div + rem * (div + 1), div);
115 template<class T, typename std::enable_if<T::kDim == 0, int>::type = 0>
118 boost::ignore_unused(geomMap);
122 template<class T, typename std::enable_if<T::kDim == 1, int>::type = 0>
123 inline int GetGeomDataDim(std::map<
int, std::shared_ptr<T>> &geomMap)
125 boost::ignore_unused(geomMap);
129 template<class T, typename std::enable_if<T::kDim == 2, int>::type = 0>
130 inline int GetGeomDataDim(std::map<
int, std::shared_ptr<T>> &geomMap)
132 boost::ignore_unused(geomMap);
136 template<class T, typename std::enable_if<T::kDim == 3, int>::type = 0>
137 inline int GetGeomDataDim(std::map<
int, std::shared_ptr<T>> &geomMap)
139 boost::ignore_unused(geomMap);
146 boost::ignore_unused(unique);
151 const std::vector<int> &input,
171 int rank = comm->GetRank(), nproc = comm->GetSize();
178 session->InitSession();
183 m_xmlGeom = m_session->GetElement(
"NEKTAR/GEOMETRY");
184 TiXmlAttribute *attr = m_xmlGeom->FirstAttribute();
185 m_meshPartitioned =
true;
187 m_spaceDimension = 3;
191 std::string attrName(attr->Name());
192 if (attrName ==
"DIM")
194 err = attr->QueryIntValue(&m_meshDimension);
195 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read mesh dimension.");
197 else if (attrName ==
"SPACE")
199 err = attr->QueryIntValue(&m_spaceDimension);
200 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read space dimension.");
202 else if (attrName ==
"PARTITION")
205 "PARTITION parameter should only be used in XML meshes");
207 else if(attrName ==
"HDF5FILE")
209 m_hdf5Name = attr->Value();
210 ASSERTL1(err == TIXML_SUCCESS,
"Unable to read hdf5 name.");
212 else if(attrName ==
"PARTITIONED")
215 "PARTITIONED parameter should only be used in XML meshes");
219 std::string errstr(
"Unknown attribute: ");
227 ASSERTL0(m_hdf5Name.size() > 0,
"Unable to obtain mesh file name.");
228 ASSERTL0(m_meshDimension <= m_spaceDimension,
229 "Mesh dimension greater than space dimension.");
233 m_readPL = H5::PList::Default();
238 parallelProps = H5::PList::FileAccess();
239 parallelProps->SetMpio(comm);
241 m_readPL = H5::PList::DatasetXfer();
242 m_readPL->SetDxMpioCollective();
245 m_file = H5::File::Open(m_hdf5Name, H5F_ACC_RDONLY, parallelProps);
247 auto root = m_file->OpenGroup(
"NEKTAR");
248 ASSERTL0(root,
"Cannot find NEKTAR group in HDF5 file.");
250 auto root2 = root->OpenGroup(
"GEOMETRY");
251 ASSERTL0(root2,
"Cannot find NEKTAR/GEOMETRY group in HDF5 file.");
254 unsigned int formatVersion;
255 H5::Group::AttrIterator attrIt = root2->attr_begin();
256 H5::Group::AttrIterator attrEnd = root2->attr_end();
257 for (; attrIt != attrEnd; ++attrIt)
259 if (*attrIt ==
"FORMAT_VERSION")
265 "Unable to determine Nektar++ geometry HDF5 file version.");
266 root2->GetAttribute(
"FORMAT_VERSION", formatVersion);
268 ASSERTL0(formatVersion <= FORMAT_VERSION,
269 "File format in " + m_hdf5Name +
" is higher than supported in " 270 "this version of Nektar++");
272 m_mesh = root2->OpenGroup(
"MESH");
273 ASSERTL0(m_mesh,
"Cannot find NEKTAR/GEOMETRY/MESH group in HDF5 file.");
274 m_maps = root2->OpenGroup(
"MAPS");
275 ASSERTL0(m_mesh,
"Cannot find NEKTAR/GEOMETRY/MAPS group in HDF5 file.");
278 std::map<int, std::vector<std::tuple<
290 std::vector<MeshEntity> elmts;
291 std::vector<int> ids;
295 std::unordered_map<int, int> row2id, id2row;
300 for (
auto &it : dataSets[m_meshDimension])
302 std::string ds = std::get<0>(it);
304 if (!m_mesh->ContainsDataSet(ds))
312 vector<hsize_t> dims = space->GetDims();
316 vector<hsize_t> mdims = mspace->GetDims();
320 vector<int> tmpElmts, tmpIds;
321 mdata->Read(tmpIds, mspace, m_readPL);
322 data->Read(tmpElmts, space, m_readPL);
324 const int nGeomData = std::get<1>(it);
326 for (
int i = 0, cnt = 0; i < tmpIds.size(); ++i, ++rowCount)
329 row2id[rowCount] = tmpIds[i];
330 id2row[tmpIds[i]] = row2id[rowCount];
333 e.
list = std::vector<unsigned int>(
334 &tmpElmts[cnt], &tmpElmts[cnt+nGeomData]);
343 bool verbRoot = rank == 0 &&
344 m_session->DefinesCmdLineArgument(
"verbose");
348 std::cout <<
"Reading HDF5 geometry..." << std::endl;
354 size_t numElmt = elmts.size();
356 "This mesh has more processors than elements!");
359 auto elRange =
SplitWork(numElmt, rank, nproc);
364 std::map<int, MeshEntity> partElmts;
365 std::unordered_set<int> facetIDs;
369 for (
int el = elRange.first; el < elRange.first + elRange.second;
374 partElmts[el] = elmt;
376 for (
auto &facet : elmt.
list)
378 facetIDs.insert(facet);
385 for (
int i = 0; i < numElmt; ++i)
388 if (i >= elRange.first && i < elRange.first + elRange.second)
398 for (
auto &eId : elmt.
list)
400 if (facetIDs.find(eId) != facetIDs.end())
410 partElmts[elmt.
id] = elmt;
417 string partitionerName = nproc > 1 ?
"PtScotch" :
"Scotch";
420 partitionerName =
"ParMetis";
422 if (session->DefinesCmdLineArgument(
"use-parmetis"))
424 partitionerName =
"ParMetis";
426 if (session->DefinesCmdLineArgument(
"use-ptscotch"))
428 partitionerName =
"PtScotch";
433 partitionerName, session, m_meshDimension,
434 partElmts, CreateCompositeDescriptor(id2row));
436 partitioner->PartitionMesh(nproc,
true,
false, nLocal);
444 std::vector<unsigned int> tmp;
445 std::unordered_set<int> toRead;
446 partitioner->GetElementIDs(comm->GetRank(), tmp);
448 for (
auto &tmpId : tmp)
450 toRead.insert(row2id[tmpId]);
456 std::vector<int> vertIDs, segIDs, triIDs, quadIDs;
457 std::vector<int> tetIDs, prismIDs, pyrIDs, hexIDs;
458 std::vector<int> segData, triData, quadData, tetData;
459 std::vector<int> prismData, pyrData, hexData;
460 std::vector<NekDouble> vertData;
462 if (m_meshDimension == 3)
466 ReadGeometryData(m_hexGeoms,
"HEX", toRead, hexIDs, hexData);
467 ReadGeometryData(m_pyrGeoms,
"PYR", toRead, pyrIDs, pyrData);
468 ReadGeometryData(m_prismGeoms,
"PRISM", toRead, prismIDs, prismData);
469 ReadGeometryData(m_tetGeoms,
"TET", toRead, tetIDs, tetData);
472 UniqueValues(toRead, hexData, pyrData, prismData, tetData);
477 if (m_meshDimension >= 2)
481 ReadGeometryData(m_triGeoms,
"TRI", toRead, triIDs, triData);
482 ReadGeometryData(m_quadGeoms,
"QUAD", toRead, quadIDs, quadData);
490 if (m_meshDimension >= 1)
494 ReadGeometryData(m_segGeoms,
"SEG", toRead, segIDs, segData);
503 ReadGeometryData(m_vertSet,
"VERT", toRead, vertIDs, vertData);
509 FillGeomMap(m_vertSet,
CurveMap(), vertIDs, vertData);
513 if (m_meshDimension >= 1)
517 for (
auto &edge : segIDs)
521 ReadCurveMap(m_curvedEdges,
"CURVE_EDGE", toRead);
524 FillGeomMap(m_segGeoms, m_curvedEdges, segIDs, segData);
529 if (m_meshDimension >= 2)
533 for (
auto &face : triIDs)
537 for (
auto &face : quadIDs)
541 ReadCurveMap(m_curvedFaces,
"CURVE_FACE", toRead);
544 FillGeomMap(m_triGeoms, m_curvedFaces, triIDs, triData);
545 FillGeomMap(m_quadGeoms, m_curvedFaces, quadIDs, quadData);
550 if (m_meshDimension >= 3)
553 FillGeomMap(m_hexGeoms,
CurveMap(), hexIDs, hexData);
554 FillGeomMap(m_prismGeoms,
CurveMap(), prismIDs, prismData);
555 FillGeomMap(m_pyrGeoms,
CurveMap(), pyrIDs, pyrData);
556 FillGeomMap(m_tetGeoms,
CurveMap(), tetIDs, tetData);
562 if (m_session->DefinesElement(
"NEKTAR/CONDITIONS"))
564 std::set<int> vBndRegionIdList;
565 TiXmlElement *vConditions =
566 new TiXmlElement(*m_session->GetElement(
"Nektar/Conditions"));
567 TiXmlElement *vBndRegions =
568 vConditions->FirstChildElement(
"BOUNDARYREGIONS");
573 vItem = vBndRegions->FirstChildElement();
576 std::string vSeqStr =
577 vItem->FirstChild()->ToText()->Value();
578 std::string::size_type indxBeg =
579 vSeqStr.find_first_of(
'[') + 1;
580 std::string::size_type indxEnd =
581 vSeqStr.find_last_of(
']') - 1;
582 vSeqStr = vSeqStr.substr(indxBeg, indxEnd - indxBeg + 1);
584 std::vector<unsigned int> vSeq;
585 ParseUtils::GenerateSeqVector(vSeqStr.c_str(), vSeq);
587 int p = atoi(vItem->Attribute(
"ID"));
588 m_bndRegOrder[
p] = vSeq;
589 vItem = vItem->NextSiblingElement();
598 template<
class T,
typename DataType>
void MeshGraphHDF5::ConstructGeomObject(
599 std::map<
int, std::shared_ptr<T>> &geomMap,
int id,
602 boost::ignore_unused(geomMap,
id, data, curve);
605 template<>
void MeshGraphHDF5::ConstructGeomObject(
606 std::map<
int, std::shared_ptr<PointGeom>> &geomMap,
int id,
609 boost::ignore_unused(curve);
611 m_spaceDimension,
id, data[0], data[1], data[2]);
614 template<>
void MeshGraphHDF5::ConstructGeomObject(
615 std::map<
int, std::shared_ptr<SegGeom>> &geomMap,
int id,
int *data,
620 id, m_spaceDimension, pts, curve);
623 template<>
void MeshGraphHDF5::ConstructGeomObject(
624 std::map<
int, std::shared_ptr<TriGeom>> &geomMap,
int id,
int *data,
628 GetSegGeom(data[0]), GetSegGeom(data[1]), GetSegGeom(data[2]) };
632 template<>
void MeshGraphHDF5::ConstructGeomObject(
633 std::map<
int, std::shared_ptr<QuadGeom>> &geomMap,
int id,
int *data,
637 GetSegGeom(data[0]), GetSegGeom(data[1]), GetSegGeom(data[2]),
643 template<>
void MeshGraphHDF5::ConstructGeomObject(
644 std::map<
int, std::shared_ptr<TetGeom>> &geomMap,
int id,
int *data,
647 boost::ignore_unused(curve);
649 std::static_pointer_cast<
TriGeom>(GetGeometry2D(data[0])),
650 std::static_pointer_cast<TriGeom>(GetGeometry2D(data[1])),
651 std::static_pointer_cast<TriGeom>(GetGeometry2D(data[2])),
652 std::static_pointer_cast<TriGeom>(GetGeometry2D(data[3]))
656 PopulateFaceToElMap(tetGeom, TetGeom::kNfaces);
657 geomMap[id] = tetGeom;
660 template<>
void MeshGraphHDF5::ConstructGeomObject(
661 std::map<
int, std::shared_ptr<PyrGeom>> &geomMap,
int id,
int *data,
664 boost::ignore_unused(curve);
666 GetGeometry2D(data[0]), GetGeometry2D(data[1]), GetGeometry2D(data[2]),
667 GetGeometry2D(data[3]), GetGeometry2D(data[4])
671 PopulateFaceToElMap(pyrGeom, PyrGeom::kNfaces);
672 geomMap[id] = pyrGeom;
675 template<>
void MeshGraphHDF5::ConstructGeomObject(
676 std::map<
int, std::shared_ptr<PrismGeom>> &geomMap,
int id,
int *data,
679 boost::ignore_unused(curve);
681 GetGeometry2D(data[0]), GetGeometry2D(data[1]), GetGeometry2D(data[2]),
682 GetGeometry2D(data[3]), GetGeometry2D(data[4])
686 PopulateFaceToElMap(prismGeom, PrismGeom::kNfaces);
687 geomMap[id] = prismGeom;
690 template<>
void MeshGraphHDF5::ConstructGeomObject(
691 std::map<
int, std::shared_ptr<HexGeom>> &geomMap,
int id,
int *data,
694 boost::ignore_unused(curve);
696 std::static_pointer_cast<
QuadGeom>(GetGeometry2D(data[0])),
697 std::static_pointer_cast<QuadGeom>(GetGeometry2D(data[1])),
698 std::static_pointer_cast<QuadGeom>(GetGeometry2D(data[2])),
699 std::static_pointer_cast<QuadGeom>(GetGeometry2D(data[3])),
700 std::static_pointer_cast<QuadGeom>(GetGeometry2D(data[4])),
701 std::static_pointer_cast<QuadGeom>(GetGeometry2D(data[5]))
705 PopulateFaceToElMap(hexGeom, HexGeom::kNfaces);
706 geomMap[id] = hexGeom;
709 template<
class T,
typename DataType>
710 void MeshGraphHDF5::FillGeomMap(
711 std::map<
int, std::shared_ptr<T>> &geomMap,
713 std::vector<int> &ids,
714 std::vector<DataType> &geomData)
717 const int nRows = geomData.size() / nGeomData;
721 if (curveMap.size() > 0)
723 for(
int i = 0, cnt = 0; i < nRows; i++, cnt += nGeomData)
725 auto cIt = curveMap.find(ids[i]);
727 geomMap, ids[i], &geomData[cnt],
728 cIt == curveMap.end() ? empty : cIt->second);
733 for(
int i = 0, cnt = 0; i < nRows; i++, cnt += nGeomData)
735 ConstructGeomObject(geomMap, ids[i], &geomData[cnt], empty);
740 template<
class T,
typename DataType>
741 void MeshGraphHDF5::ReadGeometryData(
742 std::map<
int, std::shared_ptr<T>> &geomMap,
744 const std::unordered_set<int> &readIds,
745 std::vector<int> &ids,
746 std::vector<DataType> &geomData)
748 if (!m_mesh->ContainsDataSet(dataSet))
756 vector<hsize_t> dims = space->GetDims();
761 vector<hsize_t> mdims = mspace->GetDims();
763 ASSERTL0(mdims[0] == dims[0],
"map and data set lengths do not match");
769 mdata->Read(allIds, mspace);
776 std::vector<hsize_t> coords;
777 for (
auto &
id : allIds)
779 if (readIds.find(
id) != readIds.end())
781 for (
int j = 0; j < nGeomData; ++j)
791 space->SetSelection(coords.size() / 2, coords);
794 data->Read(geomData, space, m_readPL);
797 void MeshGraphHDF5::ReadCurveMap(
800 const std::unordered_set<int> &readIds)
803 if (!m_mesh->ContainsDataSet(dsName))
817 vector<int> ids, newIds;
818 idData->Read(ids, idSpace);
819 curveSpace->ClearRange();
822 vector<hsize_t> curveSel;
827 if (readIds.find(
id) != readIds.end())
829 curveSel.push_back(cnt);
830 curveSel.push_back(0);
831 curveSel.push_back(cnt);
832 curveSel.push_back(1);
833 curveSel.push_back(cnt);
834 curveSel.push_back(2);
835 newIds.push_back(
id);
842 auto toRead = newIds.size();
851 vector<int> curveInfo;
852 curveSpace->SetSelection(curveSel.size() / 2, curveSel);
853 curveData->Read(curveInfo, curveSpace, m_readPL);
857 std::unordered_map<int, int> curvePtOffset;
860 for (
int i = 0, cnt = 0, cnt2 = 0; i < curveInfo.size() / 3; ++i, cnt += 3)
865 curve->m_points.resize(curveInfo[cnt]);
867 const int ptOffset = curveInfo[cnt + 2];
869 for (
int j = 0; j < curveInfo[cnt]; ++j)
873 curveSel.push_back(ptOffset + j);
874 curveSel.push_back(0);
875 curveSel.push_back(ptOffset + j);
876 curveSel.push_back(1);
877 curveSel.push_back(ptOffset + j);
878 curveSel.push_back(2);
883 curvePtOffset[newIds[i]] = 3 * cnt2;
884 cnt2 += curveInfo[cnt];
886 curveMap[newIds[i]] = curve;
895 nodeSpace->ClearRange();
896 nodeSpace->SetSelection(curveSel.size() / 2, curveSel);
898 vector<NekDouble> nodeRawData;
899 nodeData->Read(nodeRawData, nodeSpace, m_readPL);
902 for (
auto &cIt : curvePtOffset)
907 int cnt = cIt.second;
908 for (
int i = 0; i < curve->m_points.size(); ++i, cnt += 3)
911 0, m_spaceDimension, nodeRawData[cnt], nodeRawData[cnt+1],
917 void MeshGraphHDF5::ReadDomain()
919 map<int, CompositeSharedPtr> fullDomain;
924 dst->ReadVectorString(data, space, m_readPL);
925 GetCompositeList(data[0], fullDomain);
926 m_domain.push_back(fullDomain);
929 void MeshGraphHDF5::ReadComposites()
931 string nm =
"COMPOSITE";
935 vector<hsize_t> dims = space->GetDims();
937 vector<string> comps;
938 data->ReadVectorString(comps, space);
942 vector<hsize_t> mdims = mspace->GetDims();
945 mdata->Read(ids, mspace);
947 for(
int i = 0; i < dims[0]; i++)
949 string compStr = comps[i];
952 istringstream strm(compStr);
959 string::size_type indxBeg = compStr.find_first_of(
'[') + 1;
960 string::size_type indxEnd = compStr.find_last_of(
']') - 1;
962 string indxStr = compStr.substr(indxBeg, indxEnd - indxBeg + 1);
963 vector<unsigned int> seqVector;
965 ParseUtils::GenerateSeqVector(indxStr, seqVector);
966 m_compOrder[ids[i]] = seqVector;
971 for (
auto &i : seqVector)
973 auto it = m_vertSet.find(i);
974 if (it != m_vertSet.end())
976 comp->m_geomVec.push_back(it->second);
982 for (
auto &i : seqVector)
984 auto it = m_segGeoms.find(i);
985 if (it != m_segGeoms.end())
987 comp->m_geomVec.push_back(it->second);
992 for (
auto &i : seqVector)
994 auto it = m_quadGeoms.find(i);
995 if (it != m_quadGeoms.end())
997 comp->m_geomVec.push_back(it->second);
1002 for (
auto &i : seqVector)
1004 auto it = m_triGeoms.find(i);
1005 if (it != m_triGeoms.end())
1007 comp->m_geomVec.push_back(it->second);
1012 for(
auto &i : seqVector)
1014 auto it1 = m_quadGeoms.find(i);
1015 if (it1 != m_quadGeoms.end())
1017 comp->m_geomVec.push_back(it1->second);
1020 auto it2 = m_triGeoms.find(i);
1021 if (it2 != m_triGeoms.end())
1023 comp->m_geomVec.push_back(it2->second);
1028 for(
auto &i : seqVector)
1030 auto it = m_tetGeoms.find(i);
1031 if (it != m_tetGeoms.end())
1033 comp->m_geomVec.push_back(it->second);
1038 for(
auto &i : seqVector)
1040 auto it = m_pyrGeoms.find(i);
1041 if (it != m_pyrGeoms.end())
1043 comp->m_geomVec.push_back(it->second);
1048 for(
auto &i : seqVector)
1050 auto it = m_prismGeoms.find(i);
1051 if (it != m_prismGeoms.end())
1053 comp->m_geomVec.push_back(it->second);
1058 for(
auto &i : seqVector)
1060 auto it = m_hexGeoms.find(i);
1061 if (it != m_hexGeoms.end())
1063 comp->m_geomVec.push_back(it->second);
1069 if (comp->m_geomVec.size() > 0)
1071 m_meshComposites[ids[i]] = comp;
1077 std::unordered_map<int, int> &id2row)
1081 string nm =
"COMPOSITE";
1085 vector<hsize_t> dims = space->GetDims();
1087 vector<string> comps;
1088 data->ReadVectorString(comps, space);
1092 vector<hsize_t> mdims = mspace->GetDims();
1095 mdata->Read(ids, mspace);
1097 for (
int i = 0; i < dims[0]; i++)
1099 string compStr = comps[i];
1102 istringstream strm(compStr);
1106 string::size_type indxBeg = compStr.find_first_of(
'[') + 1;
1107 string::size_type indxEnd = compStr.find_last_of(
']') - 1;
1109 string indxStr = compStr.substr(indxBeg, indxEnd - indxBeg + 1);
1110 vector<unsigned int> seqVector;
1111 ParseUtils::GenerateSeqVector(indxStr, seqVector);
1148 std::vector<int> filteredVector;
1149 for (
auto &compElmt : seqVector)
1151 if (id2row.find(compElmt) == id2row.end())
1156 filteredVector.push_back(compElmt);
1159 if (filteredVector.size() == 0)
1164 ret[ids[i]] = std::make_pair(shapeType, filteredVector);
1171 template<class T, typename std::enable_if<T::kDim == 0, int>::type = 0>
1177 template<class T, typename std::enable_if<T::kDim == 1, int>::type = 0>
1180 return geom->GetVid(i);
1183 template<class T, typename std::enable_if<T::kDim == 2, int>::type = 0>
1184 inline int GetGeomData(std::shared_ptr<T> &geom,
int i)
1186 return geom->GetEid(i);
1189 template<class T, typename std::enable_if<T::kDim == 3, int>::type = 0>
1190 inline int GetGeomData(std::shared_ptr<T> &geom,
int i)
1192 return geom->GetFid(i);
1196 void MeshGraphHDF5::WriteGeometryMap(std::map<
int, std::shared_ptr<T>> &geomMap,
1197 std::string datasetName)
1199 typedef typename std::conditional<
1200 std::is_same<T, PointGeom>::value,
NekDouble,
int>::type DataType;
1203 const size_t nGeom = geomMap.size();
1211 vector<int> idMap(nGeom);
1212 vector<DataType> data(nGeom * nGeomData);
1214 int cnt1 = 0, cnt2 = 0;
1215 for (
auto &it : geomMap)
1217 idMap[cnt1++] = it.first;
1219 for (
int j = 0; j < nGeomData; ++j)
1227 vector<hsize_t> dims = {
static_cast<hsize_t
>(nGeom),
1228 static_cast<hsize_t>(nGeomData) };
1233 dst->Write(data, ds);
1235 tp = H5::DataType::OfObject(idMap[0]);
1237 ds = std::shared_ptr<H5::DataSpace>(
new H5::DataSpace(dims));
1238 dst = m_maps->CreateDataSet(datasetName, tp, ds);
1239 dst->Write(idMap, ds);
1248 vector<int> data, map;
1251 for (
auto &c : curves)
1253 map.push_back(c.first);
1254 data.push_back(c.second->m_points.size());
1255 data.push_back(c.second->m_ptype);
1256 data.push_back(ptOffset);
1258 ptOffset += c.second->m_points.size();
1260 for (
auto &pt : c.second->m_points)
1264 pt->GetCoords(v.
x, v.
y, v.
z);
1265 curvedPts.
pts.push_back(v);
1266 curvedPts.
index.push_back(newIdx++);
1271 vector<hsize_t> dims = { data.size() / 3, 3 };
1276 dst->Write(data, ds);
1278 tp = H5::DataType::OfObject(map[0]);
1279 dims = { map.size() };
1280 ds = std::shared_ptr<H5::DataSpace>(
new H5::DataSpace(dims));
1281 dst = m_maps->CreateDataSet(dsName, tp, ds);
1282 dst->Write(map, ds);
1287 vector<double> vertData(curvedPts.
pts.size() * 3);
1290 for (
auto &pt : curvedPts.
pts)
1292 vertData[cnt++] = pt.x;
1293 vertData[cnt++] = pt.y;
1294 vertData[cnt++] = pt.z;
1297 vector<hsize_t> dims = { curvedPts.
pts.size(), 3 };
1302 dst->Write(vertData, ds);
1307 vector<string> comps;
1314 for (
auto &cIt : composites)
1316 if (cIt.second->m_geomVec.size() == 0)
1321 comps.push_back(GetCompositeString(cIt.second));
1322 c_map.push_back(cIt.first);
1328 dst->WriteVectorString(comps, ds, tp);
1330 tp = H5::DataType::OfObject(c_map[0]);
1331 ds = H5::DataSpace::OneD(c_map.size());
1332 dst = m_maps->CreateDataSet(
"COMPOSITE", tp, ds);
1333 dst->Write(c_map, ds);
1336 void MeshGraphHDF5::WriteDomain(vector<CompositeMap> &domain)
1338 vector<unsigned int> idxList;
1339 for (
auto cIt = domain[0].begin(); cIt != domain[0].end(); ++cIt)
1341 idxList.push_back(cIt->first);
1343 stringstream domString;
1344 vector<string> doms;
1345 doms.push_back(ParseUtils::GenerateSeqString(idxList));
1350 dst->WriteVectorString(doms, ds, tp);
1353 void MeshGraphHDF5::WriteGeometry(
1354 std::string &outfilename,
1358 boost::ignore_unused(metadata);
1361 boost::split(tmp, outfilename, boost::is_any_of(
"."));
1362 string filenameXml = tmp[0] +
".xml";
1363 string filenameHdf5 = tmp[0] +
".nekg";
1372 TiXmlDocument *doc =
new TiXmlDocument;
1374 TiXmlElement *geomTag;
1376 if(boost::filesystem::exists(filenameXml.c_str()))
1378 ifstream file(filenameXml.c_str());
1380 TiXmlHandle docHandle(doc);
1381 root = docHandle.FirstChildElement(
"NEKTAR").Element();
1382 ASSERTL0(root,
"Unable to find NEKTAR tag in file.");
1383 geomTag = root->FirstChildElement(
"GEOMETRY");
1388 TiXmlDeclaration *decl =
new TiXmlDeclaration(
"1.0",
"utf-8",
"");
1389 doc->LinkEndChild(decl);
1390 root =
new TiXmlElement(
"NEKTAR");
1391 doc->LinkEndChild(root);
1393 geomTag =
new TiXmlElement(
"GEOMETRY");
1394 root->LinkEndChild(geomTag);
1398 geomTag->SetAttribute(
"DIM", m_meshDimension);
1399 geomTag->SetAttribute(
"SPACE", m_spaceDimension);
1400 geomTag->SetAttribute(
"HDF5FILE", filenameHdf5);
1406 TiXmlElement *expTag =
new TiXmlElement(
"EXPANSIONS");
1408 for (
auto it = m_meshComposites.begin(); it != m_meshComposites.end();
1411 if (it->second->m_geomVec[0]->GetShapeDim() == m_meshDimension)
1413 TiXmlElement *exp =
new TiXmlElement(
"E");
1416 "C[" + boost::lexical_cast<string>(it->first) +
"]");
1417 exp->SetAttribute(
"NUMMODES", 4);
1418 exp->SetAttribute(
"TYPE",
"MODIFIED");
1419 exp->SetAttribute(
"FIELDS",
"u");
1421 expTag->LinkEndChild(exp);
1424 root->LinkEndChild(expTag);
1427 doc->SaveFile(filenameXml);
1434 m_file = H5::File::Create(filenameHdf5, H5F_ACC_TRUNC);
1435 auto hdfRoot = m_file->CreateGroup(
"NEKTAR");
1436 auto hdfRoot2 = hdfRoot->CreateGroup(
"GEOMETRY");
1439 hdfRoot2->SetAttribute(
"FORMAT_VERSION", FORMAT_VERSION);
1442 m_mesh = hdfRoot2->CreateGroup(
"MESH");
1443 m_maps = hdfRoot2->CreateGroup(
"MAPS");
1445 WriteGeometryMap(m_vertSet,
"VERT");
1446 WriteGeometryMap(m_segGeoms,
"SEG");
1447 if (m_meshDimension > 1)
1449 WriteGeometryMap(m_triGeoms,
"TRI");
1450 WriteGeometryMap(m_quadGeoms,
"QUAD");
1452 if (m_meshDimension > 2)
1454 WriteGeometryMap(m_tetGeoms,
"TET");
1455 WriteGeometryMap(m_pyrGeoms,
"PYR");
1456 WriteGeometryMap(m_prismGeoms,
"PRISM");
1457 WriteGeometryMap(m_hexGeoms,
"HEX");
1461 int ptOffset = 0, newIdx = 0;
1463 WriteCurveMap(m_curvedEdges,
"CURVE_EDGE", curvePts, ptOffset, newIdx);
1464 WriteCurveMap(m_curvedFaces,
"CURVE_FACE", curvePts, ptOffset, newIdx);
1465 WriteCurvePoints(curvePts);
1468 WriteComposites(m_meshComposites);
1469 WriteDomain(m_domain);
#define ASSERTL0(condition, msg)
std::vector< NekInt64 > index
id of this Point set
std::shared_ptr< Geometry2D > Geometry2DSharedPtr
std::shared_ptr< MeshPartition > MeshPartitionSharedPtr
std::unordered_map< int, CurveSharedPtr > CurveMap
General purpose memory allocation routines with the ability to allocate from thread specific memory p...
std::shared_ptr< QuadGeom > QuadGeomSharedPtr
std::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
std::map< int, CompositeSharedPtr > CompositeMap
std::vector< MeshVertex > pts
mapping to access pts value.
std::shared_ptr< DataSpace > DataSpaceSharedPtr
std::shared_ptr< Composite > CompositeSharedPtr
std::shared_ptr< DomainRange > DomainRangeShPtr
std::map< std::string, std::string > FieldMetaDataMap
std::shared_ptr< DataSet > DataSetSharedPtr
std::shared_ptr< DataType > DataTypeSharedPtr
std::shared_ptr< PList > PListSharedPtr
int GetGeomData(std::shared_ptr< T > &geom, int i)
int GetGeomDataDim(std::map< int, std::shared_ptr< T >> &geomMap)
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
std::shared_ptr< TriGeom > TriGeomSharedPtr
bool ModuleExists(tKey idKey)
Checks if a particular module is available.
MeshGraphFactory & GetMeshGraphFactory()
std::vector< unsigned int > list
std::shared_ptr< PointGeom > PointGeomSharedPtr
std::map< int, std::pair< LibUtilities::ShapeType, std::vector< int > > > CompositeDescriptor
std::shared_ptr< Curve > CurveSharedPtr
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.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
MeshPartitionFactory & GetMeshPartitionFactory()
void UniqueValues(std::unordered_set< int > &unique, const std::vector< int > &input, T &... args)
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode...
std::shared_ptr< SegGeom > SegGeomSharedPtr
std::shared_ptr< SessionReader > SessionReaderSharedPtr
#define TIME_RESULT(verb, msg, timer)