Skip to content

Commit

Permalink
more format fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanmontoya committed Aug 17, 2024
1 parent 7e70aaf commit fa11728
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 24 deletions.
23 changes: 12 additions & 11 deletions examples/elixir_moist_euler_EC_bubble.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,35 +45,36 @@ function generate_function_of_y(dz, y0, r_t0, theta_e0,
return moist_state(y, dz, y0, r_t0, theta_e0, equations)
end
end

#Create Initial atmosphere by generating a layer data set
struct AtmosphereLayers{RealT <: Real}
equations::CompressibleMoistEulerEquations2D
# structure: 1--> i-layer (z = total_height/precision *(i-1)), 2--> rho, rho_theta, rho_qv, rho_ql
LayerData::Matrix{RealT} # Contains the layer data for each height
layer_data::Matrix{RealT} # Contains the layer data for each height
total_height::RealT # Total height of the atmosphere
preciseness::Int # Space between each layer data (dz)
layers::Int # Amount of layers (total height / dz)
ground_state::NTuple{2, RealT} # (rho_0, p_tilde_0) to define the initial values at height z=0
equivalentpotential_temperature::RealT # Value for theta_e since we have a constant temperature theta_e0=theta_e.
equivalent_potential_temperature::RealT # Value for theta_e since we have a constant temperature theta_e0=theta_e.
mixing_ratios::NTuple{2, RealT} # Constant mixing ratio. Also defines initial guess for rho_qv0 = r_v0 * rho_0.
end

function AtmosphereLayers(equations; total_height = 10010.0, preciseness = 10,
ground_state = (1.4, 100000.0),
equivalentpotential_temperature = 320,
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 = equivalentpotential_temperature
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
LayerData = zeros(RealT, n + 1, 4)
layer_data = zeros(RealT, n + 1, 4)

F = generate_function_of_y(dz, y0, r_t0, theta_e0, equations)
sol = nlsolve(F, y0)
Expand All @@ -84,7 +85,7 @@ function AtmosphereLayers(equations; total_height = 10010.0, preciseness = 10,
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)

LayerData[1, :] = [rho, rho_theta, rho_qv, rho_ql]
layer_data[1, :] = [rho, rho_theta, rho_qv, rho_ql]
for i in (1:n)
y0 = deepcopy(sol.zero)
dz = preciseness
Expand All @@ -98,31 +99,31 @@ function AtmosphereLayers(equations; total_height = 10010.0, preciseness = 10,
(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)

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

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

# Generate background state from the Layer data set by linearely interpolating the layers
function initial_condition_moist_bubble(x, t, equations::CompressibleMoistEulerEquations2D,
atmosphere_layers::AtmosphereLayers)
@unpack LayerData, preciseness, total_height = atmosphere_layers
@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 / dz)) + 1
z_l = (n - 1) * dz
(rho_l, rho_theta_l, rho_qv_l, rho_ql_l) = LayerData[n, :]
(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) = LayerData[n + 1, :]
(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
Expand Down
24 changes: 12 additions & 12 deletions examples/elixir_moist_euler_moist_bubble.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,31 +49,31 @@ 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
LayerData::Matrix{RealT}
layer_data::Matrix{RealT}
total_height::RealT
preciseness::Int
layers::Int
ground_state::NTuple{2, RealT}
equivalentpotential_temperature::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),
equivalentpotential_temperature = 320,
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 = equivalentpotential_temperature
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
LayerData = zeros(RealT, n + 1, 4)
layer_data = zeros(RealT, n + 1, 4)

F = generate_function_of_y(dz, y0, r_t0, theta_e0, equations)
sol = nlsolve(F, y0)
Expand All @@ -84,7 +84,7 @@ function AtmosphereLayers(equations; total_height = 10010.0, preciseness = 10,
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)

LayerData[1, :] = [rho, rho_theta, rho_qv, rho_ql]
layer_data[1, :] = [rho, rho_theta, rho_qv, rho_ql]
for i in (1:n)
y0 = deepcopy(sol.zero)
dz = preciseness
Expand All @@ -98,10 +98,10 @@ function AtmosphereLayers(equations; total_height = 10010.0, preciseness = 10,
(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)

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

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

Expand All @@ -110,22 +110,22 @@ end
# 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,
AtmosphereLayers::AtmosphereLayers)
@unpack LayerData, preciseness, total_height = AtmosphereLayers
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) = LayerData[n, :]
(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) = LayerData[n + 1, :]
(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
Expand Down
2 changes: 1 addition & 1 deletion test/test_2d_moist_euler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ include("test_trixiatmo.jl") # TODO - This is a repetition from Trixi.jl

EXAMPLES_DIR = pkgdir(TrixiAtmo, "examples") # TODO - Do we need a subdirectory for examples?

@trixiatmo_testset "elixir_moist_euler_dry_bubble.jl" begin
@trixiatmo_testset "elixir_moist_euler_dry_bubble" begin
@test_trixi_include(joinpath(EXAMPLES_DIR,
"elixir_moist_euler_dry_bubble.jl"),
l2=[
Expand Down

0 comments on commit fa11728

Please sign in to comment.