chore: sync project state and current artifacts
This commit is contained in:
@@ -0,0 +1,168 @@
|
||||
# Story 9.7: Refactoring Solver - Scinder solver.rs
|
||||
|
||||
**Epic:** 9 - Coherence Corrections (Post-Audit)
|
||||
**Priorité:** P3-AMÉLIORATION
|
||||
**Estimation:** 4h
|
||||
**Statut:** backlog
|
||||
**Dépendances:** Aucune
|
||||
|
||||
---
|
||||
|
||||
## Story
|
||||
|
||||
> En tant que développeur maintenant le code,
|
||||
> Je veux que les stratégies de solver soient dans des fichiers séparés,
|
||||
> Afin d'améliorer la maintenabilité et la lisibilité du code.
|
||||
|
||||
---
|
||||
|
||||
## Contexte
|
||||
|
||||
L'audit de cohérence a révélé que `solver.rs` fait environ **2800 lignes**, ce qui dépasse largement les recommandations de l'architecture.md (max 500 lignes par fichier).
|
||||
|
||||
---
|
||||
|
||||
## Problème Actuel
|
||||
|
||||
```
|
||||
crates/solver/src/
|
||||
├── lib.rs
|
||||
├── solver.rs # ~2800 lignes (!)
|
||||
├── system.rs
|
||||
├── jacobian.rs
|
||||
└── ...
|
||||
```
|
||||
|
||||
Le fichier `solver.rs` contient :
|
||||
- Le trait `Solver`
|
||||
- L'enum `SolverStrategy`
|
||||
- L'implémentation `NewtonRaphson`
|
||||
- L'implémentation `SequentialSubstitution`
|
||||
- L'implémentation `FallbackStrategy`
|
||||
- La logique de convergence
|
||||
- Les helpers de diagnostic
|
||||
|
||||
---
|
||||
|
||||
## Solution Proposée
|
||||
|
||||
### Structure cible
|
||||
|
||||
```
|
||||
crates/solver/src/
|
||||
├── lib.rs
|
||||
├── solver.rs # Trait Solver, SolverStrategy enum (~200 lignes)
|
||||
├── strategies/
|
||||
│ ├── mod.rs # Module exports
|
||||
│ ├── newton_raphson.rs # Implémentation Newton-Raphson
|
||||
│ ├── sequential_substitution.rs # Implémentation Picard
|
||||
│ └── fallback.rs # Stratégie de fallback
|
||||
├── convergence.rs # Critères de convergence
|
||||
├── diagnostics.rs # Helpers de diagnostic
|
||||
├── system.rs
|
||||
├── jacobian.rs
|
||||
└── ...
|
||||
```
|
||||
|
||||
### Implémentation
|
||||
|
||||
```rust
|
||||
// crates/solver/src/strategies/mod.rs
|
||||
|
||||
mod newton_raphson;
|
||||
mod sequential_substitution;
|
||||
mod fallback;
|
||||
|
||||
pub use newton_raphson::NewtonRaphson;
|
||||
pub use sequential_substitution::SequentialSubstitution;
|
||||
pub use fallback::FallbackStrategy;
|
||||
|
||||
use crate::{Solver, System, SystemState, SolverResult, SolverError};
|
||||
|
||||
/// Stratégies de résolution disponibles.
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub enum SolverStrategy {
|
||||
#[default]
|
||||
NewtonRaphson,
|
||||
SequentialSubstitution,
|
||||
Fallback,
|
||||
}
|
||||
|
||||
impl Solver for SolverStrategy {
|
||||
fn solve(&self, system: &mut System, initial_state: &SystemState) -> SolverResult {
|
||||
match self {
|
||||
SolverStrategy::NewtonRaphson => {
|
||||
NewtonRaphson.solve(system, initial_state)
|
||||
}
|
||||
SolverStrategy::SequentialSubstitution => {
|
||||
SequentialSubstitution.solve(system, initial_state)
|
||||
}
|
||||
SolverStrategy::Fallback => {
|
||||
FallbackStrategy.solve(system, initial_state)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
```rust
|
||||
// crates/solver/src/strategies/newton_raphson.rs
|
||||
|
||||
use crate::{Solver, System, SystemState, SolverResult, SolverError};
|
||||
|
||||
/// Solveur Newton-Raphson.
|
||||
///
|
||||
/// Utilise la matrice Jacobienne pour une convergence quadratique
|
||||
/// près de la solution.
|
||||
pub struct NewtonRaphson;
|
||||
|
||||
impl Solver for NewtonRaphson {
|
||||
fn solve(&self, system: &mut System, initial_state: &SystemState) -> SolverResult {
|
||||
// ... implémentation ...
|
||||
}
|
||||
}
|
||||
|
||||
// ... helper methods ...
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Fichiers à Créer/Modifier
|
||||
|
||||
| Fichier | Action |
|
||||
|---------|--------|
|
||||
| `crates/solver/src/strategies/mod.rs` | Créer |
|
||||
| `crates/solver/src/strategies/newton_raphson.rs` | Créer |
|
||||
| `crates/solver/src/strategies/sequential_substitution.rs` | Créer |
|
||||
| `crates/solver/src/strategies/fallback.rs` | Créer |
|
||||
| `crates/solver/src/convergence.rs` | Créer |
|
||||
| `crates/solver/src/diagnostics.rs` | Créer |
|
||||
| `crates/solver/src/solver.rs` | Réduire |
|
||||
| `crates/solver/src/lib.rs` | Mettre à jour exports |
|
||||
|
||||
---
|
||||
|
||||
## Critères d'Acceptation
|
||||
|
||||
- [ ] Chaque fichier < 500 lignes
|
||||
- [ ] `cargo test --workspace` passe
|
||||
- [ ] API publique inchangée (pas de breaking change)
|
||||
- [ ] `cargo clippy -- -D warnings` passe
|
||||
- [ ] Documentation rustdoc présente
|
||||
|
||||
---
|
||||
|
||||
## Risques et Mitigations
|
||||
|
||||
| Risque | Mitigation |
|
||||
|--------|------------|
|
||||
| Breaking change API | Garder les mêmes exports dans `lib.rs` |
|
||||
| Imports circulaires | Vérifier les dépendances avant refactor |
|
||||
| Perte de performance | Benchmark avant/après |
|
||||
|
||||
---
|
||||
|
||||
## Références
|
||||
|
||||
- [Architecture.md - Project Structure](../planning-artifacts/architecture.md#Project-Structure)
|
||||
- [Coherence Audit Report](./coherence-audit-remediation-plan.md)
|
||||
Reference in New Issue
Block a user