implementations.problem_classes.Battery module

class battery(ncapacitors=1, Vs=5.0, Rs=0.5, C=None, R=1.0, L=1.0, alpha=1.2, V_ref=None)[source]

Bases: battery_n_capacitors

Example implementing the battery drain model with \(N=1\) capacitor, inherits from battery_n_capacitors. This model is an example of a discontinuous problem. The state function \(decides\) which differential equation is solved. When the state function has a sign change the dynamics of the solution changes by changing the differential equation. The ODE system of this model is given by the following equations:

If \(h(v_1) := v_1 - V_{ref, 0} > 0:\)

\[\frac{d i_L (t)}{dt} = 0,\]
\[\frac{d v_1 (t)}{dt} = -\frac{1}{CR}v_1 (t),\]

else:

\[\frac{d i_L(t)}{dt} = -\frac{R_s + R}{L}i_L (t) + \frac{1}{L} V_s,\]
\[\frac{d v_1(t)}{dt} = 0,\]

where \(i_L\) denotes the function of the current over time \(t\).

Note

This class has the same attributes as the class it inherits from.

dtype_f

alias of imex_mesh

eval_f(u, t)[source]

Routine to evaluate the right-hand side of the problem.

Parameters:
  • u (dtype_u) – Current values of the numerical solution.

  • t (float) – Current time of the numerical solution is computed.

Returns:

f – The right-hand side of the problem.

Return type:

dtype_f

solve_system(rhs, factor, u0, t)[source]

Simple linear solver for \((I-factor\cdot A)\vec{u}=\vec{rhs}\).

Parameters:
  • rhs (dtype_f) – Right-hand side for the linear system.

  • factor (float) – Abbrev. for the local stepsize (or any other factor required).

  • u0 (dtype_u) – Initial guess for the iterative solver.

  • t (float) – Current time (e.g. for time-dependent BCs).

Returns:

me – The solution as mesh.

Return type:

dtype_u

u_exact(t)[source]

Routine to compute the exact solution at time \(t\).

Parameters:

t (float) – Time of the exact solution.

Returns:

me – The exact solution.

Return type:

dtype_u

class battery_implicit(ncapacitors=1, Vs=5.0, Rs=0.5, C=None, R=1.0, L=1.0, alpha=1.2, V_ref=None, newton_maxiter=100, newton_tol=1e-11)[source]

Bases: battery

Example implementing the battery drain model as above. The method solve_system uses a fully-implicit computation.

Parameters:
  • ncapacitors (int, optional) – Number of capacitors in the circuit.

  • Vs (float, optional) – Voltage at the voltage source \(V_s\).

  • Rs (float, optional) – Resistance of the resistor \(R_s\) at the voltage source.

  • C (np.1darray, optional) – Capacitances of the capacitors. Length of array must equal to number of capacitors.

  • R (float, optional) – Resistance for the load \(R_\ell\).

  • L (float, optional) – Inductance of inductor \(L\).

  • alpha (float, optional) – Factor greater than zero to describe the storage of the capacitor(s).

  • V_ref (float, optional) – Reference value greater than zero for the battery to switch to the voltage source.

  • newton_maxiter (int, optional) – Number of maximum iterations for the Newton solver.

  • newton_tol (float, optional) – Tolerance for determination of the Newton solver.

work_counters

Counts different things, here: Number of Newton iterations is counted.

Type:

WorkCounter

dtype_f

alias of mesh

eval_f(u, t)[source]

Routine to evaluate the right-hand side of the problem.

Parameters:
  • u (dtype_u) – Current values of the numerical solution.

  • t (float) – Current time of the numerical solution is computed.

Returns:

f – The right-hand side of the problem.

Return type:

dtype_f

solve_system(rhs, factor, u0, t)[source]

Simple Newton solver.

Parameters:
  • rhs (dtype_f) – Right-hand side for the nonlinear system.

  • factor (float) – Abbrev. for the local stepsize (or any other factor required).

  • u0 (dtype_u) – Initial guess for the iterative solver

  • t (float) – Current time (e.g. for time-dependent BCs).

Returns:

me – The solution as mesh.

Return type:

dtype_u

class battery_n_capacitors(ncapacitors=2, Vs=5.0, Rs=0.5, C=None, R=1.0, L=1.0, alpha=1.2, V_ref=None)[source]

Bases: Problem

Example implementing the battery drain model with \(N\) capacitors, where \(N\) is an arbitrary integer greater than zero. First, the capacitor \(C\) serves as a battery and provides energy. When the voltage of the capacitor \(v_{C_n}\) for \(n=1,..,N\) drops below their reference value \(V_{ref,n-1}\), the circuit switches to the next capacitor. If all capacitors has dropped below their reference value, the voltage source \(V_s\) provides further energy. The problem of simulating the battery draining has \(N + 1\) different states. Each of this state can be expressed as a nonhomogeneous linear system of ordinary differential equations (ODEs)

\[\frac{d u(t)}{dt} = A_k u(t) + f_k (t)\]

for \(k=1,..,N+1\) using an initial condition.

Parameters:
  • ncapacitors (int, optional) – Number of capacitors \(n_{capacitors}\) in the circuit.

  • Vs (float, optional) – Voltage at the voltage source \(V_s\).

  • Rs (float, optional) – Resistance of the resistor \(R_s\) at the voltage source.

  • C (np.1darray, optional) – Capacitances of the capacitors \(C_n\).

  • R (float, optional) – Resistance for the load \(R_\ell\).

  • L (float, optional) – Inductance of inductor \(L\).

  • alpha (float, optional) – Factor greater than zero to describe the storage of the capacitor(s).

  • V_ref (np.1darray, optional) – Array contains the reference values greater than zero for each capacitor to switch to the next energy source.

A

Coefficients matrix of the linear system of ordinary differential equations (ODEs).

Type:

matrix

switch_A

Dictionary that contains the coefficients for the coefficient matrix A.

Type:

dict

switch_f

Dictionary that contains the coefficients of the right-hand side f of the ODE system.

Type:

dict

t_switch

Time point of the discrete event found by switch estimation.

Type:

float

nswitches

Number of switches found by switch estimation.

Type:

int

Note

The array containing the capacitances \(C_n\) and the array containing the reference values \(V_{ref, n-1}\) for each capacitor must be equal to the number of capacitors \(n_{capacitors}\).

count_switches()[source]

Counts the number of switches. This function is called when a switch is found inside the range of tolerance (in pySDC/projects/PinTSimE/switch_estimator.py)

dtype_f

alias of imex_mesh

dtype_u

alias of mesh

eval_f(u, t)[source]

Routine to evaluate the right-hand side of the problem. Let \(v_k:=v_{C_k}\) be the voltage of capacitor \(C_k\) for \(k=1,..,N\) with reference value \(V_{ref, k-1}\). No switch estimator is used: For \(N = 3\) there are \(N + 1 = 4\) different states of the battery:

\(C_1\) supplies energy if:

\[v_1 > V_{ref,0}, v_2 > V_{ref,1}, v_3 > V_{ref,2},\]

\(C_2\) supplies energy if:

\[v_1 \leq V_{ref,0}, v_2 > V_{ref,1}, v_3 > V_{ref,2},\]

\(C_3\) supplies energy if:

\[v_1 \leq V_{ref,0}, v_2 \leq V_{ref,1}, v_3 > V_{ref,2},\]

\(V_s\) supplies energy if:

\[v_1 \leq V_{ref,0}, v_2 \leq V_{ref,1}, v_3 \leq V_{ref,2}.\]
\(max_{index}\) is initialized to \(-1\). List “switch” contains a True if \(v_k \leq V_{ref,k-1}\) is satisfied.
  • Is no True there (i.e., \(max_{index}=-1\)), we are in the first case.

  • \(max_{index}=k\geq 0\) means we are in the \((k+1)\)-th case. So, the actual RHS has key \(max_{index}\)-1 in the dictionary self.switch_f.

In case of using the switch estimator, we count the number of switches which illustrates in which case of voltage source we are.

Parameters:
  • u (dtype_u) – Current values of the numerical solution.

  • t (float) – Current time of the numerical solution is computed.

Returns:

f – The right-hand side of the problem.

Return type:

dtype_f

get_problem_dict()[source]

Helper to create dictionaries for both the coefficent matrix of the ODE system and the nonhomogeneous part.

get_switching_info(u, t)[source]

Provides information about a discrete event for one subinterval.

Parameters:
  • u (dtype_u) – Current values of the numerical solution.

  • t (float) – Current time of the numerical solution is computed.

Returns:

  • switch_detected (bool) – Indicates if a switch is found or not.

  • m_guess (int) – Index of collocation node inside one subinterval of where the discrete event was found.

  • state_function (list) – Contains values of the state function (for interpolation).

solve_system(rhs, factor, u0, t)[source]

Simple linear solver for \((I-factor\cdot A)\vec{u}=\vec{rhs}\).

Parameters:
  • rhs (dtype_f) – Right-hand side for the linear system.

  • factor (float) – Abbrev. for the local stepsize (or any other factor required).

  • u0 (dtype_u) – Initial guess for the iterative solver.

  • t (float) – Current time (e.g. for time-dependent BCs).

Returns:

me – The solution as mesh.

Return type:

dtype_u

u_exact(t)[source]

Routine to compute the exact solution at time \(t\).

Parameters:

t (float) – Time of the exact solution.

Returns:

me – The exact solution.

Return type:

dtype_u