From 653ee647f43c7f870fe646a9cb5824225c364b73 Mon Sep 17 00:00:00 2001 From: David Wells Date: Sat, 4 May 2019 15:09:13 -0400 Subject: [PATCH] Modernize step-25. 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 | 2 +- examples/step-25/step-25.cc | 142 +++++++++++++++------------------ 2 files changed, 67 insertions(+), 77 deletions(-) diff --git a/examples/step-25/doc/intro.dox b/examples/step-25/doc/intro.dox index c330a2b02b..a97e7cb9de 100644 --- a/examples/step-25/doc/intro.dox +++ b/examples/step-25/doc/intro.dox @@ -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 & Skyrme in Nuclear Physics 31) and the +(see, e.g., Perring & Skyrme in Nuclear %Physics 31) and the Josephson (quantum) effect in superconductor junctions (see, e.g., http://en.wikipedia.org/wiki/Long_Josephson_junction). Furthermore, from the mathematical standpoint, since the sine-Gordon diff --git a/examples/step-25/step-25.cc b/examples/step-25/step-25.cc index 7372a47980..a6685f2cdc 100644 --- a/examples/step-25/step-25.cc +++ b/examples/step-25/step-25.cc @@ -28,8 +28,8 @@ // headers for file input/output and string streams. #include #include -#include #include + #include #include #include @@ -37,15 +37,16 @@ #include #include #include + #include #include -#include -#include + #include -#include #include + #include #include + #include #include #include @@ -156,59 +157,58 @@ namespace Step25 ExactSolution(const unsigned int n_components = 1, const double time = 0.) : Function(n_components, time) {} - virtual double value(const Point & p, - const unsigned int component = 0) const override; - }; - template - double ExactSolution::value(const Point &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 &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 & p, - const unsigned int component = 0) const override; + const unsigned int component = 0) const override + { + return ExactSolution(1, this->get_time()).value(p, component); + } }; - template - double InitialValues::value(const Point & p, - const unsigned int component) const - { - return ExactSolution(1, this->get_time()).value(p, component); - } - - // @sect3{Implementation of the SineGordonProblem class} @@ -414,11 +409,7 @@ namespace Step25 std::vector old_data_values(n_q_points); std::vector new_data_values(n_q_points); - 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()) { local_nl_term = 0; // Once we re-initialize our FEValues instantiation to @@ -478,11 +469,7 @@ namespace Step25 std::vector old_data_values(n_q_points); std::vector new_data_values(n_q_points); - 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()) { local_nl_matrix = 0; // Again, first we re-initialize our FEValues @@ -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} -- 2.39.5