carbatpy.utils ============== .. py:module:: carbatpy.utils Submodules ---------- .. toctree:: :maxdepth: 1 /autoapi/carbatpy/utils/curve_min_distance_finder/index /autoapi/carbatpy/utils/exergy_loss/index /autoapi/carbatpy/utils/optimize/index /autoapi/carbatpy/utils/property_eval_mixture/index /autoapi/carbatpy/utils/property_eval_mixture_test/index /autoapi/carbatpy/utils/run_carnot_battery/index /autoapi/carbatpy/utils/run_heat_pump_simple/index /autoapi/carbatpy/utils/run_screening_evaluation/index Attributes ---------- .. autoapisummary:: carbatpy.utils.x_val carbatpy.utils.n_pos carbatpy.utils.FLUID carbatpy.utils.FLUIDS_ACTUAL Functions --------- .. autoapisummary:: carbatpy.utils.straight_diff carbatpy.utils.find_min_approach carbatpy.utils.diff_mean carbatpy.utils.s_irr_flow carbatpy.utils.exergy_loss_alternative carbatpy.utils.exergy_loss_flow carbatpy.utils.mixture_search carbatpy.utils.eval_is_eff_roskosch carbatpy.utils.get_fluid carbatpy.utils.combine carbatpy.utils.data_plot carbatpy.utils.plot_cycle carbatpy.utils.get_cycle_points Package Contents ---------------- .. py:function:: straight_diff(param, values, below=True) 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. :param param: [slope,intercept]. :type param: list of float :param values: values[0,:] are the x values, values[1,:] are the y-values. :type values: numpy.array [2,n_points] :param below: is the straight line below. The default is True. :type below: boolean, optional :returns: integral of the difference between the curves. :rtype: float .. py:function:: find_min_approach(values_in, below=True, delta=0) 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. :param values: [0,n] are the x-values, [1,n] are the y-values. :type values: numpy array [2,n] :param below: should the straight line be below? The default is True. :type below: boolean, optional :param delta: wanted least distance between curves (absolute value.) :type delta: float, optional :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}. :rtype: dictionary .. py:function:: diff_mean(high, low, dist_min=0.0, optimize=False) 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! :param high: the high values. :type high: numpy array (length m) :param low: the low values. :type low: numpy array(length m) :param dist_min: minimum required distnce, must be positive. The default is 0.. :type dist_min: float, optional :param optimize: if used for optimization. The default is False. :type optimize: boolean, optional :returns: for optimization the mean difference is returned, else a dictionary with success, mean-difference, all differences, dist_min. :rtype: dictionary or float .. py:data:: x_val .. py:data:: n_pos :value: [0, 2, 4] .. py:function:: s_irr_flow(states, mass_flow_rates, verbose=False, entropy_position=4) 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. :param states: 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). :type states: numpy-array [n,2,7] :param mass_flow_rates: the mass flow rates in SI units (kg/s). :type mass_flow_rates: numpy array of length n :param verbose: should we print? The default is False. :type verbose: Boolean, optional :param entropy_position: in the states array, where to find thge specific entropy. The default is 4. :type entropy_position: Integer, optional :returns: entropy production rate in W/K. :rtype: float .. py:function:: exergy_loss_alternative(states, mass_flow_rates, power_in=0.0, temp_surrounding=cb._T_SURROUNDING, verbose=False, entropy_position=4, enthaply_position=2) 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 .. py:function:: exergy_loss_flow(states, mass_flow_rates, power_in=0.0, temp_surrounding=cb._T_SURROUNDING, verbose=False, entropy_position=4) 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 :param states: DESCRIPTION. :type states: TYPE :param mass_flow_rates: DESCRIPTION. :type mass_flow_rates: TYPE :param power_in: DESCRIPTION. The default is 0.. :type power_in: TYPE, optional :param temp_surrounding: surrounding temperature in K. The default is cb._T_SURROUNDING. :type temp_surrounding: Float, optional :param verbose: DESCRIPTION. The default is False. :type verbose: TYPE, optional :param entropy_position: DESCRIPTION. The default is 4. :type entropy_position: TYPE, optional :returns: Exergy loss rate in W. :rtype: float .. py:data:: FLUID :value: 'Propane * Pentane' .. py:function:: mixture_search(fluids_all, temp_both, p_both, res_dir, d_temp_superheating=5, resolution=21, temp_limit=False, **kwargs) 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) :param fluids_all: up to 4 fluid names of the mixture, as defined in the fluid model (REFPROP). :type fluids_all: list of strings :param temp_both: the minimum (at low pressure) and the maximum (at high pressure) saturated vapor temperature (both dew points) in K. :type temp_both: List of two floats :param p_both: allowed min and max pressure in Pa. :type p_both: List of two floats :param res_dir: Directory name, where the results are stored. :type res_dir: string :param d_temp_superheating: super heating temperature in K. The default is 5. :type d_temp_superheating: float. optional :param resolution: inverse is the interval for the mole fraction screening (21 means every 0.05 a value is calculated). The default is 21. :type resolution: integer, optional :param temp_limit: selects only values, where the temperature of the saturated liquid at high pressure is above temp_both[0]. The default is False. :type temp_limit: Boolean, optional :param kwargs: is not implemented yet, but can be used later to select another fluid model, instead of REFPROP. :type kwargs: dict :rtype: None. .. py:function:: eval_is_eff_roskosch(data, file_out) 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 .. line-block:: a) for throttling at quality=0 b) 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. :param data: as calculated by combining the fluid screening dataFrame with the ouput of the Roskosch model (as dataFrame). :type data: pandas.dataFrame :param file_out: name of the file (incl. directory) where the resulting dataFrame shall be stored. :type file_out: string :returns: **data** -- input expanded by the results. :rtype: pandas.dataFrame .. py:function:: get_fluid(data) find the fluids used in the screening :param data: dataFrame from fluid screening with mole fractions. In the column names the names of the fluids are found. :type data: pandas.dataFrame :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. .. py:function:: combine(filenames, filename_out='automatic') 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. :param filenames: all filenames (incl. directories), to be read. :type filenames: list of strings :param filename_out: Where to store the result. The default is "automatic". Then the first filename isxpanded vy "-combined". :type filename_out: string, optional :raises ValueError: If tgere is a problem with the files. :returns: **combined** -- the combined dataFrame. :rtype: pandas.dataFrame .. py:function:: data_plot(filename, what, filename_out='automatic', fig_title='') 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. :param filename: csv-file with the data-frame to be imported. :type filename: string :param what: keys "y","x","hue", "style", size etc. values must be some column names. . :type what: dictionary :param filename_out: where to store the plot, including directory. The default is "automatic". :type filename_out: string, optional :param fig_title: Title of the figure to be plotted, default is "". :type fig_title: string, optional :returns: success? :rtype: bool .. py:function:: plot_cycle(filename, dataset) .. py:function:: get_cycle_points(data, index) .. py:data:: FLUIDS_ACTUAL :value: ['Propane', 'Ethane', 'Pentane', 'Butane']