Ejemplo n.º 1
0
def test_anisotropy_energy_random_anisotropy_constant(
        random_state_spins, build_sample, random_anisotropy_constant):
    num_sites, _, _, _ = build_sample
    anisotropy_vector = numpy.ones(shape=(num_sites, 3))
    expected = compute_anisotropy_energy(num_sites, random_state_spins,
                                         random_anisotropy_constant,
                                         anisotropy_vector)
    total = energy.compute_anisotropy_energy(random_state_spins,
                                             random_anisotropy_constant,
                                             anisotropy_vector)
    assert numpy.allclose(expected, total)
Ejemplo n.º 2
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,
                )