Please i need help with this code,its for my project #534
-
import tespy
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from tespy.networks import Network
from tespy.components import Sink, Source, Pump, HeatExchanger, Valve, Compressor, CycleCloser
from tespy.connections import Connection, Bus
from tespy.tools.characteristics import CharLine
from tespy.tools.characteristics import load_default_char as ldc
# Define the working fluid
fluid_list = ['R404A']
# Network setup
network = Network(fluids=fluid_list, T_unit='C', p_unit='bar', h_unit='kJ / kg', m_unit='kg / s')
# Define sources and sinks
source = Source('Ambient')
sink = Sink('Heat Sink')
# Define components
storage_tank = HeatExchanger('Evaporator')
condenser = HeatExchanger('Condenser')
expansion_valve = Valve('Expansion Valve')
compressor = Compressor('Compressor')
air_cooler = HeatExchanger('Air Cooler')
# Cycle Closer to ensure the fluid returns to the cycle
cycle_closer = CycleCloser('Cycle Closer')
# Connecting components together
# R404A enters the compressor
conn_source_compressor = Connection(source, 'out1', compressor, 'in1')
# From compressor to condenser
conn_compressor_condenser = Connection(compressor, 'out1', condenser, 'in1')
# From condenser to expansion valve
conn_condenser_valve = Connection(condenser, 'out1', expansion_valve, 'in1')
# From expansion valve to air cooler
conn_valve_air_cooler = Connection(expansion_valve, 'out1', air_cooler, 'in1')
# Air cooler to ice storage tank
conn_air_cooler_storage_tank = Connection(air_cooler, 'out1', storage_tank, 'in1')
# Ice storage tank to cycle closer (closing the loop)
conn_storage_tank_cycle_closer = Connection(storage_tank, 'out1', cycle_closer, 'in1')
# Cycle closer to sink
conn_cycle_closer_sink = Connection(cycle_closer, 'out1', sink, 'in1')
# Add connections to the network
network.add_conns(conn_source_compressor, conn_compressor_condenser, conn_condenser_valve,
conn_valve_air_cooler, conn_air_cooler_storage_tank, conn_storage_tank_cycle_closer, conn_cycle_closer_sink)
# Define Components Geometry
# Set compressor parameters
compressor.set_attr(eta_s=0.80)
# Set condenser parameters
condenser.set_attr(pr1=0.98, pr2=0.98, Q=2.75e3)
# Set expansion valve parameters
expansion_valve.set_attr(pr=0.6)
# Set storage tank parameters
storage_tank.set_attr(pr1=0.98, pr2=0.98, Q=-2.75e3)
# Air cooler parameters
air_cooler.set_attr(pr1=0.98, pr2=0.98, ttd_u=10)
# Set source and sink conditions
conn_source_compressor.set_attr(T=25, p=2.3, fluid={'R404A': 1})
conn_compressor_condenser.set_attr(p=14.3)
conn_condenser_valve.set_attr(T=-25)
network.solve('design')
network.print_results()
# Reference state for exergy analysis
T0 = 298.15 # Reference temperature (K)
p0 = 1.013 # Reference pressure (bar)
for conn in network.conns.all():
h = conn.h.val_SI # Enthalpy (J/kg)
s = conn.s.val_SI # Entropy (J/(kg K))
exergy = (h - 0) - T0 * (s - 0) # Simplified exergy calculation (assuming h_ref and s_ref are zero)
print(f'Exergy at connection {conn.label}: {exergy} J/kg') I keep getting an error that one of my component is missing an outgoing connection,I have tried everything possible,but still nothing |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Hey @Geminiman7, I've understood that your model doesn't work. Could you ask a specific question so that you can be helped? While screening your code, I noticed that you are using both source and sink as well as cycle closer in the main cycle. I recommend that you only use the cycle closer component. You also specify your condenser, evaporator and air cooler as heat exchanger component. It is necessary that you specify an inlet and an outlet on the cold side of these components. Otherwise it is possible to use the heat exchanger simple component. Hopefully it will help you. |
Beta Was this translation helpful? Give feedback.
-
As I wrote, the |
Beta Was this translation helpful? Give feedback.
Hey @Geminiman7, I've understood that your model doesn't work. Could you ask a specific question so that you can be helped?
While screening your code, I noticed that you are using both source and sink as well as cycle closer in the main cycle. I recommend that you only use the cycle closer component. You also specify your condenser, evaporator and air cooler as heat exchanger component. It is necessary that you specify an inlet and an outlet on the cold side of these components. Otherwise it is possible to use the heat exchanger simple component. Hopefully it will help you.