def run_finmag(demagsolver): """Run the finmag simulation and store data in (demagsolvertype)averages.txt.""" sim = Sim(mesh, Ms, unit_length=unit_length) sim.alpha = 0.5 sim.set_m((1, 0, 1)) exchange = Exchange(13.0e-12) sim.add(exchange) demag = Demag(solver=demagsolver) sim.add(demag) fh = open(os.path.join(MODULE_DIR, demagsolver + "averages.txt"), "w") fe = open(os.path.join(MODULE_DIR, demagsolver + "energies.txt"), "w") # Progressbar bar = pb.ProgressBar(maxval=60, \ widgets=[pb.ETA(), pb.Bar('=', '[', ']'), ' ', pb.Percentage()]) logger.info("Time integration") times = np.linspace(0, 3.0e-10, 61) #times = np.linspace(0, 3.0e-10, 100000) for counter, t in enumerate(times): bar.update(counter) # Integrate sim.run_until(t) print counter print("press return to continue") _ = raw_input() # Save averages to file mx, my, mz = sim.m_average fh.write(str(t) + " " + str(mx) + " " + str(my) + " " + str(mz) + "\n") # Energies E_e = exchange.compute_energy() E_d = demag.compute_energy() fe.write(str(E_e) + " " + str(E_d) + "\n") # Energy densities if counter == 10: exch_energy = exchange.energy_density_function() demag_energy = demag.demag.energy_density_function() finmag_exch, finmag_demag = [], [] R = range(100) for i in R: finmag_exch.append(exch_energy([15, 15, i])) finmag_demag.append(demag_energy([15, 15, i])) # Store data np.save( os.path.join(MODULE_DIR, "finmag%s_exch_density.npy" % demagsolver), np.array(finmag_exch)) np.save( os.path.join(MODULE_DIR, "finmag%s_demag_density.npy" % demagsolver), np.array(finmag_demag)) fh.close() fe.close()
def run_finmag(): """Run the finmag simulation and store data in averages.txt.""" sim = Sim(mesh, Ms, unit_length=unit_length) sim.alpha = 0.5 sim.set_m((1, 0, 1)) exchange = Exchange(13.0e-12) sim.add(exchange) demag = Demag(solver="FK") sim.add(demag) fh = open(os.path.join(MODULE_DIR, "averages.txt"), "w") fe = open(os.path.join(MODULE_DIR, "energies.txt"), "w") logger.info("Time integration") times = np.linspace(0, 3.0e-10, 61) for counter, t in enumerate(times): # Integrate sim.run_until(t) # Save averages to file mx, my, mz = sim.m_average fh.write(str(t) + " " + str(mx) + " " + str(my) + " " + str(mz) + "\n") # Energies E_e = exchange.compute_energy() E_d = demag.compute_energy() fe.write(str(E_e) + " " + str(E_d) + "\n") # Energy densities if counter == 10: exch_energy = exchange.energy_density_function() demag_energy = demag.energy_density_function() finmag_exch, finmag_demag = [], [] R = range(100) for i in R: finmag_exch.append(exch_energy([15, 15, i])) finmag_demag.append(demag_energy([15, 15, i])) # Store data np.save(os.path.join(MODULE_DIR, "finmag_exch_density.npy"), np.array(finmag_exch)) np.save(os.path.join(MODULE_DIR, "finmag_demag_density.npy"), np.array(finmag_demag)) fh.close() fe.close()