From: Wolfgang Bangerth Date: Fri, 7 Jan 2022 11:03:27 +0000 (-0700) Subject: Simplify initialization of block systems in step-21. X-Git-Tag: v9.4.0-rc1~652^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F13191%2Fhead;p=dealii.git Simplify initialization of block systems in step-21. --- diff --git a/examples/step-21/step-21.cc b/examples/step-21/step-21.cc index a3032ae782..5f107b0eaa 100644 --- a/examples/step-21/step-21.cc +++ b/examples/step-21/step-21.cc @@ -549,45 +549,16 @@ namespace Step21 << " (" << n_u << '+' << n_p << '+' << n_s << ')' << std::endl << std::endl; - const unsigned int n_couplings = dof_handler.max_couplings_between_dofs(); - - sparsity_pattern.reinit(3, 3); - sparsity_pattern.block(0, 0).reinit(n_u, n_u, n_couplings); - sparsity_pattern.block(1, 0).reinit(n_p, n_u, n_couplings); - sparsity_pattern.block(2, 0).reinit(n_s, n_u, n_couplings); - sparsity_pattern.block(0, 1).reinit(n_u, n_p, n_couplings); - sparsity_pattern.block(1, 1).reinit(n_p, n_p, n_couplings); - sparsity_pattern.block(2, 1).reinit(n_s, n_p, n_couplings); - sparsity_pattern.block(0, 2).reinit(n_u, n_s, n_couplings); - sparsity_pattern.block(1, 2).reinit(n_p, n_s, n_couplings); - sparsity_pattern.block(2, 2).reinit(n_s, n_s, n_couplings); - - sparsity_pattern.collect_sizes(); - - DoFTools::make_sparsity_pattern(dof_handler, sparsity_pattern); - sparsity_pattern.compress(); - + const std::vector block_sizes = {n_u, n_p, n_s}; + BlockDynamicSparsityPattern dsp(block_sizes, block_sizes); + DoFTools::make_sparsity_pattern(dof_handler, dsp); + sparsity_pattern.copy_from(dsp); system_matrix.reinit(sparsity_pattern); - - solution.reinit(3); - solution.block(0).reinit(n_u); - solution.block(1).reinit(n_p); - solution.block(2).reinit(n_s); - solution.collect_sizes(); - - old_solution.reinit(3); - old_solution.block(0).reinit(n_u); - old_solution.block(1).reinit(n_p); - old_solution.block(2).reinit(n_s); - old_solution.collect_sizes(); - - system_rhs.reinit(3); - system_rhs.block(0).reinit(n_u); - system_rhs.block(1).reinit(n_p); - system_rhs.block(2).reinit(n_s); - system_rhs.collect_sizes(); + solution.reinit(block_sizes); + old_solution.reinit(block_sizes); + system_rhs.reinit(block_sizes); }