-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmoments.jl
136 lines (132 loc) · 4.99 KB
/
moments.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
@testset "Moments" begin
f = zeros(5,5,9)
f1D = zeros(30,3)
height = zeros(5,5)
hei = zeros(30)
velx = zeros(5,5)
vely = zeros(5,5)
vel = zeros(30)
state = Swalbe.Sys(Swalbe.SysConst(Lx=5, Ly=5, param=Swalbe.Taumucs()), "CPU")
state1D = Swalbe.Sys(Swalbe.SysConst_1D(L=30, param=Swalbe.Taumucs()))
state2 = Swalbe.Sys(Swalbe.SysConst(Lx=5, Ly=5, param=Swalbe.Taumucs()), "CPU", kind="thermal")
state1D2 = Swalbe.Sys(Swalbe.SysConst_1D(L=30, param=Swalbe.Taumucs()), kind="thermal")
@testset "No velocity" begin
for i in [state.height, state2.basestate.height, state1D.height, state1D2.basestate.height]
i .= 0.0
end
for i in [f, state.fout, state2.basestate.fout]
i[:,:,1] .= 1.0
end
for i in [f1D, state1D.fout, state1D2.basestate.fout]
i[:,1] .= 1.0
end
Swalbe.moments!(height, velx, vely, f)
Swalbe.moments!(hei, vel, f1D)
Swalbe.moments!(state)
Swalbe.moments!(state2)
Swalbe.moments!(state1D)
Swalbe.moments!(state1D2)
for i in enumerate([height, state.height, state2.basestate.height, state1D.height, state1D2.basestate.height])
@test all(i[2] .== 1.0)
end
end
@testset "Velocity" begin
for i in [state.height, state2.basestate.height, state1D.height, state1D2.basestate.height]
i .= 0.0
end
for i in [f, state.fout, state2.basestate.fout]
i[:,:,2] .= 0.1
end
for i in [f1D, state1D.fout, state1D2.basestate.fout]
i[:,2] .= 0.1
end
Swalbe.moments!(height, velx, vely, f)
Swalbe.moments!(hei, vel, f1D)
Swalbe.moments!(state)
Swalbe.moments!(state2)
Swalbe.moments!(state1D)
Swalbe.moments!(state1D2)
@test all(height .== 1.1)
@test all(hei .== 1.1)
@test all(velx .== 0.1/1.1)
@test all(vely .== 0)
@test all(vel .== 0.1/1.1)
for i in [state, state2.basestate]
@test all(i.height .== 1.1)
@test all(i.velx .== 0.1/1.1)
@test all(i.vely .== 0.0)
end
for i in [state1D, state1D2.basestate]
@test all(i.height .== 1.1)
@test all(i.vel .== 0.1/1.1)
end
# with f3
for i in [state.height, state2.basestate.height, state1D.height, state1D2.basestate.height]
i .= 0.0
end
for i in [f, state.fout, state2.basestate.fout]
i[:,:,3] .= 0.2
end
for i in [f1D, state1D.fout, state1D2.basestate.fout]
i[:,3] .= 0.2
end
Swalbe.moments!(height, velx, vely, f)
Swalbe.moments!(hei, vel, f1D)
Swalbe.moments!(state)
Swalbe.moments!(state2)
Swalbe.moments!(state1D)
Swalbe.moments!(state1D2)
for i in [state, state2.basestate]
@test all(i.height .== 1.3)
@test all(i.velx .== 0.1/1.3)
@test all(i.vely .== 0.2/1.3)
end
for i in [state1D, state1D2.basestate]
@test all(isapprox.(i.height, 1.3, atol=1e-10))
@test all(isapprox.(i.vel, -0.1/1.3, atol=1e-10))
end
# 2D
for i in [state.height, state2.basestate.height, state1D.height, state1D2.basestate.height]
i .= 0.0
end
for i in [f, state.fout, state2.basestate.fout]
i[:,:,4] .= -0.2
end
Swalbe.moments!(height, velx, vely, f)
Swalbe.moments!(state)
Swalbe.moments!(state2)
for i in [state, state2.basestate]
@test all(i.height .== 1.1)
@test all(isapprox.(i.velx, 0.3/1.1, atol=1e-10))
@test all(isapprox.(i.vely, 0.2/1.1, atol=1e-10))
end
for i in [state.height, state2.basestate.height, state1D.height, state1D2.basestate.height]
i .= 0.0
end
for i in [f, state.fout, state2.basestate.fout]
i[:,:,5] .= -0.1
end
Swalbe.moments!(height, velx, vely, f)
Swalbe.moments!(state)
Swalbe.moments!(state2)
for i in [state, state2.basestate]
@test all(i.height .== 1.0)
@test all(isapprox.(i.velx, 0.3/1.0, atol=1e-10))
@test all(isapprox.(i.vely, 0.3/1.0, atol=1e-10))
end
for i in [state.height, state2.basestate.height, state1D.height, state1D2.basestate.height]
i .= 0.0
end
for i in [f, state.fout, state2.basestate.fout]
i[:,:,6] .= 0.1
end
Swalbe.moments!(height, velx, vely, f)
Swalbe.moments!(state)
Swalbe.moments!(state2)
for i in [state, state2.basestate]
@test all(i.height .== 1.1)
@test all(isapprox.(i.velx, 0.4/1.1, atol=1e-10))
@test all(isapprox.(i.vely, 0.4/1.1, atol=1e-10))
end
end
end