13 def matchProperties(element
,name
):
14 '''return matched property in given element'''
15 if element
.properties
[name
] != None :
16 return element
.properties
[name
]
21 def evalEquation(equation
,element
):
22 '''Evaluate one equation from an element and return tuple with (property,value,whoHelp)
23 property and not variable ! Each property is unique and linked the element which contain it.
24 So we dont need the return element which contain the property.'''
25 variable
= equation
[0]
27 if variable
.conn
== None :
28 #means that variable is a selfvariable
29 prop
= matchProperties(element
,variable
.name
)
31 if element
.connection
[variable
.conn
].link
!= None:
32 prop
= matchProperties(element
.connection
[variable
.conn
].link
.elem
,variable
.name
)
37 #clear variable.whoHelp before populating it with equalTo.evaluation()
38 variable
.clearwhoHelp()
39 a
= equalTo
.evaluation(element
,variable
)
40 return [prop
,a
,variable
.whoHelp
]
45 class Equation(object):
46 '''Class that handle symbolic equation with the form expression = 0, and store every evidence possible of this equation in equationList
47 Every variable contain in expression only once, will be highlight.
48 If your variable appear twice, you need to add second expression where variable appear only once thise time'''
50 self
.__equationList
= [] #list of equations
51 self
.__todo
= [] #list of expression = 0 that need to be converted in equation
54 def equationList(self
):
55 return self
.__equationList
60 def addEquation(self
,expression
):
61 #User add equation of kind expression = 0
62 self
.__todo
.append((expression
,K(0)))
64 def addTodo(self
,expression
,equalTo
):
65 #Add equation to the todolist, used inside EquationElement class
66 self
.__todo
.append((expression
,equalTo
))
69 def processTodo(self
):
70 #Transform expression into equation with Variable in evidence.
71 while len(self
.todo
) != 0 :
72 tempTodo
= list(self
.todo
)
74 x
[0].evidence(x
[1],self
)
78 class equationElement(object):
82 #Overloading operators
98 def evidence(self
,equalTo
,equation
):
99 #Highlights variables in expressions
102 def evaluation(self
,element
,variable
):
103 #Computing the value of the variable or constant which call this method
106 class K(equationElement
):
108 def __init__(self
,value
):
109 #Value should be integer or float
112 def evaluation(self
,element
,variable
):
115 class Var(equationElement
):
116 '''Class that represent variable. Variable got name,connection's kind,value and who help to compute this variable'''
117 def __init__(self
,name
,connection
):
119 self
.__conn
= connection
121 self
.__whoHelp
= set()
137 return self
.__whoHelp
139 def clearwhoHelp(self
):
140 self
.__whoHelp
= set()
142 def evidence(self
,equalTo
,equa
):
143 equa
.equationList
.append((self
,equalTo
))
145 def evaluation(self
,element
,variable
):
146 if element
.connection
[self
.__conn
].link
!= None:
147 state
= element
.connection
[self
.__conn
].link
.elem
148 result
= matchProperties(state
,self
.__name
)
149 if (result
!= None and self
.__name
!= 'fluid') or (type(result
.value
) != fluid
.Fluid
and self
.__name
== 'fluid'):
150 variable
.whoHelp
.add(result
)
158 '''Same as variable, except that they dont have connection's kind. So they are linked to the element given in evaluation'''
159 def __init__(self
,name
):
160 Var
.__init
__(self
,name
,None)
162 def evaluation(self
,element
,variable
):
163 result
= matchProperties(element
,self
.name
)
165 variable
.whoHelp
.add(result
)
173 '''Use RefVar if your equation is different than X - Xref = 0 EVEN with state equation. In case of state just put None as connection.'''
174 def __init__(self
,name
,conn
):
175 Var
.__init
__(self
,name
,conn
)
177 def evaluation(self
,element
,variable
):
178 if self
.conn
!= None:
179 if element
.connection
[self
.conn
].link
!= None:
180 state
= element
.connection
[self
.conn
].link
.elem
181 result
= matchProperties(state
,self
.name
)
183 variable
.whoHelp
.add(result
)
190 result
= matchProperties(element
,self
.name
)
192 variable
.whoHelp
.add(result
)
197 class selfRefVar(RefVar
):
198 '''Reference variable are particular, because they are linked with the reference state, wich is a boolean.
199 So theyr evaluation is different from normal variable.
200 Use this class ONLY for equation X - Xref = 0'''
201 def __init__(self
,name
):
202 RefVar
.__init
__(self
,name
,None)
204 def evaluation(self
,element
,variable
):
205 result
= matchProperties(element
,self
.name
)
206 refstate
= element
.properties
['reference state']
207 if result
!= None and refstate
.value
== True:
208 variable
.whoHelp
.add(result
)
209 variable
.whoHelp
.add(refstate
)
214 #############################
215 #Operator for usual equation#
216 #############################
218 class Plus(equationElement
):
219 #Overloading plus operator
220 def __init__(self
,A
,B
):
224 def evidence(self
,equalTo
,equation
):
225 equation
.addTodo(self
._left
,Minus(equalTo
,self
._right
))
226 equation
.addTodo(self
._right
,Minus(equalTo
,self
._left
))
228 def evaluation(self
,element
,variable
):
229 A
= self
._left
.evaluation(element
,variable
)
230 B
= self
._right
.evaluation(element
,variable
)
231 if A
== None or B
== None :
233 elif variable
.name
== 'quality' and (math
.isnan(A
) or math
.isnan(B
)):
234 #equation that will acces to this part is : x = x_ph or x = x_ps
236 elif (math
.isnan(A
) or math
.isnan(B
)):
237 #any other equation which wont compute quality will lies here if title = nan
243 class Minus(equationElement
):
244 #Overloading minus operator
245 def __init__(self
,A
,B
):
249 def evidence(self
,equalTo
,equation
):
250 equation
.addTodo(self
._left
,Plus(equalTo
,self
._right
))
251 equation
.addTodo(self
._right
,Minus(self
._left
,equalTo
))
253 def evaluation(self
,element
,variable
):
254 A
= self
._left
.evaluation(element
,variable
)
255 B
= self
._right
.evaluation(element
,variable
)
256 if A
== None or B
== None :
258 elif variable
.name
== 'quality' and (math
.isnan(A
) or math
.isnan(B
)):
259 #equation that will acces to this part is : x = x_ph or x = x_ps
261 elif (math
.isnan(A
) or math
.isnan(B
)):
262 #any other equation which wont compute quality will lies here if title = nan
267 class Mul(equationElement
):
268 #Overloading multiplication operator
269 def __init__(self
,A
,B
):
273 def evidence(self
,equalTo
,equation
):
274 equation
.addTodo(self
._left
,Div(equalTo
,self
._right
))
275 equation
.addTodo(self
._right
,Div(equalTo
,self
._left
))
277 def evaluation(self
,element
,variable
):
278 A
= self
._left
.evaluation(element
,variable
)
279 B
= self
._right
.evaluation(element
,variable
)
280 if A
== None or B
== None or math
.isnan(A
) or math
.isnan(B
):
286 class Div(equationElement
):
287 #Overloading division operator
288 def __init__(self
,A
,B
):
292 def evidence(self
,equalTo
,equation
):
293 equation
.addTodo(self
._left
,Mul(equalTo
,self
._right
))
294 equation
.addTodo(self
._right
,Div(self
._left
,equalTo
))
296 def evaluation(self
,element
,variable
):
297 A
= self
._left
.evaluation(element
,variable
)
298 B
= self
._right
.evaluation(element
,variable
)
299 if B
== 0.0 and A
!= None :
301 elif A
== None or B
== None or math
.isnan(A
) or math
.isnan(B
):
306 class Pow(equationElement
):
307 #Overloading power operator
308 def __init__(self
,A
,B
):
312 def evidence(self
,equalTo
,equation
):
313 equation
.addTodo(self
._base
,Pow(equalTo
,Div(K(1),self
._exponent
)))
314 equation
.addTodo(self
._exponent
,Div(Log(equalTo
,K(10)),Log(self
._base
,K(10)))) #Use logarithm with base 10
316 def evaluation(self
,element
,variable
):
317 A
= self
._base
.evaluation(element
,variable
)
318 B
= self
._exponent
.evaluation(element
,variable
)
319 if A
== None or B
== None or math
.isnan(A
) or math
.isnan(B
):
324 class Log(equationElement
):
325 #Overloading logarithm operator
326 def __init__(self
,number
,base
):
328 self
._number
= number
330 def evidence(self
,equalTo
,equation
):
331 equation
.addTodo(self
._number
,pow(self
._base
,equalTo
))
332 equation
.addTodo(self
._base
,Div(Ln(self
._number
),Ln(self
._equalTo
)))
334 def evaluation(self
,element
,variable
):
335 resultNumber
= self
._number
.evaluation(element
,variable
)
336 resultBase
= self
._base
.evaluation(element
,variable
)
337 if resultNumber
== None or resultBase
== None or math
.isnan(resultNumber
) or math
.isnan(resultBase
):
340 return math
.log(resultNumber
,resultBase
)
342 class Ln(equationElement
):
343 #Ln is natural logarithm, and is needed to inverse Log operator
344 def __init__(self
,number
):
345 self
._number
= number
347 def evaluation(self
,element
,variable
):
348 result
= self
._number
.evaluation(element
,variable
)
349 if result
== None or math
.isnan(result
):
352 return math
.log(result
)
358 class PropagateFluid(equationElement
):
359 '''Class that allow propagation of fluid between element'''
360 def __init__(self
,fluid1
,fluid2
):
361 self
._fluid
1 = fluid1
362 self
._fluid
2 = fluid2
364 def evidence(self
,equalTo
,equation
):
365 equation
.equationList
.append((self
._fluid
1,self
._fluid
2))
366 equation
.equationList
.append((self
._fluid
2,self
._fluid
1))
371 class CheckNullExergy(equationElement
):
372 '''Check if reference state is True, in this case return 0, else return None'''
373 def __init__(self
,exergy
):
374 self
._exergy
= exergy
376 def evidence(self
,equalTo
,equation
):
377 equation
.equationList
.append((self
._exergy
,CheckNullExergy(self
._exergy
)))
379 def evaluation(self
,element
,variable
):
380 refstate
= element
.properties
['reference state']
381 if refstate
.value
== True :
382 variable
.whoHelp
.add(refstate
)
387 class CheckRef(equationElement
):
388 '''Check if temperature, entropy and enthalpy equal reference value'''
389 def __init__(self
,refstate
):
390 self
._refstate
= refstate
392 def evidence(self
,equalTo
,equation
):
393 equation
.equationList
.append((self
._refstate
,CheckRef(self
._refstate
)))
395 def evaluation(self
,element
,variable
):
396 result
= matchProperties(element
,self
._refstate
.name
)
397 if result
.isImposed
== True and result
.value
== True :
400 temp
= element
.properties
['temperature']
401 tempref
= element
.properties
['reference temperature']
402 entr
= element
.properties
['entropy']
403 entrref
= element
.properties
['reference entropy']
404 enth
= element
.properties
['enthalpy']
405 enthref
= element
.properties
['reference enthalpy']
406 var
= matchProperties(element
,variable
.name
)
407 if (tempref
.value
== None or entrref
.value
== None or enthref
.value
== None or temp
.value
== None \
408 or enth
.value
== None or entr
.value
== None) and var
.value
== None: #case if something is None and ref state is None
410 elif (tempref
.value
== None or entrref
.value
== None or enthref
.value
== None or temp
.value
== None \
411 or enth
.value
== None or entr
.value
== None) and var
.value
!= None: #case if something is None and ref state is True/False then refstate need to be set at None. Because these module return only value that will be tell, its not possible to set None with a return. So we use variable.value = None
414 else: #case everythong is know, we check == and return what's needed.
415 if temp
.value
== tempref
.value
and entr
.value
== entrref
.value
and enth
.value
== enthref
.value
:
416 variable
.whoHelp
.add(temp
)
417 variable
.whoHelp
.add(tempref
)
418 variable
.whoHelp
.add(entr
)
419 variable
.whoHelp
.add(entrref
)
420 variable
.whoHelp
.add(enth
)
421 variable
.whoHelp
.add(enthref
)
429 #Notes : fluid have by defaut fluid.Fluid as value. fluid.Fluid return None for every functions.
431 ''' On ne cherche normalement pas le volume specifique des fractions vapeurs ou liquides
432 class vv_p(equationElement):
433 def __init__(self,pressure):
434 self._pressure = pressure
436 def evaluation(self,element,variable):
437 pressure = self._pressure.evaluation(element,variable)
438 fluidprop = element.properties['fluid']
439 fluid = fluidprop.value
440 variable.whoHelp.add(fluidprop)
441 return fluid.vv_p(pressure)
443 class vl_p(equationElement):
444 def __init__(self,pressure):
445 self._pressure = pressure
447 def evaluation(self,element,variable):
448 pressure = self._pressure.evaluation(element,variable)
449 fluidprop = element.properties['fluid']
450 fluid = fluidprop.value
451 variable.whoHelp.add(fluidprop)
452 return fluid.vl_p(pressure)
454 class vv_T(equationElement):
455 def __init__(self,temperature):
456 self._temperature = temperature
458 def evaluation(self,element,variable):
459 temperature = self._temperature.evaluation(element,variable)
460 fluidprop = element.properties['fluid']
461 fluid = fluidprop.value
462 variable.whoHelp.add(fluidprop)
463 return fluid.vv_T(temperature)
465 class vl_T(equationElement):
466 def __init__(self,temperature):
467 self._temperature = temperature
469 def evaluation(self,element,variable):
470 temperature = self._temperature.evaluation(element,variable)
471 fluidprop = element.properties['fluid']
472 fluid = fluidprop.value
473 variable.whoHelp.add(fluidprop)
474 return fluid.vl_T(temperature)
477 class v_pT(equationElement
):
478 def __init__(self
,pressure
,temperature
):
479 self
._pressure
= pressure
480 self
._temperature
= temperature
482 def evaluation(self
,element
,variable
):
483 pressure
= self
._pressure
.evaluation(element
,variable
)
484 fluidprop
= element
.properties
['fluid']
485 fluid
= fluidprop
.value
486 variable
.whoHelp
.add(fluidprop
)
487 qualityprop
= element
.properties
['quality']
488 quality
= qualityprop
.value
489 if quality
>= 0 and quality
<= 1:
490 variable
.whoHelp
.add(qualityprop
)
491 vv
= fluid
.vv_p(pressure
)
492 vl
= fluid
.vl_p(pressure
)
493 if vv
!= None and vl
!= None :
494 return vv
*quality
+ (1-quality
)*vl
497 elif quality
!= None:
498 temperature
= self
._temperature
.evaluation(element
,variable
)
499 variable
.whoHelp
.add(qualityprop
)
500 return fluid
.v_pT(pressure
,temperature
)
504 class v_ph(equationElement
):
505 def __init__(self
,pressure
,enthalpy
):
506 self
._pressure
= pressure
507 self
._enthalpy
= enthalpy
509 def evaluation(self
,element
,variable
):
510 pressure
= self
._pressure
.evaluation(element
,variable
)
511 fluidprop
= element
.properties
['fluid']
512 fluid
= fluidprop
.value
513 variable
.whoHelp
.add(fluidprop
)
514 qualityprop
= element
.properties
['quality']
515 quality
= qualityprop
.value
516 if quality
>= 0 and quality
<= 1:
517 variable
.whoHelp
.add(qualityprop
)
518 vv
= fluid
.vv_p(pressure
)
519 vl
= fluid
.vl_p(pressure
)
520 if vv
!= None and vl
!= None :
521 return vv
*quality
+ (1-quality
)*vl
524 elif quality
!= None:
525 enthalpy
= self
._enthalpy
.evaluation(element
,variable
)
526 variable
.whoHelp
.add(qualityprop
)
527 return fluid
.v_ph(pressure
,enthalpy
)
531 class v_ps(equationElement
):
532 def __init__(self
,pressure
,entropy
):
533 self
._pressure
= pressure
534 self
._entropy
= entropy
536 def evaluation(self
,element
,variable
):
537 pressure
= self
._pressure
.evaluation(element
,variable
)
538 fluidprop
= element
.properties
['fluid']
539 fluid
= fluidprop
.value
540 variable
.whoHelp
.add(fluidprop
)
541 qualityprop
= element
.properties
['quality']
542 quality
= qualityprop
.value
543 if quality
>= 0 and quality
<= 1:
544 variable
.whoHelp
.add(qualityprop
)
545 vv
= fluid
.vv_p(pressure
)
546 vl
= fluid
.vl_p(pressure
)
547 if vv
!= None and vl
!= None :
548 return vv
*quality
+ (1-quality
)*vl
551 elif quality
!= None:
552 entropy
= self
._entropy
.evaluation(element
,variable
)
553 variable
.whoHelp
.add(qualityprop
)
554 return fluid
.v_ps(pressure
,entropy
)
559 class Tsat_p(equationElement
):
560 '''Must not be used in State equation.'''
561 def __init__(self
,pressure
):
562 self
._pressure
= pressure
564 def evaluation(self
,element
,variable
):
565 pressure
= self
._pressure
.evaluation(element
,variable
)
566 fluidprop
= element
.properties
['fluid']
567 fluid
= fluidprop
.value
568 variable
.whoHelp
.add(fluidprop
)
569 return fluid
.Tsat_p(pressure
)
571 class T_px(equationElement
):
572 def __init__(self
,pressure
,quality
):
573 self
._pressure
= pressure
574 self
._quality
= quality
576 def evaluation(self
,element
,variable
):
577 quality
= self
._quality
.evaluation(element
,variable
)
578 pressure
= self
._pressure
.evaluation(element
,variable
)
579 if quality
>=0 and quality
<=1 :
580 fluidprop
= element
.properties
['fluid']
581 fluid
= fluidprop
.value
582 variable
.whoHelp
.add(fluidprop
)
583 return fluid
.Tsat_p(pressure
)
587 class T_ph(equationElement
):
588 def __init__(self
,pressure
,enthalpy
):
589 self
._pressure
= pressure
590 self
._enthalpy
= enthalpy
592 def evaluation(self
,element
,variable
):
593 enthalpy
= self
._enthalpy
.evaluation(element
,variable
)
594 pressure
= self
._pressure
.evaluation(element
,variable
)
595 fluidprop
= element
.properties
['fluid']
596 fluid
= fluidprop
.value
597 variable
.whoHelp
.add(fluidprop
)
598 return fluid
.T_ph(pressure
,enthalpy
)
600 class T_hs(equationElement
):
601 def __init__(self
,enthalpy
,entropy
):
602 self
._entropy
= entropy
603 self
._enthalpy
= enthalpy
605 def evaluation(self
,element
,variable
):
606 enthalpy
= self
._enthalpy
.evaluation(element
,variable
)
607 entropy
= self
._entropy
.evaluation(element
,variable
)
608 fluidprop
= element
.properties
['fluid']
609 fluid
= fluidprop
.value
610 variable
.whoHelp
.add(fluidprop
)
611 return fluid
.T_hs(enthalpy
,entropy
)
614 class psat_T(equationElement
):
615 '''Must not be used in state equation.'''
616 def __init__(self
,temperature
):
617 self
._temperature
= temperature
619 def evaluation(self
,element
,variable
):
620 temperature
= self
._temperature
.evaluation(element
,variable
)
621 fluidprop
= element
.properties
['fluid']
622 fluid
= fluidprop
.value
623 variable
.whoHelp
.add(fluidprop
)
624 return fluid
.psat_T(temperature
)
626 class p_Tx(equationElement
):
627 def __init__(self
,temperature
,quality
):
628 self
._temperature
= temperature
629 self
._quality
= quality
631 def evaluation(self
,element
,variable
):
632 quality
= self
._quality
.evaluation(element
,variable
)
633 temperature
= self
._temperature
.evaluation(element
,variable
)
634 if quality
>=0 and quality
<=1 :
635 fluidprop
= element
.properties
['fluid']
636 fluid
= fluidprop
.value
637 variable
.whoHelp
.add(fluidprop
)
638 return fluid
.psat_T(temperature
)
642 class p_hs(equationElement
):
643 def __init__(self
,enthalpy
,entropy
):
644 self
._entropy
= entropy
645 self
._enthalpy
= enthalpy
647 def evidence(self
,equalTo
,equation
):
648 #The first equation is useless, because we do not check the table. In addition, first equation return error because p_hs is not a variable. This is just to show the bearing of the 3 variable phs
649 #equation.equationList.append( (p_hs(self._enthalpy,self._entropy),equalTo))
650 #equation.equationList.append( (self._enthalpy,h_ps(equalTo,self._entropy)))
651 #equation.equationList.append( (self._entropy,s_ph(equalTo,self._enthalpy)))
654 def evaluation(self
,element
,variable
):
655 enthalpy
= self
._enthalpy
.evaluation(element
,variable
)
656 entropy
= self
._entropy
.evaluation(element
,variable
)
657 if element
.genericName() == 'state':
658 fluidprop
= element
.properties
['fluid']
659 fluid
= fluidprop
.value
660 variable
.whoHelp
.add(fluidprop
)
661 return fluid
.p_hs(enthalpy
,entropy
)
663 #Fluid that will help to compute h_ps must be at least the fluid comming from the first conn.
664 #Pay attention if you're dealing with heat exchanger
665 if element
.connection
['I1'].link
!= None:
666 state
= element
.connection
['I1'].link
.elem
667 fluidprop
= state
.properties
['fluid']
668 fluid
= fluidprop
.value
669 variable
.whoHelp
.add(fluidprop
)
670 return fluid
.p_hs(enthalpy
,entropy
)
675 class hV_p(equationElement
):
676 def __init__(self
,pressure
):
677 self
._pressure
= pressure
679 def evaluation(self
,element
,variable
):
680 pressure
= self
._pressure
.evaluation(element
,variable
)
681 fluidprop
= element
.properties
['fluid']
682 fluid
= fluidprop
.value
683 variable
.whoHelp
.add(fluidprop
)
684 return fluid
.hV_p(pressure
)
686 class hL_p(equationElement
):
687 def __init__(self
,pressure
):
688 self
._pressure
= pressure
690 def evaluation(self
,element
,variable
):
691 pressure
= self
._pressure
.evaluation(element
,variable
)
692 fluidprop
= element
.properties
['fluid']
693 fluid
= fluidprop
.value
694 variable
.whoHelp
.add(fluidprop
)
695 return fluid
.hL_p(pressure
)
697 class hV_T(equationElement
):
698 def __init__(self
,pressure
):
699 self
._temperature
= temperature
701 def evaluation(self
,element
,variable
):
702 temperature
= self
._temperature
.evaluation(element
,variable
)
703 fluidprop
= element
.properties
['fluid']
704 fluid
= fluidprop
.value
705 variable
.whoHelp
.add(fluidprop
)
706 return fluid
.hV_T(temperature
)
708 class hL_T(equationElement
):
709 def __init__(self
,pressure
):
710 self
._temperature
= temperature
712 def evaluation(self
,element
,variable
):
713 temperature
= self
._temperature
.evaluation(element
,variable
)
714 fluidprop
= element
.properties
['fluid']
715 fluid
= fluidprop
.value
716 variable
.whoHelp
.add(fluidprop
)
717 return fluid
.hV_T(temperature
)
719 class h_pT(equationElement
):
720 def __init__(self
,pressure
,temperature
):
721 self
._pressure
= pressure
722 self
._temperature
= temperature
724 def evaluation(self
,element
,variable
):
725 pressure
= self
._pressure
.evaluation(element
,variable
)
726 temperature
= self
._temperature
.evaluation(element
,variable
)
727 fluidprop
= element
.properties
['fluid']
728 fluid
= fluidprop
.value
729 variable
.whoHelp
.add(fluidprop
)
730 #We need to check quality, to know what formula to use
731 if variable
.name
[:9] != 'reference':
732 qualityprop
= element
.properties
['quality']
733 elif variable
.name
[:9] == 'reference':
734 qualityprop
= element
.properties
['reference quality']
735 quality
= qualityprop
.value
736 if quality
>= 0 and quality
<= 1:
737 HL
= fluid
.hL_T(temperature
)
738 HV
= fluid
.hV_T(temperature
)
739 variable
.whoHelp
.add(qualityprop
)
740 if HL
!= None and HV
!= None and (not math
.isnan(HL
)) and (not math
.isnan(HV
)):
741 return HL
*(1-quality
)+HV
*quality
745 elif quality
== None:
746 if temperature
>= fluid
.Tcrit() or pressure
>= fluid
.pcrit(): #Case : fluid supercritic
747 return fluid
.h_pT(pressure
,temperature
)
748 elif temperature
!= fluid
.Tsat_p(pressure
) : #Case : fluid subcooled or superheated
749 return fluid
.h_pT(pressure
,temperature
)
750 else : #Case : fluid is diphasic
753 elif math
.isnan(quality
):
754 variable
.whoHelp
.add(qualityprop
)
755 return fluid
.h_pT(pressure
,temperature
)
759 class h_ps(equationElement
):
760 def __init__(self
,pressure
,entropy
):
761 self
._pressure
= pressure
762 self
._entropy
= entropy
764 def evidence(self
,equalTo
,equation
):
765 #The first equation is useless, because we do not check the table. In addition, first equation return error because p_hs is not a variable. This is just to show the bearing of the 3 variable phs
766 #equation.equationList.append((h_ps(self._pressure,self._entropy),equalTo))
767 #equation.equationList.append((self._pressure,p_hs(equalTo,self._entropy)))
768 #equation.equationList.append((self._entropy,s_ph(self._pressure,equalTo)))
771 def evaluation(self
,element
,variable
):
772 pressure
= self
._pressure
.evaluation(element
,variable
)
773 entropy
= self
._entropy
.evaluation(element
,variable
)
774 if element
.genericName() == 'state':
775 fluidprop
= element
.properties
['fluid']
776 fluid
= fluidprop
.value
777 variable
.whoHelp
.add(fluidprop
)
778 return fluid
.h_ps(pressure
,entropy
)
780 #Fluid that will help to compute h_ps must be at least the fluid comming from the first conn.
781 #Pay attention if you're dealing with heat exchanger
782 if element
.connection
['I1'].link
!= None:
783 state
= element
.connection
['I1'].link
.elem
784 fluidprop
= state
.properties
['fluid']
785 fluid
= fluidprop
.value
786 variable
.whoHelp
.add(fluidprop
)
787 return fluid
.h_ps(pressure
,entropy
)
791 class h_px(equationElement
):
792 def __init__(self
,pressure
,quality
):
793 self
._pressure
= pressure
794 self
._quality
= quality
796 def evaluation(self
,element
,variable
):
797 pressure
= self
._pressure
.evaluation(element
,variable
)
798 quality
= self
._quality
.evaluation(element
,variable
)
799 fluidprop
= element
.properties
['fluid']
800 fluid
= fluidprop
.value
801 variable
.whoHelp
.add(fluidprop
)
802 return fluid
.h_px(pressure
,quality
)
804 class h_Tx(equationElement
):
805 def __init__(self
,temperature
,quality
):
806 self
._temperature
= temperature
807 self
._quality
= quality
809 def evaluation(self
,element
,variable
):
810 temperature
= self
._temperature
.evaluation(element
,variable
)
811 quality
= self
._quality
.evaluation(element
,variable
)
812 fluidprop
= element
.properties
['fluid']
813 fluid
= fluidprop
.value
814 variable
.whoHelp
.add(fluidprop
)
815 return fluid
.h_Tx(temperature
,quality
)
819 class sV_p(equationElement
):
820 def __init__(self
,pressure
):
821 self
._pressure
= pressure
823 def evaluation(self
,element
,variable
):
824 pressure
= self
._pressure
.evaluation(element
,variable
)
825 fluidprop
= element
.properties
['fluid']
826 fluid
= fluidprop
.value
827 variable
.whoHelp
.add(fluidprop
)
828 return fluid
.sV_p(pressure
)
830 class sL_p(equationElement
):
831 def __init__(self
,pressure
):
832 self
._pressure
= pressure
834 def evaluation(self
,element
,variable
):
835 pressure
= self
._pressure
.evaluation(element
,variable
)
836 fluidprop
= element
.properties
['fluid']
837 fluid
= fluidprop
.value
838 variable
.whoHelp
.add(fluidprop
)
839 return fluid
.sL_p(pressure
)
841 class sV_T(equationElement
):
842 def __init__(self
,pressure
):
843 self
._temperature
= temperature
845 def evaluation(self
,element
,variable
):
846 temperature
= self
._temperature
.evaluation(element
,variable
)
847 fluidprop
= element
.properties
['fluid']
848 fluid
= fluidprop
.value
849 variable
.whoHelp
.add(fluidprop
)
850 return fluid
.sV_T(temperature
)
852 class sL_T(equationElement
):
853 def __init__(self
,pressure
):
854 self
._temperature
= temperature
856 def evaluation(self
,element
,variable
):
857 temperature
= self
._temperature
.evaluation(element
,variable
)
858 fluidprop
= element
.properties
['fluid']
859 fluid
= fluidprop
.value
860 variable
.whoHelp
.add(fluidprop
)
861 return fluid
.sV_T(temperature
)
863 class s_pT(equationElement
):
864 def __init__(self
,pressure
,temperature
):
865 self
._pressure
= pressure
866 self
._temperature
= temperature
868 def evaluation(self
,element
,variable
):
869 pressure
= self
._pressure
.evaluation(element
,variable
)
870 temperature
= self
._temperature
.evaluation(element
,variable
)
871 fluidprop
= element
.properties
['fluid']
872 fluid
= fluidprop
.value
873 variable
.whoHelp
.add(fluidprop
)
874 if variable
.name
[:9] != 'reference':
875 qualityprop
= element
.properties
['quality']
876 elif variable
.name
[:9] == 'reference':
877 qualityprop
= element
.properties
['reference quality']
878 quality
= qualityprop
.value
879 if quality
>= 0 and quality
<= 1:
880 SL
= fluid
.sL_T(temperature
)
881 SV
= fluid
.sV_T(temperature
)
882 if SL
!= None and SV
!= None and (not math
.isnan(SL
)) and (not math
.isnan(SV
)):
883 variable
.whoHelp
.add(qualityprop
)
884 return SL
*(1-quality
)+SV
*quality
887 elif quality
== None:
888 if temperature
>= fluid
.Tcrit() or pressure
>= fluid
.pcrit(): #Case : fluid supercritic
889 return fluid
.s_pT(pressure
,temperature
)
890 elif temperature
!= fluid
.Tsat_p(pressure
) : #Case : fluid subcooled or superheated
891 return fluid
.s_pT(pressure
,temperature
)
892 else : #Case : fluid is diphasic
896 elif math
.isnan(quality
):
897 if temperature
>= fluid
.Tcrit() or pressure
>= fluid
.pcrit():
898 variable
.whoHelp
.add(qualityprop
)
899 return fluid
.s_pT(pressure
,temperature
)
905 class s_ph(equationElement
):
906 def __init__(self
,pressure
,enthalpy
):
907 self
._pressure
= pressure
908 self
._enthalpy
= enthalpy
910 def evidence(self
,equalTo
,equation
):
911 #The first equation is useless, because we do not check the table. In addition, first equation return error because p_hs is not a variable. This is just to show the bearing of the 3 variable phs.
912 #equation.equationList.append((s_ph(self._pressure,self._enthalpy),equalTo))
913 #equation.equationList.append((self._enthalpy,h_ps(self._pressure,equalTo)))
914 #equation.equationList.append((self._pressure,p_hs(self._enthalpy,equalTo)))
917 def evaluation(self
,element
,variable
):
918 enthalpy
= self
._enthalpy
.evaluation(element
,variable
)
919 pressure
= self
._pressure
.evaluation(element
,variable
)
920 if element
.genericName() == 'state':
921 fluidprop
= element
.properties
['fluid']
922 fluid
= fluidprop
.value
923 variable
.whoHelp
.add(fluidprop
)
924 return fluid
.s_ph(pressure
,enthalpy
)
926 #Fluid that will help to compute h_ps must be at least the fluid comming from the first conn.
927 #Pay attention if you're dealing with heat exchanger
928 if element
.connection
['I1'].link
!= None:
929 state
= element
.connection
['I1'].link
.elem
930 fluidprop
= state
.properties
['fluid']
931 fluid
= fluidprop
.value
932 variable
.whoHelp
.add(fluidprop
)
933 return fluid
.s_ph(pressure
,enthalpy
)
938 class x_ph(equationElement
):
939 def __init__(self
,pressure
,enthalpy
):
940 self
._pressure
= pressure
941 self
._enthalpy
= enthalpy
943 def evaluation(self
,element
,variable
):
944 enthalpy
= self
._enthalpy
.evaluation(element
,variable
)
945 pressure
= self
._pressure
.evaluation(element
,variable
)
946 fluidprop
= element
.properties
['fluid']
947 fluid
= fluidprop
.value
948 variable
.whoHelp
.add(fluidprop
)
949 return fluid
.x_ph(pressure
,enthalpy
)
951 class x_ps(equationElement
):
952 def __init__(self
,pressure
,entropy
):
953 self
._pressure
= pressure
954 self
._entropy
= entropy
956 def evaluation(self
,element
,variable
):
957 pressure
= self
._pressure
.evaluation(element
,variable
)
958 entropy
= self
._entropy
.evaluation(element
,variable
)
959 fluidprop
= element
.properties
['fluid']
960 fluid
= fluidprop
.value
961 variable
.whoHelp
.add(fluidprop
)
962 return fluid
.x_ps(pressure
,entropy
)