@@ -6,8 +6,7 @@ import ClimaComms
6
6
@static pkgversion (ClimaComms) >= v " 0.6" && ClimaComms. @import_required_backends
7
7
import ClimaCore as CC
8
8
import ClimaCoupler: ConservationChecker, Interfacer
9
-
10
- REGRID_DIR = @isdefined (REGRID_DIR) ? REGRID_DIR : joinpath (" " , " regrid_tmp/" )
9
+ import ClimaCoupler. Utilities: integral
11
10
12
11
get_slab_energy (slab_sim, T_sfc) =
13
12
slab_sim. integrator. p. params. ρ .* slab_sim. integrator. p. params. c .* T_sfc .* slab_sim. integrator. p. params. h
@@ -17,8 +16,8 @@ struct TestAtmos{I} <: Interfacer.AtmosModelSimulation
17
16
end
18
17
Interfacer. name (s:: TestAtmos ) = " TestAtmos"
19
18
Interfacer. get_field (s:: TestAtmos , :: Val{:radiative_energy_flux_toa} ) = ones (s. i. space) .* 200
20
- Interfacer. get_field (s:: TestAtmos , :: Val{:water} ) = ones ( s. i. space)
21
- Interfacer. get_field (s:: TestAtmos , :: Val{:energy} ) = ones ( s. i. space) .* CC . Spaces . undertype (s . i . space)( 1e6 )
19
+ Interfacer. get_field (s:: TestAtmos , :: Val{:water} ) = s. i. water
20
+ Interfacer. get_field (s:: TestAtmos , :: Val{:energy} ) = s. i. energy
22
21
23
22
struct TestOcean{I} <: Interfacer.SurfaceModelSimulation
24
23
i:: I
@@ -41,7 +40,10 @@ for FT in (Float32, Float64)
41
40
space = CC. CommonSpaces. CubedSphereSpace (FT; radius = FT (6371e3 ), n_quad_points = 4 , h_elem = 4 )
42
41
43
42
# set up model simulations
44
- atmos = TestAtmos ((; space = space))
43
+ initial_energy = ones (space) .* CC. Spaces. undertype (space)(1e6 )
44
+ initial_water = ones (space) .* CC. Spaces. undertype (space)(1e5 )
45
+
46
+ atmos = TestAtmos ((; space = space, energy = initial_energy, water = initial_water))
45
47
land = TestOcean ((; space = space))
46
48
ocean = TestLand ((; space = space))
47
49
ice = Interfacer. SurfaceStub ((; area_fraction = CC. Fields. ones (space) .* FT (0.5 )))
@@ -84,13 +86,28 @@ for FT in (Float32, Float64)
84
86
P = cf. P_liq
85
87
Δt = float (cs. Δt_cpl)
86
88
89
+ volume = integral (ones (space))
90
+
91
+ area_fraction_scaling =
92
+ Interfacer. get_field (land, Val (:area_fraction )) .+ Interfacer. get_field (ocean, Val (:area_fraction ))
93
+ water_from_precipitation = integral (P .* area_fraction_scaling) .* FT (Δt)
94
+ energy_from_radiation = integral (F_r) .* FT (Δt)
95
+ energy_per_unit_cell = CC. Fields. ones (space) .* energy_from_radiation ./ volume
96
+ water_per_unit_cell = CC. Fields. ones (space) .* water_from_precipitation ./ volume
97
+
87
98
# analytical solution
88
- tot_energy_an = sum (FT .(F_r .* 3 Δt .+ 1e6 .* 1.25 ))
89
- tot_water_an = sum (FT .(.- P .* 3 Δt .* 0.5 .+ CC. Fields. ones (space)))
99
+ # Only ocean and atmos have energy
100
+ area_fraction_scaling = CC. Fields. ones (space) .+ Interfacer. get_field (ocean, Val (:area_fraction ))
101
+ tot_energy_an = integral (area_fraction_scaling .* FT .(initial_energy)) + energy_from_radiation
102
+ tot_water_an = integral (FT .(initial_water)) - water_from_precipitation
90
103
91
104
# run check_conservation!
92
105
ConservationChecker. check_conservation! (cs, runtime_check = true )
106
+ atmos. i. energy .- = energy_per_unit_cell
107
+ atmos. i. water .+ = water_per_unit_cell
93
108
ConservationChecker. check_conservation! (cs, runtime_check = true )
109
+ atmos. i. energy .- = energy_per_unit_cell
110
+ atmos. i. water .+ = water_per_unit_cell
94
111
ConservationChecker. check_conservation! (cs, runtime_check = true )
95
112
96
113
total_energy = cs. conservation_checks. energy. sums. total
@@ -118,7 +135,10 @@ for FT in (Float32, Float64)
118
135
space = CC. CommonSpaces. CubedSphereSpace (FT; radius = FT (6371e3 ), n_quad_points = 4 , h_elem = 4 )
119
136
120
137
# set up model simulations
121
- atmos = TestAtmos ((; space = space))
138
+ initial_energy = ones (space) .* CC. Spaces. undertype (space)(1e6 )
139
+ initial_water = ones (space) .* CC. Spaces. undertype (space)(1e5 )
140
+
141
+ atmos = TestAtmos ((; space = space, energy = initial_energy, water = initial_water))
122
142
land = TestOcean ((; space = space))
123
143
ocean = TestLand ((; space = space))
124
144
ice = Interfacer. SurfaceStub ((; area_fraction = CC. Fields. ones (space) .* FT (0.5 )))
0 commit comments