From 5bb5547d2f22e00ed7e75a1bb79ca6299fc9297f Mon Sep 17 00:00:00 2001 From: Gregory Wagner Date: Thu, 12 Mar 2026 15:13:16 -0700 Subject: [PATCH 1/2] manually iterate to compute the interface state --- .../compute_interface_state.jl | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/EarthSystemModels/InterfaceComputations/compute_interface_state.jl b/src/EarthSystemModels/InterfaceComputations/compute_interface_state.jl index e52b5a53a..97e0f5026 100644 --- a/src/EarthSystemModels/InterfaceComputations/compute_interface_state.jl +++ b/src/EarthSystemModels/InterfaceComputations/compute_interface_state.jl @@ -43,16 +43,33 @@ end stop_criteria = flux_formulation.solver_stop_criteria iteration = 0 - while iterating(Ψₛⁿ, Ψₛ⁻, iteration, stop_criteria) - Ψₛ⁻ = Ψₛⁿ - Ψₛⁿ = iterate_interface_state(flux_formulation, + #while iterating(Ψₛⁿ, Ψₛ⁻, iteration, stop_criteria) + # Ψₛ⁻ = Ψₛⁿ + Ψₛ¹ = iterate_interface_state(flux_formulation, Ψₛ⁻, Ψₐ, Ψᵢ, downwelling_radiation, interface_properties, atmosphere_properties, interior_properties) - iteration += 1 - end + + Ψₛ² = iterate_interface_state(flux_formulation, + Ψₛ¹, Ψₐ, Ψᵢ, + downwelling_radiation, + interface_properties, + atmosphere_properties, + interior_properties) + + Ψₛ³ = iterate_interface_state(flux_formulation, + Ψₛ², Ψₐ, Ψᵢ, + downwelling_radiation, + interface_properties, + atmosphere_properties, + interior_properties) + + Ψₛⁿ = Ψₛ³ + + #iteration += 1 + #end return Ψₛⁿ end From 420be8bb46ffe5ab348e3b99b68a072cbf92ea20 Mon Sep 17 00:00:00 2001 From: Gregory Wagner Date: Thu, 12 Mar 2026 15:48:20 -0700 Subject: [PATCH 2/2] implement AbstractTurbulentFluxFormulation --- .../InterfaceComputations.jl | 3 + .../coefficient_based_turbulent_fluxes.jl | 2 +- .../compute_interface_state.jl | 58 +++++++++++++------ .../similarity_theory_turbulent_fluxes.jl | 2 +- 4 files changed, 44 insertions(+), 21 deletions(-) diff --git a/src/EarthSystemModels/InterfaceComputations/InterfaceComputations.jl b/src/EarthSystemModels/InterfaceComputations/InterfaceComputations.jl index ed93f8c9c..2748e38fb 100644 --- a/src/EarthSystemModels/InterfaceComputations/InterfaceComputations.jl +++ b/src/EarthSystemModels/InterfaceComputations/InterfaceComputations.jl @@ -71,6 +71,9 @@ include("tabulated_albedo.jl") # Turbulent fluxes include("roughness_lengths.jl") include("interface_states.jl") + +abstract type AbstractTurbulentFluxFormulation{S} end + include("compute_interface_state.jl") include("similarity_theory_turbulent_fluxes.jl") include("coefficient_based_turbulent_fluxes.jl") diff --git a/src/EarthSystemModels/InterfaceComputations/coefficient_based_turbulent_fluxes.jl b/src/EarthSystemModels/InterfaceComputations/coefficient_based_turbulent_fluxes.jl index b192e9baa..cc2213d74 100644 --- a/src/EarthSystemModels/InterfaceComputations/coefficient_based_turbulent_fluxes.jl +++ b/src/EarthSystemModels/InterfaceComputations/coefficient_based_turbulent_fluxes.jl @@ -7,7 +7,7 @@ A structure for computing turbulent fluxes using constant bulk transfer coeffici $(TYPEDFIELDS) """ -struct CoefficientBasedFluxes{CD, CH, CQ, S} +struct CoefficientBasedFluxes{CD, CH, CQ, S} <: AbstractTurbulentFluxFormulation{S} "Coefficient for momentum transfer" drag_coefficient :: CD "Coefficient for sensible heat transfer" diff --git a/src/EarthSystemModels/InterfaceComputations/compute_interface_state.jl b/src/EarthSystemModels/InterfaceComputations/compute_interface_state.jl index 97e0f5026..883522dab 100644 --- a/src/EarthSystemModels/InterfaceComputations/compute_interface_state.jl +++ b/src/EarthSystemModels/InterfaceComputations/compute_interface_state.jl @@ -43,35 +43,55 @@ end stop_criteria = flux_formulation.solver_stop_criteria iteration = 0 - #while iterating(Ψₛⁿ, Ψₛ⁻, iteration, stop_criteria) - # Ψₛ⁻ = Ψₛⁿ - Ψₛ¹ = iterate_interface_state(flux_formulation, + while iterating(Ψₛⁿ, Ψₛ⁻, iteration, stop_criteria) + Ψₛ⁻ = Ψₛⁿ + Ψₛⁿ = iterate_interface_state(flux_formulation, Ψₛ⁻, Ψₐ, Ψᵢ, downwelling_radiation, interface_properties, atmosphere_properties, interior_properties) - Ψₛ² = iterate_interface_state(flux_formulation, - Ψₛ¹, Ψₐ, Ψᵢ, - downwelling_radiation, - interface_properties, - atmosphere_properties, - interior_properties) + iteration += 1 + end - Ψₛ³ = iterate_interface_state(flux_formulation, - Ψₛ², Ψₐ, Ψᵢ, - downwelling_radiation, - interface_properties, - atmosphere_properties, - interior_properties) + return Ψₛⁿ +end + +##### +##### Solver with unrolled iterations +##### + +struct TenUnrolledIterations end - Ψₛⁿ = Ψₛ³ +@inline function compute_interface_state(flux_formulation::AbstractTurbulentFluxFormulation{<:TenUnrolledIterations}, + initial_interface_state, + atmosphere_state, + interior_state, + downwelling_radiation, + interface_properties, + atmosphere_properties, + interior_properties) - #iteration += 1 - #end + args = (downwelling_radiation, + interface_properties, + atmosphere_properties, + interior_properties) - return Ψₛⁿ + Ψₐ = atmosphere_state + Ψᵢ = interior_state + Ψₛ⁰ = initial_interface_state + Ψₛ¹ = iterate_interface_state(flux_formulation, Ψₛ⁰, Ψₐ, Ψᵢ, args...) + Ψₛ² = iterate_interface_state(flux_formulation, Ψₛ¹, Ψₐ, Ψᵢ, args...) + Ψₛ³ = iterate_interface_state(flux_formulation, Ψₛ², Ψₐ, Ψᵢ, args...) + Ψₛ⁴ = iterate_interface_state(flux_formulation, Ψₛ³, Ψₐ, Ψᵢ, args...) + Ψₛ⁵ = iterate_interface_state(flux_formulation, Ψₛ⁴, Ψₐ, Ψᵢ, args...) + Ψₛ⁶ = iterate_interface_state(flux_formulation, Ψₛ⁵, Ψₐ, Ψᵢ, args...) + Ψₛ⁷ = iterate_interface_state(flux_formulation, Ψₛ⁶, Ψₐ, Ψᵢ, args...) + Ψₛ⁸ = iterate_interface_state(flux_formulation, Ψₛ⁷, Ψₐ, Ψᵢ, args...) + Ψₛ⁹ = iterate_interface_state(flux_formulation, Ψₛ⁸, Ψₐ, Ψᵢ, args...) + + return iterate_interface_state(flux_formulation, Ψₛ⁹, Ψₐ, Ψᵢ, args...) end """ diff --git a/src/EarthSystemModels/InterfaceComputations/similarity_theory_turbulent_fluxes.jl b/src/EarthSystemModels/InterfaceComputations/similarity_theory_turbulent_fluxes.jl index dc02ebfd9..a7d0c8233 100644 --- a/src/EarthSystemModels/InterfaceComputations/similarity_theory_turbulent_fluxes.jl +++ b/src/EarthSystemModels/InterfaceComputations/similarity_theory_turbulent_fluxes.jl @@ -13,7 +13,7 @@ import Thermodynamics.Parameters: Rv_over_Rd ##### Bulk turbulent fluxes based on similarity theory ##### -struct SimilarityTheoryFluxes{FT, UF, R, B, S} +struct SimilarityTheoryFluxes{FT, UF, R, B, S} <: AbstractTurbulentFluxFormulation{S} von_karman_constant :: FT # parameter turbulent_prandtl_number :: FT # parameter gustiness_parameter :: FT # bulk velocity parameter