-
Notifications
You must be signed in to change notification settings - Fork 237
Tilted BBL example not working on GPU #4438
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I think that example is not GPU-compatible. The problem is that
to ĝ = [sind(θ), 0, cosd(θ)]
ĝ = Oceananigans.on_architecture(arch, ĝ) # assuming you have an `arch` variable with `arch == GPU()` Another way to do it is to convert the ĝ = (sind(θ), 0, cosd(θ)) |
Thanks Simone! Converting to a tuple gives the following error: Using the first change gives the following error: |
ok, we should go the tuple route I think. Can you show me the location of the error? (i.e. at which line the errors are encountered in the stacktrace) Can you also attach the snippet of your code? |
The error appears in the next line "buoyancy = BuoyancyForce(BuoyancyTracer(), gravity_unit_vector = -ĝ)" |
using Oceananigans
using Oceananigans.Units
Lx = 200meters
Lz = 100meters
Nx = 64
Nz = 64
# Creates a grid with near-constant spacing `refinement * Lz / Nz`
# near the bottom:
refinement = 1.8 # controls spacing near surface (higher means finer spaced)
stretching = 10 # controls rate of stretching at bottom
# "Warped" height coordinate
h(k) = (Nz + 1 - k) / Nz
# Linear near-surface generator
ζ(k) = 1 + (h(k) - 1) / refinement
# Bottom-intensified stretching function
Σ(k) = (1 - exp(-stretching * h(k))) / (1 - exp(-stretching))
# Generating function
z_faces(k) = - Lz * (ζ(k) * Σ(k) - 1)
grid = RectilinearGrid(GPU(), topology = (Periodic, Flat, Bounded),
size = (Nx, Nz),
x = (0, Lx),
z = z_faces)
θ = 3 # degrees
ĝ = [sind(θ), 0, cosd(θ)]
# ĝ = Oceananigans.on_architecture(GPU(), ĝ)
buoyancy = BuoyancyForce(BuoyancyTracer(), gravity_unit_vector = -ĝ)
coriolis = ConstantCartesianCoriolis(f = 1e-4, rotation_axis = ĝ)
@inline constant_stratification(x, z, t, p) = p.N² * (x * p.ĝ[1] + z * p.ĝ[3])
N² = 1e-5 # s⁻² # background vertical buoyancy gradient
B∞_field = BackgroundField(constant_stratification, parameters=(; ĝ, N² = N²))
∂z_b_bottom = - N² * cosd(θ)
negative_background_diffusive_flux = GradientBoundaryCondition(∂z_b_bottom)
b_bcs = FieldBoundaryConditions(bottom = negative_background_diffusive_flux)
V∞ = 0.1 # m s⁻¹
u_bcs = FieldBoundaryConditions(top = FluxBoundaryCondition(nothing),
bottom = ValueBoundaryCondition(0.0))
v_bcs = FieldBoundaryConditions(top = FluxBoundaryCondition(nothing),
bottom = ValueBoundaryCondition(-V∞))
V∞_field = BackgroundField(V∞)
ν = 1e-4
κ = 1e-4
closure = ScalarDiffusivity(ν=ν, κ=κ)
model = NonhydrostaticModel(; grid, buoyancy, coriolis, closure,
advection = UpwindBiased(order=5),
tracers = :b,
boundary_conditions = (u=u_bcs, v=v_bcs, b=b_bcs),
background_fields = (; b=B∞_field, v=V∞_field))
noise(x, z) = 1e-3 * randn() * exp(-(10z)^2 / grid.Lz^2)
set!(model, u=noise, w=noise)
# Δt₀ = 0.5 * minimum([minimum_zspacing(grid) / V∞, minimum_zspacing(grid)^2/κ])
# simulation = Simulation(model, Δt = Δt₀, stop_time = 1day)
simulation = Simulation(model, Δt=0.1, stop_time=8days)
wizard = TimeStepWizard(max_change=1.1, cfl=0.7)
simulation.callbacks[:wizard] = Callback(wizard, IterationInterval(4))
using Printf
start_time = time_ns() # so we can print the total elapsed wall time
progress_message(sim) =
@printf("Iteration: %04d, time: %s, Δt: %s, max|w|: %.1e m s⁻¹, wall time: %s\n",
iteration(sim), prettytime(time(sim)),
prettytime(sim.Δt), maximum(abs, sim.model.velocities.w),
prettytime((time_ns() - start_time) * 1e-9))
simulation.callbacks[:progress] = Callback(progress_message, IterationInterval(200))
u, v, w = model.velocities
b = model.tracers.b
B∞ = model.background_fields.tracers.b
B = b + B∞
V = v + V∞
outputs = (; u, V, w, B)
simulation.output_writers[:fields] = JLD2Writer(model, outputs;
filename = "bottom_drag.jld2",
schedule = TimeInterval(180minutes),
overwrite_existing = true)
run!(simulation) |
Yeah, we just need to use a tuple, plus |
which is done here: #4439 |
Works now - thanks all! |
Uh oh!
There was an error while loading. Please reload this page.
Hi! I’m trying to design a simulation based on the tilted BBL example, but it’s not working properly on GPUs. The error message is attached below. If I remove b = B∞_field from the background_fields = (; b = B∞_field, v = V∞_field) line, the simulation runs. Any help would be appreciated! (thanks for including this example - it’s been very helpful for me @tomchor )
The text was updated successfully, but these errors were encountered: