Skip to content

Commit

Permalink
examples: improved fs only check z derivs
Browse files Browse the repository at this point in the history
  • Loading branch information
mloubout committed Apr 3, 2024
1 parent 14dd726 commit 8172aab
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/pytest-core-mpi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,3 @@ jobs:
- name: Test with pytest
run: |
docker run --rm -e CODECOV_TOKEN=${{ secrets.CODECOV_TOKEN }} -e OMP_NUM_THREADS=1 --name testrun devito_img pytest tests/test_mpi.py
- name: Test examples with MPI
run: |
docker run --rm -e DEVITO_MPI=1 -e OMP_NUM_THREADS=1 --name examplerun devito_img mpiexec -n 2 pytest examples/seismic/acoustic
docker run --rm -e DEVITO_MPI=1 -e OMP_NUM_THREADS=1 --name examplerun devito_img mpiexec -n 2 pytest examples/seismic/tti
27 changes: 21 additions & 6 deletions examples/seismic/acoustic/operators.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from devito import Eq, Operator, Function, TimeFunction, Inc, solve, sign
from devito.symbolics import retrieve_functions, INT
from devito.symbolics import retrieve_functions, INT, retrieve_derivatives


def freesurface(model, eq):
Expand All @@ -14,13 +14,21 @@ def freesurface(model, eq):
eq : Eq
Time-stepping stencil (time update) to mirror at the freesurface.
"""
lhs, rhs = eq.evaluate.args
lhs, rhs = eq.args
# Get vertical dimension and corresponding subdimension
zfs = model.grid.subdomains['fsdomain'].dimensions[-1]
fsdomain = model.grid.subdomains['fsdomain']
zfs = fsdomain.dimensions[-1]
z = zfs.parent

# Functions present in the stencil
funcs = retrieve_functions(rhs)
# Retrieve vertical derivatives
Dz = {d for d in retrieve_derivatives(rhs) if z in d.dims}
# Remove inner duplicate
Dz = Dz - {d for D in Dz for d in retrieve_derivatives(D.expr) if z in d.dims}
Dz = {d: d._eval_at(lhs).evaluate for d in Dz}

# Finally get functions for evaluated derivatives
funcs = {f for f in retrieve_functions(Dz.values())}

mapper = {}
# Antisymmetric mirror at negative indices
# TODO: Make a proper "mirror_indices" tool function
Expand All @@ -29,7 +37,14 @@ def freesurface(model, eq):
if (zind - z).as_coeff_Mul()[0] < 0:
s = sign(zind.subs({z: zfs, z.spacing: 1}))
mapper.update({f: s * f.subs({zind: INT(abs(zind))})})
return Eq(lhs, rhs.subs(mapper), subdomain=model.grid.subdomains['fsdomain'])

# Mapper for vertical derivatives
dzmapper = {d: v.subs(mapper) for d, v in Dz.items()}

fs_eq = [eq.func(lhs, rhs.subs(dzmapper), subdomain=fsdomain)]
fs_eq.append(eq.func(lhs._subs(z, 0), 0, subdomain=fsdomain))

return fs_eq


def laplacian(field, model, kernel):
Expand Down

0 comments on commit 8172aab

Please sign in to comment.