Solar Water Heating loop using TESPy
Closed this issue · 0 comments
Hello everyone!
First of all, thank you for creating and sharing the TESPy library. I am an investigator and I am using it for modelling a thermal loop including a solar collector, that tranfers heat through a HX to a source-and-sink system (imitating a industrial process demand). At the hot side I've also include a pump and a cyclecloser component. Here is my current code:
from tespy.networks import Network
from tespy.components import Source, Sink, Pump, HeatExchanger, SolarCollector, CycleCloser
from tespy.connections import Connection
from tespy.tools import document_model
import logging
from tespy.tools import logger
logging.basicConfig(filename='pump_loop_log.log',
level=logging.DEBUG,
format='%(asctime)s - %(levelname)s - %(message)s')
console = logging.StreamHandler()
console.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
console.setFormatter(formatter)
logging.getLogger('').addHandler(console)
network = Network(fluids='H2O', p_unit='bar', T_unit='C')
source = Source('Source')
sink = Sink('Sink')
pump = Pump('Pump')
heat_exchanger = HeatExchanger('Heat Exchanger')
solar_collector = SolarCollector('Solar Collector')
cc = CycleCloser('cycle closing component')
conn_collector_to_hex = Connection(solar_collector, 'out1', heat_exchanger, 'in1', label='Collector to HEX')
conn_hex_to_sink = Connection(heat_exchanger, 'out2', sink, 'in1', label='HEX to Sink')
conn_source_to_hex = Connection(source, 'out1', heat_exchanger, 'in2', label='Source to HEX')
conn_hex_to_pump = Connection(heat_exchanger, 'out1', pump, 'in1', label='HEX to Pump')
conn_pump_outlet = Connection(pump, 'out1', cc, 'in1', label='Pump to Cc')
conn_collector_inlet = Connection(cc, 'out1', solar_collector, 'in1', label='Cc to Collector')
network.add_conns(conn_collector_to_hex, conn_hex_to_sink, conn_source_to_hex, conn_hex_to_pump, conn_pump_outlet, conn_collector_inlet)
pump.set_attr(eta_s=0.8)
heat_exchanger.set_attr(pr1=0.95, pr2=0.95)
solar_collector.set_attr(pr=0.95, E=3000, design=['pr', 'E'], offdesign=['Q'],
Tamb=25, A=6000, eta_opt=0.92, lkf_lin=3.034, lkf_quad=0.014)
conn_source_to_hex.set_attr(p=1, T=35, fluid={'H2O': 1}, m=300)
conn_pump_outlet.set_attr(p=3, m=400, fluid={'H2O': 1})
conn_hex_to_sink.set_attr(T=60)
network.solve('design')
network.print_results()
network.save('cset')
document_model(network, filename='pump_loop_doc')
This code runs without errors and saves the design mode results.
I've read examples in the documentation and dive into the discussions, but I still have trouble understanding the capabilities of the off-design mode. For example, I've stablish the parameters for the connections thinking of controlling some of the components and creating a simulation loop. The global idea is to imitate a transient simulation, updating input variables at each time step and exporting results. Something like this:
def run_simulation(STS_instance, tmy_path, demand_profile_path, sim_id, results_file_path, n_hours=24):
Initialization(STS_instance, tmy_path, demand_profile_path)
for i in range(n_hours):
irradiance, T_amb = TimeStepDefinition(STS_instance, i)
TimeStepSolution(STS_instance, i, irradiance, T_amb)
LastCallOfSimulation(sim_id, results_file_path)
I understand that TESPy is not designed for transient simulations, but I’d like to give it a try. In my attempt to control the operation of this loop, I plan to run the network in off-design mode. (I believe this is the recommended approach once the system has been solved in design mode and I want to evaluate its behavior when modifying variables.)
For instance, I am considering adjusting the mass flow rate exiting the pump to control the fluid temperature reaching the sink (to meet the "process" target temperature).
I realize this might be pushing TESPy beyond its intended use, but that’s part of my question: Am I on the right track in trying to use the framework to modify variables and retrieve the resulting states (to control system behavior)? If so, how should I properly implement the off-design mode solver?
Thank you in advance for any guidance!
Sincerely,
Camila Martin