HPPModel.e0000644000175000017500000002345011327435546012500 0ustar charithcharith%donald viewport view # Author: Charith Fernando # Draw the Start/Pause/Stop buttons # on the screen with separate views point btn_lbl_point btn_lbl_point = {500,500} viewport startbtnView label start_lbl start_lbl = label("Start", btn_lbl_point) viewport pausebtnView label pause_lbl pause_lbl = label("Pause", btn_lbl_point) viewport stopbtnView label stop_lbl stop_lbl = label("Stop", btn_lbl_point) # Draw the Monthly Meter # Meter will move as the Months are ticking by viewport monthmeterView label meter_lbl meter_lbl = label("Monthly Meter", {500,800}) line meter_line int meter_x meter_x = 20 meter_line = [{meter_x,0},{meter_x,1000}] ?A_meter_line = "linewidth=3"; # Divide the monthly meter into 12 line met_sep0,met_sep1,met_sep2,met_sep3,met_sep4,met_sep5,met_sep6,met_sep7,met_sep8,met_sep9,met_sep10,met_sep11,met_sep12 label lblm1,lblm2,lblm3,lblm4,lblm5,lblm6,lblm7,lblm8,lblm9,lblm10,lblm11,lblm12 met_sep0 = [{20,0},{20,1000}] met_sep1 = [{100,0},{100,1000}] met_sep2 = [{180,0},{180,1000}] met_sep3 = [{260,0},{260,1000}] met_sep4 = [{340,0},{340,1000}] met_sep5 = [{420,0},{420,1000}] met_sep6 = [{500,0},{500,1000}] met_sep7 = [{580,0},{580,1000}] met_sep8 = [{660,0},{660,1000}] met_sep9 = [{740,0},{740,1000}] met_sep10 = [{820,0},{820,1000}] met_sep11 = [{900,0},{900,1000}] met_sep12 = [{980,0},{980,1000}] lblm1 = label("1",{60,500}) lblm2 = label("2",{140,500}) lblm3 = label("3",{220,500}) lblm4 = label("4",{300,500}) lblm5 = label("5",{380,200}) lblm6 = label("6",{460,200}) lblm7 = label("7",{540,200}) lblm8 = label("8",{620,200}) lblm9 = label("9",{700,500}) lblm10 = label("10",{780,500}) lblm11 = label("11",{860,500}) lblm12 = label("12",{940,500}) viewport mainmodelView rectangle rain_box, watertank_box, water_content, stream_box, dam_box, spill_box, gen_flow label rain_fall_lbl, tank_lbl, stream_lbl, spill_lbl, dam_lbl, flow_lbl int tank_height, tank_starty tank_starty = 420 tank_height = tank_starty + (3*contentPercent!) rain_box = rectangle({300,890},{800,990}) watertank_box = rectangle({300,420},{800,790}) stream_box = rectangle({20,720},{300,790}) dam_box = rectangle({800,420},{900,720}) ?A_dam_box = "fill=solid,color=brown"; spill_box = rectangle({800,720},{975,790}) gen_flow = rectangle({740,230},{800,420}) water_content = rectangle({300,tank_starty},{800,tank_height}) ?A_water_content = "fill=solid,color=blue"; rain_fall_lbl = label("Rain Fall", {550,940}) tank_lbl = label("Water Tank", {550,745}) stream_lbl = label("Stream Input", {160,745}) spill_lbl = label("Outflow", {887,745}) dam_lbl = label("DAM", {850,570}) ?A_dam_lbl = "fill=solid,color=white"; flow_lbl = label("Water\nFlow", {770,325}) circle rd1, rd2, rd3, rd4, rd5, rd6, rd7, rd8, rd9, rd10, rd11, rd12 int rd_x, rd_y rd_x = 330 rd_y = 900 rd1 = circle({rd_x,rd_y-20},10) rd2 = circle({rd_x+40, rd_y},10) rd3 = circle({rd_x+80, rd_y-20},10) rd4 = circle({rd_x+120, rd_y},10) rd5 = circle({rd_x+160, rd_y-20},10) rd6 = circle({rd_x+200, rd_y},10) rd7 = circle({rd_x+240, rd_y-20},10) rd8 = circle({rd_x+280, rd_y},10) rd9 = circle({rd_x+320, rd_y-20},10) rd10 = circle({rd_x+360, rd_y},10) rd11 = circle({rd_x+400, rd_y-20},10) rd12 = circle({rd_x+440, rd_y},10) ?A_rd1 = "fill=solid,color=blue"; ?A_rd2 = "fill=solid,color=blue"; ?A_rd3 = "fill=solid,color=blue"; ?A_rd4 = "fill=solid,color=blue"; ?A_rd5 = "fill=solid,color=blue"; ?A_rd6 = "fill=solid,color=blue"; ?A_rd7 = "fill=solid,color=blue"; ?A_rd8 = "fill=solid,color=blue"; ?A_rd9 = "fill=solid,color=blue"; ?A_rd10 = "fill=solid,color=blue"; ?A_rd11 = "fill=solid,color=blue"; ?A_rd12 = "fill=solid,color=blue"; int strd_x, strd_y, strd_x1, strd_y1, strd_x2, strd_y2 strd_x=40 strd_y=750 strd_x1=80 strd_y1=750 strd_x2=120 strd_y2=750 circle strd1, strd2, strd3 strd1 = circle({strd_x,strd_y},10) ?A_strd1 = "fill=solid,color=blue"; strd2 = circle({strd_x1,strd_y1},10) ?A_strd2 = "fill=solid,color=blue"; strd3 = circle({strd_x2,strd_y2},10) ?A_strd3 = "fill=solid,color=blue"; circle wgdrop, spilldrop int wgd_y, spill_x # water generator flow wgd_y = 415 wgdrop = circle({770,wgd_y}, 10) ?A_wgdrop = "fill=solid,color=blue"; # Water Spill Flow spill_x = 820 spilldrop = circle({spill_x,750}, 10) ?A_spilldrop = "fill=solid,color=blue"; %eden tick = 0; setedenclock(&tick, 1); start = 0; pause = 0; ## Constants gravity = 9.8; tank_content = 24000000; ## Observables ## Dimensions of the Water Tank in meters tank_height = 200; tank_width = 300; tank_depth = 400; ## Monthly Rain Fall Litres rain_fall = [120,240,1024,240,202,420,120,4456730,6785120,530,530,250]; ## Monthly stream input Litres stream_input = [120,420,440,1110,2220,304,0,0,530,120,330,5550]; ## Generated Power storage list for 12 months generated_power = [0,0,0,0,0,0,0,0,0,0,0,0]; ## Outflow list for the 12 months spill_outflow = [0,0,0,0,0,0,0,0,0,0,0,0]; ## Water flow rate for the 12 months water_flow_rate = [2120,1130,1440,1250,160,1370,1280,1490,4100,4120,1140,2190]; ## Head of the water flow pipe head_pipe = 20; ## Moving agents current_month = 1; ## Dependency definitions tank_capacity is tank_height * tank_width * tank_depth; ## Calculate the capacity of the tank power_gen is gravity * head_pipe * water_flow_rate[current_month]; ## Calculates the power generated in a given month monthly_input is stream_input[current_month] + rain_fall[current_month]; ## Monthly input ## When the power generation is changed output the values proc powergenListener : power_gen { if(start==1 && tank_content > 0) { write("The Power Generated for the month "); write(current_month); write(" is :"); writeln(power_gen); } } ## Steps to do when the current month has been changed proc monthchangeListener: current_month { _meter_x = (80 * (current_month-1)) + 20; tank_content = tank_content + monthly_input; if(tank_content > 0) { generated_power[current_month] = power_gen; if(tank_content > tank_capacity) { spill_outflow[current_month] = tank_content - tank_capacity; tank_content = tank_capacity; } } else { generated_power[current_month] = 0; } } contentPercent is ceiling(((tank_content) / (tank_capacity*1.0))*100, 1); proc ticklistener : tick { if(start == 1 && pause == 0) { ## Move the bar of the meter _meter_x = _meter_x + 1; ## each tick is assumed to be a second, hence deduct the flow from the capacity ## And its assumed that there is only 80 seconds per month tank_content = tank_content - water_flow_rate[current_month]; if(tank_content < 0) { tank_content = 0; } if((_meter_x<980)&&((_meter_x-20)%80==0)) { current_month = current_month + 1; } ## Move the water to the generator if there is a waterflow if((water_flow_rate[current_month] > 0) && (tank_content > 0)){ _wgd_y = _wgd_y - 2; } if(_wgd_y <= 225){ _wgd_y = 415; } ## If the water spills animates the spilling if(spill_outflow[current_month] > 0){ _spill_x = _spill_x + 4; } if(_spill_x >= 950){ _spill_x = 820; } ## make the Rain drops fall only if there is rain fall during the month if(rain_fall[current_month] > 0) { _rd_y = _rd_y - 1; } ## Stream water moving only if there is stream input during that month if(stream_input[current_month] > 0) { _strd_x = _strd_x + 4; _strd_x1 = _strd_x1 + 4; _strd_x2 = _strd_x2 + 4; } ## Make the water fall when the water reaches the tank if(_strd_x > 300) { _strd_y = _strd_y - 1; } if(_strd_x1 > 300) { _strd_y1 = _strd_y1 - 1; } if(_strd_x2 > 300) { _strd_y2 = _strd_y2 - 1; } } ## If meter bar is at the end, stop the process if(_meter_x==980) { current_month = 1; spill_outflow = [0,0,0,0,0,0,0,0,0,0,0,0]; generated_power = [0,0,0,0,0,0,0,0,0,0,0,0]; ## start=0; } ## If the raindrops eaches the tank, reset them if(_rd_y == 750) { _rd_y = 900; } ## When the stream water falls into the tank, reset them if(_strd_x > 350) { _strd_x = 40; _strd_y = 750; } if(_strd_x1 > 350) { _strd_x1 = 80; _strd_y1 = 750; } if(_strd_x2 > 350) { _strd_x2 = 120; _strd_y2 = 750; } } proc toggleStart : startBtnWin_mouse { if(startBtnWin_mouse[2]==5) { if(start!=1) { spill_outflow = [0,0,0,0,0,0,0,0,0,0,0,0]; generated_power = [0,0,0,0,0,0,0,0,0,0,0,0]; start = 1; if(current_month == 12) { current_month = 1; } writeln("Power Generation Started"); } } } ## Listen to when the process stops to reset the values proc stoplistener : start { if(start==0) { current_month = 12; writeln("The Cycle has been Stopped OR Finished"); write("Power Generated [1..12]: "); writeln(generated_power); write("Water Outflow [1..12]: "); writeln(spill_outflow); write("TANK CONTENT: "); writeln(tank_content); } } proc toggleStop : stopBtnWin_mouse { if(stopBtnWin_mouse[2]==5) { start = 0; pause = 0; writeln("Power Generation Stopped"); } } proc togglePause : pauseBtnWin_mouse { if(pauseBtnWin_mouse[2]==5) { if(start==1 && pause==0) { pause = 1; } else { pause = 0; } } } %scout # Use SCOUT to define the windows and # display them display disp; window startBtnWin, pauseBtnWin, stopBtnWin, mtextWin, mainmodelWin; mainmodelWin = { box: [{20,140}, {480,480}], pict: "mainmodelView", type: DONALD, border: 1, sensitive: OFF, bgcolor: "Gray" }; mtextWin = { box: [{20,90}, {450,120}], pict: "monthmeterView", type: DONALD, border: 1, sensitive: ON }; startBtnWin = { box: [{20,20}, {150,70}], pict: "startbtnView", type: DONALD, border: 1, sensitive: ON, bgcolor: "Green" }; pauseBtnWin = { box: [{170,20}, {300,70}], pict: "pausebtnView", type: DONALD, border: 1, sensitive: ON, bgcolor: "Yellow" }; stopBtnWin = { box: [{320,20}, {450,70}], pict: "stopbtnView", type: DONALD, border: 1, sensitive: ON, bgcolor: "Red" }; # Displaying all the windows defined disp = ; screen = disp;