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

 MeshGraphIO ()=default
 
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...
 
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()

Nektar::SpatialDomains::MeshGraphIO::MeshGraphIO ( )
default

◆ ~MeshGraphIO()

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

Member Function Documentation

◆ CreateCompositeDescriptor()

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

Definition at line 229 of file MeshGraphIO.cpp.

230{
231 auto meshComposites = &m_meshGraph->GetComposites();
233
234 for (auto &comp : *meshComposites)
235 {
236 std::pair<LibUtilities::ShapeType, vector<int>> tmp;
237 tmp.first = comp.second->m_geomVec[0]->GetShapeType();
238
239 tmp.second.resize(comp.second->m_geomVec.size());
240 for (size_t i = 0; i < tmp.second.size(); ++i)
241 {
242 tmp.second[i] = comp.second->m_geomVec[i]->GetGlobalID();
243 }
244
245 ret[comp.first] = tmp;
246 }
247
248 return ret;
249}
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 129 of file MeshGraphIO.cpp.

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

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 254 of file MeshGraphIO.cpp.

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

82 {
83 v_PartitionMesh(session);
84 }
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 53 of file MeshGraphIO.cpp.

57{
58 LibUtilities::CommSharedPtr comm = session->GetComm();
59 ASSERTL0(comm.get(), "Communication not initialised.");
60
61 // Populate SessionReader. This should be done only on the root process so
62 // that we can partition appropriately without all processes having to read
63 // in the input file.
64 const bool isRoot = comm->TreatAsRankZero();
65 std::string geomType;
66
67 if (isRoot)
68 {
69 // Parse the XML document.
70 session->InitSession();
71
72 // Get geometry type, i.e. XML (compressed/uncompressed) or HDF5.
73 geomType = session->GetGeometryType();
74
75 // Convert to a vector of chars so that we can broadcast.
76 std::vector<char> v(geomType.c_str(),
77 geomType.c_str() + geomType.length());
78
79 size_t length = v.size();
80 comm->Bcast(length, 0);
81 comm->Bcast(v, 0);
82 }
83 else
84 {
85 size_t length;
86 comm->Bcast(length, 0);
87
88 std::vector<char> v(length);
89 comm->Bcast(v, 0);
90
91 geomType = std::string(v.begin(), v.end());
92 }
93
94 // Every process then creates a mesh. Partitioning logic takes place inside
95 // the PartitionMesh function so that we can support different options for
96 // XML and HDF5.
99 meshIO->m_meshGraph =
101 meshIO->m_meshGraph->SetSession(session);
102
103 // For Parallel-in-Time
104 // In contrast to XML, a pre-partitioned mesh directory (_xml) is not
105 // produced when partitionning the mesh for the fine solver when using
106 // HDF5. In order to guarantee the same partition on all time level,
107 // the fine mesh partition has to be copied explicitly.
108 if (partitionedGraph && geomType == "HDF5")
109 {
110 meshIO->m_meshGraph->SetPartition(partitionedGraph);
111 meshIO->m_meshPartitioned = true;
112 }
113
114 meshIO->PartitionMesh(session);
115
116 // Finally, read the geometry information.
117 meshIO->ReadGeometry(rng, fillGraph);
118
119 return meshIO->m_meshGraph;
120}
#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:47

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 74 of file MeshGraphIO.h.

76 {
77 v_ReadGeometry(rng, fillGraph);
78 }
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 60 of file MeshGraphIO.h.

61 {
62 m_meshGraph = meshGraph;
63 }

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 65 of file MeshGraphIO.h.

69 {
70 v_WriteGeometry(outfilename, defaultExp, metadata);
71 }
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 91 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