exerpy.parser

exerpy.parser.from_ebsilon

Ebsilon Model Parser

This module defines the EbsilonModelParser class, which is used to parse Ebsilon models, simulate them, extract data about components and connections, and write the data to a JSON file.

class exerpy.parser.from_ebsilon.ebsilon_parser.EbsilonModelParser(model_path: str, split_physical_exergy: bool = True)[source]

Bases: object

A class to parse Ebsilon models, simulate them, extract data, and write to JSON.

get_sorted_data() dict[str, Any][source]

Sorts the component and connection data alphabetically by name.

Returns:

dict – A dictionary containing sorted ‘components’, ‘connections’, and ambient conditions data.

initialize_model()[source]

Initializes the Ebsilon application and opens the specified model.

Raises:
  • FileNotFoundError – If the model file cannot be opened.

  • RuntimeError – If the COM server cannot be started or ObjectCaster cannot be obtained.

parse_component(obj: Any)[source]

Parses data from a component, including its type and various properties.

Parameters:

obj – The Ebsilon component object to parse.

parse_connection(obj: Any)[source]

Parses the connections (pipes) associated with a component.

Parameters:

obj – The Ebsilon component object whose connections are to be parsed.

parse_model()[source]

Parses all objects in the Ebsilon model to extract component and connection data.

Raises:
  • ValueError – If ambient conditions are not set.

  • Exception – If model parsing fails.

simulate_model()[source]

Simulates the Ebsilon model and logs any calculation errors.

Raises:

Exception – If model simulation fails.

write_to_json(output_path: str)[source]

Writes the parsed and sorted data to a JSON file.

Parameters:

output_path (str) – Path where the JSON file will be saved.

Raises:

Exception – If writing to JSON fails.

exerpy.parser.from_ebsilon.ebsilon_parser.run_ebsilon(model_path: str, output_dir: str | None = None, split_physical_exergy: bool = True) dict[str, Any][source]

Main function to process the Ebsilon model and return parsed data. Optionally writes the parsed data to a JSON file.

Parameters:
  • model_path (str) – Path to the Ebsilon model file.

  • output_dir (str) – Optional path where the parsed data should be saved as a JSON file.

  • split_physical_exergy (bool) – Flag to split physical exergy into thermal and mechanical components.

Returns:

dict – Parsed data in dictionary format.

Raises:
  • FileNotFoundError – If the model file is not found at the specified path.

  • RuntimeError – For any error during model initialization, simulation, parsing, or writing.

exerpy.parser.from_aspen

class exerpy.parser.from_aspen.aspen_parser.AspenModelParser(model_path, split_physical_exergy=True)[source]

Bases: object

A class to parse Aspen Plus models, simulate them, extract data, and write to JSON.

assign_combustion_chamber_connectors(block_name, aspen, connections_data)[source]

Assign connectors for a combustion chamber (RStoic), based on stream types (air, fuel, etc.).

assign_connectors(component_data, block_name)[source]

Assigns connectors to streams for each component based on its type.

assign_generic_connectors(block_name, component_type, aspen, connections_data, connector_mappings)[source]

Generic function for components with predefined connector mappings.

assign_mixer_connectors(block_name, aspen, connections_data)[source]

Assign connectors for a Mixer by examining connected streams and their source/target components.

assign_splitter_connectors(block_name, aspen, connections_data)[source]

Assign connectors for a Splitter (FSplit) by examining connected streams and their source/target components. The inlet stream is assigned ‘target_connector’ = 0. The outlet streams are assigned ‘source_connector’ numbers starting from 0.

assign_turbine_connectors(block_name, aspen, connections_data)[source]

Assign connectors for a Turbine (Compr with MODEL_TYPE=TURBINE).

In Aspen, a gas turbine has up to one input and one output power connection: - F(IN): inlet gas flow → inlet connector 0 - P(OUT): outlet gas flow → outlet connector 0 - WS(OUT): power output → outlet connector 1 - WS(IN): direction depends on the sign of the Aspen power value:

  • positive → power leaves the turbine → outlet connector 2 (source/target swapped)

  • negative → power enters the turbine → inlet connector 1 (kept as-is)

The _aspen_power_sign field (set during parse_streams) carries the sign of the raw Aspen POWER_OUT value. energy_flow is always stored as a positive value because ExerPy does not work with negative values.

get_sorted_data()[source]

Sorts the component and connection data alphabetically by name.

Returns:

dict – A dictionary containing sorted ‘components’, ‘connections’, and ambient conditions data.

group_component(component_data, component_name)[source]

Group the component based on its type into the correct group within components_data.

Parameters: - component_data: The dictionary of component attributes. - component_name: The name of the component.

initialize_model()[source]

Initializes the Aspen Plus application and opens the specified model.

parse_ambient_conditions()[source]

Parses the ambient conditions from the Aspen model and stores them as class attributes. Raises an error if Tamb or pamb are not found or are set to None.

parse_blocks()[source]

Parses the blocks (components) in the Aspen model and ensures that all components, including motors created from pumps, are properly grouped.

parse_model()[source]

Parses the components and connections from the Aspen model.

parse_streams()[source]

Parses the streams (connections) in the Aspen model.

write_to_json(output_path)[source]

Writes the parsed and sorted data to a JSON file.

Parameters:

output_path (str) – Path where the JSON file will be saved.

exerpy.parser.from_aspen.aspen_parser.run_aspen(model_path, output_dir=None, split_physical_exergy=True)[source]

Main function to process the Aspen model and return parsed data. Optionally writes the parsed data to a JSON file.

Parameters:
  • model_path (str) – Path to the Aspen model file.

  • output_dir (str) – Optional path where the parsed data should be saved as a JSON file.

  • split_physical_exergy (bool) – Flag to split physical exergy into thermal and mechanical components.

Returns:

dict – Parsed data in dictionary format.