Skip to main content

Synthetic trench scenario generator bundle (surfaces + volumetrics).

Project description

Trenchfoot

Synthetic trench scenario generator extracted from the Survi monorepo. This repository bundles surface + volumetric scene generation tooling and prebuilt scenarios.

Layout

  • packages/trenchfoot/: the generator bundle (surface CLI, Gmsh mesher, scenario specs, Dockerfile).
  • packages/trenchfoot/scenarios/: prebuilt scenes (OBJ meshes, previews, metrics).

Getting Started

uv sync
uv run python -m trenchfoot.generate_scenarios --help

Optional extras:

  • Install gmsh and meshio to emit volumetric meshes.
  • Install matplotlib to refresh preview renders.
  • Set TRENCHFOOT_SCENARIO_OUT_ROOT=/tmp/trench-previews (or another writable path) to keep generated assets out of the repo checkout; the CLI uses this location unless --out is specified.
  • Install plotly via pip install "trenchfoot[viz]" to enable Plotly HTML meshes.
  • Use uv run python -m trenchfoot.generate_scenarios --preview --gallery docs/scenario_gallery.md to regenerate previews and emit a Markdown gallery (the README table below was generated this way).

See packages/trenchfoot/README.md for the original usage notes and the CLI examples.

CLI Shortcuts

  • uv run python -m trenchfoot.generate_scenarios --scratch --skip-volumetric runs the generator in a temporary directory (no repo churn) and prints the scratch path.
  • Add --include-prebuilt if you want the shipped assets copied into the scratch directory before regeneration.
  • Combine --preview with --gallery docs/scenario_gallery.md to refresh previews and the Markdown gallery in one go.
  • trenchfoot-plot packages/trenchfoot/scenarios/S05_wide_slope_pair/trench_scene.obj --open writes an interactive Plotly HTML (requires the [viz] extra) and opens it in your browser.

Python API

Trenchfoot now exposes a light-weight SDK so you can work entirely in memory:

from trenchfoot import (
    SceneSpec,
    scene_spec_from_dict,
    generate_surface_mesh,
    generate_trench_volume,
    gmsh_available,
)

spec_dict = {
    "path_xy": [[0.0, 0.0], [5.0, 0.0]],
    "width": 1.0,
    "depth": 1.2,
    "wall_slope": 0.1,
    "ground": {"z0": 0.0, "slope": [0.0, 0.0], "size_margin": 2.0},
    "pipes": [{"radius": 0.1, "length": 1.8, "angle_deg": 0.0, "s_center": 0.5}],
    "boxes": [],
    "spheres": [],
    "noise": {"enable": False},
}

scene = scene_spec_from_dict(spec_dict)
surface = generate_surface_mesh(scene)
print(surface.metrics["surface_area_by_group"]["trench_walls"])
surface.persist("./tmp/surface", include_previews=False)

if gmsh_available():
    volume = generate_trench_volume(spec_dict, lc=0.4, persist_path="./tmp/volume/trench_volume.msh")
    print(len(volume.element_blocks), "element blocks", "across", volume.nodes.shape[0], "nodes")

SurfaceMeshResult keeps the per-group vertex/face arrays, metrics, and optional preview PNGs (as bytes). Call .persist(path) when you want OBJ + metrics written to disk. VolumeMeshResult exposes the raw node coordinates, element connectivity, and the discovered physical groups while still letting you emit .msh files on demand.

Mesh Clearance Guard Rails

The volumetric mesher enforces a minimum 50 mm gap between the trench walls and any embedded geometry, scaling the threshold with each pipe’s radius and the current wall slope. When clearance gets tight, the generator shortens the pipe run and records per-pipe margins in SUMMARY.json under pipe_clearances so you can spot scenarios that are at risk before Gmsh complains.

Scenario Gallery

Color key: trench surfaces use warm soil tones, embedded geometry is color-coded per object (pipes in rotating palette, boxes teal/olive, spheres magenta/gray).

Scenario Top Side Oblique
S01_straight_vwalls S01 top S01 side S01 oblique
S02_straight_slope_pipe S02 top S02 side S02 oblique
S03_L_slope_two_pipes_box S03 top S03 side S03 oblique
S04_U_slope_multi_noise S04 top S04 side S04 oblique
S05_wide_slope_pair S05 top S05 side S05 oblique
S06_bumpy_wide_loop S06 top S06 side S06 oblique

Testing

uv run pytest -rs

The test suite exercises the single-scenario code path, runs all bundled presets (surface + volumetric) into a scratch directory, and checks that the CLI honours TRENCHFOOT_SCENARIO_OUT_ROOT.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

trenchfoot-0.1.0.tar.gz (5.4 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

trenchfoot-0.1.0-py3-none-any.whl (5.4 MB view details)

Uploaded Python 3

File details

Details for the file trenchfoot-0.1.0.tar.gz.

File metadata

  • Download URL: trenchfoot-0.1.0.tar.gz
  • Upload date:
  • Size: 5.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for trenchfoot-0.1.0.tar.gz
Algorithm Hash digest
SHA256 03c354c7afb4086f9a049d2145a4ac25979d4dedeaef977086a615e09729edca
MD5 ee71378f0cbb49ef9d7faaa139ccd2b4
BLAKE2b-256 06c5bafa86a9d3466ba00abdcab429180f109f5cce8bae813c5b9a391954d0a7

See more details on using hashes here.

File details

Details for the file trenchfoot-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: trenchfoot-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.4 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for trenchfoot-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 25a367822b7ed78cb6b2d803e244fbb06a0dd09aea6fa86675f168c287ac206f
MD5 74d0e268236f85e6f63309e97dd37335
BLAKE2b-256 794d4990d8965b55b464bb8d34c88adddf5a2a004bbb68cc9957e9971454dba6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page