pub struct SolarPv {
pub kw_peak: f32,
pub steps_per_day: usize,
pub sunrise_idx: usize,
pub sunset_idx: usize,
pub noise_std: f32,
rng: StdRng,
}Expand description
A solar PV generator that models power generation based on daylight hours.
SolarPv creates a half-cosine shaped generation profile between sunrise and sunset
times with configurable peak power output and random noise to simulate
variations due to weather conditions.
§Examples
Note: vpp-sim currently ships as a binary-first crate; this snippet is illustrative.
use vpp_sim::devices::solar::SolarPv;
use vpp_sim::devices::types::{Device, DeviceContext};
// Create a solar PV system (5kW peak, 24 steps per day, sunrise at 6am, sunset at 6pm)
let mut pv = SolarPv::new(
5.0, // kw_peak - maximum output in ideal conditions
24, // steps_per_day - hourly resolution
6, // sunrise_idx - 6am sunrise
18, // sunset_idx - 6pm sunset
0.05, // noise_std - small random variation for cloud cover
42, // seed - for reproducible randomness
);
// Get generation at noon (step 12)
let generation = pv.power_kw(&DeviceContext::new(12));Fields§
§kw_peak: f32Maximum power output in kilowatts under ideal conditions
steps_per_day: usizeNumber of time steps per simulated day
sunrise_idx: usizeTime step index when sunrise occurs (inclusive)
sunset_idx: usizeTime step index when sunset occurs (exclusive)
noise_std: f32Standard deviation of the Gaussian noise as a fraction of output
rng: StdRngRandom number generator for noise generation
Implementations§
Source§impl SolarPv
impl SolarPv
Sourcepub fn new(
kw_peak: f32,
steps_per_day: usize,
sunrise_idx: usize,
sunset_idx: usize,
noise_std: f32,
seed: u64,
) -> Self
pub fn new( kw_peak: f32, steps_per_day: usize, sunrise_idx: usize, sunset_idx: usize, noise_std: f32, seed: u64, ) -> Self
Creates a new solar PV generator with the specified parameters.
§Arguments
kw_peak- Maximum power output in kilowatts under ideal conditionssteps_per_day- Number of time steps per simulated daysunrise_idx- Time step index when sunrise occurs (inclusive)sunset_idx- Time step index when sunset occurs (exclusive)noise_std- Standard deviation of noise (e.g., 0.05 for ±5% variation)seed- Random seed for reproducible noise generation
§Panics
This function will panic if:
steps_per_dayis zerosunrise_idxis greater thansunset_idxsunset_idxexceedssteps_per_day
§Returns
A new SolarPv instance configured with the specified parameters
Sourcefn daylight_frac(&self, t: usize) -> f32
fn daylight_frac(&self, t: usize) -> f32
Calculates the daylight fraction for a specific time step.
Returns a value between 0.0 and 1.0 representing the relative solar intensity, following a half-cosine shape from sunrise to sunset. Returns 0.0 during nighttime hours.
§Arguments
t- The simulation time step
§Returns
A fraction between 0.0 and 1.0 representing the relative solar intensity
Trait Implementations§
Source§impl Device for SolarPv
impl Device for SolarPv
Source§fn power_kw(&mut self, context: &DeviceContext) -> f32
fn power_kw(&mut self, context: &DeviceContext) -> f32
Calculates the power generation at a specific time step.
This method computes the power generation as a combination of:
- Base solar output following a half-cosine curve during daylight hours
- Random Gaussian noise to simulate variations due to cloud cover
The generation is guaranteed to be non-negative.
§Arguments
timestep- The simulation time step
§Returns
The power generation in kilowatts at the specified time step