This documentation is not for the latest stable Salvus version.
# initialize notebook
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
plt.rcParams["figure.figsize"] = (12, 8)
from salvus.mesh import mesh_block
# general input
max_x = 10000.0 # domain width in m
fmax = 2.0 # maximum frequency in Hz
elements_per_wavelength = 2.0
vs = 1000.0 # s-wave velocity in m / s
vp = 1700.0 # p-wave velocity in m / s
refine_x = 1.2 # extra security factor to make elements smaller before
refine_y = 1.2 # deformation
# compute edgelengths
hmax = vs / fmax / elements_per_wavelength
# create some artificial topography model - h(x)
nelem_x = int(np.ceil(max_x / hmax * refine_x))
h0 = 0.6
h1 = 0.5
h2 = -0.1
h3 = 0.15
x = np.linspace(0.0, max_x, nelem_x + 1)
norm_x = x / max_x * 2 * np.pi
h = (
h0
- h1 * np.cos(norm_x)
- h2 * np.cos(2 * norm_x)
- h3 * np.sin(3 * norm_x)
)
h = h * max_x / 2 / np.pi
# number of vertical elements needed for each element in horizontal direction
nelem_y = np.ceil(h / hmax * refine_y).astype("int")
# create box mesh with refinements
sg1 = mesh_block.generators.cartesian.rectangle_vertical_refine_doubling_2d(
nelem_x, nelem_y, min_x=0, max_x=max_x, min_y=0.0, max_y=np.max(h)
)
# make unstructured mesh
m1 = sg1.get_unstructured_mesh()
m1.find_side_sets("cartesian")
m1.plot(linewidths=1.0)
m1.add_dem_2D(x, h - np.max(h))
m1.apply_dem()
m1.plot(linewidths=1.0)
sg2 = mesh_block.generators.cartesian.rectangle_2d(
nelem_x, max(nelem_y), min_x=0, max_x=max_x, min_y=0.0, max_y=np.max(h)
)
m2 = sg2.get_unstructured_mesh()
m2.find_side_sets("cartesian")
m2.plot(linewidths=1.0)
m2.add_dem_2D(x, h - np.max(h))
m2.apply_dem()
m2.plot(linewidths=1.0)