started implementing turbine and controller code

This commit is contained in:
Georg ´Brantegger
2022-07-15 12:01:22 +02:00
parent 69b8beacb5
commit 04819d2e68
8 changed files with 392 additions and 10361 deletions

View File

@@ -1,5 +1,4 @@
import numpy as np import numpy as np
# from Ausgleichsbecken_functions import FODE_function, get_h_halfstep, get_p_halfstep
#importing pressure conversion function #importing pressure conversion function
import sys import sys
@@ -86,7 +85,7 @@ class Ausgleichsbecken_class:
f"Volume in reservoir = {self.volume:<10} {self.volume_unit_print} {new_line}" f"Volume in reservoir = {self.volume:<10} {self.volume_unit_print} {new_line}"
f"Current influx = {self.influx:<10} {self.flux_unit_print} {new_line}" f"Current influx = {self.influx:<10} {self.flux_unit_print} {new_line}"
f"Current outflux = {self.outflux:<10} {self.flux_unit_print} {new_line}" f"Current outflux = {self.outflux:<10} {self.flux_unit_print} {new_line}"
f"Current outflux vel = {self.outflux_vel:<10} {self.velocity_unit_print} {new_line}" f"Current outflux vel = {round(self.outflux_vel,3):<10} {self.velocity_unit_print} {new_line}"
f"Current pipe pressure = {round(p,3):<10} {self.pressure_unit_print} {new_line}" f"Current pipe pressure = {round(p,3):<10} {self.pressure_unit_print} {new_line}"
f"Simulation timestep = {self.timestep:<10} {self.time_unit_print} {new_line}" f"Simulation timestep = {self.timestep:<10} {self.time_unit_print} {new_line}"
f"----------------------------- {new_line}") f"----------------------------- {new_line}")
@@ -98,7 +97,7 @@ class Ausgleichsbecken_class:
f"Volume in reservoir = {self.volume:<10} {self.volume_unit_print} {new_line}" f"Volume in reservoir = {self.volume:<10} {self.volume_unit_print} {new_line}"
f"Current influx = {self.influx:<10} {self.flux_unit_print} {new_line}" f"Current influx = {self.influx:<10} {self.flux_unit_print} {new_line}"
f"Current outflux = {self.outflux:<10} {self.flux_unit_print} {new_line}" f"Current outflux = {self.outflux:<10} {self.flux_unit_print} {new_line}"
f"Current outflux vel = {self.outflux_vel:<10} {self.velocity_unit_print} {new_line}" f"Current outflux vel = {round(self.outflux_vel,3):<10} {self.velocity_unit_print} {new_line}"
f"Current pipe pressure = {round(p,3):<10} {self.pressure_unit_print} {new_line}" f"Current pipe pressure = {round(p,3):<10} {self.pressure_unit_print} {new_line}"
f"----------------------------- {new_line}") f"----------------------------- {new_line}")

View File

@@ -133,7 +133,7 @@
], ],
"metadata": { "metadata": {
"kernelspec": { "kernelspec": {
"display_name": "Python 3.8.13 ('Georg_DT_Slot3')", "display_name": "Python 3.8.13 ('DT_Slot_3')",
"language": "python", "language": "python",
"name": "python3" "name": "python3"
}, },
@@ -152,7 +152,7 @@
"orig_nbformat": 4, "orig_nbformat": 4,
"vscode": { "vscode": {
"interpreter": { "interpreter": {
"hash": "84fb123bdc47ab647d3782661abcbe80fbb79236dd2f8adf4cef30e8755eb2cd" "hash": "4a28055eb8a3160fa4c7e4fca69770c4e0a1add985300856aa3fcf4ce32a2c48"
} }
} }
}, },

View File

@@ -153,7 +153,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 12, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -181,8 +181,15 @@
"# axs1[2].autoscale()\n", "# axs1[2].autoscale()\n",
"fig1.tight_layout()\n", "fig1.tight_layout()\n",
"fig1.show()\n", "fig1.show()\n",
"plt.pause(1)\n", "plt.pause(1)\n"
"\n", ]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"# loop through time steps of the pipeline\n", "# loop through time steps of the pipeline\n",
"for it_pipe in range(1,pipe.nt+1):\n", "for it_pipe in range(1,pipe.nt+1):\n",
"\n", "\n",
@@ -273,7 +280,7 @@
], ],
"metadata": { "metadata": {
"kernelspec": { "kernelspec": {
"display_name": "Python 3.8.13 ('Georg_DT_Slot3')", "display_name": "Python 3.8.13 ('DT_Slot_3')",
"language": "python", "language": "python",
"name": "python3" "name": "python3"
}, },
@@ -292,7 +299,7 @@
"orig_nbformat": 4, "orig_nbformat": 4,
"vscode": { "vscode": {
"interpreter": { "interpreter": {
"hash": "84fb123bdc47ab647d3782661abcbe80fbb79236dd2f8adf4cef30e8755eb2cd" "hash": "4a28055eb8a3160fa4c7e4fca69770c4e0a1add985300856aa3fcf4ce32a2c48"
} }
} }
}, },

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,35 @@
import numpy as np
#based on https://en.wikipedia.org/wiki/PID_controller#Discrete_implementation
class P_controller_class:
def __init__(self,setpoint,proportionality_constant):
self.SP = setpoint
self.Kp = proportionality_constant
self.error_history = []
self.control_variable = 0.1
self.lower_limit = -0.1 # default
self.upper_limit = +0.1 # default
def set_control_variable_limits(self,lower_limit,upper_limit):
self.lower_limit = lower_limit
self.upper_limit = upper_limit
def calculate_error(self,process_variable):
self.error = self.SP-process_variable
self.error_history.append(self.error)
def get_control_variable(self):
new_control = self.control_variable+self.Kp*(self.error_history[-1]-self.error_history[-2])
if new_control < self.lower_limit:
new_control = self.lower_limit
if new_control > self.upper_limit:
new_control = self.upper_limit
self.control_variable = new_control
# print(new_control)
return new_control

148
Regler/regler_test.ipynb Normal file

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,19 @@
def turbine_flux(p,LA,p_exp,cubic_coeff,quadratic_coeff,linear_coeff,const_coeff):
return (p*1e-5)**p_exp*(cubic_coeff*LA**3+quadratic_coeff*LA**2+linear_coeff*LA+const_coeff)
class Francis_turbine_class:
def __init__(self):
pass
def set_turbine_flux_parameters(self,p_exp,cubic_coeff,quadratic_coeff,linear_coeff,const_coeff):
# extracted from the Muschelkurve of the Turbine and used to calculate the turbine flux for a given pressure
self.p_exp = p_exp
self.cubic_coeff = cubic_coeff
self.quadratic_coeff = quadratic_coeff
self.linear_coeff = linear_coeff
self.const_coeff = const_coeff
def get_turbine_flux(self,pressure,Leitapparatöffnung):
self.flux = turbine_flux(pressure,Leitapparatöffnung,self.p_exp,self.cubic_coeff,self.quadratic_coeff,self.linear_coeff,self.const_coeff)
return self.flux

174
Turbinen/messy.ipynb Normal file

File diff suppressed because one or more lines are too long