docs: Reorganize documentation into three-tier structure

**Three Manuals for Three Audiences:**

1. **User Manual** (docs/user/) - "Just Get It Done"
   - For end users, engineers, students
   - Simple, practical, step-by-step
   - Quick start, tutorials, examples, troubleshooting
   - Philosophy: Show me how to solve my problem

2. **Contributor Manual** (docs/contributor/) - "Show Me the Code"
   - For developers, contributors, advanced users
   - Technical, detailed, design rationale
   - Testing, architecture, performance, CI/CD
   - Philosophy: Explain HOW and WHY

3. **The JuliaFEM Book** (docs/book/) - "Let Me Show You How I Think"
   - For researchers, theory nerds, and Jukka
   - Comprehensive, educational, opinionated, personal
   - Math foundations, design philosophy, history, research
   - Philosophy: Mix theory, code, and personal experience

**Reorganization:**
- Moved: TESTING_PHILOSOPHY.md → contributor/testing_philosophy.md
- Moved: STATUS.md → contributor/status.md
- Moved: TEST_FIXES_NEEDED.md → contributor/test_fixes_needed.md
- Moved: lagrange_basis_functions.md → book/lagrange_basis_functions.md
- Moved: benchmarks/ → book/benchmarks/
- Created: docs/README.md (main index explaining structure)
- Created: README.md in each section explaining audience and contents
- Updated: All references in scripts and source files

**Naming:** All docs now lowercase (testing_philosophy not TESTING_PHILOSOPHY)

**Benefits:**
- Clear separation of concerns
- Users don't get overwhelmed with implementation details
- Contributors get technical depth
- Book preserves deep theory and personal insights
- Each manual optimized for its audience

**Next:** Populate each section with appropriate content
This commit is contained in:
Jukka Aho
2025-11-09 04:38:28 +02:00
parent 5141fd6de5
commit 626266c990
12 changed files with 298 additions and 5 deletions
+118
View File
@@ -0,0 +1,118 @@
# JuliaFEM Documentation
Welcome! JuliaFEM documentation is organized into **three manuals** for three different audiences:
---
## 📘 [User Manual](user/) - "Just Get It Done"
**For:** End users, engineers, students who want to run simulations.
**Style:** Simple, practical, step-by-step.
**Contents:**
- Quick start and installation
- Tutorials and examples
- API reference
- Troubleshooting
**Philosophy:** Show me how to solve my problem, skip the lectures.
👉 **[Start Here](user/README.md)** if you want to run simulations.
---
## 🔧 [Contributor Manual](contributor/) - "Show Me the Code"
**For:** Developers, contributors, advanced users who want to extend JuliaFEM.
**Style:** Technical, detailed, design rationale.
**Contents:**
- Testing philosophy
- Code style and architecture
- Performance guidelines
- How to add elements
- CI/CD and git workflow
**Philosophy:** Explain HOW the code works and WHY we made these choices.
👉 **[Start Here](contributor/README.md)** if you want to contribute code.
---
## 📖 [The JuliaFEM Book](book/) - "Let Me Show You How I Think"
**For:** Advanced researchers, theory nerds, those who want to understand deeply. And Jukka.
**Style:** Comprehensive, educational, opinionated, personal.
**Contents:**
- Mathematical foundations (Lagrange basis, contact mechanics, etc.)
- Design philosophy and technical vision
- Strategic mistakes and lessons learned (2015-2019)
- Research directions (nodal assembly, matrix-free, etc.)
- Personal reflections on the journey
**Philosophy:** Mix theory, software design, and personal experience. Teach FEM through implementation.
👉 **[Start Here](book/README.md)** if you love deep dives and want to understand the "why" behind everything.
---
## Quick Navigation
### I want to...
- **Solve a heat transfer problem** → [User Manual](user/)
- **Add a new element type** → [Contributor Manual](contributor/)
- **Understand Lagrange basis functions** → [Book: Lagrange Basis](book/lagrange_basis_functions.md)
- **Learn about testing** → [Contributor: Testing Philosophy](contributor/testing_philosophy.md)
- **See benchmark results** → [Book: Benchmarks](book/benchmarks/)
- **Understand the design philosophy** → [Book: Philosophy](book/)
- **Report a bug** → GitHub Issues
- **Ask a question** → GitHub Discussions
---
## Documentation Philosophy
### Why Three Manuals?
Different readers have different needs:
1. **Users** don't care about implementation details - they just want working code.
2. **Contributors** need technical depth but not necessarily all the theory.
3. **Researchers** (and Jukka) want to understand everything from first principles.
Mixing these audiences in one manual makes it too complex for users and too shallow for researchers.
### Design Principles
- **User Manual:** Optimize for time-to-first-result
- **Contributor Manual:** Optimize for correctness and maintainability
- **Book:** Optimize for understanding and education
### Cross-References
Manuals link to each other when appropriate:
- User manual links to theory when deeper understanding helps
- Contributor manual links to book for design rationale
- Book links to code examples and practical guides
---
## Contributing to Documentation
Documentation improvements are always welcome!
- **User docs:** Fix errors, add examples, improve clarity
- **Contributor docs:** Update for new features, clarify architecture
- **Book:** Add theory, share insights, document research
See [Contributor Manual](contributor/) for guidelines.
---
**License:** MIT (same as code)
**Questions?** Open an issue or discussion on GitHub
+82
View File
@@ -0,0 +1,82 @@
# The JuliaFEM Book
**Audience:** Advanced researchers, theory nerds, those who want to understand the "why" and "how" at a deep level. And Jukka.
This is the **JuliaFEM Bible** - a comprehensive manual mixing theory, philosophy, software design, and personal experience. It's educational, opinionated, and unapologetically deep.
## What's Here
- **Mathematical Foundations:** Lagrange basis functions, weak forms, contact mechanics
- **Design Philosophy:** Why JuliaFEM exists, what problems it solves (and doesn't)
- **Technical Vision:** Strategic mistakes from 2015-2019, lessons learned
- **Research Directions:** Experimental ideas (nodal assembly, matrix-free, etc.)
- **Personal Notes:** The journey, the failures, the "aha!" moments
- **Theory + Code:** How mathematics becomes software
## What's NOT Here
- "How do I install?" (see `docs/user/`)
- "How do I add a feature?" (see `docs/contributor/`)
- Short answers (everything here is DEEP)
## Philosophy
**"Let me show you how I think about FEM."**
This is:
- **Educational:** Teach FEM through implementation
- **Personal:** Written in Jukka's voice, reflecting 8+ years of experience
- **Opinionated:** Strong views on what works and what doesn't
- **Comprehensive:** From first principles to cutting-edge research
- **Honest:** Documents failures as much as successes
We assume you:
- Love mathematics AND programming
- Want to understand WHY, not just HOW
- Have time to read deeply
- Are curious about unconventional approaches
- Might be me, 5 years from now, trying to remember why I did this
## Structure
### Part I: Foundations
- Finite Element Method (brief review)
- Lagrange Basis Functions (deep dive)
- Assembly and Solving
- Contact Mechanics
### Part II: Software Design
- Type Stability and Performance
- Zero-Allocation Design
- Immutability and Composition
- Field System Architecture
### Part III: History and Vision
- Strategic Mistakes (2015-2019)
- Why JuliaFEM is Different
- Contact Mechanics Focus
- Laboratory Philosophy
### Part IV: Research
- Nodal Assembly (experimental)
- Matrix-Free Methods
- Automatic Differentiation
- GPU Acceleration
### Part V: The Journey
- Personal Reflections
- Lessons Learned
- Future Directions
- Open Questions
## Reading Guide
- **For Theory:** Start with Part I
- **For Design Rationale:** Start with Part II
- **For History:** Start with Part III
- **For Research Ideas:** Start with Part IV
- **For Philosophy:** Read Part V first, then everything else
---
**Start here:** [Mathematical Foundations](foundations.md) | [Strategic Mistakes](strategic_mistakes.md) | [Why JuliaFEM?](philosophy.md)
+226
View File
@@ -0,0 +1,226 @@
# Lagrange Basis Functions in JuliaFEM
**Date:** November 9, 2025
**Author:** JuliaFEM Development Team
## Introduction
Lagrange basis functions are the foundation of the Finite Element Method. They provide a systematic way to construct polynomial interpolation functions that satisfy the **Kronecker delta property**: the basis function associated with node $i$ equals 1 at that node and 0 at all other nodes.
$$N_i(\mathbf{x}_j) = \delta_{ij} = \begin{cases} 1 & \text{if } i = j \\ 0 & \text{if } i \neq j \end{cases}$$
This property makes it trivial to interpolate field values: $u(\mathbf{x}) = \sum_i u_i N_i(\mathbf{x})$ where $u_i$ are nodal values.
## Mathematical Foundation
### Vandermonde Matrix Method
Given:
- $n$ nodes with coordinates $\{\mathbf{x}_1, \mathbf{x}_2, \ldots, \mathbf{x}_n\}$ in reference element
- A polynomial basis (ansatz) $\{p_1(\mathbf{x}), p_2(\mathbf{x}), \ldots, p_n(\mathbf{x})\}$
We seek coefficients $\alpha_{ij}$ such that:
$$N_i(\mathbf{x}) = \sum_{j=1}^{n} \alpha_{ij} p_j(\mathbf{x})$$
The Kronecker delta property gives us:
$$N_i(\mathbf{x}_k) = \sum_{j=1}^{n} \alpha_{ij} p_j(\mathbf{x}_k) = \delta_{ik}$$
This is a linear system: $\mathbf{V} \boldsymbol{\alpha}_i = \mathbf{e}_i$
Where the **Vandermonde matrix** is:
$$V_{kj} = p_j(\mathbf{x}_k)$$
And $\mathbf{e}_i$ is the $i$-th unit vector.
### Example: 1D Linear Element (Seg2)
**Ansatz:** $p(\xi) = 1 + \xi$ (complete linear polynomial)
**Nodes:** $\xi_1 = 0$, $\xi_2 = 1$
**Vandermonde matrix:**
$$\mathbf{V} = \begin{bmatrix}
p_1(\xi_1) & p_2(\xi_1) \\
p_1(\xi_2) & p_2(\xi_2)
\end{bmatrix} = \begin{bmatrix}
1 & 0 \\
1 & 1
\end{bmatrix}$$
**Solve for $N_1$:** $\mathbf{V} \boldsymbol{\alpha}_1 = [1, 0]^T$
$$\begin{bmatrix} 1 & 0 \\ 1 & 1 \end{bmatrix} \begin{bmatrix} \alpha_{11} \\ \alpha_{12} \end{bmatrix} = \begin{bmatrix} 1 \\ 0 \end{bmatrix}$$
Solution: $\alpha_{11} = 1$, $\alpha_{12} = -1$
Therefore: $N_1(\xi) = 1 \cdot 1 + (-1) \cdot \xi = 1 - \xi$ ✓
**Solve for $N_2$:** $\mathbf{V} \boldsymbol{\alpha}_2 = [0, 1]^T$
Solution: $\alpha_{21} = 0$, $\alpha_{22} = 1$
Therefore: $N_2(\xi) = 0 \cdot 1 + 1 \cdot \xi = \xi$ ✓
**Verification:**
- $N_1(0) = 1$, $N_1(1) = 0$ ✓
- $N_2(0) = 0$, $N_2(1) = 1$ ✓
- $N_1(\xi) + N_2(\xi) = 1$ (partition of unity) ✓
## Polynomial Completeness
The ansatz polynomial must be **complete** to the desired order:
| Order | 1D | 2D | 3D | Nodes Required |
|-------|----|----|-----|----------------|
| Linear | $1 + \xi$ | $1 + \xi + \eta$ | $1 + \xi + \eta + \zeta$ | $d+1$ |
| Quadratic | $1 + \xi + \xi^2$ | $1 + \xi + \eta + \xi^2 + \xi\eta + \eta^2$ | ... | $(d+1)(d+2)/2$ |
**Example for 2D Triangle (Tri3):**
Ansatz: $p(\xi, \eta) = 1 + \xi + \eta$ (complete linear in 2D)
This is the **minimal** complete polynomial for 3 nodes.
## Implementation in JuliaFEM
### Automatic Generation Process
```julia
# 1. Define element geometry
coords = [(0.0, 0.0), (1.0, 0.0), (0.0, 1.0)] # Tri3 nodes
# 2. Define ansatz polynomial
ansatz = :(1 + u + v) # Complete linear in 2D
# 3. Build Vandermonde matrix
V[i,j] = eval_polynomial_term(ansatz_terms[j], coords[i])
# 4. For each node i:
coeffs = V \ e_i # Solve linear system
N_i = sum(coeffs[j] * ansatz_terms[j]) # Construct basis function
# 5. Symbolic differentiation
∂N_i/∂ξ = differentiate(N_i, :u)
∂N_i/∂η = differentiate(N_i, :v)
```
### Why This Works
1. **Completeness:** Ansatz spans full polynomial space of given order
2. **Linear Independence:** Vandermonde matrix is non-singular for distinct nodes
3. **Interpolation Property:** Follows directly from $\mathbf{V} \boldsymbol{\alpha}_i = \mathbf{e}_i$
### Derivatives
Once we have $N_i(\xi, \eta, \zeta)$ symbolically, derivatives are straightforward:
$$\frac{\partial N_i}{\partial \xi}, \frac{\partial N_i}{\partial \eta}, \frac{\partial N_i}{\partial \zeta}$$
These are computed **once** symbolically, then **pre-compiled** into efficient Julia code.
## Standard Lagrange Elements in JuliaFEM
### 1D Elements
- **Seg2**: Linear (2 nodes)
- **Seg3**: Quadratic (3 nodes, mid-edge node)
### 2D Elements
- **Tri3**: Linear triangle (3 corner nodes)
- **Tri6**: Quadratic triangle (6 nodes: 3 corners + 3 mid-edges)
- **Quad4**: Bilinear quadrilateral (4 corner nodes)
- **Quad8**: Serendipity quadrilateral (8 nodes: 4 corners + 4 mid-edges)
- **Quad9**: Biquadratic quadrilateral (9 nodes: 4 corners + 4 mid-edges + 1 center)
### 3D Elements
- **Tet4**: Linear tetrahedron (4 corner nodes)
- **Tet10**: Quadratic tetrahedron (10 nodes: 4 corners + 6 mid-edges)
- **Hex8**: Trilinear hexahedron (8 corner nodes)
- **Hex20**: Serendipity hexahedron (20 nodes: 8 corners + 12 mid-edges)
- **Hex27**: Triquadratic hexahedron (27 nodes: full tensor product)
- **Pyr5**: Linear pyramid (5 nodes)
- **Wedge6**: Linear wedge/prism (6 nodes)
- **Wedge15**: Quadratic wedge (15 nodes)
## Pre-Generation vs Runtime Generation
### Historical Approach (JuliaFEM ≤ 0.5.1)
```julia
# At package load time:
create_basis_and_eval(:Tet10, "...", coords, ansatz)
# - Builds Vandermonde matrix
# - Solves n linear systems
# - Symbolic differentiation
# - Simplification
# - Code generation with eval()
# Result: __precompile__(false) - slow loading
```
**Problems:**
- ❌ Symbolic math every package load (100+ ms)
- ❌ Cannot precompile (`eval()` at module scope)
- ❌ Opaque code generation
- ❌ Hard to debug
### Modern Approach (JuliaFEM ≥ 1.0)
```julia
# Once, during development:
scripts/generate_lagrange_basis.jl
# - Computes all bases symbolically
# - Writes clean Julia code to src/basis/lagrange_generated.jl
# At package load time:
include("basis/lagrange_generated.jl")
# - Just parses pre-written Julia code
# - Fully precompilable
# - Zero symbolic computation
```
**Benefits:**
- ✅ Instant package loading
- ✅ Full precompilation
- ✅ Readable generated code
- ✅ Easy to debug
- ✅ Version controlled (can review changes)
## Numerical Stability
### Vandermonde Matrix Conditioning
The Vandermonde matrix can be ill-conditioned for:
- High-order polynomials ($p > 5$)
- Poorly distributed nodes
- Reference elements far from unit cube/simplex
**JuliaFEM's approach:**
- Use canonical reference elements (unit cube $[-1,1]^d$ or unit simplex)
- Lagrange elements rarely exceed order 3 in practice
- For high-order: Consider hierarchical bases (not Lagrange)
### Verification
Generated basis functions are verified by:
1. **Kronecker delta property:** $N_i(\mathbf{x}_j) = \delta_{ij}$
2. **Partition of unity:** $\sum_i N_i(\mathbf{x}) = 1$ everywhere
3. **Derivative correctness:** Compare symbolic vs AD
See `test/test_basis_functions.jl` for comprehensive tests.
## References
1. Hughes, T.J.R., "The Finite Element Method: Linear Static and Dynamic Finite Element Analysis", Dover, 2000
2. Zienkiewicz, O.C. and Taylor, R.L., "The Finite Element Method", Volumes 1-3, Butterworth-Heinemann, 2000
3. Szabó, B. and Babuška, I., "Finite Element Analysis", Wiley, 1991
## See Also
- `scripts/generate_lagrange_basis.jl` - Generation script
- `src/basis/lagrange_generated.jl` - Generated code (do not edit manually)
- `src/basis/lagrange_generator.jl` - Generator functions (symbolic engine)
- `benchmarks/tet10_derivatives_benchmark.jl` - Performance analysis (manual vs AD)
+53
View File
@@ -0,0 +1,53 @@
# JuliaFEM Contributor Manual
**Audience:** Developers, contributors, advanced users who want to extend or modify JuliaFEM.
This manual is **technical and detailed** - it explains HOW the code works and WHY we made certain design choices.
## What's Here
- **Testing Philosophy:** How and why we test
- **Code Style:** Conventions and best practices
- **Architecture:** Module structure, data flow, key abstractions
- **Performance:** Zero-allocation design, profiling, benchmarking
- **Adding Elements:** How to implement new element types
- **CI/CD:** Continuous integration, releases, versioning
- **Git Workflow:** Branching, commits, pull requests
## What's NOT Here
- User tutorials (see `docs/user/` for that)
- Deep mathematical theory (see `docs/book/` for that)
- "How do I solve problem X?" (that's user docs)
## Philosophy
**"Show me the code AND tell me why."**
We assume you:
- Know Julia reasonably well
- Understand FEM basics
- Want to add features or fix bugs
- Care about performance and correctness
- Need to understand design rationale
## Before Contributing
1. Read [Testing Philosophy](testing_philosophy.md)
2. Understand [Architecture](architecture.md)
3. Follow [Code Style](code_style.md)
4. Check [Performance Guidelines](performance.md)
5. Review [Git Workflow](git_workflow.md)
## Key Principles
- **Type stability:** No `Any`, no `Dict` without types
- **Zero allocations:** Hot paths should allocate nothing
- **Immutability:** Prefer `struct` over `mutable struct`
- **Composition:** Use tuples and free functions, not OOP hierarchies
- **Explicit:** No magic, user knows what happens
- **Test first:** Write tests before fixing bugs
---
**Start here:** [Testing Philosophy](testing_philosophy.md) | [Architecture Overview](architecture.md)
+40
View File
@@ -0,0 +1,40 @@
# JuliaFEM User Manual
**Audience:** End users, engineers, students who want to run simulations and get results.
This manual is designed to be **simple and practical** - get you from zero to running simulations as quickly as possible.
## What's Here
- **Quick Start:** Installation and first simulation in 5 minutes
- **Tutorials:** Step-by-step guides for common problems
- **Examples:** Pre-built simulations you can run and modify
- **API Reference:** Function documentation (what does this do?)
- **Troubleshooting:** Common errors and how to fix them
## What's NOT Here
- Deep theory (see `docs/book/` for that)
- How to contribute code (see `docs/contributor/` for that)
- Internal architecture details
## Philosophy
**"Just show me how to solve my problem."**
We assume you:
- Have a problem to solve (heat transfer, elasticity, contact)
- Want working code, not lectures
- Will read theory when YOU need it, not when WE think you should
## Getting Help
1. Start with the Quick Start
2. Find an example similar to your problem
3. Modify it to fit your needs
4. If stuck, check Troubleshooting
5. Still stuck? Ask on GitHub Discussions
---
**Next:** Start with [Quick Start](quickstart.md) or browse [Examples](../examples/)