Updating the Boundary Conditions of Model during run #3602
-
Hello, I am attempting to simulate a storm event at high latitudes and using an array of ERA5 hourly sensible heat flux, latent heat flux, and wind at 10m. I am using these arrays to calculate wind drag and the surface heat flux to use as boundary conditions for my model. I have written functions that update the boundary conditions based on the time in the model. I have gotten this code to run successfully on cpu but when I adjust the code to run on the GPU, I run into some errors. This is the error that I recieve:
and this is the code that produces the error: # Constants
const initial_rho = 1026.0; # kg m⁻³, average density at the surface of the world ocean
const rho_air = 1.225; # average density of air at sea level
const drag_coef = 2.5e-3; # drag coefficient
const heat_capacity = 3991.0;
# Convert constants to GPU arrays
ρ₀ = CUDA.fill(initial_rho);
ρₐ = CUDA.fill(rho_air);
cᴰ = CUDA.fill(drag_coef);
cᴾ = CUDA.fill(heat_capacity);
#Wind Drag
Qᵘ = -ρₐ ./ ρ₀ .* cᴰ .* hourly_mean_u10_gpu .* abs.(hourly_mean_u10_gpu);
#Surface Heat Flux
Qnet = hourly_mean_latent_gpu .+ hourly_mean_sensible_gpu;
Qᵀ = Qnet ./ (ρ₀ .* cᴾ);
function surface_heat_flux(x, y, t)
hour_index = Int.(floor.(t ./ 3600)) .+ 1
t_bnd = CUDA.@allowscalar Qᵀ[1, 1, hour_index]
return t_bnd
end
function wind_drag(x, y, t)
hour_index = Int.(floor.(t ./ 3600)) .+ 1
u_bnd = CUDA.@allowscalar Qᵘ[1, 1, hour_index]
return u_bnd
end
# Boundary Conditions
u_bcs = FieldBoundaryConditions(top = FluxBoundaryCondition(wind_drag));
T_bcs = FieldBoundaryConditions(top = FluxBoundaryCondition(surface_heat_flux));
# Define your model here
model = NonhydrostaticModel(; grid, buoyancy,
advection = UpwindBiasedFifthOrder(),
timestepper = :RungeKutta3,
tracers = (:T, :S),
coriolis = FPlane(rotation_rate=7.292115e-5, latitude=72),
closure = AnisotropicMinimumDissipation(),
boundary_conditions = (u=u_bcs, T=T_bcs)); Any tips/help to diagnonse the error would be appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 10 replies
-
Seems like a cool problem... ! Since your forcing is horizontally-homogeneous, try using julia> Q = Ref(0.0)
Base.RefValue{Float64}(0.0)
julia> Q[] = 1.0
1.0 I believe I also suggest using parameters in your boundary condition functions to avoid global variables (otherwise you also need to declare Finally... I believe can actually be implemented now using |
Beta Was this translation helpful? Give feedback.
I implemented something just like this here: https://github.com/glwagner/TropicalTurbulantics.jl/blob/main/tropical_turbulence_setup.jl
Check out the function
interp_bc
. that function is incorporated into a boundary condition here:https://github.com/glwagner/TropicalTurbulantics.jl/blob/8b5e882a3ea7b72d4cdc7cdbb9cde14f59d1d105/tropical_turbulence_setup.jl#L214
Note that
interp_bc
applies to interpolating any time-series at a point. There is alsointerp_forcing
, which additionally depends on the vertical indexk
(this applies to a horizontally uniform but vertically-varying forcing, such as lateral flux divergences derived from a GCM).