def get_velocities(p_state, idx_chain=-1): """Returns the velocities perpendicular to the dividing surface with `shape(2*nos)`.""" nos = system.get_nos(p_state, -1, idx_chain) velocities = (2 * nos * ctypes.c_float)() _Get_Velocities(ctypes.c_void_p(p_state), velocities, ctypes.c_int(idx_chain)) return velocities
def get_eigenvalues_sp(p_state, idx_chain=-1): """Returns the eigenvalues at the saddle point with `shape(2*nos)`.""" nos = system.get_nos(p_state, -1, idx_chain) eigenvalues_sp = (2 * nos * ctypes.c_float)() _Get_Eigenvalues_SP(ctypes.c_void_p(p_state), eigenvalues_sp, ctypes.c_int(idx_chain)) return eigenvalues_sp
def run(enable_output = True): passed = True field_center = [] E = [] for size in system_sizes: with state.State("") as p_state: parameters.llg.set_output_general(p_state, any=False) #turn ddi on hamiltonian.set_ddi(p_state, 1) #turn everything else off hamiltonian.set_exchange(p_state, 0, []) hamiltonian.set_dmi(p_state, 0, []) hamiltonian.set_anisotropy(p_state, 0, [0,0,1]) hamiltonian.set_boundary_conditions(p_state, [0,0,0]) hamiltonian.set_field(p_state, 0, [0,0,1]) geometry.set_n_cells(p_state, [size, size, 1]) configuration.plus_z(p_state) nos = system.get_nos(p_state) simulation.start(p_state, simulation.METHOD_LLG, simulation.SOLVER_VP, n_iterations = 1) Gradient_Spirit = np.array(system.get_effective_field(p_state)).reshape(nos, 3) E_Spirit = system.get_energy(p_state) field_center.append(Gradient_Spirit[int(size/2 + size/2 * size)]) E.append(E_Spirit) if enable_output: with open(outputfile, 'w') as out: out.write("#system_size, field_center_z, energy\n") for i in range(len(E)): out.write("{0}, {1}, {2}\n".format(system_sizes[i], field_center[i][2], E[i]))
def get_eigenvalues_min(p_state, idx_chain=-1): """Returns the eigenvalues at the minimum with `shape(2*nos)`.""" nos = system.get_nos(p_state, -1, idx_chain) eigenvalues_min = (2 * nos * ctypes.c_float)() _Get_Eigenvalues_Min(ctypes.c_void_p(p_state), eigenvalues_min, ctypes.c_int(idx_chain)) return eigenvalues_min
def test_get_spin_directions(self): configuration.plus_z(self.p_state) nos = system.get_nos(self.p_state) arr = system.get_spin_directions(self.p_state) for i in range(nos): self.assertAlmostEqual(arr[i][0], 0.) self.assertAlmostEqual(arr[i][1], 0.) self.assertAlmostEqual(arr[i][2], 1.)
def get_atom_types(p_state, idx_image=-1, idx_chain=-1): """Get the types of all atoms as a `numpy.array_view` of shape (NOS). If e.g. disorder is activated, this allows to view and manipulate the types of individual atoms. """ nos = system.get_nos(p_state, idx_image, idx_chain) ArrayType = ctypes.c_int*nos Data = _Get_Atom_Types(ctypes.c_void_p(p_state), ctypes.c_int(idx_image), ctypes.c_int(idx_chain)) array_pointer = ctypes.cast(Data, ctypes.POINTER(ArrayType)) array = np.frombuffer(array_pointer.contents, dtype=ctypes.c_int) array_view = array.view() return array_view
def get_positions(p_state, idx_image=-1, idx_chain=-1): """Returns a `numpy.array_view` of shape (NOS, 3) with the components of each spins position. Changing the contents of this array_view will have direct effect on the state and should not be done. """ nos = system.get_nos(p_state, idx_image, idx_chain) ArrayType = scalar*3*nos Data = _Get_Positions(ctypes.c_void_p(p_state), ctypes.c_int(idx_image), ctypes.c_int(idx_chain)) array_pointer = ctypes.cast(Data, ctypes.POINTER(ArrayType)) array = np.frombuffer(array_pointer.contents, dtype=scalar) array_view = array.view() array_view.shape = (nos, 3) return array_view
def test_energy(self, p_state, mu=None): nos = system.get_nos(p_state) pos = np.array(geometry.get_positions(p_state)).reshape(nos, 3) spins = np.array(system.get_spin_directions(p_state)).reshape(nos, 3) if type(mu) == type(None): mu_s = np.ones(len(pos)) else: mu_s = mu E_BF = self.E_DDI_BF(pos, spins, mu_s) E_Spirit = system.get_energy(p_state) return E_BF, E_Spirit
def run(self): passed = True l_cube = 100 radius = l_cube / 4 with state.State(self.inputfile, quiet=True) as p_state: configuration.plus_z(p_state) simulation.start(p_state, simulation.METHOD_LLG, simulation.SOLVER_SIB, n_iterations=1) system.update_data(p_state) #query some quantities nos = system.get_nos(p_state) field = np.array(system.get_effective_field(p_state)).reshape( nos, 3) pos = np.array(geometry.get_positions(p_state)).reshape(nos, 3) spins = np.array(system.get_spin_directions(p_state)).reshape( nos, 3) #get quantitities in sphere center = np.array([l_cube / 2, l_cube / 2, l_cube / 2], dtype=int) idx_in_sphere = np.linalg.norm(pos - center, axis=1) <= radius mu_s = np.array([1 if idx_in_sphere[i] else 0 for i in range(nos)]) # field_bf = self.Gradient_DDI_BF(pos, spins, mu_s) # field_bf_in_sphere = field_bf[idx_in_sphere] field_in_sphere = field[idx_in_sphere] # deviation_sphere = np.std(field_in_sphere - mean_grad_sphere, axis=0) theory = np.array( [0, 0, 1]) * 2 / 3 * self.mu_0 * self.mu_B * self.mu_B * 1e30 print("Mean field = ", np.mean(field / self.mu_B, axis=0)) # print("Mean field (BF) = ", np.mean(field_bf/self.mu_B, axis=0)) print("Mean field in sphere = ", np.mean(field_in_sphere / self.mu_B, axis=0)) # print("Mean field in sphere (BF) = ", np.mean(field_bf_in_sphere/self.mu_B, axis=0)) print("Theory = ", theory) return passed
def get_eigenvectors_sp(p_state, idx_chain=-1): """Returns a numpy array view to the eigenvectors at the saddle point with `shape(n_eigenmodes_keep, 2*nos)`.""" n_modes = get_info_dict(p_state)["n_eigenmodes_keep"] nos = system.get_nos(p_state, -1, idx_chain) ArrayType = ctypes.c_float * (2 * nos * n_modes) ev_list = [] * (2 * nos * n_modes) _ev_buffer = ArrayType(*ev_list) _Get_Eigenvectors_SP(ctypes.c_void_p(p_state), _ev_buffer, ctypes.c_int(idx_chain)) ev_array = np.array(_ev_buffer) ev_view = ev_array.view() ev_view.shape = (n_modes, 2 * nos) return ev_view
def test_gradient(p_state, mu = None): nos = system.get_nos(p_state) pos = np.array(geometry.get_positions(p_state)).reshape(nos, 3) spins = np.array(system.get_spin_directions(p_state)).reshape(nos, 3) simulation.start(p_state, simulation.METHOD_LLG, simulation.SOLVER_SIB, n_iterations=1) system.update_data(p_state) if type(mu) == type(None): mu_s = np.ones(len(pos)) else: mu_s = mu Gradient_BF = Gradient_DDI_BF(pos, spins, mu_s) Gradient_Spirit = np.array(system.get_effective_field(p_state)).reshape(nos, 3) return Gradient_BF, Gradient_Spirit
def get_mmf_info(p_state, idx_image=-1, idx_chain=-1): """Returns a set of MMF information, meant mostly for testing or debugging. - `numpy.array_view` of `shape(NOS, 3)` of the energy gradient - the lowest eigenvalue - `numpy.array_view` of `shape(NOS, 3)` of the eigenmode - `numpy.array_view` of `shape(NOS, 3)` of the force """ nos = system.get_nos(p_state, idx_image, idx_chain) ArrayType = ctypes.c_float * (3 * nos) MM = [] * (3 * nos) _MM = ArrayType(*MM) FF = [] * (3 * nos) _FF = ArrayType(*FF) GG = [] * (3 * nos) _GG = ArrayType(*FF) ev = [] * 1 _eval = ArrayType(*ev) _Get_MinimumMode(p_state, _GG, _eval, _MM, _FF, idx_image, idx_chain) # array_pointer = ctypes.cast(_MM, ctypes.POINTER(ArrayType)) # array = np.frombuffer(array_pointer.contents) MMM = np.array(_MM) FFF = np.array(_FF) GGG = np.array(_GG) array_view_mode = MMM.view() array_view_mode.shape = (nos, 3) array_view_force = FFF.view() array_view_force.shape = (nos, 3) array_view_grad = GGG.view() array_view_grad.shape = (nos, 3) return array_view_grad, _eval[0], array_view_mode, array_view_force
def run(self, enable_output=True): passed = True self.inputfile = "test_cases/input/input_saturated_film.cfg" theory = 0.5 N_ITERATIONS = 1 system_sizes = [10 * (i + 1) for i in range(5)] field_center = [] E = [] for size in system_sizes: with state.State(self.inputfile) as p_state: parameters.llg.set_output_general(p_state, any=False) geometry.set_n_cells(p_state, [size, size, 1]) configuration.plus_z(p_state) nos = system.get_nos(p_state) simulation.start(p_state, simulation.METHOD_LLG, simulation.SOLVER_VP, n_iterations=1) Gradient_Spirit = np.array( system.get_effective_field(p_state)).reshape(nos, 3) E_Spirit = system.get_energy(p_state) field_center.append(Gradient_Spirit[int(size / 2 + size / 2 * size)]) E.append(E_Spirit) if enable_output: with open('output_' + self.name + '.txt', 'w') as out: out.write("#system_size, field_center_z, energy\n") for i in range(len(E)): out.write("{0}, {1}, {2}\n".format(system_sizes[i], field_center[i][2], E[i]))
def test_read(self): nos = system.get_nos(self.p_state) configuration.plus_z(self.p_state) io.image_write(self.p_state, io_image_test, io.FILEFORMAT_OVF_TEXT, "python io test") io.image_read(self.p_state, io_image_test) spins = system.get_spin_directions(self.p_state) for i in range(nos): self.assertAlmostEqual(spins[i][0], 0.) self.assertAlmostEqual(spins[i][1], 0.) self.assertAlmostEqual(spins[i][2], 1.) configuration.minus_z(self.p_state) io.image_write(self.p_state, io_image_test, io.FILEFORMAT_OVF_TEXT, "python io test") io.image_read(self.p_state, io_image_test) spins = system.get_spin_directions(self.p_state) for i in range(nos): self.assertAlmostEqual(spins[i][0], 0.) self.assertAlmostEqual(spins[i][1], 0.) self.assertAlmostEqual(spins[i][2], -1.)
def test_get_nos(self): nos = system.get_nos(self.p_state) self.assertEqual(nos, 4)
specific_heat_samples = [] binder_cumulant_samples = [] cfgfile = "ui-python/input.cfg" # Input File with state.State(cfgfile) as p_state: # State setup # Set parameters hamiltonian.set_field(p_state, 0.0, [0, 0, 1]) hamiltonian.set_exchange(p_state, Jij, [1.0]) hamiltonian.set_dmi(p_state, 0, []) parameters.mc.set_output_general(p_state, any=False) # Disallow any output geometry.set_mu_s(p_state, 1.0) geometry.set_n_cells(p_state, [system_size, system_size, system_size]) NOS = system.get_nos(p_state) # Ferromagnet in z-direction configuration.plus_z(p_state) # configuration.Random(p_state) # Loop over temperatures for iT, T in enumerate(sample_temperatures): parameters.mc.set_temperature(p_state, T) # Cumulative average variables E = 0 E2 = 0 M = 0 M2 = 0 M4 = 0