From: David Wells Date: Sat, 11 May 2019 18:14:53 +0000 (-0400) Subject: step-41: C++ modernization. X-Git-Tag: v9.1.0-rc1~57^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=14514fdc62379229f808c7dbf1bc7b14ee8a5c33;p=dealii.git step-41: C++ modernization. 1. Avoid including (we don't use it) 2. Inline function definitions 3. Use ranged-for loops --- diff --git a/examples/step-41/step-41.cc b/examples/step-41/step-41.cc index f2e5ec1171..e1f5c1f979 100644 --- a/examples/step-41/step-41.cc +++ b/examples/step-41/step-41.cc @@ -55,7 +55,6 @@ #include #include -#include namespace Step41 @@ -126,19 +125,15 @@ namespace Step41 : Function() {} - virtual double value(const Point & p, - const unsigned int component = 0) const override; - }; - - template - double RightHandSide::value(const Point &, - const unsigned int component) const - { - (void)component; - Assert(component == 0, ExcIndexRange(component, 0, 1)); + virtual double value(const Point & /*p*/, + const unsigned int component = 0) const override + { + (void)component; + AssertIndexRange(component, 1); - return -10; - } + return -10; + } + }; @@ -150,19 +145,15 @@ namespace Step41 : Function() {} - virtual double value(const Point & p, - const unsigned int component = 0) const override; - }; - - template - double BoundaryValues::value(const Point &, - const unsigned int component) const - { - (void)component; - Assert(component == 0, ExcIndexRange(component, 0, 1)); + virtual double value(const Point & /*p*/, + const unsigned int component = 0) const override + { + (void)component; + AssertIndexRange(component, 1); - return 0; - } + return 0; + } + }; @@ -177,26 +168,22 @@ namespace Step41 {} virtual double value(const Point & p, - const unsigned int component = 0) const override; + const unsigned int component = 0) const override + { + (void)component; + Assert(component == 0, ExcIndexRange(component, 0, 1)); + + if (p(0) < -0.5) + return -0.2; + else if (p(0) >= -0.5 && p(0) < 0.0) + return -0.4; + else if (p(0) >= 0.0 && p(0) < 0.5) + return -0.6; + else + return -0.8; + } }; - template - double Obstacle::value(const Point & p, - const unsigned int component) const - { - (void)component; - Assert(component == 0, ExcIndexRange(component, 0, 1)); - - if (p(0) < -0.5) - return -0.2; - else if (p(0) >= -0.5 && p(0) < 0.0) - return -0.4; - else if (p(0) >= 0.0 && p(0) < 0.5) - return -0.6; - else - return -0.8; - } - // @sect3{Implementation of the ObstacleProblem class} @@ -309,11 +296,7 @@ namespace Step41 std::vector local_dof_indices(dofs_per_cell); - typename DoFHandler::active_cell_iterator cell = - dof_handler.begin_active(), - endc = dof_handler.end(); - - for (; cell != endc; ++cell) + for (const auto &cell : dof_handler.active_cell_iterators()) { fe_values.reinit(cell); cell_matrix = 0; @@ -385,11 +368,7 @@ namespace Step41 FullMatrix cell_matrix(dofs_per_cell, dofs_per_cell); std::vector local_dof_indices(dofs_per_cell); - typename DoFHandler::active_cell_iterator cell = - dof_handler.begin_active(), - endc = dof_handler.end(); - - for (; cell != endc; ++cell) + for (const auto &cell : dof_handler.active_cell_iterators()) { fe_values.reinit(cell); cell_matrix = 0; @@ -475,10 +454,7 @@ namespace Step41 const Obstacle obstacle; std::vector dof_touched(dof_handler.n_dofs(), false); - typename DoFHandler::active_cell_iterator cell = - dof_handler.begin_active(), - endc = dof_handler.end(); - for (; cell != endc; ++cell) + for (const auto &cell : dof_handler.active_cell_iterators()) for (unsigned int v = 0; v < GeometryInfo::vertices_per_cell; ++v) { Assert(dof_handler.get_fe().dofs_per_cell == @@ -596,7 +572,7 @@ namespace Step41 data_out.build_patches(); - std::ofstream output_vtk(std::string("output_") + + std::ofstream output_vtk("output_" + Utilities::int_to_string(iteration, 3) + ".vtk"); data_out.write_vtk(output_vtk); }