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);
564 template<
class T,
typename DataType>
void MeshGraphHDF5::ConstructGeomObject(
565 std::map<
int, std::shared_ptr<T>> &geomMap,
int id,
568 boost::ignore_unused(geomMap,
id, data, curve);
571 template<>
void MeshGraphHDF5::ConstructGeomObject(
572 std::map<
int, std::shared_ptr<PointGeom>> &geomMap,
int id,
575 boost::ignore_unused(curve);
577 m_spaceDimension,
id, data[0], data[1], data[2]);
580 template<>
void MeshGraphHDF5::ConstructGeomObject(
581 std::map<
int, std::shared_ptr<SegGeom>> &geomMap,
int id,
int *data,
586 id, m_spaceDimension, pts, curve);
589 template<>
void MeshGraphHDF5::ConstructGeomObject(
590 std::map<
int, std::shared_ptr<TriGeom>> &geomMap,
int id,
int *data,
594 GetSegGeom(data[0]), GetSegGeom(data[1]), GetSegGeom(data[2]) };
598 template<>
void MeshGraphHDF5::ConstructGeomObject(
599 std::map<
int, std::shared_ptr<QuadGeom>> &geomMap,
int id,
int *data,
603 GetSegGeom(data[0]), GetSegGeom(data[1]), GetSegGeom(data[2]),
609 template<>
void MeshGraphHDF5::ConstructGeomObject(
610 std::map<
int, std::shared_ptr<TetGeom>> &geomMap,
int id,
int *data,
613 boost::ignore_unused(curve);
615 std::static_pointer_cast<
TriGeom>(GetGeometry2D(data[0])),
616 std::static_pointer_cast<TriGeom>(GetGeometry2D(data[1])),
617 std::static_pointer_cast<TriGeom>(GetGeometry2D(data[2])),
618 std::static_pointer_cast<TriGeom>(GetGeometry2D(data[3]))
622 PopulateFaceToElMap(tetGeom, TetGeom::kNfaces);
623 geomMap[id] = tetGeom;
626 template<>
void MeshGraphHDF5::ConstructGeomObject(
627 std::map<
int, std::shared_ptr<PyrGeom>> &geomMap,
int id,
int *data,
630 boost::ignore_unused(curve);
632 GetGeometry2D(data[0]), GetGeometry2D(data[1]), GetGeometry2D(data[2]),
633 GetGeometry2D(data[3]), GetGeometry2D(data[4])
637 PopulateFaceToElMap(pyrGeom, PyrGeom::kNfaces);
638 geomMap[id] = pyrGeom;
641 template<>
void MeshGraphHDF5::ConstructGeomObject(
642 std::map<
int, std::shared_ptr<PrismGeom>> &geomMap,
int id,
int *data,
645 boost::ignore_unused(curve);
647 GetGeometry2D(data[0]), GetGeometry2D(data[1]), GetGeometry2D(data[2]),
648 GetGeometry2D(data[3]), GetGeometry2D(data[4])
652 PopulateFaceToElMap(prismGeom, PrismGeom::kNfaces);
653 geomMap[id] = prismGeom;
656 template<>
void MeshGraphHDF5::ConstructGeomObject(
657 std::map<
int, std::shared_ptr<HexGeom>> &geomMap,
int id,
int *data,
660 boost::ignore_unused(curve);
662 std::static_pointer_cast<
QuadGeom>(GetGeometry2D(data[0])),
663 std::static_pointer_cast<QuadGeom>(GetGeometry2D(data[1])),
664 std::static_pointer_cast<QuadGeom>(GetGeometry2D(data[2])),
665 std::static_pointer_cast<QuadGeom>(GetGeometry2D(data[3])),
666 std::static_pointer_cast<QuadGeom>(GetGeometry2D(data[4])),
667 std::static_pointer_cast<QuadGeom>(GetGeometry2D(data[5]))
671 PopulateFaceToElMap(hexGeom, HexGeom::kNfaces);
672 geomMap[id] = hexGeom;
675 template<
class T,
typename DataType>
676 void MeshGraphHDF5::FillGeomMap(
677 std::map<
int, std::shared_ptr<T>> &geomMap,
679 std::vector<int> &ids,
680 std::vector<DataType> &geomData)
683 const int nRows = geomData.size() / nGeomData;
687 if (curveMap.size() > 0)
689 for(
int i = 0, cnt = 0; i < nRows; i++, cnt += nGeomData)
691 auto cIt = curveMap.find(ids[i]);
693 geomMap, ids[i], &geomData[cnt],
694 cIt == curveMap.end() ? empty : cIt->second);
699 for(
int i = 0, cnt = 0; i < nRows; i++, cnt += nGeomData)
701 ConstructGeomObject(geomMap, ids[i], &geomData[cnt], empty);
706 template<
class T,
typename DataType>
707 void MeshGraphHDF5::ReadGeometryData(
708 std::map<
int, std::shared_ptr<T>> &geomMap,
710 const std::unordered_set<int> &readIds,
711 std::vector<int> &ids,
712 std::vector<DataType> &geomData)
714 if (!m_mesh->ContainsDataSet(dataSet))
722 vector<hsize_t> dims = space->GetDims();
727 vector<hsize_t> mdims = mspace->GetDims();
729 ASSERTL0(mdims[0] == dims[0],
"map and data set lengths do not match");
735 mdata->Read(allIds, mspace);
742 std::vector<hsize_t> coords;
743 for (
auto &
id : allIds)
745 if (readIds.find(
id) != readIds.end())
747 for (
int j = 0; j < nGeomData; ++j)
757 space->SetSelection(coords.size() / 2, coords);
760 data->Read(geomData, space, m_readPL);
763 void MeshGraphHDF5::ReadCurveMap(
766 const std::unordered_set<int> &readIds)
769 if (!m_mesh->ContainsDataSet(dsName))
783 vector<int> ids, newIds;
784 idData->Read(ids, idSpace);
785 curveSpace->ClearRange();
788 vector<hsize_t> curveSel;
793 if (readIds.find(
id) != readIds.end())
795 curveSel.push_back(cnt);
796 curveSel.push_back(0);
797 curveSel.push_back(cnt);
798 curveSel.push_back(1);
799 curveSel.push_back(cnt);
800 curveSel.push_back(2);
801 newIds.push_back(
id);
808 auto toRead = newIds.size();
817 vector<int> curveInfo;
818 curveSpace->SetSelection(curveSel.size() / 2, curveSel);
819 curveData->Read(curveInfo, curveSpace, m_readPL);
823 std::unordered_map<int, int> curvePtOffset;
826 for (
int i = 0, cnt = 0, cnt2 = 0; i < curveInfo.size() / 3; ++i, cnt += 3)
831 curve->m_points.resize(curveInfo[cnt]);
833 const int ptOffset = curveInfo[cnt + 2];
835 for (
int j = 0; j < curveInfo[cnt]; ++j)
839 curveSel.push_back(ptOffset + j);
840 curveSel.push_back(0);
841 curveSel.push_back(ptOffset + j);
842 curveSel.push_back(1);
843 curveSel.push_back(ptOffset + j);
844 curveSel.push_back(2);
849 curvePtOffset[newIds[i]] = 3 * cnt2;
850 cnt2 += curveInfo[cnt];
852 curveMap[newIds[i]] = curve;
861 nodeSpace->ClearRange();
862 nodeSpace->SetSelection(curveSel.size() / 2, curveSel);
864 vector<NekDouble> nodeRawData;
865 nodeData->Read(nodeRawData, nodeSpace, m_readPL);
868 for (
auto &cIt : curvePtOffset)
873 int cnt = cIt.second;
874 for (
int i = 0; i < curve->m_points.size(); ++i, cnt += 3)
877 0, m_spaceDimension, nodeRawData[cnt], nodeRawData[cnt+1],
883 void MeshGraphHDF5::ReadDomain()
885 map<int, CompositeSharedPtr> fullDomain;
890 dst->ReadVectorString(data, space, m_readPL);
891 GetCompositeList(data[0], fullDomain);
892 m_domain.push_back(fullDomain);
895 void MeshGraphHDF5::ReadComposites()
897 string nm =
"COMPOSITE";
901 vector<hsize_t> dims = space->GetDims();
903 vector<string> comps;
904 data->ReadVectorString(comps, space);
908 vector<hsize_t> mdims = mspace->GetDims();
911 mdata->Read(ids, mspace);
913 for(
int i = 0; i < dims[0]; i++)
915 string compStr = comps[i];
918 istringstream strm(compStr);
925 string::size_type indxBeg = compStr.find_first_of(
'[') + 1;
926 string::size_type indxEnd = compStr.find_last_of(
']') - 1;
928 string indxStr = compStr.substr(indxBeg, indxEnd - indxBeg + 1);
929 vector<unsigned int> seqVector;
931 ParseUtils::GenerateSeqVector(indxStr, seqVector);
936 for (
auto &i : seqVector)
938 auto it = m_vertSet.find(i);
939 if (it != m_vertSet.end())
941 comp->m_geomVec.push_back(it->second);
947 for (
auto &i : seqVector)
949 auto it = m_segGeoms.find(i);
950 if (it != m_segGeoms.end())
952 comp->m_geomVec.push_back(it->second);
957 for (
auto &i : seqVector)
959 auto it = m_quadGeoms.find(i);
960 if (it != m_quadGeoms.end())
962 comp->m_geomVec.push_back(it->second);
967 for (
auto &i : seqVector)
969 auto it = m_triGeoms.find(i);
970 if (it != m_triGeoms.end())
972 comp->m_geomVec.push_back(it->second);
977 for(
auto &i : seqVector)
979 auto it1 = m_quadGeoms.find(i);
980 if (it1 != m_quadGeoms.end())
982 comp->m_geomVec.push_back(it1->second);
985 auto it2 = m_triGeoms.find(i);
986 if (it2 != m_triGeoms.end())
988 comp->m_geomVec.push_back(it2->second);
993 for(
auto &i : seqVector)
995 auto it = m_tetGeoms.find(i);
996 if (it != m_tetGeoms.end())
998 comp->m_geomVec.push_back(it->second);
1003 for(
auto &i : seqVector)
1005 auto it = m_pyrGeoms.find(i);
1006 if (it != m_pyrGeoms.end())
1008 comp->m_geomVec.push_back(it->second);
1013 for(
auto &i : seqVector)
1015 auto it = m_prismGeoms.find(i);
1016 if (it != m_prismGeoms.end())
1018 comp->m_geomVec.push_back(it->second);
1023 for(
auto &i : seqVector)
1025 auto it = m_hexGeoms.find(i);
1026 if (it != m_hexGeoms.end())
1028 comp->m_geomVec.push_back(it->second);
1034 if (comp->m_geomVec.size() > 0)
1036 m_meshComposites[ids[i]] = comp;
1042 std::unordered_map<int, int> &id2row)
1046 string nm =
"COMPOSITE";
1050 vector<hsize_t> dims = space->GetDims();
1052 vector<string> comps;
1053 data->ReadVectorString(comps, space);
1057 vector<hsize_t> mdims = mspace->GetDims();
1060 mdata->Read(ids, mspace);
1062 for (
int i = 0; i < dims[0]; i++)
1064 string compStr = comps[i];
1067 istringstream strm(compStr);
1071 string::size_type indxBeg = compStr.find_first_of(
'[') + 1;
1072 string::size_type indxEnd = compStr.find_last_of(
']') - 1;
1074 string indxStr = compStr.substr(indxBeg, indxEnd - indxBeg + 1);
1075 vector<unsigned int> seqVector;
1076 ParseUtils::GenerateSeqVector(indxStr, seqVector);
1113 std::vector<int> filteredVector;
1114 for (
auto &compElmt : seqVector)
1116 if (id2row.find(compElmt) == id2row.end())
1121 filteredVector.push_back(compElmt);
1124 if (filteredVector.size() == 0)
1129 ret[ids[i]] = std::make_pair(shapeType, filteredVector);
1136 template<class T, typename std::enable_if<T::kDim == 0, int>::type = 0>
1142 template<class T, typename std::enable_if<T::kDim == 1, int>::type = 0>
1145 return geom->GetVid(i);
1148 template<class T, typename std::enable_if<T::kDim == 2, int>::type = 0>
1149 inline int GetGeomData(std::shared_ptr<T> &geom,
int i)
1151 return geom->GetEid(i);
1154 template<class T, typename std::enable_if<T::kDim == 3, int>::type = 0>
1155 inline int GetGeomData(std::shared_ptr<T> &geom,
int i)
1157 return geom->GetFid(i);
1161 void MeshGraphHDF5::WriteGeometryMap(std::map<
int, std::shared_ptr<T>> &geomMap,
1162 std::string datasetName)
1164 typedef typename std::conditional<
1165 std::is_same<T, PointGeom>::value,
NekDouble,
int>::type DataType;
1168 const size_t nGeom = geomMap.size();
1176 vector<int> idMap(nGeom);
1177 vector<DataType> data(nGeom * nGeomData);
1179 int cnt1 = 0, cnt2 = 0;
1180 for (
auto &it : geomMap)
1182 idMap[cnt1++] = it.first;
1184 for (
int j = 0; j < nGeomData; ++j)
1192 vector<hsize_t> dims = {
static_cast<hsize_t
>(nGeom),
1193 static_cast<hsize_t>(nGeomData) };
1198 dst->Write(data, ds);
1200 tp = H5::DataType::OfObject(idMap[0]);
1202 ds = std::shared_ptr<H5::DataSpace>(
new H5::DataSpace(dims));
1203 dst = m_maps->CreateDataSet(datasetName, tp, ds);
1204 dst->Write(idMap, ds);
1213 vector<int> data, map;
1216 for (
auto &c : curves)
1218 map.push_back(c.first);
1219 data.push_back(c.second->m_points.size());
1220 data.push_back(c.second->m_ptype);
1221 data.push_back(ptOffset);
1223 ptOffset += c.second->m_points.size();
1225 for (
auto &pt : c.second->m_points)
1229 pt->GetCoords(v.
x, v.
y, v.
z);
1230 curvedPts.
pts.push_back(v);
1231 curvedPts.
index.push_back(newIdx++);
1236 vector<hsize_t> dims = { data.size() / 3, 3 };
1241 dst->Write(data, ds);
1243 tp = H5::DataType::OfObject(map[0]);
1244 dims = { map.size() };
1245 ds = std::shared_ptr<H5::DataSpace>(
new H5::DataSpace(dims));
1246 dst = m_maps->CreateDataSet(dsName, tp, ds);
1247 dst->Write(map, ds);
1252 vector<double> vertData(curvedPts.
pts.size() * 3);
1255 for (
auto &pt : curvedPts.
pts)
1257 vertData[cnt++] = pt.x;
1258 vertData[cnt++] = pt.y;
1259 vertData[cnt++] = pt.z;
1262 vector<hsize_t> dims = { curvedPts.
pts.size(), 3 };
1267 dst->Write(vertData, ds);
1272 vector<string> comps;
1279 for (
auto &cIt : composites)
1281 if (cIt.second->m_geomVec.size() == 0)
1286 comps.push_back(GetCompositeString(cIt.second));
1287 c_map.push_back(cIt.first);
1293 dst->WriteVectorString(comps, ds, tp);
1295 tp = H5::DataType::OfObject(c_map[0]);
1296 ds = H5::DataSpace::OneD(c_map.size());
1297 dst = m_maps->CreateDataSet(
"COMPOSITE", tp, ds);
1298 dst->Write(c_map, ds);
1301 void MeshGraphHDF5::WriteDomain(vector<CompositeMap> &domain)
1303 vector<unsigned int> idxList;
1304 for (
auto cIt = domain[0].begin(); cIt != domain[0].end(); ++cIt)
1306 idxList.push_back(cIt->first);
1308 stringstream domString;
1309 vector<string> doms;
1310 doms.push_back(ParseUtils::GenerateSeqString(idxList));
1315 dst->WriteVectorString(doms, ds, tp);
1318 void MeshGraphHDF5::WriteGeometry(
1319 std::string &outfilename,
1323 boost::ignore_unused(metadata);
1326 boost::split(tmp, outfilename, boost::is_any_of(
"."));
1327 string filenameXml = tmp[0] +
".xml";
1328 string filenameHdf5 = tmp[0] +
".nekg";
1337 TiXmlDocument *doc =
new TiXmlDocument;
1339 TiXmlElement *geomTag;
1341 if(boost::filesystem::exists(filenameXml.c_str()))
1343 ifstream file(filenameXml.c_str());
1345 TiXmlHandle docHandle(doc);
1346 root = docHandle.FirstChildElement(
"NEKTAR").Element();
1347 ASSERTL0(root,
"Unable to find NEKTAR tag in file.");
1348 geomTag = root->FirstChildElement(
"GEOMETRY");
1353 TiXmlDeclaration *decl =
new TiXmlDeclaration(
"1.0",
"utf-8",
"");
1354 doc->LinkEndChild(decl);
1355 root =
new TiXmlElement(
"NEKTAR");
1356 doc->LinkEndChild(root);
1358 geomTag =
new TiXmlElement(
"GEOMETRY");
1359 root->LinkEndChild(geomTag);
1363 geomTag->SetAttribute(
"DIM", m_meshDimension);
1364 geomTag->SetAttribute(
"SPACE", m_spaceDimension);
1365 geomTag->SetAttribute(
"HDF5FILE", filenameHdf5);
1371 TiXmlElement *expTag =
new TiXmlElement(
"EXPANSIONS");
1373 for (
auto it = m_meshComposites.begin(); it != m_meshComposites.end();
1376 if (it->second->m_geomVec[0]->GetShapeDim() == m_meshDimension)
1378 TiXmlElement *exp =
new TiXmlElement(
"E");
1381 "C[" + boost::lexical_cast<string>(it->first) +
"]");
1382 exp->SetAttribute(
"NUMMODES", 4);
1383 exp->SetAttribute(
"TYPE",
"MODIFIED");
1384 exp->SetAttribute(
"FIELDS",
"u");
1386 expTag->LinkEndChild(exp);
1389 root->LinkEndChild(expTag);
1392 doc->SaveFile(filenameXml);
1399 m_file = H5::File::Create(filenameHdf5, H5F_ACC_TRUNC);
1400 auto hdfRoot = m_file->CreateGroup(
"NEKTAR");
1401 auto hdfRoot2 = hdfRoot->CreateGroup(
"GEOMETRY");
1404 hdfRoot2->SetAttribute(
"FORMAT_VERSION", FORMAT_VERSION);
1407 m_mesh = hdfRoot2->CreateGroup(
"MESH");
1408 m_maps = hdfRoot2->CreateGroup(
"MAPS");
1410 WriteGeometryMap(m_vertSet,
"VERT");
1411 WriteGeometryMap(m_segGeoms,
"SEG");
1412 if (m_meshDimension > 1)
1414 WriteGeometryMap(m_triGeoms,
"TRI");
1415 WriteGeometryMap(m_quadGeoms,
"QUAD");
1417 if (m_meshDimension > 2)
1419 WriteGeometryMap(m_tetGeoms,
"TET");
1420 WriteGeometryMap(m_pyrGeoms,
"PYR");
1421 WriteGeometryMap(m_prismGeoms,
"PRISM");
1422 WriteGeometryMap(m_hexGeoms,
"HEX");
1426 int ptOffset = 0, newIdx = 0;
1428 WriteCurveMap(m_curvedEdges,
"CURVE_EDGE", curvePts, ptOffset, newIdx);
1429 WriteCurveMap(m_curvedFaces,
"CURVE_FACE", curvePts, ptOffset, newIdx);
1430 WriteCurvePoints(curvePts);
1433 WriteComposites(m_meshComposites);
1434 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)