10
10
#include < concepts>
11
11
#include < cstdint>
12
12
#include < iterator>
13
+ #include < stdexcept>
13
14
#include < vector>
14
15
16
+ #include < basix/element-families.h>
17
+
15
18
#include " dolfinx/common/IndexMap.h"
16
19
#include " dolfinx/fem/FunctionSpace.h"
17
20
#include " dolfinx/la/SparsityPattern.h"
18
21
#include " dolfinx/la/utils.h"
19
22
#include " dolfinx/mesh/Mesh.h"
20
23
21
- namespace dolfinx ::transfer
24
+ namespace dolfinx ::multigrid
22
25
{
23
26
24
27
template <std::floating_point T>
@@ -79,8 +82,7 @@ inclusion_mapping(const dolfinx::mesh::Mesh<T>& mesh_from,
79
82
// other processes.
80
83
std::vector<std::int64_t > result (map.size (), -1 );
81
84
MPI_Allreduce (map.data (), result.data (), map.size (),
82
- dolfinx::MPI::mpi_type<std::int64_t >(), MPI_MAX,
83
- mesh_from.comm ());
85
+ dolfinx::MPI::mpi_t <std::int64_t >, MPI_MAX, mesh_from.comm ());
84
86
85
87
assert (std::ranges::all_of (result, [](auto e) { return e >= 0 ; }));
86
88
return result;
@@ -92,7 +94,18 @@ create_sparsity_pattern(const dolfinx::fem::FunctionSpace<T>& V_from,
92
94
const dolfinx::fem::FunctionSpace<T>& V_to,
93
95
const std::vector<std::int64_t >& inclusion_map)
94
96
{
95
- // TODO: P1 and which elements supported?
97
+ if (*V_from.element () != *V_to.element ())
98
+ throw std::runtime_error (
99
+ " Transfer between different element types not supported" );
100
+
101
+ if (V_from.element ()->basix_element ().family () != basix::element::family::P)
102
+ throw std::runtime_error (" Only Lagrange elements supported" );
103
+
104
+ if (V_from.element ()->basix_element ().degree () != 1 )
105
+ throw std::runtime_error (" Only piecewise linear elements supported" );
106
+
107
+ // TODO: mixed elements? value shapes? DG?
108
+
96
109
auto mesh_from = V_from.mesh ();
97
110
auto mesh_to = V_to.mesh ();
98
111
assert (mesh_from);
@@ -167,11 +180,21 @@ void assemble_transfer_matrix(la::MatSet<T> auto mat_set,
167
180
const std::vector<std::int64_t >& inclusion_map,
168
181
std::function<T(std::int32_t )> weight)
169
182
{
170
- // TODO: P1 and which elements supported?
183
+ if (*V_from.element () != *V_to.element ())
184
+ throw std::runtime_error (
185
+ " Transfer between different element types not supported" );
186
+
187
+ if (V_from.element ()->basix_element ().family () != basix::element::family::P)
188
+ throw std::runtime_error (" Only Lagrange elements supported" );
189
+
190
+ if (V_from.element ()->basix_element ().degree () != 1 )
191
+ throw std::runtime_error (" Only piecewise linear elements supported" );
192
+
193
+ // TODO: mixed elements? value shapes? DG?
194
+
171
195
auto mesh_from = V_from.mesh ();
172
196
auto mesh_to = V_to.mesh ();
173
197
assert (mesh_from);
174
- assert (mesh_to);
175
198
176
199
MPI_Comm comm = mesh_from->comm ();
177
200
{
@@ -227,7 +250,7 @@ void assemble_transfer_matrix(la::MatSet<T> auto mat_set,
227
250
// asserted.
228
251
std::int32_t distance = (n == local_dof_to) ? 0 : 1 ;
229
252
mat_set (std::vector<int32_t >{dof_from_v[0 ]}, std::vector<int32_t >{n},
230
- std::vector<double >{weight (distance)});
253
+ std::vector<T >{weight (distance)});
231
254
}
232
255
}
233
256
}
0 commit comments