Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
116 commits
Select commit Hold shift + click to select a range
96a321c
Fix CompatHelper with copy from libtrixi
benegee Jul 18, 2024
8b4b4e0
try full write
benegee Jul 18, 2024
6a41dc7
structural setup, work in progress
FnHck Jul 24, 2024
b3518a0
structural setup, work in progress
FnHck Jul 24, 2024
ec087c6
ignore VS Code files
FnHck Jul 24, 2024
bc9bb5b
updating equations
FnHck Jul 24, 2024
dc4b166
back to default
FnHck Jul 30, 2024
661b079
export of rainy equations
FnHck Jul 30, 2024
c23a160
basic structural equation setup
FnHck Jul 30, 2024
06a73dd
basic elixir setup for 2D testcases
FnHck Jul 30, 2024
118b06d
rename and partial implementation of initial condition
FnHck Aug 2, 2024
2b3666a
varname changes, cons2prim and physics variables
FnHck Aug 2, 2024
1d1f20b
added source terms without phase change, added flux, fixed some mista…
FnHck Aug 6, 2024
7d1e66c
added max abs speed calculations
FnHck Aug 7, 2024
76653b1
most simple test case I could find
FnHck Aug 12, 2024
03e0f12
added NLsolve
FnHck Aug 12, 2024
e3a9288
renamed initial condition function
FnHck Aug 12, 2024
5d45cad
fixed and updated some source terms, boundary experiment
FnHck Aug 12, 2024
16532c7
updated source terms and initial condition energy
FnHck Aug 14, 2024
6f6d448
fixes, source term updates
FnHck Aug 14, 2024
3afb265
fixed energy density and adjusted source terms
FnHck Aug 21, 2024
ae7391b
moved nonlinear system, removed source_terms_dry, fixed energy flux, …
FnHck Aug 21, 2024
050250d
experiments and small fixes
FnHck Aug 22, 2024
53ea8e7
testing
FnHck Aug 23, 2024
a5fd8c3
testing
FnHck Aug 23, 2024
00a13f6
code cleanup
FnHck Aug 23, 2024
8aae032
rename, testing and dimension reduction of u
FnHck Aug 25, 2024
6e55868
fixed temperature for dry testcase, cleanup, got rid of unused 'varia…
FnHck Aug 25, 2024
8d6b7ae
added elixir for dry convergence test
FnHck Aug 29, 2024
5680793
formatting changes
FnHck Aug 29, 2024
7b9ba25
fixed max_abs_speed_naive, formatting changes and temporary tests
FnHck Aug 29, 2024
7c100bf
added Lucas' compressible moist Euler equations
FnHck Sep 2, 2024
98025e1
moist bubble testing
FnHck Sep 2, 2024
474bfef
added for future implementation
FnHck Sep 4, 2024
15dbccd
moist bubble testing
FnHck Sep 4, 2024
b016330
moist bubble testing
FnHck Sep 5, 2024
056d66d
formatting and parameter adjustments/tests
FnHck Sep 13, 2024
a6299ab
moved the nonlinear system to callback_stage for performance
FnHck Sep 13, 2024
39b8450
name change of callback to NonlineaarSolveDG
FnHck Sep 15, 2024
21c52a0
moist bubble experiments
FnHck Sep 15, 2024
e1befab
testing
FnHck Sep 18, 2024
d1ca8d7
added Trixi timer, added threading, formatting changes
FnHck Sep 18, 2024
d230a90
added Lucas' equations to directly compare
FnHck Sep 23, 2024
5895f74
added Jacobian of the nonlinear system to increase performance
FnHck Sep 23, 2024
1238175
moved comparison elixirs to a separate folder
FnHck Sep 26, 2024
cbf60c6
tested a different energy definition, commented / reverted changes
FnHck Sep 26, 2024
2a0db9e
testing performance and accuracy
FnHck Sep 26, 2024
5aa7c61
rename, relocating of convergence tests and implementation of moist c…
FnHck Sep 28, 2024
738d5c4
testing of initial condition and parameters
FnHck Sep 28, 2024
28e9e7d
comment changes
FnHck Sep 28, 2024
4340e9a
rename
FnHck Oct 1, 2024
671f488
custom newton method for much better performance
FnHck Oct 1, 2024
92f3e49
testing
FnHck Oct 8, 2024
2bc4710
added visualization function and modified nonlinear system setup stru…
FnHck Oct 8, 2024
e3a7c61
fixes and updates
FnHck Oct 15, 2024
098f868
fixes and updates
FnHck Oct 15, 2024
c7897c7
added flux LMARS and volume flux chandrashekar
FnHck Oct 19, 2024
e59eabe
work in progress convergence test rain
FnHck Oct 19, 2024
85ad006
formatting, fixes and testing
FnHck Oct 26, 2024
4478fd8
adjusted parameters for good results
FnHck Oct 26, 2024
1cc155e
testing and results
FnHck Oct 26, 2024
3f648ed
added rainy bubble initial condition
FnHck Oct 26, 2024
1855c18
comments and testing
FnHck Oct 27, 2024
6c946fb
rain testing
FnHck Nov 5, 2024
b12b377
added rain bubble adaptive mesh refinement (does not work yet)
FnHck Nov 5, 2024
e67151f
adaptive mesh refinement testing
FnHck Nov 6, 2024
026d767
rain testing
FnHck Nov 17, 2024
0f0fcf8
added a template (copy of rainy euler) for possible implementation wi…
FnHck Nov 17, 2024
773d8cb
added rainy bubble with diffusion
FnHck Nov 19, 2024
d03bf47
added boundary condition for laplace diffusion
FnHck Nov 19, 2024
0194734
added DGMulti example (work in progress)
FnHck Nov 19, 2024
a76e26f
diffusion adjustments
FnHck Nov 20, 2024
dea0087
potential temperature (work in progress)
FnHck Nov 20, 2024
1de9058
added moist potential temperature case from Oswald and Marco, changed…
FnHck Nov 21, 2024
91344ac
fixes
FnHck Nov 21, 2024
5566e0c
adjusted LMARS
FnHck Nov 21, 2024
f81d405
fixed DGMulti example
FnHck Nov 24, 2024
bb8bb51
added rainy equations DGMulti example and clarified elixir names
FnHck Nov 26, 2024
d72ef2f
added plots and rainy bubble dgmulti example
FnHck Dec 3, 2024
de1972b
fixed dgmulti solver
FnHck Dec 3, 2024
e3e9e10
attempted adding entropy2cons
FnHck Dec 3, 2024
f135408
fixed varnames of cons2eq_pot_temp
FnHck Dec 6, 2024
7a5a22a
changed folder structure and renamed some elixirs for clarity
FnHck Dec 11, 2024
a3650e3
added StartUpDG for testing overintegration
FnHck Dec 11, 2024
bee0878
LMARS rain testing
FnHck Dec 12, 2024
24eeac1
DGMulti testing
FnHck Jan 26, 2025
8bbb8c2
rain ec flux testing
FnHck Jan 26, 2025
0196d35
ec flux update and further testing
FnHck Jan 27, 2025
94b60b4
removed obsolete limiting case
FnHck Jan 28, 2025
57e491d
energy density ec flux rain case improvement and formatting changes
FnHck Jan 28, 2025
e70064c
diffusion and ec flux testing
FnHck Jan 30, 2025
d72a27d
added explicit rainy euler equations for testing
FnHck Feb 1, 2025
3af24d5
convergence test update with results
FnHck Feb 12, 2025
0c06d27
introduced boundary_condition_simple_slip_wall for compatibilty with …
FnHck Feb 12, 2025
9771cc6
removed rain-cutting experimental cases
FnHck Feb 12, 2025
fbd1526
removed unnecessary parameter from rain limiter
FnHck Feb 21, 2025
2d27987
ec flux and slip wall testing and fixes
FnHck Feb 21, 2025
05e91f0
more fixes and updates concerning ec flux and slip wall
FnHck Feb 21, 2025
54b8dae
split and named different testcases
FnHck Feb 24, 2025
6fadf30
split and named different testcases
FnHck Feb 24, 2025
be292fa
added convergence test for explicit rainy euler equations
FnHck Feb 24, 2025
e2f22c1
fixes for convergence test
FnHck Feb 24, 2025
a4f593d
updated slip wall boundary condition
FnHck Feb 24, 2025
9f5e344
updated density variables to be more physically and numerically fitting
FnHck Feb 25, 2025
eecfdb8
added convergence tests for explicit rainy euler equations
FnHck Feb 27, 2025
de3b3dc
small comment changes and fixes
FnHck Mar 10, 2025
071cca8
Code cleanup, simple slip wall fix, renames for clarification.
FnHck Apr 15, 2025
94a0e80
AtmosphereLayers name change to AtmosphereLayersRainyBubble to have u…
FnHck Apr 16, 2025
0874b27
comment cleanup
FnHck Apr 16, 2025
d2faff4
parameter adjustment
FnHck Apr 18, 2025
f0efa27
adjusted folder structure for pull request convenience
FnHck May 15, 2025
6ba2950
Merge branch 'main' of https://github.com/trixi-framework/TrixiAtmo.jl
FnHck May 15, 2025
25fddb2
add a test
benegee May 16, 2025
58591a2
remove StartupDG
benegee May 16, 2025
9f678c8
format
benegee May 16, 2025
337ca0c
correct path
benegee May 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,300 @@
using OrdinaryDiffEqLowStorageRK
using Trixi, TrixiAtmo
using TrixiAtmo: cons2aeqpot, saturation_pressure, source_terms_moist_bubble,
flux_LMARS
using NLsolve: nlsolve

###############################################################################
# semidiscretization of the compressible moist Euler equations

equations = CompressibleMoistEulerEquations2D()

function moist_state(y, dz, y0, r_t0, theta_e0,
equations::CompressibleMoistEulerEquations2D)
@unpack p_0, g, c_pd, c_pv, c_vd, c_vv, R_d, R_v, c_pl, L_00 = equations
(p, rho, T, r_t, r_v, rho_qv, theta_e) = y
p0 = y0[1]

F = zeros(7, 1)
rho_d = rho / (1 + r_t)
p_d = R_d * rho_d * T
T_C = T - 273.15
p_vs = 611.2 * exp(17.62 * T_C / (243.12 + T_C))
L = L_00 - (c_pl - c_pv) * T

F[1] = (p - p0) / dz + g * rho
F[2] = p - (R_d * rho_d + R_v * rho_qv) * T
# H = 1 is assumed
F[3] = (theta_e -
T * (p_d / p_0)^(-R_d / (c_pd + c_pl * r_t)) *
exp(L * r_v / ((c_pd + c_pl * r_t) * T)))
F[4] = r_t - r_t0
F[5] = rho_qv - rho_d * r_v
F[6] = theta_e - theta_e0
a = p_vs / (R_v * T) - rho_qv
b = rho - rho_qv - rho_d
# H=1 => phi=0
F[7] = a + b - sqrt(a * a + b * b)

return F
end

function generate_function_of_y(dz, y0, r_t0, theta_e0,
equations::CompressibleMoistEulerEquations2D)
function function_of_y(y)
return moist_state(y, dz, y0, r_t0, theta_e0, equations)
end
end

struct AtmosphereLayers{RealT <: Real}
equations::CompressibleMoistEulerEquations2D
# structure: 1--> i-layer (z = total_height/precision *(i-1)), 2--> rho, rho_theta, rho_qv, rho_ql
layer_data::Matrix{RealT}
total_height::RealT
preciseness::Int
layers::Int
ground_state::NTuple{2, RealT}
equivalent_potential_temperature::RealT
mixing_ratios::NTuple{2, RealT}
end

function AtmosphereLayers(equations; total_height = 10010.0, preciseness = 10,
ground_state = (1.4, 100000.0),
equivalent_potential_temperature = 320,
mixing_ratios = (0.02, 0.02), RealT = Float64)
@unpack kappa, p_0, c_pd, c_vd, c_pv, c_vv, R_d, R_v, c_pl = equations
rho0, p0 = ground_state
r_t0, r_v0 = mixing_ratios
theta_e0 = equivalent_potential_temperature

rho_qv0 = rho0 * r_v0
T0 = theta_e0
y0 = [p0, rho0, T0, r_t0, r_v0, rho_qv0, theta_e0]

n = convert(Int, total_height / preciseness)
dz = 0.01
layer_data = zeros(RealT, n + 1, 4)

F = generate_function_of_y(dz, y0, r_t0, theta_e0, equations)
sol = nlsolve(F, y0)
p, rho, T, r_t, r_v, rho_qv, theta_e = sol.zero

rho_d = rho / (1 + r_t)
rho_ql = rho - rho_d - rho_qv
kappa_M = (R_d * rho_d + R_v * rho_qv) / (c_pd * rho_d + c_pv * rho_qv + c_pl * rho_ql)
rho_theta = rho * (p0 / p)^kappa_M * T * (1 + (R_v / R_d) * r_v) / (1 + r_t)

layer_data[1, :] = [rho, rho_theta, rho_qv, rho_ql]
for i in (1:n)
y0 = deepcopy(sol.zero)
dz = preciseness
F = generate_function_of_y(dz, y0, r_t0, theta_e0, equations)
sol = nlsolve(F, y0)
p, rho, T, r_t, r_v, rho_qv, theta_e = sol.zero

rho_d = rho / (1 + r_t)
rho_ql = rho - rho_d - rho_qv
kappa_M = (R_d * rho_d + R_v * rho_qv) /
(c_pd * rho_d + c_pv * rho_qv + c_pl * rho_ql)
rho_theta = rho * (p0 / p)^kappa_M * T * (1 + (R_v / R_d) * r_v) / (1 + r_t)

layer_data[i + 1, :] = [rho, rho_theta, rho_qv, rho_ql]
end

return AtmosphereLayers{RealT}(equations, layer_data, total_height, dz, n, ground_state,
theta_e0, mixing_ratios)
end

# Moist bubble test case from paper:
# G.H. Bryan, J.M. Fritsch, A Benchmark Simulation for Moist Nonhydrostatic Numerical
# Models, MonthlyWeather Review Vol.130, 2917–2928, 2002,
# https://journals.ametsoc.org/view/journals/mwre/130/12/1520-0493_2002_130_2917_absfmn_2.0.co_2.xml.
function initial_condition_moist_bubble(x, t, equations::CompressibleMoistEulerEquations2D,
atmosphere_layers::AtmosphereLayers)
@unpack layer_data, preciseness, total_height = atmosphere_layers
dz = preciseness
z = x[2]
if (z > total_height && !(isapprox(z, total_height)))
error("The atmosphere does not match the simulation domain")
end
n = convert(Int, floor((z + eps()) / dz)) + 1
z_l = (n - 1) * dz
(rho_l, rho_theta_l, rho_qv_l, rho_ql_l) = layer_data[n, :]
z_r = n * dz
if (z_l == total_height)
z_r = z_l + dz
n = n - 1
end
(rho_r, rho_theta_r, rho_qv_r, rho_ql_r) = layer_data[n + 1, :]
rho = (rho_r * (z - z_l) + rho_l * (z_r - z)) / dz
rho_theta = rho * (rho_theta_r / rho_r * (z - z_l) + rho_theta_l / rho_l * (z_r - z)) /
dz
rho_qv = rho * (rho_qv_r / rho_r * (z - z_l) + rho_qv_l / rho_l * (z_r - z)) / dz
rho_ql = rho * (rho_ql_r / rho_r * (z - z_l) + rho_ql_l / rho_l * (z_r - z)) / dz

rho, rho_e, rho_qv, rho_ql = perturb_moist_profile!(x, rho, rho_theta, rho_qv, rho_ql,
equations::CompressibleMoistEulerEquations2D)

v1 = 0.0
v2 = 0.0
rho_v1 = rho * v1
rho_v2 = rho * v2
rho_E = rho_e + 1 / 2 * rho * (v1^2 + v2^2)

return SVector(rho, rho_v1, rho_v2, rho_E, rho_qv, rho_ql)
end

function perturb_moist_profile!(x, rho, rho_theta, rho_qv, rho_ql,
equations::CompressibleMoistEulerEquations2D)
@unpack kappa, p_0, c_pd, c_vd, c_pv, c_vv, R_d, R_v, c_pl, L_00 = equations
xc = 10000.0
zc = 2000.0
rc = 2000.0
Δθ = 2.0

r = sqrt((x[1] - xc)^2 + (x[2] - zc)^2)
rho_d = rho - rho_qv - rho_ql
kappa_M = (R_d * rho_d + R_v * rho_qv) / (c_pd * rho_d + c_pv * rho_qv + c_pl * rho_ql)
p_loc = p_0 * (R_d * rho_theta / p_0)^(1 / (1 - kappa_M))
T_loc = p_loc / (R_d * rho_d + R_v * rho_qv)
rho_e = (c_vd * rho_d + c_vv * rho_qv + c_pl * rho_ql) * T_loc + L_00 * rho_qv

p_v = rho_qv * R_v * T_loc
p_d = p_loc - p_v
T_C = T_loc - 273.15
p_vs = 611.2 * exp(17.62 * T_C / (243.12 + T_C))
H = p_v / p_vs
r_v = rho_qv / rho_d
r_l = rho_ql / rho_d
r_t = r_v + r_l

# equivalent potential temperature
a = T_loc * (p_0 / p_d)^(R_d / (c_pd + r_t * c_pl))
b = H^(-r_v * R_v / c_pd)
L_v = L_00 + (c_pv - c_pl) * T_loc
c = exp(L_v * r_v / ((c_pd + r_t * c_pl) * T_loc))
aeq_pot = (a * b * c) # TODO: this is not used. remove?

# Assume pressure stays constant
if (r < rc && Δθ > 0)
# Calculate background density potential temperature
θ_dens = rho_theta / rho * (p_loc / p_0)^(kappa_M - kappa)
# Calculate perturbed density potential temperature
θ_dens_new = θ_dens * (1 + Δθ * cospi(0.5 * r / rc)^2 / 300)
rt = (rho_qv + rho_ql) / rho_d
rv = rho_qv / rho_d
# Calculate moist potential temperature
θ_loc = θ_dens_new * (1 + rt) / (1 + (R_v / R_d) * rv)
# Adjust varuables until the temperature is met
if rt > 0
while true
T_loc = θ_loc * (p_loc / p_0)^kappa
T_C = T_loc - 273.15
# SaturVapor
pvs = 611.2 * exp(17.62 * T_C / (243.12 + T_C))
rho_d_new = (p_loc - pvs) / (R_d * T_loc)
rvs = pvs / (R_v * rho_d_new * T_loc)
θ_new = θ_dens_new * (1 + rt) / (1 + (R_v / R_d) * rvs)
if abs(θ_new - θ_loc) <= θ_loc * 1.0e-12
break
else
θ_loc = θ_new
end
end
else
rvs = 0
T_loc = θ_loc * (p_loc / p_0)^kappa
rho_d_new = p_loc / (R_d * T_loc)
θ_new = θ_dens_new * (1 + rt) / (1 + (R_v / R_d) * rvs)
end
rho_qv = rvs * rho_d_new
rho_ql = (rt - rvs) * rho_d_new
rho = rho_d_new * (1 + rt)
rho_d = rho - rho_qv - rho_ql
kappa_M = (R_d * rho_d + R_v * rho_qv) /
(c_pd * rho_d + c_pv * rho_qv + c_pl * rho_ql)
rho_theta = rho * θ_dens_new * (p_loc / p_0)^(kappa - kappa_M)
rho_e = (c_vd * rho_d + c_vv * rho_qv + c_pl * rho_ql) * T_loc + L_00 * rho_qv
end
return SVector(rho, rho_e, rho_qv, rho_ql)
end

# Create background atmosphere data set
atmosphere_data = AtmosphereLayers(equations)

# Create the initial condition with the initial data set
function initial_condition_moist(x, t, equations)
return initial_condition_moist_bubble(x, t, equations, atmosphere_data)
end

initial_condition = initial_condition_moist

boundary_condition = (x_neg = boundary_condition_periodic,
x_pos = boundary_condition_periodic,
y_neg = boundary_condition_slip_wall,
y_pos = boundary_condition_slip_wall)

source_term = source_terms_moist_bubble

###############################################################################
# Get the DG approximation space

polydeg = 3
basis = LobattoLegendreBasis(polydeg)

surface_flux = flux_LMARS
solver = DGSEM(basis, surface_flux)

coordinates_min = (0.0, 0.0)
coordinates_max = (20000.0, 10000.0)

cells_per_dimension = (128, 64)

mesh = StructuredMesh(cells_per_dimension, coordinates_min, coordinates_max,
periodicity = (true, false))

###############################################################################
# create the semi discretization object

semi = SemidiscretizationHyperbolic(mesh, equations, initial_condition, solver,
boundary_conditions = boundary_condition,
source_terms = source_term)

###############################################################################
# ODE solvers, callbacks etc.

tspan = (0.0, 1000.0)
ode = semidiscretize(semi, tspan)

summary_callback = SummaryCallback()

analysis_interval = 1000
solution_variables = cons2aeqpot

analysis_callback = AnalysisCallback(semi, interval = analysis_interval,
extra_analysis_errors = (:entropy_conservation_error,),
extra_analysis_integrals = (entropy, energy_total,
saturation_pressure))

alive_callback = AliveCallback(analysis_interval = analysis_interval)

save_solution = SaveSolutionCallback(interval = 1000,
save_initial_solution = true,
save_final_solution = true,
solution_variables = solution_variables)

stepsize_callback = StepsizeCallback(cfl = 1.0)

callbacks = CallbackSet(summary_callback,
analysis_callback,
alive_callback,
save_solution,
stepsize_callback)

###############################################################################
# run the simulation

sol = solve(ode, CarpenterKennedy2N54(williamson_condition = false),
dt = 1.0, # solve needs some value here but it will be overwritten by the stepsize_callback
save_everystep = false, callback = callbacks);
summary_callback() # print the timer summary
Loading
Loading