thevenin.loadfns#
This module contains classes to help construct time-varying load profiles. All of the classes are callable after construction and take in a value of time in seconds. Most load functions include a linear ramp that “smooths” transitions from rest to a constant load, or between constant steps. Using ramps helps the solver maintain stability when a boundary condition sharply changes from one value to another, e.g., jumping from rest into a high-rate charge or discharge. For example, in some cases the solver may crash for a high-rate discharge.
Classes#
Linearly ramping load. |
|
Ramp to a constant load. |
|
Step function with ramps. |
|
Piecewise step function. |
Package Contents#
- class thevenin.loadfns.Ramp(m, b=0.0)[source]#
Linearly ramping load.
A load profile that continuously ramps with slope m.
- Parameters:
m (float) – Slope [units/s].
b (float, optional) – Y-intercept [units]. The default is 0.
- class thevenin.loadfns.Ramp2Constant(m, step, b=0.0, sharpness=100.0)[source]#
Ramp to a constant load.
A load profile that ramps with slope m unil the constant step value is reached, after which, the load is equal to the step constant. A sigmoid is used to smooth the transition between the two piecewise functions. Use a large ‘sharpness’ to reduce smoothing effects.
- Parameters:
m (float) – Slope [units/s].
step (float) – Constant step value [units].
b (float, optional) – Y-intercept [units]. The default is 0.
sharpness (float, optional) – How sharp to make the transition between the ramp and step. Low values will smooth the transition more. The default is 100.
- Raises:
ValueError – m = 0. and m = inf are invalid slopes.
ValueError – Cannot reach step with m > 0. and b >= step.
ValueError – Cannot reach step with m < 0. and b <= step.
ValueError – ‘sharpness’ must be strictly positive.
- class thevenin.loadfns.RampedSteps(tp, yp, t_ramp, y0=0.0)[source]#
Step function with ramps.
This class acts like StepFunction, with the same tp, yp, and y0, but step transitions include ramps with duration t_ramp. Generally, this profile will be more stable compared to a StepFunction profile.
- Parameters:
tp (1D np.array) – Times at which a step change occurs [seconds].
yp (1D np.array) – Constant values for each time interval.
t_ramp (float) – Ramping time between step transitions [seconds].
y0 (float) – Value to return when t < tp[0]. In addition to standard float values, np.nan and np.inf are supported. The default is 0.
- Raises:
ValueError – tp and yp must both be 1D.
ValueError – tp and yp must be same size.
ValueError – t_ramp must be strictly positive.
ValueError – tp must be strictly increasing.
See also
StepFunctionUses hard discontinuous steps rather than ramped steps. Generally non-ideal for simulations, but may be useful elsewhere.
- class thevenin.loadfns.StepFunction(tp, yp, y0=0.0, ignore_nan=False)[source]#
Piecewise step function.
Construct a piecewise step function given the times at which step changes occur and the values for each time interval. For example,
tp = np.array([0, 5]) yp = np.array([-1, 1]) y = StepFunction(tp, yp, np.nan)
Corresponds to
if t < 0: y = np.nan elif 0 <= t < 5: y = -1 else: y = 1
- Parameters:
tp (1D np.array) – Times at which a step change occurs [s].
yp (1D np.array) – Constant values for each time interval.
y0 (float, optional) – Value to return when t < tp[0]. In addition to standard float values, np.nan and np.inf are supported. The default is 0.
ignore_nan (bool, optional) – Whether or not to ignore NaN inputs. For NaN inputs, the callable returns NaN when False (default) or yp[-1] when True.
- Raises:
ValueError – tp and yp must both be 1D.
ValueError – tp and yp must be same size.
ValueError – tp must be strictly increasing.
Examples
>>> tp = np.array([0, 1, 5]) >>> yp = np.array([-1, 0, 1]) >>> func = StepFunction(tp, yp, np.nan) >>> print(func(np.array([-10, 0.5, 4, 10]))) [nan -1. 0. 1.]