]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Modernize step-25. 8007/head
authorDavid Wells <drwells@email.unc.edu>
Sat, 4 May 2019 19:09:13 +0000 (15:09 -0400)
committerDavid Wells <drwells@email.unc.edu>
Sun, 5 May 2019 17:25:09 +0000 (13:25 -0400)
This PR introduces several small changes:
1. Combine declarations and definitions of some simple functinos.
2. Remove some unused headers.
3. Switch to VTU output.

examples/step-25/doc/intro.dox
examples/step-25/step-25.cc

index c330a2b02bd653896f7eb42a784814ca3838f9e1..a97e7cb9de7061dc5a5b175119c8bba22c359491 100644 (file)
@@ -14,7 +14,7 @@ so-called Klein-Gordon equation, which is a relativistic version of
 the Schrödinger equation for particles with non-zero mass. The resemblance is not just
 superficial, the sine-Gordon equation has been shown to model some
 unified-field phenomena such as interaction of subatomic particles
-(see, e.g., Perring &amp; Skyrme in Nuclear Physics <b>31</b>) and the
+(see, e.g., Perring &amp; Skyrme in Nuclear %Physics <b>31</b>) and the
 Josephson (quantum) effect in superconductor junctions (see, e.g., <a
 href="http://en.wikipedia.org/wiki/Long_Josephson_junction">http://en.wikipedia.org/wiki/Long_Josephson_junction</a>).
 Furthermore, from the mathematical standpoint, since the sine-Gordon
index 7372a4798003a8d8f5699bbbfd9c0ffab01f8a53..a6685f2cdc7c5f5b6f3401af0a7f43a98591ef02 100644 (file)
@@ -28,8 +28,8 @@
 // headers for file input/output and string streams.
 #include <deal.II/base/quadrature_lib.h>
 #include <deal.II/base/function.h>
-#include <deal.II/base/logstream.h>
 #include <deal.II/base/utilities.h>
+
 #include <deal.II/lac/vector.h>
 #include <deal.II/lac/full_matrix.h>
 #include <deal.II/lac/sparse_matrix.h>
 #include <deal.II/lac/solver_cg.h>
 #include <deal.II/lac/precondition.h>
 #include <deal.II/lac/affine_constraints.h>
+
 #include <deal.II/grid/tria.h>
 #include <deal.II/grid/grid_generator.h>
-#include <deal.II/grid/tria_accessor.h>
-#include <deal.II/grid/tria_iterator.h>
+
 #include <deal.II/dofs/dof_handler.h>
-#include <deal.II/dofs/dof_accessor.h>
 #include <deal.II/dofs/dof_tools.h>
+
 #include <deal.II/fe/fe_q.h>
 #include <deal.II/fe/fe_values.h>
+
 #include <deal.II/numerics/vector_tools.h>
 #include <deal.II/numerics/matrix_tools.h>
 #include <deal.II/numerics/data_out.h>
@@ -156,59 +157,58 @@ namespace Step25
     ExactSolution(const unsigned int n_components = 1, const double time = 0.)
       : Function<dim>(n_components, time)
     {}
-    virtual double value(const Point<dim> & p,
-                         const unsigned int component = 0) const override;
-  };
 
-  template <int dim>
-  double ExactSolution<dim>::value(const Point<dim> &p,
-                                   const unsigned int /*component*/) const
-  {
-    double t = this->get_time();
 
-    switch (dim)
-      {
-        case 1:
-          {
-            const double m  = 0.5;
-            const double c1 = 0.;
-            const double c2 = 0.;
-            return -4. * std::atan(m / std::sqrt(1. - m * m) *
-                                   std::sin(std::sqrt(1. - m * m) * t + c2) /
-                                   std::cosh(m * p[0] + c1));
-          }
-
-        case 2:
-          {
-            const double theta  = numbers::PI / 4.;
-            const double lambda = 1.;
-            const double a0     = 1.;
-            const double s      = 1.;
-            const double arg    = p[0] * std::cos(theta) +
-                               std::sin(theta) * (p[1] * std::cosh(lambda) +
-                                                  t * std::sinh(lambda));
-            return 4. * std::atan(a0 * std::exp(s * arg));
-          }
 
-        case 3:
-          {
-            const double theta = numbers::PI / 4;
-            const double phi   = numbers::PI / 4;
-            const double tau   = 1.;
-            const double c0    = 1.;
-            const double s     = 1.;
-            const double arg   = p[0] * std::cos(theta) +
-                               p[1] * std::sin(theta) * std::cos(phi) +
-                               std::sin(theta) * std::sin(phi) *
-                                 (p[2] * std::cosh(tau) + t * std::sinh(tau));
-            return 4. * std::atan(c0 * std::exp(s * arg));
-          }
-
-        default:
-          Assert(false, ExcNotImplemented());
-          return -1e8;
-      }
-  }
+    virtual double value(const Point<dim> &p,
+                         const unsigned int /*component*/ = 0) const override
+    {
+      const double t = this->get_time();
+
+      switch (dim)
+        {
+          case 1:
+            {
+              const double m  = 0.5;
+              const double c1 = 0.;
+              const double c2 = 0.;
+              return -4. * std::atan(m / std::sqrt(1. - m * m) *
+                                     std::sin(std::sqrt(1. - m * m) * t + c2) /
+                                     std::cosh(m * p[0] + c1));
+            }
+
+          case 2:
+            {
+              const double theta  = numbers::PI / 4.;
+              const double lambda = 1.;
+              const double a0     = 1.;
+              const double s      = 1.;
+              const double arg    = p[0] * std::cos(theta) +
+                                 std::sin(theta) * (p[1] * std::cosh(lambda) +
+                                                    t * std::sinh(lambda));
+              return 4. * std::atan(a0 * std::exp(s * arg));
+            }
+
+          case 3:
+            {
+              const double theta = numbers::PI / 4;
+              const double phi   = numbers::PI / 4;
+              const double tau   = 1.;
+              const double c0    = 1.;
+              const double s     = 1.;
+              const double arg   = p[0] * std::cos(theta) +
+                                 p[1] * std::sin(theta) * std::cos(phi) +
+                                 std::sin(theta) * std::sin(phi) *
+                                   (p[2] * std::cosh(tau) + t * std::sinh(tau));
+              return 4. * std::atan(c0 * std::exp(s * arg));
+            }
+
+          default:
+            Assert(false, ExcNotImplemented());
+            return -1e8;
+        }
+    }
+  };
 
   // In the second part of this section, we provide the initial conditions. We
   // are lazy (and cautious) and don't want to implement the same functions as
@@ -224,17 +224,12 @@ namespace Step25
     {}
 
     virtual double value(const Point<dim> & p,
-                         const unsigned int component = 0) const override;
+                         const unsigned int component = 0) const override
+    {
+      return ExactSolution<dim>(1, this->get_time()).value(p, component);
+    }
   };
 
-  template <int dim>
-  double InitialValues<dim>::value(const Point<dim> & p,
-                                   const unsigned int component) const
-  {
-    return ExactSolution<dim>(1, this->get_time()).value(p, component);
-  }
-
-
 
   // @sect3{Implementation of the <code>SineGordonProblem</code> class}
 
@@ -414,11 +409,7 @@ namespace Step25
     std::vector<double>                  old_data_values(n_q_points);
     std::vector<double>                  new_data_values(n_q_points);
 
-    typename DoFHandler<dim>::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())
       {
         local_nl_term = 0;
         // Once we re-initialize our <code>FEValues</code> instantiation to
@@ -478,11 +469,7 @@ namespace Step25
     std::vector<double>                  old_data_values(n_q_points);
     std::vector<double>                  new_data_values(n_q_points);
 
-    typename DoFHandler<dim>::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())
       {
         local_nl_matrix = 0;
         // Again, first we re-initialize our <code>FEValues</code>
@@ -570,10 +557,13 @@ namespace Step25
     data_out.build_patches();
 
     const std::string filename =
-      "solution-" + Utilities::int_to_string(timestep_number, 3) + ".vtk";
-
+      "solution-" + Utilities::int_to_string(timestep_number, 3) + ".vtu";
+    DataOutBase::VtkFlags vtk_flags;
+    vtk_flags.compression_level =
+      DataOutBase::VtkFlags::ZlibCompressionLevel::best_speed;
+    data_out.set_flags(vtk_flags);
     std::ofstream output(filename);
-    data_out.write_vtk(output);
+    data_out.write_vtu(output);
   }
 
   // @sect4{SineGordonProblem::run}

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.