From dbd52413c6b449552542b773b0e74f5752859bc7 Mon Sep 17 00:00:00 2001 From: Brian Groenke <brian.groenke@awi.de> Date: Wed, 9 Oct 2024 14:06:47 +0200 Subject: [PATCH] Rename computefluxes! to computeprognostic! --- docs/src/manual/architecture.md | 4 ++-- docs/src/manual/overview.md | 6 +++--- src/CryoGrid.jl | 2 +- src/Physics/Heat/heat_conduction.jl | 4 ++-- src/Physics/Heat/heat_implicit.jl | 4 ++-- src/Physics/Heat/heat_water.jl | 6 +++--- src/Physics/Hydrology/water_balance.jl | 4 ++-- src/Physics/Lakes/lake_simple.jl | 2 +- src/Physics/Salt/salt_diffusion.jl | 2 +- src/Physics/Snow/snow_bulk.jl | 12 ++++++------ src/Physics/Snow/snow_lite.jl | 2 +- src/Physics/Snow/snowpack.jl | 8 ++++---- src/Physics/Sources/Sources.jl | 6 +++--- src/Physics/Surface/SWB/coupled_sweb.jl | 6 +++--- src/Physics/Surface/SWB/swb.jl | 2 +- src/Tiles/stratigraphy.jl | 4 ++-- src/Tiles/tile.jl | 12 ++++++------ src/Tiles/tile_base.jl | 8 ++++---- src/coupling.jl | 2 +- src/methods.jl | 14 +++++++------- test/Physics/Heat/heat_conduction_tests.jl | 2 +- test/Physics/Hydrology/water_balance_tests.jl | 6 +++--- test/Physics/Salt/runtests.jl | 4 ++-- test/Physics/Sources/runtests.jl | 8 ++++---- test/Physics/Surface/swb_tests.jl | 4 ++-- 25 files changed, 67 insertions(+), 67 deletions(-) diff --git a/docs/src/manual/architecture.md b/docs/src/manual/architecture.md index 7bfd05e4..eb0720e2 100644 --- a/docs/src/manual/architecture.md +++ b/docs/src/manual/architecture.md @@ -54,7 +54,7 @@ The `CryoGrid` module defines three primary methods that can be used to implemen 1. [`computediagnostic!`](@ref) updates all (non-flux) state variables and/or derived quantities based on the current (prognostic) state. 2. [`interact!`](@ref) defines interactions between adjacent layers in the stratigraphy, including fluxes over the layer boundary. -3. [`computefluxes!`](@ref) computes all internal fluxes (and the divergence thereof) within each layer, after boundary fluxes are taken into account by `interact!`. +3. [`computeprognostic!`](@ref) computes all internal fluxes (and the divergence thereof) within each layer, after boundary fluxes are taken into account by `interact!`. Layer and/or process specific implementations of each of these methods can generally assume that the previous methods have already been invoked by the caller (it is the responsibility of the calling code to ensure that this is the case). This is, for example, the order in which these methods will be invoked by `tile(du, u, p t)`. @@ -82,7 +82,7 @@ In order to facilitate modularity and ease-of-use, CryoGrid.jl provides an autom `Prognostic`(@ref) state variables fully define the state of the system at any given time `t`. They form what is typically called the "phase space" or "state space" in the mathematics and engineering literature. In order to be compatible with standard ODE solvers (e.g. like those in `OrdinaryDiffEq`), CryoGrid.jl automatically assembles prognostic state variables into a single array `u` (and its corresponding time derivative `du`) which is returned when initializing a `Tile` with the `initialcondition!` method. Note again that this array should always fully define the state of the system. -`Diagnostic`(@ref) state variables act as caches for intermediate and derived quantities defined by the model. They also may, in some cases, provide a means of coupling between different processes (e.g. the heat and water flux variables `jH` and `jw` might be updated by more than one `Process`). For any model configuration, all diagnostic variables should be fully updated (and thus consistent) with the given prognostic state after invoking `computediagnostic!`, `interact!`, and `computefluxes!`. +`Diagnostic`(@ref) state variables act as caches for intermediate and derived quantities defined by the model. They also may, in some cases, provide a means of coupling between different processes (e.g. the heat and water flux variables `jH` and `jw` might be updated by more than one `Process`). For any model configuration, all diagnostic variables should be fully updated (and thus consistent) with the given prognostic state after invoking `computediagnostic!`, `interact!`, and `computeprognostic!`. When a `Tile` is constructed, all variables defined by each layer in the `Stratigraphy` are collected and then intiailized in [`StateVars`](@ref) according to the given `DiscretizationStrategy`. diff --git a/docs/src/manual/overview.md b/docs/src/manual/overview.md index bb5cd1ee..e58d8030 100644 --- a/docs/src/manual/overview.md +++ b/docs/src/manual/overview.md @@ -69,12 +69,12 @@ When the `HeatBalance` process is assigned to a `Soil` layer, `Tile` will invoke Each variable definition consists of a name (a Julia `Symbol`), a type, and a shape. For variables discretized on the grid, the shape is specified by `OnGrid`, which will generate an array of the appropriate size when the model is compiled. The arguments `Cells` and `Edges` specify whether the variable should be defined on the grid cells or edges respecitvely. -The real work finally happens in [`computediagnostic!`](@ref) and [`computefluxes!`](@ref), the latter of which should be used to compute the time derivatives (here `dH`). [`interact!`](@ref) defines the behavior at the boundaries and should be used to compute the derivatives (and any other necessary values) at the interface between layers. +The real work finally happens in [`computediagnostic!`](@ref) and [`computeprognostic!`](@ref), the latter of which should be used to compute the time derivatives (here `dH`). [`interact!`](@ref) defines the behavior at the boundaries and should be used to compute the derivatives (and any other necessary values) at the interface between layers. -We can take as an example the implementation of `computefluxes!` for enthalpy-based heat conduction (note that `jH` is a diagnostic variable representing the energy flux over each cell edge): +We can take as an example the implementation of `computeprognostic!` for enthalpy-based heat conduction (note that `jH` is a diagnostic variable representing the energy flux over each cell edge): ```julia -function CryoGrid.computefluxes!(::SubSurface, ::HeatBalance{<:EnthalpyBased}, state) +function CryoGrid.computeprognostic!(::SubSurface, ::HeatBalance{<:EnthalpyBased}, state) Δk = Δ(state.grid) # cell sizes ΔT = Δ(cells(state.grid)) # midpoint distances # compute internal fluxes and non-linear diffusion assuming boundary fluxes have been set diff --git a/src/CryoGrid.jl b/src/CryoGrid.jl index 97c9a994..c3dfbf78 100755 --- a/src/CryoGrid.jl +++ b/src/CryoGrid.jl @@ -54,7 +54,7 @@ include("variables.jl") export BCKind include("traits.jl") -export initialcondition!, computediagnostic!, interact!, interactmaybe!, computefluxes!, resetfluxes!, diagnosticstep! +export initialcondition!, computediagnostic!, interact!, interactmaybe!, computeprognostic!, resetfluxes!, diagnosticstep! export variables, processes, initializers, timestep, isactive, caninteract export boundaryflux, boundaryvalue, criterion, criterion!, trigger! include("methods.jl") diff --git a/src/Physics/Heat/heat_conduction.jl b/src/Physics/Heat/heat_conduction.jl index 6a237d61..785230f7 100644 --- a/src/Physics/Heat/heat_conduction.jl +++ b/src/Physics/Heat/heat_conduction.jl @@ -104,7 +104,7 @@ function CryoGrid.interact!(sub1::SubSurface, ::HeatBalance, sub2::SubSurface, : return nothing end -function CryoGrid.computefluxes!(::SubSurface, ::HeatBalance{<:EnthalpyBased}, state) +function CryoGrid.computeprognostic!(::SubSurface, ::HeatBalance{<:EnthalpyBased}, state) Δk = Δ(state.grid) # cell sizes ΔT = Δ(cells(state.grid)) # midpoint distances # compute internal fluxes and non-linear diffusion assuming boundary fluxes have been set; @@ -115,7 +115,7 @@ function CryoGrid.computefluxes!(::SubSurface, ::HeatBalance{<:EnthalpyBased}, s divergence!(state.dH, state.jH, Δk) return nothing end -function CryoGrid.computefluxes!(sub::SubSurface, ::HeatBalance{<:TemperatureBased}, state) +function CryoGrid.computeprognostic!(sub::SubSurface, ::HeatBalance{<:TemperatureBased}, state) Δk = Δ(state.grid) # cell sizes ΔT = Δ(cells(state.grid)) # midpoint distances # compute internal fluxes and non-linear diffusion assuming boundary fluxes have been set diff --git a/src/Physics/Heat/heat_implicit.jl b/src/Physics/Heat/heat_implicit.jl index dded8b6f..254527d8 100644 --- a/src/Physics/Heat/heat_implicit.jl +++ b/src/Physics/Heat/heat_implicit.jl @@ -82,8 +82,8 @@ function CryoGrid.interact!(sub1::SubSurface, ::HeatBalanceImplicit, sub2::SubSu return nothing end -# do nothing in computefluxes! -CryoGrid.computefluxes!(::SubSurface, ::HeatBalanceImplicit, state) = nothing +# do nothing in computeprognostic! +CryoGrid.computeprognostic!(::SubSurface, ::HeatBalanceImplicit, state) = nothing function CryoGrid.resetfluxes!(sub::SubSurface, heat::HeatBalanceImplicit, state) @inbounds for i in 1:length(state.H) diff --git a/src/Physics/Heat/heat_water.jl b/src/Physics/Heat/heat_water.jl index 5c513182..8ea58782 100644 --- a/src/Physics/Heat/heat_water.jl +++ b/src/Physics/Heat/heat_water.jl @@ -89,13 +89,13 @@ function CryoGrid.interact!( end # Flux calculation -function CryoGrid.computefluxes!(sub::SubSurface, ps::Coupled(WaterBalance, HeatBalance), state) +function CryoGrid.computeprognostic!(sub::SubSurface, ps::Coupled(WaterBalance, HeatBalance), state) water, heat = ps - CryoGrid.computefluxes!(sub, water, state) + CryoGrid.computeprognostic!(sub, water, state) if heat.advection water_energy_advection!(sub, ps, state) end - CryoGrid.computefluxes!(sub, heat, state) + CryoGrid.computeprognostic!(sub, heat, state) end function heatcapacitywater(sub::SubSurface, state) diff --git a/src/Physics/Hydrology/water_balance.jl b/src/Physics/Hydrology/water_balance.jl index b87ff3ef..0aea1b9e 100644 --- a/src/Physics/Hydrology/water_balance.jl +++ b/src/Physics/Hydrology/water_balance.jl @@ -219,7 +219,7 @@ function CryoGrid.computediagnostic!(sub::SubSurface, water::WaterBalance, state evapotranspiration!(sub, water, state) end -function CryoGrid.computefluxes!(sub::SubSurface, water::WaterBalance, state) +function CryoGrid.computeprognostic!(sub::SubSurface, water::WaterBalance, state) wateradvection!(sub, water, state) waterdiffusion!(sub, water, state) balancefluxes!(sub, water, state) @@ -255,7 +255,7 @@ function CryoGrid.initialcondition!(sub::SubSurface, water::WaterBalance{NoFlow} end end -CryoGrid.computefluxes!(::SubSurface, ::WaterBalance{NoFlow}, state) = nothing +CryoGrid.computeprognostic!(::SubSurface, ::WaterBalance{NoFlow}, state) = nothing CryoGrid.resetfluxes!(::SubSurface, ::WaterBalance{NoFlow}, state) = nothing diff --git a/src/Physics/Lakes/lake_simple.jl b/src/Physics/Lakes/lake_simple.jl index 643e887e..7a1ae48d 100644 --- a/src/Physics/Lakes/lake_simple.jl +++ b/src/Physics/Lakes/lake_simple.jl @@ -110,7 +110,7 @@ function CryoGrid.computediagnostic!(sub::Lake, heat::HeatBalance{<:Heat.Diffusi return nothing end -function CryoGrid.computefluxes!(::Lake, ::HeatBalance{<:Heat.Diffusion1D{:H}}, state) +function CryoGrid.computeprognostic!(::Lake, ::HeatBalance{<:Heat.Diffusion1D{:H}}, state) Δk = Δ(state.grids.k) # cell sizes ΔT = Δ(state.grids.T) # midpoint distances # compute internal fluxes and non-linear diffusion assuming boundary fluxes have been set diff --git a/src/Physics/Salt/salt_diffusion.jl b/src/Physics/Salt/salt_diffusion.jl index f6175a76..1401acc4 100644 --- a/src/Physics/Salt/salt_diffusion.jl +++ b/src/Physics/Salt/salt_diffusion.jl @@ -121,7 +121,7 @@ function CryoGrid.timestep(::SalineGround, salt::SaltMassBalance{T,<:CryoGrid.CF return dtmax end -function CryoGrid.computefluxes!( +function CryoGrid.computeprognostic!( ::SalineGround, ps::CoupledHeatSalt{THeat}, state diff --git a/src/Physics/Snow/snow_bulk.jl b/src/Physics/Snow/snow_bulk.jl index 230a7efa..35a7cbdf 100644 --- a/src/Physics/Snow/snow_bulk.jl +++ b/src/Physics/Snow/snow_bulk.jl @@ -167,16 +167,16 @@ function CryoGrid.trigger!( end # mass balance fluxes are handled in interact! for bulk snowpack -CryoGrid.computefluxes!(snow::BulkSnowpack, mass::SnowMassBalance, state) = nothing +CryoGrid.computeprognostic!(snow::BulkSnowpack, mass::SnowMassBalance, state) = nothing -# computefluxes! for free water, enthalpy based HeatBalance on bulk snow layer -function CryoGrid.computefluxes!( +# computeprognostic! for free water, enthalpy based HeatBalance on bulk snow layer +function CryoGrid.computeprognostic!( snow::BulkSnowpack, ps::CoupledSnowWaterHeat{TM,TW,TH}, state ) where {TM,TW,TH<:HeatBalance{<:EnthalpyBased}} mass, water, heat = ps - computefluxes!(snow, mass, state) + computeprognostic!(snow, mass, state) dsn = getscalar(state.dsn) if dsn < snow.para.thresh # set fluxes to zero if there is no snow @@ -185,8 +185,8 @@ function CryoGrid.computefluxes!( state.dsat .= 0.0 end else - # otherwise call computefluxes! for coupled water/heat - computefluxes!(snow, Coupled(water, heat), state) + # otherwise call computeprognostic! for coupled water/heat + computeprognostic!(snow, Coupled(water, heat), state) end return nothing end diff --git a/src/Physics/Snow/snow_lite.jl b/src/Physics/Snow/snow_lite.jl index 597194d3..1dbbeb70 100644 --- a/src/Physics/Snow/snow_lite.jl +++ b/src/Physics/Snow/snow_lite.jl @@ -40,7 +40,7 @@ CryoGrid.variables(::LiteSnowpack, ::SnowMassBalance) = ( CryoGrid.computediagnostic!(::LiteSnowpack, ::SnowMassBalance, state) = nothing -CryoGrid.computefluxes!(::LiteSnowpack, ::SnowMassBalance, state) = nothing +CryoGrid.computeprognostic!(::LiteSnowpack, ::SnowMassBalance, state) = nothing function CryoGrid.interact!( top::Top, diff --git a/src/Physics/Snow/snowpack.jl b/src/Physics/Snow/snowpack.jl index 69d67050..4644619c 100644 --- a/src/Physics/Snow/snowpack.jl +++ b/src/Physics/Snow/snowpack.jl @@ -120,14 +120,14 @@ function CryoGrid.computediagnostic!( updategrid!(state.grid, z0, state.dsn) end -function CryoGrid.computefluxes!( +function CryoGrid.computeprognostic!( snow::Snowpack, state, ) mass, water, heat = processes(snow) - computefluxes!(snow, mass, state) - computefluxes!(snow, water, state) - computefluxes!(snow, heat, state) + computeprognostic!(snow, mass, state) + computeprognostic!(snow, water, state) + computeprognostic!(snow, heat, state) end # Special overrides for heat timestep control on snow layer diff --git a/src/Physics/Sources/Sources.jl b/src/Physics/Sources/Sources.jl index 20baf9b0..53b58d4d 100644 --- a/src/Physics/Sources/Sources.jl +++ b/src/Physics/Sources/Sources.jl @@ -1,7 +1,7 @@ module Sources import CryoGrid: SubSurfaceProcess, SubSurface -import CryoGrid: computediagnostic!, initialcondition!, interact!, computefluxes!, variables +import CryoGrid: computediagnostic!, initialcondition!, interact!, computeprognostic!, variables using ..Heat using CryoGrid.Numerics @@ -52,7 +52,7 @@ ConstructionBase.constructorof(::Type{<:Source{P}}) where {P} = (term, aux) -> S (p::Periodic)(t) = p.amp*sin(2π*p.freq*t - p.shift) + p.level # HeatBalance sources -computefluxes!(::SubSurface, s::Source{<:HeatBalance,<:Constant}, state) = @inbounds @. state.dH += s.term.S₀ -computefluxes!(::SubSurface, src::Source{<:HeatBalance,<:Periodic}, state) = @inbounds @. state.dH += src.term(state.t) +computeprognostic!(::SubSurface, s::Source{<:HeatBalance,<:Constant}, state) = @inbounds @. state.dH += s.term.S₀ +computeprognostic!(::SubSurface, src::Source{<:HeatBalance,<:Periodic}, state) = @inbounds @. state.dH += src.term(state.t) end \ No newline at end of file diff --git a/src/Physics/Surface/SWB/coupled_sweb.jl b/src/Physics/Surface/SWB/coupled_sweb.jl index 19753844..53a5de79 100644 --- a/src/Physics/Surface/SWB/coupled_sweb.jl +++ b/src/Physics/Surface/SWB/coupled_sweb.jl @@ -13,11 +13,11 @@ CryoGrid.variables(top::Top, bc::SurfaceWaterEnergyBalance) = ( Prognostic(:ET, Scalar, u"m^3"), ) -function CryoGrid.computefluxes!(top::Top, bc::SurfaceWaterEnergyBalance, state) +function CryoGrid.computeprognostic!(top::Top, bc::SurfaceWaterEnergyBalance, state) swb, seb = bc - computefluxes!(top, swb, state) + computeprognostic!(top, swb, state) ET!(top, swb, state) - computefluxes!(top, seb, state) + computeprognostic!(top, seb, state) end function CryoGrid.interact!(top::Top, bc::SurfaceWaterEnergyBalance, sub::SubSurface, ps::Coupled(WaterBalance, HeatBalance), stop, ssub) diff --git a/src/Physics/Surface/SWB/swb.jl b/src/Physics/Surface/SWB/swb.jl index c395e129..3003d3df 100644 --- a/src/Physics/Surface/SWB/swb.jl +++ b/src/Physics/Surface/SWB/swb.jl @@ -71,7 +71,7 @@ function CryoGrid.computediagnostic!(::Top, swb::SurfaceWaterBalance, stop) @setscalar stop.jw_rain = swb.rainfall(stop.t) end -function CryoGrid.computefluxes!(top::Top, swb::SurfaceWaterBalance, state) +function CryoGrid.computeprognostic!(top::Top, swb::SurfaceWaterBalance, state) runoff!(top, swb, state) end diff --git a/src/Tiles/stratigraphy.jl b/src/Tiles/stratigraphy.jl index a54157c9..e7fab364 100644 --- a/src/Tiles/stratigraphy.jl +++ b/src/Tiles/stratigraphy.jl @@ -219,9 +219,9 @@ that `getproperty` would return the appropriate state object for the i'th layer return expr end -function CryoGrid.computefluxes!(strat::Stratigraphy, state) +function CryoGrid.computeprognostic!(strat::Stratigraphy, state) fastiterate(namedlayers(strat)) do named_layer - CryoGrid.computefluxes!(named_layer.val, getproperty(state, nameof(named_layer))) + CryoGrid.computeprognostic!(named_layer.val, getproperty(state, nameof(named_layer))) end end diff --git a/src/Tiles/tile.jl b/src/Tiles/tile.jl index 2b897559..ed4d2c29 100644 --- a/src/Tiles/tile.jl +++ b/src/Tiles/tile.jl @@ -108,7 +108,7 @@ function Tiles.Tile(integrator::SciMLBase.DEIntegrator) end """ - computefluxes!(_tile::Tile{TStrat,TGrid,TStates,TInits,TEvents,true}, _du, _u, p, t) where {TStrat,TGrid,TStates,TInits,TEvents} + computeprognostic!(_tile::Tile{TStrat,TGrid,TStates,TInits,TEvents,true}, _du, _u, p, t) where {TStrat,TGrid,TStates,TInits,TEvents} Time derivative step function (i.e. du/dt) for any arbitrary `Tile`. Specialized code is generated and compiled on the fly via the @generated macro to ensure type stability. The generated code updates each layer in the stratigraphy @@ -117,10 +117,10 @@ in sequence, i.e for each layer 1 <= i <= N: ```julia computediagnostic!(layer[i], ...) interact!(layer[i], ..., layer[i+1], ...) -computefluxes!(layer[i], ...) +computeprognostic!(layer[i], ...) ``` """ -function computefluxes!( +function computeprognostic!( _tile::Tile{TStrat,TGrid,TStates,TInits,TEvents,true}, _du::AbstractVector, _u::AbstractVector, @@ -139,8 +139,8 @@ function computefluxes!( checkstate!(tile, state, u, du, :computediagnostic!) CryoGrid.interact!(strat, state) checkstate!(tile, state, u, du, :interact!) - CryoGrid.computefluxes!(strat, state) - checkstate!(tile, state, u, du, :computefluxes!) + CryoGrid.computeprognostic!(strat, state) + checkstate!(tile, state, u, du, :computeprognostic!) return nothing end @@ -182,7 +182,7 @@ function CryoGrid.initialcondition!(tile::Tile, tspan::NTuple{2,Float64}, p::Abs CryoGrid.initialcondition!(tile.grid, state) CryoGrid.initialcondition!(strat, state, tile.inits...) # evaluate initial time derivative - computefluxes!(tile, du, u, p, t0) + computeprognostic!(tile, du, u, p, t0) return u, du end diff --git a/src/Tiles/tile_base.jl b/src/Tiles/tile_base.jl index 8340d52a..be02dd91 100644 --- a/src/Tiles/tile_base.jl +++ b/src/Tiles/tile_base.jl @@ -16,9 +16,9 @@ abstract type AbstractTile{iip} end (tile::AbstractTile{true})(du,u,p,t,dt=1.0) (tile::AbstractTile{false})(u,p,t,dt=1.0) -Invokes `computefluxes!` on `tile` to compute the time derivative du/dt. +Invokes `computeprognostic!` on `tile` to compute the time derivative du/dt. """ -(tile::AbstractTile{true})(du, u, p, t, dt=1.0) = computefluxes!(tile,du,u,p,t,dt) +(tile::AbstractTile{true})(du, u, p, t, dt=1.0) = computeprognostic!(tile,du,u,p,t,dt) (tile::AbstractTile{false})(u, p, t, dt=1.0) = computefluxes(tile,u,p,t,dt) """ @@ -29,11 +29,11 @@ Returns true if `tile` uses in-place mode, false if out-of-place. isinplace(::AbstractTile{iip}) where {iip} = iip """ - computefluxes!(::T,du,u,p,t) where {T<:AbstractTile} + computeprognostic!(::T,du,u,p,t) where {T<:AbstractTile} In-place update function for tile `T`. Computes du/dt and stores the result in `du`. """ -computefluxes!(::T, du, u, p, t, dt=1.0) where {T<:AbstractTile} = error("no implementation of in-place computefluxes! for $T") +computeprognostic!(::T, du, u, p, t, dt=1.0) where {T<:AbstractTile} = error("no implementation of in-place computeprognostic! for $T") """ computefluxes(::T,u,p,t) where {T<:AbstractTile} diff --git a/src/coupling.jl b/src/coupling.jl index 1567f3b0..785975a6 100644 --- a/src/coupling.jl +++ b/src/coupling.jl @@ -17,7 +17,7 @@ CryoGrid.initialcondition!(layer::Layer, ps::CoupledProcesses, state) = _invoke_ CryoGrid.computediagnostic!(layer::Layer, ps::CoupledProcesses, state) = _invoke_sequential(computediagnostic!, layer, ps, state) -CryoGrid.computefluxes!(layer::Layer, ps::CoupledProcesses, state) = _invoke_sequential(computefluxes!, layer, ps, state) +CryoGrid.computeprognostic!(layer::Layer, ps::CoupledProcesses, state) = _invoke_sequential(computeprognostic!, layer, ps, state) CryoGrid.resetfluxes!(layer::Layer, ps::CoupledProcesses, state) = _invoke_sequential(resetfluxes!, layer, ps, state) diff --git a/src/methods.jl b/src/methods.jl index a78dce27..b9511218 100644 --- a/src/methods.jl +++ b/src/methods.jl @@ -63,15 +63,15 @@ interact!(layer1::Layer, layer2::Layer, state1, state2) = interact!(layer1, proc interact!(::Layer, ::Process, ::Layer, ::Process, state1, state2) = nothing """ - computefluxes!(l::Layer, p::Process, state) + computeprognostic!(l::Layer, p::Process, state) -Calculates all internal fluxes for a given layer. Note that an instance of `computefluxes!` must be provided +Calculates all internal fluxes for a given layer. Note that an instance of `computeprognostic!` must be provided for all non-boundary (subsurface) processes/layers. """ -computefluxes!(layer::Layer, state) = computefluxes!(layer, processes(layer), state) -computefluxes!(layer::Layer, proc::Process, state) = error("computefluxes! defined for $(typeof(layer)) with $(typeof(proc))") -computefluxes!(::Top, ::BoundaryProcess, state) = nothing -computefluxes!(::Bottom, ::BoundaryProcess, state) = nothing +computeprognostic!(layer::Layer, state) = computeprognostic!(layer, processes(layer), state) +computeprognostic!(layer::Layer, proc::Process, state) = error("computeprognostic! defined for $(typeof(layer)) with $(typeof(proc))") +computeprognostic!(::Top, ::BoundaryProcess, state) = nothing +computeprognostic!(::Bottom, ::BoundaryProcess, state) = nothing """ caninteract(layer1::Layer, layer2::Layer, state1, state2) @@ -111,7 +111,7 @@ resetfluxes!(layer::Layer, proc::Process, state) = nothing isactive(::Layer, state) Returns a boolean whether or not this layer is currently active in the stratigraphy and should interact with other layers. -Note that `computediagnostic!` and `computefluxes!` are always invoked regardless of the current state of `isactive`. +Note that `computediagnostic!` and `computeprognostic!` are always invoked regardless of the current state of `isactive`. The default implementation of `isactive` always returns `true`. """ isactive(::Layer, state) = true diff --git a/test/Physics/Heat/heat_conduction_tests.jl b/test/Physics/Heat/heat_conduction_tests.jl index 9a2df956..692cf824 100644 --- a/test/Physics/Heat/heat_conduction_tests.jl +++ b/test/Physics/Heat/heat_conduction_tests.jl @@ -117,7 +117,7 @@ end state = (T=T,dH=dH,jH=jH,k=k,grid=x,grids=(T=xc,k=x),t=t) interact!(Top(bc), bc, sub, heat, state, state) interact!(sub, heat, Bottom(bc), bc, state, state) - computefluxes!(sub, heat, state) + computeprognostic!(sub, heat, state) # strip units from dH before returning it to the solver; # note that we do not need to divide by diffusivity since we assume it to be unity return ustrip.(dH) diff --git a/test/Physics/Hydrology/water_balance_tests.jl b/test/Physics/Hydrology/water_balance_tests.jl index 2c10d4f3..ac819ccd 100644 --- a/test/Physics/Hydrology/water_balance_tests.jl +++ b/test/Physics/Hydrology/water_balance_tests.jl @@ -32,14 +32,14 @@ using Test @test allfinite(state.kw) @test allfinite(state.θw) end - @testset "computefluxes!" begin + @testset "computeprognostic!" begin sub = TestGroundLayer(WaterBalance(BucketScheme())) state = Diagnostics.build_dummy_state(testgrid, sub, with_units=true) # initialize fully saturated state.sat .= 1.0 procs = CryoGrid.processes(sub) CryoGrid.computediagnostic!(sub, procs, state) - CryoGrid.computefluxes!(sub, procs, state) + CryoGrid.computeprognostic!(sub, procs, state) @test allfinite(state.kw) @test allfinite(state.θw) @test all(iszero.(state.jw)) @@ -47,7 +47,7 @@ using Test state.sat .= 0.5 procs = CryoGrid.processes(sub) CryoGrid.computediagnostic!(sub, procs, state) - CryoGrid.computefluxes!(sub, procs, state) + CryoGrid.computeprognostic!(sub, procs, state) @test allfinite(state.kw) @test allfinite(state.θw) @test all(state.jw[2:end-1] .> zero(eltype(state.jw))) diff --git a/test/Physics/Salt/runtests.jl b/test/Physics/Salt/runtests.jl index 8363c46c..d9dc4845 100644 --- a/test/Physics/Salt/runtests.jl +++ b/test/Physics/Salt/runtests.jl @@ -63,7 +63,7 @@ using Test @test state1.jc[end] > zero(eltype(state1.jc)) @test state2.jc[1] == state1.jc[end] end - @testset "computefluxes!" begin + @testset "computeprognostic!" begin soil = pstrip(SalineGround()) state = Diagnostics.build_dummy_state(testgrid, soil, with_units=false) # initialize variables @@ -72,7 +72,7 @@ using Test state.por .= porosity(soil) procs = CryoGrid.processes(soil) CryoGrid.computediagnostic!(soil, procs, state) - CryoGrid.computefluxes!(soil, procs, state) + CryoGrid.computeprognostic!(soil, procs, state) # check that all divergences are nonzero for both temperature and salt @test all(.!iszero.(state.dc)) @test all(.!iszero.(state.dT)) diff --git a/test/Physics/Sources/runtests.jl b/test/Physics/Sources/runtests.jl index 1338b5c2..0b72ea44 100644 --- a/test/Physics/Sources/runtests.jl +++ b/test/Physics/Sources/runtests.jl @@ -6,10 +6,10 @@ using Test heatsource = Source(HeatBalance, Sources.Constant(1.0u"W/m^3")) layer = TestGroundLayer(heatsource) state = (dH=zeros(100)u"W/m^3",) - computefluxes!(layer, heatsource, state) + computeprognostic!(layer, heatsource, state) @test all(state.dH .≈ 1.0u"W/m^3") state = (dH=ones(100)u"W/m^3",) - computefluxes!(layer, heatsource, state) + computeprognostic!(layer, heatsource, state) @test all(state.dH .≈ 2.0u"W/m^3") end @testset "Periodic" begin @@ -17,10 +17,10 @@ using Test heatsource = Source(HeatBalance, Sources.Periodic(; level, amp, freq, shift)) layer = TestGroundLayer(heatsource) state = (dH=zeros(100)u"W/m^3", t=1.0u"s") - computefluxes!(layer, heatsource, state) + computeprognostic!(layer, heatsource, state) @test all(state.dH .≈ level + amp*sin(2π*freq*1.0u"s" - shift)) state = (dH=ones(100)u"W/m^3", t=1.5u"s") - computefluxes!(layer, heatsource, state) + computeprognostic!(layer, heatsource, state) @test all(state.dH .≈ 1.0u"W/m^3" + level + amp*sin(2π*freq*1.5u"s" - shift)) end end diff --git a/test/Physics/Surface/swb_tests.jl b/test/Physics/Surface/swb_tests.jl index c6aabd6b..6a524984 100644 --- a/test/Physics/Surface/swb_tests.jl +++ b/test/Physics/Surface/swb_tests.jl @@ -17,7 +17,7 @@ CryoGrid.computediagnostic!(top, swb, stop) CryoGrid.computediagnostic!(sub, water, ssub) CryoGrid.interact!(top, sub, stop, ssub) - CryoGrid.computefluxes!(top, stop) + CryoGrid.computeprognostic!(top, stop) @test iszero(ssub.jw[1]) @test stop.drunoff[1] > zero(eltype(stop.drunoff)) ssub.sat .= 0.5 @@ -26,7 +26,7 @@ CryoGrid.computediagnostic!(top, swb, stop) CryoGrid.computediagnostic!(sub, water, ssub) CryoGrid.interact!(top, sub, stop, ssub) - CryoGrid.computefluxes!(top, stop) + CryoGrid.computeprognostic!(top, stop) @test ssub.jw[1] > zero(eltype(ssub.jw)) @test iszero(stop.drunoff[1]) end -- GitLab