Skip to content

Commit

Permalink
Refactor, get rid of excess NIVAFjord setups
Browse files Browse the repository at this point in the history
  • Loading branch information
Maginor committed Nov 1, 2024
1 parent f754860 commit 76e6465
Show file tree
Hide file tree
Showing 11 changed files with 361 additions and 295 deletions.
4 changes: 4 additions & 0 deletions dev_notes/todo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

*** High pri ***



# Need @else for options.


MobiView
If the plot x axis was set to nonsense since the first selected series was entirely NaN, it won't be fixed by selecting a non-NaN series.
Expand Down
21 changes: 13 additions & 8 deletions models/modules/microplastic/mp_soil_column.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,23 +98,28 @@ This is a module for transport of microplastic in a single *experimentally contr
z : property("Effective depth")
var(layer.z, [m m]) { dz*theta + z[vert.above] } @no_store


sat_lim : property("Saturation limiter")
var(layer.sat_lim, []) {
maxcap := dz * theta,
mincap := maxcap*fcs,
s_response(water, mincap, min(1.1*mincap, maxcap), 0, 1)
} @no_store

var(layer.water.side, [m m, day-1]) {
# TODO: This is wrong... Should compute gradient based on z and, z of outside and distance.
agrad := grad*(water_tot/z),
agrad*cond->>
sat_lim*agrad*cond->>
}

var(layer.water.perc, [m m, day-1]) {
maxcap := dz * theta,
maxcap_b := dz[vert.below] * theta[vert.below],

maxrate := cond->>,
mincap := maxcap*fcs,

maxperc := s_response(water, mincap, min(1.1*mincap, maxcap), 0, maxrate),
#s_response(water[vert.below], maxcap_b, 0.9*maxcap_b, 0, maxperc)
#1.1*mincap, mincap, 0, maxrate), # Cut flow off when water saturation reaches field capacity
s_response(water[vert.below], 0.9*maxcap_b, maxcap_b, maxperc, 0) # Cut flow off when water saturation below fills up
# Cut percolation off when water saturation goes below field capacity.
maxperc := sat_lim*maxrate,
# Cut percolation off when water saturation below fills up
s_response(water[vert.below], 0.9*maxcap_b, maxcap_b, maxperc, 0)

# TODO: Capillary action when water below is above fc and this layer is below fc?
# We could also compute forces on the water, but probably not necessary
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@


module("NIVAFjord lake", version(0, 0, 1),
module("NIVAFjord lake discharge", version(0, 0, 1),
river : compartment,
basin : compartment,
layer : compartment,
Expand Down
51 changes: 36 additions & 15 deletions models/nivafjord_base.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@

model("NIVAFjord") {

# NOTE: These configurations can be overruled by an extending model
has_boundaries : constant(true)
default_airsea : constant(true)

basin_idx : index_set("Basin index")
bnd_basin_idx : index_set("Boundary basin index")
all_basins : index_set("All basins") @union(basin_idx, bnd_basin_idx)
e_idx : index_set("Fjord connection index") @sub(basin_idx) # Ideally this should not be declared in this model, but then it sometimes is declared out of order.
layer_idx : index_set("Layer index") @sub(all_basins)

option(has_boundaries) {
bnd_basin_idx : index_set("Boundary basin index")
all_basins : index_set("All basins") @union(basin_idx, bnd_basin_idx)
e_idx : index_set("Fjord connection index") @sub(basin_idx) # Ideally this should not be declared in this model, but then it sometimes is declared out of order.
layer_idx : index_set("Layer index") @sub(all_basins)
} @otherwise {
layer_idx : index_set("Layer index") @sub(basin_idx)
}

air : compartment("Atmosphere")
basin : compartment("Basin", basin_idx)
layer : compartment("Fjord layer", basin_idx, layer_idx)
sediment : compartment("Fjord sediment", basin_idx, layer_idx)
bnd_basin : compartment("Boundary basin", bnd_basin_idx)
bnd_layer : compartment("Boundary layer", bnd_basin_idx, layer_idx)

option(has_boundaries) {
bnd_basin : compartment("Boundary basin", bnd_basin_idx)
bnd_layer : compartment("Boundary layer", bnd_basin_idx, layer_idx)
}

water : quantity("Water")
ice : quantity("Ice")
Expand Down Expand Up @@ -53,20 +65,29 @@ model("NIVAFjord") {
load("modules/atmospheric.txt",
module("Atmospheric", air, temp, wind, g_rad, pressure, a_hum, rho, lwd, cos_z, a_vap, s_vap))

load("modules/airsea.txt",
module("AirSea", "AirSea Fjord", air, basin, ice, heat, temp, precip, wind, g_rad, pressure, rho, a_hum, lwd, sw, attn, indicator,
evap, cos_z, loc(basin.freeze_t), loc(basin.area), loc(layer.water[vert.top]), loc(layer.water.heat[sw_vert.top])))

all_layer : compartment("All layers", all_basins, layer_idx) # This is not used for anything other than to force a par group to distribute over all_basin
option(default_airsea) {
load("modules/airsea.txt",
module("AirSea", "AirSea Fjord", air, basin, ice, heat, temp, precip, wind, g_rad, pressure, rho, a_hum, lwd, sw, attn, indicator,
evap, cos_z, loc(basin.freeze_t), loc(basin.area), loc(layer.water[vert.top]), loc(layer.water.heat[sw_vert.top])))
}

option(has_boundaries) {
all_layer : compartment("All layers", all_basins, layer_idx) # This is not used for anything other than to force a par group to distribute over all_basin
load("modules/nivafjord/basin.txt", dims : preamble("NIVAFjord dimensions", all_layer, layer))
} @otherwise {
load("modules/nivafjord/basin.txt", dims : preamble("NIVAFjord dimensions", layer, layer))
}

load("modules/nivafjord/basin.txt",
dims : preamble("NIVAFjord dimensions", all_layer, layer),
module("NIVAFjord basin", air, basin, layer, water, salt, heat, temp, salinity, pressure, wind, g_rad, rho, attn, z, dz, h, area, freeze_t, sw, loc(basin.ice.indicator), vert, sw_vert, loc(sediment.heat), dims))

load("modules/nivafjord/boundary_basin.txt",
module("NIVAFjord boundary", bnd_basin, bnd_layer, water, heat, salt, temp, salinity, dz, h, rho, pressure, vert, dims))
option(has_boundaries) {
load("modules/nivafjord/boundary_basin.txt",
module("NIVAFjord boundary", bnd_basin, bnd_layer, water, heat, salt, temp, salinity, dz, h, rho, pressure, vert, dims))

solve(sol, bnd_basin.h)
}

sol : solver("NIVAFjord solver", inca_dascru, solver_h, solver_hmin)
solve(sol, layer.water, basin.ice)
solve(sol, bnd_basin.h)
}
42 changes: 17 additions & 25 deletions models/nivafjord_chem_base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ This won't run as its own model, it is just a base for model extension.

phyt_type : index_set("Phytoplankton type")

edge : compartment("Basin edge", basin_idx, e_idx)
edge_layer : compartment("Basin edge layer", basin_idx, e_idx, layer_idx)

load("modules/nivafjord/horizontal_fluxes.txt",
module("NIVAFjord horizontal fluxes", basin, bnd_basin, layer, bnd_layer, river, edge, edge_layer, water, salt, temp, salinity, flow, rho, pressure, dz, h, horz, vert, dims),
module("NIVAFjord simple realignment", basin, layer, water, dz, vert, dims)
)
sed : quantity("Sediments")
oc : quantity("Organic carbon")
on : quantity("Organic nitrogen")
op : quantity("Organic phosphorous")
din : quantity("Nitrate")
phos : quantity("Phosphate")

# Called 'fjord_phyt' to distinguish from freshwater in the version of the model that also has EasyLake
fjord_phyt : quantity("Fjord phytoplankton")#, phyt_type)
Expand All @@ -31,33 +31,25 @@ This won't run as its own model, it is just a base for model extension.
load("modules/nivafjord/fjordchem.txt",
chem_par : preamble("NIVAFjord chemistry rates", fjord_phyt),
module("NIVAFjord chemistry", air, basin, layer, sediment, water, o2, co2, ch4, ice, oc, din, on, phos, op, sed, fjord_phyt, zoo, chl_a, temp, salinity, wind, z, dz, indicator, attn, precip, area, cos_z, sw, o2satconc, vert, chem_par, dims))

load("modules/airsea_gas.txt",
module("AirSeaGas", air, layer, basin, water, ice, o2, co2, ch4, temp, wind, precip, o2satconc, loc(basin.ice.indicator), vert, dims))

option(default_airsea) {
load("modules/airsea_gas.txt",
module("AirSeaGas", air, layer, basin, water, ice, o2, co2, ch4, temp, wind, precip, o2satconc, loc(basin.ice.indicator), vert, dims))
}

load("modules/nivafjord/sediment.txt",
module("NIVAFjord sediments", layer, sediment, water, o2, co2, ch4, salinity, sed, oc, din, on, phos, op, heat, area, temp, dz, z, vert, chem_par, dims))

load("modules/nivafjord/boudary_chem.txt",
module("NIVAFjord boundary chemistry", bnd_layer, water, o2, oc, din, on, phos, op, fjord_phyt, chl_a, sed, chem_par))
option(has_boundaries) {
load("modules/nivafjord/boudary_chem.txt",
module("NIVAFjord boundary chemistry", bnd_layer, water, o2, oc, din, on, phos, op, fjord_phyt, chl_a, sed, chem_par))
}

load("modules/nivafjord/point_sources.txt",
module("NIVAFjord point sources", layer, water, din, on, phos, sed, oc, o2, heat, temp))

load("modules/easychem.txt",
module("Simple River O₂", river, water, o2, temp))

solve(sol, sediment.sed, sediment.heat)
solve(sol, air.cos_z)

wb_index : index_set("Water body") @union(sc, basin_idx)

downstream : connection("Downstream") @directed_graph {
river+
} @no_cycles

horz : connection("Fjord horizontal") @directed_graph(e_idx) {
(river? layer+ bnd_layer?) | river
} @no_cycles
solve(sol, sediment.sed, sediment.heat)
solve(sol, air.cos_z, air.g_rad)
}

6 changes: 6 additions & 0 deletions models/nivafjord_easylake_simplycnp_model.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ model("NIVAFjord-EasyLake-SimplyCNP") {
heat : quantity,
ice : quantity,
o2 : quantity,
sed : quantity,
oc : quantity,
din : quantity,
on : quantity,
phos : quantity,
op : quantity,
temp : property,
precip : property,
wind : property,
Expand Down
13 changes: 8 additions & 5 deletions models/nivafjord_isolated_basin_fpv_model.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@ It is also currently without horizontal exchange between basins, so it only work

# TODO: FPV cover does not dynamically affect wind mixing (not sure to how large a degree that would happen).

extend("nivafjord_lake_base.txt")
# Overrule configs for nivafjord_base
has_boundaries : constant(false)
default_airsea : constant(false)

extend("nivafjord_chem_base.txt") @exclude(
has_boundaries : constant,
default_airsea : constant,
)

tox_index : index_set("Contaminant type")

Expand Down Expand Up @@ -39,10 +46,6 @@ It is also currently without horizontal exchange between basins, so it only work
module("SimplyTox partitioning", "SimplyTox fjord layer", layer, water, oc, tox, temp, loc(layer.water.sed.oc), [n g], constant(true), phys)
)

#load("modules/nivafjord/tox.txt",
# module("NIVAFjord tox air-water", basin, layer, air, water, tox, temp, area, vert, loc(basin.ice.indicator), dims, phys)
#)

load("modules/nivafjord/horizontal_fluxes.txt",
module("NIVAFjord simple realignment", basin, layer, water, dz, vert, dims))

Expand Down
90 changes: 0 additions & 90 deletions models/nivafjord_lake_base.txt

This file was deleted.

20 changes: 11 additions & 9 deletions models/nivafjord_lake_simplytox_model.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,23 @@ TODO: Maybe we want a simpler biochemistry model for this one, not the entire NI
wind : property,
sol : solver
)

has_boundaries : constant(false)

extend("nivafjord_lake_base.txt")
extend("nivafjord_chem_base.txt") @exclude(has_boundaries : constant) # Overrule the has_boundaries from the base model.

downstream : connection("Downstream") @directed_graph { river+ } @no_cycles

river_lake : connection("River-lake") @directed_graph { river+ layer } @no_cycles

load("modules/airsea.txt",
module("AirSea", "AirSea Fjord", air, basin, ice, heat, temp, precip, wind, g_rad, pressure, rho, a_hum, lwd, sw, attn, indicator,
evap, cos_z, loc(basin.freeze_t), loc(basin.area), loc(layer.water[vert.top]), loc(layer.water.heat[sw_vert.top]))
)

load("modules/nivafjord/lake_basin.txt",
module("NIVAFjord lake", river, basin, layer, water, flow, dz, river_lake, vert, dims)
load("modules/nivafjord/lake_discharge.txt",
module("NIVAFjord lake discharge", river, basin, layer, water, flow, dz, river_lake, vert, dims)
)

load("modules/simplytox.txt",
module("SimplyTox partitioning", "SimplyTox fjord layer", layer, water, oc, tox, temp, loc(layer.water.sed.oc), [n g], constant(true), phys),
module("SimplyTox partitioning", "SimplyTox fjord sediments", sediment, water, oc, tox, temp, loc(sediment.sed.oc), [n g], constant(false), phys),
module("SimplyTox air-water", "SimplyTox lake air-water", air, basin, water, tox, temp, wind, loc(basin.area), phys)
#module("SimplyTox partitioning", "SimplyTox lake sediments", lake_sed, water, oc, tox, temp, loc(lake_sed.sed.oc), [n g, m-2], constant(false), phys)
)

load("modules/nivafjord/tox.txt",
Expand All @@ -48,6 +44,10 @@ TODO: Maybe we want a simpler biochemistry model for this one, not the entire NI
load("modules/nivafjord/horizontal_fluxes.txt",
module("NIVAFjord simple realignment", basin, layer, water, dz, vert, dims))

load("modules/easychem.txt",
module("Simple River O₂", river, water, o2, temp))

# This could maybe go into the main NIVAFjord model (put in same file as point_sources). It is relevant for different applications.
module("NIVAFjord extraction", version(0, 0, 1)) {

par_group("Extraction", layer) {
Expand All @@ -58,4 +58,6 @@ TODO: Maybe we want a simpler biochemistry model for this one, not the entire NI
ext
}
}

solve(sol, sediment.water)
}
Loading

0 comments on commit 76e6465

Please sign in to comment.