Utilities¶
This utility script calculates entropy production rate and exergy loss rates, but specifically for adiabatic heat pumps or heat exchangers, only. It is used by the heat_pump_simple.py script.
It is found at: carbatpy.utils.exergy_loss
Created on Sun Nov 5 10:01:28 2023
@author: atakan
- carbatpy.utils.exergy_loss.exergy_loss_alternative(states, mass_flow_rates, power_in=0.0, temp_surrounding=288.15, verbose=False, entropy_position=4, enthaply_position=2)[source]¶
assumption both fluids enter in equilibrium with the surrounding if entropy is reduced, T is below the environment T and exergy is positive
but this not correct yet, should be implemented correctly
- carbatpy.utils.exergy_loss.exergy_loss_flow(states, mass_flow_rates, power_in=0.0, temp_surrounding=288.15, verbose=False, entropy_position=4)[source]¶
Calculate the exergy loss rate for two fluid flows or an adiabatic heat exchanger. It is intended to use for heat pumps, where energy is stored at low and at high temperature. Uses s_irr_flow. All parameters are described there, except one. Gouy-Stodola
- Parameters:
states (TYPE) – DESCRIPTION.
mass_flow_rates (TYPE) – DESCRIPTION.
power_in (TYPE, optional) – DESCRIPTION. The default is 0..
temp_surrounding (Float, optional) – surrounding temperature in K. The default is cb._T_SURROUNDING.
verbose (TYPE, optional) – DESCRIPTION. The default is False.
entropy_position (TYPE, optional) – DESCRIPTION. The default is 4.
- Returns:
Exergy loss rate in W.
- Return type:
float
- carbatpy.utils.exergy_loss.s_irr_flow(states, mass_flow_rates, verbose=False, entropy_position=4)[source]¶
Irreversible entropy production rate for two fluid flows or an adiabatic heat exchanger. It is intended to use for heat pumps, where energy is stored at low and at high temperature.
- Parameters:
states (numpy-array [n,2,7]) – the states to analyse ordered as entering fluids[:,0,:] and exiting fluid [:,1,:] the states are as defined in fluid_props, with the 4th value being the specific entropy in J/(kg K)(see below).
mass_flow_rates (numpy array of length n) – the mass flow rates in SI units (kg/s).
verbose (Boolean, optional) – should we print? The default is False.
entropy_position (Integer, optional) – in the states array, where to find thge specific entropy. The default is 4.
- Returns:
entropy production rate in W/K.
- Return type:
float
find the straight line which just touches a curve, while having the minimum area between the curves.
2024-02-11 part of carbatpy
@author: atakan
- carbatpy.utils.curve_min_distance_finder.diff_mean(high, low, dist_min=0.0, optimize=False)[source]¶
calculate the mean distance between two equally-spaced arrays
In thermodynamics/heat exchangers for minimum approach temperature. The size of both arrays must be the same. If the curves cross, success will be False!
- Parameters:
high (numpy array (length m)) – the high values.
low (numpy array(length m)) – the low values.
dist_min (float, optional) – minimum required distnce, must be positive. The default is 0..
optimize (boolean, optional) – if used for optimization. The default is False.
- Returns:
for optimization the mean difference is returned, else a dictionary with success, mean-difference, all differences, dist_min.
- Return type:
dictionary or float
- carbatpy.utils.curve_min_distance_finder.find_min_approach(values_in, below=True, delta=0)[source]¶
Finds a straight line which approaches a curve, without crossing.
Mainly for finding the minimum approach of a fluid with phase change to a fluid with a constant heat capacity along heat transfer. One can select, whether the straight line should be below the curve or above.
- Parameters:
values (numpy array [2,n]) – [0,n] are the x-values, [1,n] are the y-values.
below (boolean, optional) – should the straight line be below? The default is True.
delta (float, optional) – wanted least distance between curves (absolute value.)
- Returns:
output – keys are “success”, “integral”: the integral between curve and line, “line_par”: slope and intercept of the line (np.array),”below”:as above, “message”: result.message from minimize}.
- Return type:
dictionary
- carbatpy.utils.curve_min_distance_finder.straight_diff(param, values, below=True)[source]¶
Calculating the integral between a straight line and points from a curve
the line is defined by the param values [slope,intercept], values[0,:] are the x values, values[1,:] are the y-values. below decides, whether the straight line should be below or not. This function is used for minimization. If the curves cross each other or if the line is on the wrong side, a large value is returned.
- Parameters:
param (list of float) – [slope,intercept].
values (numpy.array [2,n_points]) – values[0,:] are the x values, values[1,:] are the y-values.
below (boolean, optional) – is the straight line below. The default is True.
- Returns:
integral of the difference between the curves.
- Return type:
float
Carnot Battery¶
A simple Carnot battery run-script is found at carbatpy.utils.run_carnot_battery which goes through the thermodynamics.
This can be used as a starting point for own scripts and variations. The structure is for two double-tank storages, together with heat rejection to water at ambient temperature. Most of the script sets pressures, temperature levels, fluid composition, heat flow rates etc. The heat pump instance is hp0 and the ORC is orc0. Please check the warnings at the end; only when both braclkets are empty, there will be no crossing of temperature curves or too small temperature differences. The final plot is found in the results directory (resultslast_T_H_dot_plot_orc.png), but also further data are stored there. The directory can be changed.
Helpers¶
Some helper functions, found at carbatpy\helpers Here for copying all results and the source py-file to a new directory.
Helpers for file handling, e.g. copy the actual py-File after adding the actual date-time and copy it to a directory
Created on Thu Feb 1 16:18:03 2024
@author: atakan
- carbatpy.helpers.file_copy.copy_script_add_date(file_name_end, source_file, directory)[source]¶
File handling, copy the actual py-File after adding the actual date-time and copy it to a directory which is also named date-time - file_name_end return the date-time for further usage
- Parameters:
file_name_end (string) – the file name to be added to the date, also for the directory name.
source_file (string) – The source file to copy (from __file__).
directory (string) – The directory to copy to.
- Returns:
directory – The new directory name and the file name(s) without extension.
- Return type:
String