Skip to content

Commit

Permalink
fix ReactionAreaVolumeValInRange with isotope (#26)
Browse files Browse the repository at this point in the history
* fix ReactionAreaVolumeValInRange with isotope

* fix ReactionWeightedMean for isotopes
  • Loading branch information
sjdaines authored May 19, 2022
1 parent 8d238f0 commit abecdd1
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "PALEOboxes"
uuid = "804b410e-d900-4b2a-9ecd-f5a06d4c1fd4"
authors = ["Stuart Daines <[email protected]>"]
version = "0.18.6"
version = "0.18.7"

[deps]
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
Expand Down
11 changes: 8 additions & 3 deletions src/reactioncatalog/VariableStats.jl
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ Base.@kwdef mutable struct ReactionWeightedMean{P} <: PB.AbstractReaction
base::PB.ReactionBase

pars::P = PB.ParametersTuple(
PB.ParType(PB.AbstractData, "field_data", PB.ScalarData,
allowed_values=PB.IsotopeTypes,
description="disable / enable isotopes and specify isotope type"),
)


Expand All @@ -216,11 +219,12 @@ end
function PB.register_methods!(rj::ReactionWeightedMean)

vars = [
PB.VarDep( "var", "measure-1", "variable to calculate weighted mean from"),
PB.VarDep( "var", "measure-1", "variable to calculate weighted mean from",
attributes=(:field_data=>rj.pars.field_data.v,)),
PB.VarDep( "measure", "", "cell area or volume"),
PB.VarDepScalar( "measure_total", "", "total Domain area or volume"),
PB.VarPropScalar("var_mean", "", "weighted mean over Domain area or volume",
attributes=(:initialize_to_zero=>true, :atomic=>true)),
attributes=(:field_data=>rj.pars.field_data.v, :initialize_to_zero=>true, :atomic=>true)),
]

PB.add_method_do!(rj, do_weighted_mean, (PB.VarList_namedtuple(vars),))
Expand Down Expand Up @@ -273,7 +277,8 @@ end
function PB.register_methods!(rj::ReactionAreaVolumeValInRange)

vars = [
PB.VarDep( "rangevar", "mol m-3", "variable to check within range"),
PB.VarDep( "rangevar", "mol m-3", "variable to check within range";
attributes=(:field_data=>PB.ScalarData, )), # total only, not isotope
PB.VarDep( "measure", "", "cell area or volume"),
PB.VarDepScalar( "measure_total", "", "total Domain area or volume"),
PB.VarPropScalar("frac", "", "fraction of Domain area or volume in specified range",
Expand Down
30 changes: 30 additions & 0 deletions test/configreservoirs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,25 @@ model1:
ocean:

reactions:
grid:
class: ReactionUnstructuredVectorGrid
parameters:
ncells: 1000

const_volume:
class: ReactionConst
parameters:
constnames: ["volume"]
variable_attributes:
volume:initial_value: 10.0

const_volume_total:
class: ReactionScalarConst
parameters:
constnames: ["volume_total"]
variable_attributes:
volume_total:initial_value: 10000.0

reservoir_const:
class: ReactionReservoirConst
parameters:
Expand All @@ -80,4 +92,22 @@ model1:
vars_to_add: [volume, 2*T]
variable_links:
sum: vectorsum # 30.0

weightedmean:
class: ReactionWeightedMean
parameters:
field_data: IsotopeLinear
variable_links:
var*: const_conc*
measure*: volume*

volinrange:
class: ReactionAreaVolumeValInRange
parameters:
range_min: 0.0
range_max: 0.2
variable_links:
rangevar: const_conc
measure*: volume*


11 changes: 9 additions & 2 deletions test/runreservoirtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ using Logging

import PALEOboxes as PB

import Infiltrator

@testset "Reservoirs" begin

Expand All @@ -19,7 +20,6 @@ import PALEOboxes as PB
@test global_domain.name == "global"
@test PB.get_length(global_domain) == 1
ocean_domain = PB.get_domain(model, "ocean")
ocean_domain.grid = PB.Grids.UnstructuredVectorGrid(ncells=1000)
@test PB.get_length(ocean_domain) == 1000
ocean_length = PB.get_length(ocean_domain)

Expand Down Expand Up @@ -75,8 +75,10 @@ import PALEOboxes as PB
@info "ocean host-dependent variables:\n" ocean_hostdep_data
@test ocean_hostdep_data["T"][1] == 1.0*10.0

# take a time step
dispatchlists = modeldata.dispatchlists_all
PB.do_deriv(dispatchlists)

@info "global model-created variables:\n" global_modelcreated_vars_dict
@test PB.get_data(global_modelcreated_vars_dict["A_norm"], modeldata)[] == 10.0
@test PB.get_data(global_modelcreated_vars_dict["A_delta"], modeldata)[]== 2.0
Expand All @@ -95,7 +97,12 @@ import PALEOboxes as PB
@test const_conc_data.v == fill(0.1, ocean_length)
@test const_conc_data.v_moldelta == fill(-0.2, ocean_length)

model = nothing
@info "weighted mean"
@test PB.get_data(ocean_modelcreated_vars_dict["const_conc_mean"], modeldata)[] == PB.IsotopeLinear(0.1, -0.2)

@info "volume in range"
@test PB.get_data(ocean_modelcreated_vars_dict["frac"], modeldata)[] == 1.0


@info "test complete"
# close(logfile)
Expand Down

2 comments on commit abecdd1

@sjdaines
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/60574

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.18.7 -m "<description of version>" abecdd194258e6df4198337b8e0cc51a1544f1d8
git push origin v0.18.7

Please sign in to comment.