From 03eca6138decede366eb9cc2990af3b33144532d Mon Sep 17 00:00:00 2001 From: Cal Wing Date: Fri, 14 Feb 2025 21:42:21 +0100 Subject: [PATCH] Task 4 --- a1.py | 57 ++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 15 deletions(-) diff --git a/a1.py b/a1.py index 5199a35..651dfde 100644 --- a/a1.py +++ b/a1.py @@ -1,5 +1,5 @@ # These could be from the std math lib, but I like the numpy ones better personally -from numpy import sin, cos, pi +from numpy import sin, cos, pi, sqrt # Pull a1 support from a1_support import GRAVITY_ACC, WATER_DENSITY, HELP_MESSAGE @@ -12,7 +12,8 @@ __date__ = "14/02/2025" __version__ = "1.0.0" # Task 1 [Broken] -def determine_power_used(water_mass: float, elevation: float, pumping_time: float, efficiency: float) -> float: +def determine_power_used(water_mass: float, elevation: float, + pumping_time: float, efficiency: float) -> float: """ Calculates the power required to pump a certain mass of water a certain height taking into account the pumping_time and efficiency. @@ -39,18 +40,19 @@ def determine_power_used(water_mass: float, elevation: float, pumping_time: floa return power_used / 1e3 # W -> kW # Task 2 -def determine_water_released(gen_power: float, elevation: float, pumping_time: float, efficiency: float) -> float: +def determine_water_released(gen_power: float, elevation: float, + pumping_time: float, efficiency: float) -> float: """ - Calculates the mass of water released required to generate a specified power - - Parameters: - gen_power (float): the specified power to be generated [kW] - elevation (float): the height difference [m] - pumping_time (float): the time the pump is running for [hrs] - efficiency (float): the conversion efficiency [%] - - Returns: - (float): the mass of the water required [kg] + Calculates the mass of water released required to generate a specified power + + Parameters: + gen_power (float): the specified power to be generated [kW] + elevation (float): the height difference [m] + pumping_time (float): the time the pump is running for [hrs] + efficiency (float): the conversion efficiency [%] + + Returns: + (float): the mass of the water required [kg] """ # How much electrical engery was generated? @@ -65,7 +67,8 @@ def determine_water_released(gen_power: float, elevation: float, pumping_time: f return water_mass # Task 3 -def determine_cost_to_pump(gen_power: float, pumping_time: float, off_peak_tariff: float) -> float: +def determine_cost_to_pump(gen_power: float, pumping_time: float, + off_peak_tariff: float) -> float: """ Calculates the cost of using the pump during off peak period @@ -82,7 +85,29 @@ def determine_cost_to_pump(gen_power: float, pumping_time: float, off_peak_tarif return cost +# Task 4 +def calc_speed_at_outlet(water_height: float) -> float: + """ + Calculates the speed of the water at the outlet of the dam + Parameters: + water_height (float): the height of the water in the pipe [m] + + Returns: + (float): the speed of the water at the outlet [m/s] + """ + + speed = sqrt(2 * water_height * GRAVITY_ACC) + + return speed + +# Task 5 +def calc_new_water_height(old_water_height: float, reservoir_area: float, + outlet_area: float, time_inc: float) -> tuple[float, float]: + + + + return (0.0, 0.0) # See if I get what the task sheet wants @@ -91,7 +116,9 @@ def sheet_tasks(): TASKS = ( (determine_power_used, (5e6, 250, 8, 85), 500.9191176470588), (determine_water_released, (300, 250, 8, 85), 2994495.4128440367), - (determine_cost_to_pump, (300, 8, 0.02), 48), + (determine_cost_to_pump, (300, 8, 0.02), 48), + (calc_speed_at_outlet, (30), 24.261079942986875), + (calc_new_water_height, (20, 40000, 1, 30), (19.985143183382704, 592567.1021442247)), ) for i, (task, args, expected) in enumerate(TASKS):