SpECTRE Documentation Coverage Report
Current view: top level - PointwiseFunctions/AnalyticData/Burgers - Sinusoid.hpp Hit Total Coverage
Commit: 2ae2b99409ac582030d56a4560a92a3e066a7e54 Lines: 1 15 6.7 %
Date: 2022-01-15 08:40:38
Legend: Lines: hit not hit

          Line data    Source code
       1           0 : // Distributed under the MIT License.
       2             : // See LICENSE.txt for details.
       3             : 
       4             : #pragma once
       5             : 
       6             : #include "DataStructures/DataBox/Prefixes.hpp"  // IWYU pragma: keep
       7             : #include "DataStructures/Tensor/TypeAliases.hpp"
       8             : #include "Evolution/Systems/Burgers/Tags.hpp"  // IWYU pragma: keep
       9             : #include "Options/Options.hpp"
      10             : #include "PointwiseFunctions/AnalyticData/AnalyticData.hpp"
      11             : #include "Utilities/TMPL.hpp"
      12             : #include "Utilities/TaggedTuple.hpp"
      13             : 
      14             : /// \cond
      15             : class DataVector;
      16             : // IWYU pragma: no_forward_declare Tensor
      17             : namespace PUP {
      18             : class er;
      19             : }  // namespace PUP
      20             : /// \endcond
      21             : 
      22             : namespace Burgers {
      23             : namespace AnalyticData {
      24             : /*!
      25             :  * \brief Analytic data (with an "exact" solution known) that is periodic over
      26             :  * the interval \f$[0,2\pi]\f$.
      27             :  *
      28             :  * The initial data is given by:
      29             :  *
      30             :  * \f{align}{
      31             :  *   u(x, 0) = \sin(x)
      32             :  * \f}
      33             :  *
      34             :  * At future times the analytic solution can be found by solving the
      35             :  * transcendental equation \cite Harten19973
      36             :  *
      37             :  * \f{align}{
      38             :  *   \label{eq:transcendental burgers periodic}
      39             :  *   \mathcal{F}=\sin\left(x-\mathcal{F}t\right)
      40             :  * \f}
      41             :  *
      42             :  * on the interval \f$x\in(0,\pi)\f$. The solution from \f$x\in(\pi,2\pi)\f$ is
      43             :  * given by \f$\mathcal{F}(x, t)=-\mathcal{F}(2\pi-x,t)\f$. The transcendental
      44             :  * equation \f$(\ref{eq:transcendental burgers periodic})\f$ can be solved with
      45             :  * a Newton-Raphson iterative scheme. Since this can be quite sensitive to the
      46             :  * initial guess we implement this solution as analytic data. The python code
      47             :  * below can be used to compute the analytic solution if desired.
      48             :  *
      49             :  * At time \f$1\f$ the solution develops a discontinuity at \f$x=\pi\f$ followed
      50             :  * by the amplitude of the solution decaying over time.
      51             :  *
      52             :  * \note We have rescaled \f$x\f$ and \f$t\f$ by \f$\pi\f$ compared to
      53             :  * \cite Harten19973.
      54             :  *
      55             :  * \code{py}
      56             :    import numpy as np
      57             :    from scipy.optimize import newton
      58             : 
      59             :    # x_grid is a np.array of positions at which to evaluate the solution
      60             :    def burgers_periodic(x_grid, time):
      61             :        def opt_fun(F, x, t):
      62             :            return np.sin((x - F * t)) - F
      63             : 
      64             :        results = []
      65             :        for i in range(len(x_grid)):
      66             :            x = x_grid[i]
      67             :            greater_than_pi = False
      68             :            if x > np.pi:
      69             :                x = x - np.pi
      70             :                x = -x
      71             :                x = x + np.pi
      72             :                greater_than_pi = True
      73             : 
      74             :            guess = 0.0
      75             :            if len(results) > 0:
      76             :                if results[-1] < 0.0:
      77             :                    guess = -results[-1]
      78             :                else:
      79             :                    guess = results[-1]
      80             :            res = newton(lambda F: opt_fun(F, x, time), x0=guess)
      81             : 
      82             :            if greater_than_pi:
      83             :                results.append(-res)
      84             :            else:
      85             :                results.append(res)
      86             : 
      87             :        return np.asarray(results)
      88             :  * \endcode
      89             :  */
      90           1 : class Sinusoid : public MarkAsAnalyticData {
      91             :  public:
      92           0 :   using options = tmpl::list<>;
      93           0 :   static constexpr Options::String help{
      94             :       "A solution that is periodic over the interval [0,2pi]. The solution "
      95             :       "starts as a sinusoid: u(x,0) = sin(x) and develops a "
      96             :       "discontinuity at x=pi and t=1."};
      97             : 
      98           0 :   Sinusoid() = default;
      99           0 :   Sinusoid(const Sinusoid&) = default;
     100           0 :   Sinusoid& operator=(const Sinusoid&) = default;
     101           0 :   Sinusoid(Sinusoid&&) = default;
     102           0 :   Sinusoid& operator=(Sinusoid&&) = default;
     103           0 :   ~Sinusoid() = default;
     104             : 
     105             :   template <typename T>
     106           0 :   Scalar<T> u(const tnsr::I<T, 1>& x) const;
     107             : 
     108           0 :   tuples::TaggedTuple<Tags::U> variables(const tnsr::I<DataVector, 1>& x,
     109             :                                          tmpl::list<Tags::U> /*meta*/) const;
     110             : 
     111             :   // NOLINTNEXTLINE(google-runtime-references)
     112           0 :   void pup(PUP::er& p);
     113             : };
     114             : 
     115           0 : bool operator==(const Sinusoid& /*lhs*/, const Sinusoid& /*rhs*/);
     116             : 
     117           0 : bool operator!=(const Sinusoid& lhs, const Sinusoid& rhs);
     118             : }  // namespace AnalyticData
     119             : }  // namespace Burgers

Generated by: LCOV version 1.14