Rust와 코딩하기: ‘Rust’를 위한 100시간 배터리 그리드 모델링

발행: (2025년 12월 10일 오전 05:33 GMT+9)
2 min read
원문: Dev.to

Source: Dev.to

Rust 구현: Iron‑Air 배터리

#[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 배터리 다이어그램

Iron‑Air 배터리 다이어그램

멀티‑데이 알고리즘 (Python)

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  (
  
  
  
  
  
  
  
);

JavaScript 내보내기

); export default GridDashboard;

Iron‑Air 화학을 먼저 이해하세요—이해하지 못하면 최적화할 수 없습니다.

행복한 코딩 (그리고 부식)!

Back to Blog

관련 글

더 보기 »

신뢰할 수 있는 C

기사 URL: https://dependablec.org/ 댓글 URL: https://news.ycombinator.com/item?id=46214091 점수: 8 댓글: 1...