Esempio n. 1
0
def test_magnetic_energy_null_intensity(random_spin_moments, random_state_spins):
    num_sites = len(random_spin_moments)
    intensities = [0.0] * num_sites
    directions = numpy.ones(shape=(num_sites, 3))
    magnetic_fields = (
        numpy.array([intensities, intensities, intensities]).T * directions
    )
    expected = compute_magnetic_energy(
        num_sites, random_spin_moments, random_state_spins, intensities, directions
    )
    total = energy.compute_magnetic_energy(
        random_state_spins, random_spin_moments, magnetic_fields
    )
    assert numpy.allclose(expected, total)
Esempio n. 2
0
def test_magnetic_energy_random_directions(random_spin_moments, random_state_spins):
    num_sites = len(random_spin_moments)
    intensities = [1.0] * num_sites
    random_directions = numpy.random.normal(size=(num_sites, 3))
    magnetic_fields = (
        numpy.array([intensities, intensities, intensities]).T * random_directions
    )
    expected = compute_magnetic_energy(
        num_sites,
        random_spin_moments,
        random_state_spins,
        intensities,
        random_directions,
    )
    total = energy.compute_magnetic_energy(
        random_state_spins, random_spin_moments, magnetic_fields
    )
    assert numpy.allclose(expected, total)
Esempio n. 3
0
def test_magnetic_energy_random_intensity(random_spin_moments, random_state_spins):
    num_sites = len(random_spin_moments)
    random_intensities = numpy.random.normal(size=(num_sites))
    directions = numpy.ones(shape=(num_sites, 3))
    magnetic_fields = (
        numpy.array([random_intensities, random_intensities, random_intensities]).T
        * directions
    )
    expected = compute_magnetic_energy(
        num_sites,
        random_spin_moments,
        random_state_spins,
        random_intensities,
        directions,
    )
    total = energy.compute_magnetic_energy(
        random_state_spins, random_spin_moments, magnetic_fields
    )
    assert numpy.allclose(expected, total)
Esempio n. 4
0
    def run(self):
        """This function creates a generator. It calculates the evolve of the states
        through the implementation of the LLG equation. Also, it uses these states for
        calculate the exchange energy, anisotropy energy, magnetic energy, and hence,
        the total energy of the system.

        :param spin_norms: It receives the spin norms of the sites in the system.
        :type spin_norms: list
        :param damping: It receives the damping constant of the sites in the system.
        :type damping: float
        :param deltat: It receives the step of time.
        :type deltat: float
        :param gyromagnetic: It receives the gyromagnetic constant of the sites in the
        system.
        :type gyromagnetic: float
        :param kb: It receives the Boltzmann constant in an specific units.
        :type kb: float
        :param field_axes: It receives the field axis of the sites in the system.
        :type field_axes: float/list
        :param j_exchanges: It receives the list of the exchanges interactions of the
        sites in the system.
        :type j_exchanges: list
        :param num_neighbors: It receives the number of neighbors per site of the
        system.
        :type num_neighbors: list
        :param neighbors: It receives the list of neighbors of the sites in the system.
        :type neighbors: list
        :param anisotropy_constants: It receives the anisotropy constants of the sites
        in the system.
        :type anisotropy_constants: float
        :param anisotropy_vectors: It receives the anisotropy axis of the sites in the
        system.
        :type anisotropy_vectors: list
        :param num_sites: It receives the total of spin magnetic moments.
        :type num_sites: list
        :param state: It receives the initial state of the system.
        :type state: list
        """
        spin_norms = self.system.geometry.spin_norms
        damping = self.system.damping
        deltat = self.system.deltat
        gyromagnetic = self.system.gyromagnetic
        kb = self.system.kb
        field_axes = self.system.geometry.field_axes
        exchanges = self.system.geometry.exchanges
        neighbors = self.system.geometry.neighbors
        anisotropy_constants = self.system.geometry.anisotropy_constants
        anisotropy_vectors = self.system.geometry.anisotropy_axes
        num_sites = self.system.geometry.num_sites
        state = self.initial_state

        for T, H in zip(self.temperature, self.field):
            temperatures = numpy.array([T] * num_sites)
            magnetic_fields = H * field_axes

            for _ in tqdm(range(self.num_iterations)):
                state = heun.integrate(
                    state,
                    spin_norms,
                    temperatures,
                    damping,
                    deltat,
                    gyromagnetic,
                    kb,
                    magnetic_fields,
                    exchanges,
                    neighbors,
                    anisotropy_constants,
                    anisotropy_vectors,
                )

                exchange_energy_value = energy.compute_exchange_energy(
                    state, exchanges, neighbors)
                anisotropy_energy_value = energy.compute_anisotropy_energy(
                    state, anisotropy_constants, anisotropy_vectors)
                magnetic_energy_value = energy.compute_magnetic_energy(
                    state, spin_norms, magnetic_fields)
                total_energy_value = (exchange_energy_value +
                                      anisotropy_energy_value +
                                      magnetic_energy_value)

                yield (
                    state,
                    exchange_energy_value,
                    anisotropy_energy_value,
                    magnetic_energy_value,
                    total_energy_value,
                )