diff --git a/description.lua b/description.lua index 991dbb9..25d5fbd 100644 --- a/description.lua +++ b/description.lua @@ -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 = "pedro.andrade@inpe.br" diff --git a/load.lua b/load.lua old mode 100755 new mode 100644 diff --git a/lua/ChaoticGrowth.lua b/lua/ChaoticGrowth.lua index c266d97..7b478a4 100644 --- a/lua/ChaoticGrowth.lua +++ b/lua/ChaoticGrowth.lua @@ -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, diff --git a/lua/Homeostasis.lua b/lua/Homeostasis.lua index 6909d9e..4e6f9ba 100644 --- a/lua/Homeostasis.lua +++ b/lua/Homeostasis.lua @@ -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}, diff --git a/lua/LimitedGrowth.lua b/lua/LimitedGrowth.lua index 0477aab..29cd644 100644 --- a/lua/LimitedGrowth.lua +++ b/lua/LimitedGrowth.lua @@ -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, diff --git a/lua/MonoLake.lua b/lua/MonoLake.lua index 7e60bb0..2f63826 100644 --- a/lua/MonoLake.lua +++ b/lua/MonoLake.lua @@ -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 @@ -74,6 +80,6 @@ MonoLake = SysDynModel { model.level = waterElevation:value(model.waterInLake) end, - graphics = { timeseries = { {"level"}, {"waterInLake" }}} + graphics = {timeseries = {{"level"}, {"waterInLake"}}} } diff --git a/lua/PopulationGrowth.lua b/lua/PopulationGrowth.lua index cef6a18..e5c8cc0 100644 --- a/lua/PopulationGrowth.lua +++ b/lua/PopulationGrowth.lua @@ -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, diff --git a/lua/PredatorPrey.lua b/lua/PredatorPrey.lua index 5d4bf15..d2239d2 100644 --- a/lua/PredatorPrey.lua +++ b/lua/PredatorPrey.lua @@ -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}, diff --git a/lua/RandomWalk.lua b/lua/RandomWalk.lua index 906397e..ae935cd 100644 --- a/lua/RandomWalk.lua +++ b/lua/RandomWalk.lua @@ -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 diff --git a/lua/RoomTemperature.lua b/lua/RoomTemperature.lua old mode 100755 new mode 100644 index 245bba0..0ee72ef --- a/lua/RoomTemperature.lua +++ b/lua/RoomTemperature.lua @@ -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"}} diff --git a/lua/SysDynModel.lua b/lua/SysDynModel.lua old mode 100755 new mode 100644 index 480e11e..3331891 --- a/lua/SysDynModel.lua +++ b/lua/SysDynModel.lua @@ -36,8 +36,11 @@ 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, @@ -45,6 +48,8 @@ end -- 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") @@ -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