SolarPv

Struct SolarPv 

Source
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: f32

Maximum power output in kilowatts under ideal conditions

§steps_per_day: usize

Number of time steps per simulated day

§sunrise_idx: usize

Time step index when sunrise occurs (inclusive)

§sunset_idx: usize

Time step index when sunset occurs (exclusive)

§noise_std: f32

Standard deviation of the Gaussian noise as a fraction of output

§rng: StdRng

Random number generator for noise generation

Implementations§

Source§

impl SolarPv

Source

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 conditions
  • steps_per_day - Number of time steps per simulated day
  • sunrise_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_day is zero
  • sunrise_idx is greater than sunset_idx
  • sunset_idx exceeds steps_per_day
§Returns

A new SolarPv instance configured with the specified parameters

Source

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 Debug for SolarPv

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Device for SolarPv

Source§

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

Source§

fn device_type(&self) -> &'static str

Returns a human-readable type name for the device.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.