tespy.models package¶
tespy.models.template module¶
- class tespy.models.template.ModelTemplate[source]¶
Bases:
object- create_diagram(fluid_name)[source]¶
Create and configure a fluid property diagram for a fluid.
Override this method to customize the diagram, e.g. to adjust the isoline ranges to the operating envelope of your model. The base implementation creates subcritical isolines between -20 °C and 200 °C.
- Parameters:
fluid_name (str) – Name of the (pure) fluid.
- Returns:
fluprodia.FluidPropertyDiagram – Diagram with calculated isolines.
- optimize(algorithm, termination, variables: dict, constraints: dict = None, objective: list = None, minimize_flags: list = None, kpi: list = None) tuple[source]¶
Run a pymoo optimization and return the full evaluation log and the pymoo result.
- Parameters:
algorithm – A pymoo algorithm instance, e.g.
PSO(pop_size=20).termination – Pymoo termination criterion, e.g.
("n_gen", 50).variables (dict) – Decision variables mapping parameter name to
{"min": ..., "max": ...}.constraints (dict, optional) – Inequality constraints mapping parameter name to a bound, e.g.
{"p_extraction_1": "p_extraction_2"}enforcesp_extraction_1 > p_extraction_2.objective (list, optional) – Names of model parameters to use as objectives.
minimize_flags (list, optional) – One
boolper objective;Trueminimizes,Falsemaximizes. Defaults to minimization for all.kpi (list, optional) – Additional parameter names to record in the log alongside the objectives.
- Returns:
tuple – A
(log, result)tuple wherelogis apandas.DataFrameof every evaluated individual (including infeasible ones) andresultis the pymoo result object. When constraints are active, filterlogfor feasibility before selecting the optimum.result.Xandresult.Falready contain only feasible solutions.
- plot_Ts_diagram_matplotlib(connection_label, ax=None, save_dir=None, figsize=None, xlim=None, ylim=None, diagram=None, strict=False)[source]¶
Plot the process into a Ts diagram.
- Parameters:
connection_label (str) – Label of any connection of the process to plot.
ax (matplotlib.axes.Axes, optional) – Axes to plot into.
save_dir (str, optional) – Directory to save the figure to.
figsize (tuple, optional) – Figure size for a new figure.
xlim (tuple, optional) – x axis limits.
ylim (tuple, optional) – y axis limits.
diagram (fluprodia.FluidPropertyDiagram, optional) – Pre-configured diagram to use instead of the one from
create_diagram().strict (bool, optional) – Raise instead of falling back to a state point only plot, if no diagram is available for the fluid, default False.
- Returns:
tuple – matplotlib figure and axes.
- plot_logph_diagram_matplotlib(connection_label, ax=None, save_dir=None, figsize=None, xlim=None, ylim=None, diagram=None, strict=False)[source]¶
Plot the process into a logph diagram.
- Parameters:
connection_label (str) – Label of any connection of the process to plot.
ax (matplotlib.axes.Axes, optional) – Axes to plot into.
save_dir (str, optional) – Directory to save the figure to.
figsize (tuple, optional) – Figure size for a new figure.
xlim (tuple, optional) – x axis limits.
ylim (tuple, optional) – y axis limits.
diagram (fluprodia.FluidPropertyDiagram, optional) – Pre-configured diagram to use instead of the one from
create_diagram().strict (bool, optional) – Raise instead of falling back to a state point only plot, if no diagram is available for the fluid, default False.
- Returns:
tuple – matplotlib figure and axes.
- register_diagram(fluid_name, diagram)[source]¶
Register a pre-configured fluid property diagram for a fluid.
A registered diagram replaces an existing cached diagram, which was created earlier. This is useful in interactive sessions, where a diagram can be configured once and reused for all subsequent plots.
- Parameters:
fluid_name (str) – Name of the (pure) fluid.
diagram (fluprodia.FluidPropertyDiagram) – Diagram with calculated isolines.
- run_exergy_analysis(Tamb, pamb, E_F, E_P, E_L=None)[source]¶
Run an exergy analysis via exerpy and cache the result.
- Parameters:
Tamb (float) – Ambient temperature in °C.
pamb (float) – Ambient pressure in bar.
E_F (dict) – Fuel exergy definition, e.g.
{'inputs': [...], 'outputs': [...]}.E_P (dict) – Product exergy definition.
E_L (dict, optional) – Loss exergy definition.
- Returns:
exerpy.ExergyAnalysis
- sensitivity_analysis(param_dict=None, result_param_list=None, mode='design', postproc_func=None) DataFrame[source]¶
- Parameters:
param_dict (dict) – A dictionary of parameter names and lists of values to be used in the sensitivity analysis. All lists must have the same length, which determines the number of simulations to be run.
result_param_list (list, optional) – Names of model parameters (from
_parameter_lookup()) to record after each simulation step.mode (str, optional) –
'design'or'offdesign'. Default is'design'.postproc_func (callable, optional) – A function
postproc_func(model) -> dict | Nonecalled after each successful solve. Use it to run any postprocessing - e.g. an exergy analysis, custom KPI calculation, or result export. The returned dict (if any) is merged into the result row as additional columns alongsideresult_param_list. If the function returnsNoneno extra columns are added.Example - running an exergy analysis after each offdesign solve:
def run_exergy(model): model.run_exergy_analysis(Tamb, pamb, E_F, E_P) hp.sensitivity_analysis( param_dict={"T_geo": [8, 9, 10, 11]}, result_param_list=["epsilon"], mode="offdesign", postproc_func=run_exergy, )
- Returns:
pandas.core.frame.DataFrame – DataFrame with input parameter columns and result columns.
- supports_fluid_diagram(connection_label)[source]¶
Check whether a fluid property diagram is available for the fluid of a connection.
This is the case, if the fluid of the connection is a pure fluid (fluprodia does not support mixtures) and the diagram creation via
create_diagram()succeeds (or a diagram was registered withregister_diagram()).- Parameters:
connection_label (str) – Label of the connection.
- Returns:
bool