Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

Β 

History

95 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

ModelingAlgorithms: Seismic Wave Propagation Suite

Language Acceleration

A high-performance repository dedicated to 2D Acoustic Seismic Wavefield Modeling using finite-difference methods across multiple programming languages and parallel computing paradigms.

GPU acceleration via OpenACC achieves up to a 98% reduction in computation time compared to traditional serial CPU implementations. GPU acceleration via CUDA achieves optimal performance on NVIDIA architectures, while the new C++20 engine provides a modular, type-safe, and RAII-managed framework for high-fidelity simulations.


πŸ“‹ Table of Contents


πŸ” Overview

Seismic wave modeling simulates the propagation of acoustic waves through heterogeneous subsurface geological media. This repository contains implementations of 2D acoustic wave solvers utilizing spatial finite-difference operators, absorbing boundary conditions, and Ricker source wavelets.

The project serves both as a benchmarking suite comparing execution efficiency (Serial vs. OpenMP vs. OpenACC/CUDA) and as a foundation for next-generation seismic imaging (RTM) and inversion (FWI) algorithms.


πŸ“ Repository Structure

ModelingAlgorithms/
β”‚
β”œβ”€β”€ πŸ†• C++20 / CUDA Engine (active development)
β”œβ”€β”€ CMakeLists.txt             # CMake build system (C++20 + CUDA multi-arch)
β”œβ”€β”€ include/
β”‚   β”œβ”€β”€ core/
β”‚   β”‚   └── grid2d.hpp         # RAII Grid2D<T> β€” host & device memory manager
β”‚   β”œβ”€β”€ solvers/
β”‚   β”‚   └── acoustic_kernel.hpp  # Pure C++ interface (no CUDA types exposed)
β”‚   └── utils/
β”‚       └── cuda_utils.hpp     # CUDA_CHECK / CUDA_CHECK_KERNEL macros
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ main.cpp               # Entry point: CFL check, Ricker source, time loop
β”‚   └── solvers/cuda/
β”‚       └── acoustic_kernel.cu # FD 8th-order kernel + __constant__ coefficients
β”œβ”€β”€ inputs/                    # πŸ†• Simulation inputs (see section below)
β”‚   β”œβ”€β”€ parameters/
β”‚   β”‚   └── modeling_params.dat   # Grid, time, source, stencil settings
β”‚   β”œβ”€β”€ models/
β”‚   β”‚   └── README.md             # Convention for Vp, Vs, density binary files
β”‚   └── acquisition/
β”‚       └── geometry_2d.dat       # Shot/receiver positions and survey layout
β”œβ”€β”€ build/                     # CMake build artifacts (auto-generated)
β”‚   └── bin/
β”‚       └── seismic_sim        # Compiled executable
β”‚
β”œβ”€β”€ πŸ“¦ Legacy Implementations
β”œβ”€β”€ C/                         # C (Serial, OpenMP, OpenACC)
β”œβ”€β”€ fortran/                   # Fortran 90 (Serial, OpenMP, OpenACC)
β”œβ”€β”€ python/                    # Python solvers + CuPy / Numba CUDA kernels
β”œβ”€β”€ miscellaneous/             # Geophysical pre/post-processing utilities
β”œβ”€β”€ parameters/                # Legacy .dat parameter files
β”‚
β”œβ”€β”€ CONTEXT.md                 # Architecture guidelines for C++20/CUDA engine
β”œβ”€β”€ SPEC.md                    # Mathematical & physical specification
β”œβ”€β”€ Makefile                   # Legacy master Makefile (C & Fortran)
└── Makefile.inc               # Compiler flags for legacy builds

βš™οΈ C++20 / CUDA Engine (Active Development)

Architecture

The new engine follows the modular structure defined in CONTEXT.md:

Component File Responsibility
RAII Memory grid2d.hpp Templated Grid2D<T> managing pinned host + device buffers
Error Handling cuda_utils.hpp CUDA_CHECK() and CUDA_CHECK_KERNEL() macros
Solver Interface acoustic_kernel.hpp Pure C++ API β€” no CUDA headers exposed to .cpp files
CUDA Kernel acoustic_kernel.cu 8th-order FD stencil, __constant__ memory, coalesced access
Entry Point main.cpp Grid setup, CFL validation, Ricker source, time loop

GPU targets (compiled simultaneously):

GPU Architecture Compute Capability
GTX 1050 Ti Pascal SM 6.1
RTX 4000 Turing / Ada SM 7.5 / 8.9
H100 Hopper SM 9.0

Precision: float (FP32) by default. Switch to double (FP64) via Grid2D<double> for H100 runs β€” no kernel rewrites needed (templates).


πŸ“‚ Inputs Directory

All simulation inputs are organized under inputs/:

inputs/parameters/modeling_params.dat

Central configuration file for the C++20/CUDA engine:

# Grid
250       # Nx         - Grid points in X (horizontal)
250       # Nz         - Grid points in Z (depth)
10.0      # dx         - Horizontal spacing [m]
10.0      # dz         - Vertical spacing [m]

# Time
200       # Nt         - Number of time steps
0.0       # dt         - Time step [s] (0.0 = auto via CFL)

# Source
30.0      # f_peak     - Ricker peak frequency [Hz]
125       # sx         - Source X position [grid index]
125       # sz         - Source Z position [grid index]

# Stencil
8         # fd_order   - Spatial FD order (4 or 8)
0.25      # cfl_factor - CFL stability factor (Ξ³ = 0.25 for 8th-order)

# Output
1         # snap_interval  - Snapshot every N steps (0 = off)
outputs/  # output_dir     - Binary output directory

inputs/models/

Binary property model files (FP32, raw, idx = x + z * Nx):

File Property Units
vp_model.bin P-wave velocity m/s
vs_model.bin S-wave velocity (elastic phase) m/s
rho_model.bin Density (elastic phase) kg/mΒ³

Generate synthetic models with scripts in miscellaneous/.

inputs/acquisition/geometry_2d.dat

Shot and receiver layout for multi-shot surveys:

3         # n_shots    - Total number of shots
0         # sx_start   - First shot X [grid index]
124       # sx_end     - Last shot X  [grid index]
62        # sx_step    - Shot spacing [grid points]
5         # sz_fixed   - Shot depth   [grid index]

0         # rx_start   - First receiver X
249       # rx_end     - Last receiver X
1         # rx_step    - Receiver spacing [grid points]
2         # rz_fixed   - Receiver depth   [grid index]

fixed_spread  # acq_type - fixed_spread | moving_spread | crosswell

Numerical Scheme

Based on SPEC.md:

Wave equation (constant density): $$\frac{1}{c^2} \frac{\partial^2 p}{\partial t^2} = \frac{\partial^2 p}{\partial x^2} + \frac{\partial^2 p}{\partial z^2} + s(x,z,t)$$

Time update (leapfrog, 2nd-order): $$p^{n+1}{i,j} = 2p^n{i,j} - p^{n-1}{i,j} + c{i,j}^2 \Delta t^2 \left[\nabla^2_8 p^n_{i,j} + s^n_{i,j} \right]$$

Spatial stencil: 8th-order centered FD (Fornberg coefficients stored in __constant__ memory).

CFL stability (Ξ³ = 0.25 for 8th-order space / 2nd-order time): $$\Delta t \le \gamma \cdot \frac{\min(\Delta x, \Delta z)}{v_{\max}}, \quad \gamma \approx 0.25$$

Dispersion criterion (β‰₯ 10 points per minimum wavelength): $$\min(\Delta x, \Delta z) \le \frac{v_{\min}}{10 \cdot f_{\max}}$$

Memory layout (X = fast index, coalesced GPU access):

idx = x + z * Nx

Build & Run

Requirements: CMake β‰₯ 3.22, CUDA Toolkit 12.x, GCC with C++20 support, WSL2 Ubuntu/Debian.

# 1. Configure (Release mode)
cmake -B build -S . -DCMAKE_BUILD_TYPE=Release

# 2. Compile (all CPU cores)
cmake --build build -j$(nproc)

# 3. Run simulation
./build/bin/seismic_sim

Expected terminal output:

======================================================
  2D Acoustic Wave Propagator – Homogeneous Prototype
======================================================
  Grid         : 250 Γ— 250 points
  Spacing      : dx=10.0 m,  dz=10.0 m
  Velocity     : 2000.0 m/s (homogeneous)
  dt (CFL 90%) : 0.001125 s
  Time steps   : 200
  Source       : Ricker @ (125, 125), f_peak=30.0 Hz

  [OK] CFL condition satisfied.
  [OK] FD stencil coefficients uploaded to __constant__ memory.
  ...
  [OK] All GPU and CPU buffers released by RAII destructors.
======================================================
  Simulation finished successfully.
======================================================

GPU Profiling

# Timeline profiling (Nsight Systems)
nsys profile --stats=true ./build/bin/seismic_sim

# Kernel-level analysis (Nsight Compute)
ncu --target-processes all ./build/bin/seismic_sim

Legacy Implementations

C Implementations (/C)

  • C/serial: Baseline 2D acoustic solver β€” 2nd-order time, 4th-order space FD.
  • C/openmp: Multi-threaded CPU implementation via OpenMP pragma loops.
  • C/openacc: GPU offload via OpenACC (β‰ˆ98% speedup over serial).

Fortran Implementations (/fortran)

  • fortran/serial: Fortran 90, array-optimized serial solver.
  • fortran/openmp: OpenMP multi-threaded Fortran solver.
  • fortran/openacc: GPU-accelerated Fortran (pgfortran / nvfortran).

Compile all legacy targets:

make          # C + Fortran (serial, OpenMP, OpenACC)
make clean    # Remove build artifacts

Run a specific solver:

cd C/serial && make && make run
cd fortran/openmp && make && make run

Python Solvers & CUDA (/python)

  • SeismicModeling2D.py: OO wavefield class β€” CFL check, source injection, snapshots.
  • solvers.py: Vectorized Laplacian, Ricker wavelet, velocity model builders, CUDA wrappers.
  • CUDA_Kernels.py: Low-level CUDA C kernels executed via CuPy / Numba JIT.
# Requires: numpy, numba, matplotlib, cupy (optional)
python3 python/SeismicModeling2D.py

Miscellaneous Pre/Post-Processing Utilities

  • Velocity model generators: layered models, horizon-based models, smooth gradients.
  • Elastic parameters: derive Vp, Vs, density for elastic phase.
  • QC & analysis: grid interpolation (bilinearInterpolation.py), wavefield validation.

βš™οΈ Legacy Configuration & Parameters

Legacy C/Fortran solvers read parameters/2D_acoustic_modeling.dat:

300    # Nx       - Number of horizontal grid points
200    # Nz       - Number of vertical grid points
10     # dx       - Horizontal grid spacing (m)
10     # dz       - Vertical grid spacing (m)
2001   # Nt       - Number of time steps
1.0e-3 # dt      - Time sampling interval (s)
3      # Nshot   - Number of shot records
30     # x_step  - Shot spacing (grid points)

For the C++20/CUDA engine, use inputs/parameters/modeling_params.dat instead.


πŸ“Š Result Visualization

Binary output files (seismogram.bin, snapshots.bin) are visualized with Seismic Unix:

# Seismogram
ximage n1=Nt < seismogram.bin perc=99 &

# Wavefield snapshots (movie)
xmovie n1=Nz n2=Nx loop=1 sleep=1 < snapshots.bin &

πŸš€ Project Roadmap

Phase Status Description
2D Acoustic (Homogeneous) βœ… Operational 8th-order FD, Ricker source, CUDA multi-arch
2D Acoustic + CPML πŸ”„ Planned Convolutional PML absorbing boundaries
3D Acoustic πŸ”„ Planned 3D grid, 3D stencil, multi-GPU
Elastic Wave πŸ”„ Planned P + S waves, stress-velocity formulation
RTM πŸ”„ Planned Reverse Time Migration imaging
FWI πŸ”„ Planned Full Waveform Inversion

Core Architectural Standards

  • Memory layout: idx = x + z * Nx β€” X is the fast dimension for GPU thread coalescing.
  • Stability: CFL guard (Ξ³ = 0.25 for 8th-order) enforced before every time loop.
  • RAII: All device/host buffers managed by Grid2D<T>; zero manual cudaFree in application code.
  • Templates: Grid2D<T = float> β€” switch to double for H100 FP64 runs without rewriting kernels.
  • No allocations in loop: All cudaMalloc calls happen at initialization time.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages