Skip to main content

Python wrapper for the CANDE FEA culvert analysis engine

Project description

cande-wrapper

Python wrapper for the CANDE (Culvert ANalysis and DEsign) finite element engine.

The CANDE-2025 Fortran source is compiled via f2py into a native Python extension module, allowing direct calls from Python without subprocess overhead or DLL wrappers.

Prerequisites

Dependency Version Purpose
Python >= 3.10 Runtime
gfortran any recent Compiles the CANDE Fortran engine
NumPy >= 1.26 f2py extension building and runtime
Meson >= 1.1 Build system
Ninja any recent Build backend for Meson

Installing gfortran on Windows

The easiest way is via MSYS2:

# In MSYS2 terminal
pacman -S mingw-w64-x86_64-gcc-fortran

# Add to PATH (PowerShell)
$env:PATH += ";C:\msys64\mingw64\bin"

Or install via conda:

conda install -c conda-forge gfortran

Installing build tools

pip install meson-python meson ninja numpy

Installation

From the project root:

pip install -e ".[dev]"

This compiles the Fortran engine via f2py and installs the Python package in editable mode. The [dev] extra includes pytest and jupyter for testing and notebooks.

If the build fails, see Troubleshooting below.

Quick Start

from cande_wrapper import CandeEngine

engine = CandeEngine(work_dir="path/to/my/models")
result = engine.run("EX1")  # reads EX1.cid, writes EX1.out
print(result.output_text)

CANDE Input Files

CANDE reads .cid input files (CANDE Input Data). These are fixed-format text files with sections:

  • A-1: Master control line (analysis/design mode, solution level, title)
  • A-2: Pipe type and element counts
  • B-*: Pipe material properties
  • C-*: Mesh, node, and element definitions
  • D-*: Soil properties and load steps
  • STOP: End-of-problem marker

Multiple problems can be run back-to-back in a single .cid file, each terminated by STOP.

An example input file is included at tests/example_data/MGK-IO.cid.

Output Files

After running engine.run("prefix"), these files are created in the working directory:

File Description
prefix.out Main analysis output report
prefix.log Engine log messages
prefix.ctc Table of contents for the output
prefix_MeshGeom.xml Mesh geometry (for visualization)
prefix_MeshResults.xml Mesh results (for visualization)
prefix_BeamResults.xml Beam element results
prefix_PLOT1.dat Plot data file 1
prefix_PLOT2.dat Plot data file 2

The CandeResult object returned by engine.run() gives convenient access to the main output files:

result = engine.run("EX1")
print(result.output_file)   # Path to EX1.out
print(result.log_file)      # Path to EX1.log
print(result.output_text)   # Full contents of EX1.out

Testing

pytest -v                    # unit tests (no build required)
pytest -m integration -v     # integration tests (requires build)
pytest -m "" -v              # all tests

Troubleshooting

gfortran: command not found

gfortran is not on your PATH. Verify with gfortran --version. On Windows, ensure the MSYS2/MinGW or conda bin directory is in your PATH.

Linker errors about missing symbols

The meson.build file lists Engine source files explicitly. If you see unresolved symbols like plasti_ or prhero_, the corresponding .f file needs to be added to the engine_sources list in meson.build.

ImportError: CANDE Fortran extension not found

The package was imported but the compiled extension (_cande.pyd / _cande.so) was not found. Rebuild with:

pip install -e . --no-build-isolation

Large memory usage

The CANDE engine statically allocates ~320 MB for the stiffness matrix (REAL*8 A(20000,2000) in system.fi). This is normal for FEA solvers and is mapped as virtual memory.

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

cande_wrapper-0.1.6.tar.gz (383.6 kB view details)

Uploaded Source

Built Distributions

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

cande_wrapper-0.1.6-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

cande_wrapper-0.1.6-cp312-cp312-win_amd64.whl (1.9 MB view details)

Uploaded CPython 3.12Windows x86-64

cande_wrapper-0.1.6-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

cande_wrapper-0.1.6-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

cande_wrapper-0.1.6-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

File details

Details for the file cande_wrapper-0.1.6.tar.gz.

File metadata

  • Download URL: cande_wrapper-0.1.6.tar.gz
  • Upload date:
  • Size: 383.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.20

File hashes

Hashes for cande_wrapper-0.1.6.tar.gz
Algorithm Hash digest
SHA256 62f24a0948de39fea955fed8bd00dc96e4f3b91f568b0ae8acf59f06324d67ae
MD5 3a3d0ddd82c4083b7d59a26357300ff0
BLAKE2b-256 ff6db44e96154e630ed0d7865900fff30c9b06d0b0e2762d23bcf5befee05a96

See more details on using hashes here.

File details

Details for the file cande_wrapper-0.1.6-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for cande_wrapper-0.1.6-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 ab5299fd8f395d2389f55b78a79501a889ff30295a2ff4d895966003e8b7c62e
MD5 b7fa65835363be67a46e055c09e3d6d5
BLAKE2b-256 6ad57db7c86e829009db5e104b57134b8d2f8243546ad3dc6305af2c47db4110

See more details on using hashes here.

File details

Details for the file cande_wrapper-0.1.6-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for cande_wrapper-0.1.6-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 a08b30a25ac7d974f86e671f4c50ef1ef2cee0591534b744e2c57ddaff1675d0
MD5 dddc042a2551d417d44f8eaf2a4859fe
BLAKE2b-256 c6cb3b05eb131c718bbd454443ec5288ce1877f0fb8a35a1569f971cbd643d0c

See more details on using hashes here.

File details

Details for the file cande_wrapper-0.1.6-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for cande_wrapper-0.1.6-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 58c99f9b1cf0899d1928bacb9e87eb25a0f77d171d893aa0a356481370a936fd
MD5 b19881c8778ac0275fbff9c581a8f8ad
BLAKE2b-256 c4314f2895fd5669f117e62e3befbc74ab5c75b904462a8e5859ff236f83a95b

See more details on using hashes here.

File details

Details for the file cande_wrapper-0.1.6-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for cande_wrapper-0.1.6-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 f9885b3b0385261c4be730aeb5c18b8b2d8be0611d1b8cd60f312d758c89de57
MD5 d4571e4ae4241fc15ecab23832ce709a
BLAKE2b-256 81ad3e7ae88d825b0eb162ee4d3940c8d035591ca8a4e0062142b31b8be41889

See more details on using hashes here.

File details

Details for the file cande_wrapper-0.1.6-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for cande_wrapper-0.1.6-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 8fffe0c4508e136811f11a5d1245b812ef91679ce6c65d98926d91896cc33c11
MD5 654d03456521e3831e8ddc62c7223fff
BLAKE2b-256 28f94d5fb174d26a560e9814c5f7d626b6f3b01e22221e37ec07294b1016e63c

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