Skip to content
This repository has been archived by the owner on Mar 1, 2023. It is now read-only.

Commit

Permalink
Store ∇ʰu separately from ν∇u, simplify continuity equation
Browse files Browse the repository at this point in the history
  • Loading branch information
blallen committed Jul 21, 2020
1 parent af0d8c6 commit 5ba1ce7
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 449 deletions.
50 changes: 2 additions & 48 deletions experiments/OceanBoxGCM/ocean_gyre.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,7 @@ function run_ocean_gyre(; imex::Bool = false, BC = nothing, nt = 0, refDat = ())

nt_freq = 620
cb = ClimateMachine.StateCheck.sccreate(
[
(solver_config.Q, "Q"),
(solver_config.dg.state_auxiliary, "s_aux"),
(solver_config.dg.state_gradient_flux, "s_gflux"),
],
[(solver_config.Q, "Q"), (solver_config.dg.state_auxiliary, "s_aux")],
nt_freq;
prec = 12,
)
Expand Down Expand Up @@ -146,50 +142,8 @@ end
# Ocean floor BCs,
# Surface BCc
# )
boundary_conditions = [
(
OceanBC(Impenetrable(NoSlip()), Insulating()),
OceanBC(Impenetrable(NoSlip()), Insulating()),
OceanBC(Penetrable(KinematicStress()), TemperatureFlux()),
),
(
OceanBC(Impenetrable(FreeSlip()), Insulating()),
OceanBC(Impenetrable(NoSlip()), Insulating()),
OceanBC(Penetrable(KinematicStress()), TemperatureFlux()),
),
(
OceanBC(Impenetrable(NoSlip()), Insulating()),
OceanBC(Impenetrable(FreeSlip()), Insulating()),
OceanBC(Penetrable(KinematicStress()), TemperatureFlux()),
),
(
OceanBC(Impenetrable(FreeSlip()), Insulating()),
OceanBC(Impenetrable(FreeSlip()), Insulating()),
OceanBC(Penetrable(KinematicStress()), TemperatureFlux()),
),
(
OceanBC(Impenetrable(NoSlip()), Insulating()),
OceanBC(Impenetrable(NoSlip()), Insulating()),
OceanBC(Penetrable(FreeSlip()), TemperatureFlux()),
),
(
OceanBC(Impenetrable(FreeSlip()), Insulating()),
OceanBC(Impenetrable(NoSlip()), Insulating()),
OceanBC(Penetrable(FreeSlip()), TemperatureFlux()),
),
(
OceanBC(Impenetrable(NoSlip()), Insulating()),
OceanBC(Impenetrable(FreeSlip()), Insulating()),
OceanBC(Penetrable(FreeSlip()), TemperatureFlux()),
),
(
OceanBC(Impenetrable(FreeSlip()), Insulating()),
OceanBC(Impenetrable(FreeSlip()), Insulating()),
OceanBC(Penetrable(FreeSlip()), TemperatureFlux()),
),
]

## By default test with a couple of standard bc's
# Prior block shows that many other combinations are possible
# - noslip on sides and bottom
# - freeslip on sides and no-slipt on bottom
boundary_conditions = [
Expand Down
227 changes: 150 additions & 77 deletions experiments/OceanBoxGCM/refvals/ocean_gyre_refvals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@
#
# Now for real!
#
#! format: off

refVals=[]
refPrecs=[]
refVals = []
refPrecs = []

# SC ========== Test number 1 reference values and precision match template. =======
# SC ========== /home/cnh/projects/cm/experiments/OceanBoxGCM/ocean_gyre.jl test reference values ======================================
Expand All @@ -42,48 +41,86 @@
# [ : : : : : : ],
# ]
varr = [
[ "Q", "u[1]", -7.88803234115370288659e-02, 6.54328011157667283060e-02, 2.01451525264660777012e-03, 1.24588716783015467093e-02 ],
[ "Q", "u[2]", -8.71605274310934263760e-02, 1.47505267452495314462e-01, 5.63158201082454307890e-03, 1.28959719954838437916e-02 ],
[ "Q", , -4.73491408441974459542e-01, 4.02693687285993751068e-01, -6.49059970676089264836e-05, 2.21689928090662985438e-01 ],
[ "Q", , 4.24292935192304451839e-04, 9.24539353455580759089e+00, 2.49938206627401893201e+00, 2.17986626392490689952e+00 ],
[ "s_aux", :y, 0.00000000000000000000e+00, 4.00000000000000046566e+06, 1.99999999999999976717e+06, 1.15573163901915703900e+06 ],
[ "s_aux", :w, -2.22086406767055965930e-04, 2.00575090959195941574e-04, 2.53168866096191178104e-07, 1.66257132341925427171e-05 ],
[ "s_aux", :pkin, -9.00869877619915215838e-01, 0.00000000000000000000e+00, -3.33171488779369640021e-01, 2.54740287894525019308e-01 ],
[ "s_aux", :wz0, -2.96608015794916532427e-05, 3.66759042312538147113e-05, 3.78116102589123325624e-10, 1.07073256826409470244e-05 ],
[ "s_gflux", "ν∇u[1]", -1.98765276856145908790e-02, 1.92976912753076192131e-02, 9.31995586073550077850e-09, 2.84016926475062683050e-04 ],
[ "s_gflux", "ν∇u[2]", -8.60188027210821715141e-03, 2.03898608650850965418e-02, 1.44279862042391183595e-05, 7.01831343135553482361e-04 ],
[ "s_gflux", "ν∇u[3]", -2.36999031942582461820e-05, 3.39171933774427215489e-05, 1.79310417841609871239e-08, 3.03350466717279338539e-06 ],
[ "s_gflux", "ν∇u[4]", -3.27811105688537093861e-02, 3.33776923250933485465e-02, -8.41954909635648634245e-06, 9.93067541524441646170e-04 ],
[ "s_gflux", "ν∇u[5]", -3.19705003898926379269e-02, 3.94072309121676778859e-03, -2.09915474589233714674e-06, 4.56596518968874199012e-04 ],
[ "s_gflux", "ν∇u[6]", -3.84552825296212839770e-05, 3.30579003830798668533e-05, -6.85753430789401392363e-08, 3.41712910764070301712e-06 ],
[ "s_gflux", "κ∇θ[1]", -1.90663030661463762938e-03, 1.59419367775516821958e-03, -2.07346812692515548133e-05, 1.38241222633447261199e-04 ],
[ "s_gflux", "κ∇θ[2]", -1.17846832845764997420e-03, 3.03333905110560143534e-03, 9.95380871168155762288e-04, 8.10649417649871592909e-04 ],
[ "s_gflux", "κ∇θ[3]", -1.91676759182478058212e-05, 6.14879473708830387359e-05, -4.12675761035662034755e-07, 1.91038619046619808554e-06 ],
[
"Q",
"u[1]",
-7.88803234115370288659e-02,
6.54328011157667283060e-02,
2.01451525264660777012e-03,
1.24588716783015467093e-02,
],
[
"Q",
"u[2]",
-8.71605274310934263760e-02,
1.47505267452495314462e-01,
5.63158201082454307890e-03,
1.28959719954838437916e-02,
],
[
"Q",
,
-4.73491408441974459542e-01,
4.02693687285993751068e-01,
-6.49059970676089264836e-05,
2.21689928090662985438e-01,
],
[
"Q",
,
4.24292935192304451839e-04,
9.24539353455580759089e+00,
2.49938206627401893201e+00,
2.17986626392490689952e+00,
],
[
"s_aux",
:y,
0.00000000000000000000e+00,
4.00000000000000046566e+06,
1.99999999999999976717e+06,
1.15573163901915703900e+06,
],
[
"s_aux",
:w,
-2.22086406767055965930e-04,
2.00575090959195941574e-04,
2.53168866096191178104e-07,
1.66257132341925427171e-05,
],
[
"s_aux",
:pkin,
-9.00869877619915215838e-01,
0.00000000000000000000e+00,
-3.33171488779369640021e-01,
2.54740287894525019308e-01,
],
[
"s_aux",
:wz0,
-2.96608015794916532427e-05,
3.66759042312538147113e-05,
3.78116102589123325624e-10,
1.07073256826409470244e-05,
],
]
parr = [
[ "Q", "u[1]", 12, 12, 12, 12 ],
[ "Q", "u[2]", 12, 12, 12, 12 ],
[ "Q", , 12, 12, 12, 12 ],
[ "Q", , 12, 12, 12, 12 ],
[ "s_aux", :y, 12, 12, 12, 12 ],
[ "s_aux", :w, 12, 12, 12, 12 ],
[ "s_aux", :pkin, 12, 12, 12, 12 ],
[ "s_aux", :wz0, 12, 12, 8, 12 ],
[ "s_gflux", "ν∇u[1]", 12, 12, 8, 12 ],
[ "s_gflux", "ν∇u[2]", 12, 12, 12, 12 ],
[ "s_gflux", "ν∇u[3]", 12, 12, 12, 12 ],
[ "s_gflux", "ν∇u[4]", 12, 12, 12, 12 ],
[ "s_gflux", "ν∇u[5]", 12, 12, 12, 12 ],
[ "s_gflux", "ν∇u[6]", 12, 12, 12, 12 ],
[ "s_gflux", "κ∇θ[1]", 12, 12, 12, 12 ],
[ "s_gflux", "κ∇θ[2]", 12, 12, 12, 12 ],
[ "s_gflux", "κ∇θ[3]", 12, 12, 12, 12 ],
["Q", "u[1]", 12, 12, 12, 12],
["Q", "u[2]", 12, 12, 12, 12],
["Q", , 12, 12, 12, 12],
["Q", , 12, 12, 12, 12],
["s_aux", :y, 12, 12, 12, 12],
["s_aux", :w, 12, 12, 12, 12],
["s_aux", :pkin, 12, 12, 12, 12],
["s_aux", :wz0, 12, 12, 8, 12],
]
# END SCPRINT
# SC ====================================================================================

append!(refVals ,[ varr ] )
append!(refPrecs,[ parr ] )
append!(refVals, [varr])
append!(refPrecs, [parr])

# SC ========== Test number 2 reference values and precision match template. =======
# SC ========== /home/cnh/projects/cm/experiments/OceanBoxGCM/ocean_gyre.jl test reference values ======================================
Expand All @@ -96,47 +133,83 @@ parr = [
# [ : : : : : : ],
# ]
varr = [
[ "Q", "u[1]", -3.08415268094245687003e-01, 3.31683879748177812274e-01, 2.34355645025035056947e-03, 1.38278493625595393784e-02 ],
[ "Q", "u[2]", -9.30330187375882494694e-02, 1.45773331490709479041e-01, 6.38739141648009701308e-03, 1.38107523198905141754e-02 ],
[ "Q", , -4.60215148246349181615e-01, 3.97155090993862369686e-01, -1.05814653709044253051e-04, 2.14356824554893188317e-01 ],
[ "Q", , 3.90305009874997816885e-04, 9.28488770009523101123e+00, 2.49938688339290848717e+00, 2.17986650147491722862e+00 ],
[ "s_aux", :y, 0.00000000000000000000e+00, 4.00000000000000046566e+06, 1.99999999999999976717e+06, 1.15573163901915703900e+06 ],
[ "s_aux", :w, -2.65432487944419423249e-04, 2.51335486222488370053e-04, 3.34985017281366756292e-07, 1.98256782258218657716e-05 ],
[ "s_aux", :pkin, -9.01203660410079376852e-01, 0.00000000000000000000e+00, -3.33173652152760846334e-01, 2.54737286187841360796e-01 ],
[ "s_aux", :wz0, -3.16776291712146345464e-05, 3.89428424525183031852e-05, 4.05688221636862481177e-10, 1.10561449663397378925e-05 ],
[ "s_gflux", "ν∇u[1]", -6.91411158656193985950e-02, 6.71894067927724242262e-02, 1.93151282317531301526e-08, 3.67871498890457999768e-04 ],
[ "s_gflux", "ν∇u[2]", -6.41072589623675609394e-02, 5.93158959821227672188e-03, -1.72612717858599068401e-05, 1.09370391833557892812e-03 ],
[ "s_gflux", "ν∇u[3]", -7.40852152420143496942e-05, 7.70630509235797829829e-05, 1.94096112473072846645e-08, 3.35721658566900582726e-06 ],
[ "s_gflux", "ν∇u[4]", -2.77618725100101104708e-02, 2.76053769492804849939e-02, 8.37000168929151316390e-06, 1.04649435866464054871e-03 ],
[ "s_gflux", "ν∇u[5]", -3.57980327012049140412e-02, 4.20082014423407961584e-03, -2.26270579934147913334e-06, 5.16063361553070450508e-04 ],
[ "s_gflux", "ν∇u[6]", -3.87729590851969090591e-05, 3.38326906830031177748e-05, -7.64232106453937395084e-08, 3.42855062975519724920e-06 ],
[ "s_gflux", "κ∇θ[1]", -2.63114521554794764460e-03, 3.13139570197398927828e-03, -2.58270397697685688597e-05, 1.80489106756528977114e-04 ],
[ "s_gflux", "κ∇θ[2]", -4.29150657020392189284e-03, 3.20181945576268351533e-03, 9.94194034856019440149e-04, 8.13274467049271117605e-04 ],
[ "s_gflux", "κ∇θ[3]", -3.08119171379054497821e-05, 9.12508944783092335127e-05, -4.12575332587978521639e-07, 1.92043362474637987870e-06 ],
[
"Q",
"u[1]",
-3.08415268094245687003e-01,
3.31683879748177812274e-01,
2.34355645025035056947e-03,
1.38278493625595393784e-02,
],
[
"Q",
"u[2]",
-9.30330187375882494694e-02,
1.45773331490709479041e-01,
6.38739141648009701308e-03,
1.38107523198905141754e-02,
],
[
"Q",
,
-4.60215148246349181615e-01,
3.97155090993862369686e-01,
-1.05814653709044253051e-04,
2.14356824554893188317e-01,
],
[
"Q",
,
3.90305009874997816885e-04,
9.28488770009523101123e+00,
2.49938688339290848717e+00,
2.17986650147491722862e+00,
],
[
"s_aux",
:y,
0.00000000000000000000e+00,
4.00000000000000046566e+06,
1.99999999999999976717e+06,
1.15573163901915703900e+06,
],
[
"s_aux",
:w,
-2.65432487944419423249e-04,
2.51335486222488370053e-04,
3.34985017281366756292e-07,
1.98256782258218657716e-05,
],
[
"s_aux",
:pkin,
-9.01203660410079376852e-01,
0.00000000000000000000e+00,
-3.33173652152760846334e-01,
2.54737286187841360796e-01,
],
[
"s_aux",
:wz0,
-3.16776291712146345464e-05,
3.89428424525183031852e-05,
4.05688221636862481177e-10,
1.10561449663397378925e-05,
],
]
parr = [
[ "Q", "u[1]", 12, 12, 12, 12 ],
[ "Q", "u[2]", 12, 12, 12, 12 ],
[ "Q", , 12, 12, 12, 12 ],
[ "Q", , 12, 12, 12, 12 ],
[ "s_aux", :y, 12, 12, 12, 12 ],
[ "s_aux", :w, 12, 12, 12, 12 ],
[ "s_aux", :pkin, 12, 12, 12, 12 ],
[ "s_aux", :wz0, 12, 12, 8, 12 ],
[ "s_gflux", "ν∇u[1]", 12, 12, 8, 12 ],
[ "s_gflux", "ν∇u[2]", 12, 12, 12, 12 ],
[ "s_gflux", "ν∇u[3]", 12, 12, 12, 12 ],
[ "s_gflux", "ν∇u[4]", 12, 12, 12, 12 ],
[ "s_gflux", "ν∇u[5]", 12, 12, 12, 12 ],
[ "s_gflux", "ν∇u[6]", 12, 12, 12, 12 ],
[ "s_gflux", "κ∇θ[1]", 12, 12, 12, 12 ],
[ "s_gflux", "κ∇θ[2]", 12, 12, 12, 12 ],
[ "s_gflux", "κ∇θ[3]", 12, 12, 12, 12 ],
["Q", "u[1]", 12, 12, 12, 12],
["Q", "u[2]", 12, 12, 12, 12],
["Q", , 12, 12, 12, 12],
["Q", , 12, 12, 12, 12],
["s_aux", :y, 12, 12, 12, 12],
["s_aux", :w, 12, 12, 12, 12],
["s_aux", :pkin, 12, 12, 12, 12],
["s_aux", :wz0, 12, 12, 8, 12],
]
# END SCPRINT
# SC ====================================================================================

append!(refVals ,[ varr ] )
append!(refPrecs,[ parr ] )

#! format: on
append!(refVals, [varr])
append!(refPrecs, [parr])
9 changes: 6 additions & 3 deletions src/Ocean/HydrostaticBoussinesq/HydrostaticBoussinesqModel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ multiplies ∇u by viscosity tensor and ∇θ by the diffusivity tensor
"""
function vars_state_gradient_flux(m::HBModel, T)
@vars begin
∇ʰu::T
ν∇u::SMatrix{3, 2, T, 6}
κ∇θ::SVector{3, T}
end
Expand Down Expand Up @@ -250,6 +251,9 @@ this computation is done pointwise at each nodal point
A::Vars,
t,
)
# store ∇ʰu for continuity equation (convert gradient to divergence)
D.∇ʰu = G.∇u[1, 1] + G.∇u[2, 2]

ν = viscosity_tensor(m)
D.ν∇u = -ν * G.∇u

Expand Down Expand Up @@ -619,9 +623,8 @@ function update_auxiliary_state_gradient!(
# store ∇ʰu as integrand for w
function f!(m::HBModel, Q, A, D, t)
@inbounds begin
ν = viscosity_tensor(m)
∇u = ν \ D.ν∇u # minus sign included in gradient flux
A.w = (∇u[1, 1] + ∇u[2, 2])
# load -∇ʰu as ∂ᶻw
A.w = -D.∇ʰu
end

return nothing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function run_hydrostatic_test(; imex::Bool = false, BC = nothing, refDat = ())
[
(solver.Q, "state"),
(solver.dg.state_auxiliary, "aux"),
(solver.dg.state_gradient_flux, "gradient"),
# (solver.dg.state_gradient_flux, "gradient"),
],
output_interval;
prec = 12,
Expand Down
6 changes: 1 addition & 5 deletions test/Ocean/HydrostaticBoussinesq/test_ocean_gyre.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,7 @@ function test_ocean_gyre(;
## every ntFreq timesteps.
nt_freq = 30
cb = ClimateMachine.StateCheck.sccreate(
[
(solver_config.Q, "Q"),
(solver_config.dg.state_auxiliary, "s_aux"),
(solver_config.dg.state_gradient_flux, "s_gflux"),
],
[(solver_config.Q, "Q"), (solver_config.dg.state_auxiliary, "s_aux")],
nt_freq;
prec = 12,
)
Expand Down
Loading

0 comments on commit 5ba1ce7

Please sign in to comment.