freegsnke.implicit_euler module

Implements implicit time integration.

Copyright 2025 UKAEA, UKRI-STFC, and The Authors, as per the COPYRIGHT and README files.

This file is part of FreeGSNKE.

FreeGSNKE is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

FreeGSNKE is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with FreeGSNKE. If not, see <http://www.gnu.org/licenses/>.

class freegsnke.implicit_euler.implicit_euler_solver(Mmatrix: ndarray, Rmatrix: ndarray, full_timestep: float, max_internal_timestep: float)[source]

Bases: object

An implicit Euler time stepper for the linearized circuit equations. Solves an equation of type

\[M\dot{I} + RI = F\]
,

with generic M, R and F. The internal_stepper and full_stepper solve for I(t+dt) using

\[I(t+dt) = (M + Rdt)^{-1} (Fdt + MI(t))\]
.

The implementation actually allows for

\[I(t+dt) = (M + Rdt)^{-1} (Fdt + LI(t))\]

with M != L

__init__(Mmatrix: ndarray, Rmatrix: ndarray, full_timestep: float, max_internal_timestep: float) → None[source]

Set up the implicit Euler solver.

Parameters:
  • Mmatrix (np.ndarray) – (NxN) Mutual inductance matrix

  • Rmatrix (np.ndarray) – (NxN) Diagonal resistance matrix

  • full_timestep (float) – Full timestep (dt) for the stepper

  • max_internal_timestep (float) – Maximum size of the intermediate timesteps taken during the stepper. If max_internal_timestep < full_timestep, multiple steps are taken up to dt=full_timestep

calc_inverse_operator() → None[source]

Calculate the inverse operator (M + R dt)^-1 and store it as inverse_operator.

Note this needs to be redone whenever M, R or the internal timestep are updated.

full_stepper(It: ndarray, forcing: ndarray) → ndarray[source]

Calculate the next full timestep I(t + self.full_timestep).

Repeatedly solves for the internal timestep I(t + self.internal_timestep) for self.n_steps steps.

Parameters:
  • It (np.ndarray) – Length N vector of the currents, I, at time t

  • forcing (np.ndarray) – Length N vector of the forcing, F, at time t (held constant over the step).

Returns:

Length N vector of the currents at time t + self.full_timestep.

Return type:

np.ndarray

internal_stepper(It: ndarray, dtforcing: ndarray) → ndarray[source]

Calculate the next internal timestep I(t + internal_timestep).

Parameters:
  • It (np.ndarray) – Length N vector of the currents, I, at time t

  • dtforcing (np.ndarray) – Length N vector of the forcing F at time t, multiplied by self.internal_timestep.

Returns:

Length N vector of the currents at time t + self.internal_timestep.

Return type:

np.ndarray

set_Lmatrix(Lmatrix: ndarray) → None[source]

Set a separate mutual inductance matrix L != M.

Parameters:

Lmatrix (np.ndarray) – (NxN) Mutual inductance matrix

set_Mmatrix(Mmatrix: ndarray) → None[source]

Updates the mutual inductance matrix.

Parameters:

Mmatrix (np.ndarray) – (NxN) Mutual inductance matrix

set_Rmatrix(Rmatrix: ndarray) → None[source]

Updates the resistance matrix.

Parameters:

Rmatrix (np.ndarray) – (NxN) Diagonal resistance matrix

set_timesteps(full_timestep: float, max_internal_timestep: float) → None[source]

Sets the timesteps for the stepper and (re)calculate the inverse operator.

Parameters:
  • full_timestep (float) – Full timestep (dt) for the stepper

  • max_internal_timestep (float) – Maximum size of the intermediate timesteps taken during the stepper. If max_internal_timestep < full_timestep, multiple steps are taken up to dt=full_timestep