Skip to content

Conversation

@fderuiter
Copy link
Owner

This PR refactors the math_explorer/src/biology/morphogenesis.rs file into a modular structure.
It addresses the "God Method" anti-pattern where the finite-difference stencil logic was duplicated between the Euler integrator and the ODE system derivative calculation.

Key Changes:

  1. Module Decomposition: Split the monolithic file into kinetics (Reaction Rules), state (Data Structure), and system (Solver Logic).
  2. Stencil Abstraction: Created a private, generic apply_reaction_diffusion_stencil method that handles the sliding window optimization and boundary conditions. It accepts a closure to define how the calculated rates are used (state update vs derivative storage).
  3. Zero-Cost Abstraction: The closure strategy is inlined, ensuring that the performance matches the original hand-rolled loops (verified via inspection).

This improves maintainability and prepares the module for future extensions (e.g., 2D support) without duplicating the grid iteration logic.


PR created automatically by Jules for task 1436632298601569212 started by @fderuiter

- Split `morphogenesis.rs` into `kinetics.rs`, `state.rs`, `system.rs`.
- Extracted `apply_reaction_diffusion_stencil` to deduplicate logic between `step` (Euler) and `derivative` (ODE).
- Implemented Zero-Cost Abstraction using closure strategy for the stencil loop.
- Updated ADR and documentation.

Co-authored-by: fderuiter <127706008+fderuiter@users.noreply.github.com>
@google-labs-jules
Copy link
Contributor

πŸ‘‹ Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a πŸ‘€ emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@fderuiter
Copy link
Owner Author

Run cargo fmt -- --check
Diff in /home/runner/work/math/math/math_explorer/src/biology/morphogenesis/system.rs:1:
-use crate::pure_math::analysis::ode::{OdeSystem, TimeStepper};
use super::kinetics::{ReactionKinetics, SchnakenbergKinetics};
use super::state::TuringState;
+use crate::pure_math::analysis::ode::{OdeSystem, TimeStepper};

/// Represents a 1D Reaction-Diffusion system.
pub struct TuringSystem<K: ReactionKinetics = SchnakenbergKinetics> {
Diff in /home/runner/work/math/math/math_explorer/src/biology/morphogenesis/system.rs:237:
self.d_u,
self.d_v,
self.dx,

  •        |i, _u, _v, du, dv| {
    
  •            unsafe {
    
  •                *out_u.get_unchecked_mut(i) = du;
    
  •                *out_v.get_unchecked_mut(i) = dv;
    
  •            }
    
  •        |i, _u, _v, du, dv| unsafe {
    
  •            *out_u.get_unchecked_mut(i) = du;
    
  •            *out_v.get_unchecked_mut(i) = dv;
           },
       );
    
    }
    Error: Process completed with exit code 1.

@google-labs-jules
Copy link
Contributor

Run cargo fmt -- --check
Diff in /home/runner/work/math/math/math_explorer/src/biology/morphogenesis/system.rs:1:
-use crate::pure_math::analysis::ode::{OdeSystem, TimeStepper};
use super::kinetics::{ReactionKinetics, SchnakenbergKinetics};
use super::state::TuringState;
+use crate::pure_math::analysis::ode::{OdeSystem, TimeStepper};

/// Represents a 1D Reaction-Diffusion system.
pub struct TuringSystem<K: ReactionKinetics = SchnakenbergKinetics> {
Diff in /home/runner/work/math/math/math_explorer/src/biology/morphogenesis/system.rs:237:
self.d_u,
self.d_v,
self.dx,

  •        |i, _u, _v, du, dv| {
    
  •            unsafe {
    
  •                *out_u.get_unchecked_mut(i) = du;
    
  •                *out_v.get_unchecked_mut(i) = dv;
    
  •            }
    
  •        |i, _u, _v, du, dv| unsafe {
    
  •            *out_u.get_unchecked_mut(i) = du;
    
  •            *out_v.get_unchecked_mut(i) = dv;
           },
       );
    
    }
    Error: Process completed with exit code 1.

Fixed formatting issues by running cargo fmt.

Co-authored-by: fderuiter <127706008+fderuiter@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants