Nektar++
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Nektar::SpatialDomains::MeshGraphIO Class Referenceabstract

#include <MeshGraphIO.h>

Inheritance diagram for Nektar::SpatialDomains::MeshGraphIO:
[legend]

Public Member Functions

virtual ~MeshGraphIO ()=default
 
void SetMeshGraph (MeshGraphSharedPtr &meshGraph)
 
void WriteGeometry (const std::string &outfilename, bool defaultExp=false, const LibUtilities::FieldMetaDataMap &metadata=LibUtilities::NullFieldMetaDataMap)
 
void ReadGeometry (LibUtilities::DomainRangeShPtr rng, bool fillGraph)
 
void PartitionMesh (LibUtilities::SessionReaderSharedPtr session)
 
std::map< int, MeshEntityCreateMeshEntities ()
 Create mesh entities for this graph. More...
 
CompositeDescriptor CreateCompositeDescriptor ()
 

Static Public Member Functions

static MeshGraphSharedPtr Read (const LibUtilities::SessionReaderSharedPtr pSession, LibUtilities::DomainRangeShPtr rng=LibUtilities::NullDomainRangeShPtr, bool fillGraph=true, SpatialDomains::MeshGraphSharedPtr partitionedGraph=nullptr)
 

Protected Member Functions

std::string GetCompositeString (CompositeSharedPtr comp)
 Returns a string representation of a composite. More...
 
 MeshGraphIO ()=default
 
virtual void v_WriteGeometry (const std::string &outfilename, bool defaultExp=false, const LibUtilities::FieldMetaDataMap &metadata=LibUtilities::NullFieldMetaDataMap)=0
 
virtual void v_ReadGeometry (LibUtilities::DomainRangeShPtr rng, bool fillGraph)=0
 
virtual void v_PartitionMesh (LibUtilities::SessionReaderSharedPtr session)=0
 

Protected Attributes

LibUtilities::SessionReaderSharedPtr m_session
 
MeshGraphSharedPtr m_meshGraph
 
int m_partition
 
bool m_meshPartitioned = false
 
CompositeOrdering m_compOrder
 
BndRegionOrdering m_bndRegOrder
 

Detailed Description

Definition at line 48 of file MeshGraphIO.h.

Constructor & Destructor Documentation

◆ ~MeshGraphIO()

virtual Nektar::SpatialDomains::MeshGraphIO::~MeshGraphIO ( )
virtualdefault

◆ MeshGraphIO()

Nektar::SpatialDomains::MeshGraphIO::MeshGraphIO ( )
protecteddefault

Member Function Documentation

◆ CreateCompositeDescriptor()

CompositeDescriptor Nektar::SpatialDomains::MeshGraphIO::CreateCompositeDescriptor ( )

Definition at line 227 of file MeshGraphIO.cpp.

228{
229 auto meshComposites = &m_meshGraph->GetComposites();
231
232 for (auto &comp : *meshComposites)
233 {
234 std::pair<LibUtilities::ShapeType, std::vector<int>> tmp;
235 tmp.first = comp.second->m_geomVec[0]->GetShapeType();
236
237 tmp.second.resize(comp.second->m_geomVec.size());
238 for (size_t i = 0; i < tmp.second.size(); ++i)
239 {
240 tmp.second[i] = comp.second->m_geomVec[i]->GetGlobalID();
241 }
242
243 ret[comp.first] = tmp;
244 }
245
246 return ret;
247}
std::map< int, std::pair< LibUtilities::ShapeType, std::vector< int > > > CompositeDescriptor
Definition: MeshGraph.h:61

References m_meshGraph.

Referenced by Nektar::SpatialDomains::MeshGraphIOHDF5::v_PartitionMesh(), and Nektar::SpatialDomains::MeshGraphIOXml::v_PartitionMesh().

◆ CreateMeshEntities()

std::map< int, MeshEntity > Nektar::SpatialDomains::MeshGraphIO::CreateMeshEntities ( )

Create mesh entities for this graph.

This function will create a map of all mesh entities of the current graph, which can then be used within the mesh partitioner to construct an appropriate partitioning.

Definition at line 127 of file MeshGraphIO.cpp.

128{
129 std::map<int, MeshEntity> elements;
130 switch (m_meshGraph->GetMeshDimension())
131 {
132 case 1:
133 {
134 for (auto &i : m_meshGraph->GetAllSegGeoms())
135 {
136 MeshEntity e;
137 e.id = e.origId = i.first;
138 e.list.push_back(i.second->GetVertex(0)->GetGlobalID());
139 e.list.push_back(i.second->GetVertex(1)->GetGlobalID());
140 e.ghost = false;
141 elements[e.id] = e;
142 }
143 }
144 break;
145 case 2:
146 {
147 for (auto &i : m_meshGraph->GetAllTriGeoms())
148 {
149 MeshEntity e;
150 e.id = e.origId = i.first;
151 e.list.push_back(i.second->GetEdge(0)->GetGlobalID());
152 e.list.push_back(i.second->GetEdge(1)->GetGlobalID());
153 e.list.push_back(i.second->GetEdge(2)->GetGlobalID());
154 e.ghost = false;
155 elements[e.id] = e;
156 }
157 for (auto &i : m_meshGraph->GetAllQuadGeoms())
158 {
159 MeshEntity e;
160 e.id = e.origId = i.first;
161 e.list.push_back(i.second->GetEdge(0)->GetGlobalID());
162 e.list.push_back(i.second->GetEdge(1)->GetGlobalID());
163 e.list.push_back(i.second->GetEdge(2)->GetGlobalID());
164 e.list.push_back(i.second->GetEdge(3)->GetGlobalID());
165 e.ghost = false;
166 elements[e.id] = e;
167 }
168 }
169 break;
170 case 3:
171 {
172 for (auto &i : m_meshGraph->GetAllTetGeoms())
173 {
174 MeshEntity e;
175 e.id = e.origId = i.first;
176 e.list.push_back(i.second->GetFace(0)->GetGlobalID());
177 e.list.push_back(i.second->GetFace(1)->GetGlobalID());
178 e.list.push_back(i.second->GetFace(2)->GetGlobalID());
179 e.list.push_back(i.second->GetFace(3)->GetGlobalID());
180 e.ghost = false;
181 elements[e.id] = e;
182 }
183 for (auto &i : m_meshGraph->GetAllPyrGeoms())
184 {
185 MeshEntity e;
186 e.id = e.origId = i.first;
187 e.list.push_back(i.second->GetFace(0)->GetGlobalID());
188 e.list.push_back(i.second->GetFace(1)->GetGlobalID());
189 e.list.push_back(i.second->GetFace(2)->GetGlobalID());
190 e.list.push_back(i.second->GetFace(3)->GetGlobalID());
191 e.list.push_back(i.second->GetFace(4)->GetGlobalID());
192 e.ghost = false;
193 elements[e.id] = e;
194 }
195 for (auto &i : m_meshGraph->GetAllPrismGeoms())
196 {
197 MeshEntity e;
198 e.id = e.origId = i.first;
199 e.list.push_back(i.second->GetFace(0)->GetGlobalID());
200 e.list.push_back(i.second->GetFace(1)->GetGlobalID());
201 e.list.push_back(i.second->GetFace(2)->GetGlobalID());
202 e.list.push_back(i.second->GetFace(3)->GetGlobalID());
203 e.list.push_back(i.second->GetFace(4)->GetGlobalID());
204 e.ghost = false;
205 elements[e.id] = e;
206 }
207 for (auto &i : m_meshGraph->GetAllHexGeoms())
208 {
209 MeshEntity e;
210 e.id = e.origId = i.first;
211 e.list.push_back(i.second->GetFace(0)->GetGlobalID());
212 e.list.push_back(i.second->GetFace(1)->GetGlobalID());
213 e.list.push_back(i.second->GetFace(2)->GetGlobalID());
214 e.list.push_back(i.second->GetFace(3)->GetGlobalID());
215 e.list.push_back(i.second->GetFace(4)->GetGlobalID());
216 e.list.push_back(i.second->GetFace(5)->GetGlobalID());
217 e.ghost = false;
218 elements[e.id] = e;
219 }
220 }
221 break;
222 }
223
224 return elements;
225}

References Nektar::SpatialDomains::MeshEntity::ghost, Nektar::SpatialDomains::MeshEntity::id, Nektar::SpatialDomains::MeshEntity::list, m_meshGraph, and Nektar::SpatialDomains::MeshEntity::origId.

Referenced by Nektar::SpatialDomains::MeshGraphIOXml::v_PartitionMesh().

◆ GetCompositeString()

std::string Nektar::SpatialDomains::MeshGraphIO::GetCompositeString ( CompositeSharedPtr  comp)
protected

Returns a string representation of a composite.

Definition at line 252 of file MeshGraphIO.cpp.

253{
254 if (comp->m_geomVec.size() == 0)
255 {
256 return "";
257 }
258
259 // Create a map that gets around the issue of mapping faces -> F and edges
260 // -> E inside the tag.
261 std::map<LibUtilities::ShapeType, std::pair<std::string, std::string>>
262 compMap;
263 compMap[LibUtilities::ePoint] = std::make_pair("V", "V");
264 compMap[LibUtilities::eSegment] = std::make_pair("S", "E");
265 compMap[LibUtilities::eQuadrilateral] = std::make_pair("Q", "F");
266 compMap[LibUtilities::eTriangle] = std::make_pair("T", "F");
267 compMap[LibUtilities::eTetrahedron] = std::make_pair("A", "A");
268 compMap[LibUtilities::ePyramid] = std::make_pair("P", "P");
269 compMap[LibUtilities::ePrism] = std::make_pair("R", "R");
270 compMap[LibUtilities::eHexahedron] = std::make_pair("H", "H");
271
272 std::stringstream s;
273
274 GeometrySharedPtr firstGeom = comp->m_geomVec[0];
275 int shapeDim = firstGeom->GetShapeDim();
276 std::string tag = (shapeDim < m_meshGraph->GetMeshDimension())
277 ? compMap[firstGeom->GetShapeType()].second
278 : compMap[firstGeom->GetShapeType()].first;
279
280 std::vector<unsigned int> idxList;
281 std::transform(comp->m_geomVec.begin(), comp->m_geomVec.end(),
282 std::back_inserter(idxList),
283 [](GeometrySharedPtr geom) { return geom->GetGlobalID(); });
284
285 s << " " << tag << "[" << ParseUtils::GenerateSeqString(idxList) << "] ";
286 return s.str();
287}
static std::string GenerateSeqString(const std::vector< T > &v)
Generate a compressed comma-separated string representation of a vector of unsigned integers.
Definition: ParseUtils.h:72
std::shared_ptr< Geometry > GeometrySharedPtr
Definition: Geometry.h:51

References Nektar::LibUtilities::eHexahedron, Nektar::LibUtilities::ePoint, Nektar::LibUtilities::ePrism, Nektar::LibUtilities::ePyramid, Nektar::LibUtilities::eQuadrilateral, Nektar::LibUtilities::eSegment, Nektar::LibUtilities::eTetrahedron, Nektar::LibUtilities::eTriangle, Nektar::ParseUtils::GenerateSeqString(), and m_meshGraph.

Referenced by Nektar::SpatialDomains::MeshGraphIOHDF5::WriteComposites(), and Nektar::SpatialDomains::MeshGraphIOXml::WriteComposites().

◆ PartitionMesh()

void Nektar::SpatialDomains::MeshGraphIO::PartitionMesh ( LibUtilities::SessionReaderSharedPtr  session)
inline

Definition at line 79 of file MeshGraphIO.h.

81 {
82 v_PartitionMesh(session);
83 }
virtual void v_PartitionMesh(LibUtilities::SessionReaderSharedPtr session)=0

References v_PartitionMesh().

◆ Read()

MeshGraphSharedPtr Nektar::SpatialDomains::MeshGraphIO::Read ( const LibUtilities::SessionReaderSharedPtr  pSession,
LibUtilities::DomainRangeShPtr  rng = LibUtilities::NullDomainRangeShPtr,
bool  fillGraph = true,
SpatialDomains::MeshGraphSharedPtr  partitionedGraph = nullptr 
)
static

Definition at line 51 of file MeshGraphIO.cpp.

55{
56 LibUtilities::CommSharedPtr comm = session->GetComm();
57 ASSERTL0(comm.get(), "Communication not initialised.");
58
59 // Populate SessionReader. This should be done only on the root process so
60 // that we can partition appropriately without all processes having to read
61 // in the input file.
62 const bool isRoot = comm->TreatAsRankZero();
63 std::string geomType;
64
65 if (isRoot)
66 {
67 // Parse the XML document.
68 session->InitSession();
69
70 // Get geometry type, i.e. XML (compressed/uncompressed) or HDF5.
71 geomType = session->GetGeometryType();
72
73 // Convert to a vector of chars so that we can broadcast.
74 std::vector<char> v(geomType.c_str(),
75 geomType.c_str() + geomType.length());
76
77 size_t length = v.size();
78 comm->Bcast(length, 0);
79 comm->Bcast(v, 0);
80 }
81 else
82 {
83 size_t length;
84 comm->Bcast(length, 0);
85
86 std::vector<char> v(length);
87 comm->Bcast(v, 0);
88
89 geomType = std::string(v.begin(), v.end());
90 }
91
92 // Every process then creates a mesh. Partitioning logic takes place inside
93 // the PartitionMesh function so that we can support different options for
94 // XML and HDF5.
97 meshIO->m_meshGraph =
99 meshIO->m_meshGraph->SetSession(session);
100
101 // For Parallel-in-Time
102 // In contrast to XML, a pre-partitioned mesh directory (_xml) is not
103 // produced when partitionning the mesh for the fine solver when using
104 // HDF5. In order to guarantee the same partition on all time level,
105 // the fine mesh partition has to be copied explicitly.
106 if (partitionedGraph && geomType == "HDF5")
107 {
108 meshIO->m_meshGraph->SetPartition(partitionedGraph);
109 meshIO->m_meshPartitioned = true;
110 }
111
112 meshIO->PartitionMesh(session);
113
114 // Finally, read the geometry information.
115 meshIO->ReadGeometry(rng, fillGraph);
116
117 return meshIO->m_meshGraph;
118}
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:208
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
std::shared_ptr< Comm > CommSharedPtr
Pointer to a Communicator object.
Definition: Comm.h:55
std::shared_ptr< MeshGraphIO > MeshGraphIOSharedPtr
Definition: MeshGraphIO.h:46
MeshGraphIOFactory & GetMeshGraphIOFactory()
Definition: MeshGraphIO.cpp:45

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), ASSERTL0, Nektar::LibUtilities::NekFactory< tKey, tBase, tParam >::CreateInstance(), and Nektar::SpatialDomains::GetMeshGraphIOFactory().

Referenced by Diffusion::Diffusion(), Nektar::SolverUtils::DriverParallelInTime::SetParallelInTimeEquationSystem(), Nektar::VarcoeffHashingTest::setupContFieldSolve(), Nektar::SolverUtils::CouplingCwipi::SetupReceive(), Nektar::SolverUtils::Driver::v_InitObject(), Nektar::FieldUtils::InputXml::v_Process(), Nektar::FieldUtils::ProcessDisplacement::v_Process(), Nektar::FieldUtils::ProcessInterpField::v_Process(), Nektar::FieldUtils::ProcessInterpPoints::v_Process(), Nektar::SolverUtils::FilterModalEnergy::v_Update(), and Nektar::VortexWaveInteraction::VortexWaveInteraction().

◆ ReadGeometry()

void Nektar::SpatialDomains::MeshGraphIO::ReadGeometry ( LibUtilities::DomainRangeShPtr  rng,
bool  fillGraph 
)
inline

Definition at line 73 of file MeshGraphIO.h.

75 {
76 v_ReadGeometry(rng, fillGraph);
77 }
virtual void v_ReadGeometry(LibUtilities::DomainRangeShPtr rng, bool fillGraph)=0

References v_ReadGeometry().

Referenced by Nektar::SpatialDomains::MeshGraphIOXml::v_PartitionMesh().

◆ SetMeshGraph()

void Nektar::SpatialDomains::MeshGraphIO::SetMeshGraph ( MeshGraphSharedPtr meshGraph)
inline

Definition at line 59 of file MeshGraphIO.h.

60 {
61 m_meshGraph = meshGraph;
62 }

References m_meshGraph.

◆ v_PartitionMesh()

virtual void Nektar::SpatialDomains::MeshGraphIO::v_PartitionMesh ( LibUtilities::SessionReaderSharedPtr  session)
protectedpure virtual

◆ v_ReadGeometry()

virtual void Nektar::SpatialDomains::MeshGraphIO::v_ReadGeometry ( LibUtilities::DomainRangeShPtr  rng,
bool  fillGraph 
)
protectedpure virtual

◆ v_WriteGeometry()

virtual void Nektar::SpatialDomains::MeshGraphIO::v_WriteGeometry ( const std::string &  outfilename,
bool  defaultExp = false,
const LibUtilities::FieldMetaDataMap metadata = LibUtilities::NullFieldMetaDataMap 
)
protectedpure virtual

◆ WriteGeometry()

void Nektar::SpatialDomains::MeshGraphIO::WriteGeometry ( const std::string &  outfilename,
bool  defaultExp = false,
const LibUtilities::FieldMetaDataMap metadata = LibUtilities::NullFieldMetaDataMap 
)
inline

Definition at line 64 of file MeshGraphIO.h.

68 {
69 v_WriteGeometry(outfilename, defaultExp, metadata);
70 }
virtual void v_WriteGeometry(const std::string &outfilename, bool defaultExp=false, const LibUtilities::FieldMetaDataMap &metadata=LibUtilities::NullFieldMetaDataMap)=0

References v_WriteGeometry().

Member Data Documentation

◆ m_bndRegOrder

BndRegionOrdering Nektar::SpatialDomains::MeshGraphIO::m_bndRegOrder
protected

◆ m_compOrder

CompositeOrdering Nektar::SpatialDomains::MeshGraphIO::m_compOrder
protected

◆ m_meshGraph

MeshGraphSharedPtr Nektar::SpatialDomains::MeshGraphIO::m_meshGraph
protected

Definition at line 90 of file MeshGraphIO.h.

Referenced by Nektar::SpatialDomains::MeshGraphIOHDF5::ConstructGeomObject(), CreateCompositeDescriptor(), Nektar::SpatialDomains::MeshGraphIOXml::CreateCompositeOrdering(), CreateMeshEntities(), GetCompositeString(), Nektar::SpatialDomains::MeshGraphIOHDF5::ReadComposites(), Nektar::SpatialDomains::MeshGraphIOXml::ReadComposites(), Nektar::SpatialDomains::MeshGraphIOHDF5::ReadCurveMap(), Nektar::SpatialDomains::MeshGraphIOHDF5::ReadDomain(), Nektar::SpatialDomains::MeshGraphIOXml::ReadDomain(), Nektar::SpatialDomains::MeshGraphIOXml::ReadElements(), Nektar::SpatialDomains::MeshGraphIOXml::ResolveGeomRef(), Nektar::SpatialDomains::MeshGraphIOXml::ResolveGeomRef1D(), Nektar::SpatialDomains::MeshGraphIOXml::ResolveGeomRef2D(), Nektar::SpatialDomains::MeshGraphIOXml::ResolveGeomRef3D(), SetMeshGraph(), Nektar::SpatialDomains::MeshGraphIOHDF5::v_PartitionMesh(), Nektar::SpatialDomains::MeshGraphIOXml::v_PartitionMesh(), Nektar::SpatialDomains::MeshGraphIOXml::v_ReadCurves(), Nektar::SpatialDomains::MeshGraphIOXmlCompressed::v_ReadCurves(), Nektar::SpatialDomains::MeshGraphIOXml::v_ReadEdges(), Nektar::SpatialDomains::MeshGraphIOXmlCompressed::v_ReadEdges(), Nektar::SpatialDomains::MeshGraphIOXml::v_ReadElements1D(), Nektar::SpatialDomains::MeshGraphIOXmlCompressed::v_ReadElements1D(), Nektar::SpatialDomains::MeshGraphIOXml::v_ReadElements2D(), Nektar::SpatialDomains::MeshGraphIOXmlCompressed::v_ReadElements2D(), Nektar::SpatialDomains::MeshGraphIOXml::v_ReadElements3D(), Nektar::SpatialDomains::MeshGraphIOXmlCompressed::v_ReadElements3D(), Nektar::SpatialDomains::MeshGraphIOXml::v_ReadFaces(), Nektar::SpatialDomains::MeshGraphIOXmlCompressed::v_ReadFaces(), Nektar::SpatialDomains::MeshGraphIOHDF5::v_ReadGeometry(), Nektar::SpatialDomains::MeshGraphIOXml::v_ReadGeometry(), Nektar::SpatialDomains::MeshGraphIOXml::v_ReadVertices(), Nektar::SpatialDomains::MeshGraphIOXmlCompressed::v_ReadVertices(), Nektar::SpatialDomains::MeshGraphIOXml::v_WriteEdges(), Nektar::SpatialDomains::MeshGraphIOXmlCompressed::v_WriteEdges(), Nektar::SpatialDomains::MeshGraphIOHDF5::v_WriteGeometry(), Nektar::SpatialDomains::MeshGraphIOXml::v_WriteGeometry(), Nektar::SpatialDomains::MeshGraphIOXml::WriteComposites(), Nektar::SpatialDomains::MeshGraphIOXml::WriteDefaultExpansion(), and Nektar::SpatialDomains::MeshGraphIOXml::WriteXMLGeometry().

◆ m_meshPartitioned

bool Nektar::SpatialDomains::MeshGraphIO::m_meshPartitioned = false
protected

◆ m_partition

int Nektar::SpatialDomains::MeshGraphIO::m_partition
protected

◆ m_session

LibUtilities::SessionReaderSharedPtr Nektar::SpatialDomains::MeshGraphIO::m_session
protected