From: David Wells Date: Wed, 8 May 2019 22:13:54 +0000 (-0400) Subject: step-30: minor modernizations. X-Git-Tag: v9.1.0-rc1~101^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=96d8bbc3aa6022a9ac76e8945451f530e7316041;p=dealii.git step-30: minor modernizations. 1. Inline function definitions. 2. Remove unnecessary class destructor. 3. More modernization: std::abs, std::array. 4. Reorganize the headers 5. Minor formatting and whitespace improvements 6. remove a second mention of a deleted member of GeometryInfo --- diff --git a/examples/step-30/doc/intro.dox b/examples/step-30/doc/intro.dox index e38bcb05b1..d2fd5587f3 100644 --- a/examples/step-30/doc/intro.dox +++ b/examples/step-30/doc/intro.dox @@ -204,12 +204,10 @@ GeometryInfo::max_children_per_cell which specifies the maximum number of children a cell can have. How many children a refined cell has was previously available as static information, but now it depends on the actual refinement state of a cell and can be -retrieved using the function call cell-@>n_children(), +retrieved using TriaAccessor::n_children(), a call that works equally well for both isotropic and anisotropic refinement. A very similar situation can be found for -faces and their subfaces: the previously available variable -GeometryInfo::subfaces_per_face no -longer exists; the pertinent information can now be queried using +faces and their subfaces: the pertinent information can be queried using GeometryInfo::max_children_per_face or face->n_children(), depending on the context. @@ -252,7 +250,7 @@ write code that works for both isotropic and anisotropic refinement: i.e. has children occupying only part of the common face. In this case, the face under consideration has to be a refined one, which can determine by - asking if(face->has_children()). If this is true, we need to + asking if (face->has_children()). If this is true, we need to loop over all subfaces and get the neighbors' child behind this subface, so that we can reinit an FEFaceValues object with the neighbor and an FESubfaceValues object @@ -450,7 +448,7 @@ cell. Of course, in the limit we expect that the jumps tend to zero as we refine the mesh and approximate the true solution better and better. Thus, a large jump across a given face indicates that the cell should be refined (at least) -orthogonal to that face, whereas a small jump does not lead to this +orthogonally to that face, whereas a small jump does not lead to this conclusion. It is possible, of course, that the exact solution is not smooth and that it also features a jump. In that case, however, a large jump over one face indicates, that this face is more or less parallel to the jump and in the diff --git a/examples/step-30/step-30.cc b/examples/step-30/step-30.cc index fc4659da2f..5a4e48071e 100644 --- a/examples/step-30/step-30.cc +++ b/examples/step-30/step-30.cc @@ -20,29 +20,30 @@ // The deal.II include files have already been covered in previous examples // and will thus not be further commented on. -#include #include -#include +#include +#include +#include +#include #include +#include #include #include #include #include #include #include -#include #include #include #include -#include +#include #include #include -#include -#include +#include #include -#include // And this again is C++: +#include #include #include @@ -62,7 +63,14 @@ namespace Step30 public: virtual void value_list(const std::vector> &points, std::vector & values, - const unsigned int component = 0) const override; + const unsigned int /*component*/ = 0) const override + { + (void)points; + Assert(values.size() == points.size(), + ExcDimensionMismatch(values.size(), points.size())); + + std::fill(values.begin(), values.end(), 0.); + } }; @@ -72,7 +80,19 @@ namespace Step30 public: virtual void value_list(const std::vector> &points, std::vector & values, - const unsigned int component = 0) const override; + const unsigned int /*component*/ = 0) const override + { + Assert(values.size() == points.size(), + ExcDimensionMismatch(values.size(), points.size())); + + for (unsigned int i = 0; i < values.size(); ++i) + { + if (points[i](0) < 0.5) + values[i] = 1.; + else + values[i] = 0.; + } + } }; @@ -80,73 +100,38 @@ namespace Step30 class Beta { public: + // The flow field is chosen to be a quarter circle with counterclockwise + // flow direction and with the origin as midpoint for the right half of the + // domain with positive $x$ values, whereas the flow simply goes to the left + // in the left part of the domain at a velocity that matches the one coming + // in from the right. In the circular part the magnitude of the flow + // velocity is proportional to the distance from the origin. This is a + // difference to step-12, where the magnitude was 1 everywhere. the new + // definition leads to a linear variation of $\beta$ along each given face + // of a cell. On the other hand, the solution $u(x,y)$ is exactly the same + // as before. void value_list(const std::vector> &points, - std::vector> & values) const; - }; - - - template - void RHS::value_list(const std::vector> &points, - std::vector & values, - const unsigned int) const - { - (void)points; - Assert(values.size() == points.size(), - ExcDimensionMismatch(values.size(), points.size())); - - std::fill(values.begin(), values.end(), 0.); - } - - - // The flow field is chosen to be a quarter circle with counterclockwise - // flow direction and with the origin as midpoint for the right half of the - // domain with positive $x$ values, whereas the flow simply goes to the left - // in the left part of the domain at a velocity that matches the one coming - // in from the right. In the circular part the magnitude of the flow - // velocity is proportional to the distance from the origin. This is a - // difference to step-12, where the magnitude was 1 everywhere. the new - // definition leads to a linear variation of $\beta$ along each given face - // of a cell. On the other hand, the solution $u(x,y)$ is exactly the same - // as before. - template - void Beta::value_list(const std::vector> &points, - std::vector> & values) const - { - Assert(values.size() == points.size(), - ExcDimensionMismatch(values.size(), points.size())); - - for (unsigned int i = 0; i < points.size(); ++i) - { - if (points[i](0) > 0) - { - values[i](0) = -points[i](1); - values[i](1) = points[i](0); - } - else - { - values[i] = Point(); - values[i](0) = -points[i](1); - } - } - } - + std::vector> & values) const + { + Assert(values.size() == points.size(), + ExcDimensionMismatch(values.size(), points.size())); - template - void BoundaryValues::value_list(const std::vector> &points, - std::vector & values, - const unsigned int) const - { - Assert(values.size() == points.size(), - ExcDimensionMismatch(values.size(), points.size())); + for (unsigned int i = 0; i < points.size(); ++i) + { + if (points[i](0) > 0) + { + values[i](0) = -points[i](1); + values[i](1) = points[i](0); + } + else + { + values[i] = Point(); + values[i](0) = -points[i](1); + } + } + } + }; - for (unsigned int i = 0; i < values.size(); ++i) - { - if (points[i](0) < 0.5) - values[i] = 1.; - else - values[i] = 0.; - } - } // @sect3{Class: DGTransportEquation} @@ -181,6 +166,7 @@ namespace Step30 }; + // Likewise, the constructor of the class as well as the functions // assembling the terms corresponding to cell interiors and boundary faces // are unchanged from before. The function that assembles face terms between @@ -198,6 +184,7 @@ namespace Step30 {} + template void DGTransportEquation::assemble_cell_term( const FEValues &fe_v, @@ -315,7 +302,6 @@ namespace Step30 { public: DGMethod(const bool anisotropic); - ~DGMethod(); void run(); @@ -380,12 +366,6 @@ namespace Step30 {} - template - DGMethod::~DGMethod() - { - dof_handler.clear(); - } - template void DGMethod::setup_system() @@ -813,7 +793,7 @@ namespace Step30 // accumulate these values into vectors with // dim components. jump[face_no / 2] += - std::fabs(u[x] - u_neighbor[x]) * JxW[x]; + std::abs(u[x] - u_neighbor[x]) * JxW[x]; // We also sum up the scaled weights to obtain // the measure of the face. area[face_no / 2] += JxW[x]; @@ -847,7 +827,7 @@ namespace Step30 ++x) { jump[face_no / 2] += - std::fabs(u[x] - u_neighbor[x]) * JxW[x]; + std::abs(u[x] - u_neighbor[x]) * JxW[x]; area[face_no / 2] += JxW[x]; } } @@ -892,7 +872,7 @@ namespace Step30 ++x) { jump[face_no / 2] += - std::fabs(u[x] - u_neighbor[x]) * JxW[x]; + std::abs(u[x] - u_neighbor[x]) * JxW[x]; area[face_no / 2] += JxW[x]; } } @@ -901,8 +881,8 @@ namespace Step30 } // Now we analyze the size of the mean jumps, which we get dividing // the jumps by the measure of the respective faces. - double average_jumps[dim]; - double sum_of_average_jumps = 0.; + std::array average_jumps; + double sum_of_average_jumps = 0.; for (unsigned int i = 0; i < dim; ++i) { average_jumps[i] = jump(i) / area(i); @@ -976,6 +956,7 @@ namespace Step30 } + template void DGMethod::run() {