Skip to content

Commit

Permalink
Merge pull request #240 from PrincetonUniversity/issue-213
Browse files Browse the repository at this point in the history
Issue 213
  • Loading branch information
Rohit-Kakodkar authored Dec 9, 2024
2 parents af102bc + 264afde commit 0e55182
Show file tree
Hide file tree
Showing 16 changed files with 1,087 additions and 3,460 deletions.
4 changes: 4 additions & 0 deletions examples/Tromp_2005/CMakeFiles/Snakefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ rule plot_kernels:
run:
from plot import plot_kernels

# Set matplotlib gui off
import matplotlib
matplotlib.use("Agg")

plot_kernels(input.kernels, output.plot)


Expand Down
2 changes: 2 additions & 0 deletions examples/fluid-solid-bathymetry/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
specfem_config.yaml
Par_File
line_sources.yaml
__pycache__
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ parameters:
Interfaces : Acoustic-elastic interface (1) (orientation horizontal with acoustic domain on top)
Sources : Moment-tensor (234)
Boundary conditions : Neumann BCs on all edges
Debugging comments: This tests checks coupling acoustic-elastic interface implementation.
The orientation of the interface is horizontal with acoustic domain on top.

simulation-setup:
## quadrature setup
Expand All @@ -31,7 +29,7 @@ parameters:
writer:
seismogram:
format: ascii
directory: @CMAKE_SOURCE_DIR@/examples/fluid-solid-bathymetry/OUTPUT_FILES/seismograms
directory: @CMAKE_SOURCE_DIR@/examples/fluid-solid-bathymetry/OUTPUT_FILES/results

display:
format: PNG
Expand All @@ -44,7 +42,6 @@ parameters:
stations-file: @CMAKE_SOURCE_DIR@/examples/fluid-solid-bathymetry/OUTPUT_FILES/STATIONS
angle: 0.0
seismogram-type:
- displacement
- pressure
nstep_between_samples: 10

Expand Down
39 changes: 39 additions & 0 deletions examples/fluid-solid-bathymetry/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Wave propagration through fluid-solid interface

This example simulates a tele-seismic plane wave within a fluid-solid domain. This example is contributed by Sirawich Pipatprathanporn and is part of the publication [Pipatprathanporn et al. (2024)](https://doi.org/10.1093/gji/ggae238)

## Running the examples

To run the examples, you first need to install poetry following these [instructions](https://python-poetry.org/docs/#installation). Once you've done so, you can install the dependencies for the examples by running the following command in the current directory:

```bash
# verify poetry is installed
poetry --version

# install dependencies
poetry install

```

After installing the dependencies, you can run the examples by running the following command within the example directory you want to run:

```bash

# run the example
poetry run snakemake -j 1

# or to run the example on a slurm cluster
poetry run snakemake --executor slurm -j 1

```

## Cleaning up

To clean up the example directory, you can run the following command in the directory of the example you want to clean up:

```bash

# clean up the example
poetry run snakemake clean

```
134 changes: 134 additions & 0 deletions examples/fluid-solid-bathymetry/Snakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
SPECFEM_BIN = "specfem2d"
MESHFEM_BIN = "xmeshfem2D"


rule all:
input:
plot="OUTPUT_FILES/results/plot.png",
localrule: True

rule generate_mesh:
input:
"Par_File",
output:
database="OUTPUT_FILES/database.bin",
stations="OUTPUT_FILES/STATIONS",
localrule: True
shell:
"""
mkdir -p OUTPUT_FILES
{MESHFEM_BIN} -p {input}
"""

rule generate_line_sources:
input:
jinja_file = "line_sources.yaml.j2",
jinja_variables = "jinja_variables.yaml",
output:
source_file = "line_sources.yaml",
localrule: True
run:
import jinja2
import yaml

def generate_sources():
# read jinja2 variables yaml file
with open(input.jinja_variables, 'r') as f:
jinja_vars = yaml.safe_load(f)

with open(input.jinja_file, 'r') as f:
template = jinja2.Template(f.read())

variables = jinja_vars['variables']
with open(output.source_file, 'w') as f:
f.write(template.render(variables))

generate_sources()

rule run_simulation:
input:
database="OUTPUT_FILES/database.bin",
stations="OUTPUT_FILES/STATIONS",
line_sources="line_sources.yaml",
specfem_config="specfem_config.yaml",
output:
pressure_siesmograms=expand(
"OUTPUT_FILES/results/{station_name}{network_name}{component}.semp",
station_name=[
"S0001",
"S0002",
],
network_name=["AA"],
component=["PRE"],
),
resources:
nodes=1,
tasks=1,
cpus_per_task=1,
runtime=40,
shell:
"""
module purge
module load boost/1.73.0
mkdir -p OUTPUT_FILES/results
mkdir -p OUTPUT_FILES/display
echo "Hostname: $(hostname)" > output.log
{SPECFEM_BIN} -p {input.specfem_config} >> output.log
"""

rule plot_seismogram:
input:
pressure_siesmograms=expand(
"OUTPUT_FILES/results/{station_name}{network_name}{component}.semp",
station_name=[
"S0001",
"S0002",
],
network_name=["AA"],
component=["PRE"],
),
output:
traces="OUTPUT_FILES/results/plot.png",
localrule: True
run:
import glob
import os
import numpy as np
import obspy

# Set matplotlib gui off
import matplotlib
matplotlib.use("Agg")

def get_traces(directory):
traces = []
files = glob.glob(directory + "/*.sem*")
## iterate over all seismograms
for filename in files:
station_name = os.path.splitext(filename)[0]
station_name = station_name.split("/")[-1]
trace = np.loadtxt(filename, delimiter=" ")
starttime = trace[0, 0]
dt = trace[1, 0] - trace[0, 0]
traces.append(
obspy.Trace(
trace[:, 1],
{"network": station_name, "starttime": starttime, "delta": dt},
)
)

stream = obspy.Stream(traces)

return stream


stream = get_traces("OUTPUT_FILES/results")
stream.plot(size=(800, 1000)).savefig(output.traces)

rule clean:
localrule: True
shell:
"""
rm -rf OUTPUT_FILES
rm -f line_sources.yaml
"""
4 changes: 4 additions & 0 deletions examples/fluid-solid-bathymetry/jinja_variables.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

variables:
number_of_sources_x: 197
number_of_sources_z: 37
Loading

0 comments on commit 0e55182

Please sign in to comment.