forked from EarthSciML/AtmosphericDeposition.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'EarthSciML:main' into main
- Loading branch information
Showing
6 changed files
with
150 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
module EarthSciDataExt | ||
|
||
using AtmosphericDeposition, EarthSciData, EarthSciMLBase, Unitful, ModelingToolkit | ||
|
||
function EarthSciMLBase.couple2(d::AtmosphericDeposition.DrydepositionGCoupler, g::EarthSciData.GEOSFPCoupler) | ||
d, g = d.sys, g.sys | ||
|
||
@constants( | ||
PaPerhPa = 100, [unit = u"Pa/hPa", description="Conversion factor from hPa to Pa"], | ||
MW_air = 29, [unit = u"g/mol", description="dry air molar mass"], | ||
kgperg = 1e-3, [unit = u"kg/g", description="Conversion factor from g to kg"], | ||
R = 8.31446261815324, [unit = u"m^3*Pa/mol/K", description="Ideal gas constant"], | ||
) | ||
|
||
# ρA in DrydepositionG(t) are in units of "kg/m3". | ||
# ρ = P*M/(R*T)= Pa*(g/mol)/(m3*Pa/mol/K*K) = g/m3 | ||
# Overall, ρA = P*M/(R*T)*kgperg | ||
|
||
d = param_to_var(d, :T, :z, :z₀, :u_star, :G, :ρA) | ||
ConnectorSystem([ | ||
d.T ~ g.I3₊T, | ||
d.z ~ g.A1₊PBLH, | ||
d.z₀ ~ g.A1₊Z0M, | ||
d.u_star ~ g.A1₊USTAR, | ||
d.G ~ g. A1₊SWGDN, | ||
d.ρA ~ g.P * PaPerhPa/(g.I3₊T*R)*kgperg*MW_air, | ||
], d, g) | ||
end | ||
|
||
function EarthSciMLBase.couple2(d::AtmosphericDeposition.WetdepositionCoupler, g::EarthSciData.GEOSFPCoupler) | ||
d, g = d.sys, g.sys | ||
|
||
@constants( | ||
PaPerhPa = 100, [unit = u"Pa/hPa", description="Conversion factor from hPa to Pa"], | ||
MW_air = 29, [unit = u"g/mol", description="dry air molar mass"], | ||
kgperg = 1e-3, [unit = u"kg/g", description="Conversion factor from g to kg"], | ||
R = 8.31446261815324, [unit = u"m^3*Pa/mol/K", description="Ideal gas constant"], | ||
) | ||
|
||
# ρ_air in Wetdeposition(t) are in units of "kg/m3". | ||
# ρ = P*M/(R*T)= Pa*(g/mol)/(m3*Pa/mol/K*K) = g/m3 | ||
# Overall, ρ_air = P*M/(R*T)*kgperg | ||
|
||
d = param_to_var(d, :cloudFrac, :ρ_air) | ||
ConnectorSystem([ | ||
d.cloudFrac ~ g.A3cld₊CLOUD, | ||
d.ρ_air ~ g.P * PaPerhPa/(g.I3₊T*R)*kgperg*MW_air, | ||
], d, g) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,37 @@ | ||
using AtmosphericDeposition | ||
using Test, Unitful, ModelingToolkit, GasChem, Dates, EarthSciMLBase | ||
using Test, Unitful, ModelingToolkit, GasChem, Dates, EarthSciMLBase, EarthSciData | ||
|
||
@testset "Connector" begin | ||
ModelingToolkit.check_units(eqs...) = nothing | ||
@testset "GasChemExt" begin | ||
start = Dates.datetime2unix(Dates.DateTime(2016, 5, 1)) | ||
@parameters t | ||
@parameters t [unit = u"s"] | ||
composed_ode = couple(SuperFast(t), FastJX(t), DrydepositionG(t), Wetdeposition(t)) | ||
tspan = (start, start+3600*24*3) | ||
sys = structural_simplify(get_mtk(composed_ode)) | ||
@test length(states(sys)) ≈ 18 | ||
|
||
eqs = string(equations(sys)) | ||
wanteqs = ["Differential(t)(superfast₊O3(t)) ~ superfast₊DrydepositionG_ddt_O3ˍt(t) + superfast₊WetDeposition_ddt_O3ˍt(t)"] | ||
wanteqs = ["Differential(t)(SuperFast₊O3(t)) ~ SuperFast₊DrydepositionG_ddt_O3ˍt(t) + SuperFast₊Wetdeposition_ddt_O3ˍt(t)"] | ||
@test contains(string(eqs), wanteqs[1]) | ||
end | ||
|
||
@testset "EarthSciDataExt" begin | ||
@parameters t [unit = u"s"] | ||
|
||
@parameters lat = 40 | ||
@parameters lon = -97 | ||
@parameters lev = 1 | ||
geosfp = GEOSFP("4x5", t) | ||
|
||
model = couple(SuperFast(t), FastJX(t), geosfp, Wetdeposition(t), DrydepositionG(t)) | ||
|
||
sys = structural_simplify(get_mtk(model)) | ||
@test length(states(sys)) ≈ 18 | ||
|
||
eqs = string(equations(get_mtk(model))) | ||
wanteq = "DrydepositionG₊G(t) ~ GEOSFP₊A1₊SWGDN(t)" | ||
@test contains(eqs, wanteq) | ||
wanteq = "Wetdeposition₊cloudFrac(t) ~ GEOSFP₊A3cld₊CLOUD(t)" | ||
@test contains(eqs, wanteq) | ||
wanted = "Wetdeposition₊ρA(t) ~ GEOSFP₊P * PaPerhPa/(GEOSFP₊I3₊T*R)*kgperg*MW_air" | ||
@test contains(eqs, wanteq) | ||
end |