-
Notifications
You must be signed in to change notification settings - Fork 3
/
FastField.jl
170 lines (132 loc) · 3.87 KB
/
FastField.jl
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
using JLD
using SurfaceGeometry
using Distributed
@everywhere include("field.jl")
include("velocity.jl")
#bname = "/SlowFieldEiler/"
function DropEnergy(points,faces,normals,psix,psiy,H0)
vareas = zero(points)
for i in 1:size(faces,2)
v1,v2,v3 = faces[:,i]
area = norm(cross(points[:,v2]-points[:,v1],points[:,v3]-points[:,v1])) /2
vareas[v1] += area/3
vareas[v2] += area/3
vareas[v3] += area/3
end
Area = sum(vareas)
# psix = PotentialSimple(points,faces,mup,H0*[1,0,0],regularize=true)
# psiy = PotentialSimple(points,faces,mup,H0*[0,1,0],regularize=true)
s = 0
for xkey in 1:size(points,2)
s += dot(H0/2*[psix[xkey],psiy[xkey],0],normals[:,xkey]) * vareas[xkey]
end
Es = gammap * Area
Em = 1/8/pi * (1 - mup) * s
### Here I could also do the normalisation of it
return Es+Em
end
# if !isdir(datadir*bname)
# mkdir(datadir*bname)
# end
memory = []
if con==true
info("Continuing from last simulation")
if !isdir(outdir) || isempty(outdir)
error("No previous simulation found")
end
# 107;Bm=25.jld ### when viewing find a point or semicolon
outfiles = readdir(outdir)
import Base.isless
function Base.isless(x::ASCIIString,y::ASCIIString)
nx = parse(Int,x[1:length(x)-4])
ny = parse(Int,y[1:length(y)-4])
return nx < ny
end
sort!(outfiles)
last = outfiles[end]
i = parse(Int,last[1:length(last)-4])
data = load("$outdir/$last")["memory"][end]
ti,points,faces = data[1],data[2],data[3]
else
@info "Starting fresh simulation"
run(`rm -rf $outdir`)
mkdir(outdir)
ti = 0
i = 1
end
volume0 = volume(points,faces)
sc = 0.01*(3*volume0/4/pi)^(1/3) ### charectaristic scale
@info "Proceding with simulation at Bm=$Bm"
H0 = sqrt(Bm*gammap/(volume(points,faces)*3/4/pi)^(1/3))
memory = []
vn = zero(points)
tp = 0
ip = i
vi = 0
xi = 0
taui = 0
Ei = Inf
FluctatingEnergy = false
Equilibrium = false
# WTF issue
points2 = copy(points)
faces2 = copy(faces)
while true
@info "Starting with step $i"
points = points2
faces = faces2
Ep = Ei
xp = xi
vp = vi
taup = taui
pointsp = copy(points)
normals = Array{Float64}(undef,size(points)...);
NormalVectors!(normals,points,faces,i->FaceVRing(i,faces))
fieldx = @spawn surfacefield(points,faces,normals,mup,H0*[1,0,0])
fieldy = @spawn surfacefield(points,faces,normals,mup,H0*[0,1,0])
psix,Htx,Hnx = fetch(fieldx)
psiy,Hty,Hny = fetch(fieldy)
tensorn = mup*(mup-1)/8/pi/2 * (Hnx.^2 + Hny.^2) + (mup-1)/8/pi/2 * (Htx.^2 + Hty.^2)
global vn = InterfaceSpeedZinchenko(points,faces,tensorn,etap,gammap)
### Calculating variables for this step
#pDx = xp - xi
global Ei = DropEnergy(points,faces,normals,psix,psiy,H0)
rV = volume(points,faces)/volume0
global vi = maximum(abs.(vn))
global xi = vi*(ti-tp)
global taui = h/log(vp/vi)
if i==ip
global v0max = vi
end
println("E = $Ei")
println("$(h/log(vp/vi)*vi) < $(sc)")
println("vi/v0max = $(vi/v0max)")
push!(memory,(ti,copy(points),copy(faces),Ei,taui))
if mod(i,5)==0
save("$outdir/$i.jld","memory",memory)
global memory = []
end
### This is more cosmetic one
if rV==NaN || abs(rV - 1)>0.5
# break
end
if (i-ip)>1000
# break
end
if ti!=tp && h/log(vp/vi)*vi < sc && vi/v0max<0.01 # 1000
global Equilibrium = true
# break
end
for j in 1:size(points,2)
points[:,j] += normals[:,j]*vn[j]*h
end
global ti += h
global i += 1
# ElTopo magic.
actualdt,points,faces = improvemeshcol(pointsp,faces,points,par)
#points,faces = improvemesh(points,faces,par)
end
save("$outdir/$i.jld","memory",memory)
if Equilibrium==false
@info "Simulation did not achieve equilibrium"
end