Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
48a719c
Added StateParameters.number_of_constraints.
davidfillmore Oct 15, 2025
1f10bba
Added number_of_constraints to solver_builder.inl.
davidfillmore Oct 15, 2025
8acd5c9
Added number_of_constraints arguments to AbstractBackwardEuler.
davidfillmore Oct 15, 2025
30971c2
Use number_of_species + number_of_constraints in BuildJacobian.
davidfillmore Oct 15, 2025
2117432
Added upper_left_diagonal_elements_.
davidfillmore Oct 17, 2025
51f7e27
Added upper_left_diagonal_elements_ in State constructors.
davidfillmore Oct 17, 2025
cd249cc
Added constraint_size_ to State.
davidfillmore Oct 19, 2025
98d15be
Renamed to upper_left_identity_diagonal_.
davidfillmore Oct 19, 2025
767addb
BuildJacobian with state_size_ + constraint_size_ in State.
davidfillmore Oct 19, 2025
255d3c7
Added includes.
Nov 21, 2025
c2df336
Merge branch 'main' into rosenbrock_dae
Nov 21, 2025
5c3e587
Implemented builder-level support for future constraints without chan…
Nov 25, 2025
3e58d73
Merge branch 'main' into rosenbrock_dae
Jan 14, 2026
0843d14
Add DAE constraint system infrastructure
dwfncar Jan 14, 2026
143b7dd
Fix AlphaMinusJacobian for DAE constraint support
dwfncar Jan 14, 2026
29d871d
Add Claude Code skills for MICM development
dwfncar Jan 14, 2026
a9bbb30
Add CLAUDE.md project context for Claude Code
dwfncar Jan 14, 2026
5c09062
Add TESTS.md with 12 DAE test cases, Chapman mechanism next
dwfncar Jan 14, 2026
0348c93
Add CSV output requirement for numerical tests
dwfncar Jan 14, 2026
632a201
Add resume prompt to CLAUDE.md for future sessions
dwfncar Jan 14, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions .claude/commands/debug-test.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Debug Test

Debug a failing MICM test with tracing support.

## Usage

- `/debug-test <test_name>` - Debug a specific test

## Instructions

When the user invokes this skill with a test name:

1. **Run the test first** to confirm failure:
```bash
ctest --test-dir /Users/fillmore/EarthSystem/MICM/build --output-on-failure -R "<test_name>" -V
```

2. **If the test passes**, report success and exit.

3. **If the test fails**, analyze the output:
- Look for NaN, Inf, or exploding values
- Check for assertion failures
- Identify which solver component failed

4. **For numerical failures** (NaN/Inf/explosion):
- Offer to add debug tracing to `rosenbrock.inl`
- Key trace points:
- After `AlphaMinusJacobian`: print diagonal values
- After linear solve: print K values
- In forcing: print residual values

5. **Add tracing code** (with user confirmation):
```cpp
// In rosenbrock.inl Solve() loop, after LinearFactor call:
std::cerr << "=== Step " << result.stats_.number_of_steps_ << " ===" << std::endl;
std::cerr << "H = " << H << ", alpha = " << (1.0 / (H * parameters.gamma_[0])) << std::endl;
for (std::size_t i = 0; i < state.jacobian_.NumColumns(); ++i)
std::cerr << "Diag[" << i << "] = " << state.jacobian_.DiagonalElement(0, i) << std::endl;
```

6. **Rebuild and rerun** with tracing enabled.

7. **Analyze trace output**:
- Compare diagonal magnitudes (should be similar)
- Check K value scaling (should scale with H)
- Look for sign errors

8. **Clean up** tracing code when done.

## Common Issues

| Symptom | Likely Cause | Check |
|---------|--------------|-------|
| Values explode to 10^16+ | Ill-conditioned matrix | Diagonal magnitudes |
| NaN after linear solve | Singular matrix | Zero diagonals |
| Wrong steady state | Sign error in Jacobian | SubtractJacobianTerms signs |
| Constraint not satisfied | Missing projection step | Post-solve enforcement |
45 changes: 45 additions & 0 deletions .claude/commands/micm-test.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# MICM Test Runner

Build and run MICM tests efficiently.

## Usage

- `/micm-test` - Build and run all tests
- `/micm-test build` - Build only (no tests)
- `/micm-test <pattern>` - Run tests matching pattern (e.g., `constraint`, `rosenbrock`)

## Instructions

When the user invokes this skill:

1. **Parse the argument** (if any):
- No argument or empty: run all tests
- `build`: build only
- Any other string: use as test filter pattern

2. **Build the project**:
```bash
cmake --build /Users/fillmore/EarthSystem/MICM/build -j$(sysctl -n hw.ncpu)
```

3. **Run tests** (unless build-only):
- All tests: `ctest --test-dir /Users/fillmore/EarthSystem/MICM/build --output-on-failure`
- Filtered: `ctest --test-dir /Users/fillmore/EarthSystem/MICM/build --output-on-failure -R "<pattern>"`

4. **Report results**:
- Show pass/fail count
- If failures, show which tests failed
- Suggest `/debug-test <name>` for failed tests

## Example Output

```
Building MICM...
Build successful.

Running tests matching "constraint"...
3/3 tests passed:
- constraint
- constraint_set
- equilibrium (contains constraint tests)
```
78 changes: 78 additions & 0 deletions .claude/commands/solver-debug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Solver Debug Agent

Investigate numerical issues in MICM solvers.

## Usage

- `/solver-debug` - Start numerical debugging investigation

## Instructions

When the user invokes this skill, launch an investigation of solver numerical issues.

### Phase 1: Gather Context

1. **Ask the user** what symptom they're seeing:
- Values exploding (which variable?)
- NaN or Inf appearing
- Wrong steady state
- Solver not converging
- Step size going to minimum

2. **Read the relevant solver file**:
- For Rosenbrock: `include/micm/solver/rosenbrock.inl`
- For Backward Euler: `include/micm/solver/backward_euler.inl`

### Phase 2: Trace Data Flow

For Rosenbrock solver issues, trace through:

1. **Forcing calculation** (`AddForcingTerms`):
- ODE forcing: `rates_.AddForcingTerms()`
- Constraint forcing: `constraints_.AddForcingTerms()`
- Expected magnitude: O(rate × concentration)

2. **Jacobian calculation** (`SubtractJacobianTerms`):
- Stores `-J_true` (negative of true Jacobian)
- ODE Jacobian: `rates_.SubtractJacobianTerms()`
- Constraint Jacobian: `constraints_.SubtractJacobianTerms()`

3. **Matrix formation** (`AlphaMinusJacobian`):
- Adds `alpha = 1/(H * gamma)` to ALL diagonals
- Result should have all diagonals of similar magnitude
- If constraint diagonals are much smaller → ill-conditioning

4. **Linear solve**:
- Solves `(αI - J) * K = forcing`
- K values should scale with H

5. **Stage computation**:
- Uses `c/H * K` terms
- If K doesn't scale with H → c/H amplifies errors

### Phase 3: Identify Root Cause

Common patterns:

| Symptom | Root Cause | Solution |
|---------|------------|----------|
| Constraint var explodes | Missing alpha on constraint diagonal | Check AlphaMinusJacobian |
| All vars explode | Singular Jacobian | Check for zero rate constants |
| Wrong equilibrium | Sign error | Check SubtractJacobianTerms |
| Slow convergence | Step too large | Reduce h_max |

### Phase 4: Recommend Fix

Based on the root cause:

1. **Code fix**: If a bug is found, show the fix
2. **Parameter tuning**: Suggest solver parameter changes
3. **Usage fix**: Suggest projection steps or smaller time steps
4. **Test addition**: Suggest a test case to prevent regression

## Key Files Reference

- `rosenbrock.inl:52-60` - Forcing calculation
- `rosenbrock.inl:62-71` - Jacobian calculation
- `rosenbrock.inl:224-261` - AlphaMinusJacobian (both versions)
- `constraint_set.hpp` - Constraint forcing/Jacobian methods
Loading
Loading