Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dam Model #26

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Binary file added log/Dam-chart-1.bmp
Binary file not shown.
Binary file added log/Dam-chart-2.bmp
Binary file not shown.
Binary file added lua/.terrametmp_DeI4D/Coffee-chart-1.bmp
Binary file not shown.
Binary file added lua/.terrametmp_DeI4D/Daisyworld-chart-1.bmp
Binary file not shown.
Binary file added lua/.terrametmp_DeI4D/Daisyworld-chart-2.bmp
Binary file not shown.
Binary file added lua/.terrametmp_DeI4D/Daisyworld-chart-3.bmp
Binary file not shown.
Binary file added lua/.terrametmp_DeI4D/Daisyworld-chart-4.bmp
Binary file not shown.
Binary file added lua/.terrametmp_DeI4D/Dam-chart-1.bmp
Binary file not shown.
Binary file added lua/.terrametmp_DeI4D/Lorenz-chart-2.bmp
Binary file not shown.
Binary file added lua/.terrametmp_DeI4D/SIR-chart-1.bmp
Binary file not shown.
Binary file added lua/.terrametmp_DeI4D/SIR-chart-2.bmp
Binary file not shown.
Binary file added lua/.terrametmp_DeI4D/Yeast-chart-1.bmp
Binary file not shown.
Binary file added lua/.terrametmp_DeI4D/chaotic-growth.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lua/.terrametmp_DeI4D/monolake-1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lua/.terrametmp_DeI4D/monolake-2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lua/.terrametmp_DeI4D/population-growth.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lua/.terrametmp_DeI4D/predator-prey-1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lua/.terrametmp_DeI4D/tub-2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lua/.terrametmp_DeI4D/tub.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lua/.terrametmp_DxwSv/Daisyworld-chart-2.bmp
Binary file not shown.
Binary file added lua/.terrametmp_DxwSv/Daisyworld-chart-3.bmp
Binary file not shown.
Binary file added lua/.terrametmp_DxwSv/Daisyworld-chart-4.bmp
Binary file not shown.
Binary file added lua/.terrametmp_DxwSv/Lorenz-chart-1.bmp
Binary file not shown.
Binary file added lua/.terrametmp_DxwSv/Lorenz-chart-2.bmp
Binary file not shown.
Binary file added lua/.terrametmp_DxwSv/SIR-chart-1.bmp
Binary file not shown.
Binary file added lua/.terrametmp_DxwSv/SIR-chart-2.bmp
Binary file not shown.
Binary file added lua/.terrametmp_DxwSv/Yeast-chart-1.bmp
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lua/.terrametmp_DxwSv/homeostasis.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lua/.terrametmp_DxwSv/limited-growth.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lua/.terrametmp_DxwSv/monolake-1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lua/.terrametmp_DxwSv/monolake-2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lua/.terrametmp_DxwSv/population-growth.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lua/.terrametmp_DxwSv/predator-prey-1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lua/.terrametmp_DxwSv/tub-2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lua/.terrametmp_DxwSv/tub.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lua/.terrametmp_GtFj1/Coffee-chart-1.bmp
Binary file not shown.
Binary file added lua/.terrametmp_GtFj1/Daisyworld-chart-1.bmp
Binary file not shown.
Binary file added lua/.terrametmp_GtFj1/Daisyworld-chart-2.bmp
Binary file not shown.
Binary file added lua/.terrametmp_GtFj1/chaotic-growth.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lua/.terrametmp_MtwRP/Coffee-chart-1.bmp
Binary file not shown.
Binary file added lua/.terrametmp_MtwRP/Daisyworld-chart-1.bmp
Binary file not shown.
Binary file added lua/.terrametmp_MtwRP/Daisyworld-chart-2.bmp
Binary file not shown.
Binary file added lua/.terrametmp_MtwRP/Daisyworld-chart-3.bmp
Binary file not shown.
Binary file added lua/.terrametmp_MtwRP/Daisyworld-chart-4.bmp
Binary file not shown.
Binary file added lua/.terrametmp_MtwRP/homeostasis.png
Binary file added lua/.terrametmp_MtwRP/limited-growth.png
Binary file added lua/.terrametmp_MtwRP/monolake-2.png
Binary file added lua/.terrametmp_MtwRP/population-growth.png
Binary file added lua/.terrametmp_MtwRP/predator-prey-1.png
Binary file added lua/.terrametmp_MtwRP/predator-prey-2.png
67 changes: 67 additions & 0 deletions lua/Dam.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
--- A water in the dam model.
-- @arg data.water The initial stock of water measured in m³. The initial value is 5,000,000,000.
-- @arg data.inFlow1 The flow of water into the dam each first season. The default is 2e9.
-- @arg data.inFlow2 The flow of water into the dam each second season. The default is 2e9.
-- @arg data.population The total amount of inhabitants. The default value is 1e5.
-- @arg data.consumePerPerson The total amount of water per inhabitant. The default value is 10.
-- @arg data.currentYear Year 1995.
-- @arg data.kWh2cubicMeters The total amount of kWh produced by cubic meters. The default value is 100.
-- @arg data.growth The comsumption amount of kWh produced by cubic meters. The default value is 100.
-- @arg data.countYear The flag in which defines whether count or not the years . The default value is false.
-- @arg data.changedYear The year in which water values change. The default value is 1970.
-- @arg data.finalTime The final time of the simulation in months. The default value is 1000.
Dam = Model{
water = 5e9,
inFlow1 = 2e9,
inFlow2 = 1.5e9,
population = 1e5,
consumePerPerson = 10,
kWh2cubicMeters = 100,
growth = 0.05,
countYear = false,
changedYear= 1970,
currentYear = 1950,
finalTime = 1000,
execute = function(self) -- each time step
local outFlow = self.population * self.consumePerPerson * self.kWh2cubicMeters -- update outflow
self.water = self.water - outFlow -- update water
--local abc = 5

if self.water <= 0 then -- water amount less than zero
self.water = 0
--print(self.timer:getTime())
elseif self.water > 5e9 then-- water amount more than dam capacity
self.water = 5e9
end
if (self.countYear == true) then
if (self.timer:getTime()%12 == 0) then -- every each year increments current year
self.currentYear = self.currentYear + 1
if (self.currentYear == self.changedYear) then -- when changedYear equal to currentYear
self.inFlow1 = self.inFlow1/2
self.inFlow2 = self.inFlow2/2
end
end
end
end,
init = function (self)
self.chart = Chart{
target = self,
select = "water"
}

self.timer = Timer{
Event{action = self, priority = 'high'},
Event{period = 12, action = function()
self.water = self.water + self.inFlow1 -- first season in first semester
end},
Event{start = 7, period = 12, action = function()
self.water = self.water + self.inFlow2 -- second season in second semester
end},
Event{start = 12, period = 12, action = function()
self.consumePerPerson = self.consumePerPerson*(1 + self.growth) -- every year add 5%
end},
Event{action = self.chart}
}
end
}

18 changes: 18 additions & 0 deletions tests/Dam.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
-- Test file for Dam.lua
-- Author: Gilberto Camara and Pedro R. Andrade

return{
Dam = function(unitTest)
local model = Dam{}

model:run()

unitTest:assertSnapshot(model.chart, "Dam-chart-1.bmp",0.15)

model = Dam{countYear = true}

model:run()
unitTest:assertSnapshot(model.chart, "Dam-chart-2.bmp",0.12)
end,
}