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¶
Damping applied to the outer update when materials are nonlinear. A value in
\((0, 1]\); values below 1 add damping and can stabilise strongly nonlinear
cases at the cost of more iterations. Default 1.0 (no damping).
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 for inspecting 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)