Implementation
Cauchy is a header-only C++20 codebase with 7 core headers, 6 validation entry points, and 19 Google Test cases. The architecture mirrors the LBM-2D solver for consistency across the portfolio.
Module Reference
| File | Lines | Purpose | Key Types |
|---|---|---|---|
fea_types.hpp | 216 | Core types, enums, globals, JSON parser | Material, Node, Mesh, CaseType, PlaneType |
elements.hpp | 380 | Element stiffness matrices | BarElement, Q4Element, Q8Element, T3Element |
sparse.hpp | 170 | Sparse matrix formats | COOMatrix, CSRMatrix, DenseMatrix |
solver.hpp | 173 | Linear solvers | CholeskySolver, CGSolver |
mesh.hpp | 400 | Mesh generation | generate_structured_quad, generate_structured_quad8, generate_cook_quad8, load_json |
postprocess.hpp | 288 | Stress recovery, JSON output | ElementStress, compute_all_stresses |
adaptivity.hpp | 350 | ZZ error estimator, adaptive refinement | SPRResult, ElementError, refine_mesh, adaptive_loop |
convergence.hpp | 140 | GCI computation, h-refinement wrapper | GCIResult, ConvergenceSample, run_study |
fea.hpp | 240 | Assembly + solve pipeline | assemble, solve, compute_strain_energy |
Include Hierarchy
fea.hpp
fea_types.hpp (types, enums, globals)
elements.hpp (bar + Q4 + Q8 + T3 stiffness matrices)
sparse.hpp (COO/CSR sparse matrix)
solver.hpp (Cholesky + CG)
mesh.hpp (structured quad mesher + Q8 generators + JSON input)
postprocess.hpp (stress recovery, Von Mises)
adaptivity.hpp (ZZ SPR, error indicators, red-green refinement)
convergence.hpp (GCI, h-refinement)
Entry Point Pattern
Each main_*.cpp follows a consistent 7-step pipeline:
- Set globals (
g_nx,g_ny,g_case,g_analysis) - Generate or load mesh (Q4 or Q8 via
--q8flag) - Assemble global stiffness matrix (COO, OpenMP parallel)
- Apply boundary conditions (penalty method, including Q8 midside nodes)
- Solve (Cholesky or Conjugate Gradient)
- Post-process (stress recovery, energy balance)
- Write JSON output, report statistics
Build Instructions
cmake -B build
cmake --build build -j$(sysctl -n hw.ncpu)
Requirements: C++20 compiler, CMake 3.15+, OpenMP (optional), Google Test (auto-fetched)
Adaptive Refinement Pipeline
The adaptivity module (adaptivity.hpp) implements:
- SPR Recovery: Weighted average of Gauss-point stresses at nodes from surrounding elements
- Error Indicators: Element-wise = integral of |recovered - FE stress|^2
- Marking: "Largest first" strategy with threshold theta (0.5 default)
- Red-Green Refinement: Split marked Q4 elements into 4 (red) or 2 (green), add midside nodes
- Adaptive Loop: Solve -> recover -> estimate -> mark -> refine -> repeat
./build/FEA_AdaptHole 8 --iters 4
Runs 4 adaptive iterations on the plate-with-hole case, writing
output/adapt_hole_adaptive_convergence.json for visualization.
22 Google Test cases across 10 test suites:
| Suite | Tests | What It Validates |
|---|---|---|
| BarElementTest | 2 | Stiffness matrix correctness, symmetry |
| Q4ElementTest | 4 | Shape functions, Jacobian, stiffness symmetry, negative Jacobian detection |
| Q8ElementTest | 3 | Shape functions, 3x3 Gauss, 16x16 stiffness symmetry |
| SparseMatrixTest | 3 | COO-to-CSR conversion, SpMV, duplicate merging |
| CholeskyTest | 2 | Identity and diagonal system solves |
| CGTest | 2 | Diagonal system convergence, real FE system convergence |
| MeshTest | 3 | Node counts, coordinates, element connectivity |
| PatchTest | 1 | Constant stress recovery (element verification) |
| EnergyBalanceTest | 1 | Strain energy == work done (U == W) |
| SolverComparisonTest | 1 | Cholesky and CG produce identical results |
CI Pipeline
GitHub Actions runs on every push: builds on Ubuntu and macOS, runs the full Google Test suite. Matrix configuration ensures cross-platform compatibility.