Simplify component/connection property value check #1048
Replies: 2 comments 4 replies
|
I think that is a nice idea, I already thought about similar here #796.
This is a really valid point, that was something which has confused me in the past as well :D What about something like this: print("=" * 60)
print("before solving")
print("=" * 60)
print(repr(c1))
print()
print(c1)
print()
print(c2)
print()
print(va)
nw.solve("design")
print()
print("=" * 60)
print("after solving")
print("=" * 60)
print(c1)
print()
print(c2)
print()
print(va)
print()
print("single data containers")
print("-" * 60)
print("print(c1.T):")
print(c1.T)
print()
print("print(c1.fluid):")
print(c1.fluid)
print()
print("repr(c1.T): ", repr(c1.T))
print("repr(c1.fluid):", repr(c1.fluid))
print("repr(va.pr): ", repr(va.pr))
print()
print("connection with a four component mixture")
print("-" * 60)
air_so = Source("air source")
air_si = Sink("air sink")
c3 = Connection(air_so, "out1", air_si, "in1", label="air")
c3.set_attr(
m=1.2,
fluid={"N2": 0.7551, "O2": 0.2314, "Ar": 0.0129, "CO2": 0.0006}
)
print(c3)
print()
print("print(c3.fluid):")
print(c3.fluid)============================================================
before solving
============================================================
Connection('1', source:out1 -> expansion valve:in1)
Connection: 1 (source:out1 -> expansion valve:in1)
property value unit SI value spec
---------- ------- ---- -------- ----
m 3.6000 nan set
p 16.0000 nan set
T 95.3000 nan set
fluid[NH3] 1.0000 set
Connection: 2 (expansion valve:out1 -> sink:in1)
property value unit SI value spec
-------- ---------------- ---- -------- ----
p_ref 0.5 * p('1') + 0 set
Valve: expansion valve
no specifications or results
============================================================
after solving
============================================================
Connection: 1 (source:out1 -> expansion valve:in1)
property value unit SI value spec
---------- --------- ---------- ----------- ----
m 3.6000 kg / s 3.6000e+00 set
p 16.0000 bar 1.6000e+06 set
h 1797.2835 kJ / kg 1.7973e+06
T 95.3000 °C 3.6845e+02 set
T_bubble 41.0430 °C 3.1419e+02
T_dew 41.0430 °C 3.1419e+02
v 0.3730 m3 / s 3.7301e-01
x 1.0000 1.0000e+00
td_dew 54.2570 Δ°C 5.4257e+01
td_bubble -54.2570 Δ°C -5.4257e+01
vol 0.1036 m3 / kg 1.0361e-01
s 6103.0951 J / K / kg 6.1031e+03
fluid[NH3] 1.0000 set
Connection: 2 (expansion valve:out1 -> sink:in1)
property value unit SI value spec
---------- ---------------- ---------- ----------- ----
m 3.6000 kg / s 3.6000e+00
p 8.0000 bar 8.0000e+05
h 1797.2835 kJ / kg 1.7973e+06
T 84.1502 °C 3.5730e+02
T_bubble 17.8634 °C 2.9101e+02
T_dew 17.8634 °C 2.9101e+02
v 0.7514 m3 / s 7.5142e-01
x 1.0000 1.0000e+00
td_dew 66.2868 Δ°C 6.6287e+01
td_bubble -66.2868 Δ°C -6.6287e+01
p_ref 0.5 * p('1') + 0 set
vol 0.2087 m3 / kg 2.0873e-01
s 6421.5284 J / K / kg 6.4215e+03
fluid[NH3] 1.0000
Valve: expansion valve
parameter value unit SI value spec
--------- ---------- ---- ---------- ----
pr 0.5000 5.0000e-01
dp 8.0000 bar 8.0000e+05
zeta_d4 4.8763e+05 4.8763e+05
zeta 4.8763e+05 4.8763e+05
single data containers
------------------------------------------------------------
print(c1.T):
value unit SI value spec
------- ---- ---------- ----
95.3000 °C 3.6845e+02 set
print(c1.fluid):
fluid mass fraction spec
----- ------------- ----
NH3 1.0000 set
repr(c1.T): FluidProperties(val=95.3, unit='°C', val_SI=368.45, is_set=True)
repr(c1.fluid): FluidComposition(val={'NH3': 1.0}, is_set=['NH3'])
repr(va.pr): ComponentProperties(val=0.5, unit='', val_SI=0.5, is_set=False, is_var=False)
connection with a four component mixture
------------------------------------------------------------
Connection: air (air source:out1 -> air sink:in1)
property value unit SI value spec
---------- ------ ---- -------- ----
m 1.2000 nan set
fluid[N2] 0.7551 set
fluid[O2] 0.2314 set
fluid[Ar] 0.0129 set
fluid[CO2] 0.0006 set
print(c3.fluid):
fluid mass fraction spec
----- ------------- ----
N2 0.7551 set
O2 0.2314 set
Ar 0.0129 set
CO2 0.0006 set |
|
Ah, yes that looks nice. By the advanced formatting of the printouts it is clear, that it is just a printout. |
Uh oh!
There was an error while loading. Please reload this page.
It annoys me to have to type
._valeach time I just want to get a component property for debugging or whatevver.I would appreciate when I could get the value as pint quantity just by writting (like it is the case for property decorated methods):
my_connection.TAs the datacontainer should be revised anyway, this might be a good moment to think about such a feature.
A first quite simple idea is to add a
__repr__()dunder method to the corresponding datacontainers, returning the._valproperty:I already tested it and it works, it just might confuse people, as it seems to return the value, but it is actually still the object and just prints the value.
All reactions