Front simulation weird patterns at the surface (no forcing) #2406
-
Hi all, I am having some weird patterns for buoyancy at the surface that blows up the model, even that I am not applying any forcing there. The contextI am currently trying to setup a front simulation to couple with the NP model being developed in #2385 . The initial conditionsI am starting the simulation with a single buoyant front that adds to an initial buoyancy profile. const g = 9.82 # gravity
const ρₒ = 1026 # reference density
# background density profile based on Argo data
@inline bg(z) = 0.25*tanh(0.0027*(-653.3-z))-6.8*z/1e5+1027.56
# decay function for fronts
@inline decay(z) = (tanh((z+500)/300)+1)/2
@inline front(x, y, z, cy) = tanh((y-cy)/12kilometers)
@inline D(x, y, z) = bg(z) + 0.8*decay(z)*front(x, y, z, 0)/4
@inline B(x, y, z) = -(g/ρₒ)*D(x, y, z)
# setting the initial conditions
set!(model; b=B) The problemAfter 1 timestep it starts to present weird patters at the surface. Full code:using Oceananigans
using Oceananigans.Units
# define the size and max depth of the simulation
const Ny = 100
const Nz = 48 # number of points in z
const H = 1000 # maximum depth
# create the grid of the model
grid = RectilinearGrid(GPU(),
size=(Ny, Nz),
halo=(3,3),
y=(-(Ny/2)kilometers, (Ny/2)kilometers),
z=(H * cos.(LinRange(π/2,0,Nz+1)) .- H)meters,
topology=(Flat, Bounded, Bounded)
)
# define the turbulence closure of the model
horizontal_closure = ScalarDiffusivity(ν=1, κ=1)
vertical_closure = ScalarDiffusivity(ν=1e-5, κ=1e-5)
coriolis = FPlane(latitude=60)
#--------------- Instantiate Model
# create the model
model = NonhydrostaticModel(grid = grid,
advection = WENO5(),
timestepper = :RungeKutta3,
coriolis = coriolis,
closure=(horizontal_closure,vertical_closure),
tracers = (:b),
buoyancy = BuoyancyTracer())
#--------------- Initial Conditions
const g = 9.82 # gravity
const ρₒ = 1026 # reference density
# background density profile based on Argo data
@inline bg(z) = 0.25*tanh(0.0027*(-653.3-z))-6.8*z/1e5+1027.56
# decay function for fronts
@inline decay(z) = (tanh((z+500)/300)+1)/2
@inline front(x, y, z, cy) = tanh((y-cy)/12kilometers)
@inline D(x, y, z) = bg(z) + 0.8*decay(z)*front(x, y, z, 0)/4
@inline B(x, y, z) = -(g/ρₒ)*D(x, y, z)
# setting the initial conditions
set!(model; b=B)
#--------------- Simulation
simulation = Simulation(model, Δt = 10seconds, stop_time = 10minutes)
wizard = TimeStepWizard(cfl=1.0, max_change=1.1, max_Δt=6minutes)
simulation.callbacks[:wizard] = Callback(wizard, IterationInterval(5))
# merge light and h to the outputs
outputs = merge(model.velocities, model.tracers) # make a NamedTuple with all outputs
# writing the output
simulation.output_writers[:fields] =
NetCDFOutputWriter(model, outputs, filepath = "data/output.nc",
schedule=IterationInterval(1))
# run the simulation
run!(simulation) Plotting code (Python)import xarray as xr
import matplotlib.pyplot as plt
import numpy as np
ds = xr.open_dataset("data/output.nc").squeeze()#.isel(time=0)
ds = ds.assign_coords(time=ds.time.astype("float")*1e-9/86400) #convert to days
# first plot
fig,ax = plt.subplots()
ds.b.isel(time=0).plot()
ds.b.isel(time=0).plot.contour(levels=20,colors='k',linestyles='solid',linewidths=1,alpha=0.6)
# second plot
levels = np.arange(-9.84,-9.3,0.001)
kw = dict(vmin=ds.b.isel(time=0).min().values+0.001,vmax=ds.b.isel(time=0).max().values,extend='both')
fig,ax = plt.subplots(1,2,figsize=(14,4))
ti = 0
ds.b.isel(time=ti).isel(zC=slice(-10,None)).plot(ax=ax[0],add_colorbar=False,**kw)
ds.b.isel(time=ti).isel(zC=slice(-10,None)).plot.contour(ax=ax[0],colors='k',linestyles='solid',linewidths=1,alpha=0.6,levels=levels)
ti = 1
C = ds.b.isel(time=ti).isel(zC=slice(-10,None)).plot(ax=ax[1],add_colorbar=False,**kw)
ds.b.isel(time=ti).isel(zC=slice(-10,None)).plot.contour(ax=ax[1],colors='k',linestyles='solid',linewidths=1,alpha=0.6,levels=levels)
fig.colorbar(C,ax=ax)
_ = [a.set(ylim=[-20,0]) for a in ax] |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 3 replies
-
Should we convert to a discussion? There's a nice Q&A format there and you can give people credit for answering your q. |
Beta Was this translation helpful? Give feedback.
-
Might be nice to include the plotting code! |
Beta Was this translation helpful? Give feedback.
-
Of course! |
Beta Was this translation helpful? Give feedback.
-
Both your closures are 3D horizontal_closure = ScalarDiffusivity(ν=1, κ=1)
vertical_closure = ScalarDiffusivity(ν=1e-5, κ=1e-5) I think you may want horizontal_closure = HorizontalScalarDiffusivity(ν=1, κ=1)
vertical_closure = VerticalScalarDiffusivity(ν=1e-5, κ=1e-5) Or even using Oceananigans.TurbulenceClosures: VerticallyImplicitTimeDiscretization
horizontal_closure = HorizontalScalarDiffusivity(ν=1, κ=1)
vertical_closure = VerticalScalarDiffusivity(VerticallyImplicitTimeDiscretization(), ν=1e-5, κ=1e-5) |
Beta Was this translation helpful? Give feedback.
-
Does the benefit of |
Beta Was this translation helpful? Give feedback.
Both your closures are 3D
ScalarDiffusivity
:I think you may want
Or even