Skip to content

Commit 70fe0b4

Browse files
committed
[WIP]
1 parent 7e4e1dd commit 70fe0b4

File tree

10 files changed

+461
-394
lines changed

10 files changed

+461
-394
lines changed

cpp/dolfinx/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ set(DOLFINX_DIRS
1717
io
1818
la
1919
mesh
20+
multigrid
2021
nls
2122
refinement
22-
transfer
2323
)
2424

2525
# Add source to dolfinx target, and get sets of header files
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
set(HEADERS_transfer
1+
set(HEADERS_multigrid
22
${CMAKE_CURRENT_SOURCE_DIR}/transfer_matrix.h
33
PARENT_SCOPE
44
)

cpp/dolfinx/transfer/transfer_matrix.h renamed to cpp/dolfinx/multigrid/transfer_matrix.h

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,18 @@
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

2427
template <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
}

cpp/test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ add_executable(
4848
mesh/refinement/interval.cpp
4949
mesh/refinement/option.cpp
5050
mesh/refinement/rectangle.cpp
51-
transfer/transfer_matrix.cpp
51+
multigrid/transfer_matrix.cpp
5252
${CMAKE_CURRENT_BINARY_DIR}/poisson.c
5353
)
5454
target_link_libraries(unittests PRIVATE Catch2::Catch2WithMain dolfinx)

0 commit comments

Comments
 (0)