Skip to content

Energy

EnergyCompute

Energy density in [J/m^3] computing functions

Source code in cmtj/utils/energy.py
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
class EnergyCompute:
    """Energy density in [J/m^3] computing functions"""

    def __init__(self, cell_surface: float, thickness: float,
                 log: Dict[str, List[float]]) -> None:
        """Initialise energy computation class
        :param cell_surface: surface of the cell in [m^2]
        :param thickness: thickness of the cell in [m]
        :param log: log of the simulation (directly from .getLog())"""
        self.cell_surface = cell_surface
        self.thickness = thickness
        self.cell_volumne = self.cell_surface * thickness
        self.log = log

    def compute_from_log(self) -> Dict[str, List[float]]:
        """
        Computes a log of energies over time and returns it
        in the same form of the
        """
        field_keys = list({k[:-1] for k in self.log if "_H" in k})
        mag_k = (k.replace("_mx", "") for k in self.log if "_mx" in k)
        mag_vectors = {
            k: np.asarray([
                self.log[f"{k}_mx"], self.log[f"{k}_my"], self.log[f"{k}_mz"]
            ])
            for k in mag_k
        }
        energy_data = {}
        for field_key in field_keys:
            if "J_" in field_key:
                eng_fn = self.calculate_energy_from_field_interfacial
            else:
                eng_fn = self.calculate_energy_from_field

            m_key = field_key.split("_")[0]  # get m key
            m = mag_vectors[m_key]
            field_series = np.asarray([
                self.log[f"{field_key}x"],
                self.log[f"{field_key}y"],
                self.log[f"{field_key}z"],
            ])
            energy_data[f"energy_{field_key}"] = eng_fn(m, field_series)

        return energy_data

    def calculate_energy_from_field(self, m: np.ndarray,
                                    field_vector: np.ndarray) -> np.ndarray:
        """
        :param m: magnetisation
        :param field_vector: magnetic field vector (can be external, Oersted etc.)
        Compute generic energy density
        E = H * (mi0 Ms/V)
        where mi0 Ms is in [T], Ms in [A/m], H in [A/m]
        """
        return -np.sum(m * field_vector, axis=0) / self.cell_volumne

    def calculate_energy_from_field_interfacial(
            self, m: np.ndarray, field_vector: np.ndarray) -> np.ndarray:
        """
        :param m: magnetisation
        :param field_vector: magnetic field vector (can be IEC etc.)
        Compute generic energy density
        E = H * (mi0 Ms/A)
        where mi0 Ms is in [T], Ms in [A/m], H in [A/m]
        """
        return -np.sum(m * field_vector, axis=0) / self.cell_surface

__init__(cell_surface, thickness, log)

Initialise energy computation class

Parameters:

Name Type Description Default
cell_surface float

surface of the cell in [m^2]

required
thickness float

thickness of the cell in [m]

required
log Dict[str, List[float]]

log of the simulation (directly from .getLog())

required
Source code in cmtj/utils/energy.py
 9
10
11
12
13
14
15
16
17
18
def __init__(self, cell_surface: float, thickness: float,
             log: Dict[str, List[float]]) -> None:
    """Initialise energy computation class
    :param cell_surface: surface of the cell in [m^2]
    :param thickness: thickness of the cell in [m]
    :param log: log of the simulation (directly from .getLog())"""
    self.cell_surface = cell_surface
    self.thickness = thickness
    self.cell_volumne = self.cell_surface * thickness
    self.log = log

calculate_energy_from_field(m, field_vector)

Parameters:

Name Type Description Default
m np.ndarray

magnetisation

required
field_vector np.ndarray

magnetic field vector (can be external, Oersted etc.) Compute generic energy density E = H * (mi0 Ms/V) where mi0 Ms is in [T], Ms in [A/m], H in [A/m]

required
Source code in cmtj/utils/energy.py
51
52
53
54
55
56
57
58
59
60
def calculate_energy_from_field(self, m: np.ndarray,
                                field_vector: np.ndarray) -> np.ndarray:
    """
    :param m: magnetisation
    :param field_vector: magnetic field vector (can be external, Oersted etc.)
    Compute generic energy density
    E = H * (mi0 Ms/V)
    where mi0 Ms is in [T], Ms in [A/m], H in [A/m]
    """
    return -np.sum(m * field_vector, axis=0) / self.cell_volumne

calculate_energy_from_field_interfacial(m, field_vector)

Parameters:

Name Type Description Default
m np.ndarray

magnetisation

required
field_vector np.ndarray

magnetic field vector (can be IEC etc.) Compute generic energy density E = H * (mi0 Ms/A) where mi0 Ms is in [T], Ms in [A/m], H in [A/m]

required
Source code in cmtj/utils/energy.py
62
63
64
65
66
67
68
69
70
71
def calculate_energy_from_field_interfacial(
        self, m: np.ndarray, field_vector: np.ndarray) -> np.ndarray:
    """
    :param m: magnetisation
    :param field_vector: magnetic field vector (can be IEC etc.)
    Compute generic energy density
    E = H * (mi0 Ms/A)
    where mi0 Ms is in [T], Ms in [A/m], H in [A/m]
    """
    return -np.sum(m * field_vector, axis=0) / self.cell_surface

compute_from_log()

Computes a log of energies over time and returns it in the same form of the

Source code in cmtj/utils/energy.py
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
def compute_from_log(self) -> Dict[str, List[float]]:
    """
    Computes a log of energies over time and returns it
    in the same form of the
    """
    field_keys = list({k[:-1] for k in self.log if "_H" in k})
    mag_k = (k.replace("_mx", "") for k in self.log if "_mx" in k)
    mag_vectors = {
        k: np.asarray([
            self.log[f"{k}_mx"], self.log[f"{k}_my"], self.log[f"{k}_mz"]
        ])
        for k in mag_k
    }
    energy_data = {}
    for field_key in field_keys:
        if "J_" in field_key:
            eng_fn = self.calculate_energy_from_field_interfacial
        else:
            eng_fn = self.calculate_energy_from_field

        m_key = field_key.split("_")[0]  # get m key
        m = mag_vectors[m_key]
        field_series = np.asarray([
            self.log[f"{field_key}x"],
            self.log[f"{field_key}y"],
            self.log[f"{field_key}z"],
        ])
        energy_data[f"energy_{field_key}"] = eng_fn(m, field_series)

    return energy_data