Reference documentation for deal.II version Git 74a90b4 20180621 22:45:02 +0200

This tutorial depends on step24.
Table of contents  

This program grew out of a student project by Ivan Christov at Texas A&M University. Most of the work for this program is by him.
The goal of this program is to solve the sineGordon soliton equation in 1, 2 or 3 spatial dimensions. The motivation for solving this equation is that very little is known about the nature of the solutions in 2D and 3D, even though the 1D case has been studied extensively.
Rather facetiously, the sineGordon equation's moniker is a pun on the socalled KleinGordon equation, which is a relativistic version of the SchrÃ¶dinger equation for particles with nonzero mass. The resemblance is not just superficial, the sineGordon equation has been shown to model some unifiedfield phenomena such as interaction of subatomic particles (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 sineGordon equation is "completely integrable," it is a candidate for study using the usual methods such as the inverse scattering transform. Consequently, over the years, many interesting solitarywave, and even stationary, solutions to the sineGordon equation have been found. In these solutions, particles correspond to localized features. For more on the sineGordon equation, the inverse scattering transform and other methods for finding analytical soliton equations, the reader should consult the following "classical" references on the subject: G. L. Lamb's Elements of Soliton Theory (Chapter 5, Section 2) and G. B. Whitham's Linear and Nonlinear Waves (Chapter 17, Sections 1013).
The sineGordon initialboundaryvalue problem (IBVP) we wish to solve consists of the following equations:
\begin{eqnarray*} u_{tt}\Delta u &=& \sin(u) \quad\mbox{for}\quad (x,t) \in \Omega \times (t_0,t_f],\\ {\mathbf n} \cdot \nabla u &=& 0 \quad\mbox{for}\quad (x,t) \in \partial\Omega \times (t_0,t_f],\\ u(x,t_0) &=& u_0(x). \end{eqnarray*}
It is a nonlinear equation similar to the wave equation we discussed in step23 and step24. We have chosen to enforce zero Neumann boundary conditions in order for waves to reflect off the boundaries of our domain. It should be noted, however, that Dirichlet boundary conditions are not appropriate for this problem. Even though the solutions to the sineGordon equation are localized, it only makes sense to specify (Dirichlet) boundary conditions at \(x=\pm\infty\), otherwise either a solution does not exist or only the trivial solution \(u=0\) exists.
However, the form of the equation above is not ideal for numerical discretization. If we were to discretize the secondorder time derivative directly and accurately, then we would need a large stencil (i.e., several time steps would need to be kept in the memory), which could become expensive. Therefore, in complete analogy to what we did in step23 and step24, we split the secondorder (in time) sineGordon equation into a system of two firstorder (in time) equations, which we call the split, or velocity, formulation. To this end, by setting \(v = u_t\), it is easy to see that the sineGordon equation is equivalent to
\begin{eqnarray*} u_t  v &=& 0,\\ v_t  \Delta u &=& \sin(u). \end{eqnarray*}
Now, we can discretize the split formulation in time using the \(\theta\)method, which has a stencil of only two time steps. By choosing a \(\theta\in [0,1]\), the latter discretization allows us to choose from a continuum of schemes. In particular, if we pick \(\theta=0\) or \(\theta=1\), we obtain the firstorder accurate explicit or implicit Euler method, respectively. Another important choice is \(\theta=\frac{1}{2}\), which gives the secondorder accurate CrankNicolson scheme. Henceforth, a superscript \(n\) denotes the values of the variables at the \(n^{\mathrm{th}}\) time step, i.e. at \(t=t_n:= n k\), where \(k\) is the (fixed) time step size. Thus, the split formulation of the timediscretized sineGordon equation becomes
\begin{eqnarray*} \frac{u^n  u^{n1}}{k}  \left[\theta v^n + (1\theta) v^{n1}\right] &=& 0,\\ \frac{v^n  v^{n1}}{k}  \Delta\left[\theta u^n + (1\theta) u^{n1}\right] &=& \sin\left[\theta u^n + (1\theta) u^{n1}\right]. \end{eqnarray*}
We can simplify the latter via a bit of algebra. Eliminating \(v^n\) from the first equation and rearranging, we obtain
\begin{eqnarray*} \left[ 1k^2\theta^2\Delta \right] u^n &=& \left[ 1+k^2\theta(1\theta)\Delta\right] u^{n1} + k v^{n1}  k^2\theta\sin\left[\theta u^n + (1\theta) u^{n1}\right],\\ v^n &=& v^{n1} + k\Delta\left[ \theta u^n + (1\theta) u^{n1}\right]  k\sin\left[ \theta u^n + (1\theta) u^{n1} \right]. \end{eqnarray*}
It may seem as though we can just proceed to discretize the equations in space at this point. While this is true for the second equation (which is linear in \(v^n\)), this would not work for all \(\theta\) since the first equation above is nonlinear. Therefore, a nonlinear solver must be implemented, then the equations can be discretized in space and solved.
To this end, we can use Newton's method. Given the nonlinear equation \(F(u^n) = 0\), we produce successive approximations to \(u^n\) as follows:
\begin{eqnarray*} \mbox{ Find } \delta u^n_l \mbox{ s.t. } F'(u^n_l)\delta u^n_l = F(u^n_l) \mbox{, set } u^n_{l+1} = u^n_l + \delta u^n_l. \end{eqnarray*}
The iteration can be initialized with the old time step, i.e. \(u^n_0 = u^{n1}\), and eventually it will produce a solution to the first equation of the split formulation (see above). For the time discretization of the sineGordon equation under consideration here, we have that
\begin{eqnarray*} F(u^n_l) &=& \left[ 1k^2\theta^2\Delta \right] u^n_l  \left[ 1+k^2\theta(1\theta)\Delta\right] u^{n1}  k v^{n1} + k^2\theta\sin\left[\theta u^n_l + (1\theta) u^{n1}\right],\\ F'(u^n_l) &=& 1k^2\theta^2\Delta + k^2\theta^2\cos\left[\theta u^n_l + (1\theta) u^{n1}\right]. \end{eqnarray*}
Notice that while \(F(u^n_l)\) is a function, \(F'(u^n_l)\) is an operator.
With hindsight, we choose both the solution and the test space to be \(H^1(\Omega)\). Hence, multiplying by a test function \(\varphi\) and integrating, we obtain the following variational (or weak) formulation of the split formulation (including the nonlinear solver for the first equation) at each time step:
\begin{eqnarray*} &\mbox{ Find}& \delta u^n_l \in H^1(\Omega) \mbox{ s.t. } \left( F'(u^n_l)\delta u^n_l, \varphi \right)_{\Omega} = \left(F(u^n_l), \varphi \right)_{\Omega} \;\forall\varphi\in H^1(\Omega), \mbox{ set } u^n_{l+1} = u^n_l + \delta u^n_l,\; u^n_0 = u^{n1}.\\ &\mbox{ Find}& v^n \in H^1(\Omega) \mbox{ s.t. } \left( v^n, \varphi \right)_{\Omega} = \left( v^{n1}, \varphi \right)_{\Omega}  k\theta\left( \nabla u^n, \nabla\varphi \right)_{\Omega}  k (1\theta)\left( \nabla u^{n1}, \nabla\varphi \right)_{\Omega}  k\left(\sin\left[ \theta u^n + (1\theta) u^{n1} \right], \varphi \right)_{\Omega} \;\forall\varphi\in H^1(\Omega). \end{eqnarray*}
Note that the we have used integration by parts and the zero Neumann boundary conditions on all terms involving the Laplacian operator. Moreover, \(F(\cdot)\) and \(F'(\cdot)\) are as defined above, and \((\cdot,\cdot)_{\Omega}\) denotes the usual \(L^2\) inner product over the domain \(\Omega\), i.e. \((f,g)_{\Omega} = \int_\Omega fg \,\mathrm{d}x\). Finally, notice that the first equation is, in fact, the definition of an iterative procedure, so it is solved multiple times during each time step until a stopping criterion is met.
Using the Finite Element Method, we discretize the variational formulation in space. To this end, let \(V_h\) be a finitedimensional \(H^1(\Omega)\)conforming finite element space ( \(\mathrm{dim}\, V_h = N < \infty\)) with nodal basis \(\{\varphi_1,\ldots,\varphi_N\}\). Now, we can expand all functions in the weak formulation (see above) in terms of the nodal basis. Henceforth, we shall denote by a capital letter the vector of coefficients (in the nodal basis) of a function denoted by the same letter in lower case; e.g., \(u^n = \sum_{i=1}^N U^n_i \varphi_i\) where \(U^n \in {R}^N\) and \(u^n \in H^1(\Omega)\). Thus, the finitedimensional version of the variational formulation requires that we solve the following matrix equations at each time step:
\begin{eqnarray*} F_h'(U^{n,l})\delta U^{n,l} &=& F_h(U^{n,l}), \qquad U^{n,l+1} = U^{n,l} + \delta U^{n,l}, \qquad U^{n,0} = U^{n1}; \\ MV^n &=& MV^{n1}  k \theta AU^n k (1\theta) AU^{n1}  k S(u^n,u^{n1}). \end{eqnarray*}
Above, the matrix \(F_h'(\cdot)\) and the vector \(F_h(\cdot)\) denote the discrete versions of the gadgets discussed above, i.e.,
\begin{eqnarray*} F_h(U^{n,l}) &=& \left[ M+k^2\theta^2A \right] U^{n,l}  \left[ Mk^2\theta(1\theta)A \right] U^{n1}  k MV^{n1} + k^2\theta S(u^n_l, u^{n1}),\\ F_h'(U^{n,l}) &=& M+k^2\theta^2A + k^2\theta^2N(u^n_l,u^{n1}) \end{eqnarray*}
Again, note that the first matrix equation above is, in fact, the definition of an iterative procedure, so it is solved multiple times until a stopping criterion is met. Moreover, \(M\) is the mass matrix, i.e. \(M_{ij} = \left( \varphi_i,\varphi_j \right)_{\Omega}\), \(A\) is the Laplace matrix, i.e. \(A_{ij} = \left( \nabla \varphi_i, \nabla \varphi_j \right)_{\Omega}\), \(S\) is the nonlinear term in the equation that defines our auxiliary velocity variable, i.e. \(S_j(f,g) = \left( \sin\left[ \theta f + (1\theta) g\right], \varphi_j \right)_{\Omega}\), and \(N\) is the nonlinear term in the Jacobian matrix of \(F(\cdot)\), i.e. \(N_{ij}(f,g) = \left( \cos\left[ \theta f + (1\theta) g\right]\varphi_i, \varphi_j \right)_{\Omega}\).
What solvers can we use for the first equation? Let's look at the matrix we have to invert:
\[ (M+k^2\theta^2(A + N))_{ij} = \int_\Omega (1+k^2\theta^2 \cos \alpha) \varphi_i\varphi_j \; dx + k^2 \theta^2 \int_\Omega \nabla\varphi_i\nabla\varphi_j \; dx, \]
for some \(\alpha\) that depends on the present and previous solution. First, note that the matrix is symmetric. In addition, if the time step \(k\) is small enough, i.e. if \(k\theta<1\), then the matrix is also going to be positive definite. In the program below, this will always be the case, so we will use the Conjugate Gradient method together with the SSOR method as preconditioner. We should keep in mind, however, that this will fail if we happen to use a bigger time step. Fortunately, in that case the solver will just throw an exception indicating a failure to converge, rather than silently producing a wrong result. If that happens, then we can simply replace the CG method by something that can handle indefinite symmetric systems. The GMRES solver is typically the standard method for all "bad" linear systems, but it is also a slow one. Possibly better would be a solver that utilizes the symmetry, such as, for example, SymmLQ, which is also implemented in deal.II.
This program uses a clever optimization over step23 and step24: If you read the above formulas closely, it becomes clear that the velocity \(V\) only ever appears in products with the mass matrix. In step23 and step24, we were, therefore, a bit wasteful: in each time step, we would solve a linear system with the mass matrix, only to multiply the solution of that system by \(M\) again in the next time step. This can, of course, be avoided, and we do so in this program.
There are a few analytical solutions for the sineGordon equation, both in 1D and 2D. In particular, the program as is computes the solution to a problem with a single kinklike solitary wave initial condition. This solution is given by Leibbrandt in Phys. Rev. Lett. 41(7), and is implemented in the ExactSolution
class.
It should be noted that this closedform solution, strictly speaking, only holds for the infinitespace initialvalue problem (not the Neumann initialboundaryvalue problem under consideration here). However, given that we impose zero Neumann boundary conditions, we expect that the solution to our initialboundaryvalue problem would be close to the solution of the infinitespace initialvalue problem, if reflections of waves off the boundaries of our domain do not occur. In practice, this is of course not the case, but we can at least assume that this were so.
The constants \(\vartheta\) and \(\lambda\) in the 2D solution and \(\vartheta\), \(\phi\) and \(\tau\) in the 3D solution are called the Bäcklund transformation parameters. They control such things as the orientation and steepness of the kink. For the purposes of testing the code against the exact solution, one should choose the parameters so that the kink is aligned with the grid.
The solutions that we implement in the ExactSolution
class are these:
In 1D:
\[ u(x,t) = 4 \arctan\left[ \frac{m}{\sqrt{1m^2}} \frac{\sin\left(\sqrt{1m^2}t+c_2\right)} {\cosh\left(mx+c_1\right)} \right], \]
where we choose \(m=\frac 12, c_1=c_2=0\).
In 1D, more interesting analytical solutions are known. Many of them are listed on http://mathworld.wolfram.com/SineGordonEquation.html .
In 2D:
\[ u(x,y,t) = 4 \arctan \left[a_0 e^{s\xi}\right], \]
where \(\xi\) is defined as
\[ \xi = x \cos\vartheta + \sin(\vartheta) (y\cosh\lambda + t\sinh \lambda), \]
and where we choose \(\vartheta=\frac \pi 4, \lambda=a_0=s=1\).
\[ u(x,y,z,t) = 4 \arctan \left[c_0 e^{s\xi}\right], \]
where \(\xi\) is defined as\[ \xi = x \cos\vartheta + y \sin \vartheta \cos\phi + \sin \vartheta \sin\phi (z\cosh\tau + t\sinh \tau), \]
and where we choose \(\vartheta=\phi=\frac{\pi}{4}, \tau=c_1=s=1\).Since it makes it easier to play around, the InitialValues
class that is used to set — surprise! — the initial values of our simulation simply queries the class that describes the exact solution for the value at the initial time, rather than duplicating the effort to implement a solution function.
For an explanation of the include files, the reader should refer to the example programs step1 through step4. They are in the standard order, which is base
– lac
– grid
– dofs
– fe
– numerics
(since each of these categories roughly builds upon previous ones), then a few C++ headers for file input/output and string streams.
The last step is as in all previous programs:
SineGordonProblem
class templateThe entire algorithm for solving the problem is encapsulated in this class. As in previous example programs, the class is declared with a template parameter, which is the spatial dimension, so that we can solve the sineGordon equation in one, two or three spatial dimensions. For more on the dimensionindependent classencapsulation of the problem, the reader should consult step3 and step4.
Compared to step23 and step24, there isn't anything newsworthy in the general structure of the program (though there is of course in the inner workings of the various functions!). The most notable difference is the presence of the two new functions compute_nl_term
and compute_nl_matrix
that compute the nonlinear contributions to the system matrix and righthand side of the first equation, as discussed in the Introduction. In addition, we have to have a vector solution_update
that contains the nonlinear update to the solution vector in each Newton step.
As also mentioned in the introduction, we do not store the velocity variable in this program, but the mass matrix times the velocity. This is done in the M_x_velocity
variable (the "x" is intended to stand for "times").
Finally, the output_timestep_skip
variable stores the number of time steps to be taken each time before graphical output is to be generated. This is of importance when using fine meshes (and consequently small time steps) where we would run lots of time steps and create lots of output files of solutions that look almost the same in subsequent files. This only clogs up our visualization procedures and we should avoid creating more output than we are really interested in. Therefore, if this variable is set to a value \(n\) bigger than one, output is generated only every \(n\)th time step.
In the following two classes, we first implement the exact solution for 1D, 2D, and 3D mentioned in the introduction to this program. This spacetime solution may be of independent interest if one wanted to test the accuracy of the program by comparing the numerical against the analytic solution (note however that the program uses a finite domain, whereas these are analytic solutions for an unbounded domain). This may, for example, be done using the VectorTools::integrate_difference function. Note, again (as was already discussed in step23), how we describe spacetime functions as spatial functions that depend on a time variable that can be set and queried using the FunctionTime::set_time() and FunctionTime::get_time() member functions of the FunctionTime base class of the Function class.
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 above a second time. Rather, if we are queried for initial conditions, we create an object ExactSolution
, set it to the correct time, and let it compute whatever values the exact solution has at that time:
SineGordonProblem
classLet's move on to the implementation of the main class, as it implements the algorithm outlined in the introduction.
This is the constructor of the SineGordonProblem
class. It specifies the desired polynomial degree of the finite elements, associates a DoFHandler
to the triangulation
object (just as in the example programs step3 and step4), initializes the current or initial time, the final time, the time step size, and the value of \(\theta\) for the time stepping scheme. Since the solutions we compute here are timeperiodic, the actual value of the starttime doesn't matter, and we choose it so that we start at an interesting time.
Note that if we were to chose the explicit Euler time stepping scheme ( \(\theta = 0\)), then we must pick a time step \(k \le h\), otherwise the scheme is not stable and oscillations might arise in the solution. The CrankNicolson scheme ( \(\theta = \frac{1}{2}\)) and the implicit Euler scheme ( \(\theta=1\)) do not suffer from this deficiency, since they are unconditionally stable. However, even then the time step should be chosen to be on the order of \(h\) in order to obtain a good solution. Since we know that our mesh results from the uniform subdivision of a rectangle, we can compute that time step easily; if we had a different domain, the technique in step24 using GridTools::minimal_cell_diameter would work as well.
This function creates a rectangular grid in dim
dimensions and refines it several times. Also, all matrix and vector members of the SineGordonProblem
class are initialized to their appropriate sizes once the degrees of freedom have been assembled. Like step24, we use MatrixCreator
functions to generate a mass matrix \(M\) and a Laplace matrix \(A\) and store them in the appropriate variables for the remainder of the program's life.
This function assembles the system matrix and righthand side vector for each iteration of Newton's method. The reader should refer to the Introduction for the explicit formulas for the system matrix and righthand side.
Note that during each time step, we have to add up the various contributions to the matrix and right hand sides. In contrast to step23 and step24, this requires assembling a few more terms, since they depend on the solution of the previous time step or previous nonlinear step. We use the functions compute_nl_matrix
and compute_nl_term
to do this, while the present function provides the toplevel logic.
First we assemble the Jacobian matrix \(F'_h(U^{n,l})\), where \(U^{n,l}\) is stored in the vector solution
for convenience.
Next we compute the righthand side vector. This is just the combination of matrixvector products implied by the description of \(F_h(U^{n,l})\) in the introduction.
This function computes the vector \(S(\cdot,\cdot)\), which appears in the nonlinear term in both equations of the split formulation. This function not only simplifies the repeated computation of this term, but it is also a fundamental part of the nonlinear iterative solver that we use when the time stepping is implicit (i.e. \(\theta\ne 0\)). Moreover, we must allow the function to receive as input an "old" and a "new" solution. These may not be the actual solutions of the problem stored in old_solution
and solution
, but are simply the two functions we linearize about. For the purposes of this function, let us call the first two arguments \(w_{\mathrm{old}}\) and \(w_{\mathrm{new}}\) in the documentation of this class below, respectively.
As a sidenote, it is perhaps worth investigating what order quadrature formula is best suited for this type of integration. Since \(\sin(\cdot)\) is not a polynomial, there are probably no quadrature formulas that can integrate these terms exactly. It is usually sufficient to just make sure that the right hand side is integrated up to the same order of accuracy as the discretization scheme is, but it may be possible to improve on the constant in the asymptotic statement of convergence by choosing a more accurate quadrature formula.
Once we reinitialize our FEValues
instantiation to the current cell, we make use of the get_function_values
routine to get the values of the "old" data (presumably at \(t=t_{n1}\)) and the "new" data (presumably at \(t=t_n\)) at the nodes of the chosen quadrature formula.
Now, we can evaluate \(\int_K \sin\left[\theta w_{\mathrm{new}} + (1\theta) w_{\mathrm{old}}\right] \,\varphi_j\,\mathrm{d}x\) using the desired quadrature formula.
We conclude by adding up the contributions of the integrals over the cells to the global integral.
This is the second function dealing with the nonlinear scheme. It computes the matrix \(N(\cdot,\cdot)\), which appears in the nonlinear term in the Jacobian of \(F(\cdot)\). Just as compute_nl_term
, we must allow this function to receive as input an "old" and a "new" solution, which we again call \(w_{\mathrm{old}}\) and \(w_{\mathrm{new}}\) below, respectively.
Again, first we reinitialize our FEValues
instantiation to the current cell.
Then, we evaluate \(\int_K \cos\left[\theta w_{\mathrm{new}} + (1\theta) w_{\mathrm{old}}\right]\, \varphi_i\, \varphi_j\,\mathrm{d}x\) using the desired quadrature formula.
Finally, we add up the contributions of the integrals over the cells to the global integral.
As discussed in the Introduction, this function uses the CG iterative solver on the linear system of equations resulting from the finite element spatial discretization of each iteration of Newton's method for the (nonlinear) first equation of the split formulation. The solution to the system is, in fact, \(\delta U^{n,l}\) so it is stored in solution_update
and used to update solution
in the run
function.
Note that we reset the solution update to zero before solving for it. This is not necessary: iterative solvers can start from any point and converge to the correct solution. If one has a good estimate about the solution of a linear system, it may be worthwhile to start from that vector, but as a general observation it is a fact that the starting point doesn't matter very much: it has to be a very, very good guess to reduce the number of iterations by more than a few. It turns out that for this problem, using the previous nonlinear update as a starting point actually hurts convergence and increases the number of iterations needed, so we simply set it to zero.
The function returns the number of iterations it took to converge to a solution. This number will later be used to generate output on the screen showing how many iterations were needed in each nonlinear iteration.
This function outputs the results to a file. It is pretty much identical to the respective functions in step23 and step24:
This function has the toplevel control over everything: it runs the (outer) timestepping loop, the (inner) nonlinearsolver loop, and outputs the solution after each time step.
To acknowledge the initial condition, we must use the function \(u_0(x)\) to compute \(U^0\). To this end, below we will create an object of type InitialValues
; note that when we create this object (which is derived from the Function
class), we set its internal time variable to \(t_0\), to indicate that the initial condition is a function of space and time evaluated at \(t=t_0\).
Then we produce \(U^0\) by projecting \(u_0(x)\) onto the grid using VectorTools::project
. We have to use the same construct using hanging node constraints as in step21: the VectorTools::project function requires a hanging node constraints object, but to be used we first need to close it:
For completeness, we output the zeroth time step to a file just like any other time step.
Now we perform the time stepping: at every time step we solve the matrix equation(s) corresponding to the finite element discretization of the problem, and then advance our solution according to the time stepping formulas we discussed in the Introduction.
At the beginning of each time step we must solve the nonlinear equation in the split formulation via Newton's method — i.e. solve for \(\delta U^{n,l}\) then compute \(U^{n,l+1}\) and so on. The stopping criterion for this nonlinear iteration is that \(\F_h(U^{n,l})\_2 \le 10^{6} \F_h(U^{n,0})\_2\). Consequently, we need to record the norm of the residual in the first iteration.
At the end of each iteration, we output to the console how many linear solver iterations it took us. When the loop below is done, we have (an approximation of) \(U^n\).
Upon obtaining the solution to the first equation of the problem at \(t=t_n\), we must update the auxiliary velocity variable \(V^n\). However, we do not compute and store \(V^n\) since it is not a quantity we use directly in the problem. Hence, for simplicity, we update \(MV^n\) directly:
Oftentimes, in particular for fine meshes, we must pick the time step to be quite small in order for the scheme to be stable. Therefore, there are a lot of time steps during which "nothing interesting happens" in the solution. To improve overall efficiency – in particular, speed up the program and save disk space – we only output the solution every output_timestep_skip
time steps:
main
functionThis is the main function of the program. It creates an object of toplevel class and calls its principal function. If exceptions are thrown during the execution of the run method of the SineGordonProblem
class, we catch and report them here. For more information about exceptions the reader should consult step6.
The explicit Euler time stepping scheme ( \(\theta=0\)) performs adequately for the problems we wish to solve. Unfortunately, a rather small time step has to be chosen due to stability issues — \(k\sim h/10\) appears to work for most the simulations we performed. On the other hand, the CrankNicolson scheme ( \(\theta=\frac{1}{2}\)) is unconditionally stable, and (at least for the case of the 1D breather) we can pick the time step to be as large as \(25h\) without any ill effects on the solution. The implicit Euler scheme ( \(\theta=1\)) is "exponentially damped," so it is not a good choice for solving the sineGordon equation, which is conservative. However, some of the damped schemes in the continuum that is offered by the \(\theta\)method were useful for eliminating spurious oscillations due to boundary effects.
In the simulations below, we solve the sineGordon equation on the interval \(\Omega = [10,10]\) in 1D and on the square \(\Omega = [10,10]\times [10,10]\) in 2D. In each case, the respective grid is refined uniformly 6 times, i.e. \(h\sim 2^{6}\).
The first example we discuss is the socalled 1D (stationary) breather solution of the sineGordon equation. The breather has the following closedform expression, as mentioned in the Introduction:
\[ u_{\mathrm{breather}}(x,t) = 4\arctan \left(\frac{m}{\sqrt{1m^2}} \frac{\sin\left(\sqrt{1m^2}t +c_2\right)}{\cosh(mx+c_1)} \right), \]
where \(c_1\), \(c_2\) and \(m<1\) are constants. In the simulation below, we have chosen \(c_1=0\), \(c_2=0\), \(m=0.5\). Moreover, it is know that the period of oscillation of the breather is \(2\pi\sqrt{1m^2}\), hence we have chosen \(t_0=5.4414\) and \(t_f=2.7207\) so that we can observe three oscillations of the solution. Then, taking \(u_0(x) = u_{\mathrm{breather}}(x,t_0)\), \(\theta=0\) and \(k=h/10\), the program computed the following solution.
Though not shown how to do this in the program, another way to visualize the (1+1)d solution is to use output generated by the DataOutStack class; it allows to "stack" the solutions of individual time steps, so that we get 2D spacetime graphs from 1D timedependent solutions. This produces the spacetime plot below instead of the animation above.
Furthermore, since the breather is an analytical solution of the sineGordon equation, we can use it to validate our code, although we have to assume that the error introduced by our choice of Neumann boundary conditions is small compared to the numerical error. Under this assumption, one could use the VectorTools::integrate_difference function to compute the difference between the numerical solution and the function described by the ExactSolution
class of this program. For the simulation shown in the two images above, the \(L^2\) norm of the error in the finite element solution at each time step remained on the order of \(10^{2}\). Hence, we can conclude that the numerical method has been implemented correctly in the program.
The only analytical solution to the sineGordon equation in (2+1)D that can be found in the literature is the socalled kink solitary wave. It has the following closedform expression:
\[ u(x,y,t) = 4 \arctan \left[a_0 e^{s\xi}\right] \]
with
\[ \xi = x \cos\vartheta + \sin(\vartheta) (y\cosh\lambda + t\sinh \lambda) \]
where \(a_0\), \(\vartheta\) and \(\lambda\) are constants. In the simulation below we have chosen \(a_0=\lambda=1\). Notice that if \(\vartheta=\pi\) the kink is stationary, hence it would make a good solution against which we can validate the program in 2D because no reflections off the boundary of the domain occur.
The simulation shown below was performed with \(u_0(x) = u_{\mathrm{kink}}(x,t_0)\), \(\theta=\frac{1}{2}\), \(k=20h\), \(t_0=1\) and \(t_f=500\). The \(L^2\) norm of the error of the finite element solution at each time step remained on the order of \(10^{2}\), showing that the program is working correctly in 2D, as well as 1D. Unfortunately, the solution is not very interesting, nonetheless we have included a snapshot of it below for completeness.
Now that we have validated the code in 1D and 2D, we move to a problem where the analytical solution is unknown.
To this end, we rotate the kink solution discussed above about the \(z\) axis: we let \(\vartheta=\frac{\pi}{4}\). The latter results in a solitary wave that is not aligned with the grid, so reflections occur at the boundaries of the domain immediately. For the simulation shown below, we have taken \(u_0(x)=u_{\mathrm{kink}}(x,t_0)\), \(\theta=\frac{2}{3}\), \(k=20h\), \(t_0=0\) and \(t_f=20\). Moreover, we had to pick \(\theta=\frac{2}{3}\) because for any \(\theta\le\frac{1}{2}\) oscillations arose at the boundary, which are likely due to the scheme and not the equation, thus picking a value of \(\theta\) a good bit into the "exponentially damped" spectrum of the time stepping schemes assures these oscillations are not created.
Another interesting solution to the sineGordon equation (which cannot be obtained analytically) can be produced by using two 1D breathers to construct the following separable 2D initial condition:
\[ u_0(x) = u_{\mathrm{pseudobreather}}(x,t_0) = 16\arctan \left( \frac{m}{\sqrt{1m^2}} \frac{\sin\left(\sqrt{1m^2}t_0\right)}{\cosh(mx_1)} \right) \arctan \left( \frac{m}{\sqrt{1m^2}} \frac{\sin\left(\sqrt{1m^2}t_0\right)}{\cosh(mx_2)} \right), \]
where \(x=(x_1,x_2)\in{R}^2\), \(m=0.5<1\) as in the 1D case we discussed above. For the simulation shown below, we have chosen \(\theta=\frac{1}{2}\), \(k=10h\), \(t_0=5.4414\) and \(t_f=2.7207\). The solution is pretty interesting — it acts like a breather (as far as the pictures are concerned); however, it appears to break up and reassemble, rather than just oscillate.
It is instructive to change the initial conditions. Most choices will not lead to solutions that stay localized (in the soliton community, such solutions are called "stationary", though the solution does change with time), but lead to solutions where the wavelike character of the equation dominates and a wave travels away from the location of a localized initial condition. For example, it is worth playing around with the InitialValues
class, by replacing the call to the ExactSolution
class by something like this function:
\[ u_0(x,y) = \cos\left(\frac x2\right)\cos\left(\frac y2\right) \]
if \(x,y\le \frac\pi 2\), and \(u_0(x,y)=0\) outside this region.
A second area would be to investigate whether the scheme is energypreserving. For the pure wave equation, discussed in step23, this is the case if we choose the time stepping parameter such that we get the CrankNicolson scheme. One could do a similar thing here, noting that the energy in the sineGordon solution is defined as
\[ E(t) = \frac 12 \int_\Omega \left(\frac{\partial u}{\partial t}\right)^2 + \left(\nabla u\right)^2 + 2 (1\cos u) \; dx. \]
(We use \(1\cos u\) instead of \(\cos u\) in the formula to ensure that all contributions to the energy are positive, and so that decaying solutions have finite energy on unbounded domains.)
Beyond this, there are two obvious areas: