Esempio n. 1
0
    def setup(self, mesh, spin, Ms, Ms_inv):
        super(Demag, self).setup(mesh, spin, Ms, Ms_inv)

        if self.pbc_2d is True:
            self.demag = clib.FFTDemag(self.dx, self.dy, self.dz,
                                       self.nx, self.ny, self.nz, tensor_type='2d_pbc')
            nxyz = self.nx*self.ny*self.nz
            tensors = np.zeros(6*nxyz, dtype=np.float)
            pbc_2d_error = 1e-10
            sample_repeat_nx = -1
            sample_repeat_ny = -1
            asymptotic_radius = 32.0
            dipolar_radius = 10000.0
            tensor_file_name = None
            options = self.pbc_options

            if 'sample_repeat_nx' in options:
                sample_repeat_nx = options['sample_repeat_nx']
                sample_repeat_ny = options['sample_repeat_ny']
            if 'relative_tensor_error' in options:
                pbc_2d_error = options['relative_tensor_error']
            if 'asymptotic_radius' in options:
                asymptotic_radius = options['asymptotic_radius']
            if 'dipolar_radius' in options:
                dipolar_radius = options['dipolar_radius']
            if 'tensor_file_name' in options:
                tensor_file_name = options['tensor_file_name']

            if tensor_file_name:
                if not (os.path.exists(tensor_file_name+'.npz')):
                    self.demag.compute_tensors_2dpbc(tensors, pbc_2d_error, sample_repeat_nx, sample_repeat_ny, dipolar_radius)
                else:
                    npzfile = np.load(tensor_file_name+'.npz')
                    geo_info = npzfile['geo']
                    geo_arr = np.array([self.nx,self.ny, self.nz, self.dx, self.dy, self.dz], dtype=np.float)
                    #print 'info', geo_info
                    if not np.allclose(geo_arr, geo_info):
                        self.demag.compute_tensors_2dpbc(tensors, pbc_2d_error, sample_repeat_nx, sample_repeat_ny, dipolar_radius)
                    else:
                        tensors = npzfile['tensors']
                geo_arr = np.array([self.nx, self.ny, self.nz, self.dx, self.dy, self.dz], dtype=np.float)
                np.savez(tensor_file_name+'.npz', geo=geo_arr, tensors=tensors)

            else:
                self.demag.compute_tensors_2dpbc(tensors, pbc_2d_error, sample_repeat_nx, sample_repeat_ny, dipolar_radius)

            #print tensors
            self.demag.fill_demag_tensors(tensors)


        else:
            self.demag = clib.FFTDemag(self.dx, self.dy, self.dz,
                                       self.nx, self.ny, self.nz,
                                       tensor_type='demag')
        if not self.calc_every:
            self.compute_field = self.compute_field_every
        else:
            self.count = 0
            self.compute_field = self.compute_field_periodically
Esempio n. 2
0
    def setup(self, mesh, spin, mu_s):
        self.mesh = mesh
        self.dx = mesh.dx
        self.dy = mesh.dy
        self.dz = mesh.dz
        self.nx = mesh.nx
        self.ny = mesh.ny
        self.nz = mesh.nz
        self.spin = spin
        self.n = mesh.n
        self.field = np.zeros(3 * self.n, dtype=np.float)
        unit_length = mesh.unit_length
        self.mu_s_scale = np.zeros(mesh.n, dtype=np.float)

        # note that the 1e-7 comes from \frac{\mu_0}{4\pi}
        self.scale = 1e-7 / unit_length**3

        # could be wrong, needs carefully tests!!!
        self.mu_s_scale = mu_s * self.scale

        self.demag = clib.FFTDemag(self.dx,
                                   self.dy,
                                   self.dz,
                                   self.nx,
                                   self.ny,
                                   self.nz,
                                   tensor_type='dipolar')
Esempio n. 3
0
    def setup(self, mesh, spin, mu_s, mu_s_inv):

        if mesh.mesh_type != 'hexagonal':
            raise Exception('This interaction is only defined'
                            'for hexagonal meshes'
                            )
        self.mesh = mesh

        self.dx = mesh.dx
        self.dx_c = 0.5 * mesh.dx

        self.dy = mesh.dy
        self.dz = mesh.dz

        self.nx = mesh.nx
        self.nx_c = 2 * mesh.nx

        self.ny = mesh.ny
        self.nz = mesh.nz

        self.spin = spin
        self.spin_c = np.zeros(2 * len(spin))

        self.n = mesh.n
        self.n_c = mesh.n * 2
        # self.n_c = self.mesh_c.n

        self.field = np.zeros(3 * self.n, dtype=np.float)
        self.field_c = np.zeros(3 * self.n_c, dtype=np.float)

        self.energy = np.zeros(self.n, dtype=np.float)
        self.energy_c = np.zeros(self.n_c, dtype=np.float)

        unit_length = mesh.unit_length
        self.mu_s_scale = np.zeros(mesh.n, dtype=np.float)
        self.mu_s_scale_c = np.zeros(2 * self.n, dtype=np.float)

        # note that the 1e-7 comes from \frac{\mu_0}{4\pi}
        self.scale = 1e-7 / unit_length ** 3

        # could be wrong, needs carefully tests!!!
        # David Tue 19 Jun 2018: this variable is upated in the sim class
        # in case mu_s changes
        self.mu_s_scale = mu_s * self.scale

        # This seems not to be necessary
        # self.create_cuboid_mesh()

        self.scalar2cuboid(self.mu_s_scale, self.mu_s_scale_c)

        # Compute demag using the cuboid mesh with the double
        # number of x finite differences
        self.demag = clib.FFTDemag(self.dx_c, self.dy, self.dz,
                                   self.nx_c, self.ny, self.nz,
                                   tensor_type='dipolar')
Esempio n. 4
0
    def setup(self, mesh, spin, Ms):
        self.mesh = mesh
        self.dx = mesh.dx
        self.dy = mesh.dy
        self.dz = mesh.dz
        self.nx = mesh.nx
        self.ny = mesh.ny
        self.nz = mesh.nz
        self.spin = spin
        self.field = np.zeros(3 * mesh.n, dtype=np.float)

        self.Ms = Ms

        self.demag = clib.FFTDemag(self.dx, self.dy, self.dz, self.nx, self.ny,
                                   self.nz, self.oommf)
Esempio n. 5
0
    def setup(self, mesh, spin, mu_s, mu_s_inv):
        super(Demag, self).setup(mesh, spin, mu_s, mu_s_inv)

        # Ryan Pepper 04/04/2019
        # We *do not* need to scale by mesh.unit_length**3 here!
        # This is because in the base energy class, dx, dy and dz
        # are scaled.
        self.scale = 1e-7
        self.mu_s_scale = mu_s * self.scale

        self.demag = clib.FFTDemag(self.dx, self.dy, self.dz,
                                   self.nx, self.ny, self.nz,
                                   tensor_type='dipolar')
        if not self.calc_every:
            self.compute_field = self.compute_field_every
        else:
            self.count = 0
            self.compute_field = self.compute_field_periodically
Esempio n. 6
0
    def setup(self, mesh, spin, mu_s, mu_s_inv):
        super(Demag, self).setup(mesh, spin, mu_s, mu_s_inv)
        self.scale = 1e-7 / mesh.unit_length**3
        # could be wrong, needs carefully tests!!!
        # David Tue 19 Jun 2018: This variable is updated in the SIM class in
        # case mu_s changes
        self.mu_s_scale = mu_s * self.scale

        self.demag = clib.FFTDemag(self.dx,
                                   self.dy,
                                   self.dz,
                                   self.nx,
                                   self.ny,
                                   self.nz,
                                   tensor_type='dipolar')
        if not self.calc_every:
            self.compute_field = self.compute_field_every
        else:
            self.count = 0
            self.compute_field = self.compute_field_periodically
Esempio n. 7
0
    def setup(self, mesh, spin, Ms, Ms_inv):
        super(Demag, self).setup(mesh, spin, Ms, Ms_inv)

        if self.pbc_2d is True:
            self.demag = clib.FFTDemag(self.dx,
                                       self.dy,
                                       self.dz,
                                       self.nx,
                                       self.ny,
                                       self.nz,
                                       tensor_type='2d_pbc')
            nxyz = self.nx * self.ny * self.nz
            tensors = np.zeros(6 * nxyz, dtype=np.float)
            pbc_2d_error = 1e-10
            sample_repeat_nx = -1
            sample_repeat_ny = -1
            asymptotic_radius = 32.0
            dipolar_radius = 10000.0
            tensor_file_name = None
            options = self.pbc_options

            if 'sample_repeat_nx' in options:
                sample_repeat_nx = options['sample_repeat_nx']
                sample_repeat_ny = options['sample_repeat_ny']
            if 'relative_tensor_error' in options:
                pbc_2d_error = options['relative_tensor_error']
            if 'asymptotic_radius' in options:
                asymptotic_radius = options['asymptotic_radius']
            if 'dipolar_radius' in options:
                dipolar_radius = options['dipolar_radius']
            if 'tensor_file_name' in options:
                tensor_file_name = options['tensor_file_name']

            if tensor_file_name:
                if not (os.path.exists(tensor_file_name + '.npz')):
                    self.demag.compute_tensors_2dpbc(tensors, pbc_2d_error,
                                                     sample_repeat_nx,
                                                     sample_repeat_ny,
                                                     dipolar_radius)
                else:
                    npzfile = np.load(tensor_file_name + '.npz')
                    geo_info = npzfile['geo']
                    geo_arr = np.array(
                        [self.nx, self.ny, self.nz, self.dx, self.dy, self.dz],
                        dtype=np.float)
                    #print 'info', geo_info
                    if not np.allclose(geo_arr, geo_info):
                        self.demag.compute_tensors_2dpbc(
                            tensors, pbc_2d_error, sample_repeat_nx,
                            sample_repeat_ny, dipolar_radius)
                    else:
                        tensors = npzfile['tensors']
                geo_arr = np.array(
                    [self.nx, self.ny, self.nz, self.dx, self.dy, self.dz],
                    dtype=np.float)
                np.savez(tensor_file_name + '.npz',
                         geo=geo_arr,
                         tensors=tensors)

            else:
                self.demag.compute_tensors_2dpbc(tensors, pbc_2d_error,
                                                 sample_repeat_nx,
                                                 sample_repeat_ny,
                                                 dipolar_radius)

            #print tensors
            self.demag.fill_demag_tensors(tensors)

        else:
            if True in mesh.periodicity:
                print(
                    'Warning - you have enabled a periodic mesh, but not enabled the 2d_pbc parameter.\n'
                    'Please look at the implementation of the demag class.\n'
                    '  * You can either specify *both* of sample_repeat_nx and sample_repeat_ny'
                    '  * Alternatively, specify relative_tensor_error to take enough\n'
                    '    repetitions until the demag tensor components are not changing\n'
                    '    more than this tolerance.\n')

            self.demag = clib.FFTDemag(self.dx,
                                       self.dy,
                                       self.dz,
                                       self.nx,
                                       self.ny,
                                       self.nz,
                                       tensor_type='demag')
        if not self.calc_every:
            self.compute_field = self.compute_field_every
        else:
            self.count = 0
            self.compute_field = self.compute_field_periodically
Esempio n. 8
0
    def setup(self, mesh, spin, Ms):
        self.mesh = mesh
        self.dx = mesh.dx
        self.dy = mesh.dy
        self.dz = mesh.dz
        self.nx = mesh.nx
        self.ny = mesh.ny
        self.nz = mesh.nz
        self.spin = spin
        self.field = np.zeros(3 * mesh.n, dtype=np.float)

        self.Ms = Ms

        if self.pbc_2d is True:

            self.demag = clib.FFTDemag(self.dx,
                                       self.dy,
                                       self.dz,
                                       self.nx,
                                       self.ny,
                                       self.nz,
                                       tensor_type='2d_pbc')

            nxyz = self.nx * self.ny * self.nz
            tensors = np.zeros(6 * nxyz, dtype=np.float)

            pbc_2d_error = 1e-10
            sample_repeat_nx = -1
            sample_repeat_ny = -1
            asymptotic_radius = 32.0
            dipolar_radius = 10000.0
            tensor_file_name = ''

            options = self.pbc_options

            if 'sample_repeat_nx' in options:
                sample_repeat_nx = options['sample_repeat_nx']
                sample_repeat_ny = options['sample_repeat_ny']
            if 'relative_tensor_error' in options:
                pbc_2d_error = options['relative_tensor_error']
            if 'asymptotic_radius' in options:
                asymptotic_radius = options['asymptotic_radius']
            if 'dipolar_radius' in options:
                dipolar_radius = options['dipolar_radius']
            if 'tensor_file_name' in options:
                tensor_file_name = options['tensor_file_name']

            if len(tensor_file_name) > 0:
                if not (os.path.exists(tensor_file_name + '.npz')):

                    self.demag.compute_tensors_2dpbc(tensors, pbc_2d_error,
                                                     sample_repeat_nx,
                                                     sample_repeat_ny,
                                                     dipolar_radius)
                else:
                    npzfile = np.load(tensor_file_name + '.npz')
                    geo_info = npzfile['geo']
                    geo_arr = np.array(
                        [self.nx, self.ny, self.nz, self.dx, self.dy, self.dz],
                        dtype=np.float)
                    #print 'info', geo_info
                    if not np.allclose(geo_arr, geo_info):
                        self.demag.compute_tensors_2dpbc(
                            tensors, pbc_2d_error, sample_repeat_nx,
                            sample_repeat_ny, dipolar_radius)
                    else:
                        tensors = npzfile['tensors']

                geo_arr = np.array(
                    [self.nx, self.ny, self.nz, self.dx, self.dy, self.dz],
                    dtype=np.float)
                np.savez(tensor_file_name + '.npz',
                         geo=geo_arr,
                         tensors=tensors)

            else:
                self.demag.compute_tensors_2dpbc(tensors, pbc_2d_error,
                                                 sample_repeat_nx,
                                                 sample_repeat_ny,
                                                 dipolar_radius)

            #print tensors
            self.demag.fill_demag_tensors(tensors)

        else:
            self.demag = clib.FFTDemag(self.dx,
                                       self.dy,
                                       self.dz,
                                       self.nx,
                                       self.ny,
                                       self.nz,
                                       tensor_type='demag')