-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathexample_3D_test.jl
51 lines (40 loc) · 1.7 KB
/
example_3D_test.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
using PlanktonIndividuals
grid = RectilinearGrid(size = (16, 16, 16), x = (0,32), y = (0,32), z = (0,-32))
model = PlanktonModel(CPU(), grid; mode = CarbonMode())
function tot_mass(nut, g)
mass = zeros(g.Nx, g.Ny, g.Nz)
for i in 1:g.Nx
for j in 1:g.Ny
for k in 1:g.Nz
mass[i,j,k] = nut[i+g.Hx, j+g.Hy, k+g.Hz] * PlanktonIndividuals.Grids.volume(i+g.Hx, j+g.Hy, k+g.Hz, g)
end
end
end
return sum(mass)
end
TC = tot_mass(model.nutrients.DIC.data, grid) +
tot_mass(model.nutrients.DOC.data, grid) +
tot_mass(model.nutrients.POC.data, grid)
TC = TC + sum(model.individuals.phytos.sp1.data.Bm)
uvel = zeros(16,16,16,11)
vvel = zeros(16,16,16,11)
wvel = zeros(16,16,17,11)
for i in 1:11
uvel[:,:,:,i] .= randn(16,16,16) .* 1e-4
vvel[:,:,:,i] .= randn(16,16,16) .* 1e-4
wvel[:,:,:,i] .= randn(16,16,17) .* 1e-4
end
# add boundary conditions for DOC
model.nutrients.DON.bc.west = 1.0e-3 # west boundary condition of 0.1 mmol/m^2/second
model.nutrients.DON.bc.east = randn(16,16) .* 1e-3 # east boundary condition of -0.1 mmol/m^2/second
model.nutrients.DON.bc.south = randn(16,16,10) .* 1e-3 # south boundary condition of 0.1 mmol/m^2/second
model.nutrients.DON.bc.north = randn(16,16,10) .* 1e-3 # north boundary condition of -0.1 mmol/m^2/second
sim = PlanktonSimulation(model, ΔT = 60.0, iterations = 10, vels=(u=uvel, v=vvel, w=wvel))
update!(sim)
TCt = tot_mass(model.nutrients.DIC.data, grid) +
tot_mass(model.nutrients.DOC.data, grid) +
tot_mass(model.nutrients.POC.data, grid)
TCt = TCt + sum(model.individuals.phytos.sp1.data.Bm)
@testset "PlanktonIndividuals 3D tests:" begin
@test isapprox(TC,TCt; atol=1e3)
end