From a81cbd6bd28479d59238112ce3525e077dbc378b Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Fri, 7 Jan 2022 03:53:46 -0700 Subject: [PATCH] Simplify initialization of block systems. --- examples/step-20/step-20.cc | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) 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); } -- 2.39.5