Skip to content

Time-Harmonic Magnetic Solver

The TimeHarmonicMagneticSolver controls how the Time-Harmonic Magnetic Model is solved. The complex-valued linear system can be solved either iteratively (the default) or with a direct solver, and an under-relaxation factor handles the outer iteration when materials are nonlinear. For the underlying method, see Linear Solvers and Newton Form.

The solver is not created directly; every TimeHarmonicMagneticModel owns one. Access it with get_solver():

solver = time_harmonic_magnetic_model.get_solver()

Linear solver controls

set_direct_solver

solver.set_direct_solver(use_direct_solver: bool)

Select the linear solver. When False (default) an iterative solver is used; when True a direct solver is used instead. A direct solver is robust for smaller problems, while the iterative solver scales better to large meshes.

set_relative_tolerance

solver.set_relative_tolerance(relative_tolerance: float)

Relative convergence tolerance of the iterative solver: the iteration stops once the residual norm has dropped by this factor relative to the initial residual. Default 1e-6.

set_absolute_tolerance

solver.set_absolute_tolerance(absolute_tolerance: float)

Absolute residual floor of the iterative solver. Default 0.0.

set_iteration_number

solver.set_iteration_number(iteration_number: int)

Maximum number of iterations of the iterative solver. Default 50.

Nonlinear iteration controls

set_under_relaxation_factor

solver.set_under_relaxation_factor(under_relaxation_factor: float)

This factor damps the outer update when the materials are nonlinear. The value is in \((0, 1]\). Values below 1 add damping. This can make strongly nonlinear cases stable, but the solver then needs more iterations. Default 1.0 (no damping).

set_relaxation_type

from mufem.electromagnetics.timeharmonicmagnetic import RelaxationType

solver.set_relaxation_type(relaxation_type: RelaxationType)

Select how the solver sets the under-relaxation factor of the outer iteration:

  • RelaxationType.Constant (default) — use the fixed factor of set_under_relaxation_factor for each iteration.
  • RelaxationType.Aitken — calculate a new factor \(\omega^k\) for each iteration \(k\) with the Aitken \(\Delta^2\) method [1, 2]:

$$ \omega^k = -\,\omega^{k-1} \frac{\langle \boldsymbol{\delta}^{k-1},\, \boldsymbol{\delta}^{k} - \boldsymbol{\delta}^{k-1} \rangle} {\lVert \boldsymbol{\delta}^{k} - \boldsymbol{\delta}^{k-1} \rVert^2}, $$

where:

  • \(\omega^k\) is the under-relaxation factor of iteration \(k\) (dimensionless),
  • \(\boldsymbol{\delta}^k\) is the vector of the solution correction of iteration \(k\) (real and imaginary parts).

The solver limits \(\omega^k\) to the range \([0.1, 2.0]\). The solver starts the method again at each time step of an unsteady run. The first iteration of each time step uses the factor of set_under_relaxation_factor.

Use Aitken for strongly coupled problems, for example induction heating with temperature-dependent material properties. There, a fixed factor is often too small (slow convergence) or too large (oscillation).

solver.get_relaxation_type() returns the current setting.

set_frozen

solver.set_frozen(is_frozen: bool)

Freeze the model state. When True, the solve returns immediately without reassembling or updating — the magnetic field is held fixed. This is useful in co-simulations where the magnetic solution should stay constant while another physics advances. Default False.

set_verbose

solver.set_verbose(verbose: bool)

Enable detailed per-iteration output from the solver. Default False.

Diagnostics

get_residual_history

residuals = solver.get_residual_history()

Return the residual norm recorded at each iteration of the most recent solve, useful to inspect convergence behaviour.

Examples

Direct solver

For a robust solve on a moderate mesh:

solver = time_harmonic_magnetic_model.get_solver()
solver.set_direct_solver(True)
solver.set_verbose(True)

Tighter iterative tolerance

solver = time_harmonic_magnetic_model.get_solver()
solver.set_iteration_number(250)
solver.set_relative_tolerance(1.0e-10)

Inspecting convergence

residuals = time_harmonic_magnetic_model.get_solver().get_residual_history()

Induction heating with Aitken relaxation

A time-harmonic magnetic model that is coupled to a temperature model with temperature-dependent materials (see the COMPUMAG TEAM 36 benchmark):

solver = magnetic_model.get_solver()
solver.set_under_relaxation_factor(0.7)
solver.set_relaxation_type(RelaxationType.Aitken)

References

  1. B. M. Irons and R. C. Tuck, "A version of the Aitken accelerator for computer iteration", International Journal for Numerical Methods in Engineering, 1(3), pp. 275–277, 1969.
  2. U. Küttler and W. A. Wall, "Fixed-point fluid–structure interaction solvers with dynamic relaxation", Computational Mechanics, 43(1), pp. 61–72, 2008.