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);
85 MeshGraph::FillGraph();
100 std::pair<size_t, size_t>
SplitWork(
size_t vecsize,
int rank,
int nprocs)
102 size_t div = vecsize / nprocs;
103 size_t rem = vecsize % nprocs;
106 return std::make_pair(rank * (div + 1), div + 1);
110 return std::make_pair((rank - rem) * div + rem * (div + 1), div);
114 template<class T, typename std::enable_if<T::kDim == 0, int>::type = 0>
117 boost::ignore_unused(geomMap);
121 template<class T, typename std::enable_if<T::kDim == 1, int>::type = 0>
122 inline int GetGeomDataDim(std::map<
int, std::shared_ptr<T>> &geomMap)
124 boost::ignore_unused(geomMap);
128 template<class T, typename std::enable_if<T::kDim == 2, int>::type = 0>
129 inline int GetGeomDataDim(std::map<
int, std::shared_ptr<T>> &geomMap)
131 boost::ignore_unused(geomMap);
135 template<class T, typename std::enable_if<T::kDim == 3, int>::type = 0>
136 inline int GetGeomDataDim(std::map<
int, std::shared_ptr<T>> &geomMap)
138 boost::ignore_unused(geomMap);
145 boost::ignore_unused(unique);
150 const std::vector<int> &input,
170 int rank = comm->GetRank(), nproc = comm->GetSize();
177 session->InitSession();
182 m_xmlGeom = m_session->GetElement(
"NEKTAR/GEOMETRY");
183 TiXmlAttribute *attr = m_xmlGeom->FirstAttribute();
184 m_meshPartitioned =
true;
186 m_spaceDimension = 3;
190 std::string attrName(attr->Name());
191 if (attrName ==
"DIM")
193 err = attr->QueryIntValue(&m_meshDimension);
194 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read mesh dimension.");
196 else if (attrName ==
"SPACE")
198 err = attr->QueryIntValue(&m_spaceDimension);
199 ASSERTL0(err == TIXML_SUCCESS,
"Unable to read space dimension.");
201 else if (attrName ==
"PARTITION")
204 "PARTITION parameter should only be used in XML meshes");
206 else if(attrName ==
"HDF5FILE")
208 m_hdf5Name = attr->Value();
209 ASSERTL1(err == TIXML_SUCCESS,
"Unable to read hdf5 name.");
211 else if(attrName ==
"PARTITIONED")
214 "PARTITIONED parameter should only be used in XML meshes");
218 std::string errstr(
"Unknown attribute: ");
226 ASSERTL0(m_hdf5Name.size() > 0,
"Unable to obtain mesh file name.");
227 ASSERTL0(m_meshDimension <= m_spaceDimension,
228 "Mesh dimension greater than space dimension.");
232 m_readPL = H5::PList::Default();
237 parallelProps = H5::PList::FileAccess();
238 parallelProps->SetMpio(comm);
240 m_readPL = H5::PList::DatasetXfer();
241 m_readPL->SetDxMpioCollective();
244 m_file = H5::File::Open(m_hdf5Name, H5F_ACC_RDONLY, parallelProps);
246 auto root = m_file->OpenGroup(
"NEKTAR");
247 ASSERTL0(root,
"Cannot find NEKTAR group in HDF5 file.");
249 auto root2 = root->OpenGroup(
"GEOMETRY");
250 ASSERTL0(root2,
"Cannot find NEKTAR/GEOMETRY group in HDF5 file.");
253 unsigned int formatVersion;
254 H5::Group::AttrIterator attrIt = root2->attr_begin();
255 H5::Group::AttrIterator attrEnd = root2->attr_end();
256 for (; attrIt != attrEnd; ++attrIt)
258 if (*attrIt ==
"FORMAT_VERSION")
264 "Unable to determine Nektar++ geometry HDF5 file version.");
265 root2->GetAttribute(
"FORMAT_VERSION", formatVersion);
267 ASSERTL0(formatVersion <= FORMAT_VERSION,
268 "File format in " + m_hdf5Name +
" is higher than supported in "
269 "this version of Nektar++");
271 m_mesh = root2->OpenGroup(
"MESH");
272 ASSERTL0(m_mesh,
"Cannot find NEKTAR/GEOMETRY/MESH group in HDF5 file.");
273 m_maps = root2->OpenGroup(
"MAPS");
274 ASSERTL0(m_mesh,
"Cannot find NEKTAR/GEOMETRY/MAPS group in HDF5 file.");
277 std::map<int, std::vector<std::tuple<
289 std::vector<MeshEntity> elmts;
290 std::vector<int> ids;
294 std::unordered_map<int, int> row2id, id2row;
299 for (
auto &it : dataSets[m_meshDimension])
301 std::string ds = std::get<0>(it);
303 if (!m_mesh->ContainsDataSet(ds))
311 vector<hsize_t> dims = space->GetDims();
315 vector<hsize_t> mdims = mspace->GetDims();
319 vector<int> tmpElmts, tmpIds;
320 mdata->Read(tmpIds, mspace, m_readPL);
321 data->Read(tmpElmts, space, m_readPL);
323 const int nGeomData = std::get<1>(it);
325 for (
int i = 0, cnt = 0; i < tmpIds.size(); ++i, ++rowCount)
328 row2id[rowCount] = tmpIds[i];
329 id2row[tmpIds[i]] = row2id[rowCount];
332 e.
list = std::vector<unsigned int>(
333 &tmpElmts[cnt], &tmpElmts[cnt+nGeomData]);
342 bool verbRoot = rank == 0 &&
343 m_session->DefinesCmdLineArgument(
"verbose");
347 std::cout <<
"Reading HDF5 geometry..." << std::endl;
353 size_t numElmt = elmts.size();
355 "This mesh has more processors than elements!");
358 auto elRange =
SplitWork(numElmt, rank, nproc);
363 std::map<int, MeshEntity> partElmts;
364 std::unordered_set<int> facetIDs;
368 for (
int el = elRange.first; el < elRange.first + elRange.second;
373 partElmts[el] = elmt;
375 for (
auto &facet : elmt.
list)
377 facetIDs.insert(facet);
384 for (
int i = 0; i < numElmt; ++i)
387 if (i >= elRange.first && i < elRange.first + elRange.second)
397 for (
auto &eId : elmt.
list)
399 if (facetIDs.find(eId) != facetIDs.end())
409 partElmts[elmt.
id] = elmt;
416 string partitionerName = nproc > 1 ?
"PtScotch" :
"Scotch";
419 partitionerName =
"ParMetis";
421 if (session->DefinesCmdLineArgument(
"use-parmetis"))
423 partitionerName =
"ParMetis";
425 if (session->DefinesCmdLineArgument(
"use-ptscotch"))
427 partitionerName =
"PtScotch";
432 partitionerName, session, m_meshDimension,
433 partElmts, CreateCompositeDescriptor(id2row));
435 partitioner->PartitionMesh(nproc,
true,
false, nLocal);
443 std::vector<unsigned int> tmp;
444 std::unordered_set<int> toRead;
445 partitioner->GetElementIDs(comm->GetRank(), tmp);
447 for (
auto &tmpId : tmp)
449 toRead.insert(row2id[tmpId]);
455 std::vector<int> vertIDs, segIDs, triIDs, quadIDs;
456 std::vector<int> tetIDs, prismIDs, pyrIDs, hexIDs;
457 std::vector<int> segData, triData, quadData, tetData;
458 std::vector<int> prismData, pyrData, hexData;
459 std::vector<NekDouble> vertData;
461 if (m_meshDimension == 3)
465 ReadGeometryData(m_hexGeoms,
"HEX", toRead, hexIDs, hexData);
466 ReadGeometryData(m_pyrGeoms,
"PYR", toRead, pyrIDs, pyrData);
467 ReadGeometryData(m_prismGeoms,
"PRISM", toRead, prismIDs, prismData);
468 ReadGeometryData(m_tetGeoms,
"TET", toRead, tetIDs, tetData);
471 UniqueValues(toRead, hexData, pyrData, prismData, tetData);
476 if (m_meshDimension >= 2)
480 ReadGeometryData(m_triGeoms,
"TRI", toRead, triIDs, triData);
481 ReadGeometryData(m_quadGeoms,
"QUAD", toRead, quadIDs, quadData);
489 if (m_meshDimension >= 1)
493 ReadGeometryData(m_segGeoms,
"SEG", toRead, segIDs, segData);
502 ReadGeometryData(m_vertSet,
"VERT", toRead, vertIDs, vertData);
508 FillGeomMap(m_vertSet,
CurveMap(), vertIDs, vertData);
512 if (m_meshDimension >= 1)
516 for (
auto &edge : segIDs)
520 ReadCurveMap(m_curvedEdges,
"CURVE_EDGE", toRead);
523 FillGeomMap(m_segGeoms, m_curvedEdges, segIDs, segData);
528 if (m_meshDimension >= 2)
532 for (
auto &face : triIDs)
536 for (
auto &face : quadIDs)
540 ReadCurveMap(m_curvedFaces,
"CURVE_FACE", toRead);
543 FillGeomMap(m_triGeoms, m_curvedFaces, triIDs, triData);
544 FillGeomMap(m_quadGeoms, m_curvedFaces, quadIDs, quadData);
549 if (m_meshDimension >= 3)
552 FillGeomMap(m_hexGeoms,
CurveMap(), hexIDs, hexData);
553 FillGeomMap(m_prismGeoms,
CurveMap(), prismIDs, prismData);
554 FillGeomMap(m_pyrGeoms,
CurveMap(), pyrIDs, pyrData);
555 FillGeomMap(m_tetGeoms,
CurveMap(), tetIDs, tetData);
561 if (m_session->DefinesElement(
"NEKTAR/CONDITIONS"))
563 std::set<int> vBndRegionIdList;
564 TiXmlElement *vConditions =
565 new TiXmlElement(*m_session->GetElement(
"Nektar/Conditions"));
566 TiXmlElement *vBndRegions =
567 vConditions->FirstChildElement(
"BOUNDARYREGIONS");
572 vItem = vBndRegions->FirstChildElement();
575 std::string vSeqStr =
576 vItem->FirstChild()->ToText()->Value();
577 std::string::size_type indxBeg =
578 vSeqStr.find_first_of(
'[') + 1;
579 std::string::size_type indxEnd =
580 vSeqStr.find_last_of(
']') - 1;
581 vSeqStr = vSeqStr.substr(indxBeg, indxEnd - indxBeg + 1);
583 std::vector<unsigned int> vSeq;
584 ParseUtils::GenerateSeqVector(vSeqStr.c_str(), vSeq);
586 int p = atoi(vItem->Attribute(
"ID"));
587 m_bndRegOrder[
p] = vSeq;
588 vItem = vItem->NextSiblingElement();
597 template<
class T,
typename DataType>
void MeshGraphHDF5::ConstructGeomObject(
598 std::map<
int, std::shared_ptr<T>> &geomMap,
int id,
601 boost::ignore_unused(geomMap,
id, data, curve);
604 template<>
void MeshGraphHDF5::ConstructGeomObject(
605 std::map<
int, std::shared_ptr<PointGeom>> &geomMap,
int id,
608 boost::ignore_unused(curve);
610 m_spaceDimension,
id, data[0], data[1], data[2]);
613 template<>
void MeshGraphHDF5::ConstructGeomObject(
614 std::map<
int, std::shared_ptr<SegGeom>> &geomMap,
int id,
int *data,
619 id, m_spaceDimension, pts, curve);
622 template<>
void MeshGraphHDF5::ConstructGeomObject(
623 std::map<
int, std::shared_ptr<TriGeom>> &geomMap,
int id,
int *data,
627 GetSegGeom(data[0]), GetSegGeom(data[1]), GetSegGeom(data[2]) };
631 template<>
void MeshGraphHDF5::ConstructGeomObject(
632 std::map<
int, std::shared_ptr<QuadGeom>> &geomMap,
int id,
int *data,
636 GetSegGeom(data[0]), GetSegGeom(data[1]), GetSegGeom(data[2]),
642 template<>
void MeshGraphHDF5::ConstructGeomObject(
643 std::map<
int, std::shared_ptr<TetGeom>> &geomMap,
int id,
int *data,
646 boost::ignore_unused(curve);
648 std::static_pointer_cast<TriGeom>(GetGeometry2D(data[0])),
649 std::static_pointer_cast<TriGeom>(GetGeometry2D(data[1])),
650 std::static_pointer_cast<TriGeom>(GetGeometry2D(data[2])),
651 std::static_pointer_cast<TriGeom>(GetGeometry2D(data[3]))
655 PopulateFaceToElMap(tetGeom, TetGeom::kNfaces);
656 geomMap[id] = tetGeom;
659 template<>
void MeshGraphHDF5::ConstructGeomObject(
660 std::map<
int, std::shared_ptr<PyrGeom>> &geomMap,
int id,
int *data,
663 boost::ignore_unused(curve);
665 GetGeometry2D(data[0]), GetGeometry2D(data[1]), GetGeometry2D(data[2]),
666 GetGeometry2D(data[3]), GetGeometry2D(data[4])
670 PopulateFaceToElMap(pyrGeom, PyrGeom::kNfaces);
671 geomMap[id] = pyrGeom;
674 template<>
void MeshGraphHDF5::ConstructGeomObject(
675 std::map<
int, std::shared_ptr<PrismGeom>> &geomMap,
int id,
int *data,
678 boost::ignore_unused(curve);
680 GetGeometry2D(data[0]), GetGeometry2D(data[1]), GetGeometry2D(data[2]),
681 GetGeometry2D(data[3]), GetGeometry2D(data[4])
685 PopulateFaceToElMap(prismGeom, PrismGeom::kNfaces);
686 geomMap[id] = prismGeom;
689 template<>
void MeshGraphHDF5::ConstructGeomObject(
690 std::map<
int, std::shared_ptr<HexGeom>> &geomMap,
int id,
int *data,
693 boost::ignore_unused(curve);
695 std::static_pointer_cast<QuadGeom>(GetGeometry2D(data[0])),
696 std::static_pointer_cast<QuadGeom>(GetGeometry2D(data[1])),
697 std::static_pointer_cast<QuadGeom>(GetGeometry2D(data[2])),
698 std::static_pointer_cast<QuadGeom>(GetGeometry2D(data[3])),
699 std::static_pointer_cast<QuadGeom>(GetGeometry2D(data[4])),
700 std::static_pointer_cast<QuadGeom>(GetGeometry2D(data[5]))
704 PopulateFaceToElMap(hexGeom, HexGeom::kNfaces);
705 geomMap[id] = hexGeom;
708 template<
class T,
typename DataType>
709 void MeshGraphHDF5::FillGeomMap(
710 std::map<
int, std::shared_ptr<T>> &geomMap,
712 std::vector<int> &ids,
713 std::vector<DataType> &geomData)
716 const int nRows = geomData.size() / nGeomData;
720 if (curveMap.size() > 0)
722 for(
int i = 0, cnt = 0; i < nRows; i++, cnt += nGeomData)
724 auto cIt = curveMap.find(ids[i]);
726 geomMap, ids[i], &geomData[cnt],
727 cIt == curveMap.end() ? empty : cIt->second);
732 for(
int i = 0, cnt = 0; i < nRows; i++, cnt += nGeomData)
734 ConstructGeomObject(geomMap, ids[i], &geomData[cnt], empty);
739 template<
class T,
typename DataType>
740 void MeshGraphHDF5::ReadGeometryData(
741 std::map<
int, std::shared_ptr<T>> &geomMap,
743 const std::unordered_set<int> &readIds,
744 std::vector<int> &ids,
745 std::vector<DataType> &geomData)
747 if (!m_mesh->ContainsDataSet(dataSet))
755 vector<hsize_t> dims = space->GetDims();
760 vector<hsize_t> mdims = mspace->GetDims();
762 ASSERTL0(mdims[0] == dims[0],
"map and data set lengths do not match");
768 mdata->Read(allIds, mspace);
775 std::vector<hsize_t> coords;
776 for (
auto &
id : allIds)
778 if (readIds.find(
id) != readIds.end())
780 for (
int j = 0; j < nGeomData; ++j)
790 space->SetSelection(coords.size() / 2, coords);
793 data->Read(geomData, space, m_readPL);
796 void MeshGraphHDF5::ReadCurveMap(
799 const std::unordered_set<int> &readIds)
802 if (!m_mesh->ContainsDataSet(dsName))
816 vector<int> ids, newIds;
817 idData->Read(ids, idSpace);
818 curveSpace->ClearRange();
821 vector<hsize_t> curveSel;
826 if (readIds.find(
id) != readIds.end())
828 curveSel.push_back(cnt);
829 curveSel.push_back(0);
830 curveSel.push_back(cnt);
831 curveSel.push_back(1);
832 curveSel.push_back(cnt);
833 curveSel.push_back(2);
834 newIds.push_back(
id);
841 auto toRead = newIds.size();
850 vector<int> curveInfo;
851 curveSpace->SetSelection(curveSel.size() / 2, curveSel);
852 curveData->Read(curveInfo, curveSpace, m_readPL);
856 std::unordered_map<int, int> curvePtOffset;
859 for (
int i = 0, cnt = 0, cnt2 = 0; i < curveInfo.size() / 3; ++i, cnt += 3)
864 curve->m_points.resize(curveInfo[cnt]);
866 const int ptOffset = curveInfo[cnt + 2];
868 for (
int j = 0; j < curveInfo[cnt]; ++j)
872 curveSel.push_back(ptOffset + j);
873 curveSel.push_back(0);
874 curveSel.push_back(ptOffset + j);
875 curveSel.push_back(1);
876 curveSel.push_back(ptOffset + j);
877 curveSel.push_back(2);
882 curvePtOffset[newIds[i]] = 3 * cnt2;
883 cnt2 += curveInfo[cnt];
885 curveMap[newIds[i]] = curve;
894 nodeSpace->ClearRange();
895 nodeSpace->SetSelection(curveSel.size() / 2, curveSel);
897 vector<NekDouble> nodeRawData;
898 nodeData->Read(nodeRawData, nodeSpace, m_readPL);
901 for (
auto &cIt : curvePtOffset)
906 int cnt = cIt.second;
907 for (
int i = 0; i < curve->m_points.size(); ++i, cnt += 3)
910 0, m_spaceDimension, nodeRawData[cnt], nodeRawData[cnt+1],
916 void MeshGraphHDF5::ReadDomain()
918 map<int, CompositeSharedPtr> fullDomain;
923 dst->ReadVectorString(data, space, m_readPL);
924 GetCompositeList(data[0], fullDomain);
925 m_domain.push_back(fullDomain);
928 void MeshGraphHDF5::ReadComposites()
930 string nm =
"COMPOSITE";
934 vector<hsize_t> dims = space->GetDims();
936 vector<string> comps;
937 data->ReadVectorString(comps, space);
941 vector<hsize_t> mdims = mspace->GetDims();
944 mdata->Read(ids, mspace);
946 for(
int i = 0; i < dims[0]; i++)
948 string compStr = comps[i];
951 istringstream strm(compStr);
958 string::size_type indxBeg = compStr.find_first_of(
'[') + 1;
959 string::size_type indxEnd = compStr.find_last_of(
']') - 1;
961 string indxStr = compStr.substr(indxBeg, indxEnd - indxBeg + 1);
962 vector<unsigned int> seqVector;
964 ParseUtils::GenerateSeqVector(indxStr, seqVector);
965 m_compOrder[ids[i]] = seqVector;
970 for (
auto &i : seqVector)
972 auto it = m_vertSet.find(i);
973 if (it != m_vertSet.end())
975 comp->m_geomVec.push_back(it->second);
981 for (
auto &i : seqVector)
983 auto it = m_segGeoms.find(i);
984 if (it != m_segGeoms.end())
986 comp->m_geomVec.push_back(it->second);
991 for (
auto &i : seqVector)
993 auto it = m_quadGeoms.find(i);
994 if (it != m_quadGeoms.end())
996 comp->m_geomVec.push_back(it->second);
1001 for (
auto &i : seqVector)
1003 auto it = m_triGeoms.find(i);
1004 if (it != m_triGeoms.end())
1006 comp->m_geomVec.push_back(it->second);
1011 for(
auto &i : seqVector)
1013 auto it1 = m_quadGeoms.find(i);
1014 if (it1 != m_quadGeoms.end())
1016 comp->m_geomVec.push_back(it1->second);
1019 auto it2 = m_triGeoms.find(i);
1020 if (it2 != m_triGeoms.end())
1022 comp->m_geomVec.push_back(it2->second);
1027 for(
auto &i : seqVector)
1029 auto it = m_tetGeoms.find(i);
1030 if (it != m_tetGeoms.end())
1032 comp->m_geomVec.push_back(it->second);
1037 for(
auto &i : seqVector)
1039 auto it = m_pyrGeoms.find(i);
1040 if (it != m_pyrGeoms.end())
1042 comp->m_geomVec.push_back(it->second);
1047 for(
auto &i : seqVector)
1049 auto it = m_prismGeoms.find(i);
1050 if (it != m_prismGeoms.end())
1052 comp->m_geomVec.push_back(it->second);
1057 for(
auto &i : seqVector)
1059 auto it = m_hexGeoms.find(i);
1060 if (it != m_hexGeoms.end())
1062 comp->m_geomVec.push_back(it->second);
1068 if (comp->m_geomVec.size() > 0)
1070 m_meshComposites[ids[i]] = comp;
1076 std::unordered_map<int, int> &id2row)
1080 string nm =
"COMPOSITE";
1084 vector<hsize_t> dims = space->GetDims();
1086 vector<string> comps;
1087 data->ReadVectorString(comps, space);
1091 vector<hsize_t> mdims = mspace->GetDims();
1094 mdata->Read(ids, mspace);
1096 for (
int i = 0; i < dims[0]; i++)
1098 string compStr = comps[i];
1101 istringstream strm(compStr);
1105 string::size_type indxBeg = compStr.find_first_of(
'[') + 1;
1106 string::size_type indxEnd = compStr.find_last_of(
']') - 1;
1108 string indxStr = compStr.substr(indxBeg, indxEnd - indxBeg + 1);
1109 vector<unsigned int> seqVector;
1110 ParseUtils::GenerateSeqVector(indxStr, seqVector);
1147 std::vector<int> filteredVector;
1148 for (
auto &compElmt : seqVector)
1150 if (id2row.find(compElmt) == id2row.end())
1155 filteredVector.push_back(compElmt);
1158 if (filteredVector.size() == 0)
1163 ret[ids[i]] = std::make_pair(shapeType, filteredVector);
1170 template<class T, typename std::enable_if<T::kDim == 0, int>::type = 0>
1176 template<class T, typename std::enable_if<T::kDim == 1, int>::type = 0>
1179 return geom->GetVid(i);
1182 template<class T, typename std::enable_if<T::kDim == 2, int>::type = 0>
1183 inline int GetGeomData(std::shared_ptr<T> &geom,
int i)
1185 return geom->GetEid(i);
1188 template<class T, typename std::enable_if<T::kDim == 3, int>::type = 0>
1189 inline int GetGeomData(std::shared_ptr<T> &geom,
int i)
1191 return geom->GetFid(i);
1195 void MeshGraphHDF5::WriteGeometryMap(std::map<
int, std::shared_ptr<T>> &geomMap,
1196 std::string datasetName)
1198 typedef typename std::conditional<
1199 std::is_same<T, PointGeom>::value,
NekDouble,
int>::type DataType;
1202 const size_t nGeom = geomMap.size();
1210 vector<int> idMap(nGeom);
1211 vector<DataType> data(nGeom * nGeomData);
1213 int cnt1 = 0, cnt2 = 0;
1214 for (
auto &it : geomMap)
1216 idMap[cnt1++] = it.first;
1218 for (
int j = 0; j < nGeomData; ++j)
1226 vector<hsize_t> dims = {
static_cast<hsize_t
>(nGeom),
1227 static_cast<hsize_t
>(nGeomData) };
1232 dst->Write(data, ds);
1234 tp = H5::DataType::OfObject(idMap[0]);
1236 ds = std::shared_ptr<H5::DataSpace>(
new H5::DataSpace(dims));
1237 dst = m_maps->CreateDataSet(datasetName, tp, ds);
1238 dst->Write(idMap, ds);
1247 vector<int> data, map;
1250 for (
auto &c : curves)
1252 map.push_back(c.first);
1253 data.push_back(c.second->m_points.size());
1254 data.push_back(c.second->m_ptype);
1255 data.push_back(ptOffset);
1257 ptOffset += c.second->m_points.size();
1259 for (
auto &pt : c.second->m_points)
1263 pt->GetCoords(v.
x, v.
y, v.
z);
1264 curvedPts.
pts.push_back(v);
1265 curvedPts.
index.push_back(newIdx++);
1270 vector<hsize_t> dims = { data.size() / 3, 3 };
1275 dst->Write(data, ds);
1277 tp = H5::DataType::OfObject(map[0]);
1278 dims = { map.size() };
1279 ds = std::shared_ptr<H5::DataSpace>(
new H5::DataSpace(dims));
1280 dst = m_maps->CreateDataSet(dsName, tp, ds);
1281 dst->Write(map, ds);
1286 vector<double> vertData(curvedPts.
pts.size() * 3);
1289 for (
auto &pt : curvedPts.
pts)
1291 vertData[cnt++] = pt.x;
1292 vertData[cnt++] = pt.y;
1293 vertData[cnt++] = pt.z;
1296 vector<hsize_t> dims = { curvedPts.
pts.size(), 3 };
1301 dst->Write(vertData, ds);
1306 vector<string> comps;
1313 for (
auto &cIt : composites)
1315 if (cIt.second->m_geomVec.size() == 0)
1320 comps.push_back(GetCompositeString(cIt.second));
1321 c_map.push_back(cIt.first);
1327 dst->WriteVectorString(comps, ds, tp);
1329 tp = H5::DataType::OfObject(c_map[0]);
1330 ds = H5::DataSpace::OneD(c_map.size());
1331 dst = m_maps->CreateDataSet(
"COMPOSITE", tp, ds);
1332 dst->Write(c_map, ds);
1335 void MeshGraphHDF5::WriteDomain(vector<CompositeMap> &domain)
1337 vector<unsigned int> idxList;
1338 for (
auto cIt = domain[0].begin(); cIt != domain[0].end(); ++cIt)
1340 idxList.push_back(cIt->first);
1342 stringstream domString;
1343 vector<string> doms;
1344 doms.push_back(ParseUtils::GenerateSeqString(idxList));
1349 dst->WriteVectorString(doms, ds, tp);
1352 void MeshGraphHDF5::WriteGeometry(
1353 std::string &outfilename,
1357 boost::ignore_unused(metadata);
1360 boost::split(tmp, outfilename, boost::is_any_of(
"."));
1361 string filenameXml = tmp[0] +
".xml";
1362 string filenameHdf5 = tmp[0] +
".nekg";
1371 TiXmlDocument *doc =
new TiXmlDocument;
1373 TiXmlElement *geomTag;
1375 if(boost::filesystem::exists(filenameXml.c_str()))
1377 ifstream file(filenameXml.c_str());
1379 TiXmlHandle docHandle(doc);
1380 root = docHandle.FirstChildElement(
"NEKTAR").Element();
1381 ASSERTL0(root,
"Unable to find NEKTAR tag in file.");
1382 geomTag = root->FirstChildElement(
"GEOMETRY");
1387 TiXmlDeclaration *decl =
new TiXmlDeclaration(
"1.0",
"utf-8",
"");
1388 doc->LinkEndChild(decl);
1389 root =
new TiXmlElement(
"NEKTAR");
1390 doc->LinkEndChild(root);
1392 geomTag =
new TiXmlElement(
"GEOMETRY");
1393 root->LinkEndChild(geomTag);
1397 geomTag->SetAttribute(
"DIM", m_meshDimension);
1398 geomTag->SetAttribute(
"SPACE", m_spaceDimension);
1399 geomTag->SetAttribute(
"HDF5FILE", filenameHdf5);
1405 TiXmlElement *expTag =
new TiXmlElement(
"EXPANSIONS");
1407 for (
auto it = m_meshComposites.begin(); it != m_meshComposites.end();
1410 if (it->second->m_geomVec[0]->GetShapeDim() == m_meshDimension)
1412 TiXmlElement *exp =
new TiXmlElement(
"E");
1415 "C[" + boost::lexical_cast<string>(it->first) +
"]");
1416 exp->SetAttribute(
"NUMMODES", 4);
1417 exp->SetAttribute(
"TYPE",
"MODIFIED");
1418 exp->SetAttribute(
"FIELDS",
"u");
1420 expTag->LinkEndChild(exp);
1423 root->LinkEndChild(expTag);
1426 doc->SaveFile(filenameXml);
1433 m_file = H5::File::Create(filenameHdf5, H5F_ACC_TRUNC);
1434 auto hdfRoot = m_file->CreateGroup(
"NEKTAR");
1435 auto hdfRoot2 = hdfRoot->CreateGroup(
"GEOMETRY");
1438 hdfRoot2->SetAttribute(
"FORMAT_VERSION", FORMAT_VERSION);
1441 m_mesh = hdfRoot2->CreateGroup(
"MESH");
1442 m_maps = hdfRoot2->CreateGroup(
"MAPS");
1444 WriteGeometryMap(m_vertSet,
"VERT");
1445 WriteGeometryMap(m_segGeoms,
"SEG");
1446 if (m_meshDimension > 1)
1448 WriteGeometryMap(m_triGeoms,
"TRI");
1449 WriteGeometryMap(m_quadGeoms,
"QUAD");
1451 if (m_meshDimension > 2)
1453 WriteGeometryMap(m_tetGeoms,
"TET");
1454 WriteGeometryMap(m_pyrGeoms,
"PYR");
1455 WriteGeometryMap(m_prismGeoms,
"PRISM");
1456 WriteGeometryMap(m_hexGeoms,
"HEX");
1460 int ptOffset = 0, newIdx = 0;
1462 WriteCurveMap(m_curvedEdges,
"CURVE_EDGE", curvePts, ptOffset, newIdx);
1463 WriteCurveMap(m_curvedFaces,
"CURVE_FACE", curvePts, ptOffset, newIdx);
1464 WriteCurvePoints(curvePts);
1467 WriteComposites(m_meshComposites);
1468 WriteDomain(m_domain);
#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.
General purpose memory allocation routines with the ability to allocate from thread specific memory p...
std::shared_ptr< DataSpace > DataSpaceSharedPtr
std::shared_ptr< PList > PListSharedPtr
std::shared_ptr< DataType > DataTypeSharedPtr
std::shared_ptr< DataSet > DataSetSharedPtr
std::map< std::string, std::string > FieldMetaDataMap
std::shared_ptr< SessionReader > SessionReaderSharedPtr
std::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
std::shared_ptr< QuadGeom > QuadGeomSharedPtr
void UniqueValues(std::unordered_set< int > &unique, const std::vector< int > &input, T &... args)
std::map< int, std::pair< LibUtilities::ShapeType, std::vector< int > > > CompositeDescriptor
int GetGeomDataDim(std::map< int, std::shared_ptr< T >> &geomMap)
MeshPartitionFactory & GetMeshPartitionFactory()
std::shared_ptr< DomainRange > DomainRangeShPtr
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< Curve > CurveSharedPtr
std::unordered_map< int, CurveSharedPtr > CurveMap
std::map< int, CompositeSharedPtr > CompositeMap
int GetGeomData(std::shared_ptr< T > &geom, int i)
std::shared_ptr< SegGeom > SegGeomSharedPtr
std::shared_ptr< PointGeom > PointGeomSharedPtr
std::shared_ptr< Geometry2D > Geometry2DSharedPtr
std::shared_ptr< MeshPartition > MeshPartitionSharedPtr
std::shared_ptr< TriGeom > TriGeomSharedPtr
MeshGraphFactory & GetMeshGraphFactory()
std::shared_ptr< Composite > CompositeSharedPtr
std::vector< MeshVertex > pts
mapping to access pts value.
std::vector< NekInt64 > index
id of this Point set
std::vector< unsigned int > list