SharedF_res vs. H.ipynbOpen in CoCalc
Jupyter notebook F_res vs. H.ipynb

Fitting of Fresvs.HF_{res} vs. H for pMTJ structures using Python

##Introduction

In this project, we ae going to model an all prependicular device based on Kittle formula and try to calculate its FMR frequency under the application of a tilted field. The structure contains two magnetic layers, 11 is the fixed layer and 22 is the free layer, which are separated by an insulator spacer. Based on Kittle formula, the resonance frequency, ωr\omega_r, for an applied DC magnetic field, HdcH_{dc}, is equal to

(ωrγ)2=H1H2\displaystyle(\frac{\omega_r}{\gamma})^2=H_1 H_2

Here, γ\gamma is Gyromagnetic ratio, HKi1eff=Msμ02Ki1+2Ki2Ms\displaystyle H_{Ki1}^{eff} = \frac{M_s}{\mu_0} - 2*\frac{K_{i1}+2K_{i2}}{M_s} and HKi2eff=4Ki2Ms\displaystyle H_{Ki2}^{eff} = 4*\frac{K_{i2}}{M_s} are the magnetic anisotropy fields in which Ki1K_{i1} and Ki2K_{i2} are the first and second order anisotropy for the ithi_{th} layer. HstH_{st} is defined as the stray field between the layers. θHθ_H is the angle of the DC applied field and θ1θ_1 and θ2θ_2 are the equilibrium angles of the layers when the DC field is applied to the structure. All the angles are defined w.r.t. the normal vector of the layers. To find θ1θ_1 and θ2θ_2 values, the equilibrium conditions of both the layers should be solved for all the applied field values.

pMTJ Structure

In order to simplify the model, we consider the fixed layer is always prependicular (θeq1=0θ_{eq1} = 0), and also ignore the second order anisotropy of the free layer (HK22=0H_{K22} = 0). Then the equilibrium condition for the free layer is:

Also H1H_{1} and H2H_{2} is simpliefied to

Using the formula, we can simply extract the equilibrium angle of the magnetization versus the strength of the field for a given external field angel.

##Results

First we import the PythonPython libraries we need. NumpyNumpy for handling arrays, ScipyScipy for finding the equilibrium angle, and pylabpylab for plotting.

from scipy.optimize import fsolve
import math
import numpy as np
from scipy.optimize import curve_fit
from numpy import *
import matplotlib.pyplot as plt
import matplotlib.lines as mlines

import pylab as pl           # Imports all plotting capability of magplotlib.
%matplotlib inline           
# "%matplotlib inline" makes all plots show up inside the document (i.e. "inline") and not in a separate plot window.

Then we need to set the ranges for the parameters in our model. Here we can define the ranges for HK11H_{K11} and HstHst. The code uses for loops to solve the equation for every combinations of these two parameters.

Hk21max=16000
Hk21min=16000
Hk21step=500 # should be positive
#----------------------------------
Hstmax=0
Hstmin=0
Hststep=500 # should be positive
#==================================
gamma = 0.00319

Here, the external field is defined. angleangle is the angle of the applied DC magnetic field in degree w.r.t. the normal vector of the layers (For in-plane field, angle=90angle = 90), and HdcH_{dc} is vector contains the strength of the applied field.

angle=20

#Whole the range
Hdc = array(range(0, 20000, 50))

Here the equilibrium condition and the resonance frequency for the free layer based on Kittel formula are defined.

def equilibrium_eq(p):
    theta2 = p
    return (H*math.cos(theta2+np.pi/2-thetaH)-Hst*math.sin(theta2)+Hk21*math.sin(theta2)*math.cos(theta2))
################################################################################
def fres_func(Hdc, theta2):
    return gamma*( (Hdc*np.sin(theta2+np.pi/2-thetaH)+Hst*np.cos(theta2)-(HK21)*np.cos(2*theta2)) * (Hdc*np.sin(theta2+np.pi/2-thetaH)+Hst*np.cos(theta2)-HK21*np.cos(theta2)**2) )**(0.5)

The next cell is for the initialization of the variables used in the code.

thetaH=np.pi/180*(angle)
Theta2 = array(zeros(len(Hdc)))
Frequency = array(zeros(len(Hdc)))


Here, based on the ranges defined for the parameters, the code does the sweep and fitting. The output is the table contains the combination of the parameters and the calculated adj.r.sqadj.r.sq values.

print "=========================================================================================================================="
print "----------------------------------------------------------------------------"
print "gamma=",gamma,", angle=",angle
print "Hdc :", (Hdc)
print "----------------------------------------------------------------------------"
plt.close('all')
print "=========================================================================================================================="
for Hst in xrange(Hstmin,Hstmax+Hststep,Hststep):
    for Hk21 in xrange(Hk21min,Hk21max+Hk21step,Hk21step):
        HK21=[Hk21]
        for i in xrange(0,len(Hdc)):
            H = Hdc[i]
            x2 =  fsolve(equilibrium_eq, (0))
            Theta2[i]=x2
################################################################################
        Frequency = fres_func(Hdc, Theta2)
        print "Hst=",np.round(Hst),", Hk21=",np.round(Hk21)
        print "--------------------------------------------------------------------------------------------------------------------------"
        print "theta :", (Theta2/np.pi*180)
        print "=========================================================================================================================="
        print "--------------------------------------------------------------------------------------------------------------------------"
        print "Frequency :", (Frequency)
        print "=========================================================================================================================="
        plt.figure("Theta", figsize=(8, 6), dpi=80)
        plt.ylabel('theta (degree)')
        plt.xlabel('Hdc (Oe)')
        plt.plot(Hdc, Theta2/np.pi*180)
        #plt.plot(Hdc,  angel, 'g^',label='Field angle')
        #plt.title('Theta1:blue, Theta2:red, Relative Theta:green ')
        #plt.legend(loc='upper left',handles=[mlines.Line2D([], [], color='blue', marker='s', label='Theta1'),mlines.Line2D([], [], color='red', marker='s', label='Theta2'),mlines.Line2D([], [], color='green', marker='^', label='relTheta')],numpoints=1)       
        plt.figure("main", figsize=(8, 6), dpi=80)
        ax = plt.subplot(111)
        plt.ylabel('f_resonance (GHz)')
        plt.xlabel('Hdc (Oe)')
        plt.plot(Hdc, Frequency)
        #plt.plot(Hdc, fittedFres, label=('Hk21='+str(Hk21)+' ,Hst='+str(Hst)) )
            

========================================================================================================================== ---------------------------------------------------------------------------- gamma= 0.00319 , angle= 20 Hdc : [ 0 50 100 150 200 250 300 350 400 450 500 550 600 650 700 750 800 850 900 950 1000 1050 1100 1150 1200 1250 1300 1350 1400 1450 1500 1550 1600 1650 1700 1750 1800 1850 1900 1950 2000 2050 2100 2150 2200 2250 2300 2350 2400 2450 2500 2550 2600 2650 2700 2750 2800 2850 2900 2950 3000 3050 3100 3150 3200 3250 3300 3350 3400 3450 3500 3550 3600 3650 3700 3750 3800 3850 3900 3950 4000 4050 4100 4150 4200 4250 4300 4350 4400 4450 4500 4550 4600 4650 4700 4750 4800 4850 4900 4950 5000 5050 5100 5150 5200 5250 5300 5350 5400 5450 5500 5550 5600 5650 5700 5750 5800 5850 5900 5950 6000 6050 6100 6150 6200 6250 6300 6350 6400 6450 6500 6550 6600 6650 6700 6750 6800 6850 6900 6950 7000 7050 7100 7150 7200 7250 7300 7350 7400 7450 7500 7550 7600 7650 7700 7750 7800 7850 7900 7950 8000 8050 8100 8150 8200 8250 8300 8350 8400 8450 8500 8550 8600 8650 8700 8750 8800 8850 8900 8950 9000 9050 9100 9150 9200 9250 9300 9350 9400 9450 9500 9550 9600 9650 9700 9750 9800 9850 9900 9950 10000 10050 10100 10150 10200 10250 10300 10350 10400 10450 10500 10550 10600 10650 10700 10750 10800 10850 10900 10950 11000 11050 11100 11150 11200 11250 11300 11350 11400 11450 11500 11550 11600 11650 11700 11750 11800 11850 11900 11950 12000 12050 12100 12150 12200 12250 12300 12350 12400 12450 12500 12550 12600 12650 12700 12750 12800 12850 12900 12950 13000 13050 13100 13150 13200 13250 13300 13350 13400 13450 13500 13550 13600 13650 13700 13750 13800 13850 13900 13950 14000 14050 14100 14150 14200 14250 14300 14350 14400 14450 14500 14550 14600 14650 14700 14750 14800 14850 14900 14950 15000 15050 15100 15150 15200 15250 15300 15350 15400 15450 15500 15550 15600 15650 15700 15750 15800 15850 15900 15950 16000 16050 16100 16150 16200 16250 16300 16350 16400 16450 16500 16550 16600 16650 16700 16750 16800 16850 16900 16950 17000 17050 17100 17150 17200 17250 17300 17350 17400 17450 17500 17550 17600 17650 17700 17750 17800 17850 17900 17950 18000 18050 18100 18150 18200 18250 18300 18350 18400 18450 18500 18550 18600 18650 18700 18750 18800 18850 18900 18950 19000 19050 19100 19150 19200 19250 19300 19350 19400 19450 19500 19550 19600 19650 19700 19750 19800 19850 19900 19950] ---------------------------------------------------------------------------- ========================================================================================================================== Hst= 0 , Hk21= 16000 -------------------------------------------------------------------------------------------------------------------------- theta :
/ext/sage/sage-8.0/local/lib/python2.7/site-packages/scipy/optimize/minpack.py:161: RuntimeWarning: The iteration is not making good progress, as measured by the improvement from the last ten iterations. warnings.warn(msg, RuntimeWarning) /ext/sage/sage-8.0/local/lib/python2.7/site-packages/scipy/optimize/minpack.py:161: RuntimeWarning: The iteration is not making good progress, as measured by the improvement from the last five Jacobian evaluations. warnings.warn(msg, RuntimeWarning) /ext/sage/sage-8.0/local/lib/python2.7/site-packages/ipykernel/__main__.py:6: RuntimeWarning: invalid value encountered in sqrt
[ 0. -0.06141884 -0.1232006 -0.18534859 -0.24786615 -0.31075667 -0.37402359 -0.43767038 -0.50170059 -0.56611778 -0.63092559 -0.69612768 -0.7617278 -0.82772971 -0.89413724 -0.96095429 -1.02818479 -1.09583274 -1.16390219 -1.23239726 -1.30132212 -1.37068099 -1.44047818 -1.51071804 -1.58140499 -1.65254352 -1.72413818 -1.79619361 -1.86871449 -1.94170559 -2.01517175 -2.08911789 -2.16354899 -2.23847013 -2.31388645 -2.38980319 -2.46622566 -2.54315926 -2.62060949 -2.69858191 -2.7770822 -2.85611613 -2.93568956 -3.01580843 -3.09647882 -3.17770689 -3.2594989 -3.34186123 -3.42480038 -3.50832294 -3.59243563 -3.6771453 -3.7624589 -3.84838353 -3.9349264 -4.02209486 -4.10989641 -4.19833866 -4.28742939 -4.37717652 -4.46758812 -4.55867241 -4.65043778 -4.74289278 -4.83604614 -4.92990675 -5.02448368 -5.11978619 -5.21582374 -5.31260597 -5.41014272 -5.50844405 -5.60752024 -5.70738176 -5.80803934 -5.90950393 -6.01178672 -6.11489916 -6.21885294 -6.32366005 -6.42933271 -6.53588346 -6.64332512 -6.75167082 -6.860934 -6.97112842 -7.08226818 -7.19436774 -7.30744191 -7.42150588 -7.53657521 -7.6526659 -7.76979433 -7.88797732 -8.00723217 -8.12757661 -8.24902888 -8.37160771 -8.49533236 -8.62022263 -8.74629892 -8.87358218 -9.00209399 -9.13185661 -9.26289291 -9.39522651 -9.52888175 -9.66388372 -9.80025833 -9.93803231 -10.07723328 -10.21788976 -10.36003126 -10.50368827 -10.64889236 -10.79567619 -10.94407361 -11.09411968 -11.24585076 -11.39930459 -11.55452031 -11.7115386 -11.87040174 -12.03115369 -12.1938402 -12.35850892 -12.52520949 -12.69399369 -12.86491557 -13.03803157 -13.21340067 -13.39108461 -13.57114801 -13.7536586 -13.93868743 -14.1263091 -14.31660202 -14.5096487 -14.70553603 -14.90435566 -15.10620433 -15.31118432 -15.51940388 -15.73097775 -15.94602772 -16.16468323 -16.38708214 -16.61337141 -16.84370807 -17.07826019 -17.31720796 -17.56074502 -17.8090799 -18.06243766 -18.32106181 -18.58521652 -18.85518916 -19.13129328 -19.41387206 -19.70330245 -20. -20.30442466 -20.61708773 -20.93856032 -21.26948363 -21.61058165 -21.962677 -22.3267109 -22.7037686 -23.09511235 -23.50222474 -23.92686671 -24.37115691 -24.83768258 -25.32965923 -25.85116775 -26.40752092 -27.00585744 -27.65616464 -28.3731822 -29.18034196 -30.11927711 -31.27928703 -32.95187039 -35.49412469 -35.46890554 -35.3507399 -35.28226834 -35.20535311 -35.13004491 -35.05925216 -34.98053943 -34.90904108 -34.83894403 -34.7513119 -34.68564584 -34.61008223 -34.51183406 -34.45802045 -34.41675556 -34.3016975 -34.23096385 -34.15025756 -34.07691338 -33.99492812 -33.92240638 -33.84880687 -33.75983631 -33.66952318 -33.59594363 -33.51393875 -33.41963573 -33.3683364 -33.22659285 -33.2181317 -33.08811115 -33.01720251 -32.9451459 -32.85636357 -32.76611991 -32.69018686 -32.59704349 -32.51036539 -32.42221273 -32.30802189 -32.19185398 -32.17347224 -32.08763776 -31.99181196 -31.87718471 -31.82081564 -31.71558087 -31.63473958 -31.53910623 -31.47744739 -31.34240217 -31.20477365 -31.21171165 -31.07012389 -30.98204412 -30.89221215 -30.78143291 -30.70707868 -30.58958968 -30.4958799 -30.3550117 -30.29315593 -30.14849555 -30.14484339 -29.99540207 -29.92684105 -29.79290707 -29.61290601 -29.58115995 -29.47161581 -29.35951079 -29.25602276 -29.15005661 -29.04152365 -28.97706526 -28.8163711 -28.72350531 -28.62827416 -28.50601245 -28.38055589 -28.28961481 -28.1195439 -28.08735768 -27.94921129 -27.80720266 -27.6949336 -27.59313615 -27.57872232 -27.30996613 -27.26222587 -26.98043926 -26.985162 -26.84758545 -26.75131287 -26.62868808 -26.45479945 -26.37108123 -26.23567637 -26.0955648 -25.95049676 -25.80878171 -25.67933857 -25.62513894 -25.24246421 -25.28859859 -25.11033946 -25.00181196 -24.8102989 -24.69089431 -24.40258169 -24.43635149 -24.25772416 -24.09277294 -23.94246459 -23.76198186 -23.59609661 -23.47001376 -23.31266481 -23.14693218 -22.94605241 -22.73386722 -22.6473198 -22.49879678 -22.25330136 -22.11307363 -21.94806256 -21.72215913 -21.90050284 -21.58870572 -21.25340838 -21.04107871 -20.96675245 -20.60276948 -20.46012572 -20.17152685 -19.94760211 -19.70075542 -19.53006411 -19.39423184 -19.1267504 -18.89447774 -18.62165725 -18.38492943 -17.780573 -17.64119018 -17.59153705 -17.35727781 -17.07452963 -16.81189035 -16.45596972 -16.32753396 48.23897561 48.15748113 48.0762525 47.9952895 47.9145919 47.83415947 47.75399198 47.67408918 47.59445081 47.51507662 47.43596633 47.35711969 47.2785364 47.20021618 47.12215874 47.04436377 46.96683097 46.88956003 46.81255062 46.73580242 46.65931509 46.5830883 46.5071217 46.43141493 46.35596763 46.28077945 46.20585 46.13117891 46.0567658 45.98261027 45.90871192 45.83507036 45.76168518 45.68855595 45.61568226 45.54306369 45.47069979 45.39859013 45.32673427 45.25513176 45.18378214 45.11268494 45.04183971 44.97124597 44.90090325 44.83081105 44.7609689 44.6913763 44.62203274 44.55293774 44.48409077 44.41549133 44.3471389 44.27903295 44.21117295 44.14355838 44.07618869 44.00906334 43.94218179 43.87554349 43.80914787 43.74299438 43.67708246 43.61141154] ========================================================================================================================== -------------------------------------------------------------------------------------------------------------------------- Frequency : [ 5.10400000e+01 5.08900896e+01 5.07401194e+01 5.05900877e+01 5.04399929e+01 5.02898334e+01 5.01396075e+01 4.99893135e+01 4.98389496e+01 4.96885140e+01 4.95380049e+01 4.93874205e+01 4.92367588e+01 4.90860180e+01 4.89351959e+01 4.87842907e+01 4.86333002e+01 4.84822224e+01 4.83310551e+01 4.81797961e+01 4.80284432e+01 4.78769940e+01 4.77254464e+01 4.75737978e+01 4.74220459e+01 4.72701881e+01 4.71182221e+01 4.69661450e+01 4.68139545e+01 4.66616476e+01 4.65092217e+01 4.63566739e+01 4.62040015e+01 4.60512014e+01 4.58982706e+01 4.57452061e+01 4.55920048e+01 4.54386634e+01 4.52851786e+01 4.51315472e+01 4.49777657e+01 4.48238307e+01 4.46697384e+01 4.45154854e+01 4.43610678e+01 4.42064818e+01 4.40517236e+01 4.38967891e+01 4.37416742e+01 4.35863747e+01 4.34308865e+01 4.32752050e+01 4.31193258e+01 4.29632444e+01 4.28069559e+01 4.26504557e+01 4.24937388e+01 4.23368001e+01 4.21796345e+01 4.20222367e+01 4.18646012e+01 4.17067226e+01 4.15485951e+01 4.13902129e+01 4.12315700e+01 4.10726604e+01 4.09134776e+01 4.07540153e+01 4.05942669e+01 4.04342256e+01 4.02738845e+01 4.01132363e+01 3.99522739e+01 3.97909896e+01 3.96293758e+01 3.94674245e+01 3.93051276e+01 3.91424768e+01 3.89794634e+01 3.88160787e+01 3.86523136e+01 3.84881587e+01 3.83236045e+01 3.81586410e+01 3.79932583e+01 3.78274458e+01 3.76611928e+01 3.74944882e+01 3.73273208e+01 3.71596786e+01 3.69915497e+01 3.68229216e+01 3.66537815e+01 3.64841162e+01 3.63139120e+01 3.61431549e+01 3.59718303e+01 3.57999233e+01 3.56274183e+01 3.54542995e+01 3.52805502e+01 3.51061534e+01 3.49310915e+01 3.47553462e+01 3.45788986e+01 3.44017292e+01 3.42238177e+01 3.40451432e+01 3.38656839e+01 3.36854173e+01 3.35043200e+01 3.33223678e+01 3.31395355e+01 3.29557970e+01 3.27711251e+01 3.25854915e+01 3.23988668e+01 3.22112205e+01 3.20225208e+01 3.18327344e+01 3.16418267e+01 3.14497617e+01 3.12565016e+01 3.10620072e+01 3.08662373e+01 3.06691489e+01 3.04706969e+01 3.02708342e+01 3.00695113e+01 2.98666764e+01 2.96622749e+01 2.94562497e+01 2.92485404e+01 2.90390837e+01 2.88278128e+01 2.86146571e+01 2.83995422e+01 2.81823893e+01 2.79631152e+01 2.77416315e+01 2.75178445e+01 2.72916548e+01 2.70629562e+01 2.68316361e+01 2.65975739e+01 2.63606410e+01 2.61206995e+01 2.58776017e+01 2.56311887e+01 2.53812897e+01 2.51277202e+01 2.48702808e+01 2.46087554e+01 2.43429093e+01 2.40724869e+01 2.37972087e+01 2.35167689e+01 2.32308310e+01 2.29390243e+01 2.26409380e+01 2.23361158e+01 2.20240483e+01 2.17041641e+01 2.13758191e+01 2.10382831e+01 2.06907232e+01 2.03321828e+01 1.99615551e+01 1.95775484e+01 1.91786412e+01 1.87630217e+01 1.83285065e+01 1.78724269e+01 1.73914676e+01 1.68814305e+01 1.63368763e+01 1.57505590e+01 1.51124857e+01 1.44082522e+01 1.36158423e+01 1.26987404e+01 1.15884777e+01 1.01268415e+01 7.72621119e+00 1.62010258e-01 nan 1.30794228e-01 nan 1.51152630e-01 2.64972003e-01 1.24417928e-01 3.44954625e-01 2.55192043e-01 nan 4.88387401e-01 2.13550225e-01 2.17123393e-01 7.03383174e-01 2.17404476e-01 nan 3.19578189e-01 nan 1.80136550e-01 nan 9.88037868e-02 nan nan nan 3.90260013e-01 1.60232953e-01 2.16669861e-01 5.31820416e-01 nan 8.94974897e-01 nan 5.61934988e-01 3.10673440e-01 nan nan 2.56742887e-01 nan 1.91537821e-01 2.15408768e-01 2.69228137e-01 7.17846355e-01 9.87548998e-01 nan nan nan 5.59223606e-01 nan 1.30897451e-01 nan nan nan 3.21872964e-01 8.69130063e-01 nan nan nan nan 7.41047402e-02 nan nan nan 7.02236866e-01 nan 7.64684894e-01 nan nan nan nan 9.45194925e-01 nan 2.36630953e-01 3.73253244e-01 3.30292655e-01 3.16348477e-01 3.35340545e-01 nan 4.49743569e-01 1.00967372e-01 nan nan 3.27941399e-01 nan 6.83266944e-01 nan nan 3.13028329e-01 2.11971296e-01 nan nan 5.50736748e-01 nan 1.04860943e+00 nan 1.53420369e-01 nan nan 3.69395343e-01 nan nan nan nan 2.14021254e-01 4.31012944e-02 nan 1.11423454e+00 nan 3.44151812e-01 nan 4.69067574e-01 1.99375186e-01 1.00200629e+00 nan nan 2.35885585e-01 1.93587015e-01 4.40796565e-01 4.95522425e-01 2.22266431e-01 1.73541105e-01 2.17660917e-01 4.94871730e-01 6.93902908e-01 1.99689334e-01 nan 5.29664444e-01 3.15826831e-01 1.80183544e-01 4.84278125e-01 nan nan nan nan nan 2.72189400e-01 nan 3.75423649e-01 4.22897945e-01 5.24380306e-01 3.30449601e-01 nan nan nan 1.92241608e-01 1.05221011e-01 9.21501707e-01 7.33062959e-01 2.03394141e-01 nan nan nan 2.96458266e-02 nan 3.60786269e+01 3.61662989e+01 3.62541536e+01 3.63421918e+01 3.64304141e+01 3.65188212e+01 3.66074137e+01 3.66961921e+01 3.67851571e+01 3.68743092e+01 3.69636490e+01 3.70531771e+01 3.71428940e+01 3.72328002e+01 3.73228961e+01 3.74131824e+01 3.75036595e+01 3.75943279e+01 3.76851879e+01 3.77762402e+01 3.78674850e+01 3.79589228e+01 3.80505540e+01 3.81423791e+01 3.82343983e+01 3.83266120e+01 3.84190207e+01 3.85116246e+01 3.86044240e+01 3.86974193e+01 3.87906108e+01 3.88839987e+01 3.89775834e+01 3.90713651e+01 3.91653441e+01 3.92595206e+01 3.93538948e+01 3.94484669e+01 3.95432372e+01 3.96382058e+01 3.97333730e+01 3.98287388e+01 3.99243035e+01 4.00200672e+01 4.01160301e+01 4.02121922e+01 4.03085536e+01 4.04051146e+01 4.05018751e+01 4.05988352e+01 4.06959950e+01 4.07933546e+01 4.08909140e+01 4.09886733e+01 4.10866325e+01 4.11847915e+01 4.12831504e+01 4.13817092e+01 4.14804679e+01 4.15794264e+01 4.16785848e+01 4.17779429e+01 4.18775007e+01 4.19772582e+01] ==========================================================================================================================
/ext/sage/sage-8.0/local/lib/python2.7/site-packages/matplotlib/font_manager.py:273: UserWarning: Matplotlib is building the font cache using fc-list. This may take a moment. warnings.warn('Matplotlib is building the font cache using fc-list. This may take a moment.')