This documentation is not for the latest stable Salvus version.
# set up the notebook
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
plt.rcParams["figure.figsize"] = (10, 8)
%%writefile three_layer.bm
NAME three_layer
UNITS km
COLUMNS depth rho vp vs
0.0 2.6 1.7 1.0
10.0 2.6 1.7 1.0
10.0 3.0 3.5 2.2
15.0 3.0 3.5 2.2
15.0 3.5 3.8 2.6
100.0 3.5 3.8 2.6
Writing three_layer.bm
from salvus.mesh.models_1D import model
model = model.read("three_layer.bm")
model.plot_vp_vs_profile(depth=True)
print(
"discontinuities:",
["{:.1f}".format(i) for i in model.discontinuities * model.scale],
)
print(
"element size: ",
[
"{:.1f}".format(i)
for i in model.get_edgelengths(
dominant_period=1.0, elements_per_wavelength=2
)
* model.scale
],
)
discontinuities: ['0.0', '85000.0', '90000.0', '100000.0'] element size: ['1300.0', '1100.0', '500.0']
frequency = 0.1 # maximum frequency in Hz
max_x = 200000.0 # Domain size in horizontal direction in m
hmax_refinement = (
1.5 # critertion to avoid refinements in thin layers, need to be > 1.0,
)
# default is 1.5, smaller value = more aggressive
refinement_style = "doubling" # 'doubling' or 'tripling'
refinement_top_down = True # True or False
ndim = 2 # 2 or 3
from salvus.mesh import mesh_block
if ndim == 2:
horizontal_boundaries = (np.array([0]), np.array([max_x / model.scale]))
elif ndim == 3:
horizontal_boundaries = (
np.array([0, 0]),
np.array([max_x / model.scale, max_x / model.scale]),
)
sk = mesh_block.generators.cartesian.mesh_block_collection(
model.discontinuities,
model.get_edgelengths(1.0 / frequency),
hmax_refinement=hmax_refinement,
horizontal_boundaries=horizontal_boundaries,
refinement_top_down=refinement_top_down,
refinement_style=refinement_style,
ndim=ndim,
)
m = sk.get_unstructured_mesh()
m.find_side_sets(mode="cartesian")
m
<salvus.mesh.unstructured_mesh.UnstructuredMesh at 0x7f15f561f190>
m.plot_quality("equiangular_skewness")
m.attach_field(
"equiangular_skewness", m.compute_mesh_quality("equiangular_skewness")
)
m