Skip to content

Commit 75cf562

Browse files
committed
Import remote boundary data when assembling Direct preconditioners
1 parent 0501446 commit 75cf562

3 files changed

Lines changed: 118 additions & 9 deletions

File tree

‎source/bem_problem.cc‎

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2750,6 +2750,11 @@ template <int dim>
27502750
void
27512751
BEMProblem<dim>::assemble_preconditioner()
27522752
{
2753+
// Each owned matrix row also contains columns owned by other ranks.
2754+
// Import column data collectively before the rank-local assembly loops.
2755+
const Vector<double> column_dirichlet_nodes(dirichlet_nodes);
2756+
const Vector<double> column_robin_nodes(robin_nodes);
2757+
const Vector<double> column_robin_diagonal(robin_matrix_diagonal);
27532758
if (!is_preconditioner_initialized)
27542759
{
27552760
for (auto i : this_cpu_set)
@@ -2794,18 +2799,18 @@ BEMProblem<dim>::assemble_preconditioner()
27942799
++j)
27952800
{
27962801
// if (dirichlet_nodes(i) == 0)
2797-
if (dirichlet_nodes(j) == 0)
2802+
if (column_dirichlet_nodes(j) == 0)
27982803
{
27992804
// Nodo di Neumann - or Robin
28002805
band_system.add(i, j, neumann_matrix(i, j));
28012806

28022807
// TODO: account for Robin node
2803-
if (robin_nodes(j) == 1)
2808+
if (column_robin_nodes(j) == 1)
28042809
{
28052810
band_system.add(i,
28062811
j,
28072812
dirichlet_matrix(i, j) *
2808-
robin_matrix_diagonal(j));
2813+
column_robin_diagonal(j));
28092814
}
28102815

28112816
if (i == j)
@@ -2843,6 +2848,12 @@ template <int dim>
28432848
void
28442849
BEMProblem<dim>::assemble_preconditioner_complex()
28452850
{
2851+
// Each owned matrix row also contains columns owned by other ranks.
2852+
// Import column data collectively before the rank-local assembly loops.
2853+
const Vector<double> column_dirichlet_nodes(dirichlet_nodes);
2854+
const Vector<double> column_robin_nodes(robin_nodes);
2855+
const Vector<double> column_robin_diagonal(robin_matrix_diagonal);
2856+
const Vector<double> column_robin_diagonal_imag(robin_matrix_diagonal_imag);
28462857
if (!is_preconditioner_complex_initialized)
28472858
{
28482859
for (auto i : this_cpu_set)
@@ -2890,27 +2901,27 @@ BEMProblem<dim>::assemble_preconditioner_complex()
28902901

28912902
for (auto j = from; j < to; ++j)
28922903
{
2893-
if (dirichlet_nodes(j) == 0)
2904+
if (column_dirichlet_nodes(j) == 0)
28942905
{
28952906
// neumann and robin nodes are implicitly merged, here
28962907
band_system_complex.add(i, j, neumann_matrix(i, j));
28972908
band_system_complex.add(i + this_cpu_set.size(),
28982909
j + this_cpu_set.size(),
28992910
neumann_matrix(i, j));
29002911

2901-
if (robin_nodes(j) == 1)
2912+
if (column_robin_nodes(j) == 1)
29022913
{
29032914
// scale the row from D, using the robin matrix
29042915
// diagonal
29052916
// for now, ignore the pairing parts
29062917
band_system_complex.add(i,
29072918
j,
29082919
dirichlet_matrix(i, j) *
2909-
robin_matrix_diagonal(j));
2920+
column_robin_diagonal(j));
29102921
band_system_complex.add(i + this_cpu_set.size(),
29112922
j + this_cpu_set.size(),
29122923
dirichlet_matrix(i, j) *
2913-
robin_matrix_diagonal(j));
2924+
column_robin_diagonal(j));
29142925

29152926
// check for pairing elements
29162927
if ((robin_nodes(i) == 1) &&
@@ -2922,12 +2933,12 @@ BEMProblem<dim>::assemble_preconditioner_complex()
29222933
band_system_complex.add(i,
29232934
j + this_cpu_set.size(),
29242935
-dirichlet_matrix(i, j) *
2925-
robin_matrix_diagonal_imag(
2936+
column_robin_diagonal_imag(
29262937
j));
29272938
band_system_complex.add(i + this_cpu_set.size(),
29282939
j,
29292940
dirichlet_matrix(i, j) *
2930-
robin_matrix_diagonal_imag(
2941+
column_robin_diagonal_imag(
29312942
j));
29322943
}
29332944
}

‎tests/direct_preconditioner_mpi.cc‎

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
// An owned matrix row needs boundary data for columns on other MPI ranks.
2+
// Exercise real and complex preconditioners against an explicit small matrix.
3+
#include "bem_problem.h"
4+
#include "tests.h"
5+
6+
int
7+
main(int argc, char **argv)
8+
{
9+
Utilities::MPI::MPI_InitFinalize mpi(argc, argv, 1);
10+
const auto rank = Utilities::MPI::this_mpi_process(MPI_COMM_WORLD);
11+
if (rank == 0)
12+
initlog();
13+
AssertThrow(Utilities::MPI::n_mpi_processes(MPI_COMM_WORLD) == 2,
14+
ExcMessage("This regression requires two MPI ranks"));
15+
ComputationalDomain<3> domain;
16+
GridGenerator::hyper_cube(domain.tria);
17+
BEMProblem<3> problem(domain);
18+
problem.fe = std::make_unique<FE_Q<2, 3>>(1);
19+
problem.dh.distribute_dofs(*problem.fe);
20+
AssertThrow(problem.dh.n_dofs() == 4, ExcInternalError());
21+
problem.this_cpu_set = IndexSet(4);
22+
problem.this_cpu_set.add_range(2 * rank, 2 * rank + 2);
23+
problem.this_cpu_set.compress();
24+
problem.preconditioner_type = "ILU";
25+
problem.preconditioner_band = 8;
26+
problem.is_preconditioner_initialized = false;
27+
problem.is_preconditioner_complex_initialized = false;
28+
problem.constraints.close();
29+
problem.constraints_imag.close();
30+
problem.full_sparsity_pattern.reinit(problem.this_cpu_set, MPI_COMM_WORLD);
31+
problem.preconditioner_sparsity_pattern.reinit(problem.this_cpu_set,
32+
MPI_COMM_WORLD,
33+
4);
34+
IndexSet complex_owned(8);
35+
complex_owned.add_indices(problem.this_cpu_set);
36+
complex_owned.add_indices(problem.this_cpu_set, 4);
37+
complex_owned.compress();
38+
problem.preconditioner_complex_sparsity_pattern.reinit(complex_owned,
39+
MPI_COMM_WORLD,
40+
8);
41+
for (auto i : problem.this_cpu_set)
42+
for (unsigned int j = 0; j < 4; ++j)
43+
problem.full_sparsity_pattern.add(i, j);
44+
problem.full_sparsity_pattern.compress();
45+
problem.neumann_matrix.reinit(problem.full_sparsity_pattern);
46+
problem.dirichlet_matrix.reinit(problem.full_sparsity_pattern);
47+
for (auto *v : {&problem.dirichlet_nodes,
48+
&problem.robin_nodes,
49+
&problem.robin_matrix_diagonal,
50+
&problem.robin_matrix_diagonal_imag,
51+
&problem.alpha})
52+
v->reinit(problem.this_cpu_set, MPI_COMM_WORLD);
53+
for (auto i : problem.this_cpu_set)
54+
{
55+
problem.dirichlet_nodes(i) = (i == 0 || i == 3) ? 1 : 0;
56+
problem.robin_nodes(i) = i == 1 ? 1 : 0;
57+
problem.robin_matrix_diagonal(i) = i == 1 ? 3 : 0;
58+
problem.robin_matrix_diagonal_imag(i) = 0;
59+
problem.alpha(i) = 4;
60+
for (unsigned int j = 0; j < 4; ++j)
61+
{
62+
problem.neumann_matrix.set(i, j, 1);
63+
problem.dirichlet_matrix.set(i, j, 2);
64+
}
65+
}
66+
for (auto *v : {&problem.dirichlet_nodes,
67+
&problem.robin_nodes,
68+
&problem.robin_matrix_diagonal,
69+
&problem.robin_matrix_diagonal_imag,
70+
&problem.alpha})
71+
v->compress(VectorOperation::insert);
72+
problem.neumann_matrix.compress(VectorOperation::insert);
73+
problem.dirichlet_matrix.compress(VectorOperation::insert);
74+
problem.assemble_preconditioner();
75+
problem.assemble_preconditioner_complex();
76+
const double expected[4][4] = {{-2, 7, 1, -2},
77+
{-2, 11, 1, -2},
78+
{-2, 7, 5, -2},
79+
{-2, 7, 1, -2}};
80+
for (auto i : problem.this_cpu_set)
81+
for (unsigned int j = 0; j < 4; ++j)
82+
{
83+
AssertThrow(std::abs(problem.band_system.el(i, j) - expected[i][j]) <
84+
1e-14,
85+
ExcInternalError());
86+
AssertThrow(std::abs(problem.band_system_complex.el(i, j) -
87+
expected[i][j]) < 1e-14,
88+
ExcInternalError());
89+
AssertThrow(std::abs(problem.band_system_complex.el(i + 4, j + 4) -
90+
expected[i][j]) < 1e-14,
91+
ExcInternalError());
92+
}
93+
if (rank == 0)
94+
deallog << "Real and complex preconditioners import remote column data"
95+
<< std::endl;
96+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
DEAL::Real and complex preconditioners import remote column data

0 commit comments

Comments
 (0)