Micromagnetic output
Matlab solution struct
The MEX-file returns the solution struct, and optionally the grid information as a second output:
solution = struct();
[solution, GridInfo] = problem.MagTenseLandauLifshitzSolver_mex( struct(problem), solution );
The solution struct contains
Field |
Size |
Description |
|---|---|---|
|
|
The times at which the solution was stored. |
|
|
The reduced magnetization. The third dimension is the applied-field index, which is 1 for the dynamic solver and the number of field steps for the explicit solver. |
|
|
Centre coordinates of the cells, in the same order as the other per-cell arrays. |
|
|
Exchange field in A/m. Only filled when |
|
|
Applied field in A/m. Only filled when |
|
|
Demagnetization field in A/m. Only filled when |
|
|
Anisotropy field in A/m. Only filled when |
|
scalar |
Number of accepted applied-field steps. Only meaningful for Adaptive hysteresis. |
|
|
Energies in J in the order exchange, external (Zeeman),
demagnetization, anisotropy. Always filled at the last output time; at
the other output times only when |
|
|
Number of effective-field evaluations spent relaxing at each applied field. This is the cost measure that scales with the problem size, and the one to compare between the time integration and the minimizer. |
|
|
Minimizer iterations at each applied field, 0 for the time integration. |
|
|
Final largest relative torque \(\max_i |\mathbf{m}_i \times \mathbf{H}_i| / \max(M_s)\), minimizer only. |
|
|
|
ReturnHall (Python usereturnhall) is off by default. Turning it on
returns the four individual field terms as additional
(nt, ntot, nt_Hext, 3) arrays, which is worth keeping in mind for the
memory of a large problem.
The energies are evaluated in Fortran from the same fields the solver ran on. The exchange, external and demagnetization terms are \(-\tfrac{1}{2}\mu_0 \sum_i M_{s,i} V_i\, \mathbf{m}_i\cdot\mathbf{H}_i\) (without the one half for the external field). The anisotropy term is the energy density integrated over the cells: \(K_0 (1 - (\mathbf{u}\cdot\mathbf{m})^2)\) for the uniaxial case, so that it is non-negative, and the polynomial documented in Magnetocrystalline anisotropy plus the cubic \(K_1\), \(K_2\) terms otherwise. Dividing by \(\tfrac{1}{2}\mu_0 M_s^2 V\) gives the reduced energies used by the mumag standard problems.
Note
The four H_* arrays are evaluated from the stored solution at the
nt output times after the integration has finished, so they belong
exactly to the returned magnetization states rather than to an internal
step of the integrator.
The optional GridInfo output carries the analysed mesh - face normals,
face areas, cell volumes, cell and face centres, the interpolation index
arrays, and the assembled exchange matrix in COO form (ExchMat_r,
ExchMat_c, ExchMat_v, ExchMat_nr, ExchMat_nc). It is what
cartesianUnstructuredMeshPlot plots.
The Matlab helper computeMagneticMomentGeneralMesh converts a solution into
the volume-averaged magnetic moment, and computeMagneticEnergy evaluates
the energy terms.
Python result list
run_simulation and run_hysteresis return a list:
Index |
Name |
Description |
|---|---|---|
0 |
|
Output times. |
1 |
|
Reduced magnetization, |
2 |
|
Cell centres, |
3 |
|
Exchange field, same shape as |
4 |
|
Applied field. |
5 |
|
Demagnetization field. |
6 |
|
Anisotropy field. |
7 |
|
Number of non-zero entries in the exchange matrix. |
8, 9, 10 |
|
The exchange matrix in COO form, already sliced to
|
11, 12 |
|
Number of rows and columns of the exchange matrix. |
run_hysteresis_adaptive returns the same twelve entries followed by one
extra element, the number of accepted field steps, and the arrays with an
applied-field dimension are already sliced to that number.
The energies and the relaxation diagnostics are attributes of the problem object after any of the three run methods, which keeps the layout of the list unchanged. Their meaning is given in the Matlab table above:
problem.E_out # (nt, nt_h_ext, 4): exchange, external, demag, anisotropy [J]
problem.n_feval # (nt_h_ext,) effective-field evaluations per applied field
problem.min_iter # (nt_h_ext,) minimizer iterations
problem.min_torque # (nt_h_ext,) final largest relative torque
problem.min_status # (nt_h_ext,) -1 LL, 0 converged, 1 after fallback, 2 failed
For an adaptive run they are sliced to the accepted field steps.
A typical unpacking is
t_out, M_out = problem.run_simulation(
t_end=1e-9, nt=200, fct_h_ext=h_ext_fct, nt_h_ext=2000
)[:2]
# Volume-averaged reduced magnetization as a function of time
M_avg = M_out[:, :, 0, :].mean(axis=1)
The helper magtense.utils.plot_M_thin_film plots the magnetization of a
thin-film problem, and magtense.utils.create_plot handles the magnetostatic
tile plots.
Dry runs
Setting dummy_run = 1 builds the problem, the mesh, the exchange operator
and the demagnetization tensor, but skips the time integration. This is useful
for timing the setup phase, for checking the memory footprint of a large
problem, and for extracting the exchange matrix or the demagnetization tensor
without paying for a solve. The returned magnetization arrays are zeroed in
that case.