carbatpy.utils¶
Submodules¶
Attributes¶
Functions¶
|
Calculating the integral between a straight line and points from a curve |
|
Finds a straight line which approaches a curve, without crossing. |
|
calculate the mean distance between two equally-spaced arrays |
|
Irreversible entropy production rate for two fluid flows or an adiabatic |
|
assumption both fluids enter in equilibrium with the surrounding |
|
Calculate the exergy loss rate for two fluid flows or an adiabatic |
|
Mixtures are evaluated/screened to find mixtures with a given temperature |
|
Evalutes the data in the combined dataFrame with the initial fluid screening |
|
find the fluids used in the screening |
|
Combine two data frames out of two or more files with same number of lines |
|
Plotting a dataframe from a file using a dictionary with the keys |
|
|
|
Package Contents¶
- carbatpy.utils.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
- carbatpy.utils.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.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.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
- carbatpy.utils.exergy_loss_alternative(states, mass_flow_rates, power_in=0.0, temp_surrounding=cb._T_SURROUNDING, 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_flow(states, mass_flow_rates, power_in=0.0, temp_surrounding=cb._T_SURROUNDING, 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.mixture_search(fluids_all, temp_both, p_both, res_dir, d_temp_superheating=5, resolution=21, temp_limit=False, **kwargs)[source]¶
Mixtures are evaluated/screened to find mixtures with a given temperature glide in a certain pressure range. For all possible mixture compositions first the saturated vapor pressure at the given low temperature and composition is evaluated, if it is in the allowed regime, the saturated vapor pressure (p_h) of the mixture at the high temperature is evaluated. If this is below the allowed high pressure, the saturated liquid temperature at this p_h is evaluated and the temperature difference is taken as temperature glide. The pressure ratio is plotted as a function of temperature glide. The plot, the states (as csv-file) and the input parameters (as .json-file) are stored. in the csv-File first the mole fractions are given followed by the properties of the low temperature sat.vapor, after superheating, for thehigh temperature sat. vapor, the isentropic state after compression, high pressure sat.liquid, low pressuer isenthalpic (throtteling) state to the high pressure sat. liquid, and the low pressure saturated liquis state. For each of them: T,p,h,v,s,q,u in SI units(mass base)
- Parameters:
fluids_all (list of strings) – up to 4 fluid names of the mixture, as defined in the fluid model (REFPROP).
temp_both (List of two floats) – the minimum (at low pressure) and the maximum (at high pressure) saturated vapor temperature (both dew points) in K.
p_both (List of two floats) – allowed min and max pressure in Pa.
res_dir (string) – Directory name, where the results are stored.
d_temp_superheating (float. optional) – super heating temperature in K. The default is 5.
resolution (integer, optional) – inverse is the interval for the mole fraction screening (21 means every 0.05 a value is calculated). The default is 21.
temp_limit (Boolean, optional) – selects only values, where the temperature of the saturated liquid at high pressure is above temp_both[0]. The default is False.
kwargs (dict) – is not implemented yet, but can be used later to select another fluid model, instead of REFPROP.
- Return type:
None.
- carbatpy.utils.eval_is_eff_roskosch(data, file_out)[source]¶
Evalutes the data in the combined dataFrame with the initial fluid screening
and the output of the Roskosch compressor model (h_aus, s_aus, h_e) for exactly the states calculated along the screening. The column names are quite special and one has to know that the Roskosch model calculates in kJ, while carbatpy uses SI units (J). With the output enthalpy of the Roskosch model, the COP_comp is calculated. Using the enthalpies and entropies along the isobaric heat ransfer, mean temperatures are calculated.Here are again two cases
a) for throttling at quality=0b) throttling after subcooling to T_low (names: _lowT).With these mean temperatures, the COPs for two reversible cases are calculated: for the isentropic efficieciecy of 80% COP_rev80 and for the Roskosch ‘real’ case COP_rev_r. Finally, the (pseudo-)real COP is compared to the reversible COP, giving a second law efficiency eff_sec_law_r for the Roskosch efficiencies and eff_sec_law_80 for the fixed 80% efficiency, which include the compressor and the throttling, but no heat transfer!
The Roskosch piston compressor model is described here: http://dx.doi.org/10.1016/j.ijrefrig.2017.08.011
Is part of carbatpy.
- Parameters:
data (pandas.dataFrame) – as calculated by combining the fluid screening dataFrame with the ouput of the Roskosch model (as dataFrame).
file_out (string) – name of the file (incl. directory) where the resulting dataFrame shall be stored.
- Returns:
data – input expanded by the results.
- Return type:
pandas.dataFrame
- carbatpy.utils.get_fluid(data)[source]¶
find the fluids used in the screening
- Parameters:
data (pandas.dataFrame) – dataFrame from fluid screening with mole fractions. In the column names the names of the fluids are found.
- Returns:
fluids (list of strings) – names of the fluids.
fluid_col (list of strings) – List with the column names (includes a sarting”x_”.
fluid_str (string) – Fluid composition string as accepted by RefProp.
- carbatpy.utils.combine(filenames, filename_out='automatic')[source]¶
Combine two data frames out of two or more files with same number of lines
and fitting to each other. Can be used, when after fluid screening machine efficienceies, costs, etc. are calculated as post-processing. Can help in evaluation and plotting.
- Parameters:
filenames (list of strings) – all filenames (incl. directories), to be read.
filename_out (string, optional) – Where to store the result. The default is “automatic”. Then the first filename isxpanded vy “-combined”.
- Raises:
ValueError – If tgere is a problem with the files.
- Returns:
combined – the combined dataFrame.
- Return type:
pandas.dataFrame
- carbatpy.utils.data_plot(filename, what, filename_out='automatic', fig_title='')[source]¶
Plotting a dataframe from a file using a dictionary with the keys
being the plotted parameters “x”, “y”, “hue” etc. and storing it to a file.
- Parameters:
filename (string) – csv-file with the data-frame to be imported.
what (dictionary) – keys “y”,”x”,”hue”, “style”, size etc. values must be some column names. .
filename_out (string, optional) – where to store the plot, including directory. The default is “automatic”.
fig_title (string, optional) – Title of the figure to be plotted, default is “”.
- Returns:
success?
- Return type:
bool