Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate required files for examples/Tromp2005 from CMake #393

Open
wants to merge 1 commit into
base: issue-228-anisotropy
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions examples/Tromp_2005/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ OUTPUT_FILES/*
*.semd
*.adj
Par_File
Snakefile
*.pyc
forward_source.yaml
forward_config.yaml
adjoint_source.yaml
adjoint_config.yaml
Original file line number Diff line number Diff line change
@@ -1,40 +1,52 @@
parameters:

databases:
mesh-database: "@CMAKE_SOURCE_DIR@/examples/Tromp_2005/OUTPUT_FILES/database.bin"
source-file: "@CMAKE_SOURCE_DIR@/examples/Tromp_2005/adjoint_source.yaml"
header:
title: "Tromp-Tape-Liu (GJI 2005)"
description: |
Material systems : Elastic domain (1)
description: 'Material systems : Elastic domain (1)

Interfaces : None

Sources : Force source (1)

Boundary conditions : Free surface (1)

Mesh : 2D Cartesian grid (1)

Receiver : Displacement seismogram (1)

Output : Wavefield at the last time step (1)

Output : Seismograms in ASCII format (1)

'
title: Tromp-Tape-Liu (GJI 2005)
receivers:
angle: 0.0
nstep_between_samples: 1
seismogram-type:
- displacement
stations-file: placeholder/for/path/to/STATIONS
run-setup:
number-of-processors: 1
number-of-runs: 1
simulation-setup:
quadrature:
quadrature-type: GLL4

simulation-mode:
combined:
reader:
wavefield:
directory: "@CMAKE_SOURCE_DIR@/examples/Tromp_2005/OUTPUT_FILES"
format: HDF5
writer:
kernels:
directory: "@CMAKE_SOURCE_DIR@/examples/Tromp_2005/OUTPUT_FILES"
format: ASCII
solver:
time-marching:
time-scheme:
type: Newmark
dt: 0.02
nstep: 2004
t0: 8.0

receivers:
stations-file: placeholder/for/path/to/STATIONS
angle: 0.0
seismogram-type:
- displacement
nstep_between_samples: 1

run-setup:
number-of-processors: 1
number-of-runs: 1

databases:
mesh-database: placeholder/for/path/to/database.bin
source-file: placeholder/for/path/to/source.yaml
type: Newmark
51 changes: 51 additions & 0 deletions examples/Tromp_2005/CMakeFiles/forward_config.yaml.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
parameters:
databases:
mesh-database: "@CMAKE_SOURCE_DIR@/examples/Tromp_2005/OUTPUT_FILES/database.bin"
source-file: "@CMAKE_SOURCE_DIR@/examples/Tromp_2005/forward_source.yaml"
header:
description: 'Material systems : Elastic domain (1)

Interfaces : None

Sources : Force source (1)

Boundary conditions : Free surface (1)

Mesh : 2D Cartesian grid (1)

Receiver : Displacement seismogram (1)

Output : Wavefield at the last time step (1)

Output : Seismograms in ASCII format (1)

'
title: Tromp-Tape-Liu (GJI 2005)
receivers:
angle: 0.0
nstep_between_samples: 1
seismogram-type:
- displacement
stations-file: "@CMAKE_SOURCE_DIR@/examples/Tromp_2005/OUTPUT_FILES/STATIONS"
run-setup:
number-of-processors: 1
number-of-runs: 1
simulation-setup:
quadrature:
quadrature-type: GLL4
simulation-mode:
forward:
writer:
seismogram:
directory: "@CMAKE_SOURCE_DIR@/examples/Tromp_2005/OUTPUT_FILES/results"
format: ASCII
wavefield:
directory: "@CMAKE_SOURCE_DIR@/examples/Tromp_2005/OUTPUT_FILES"
format: HDF5
solver:
time-marching:
time-scheme:
dt: 0.02
nstep: 2004
t0: 8.0
type: Newmark
3 changes: 2 additions & 1 deletion examples/Tromp_2005/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.17.5)

configure_file(CMakeFiles/Par_File.in ${CMAKE_SOURCE_DIR}/examples/Tromp_2005/Par_File)
configure_file(CMakeFiles/Snakefile.in ${CMAKE_SOURCE_DIR}/examples/Tromp_2005/Snakefile)
configure_file(CMakeFiles/forward_config.yaml.in ${CMAKE_SOURCE_DIR}/examples/Tromp_2005/forward_config.yaml)
configure_file(CMakeFiles/adjoint_config.yaml.in ${CMAKE_SOURCE_DIR}/examples/Tromp_2005/adjoint_config.yaml)
126 changes: 126 additions & 0 deletions examples/Tromp_2005/Snakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
SPECFEM_BIN = "specfem2d"
MESHFEM_BIN = "xmeshfem2D"
ADJ_SEISMOGRAM_BIN = "xadj_seismogram"


rule all:
input:
kernels="OUTPUT_FILES/Kernels.png",


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 forward_simulation:
input:
database="OUTPUT_FILES/database.bin",
stations="OUTPUT_FILES/STATIONS",
source="forward_source.yaml",
config="forward_config.yaml",
output:
siesmograms=expand(
"OUTPUT_FILES/results/{station_name}{network_name}{component}.semd",
station_name=["S0001"],
network_name=["AA"],
component=["BXX", "BXZ"],
),
forward_wavefield="OUTPUT_FILES/ForwardWavefield.h5",
resources:
nodes=1,
tasks=1,
cpus_per_task=1,
runtime=10,
shell:
"""
# module purge
# module load boost/1.73.0
mkdir -p OUTPUT_FILES/results
echo "Hostname: $(hostname)" > output.log
{SPECFEM_BIN} -p {input.config} >> output.log
"""


rule compute_adjoint_sources:
input:
seismograms=expand(
"OUTPUT_FILES/results/{station_name}{network_name}{component}.semd",
station_name=["S0001"],
network_name=["AA"],
component=["BXX", "BXZ"],
),
output:
adjoint_sources=expand(
"adjoint_sources/{station_name}{network_name}.{component}.adj",
station_name=["S0001"],
network_name=["AA"],
component=["BXX", "BXZ"],
),
shell:
"""
mkdir -p adjoint_sources
echo "Hostname: $(hostname)" > output.log
{ADJ_SEISMOGRAM_BIN} 27.0 32.0 S0001AA OUTPUT_FILES/results/ adjoint_sources/ 1
"""


rule adjoint_simulation:
input:
database="OUTPUT_FILES/database.bin",
stations="OUTPUT_FILES/STATIONS",
source="adjoint_source.yaml",
config="adjoint_config.yaml",
adjoint_sources=expand(
"adjoint_sources/{station_name}{network_name}.{component}.adj",
station_name=["S0001"],
network_name=["AA"],
component=["BXX", "BXZ"],
),
output:
kernels=directory("OUTPUT_FILES/Kernels"),
resources:
nodes=1,
tasks=1,
cpus_per_task=1,
runtime=10,
shell:
"""
# module purge
# module load boost/1.73.0
mkdir -p OUTPUT_FILES/results
echo "Hostname: $(hostname)" > output.log
{SPECFEM_BIN} -p {input.config} >> output.log
"""


rule plot_kernels:
input:
kernels="OUTPUT_FILES/Kernels",
plot_script="plot.py",
output:
plot="OUTPUT_FILES/Kernels.png",
run:
from plot import plot_kernels

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

plot_kernels(input.kernels, output.plot)


rule clean:
shell:
"""
rm -rf OUTPUT_FILES adjoint_sources
"""
27 changes: 27 additions & 0 deletions examples/Tromp_2005/adjoint_source.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
number-of-sources: 2
sources:
- force:
Ricker:
f0: 0.42
factor: 7500000000.0
tshift: 0.0
angle: 270.0
source_surf: false
vx: 0.0
vz: 0.0
x: 50000
z: 40000
- adjoint-source:
External:
format: ASCII
stf:
X-component: adjoint_sources/S0001AA.BXX.adj
Z-component: adjoint_sources/S0001AA.BXZ.adj
angle: 0.0
network_name: S0001
source-surf: false
station_name: AA
vx: 0.0
vz: 0.0
x: 150000.0
z: 40000.0
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ rule forward_configuration:
"writer": {
"wavefield": {
"format": "HDF5",
"directory": "@CMAKE_SOURCE_DIR@/examples/Tromp_2005/OUTPUT_FILES",
"directory": "/Users/ccui/Documents/SPECFEMPP/examples/Tromp_2005/examples/Tromp_2005/OUTPUT_FILES",
},
"seismogram": {
"format": "ASCII",
"directory": "@CMAKE_SOURCE_DIR@/examples/Tromp_2005/OUTPUT_FILES/results",
"directory": "/Users/ccui/Documents/SPECFEMPP/examples/Tromp_2005/examples/Tromp_2005/OUTPUT_FILES/results",
},
}
}
Expand All @@ -56,9 +56,9 @@ rule forward_configuration:

## Add forward node to the simulation setup
config["parameters"]["simulation-setup"].update(forward)
config["parameters"]["databases"]["source-file"] = "@CMAKE_SOURCE_DIR@/examples/Tromp_2005/forward_source.yaml"
config["parameters"]["receivers"]["stations-file"] = "@CMAKE_SOURCE_DIR@/examples/Tromp_2005/OUTPUT_FILES/STATIONS"
config["parameters"]["databases"]["mesh-database"] = "@CMAKE_SOURCE_DIR@/examples/Tromp_2005/OUTPUT_FILES/database.bin"
config["parameters"]["databases"]["source-file"] = "/Users/ccui/Documents/SPECFEMPP/examples/Tromp_2005/examples/Tromp_2005/forward_source.yaml"
config["parameters"]["receivers"]["stations-file"] = "/Users/ccui/Documents/SPECFEMPP/examples/Tromp_2005/examples/Tromp_2005/OUTPUT_FILES/STATIONS"
config["parameters"]["databases"]["mesh-database"] = "/Users/ccui/Documents/SPECFEMPP/examples/Tromp_2005/examples/Tromp_2005/OUTPUT_FILES/database.bin"

with open(output.config, "w") as f:
yaml.safe_dump(config, f)
Expand Down Expand Up @@ -140,13 +140,13 @@ rule adjoint_configuration:
"writer": {
"kernels": {
"format": "ASCII",
"directory": "@CMAKE_SOURCE_DIR@/examples/Tromp_2005/OUTPUT_FILES",
"directory": "/Users/ccui/Documents/SPECFEMPP/examples/Tromp_2005/examples/Tromp_2005/OUTPUT_FILES",
}
},
"reader": {
"wavefield": {
"format": "HDF5",
"directory": "@CMAKE_SOURCE_DIR@/examples/Tromp_2005/OUTPUT_FILES",
"directory": "/Users/ccui/Documents/SPECFEMPP/examples/Tromp_2005/examples/Tromp_2005/OUTPUT_FILES",
}
},
}
Expand All @@ -158,8 +158,8 @@ rule adjoint_configuration:

## Add adjoint node to the simulation setup
config["parameters"]["simulation-setup"].update(adjoint)
config["parameters"]["databases"]["source-file"] = "@CMAKE_SOURCE_DIR@/examples/Tromp_2005/adjoint_source.yaml"
config["parameters"]["databases"]["mesh-database"] = "@CMAKE_SOURCE_DIR@/examples/Tromp_2005/OUTPUT_FILES/database.bin"
config["parameters"]["databases"]["source-file"] = "/Users/ccui/Documents/SPECFEMPP/examples/Tromp_2005/examples/Tromp_2005/adjoint_source.yaml"
config["parameters"]["databases"]["mesh-database"] = "/Users/ccui/Documents/SPECFEMPP/examples/Tromp_2005/examples/Tromp_2005/OUTPUT_FILES/database.bin"

with open(output.config, "w") as f:
yaml.safe_dump(config, f)
Expand Down
13 changes: 13 additions & 0 deletions examples/Tromp_2005/forward_source.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
number-of-sources: 1
sources:
- force:
Ricker:
f0: 0.42
factor: 7500000000.0
tshift: 0.0
angle: 270.0
source_surf: false
vx: 0.0
vz: 0.0
x: 50000
z: 40000
13 changes: 0 additions & 13 deletions examples/Tromp_2005/templates/source.yaml

This file was deleted.

Loading