This documentation is not for the latest stable Salvus version.
%matplotlib inline
from pathlib import Path
import h5py
import matplotlib.pyplot as plt
import numpy as np
import os
import salvus.mesh.unstructured_mesh as um
from salvus.flow import api
from salvus.flow import simple_config as sc
from typing import List
SALVUS_FLOW_SITE_NAME = os.environ.get("SITE_NAME", "local")
def get_basic_source(
*, frequency: float, physics: str, location: List
) -> sc.source:
"""Gets a simple physics- and dimension-dependent source.
Args:
frequency: Center frequency of the (Ricker) wavelet.
physics: Physics of the source.
location: Location of the source.
Returns:
SalvusFlow source object appropriate for the specified physics.
"""
l = location
src = sc.source.cartesian
s = sc.stf.Ricker(center_frequency=frequency)
if physics == "acoustic":
return src.ScalarPoint3D(
x=l[0], y=l[1], z=l[2], f=1, source_time_function=s
)
return src.VectorPoint3D(
x=l[0], y=l[1], z=l[2], fx=1.0, fy=1.0, fz=0.0, source_time_function=s
)
# Read mesh from Exodus file.
mesh = um.UnstructuredMesh.from_exodus("./data/glass.e")
# Find the surface of mesh.
mesh.find_surface(side_set_name="surface")
# Mark simulation as elastic.
mesh.attach_field("fluid", np.zeros(mesh.nelem))
# Attach parameters.
pars = {"VP": 5800, "VS": 4000, "RHO": 2600}
template = np.ones_like(mesh.get_element_nodes()[:, :, 0])
for key, value in pars.items():
mesh.attach_field(key, template * value)
# Visualize.
mesh
<salvus.mesh.unstructured_mesh.UnstructuredMesh at 0x7f5218dea4d0>
# Set up simulation.
w = sc.simulation.Waveform(
mesh=mesh,
sources=get_basic_source(
frequency=100.0, physics="elastic", location=[0, 0, 70]
<