|
| 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 | +} |
0 commit comments