-
Notifications
You must be signed in to change notification settings - Fork 6
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 #157 from worlddynamics/world1b
Implement World1B update Thnx @universmile for reviewing.
- Loading branch information
Showing
11 changed files
with
113 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module World1B | ||
|
||
using ModelingToolkit | ||
using WorldDynamics | ||
|
||
include("world1b/tables.jl") | ||
include("world1b/parameters.jl") | ||
include("world1b/initialisations.jl") | ||
include("world1b/subsystems.jl") | ||
include("world1b/scenarios.jl") | ||
include("world1b/plots.jl") | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
_inits = copy(World1A._inits) | ||
|
||
getinitialisations() = copy(_inits) |
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,5 @@ | ||
_params = copy(World1A._params) | ||
|
||
_params[:ciafn] = 0.3 | ||
|
||
getparameters() = copy(_params) |
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,29 @@ | ||
function standardrunsolution() | ||
isdefined(@__MODULE__, :_solution_standardrun) && return _solution_standardrun | ||
global _solution_standardrun = solve(standard_run(), (1900, 2100)) | ||
return _solution_standardrun | ||
end | ||
|
||
function _variables_std() | ||
@named w1 = World1.world1() | ||
|
||
variables = [ | ||
(w1.pop, 1e9, 3e9, "Population"), | ||
(w1.polr, 0, 0.8, "Pollution"), | ||
(w1.ci, 0, 2e9, "Capital investment"), | ||
(w1.fr, 0.9, 1.1, "Food ratio"), | ||
(w1.cr, 0.1, 0.9, "Crowding ratio"), | ||
(w1.msl, 0.1, 0.5, "Material standard of living"), | ||
(w1.qlm, 0.2, 0.6, "Quality of life from materials"), | ||
(w1.ql, 0.65, 0.85, "Quality of life"), | ||
(w1.ciaf, 0.23, 0.31, "Capital in agriculture"), | ||
(w1.nr, 500e9, 900e9, "Natural resources"), | ||
] | ||
|
||
return variables | ||
end | ||
|
||
|
||
@variables t | ||
|
||
fig_std(; kwargs...) = plotvariables(standardrunsolution(), (t, 1900, 2100), _variables_std(); title="WRLD1B-STD", showaxis=false, showlegend=false,kwargs...) |
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,26 @@ | ||
function standard_run(; kwargs...) | ||
@named w1 = World1.standard_run(params=_params, inits=_inits, tables=_tables, ranges=_ranges) | ||
@named w1a = World1A.standard_run(params=_params, inits=_inits, tables=_tables, ranges=_ranges) | ||
@named w1b = world1b() | ||
|
||
systems = [w1, w1a, w1b] | ||
|
||
connection_eqs = [ | ||
w1b.qlm ~ w1.qlm | ||
w1b.qlf ~ w1.qlf | ||
] | ||
|
||
system = WorldDynamics.compose(systems, connection_eqs) | ||
|
||
@variables t | ||
D = Differential(t) | ||
|
||
new_equations = equations(system) | ||
new_equations[10] = w1.msl ~ w1.ecir / (1.0 - _params[:ciafn]) | ||
new_equations[27] = w1.cira ~ w1.cir * w1.ciaf / _params[:ciafn] | ||
new_equations[7] = D(w1.ciaf) ~ (w1.cfifr * w1b.ciqr - w1.ciaf) / (w1.ciaft) | ||
|
||
@named new_system = ODESystem(new_equations) | ||
|
||
return new_system | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
@variables t | ||
|
||
function world1b(; name, params=_params, inits=_inits, tables=_tables, ranges=_ranges) | ||
@variables qlm(t) qlf(t) | ||
@variables ciqr(t) | ||
|
||
eqs = [ | ||
ciqr ~ interpolate(qlm / qlf, tables[:ciqr], ranges[:ciqr]) | ||
] | ||
|
||
ODESystem(eqs; name) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
_tables = copy(World1A._tables) | ||
_ranges = copy(World1A._ranges) | ||
|
||
_tables[:brmm] = (1.2, 1.0, 0.85, 0.75, 0.7, 0.7) | ||
_tables[:cfifr] = (1.0, 0.6, 0.3, 0.15, 0.1) | ||
_tables[:ciqr] = (0.7, 0.8, 1.0, 1.5, 2.0) | ||
|
||
_ranges[:ciqr] = (0.0, 2.0) | ||
|
||
gettables() = copy(_tables) | ||
getranges() = copy(_ranges) |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
using WorldDynamics, Test, PlotlyJS | ||
|
||
@testset "World1B" begin | ||
@test isa(World1B.fig_std(), PlotlyJS.SyncPlot) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
using WorldDynamics, Test, ModelingToolkit | ||
|
||
@testset "World1B" begin | ||
@test isa(World1B.standard_run(), ModelingToolkit.ODESystem) | ||
end |