1010#include < concepts>
1111#include < cstdint>
1212#include < iterator>
13+ #include < stdexcept>
1314#include < vector>
1415
16+ #include < basix/element-families.h>
17+
1518#include " dolfinx/common/IndexMap.h"
1619#include " dolfinx/fem/FunctionSpace.h"
1720#include " dolfinx/la/SparsityPattern.h"
1821#include " dolfinx/la/utils.h"
1922#include " dolfinx/mesh/Mesh.h"
2023
21- namespace dolfinx ::transfer
24+ namespace dolfinx ::multigrid
2225{
2326
2427template <std::floating_point T>
@@ -79,8 +82,7 @@ inclusion_mapping(const dolfinx::mesh::Mesh<T>& mesh_from,
7982 // other processes.
8083 std::vector<std::int64_t > result (map.size (), -1 );
8184 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 ());
8486
8587 assert (std::ranges::all_of (result, [](auto e) { return e >= 0 ; }));
8688 return result;
@@ -92,7 +94,18 @@ create_sparsity_pattern(const dolfinx::fem::FunctionSpace<T>& V_from,
9294 const dolfinx::fem::FunctionSpace<T>& V_to,
9395 const std::vector<std::int64_t >& inclusion_map)
9496{
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+
96109 auto mesh_from = V_from.mesh ();
97110 auto mesh_to = V_to.mesh ();
98111 assert (mesh_from);
@@ -167,11 +180,21 @@ void assemble_transfer_matrix(la::MatSet<T> auto mat_set,
167180 const std::vector<std::int64_t >& inclusion_map,
168181 std::function<T(std::int32_t )> weight)
169182{
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+
171195 auto mesh_from = V_from.mesh ();
172196 auto mesh_to = V_to.mesh ();
173197 assert (mesh_from);
174- assert (mesh_to);
175198
176199 MPI_Comm comm = mesh_from->comm ();
177200 {
@@ -227,7 +250,7 @@ void assemble_transfer_matrix(la::MatSet<T> auto mat_set,
227250 // asserted.
228251 std::int32_t distance = (n == local_dof_to) ? 0 : 1 ;
229252 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)});
231254 }
232255 }
233256 }
0 commit comments