Skip to content

Commit

Permalink
Merge pull request #157 from worlddynamics/world1b
Browse files Browse the repository at this point in the history
Implement World1B update

Thnx @universmile for reviewing.
  • Loading branch information
natema authored Nov 7, 2022
2 parents 2dc45fc + 37ebba6 commit 6dfd4b9
Show file tree
Hide file tree
Showing 11 changed files with 113 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/World1B/World1B.jl
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
3 changes: 3 additions & 0 deletions src/World1B/world1b/initialisations.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
_inits = copy(World1A._inits)

getinitialisations() = copy(_inits)
5 changes: 5 additions & 0 deletions src/World1B/world1b/parameters.jl
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)
29 changes: 29 additions & 0 deletions src/World1B/world1b/plots.jl
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...)
26 changes: 26 additions & 0 deletions src/World1B/world1b/scenarios.jl
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
12 changes: 12 additions & 0 deletions src/World1B/world1b/subsystems.jl
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
11 changes: 11 additions & 0 deletions src/World1B/world1b/tables.jl
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)
2 changes: 2 additions & 0 deletions src/WorldDynamics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ using ModelingToolkit

export World1
export World1A
export World1B
export World2
export World3
export World3_91
export World3_03

include("World1/World1.jl")
include("World1A/World1A.jl")
include("World1B/World1B.jl")
include("World2/World2.jl")
include("World3/World3.jl")
include("World3_91/World3_91.jl")
Expand Down
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ using WorldDynamics, Test
@testset verbose=true "Scenarios" begin
include("world1/scenarios.jl")
include("world1a/scenarios.jl")
include("world1b/scenarios.jl")
include("world2/scenarios.jl")
include("world3/scenarios.jl")
include("world3_91/scenarios.jl")
Expand All @@ -14,6 +15,7 @@ using WorldDynamics, Test
@testset verbose=true "Figures" begin
include("world1/figures.jl")
include("world1a/figures.jl")
include("world1b/figures.jl")
include("world2/figures.jl")
include("world3/figures.jl")
include("world3_91/figures.jl")
Expand Down
5 changes: 5 additions & 0 deletions test/world1b/figures.jl
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
5 changes: 5 additions & 0 deletions test/world1b/scenarios.jl
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

0 comments on commit 6dfd4b9

Please sign in to comment.