Exemplo n.º 1
0
    def check_energies(m=None, theta=None):
        """
        Helper function to compare the computed energy for a given
        magnetisation with an expected analytical value. The argument
        theta is the angle between the magnetisation vector and the
        x-axis.

        """
        # Exactly one of m, theta must be given
        assert ((m is None or theta is None)
                and not (m is None and theta is None))
        if m is None:
            if theta is None:
                raise ValueError("Exactly one of m, theta must be given.")
            theta_rad = theta * pi / 180.
            m = (cos(theta_rad), sin(theta_rad), 0)
        else:
            if theta != None:
                raise ValueError("Exactly one of m, theta must be given.")
        m = m / np.linalg.norm(m)
        m_field = Field(S3)
        m_field.set(df.Constant(m))
        H_ext = Zeeman(H * np.array([1, 0, 0]))
        H_ext.setup(m_field,
                    Field(df.FunctionSpace(mesh, 'DG', 0), Ms),
                    unit_length=unit_length)

        #E_analytical_1 = -mu0 * Ms * H * volume_1 * cos(theta_rad)
        E_analytical_1 = -mu0 * Ms * H * volume_1 * np.dot(m, [1, 0, 0])
        E_analytical_2 = -mu0 * Ms * H * volume_2 * np.dot(m, [1, 0, 0])
        E_analytical_total = E_analytical_1 + E_analytical_2

        E_computed_1 = H_ext.compute_energy(dx=dx_disk_1)
        E_computed_2 = H_ext.compute_energy(dx=dx_disk_2)
        E_computed_total = H_ext.compute_energy(dx=df.dx)

        # Check that the sum of the computed energies for disk #1 and #2 equals
        # the total computed energy
        assert np.allclose(E_computed_1 + E_computed_2,
                           E_computed_total,
                           atol=0,
                           rtol=1e-12)

        # Check that the computed energies are within the tolerance of the
        # analytical expressions
        assert np.allclose(E_computed_1, E_analytical_1, atol=0, rtol=RTOL)
        assert np.allclose(E_computed_2, E_analytical_2, atol=0, rtol=RTOL)
        assert np.allclose(E_computed_total,
                           E_analytical_total,
                           atol=0,
                           rtol=RTOL)
Exemplo n.º 2
0
    def check_energy_for_m(m, E_expected):
        """
        Helper function to compare the computed energy for a given
        magnetisation with an expected analytical value.
        """
        m_field = Field(S3)
        m_field.set(df.Constant(m))
        H_ext = Zeeman(H * np.array([1, 0, 0]))
        H_ext.setup(m_field, Ms, unit_length=unit_length)

        E_computed = H_ext.compute_energy()
        assert np.allclose(E_computed, E_expected, atol=0, rtol=1e-12)