#with out "eta_field": 0 in spin orbit torque class
from magnumnp import *
import torch
import logging
import os
import math
logging.getLogger('magnum.np').setLevel(logging.CRITICAL)
def erase_file(file_path):
if os.path.isfile(file_path):
with open(file_path, 'w') as f:
f.truncate(0)
print(f'{file_path}'"_File erased successfully.")
else:
# Create the file if it doesn't exist
with open(file_path, 'w') as f:
pass
print("File does not exist.")
class SpinOrbitTorque_ver01(object):
r"""
General spin torque contributions can be described by the following field
.. math::
\vec{h}^\text{sot} = -\frac{j_e \hbar}{2 e \mu_0 M_s} \left[\eta_\text{damp} \, \vec{m} \times \vec{p} + \eta_\text{field} \, \vec{p} \right],
with the current density :math:`j_e`, the reduced Planck constant :math:`\hbar`,
the elementary charge :math:`e`, and the polarization of the electrons :math:`\vec{p}`.
:math:`\eta_\text{damp}` and :math:`\eta_\text{field}` are material parameters which
describe the amplitude of damping- and field-like torque.
In case of Spin-Orbit-Torqe (SOT) :math:`\eta_\text{field}` and :math:`\eta_\text{damp}` are constant material parameters.
"""
#@timedmethod
def h(self, state):
p = state.material["p"].expand_as(state.m)
h = state.material["eta_damp"] * torch.linalg.cross(state.m, p)
h *= -state.material["je"] * constants.hbar / (2. * constants.e * state.material["Ms"] * constants.mu_0 * state.material["d"])
return torch.nan_to_num(h, posinf=0, neginf=0)
def E(self, state):
raise NotImplemented()
class ThermalField1():
r"""
"""
#parameters = ["T"]
def __init__(self, domain=None, **kwargs):
self._step = None
super().__init__(**kwargs)
#@timedmethod
def h(self, state):
if state._step != self._step: # update random field
self._sigma = state._normal(0., 1., size = state.m.shape)
self._step = state._step
alpha = state.material["alpha"].torch_tensor
Ms = state.material["Ms"].torch_tensor
return self._h(self._sigma, alpha, Ms, state)
#@torch.compile
def _h(self, sigma, alpha, Ms, state):
return sigma * torch.sqrt(2. * alpha * constants.kb * 0.8 / (constants.mu_0 * Ms * constants.gamma * state.cell_volumes * state.Tensor(1e-11)))
initialize mesh
eps = 1e-15
#n = (2, 2, 2)
n = (1, 1, 1)
dx = (1.0e-9, 1.0e-9, 1e-9)
mesh = Mesh(n, dx)
state = State(mesh)
Angle in degrees
#n_in_degrees = 6
Convert to radians
n_in_radians = 0.1
Calculate sine
sin_n = math.sin(n_in_radians)
cos_n = math.cos(n_in_radians)
jex=0e12 #x direction with SOPE + SOT
jey=4.1e12 # -y direction with SOT
je=math.sqrt(jexjex+jeyjey)
Example usage:
file_path = f"data_/{jex/1e11}_log1.txt"
erase_file(file_path)
Angjxy=math.atan2(jex, jey) #jex=0 Angjxy=0 jey=0 Angjxy=90
cos_Angjxy=math.cos(Angjxy)
sin_Angjxy=math.sin(Angjxy)
initialize polarization, p, and charge current amplitude
thickness of thin film on which the SOT acts
p = state.Tensor((-cos_Angjxy, -sin_Angjxycos_n, sin_Angjxysin_n))
initialize polarization, p, and charge current amplitude
thickness of thin film on which the SOT acts
#je = 5e12
d = n[2] * dx[2]
Keff = 5e5
state.material = {
"Ms": 1200e3,
"A": 15e-12,
"Ku": Keff,
"Ku_axis": [0, 0, 1],
"gamma": 2.211e5,
"alpha": 0.005,
"eta_damp": -0.3, # both eta with opposite sign as magnum.af, same as magnum.pi
"eta_field": 0,
"p": p,
"d": d,
"je": je # Initial current density
}
def Proba(i):
Timer.enable()
t_run=10e-9
#Current cut off time
cut_off_time = 1e-9
# initialize field terms
exchange = ExchangeField()
aniso = UniaxialAnisotropyField()
therm= ThermalField1()
torque = SpinOrbitTorque_ver01()
# initialize magnetization that relaxes into s-state
state.m = state.Constant([0,0,-1])
# relax without external field
llg = LLGSolver([exchange, aniso])
llg.relax(state)
# perform integration with external field
state.t = 0.
llg = LLGSolver([exchange, aniso]) # Update solver without torque for initial relaxation
def get_je(state):
return state.material["je"]
slogger = ScalarLogger(f"data_je_{jex/1e11}/log_run{i+1}.dat", ['t', 'm', get_je])
while state.t < t_run-eps:
# Update LLG equation and cut off current density after cut_off_time
if state.t < cut_off_time:
llg = LLGSolver([exchange, torque, aniso]) # Include torque during this period
state.material["je"] = je
else:
llg = LLGSolver([exchange, aniso,therm]) # Exclude torque after cut_off_time
state.material["je"] = 0.0 # Set current density to zero
slogger << state
llg.step(state, 1e-11)
slogger1 = ScalarLogger(f"data_/{jex/1e11}_log2.txt", ['t', 'm', get_je])
slogger1 << state
print(f"finish_run{i}")
def append_rows(file_to_append, file_to_append_to):
with open(file_to_append, 'r') as f:
rows_to_append = f.readlines()[1:]
with open(file_to_append_to, 'a') as f:
for row in rows_to_append:
f.write(row)
log2_file = f"data_/{jex/1e11}_log2.txt"
log1_file = f"data_/{jex/1e11}_log1.txt"
append_rows(log2_file, log1_file)
for i in range(0,100):
Proba(i)
#with out "eta_field": 0 in spin orbit torque class
from magnumnp import *
import torch
import logging
import os
import math
logging.getLogger('magnum.np').setLevel(logging.CRITICAL)
def erase_file(file_path):
if os.path.isfile(file_path):
with open(file_path, 'w') as f:
f.truncate(0)
print(f'{file_path}'"_File erased successfully.")
else:
# Create the file if it doesn't exist
with open(file_path, 'w') as f:
pass
print("File does not exist.")
class SpinOrbitTorque_ver01(object):
r"""
General spin torque contributions can be described by the following field
class ThermalField1():
r"""
"""
initialize mesh
eps = 1e-15
#n = (2, 2, 2)
n = (1, 1, 1)
dx = (1.0e-9, 1.0e-9, 1e-9)
mesh = Mesh(n, dx)
state = State(mesh)
Angle in degrees
#n_in_degrees = 6
Convert to radians
n_in_radians = 0.1
Calculate sine
sin_n = math.sin(n_in_radians)
cos_n = math.cos(n_in_radians)
jex=0e12 #x direction with SOPE + SOT
jey=4.1e12 # -y direction with SOT
je=math.sqrt(jexjex+jeyjey)
Example usage:
file_path = f"data_/{jex/1e11}_log1.txt"
erase_file(file_path)
Angjxy=math.atan2(jex, jey) #jex=0 Angjxy=0 jey=0 Angjxy=90
cos_Angjxy=math.cos(Angjxy)
sin_Angjxy=math.sin(Angjxy)
initialize polarization, p, and charge current amplitude
thickness of thin film on which the SOT acts
p = state.Tensor((-cos_Angjxy, -sin_Angjxycos_n, sin_Angjxysin_n))
initialize polarization, p, and charge current amplitude
thickness of thin film on which the SOT acts
#je = 5e12
d = n[2] * dx[2]
Keff = 5e5
state.material = {
"Ms": 1200e3,
"A": 15e-12,
"Ku": Keff,
"Ku_axis": [0, 0, 1],
"gamma": 2.211e5,
"alpha": 0.005,
"eta_damp": -0.3, # both eta with opposite sign as magnum.af, same as magnum.pi
"eta_field": 0,
}
def Proba(i):
Timer.enable()
t_run=10e-9
#Current cut off time
cut_off_time = 1e-9
# initialize field terms
exchange = ExchangeField()
aniso = UniaxialAnisotropyField()
therm= ThermalField1()
torque = SpinOrbitTorque_ver01()
for i in range(0,100):
Proba(i)