Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_comps of class Network does not work prior to first solve #360

Closed
fwitte opened this issue Sep 23, 2022 Discussed in #359 · 5 comments · Fixed by #362
Closed

get_comps of class Network does not work prior to first solve #360

fwitte opened this issue Sep 23, 2022 Discussed in #359 · 5 comments · Fixed by #362

Comments

@fwitte
Copy link
Member

fwitte commented Sep 23, 2022

Discussed in #359

Originally posted by GoldenPotatis September 22, 2022
Hi!

I'm a new user of TESPy and still learning. I found this small issue and would like to share with the community.
I'm using Python3.8.9 and TESPy0.6.0

In the Network Class, it is possible to view the network connections and components by calling the network.conns attributes and network.comps attributes. The network.conns works perfectly fine. However, the user may find that network.comps does not work. It returns AttributeError: 'Network' object has no attribute 'comps'.

The example I'm using is a simple condenser cooled by air, same as in the Condenser example code in tespy.readthedocs:

from tespy.networks import Network
from tespy.components import Source, Sink, Condenser
from tespy.connections import Connection

# create a network and components
nw = Network(fluids=['water', 'air'], T_unit='C', p_unit='bar', h_unit='kJ / kg')
air_in = Source(label='air inlet')
air_out = Sink('air outlet')
waste_steam = Source('waste steam')
water = Sink('condensate water')
condenser = Condenser('condenser')

# create connections
air_con = Connection(air_in, 'out1', condenser, 'in2', label='air to condenser')
con_air = Connection(condenser, 'out2', air_out, 'in1', label='condenser to air')
ws_con = Connection(waste_steam, 'out1', condenser, 'in1', label='ws to con')
con_water = Connection(condenser, 'out1', water, 'in1')

nw.add_conns(air_con, con_air, ws_con, con_water)

When calling the nw.conns attributes, it will return a Pandas DataFrame. But calling nw.comps will result in AttributeError: 'Network' object has no attribute 'comps'.

image

Correspondingly, the Network.get_comp() doesn't work neither.

After looking into the source code of Network, it is found that the network.conns is initiated at the beginning under def __init__(self, fluids, memorise_fluid_properties=True, **kwargs) and def set_defaults(self). But network.comps is not initiated. The first time network.comps is initiated is actually under def check_network(self), which is:

comps = pd.unique(self.conns[['source', 'target']].values.ravel())
# build the dataframe for components

After running nw.check_network(), the nw.comps then works perfectly fine, which gives a dataframe of the components.

image

It is therefore suggested to initiate the .comps at the beginning of the code to avoid such error.

Another attached question is under the example code of Condenser in readthedocs, why the air inlet is Sink and air outlet is Source?

amb_in = Sink('ambient air inlet')
amb_out = Source('air outlet')

Based on the definition of Source and Sink, should it be like air inlet is Source and air outlet is Sink?

@fwitte
Copy link
Member Author

fwitte commented Sep 23, 2022

Hi @GoldenPotatis,

I made your suggestion an issue and will open a pr to fix this. You could do it yourself, if you are interested. If you need help with that, please let me know.

Thank you very much for you suggestions!

@GoldenPotatis
Copy link

Hi @GoldenPotatis,

I made your suggestion an issue and will open a pr to fix this. You could do it yourself, if you are interested. If you need help with that, please let me know.

Thank you very much for you suggestions!

Hi Francesco, yes I can try to fix it, thanks for opening it for me!

@fwitte
Copy link
Member Author

fwitte commented Oct 2, 2022

@GoldenPotatis: I fixed the issue in #362 and merged it in dev already. It is now possible to access all components, which were part of the connections added to the network even before solving the model. Thank you again for reporting the bug, cheers!

@GoldenPotatis
Copy link

GoldenPotatis commented Oct 2, 2022 via email

@fwitte
Copy link
Member Author

fwitte commented Oct 2, 2022

Oh, dont worry :).

Get well soon!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants