Skip to content
Snippets Groups Projects
Commit 180d62d6 authored by Brian Groenke's avatar Brian Groenke
Browse files

Fix failing tests and remove Presets submodule

parent 94720260
No related branches found
No related tags found
No related merge requests found
Showing
with 44 additions and 42 deletions
......@@ -51,12 +51,12 @@ using Plots: plot
# The forcing file will be automatically downloaded to the input/ folder if not already present.
forcings = loadforcings(CryoGrid.Forcings.Samoylov_ERA_obs_fitted_1979_2014_spinup_extended_2044);
# get preset soil and initial temperature profile for Samoylov
soilprofile, tempprofile = CryoGrid.Presets.SamoylovDefault
soilprofile, tempprofile = CryoGrid.SamoylovDefault
initT = initializer(:T, tempprofile)
# choose grid with 5cm spacing
grid = CryoGrid.Presets.DefaultGrid_5cm
grid = CryoGrid.DefaultGrid_5cm
# build a default Tile with heat conduction on the given soil profile
tile = CryoGrid.Presets.SoilHeatTile(
tile = CryoGrid.SoilHeatTile(
TemperatureBC(forcings.Tair),
GeothermalHeatFlux(0.053u"W/m^2"),
soilprofile,
......
......@@ -65,7 +65,7 @@ using CryoGrid
using CryoGrid.Diagnostics
soil = Ground()
grid = CryoGrid.Presets.DefaultGrid_5cm
grid = CryoGrid.DefaultGrid_5cm
state = Diagnostics.build_dummy_state(grid, soil)
@which CryoGrid.computediagnostic!(soil, state)
......
......@@ -18,7 +18,7 @@ strat = Stratigraphy(
0.0u"m" => Ground(soilprofile, HeatBalance(:H; freezecurve=DallAmico())),
1000.0u"m" => Bottom(GeothermalHeatFlux(0.053u"J/s/m^2"))
);
grid = CryoGrid.Presets.DefaultGrid_5cm
grid = CryoGrid.DefaultGrid_5cm
# define initial conditions for temperature using a given profile;
# The default initializer linearly interpolates between profile points.
initT = initializer(:T, tempprofile)
......
## Quick start
After [installing](installation.md) `CryoGrid.jl`, you can get started right away with a simple soil heat model. The [`Presets`](@ref) module (aliased `CryoGrid.Presets`) provides pre-specified model configurations that can be obtained with a single function call. It is also possible to provide a custom soil and temperature profile to `SoilHeatTile`; here the values given in `Presets.SamoylovDefault` is used.
After [installing](installation.md) `CryoGrid.jl`, you can get started right away with a simple soil heat model. The [`Presets`](@ref) module (aliased `CryoGrid.Presets`) provides pre-specified model configurations that can be obtained with a single function call. It is also possible to provide a custom soil and temperature profile to `SoilHeatTile`; here the values given in `SamoylovDefault` is used.
```julia
using CryoGrid
......@@ -10,12 +10,12 @@ using Plots
# The forcing file will be automatically downloaded to the input/ folder if not already present.
forcings = loadforcings(CryoGrid.Forcings.Samoylov_ERA_obs_fitted_1979_2014_spinup_extended_2044, :Tair => u"°C");
# get preset soil and initial temperature profile for Samoylov
soilprofile, tempprofile = CryoGrid.Presets.SamoylovDefault
soilprofile, tempprofile = CryoGrid.SamoylovDefault
initT = initializer(:T, tempprofile)
# choose grid with 5cm spacing
grid = CryoGrid.Presets.DefaultGrid_5cm
grid = CryoGrid.DefaultGrid_5cm
# build Tile from the given soil and temperature profiles
tile = CryoGrid.Presets.SoilHeatTile(TemperatureBC(forcings.Tair), GeothermalHeatFlux(0.053u"W/m^2"), soilprofile, initT, grid=grid)
tile = CryoGrid.SoilHeatTile(TemperatureBC(forcings.Tair), GeothermalHeatFlux(0.053u"W/m^2"), soilprofile, initT, grid=grid)
# define time span (1 year)
tspan = (DateTime(2010,11,30),DateTime(2011,11,30))
u0, du0 = initialcondition!(tile, tspan)
......
......@@ -42,7 +42,7 @@ strat = Stratigraphy(
soil_layers,
z_bot => Bottom(GeothermalHeatFlux(0.053u"W/m^2"))
);
modelgrid = CryoGrid.Presets.DefaultGrid_2cm
modelgrid = CryoGrid.DefaultGrid_2cm
tile = Tile(strat, modelgrid, ssinit);
# Since the solver can take daily timesteps, we can easily specify longer simulation time spans at minimal cost.
# Here we specify a time span of 10 years.
......
......@@ -6,7 +6,7 @@
# Frist, load forcings and define boundary conditions.
using CryoGrid
forcings = loadforcings(CryoGrid.Forcings.Samoylov_ERA_obs_fitted_1979_2014_spinup_extended_2044);
_, tempprofile = CryoGrid.Presets.SamoylovDefault;
_, tempprofile = CryoGrid.SamoylovDefault;
initT = initializer(:T, tempprofile)
initsat = initializer(:sat, (l,state) -> state.sat .= l.para.sat);
upperbc = WaterHeatBC(
......@@ -23,7 +23,7 @@ strat = @Stratigraphy(
2.0u"m" => Ground(SimpleSoil(por=0.10,sat=1.0,org=0.0), heat=HeatBalance(), water=WaterBalance(BucketScheme())),
1000.0u"m" => Bottom(GeothermalHeatFlux(0.053u"W/m^2")),
);
modelgrid = CryoGrid.Presets.DefaultGrid_2cm
modelgrid = CryoGrid.DefaultGrid_2cm
tile = Tile(strat, modelgrid, forcings, initT, initsat);
# Now we set up the problem and solve using the integrator interface.
......
......@@ -20,7 +20,7 @@ tempprofile_linear = TemperatureProfile(
10.0u"m" => -10.0u"°C",
1000.0u"m" => 10.2u"°C"
)
modelgrid = Grid(vcat(-1.0u"m":0.02u"m":-0.02u"m", CryoGrid.Presets.DefaultGrid_2cm))
modelgrid = Grid(vcat(-1.0u"m":0.02u"m":-0.02u"m", CryoGrid.DefaultGrid_2cm))
z_top = -1.0u"m"
z_sub = keys(soilprofile)
z_bot = modelgrid[end]
......
......@@ -36,7 +36,7 @@ strat = @Stratigraphy(
soil_layers...,
z_bot => Bottom(GeothermalHeatFlux(0.053u"W/m^2"))
);
modelgrid = Grid(vcat(z_top:0.02u"m":-0.02u"m", CryoGrid.Presets.DefaultGrid_2cm))
modelgrid = Grid(vcat(z_top:0.02u"m":-0.02u"m", CryoGrid.DefaultGrid_2cm))
tile = Tile(strat, modelgrid, forcings, ssinit);
# Since the solver can take daily timesteps, we can easily specify longer simulation time spans at minimal cost.
......
......@@ -23,14 +23,14 @@ soilprofile = SoilProfile(
);
# We construct a state variable initializer for temperature `T` from the temperature profile preset for Samoylov.
initT = initializer(:T, CryoGrid.Presets.SamoylovDefault.tempprofile);
initT = initializer(:T, CryoGrid.SamoylovDefault.tempprofile);
# We choose the default grid discretization with 5 cm spacing at the surface.
grid = CryoGrid.DefaultGrid_5cm;
# Now we construct the Tile using the built-in model configuration `SoilHeatTile` which defines a
# standalone soil straigraphy with only heat conduction and no water flow.
tile = CryoGrid.Presets.SoilHeatTile(
tile = CryoGrid.SoilHeatTile(
:H,
TemperatureBC(Input(:Tair), NFactor(nf=Param(0.6), nt=Param(0.9))),
GeothermalHeatFlux(0.053u"W/m^2"),
......@@ -59,7 +59,4 @@ out = CryoGridOutput(sol)
import Plots
zs = [1,10,20,30,50,100,200,500,1000]u"cm"
cg = Plots.cgrad(:copper,rev=true);
Plots.plot(out.T[Z(Near(zs))], color=cg[LinRange(0.0,1.0,length(zs))]', ylabel="Temperature", leg=false, size=(800,500), dpi=150)
using BenchmarkTools
@profview @btime $tile($du0, $u0, $prob.p, $prob.tspan[1])
Plots.plot(out.T[Z(Near(zs))], color=cg[LinRange(0.0,1.0,length(zs))]', ylabel="Temperature", leg=false, size=(800,500), dpi=150)
\ No newline at end of file
......@@ -8,7 +8,7 @@ using CryoGrid
using OrdinaryDiffEq
# First, load the forcings and construct the Tile.
modelgrid = CryoGrid.Presets.DefaultGrid_2cm;
modelgrid = CryoGrid.DefaultGrid_2cm;
soilprofile = SoilProfile(
0.0u"m" => SimpleSoil(por=0.80,sat=1.0,org=0.75),
0.1u"m" => SimpleSoil(por=0.80,sat=1.0,org=0.25),
......@@ -17,9 +17,9 @@ soilprofile = SoilProfile(
10.0u"m" => SimpleSoil(por=0.30,sat=1.0,org=0.0),
);
## mid-winter temperature profile
tempprofile = CryoGrid.Presets.SamoylovDefault.tempprofile
tempprofile = CryoGrid.SamoylovDefault.tempprofile
forcings = loadforcings(CryoGrid.Forcings.Samoylov_ERA_obs_fitted_1979_2014_spinup_extended_2044);
tempprofile = CryoGrid.Presets.SamoylovDefault.tempprofile
tempprofile = CryoGrid.SamoylovDefault.tempprofile
initT = initializer(:T, tempprofile)
seb = SurfaceEnergyBalance()
swb = SurfaceWaterBalance()
......
......@@ -15,7 +15,7 @@ soilprofile = SoilProfile(
3.0u"m" => SimpleSoil(por=0.50,sat=1.0,org=0.0),
10.0u"m" => SimpleSoil(por=0.30,sat=1.0,org=0.0),
);
initT = initializer(:T, CryoGrid.Presets.SamoylovDefault.tempprofile)
initT = initializer(:T, CryoGrid.SamoylovDefault.tempprofile)
initsat = initializer(:sat, 1.0)
z_top = -2.0u"m"
z_sub = keys(soilprofile)
......@@ -39,7 +39,7 @@ strat = @Stratigraphy(
ground_layers...,
z_bot => Bottom(GeothermalHeatFlux(0.053u"J/s/m^2"))
);
modelgrid = CryoGrid.Presets.DefaultGrid_5cm
modelgrid = CryoGrid.DefaultGrid_5cm
tile = Tile(strat, modelgrid, forcings, initT, initsat)
# define time span, 2 years + 3 months
tspan = (DateTime(2010,9,30), DateTime(2012,9,30))
......
......@@ -8,7 +8,7 @@
using CryoGrid
# Select default grid and initial temperature profile.
grid = CryoGrid.Presets.DefaultGrid_10cm
grid = CryoGrid.DefaultGrid_10cm
tempprofile = TemperatureProfile(
0.0u"m" => -20.0u"°C",
1000.0u"m" => 10.0u"°C",
......@@ -31,7 +31,7 @@ Plots.plot(-2.0u"°C":0.01u"K":0.0u"°C", sfcc)
# specified.
heatop = Heat.Diffusion1D(:H)
initT = initializer(:T, tempprofile)
tile = CryoGrid.Presets.SoilHeatTile(
tile = CryoGrid.SoilHeatTile(
heatop,
## 10 W/m^2 in and out, i.e. net zero flux
ConstantBC(HeatBalance, CryoGrid.Neumann, 10.0u"W/m^2"),
......
......@@ -38,7 +38,7 @@ strat = @Stratigraphy(
2.0u"m" => Ground(SimpleSoil(por=0.10,sat=1.0,org=0.0,freezecurve=sfcc); heat, water),
1000.0u"m" => Bottom(GeothermalHeatFlux(0.053u"W/m^2"))
);
grid = CryoGrid.Presets.DefaultGrid_2cm
grid = CryoGrid.DefaultGrid_2cm
tile = Tile(strat, grid, forcings, initT);
u0, du0 = @time initialcondition!(tile, tspan)
prob = CryoGridProblem(tile, u0, tspan, saveat=3*3600, savevars=(:T,:θw,:θwi,:kw));
......
......@@ -14,7 +14,7 @@ strat = @Stratigraphy(
0.0u"m" => SalineGround(SimpleSoil(freezecurve=sfcc), heat=HeatBalance(:T), salt=SaltMassBalance()),
1000.0u"m" => Bottom(GeothermalHeatFlux(0.053u"W/m^2"))
);
modelgrid = CryoGrid.Presets.DefaultGrid_10cm
modelgrid = CryoGrid.DefaultGrid_10cm
tile = Tile(strat, modelgrid, initT, initsalt, initpor)
tspan = (DateTime(1990,1,1),DateTime(2000,12,31))
u0, du0 = initialcondition!(tile, tspan)
......
......@@ -5,14 +5,15 @@
using CryoGrid
# First we set up the soil heat model:
# First we set up the soil heat model. Note that the default soil profile
# for Samoylov already includes the appropriate freeze curves.
forcings = loadforcings(CryoGrid.Forcings.Samoylov_ERA5_fitted_daily_1979_2020);
grid = CryoGrid.Presets.DefaultGrid_5cm
soilprofile, tempprofile = CryoGrid.Presets.SamoylovDefault
grid = CryoGrid.DefaultGrid_5cm
soilprofile, tempprofile = CryoGrid.SamoylovDefault
initT = initializer(:T, tempprofile)
upperbc = TemperatureBC(Input(:Tair), NFactor(nf=0.6, nt=0.9))
lowerbc = GeothermalHeatFlux(0.053u"W/m^2")
tile = CryoGrid.Presets.SoilHeatTile(upperbc, lowerbc, soilprofile, forcings, initT; grid=grid)
tile = CryoGrid.SoilHeatTile(upperbc, lowerbc, soilprofile, forcings, initT; grid=grid)
tspan = (DateTime(2010,10,30),DateTime(2011,10,30))
u0, du0 = @time initialcondition!(tile, tspan)
prob = CryoGridProblem(tile, u0, tspan, saveat=3*3600.0, savevars=(:T,));
......
......@@ -7,10 +7,10 @@
# Set up forcings and boundary conditions similarly to other examples:
using CryoGrid
forcings = loadforcings(CryoGrid.Forcings.Samoylov_ERA_obs_fitted_1979_2014_spinup_extended_2044);
soilprofile, tempprofile = CryoGrid.Presets.SamoylovDefault
grid = CryoGrid.Presets.DefaultGrid_5cm
soilprofile, tempprofile = CryoGrid.SamoylovDefault
grid = CryoGrid.DefaultGrid_5cm
initT = initializer(:T, tempprofile)
tile = CryoGrid.Presets.SoilHeatTile(
tile = CryoGrid.SoilHeatTile(
:T,
TemperatureBC(Input(:Tair), NFactor(nf=Param(0.5), nt=Param(0.9))),
GeothermalHeatFlux(0.053u"W/m^2"),
......
......@@ -36,6 +36,8 @@ import Interpolations
@reexport using Unitful
@reexport using UnPack
using SciMLBase: intervals # resolve name collision
export Interpolations
# Common types and methods
......@@ -79,6 +81,7 @@ include("IO/InputOutput.jl")
include("Tiles/Tiles.jl")
@reexport using .Tiles
using .Tiles: layers # resolve name collision
parameters = Tiles.parameters
export ConstantBC, PeriodicBC, ConstantValue, PeriodicValue, ConstantFlux, PeriodicFlux
......@@ -99,8 +102,9 @@ include("problem.jl")
export CGEuler, CryoGridIntegrator, CryoGridSolution
include("Solvers/Solvers.jl")
# Presets
include("Presets/Presets.jl")
# Built-in model definitions
export SoilHeatTile, SamoylovDefault
include("models.jl")
using .InputOutput: Resource
......
......@@ -41,7 +41,7 @@ function loadforcings(format::ForcingFormatJSON{1}, filename::String, kwargs...)
end
return Interpolated1D(DimStack((; forcings...)); kwargs...)
end
function loadforcings(format::ForcingFormatJSON{2}, filename::String)
function loadforcings(format::ForcingFormatJSON{2}, filename::String; kwargs...)
dict = open(filename, "r") do file; JSON3.read(file) end
# convert JSON3 dict for data field to Julia dict
data = Dict(dict[:data]...)
......
......@@ -35,12 +35,12 @@ SoilThermalProperties(
kh_i = ThermalProperties().kh_i,
kh_a = ThermalProperties().kh_a,
kh_o=Param(0.25, units=u"W/m/K", domain=0..Inf), # organic [Hillel (1982)]
kh_m=Param(3.8, untis=u"W/m/K", domain=0..Inf), # mineral [Hillel (1982)]
kh_m=Param(3.8, units=u"W/m/K", domain=0..Inf), # mineral [Hillel (1982)]
ch_w = ThermalProperties().ch_w,
ch_i = ThermalProperties().ch_i,
ch_a = ThermalProperties().ch_a,
ch_o=Param(2.5e6, units=u"J/K/m^3", domain=0..Inf), # heat capacity organic
ch_m=Param(2.0e6, untis=u"J/K/m^3", domain=0..Inf), # heat capacity mineral
ch_m=Param(2.0e6, units=u"J/K/m^3", domain=0..Inf), # heat capacity mineral
kwargs...,
) = ThermalProperties(; kh_w, kh_i, kh_a, kh_m, kh_o, ch_w, ch_i, ch_a, ch_m, ch_o, kwargs...)
......
......@@ -96,7 +96,7 @@ function SurfaceEnergyBalance(;
stabfun::StabilityFunctions = HøgstrømSHEBA(),
)
inputs = (; Tair, Lin, Sin, pr, qh, wind)
SurfaceEnergyBalance(; inputs, para, solscheme, stabfun)
SurfaceEnergyBalance(inputs, para, solscheme, stabfun)
end
"""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment