Skip to content

Commit

Permalink
Updating the package to TerraME version 1.6. Close #6.
Browse files Browse the repository at this point in the history
  • Loading branch information
pedro-andrade-inpe committed Oct 14, 2015
1 parent bce2e09 commit a24d304
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 12 deletions.
3 changes: 2 additions & 1 deletion description.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
version = "0.3"
version = "0.4"
license = "GPL"
package = "sysdyn"
depends = "terrame (>= 1.6), sci (>= 0.1)"
title = "System Dynamics"
authors = "Gilberto Camara and Pedro R. Andrade"
contact = "[email protected]"
Expand Down
Empty file modified load.lua
100755 → 100644
Empty file.
6 changes: 6 additions & 0 deletions lua/ChaoticGrowth.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
--- A Model that describes a chaotic population growth.
-- @arg data.pop The initial population. The default value is 0.1.
-- @arg data.rate The rate that multiplies the population size in each time step. The degault value is 4.
-- @arg data.deltaTime A numeric value with the period to execute the changes of
-- the model. The default value is one.
-- @arg data.updateTime A numeric value with the period to update the charts.
-- The default value is one.
-- @arg data.finalTime The final time of the simulation. The default value is 300.
-- @arg data.view A table with two boolean elements, timeSeries and cobWeb (default true),
-- indicating whether a time series charts should be drawn.
-- @image chaotic-growth.bmp
ChaoticGrowth = SysDynModel{
pop = 0.10,
Expand Down
7 changes: 7 additions & 0 deletions lua/Homeostasis.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@

--- A model to show homeostasis taking place.
-- @arg data.stock The initial stock. The default value is 0.
-- @arg data.gain The fixed increment in the stock in each time step. The default value is 2.0.
-- @arg data.rate The rate that multiplies the stock in each time step. The default value is -0.4.
-- @arg data.finalTime The final time of the simulation. The default value is 30.
-- @arg data.deltaTime A numeric value with the period to execute the changes of
-- the model. The default value is one.
-- @arg data.updateTime A numeric value with the period to update the charts.
-- The default value is one.
-- @arg data.view A table with a boolean element timeSeries (default true) indicating whether
-- a time series chart should be drawn.
-- @image homeostasis.bmp
Homeostasis = SysDynModel{
stock = Choice{0.0, 2.0, 4.0, 10.0, 100.0},
Expand Down
6 changes: 6 additions & 0 deletions lua/LimitedGrowth.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
-- @arg data.rate The growth rate of the population.
-- @arg data.capacity The maximum amount of individuals.
-- @arg data.finalTime The number of simulation steps.
-- @arg data.deltaTime A numeric value with the period to execute the changes of
-- the model. The default value is one.
-- @arg data.updateTime A numeric value with the period to update the charts.
-- The default value is one.
-- @arg data.view A table with a boolean element timeSeries (default true) indicating whether
-- a time series chart should be drawn.
-- @image limited-growth.bmp
LimitedGrowth = SysDynModel{
pop = 300,
Expand Down
10 changes: 8 additions & 2 deletions lua/MonoLake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,17 @@ end
-- @arg data.otherIn Other inputs of water to the lake in KAF/year.
-- @arg data.evapRate The evaporation rate in feet/year.
-- @arg data.otherOut Other output of water from the lake in KAF/year.
-- @arg data.deltaTime A numeric value with the period to execute the changes of
-- the model. The default value is one.
-- @arg data.updateTime A numeric value with the period to update the charts.
-- The default value is one.
-- @arg data.finalTime The final time of the simulation. The default value is 50.
-- @arg data.view A table with a boolean element timeSeries (default true) indicating whether
-- a time series chart should be drawn.
-- @image monolake.bmp
MonoLake = SysDynModel {
waterInLake = 2228.0, -- kiloAcre * feet
level = 6224,
surf = 0.0,
-- input
precRate = 0.67, -- feet/year
runoff = 150, -- KAF/year
Expand All @@ -74,6 +80,6 @@ MonoLake = SysDynModel {
model.level = waterElevation:value(model.waterInLake)
end,

graphics = { timeseries = { {"level"}, {"waterInLake" }}}
graphics = {timeseries = {{"level"}, {"waterInLake"}}}
}

6 changes: 6 additions & 0 deletions lua/PopulationGrowth.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
-- @arg data.growthChange The change of the growth rate. The growth
-- rate is multiplied by this value in each time step.
-- @arg data.finalTime The final time of the simulation. The default value is 100.
-- @arg data.deltaTime A numeric value with the period to execute the changes of
-- the model. The default value is one.
-- @arg data.updateTime A numeric value with the period to update the charts.
-- The default value is one.
-- @arg data.view A table with a boolean element timeSeries (default true) indicating whether
-- a time series chart should be drawn.
-- @image population-growth.bmp
PopulationGrowth = SysDynModel{
population1 = 60,
Expand Down
6 changes: 6 additions & 0 deletions lua/PredatorPrey.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@
-- to die. The default value is 0.02.
-- @arg data.predGrowthKills A number between 0 and 0.01 with the increase in the size of the
-- predator population per eack prey killed. The default value is 0.00002.
-- @arg data.deltaTime A numeric value with the period to execute the changes of
-- the model. The default value is one.
-- @arg data.updateTime A numeric value with the period to update the charts.
-- The default value is one.
-- @arg data.finalTime The final time of the simulation. The minimum value is 50 and the
-- default value is 500.
-- @arg data.view A table with two boolean elements, timeSeries and phaseSpace (default true),
-- indicating whether a time series charts should be drawn.
-- @image predator-prey.bmp
PredatorPrey = SysDynModel{
wolves = Choice{min = 10, default = 40},
Expand Down
6 changes: 6 additions & 0 deletions lua/RandomWalk.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
-- time step. The available values are 0, 0.3, 0.5 (default), 0.7, 0.95, and 1.
-- @arg data.finalTime The final time of the simulation. It should be
-- at least 10. The default value is 100.
-- @arg data.deltaTime A numeric value with the period to execute the changes of
-- the model. The default value is one.
-- @arg data.updateTime A numeric value with the period to update the charts.
-- The default value is one.
-- @arg data.view A table with a boolean element timeSeries (default true) indicating whether
-- a time series chart should be drawn.
-- @image random-walk.bmp
RandomWalk = SysDynModel{
value = 0, -- initial condition
Expand Down
27 changes: 20 additions & 7 deletions lua/RoomTemperature.lua
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,36 @@
-- @arg data.temperature3 The initial temperature of the third room. The default value is 5.
-- @arg data.exterior The temperature outside the rooms. The default value is 20.
-- @arg data.finalTime The final time of the simulation. The default value is 100.
-- @arg data.deltaTime A numeric value with the period to execute the changes of
-- the model. The default value is one.
-- @arg data.updateTime A numeric value with the period to update the charts.
-- The default value is one.
-- @arg data.outside The temperature outside the room. The default value is 1.
-- @arg data.inside The temperature inside the room. The default initial value is 15.
-- @arg data.tempSet The selected temperature in the thermostat. The default value is 20.
-- @arg data.lossToOutside The percentage of heat loss every time step according to the
-- difference between the temperature inside and outside the room. The default value is 0.3.
-- @arg data.thermalInertia The percentage of input heat every time step according to the
-- difference between the temperature inside the room and the one selected in the thermostat.
-- The default value is 0.3.
-- @arg data.view A table with a boolean element timeSeries (default true) indicating whether
-- a time series chart should be drawn.
-- @image room-temperature.bmp
RoomTemperature = SysDynModel{
tempSet = 20.0,
inside = 15.0,
outside = 1.0,
hour = 0,
climate = function (hour)
return 15 - 0.1*(hour - 12)^2 -- varies btw 1 and 15 degrees
end,
climate = function(hour)
return 15 - 0.1*(hour - 12)^2 -- varies btw 1 and 15 degrees
end,
thermalInertia = 0.33,
lossToOutside = 0.30,
finalTime = 24,
changes = function (model, time)
model.outside = model.climate (time)
changes = function(model, time)
model.outside = model.climate(time)
local inflow = model.thermalInertia * (model.tempSet - model.inside)
local outflow = model.lossToOutside * (model.inside - model.outside)
model.inside = model.inside + inflow - outflow
model.inside = model.inside + inflow - outflow
end,
graphics = {
timeseries = {{"inside", "tempSet", "outside"}}
Expand Down
9 changes: 7 additions & 2 deletions lua/SysDynModel.lua
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,20 @@ end
-- The default value is one.
-- x axis.
-- @arg data.... Any other value that can be used as parameter for the Model.
-- @usage Tube = SysDynModel{
-- @usage import("sysdyn")
--
-- tube = SysDynModel{
-- water = 20,
-- finalTime = 20,
-- changes = function(model)
-- model.water = model.water - 1
-- end,
-- graphics = {
-- timeseries = {{"water"}},
-- }
-- }
--
-- tube:execute()
function SysDynModel(data)
verify(data.graphics, "System Dynamics 'graphics' must be provided")
verify(data.changes, "System Dynamics 'changes()' must be provided")
Expand All @@ -58,7 +63,7 @@ function SysDynModel(data)

if data.graphics.phasespace then data.view.phaseSpace = true end
if data.graphics.timeseries then data.view.timeSeries = true end
if data.graphics.cobweb then data.view.cobweb = true end
if data.graphics.cobweb then data.view.cobWeb = true end

forEachElement(data.graphics, function(idx)
if type(idx) ~= "string" then
Expand Down

0 comments on commit a24d304

Please sign in to comment.