# Discrete wave simulation - absorbing boundaries?

I wrote a simple 2D wave simulation using the following equations: $$\frac{\partial^2 u}{\partial t^2}=c^2\nabla^2u$$ Where $\nabla^2$ is the discrete laplace operator using a Von Neumann neighborhood lattice.
$$\mathbf {D}^2_{xy} = \begin{bmatrix} 0 & 1 & 0 \\ 1 & -4 & 1 \\ 0 & 1 & 0 \end{bmatrix}$$ This gives the discrete formula: $$\Delta{}^t_{t+1}u_{x,y} - \Delta^{t}_{t-1}u_{x,y} = c^2(u_{x+1,y,t}+u_{x-1,y,t}+u_{x,y+1,t}+u_{x,y-1,t}-4u_{x,y,t})$$ Rearranging the terms gives the solution for the next timestep: $$u_{x,y,t+1} = c^2(u_{x+1,y,t}+u_{x-1,y,t}+u_{x,y+1,t}+u_{x,y-1,t}-4u_{x,y,t}) + \Delta^{t}_{t-1}u_{x,y} + u_{x,y,t}$$

This seems to work well, but I am currently taking $u=0$ when out of boundary. (which is apparently called the Dirichlet condition)

$$A_{m\times n}\\ \begin{cases} 0, & \text{if}\ (i<0) \lor (j<0) \lor (i\geq m) \lor (j\geq n) \\ A_{ij}, & \text{otherwise} \end{cases}$$

But according to the wave equation, that will make the boundaries act like walls, which waves can bounce on, like this:

Animated Example

But I cannot figure out how to make the boundaries "pass through" as if the grid were infinite. Other simulators do it, but I could not figure out the equations for it.

Example of a simulation that has absorbing boundaries, the waves do not reflect on the borders.

Is there a simple method that I can apply to my currently used equation? I don't need anything fancy, only something simple to apply and fast to compute.

• What is your domain? what are your boundary and initial conditions? – nicoguaro Apr 26 '17 at 16:50
• The initial conditions are arbitrary, a user can add or remove wave sources and walls at will, anytime. – Bloc97 Apr 26 '17 at 16:52
• if i understand you well, what you want are absorbing boundary conditions. there are some helpful posts on this website, see this one for example, and a bunch of useful web references. here's one and another to get the ball rolling. – GoHokies Apr 26 '17 at 18:14
• Thanks! That's exactly what I was looking for, but I didn't know what it was called. – Bloc97 Apr 26 '17 at 20:53
• Strictly speaking, there is no solution to this problem except in one space dimension, because waves that have passed through the boundary might always interact and send waves back. Therefore any attempt to impose a local boundary condition must exhibit some reflection. Nevertheless, some treatments are better than others. There has been a vast amount of work on this. A recent paper,Bogey, Christophe, and Christophe Bailly. "Three-dimensional non-reflective boundary conditions ..." Acta Acustica united with Acustica 88.4 (2002): 463-471." has a good bibliography of significant contributions. – Philip Roe Apr 27 '17 at 3:23

## Overview

First a few comments on absorbing boundaries: your second picture seems to imply that it's really the edges of your square which absorb the wave, but this is not quite true. Rather, one can consider your picture as in the following:

That is, you see only the excerpt of the full space in which the wave is considered as undisturbed. And outside of what you see is something happening. Most straightforwardly, that would be a grid large enough so that no reflections can occur. But depending on the parameters, this is numerically too costly.

For this case, one can apply "absorbing" techniques whose general idea is to make the solution vanish outside the region of interest, without changing the behavior inside (the outside boundary is here sketched as a circle, which might be more appropriate due to symmetry, but depending on your wave this doesn't have to be). In order to do so, a balance must be found between (i) having as little impact on the inner region as possible and (ii) an as small outer region as possible.

There are many different techniques to implement the absorbing which try to find such an appropriate balance, among them (complex) absorbing potential, complex exterior scaling, masking functions, etc. (see also the references in the comments).

## Masking functions / absorbing potentials

As the OP asked for a simple method, I would suggest to try a masking function: for this you apply a given function $\text{mask}(x,y)$ to your solution at each time step which is smaller than in the outside region $R_\text{out}$. A suitable function could be

$$f_\text{mask}(x,y) = \tanh^2\left(\lambda (R - \sqrt{x^2+y^2})\right)$$

where $R$ denotes the maximum radius on the grid and the parameter $\lambda$ determines the width of the mask which is to be tuned appropriately. Many other choices are possible here as well, e.g. a suitably streched quarter wavelength of a cosine, etc.

There are basically two alternatives how the masking function is applied. The simple version is to simply multiply the solution $u(x,y)$ by $\text{mask}(x,y)$ at each timestep. More sophisticated, one can include the logarithm of the masking function to the partial differential equation, $$\frac{\partial u}{\partial t}=v + \log(f_\text{mask}(x,y)) u\\ \frac{\partial v}{\partial t} = c^2\nabla^2u$$ Why the log? Because in the operator one needs something which is zero inside, and smaller than zero outside. The latter version is very similar to the (complex) absorbing potential technique.

Although there are more efficient methods available, imo nothing beats the conceptual simplicity of the masking approach.

EDIT: the previous applies to first-order-in-time PDEs, the kind of which I'm usually dealing with. For second order equations, represented as two first-order equations for the function and the temporal derivative, the absorbing potential must be applied only to the first equation corresponding to the function. The reason is that one does not want the derivative to be damped out, but the function value.

• This isn't very clear - how is the masking function applied to the solution? How is it absorbing anything? Aren't you distorting the solution field inside the domain? Do you have a reference perhaps? – DanielRch Apr 30 '17 at 18:24
• @DanielRch: (i) multiply the solution $v(x,y)$ at each time step by the masking function (or, a bit more sophisticated, add it to the linear operator driving your equation). (ii) As the latter is =1 inside and <1 outside the region of interest, and =0 at the boundary $R$, it will damp the wave outside. (iii) sure you are. But the goal is to choose a function which hardly does so. – davidhigh May 1 '17 at 12:06
• @DanielRch: (iv) There are not that many references, I suppose because it's rather unsophisticated. See here or here, for example. But it's very similar to the complex absorbing potential technique, for which one will find far more references (the difference is that the CAP technique uses $\exp(V(x))$ instead of $\text{mask}(x)$, with a potential $V(x)$ which is zero inside and negative outside the region of interest). – davidhigh May 1 '17 at 12:08
• I'd be interested in more references, specifically references that compare different damping mechanisms (masking function vs complex potential vs PML) – AlexE May 1 '17 at 18:41
• @AlexE: I think that's a too broad question, in general: there is no free lunch, and the damping functionality of a given function will heavily depend on the system parameters such as the outgoing energy. Many references also focus on more detailed questions, e.g. how to generate the spectrum even though the solution gets absorbed. However, in general, masking functions and absorbing potentials can be used anlogously as mentioned in my comment above. – davidhigh May 1 '17 at 19:33