1. Homepage
  2. Programming
  3. ENGG1001: Programming for Engineers - Assignment 1: Modelling Hydro-Electric Storage

ENGG1001: Programming for Engineers - Assignment 1: Modelling Hydro-Electric Storage

Engage in a Conversation
PythonENGG1001Programming for EngineersModelling Hydro-Electric StorageAustraliaThe University of Queensland

Assignment 1: Modelling Hydro-Electric Storage (15 Marks) CourseNana.COM

ENGG1001: Programming for Engineers — Semester 1, 2023 Due: Friday 31 March 2023 at 4:00pm CourseNana.COM

Introduction CourseNana.COM

There is an increasing modern trend to generate electricity through renewable solar energy. This type of energy, however, is produced during the day when there is limited electrical demand. It is important, therefore, to store this energy in some way so that it is available at night when the demand is higher. One of the most successful ways of storing the energy is a “pumped hydro” system, which involves using electricity to pump water from a lower reservoir to an upper reservoir during the day. Then, at night, the water is released under gravity to drive generators which produce night time power. A typical system is shown in Figure 1. CourseNana.COM

Figure 1: Diagrammatic representation of a pumped hydro electricity generation system CourseNana.COM

Because the electricity generating plant uses cheap daytime electricity to pump water upwards and then releases the water to regenerate more costly night time electricity, the pumped hydro systems typically generate substantial revenue for the electricity generating company. CourseNana.COM

For this assignment you need to imagine that you are employed at a company that is investigating a number of possible scenarios for a pumped hydro electricity generating facility. They in turn have assigned you to write some code to simulate and evaluate these different scenarios. In order to do this simulation you need to write the modules of code described in the tasks below. CourseNana.COM

A pumped hydro system relies on converting electrical energy to potential energy during the day and then converting it back to electrical energy at night. The relevant formulae for electrical and potential energy are given below in equations (1a) and (1b) below. CourseNana.COM

[J] [W] [s CourseNana.COM

electical energy = electrical power × time (1a) CourseNana.COM

potential energy = mass × GRAVITY × h (1b) CourseNana.COM

[J] [kg] [m/s ] [m] CourseNana.COM

where GRAVITY = 9.81 m/s2 and h is the difference in elevation between the lower and upper reservoirs. Ideally, the conversion between electrical and potential energy would occur without loss, but in practice there is some loss. Typically, the conversion efficiency is about 80%. CourseNana.COM

Making use of equations (1a) and (1b), you need to write a function, determine_water_pumped, which returns the amount of water that is pumped to the upper reservoir, given the generator power used to pump water upwards, the height difference between the upper and lower reservoirs, the number of hours per day that water is pumped, and the percentage efficiency of conversion of electrical energy to potential energy. You can assume that the height of water in each of the reservoirs is much smaller than the difference in elevation of the two reservoirs. A docstring for the function is given below. CourseNana.COM

def determine_water_pumped(gen_power, height_difference, pumping_time, \ efficiency): CourseNana.COM

"""
Function to determine the amount of water pumped for a given Pumped hydro scenario.
CourseNana.COM

Parameters:
gen_power (float): generator power used to pump water [kW] height_difference (float): difference in the elevation levels of
CourseNana.COM

the upper and lower reservoirs [m]
pumping_time (float): the number of daytime hours that water is
CourseNana.COM

            pumped [hours]
        efficiency (float): the percentage efficiency of conversion from

electrical to potential energy. [%] CourseNana.COM

    Returns:
        (float): total mass of water pumped upwards [kg]

""" CourseNana.COM

A sample usage of the function is given below. CourseNana.COM

>>> water_pumped = determine_water_pumped(20E+03, 200, 7.5, 80) >>> water_pumped
220183486.2385321 CourseNana.COM

In Task 2 you are required to write a function to calculate the daily cost of using electricity to pump water up to the upper reservoir. You will need to use the formula in equation (2) below to do this. CourseNana.COM

The cost to pump water upwards during the day is given by: CourseNana.COM

daily_cost_to_pump = generator_power × hours_of_pumping × day_tariff (2) ? ?? ?? ?? ????? CourseNana.COM

[kW] [hours] [$/kWh] CourseNana.COM

An incomplete docstring for the required function is given below. CourseNana.COM

def calc_cost_to_pump(gen_power, pumping_time, day_tariff): """ CourseNana.COM

Parameters:
gen_power (float): generator power used to pump water [kW] pumping_time (float): the number of daytime hours that water is
CourseNana.COM

pumped [hours]
day_tariff (float): day-time energy cost per kWh [$/kWh]
CourseNana.COM

    Returns:
       (float): daily cost to pump water upwards [$]

""" CourseNana.COM

... CourseNana.COM

>>> daily_cost = calc_cost_to_pump(20E+03, 8, 0.02) >>> daily_cost
3200.0 CourseNana.COM

Task 3 CourseNana.COM

At the beginning of the night the release valve in the upper reservoir will be opened and the pressure of the water in the reservoir will force water downwards to drive generators and produce night time electricity. CourseNana.COM

In this task you need to simulate the outflow of the water from the upper reservoir during the night. It is not possible to precisely model the continuous time flow of water out of the reservoir with a digital computer, so a discrete time approximation is used. The outflow of water is calculated in relatively short discrete time intervals, assuming that the flow of water is constant during each of these intervals. Note that for the simulation, the length of the discrete time intervals is referred to as time_increment and this length is typically set to about 30 seconds. CourseNana.COM

In summary, then, you need to determine the amount of water flowing out of the upper reservoir during all of the following time periods: CourseNana.COM

t = 0 t = 1*time_inc t = 2*time_inc Period 0 Period 1 CourseNana.COM

Time (t) CourseNana.COM

t = i*time_inc t = (i+1)*time_inc Period i CourseNana.COM

To help you do this you are provided with the function, water_mass_drained in the file, a1_support.py. This function determines the amount of water drained out of the upper reservoir over a single period of time equal to time_increment, assuming water_mass is the mass of water currently in the reservoir. The function has two input parameters: water_mass and time_increment. CourseNana.COM

An example usage of this function is given below. CourseNana.COM

Make sure you can use this function by typing in the above commands and verifying that you obtain the appropriate output. CourseNana.COM

While you are provided with the function, water_mass_drained and you do not have to write it yourself, it is nonetheless instructive to see how it has been implemented. It is based on using the principle of conservation of energy, as outlined in the discussion and equations equations (3a) to (3d) below. CourseNana.COM

>>> water_out = water_mass_drained(200_000_000, 30) >>> water_out
297136.33234594524 CourseNana.COM

Deriving the Water Flow Rate CourseNana.COM

During a single time period (denoted period i) a certain mass of water will shoot out of the outlet valve at the bottom of the reservoir, and the water level higher up in the reservoir will decrease by a commensurate amount. Because energy must be conserved the kinetic energy of the water leaving must equal the decrease in potential energy due to the water "lost" from higher up in the reservoir. So: CourseNana.COM

12 × water_mass_outi × water_speedi 2 = heighti [m] × GRAVITY × water_mass_outi (3a) CourseNana.COM

[kg] [m/s] [m/s ] [kg]
where heighti is the height of the water level relative to the bottom of the reservoir. Assuming CourseNana.COM

the water inside the reservoir is still, then re-arranging equation (3a) gives: CourseNana.COM

? CourseNana.COM

2 × heighti × GRAVITY (3b) ? ?? ? ? ??2 ? CourseNana.COM

[m/s]
The height of the water relative to the bottom of the reservoir is: CourseNana.COM

heighti = ? ?? ? CourseNana.COM

[kg]
? ?? ? CourseNana.COM

total_water_massi (3c) CourseNana.COM

WATER_DENSITY × RESERVOIR_FOOTPRINT ????? ?? ? CourseNana.COM

water_speedi = ? ?? ? CourseNana.COM

[m] [m/s ] CourseNana.COM

[m]
where WATER_DENSITY and RESERVOIR_FOOTPRINT are constants. Knowing the speed of the water CourseNana.COM

[kg/m3 ] [m2 ]
when leaving the outlet, the amount of outflow over a given time can be calculated: CourseNana.COM

water_outi = WATER_DENSITY × water_speedi × OUTLET_AREA × time_increment (3d) CourseNana.COM

[kg/s] [kg/m3 ] [m/s] [m2 ] [s] CourseNana.COM

The OUTLET_AREA is also a constant, and all constants are defined at the start of the a1_support.py file. Note that this derivation makes several assumptions, such as ignoring the friction between the water and the pipe-walls, and turbulence in the flow. CourseNana.COM

The water_mass_drained function computes the amount of water leaving the upper reservoir in a single time period. Task 3 requires that you to write another function which computes the amount of water leaving the upper reservoir in all time periods during the night. The following paragraphs give some guidelines on how to achieve this. CourseNana.COM

At the start of every day there will be a base mass of water in the upper reservoir, referred to as water_base_mass. Throughout the day, an additional quantity of water (referred to as water_pumped_daily) will be pumped to the upper reservoir. i.e. the water in the reservoir at the start of the night is given by: CourseNana.COM

water_start_of_night = water_base_mass + water_pumped_daily (4) At night, as water is released from the reservoir, the amount of water during left in the reservoir at CourseNana.COM

time period, i + 1, is given by:
water_in_reservoiri+1 = water_mass_in_reservoiri water_outi (5) CourseNana.COM

You need to write a function, water_flow_out, which takes in the parameters described in the incomplete docstring below and returns a tuple. The 0th element in this returned tuple is the mass of water which flows out of the upper reservoir during time period, 0. The 1st element in the tuple is the outflow of water during time period, 1. The 2nd element in the tuple is the outflow of water during time period, 2, etc. The last element in the tuple is the outflow in the last time period before the water reduces to, or below water_base_mass. An incomplete docstring for the function is given below. CourseNana.COM

def water_flow_out(water_pumped_daily, water_base_mass, time_interval): """ CourseNana.COM

Parameters:
water_pumped_daily (float): water transferred to upper
CourseNana.COM

reservoir during the day [kg]
water_base_mass (float): the mass of water in the reservoir at
CourseNana.COM

the start of every day (i.e. before upward pumping CourseNana.COM

commences) [kg]
time_interval (float): discrete time increment used during the
CourseNana.COM

            computer simulation [sec]
    Returns:
        tuple[float]: tuple of the outflows of water out in
each time interval as water is released under gravity [kg]

You are required to implement the function, making use of equations (4) and (5), as well as the function, water_mass_drained. An example usage of the function is given below. CourseNana.COM

Task 4 CourseNana.COM

As water flows out of the reservoir and drives the electrical turbines, the potential energy is converted to electrical energy. This is expressed mathematically for time period, i, as: CourseNana.COM

>>> water_out_tuple = water_flow_out(200_000_000, 40_000, 30)
>>> water_out_tuple[0:4] # First 4 values
(297166.0444936467, 296945.2374591286, 296724.4303635647, 296503.623206864) CourseNana.COM

elec_energyi = water_outi × GRAVITY × height_difference × efficiency (6) elec_poweri =elec_energyi/time_interval (7) CourseNana.COM

You are required to write a function, determine_power_formed, making use of equations (6) and (7). The first input parameter for this function is a tuple of water outflows returned from the water_flow_out function. The second input parameter is the number of seconds in the time increment, the third parameter is the efficiency, the fourth parameter is the height difference between the upper and lower reservoirs. The function returns two parameters: the first is a tuple whose elements correspond to the power generated at each time period; i.e. element 0 of the returned tuple is the power generated during time period 0, element 1 is the power generated during time period 1, etc. The second parameter returned by the function is the average nightly power. Assuming the returned tuple is called elec_power_tuple, the average_nightly_power is computed according to equation (8). CourseNana.COM

average_nightly_power = N1 ? elec_poweri (8) i CourseNana.COM

where N = len(elec_power_tuple). An example usage of the function is given below. CourseNana.COM

>>> water_out_tuple = water_flow_out(200_000_000, 40_000, 30)
>>> water_out_tuple[0:4]
(297166.0444936467, 296945.2374591286, 296724.4303635647, 296503.623206864) >>> elec_power_tuple, average_power = determine_power_formed( CourseNana.COM

... water_out_tuple, 30, 80, 100)
>>> elec_power_tuple[0:4]
(7773.863723953798, 7768.087411930805, 7762.3110983108545, 7756.534783091563) >>> average_power
3945.772042536785 CourseNana.COM

Task 5 CourseNana.COM

The revenue obtained from night-time electricity generation is computed according to: CourseNana.COM

daily_revenue=?(elec_power_tuplei)×(time_increment/3600)×night_tariff (9) CourseNana.COM

[sec] [sec /h] [$/kWh] CourseNana.COM

You are required to write a function, revenue_generated, which returns the daily revenue, given a tuple of the electrical power values during each time increment, the length of the time increment and the night tariff. An incomplete docstring for the function is given below. CourseNana.COM

  1. 1  def revenue_generated(elec_power_tuple, time_increment, night_tariff): CourseNana.COM

  2. 2  """ CourseNana.COM

  3. 3       Function to determine the daily revenue obtained by the generation
    
  4. 4  of night-time electricity CourseNana.COM

5 CourseNana.COM

  1. 6       Parameters:
    
  2. 7  ... CourseNana.COM

8 CourseNana.COM

9 10 11 12 CourseNana.COM

Returns
(float): Daily revenue from night-time electricity generation [$]
CourseNana.COM

""" CourseNana.COM

... CourseNana.COM

Task 6 CourseNana.COM

Write a function, determine_profit, which returns the daily profit. You should use the various functions you have written previously, along with equation (10) to write this new function. CourseNana.COM

daily_profit = daily_revenue daily_cost_to_pump (10) A docstring for the function is given below: CourseNana.COM

def determine_profit(height_difference, pumping_time, gen_power, \ day_tariff, night_tariff, efficiency, water_base_mass,time_increment): """
Function to determine profit by pumping upwards and then releasing
at night.
CourseNana.COM

Parameters
height_difference (float): the height difference between the
CourseNana.COM

    upper and lower reservoirs [m]
pumping time (float): the number of daytime hours that water is

pumped [hours]
gen_power (float): generator power used to pump water [kW] day_tariff (float): day-time energy cost per kWh [$/kWh] night_tariff (float): night-time energy cost per kWh [$/kWh] efficiency (float): efficiency of conversion of
CourseNana.COM

between electrical and potential energy and vice versa [%] water_base_mass (float): the mass of water in the reservoir at CourseNana.COM

the start of every day (i.e. before upward pumping CourseNana.COM

commences) [kg]
time_interval (float): discrete time increment used during the
CourseNana.COM

computer simulation [sec]

A sample usage for the function is given below. CourseNana.COM

Task 7 CourseNana.COM

This task involves creating a table which prints out the profit for the various potential pumped hydro scenarios under consideration. To create this table you need to write a function, print_table, which has an input parameter attributes that is a tuple of tuples, as illustrated below CourseNana.COM

>>> profit = determine_profit(200, 8, 20E+03, 0.02, 0.1, 80, 40_000, 30) >>> profit
7040.052744524599 CourseNana.COM

1 2 3 4 5 6 7 8 9 CourseNana.COM

attributes = (
(height_difference_1, pumping_time_1, gen_power_1, day_tariff_1, \
CourseNana.COM

night_tariff_1, efficiency_1, water_base_mass_1, time_interval), (height_difference_2, pumping_time_2, gen_power_2, day_tariff_2, \ night_tariff_2, efficiency_2, water_base_mass_2, time_interval), (height_difference_3, pumping_time_3, gen_power_3, day_tariff_3, \ night_tariff_3, efficiency_3, water_base_mass_3, time_interval), CourseNana.COM

... CourseNana.COM

). CourseNana.COM

The function, print_table, does not return anything – it simply prints out the table. A sample usage of the function is given below. CourseNana.COM

>>>
...
...
...
...
>>>
################################################### # Scenario number # Daily profit ($) # ################################################### # 1 # 5280.12 # # 2 # 3806.26 # # 3 # 5881.10 # ################################################### CourseNana.COM

attributes = (
(200, 6, 20E+03, 0.02, 0.1, 80, 40_000, 30), (220, 7, 15E+03, 0.02, 0.1, 75, 50_000, 30), (240, 8, 18E+03, 0.02, 0.1, 78, 45_000, 30),
CourseNana.COM

) print_table(attributes) CourseNana.COM

Task 8 CourseNana.COM

This task involves creating a table which prints out the profit and the average electrical power for the various potential pumped hydro scenarios under consideration. To create this table you need to write a function, print_table_extended, which takes in attributes, a tuple of tuples. Note that attributes is defined exactly the same as for Task 7. CourseNana.COM

The function, print_table_extended, does not return anything – it simply prints out the table. A sample usage of the function is given below. CourseNana.COM

>>>
...
...
...
...
>>>
############################################################################ # Scenario number # Daily profit ($) # Ave power (kW) # ############################################################################ CourseNana.COM

  1. #1  # 5280.12 # 7414.43 # CourseNana.COM

  2. #2  # 3806.26 # 6636.25 # CourseNana.COM

  3. #3  # 5881.10 # 8575.31 # CourseNana.COM

############################################################################

attributes = (
(200, 6, 20E+03, 0.02, 0.1, 80, 40_000, 30), (220, 7, 15E+03, 0.02, 0.1, 75, 50_000, 30), (240, 8, 18E+03, 0.02, 0.1, 78, 45_000, 30),
CourseNana.COM

) print_table_extended(attributes) CourseNana.COM

This task involves writing a user interaction function. This function is called main, and it has no inputs and returns nothing. An illustration of its operation is provided below. CourseNana.COM

>>> main()
Please enter a command: h
    The available commands are:

'h' - provide help message
'r' - read input parameters for various scenarios from a file
'p c' - print a table with the cost savings for the various pumped CourseNana.COM

electricity scenarios
'p c e' - print a table with the cost savings and the available average CourseNana.COM

night power for the various pumped electricity scenarios 'q' - quit CourseNana.COM

Please enter a command: r
Please specify the directory: test
Please specify the filename: test_data.txt
Please enter a command: p c ################################################### # Scenario number # Daily profit ($) # ################################################### # 1 # 5280.12 # # 2 # 3806.26 # # 3 # 5881.10 # ################################################### CourseNana.COM

Please enter a command: p c e
############################################################################
#    Scenario number     #    Daily profit ($)    #     Ave power (kW)     #
############################################################################
  1. #1#  5280.12 CourseNana.COM

  2. #2#  3806.26 CourseNana.COM

  3. #3#  5881.10 CourseNana.COM

############################################################################
Please enter a command: q
Are you sure (y/n): y
>>>

# 7414.43 # # 6636.25 # # 8575.31 # CourseNana.COM

You are encouraged to incorporate the code you have written in the previous tasks when writing the code for main. You can also use the pre-written function, load_data, in the a1_support.py to read in text from a file and return it in the form of a tuple of tuples. Assume that the relevant file to be read is called test_data.txt and that it is in directory test. Then a sample usage of the load_data function, is: CourseNana.COM

>>> attributes = load_data("test", "test_data.txt")
>>> attributes
((200, 6, 20000.0, 0.02, 0.1, 80, 40000, 30), (220, 7, 15000.0, 0.02, 0.1, 75, 50000, 30), (240, 8, 18000.0, 0.02, 0.1, 78, 45000, 30)) CourseNana.COM

Writing your code CourseNana.COM

You must download the file, a1.py, from Blackboard, and write your code in that file. When you submit your assignment to Gradescope you must submit only one file and it must be called a1.py. Do not submit any other files or it can disrupt the automatic code testing program which will grade your assignments. CourseNana.COM

Design CourseNana.COM

You are expected to use good programming practice in your code, and you must incorporate at least the functions described in the previous part of the assignment sheet. CourseNana.COM

Assessment and Marking Criteria
The maximum achievable mark for this assignment is 15 marks. CourseNana.COM

Functionality Assessment (11 Marks) CourseNana.COM

The functionality will be marked out of 11. Your assignment will be put through a series of tests and your functionality mark will be proportional to the number of tests you pass. If, say, there are 25 functionality tests and you pass 20 of them, then your functionality mark will be 20/25 × 11. You will be given the functionality tests before the due date for the assignment so that you can gain a good idea of the correctness of your assignment yourself before submitting. You should, however, make sure that your program meets all the specifications given in the assignment. That will ensure that your code passes all the tests. Note that functionality tests are automated and so string outputs need to exactly match what is expected. Do not leave it until the last minute because it generally takes time to get your code to pass the tests. CourseNana.COM

Code Style Assessment (4 Marks) CourseNana.COM

The style of your assignment will be assessed by one of the tutors, and you will be marked according to the style rubric provided with the assignment. The style mark will be out of 4. CourseNana.COM

Get in Touch with Our Experts

WeChat WeChat
Whatsapp WhatsApp
Python代写,ENGG1001代写,Programming for Engineers代写,Modelling Hydro-Electric Storage代写,Australia代写,The University of Queensland代写,Python代编,ENGG1001代编,Programming for Engineers代编,Modelling Hydro-Electric Storage代编,Australia代编,The University of Queensland代编,Python代考,ENGG1001代考,Programming for Engineers代考,Modelling Hydro-Electric Storage代考,Australia代考,The University of Queensland代考,Pythonhelp,ENGG1001help,Programming for Engineershelp,Modelling Hydro-Electric Storagehelp,Australiahelp,The University of Queenslandhelp,Python作业代写,ENGG1001作业代写,Programming for Engineers作业代写,Modelling Hydro-Electric Storage作业代写,Australia作业代写,The University of Queensland作业代写,Python编程代写,ENGG1001编程代写,Programming for Engineers编程代写,Modelling Hydro-Electric Storage编程代写,Australia编程代写,The University of Queensland编程代写,Pythonprogramming help,ENGG1001programming help,Programming for Engineersprogramming help,Modelling Hydro-Electric Storageprogramming help,Australiaprogramming help,The University of Queenslandprogramming help,Pythonassignment help,ENGG1001assignment help,Programming for Engineersassignment help,Modelling Hydro-Electric Storageassignment help,Australiaassignment help,The University of Queenslandassignment help,Pythonsolution,ENGG1001solution,Programming for Engineerssolution,Modelling Hydro-Electric Storagesolution,Australiasolution,The University of Queenslandsolution,