mammos_mumag quickstart#

mammos_mumag can compute hysteresis loops of magnetic materials using finite elements.

Requirements:

  • mammos and esys-escript

[1]:
import mammos_entity as me
import mammos_units as u
import pandas as pd
from mammos_mumag import hysteresis
[2]:
u.set_enabled_equivalencies(u.magnetic_flux_field())
[2]:
<astropy.units.core._UnitContext at 0x707f9fc54c90>

Hysteresis simulation#

The hysteresis.run function computes a hysteresis loop for a homogeneous material with given parameters. We need to pass in a suitable mesh, mammos_mumag.mesh provides a sample mesh.

[3]:
hysteresis_result = hysteresis.run(
    mesh="cube20_singlegrain_msize2",
    Ms=me.Ms(1280000, unit="A/m"),
    A=me.A(7.7e-12, unit="J/m"),
    K1=me.Ku(4300000, unit="J/m3"),
    hstart=(10 * u.T).to("A/m"),
    hfinal=(-10 * u.T).to("A/m"),
    hnsteps=20,
)

Hysteresis result object#

The returned results_hysteresis object provides a plot method to visualize the computed data. mammos_mumag.hysteresis only computes half a hysteresis loop, going from hstart to hfinal. To show a full loop this function mirrors the computed data and plots it twice:

[4]:
hysteresis_result.plot();
../../_images/examples_mammos-mumag_quickstart_6_0.png

To only see the actual simulation, we can use the flag duplicate=False:

[5]:
hysteresis_result.plot(duplicate=False);
../../_images/examples_mammos-mumag_quickstart_8_0.png

The results object provides access to:

  • the external field H

  • the magnetization M in the direction of the applied field

  • the component Mx, My, Mz of the spontaneous magnetization

  • the energy density

[6]:
hysteresis_result.H
[6]:
ExternalMagneticField(value=
[ 7957747.15026276  7161972.43523649  6366197.72021021  5570423.00518393
  4774648.29015766  3978873.57513138  3183098.86010511  2387324.14507883
  1591549.43005255   795774.71502628        0.          -795774.71502628
 -1591549.43005255 -2387324.14507883 -3183098.86010511 -3978873.57513138
 -4774648.29015766],
 unit=A / m)
[7]:
hysteresis_result.M
[7]:
SpontaneousMagnetization(value=
[ 1279889.28858392  1279875.35487467  1279858.60865277  1279838.23693916
  1279813.10960709  1279781.61816142  1279741.40923658  1279688.92826229
  1279618.59692477  1279521.24777533  1279380.92895733  1279167.7912497
  1278820.31896664  1278193.40901809  1276865.45558106  1273023.46966219
 -1279813.11387667],
 unit=A / m)
[8]:
hysteresis_result.Mx
[8]:
SpontaneousMagnetization(value=
[ 1.33369419e+04  1.27642912e+04  1.21138305e+04  1.13685440e+04
  1.05060693e+04  9.49642262e+03  8.29840374e+03  6.85388864e+03
  5.07807498e+03  2.84220258e+03 -5.92136134e+01 -3.97555586e+03
 -9.55402103e+03 -1.81446442e+04 -3.31351860e+04 -6.65045268e+04
 -1.05064987e+04],
 unit=A / m)
[9]:
hysteresis_result.My
[9]:
SpontaneousMagnetization(value=
[ -48.88653309  -51.96927454  -55.46739079  -59.47103435  -64.09846672
  -69.50895303  -75.91814421  -83.6324871   -93.09714628 -104.9867318
 -120.3756958  -141.08903508 -170.50557383 -215.70060351 -294.72360266
 -476.00202952   64.1468076 ],
 unit=A / m)
[10]:
hysteresis_result.Mz
[10]:
SpontaneousMagnetization(value=
[ 1279851.43397906  1279847.49250133  1279842.09608478  1279834.72859931
  1279824.65003271  1279810.77494584  1279791.46867247  1279764.19052807
  1279724.84138723  1279666.49962961  1279576.79725727  1279431.97819969
  1279181.81279538  1278704.73773837  1277638.20888414  1274378.02605529
 -1279824.64680888],
 unit=A / m)
[11]:
hysteresis_result.energy_density
[11]:
EnergyDensity(value=
[-16793259.14717999 -15513376.61777121 -14233509.37078527
 -12953660.60369528 -11673834.47507031 -10394036.49593287
  -9114274.12985358  -7834557.74471191  -6554902.18356019
  -5275329.48376665  -3995873.86584997  -2716591.57883735
  -1437582.25793928   -159041.64107595   1118580.91577263
   2393925.95515716 -11673834.47506087],
 unit=J / m3)

The attribute configuration_type contains a list of indices that refer to saved magnetization field configurations. We will use this information later.

[12]:
hysteresis_result.configuration_type
[12]:
array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2])

We can also get the hysteresis data as a pandas dataframe in SI units:

[13]:
hysteresis_result.dataframe
[13]:
configuration_type H M Mx My Mz energy_density
0 1 7.957747e+06 1.279889e+06 13336.941917 -48.886533 1.279851e+06 -1.679326e+07
1 1 7.161972e+06 1.279875e+06 12764.291237 -51.969275 1.279847e+06 -1.551338e+07
2 1 6.366198e+06 1.279859e+06 12113.830536 -55.467391 1.279842e+06 -1.423351e+07
3 1 5.570423e+06 1.279838e+06 11368.544041 -59.471034 1.279835e+06 -1.295366e+07
4 1 4.774648e+06 1.279813e+06 10506.069333 -64.098467 1.279825e+06 -1.167383e+07
5 1 3.978874e+06 1.279782e+06 9496.422617 -69.508953 1.279811e+06 -1.039404e+07
6 1 3.183099e+06 1.279741e+06 8298.403739 -75.918144 1.279791e+06 -9.114274e+06
7 1 2.387324e+06 1.279689e+06 6853.888645 -83.632487 1.279764e+06 -7.834558e+06
8 1 1.591549e+06 1.279619e+06 5078.074979 -93.097146 1.279725e+06 -6.554902e+06
9 1 7.957747e+05 1.279521e+06 2842.202577 -104.986732 1.279666e+06 -5.275329e+06
10 1 0.000000e+00 1.279381e+06 -59.213613 -120.375696 1.279577e+06 -3.995874e+06
11 1 -7.957747e+05 1.279168e+06 -3975.555864 -141.089035 1.279432e+06 -2.716592e+06
12 1 -1.591549e+06 1.278820e+06 -9554.021032 -170.505574 1.279182e+06 -1.437582e+06
13 1 -2.387324e+06 1.278193e+06 -18144.644172 -215.700604 1.278705e+06 -1.590416e+05
14 1 -3.183099e+06 1.276865e+06 -33135.185971 -294.723603 1.277638e+06 1.118581e+06
15 1 -3.978874e+06 1.273023e+06 -66504.526815 -476.002030 1.274378e+06 2.393926e+06
16 2 -4.774648e+06 -1.279813e+06 -10506.498724 64.146808 -1.279825e+06 -1.167383e+07

We can generate a table in alternate units:

[14]:
df = pd.DataFrame(
    {
        "mu0_H": hysteresis_result.H.q.to(u.T),
        "J": hysteresis_result.M.q.to(u.T),
    },
)
df.head()
[14]:
mu0_H J
0 10.0 1.608356
1 9.0 1.608339
2 8.0 1.608318
3 7.0 1.608292
4 6.0 1.608261

Visualizing magnetization configurations#

To plot the hysteresis loop (including the available configurations), run

[15]:
hysteresis_result.plot(configuration_marks=True);
../../_images/examples_mammos-mumag_quickstart_23_0.png

We can get the location of the saved configurations from the attribute configurations:

[16]:
hysteresis_result.configurations
[16]:
{1: PosixPath('/home/pepe/repo/mammos/mammos-mumag/examples/hystloop/hystloop_0001.vtu'),
 2: PosixPath('/home/pepe/repo/mammos/mammos-mumag/examples/hystloop/hystloop_0002.vtu')}

To inspect the configurations more conveniently directly in the notebook we can use the plot_configuration function of hysteresis_result. We need to pass the index and get an interactive 3D plot (using pyvista):

[17]:
hysteresis_result.plot_configuration(1)

Note: the small object size is a consequence of the empty sphere around the cube.