]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Simplify initialization of block systems. 13190/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Fri, 7 Jan 2022 10:53:46 +0000 (03:53 -0700)
committerWolfgang Bangerth <bangerth@colostate.edu>
Fri, 7 Jan 2022 10:53:46 +0000 (03:53 -0700)
examples/step-20/step-20.cc

index 833b04104226450136fdc97a3acda04c0720a437..c447fba2045ba0e73afcfacf3016dafa4db78529 100644 (file)
@@ -403,15 +403,9 @@ namespace Step20
     // <code>DynamicSparsityPattern</code>. This block sparsity pattern has
     // four blocks in a $2 \times 2$ pattern. The blocks' sizes depend on
     // <code>n_u</code> and <code>n_p</code>, 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 <code>dsp.collect_sizes ()</code> 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<types::global_dof_index> 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);
   }
 
 

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.