Skip to content

Commit ee36833

Browse files
author
Milan K
authored
Merge pull request #132 from milankl/whatsnext
Whatsnext
2 parents 718e62e + f2141ac commit ee36833

File tree

7 files changed

+183
-25
lines changed

7 files changed

+183
-25
lines changed

Manifest.toml

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
# This file is machine-generated - editing it directly is not advised
22

3+
[[AxisAlgorithms]]
4+
deps = ["LinearAlgebra", "Random", "SparseArrays", "WoodburyMatrices"]
5+
git-tree-sha1 = "a4d07a1c313392a77042855df46c5f534076fab9"
6+
uuid = "13072b0f-2c55-5437-9ae7-d433b7a33950"
7+
version = "1.0.0"
8+
39
[[Base64]]
410
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
511

612
[[BinDeps]]
7-
deps = ["Compat", "Libdl", "SHA", "URIParser"]
8-
git-tree-sha1 = "12093ca6cdd0ee547c39b1870e0c9c3f154d9ca9"
13+
deps = ["Libdl", "Pkg", "SHA", "URIParser", "Unicode"]
14+
git-tree-sha1 = "66158ad56b4bf6cc8413b37d0b7bc52402682764"
915
uuid = "9e28174c-4ba2-5203-b857-d8d62c4213ee"
10-
version = "0.8.10"
16+
version = "1.0.0"
1117

1218
[[Compat]]
1319
deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"]
@@ -17,15 +23,15 @@ version = "2.2.0"
1723

1824
[[Conda]]
1925
deps = ["JSON", "VersionParsing"]
20-
git-tree-sha1 = "9a11d428dcdc425072af4aea19ab1e8c3e01c032"
26+
git-tree-sha1 = "7a58bb32ce5d85f8bf7559aa7c2842f9aecf52fc"
2127
uuid = "8f4d0f93-b110-5947-807f-2305c1781a2d"
22-
version = "1.3.0"
28+
version = "1.4.1"
2329

2430
[[CondaBinDeps]]
25-
deps = ["BinDeps", "Compat", "Conda", "Libdl"]
26-
git-tree-sha1 = "3b868935adf4ce2115f5487e789553507739014c"
31+
deps = ["BinDeps", "Conda"]
32+
git-tree-sha1 = "25f750df2893991f2c9b18425bfac6f2ce855154"
2733
uuid = "a9693cdc-2bc8-5703-a9cd-1da358117377"
28-
version = "0.1.0"
34+
version = "0.2.0"
2935

3036
[[Dates]]
3137
deps = ["Printf"]
@@ -49,6 +55,12 @@ version = "0.4.1"
4955
deps = ["Markdown"]
5056
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
5157

58+
[[Interpolations]]
59+
deps = ["AxisAlgorithms", "LinearAlgebra", "OffsetArrays", "Random", "Ratios", "SharedArrays", "SparseArrays", "StaticArrays", "WoodburyMatrices"]
60+
git-tree-sha1 = "c7579b2617b513d8e6eb9f4b91837eefe7080af8"
61+
uuid = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"
62+
version = "0.12.8"
63+
5264
[[JSON]]
5365
deps = ["Dates", "Mmap", "Parsers", "Unicode"]
5466
git-tree-sha1 = "b34d7cef7b337321e97d22242c3c2b91f476748e"
@@ -81,6 +93,11 @@ git-tree-sha1 = "fce0c7962fb14b8cf2f33ea77885f3b7c7e1485e"
8193
uuid = "30363a11-5582-574a-97bb-aa9a979735b9"
8294
version = "0.8.0"
8395

96+
[[OffsetArrays]]
97+
git-tree-sha1 = "707e34562700b81e8aa13548eb6b23b18112e49b"
98+
uuid = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
99+
version = "1.0.2"
100+
84101
[[OrderedCollections]]
85102
deps = ["Random", "Serialization", "Test"]
86103
git-tree-sha1 = "c4c13474d23c60d20a67b217f1d7f22a40edf8f1"
@@ -95,12 +112,12 @@ version = "0.12.0"
95112

96113
[[Parsers]]
97114
deps = ["Dates", "Test"]
98-
git-tree-sha1 = "ef0af6c8601db18c282d092ccbd2f01f3f0cd70b"
115+
git-tree-sha1 = "d112c19ccca00924d5d3a38b11ae2b4b268dda39"
99116
uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0"
100-
version = "0.3.7"
117+
version = "0.3.11"
101118

102119
[[Pkg]]
103-
deps = ["Dates", "LibGit2", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"]
120+
deps = ["Dates", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "Test", "UUIDs"]
104121
uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
105122

106123
[[Printf]]
@@ -115,6 +132,12 @@ uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
115132
deps = ["Serialization"]
116133
uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
117134

135+
[[Ratios]]
136+
deps = ["Compat"]
137+
git-tree-sha1 = "cdbbe0f350581296f3a2e3e7a91b214121934407"
138+
uuid = "c84ed2f1-dad5-54f0-aa8e-dbefe2724439"
139+
version = "0.3.1"
140+
118141
[[SHA]]
119142
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"
120143

@@ -132,6 +155,12 @@ uuid = "6462fe0b-24de-5631-8697-dd941f90decc"
132155
deps = ["LinearAlgebra", "Random"]
133156
uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
134157

158+
[[StaticArrays]]
159+
deps = ["LinearAlgebra", "Random", "Statistics"]
160+
git-tree-sha1 = "5a3bcb6233adabde68ebc97be66e95dcb787424c"
161+
uuid = "90137ffa-7385-5640-81b9-e52037218182"
162+
version = "0.12.1"
163+
135164
[[Statistics]]
136165
deps = ["LinearAlgebra", "SparseArrays"]
137166
uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
@@ -154,7 +183,12 @@ uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
154183
uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"
155184

156185
[[VersionParsing]]
157-
deps = ["Compat"]
158-
git-tree-sha1 = "c9d5aa108588b978bd859554660c8a5c4f2f7669"
186+
git-tree-sha1 = "80229be1f670524750d905f8fc8148e5a8c4537f"
159187
uuid = "81def892-9a0e-5fdd-b105-ffc91e053289"
160-
version = "1.1.3"
188+
version = "1.2.0"
189+
190+
[[WoodburyMatrices]]
191+
deps = ["LinearAlgebra", "SparseArrays"]
192+
git-tree-sha1 = "bbb9f7fd6fbdd9582e77c0b698312c543de5eb71"
193+
uuid = "efce3f68-66dc-5838-9240-27a6d6f5f9b6"
194+
version = "0.5.0"

Project.toml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@ uuid = "56019723-2d87-4a65-81ff-59d5d8913e3c"
33
authors = ["Milan Kloewer"]
44
version = "0.1.0"
55

6-
[compat]
7-
julia = "1"
8-
Parameters = "^0.12"
9-
NetCDF = "^0.8"
10-
116
[deps]
127
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
8+
Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"
139
NetCDF = "30363a11-5582-574a-97bb-aa9a979735b9"
1410
Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a"
1511
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
1612

13+
[compat]
14+
NetCDF = "^0.8"
15+
Parameters = "^0.12"
16+
julia = "1"
17+
1718
[extras]
1819
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1920

src/DefaultParameters.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
init_starti::Int=-1 # timestep to start from (-1 meaning last)
103103
get_id_mode::String="continue" # How to determine the run id: "continue" or "fill"
104104
run_id::Int=-1 # Output with a specific run id
105+
init_interpolation::Bool=true # Interpolate the initial conditions in case grids don't match?
105106

106107
# ASSERT - CHECK THAT THE INPUT PARAMETERS MAKE SENSE
107108
@assert all((nx,Lx,L_ratio) .> 0.) "nx, Lx, L_ratio have to be >0"

src/Gradients.jl

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,36 @@ function ∇²!(du::Array{T,2},u::Array{T,2}) where {T<:AbstractFloat}
3939
end
4040
end
4141
end
42+
43+
function ∂x(u::Array{T,2},Δx::Real) where {T<:AbstractFloat}
44+
45+
m,n = size(u)
46+
47+
dudx = Array{T,2}(undef,m-1,n)
48+
one_over_dx = T(1.0/Δx)
49+
50+
51+
@inbounds for j 1:n
52+
for i 1:m-1
53+
dudx[i,j] = one_over_dx*(u[i+1,j] - u[i,j])
54+
end
55+
end
56+
57+
return dudx
58+
end
59+
60+
function ∂y(u::Array{T,2},Δy::Real) where {T<:AbstractFloat}
61+
62+
m,n = size(u)
63+
64+
dudy = Array{T,2}(undef,m,n-1)
65+
one_over_dy = T(1.0/Δy)
66+
67+
@inbounds for j 1:n-1
68+
for i 1:m
69+
dudy[i,j] = one_over_dy*(u[i,j+1] - u[i,j])
70+
end
71+
end
72+
73+
return dudy
74+
end

src/InitialConditions.jl

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ function initial_conditions(::Type{T},S::ModelSetup) where {T<:AbstractFloat}
3939
elseif initial_cond == "ncfile"
4040

4141
@unpack initpath,init_run_id,init_starti = S.parameters
42+
@unpack init_interpolation = S.parameters
43+
@unpack nx,ny = S.grid
4244

4345
inirunpath = joinpath(initpath,"run"*@sprintf("%04d",init_run_id))
4446

@@ -62,11 +64,61 @@ function initial_conditions(::Type{T},S::ModelSetup) where {T<:AbstractFloat}
6264
NetCDF.close(ncη)
6365

6466
# remove singleton time dimension
65-
# and convert from Float32 to type T
66-
u = T.(reshape(u,size(u)[1:2]))
67-
v = T.(reshape(v,size(v)[1:2]))
68-
η = T.(reshape(η,size(η)[1:2]))
67+
u = reshape(u,size(u)[1:2])
68+
v = reshape(v,size(v)[1:2])
69+
η = reshape(η,size(η)[1:2])
6970

71+
# Interpolation in case the grids don't match?
72+
73+
nx_old,ny_old = size(η)
74+
75+
if (nx_old,ny_old) != (nx,ny)
76+
if init_interpolation
77+
78+
# old grids
79+
x_T = collect(0.5:nx_old-0.5)
80+
y_T = collect(0.5:ny_old-0.5)
81+
82+
# assuming periodic BC for now #TODO make flexible
83+
x_u = collect(0:nx_old-1)
84+
y_u = y_T
85+
86+
x_v = x_T
87+
y_v = collect(1:ny_old-1)
88+
89+
# set up interpolation functions
90+
u_itp = interpolate((x_u,y_u),u,Gridded(Linear()))
91+
v_itp = interpolate((x_v,y_v),v,Gridded(Linear()))
92+
η_itp = interpolate((x_T,y_T),η,Gridded(Linear()))
93+
94+
#TODO in case of interpolation on larger grids
95+
#TODO make BC adapting to actual BCs used.
96+
u_etp = extrapolate(u_itp,(Flat(),Flat()))
97+
v_etp = extrapolate(v_itp,(Flat(),Flat()))
98+
η_etp = extrapolate(η_itp,(Flat(),Flat()))
99+
100+
# new grids
101+
Δx = nx_old/nx
102+
Δy = ny_old/ny
103+
104+
x_T_new = collect(Δx/2:Δx:nx_old-Δx/2)
105+
y_T_new = collect(Δy/2:Δy:ny_old-Δy/2)
106+
107+
x_u_new = collect(0:Δx:nx_old-Δx)
108+
y_u_new = y_T_new
109+
110+
x_v_new = x_T_new
111+
y_v_new = collect(Δy:Δy:ny_old-Δy)
112+
113+
# retrieve values and overwrite existing arrays
114+
u = u_etp(x_u_new,y_u_new)
115+
v = v_etp(x_v_new,y_v_new)
116+
η = η_etp(x_T_new,y_T_new)
117+
118+
else
119+
throw(error("Grid size $((nx,ny)) doesn't match initial conditions on a $(size(η)) grid."))
120+
end
121+
end
70122
end
71123

72124
## SST
@@ -102,6 +154,11 @@ function initial_conditions(::Type{T},S::ModelSetup) where {T<:AbstractFloat}
102154

103155
# Convert to number format T
104156
sst = T.(sst)
157+
u = T.(u)
158+
v = T.(v)
159+
η = T.(η)
160+
161+
#TODO SST INTERPOLATION
105162

106163
u,v,η,sst = add_halo(u,v,η,sst,S)
107164

src/Interpolations.jl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,35 @@ function Ixy!(uxy::Array{T,2},u::Array{T,2}) where {T<:AbstractFloat}
4242
end
4343
end
4444
end
45+
46+
function Ix(u::Array{T,2}) where {T<:AbstractFloat}
47+
48+
m,n = size(u)
49+
ux = Array{T,2}(undef,m-1,n)
50+
51+
one_half = T(0.5)
52+
53+
@inbounds for j 1:n
54+
for i 1:m-1
55+
ux[i,j] = one_half*(u[i+1,j] + u[i,j])
56+
end
57+
end
58+
59+
return ux
60+
end
61+
62+
function Iy(u::Array{T,2}) where {T<:AbstractFloat}
63+
64+
m,n = size(u)
65+
uy = Array{T,2}(undef,m,n-1)
66+
67+
one_half = T(0.5)
68+
69+
@inbounds for j 1:n-1
70+
for i 1:m
71+
uy[i,j] = one_half*(u[i,j+1] + u[i,j])
72+
end
73+
end
74+
75+
return uy
76+
end

src/ShallowWaters.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module ShallowWaters
22

3-
export RunModel, Parameter
3+
export RunModel, Parameter, ∂x, ∂y, Ix, Iy
44

5-
using NetCDF, Parameters, Printf, Dates
5+
using NetCDF, Parameters, Printf, Dates, Interpolations
66

77
include("DefaultParameters.jl")
88
include("Grid.jl")

0 commit comments

Comments
 (0)