-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptimize3.py
More file actions
77 lines (62 loc) · 2.08 KB
/
Copy pathoptimize3.py
File metadata and controls
77 lines (62 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"""
Example:
Minimize PQR by means of flow, UVT for the RED > 40
Next step - maximum RED for minimum PQR
"""
from gekko import GEKKO
import opt_config
from opt_config import systems, LampPower
from opt_config import namespace,NLamps
from statistics import mean
import inspect
m = GEKKO()
System = 'RZ-104-11'
def RED(**kwargs):
'''
Returns a RED value of the selected UV system
param 'module': name of the system
'''
try:
modulename = __import__(kwargs['module'])
except ImportError:
print('No module found')
sys.exit(1)
# Get the arguments of the specific RED function
moduleargs = inspect.getfullargspec(modulename.RED).args
# TODO: UVT215
params = [kwargs[namespace[argument]] for argument in moduleargs]
#print([type(param) for param in params])
return modulename.RED(*params)
P,Q,UVT = [m.Var() for _ in range(3)]
PQR = m.Var()
xRED = m.Var()
#lower bounds
P.lower = 60
Q.lower = 5
UVT.lower = 40
#upper bounds
P.upper = 100
Q.upper = 140
UVT.upper = 99
# Initial values considered to be a mean between the bounds, since the RED function is monotonic
P.value = mean([P.upper,P.lower])
Q.value = mean([Q.upper,Q.lower])
UVT.value = mean([UVT.upper,UVT.lower])
#Equations
m.Equation(xRED == RED(module = systems[System],P=P,Flow=Q,UVT=UVT,UVT215=UVT,Status = 100,D1Log=18,NLamps=NLamps[System]))
m.Equation(PQR == P/Q)
m.Equation(xRED>10)
m.Minimize(PQR)
#m.Obj(PQR)
#Set global options
m.options.IMODE = 3 #steady state optimization
#m.options.SOLVER = 3 # IPOPT
#m.options.AUTO_COLD = 5 # Cold start after X cycles
#Solve simulation
m.solve(disp=False) #disp is True by default
print(f'P = {round(P.value[0],1)}[%]')
print(f'Q = {round(Q.value[0],1)}[m³/h]')
print(f'UVT = {round(UVT.value[0],1)}[%-1cm]')
print(f'PQR = {round(LampPower(System)*P.value[0]/Q.value[0],1)}[W/(m³/h)]') # multiply by N_Lamps
#print(f'RED = {round(xRED.value[0],1)}[mJ/cm²]')
print(f'RED = {round(RED(module = systems[System],P=P.value[0],Flow=Q.value[0],UVT=UVT.value[0],UVT215=UVT.value[0],Status = 100,D1Log=18,NLamps=NLamps[System]),1)}[mJ/cm²]')