GridFormat
0.6.0
I/O-Library for grid-like data structures
Toggle main menu visibility
Loading...
Searching...
No Matches
mfem.hpp
Go to the documentation of this file.
1
// SPDX-FileCopyrightText: 2022-2023 Dennis Gläser <dennis.glaeser@iws.uni-stuttgart.de>
2
// SPDX-License-Identifier: MIT
9
#ifndef GRIDFORMAT_TRAITS_MFEM_HPP_
10
#define GRIDFORMAT_TRAITS_MFEM_HPP_
11
12
#include <cassert>
13
#include <ranges>
14
#include <vector>
15
#include <array>
16
#include <type_traits>
17
18
#include <mfem/mesh/mesh.hpp>
19
20
#include <gridformat/common/exceptions.hpp>
21
22
#include <gridformat/grid/cell_type.hpp>
23
#include <gridformat/grid/traits.hpp>
24
25
namespace
GridFormat::MFEM {
26
27
#ifndef DOXYGEN
28
namespace
Detail {
29
CellType cell_type(mfem::Element::Type ct) {
30
switch
(ct) {
31
case
mfem::Element::Type::POINT:
return
GridFormat::CellType::vertex;
32
case
mfem::Element::Type::SEGMENT:
return
GridFormat::CellType::segment;
33
case
mfem::Element::Type::TRIANGLE:
return
GridFormat::CellType::triangle;
34
case
mfem::Element::Type::QUADRILATERAL:
return
GridFormat::CellType::quadrilateral;
35
case
mfem::Element::Type::TETRAHEDRON:
return
GridFormat::CellType::tetrahedron;
36
case
mfem::Element::Type::WEDGE:
break
;
37
case
mfem::Element::Type::PYRAMID:
break
;
38
case
mfem::Element::Type::HEXAHEDRON:
return
GridFormat::CellType::hexahedron;
39
}
40
throw
NotImplemented(
"Support for given mfem cell type"
);
41
}
42
}
// namespace Detail
43
#endif
// DOXYGEN
44
45
using
Point = int;
46
using
Cell = int;
47
48
}
// namespace GridFormat::MFEM
49
50
// Specializations of the traits required for the `UnstructuredGrid` concept for mfem::Mesh
51
namespace
GridFormat::Traits {
52
53
template
<>
54
struct
Points<mfem::Mesh> {
55
static
std::ranges::range
auto
get(
const
mfem::Mesh& mesh) {
56
return
std::views::iota(0, mesh.GetNV());
57
}
58
};
59
60
template
<>
61
struct
Cells<mfem::Mesh> {
62
static
std::ranges::range
auto
get(
const
mfem::Mesh& mesh) {
63
return
std::views::iota(0, mesh.GetNE());
64
}
65
};
66
67
template
<>
68
struct
CellType<mfem::Mesh, GridFormat::MFEM::Cell> {
69
static
GridFormat::CellType get(
const
mfem::Mesh& mesh,
const
GridFormat::MFEM::Cell& cell) {
70
return
GridFormat::MFEM::Detail::cell_type(mesh.GetElement(cell)->GetType());
71
}
72
};
73
74
template
<>
75
struct
CellPoints<mfem::Mesh, GridFormat::MFEM::Cell> {
76
static
std::ranges::range
decltype
(
auto
) get(
const
mfem::Mesh& mesh,
const
GridFormat::MFEM::Cell& cell) {
77
const
auto
element = mesh.GetElement(cell);
78
auto
begin = element->GetVertices();
79
return
std::ranges::subrange(begin, begin + element->GetNVertices());
80
}
81
};
82
83
template
<>
84
struct
PointId<mfem::Mesh, GridFormat::MFEM::Point> {
85
static
auto
get(
const
mfem::Mesh&,
const
GridFormat::MFEM::Point& point) {
86
return
point;
87
}
88
};
89
90
template
<>
91
struct
PointCoordinates<mfem::Mesh, GridFormat::MFEM::Point> {
92
static
std::ranges::range
decltype
(
auto
) get(
const
mfem::Mesh& mesh,
const
GridFormat::MFEM::Point& point) {
93
std::array<double, 3> coords = {};
94
auto
begin = mesh.GetVertex(point);
95
std::copy(begin, begin + mesh.SpaceDimension(), coords.begin());
96
return
coords;
97
}
98
};
99
100
template
<>
101
struct
NumberOfPoints<mfem::Mesh> {
102
static
std::integral
auto
get(
const
mfem::Mesh& mesh) {
103
return
mesh.GetNV();
104
}
105
};
106
107
template
<>
108
struct
NumberOfCells<mfem::Mesh> {
109
static
std::integral
auto
get(
const
mfem::Mesh& mesh) {
110
return
mesh.GetNE();
111
}
112
};
113
114
template
<>
115
struct
NumberOfCellPoints<mfem::Mesh, GridFormat::MFEM::Cell> {
116
static
std::integral
auto
get(
const
mfem::Mesh& mesh,
const
GridFormat::MFEM::Cell& cell) {
117
return
mesh.GetElement(cell)->GetNVertices();
118
}
119
};
120
121
}
// namespace GridFormat::Traits
122
123
#endif
// GRIDFORMAT_TRAITS_MFEM_HPP_
gridformat
traits
mfem.hpp
Generated by
1.18.0