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():
Linear solver controls¶
set_direct_solver¶
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¶
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¶
Absolute residual floor of the iterative solver. Default 0.0.
set_iteration_number¶
Maximum number of iterations of the iterative solver. Default 50.
Nonlinear iteration controls¶
set_under_relaxation_factor¶
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 ofset_under_relaxation_factorfor 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¶
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¶
Enable detailed per-iteration output from the solver. Default False.
Diagnostics¶
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¶
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¶
- 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.
- U. Küttler and W. A. Wall, "Fixed-point fluid–structure interaction solvers with dynamic relaxation", Computational Mechanics, 43(1), pp. 61–72, 2008.