Nektar++
Loading...
Searching...
No Matches
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 (bool fillGraph)
 
void PartitionMesh (LibUtilities::SessionReaderSharedPtr session)
 
std::map< int, MeshEntityCreateMeshEntities ()
 Create mesh entities for this graph.
 
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.
 
 MeshGraphIO ()=default
 
virtual void v_WriteGeometry (const std::string &outfilename, bool defaultExp=false, const LibUtilities::FieldMetaDataMap &metadata=LibUtilities::NullFieldMetaDataMap)=0
 
virtual void v_ReadGeometry (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 248 of file MeshGraphIO.cpp.

249{
250 auto meshComposites = &m_meshGraph->GetComposites();
252
253 for (auto &comp : *meshComposites)
254 {
255 std::pair<LibUtilities::ShapeType, std::vector<int>> tmp;
256 tmp.first = comp.second->m_geomVec[0]->GetShapeType();
257
258 tmp.second.resize(comp.second->m_geomVec.size());
259 for (size_t i = 0; i < tmp.second.size(); ++i)
260 {
261 tmp.second[i] = comp.second->m_geomVec[i]->GetGlobalID();
262 }
263
264 ret[comp.first] = tmp;
265 }
266
267 return ret;
268}
std::map< int, std::pair< LibUtilities::ShapeType, std::vector< int > > > CompositeDescriptor
Definition MeshGraph.h:124

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

131{
132 std::map<int, MeshEntity> elements;
133 switch (m_meshGraph->GetMeshDimension())
134 {
135 case 1:
136 {
137 for (auto [id, geom] : m_meshGraph->GetGeomMap<SegGeom>())
138 {
139 MeshEntity e;
140 e.id = e.origId = id;
141 e.list.push_back(geom->GetVertex(0)->GetGlobalID());
142 e.list.push_back(geom->GetVertex(1)->GetGlobalID());
143 e.ghost = false;
144 elements[e.id] = e;
145 }
146 }
147 break;
148 case 2:
149 {
150 for (auto [id, geom] : m_meshGraph->GetGeomMap<TriGeom>())
151 {
152 if (m_meshGraph->CheckRange(*geom))
153 {
154 MeshEntity e;
155 e.id = e.origId = id;
156 e.list.push_back(geom->GetEdge(0)->GetGlobalID());
157 e.list.push_back(geom->GetEdge(1)->GetGlobalID());
158 e.list.push_back(geom->GetEdge(2)->GetGlobalID());
159 e.ghost = false;
160 elements[e.id] = e;
161 }
162 }
163 for (auto [id, geom] : m_meshGraph->GetGeomMap<QuadGeom>())
164 {
165 if (m_meshGraph->CheckRange(*geom))
166 {
167 MeshEntity e;
168 e.id = e.origId = id;
169 e.list.push_back(geom->GetEdge(0)->GetGlobalID());
170 e.list.push_back(geom->GetEdge(1)->GetGlobalID());
171 e.list.push_back(geom->GetEdge(2)->GetGlobalID());
172 e.list.push_back(geom->GetEdge(3)->GetGlobalID());
173 e.ghost = false;
174 elements[e.id] = e;
175 }
176 }
177 }
178 break;
179 case 3:
180 {
181 for (auto [id, geom] : m_meshGraph->GetGeomMap<TetGeom>())
182 {
183 if (m_meshGraph->CheckRange(*geom))
184 {
185 MeshEntity e;
186 e.id = e.origId = id;
187 e.list.push_back(geom->GetFace(0)->GetGlobalID());
188 e.list.push_back(geom->GetFace(1)->GetGlobalID());
189 e.list.push_back(geom->GetFace(2)->GetGlobalID());
190 e.list.push_back(geom->GetFace(3)->GetGlobalID());
191 e.ghost = false;
192 elements[e.id] = e;
193 }
194 }
195 for (auto [id, geom] : m_meshGraph->GetGeomMap<PyrGeom>())
196 {
197 if (m_meshGraph->CheckRange(*geom))
198 {
199 MeshEntity e;
200 e.id = e.origId = id;
201 e.list.push_back(geom->GetFace(0)->GetGlobalID());
202 e.list.push_back(geom->GetFace(1)->GetGlobalID());
203 e.list.push_back(geom->GetFace(2)->GetGlobalID());
204 e.list.push_back(geom->GetFace(3)->GetGlobalID());
205 e.list.push_back(geom->GetFace(4)->GetGlobalID());
206 e.ghost = false;
207 elements[e.id] = e;
208 }
209 }
210 for (auto [id, geom] : m_meshGraph->GetGeomMap<PrismGeom>())
211 {
212 if (m_meshGraph->CheckRange(*geom))
213 {
214 MeshEntity e;
215 e.id = e.origId = id;
216 e.list.push_back(geom->GetFace(0)->GetGlobalID());
217 e.list.push_back(geom->GetFace(1)->GetGlobalID());
218 e.list.push_back(geom->GetFace(2)->GetGlobalID());
219 e.list.push_back(geom->GetFace(3)->GetGlobalID());
220 e.list.push_back(geom->GetFace(4)->GetGlobalID());
221 e.ghost = false;
222 elements[e.id] = e;
223 }
224 }
225 for (auto [id, geom] : m_meshGraph->GetGeomMap<HexGeom>())
226 {
227 if (m_meshGraph->CheckRange(*geom))
228 {
229 MeshEntity e;
230 e.id = e.origId = id;
231 e.list.push_back(geom->GetFace(0)->GetGlobalID());
232 e.list.push_back(geom->GetFace(1)->GetGlobalID());
233 e.list.push_back(geom->GetFace(2)->GetGlobalID());
234 e.list.push_back(geom->GetFace(3)->GetGlobalID());
235 e.list.push_back(geom->GetFace(4)->GetGlobalID());
236 e.list.push_back(geom->GetFace(5)->GetGlobalID());
237 e.ghost = false;
238 elements[e.id] = e;
239 }
240 }
241 }
242 break;
243 }
244
245 return elements;
246}

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

274{
275 if (comp->m_geomVec.size() == 0)
276 {
277 return "";
278 }
279
280 // Create a map that gets around the issue of mapping faces -> F and edges
281 // -> E inside the tag.
282 std::map<LibUtilities::ShapeType, std::pair<std::string, std::string>>
283 compMap;
284 compMap[LibUtilities::ePoint] = std::make_pair("V", "V");
285 compMap[LibUtilities::eSegment] = std::make_pair("S", "E");
286 compMap[LibUtilities::eQuadrilateral] = std::make_pair("Q", "F");
287 compMap[LibUtilities::eTriangle] = std::make_pair("T", "F");
288 compMap[LibUtilities::eTetrahedron] = std::make_pair("A", "A");
289 compMap[LibUtilities::ePyramid] = std::make_pair("P", "P");
290 compMap[LibUtilities::ePrism] = std::make_pair("R", "R");
291 compMap[LibUtilities::eHexahedron] = std::make_pair("H", "H");
292
293 std::stringstream s;
294
295 Geometry *firstGeom = comp->m_geomVec[0];
296 int shapeDim = firstGeom->GetShapeDim();
297 std::string tag = (shapeDim < m_meshGraph->GetMeshDimension())
298 ? compMap[firstGeom->GetShapeType()].second
299 : compMap[firstGeom->GetShapeType()].first;
300
301 std::vector<unsigned int> idxList;
302 std::transform(comp->m_geomVec.begin(), comp->m_geomVec.end(),
303 std::back_inserter(idxList),
304 [](Geometry *geom) { return geom->GetGlobalID(); });
305
306 s << " " << tag << "[" << ParseUtils::GenerateSeqString(idxList) << "] ";
307 return s.str();
308}
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

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(), Nektar::SpatialDomains::Geometry::GetShapeDim(), Nektar::SpatialDomains::Geometry::GetShapeType(), 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 78 of file MeshGraphIO.h.

80 {
81 v_PartitionMesh(session);
82 }
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 // set up domain range info before partitioning
113 meshIO->m_meshGraph->SetDomainRange(rng);
114
115 meshIO->PartitionMesh(session);
116
117 // Finally, read the geometry information.
118 meshIO->ReadGeometry(fillGraph);
119
120 return meshIO->m_meshGraph;
121}
#define ASSERTL0(condition, msg)
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()

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

Referenced by Diffusion::Diffusion(), main(), MeshGraphIO_Read(), 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 ( bool  fillGraph)
inline

Definition at line 73 of file MeshGraphIO.h.

74 {
75 v_ReadGeometry(fillGraph);
76 }
virtual void v_ReadGeometry(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.

Referenced by export_MeshGraphIO().

◆ v_PartitionMesh()

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

◆ v_ReadGeometry()

virtual void Nektar::SpatialDomains::MeshGraphIO::v_ReadGeometry ( 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().

Referenced by export_MeshGraphIO().

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

Referenced by Nektar::SpatialDomains::MeshGraphIOHDF5::ConstructGeomObject(), Nektar::SpatialDomains::MeshGraphIOHDF5::ConstructGeomObject(), Nektar::SpatialDomains::MeshGraphIOHDF5::ConstructGeomObject(), Nektar::SpatialDomains::MeshGraphIOHDF5::ConstructGeomObject(), Nektar::SpatialDomains::MeshGraphIOHDF5::ConstructGeomObject(), Nektar::SpatialDomains::MeshGraphIOHDF5::ConstructGeomObject(), Nektar::SpatialDomains::MeshGraphIOHDF5::ConstructGeomObject(), 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::v_WriteHexs(), Nektar::SpatialDomains::MeshGraphIOXmlCompressed::v_WriteHexs(), Nektar::SpatialDomains::MeshGraphIOXml::v_WritePrisms(), Nektar::SpatialDomains::MeshGraphIOXmlCompressed::v_WritePrisms(), Nektar::SpatialDomains::MeshGraphIOXml::v_WritePyrs(), Nektar::SpatialDomains::MeshGraphIOXmlCompressed::v_WritePyrs(), Nektar::SpatialDomains::MeshGraphIOXml::v_WriteQuads(), Nektar::SpatialDomains::MeshGraphIOXmlCompressed::v_WriteQuads(), Nektar::SpatialDomains::MeshGraphIOXml::v_WriteTets(), Nektar::SpatialDomains::MeshGraphIOXmlCompressed::v_WriteTets(), Nektar::SpatialDomains::MeshGraphIOXml::v_WriteTris(), Nektar::SpatialDomains::MeshGraphIOXmlCompressed::v_WriteTris(), Nektar::SpatialDomains::MeshGraphIOXml::v_WriteVertices(), Nektar::SpatialDomains::MeshGraphIOXmlCompressed::v_WriteVertices(), 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