Example #1
0
    def __init__(self, mesh, spin, mu_s, mu_s_inv, field, pins,
                 interactions,
                 name,
                 data_saver,
                 use_jac=False,
                 integrator='sundials'
                 ):

        # Inherit from the driver class
        super(SLLG, self).__init__(mesh, spin, mu_s, mu_s_inv, field,
                                   pins, interactions, name,
                                   data_saver,
                                   use_jac=use_jac,
                                   integrator=integrator
                                   )

        self._T = np.zeros(self.n, dtype=np.float)
        self.next_spin = np.zeros(3*self.n, dtype=np.float)
        self.eta = np.zeros(3*self.n, dtype=np.float)
        self.dm1 = np.zeros(3*self.n, dtype=np.float)
        self.dm2 = np.zeros(3*self.n, dtype=np.float)

        self.minor_step = 0
        self.mt19937 = clib.rng_mt19937()

        self.set_options()
Example #2
0
def test_random_sphere(do_plot=False):
    """
    test whether spins are uniformly distributed on the surface of a sphere.
    """
    mt19937 = clib.rng_mt19937()
    mt19937.set_seed(123)
    spin = np.zeros(3 * 10000, dtype=np.float)
    mt19937.fill_vector_uniform_sphere(spin, 10000)
    spin.shape = (-1, 3)
    n = spin.shape[0]
    x = np.average([spin[i, 0] for i in range(n) if spin[i, 0] > 0])
    y = np.average([spin[i, 1] for i in range(n) if spin[i, 1] > 0])
    z = np.average([spin[i, 2] for i in range(n) if spin[i, 2] > 0])
    print(x, y, z)
    print(abs(x - y), abs(x - z), abs(y - z))
    assert (abs(x - y) < 4e-3)
    assert (abs(x - z) < 4e-3)
    assert (abs(y - z) < 4e-3)

    if do_plot:
        fig = plt.figure()
        ax3D = fig.add_subplot(111, projection='3d')
        ax3D.scatter(spin[:1000, 0],
                     spin[:1000, 1],
                     spin[:1000, 2],
                     s=30,
                     marker='.')
        plt.savefig('test_random_sphere.png')
def test_random_sphere(do_plot=False):
    """
    test whether spins are uniformly distributed on the surface of a sphere.
    """
    mt19937 = clib.rng_mt19937()
    mt19937.set_seed(123)
    spin = np.zeros(3 * 10000, dtype=np.float)
    mt19937.fill_vector_uniform_sphere(spin, 10000)
    spin.shape = (-1,3)
    n = spin.shape[0]
    x = np.average([spin[i,0] for i in range(n) if spin[i,0]>0])
    y = np.average([spin[i,1] for i in range(n) if spin[i,1]>0])
    z = np.average([spin[i,2] for i in range(n) if spin[i,2]>0])
    print(x,y,z)
    print(abs(x-y), abs(x-z), abs(y-z))
    assert(abs(x-y)<4e-3)
    assert(abs(x-z)<4e-3)
    assert(abs(y-z)<4e-3)

    if do_plot:
        fig = plt.figure()
        ax3D = fig.add_subplot(111, projection='3d')
        ax3D.scatter(spin[:1000,0], spin[:1000,1], spin[:1000,2], s=30, marker='.')
        plt.savefig('test_random_sphere.png')