-
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 pull request #19 from PALEOtoolkit/ocean_chemistry
Move Xiyuan's ocean chemistry example to a new folder
- Loading branch information
Showing
13 changed files
with
494 additions
and
177 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
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 |
---|---|---|
|
@@ -2,3 +2,5 @@ reservoirs | |
solvers | ||
error_examples | ||
CPU | ||
ocean_chemistry | ||
|
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,136 @@ | ||
# Ocean chemistry | ||
|
||
These examples illustrate how to implement: | ||
- a minimal model of the marine carbonate system | ||
- air-sea exchange of CO2 between ocean and atmosphere Domains | ||
|
||
See `PALEOmodel` [documentation](https://paleotoolkit.github.io/PALEOmodel.jl/) for more information on analysing model output. | ||
|
||
## Example 1 Minimal Alk-pH model | ||
|
||
Generalizing the Reaction to establish a minimal Alk-pH model. Math equations are from Richard E. Zeebe's book(2001). | ||
|
||
### Additional code files | ||
The Reaction code (file `examples/ocean_chemistry/reactions_Alk_pH.jl`) now produces calculation of different carbonic acid `HCO3_conc`, `CO3_conc`, `CO2_aq_conc`, and coeval concentrations change of `BOH4_conc`, `H_conc`, `OH_conc`, `DIC_conc` and `TAlk_conc`: | ||
```@eval | ||
str = read("../../../../examples/ocean_chemistry/reactions_Alk_pH.jl", String) | ||
str = """```julia | ||
$str | ||
```""" | ||
import Markdown | ||
Markdown.parse(str) | ||
``` | ||
|
||
### yaml configuration file | ||
The model configuration (file `examples/ocean_chemistry/config_ex1.yaml`) contains two Reservoirs `DIC`, `TAlk`. | ||
A `ReactionFluxPerturb` from the PALEOboxes.jl reaction catalog is used to add a constant TAlk flux. | ||
```@eval | ||
str = read("../../../../examples/ocean_chemistry/config_ex1.yaml", String) | ||
str = """```julia | ||
$str | ||
```""" | ||
import Markdown | ||
Markdown.parse(str) | ||
``` | ||
|
||
### Run script | ||
The script to run the model (file `examples/ocean_chemistry/run_ex1.jl`) contains: | ||
```@eval | ||
str = read("../../../../examples/ocean_chemistry/run_ex1.jl", String) | ||
str = """```julia | ||
$str | ||
```""" | ||
import Markdown | ||
Markdown.parse(str) | ||
``` | ||
and produces output showing the change, if `TAlk_conc` increase, how the carbonic acid and pH change in ocean: | ||
```@example ex1 | ||
include("../../../../examples/ocean_chemistry/run_ex1.jl") # hide | ||
plot(paleorun.output, ["ocean.TAlk_conc", "ocean.DIC_conc"], (cell=1,); ylabel="TAlk, DIC conc (mol m-3)") # hide | ||
savefig("ex1_plot1.svg"); nothing # hide | ||
plot(paleorun.output, "ocean.pH", (cell=1,)) # hide | ||
savefig("ex1_plot2.svg"); nothing # hide | ||
plot(paleorun.output, ["ocean.DIC_conc", "ocean.HCO3_conc", "ocean.CO3_conc", "ocean.CO2_aq_conc"], (cell=1,); ylabel="DIC species (mol m-3)") # hide | ||
savefig("ex1_plot3.svg"); nothing # hide | ||
``` | ||
|
||
![](ex1_plot1.svg) | ||
![](ex1_plot2.svg) | ||
![](ex1_plot3.svg) | ||
|
||
|
||
### Displaying model structure and variables | ||
|
||
All metadata for model variables can be displayed with `PB.show_variables`: | ||
```@example ex1 | ||
show(PB.show_variables(model), allcols=true, allrows=true) # display in REPL | ||
# vscodedisplay(PB.show_variables(model)) # more convenient when using VS code | ||
``` | ||
|
||
## Example 2 Air-sea exchange | ||
|
||
Adds air-sea exchange of CO2 to Example 1 | ||
|
||
### Additional code files | ||
|
||
In order to evaluate the CO2 flux change between air and sea, we add a file (file `examples/ocean_chemistry/reactions_AirSeaExchange.jl`) to achieve air-sea CO2 exchange following Henry's Law. | ||
```@eval | ||
str = read("../../../../examples/ocean_chemistry/reactions_AirSeaExchange.jl", String) | ||
str = """```julia | ||
$str | ||
```""" | ||
import Markdown | ||
Markdown.parse(str) | ||
``` | ||
|
||
### yaml configuration file | ||
The model configuration (file `examples/ocean_chemistry/config_ex2.yaml`) contains three Reservoirs `DIC`, `TAlk` and `CO2`. Following `reservoirs` [Example 4 Transfer between Domains](@ref), we use `ReactionFluxTarget` and `ReactionFluxTransfer` to transfer `CO2_airsea_exchange` between `DIC` reservoir and `CO2` reservoir: | ||
```@eval | ||
str = read("../../../../examples/ocean_chemistry/config_ex2.yaml", String) | ||
str = """```julia | ||
$str | ||
```""" | ||
import Markdown | ||
Markdown.parse(str) | ||
``` | ||
|
||
### Run script | ||
The script to run the model (file `examples/ocean_chemistry/run_ex2.jl`) contains: | ||
```@eval | ||
str = read("../../../../examples/ocean_chemistry/run_ex2.jl", String) | ||
str = """```julia | ||
$str | ||
```""" | ||
import Markdown | ||
Markdown.parse(str) | ||
``` | ||
and produces output showing the change, if `TAlk_conc` increase, how the carbonic acid and pH change in ocean and CO2 change in the air: | ||
```@example ex2 | ||
include("../../../../examples/ocean_chemistry/run_ex2.jl") # hide | ||
plot(paleorun.output, ["ocean.TAlk_conc", "ocean.DIC_conc"], (cell=1,); ylabel="TAlk, DIC conc (mol m-3)") # hide | ||
savefig("ex2_plot1.svg"); nothing # hide | ||
plot(paleorun.output, "ocean.pH", (cell=1,)) # hide | ||
savefig("ex2_plot2.svg"); nothing # hide | ||
plot(paleorun.output, ["ocean.DIC_conc", "ocean.HCO3_conc", "ocean.CO3_conc", "ocean.CO2_aq_conc"], (cell=1,); ylabel="DIC species (mol m-3)") # hide | ||
savefig("ex2_plot3.svg"); nothing # hide | ||
display(plot(paleorun.output, "atm.pCO2atm", )) # hide | ||
savefig("ex2_plot4.svg"); nothing # hide | ||
display(plot(paleorun.output, ["global.C_total", "atm.CO2", "ocean.DIC_total"] ; ylabel="atm-ocean carbon (mol)")) | ||
savefig("ex2_plot5.svg"); nothing # hide | ||
``` | ||
|
||
![](ex2_plot1.svg) | ||
![](ex2_plot2.svg) | ||
![](ex2_plot3.svg) | ||
![](ex2_plot4.svg) | ||
![](ex2_plot5.svg) | ||
|
||
### Displaying model structure and variables | ||
|
||
All metadata for model variables can be displayed with `PB.show_variables`: | ||
```@example ex2 | ||
show(PB.show_variables(model), allcols=true, allrows=true) # display in REPL | ||
# vscodedisplay(PB.show_variables(model)) # more convenient when using VS code | ||
``` | ||
|
||
For more information and cooperation, please communicate with us! |
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,83 @@ | ||
Minimal_Alk_pH: | ||
|
||
domains: | ||
|
||
global: | ||
|
||
reactions: | ||
add_Alk: | ||
# from PALEOboxes reaction catalog: constant input flux of Alk | ||
class: ReactionFluxPerturb | ||
parameters: | ||
# linear interpolation for input flux - set to constant | ||
perturb_times: [-1e30, 1e30] | ||
# ocean volume = 3.6e14 * 3688.0 = 1.33e18 m^3 | ||
# DIC in ocean = 2 * 1.33e18 = 2.66e18 mol | ||
# set Alk flux so Alk = DIC after 100 yr-1 = 2.66e18/100 = 2.66e16 mol yr-1 | ||
perturb_totals: [2.66e16, 2.66e16] | ||
variable_links: | ||
F: ocean.TAlk_sms # add flux to TAlk reservoir NB: works for single-box ocean only !! | ||
# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ||
|
||
ocean: | ||
|
||
reactions: | ||
|
||
oceantrasport: | ||
|
||
class: ReactionOceanNoTransport | ||
|
||
parameters: | ||
|
||
area: [3.6e14] | ||
depth: [3688.0] | ||
|
||
|
||
|
||
reservoir_TA: | ||
|
||
class: ReactionReservoir | ||
|
||
variable_links: | ||
R*: TAlk* | ||
variable_attributes: | ||
R:initial_value: 0.0 | ||
R:norm_value: 2.4e0 | ||
|
||
|
||
|
||
reservoir_DIC: | ||
class: ReactionReservoir | ||
|
||
variable_links: | ||
R*: DIC* | ||
variable_attributes: | ||
R:initial_value: 2.0e0 | ||
R:norm_value: 2.0e0 | ||
|
||
|
||
solve_Alk_pH: | ||
|
||
class: Reaction_Alk_pH | ||
|
||
parameters: | ||
|
||
# kappa: 1.0 | ||
# density: 1027.0 | ||
# TAlk_conc_change: 10.0e-7 | ||
|
||
K_1: 1.4e-6 | ||
K_2: 1.2e-9 | ||
K_w: 6.0e-14 | ||
K_B: 2.5e-9 | ||
B_total: 4.2e-4 | ||
|
||
variable_links: | ||
density: rho_ref # OceanNoTransport provides density as rho_ref | ||
|
||
|
||
oceanfloor: | ||
# unused here, set up by ReactionOceanNoTransport | ||
|
||
oceansurface: | ||
# unused here, set up by ReactionOceanNoTransport |
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
Oops, something went wrong.