Skip to content

Commit

Permalink
Simpler syntax for CreateReaction
Browse files Browse the repository at this point in the history
Can now use
    localname=>link_namestr
instead of
    localname, link_namestr=link_namestr
  • Loading branch information
Stuart Daines committed May 15, 2022
1 parent 72be3bf commit 6ce964c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 18 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.3"
version = "0.18.4"

[deps]
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
Expand Down
31 changes: 21 additions & 10 deletions src/VariableReaction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ end
##################################################

"""
CreateVariableReaction(var_type, linklocal_namestr, units, description;
attributes=Tuple(), link_namestr=linklocal_namestr)
-> VariableReaction{T}
CreateVariableReaction(T, localname => link_namestr, units, description; attributes=Tuple()) -> VariableReaction{T}
CreateVariableReaction(T, linklocal_namestr, units, description; attributes=Tuple()) -> VariableReaction{T}
[deprecated] CreateVariableReaction(T, localname, units, description; link_namestr, attributes=Tuple()) -> VariableReaction{T}
Create a [`VariableReaction`](@ref).
Expand All @@ -76,19 +76,30 @@ Not called directly: use short names `VarProp`, `VarDep`, `VarContrib`, `VarTarg
# Arguments
- `var_type::VariableType`: one of `VT_ReactProperty`, `VT_ReactDependency`, `VT_ReactContributor`, `VT_ReactTarget`
- `linklocal_namestr::AbstractString`: either
- `localname`, or
- `<linkreq_domain>.[linkreq_subdomain.]localname` (which is parsed by [`parse_variablereaction_namestr`](@ref)
to define the requested linking to `Domain` Variable).
- `localname::AbstractString`: Reaction-local Variable name
- `link_namestr::AbstractString`: `<linkreq_domain>.[linkreq_subdomain.]linkreq_name`. Parsed by [`parse_variablereaction_namestr`](@ref)
to define the requested linking to `Domain` Variable.
- `linklocal_namestr::AbstractString`: `<linkreq_domain>.[linkreq_subdomain.]localname`. Convenience form to define both `localname`
and requested linking to Domain Variable, for the common case where `linkreq_name == localname`.
- `units::AbstractString`: units ("" if not applicable)
- `description::AbstractString`: text describing the variable
# Keywords
- `attributes::Tuple(:attrb1name=>attrb1value, :attrb2name=>attrb2value, ...)`:
variable attributes, see [`StandardAttributes`](@ref), [`set_attribute!`](@ref), [`get_attribute`](@ref)
- `link_namestr::AbstractString`: parsed by [`parse_variablereaction_namestr`](@ref)
to define requested linking to `Domain` Variable. Only required to specify a requested link name where `linkreq_name`
is different from `localname`. If supplied, `linklocal_namestr` must then be just `localname`.
"""
function CreateVariableReaction end

CreateVariableReaction(
var_type::VariableType,
localname_linkname::Pair{<:AbstractString, <:AbstractString},
units::AbstractString,
description::AbstractString;
attributes::Tuple{Vararg{Pair}}=(), # (:atrb1=>value1, :atrb2=>value2)
) = CreateVariableReaction(
var_type, first(localname_linkname), units, description;
link_namestr=last(localname_linkname), attributes=attributes
)

function CreateVariableReaction(
var_type::VariableType,
linklocal_namestr::AbstractString,
Expand Down
9 changes: 3 additions & 6 deletions src/reactioncatalog/Fluxes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ function _FluxVars(
push!(
variables,
varctorfn(
localname, "mol yr-1", "$description $fluxname",
link_namestr=link_namestr,
localname=>link_namestr, "mol yr-1", "$description $fluxname",
attributes=attributes
)
)
Expand Down Expand Up @@ -321,8 +320,7 @@ function PB.register_dynamic_methods!(rj::ReactionFluxTransfer, model::PB.Model)
input_attrb = Tuple(atnm=>PB.get_attribute(input_var, atnm) for atnm in (:field_data, :data_dims, :space))

push!(var_inputs,
PB.VarDep("input_"*fluxname, "mol yr-1", "flux input",
link_namestr=input_namestr,
PB.VarDep("input_"*fluxname => input_namestr, "mol yr-1", "flux input",
attributes=input_attrb,
)
)
Expand All @@ -333,8 +331,7 @@ function PB.register_dynamic_methods!(rj::ReactionFluxTransfer, model::PB.Model)
replace(output_var_patternname, "\$fluxname\$" => fluxname)
)*")"
push!(var_outputs,
PB.VarContrib("output_"*fluxname, "mol yr-1", "flux output",
link_namestr=output_namestr,
PB.VarContrib("output_"*fluxname => output_namestr, "mol yr-1", "flux output",
attributes=input_attrb,
)
)
Expand Down
2 changes: 1 addition & 1 deletion src/reactioncatalog/VariableStats.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function PB.register_methods!(rj::ReactionSum)
# mark all vars_to_add as optional to help diagnose config errors
# default :field_data=>PB.UndefinedData to allow Variable to link to any data type (this is checked later)
push!(vars_to_add,
PB.VarDep(localname, "", "", link_namestr="("*varname*")")
PB.VarDep(localname => "("*varname*")", "", "")
)
end

Expand Down

0 comments on commit 6ce964c

Please sign in to comment.