From f2d25e08f30a3b566ea600f7f1dd6c2e3d9d5d20 Mon Sep 17 00:00:00 2001 From: ccui Date: Tue, 14 Jan 2025 11:46:00 -0500 Subject: [PATCH] Update examples --- examples/Tromp_2005/.gitignore | 3 - .../adjoint_config.yaml.in} | 54 +++++--- .../CMakeFiles/forward_config.yaml.in | 51 +++++++ examples/Tromp_2005/CMakeLists.txt | 3 +- examples/Tromp_2005/Snakefile | 126 ++++++++++++++++++ examples/Tromp_2005/adjoint_source.yaml | 27 ++++ .../Tromp_2005/Snakefile} | 18 +-- examples/Tromp_2005/forward_source.yaml | 13 ++ examples/Tromp_2005/templates/source.yaml | 13 -- 9 files changed, 261 insertions(+), 47 deletions(-) rename examples/Tromp_2005/{templates/specfem_config.yaml => CMakeFiles/adjoint_config.yaml.in} (54%) create mode 100644 examples/Tromp_2005/CMakeFiles/forward_config.yaml.in create mode 100644 examples/Tromp_2005/Snakefile create mode 100644 examples/Tromp_2005/adjoint_source.yaml rename examples/Tromp_2005/{CMakeFiles/Snakefile.in => examples/Tromp_2005/Snakefile} (83%) create mode 100644 examples/Tromp_2005/forward_source.yaml delete mode 100644 examples/Tromp_2005/templates/source.yaml diff --git a/examples/Tromp_2005/.gitignore b/examples/Tromp_2005/.gitignore index e2834a14..d87a8f9e 100644 --- a/examples/Tromp_2005/.gitignore +++ b/examples/Tromp_2005/.gitignore @@ -3,9 +3,6 @@ OUTPUT_FILES/* *.semd *.adj Par_File -Snakefile *.pyc -forward_source.yaml forward_config.yaml -adjoint_source.yaml adjoint_config.yaml diff --git a/examples/Tromp_2005/templates/specfem_config.yaml b/examples/Tromp_2005/CMakeFiles/adjoint_config.yaml.in similarity index 54% rename from examples/Tromp_2005/templates/specfem_config.yaml rename to examples/Tromp_2005/CMakeFiles/adjoint_config.yaml.in index 4409815e..b0b034dc 100644 --- a/examples/Tromp_2005/templates/specfem_config.yaml +++ b/examples/Tromp_2005/CMakeFiles/adjoint_config.yaml.in @@ -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 diff --git a/examples/Tromp_2005/CMakeFiles/forward_config.yaml.in b/examples/Tromp_2005/CMakeFiles/forward_config.yaml.in new file mode 100644 index 00000000..dbc241c8 --- /dev/null +++ b/examples/Tromp_2005/CMakeFiles/forward_config.yaml.in @@ -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 diff --git a/examples/Tromp_2005/CMakeLists.txt b/examples/Tromp_2005/CMakeLists.txt index b511f69e..da100320 100644 --- a/examples/Tromp_2005/CMakeLists.txt +++ b/examples/Tromp_2005/CMakeLists.txt @@ -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) diff --git a/examples/Tromp_2005/Snakefile b/examples/Tromp_2005/Snakefile new file mode 100644 index 00000000..a0a18f99 --- /dev/null +++ b/examples/Tromp_2005/Snakefile @@ -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 + """ diff --git a/examples/Tromp_2005/adjoint_source.yaml b/examples/Tromp_2005/adjoint_source.yaml new file mode 100644 index 00000000..13168bba --- /dev/null +++ b/examples/Tromp_2005/adjoint_source.yaml @@ -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 diff --git a/examples/Tromp_2005/CMakeFiles/Snakefile.in b/examples/Tromp_2005/examples/Tromp_2005/Snakefile similarity index 83% rename from examples/Tromp_2005/CMakeFiles/Snakefile.in rename to examples/Tromp_2005/examples/Tromp_2005/Snakefile index a07ee4bc..54c98c23 100644 --- a/examples/Tromp_2005/CMakeFiles/Snakefile.in +++ b/examples/Tromp_2005/examples/Tromp_2005/Snakefile @@ -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", }, } } @@ -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) @@ -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", } }, } @@ -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) diff --git a/examples/Tromp_2005/forward_source.yaml b/examples/Tromp_2005/forward_source.yaml new file mode 100644 index 00000000..06b22fab --- /dev/null +++ b/examples/Tromp_2005/forward_source.yaml @@ -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 diff --git a/examples/Tromp_2005/templates/source.yaml b/examples/Tromp_2005/templates/source.yaml deleted file mode 100644 index 1114c3d6..00000000 --- a/examples/Tromp_2005/templates/source.yaml +++ /dev/null @@ -1,13 +0,0 @@ -number-of-sources: 1 -sources: - - force: - x: 50000 - z: 40000 - source_surf: false - angle: 270.0 - vx: 0.0 - vz: 0.0 - Ricker: - factor: 0.75e+10 - tshift: 0.0 - f0: 0.42