-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDemo.asv
173 lines (143 loc) · 5.94 KB
/
Demo.asv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
%% Stoner-Wohlfarth Macrospin Particle - Demo Script
% John Domann
% 3-7-2017
clear
clc
%Tell matlab where to find the macrospin model
addpath('Class Definitions')
%% Setup time points
%time arrays
nPtsPerCycle_dynamic = 1e3; %dynamic - number of time points
nPtsPerCycle_static = 2e2; %static - number of time points
freq = 1e9;
ncycles = 2;
time_dynamic = linspace(0,1/(freq)*ncycles,ncycles*nPtsPerCycle_dynamic); %time
time_static = linspace(0,1/(freq)*ncycles,ncycles*nPtsPerCycle_static); %time
delT = min(min(diff(time_dynamic)), 1e-12); %minimum time stepping in LLG ODE Solver
npts_dynamic = numel(time_dynamic);
npts_static = numel(time_static);
%% Driving fields
%Applied magnetic field (A/m)
H0 = 1e6; %amplitude
Hav = 0; %mean
[H1_stat,H2_stat,H3_stat] = MS.Create_Field([H0,0,0],[Hav 0 0],...
{'cos','const','const'},nPtsPerCycle_static,npts_static);
[H1_dyn,H2_dyn,H3_dyn] = MS.Create_Field([H0,0,0],[Hav 0 0],...
{'cos','const','const'},nPtsPerCycle_dynamic,npts_dynamic);
%Appliedd strain (-)
SMax = 0e-6;
[S1_stat,S2_stat,S3_stat,S4_stat,S5_stat,S6_stat] = MS.Create_Field([SMax,0,0,0,0,0],[0,0,0,0,0,0],...
{'cos','const','const','const','const','const'},nPtsPerCycle_static,npts_static);
[S1_dyn,S2_dyn,S3_dyn,S4_dyn,S5_dyn,S6_dyn] = MS.Create_Field([SMax,0,0,0,0,0],[0,0,0,0,0,0],...
{'sin','const','const','const','const','const'},nPtsPerCycle_dynamic,npts_dynamic);
%SOT current (dynamic fields only)
IMax = 0e4;
[sigma1,sigma2,sigma3] = MS.Create_Field([0,IMax,0],[0 0 0],...
{'sin','const','const'},nPtsPerCycle_dynamic,npts_dynamic);
%% Create particle
% s = MSParticle_; %with all default properties
% A 'Property','Value' pair list can be used in MSParticle_ constructor
% prop_list = s.Properties.Property_List;
%Example to construct a rectangular iron particle
n = MSParticle_('Mat_Name','Nickel','Shape','Rectangle','Dims',[5 1 2],'Location',[0 0 0]);
%Values can be updated after creation
n.Properties.Shape='Ellipse'; %you can update shape after creation
n.Properties.Crystal = 'Amorphous'; %and change other properties
n.Properties.Dims = [90 100 10]*1e-9; %or update the dimensions
n.Properties.Alpha = 1e-1;
%Set_State will normalize all inputs to a magnitude of 1, so inputting
%crystal directions like [1 1 1] works just fine
n.Set_State('m1',1,'m2',0.1,'m3',0.1); % initial magnetic orientation
n.Set_State('m2',0.1,'m3',1); % you only need to specify non-zero components
n.Set_State('m',[1 .1 .1]); % or you can specify all components with a vector
%But make sure to update the particle!
n.Update;
%% Update Source Fields
n.Set_Static_Fields(...
'H1',H1_stat,'H2',H2_stat,'H3',H3_stat,...
'S1',S1_stat,'S2',S2_stat,'S3',S3_stat,...
'S4',S4_stat,'S5',S5_stat,'S6',S6_stat);
n.Set_Dynamic_Fields(...
'H1',H1_dyn,'H2',H2_dyn,'H3',H3_dyn,...
'S1',S1_dyn,'S2',S2_dyn,'S3',S3_dyn,...
'S4',S4_dyn,'S5',S5_dyn,'S6',S6_dyn,...
'sigma1',sigma1,'sigma2',sigma2,'sigma3',sigma3,...
't',time_dynamic);
%% Create new particles
%copy to new particle, and change initial magnetization orientation. THe
%source fields applied to 'n' will be copied as well
m=copy(n);
m.Set_State('m1',1,'m3',.1);
m.Properties.Location = [150 0 0]*1e-9;
% m.Properties.Alpha = 1e-1;
m.Update;
%% Create MS Model
particles = {n,m}; %group particles together
nparts = numel(particles); %store number of particles
model = MSModel_(particles); %create a macrospin model with the particles
%update ode options
model.set_ode_options('MaxStep',delT,'InitialStep',delT*1e-3'); %solvers: 'ode45','ode23','ode113','ode15s'
model.r_cutoff = inf; %dipole coupling radius: 0 = no dipole coupling, inf = couples all particles
%% Check Initial State
%model.Plots.Plot_Initial_State([Particle Numbers]);
% model.Plots.Plot_Initial_State([1]); %shows only particle 1
% model.Plots.Plot_Initial_State([2]); %shows only particle 2
model.Plots.Plot_Initial_State([1:nparts]); %show all particles
%% Static MH Loops
%Run MH loops
model.set_static_solver_options('TolX',1e-6,'TolFun',1e-6);
% model.set_static_solver_type('segregated'); %STILL NEEDS WORK
model.set_static_solver_type('coupled');
model.RUN_static;
%% Visualize the static results
% For possible values, see:
% model.Plots.Source_field_names
% model.Plots.State_names
model.Plots.fig_num = 2;
model.Plots.Particle_Plot(...
1,'static.H1','Stat_m1',...
1,'static.H1','Stat_m2',...
1,'static.H1','Stat_m3',...
2,'static.H1','Stat_m1',...
2,'static.H1','Stat_m2',...
2,'static.H1','Stat_m3');
h1 = model.Plots.plot_handle; %get model handles (figure, axis, lines, and legend)
h1.ax(1).LineWidth = 1.5; %so you can refine how the plot looks
h1.ax(1).FontSize = 12;
h1.ax(1).FontWeight = 'bold';
for i = 1:numel(h1.lines); h1.lines(i).LineWidth = 2; end
%% Animate Static
model.Plots.fig_num = 3;
model.Plots.Animate_Spins([1:nparts],{'static'})
%% Dynamic MH Loops
model.set_ode_options('solver','ode15s');
model.r_cutoff = inf; %dipole couple all particles
model.RUN_LLG;
%Sample times:
%ode45: 55sec
%ode23: 33sec
%ode113: 23sec
%ode15s: 15sec ---- RECOMENDED SOLVER
%% Visualize the dynamic results
% For possible values, see:
% model.Plots.Source_field_names
% model.Plots.State_names
model.Plots.fig_num = 4;
model.Plots.Particle_Plot(...
1,'dynamic.t','Dyn_m1',...%
1,'dynamic.t','Dyn_m2',...
1,'dynamic.t','Dyn_m3',...
2,'dynamic.t','Dyn_m1',...%
2,'dynamic.t','Dyn_m2',...
2,'dynamic.t','Dyn_m3');
h2 = model.Plots.plot_handle;
for i = 1:numel(h2.lines); h2.lines(i).LineWidth = 2; end
%% Animate Dynamic
model.Plots.fig_num = 5;
model.Plots.Animate_Spins([1:nparts],{'dynamic'})
%% Save movies
model.Plots.fig_num = 2;
model.Plots.make_movie([1:nparts],{'static'},'Movies\demo-movie-static')
model.Plots.fig_num = 4;
model.Plots.make_movie([1:nparts],{'dynamic'},'Movies\demo-movie-dynamic')
disp('end')