import numpy as np
f_cut = 15e9 # Maximum cutoff frequency (Hz)
df = 0.1e9 # Frequency resolution (Hz)
# Calculate sampling time step
t_sampl = 0.5 / (f_cut * 1.25) # Sampling time step (s)
# Calculate the total number of samples needed to achieve the desired frequency resolution
n_of_samples = int(np.ceil(1 / (df * t_sampl)))
# Total time to simulate; increasing this gives you more frequency points in the transform
total_time = 4e-9
# Frequency array for the FFT
freq = np.fft.fftfreq(n_of_samples, t_sampl)
# Debug information
print(f"Sampling time step (t_sampl): {t_sampl:.2e} s")
print(f"Number of samples (n_of_samples): {n_of_samples}")
print(f"Total simulation time (total_time): {total_time:.2e} s")
print(f"Maximum frequency (freq.max()): {freq.max()/1e9:.2f} GHz")
print(f"Frequency resolution (freq[1]): {freq[1]/1e9:.2f} GHz")
# Simulation parameters for the LLG solver
ns.setode('LLG', 'RK4')
dt=2e-13
ns.setdt(dt)
print(250e-15, t_sampl)
# Field and excitation field strength
ns.setdata('commbuf')
ns.iterupdate(100)
ns.setstage('Hequation',"supermesh")
# Set stage stop and data save intervals
ns.editstagestop(0, 'time', total_time)
ns.editdatasave(0, 'time', t_sampl)
# Define the equation constants
# Excitation field (A/m)
# Define excitation field as a sinc function
phi = 0.00001 * np.pi / 180
theta = 89.99999 * np.pi / 180
B0=0.005 #Tesla
H0 = 795775*B0
He = H0 * 0.01
ns.equationconstants('H0', H0)
ns.equationconstants('theta', theta)
ns.equationconstants('phi', phi)
ns.equationconstants('t0', 2e-9)
ns.equationconstants('He', He)
ns.equationconstants('fc', f_cut)
ns.editstagevalue(0,'H0*sin(theta)*cos(phi), H0*sin(theta)*sin(phi), H0*cos(theta))+ He*sinc(2*PI*fc*(t-t0)')
ns.editstagestop(0, 'time', total_time)
ns.editdatasave(0, 'time', t_sampl)
# print(int(t_sampl/dt))
# ns.editdatasave(0, 'iter', int(t_sampl/dt))
import os
path = 'R:/Boris/v5DP_2e14_0005T/'
try:
os.makedirs(path)
except OSError as error:
print(error)
ns.saveovf2mag(f'{path}fmr_%time%.ovf', bufferCommand = True)
ns.cuda(1)
ns.reset()
ns.Run()