# \[ParallelStencil\] Boundary Conditions

**URL:** <https://discourse.julialang.org/t/parallelstencil-boundary-conditions/70171>\
**Category:** Modelling & Simulations\
**Created:** [October 21, 2021, 6:54pm UTC](https://discourse.julialang.org/t/parallelstencil-boundary-conditions/70171 "2021-10-21T18:54:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![apattyn](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@apattyn](https://discourse.julialang.org/u/apattyn)\
**Post date:** [October 21, 2021, 6:54pm UTC](https://discourse.julialang.org/t/parallelstencil-boundary-conditions/70171/1 "2021-10-21T18:54:04Z")

</div>

I was taking a look at the [acoustic apps](https://github.com/omlins/ParallelStencil.jl/blob/main/miniapps/acoustic2D.jl), and I was able to modify it to include a time-varying pressure source.

![acoustic2D](https://global.discourse-cdn.com/julialang/original/3X/f/8/f8b5a3deca46d9bf3684647d2d5e8ebe245f32eb.gif)

However, I can’t quite figure out how to prevent back reflections from the boundary. Is it possible to make the boundary absorptive?

---

<div class="post-metadata">

**Author:** ![luraess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/luraess/32/16189_2.png) [@luraess](https://discourse.julialang.org/u/luraess)\
**Post date:** [October 21, 2021, 9:26pm UTC](https://discourse.julialang.org/t/parallelstencil-boundary-conditions/70171/2 "2021-10-21T21:26:08Z")

</div>

Great you managed to enhance the wave code with a time-varying pressure source.

> how to prevent back reflections from the boundary

Modelling wave propagation often requires implementing some kind of absorptive layers in order to avoid reflection artefacts at boundaries. This is a specific domain science related issue and thus not exposed as a ready to use solution from within ParallelStencil.

Various approaches exist to implement absorptive boundaries, among those the [perfectly matched layer](https://en.wikipedia.org/wiki/Perfectly_matched_layer) (PML) and the less accurate/fancy “sponge” boundaries. You can find [here](https://bitbucket.org/lraess/grfs_extras/src/78798586793bfb68b212c92688651ddcc93de52f/GRFS_routines_wave/wave_3D_rnd_1.m#lines-85) an implementations of the latter; unfortunately no Julia code (then); [CUDA C](https://bitbucket.org/lraess/grfs_extras/src/78798586793bfb68b212c92688651ddcc93de52f/GRFS_routines_wave/GPU_Wave_3D_v5.cu#lines-126) and [Matlab](https://bitbucket.org/lraess/grfs_extras/src/78798586793bfb68b212c92688651ddcc93de52f/GRFS_routines_wave/wave_3D_rnd_1.m#lines-85) only. The CUDA C version could though easily be ported to ParallelStencil using the `@parallel_indices` notation.

---

<div class="post-metadata">

**Author:** ![apattyn](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@apattyn](https://discourse.julialang.org/u/apattyn)\
**Post date:** [October 22, 2021, 1:22am UTC](https://discourse.julialang.org/t/parallelstencil-boundary-conditions/70171/3 "2021-10-22T01:22:55Z")

</div>

Thanks, I know a popular toolbox used in my field - [k-wave](http://www.k-wave.org/), uses a PML. I thought that was primary due to them using a spectral method to solve the acoustic wave equation though. I wasn’t sure if a hacky solution of just setting the pressure at the edges to zeros constantly would be feasible.

But once I include acoustic attenuation it should be relatively easy to implement a PML - hopefully 😅

But thank you for the hints relating to “sponge” boundaries!
