from NetSocks import NSClient
import matplotlib.pyplot as plt
import numpy as np
import scipy as sp
import os
# Initialize NetSocks client
ns = NSClient(embedded=False)
ns.configure(True)
cuda = 0
############## Magnetic Parameters #############################
Ms = 900e3
damping = 0.02
RA = 0.15 * 1e-12 # Ohm m2
################################################################
############# AFM ##############################################
################################################################
AFM = ns.AntiFerromagnet([0, 0, -17e-9, 50e-9, 50e-9, 0], [5e-9, 5e-9, 0.520e-9])
AFM.modules(['demag', 'aniuni', 'exchange', 'Zeeman', 'surfexchange'])
AFM.param.K1_AFM = [600e3, 600e3]
AFM.param.ea1 = [1, 0, 0]
AFM.param.J1 = 800e-6
AFM.setangle(90, 0)
############# Pinned Layer #####################################
PL = ns.Material('CoFeB', [0, 0, 0, 50e-9, 50e-9, 2.6e-9], [5e-9, 5e-9, 0.520e-9])
PL.modules(['demag', 'exchange', 'Zeeman', 'aniuni', 'surfexchange'])
PL.param.K1 = 1e3
PL.param.ea1 = [0, 0, 1]
PL.param.Ms = Ms
PL.param.grel = 1
PL.param.A = 14e-12
PL.param.J1 = 600e-6
PL.setangle(-90, 0)
PL.param.damping = damping
############# Reference Layer ##################################
RL = ns.Material('CoFeB', [0, 0, 3.4e-9, 50e-9, 50e-9, 6e-9], [5e-9, 5e-9, 0.520e-9])
RL.modules(['demag', 'exchange', 'Zeeman', 'aniuni', 'surfexchange'])
RL.param.K1 = 2e3
RL.param.ea1 = [0, 0, 1]
RL.param.Ms = Ms
RL.param.grel = 1
RL.param.A = 14e-12
RL.param.J1 = -450e-6
RL.setangle(-90, 0)
RL.param.damping = damping
############# Free Layer #######################################
FL = ns.Material('CoFeB', [0, 0, 6.8e-9, 50e-9, 50e-9, 9.8e-9], [5e-9, 5e-9, 0.520e-9])
FL.modules(['demag', 'exchange', 'Zeeman', 'aniuni', 'surfexchange'])
FL.param.K1 = 2e3
FL.param.ea1 = [0, 0, 1]
FL.param.Ms = Ms
FL.param.grel = 1
FL.param.A = 14e-12
FL.param.J1 = 20e-6
FL.setangle(-90, 0)
FL.param.damping = damping
#####################################################
ns.addmodule('supermesh', 'sdemag')
ns.cuda(cuda)
#####################################################
def get_fmr_peak(P):
#2D fft
fourier_data = np.fft.fftshift(np.abs(sp.fftpack.fft(P))**2)
#get value ranges
freq_len = len(fourier_data)
freq = sp.fftpack.fftfreq(freq_len, time_step)
#extract result from fourier data in a plottable form
result = fourier_data[int(freq_len/2):freq_len]
return freq, result
#H0: bias field strength (A/m)
def simulate_fmr_peak(H0):
"""Simulate FMR peak for given bias field strength"""
#Bias field (A/m)
ns.equationconstants('H0', H0)
ns.equationconstants('He', He)
#f cutoff (Hz)
ns.equationconstants('fc', fc)
#sinc pulse center (s)
ns.equationconstants('t0', total_time / 2)
ns.reset()
ns.Run()
#Analyse
#get 2D list as position along horizontal, time along vertical
data = ns.Get_Data_Columns(ns.savedatafile())
Mx_FL = [row[1]/Ms for row in data]
Mx_RL = [row[4]/Ms for row in data]
Mx_PL = [row[7]/Ms for row in data]
Mx = np.array(Mx_PL) * 0.32098 + np.array(Mx_RL) * 0.32098 + np.array(Mx_FL) * 0.358024
plt.axes(xlabel = 'f (Hz)', ylabel = 'FMR Signal (a.u.)', title = 'Frequency-swept FMR_H0_{H0}')
freq, result = get_fmr_peak(Mx)
plt.plot(freq[0:len(result)], result, '.-', label = 'MTJ')
xy = []
xy.append(freq[0:len(result)])
xy.append(result)
ns.Save_Data_Columns(f'fmr_temp_H0_{H0}.txt', xy)
plt.legend()
plt.show()
########################################
#FMR peak simulation
H0 = 71e3
#relax starting configuration
ns.setode('LLGStatic', 'SDesc')
ns.setfield(H0, 0, 0)
ns.Relax(['mxh', 1e-5])
ns.reset()
#data to save
ns.setsavedata('MTJ_FMR.txt', ['<M>', FL], ['<M>', RL], ['<M>', PL])
#cutoff frequency (Hz)
fc = 20e9
#time step for saving magnetisation (s) : determined by Nyquist criterion from cutoff frequency
time_step = (0.5 / fc)
#total time to simulate; increasing this gives you more frequency points in the transform
total_time = 5000e-12
#Field and excitation field strength
He = 100
#setup sinc pulse using a formula
ns.setstage(['Hequation', 'supermesh'])
ns.editstagevalue(0, 'H0, He * sinc(2*PI*fc*(t-t0)), 0')
ns.editstagestop(0, 'time', total_time)
ns.editdatasave(0, 'time', time_step)
#define the equation constants
#Excitation field (A/m)
ns.equationconstants('He', He)
#f cutoff (Hz)
ns.equationconstants('fc', fc)
#sinc pulse center (s)
ns.equationconstants('t0', total_time / 2)
ns.setode('LLG', 'RK4')
ns.setdt(250e-15)
#Simulate
simulate_fmr_peak(H0)
########################################
same. Also, if I changed the GPU, it would change.
should not be there. What can we other possible solutions to get proper FMR spectra?