From 2964bb0abe3e9a41abaa1d585feff503aaaaf414 Mon Sep 17 00:00:00 2001 From: jialinl6 Date: Fri, 23 Feb 2024 12:45:18 -0600 Subject: [PATCH 1/4] Add descriptions to parameters and variables & delete unnecessary export functions and variables in wesley1989.jl --- src/dry_deposition.jl | 32 ++++++++++++++++---------------- src/wesley1989.jl | 3 +-- src/wet_deposition.jl | 2 +- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/dry_deposition.jl b/src/dry_deposition.jl index 000256b1..e4f68146 100644 --- a/src/dry_deposition.jl +++ b/src/dry_deposition.jl @@ -1,7 +1,7 @@ export defaults, ra, mu, mfp, cc, vs, dParticle, dH2O, sc, stSmooth, stVeg, RbGas, z₀_table, A_table, α_table, γ_table, RbParticle, DryDepGas, DryDepParticle, DrydepositionG @constants g = 9.81 [unit = u"m*s^-2", description = "gravitational acceleration"] -@constants κ = 0.4 # von Karman constant +@constants κ = 0.4 [description = "von Karman constant"] @constants k = 1.3806488e-23 [unit = u"m^2*kg*s^-2/K", description = "Boltzmann constant"] @constants M_air = 28.97e-3 [unit = u"kg/mol", description = "molecular weight of air"] @constants R = 8.3144621 [unit = u"kg*m^2*s^−2*K^-1*mol^-1", description = "Gas constant"] @@ -23,8 +23,8 @@ function ra(z, z₀, u_star, L) return rₐ end -@constants unit_T = 1 [unit = u"K"] -@constants unit_convert_mu = 1 [unit = u"kg/m/s"] +@constants unit_T = 1 [unit = u"K", description = "unit one for temperature"] +@constants unit_convert_mu = 1 [unit = u"kg/m/s", description = "unit one for mu"] """ Function mu calculates the dynamic viscosity of air [kg m-1 s-1] where T is temperature [K]. """ @@ -51,7 +51,7 @@ function cc(Dₚ, T, P, μ) return 1 + 2 * λ / Dₚ * (1.257 + 0.4 * exp(-1.1 * Dₚ / (2 * λ))) end -@constants unit_v = 1 [unit = u"m/s"] +@constants unit_v = 1 [unit = u"m/s", description = "unit one for speed"] """ Function vs calculates the terminal setting velocity of a particle where Dp is particle diameter [m], ρₚ is particle density [kg/m3], Cc is the Cunningham slip correction factor, and μ is air dynamic viscosity [kg/(s m)]. @@ -71,8 +71,8 @@ function dParticle(T, P, Dₚ, Cc, μ) return k * T * Cc / (3 * pi * μ * Dₚ) end -@constants T_unitless = 1 [unit = u"K^-1"] -@constants unit_dH2O = 1 [unit = u"m^2/s"] +@constants T_unitless = 1 [unit = u"K^-1", description = "used to offset temperature unit"] +@constants unit_dH2O = 1 [unit = u"m^2/s", description = "unit for molecular diffusivity"] """ Function dH2O calculates molecular diffusivity of water vapor in air [m2/s] where T is temperature [K] using a regression fit to data in Bolz and Tuve (1976) found here: http://www.cambridge.org/us/engineering/author/nellisandklein/downloads/examples/EXAMPLE_9.2-1.pdf @@ -174,8 +174,8 @@ function RbParticle(Sc, u_star, St, Dₚ, iSeason::Int, iLandUse::Int) return 1 / (3 * u_star * (term_1 + term_2 + term_3) * R1) end -@constants G_unitless = 1 [unit = u"m^2/W"] -@constants Rc_unit = 1 [unit = u"s/m"] +@constants G_unitless = 1 [unit = u"m^2/W", description = "used to offset the unit of irradiation"] +@constants Rc_unit = 1 [unit = u"s/m", description = "unit for surface resistance"] """ Function DryDepGas calculates dry deposition velocity [m/s] for a gas species, where z is the height of the surface layer [m], zo is roughness length [m], u_star is friction velocity [m/s], @@ -243,14 +243,14 @@ struct DrydepositionG <: EarthSciMLODESystem iLandUse = 10 rain = false dew = false - @parameters z = 50 [unit = u"m"] - @parameters z₀ = 0.04 [unit = u"m"] - @parameters u_star = 0.44 [unit = u"m/s"] - @parameters L = 0 [unit = u"m"] - @parameters ρA = 1.2 [unit = u"kg*m^-3"] - @parameters G = 300 [unit = u"W*m^-2"] - @parameters T = 298 [unit = u"K"] - @parameters θ = 0 + @parameters z = 50 [unit = u"m", description = "top of the surface layer"] + @parameters z₀ = 0.04 [unit = u"m", description = "roughness lenght"] + @parameters u_star = 0.44 [unit = u"m/s", description = "friction velocity"] + @parameters L = 0 [unit = u"m", description = "Monin-Obukhov length"] + @parameters ρA = 1.2 [unit = u"kg*m^-3", description = "air density"] + @parameters G = 300 [unit = u"W*m^-2", description = "solar irradiation"] + @parameters T = 298 [unit = u"K", description = "temperature"] + @parameters θ = 0 [description = "slope of the local terrain, in unit radians"] D = Differential(t) diff --git a/src/wesley1989.jl b/src/wesley1989.jl index 17d50344..62f64e9e 100644 --- a/src/wesley1989.jl +++ b/src/wesley1989.jl @@ -1,5 +1,4 @@ -export GasData, r_s, r_dc, r_mx, r_smx, r_lux, r_clx, r_gsx, WesleySurfaceResistance, inf, r_i, r_lu, r_ac, r_gsS, r_gsO, r_clS, r_clO, So2Data, O3Data, No2Data, NoData, Hno3Data, H2o2Data, GasData, AldData, HchoData, OpData, PaaData, OraData, Nh3Data, PanData, Hno2Data - +export WesleySurfaceResistance const inf = 1.e25 diff --git a/src/wet_deposition.jl b/src/wet_deposition.jl index 3f4b956a..e5549fb2 100644 --- a/src/wet_deposition.jl +++ b/src/wet_deposition.jl @@ -1,7 +1,7 @@ export WetDeposition, Wetdeposition, wd_defaults @constants A_wd = 5.2 [unit = u"m^3/kg/s", description = "Empirical coefficient"] -@constants ρwater = 1000.0 [unit = u"kg*m^-3"] +@constants ρwater = 1000.0 [unit = u"kg*m^-3", description = "water density"] @constants Vdr = 5.0 [unit = u"m/s", description = "raindrop fall speed"] """ From 27a5ef2f3a933a223dbd6fe2253516cc75604d57 Mon Sep 17 00:00:00 2001 From: jialinl6 Date: Fri, 23 Feb 2024 13:17:22 -0600 Subject: [PATCH 2/4] Turns out those functions and variables are important during test for wesley1989.jl --- src/wesley1989.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wesley1989.jl b/src/wesley1989.jl index 62f64e9e..011badcd 100644 --- a/src/wesley1989.jl +++ b/src/wesley1989.jl @@ -1,4 +1,4 @@ -export WesleySurfaceResistance +export GasData, r_s, r_dc, r_mx, r_smx, r_lux, r_clx, r_gsx, WesleySurfaceResistance, inf, r_i, r_lu, r_ac, r_gsS, r_gsO, r_clS, r_clO, So2Data, O3Data, No2Data, NoData, Hno3Data, H2o2Data, GasData, AldData, HchoData, OpData, PaaData, OraData, Nh3Data, PanData, Hno2Data const inf = 1.e25 From 6470d64b45c32b8c221e13f5d94741fe4d413359 Mon Sep 17 00:00:00 2001 From: jialinl6 Date: Thu, 29 Feb 2024 13:11:40 -0600 Subject: [PATCH 3/4] Delete unnecessary export functions and variables in wesley1989.jl --- src/wesley1989.jl | 2 +- test/wesely1989_test.jl | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/wesley1989.jl b/src/wesley1989.jl index 011badcd..62f64e9e 100644 --- a/src/wesley1989.jl +++ b/src/wesley1989.jl @@ -1,4 +1,4 @@ -export GasData, r_s, r_dc, r_mx, r_smx, r_lux, r_clx, r_gsx, WesleySurfaceResistance, inf, r_i, r_lu, r_ac, r_gsS, r_gsO, r_clS, r_clO, So2Data, O3Data, No2Data, NoData, Hno3Data, H2o2Data, GasData, AldData, HchoData, OpData, PaaData, OraData, Nh3Data, PanData, Hno2Data +export WesleySurfaceResistance const inf = 1.e25 diff --git a/test/wesely1989_test.jl b/test/wesely1989_test.jl index 2738e588..95177ea2 100644 --- a/test/wesely1989_test.jl +++ b/test/wesely1989_test.jl @@ -104,10 +104,10 @@ function TestWesely() testData = [SO2, O3, NO2, H2O2, ALD, HCHO, OP, PAA, ORA, NH3, PAN, HNO2] gasData = [ - So2Data, O3Data, No2Data, - H2o2Data, AldData, HchoData, - OpData, PaaData, OraData, - Nh3Data, PanData, Hno2Data] + AtmosphericDeposition.So2Data, AtmosphericDeposition.O3Data, AtmosphericDeposition.No2Data, + AtmosphericDeposition.H2o2Data, AtmosphericDeposition.AldData, AtmosphericDeposition.HchoData, + AtmosphericDeposition.OpData, AtmosphericDeposition.PaaData, AtmosphericDeposition.OraData, + AtmosphericDeposition.Nh3Data, AtmosphericDeposition.PanData, AtmosphericDeposition.Hno2Data] for i in 1:12 pol = polNames[i] @@ -148,12 +148,12 @@ end @testset "wesley1989.jl" begin @test TestWesely() == true - @test r_s(1.0, 1.0, 1, 1, true) ≈ 3.0772306344553016e30 - @test r_dc(1.0, 1.0) ≈ 9.181727363545544 - @test r_mx(1.0, 1.0) ≈ 0.009999966666777778 - @test r_smx(1.0, 1.0, 1.0) ≈ 2.0 - @test r_lux(1.0, 1.0, 1, 1, true, false, true, false) ≈ 50 - @test r_clx(1.0, 1.0, 1, 1) ≈ 9.999899563027895e24 - @test r_gsx(1.0, 1.0, 1, 1) ≈ 299.9977500168749 + @test AtmosphericDeposition.r_s(1.0, 1.0, 1, 1, true) ≈ 3.0772306344553016e30 + @test AtmosphericDeposition.r_dc(1.0, 1.0) ≈ 9.181727363545544 + @test AtmosphericDeposition.r_mx(1.0, 1.0) ≈ 0.009999966666777778 + @test AtmosphericDeposition.r_smx(1.0, 1.0, 1.0) ≈ 2.0 + @test AtmosphericDeposition.r_lux(1.0, 1.0, 1, 1, true, false, true, false) ≈ 50 + @test AtmosphericDeposition.r_clx(1.0, 1.0, 1, 1) ≈ 9.999899563027895e24 + @test AtmosphericDeposition.r_gsx(1.0, 1.0, 1, 1) ≈ 299.9977500168749 @test WesleySurfaceResistance(So2Data, 1.0, 1.0, 1.0, 1, 1, true, true, true, false) ≈ 45.45454545454546 end From 19ef574027d3d4a6a993d33882d3fd0429e73313 Mon Sep 17 00:00:00 2001 From: jialinl6 Date: Thu, 29 Feb 2024 13:25:39 -0600 Subject: [PATCH 4/4] Fix errors during tests --- test/drydep_test.jl | 4 ++-- test/wesely1989_test.jl | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/drydep_test.jl b/test/drydep_test.jl index 3bb53a50..517e3df4 100644 --- a/test/drydep_test.jl +++ b/test/drydep_test.jl @@ -28,7 +28,7 @@ end #@test unit(dH2O(300u"K"))==u"m^2/s" @test ModelingToolkit.get_unit(DryDepParticle(z, z₀, u_star, L, Dp, T, P, ρParticle, ρA, 1, 1)) == u"m/s" #@test unit(DryDepParticle(0.4u"m",0.3u"m",1u"m/s", 1u"m", 1e-6u"m", 300u"K", 10300u"Pa", 1u"kg*m^-3",0.001u"kg*m^-3",1,1)) == u"m/s" - @test ModelingToolkit.get_unit(DryDepGas(z, z₀, u_star, L, ρA, So2Data, G, T, θ, 1, 1, false, false, true, false)) == u"m/s" + @test ModelingToolkit.get_unit(DryDepGas(z, z₀, u_star, L, ρA, AtmosphericDeposition.So2Data, G, T, θ, 1, 1, false, false, true, false)) == u"m/s" #@test unit(DryDepGas(0.4u"m",0.3u"m",1u"m/s", 1u"m", 0.001u"kg*m^-3", So2Data, 800u"W*m^-2", 300u"K", 0, 1, 1, false, false, true, false)) == u"m/s" end @@ -73,7 +73,7 @@ end @testset "DryDepGas" begin vd_true = 0.03 # m/s - @test (substitute(DryDepGas(z, z₀, u_star, L, ρA, No2Data, G, T, 0, 1, 10, false, false, false, false), Dict(z => 50, z₀ => 0.04, u_star => 0.44, L => 0, T => 298, ρA => 1.2, G => 300, defaults...)) - vd_true) / vd_true < 0.33 + @test (substitute(DryDepGas(z, z₀, u_star, L, ρA, AtmosphericDeposition.No2Data, G, T, 0, 1, 10, false, false, false, false), Dict(z => 50, z₀ => 0.04, u_star => 0.44, L => 0, T => 298, ρA => 1.2, G => 300, defaults...)) - vd_true) / vd_true < 0.33 end @testset "DryDepParticle" begin diff --git a/test/wesely1989_test.jl b/test/wesely1989_test.jl index 95177ea2..ba694862 100644 --- a/test/wesely1989_test.jl +++ b/test/wesely1989_test.jl @@ -155,5 +155,5 @@ end @test AtmosphericDeposition.r_lux(1.0, 1.0, 1, 1, true, false, true, false) ≈ 50 @test AtmosphericDeposition.r_clx(1.0, 1.0, 1, 1) ≈ 9.999899563027895e24 @test AtmosphericDeposition.r_gsx(1.0, 1.0, 1, 1) ≈ 299.9977500168749 - @test WesleySurfaceResistance(So2Data, 1.0, 1.0, 1.0, 1, 1, true, true, true, false) ≈ 45.45454545454546 + @test WesleySurfaceResistance(AtmosphericDeposition.So2Data, 1.0, 1.0, 1.0, 1, 1, true, true, true, false) ≈ 45.45454545454546 end