Skip to content

Commit

Permalink
Merge pull request #73 from DEEPDIP-project/update_ins
Browse files Browse the repository at this point in the history
Made functions compatible with most up-to-date version of INS
  • Loading branch information
v1kko authored Nov 19, 2024
2 parents 69f8e00 + d20d327 commit c2aed45
Show file tree
Hide file tree
Showing 14 changed files with 49 additions and 199 deletions.
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Lux = "b2108857-7c20-44ae-9111-449ecde12c47"
LuxCUDA = "d0bbae9a-e099-4d5b-a835-1c6931763bda"
LuxCore = "bb33d45b-7691-41d6-9220-0943567d0623"
NNlib = "872c559c-99b0-510c-b3b7-b6c96a88d5cd"
#NeuralClosure = "099dac27-d7f2-4047-93d5-0baee36b9c25"
Optimization = "7f7a1694-90dd-40f0-9382-eb1efda571ba"
OptimizationOptimisers = "42dfb2eb-d2b4-4451-abcd-913932933ac1"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
Expand All @@ -48,14 +49,15 @@ Documenter = "1"
FFTW = "1"
GLMakie = "0.10"
Glob = "1"
IncompressibleNavierStokes = "1"
IncompressibleNavierStokes = "^2.0.1"
JLD2 = "0.5"
JuliaFormatter = "1"
Juno = "0.8"
Literate = "2"
Lux = "1"
LuxCUDA = "0.3"
LuxCore = "1"
#NeuralClosure = "^1.0.0"
NNlib = "0.9"
Optimization = "4"
OptimizationOptimisers = "0.3"
Expand Down
Binary file not shown.
13 changes: 6 additions & 7 deletions simulations/NavierStokes_2D/scripts/evaluate_posteriori.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using CoupledNODE: cnn
using CoupledNODE.NavierStokes: create_right_hand_side_with_closure, INS_to_NN
using CoupledNODE.NavierStokes: create_right_hand_side_with_closure
using DifferentialEquations: ODEProblem, solve, Tsit5
using IncompressibleNavierStokes: IncompressibleNavierStokes as INS
using JLD2: load, @load
Expand All @@ -21,8 +21,8 @@ params = load("simulations/NavierStokes_2D/data/params_data.jld2", "params")
D = params.D # dimension
# Build LES setups and assemble operators
setups = map(params.nles) do nles
x = ntuple-> LinRange(T(0.0), T(1.0), nles[α] + 1), params.D)
INS.Setup(x...; params.Re)
x = ntuple-> LinRange(T(0.0), T(1.0), nles + 1), params.D)
INS.Setup(; x = x, Re = params.Re)
end

# Create model
Expand All @@ -45,16 +45,15 @@ dt = params.Δt
tspan = [T(0), T(1)]

u0 = INS.random_field(setups[ig], T(0))
u0_NN = INS_to_NN(u0)
prob = ODEProblem(dudt_nn, u0_NN, tspan, θ_posteriori)
sol = solve(prob, Tsit5(); u0 = u0_NN, p = θ_posteriori, dt = dt, adaptive = false)
prob = ODEProblem(dudt_nn, u0, tspan, θ_posteriori)
sol = solve(prob, Tsit5(); u0 = u0, p = θ_posteriori, dt = dt, adaptive = false)

# Plot the field results
function animation_plots(sol_ode, setup; variable = "vorticity")
anim = Plots.Animation()
for (idx, (t, u)) in enumerate(zip(sol_ode.t, sol_ode.u))
if variable == "vorticity"
ω = INS.vorticity((u[:, :, 1], u[:, :, 2]), setup)
ω = INS.vorticity(u, setup)
title = @sprintf("Vorticity, t = %.3f s", t)
vor_lims = extrema(ω) # can specify manually other limits
fig = Plots.heatmap'; xlabel = "x", ylabel = "y", title, clims = vor_lims,
Expand Down
16 changes: 8 additions & 8 deletions simulations/NavierStokes_2D/scripts/generate_data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,23 @@ Nsim_test = 2
params = (;
D = 2,
Re = T(1e3),
lims = (T(0.0), T(1.0)),
nles = [16, 32],
ndns = 64,
filters = (NC.FaceAverage(),),
tburn = T(5e-2),
tsim = T(0.5),
Δt = T(5e-3),
nles = [(16, 16), (32, 32)],
ndns = (64, 64),
filters = (NC.FaceAverage(),),
create_psolver = INS.psolver_spectral,
savefreq = 1,
Δt = T(5e-3), create_psolver = INS.psolver_spectral,
icfunc = (setup, psolver, rng) -> INS.random_field(
setup, zero(eltype(setup.grid.x[1])); kp = 20, psolver, rng),
rng,
savefreq = 1
rng
)

data_train = [NC.create_les_data(; params...) for _ in 1:Nsim_train];
data_test = [NC.create_les_data(; params...) for _ in 1:Nsim_test];

# save data
#save data
jldsave("simulations/NavierStokes_2D/data/data_train.jld2"; data_train)
jldsave("simulations/NavierStokes_2D/data/data_test.jld2"; data_test)
jldsave("simulations/NavierStokes_2D/data/params_data.jld2"; params)
6 changes: 3 additions & 3 deletions simulations/NavierStokes_2D/scripts/preprocess_posteriori.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ params = load("simulations/NavierStokes_2D/data/params_data.jld2", "params")

# Build LES setups and assemble operators
setups = map(params.nles) do nles
x = ntuple-> LinRange(T(0.0), T(1.0), nles[α] + 1), params.D)
INS.Setup(x...; params.Re)
x = ntuple-> LinRange(T(0.0), T(1.0), nles + 1), params.D)
INS.Setup(; x = x, Re = params.Re)
end

# * A posteriori io_arrays
using CoupledNODE.NavierStokes: create_io_arrays_posteriori
io_post = create_io_arrays_posteriori(data, setups)

ig = 1
# Example of dimensions and how to operate with io_arrays_posteriori
(n, _, dim, samples, nsteps) = size(io_post[ig].u) # (nles, nles, D, samples, tsteps+1)
(samples, nsteps) = size(io_post[ig].t)
Expand Down
4 changes: 2 additions & 2 deletions simulations/NavierStokes_2D/scripts/preprocess_priori.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ params = load("simulations/NavierStokes_2D/data/params_data.jld2", "params")

# Build LES setups and assemble operators
setups = map(params.nles) do nles
x = ntuple-> LinRange(T(0.0), T(1.0), nles[α] + 1), params.D)
INS.Setup(x...; params.Re)
x = ntuple-> LinRange(T(0.0), T(1.0), nles + 1), params.D)
INS.Setup(; x = x, Re = params.Re)
end

# create io_arrays
Expand Down
2 changes: 1 addition & 1 deletion simulations/NavierStokes_2D/scripts/train_posteriori.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ include("preprocess_posteriori.jl")
using ComponentArrays: ComponentArray
using Lux: Lux
u = io_post[ig].u[:, :, :, 1, 1:50]
T = setups[1].T
#T = setups[1].T
d = D = setups[1].grid.dimension()
N = size(u, 1)
emb_size = 8
Expand Down
Loading

0 comments on commit c2aed45

Please sign in to comment.