Skip to content

Commit 31f0bc9

Browse files
Merge pull request #258 from CliMA/ck/fix_warnings
Fix some warnings
2 parents e160d77 + fd56e83 commit 31f0bc9

File tree

3 files changed

+65
-70
lines changed

3 files changed

+65
-70
lines changed

src/utilities/convergence_condition.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,10 @@ updated_cache((; rate, order)::MinimumRateOfConvergence, cache, val, err, iter)
9292
Checks multiple `ConvergenceCondition`s, combining their results with either
9393
`all` or `any`.
9494
"""
95-
struct MultipleConditions{CC <: Union{typeof(all), typeof(any)}, C <: Tuple{Vararg{<:ConvergenceCondition}}} <:
96-
ConvergenceCondition
95+
struct MultipleConditions{
96+
CC <: Union{typeof(all), typeof(any)},
97+
C <: Tuple{Vararg{T} where {T <: ConvergenceCondition}},
98+
} <: ConvergenceCondition
9799
condition_combiner::CC
98100
conditions::C
99101
end

test/integrator_utils.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ data structure has an instance of any types in `t`.
66
"""
77
function any_reltype(found, obj, name, ets, pc = (); warn = true)
88
for pn in propertynames(obj)
9-
prop = getproperty(obj, pn)
9+
prop = if obj isa Base.Pairs
10+
values(obj)
11+
else
12+
getproperty(obj, pn)
13+
end
1014
pc_full = (pc..., ".", pn)
1115
pc_string = name * string(join(pc_full))
1216
for et in ets

test/problems.jl

Lines changed: 56 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
11
using DiffEqBase, ClimaTimeSteppers, LinearAlgebra, StaticArrays
22
using ClimaCore
33
using ClimaComms
4-
import ClimaCore.Domains as Domains
5-
import ClimaCore.Geometry as Geometry
6-
import ClimaCore.Meshes as Meshes
7-
import ClimaCore.Topologies as Topologies
8-
import ClimaCore.Spaces as Spaces
9-
import ClimaCore.Fields as Fields
10-
import ClimaCore.Operators as Operators
11-
12-
import Krylov
13-
Krylov.ktypeof(x::Fields.FieldVector) = ClimaComms.array_type(x){eltype(parent(x)), 1}
4+
import ClimaCore: Domains, Geometry, Meshes, Topologies, Spaces, Fields, Operators, Limiters
145

156
"""
167
Single variable linear ODE
@@ -449,6 +440,7 @@ Wfact!(W, Y, p, dtγ, t) = nothing
449440
2D diffusion test problem. See [`2D diffusion problem`](@ref) for more details.
450441
"""
451442
function climacore_2Dheat_test_cts(::Type{FT}) where {FT}
443+
context = ClimaComms.context()
452444
dss_tendency = true
453445

454446
n_elem_x = 2
@@ -465,7 +457,7 @@ function climacore_2Dheat_test_cts(::Type{FT}) where {FT}
465457
Domains.IntervalDomain(Geometry.YPoint(FT(0)), Geometry.YPoint(FT(1)), periodic = true),
466458
)
467459
mesh = Meshes.RectilinearMesh(domain, n_elem_x, n_elem_y)
468-
topology = Topologies.Topology2D(mesh)
460+
topology = Topologies.Topology2D(context, mesh)
469461
quadrature = Spaces.Quadratures.GLL{n_poly + 1}()
470462
space = Spaces.SpectralElementSpace2D(topology, quadrature)
471463
(; x, y) = Fields.coordinate_field(space)
@@ -564,6 +556,7 @@ end
564556
# Implemented in flux form, with an optional limiter and hyperdiffusion.
565557
# TODO: Use this as an integration test.
566558
function deformational_flow_test(::Type{FT}; use_limiter = true, use_hyperdiffusion = true) where {FT}
559+
context = ClimaComms.context()
567560
# Table III
568561
# Note: the paper uses "a" in place of "R"
569562
R = FT(6371220) # radius of Earth [m]
@@ -593,30 +586,28 @@ function deformational_flow_test(::Type{FT}; use_limiter = true, use_hyperdiffus
593586
# hyperviscosity coefficient [m^4] (specified in the limiter paper)
594587
D₄ = FT(6.6e14)
595588

596-
centers = ClimaCore.Geometry.LatLongZPoint.(rad2deg(φ_c), rad2deg.((λ_c1, λ_c2)), FT(0))
589+
centers = Geometry.LatLongZPoint.(rad2deg(φ_c), rad2deg.((λ_c1, λ_c2)), FT(0))
597590

598591
# custom discretization (paper's discretization results in a very slow test)
599592
vert_nelems = 10
600593
horz_nelems = 4
601594
horz_npoly = 3
602595

603-
vert_domain = ClimaCore.Domains.IntervalDomain(
604-
ClimaCore.Geometry.ZPoint(FT(0)),
605-
ClimaCore.Geometry.ZPoint(z_top);
606-
boundary_names = (:bottom, :top),
607-
)
608-
vert_mesh = ClimaCore.Meshes.IntervalMesh(vert_domain, nelems = vert_nelems)
609-
vert_cent_space = ClimaCore.Spaces.CenterFiniteDifferenceSpace(vert_mesh)
596+
vert_domain =
597+
Domains.IntervalDomain(Geometry.ZPoint(FT(0)), Geometry.ZPoint(z_top); boundary_names = (:bottom, :top))
598+
vert_mesh = Meshes.IntervalMesh(vert_domain, nelems = vert_nelems)
599+
z_topology = Topologies.IntervalTopology(context, vert_mesh)
600+
vert_cent_space = Spaces.CenterFiniteDifferenceSpace(z_topology)
610601

611-
horz_domain = ClimaCore.Domains.SphereDomain(R)
612-
horz_mesh = ClimaCore.Meshes.EquiangularCubedSphere(horz_domain, horz_nelems)
613-
horz_topology = ClimaCore.Topologies.Topology2D(horz_mesh)
614-
horz_quad = ClimaCore.Spaces.Quadratures.GLL{horz_npoly + 1}()
615-
horz_space = ClimaCore.Spaces.SpectralElementSpace2D(horz_topology, horz_quad)
602+
horz_domain = Domains.SphereDomain(R)
603+
horz_mesh = Meshes.EquiangularCubedSphere(horz_domain, horz_nelems)
604+
horz_topology = Topologies.Topology2D(context, horz_mesh)
605+
horz_quad = Spaces.Quadratures.GLL{horz_npoly + 1}()
606+
horz_space = Spaces.SpectralElementSpace2D(horz_topology, horz_quad)
616607

617-
cent_space = ClimaCore.Spaces.ExtrudedFiniteDifferenceSpace(horz_space, vert_cent_space)
618-
cent_coords = ClimaCore.Fields.coordinate_field(cent_space)
619-
face_space = ClimaCore.Spaces.FaceExtrudedFiniteDifferenceSpace(cent_space)
608+
cent_space = Spaces.ExtrudedFiniteDifferenceSpace(horz_space, vert_cent_space)
609+
cent_coords = Fields.coordinate_field(cent_space)
610+
face_space = Spaces.FaceExtrudedFiniteDifferenceSpace(cent_space)
620611

621612
# initial density (Equation 8)
622613
cent_ρ = @. p_0 / (R_d * T_0) * exp(-cent_coords.z / H)
@@ -627,7 +618,7 @@ function deformational_flow_test(::Type{FT}; use_limiter = true, use_hyperdiffus
627618
φ = deg2rad(coord.lat)
628619

629620
ds = map(centers) do center
630-
r = ClimaCore.Geometry.great_circle_distance(coord, center, horz_space.global_geometry)
621+
r = Geometry.great_circle_distance(coord, center, horz_space.global_geometry)
631622
return min(1, (r / R_t)^2 + ((z - z_c) / Z_t)^2)
632623
end
633624
in_slot = z > z_c && φ_c - FT(0.125) < φ < φ_c + FT(0.125)
@@ -640,11 +631,11 @@ function deformational_flow_test(::Type{FT}; use_limiter = true, use_hyperdiffus
640631
return (; q1, q2, q3, q4, q5)
641632
end
642633

643-
init_state = ClimaCore.Fields.FieldVector(; cent_ρ, cent_ρq = cent_ρ .* cent_q)
634+
init_state = Fields.FieldVector(; cent_ρ, cent_ρq = cent_ρ .* cent_q)
644635

645636
# current wind vector (Equations 15--26)
646-
current_cent_wind_vector = ClimaCore.Fields.Field(ClimaCore.Geometry.UVWVector{FT}, cent_space)
647-
current_face_wind_vector = ClimaCore.Fields.Field(ClimaCore.Geometry.UVWVector{FT}, face_space)
637+
current_cent_wind_vector = Fields.Field(Geometry.UVWVector{FT}, cent_space)
638+
current_face_wind_vector = Fields.Field(Geometry.UVWVector{FT}, face_space)
648639
function wind_vector(coord, ρ, t)
649640
z = coord.z
650641
φ = deg2rad(coord.lat)
@@ -667,45 +658,42 @@ function deformational_flow_test(::Type{FT}; use_limiter = true, use_hyperdiffus
667658
ω = ω_0 * sin(λ′) * cos(φ) * cos(2 * FT(π) * t / τ) * s
668659
w = -ω / (g * ρ)
669660

670-
return ClimaCore.Geometry.UVWVector(u, v, w)
661+
return Geometry.UVWVector(u, v, w)
671662
end
672663

673-
horz_div = ClimaCore.Operators.Divergence()
674-
horz_wdiv = ClimaCore.Operators.WeakDivergence()
675-
horz_grad = ClimaCore.Operators.Gradient()
664+
horz_div = Operators.Divergence()
665+
horz_wdiv = Operators.WeakDivergence()
666+
horz_grad = Operators.Gradient()
676667
cent_χ = similar(cent_q)
677668
function T_lim!(tendency, state, _, t)
678669
@. current_cent_wind_vector = wind_vector(cent_coords, state.cent_ρ, t)
679670
@. tendency.cent_ρ = -horz_div(state.cent_ρ * current_cent_wind_vector)
680671
@. tendency.cent_ρq = -horz_div(state.cent_ρq * current_cent_wind_vector)
681672
use_hyperdiffusion || return nothing
682673
@. cent_χ = horz_wdiv(horz_grad(state.cent_ρq / state.cent_ρ))
683-
ClimaCore.Spaces.weighted_dss!(cent_χ)
674+
Spaces.weighted_dss!(cent_χ)
684675
@. tendency.cent_ρq += -D₄ * horz_wdiv(state.cent_ρ * horz_grad(cent_χ))
685676
return nothing
686677
end
687678

688-
limiter = ClimaCore.Limiters.QuasiMonotoneLimiter(cent_q; rtol = FT(0))
679+
limiter = Limiters.QuasiMonotoneLimiter(cent_q; rtol = FT(0))
689680
function lim!(state, _, t, ref_state)
690681
use_limiter || return nothing
691-
ClimaCore.Limiters.compute_bounds!(limiter, ref_state.cent_ρq, ref_state.cent_ρ)
692-
ClimaCore.Limiters.apply_limiter!(state.cent_ρq, state.cent_ρ, limiter)
682+
Limiters.compute_bounds!(limiter, ref_state.cent_ρq, ref_state.cent_ρ)
683+
Limiters.apply_limiter!(state.cent_ρq, state.cent_ρ, limiter)
693684
return nothing
694685
end
695686

696-
vert_div = ClimaCore.Operators.DivergenceF2C()
697-
vert_interp = ClimaCore.Operators.InterpolateC2F(
698-
top = ClimaCore.Operators.Extrapolate(),
699-
bottom = ClimaCore.Operators.Extrapolate(),
700-
)
687+
vert_div = Operators.DivergenceF2C()
688+
vert_interp = Operators.InterpolateC2F(top = Operators.Extrapolate(), bottom = Operators.Extrapolate())
701689
function T_exp!(tendency, state, _, t)
702690
@. current_face_wind_vector = wind_vector(face_coords, vert_interp(state.cent_ρ), t)
703691
@. tendency.cent_ρ = -vert_div(vert_interp(state.cent_ρ) * current_face_wind_vector)
704692
@. tendency.cent_ρq = -vert_div(vert_interp(state.cent_ρq) * current_face_wind_vector)
705693
end
706694

707695
function dss!(state, _, t)
708-
ClimaCore.Spaces.weighted_dss!(state.q)
696+
Spaces.weighted_dss!(state.q)
709697
end
710698

711699
function analytic_sol(t)
@@ -731,6 +719,7 @@ end
731719
# (https://gmd.copernicus.org/articles/5/887/2012/gmd-5-887-2012.pdf)
732720
# Implemented in flux form, with an optional limiter and hyperdiffusion.
733721
function horizontal_deformational_flow_test(::Type{FT}; use_limiter = true, use_hyperdiffusion = true) where {FT}
722+
context = ClimaComms.context()
734723
# constants (using the same notation as deformational_flow_test)
735724
R = FT(6371220) # radius of Earth [m]
736725
τ = 60 * 60 * 24 * FT(12) # period of motion (12 days) [s]
@@ -740,18 +729,18 @@ function horizontal_deformational_flow_test(::Type{FT}; use_limiter = true, use_
740729
R_t = R / 2 # horizontal half-width of tracers [m]
741730
D₄ = FT(6.6e14) # hyperviscosity coefficient [m^4] (specified in the limiter paper)
742731

743-
centers = ClimaCore.Geometry.LatLongPoint.(rad2deg(φ_c), rad2deg.((λ_c1, λ_c2)))
732+
centers = Geometry.LatLongPoint.(rad2deg(φ_c), rad2deg.((λ_c1, λ_c2)))
744733

745734
# 1.5° resolution on the equator: 360° / (4 * nelems * npoly) = 1.5°
746735
nelems = 20
747736
npoly = 3
748737

749-
domain = ClimaCore.Domains.SphereDomain(R)
750-
mesh = ClimaCore.Meshes.EquiangularCubedSphere(domain, nelems)
751-
topology = ClimaCore.Topologies.Topology2D(mesh)
752-
quad = ClimaCore.Spaces.Quadratures.GLL{npoly + 1}()
753-
space = ClimaCore.Spaces.SpectralElementSpace2D(topology, quad)
754-
coords = ClimaCore.Fields.coordinate_field(space)
738+
domain = Domains.SphereDomain(R)
739+
mesh = Meshes.EquiangularCubedSphere(domain, nelems)
740+
topology = Topologies.Topology2D(context, mesh)
741+
quad = Spaces.Quadratures.GLL{npoly + 1}()
742+
space = Spaces.SpectralElementSpace2D(topology, quad)
743+
coords = Fields.coordinate_field(space)
755744

756745
# initial conditions (Section 2.2)
757746
ρ = ones(space)
@@ -760,15 +749,15 @@ function horizontal_deformational_flow_test(::Type{FT}; use_limiter = true, use_
760749
λ = deg2rad(coord.long)
761750

762751
hs = map(centers) do center
763-
center′ = ClimaCore.Geometry.CartesianPoint(center, space.global_geometry)
764-
coord′ = ClimaCore.Geometry.CartesianPoint(coord, space.global_geometry)
752+
center′ = Geometry.CartesianPoint(center, space.global_geometry)
753+
coord′ = Geometry.CartesianPoint(coord, space.global_geometry)
765754
dist_squared = (coord′.x1 - center′.x1)^2 + (coord′.x2 - center′.x2)^2 + (coord′.x3 - center′.x3)^2
766755
# Note: the paper doesn't divide by R^2, which only works if R = 1
767756
return FT(0.95) * exp(-5 * dist_squared / R^2)
768757
end
769758
gaussian_hills = hs[1] + hs[2]
770759
rs = map(centers) do center
771-
return ClimaCore.Geometry.great_circle_distance(coord, center, space.global_geometry)
760+
return Geometry.great_circle_distance(coord, center, space.global_geometry)
772761
end
773762
cosine_bells = if rs[1] < R_t
774763
FT(0.1) + FT(0.9) * (1 + cos(FT(π) * rs[1] / R_t)) / 2
@@ -791,10 +780,10 @@ function horizontal_deformational_flow_test(::Type{FT}; use_limiter = true, use_
791780

792781
return (; gaussian_hills, cosine_bells, slotted_cylinders)
793782
end
794-
init_state = ClimaCore.Fields.FieldVector(; ρ, ρq = ρ .* q)
783+
init_state = Fields.FieldVector(; ρ, ρq = ρ .* q)
795784

796785
# current wind vector (Section 2.3)
797-
current_wind_vector = ClimaCore.Fields.Field(ClimaCore.Geometry.UVVector{FT}, space)
786+
current_wind_vector = Fields.Field(Geometry.UVVector{FT}, space)
798787
function wind_vector(coord, t)
799788
φ = deg2rad(coord.lat)
800789
λ = deg2rad(coord.long)
@@ -805,35 +794,35 @@ function horizontal_deformational_flow_test(::Type{FT}; use_limiter = true, use_
805794
u = k * sin(λ′)^2 * sin(2 * φ) * cos(FT(π) * t / τ) + 2 * FT(π) * R / τ * cos(φ)
806795
v = k * sin(2 * λ′) * cos(φ) * cos(FT(π) * t / τ)
807796

808-
return ClimaCore.Geometry.UVVector(u, v)
797+
return Geometry.UVVector(u, v)
809798
end
810799

811-
div = ClimaCore.Operators.Divergence()
812-
wdiv = ClimaCore.Operators.WeakDivergence()
813-
grad = ClimaCore.Operators.Gradient()
800+
div = Operators.Divergence()
801+
wdiv = Operators.WeakDivergence()
802+
grad = Operators.Gradient()
814803
χ = similar(q)
815804
function T_lim!(tendency, state, _, t)
816805
@. current_wind_vector = wind_vector(coords, t)
817806
@. tendency.ρ = -div(state.ρ * current_wind_vector)
818807
@. tendency.ρq = -div(state.ρq * current_wind_vector)
819808
use_hyperdiffusion || return nothing
820809
@. χ = wdiv(grad(state.ρq / state.ρ))
821-
ClimaCore.Spaces.weighted_dss!(χ)
810+
Spaces.weighted_dss!(χ)
822811
@. tendency.ρq += -D₄ * wdiv(state.ρ * grad(χ))
823812
return nothing
824813
end
825814

826-
limiter = ClimaCore.Limiters.QuasiMonotoneLimiter(q; rtol = FT(0))
815+
limiter = Limiters.QuasiMonotoneLimiter(q; rtol = FT(0))
827816
function lim!(state, _, t, ref_state)
828817
use_limiter || return nothing
829-
ClimaCore.Limiters.compute_bounds!(limiter, ref_state.ρq, ref_state.ρ)
830-
ClimaCore.Limiters.apply_limiter!(state.ρq, state.ρ, limiter)
818+
Limiters.compute_bounds!(limiter, ref_state.ρq, ref_state.ρ)
819+
Limiters.apply_limiter!(state.ρq, state.ρ, limiter)
831820
return nothing
832821
end
833822

834823
function dss!(state, _, t)
835-
ClimaCore.Spaces.weighted_dss!(state.ρ)
836-
ClimaCore.Spaces.weighted_dss!(state.ρq)
824+
Spaces.weighted_dss!(state.ρ)
825+
Spaces.weighted_dss!(state.ρq)
837826
end
838827

839828
function analytic_sol(t)

0 commit comments

Comments
 (0)