Skip to content

Commit

Permalink
Add tests for ReactionReservoirScalar const and state_norm options
Browse files Browse the repository at this point in the history
  • Loading branch information
sjdaines committed Dec 20, 2024
1 parent 9d6036a commit 9ca737a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
23 changes: 23 additions & 0 deletions test/configreservoirs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,29 @@ model1:
R:norm_value: 10.0
R:initial_value: 1.0

reservoir_NormS:
class: ReactionReservoirScalar

parameters:
state_norm: true
variable_links:
R*: NormS*
variable_attributes:
R:norm_value: 10.0
R:initial_value: 1.0

reservoir_ConstNormS:
class: ReactionReservoirScalar

parameters:
const: true
state_norm: true
variable_links:
R*: ConstNormS*
variable_attributes:
R:norm_value: 10.0
R:initial_value: 1.0

scalar_sum:
class: ReactionSum
parameters:
Expand Down
12 changes: 8 additions & 4 deletions test/runreservoirtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ end
modeldata = PB.create_modeldata(model)
PB.allocate_variables!(model, modeldata, 1; hostdep=false, check_units_opt=:error)

@test length( PB.get_unallocated_variables(global_domain, modeldata, 1)) == 4
@test length( PB.get_unallocated_variables(global_domain, modeldata, 1)) == 6
@test PB.check_ready(global_domain, modeldata, throw_on_error=false) == false

# allocate arrays for host dependencies and set data pointers
Expand All @@ -53,7 +53,7 @@ end
# check state variables
stateexplicit_vars, stateexplicit_sms_vars =
PB.get_host_variables(global_domain, PB.VF_StateExplicit, match_deriv_suffix="_sms")
@test length(stateexplicit_vars) == 2 # A and O
@test length(stateexplicit_vars) == 3 # A, O, NormS_solve
# get global state variable aggregator
global_stateexplicit_va = PB.VariableAggregator(stateexplicit_vars, fill(nothing, length(stateexplicit_vars)), modeldata, 1)

Expand All @@ -65,7 +65,7 @@ end

# get host-dependent variables
global_hostdep_vars_vec = PB.get_variables(global_domain, hostdep=true)
@test length(global_hostdep_vars_vec) == 4
@test length(global_hostdep_vars_vec) == 6

ocean_hostdep_vars_vec = PB.get_variables(ocean_domain, hostdep=true)
@test length(ocean_hostdep_vars_vec) == 4
Expand All @@ -78,11 +78,12 @@ end
PB.dispatch_setup(model, :initial_value, modeldata)

@info "global stateexplicit variables:\n"
@test all_data.global.NormS_solve[] == 0.1
@test all_data.global.A.v[] == 3.193e18 # A
@test all_data.global.A.v_moldelta[] == 2.0*3.193e18 # A_moldelta
# test access via flattened vector (as used eg by an ODE solver)
global_A_indices = PB.get_indices(global_stateexplicit_va, "global.A")
@test global_A_indices == 2:3
@test global_A_indices == 3:4 # NormS_solve, O, A - NB: order is implementation-dependent, not well defined
stateexplicit_vector = PB.get_data(global_stateexplicit_va)
@test stateexplicit_vector[global_A_indices] == [all_data.global.A.v[], all_data.global.A.v_moldelta[]]
# test VariableAggregatorNamed created from VariableAggregator
Expand All @@ -91,6 +92,7 @@ end

@info "global const variables:"
@test all_data.global.ConstS[] == 1.0
@test all_data.global.ConstNormS[] == 1.0

@info "ocean host-dependent variable initialisation:\n"
@test all_data.ocean.T[1] == 1.0*10.0
Expand All @@ -103,6 +105,8 @@ end
@info "global model-created variables:\n"
@test all_data.global.A_norm[] == 10.0
@test all_data.global.A_delta[] == 2.0
@test all_data.global.NormS[] == 1.0
@test all_data.global.NormS_norm[] == 0.1

@info "ocean model-created variables:\n"
@test all_data.ocean.T_conc == fill(1.0, ocean_length)
Expand Down

0 comments on commit 9ca737a

Please sign in to comment.