Add cartesian_mesh_from_geometry convenience function#52
Merged
Conversation
Generate a VCell finite-volume CartesianMesh straight from a Geometry, without
hand-building a biomodel:
mesh = vc.cartesian_mesh_from_geometry(geometry, mesh_size=(64, 64, 64))
mesh = geometry.to_cartesian_mesh() # convenience method
It wraps the geometry in a minimal spatial biomodel (one structure per
subvolume/surface + a single diffusing probe species), runs libvcell + the FV
solver for one trivial step to produce the .mesh file, parses it via
CartesianMesh, and cleans up the temp output. mesh_size defaults to the image
size for image-based geometries, otherwise `resolution` (default 50) along each
active dimension.
Lives in vcml_simulation.py (heavy/solver path) and is exposed lazily from
pyvcell.vcml; Geometry.to_cartesian_mesh delegates via a lazy import so
models_geometry stays import-light (no libvcell/solver pulled at import).
Tests cover 2D and 3D analytic geometries (function + method forms) and the
default-resolution path. make check green; tests/vcml 46 passed / 5 skipped.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Generate a VCell finite-volume
CartesianMeshdirectly from aGeometry, without hand-assembling a biomodel:How
cartesian_mesh_from_geometry(invcml_simulation.py) wraps the geometry in a minimal spatial biomodel — one structure per subvolume (Feature) and surface (Membrane), plus a single diffusing "probe" species so the simulation is a valid PDE — then:vcml_to_finite_volume_input) + the FV solver (simulate) to run one trivial time step, which writes the.meshfile (the.meshis produced by the solver from the.vcg, not by the input step);CartesianMesh(...).read();mesh_sizedefaults to the image size for image-based geometries, otherwiseresolution(default 50) along each active dimension. Note: the region-defining subvolume must be added before the background (add_spherethenadd_background), since earlier subvolumes have higher priority.API placement / import-weight
pyvcell.vcml(likesimulate).Geometry.to_cartesian_mesh(...)delegates via a lazy import, soimport pyvcell.vcml.models_geometrystays import-light (verified: pulls nolibvcell/pyvcell_fvsolver/vtk/zarr).native+solverextras at call time.Tests / verification
tests/vcml/test_mesh_from_geometry.py: 2D and 3D analytic geometries (both the standalone function and theGeometrymethod), plus the default-resolution path — asserts size/extent/origin, dimension, the two volume regions (bg,cell), and the membrane region. (1D skipped per request; focus on 2D/3D.)[107, 87, 107]).make checkgreen (ruff, mypy 313 files, deptry);pytest tests/vcml→ 46 passed, 5 skipped.🤖 Generated with Claude Code