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:

{2ut2c2Δu=finΩ×]0,T[un=0inΩ×]0,T[u(x,0)=ut(x,0)=0inΩ

Using classical leap-frog scheme with time discretization tn=nΔt, leads to (un approximates u(x,tn)):

{un+1=2unun1+(cΔt)2Δun+(Δt)2fninΩ, n>1unn=0inΩ, n>1u0=u1=0inΩ

or, in variational form, vV=H1(Ω):

{Ωun+1v=2ΩunvΩun1v(cΔt)2Ωun.v+(Δt)2Ωfnv  n>1u0=u1=0inΩ

When approximating space V by a finite dimension space Vh with basis (wi)i=1,p, the variational formulation is reinterpreted in terms of matrices and vectors as follows:

{Un+1=2UnUn1M1((cΔt)2KUn(Δt)2Fn)  n>1U0=U1=0inΩ

where

Mij=Ωwiwj, Kij=Ωwi.wj, (Fn)i=Ωfnwi.

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)#