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 run(self): passed = True with state.State(self.inputfile1, quiet=True) as p_state: configuration.plus_z(p_state) system.update_data(p_state) E_1 = system.get_energy(p_state) print('>>> Result 1: mu_s = 1') print('E_DDI = ', E_1) with state.State(self.inputfile2, quiet=True) as p_state: configuration.plus_z(p_state) system.update_data(p_state) E_2 = system.get_energy(p_state) print('\n>>> Result 2: mu_s = 2') print('E_DDI = ', E_2) if np.abs(E_1 * 2**2 - E_2) > 1e-1: passed = False return passed
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, 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_get_energy(self): # NOTE: that test is trivial E = system.get_energy(self.p_state)
p_state, n_thermalisation, n_thermalisation ) # We want n_thermalisation iterations and only a single log message simulation.start(p_state, MC) # Start a MC simulation # Sampling at given temperature parameters.mc.set_iterations( p_state, n_decorrelation * n_samples, n_decorrelation * n_samples ) # We want n_decorrelation iterations and only a single log message simulation.start(p_state, MC, single_shot=True) # Start a single-shot MC simulation for n in range(n_samples): # Run decorrelation for i_decorr in range(n_decorrelation): simulation.single_shot(p_state) # one MC iteration # Get energy E_local = system.get_energy(p_state) / NOS # Get magnetization M_local = np.array(quantities.get_magnetization(p_state)) M_local_tot = np.linalg.norm(M_local) # Add to cumulative averages E += E_local E2 += E_local**2 M += M_local_tot M2 += M_local_tot**2 M4 += M_local_tot**4 # Make sure the MC simulation is not running anymore simulation.stop(p_state) # Average over samples E /= n_samples E2 /= n_samples