Metadata-Version: 2.4
Name: seismicx-grtm
Version: 0.5.1
Summary: SeismicX GRTM: layered-medium Green functions with C, CUDA and Apple Metal backends
License-Expression: LicenseRef-SeismicX-Research-NonCommercial
License-File: LICENSE
License-File: NOTICE.md
License-File: licenses/Cython.txt
License-File: licenses/LLVM-libcxx.txt
License-File: licenses/NVIDIA-CUDA.txt
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: C
Classifier: Operating System :: POSIX :: Linux
Classifier: Operating System :: MacOS
Classifier: Topic :: Scientific/Engineering :: Physics
Project-URL: Repository, https://github.com/cangyeone/seismicx-grtm
Project-URL: Documentation, https://pypi.org/project/seismicx-grtm/
Project-URL: Issues, https://github.com/cangyeone/seismicx-grtm/issues
Requires-Python: >=3.10
Requires-Dist: numpy>=1.20
Provides-Extra: rf
Requires-Dist: scipy>=1.8; extra == "rf"
Provides-Extra: torch
Requires-Dist: torch>=2.4; extra == "torch"
Provides-Extra: jax
Requires-Dist: jax>=0.4.35; extra == "jax"
Description-Content-Type: text/markdown

# SeismicX GRTM

Layered-medium Green's functions with a Python interface and **C, NVIDIA CUDA,
and Apple Metal** computation engines. Distribution: `seismicx-grtm`.
Import: `grtm`.

**License:** proprietary; noncommercial scientific research only. Commercial
use requires separate written permission. Implementation source code is not
included. See the license and third-party notices installed with the package.

## Installation

```sh
python -m pip install seismicx-grtm
python -m pip install 'seismicx-grtm[rf]'         # receiver-function inversion
python -m pip install 'seismicx-grtm[torch,jax]'  # optional framework adapters
```

Binary wheels support CPython 3.10–3.14 on Apple Silicon macOS and Linux/WSL
x86_64. Native Windows and Intel macOS wheels are not supplied. Installation
requires no C/C++ or CUDA compiler. There is no source-build fallback.

| Platform | Included engines | Requirements |
|---|---|---|
| Apple Silicon | CPU and Metal (`mps` alias) | macOS 11 or newer; Apple GPU for Metal |
| Linux/WSL x86_64 | CPU and CUDA | glibc 2.28 or newer; CPU works without a GPU |
| CUDA execution | CUDA 12.8, compute capability 12.0 | RTX 5090 tested; compatible NVIDIA driver required |

Use `grtm.Solver(backend="cpu")`, `backend="cuda"`, or `backend="metal"`.
The C engine is the default. The same Linux wheel contains CPU and CUDA; there
is no separate CPU/CUDA package to replace. CUDA capability 12.0 targets RTX
50-series hardware; this release does not provide kernels for older GPUs.
`grtm.available_backends()` lists installed engines, not usable devices.
GPU errors are reported explicitly.

## Moment tensor or strike–dip–rake forward modelling

High-level interfaces use **north–east–down (NED)** coordinates and **SI units**.
Strike, dip, rake and azimuth are in degrees; azimuth is clockwise from north.

```python
import grtm

solver = grtm.Solver(backend="cpu")
model = grtm.example_model(units="si")
source = grtm.strike_dip_rake(20, 40, 60, scalar_moment=1e15)
result = solver.forward(
    model, moment_tensor=source, azimuth=45,
    fields=("displacement", "strain", "stress"), threads=8,
)
print(result["displacement"].shape)  # [distance, sample, 3]
```

Without a source-time history, outputs are impulse kernels: displacement in m/s,
strain in 1/s, and stress in Pa/s. Supplying a dimensionless source history as
`stf` applies the causal convolution with `dt`, producing m, strain, and Pa.
Strain and stress have shape `[distance, sample, 3, 3]`.

The legacy `grtm.compute()` interface uses km, km/s, and g/cm³. Each layer is
`[top_depth, Vp, Vs, density, Qp, Qs]`; the last layer is a half-space. Point-source
models support horizontal isotropic solid layers, positive epicentral distance,
and finite-Q attenuation. Fluid layers and the axial zero-distance limit are
not supported. Check numerical integration convergence for your frequency band,
source depth, distance range, and model contrasts.

## Batch models, derivatives, and frameworks

```python
batch = solver.forward_batch(
    [model, model], moment_tensor=source, azimuth=45,
    fields=("displacement",), workers=2, threads=4,
)
```

Point-source structural Jacobians and vector–Jacobian products use native
forward-mode tangents on a fixed local integration grid. Receiver-coordinate
derivatives support strain/stress evaluation. PyTorch and JAX adapters expose
forward and first-derivative interfaces; consult the installed guide for exact
framework/device and derivative-order support. Receiver-function inversion uses
finite-difference structural derivatives and a separate elastic plane-P solver.

The receiver-function workflow connects **H–κ stacking → waveform fitting →
structural inversion**, with bounded parameters and identifiability diagnostics:

```python
import numpy as np
# observed is a synthetic_rf()/receiver_function() result with ray slownesses
# fit = grtm.receiver_function_workflow(
#     observed, h=np.arange(20000, 60001, 500),
#     kappa=np.arange(1.5, 2.001, .01), vp=6300,
#     inversion_options={"fit_window": (1, 26)},
# )
```

This RF solver assumes elastic solid layers and explicitly ignores Q. The
default workflow estimates thickness and Vp/Vs with Vp, density and mantle fixed.
Reported local uncertainty requires careful interpretation under model error.

## Documentation and command line

English guides and Chinese companions are included in `grtm/docs`:

```python
from pathlib import Path
import grtm
print(Path(grtm.__file__).parent / "docs" / "PYTHON_FORWARD.md")
print(Path(grtm.__file__).parent / "docs" / "RECEIVER_FUNCTIONS.md")
```

```sh
grtm --info
grtm --model model.json --backend cpu --threads 8 --output result.npz
```

中文：本软件仅限非商业科研用途。安装发行名为 `seismicx-grtm`，调用方式为
`import grtm`。默认使用 CPU，可选择 `cuda` 或 `metal`/`mps`。中文文档随包安装于
`grtm/docs`，文件名以 `.zh-CN.md` 结尾。高层接口默认 NED 坐标与 SI 单位。

Historical benchmarks refer to the independent
[Fortran GRTM by Yunyi Qian](https://github.com/YunyiQian/grtm) and
[FK by Lupei Zhu and its maintainers](https://github.com/rwalkerlewis/fk).
Neither reference program is included in this distribution. No universal speedup
is claimed: performance depends on the model, sampling, distance count and device.
