Julia package for 3D gravity forward modeling and analysis with UBC-GIF format support.
- 3D Mesh Creation: Uniform and variable cell mesh support
- UBC Format I/O: Read/write mesh, model, and data files in UBC-GIF format
- Forward Modeling Methods:
- Prism (Analytical): Closed-form solution based on Plouff (1976) / Blakely (1995)
- Finite Difference: Poisson equation solver with CG and Jacobi preconditioner
- Model Building: Block and sphere anomaly utilities
- Visualization: Comparison plots and model slices (requires Plots.jl)
using Pkg
Pkg.add(url="https://github.com/yourusername/GravityGeophysics.jl")Or for development:
] dev path/to/GravityGeophysics.jlusing GravityGeophysics
# Create mesh (160 km × 160 km × 80 km domain)
mesh = create_mesh(
nx = 64, ny = 64, nz = 40,
lx = 160000.0, ly = 160000.0, lz = 80000.0
)
# Create model with density anomaly
model = create_model(mesh)
add_block_anomaly!(model;
xmin = -4000.0, xmax = 4000.0,
ymin = -4000.0, ymax = 4000.0,
zmin = 8000.0, zmax = 16000.0,
drho = 300.0 # kg/m³
)
# Create receivers
receivers = create_receivers(mesh; nrx=51, nry=51, z=50.0)
# Forward modeling - Prism method
data_prism = forward(model, receivers, Prism())
# Forward modeling - Finite Difference method
data_fd = forward(model, receivers, FiniteDifference())
# Compare methods
stats = compute_stats(data_prism, data_fd)
# Save in UBC format
save_data_ubc("gravity.obs", data_prism)
save_model_ubc("density.den", model)GravityGeophysics.jl/
├── Project.toml
├── README.md
├── LICENSE.md
├── src/
│ ├── GravityGeophysics.jl # Main module
│ ├── Mesh.jl # Mesh and model types
│ ├── UBCFormat.jl # UBC-GIF I/O
│ ├── ForwardPrism.jl # Analytical prism method
│ ├── ForwardFD.jl # Finite difference method
│ ├── Forward.jl # Unified interface
│ └── Visualization.jl # Plotting utilities
├── examples/
│ └── 01_gravity_forward.jl # Basic forward modeling example
└── test/
└── runtests.jl
# Create uniform mesh
mesh = create_mesh(nx=64, ny=64, nz=32, lx=10000.0, ly=10000.0, lz=5000.0)
# Get cell centers and edges
xc, yc, zc = get_cell_centers(mesh)
xe, ye, ze = get_cell_edges(mesh)
# Print mesh info
mesh_info(mesh)# Create empty model
model = create_model(mesh; background=0.0)
# Add anomalies
add_block_anomaly!(model; xmin, xmax, ymin, ymax, zmin, zmax, drho)
add_sphere_anomaly!(model; cx, cy, cz, radius, drho)# Prism method (exact, slower for large meshes)
data = forward(model, receivers, Prism())
# Finite Difference method (faster for large meshes)
fd_opts = FDOptions(tol=1e-10, maxiter=5000, use_prism_bc=false)
data = forward(model, receivers, FiniteDifference(fd_opts))
# Compare methods
data_prism, data_fd, stats = compare_methods(model, receivers)# Mesh
save_mesh_ubc("mesh.msh", mesh)
mesh = load_mesh_ubc("mesh.msh")
# Model
save_model_ubc("density.den", model)
model = load_model_ubc("density.den", mesh)
# Data
save_data_ubc("gravity.obs", data)
data = load_data_ubc("gravity.obs")Computes the vertical gravity component (gz) using the closed-form rectangular prism formula:
where
Characteristics:
- Exact solution for homogeneous rectangular prisms
- O(N_cells × N_receivers) complexity
- Best for small to medium-sized problems
Solves the 3D Poisson equation:
Using:
- 7-point Laplacian stencil
- Dirichlet boundary conditions (monopole approximation or exact prism)
- CG solver with Jacobi preconditioner
Gravity computed via:
Characteristics:
- Better scaling for large meshes
- Approximate solution
- 2nd or 4th order derivative schemes available
-
Plouff, D., 1976, Gravity and magnetic fields of polygonal prisms and application to magnetic terrain corrections: Geophysics, 41, 727-741.
-
Blakely, R.J., 1995, Potential Theory in Gravity and Magnetic Applications, Cambridge University Press.
-
UBC-GIF, GRAV3D Documentation, https://grav3d.readthedocs.io/
MIT License - see LICENSE.md
Contributions welcome! Please open an issue or submit a pull request.