carbatpy.helpers.opti_cycle_comp_helpers
Helper functions for optimizations of cycles, which use comp.py.
Created on Mon Aug 4 11:39:05 2025
@author: atakan Universität Duisburg-Essen, Germany
In the framework of the Priority Programme: “Carnot Batteries: Inverse Design from Markets to Molecules” (SPP 2403) https://www.uni-due.de/spp2403/ https://git.uni-due.de/spp-2403/residuals_weather_storage
Functions
|
Heat pump COP optimization, varying p_high and mixture composition |
|
ORC optimization, varying p_high and mixture composition etc. |
|
CB optimization, varying p_high and mixture composition etc. |
|
|
|
Extracts all optimizable parameter values, along with their bounds and hierarchical paths, |
|
Reconstructs a configuration dictionary from a flat list of optimized values |
|
Converts a species string in format 'Propane * Butane * Pentane * Hexane' |
|
Extracts column names for optimization variables based on paths. |
|
Extracts column names for optimization variables based on paths. |
Module Contents
- carbatpy.helpers.opti_cycle_comp_helpers.optimize_wf_heat_pump(dir_name, config_0, bounds_0, **kwargs)[source]
Heat pump COP optimization, varying p_high and mixture composition
p_low cannot be selected directly, it is determined by the storage temperature and the superheating temperature difference and the minimum approach temperature. In optimization, the low pressure (wanted) from the configuration yaml file is checked. If the calculated low pressure is below that value, the COP is weighted with the ratio.
- Parameters:
dir_name (str or dict) – either the path to the yaml file with all configuration parameters, or a dictionary with all values.
config_0 (dict) – vales set here and deviating from dir_name.
bounds_0 (dictTYPE) – dictionary with the p_high bounds and the upper bounds of the first three molefractions. The remaining value is the difference to 1. It is checked that the sum is 1 and all vales are positive.
**kwargs –
‘optimize_global’: select optimization algorith “dif_evol”, “bas_hop”, ‘shgo’, or local minimizer (Nelson Mead).
- Returns:
result (OptimizeResult) – The result of the optimization.
paths (list of lists) – from function extract_optim_data_with_paths. Needed to reconstruct the config_0 dictionary from the optimizer x-list.
- carbatpy.helpers.opti_cycle_comp_helpers.optimize_orc(dir_name, cop, q_dot_h, config_0, bounds_0, **kwargs)[source]
ORC optimization, varying p_high and mixture composition etc.
- Parameters:
dir_name (str or dict) – either the path to the yaml file with all configuration parameters, or a dictionary with all values.
cop (float) – COP of the charging heat pump; is needed to secure steady state discharging.
q_dot_h (float) – The heat flow from the high temperature storage to the working fluid in the evaporator.
config_0 (dict) – vales set here and deviating from dir_name.
bounds_0 (dictTYPE) – dictionary with the p_high bounds and the upper bounds of the first three molefractions. The remaining value is the difference to 1. It is checked that the sum is 1 and all vales are positive.
**kwargs –
- ‘optimize_global’: select optimization algorith “dif_evol”, “bas_hop”,
or local minimizer (Nelson Mead).
- Returns:
result (OptimizeResult) – The result of the optimization.
paths (list of lists) – from function extract_optim_data_with_paths. Needed to reconstruct the config_0 dictionary from the optimizer x-list.
- carbatpy.helpers.opti_cycle_comp_helpers.optimize_cb(dir_names, configs, bounds, **kwargs)[source]
CB optimization, varying p_high and mixture composition etc.
- Parameters:
dir_name (str or dict) – either the path to the yaml file with all configuration parameters, or a dictionary with all values.
cop (float) – COP of the charging heat pump; is needed to secure steady state discharging.
q_dot_h (float) – The heat flow from the high temperature storage to the working fluid in the evaporator.
config_0 (dict) – vales set here and deviating from dir_name.
bounds_0 (dictTYPE) – dictionary with the p_high bounds and the upper bounds of the first three molefractions. The remaining value is the difference to 1. It is checked that the sum is 1 and all vales are positive.
**kwargs –
- ‘optimize_global’: select optimization algorith “dif_evol”, “bas_hop”,
or local minimizer (Nelson Mead).
- ’workers’: the number of workers for the differential evolution algorithm.
Integer, optional, default value is 1.
’maxiter’: maximum iterations of optimizers, integer, default value is 200.
- Returns:
result (OptimizeResult) – The result of the optimization.
paths (list of lists) – from function extract_optim_data_with_paths. Needed to reconstruct the config_0 dictionary from the optimizer x-list.
- carbatpy.helpers.opti_cycle_comp_helpers.extract_optim_data_with_paths(config, bounds)[source]
Extracts all optimizable parameter values, along with their bounds and hierarchical paths, from a (possibly nested) configuration dictionary for optimization (e.g., heat pump application).
- Parameters:
config (dict) – The (possibly nested) configuration dictionary containing initial values.
bounds (dict) – Dictionary with bounds for all optimizable parameters, structured like config.
- Returns:
x0 (list) – A flat list of all initial parameter values to be optimized (e.g., p_high and mole fractions).
bnds (list) – List of bounds tuples corresponding to all entries in x0.
paths (list of lists) – Each entry is the hierarchical path (list of keys/indices) to the corresponding variable in config. Can be used to reconstruct the config dictionary from an x-list after optimization.
Example
>>> x0, bnds, paths = extract_optim_data_with_paths(config, bounds)
- carbatpy.helpers.opti_cycle_comp_helpers.insert_optim_data(config, x, paths)[source]
Reconstructs a configuration dictionary from a flat list of optimized values and corresponding paths, including special handling for mole fractions. For back conversion after optimization (scipy.optimize).
- Parameters:
config (dict) – The original configuration dictionary (will be deep-copied).
x (list or array) – The optimizer parameter vector (e.g., for p_high and first n-1 mole fractions).
paths (list of lists) – The list of hierarchical paths as produced by extract_optim_data_with_paths; describes where in config each value from x should be inserted.
- Returns:
conf_new – A new dictionary with the updated parameter values from x inserted. For fields called ‘fractions’, the last value is set to 1 minus the sum of the others (to ensure the fractions sum to 1).
- Return type:
dict
Example
>>> conf_new = insert_optim_data(config, x, paths)
- carbatpy.helpers.opti_cycle_comp_helpers.parse_species_string(species_str)[source]
Converts a species string in format ‘Propane * Butane * Pentane * Hexane’ into a list without spaces and asterisks.
- Parameters:
species_str (str) – Species string with asterisk separation
- Returns:
List of species names
- Return type:
list
- carbatpy.helpers.opti_cycle_comp_helpers.extract_cycle_column_names_from_config(config_dict, paths)[source]
Extracts column names for optimization variables based on paths. Returns a single flat list with prefixed names for non-fraction variables.
- Parameters:
config_dict (dict) – Dictionary with configuration data (contains species names for fractions) Structure: config_dict[“working_fluid”][“species”] = “Propane * Butane * …”
paths (list) – Dictionary with paths for each optimization
- Returns:
Single flat list of column names for all optimization variables
- Return type:
list
- carbatpy.helpers.opti_cycle_comp_helpers.extract_column_names_from_config(config_dict, paths_dict)[source]
Extracts column names for optimization variables based on paths. Returns a single flat list with prefixed names for non-fraction variables.
- Parameters:
config_dict (dict) – Dictionary with configuration data (contains species names for fractions) Structure: config_dict[“working_fluid”][“species”] = “Propane * Butane * …”
paths_dict (dict) – Dictionary with paths for each optimization group (e.g. “hp”, “orc”)
- Returns:
Single flat list of column names for all optimization variables
- Return type:
list