Mohit Mithaliya
unread,Jun 27, 2025, 2:23:04 AMJun 27Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Boris Computational Spintronics
Hello Serban,
I was working on FMR simulation on Boris and i have performed simulation for permalloy with the given code in Boris data. But now i want to perform the FMR for the Synthetic antiferromagnet (SAF) system. Since last week i was developing a code for SAF FMR, but i am having difficulty getting FMR. please check the and help,
In code, there are several issues: 1= it is not saving Hbias in the saved file.
Please, sir, check this code and help. Thank you
import sys
import matplotlib.pyplot as plt
import numpy as np
# Setup Boris NetSocks
sys.path.append(r"D:\\Boris Data\\BorisPythonScripts")
from NetSocks import NSClient, customize_plots
ns = NSClient()
ns.configure(True)
customize_plots()
# ==================== SMART LOAD FUNCTION =========================
def smart_loadtxt(filename):
with open(filename) as f:
for i, line in enumerate(f):
try:
float(line.strip().split()[0]) # try to convert first value to float
break
except:
continue
return np.loadtxt(filename, skiprows=i)
# =========================== SAF SETUP ============================
def SetupSAF():
ns.reset()
FM1 = ns.Ferromagnet([200e-9, 200e-9, 2e-9], [5e-9, 5e-9, 1e-9])
FM1.modules(['Zeeman', 'demag', 'exchange', 'surfexchange'])
FM1.param.K1 = 1e-3
FM1.param.ea1 = [1, 0, 0]
FM1.param.grel = 1
FM1.param.A = 13e-12
FM1.param.J1 = -20e-6
FM2 = ns.Ferromagnet([0.0, 0.0, 3e-9, 200e-9, 200e-9, 6e-9], [5e-9, 5e-9, 1e-9])
FM2.modules(['Zeeman', 'demag', 'exchange', 'surfexchange'])
FM2.param.K1 = 1e-3
FM2.param.ea1 = [1, 0, 0]
FM2.param.grel = 1
FM2.param.A = 13e-12
FM2.param.J1 = -20e-6
ns.addmodule('supermesh', 'sdemag')
ns.savesim('fmr')
# ==================== PREPARE FMR SIMULATION ======================
def PrepareFMRSimulation(simulationFile):
ns.loadsim(simulationFile)
ns.savedatafile('fmrcycle.txt')
ns.setstage('Hfmr', 'FM1')
ns.addstage('Hfmr', 'FM1')
ns.editdatasave(1, 'step')
# Apply field and collect data from both FM1 and FM2
ns.setdata('Ha', 'FM1')
ns.setdata('Ha', 'FM2')
ns.adddata('<M>', 'FM1') # columns 3–5
ns.adddata('<M>', 'FM2') # columns 6–8
ns.setangle(90, 0)
ns.savesim(simulationFile)
# ==================== SAF FMR SWEEP FUNCTION ======================
def RunFMRStep(biasH, rfFreq, fileName):
cyclesMax = 200
cyclesChunk = 5
rfH = 100
steps_per_cycle = 5
stopping_time = (1 / rfFreq) / steps_per_cycle
previous_amplitude = 0.0
cyclesSimulated = 0
while cyclesSimulated < cyclesMax:
ns.reset()
ns.dp_clearall()
ns.editstagevalue(0, [0, biasH, 0, rfH, 0, 0, steps_per_cycle, cyclesChunk])
ns.editstagestop(0, 'time', stopping_time)
ns.editstagevalue(1, [0, biasH, 0, rfH, 0, 0, steps_per_cycle, 1])
ns.editstagestop(1, 'time', stopping_time)
ns.Run()
try:
data = smart_loadtxt('fmrcycle.txt')
Mx1 = data[:, 3]
Mx2 = data[:, 6]
netMx = (2/5) * Mx1 + (3/5) * Mx2
time = data[:, 0]
processed = np.column_stack((netMx, time))
np.savetxt('netmx_vs_time.txt', processed, fmt='%.6e')
ns.dp_load('netmx_vs_time.txt', [0, 1])
new_amplitude = float(ns.dp_getampli(0, steps_per_cycle))
except Exception as e:
print("⚠️ Error loading or processing fmrcycle.txt:", e)
new_amplitude = 0.0
cyclesSimulated += cyclesChunk
if new_amplitude:
change = abs((new_amplitude - previous_amplitude) / new_amplitude)
if change < 0.001:
break
previous_amplitude = new_amplitude
ns.SaveDataToFile(fileName, [abs(biasH), new_amplitude])
# =========================== MAIN SCRIPT ===========================
simulation_file = 'fmr'
output_file = simulation_file + '_fieldsweepFMR_data.txt'
ns.dp_newfile(output_file)
Hstart = 75e3
Hend = 85e3
Hstep = 1000
rfFreq = 9e9
SetupSAF()
PrepareFMRSimulation(simulation_file)
for step in range(int((Hend - Hstart) / Hstep) + 1):
Hbias = Hstart + step * Hstep
print("Bias field =", Hbias)
RunFMRStep(-Hbias, rfFreq, output_file)
# ============================ PLOTTING =============================
data = ns.Get_Data_Columns(output_file, [0, 1])
Hrange = [H for H in data[0]]
fmr_signal = [amplitude**2 for amplitude in data[1]]
plt.figure()
plt.axes(xlabel='H (kA/m)', ylabel='FMR Signal (a.u.)')
plt.plot(np.array(Hrange) / 1e3, fmr_signal, 'o-', label='Net SAF Mx')
plt.legend()
plt.savefig('SAF_FMR_NET.png')
plt.show()