From: Wolfgang Bangerth Date: Fri, 7 Jan 2022 10:53:46 +0000 (-0700) Subject: Simplify initialization of block systems. X-Git-Tag: v9.4.0-rc1~653^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F13190%2Fhead;p=dealii.git Simplify initialization of block systems. --- diff --git a/examples/step-20/step-20.cc b/examples/step-20/step-20.cc index 833b041042..c447fba204 100644 --- a/examples/step-20/step-20.cc +++ b/examples/step-20/step-20.cc @@ -403,15 +403,9 @@ namespace Step20 // DynamicSparsityPattern. This block sparsity pattern has // four blocks in a $2 \times 2$ pattern. The blocks' sizes depend on // n_u and n_p, which hold the number of velocity - // and pressure variables. In the second step we have to instruct the block - // system to update its knowledge about the sizes of the blocks it manages; - // this happens with the dsp.collect_sizes () call. - BlockDynamicSparsityPattern dsp(2, 2); - dsp.block(0, 0).reinit(n_u, n_u); - dsp.block(1, 0).reinit(n_p, n_u); - dsp.block(0, 1).reinit(n_u, n_p); - dsp.block(1, 1).reinit(n_p, n_p); - dsp.collect_sizes(); + // and pressure variables. + const std::vector block_sizes = {n_u, n_p}; + BlockDynamicSparsityPattern dsp(block_sizes, block_sizes); DoFTools::make_sparsity_pattern(dof_handler, dsp); // We use the compressed block sparsity pattern in the same way as the @@ -422,15 +416,8 @@ namespace Step20 // Then we have to resize the solution and right hand side vectors in // exactly the same way as the block compressed sparsity pattern: - solution.reinit(2); - solution.block(0).reinit(n_u); - solution.block(1).reinit(n_p); - solution.collect_sizes(); - - system_rhs.reinit(2); - system_rhs.block(0).reinit(n_u); - system_rhs.block(1).reinit(n_p); - system_rhs.collect_sizes(); + solution.reinit(block_sizes); + system_rhs.reinit(block_sizes); }