forked from basselqd/FCC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DenseSphere.lua
96 lines (71 loc) · 2.46 KB
/
DenseSphere.lua
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
-- This script set the micro system (nanoparticle) with sLLG
-- This script runs only once.
rank=mpi.get_rank()
rngsd=rank+1000000 -- seed for random number generator
dofile("maglua://RungeKutta.lua")
dofile("maglua://MakeMacro.lua")
dofile("SetupSphericalParticle.lua") -- load setup function
rng = Random.Isaac.new()
rng:setSeed(rngsd)
-- setup system, objects, etc
nos,ss, ex, ani, regions, sinfo = makeSphericalParticle(L, ST, rng)
th = Thermal.new(ss, rng)
af = AppliedField.new(ss)
llg = LLG.Quaternion.new(ss)
llg:setThermalOnlyFirstTerm(false)
odt = ss:timeStep() --original timestep
-- mapping here is to increase the efficiency of sLLG
mapping = {}
for k=1,ss:nz() do
for j=1,ss:ny() do
for i=1,ss:nx() do
local ed = ss:extraData(i,j,k)
if ed then --if the site exists
table.insert(mapping, {{i,j,k}}) -- mapping for all
end
end
end
end
-- combine, make new data/operators as per mapping
invmap, ss, ex, ani, af = MakeMacro(mapping, ss, ex, ani, af)
ftime=io.open("time.dat","a")
function calculateDeterministicField(spinsystem)
spinsystem:resetFields()
ani:apply(spinsystem)
ex:apply(spinsystem)
af:apply(spinsystem)
spinsystem:sumFields()
end
function dynamics(spinsystem)
local t = spinsystem:time()
th:set(T)
end
-- sLLG step
step = make_rk_step_function(ss, "RK4", calculateDeterministicField, dynamics, llg, th)
function DplFld() --calculate and set the dipole field
if (math.abs(math.fmod (drun,dnumber)) < 1 ) then --update the dipole field each dnumber (100) steps
applyFld()
end
drun=drun+1 -- counter for updating the dipole field
end
function run(dt, r) --equilibration for dt time units (tu) and save info each r tu
tTill=ss:time()+dt
next_func_call=ss:time()+r
drun=0
sst = ss:time()
local t=sst
while ss:time() < tTill do -- equilibrate till tTill
DplFld()
step(ss)
if ss:time() > next_func_call then -- each r time unites do ...
rayt() -- write individual nanoparticle info
next_func_call = ss:time() + r
drun=0 -- update dipole field for the next sLLG step (this is just for consistency in case of loading files later on)
-- save point
checkpointSave("SSS"..T.."."..rank..".dat",invmap, ss, ex, ani, af, mappingd, tTill, next_func_call, ss:time(), drun, T,rngsd)
end
end
drun=0
-- save the nanoparticle info and state to a file
checkpointSave("SSS"..T..".f."..rank..".dat",invmap, ss, ex, ani, af, mappingd, tTill, next_func_call, ss:time(), drun, T,rngsd)
end