Solving wave equation with Leap-frog scheme#

Keywords: PDE:Wave Method:FEM FE:Lagrange Condition:Dirichlet Solver:Direct

So far, only the harmonic problems were considered. Time problem may also be solved using XLiFE++. But there is no specific tools dedicated to. Users have to implement the time loop related to the finite difference time scheme they choose.

As an example, consider the wave equation:

\[\begin{split}\begin{cases} \dfrac{\partial^2u}{\partial t^2}-c^2\Delta u = f & \mathrm{\;in\;} \Omega\times\left]0,T\right[\\ \dfrac{\partial u}{\partial n}=0 & \mathrm{\;in\;} \partial\Omega\times\left]0,T\right[\\ \displaystyle u(x,0)=\dfrac{\partial u}{\partial t}(x,0)=0 & \mathrm{\;in\;} \Omega \end{cases}\end{split}\]

Using classical leap-frog scheme with time discretization \(t^n=n\Delta t\), leads to (\(u^n\) approximates \(u(x,t^n)\)):

\[\begin{split}\begin{cases} u^{n+1}=2u^n-u^{n-1}+(c\Delta t)^2\Delta u^n+(\Delta t)^2f^n & \mathrm{\;in\;} \Omega,\ \forall n>1\\ \dfrac{\partial u^n}{\partial n}=0 & \mathrm{\;in\;} \partial\Omega,\ \forall n>1\\ u^0=u^1=0 & \mathrm{\;in\;} \Omega \end{cases}\end{split}\]

or, in variational form, \(\forall v\in V=H^1(\Omega)\):

\[\begin{split}\left\{ \begin{array}{l} \displaystyle \int_{\Omega}u^{n+1}v=2\int_{\Omega}u^{n}v-\int_{\Omega}u^{n-1}v-(c\Delta t)^2\int_{\Omega}\nabla u^n.\nabla v+(\Delta t)^2\int_{\Omega}f^n\,v\ \ \forall n>1 \\ u^0=u^1=0 \mathrm{\;in\;} \Omega \end{array} \right.\end{split}\]

When approximating space \(V\) by a finite dimension space \(V_h\) with basis \((w_i)_{i=1,p}\), the variational formulation is reinterpreted in terms of matrices and vectors as follows:

\[\begin{split}\left\{ \begin{array}{l} \displaystyle U^{n+1}=2U^n-U^{n-1}-\mathbb{M}^{-1}\left((c\Delta t)^2\mathbb{K} U^n-(\Delta t)^2F^n\right)\ \ \forall n>1\\ U^0=U^1=0 \mathrm{\;in\;} \Omega \end{array} \right.\end{split}\]

where

\[\mathbb{M}_{ij}=\int_{\Omega}w_iw_j,\ \mathbb{K}_{ij}=\int_{\Omega}\nabla w_i.\nabla w_j,\ (F^n)_i=\int_{\Omega}f^n\,w_i.\]

The XLiFE++ implementation of this scheme on the unity square when using P1 Lagrange interpolation looks like (\(f(x,t)=h(t)g(x)\)):

#include "xlife++.h"
using namespace xlifepp;

Real g(const Point& P, Parameters& pa = defaultParameters)
{
  Real d=P.distance(Point(0.5, 0.5));
  Real R= 0.02;        // source radius
  Real amp= 1./(pi_*R*R); // source amplitude (constant power)
  if (d<=0.02) return amp; else return 0.;
}

Real h(const Real& t)
{
  Real a=10000, t0=0.04 ; //gaussian slope and center
  return exp(-a*(t-t0)*(t-t0));
}

int main(int argc, char** argv)
{
  init(argc, argv, _lang=en);
  // create a mesh and domain omega
  SquareGeo sq(_origin=Point(0., 0.), _length=1, _nnodes=70);
  Mesh mesh2d(sq, _shape=triangle, _generator=structured);
  Domain omega=mesh2d.domain("Omega");
  // create interpolation
  Space V(_domain=omega, _interpolation=P1, _name="V");
  Unknown u(V, _name="u");
  TestFunction v(u, _name="v");
  // define FE terms
  TermMatrix A(intg(omega, grad(u)|grad(v)), _name="A"), M(intg(omega, u*v), _name="M");
  TermVector G(intg(omega, g*v), _name="G");
  TermMatrix L; ldltFactorize(M, L);
  // leap-frog scheme
  Real c=1, dt=0.004, dt2=dt*dt, cdt2=c*c*dt2;
  Number nbt=200;
  TermVectors U(nbt);  // to store solution at t=ndt
  TermVector zeros(u, omega, 0.);  U(1)=zeros;  U(2)=zeros;
  Real t=dt;
  for (Number n=2; n<nbt; n++, t+=dt)
  {
    U(n+1)=2.*U(n)-U(n-1)-factSolve(L, cdt2*(A*U(n))-dt2*h(t)*G);
  }
  saveToFile("U", U, vtu);
  return 0;
}

Note the very simple syntax taken into account the leap-frog scheme. The following figure represents the solution at different instants for a constant source localized in disk with center \((0.5,0.5)\), radius \(R=0.02\) and time excitation that is a Gaussian function. For chosen parameter \(dt=0.04\), the leap-frog scheme is stable (it satisfies the CFL condition) but dispersion effects obviously appear.

../_images/wave2d.png

Fig. 12 Solution of the wave equation at different instants for a constant source localized in disk with center \((0.5,0.5)\)#