Coding with Rust for 'Rust': Modeling the 100-Hour Battery Grid

Published: (December 9, 2025 at 03:33 PM EST)
2 min read
Source: Dev.to

Source: Dev.to

How Software Engineers Will Manage the Next Generation of Long-Duration Energy Storage

#[derive(Debug, Clone)]
struct IronAirBattery {
    capacity_kwh: f64,
    current_charge_kwh: f64,
    efficiency_factor: f64, // Iron‑Air is usually around 50‑60%
    max_charge_rate_kw: f64,
    max_discharge_rate_kw: f64,
    is_rusting: bool, // True = Discharging, False = Charging
}

impl IronAirBattery {
    fn new(capacity: f64) -> Self {
        IronAirBattery {
            capacity_kwh: capacity,
            current_charge_kwh: 0.0,
            efficiency_factor: 0.55, // The physics constraint
            max_charge_rate_kw: 50.0, // Slow charge
            max_discharge_rate_kw: 50.0, // Slow discharge
            is_rusting: true,
        }
    }

    // The "Un‑Rusting" Process (Charging)
    fn charge(&mut self, energy_input_kwh: f64) -> Result {
        let actual_stored = energy_input_kwh * self.efficiency_factor;

        if self.current_charge_kwh + actual_stored > self.capacity_kwh {
            self.current_charge_kwh = self.capacity_kwh;
            self.is_rusting = false;
            return Ok(self.capacity_kwh);
        }

        self.current_charge_kwh += actual_stored;
        self.is_rusting = false;
        Ok(self.current_charge_kwh)
    }

    // The "Rusting" Process (Discharging)
    fn discharge(&mut self, demand_kwh: f64) -> f64 {
        self.is_rusting = true;
        if self.current_charge_kwh >= demand_kwh {
            self.current_charge_kwh -= demand_kwh;
            demand_kwh
        } else {
            let remaining = self.current_charge_kwh;
            self.current_charge_kwh = 0.0;
            remaining
        }
    }
}

Iron‑Air Battery Diagram

Part 3: The Logic Layer – The “Multi‑Day” Algorithm

The main challenge with Iron‑Air batteries is their slow response. They are unsuitable for second‑by‑second grid‑frequency regulation and are instead designed for multi‑day shifting. Consequently, the control algorithm must incorporate weather forecasts rather than relying solely on current load.

import numpy as np

class HybridGridController:
    def __init__(self, li_ion_capacity, iron_air_capacity):
        self.li_ion_storage = li_ion_capacity
        self.iron_air_storage = iron_air_capacity
        # Threshold: Only use Iron‑Air if outage is predicted > 4 hours
        self.long_duration_threshold = 4

    def decision_logic(self, grid_status, forecast_hours_without_sun):
        """
        grid_status: 'NORMAL', 'STRESS', 'BLACKOUT'
        forecast_hours_without_sun: int
        """
        print(f"Analyzing Grid: {grid_status} | Darkness Forecast: {forecast_hours_without_sun}h")

        if grid_status == 'NORMAL':
            # Priority: Recharge Iron‑Air first because it takes literally days
            return "ACTION: CHARGE_IRON_AIR_SLOWLY"

        elif grid_status == 'STRESS':
            if forecast_hours_without_sun  (
  
    
    
    
    
    
    
  
);

export default GridDashboard;

Start by understanding the Iron‑Air chemistry—because you can’t optimize what you don’t understand.

Happy coding (and rusting)!

Back to Blog

Related posts

Read more »