-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
442: add dss_state! function r=juliasloan25 a=juliasloan25 Co-authored-by: Julia Sloan <jsloan@caltech.edu>
- Loading branch information
Showing
14 changed files
with
273 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using Test | ||
import ClimaCoupler | ||
using ClimaCoupler.TestHelper: create_space | ||
using ClimaCore: Fields, Spaces | ||
|
||
include(pkgdir(ClimaCoupler, "experiments/AMIP/modular/components/land/bucket_init.jl")) | ||
include(pkgdir(ClimaCoupler, "experiments/AMIP/modular/components/land/bucket_utils.jl")) | ||
|
||
# struct DummySimulationBucket{I} <: BucketSimulation | ||
# integrator::I | ||
# end | ||
|
||
# TODO bucket doesn't currently work with Float32, but we want to eventually test with both FTs | ||
for FT in (Float64,) | ||
@testset "dss_state! BucketSimulation for FT=$FT" begin | ||
# use TestHelper to create space, extract surface space | ||
subsurface_space = create_space(FT, nz = 2) | ||
surface_space = subsurface_space.horizontal_space | ||
|
||
# set up objects for test | ||
dss_buffer_3d = Spaces.create_dss_buffer(Fields.zeros(subsurface_space)) | ||
dss_buffer_2d = Spaces.create_dss_buffer(Fields.zeros(surface_space)) | ||
|
||
integrator = (; | ||
u = Fields.FieldVector( | ||
state_field1 = Fields.ones(surface_space), | ||
state_field_2d = Fields.zeros(surface_space), | ||
state_field_3d = Fields.zeros(subsurface_space), | ||
), | ||
p = (; | ||
cache_field = Fields.zeros(surface_space), | ||
dss_buffer_2d = dss_buffer_2d, | ||
dss_buffer_3d = dss_buffer_3d, | ||
), | ||
t = FT(0), | ||
) | ||
integrator_copy = deepcopy(integrator) | ||
# sim = DummySimulationBucket(integrator) | ||
sim = BucketSimulation(nothing, nothing, nothing, integrator, nothing) | ||
|
||
# make fields non-constant to check the impact of the dss step | ||
for i in eachindex(parent(sim.integrator.u.state_field_2d)) | ||
parent(sim.integrator.u.state_field_2d)[i] = sin(i) | ||
end | ||
for i in eachindex(parent(sim.integrator.u.state_field_3d)) | ||
parent(sim.integrator.u.state_field_3d)[i] = sin(i) | ||
end | ||
|
||
# apply DSS | ||
dss_state!(sim) | ||
|
||
# test that uniform field and cache are unchanged, non-constant is changed | ||
# note: uniform field is changed slightly by dss | ||
@test sim.integrator.u.state_field1 ≈ integrator_copy.u.state_field1 | ||
@test sim.integrator.u.state_field_2d != integrator_copy.u.state_field_2d | ||
@test sim.integrator.u.state_field_3d != integrator_copy.u.state_field_3d | ||
@test sim.integrator.p.cache_field == integrator_copy.p.cache_field | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using Test | ||
import ClimaCoupler | ||
using ClimaCoupler.Interfacer: AtmosModelSimulation | ||
using ClimaCoupler.TestHelper: create_space | ||
using ClimaCore: Fields, Spaces | ||
|
||
include(pkgdir(ClimaCoupler, "experiments/AMIP/modular/components/atmosphere/climaatmos_init.jl")) | ||
|
||
for FT in (Float32, Float64) | ||
@testset "dss_state! ClimaAtmosSimulation for FT=$FT" begin | ||
# use TestHelper to create space | ||
boundary_space = create_space(FT) | ||
|
||
# set up objects for test | ||
integrator = (; | ||
u = (; state_field1 = FT.(Fields.ones(boundary_space)), state_field2 = FT.(Fields.zeros(boundary_space))), | ||
p = (; cache_field = FT.(Fields.zeros(boundary_space))), | ||
) | ||
integrator_copy = deepcopy(integrator) | ||
sim = ClimaAtmosSimulation(nothing, nothing, nothing, integrator) | ||
|
||
# make field non-constant to check the impact of the dss step | ||
for i in eachindex(parent(sim.integrator.u.state_field2)) | ||
parent(sim.integrator.u.state_field2)[i] = FT(sin(i)) | ||
end | ||
|
||
# apply DSS | ||
dss_state!(sim) | ||
|
||
# test that uniform field and cache are unchanged, non-constant is changed | ||
# note: uniform field is changed slightly by dss | ||
@test sim.integrator.u.state_field1 ≈ integrator_copy.u.state_field1 | ||
@test sim.integrator.u.state_field2 != integrator_copy.u.state_field2 | ||
@test sim.integrator.p.cache_field == integrator_copy.p.cache_field | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using Test | ||
import ClimaCoupler | ||
using ClimaCoupler.Interfacer: OceanModelSimulation | ||
using ClimaCoupler.TestHelper: create_space | ||
using ClimaCore | ||
using ClimaCore: Fields, Spaces | ||
import CLIMAParameters as CP | ||
import Thermodynamics.Parameters as TDP | ||
|
||
include(pkgdir(ClimaCoupler, "experiments/AMIP/modular/components/ocean/slab_ocean_init.jl")) | ||
|
||
for FT in (Float32, Float64) | ||
@testset "dss_state! SlabOceanSimulation for FT=$FT" begin | ||
# use TestHelper to create space | ||
boundary_space = create_space(FT) | ||
|
||
# construct dss buffer to put in cache | ||
dss_buffer = Spaces.create_dss_buffer(Fields.zeros(boundary_space)) | ||
|
||
# set up objects for test | ||
integrator = (; | ||
u = (; state_field1 = FT.(Fields.ones(boundary_space)), state_field2 = FT.(Fields.zeros(boundary_space))), | ||
p = (; cache_field = FT.(Fields.zeros(boundary_space)), dss_buffer = dss_buffer), | ||
) | ||
integrator_copy = deepcopy(integrator) | ||
sim = SlabOceanSimulation(nothing, nothing, nothing, integrator) | ||
|
||
# make field non-constant to check the impact of the dss step | ||
for i in eachindex(parent(sim.integrator.u.state_field2)) | ||
parent(sim.integrator.u.state_field2)[i] = FT(sin(i)) | ||
end | ||
|
||
# apply DSS | ||
dss_state!(sim) | ||
|
||
# test that uniform field and cache are unchanged, non-constant is changed | ||
# note: uniform field is changed slightly by dss | ||
@test sim.integrator.u.state_field1 ≈ integrator_copy.u.state_field1 | ||
@test sim.integrator.u.state_field2 != integrator_copy.u.state_field2 | ||
@test sim.integrator.p.cache_field == integrator_copy.p.cache_field | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.