How ritchie46/anastruct works
Project type and purpose
• Type: Python library (with optional Cython extensions) for structural analysis (FEM).
• Purpose: Provide an API (SystemElements, basic routines) to build 2D structural models, assemble & solve them, post-process results, and plot outcomes.
File structure
Top‐level:
• anastruct/ ← core package
– basic.py ← simple non-FEM routines & helper functions
– cython/ ← performance modules implemented in Cython
– fem/ ← main FEM logic
• cython/ ← Cython speedups for assembly & element routines
• elements.py ← element definitions (beam, truss)
• system_components/ ← assembly, solver, utility classes
• postprocess.py← result extraction
• plotter/ ← Matplotlib & null plotting backends
• util/ ← load & envelope utilities
– material/ ← material profiles & unit conversions (CSV data)
– sectionbase/ ← section database & property calculators (XML)
– types.py, vertex.py ← shared data types
• doc/ ← Sphinx documentation sources
• tests/ ← unit, E2E, benchmark tests
• build_cython_ext.py, pyproject.toml ← build & packaging
• .github/ workflows ← CI/CD.
Pull insights from the README
• The public API centers on SystemElements.
• Supports pure‐Python and Cython‐accelerated code paths.
• Relies on external databases (steel sections) and Matplotlib for plotting.
Main components & their interactions
A. User/API Layer
• “SystemElements” class (anastruct/basic.py + fem/system.py)
• Example scripts (in doc/examples & tests)
B. Core Domain Logic
1. Geometry & Model Builder
– Node & element data structures (vertex.py, types.py)
– Element definitions (fem/elements.py)
2. Solver & Assembly
– Assembly routines (fem/system_components/assembly.py)
– Solver (fem/system_components/solver.py)
– Utilities (fem/system_components/util.py)
3. Material & Section Data
– Material profiles (material/profile.py, units.py)
– Section database (sectionbase/*.xml via sectionbase/sectionbase.py)
C. Performance / Extension Layer
• Cython modules (anastruct/cython and anastruct/fem/cython)
– Accelerated stiffness & element routines
– Bound to Python classes via .pxd/.pyx
D. Post-Processing & Visualization
• Postprocess (fem/postprocess.py) calculates forces/moments/displacements
• Plotter backends (fem/plotter/mpl.py, null.py)
E. External Services & Tools
• Matplotlib (plotting)
• CI/CD (GitHub Actions workflows)
• Sphinx (docs)
• PyPI (distribution)
Relationships & data flow
1. User code → calls SystemElements (public API).
2. SystemElements → builds internal model (nodes/elements).
3. Model → passes to Assembly → creates global stiffness matrix.
4. Solver → applies boundary conditions, solves linear/nonlinear system.
5. Postprocess → extracts result vectors.
7. Data sources (material/sectionbase) feed properties into model.
8. Cython modules can be invoked at steps 3 & 4 for speed.
Architectural patterns & design principles
• Layered architecture (API → Core → Data → Performance → I/O).
• Clear separation of concerns: building, solving, post-processing, plotting.
• Plugin/extension points: multiple plotter backends; pure-Python vs Cython code paths.
• Data‐driven: element & material databases loaded from external files.
Detail without clutter
• External dependencies separately (Matplotlib, CI, docs).
• Don’t over‐fragment—focus on the main logical components and their interactions.