Skip to content

Commit

Permalink
Merge pull request #6 from PALEOtoolkit/sync_PALEOboxes
Browse files Browse the repository at this point in the history
Update to PALEOboxes v0.18
  • Loading branch information
sjdaines authored May 12, 2022
2 parents 0d139c0 + 7c915e3 commit 85d1b18
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 108 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "PALEOcopse"
uuid = "4a6ed817-0e58-48c6-8452-9e9afc8cb508"
authors = ["sd336 "]
version = "0.2.1"
version = "0.2.2"

[deps]
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Expand All @@ -19,7 +19,7 @@ Documenter = "0.27"
Infiltrator = "1.0"
Interpolations = "0.13"
MAT = "0.10"
PALEOboxes = "0.17"
PALEOboxes = "0.18"
PALEOmodel = "0.14"
Plots = "1.0"
Roots = "1.0, 2.0"
Expand Down
6 changes: 5 additions & 1 deletion src/COPSE/MapAtmOceanReservoirs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,18 @@ Base.@kwdef mutable struct ReactionAtmOcean_A{P} <: PB.AbstractReaction
description="calculate d13CO2, d13DIC relative to A"),
PB.ParBool("fix_cisotopefrac_T", false,
description="remove temperature dependence of d13CO2, d13DIC relative to A"),
PB.ParType(PB.AbstractData, "CIsotope", PB.ScalarData,
external=true,
allowed_values=PB.IsotopeTypes,
description="disable / enable carbon isotopes and specify isotope type"),
)

norm_value::Float64 = NaN
end

function PB.register_methods!(rj::ReactionAtmOcean_A)

_, CIsotopeType = PB.split_nameisotope("::CIsotope", rj.external_parameters; default=PB.ScalarData)
CIsotopeType = rj.pars.CIsotope.v

vars = [
PB.VarStateExplicitScalar("A", "mol", "atm-ocean inorganic carbon (CO2 + DIC)",
Expand Down
8 changes: 6 additions & 2 deletions src/Forcings/LipForcing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,10 @@ Base.@kwdef mutable struct ReactionForce_LIPs{P} <: PB.AbstractReaction
description="smooth LIP basalt emplacement"),
PB.ParString("co2releasefield", "NoCO2", allowed_values=["NoCO2", "CO2min", "CO2max"],
description="LIP CO2 release"),
PB.ParType(PB.AbstractData, "CIsotope", PB.ScalarData,
external=true,
allowed_values=PB.IsotopeTypes,
description="disable / enable carbon isotopes and specify isotope type"),
)

LIP_data = nothing
Expand All @@ -262,8 +266,8 @@ function PB.register_methods!(rj::ReactionForce_LIPs)

rj.LIP_data = read_lips_xlsx(lipfile)

_, CIsotopeType = PB.split_nameisotope("::CIsotope", rj.external_parameters; default=PB.ScalarData)
@info " CIsotopeType=$(CIsotopeType) from CIsotope in external_parameters"
CIsotopeType = rj.pars.CIsotope.v
@info " CIsotopeType=$(CIsotopeType)"

vars = [
PB.VarDepScalar("tforce", "yr", "historical time at which to apply forcings, present = 0 yr"),
Expand Down
40 changes: 23 additions & 17 deletions src/biogeochem/Strontium.jl
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,26 @@ Base.@kwdef mutable struct ReactionSrSed{P} <: PB.AbstractReaction
description="functional form for sediment Sr metamorphic loss"),
PB.ParDouble("k_Sr_metam", 13e9, units="mol yr-1",
description="rate of metamorphic loss of Sr from sedimentary reservoir"),

# Isotopes
PB.ParType(PB.AbstractData, "SrIsotope", SrIsotopeDefault,
external=true,
allowed_values=[PB.ScalarData, PB.IsotopeLinear],
description="disable / enable Sr isotopes and specify isotope type"),
)
end

function PB.register_methods!(rj::ReactionSrSed)
_, SrIsotopeType = PB.split_nameisotope("::SrIsotope", rj.external_parameters; default=SrIsotopeDefault)
SrIsotopeType = rj.pars.SrIsotope.v

vars = [
PB.VarDepScalar("global.tforce", "yr", "historical time at which to apply forcings, present = 0 yr"),
PB.VarDepScalar("global.DEGASS", "", "normalized DEGASS forcing"),

PB.VarDepScalar("Sr_sed", "mol", "sedimentary Sr", attributes=(:field_data=>SrIsotopeType, )),
PB.VarDepScalar("Sr_sed", "mol", "sedimentary Sr"),
PB.VarDepScalar("Sr_sed_delta", "", "d87Sr of sedimentary Sr"),
PB.VarDepScalar("Sr_sed_norm", "", "normalized sedimentary Sr"),
PB.VarContribScalar("Sr_sed_sms", "mol yr-1", "sedimentary Sr source minus sink flux", attributes=(:field_data=>SrIsotopeType, ))
PB.VarContribScalar("Sr_sed_sms", "mol yr-1", "sedimentary Sr source minus sink flux")
]

PB.add_method_do!(
Expand All @@ -153,18 +159,6 @@ function PB.register_methods!(rj::ReactionSrSed)
return nothing
end

function PB.check_configuration(rj::ReactionSrSed, model::PB.Model)
configok = true

_, SrIsotopeType = PB.split_nameisotope("::SrIsotope", rj.external_parameters; default=SrIsotopeDefault)

if !(SrIsotopeType in (PB.ScalarData, PB.IsotopeLinear))
@warn "ReactionSrSed.check_configuration unsupported IsotopeType $SrIsotopeType"
configok = false
end

return configok
end

function do_Sr_sed(
m::PB.ReactionMethod,
Expand Down Expand Up @@ -229,12 +223,18 @@ Base.@kwdef mutable struct ReactionSrLand{P} <: PB.AbstractReaction
description="functional form for sediment Sr weathering"),
PB.ParDouble("k_Sr_sedw", 17e9, units="mol yr-1",
description="Sr weathering rate constant from sediments"),

# Isotopes
PB.ParType(PB.AbstractData, "SrIsotope", SrIsotopeDefault,
external=true,
allowed_values=[PB.ScalarData, PB.IsotopeLinear],
description="disable / enable Sr isotopes and specify isotope type"),
)
end


function PB.register_methods!(rj::ReactionSrLand)
_, SrIsotopeType = PB.split_nameisotope("::SrIsotope", rj.external_parameters; default=SrIsotopeDefault)
SrIsotopeType = rj.pars.SrIsotope.v

vars = [
PB.VarDepScalar("basw_relative", "", "Basalt weathering normalized to present"),
Expand Down Expand Up @@ -327,12 +327,18 @@ Base.@kwdef mutable struct ReactionSrOceanfloor{P} <: PB.AbstractReaction
description="Sr burial output"),
PB.ParDouble("k_mccb_0", NaN, units="mol yr-1",
description="Carbonate burial rate to normalize Sr burial output for f_Sr_sedb=\"carbburial\""),

# Isotopes
PB.ParType(PB.AbstractData, "SrIsotope", SrIsotopeDefault,
external=true,
allowed_values=[PB.ScalarData, PB.IsotopeLinear],
description="disable / enable Sr isotopes and specify isotope type"),
)
end


function PB.register_methods!(rj::ReactionSrOceanfloor)
_, SrIsotopeType = PB.split_nameisotope("::SrIsotope", rj.external_parameters; default=SrIsotopeDefault)
SrIsotopeType = rj.pars.SrIsotope.v

vars = [
PB.VarDepScalar("global.DEGASS", "", "normalized DEGASS forcing"),
Expand Down
33 changes: 18 additions & 15 deletions src/landsurface/LandBergman2004.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ Base.@kwdef mutable struct ReactionLandBergman2004{P} <: PB.AbstractReaction

# Organic carbon burial
PB.ParString("f_locb", "original", allowed_values=["original", "Prescribed"]),

PB.ParType(PB.AbstractData, "CIsotope", PB.ScalarData,
external=true,
allowed_values=PB.IsotopeTypes,
description="disable / enable carbon isotopes and specify isotope type"),
PB.ParType(PB.AbstractData, "SIsotope", PB.ScalarData,
external=true,
allowed_values=PB.IsotopeTypes,
description="disable / enable sulphur isotopes and specify isotope type"),
)

end
Expand Down Expand Up @@ -142,28 +151,22 @@ function PB.register_methods!(rj::ReactionLandBergman2004)
("eps_eqbw", "per mil", "approximate atmosphere-runoff d13C")
])

# isotopes with defaults
isotope_data = merge(
Dict("CIsotope"=>PB.ScalarData, "SIsotope"=>PB.ScalarData),
rj.external_parameters
)
# isotope Types
CIsotopeType = rj.pars.CIsotope.v
SIsotopeType = rj.pars.SIsotope.v

# Add flux couplers
fluxAtoLand = PB.Fluxes.FluxContribScalar(
"fluxAtoLand.flux_", ["CO2::CIsotope", "O2"],
isotope_data=isotope_data)
"fluxAtoLand.flux_", ["CO2::$CIsotopeType", "O2"],
isotope_data=Dict())

fluxRtoOcean = PB.Fluxes.FluxContribScalar(
"fluxRtoOcean.flux_", ["DIC::CIsotope", "TAlk", "Ca", "P", "SO4::SIsotope"],
isotope_data=isotope_data)
"fluxRtoOcean.flux_", ["DIC::$CIsotopeType", "TAlk", "Ca", "P", "SO4::$SIsotopeType"],
isotope_data=Dict())

fluxLandtoSedCrust = PB.Fluxes.FluxContribScalar(
"fluxLandtoSedCrust.flux_", ["Ccarb::CIsotope", "Corg::CIsotope", "GYP::SIsotope", "PYR::SIsotope"],
isotope_data=isotope_data)

# isotope Types
_, CIsotopeType = PB.split_nameisotope("::CIsotope", isotope_data)
_, SIsotopeType = PB.split_nameisotope("::SIsotope", isotope_data)
"fluxLandtoSedCrust.flux_", ["Ccarb::$CIsotopeType", "Corg::$CIsotopeType", "GYP::$SIsotopeType", "PYR::$SIsotopeType"],
isotope_data=Dict())

PB.add_method_do!(
rj,
Expand Down
34 changes: 19 additions & 15 deletions src/landsurface/LandCOPSEReloaded.jl
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,16 @@ Base.@kwdef mutable struct ReactionLandWeatheringFluxes{P} <: PB.AbstractReactio
description="fraction of locb assumed to occur in aquatic settings (not coals)"),
PB.ParDouble("CPland0", 1000.0, units="",
description="present-day C/P land burial"),

# Isotopes
PB.ParType(PB.AbstractData, "CIsotope", PB.ScalarData,
external=true,
allowed_values=PB.IsotopeTypes,
description="disable / enable carbon isotopes and specify isotope type"),
PB.ParType(PB.AbstractData, "SIsotope", PB.ScalarData,
external=true,
allowed_values=PB.IsotopeTypes,
description="disable / enable sulphur isotopes and specify isotope type"),
)

end
Expand Down Expand Up @@ -580,28 +590,22 @@ function PB.register_methods!(rj::ReactionLandWeatheringFluxes)
]
)

# isotopes with defaults
isotope_data = merge(
Dict("CIsotope"=>PB.ScalarData, "SIsotope"=>PB.ScalarData),
rj.external_parameters
)
# isotope Types
CIsotopeType = rj.pars.CIsotope.v
SIsotopeType = rj.pars.SIsotope.v

# Add flux couplers
fluxAtoLand = PB.Fluxes.FluxContribScalar(
"fluxAtoLand.flux_", ["CO2::CIsotope", "O2"],
isotope_data=isotope_data)
"fluxAtoLand.flux_", ["CO2::$CIsotopeType", "O2"],
isotope_data=Dict())

fluxRtoOcean = PB.Fluxes.FluxContribScalar(
"fluxRtoOcean.flux_", ["DIC::CIsotope", "TAlk", "Ca", "P", "SO4::SIsotope"],
isotope_data=isotope_data)
"fluxRtoOcean.flux_", ["DIC::$CIsotopeType", "TAlk", "Ca", "P", "SO4::$SIsotopeType"],
isotope_data=Dict())

fluxLandtoSedCrust = PB.Fluxes.FluxContribScalar(
"fluxLandtoSedCrust.flux_", ["Ccarb::CIsotope", "Corg::CIsotope", "GYP::SIsotope", "PYR::SIsotope"],
isotope_data=isotope_data)

# isotope Types
_, CIsotopeType = PB.split_nameisotope("::CIsotope", isotope_data)
_, SIsotopeType = PB.split_nameisotope("::SIsotope", isotope_data)
"fluxLandtoSedCrust.flux_", ["Ccarb::$CIsotopeType", "Corg::$CIsotopeType", "GYP::$SIsotopeType", "PYR::$SIsotopeType"],
isotope_data=Dict())

PB.add_method_do!(
rj,
Expand Down
51 changes: 27 additions & 24 deletions src/ocean/OceanCOPSE.jl
Original file line number Diff line number Diff line change
Expand Up @@ -96,40 +96,51 @@ Base.@kwdef mutable struct ReactionOceanCOPSE{P} <: PB.AbstractReaction
PB.ParString("f_sisotopefrac","fixed", allowed_values=["fixed", "copse_O2"],
description="S isotope fractionation calculation."),

# Isotopes
PB.ParType(PB.AbstractData, "CIsotope", PB.ScalarData,
external=true,
allowed_values=PB.IsotopeTypes,
description="disable / enable carbon isotopes and specify isotope type"),
PB.ParType(PB.AbstractData, "SIsotope", PB.ScalarData,
external=true,
allowed_values=PB.IsotopeTypes,
description="disable / enable sulphur isotopes and specify isotope type"),
)

end


function PB.register_methods!(rj::ReactionOceanCOPSE)

# isotopes with defaults
isotope_data = merge(
Dict("CIsotope"=>PB.ScalarData, "SIsotope"=>PB.ScalarData),
rj.external_parameters
)


# TODO - not the right place for this ?
# define a 1 cell grid
rj.domain.grid = PB.Grids.UnstructuredVectorGrid(ncells=1)
PB.Grids.set_subdomain!(rj.domain.grid, "oceansurface", PB.Grids.BoundarySubdomain([1]), true)
PB.Grids.set_subdomain!(rj.domain.grid, "oceanfloor", PB.Grids.BoundarySubdomain([1]), true)


# isotope Types
CIsotopeType = rj.pars.CIsotope.v
if rj.pars.enableS.v
SIsotopeType = rj.pars.SIsotope.v
else
SIsotopeType = PB.ScalarData
end

state_varnames = [
("P", "mol P", "Marine phosphorus"),
("O", "mol O2", "Atm-ocean oxygen"),
("(DIC::CIsotope)", "mol C", "ocean inorganic carbon"),
("(CAL)", "mol Ca", "Marine calcium"),
("P", "mol P", "Marine phosphorus"),
("O", "mol O2", "Atm-ocean oxygen"),
("(DIC::$CIsotopeType)", "mol C", "ocean inorganic carbon"),
("(CAL)", "mol Ca", "Marine calcium"),
]
if rj.pars.enableS.v
push!(state_varnames, ("S::SIsotope", "mol S", "Marine sulphate"))
push!(state_varnames, ("S::$SIsotopeType", "mol S", "Marine sulphate"))
end
if rj.pars.f_ncycle.v
push!(state_varnames, ("N", "mol N", "Marine nitrogen"))
end
vars_res, vars_sms, vars_dep_res = PB.Reservoirs.ReservoirLinksVector(
isotope_data, state_varnames
Dict(), state_varnames
)

# dependencies required in do_react
Expand Down Expand Up @@ -184,26 +195,18 @@ function PB.register_methods!(rj::ReactionOceanCOPSE)

# Define flux coupler (a NamedTuple of Variables)
burial_fluxnames = [
"Corg::CIsotope", "Ccarb::CIsotope",
"Corg::$CIsotopeType", "Ccarb::$CIsotopeType",
"Porg", "Pauth", "PFe", "P",
]
if rj.pars.enableS.v
push!(burial_fluxnames, "GYP::SIsotope", "PYR::SIsotope")
push!(burial_fluxnames, "GYP::$SIsotopeType", "PYR::$SIsotopeType")
end

fluxOceanBurial = PB.Fluxes.FluxContrib( # Scalar ?
"fluxOceanBurial.flux_",
burial_fluxnames,
isotope_data=isotope_data
isotope_data=Dict(),
)

# isotope Types
_, CIsotopeType = PB.split_nameisotope("::CIsotope", isotope_data)
if rj.pars.enableS.v
_, SIsotopeType = PB.split_nameisotope("::SIsotope", isotope_data)
else
SIsotopeType = PB.ScalarData
end

# Now assemble these lists into properties and dependencies for each method,
# following the Matlab COPSE convention that:
Expand Down
22 changes: 12 additions & 10 deletions src/oceanfloor/Weathering.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,19 @@ Base.@kwdef mutable struct ReactionSeafloorWeathering{P} <: PB.AbstractReaction

PB.ParString("f_sfw_d13C", "delta_DIC", allowed_values=["delta_DIC", "delta_mccb"],
description="d13C delta"),

# Isotopes
PB.ParType(PB.AbstractData, "CIsotope", PB.ScalarData,
external=true,
allowed_values=PB.IsotopeTypes,
description="disable / enable carbon isotopes and specify isotope type"),
)
end


function PB.register_methods!(rj::ReactionSeafloorWeathering)
# isotopes with defaults
isotope_data = merge(
Dict("CIsotope"=>PB.ScalarData, ),
rj.external_parameters
)
_, CIsotopeType = PB.split_nameisotope("::CIsotope", isotope_data)

CIsotopeType = rj.pars.CIsotope.v

vars = [
PB.VarDep("global.RHOSFW", "", "seafloor weathering-specific additional forcing (usually 1.0)"),
Expand All @@ -77,13 +79,13 @@ function PB.register_methods!(rj::ReactionSeafloorWeathering)
# flux couplers
fluxOceanBurial = PB.Fluxes.FluxContrib(
"fluxOceanBurial.flux_",
["Ccarb::CIsotope"],
isotope_data=isotope_data)
["Ccarb::$CIsotopeType"],
isotope_data=Dict())

fluxOceanfloorSolute = PB.Fluxes.FluxContrib(
"fluxOceanfloor.soluteflux_",
["DIC::CIsotope"],
isotope_data=isotope_data)
["DIC::$CIsotopeType"],
isotope_data=Dict())

if rj.pars.sfw_distribution_method.v == "Depth"
grid_vars = [
Expand Down
Loading

2 comments on commit 85d1b18

@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/60118

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.2.2 -m "<description of version>" 85d1b188557e2d6154d9aa28543497e4c0747108
git push origin v0.2.2

Please sign in to comment.