pysis.flowsheet

class pysis.flowsheet.Component(COMObject)

Bases: object

Component class that represents a component in the HYSYS simulation.

Args:

COMObject (COMObject): COMObject of the HYSYS component.

Attributes:

COMObject (COMObject): The COMObject of the HYSYS component. name (str): The name of the component. formula (str): The chemical formula of the component. MW (float): The molecular weight of the component.

Methods:

get_CAS: Gets the CAS number of the component. get_Pc: Gets the critical pressure of the component. get_Tc: Gets the critical temperature of the component. get_bp: Gets the boiling point of the component.

get_Antoine_parameters() tuple

Gets the Antoine parameters of the component. The equation is as follows: ln(P[kPa]) = a + b/(T[K] + c) + d*ln(T[K]) + e*T^f

Returns:

tuple: A tuple containing the Antoine parameters. It has a lot of them, tho, from a to j, even though the equation only uses until f.

get_CAS() str

Gets the CAS number of the component.

Returns:

str: The CAS number of the component.

get_Pc(units='Pa') float

Gets the critical pressure of the component.

Args:

units (str, optional): Units of the critical pressure. Defaults to “Pa”.

Returns:

float: The critical pressure of the component in the specified units.

get_Tc(units='K') float

Gets the critical temperature of the component.

Args:

units (str, optional): Units of the critical temperature. Defaults to “K”.

Returns:

float: The critical temperature of the component in the specified units.

get_bp(units='K') float

Gets the boiling point of the component.

Args:

units (str, optional): Units of the boiling point. Defaults to “K”.

Returns:

float: The boiling point of the component in the specified units.

class pysis.flowsheet.DistillationColumn(COMObject)

Bases: ProcessUnit

Child of process unit. It contains the COMObject, the ColumnFlowsheet, and the Main Tower. In some thermodynamic packages, it seems that the main tower is not available.

Args:

COMObject (COMObject): COMObject from HYSYS.

Attributes:

column_flowsheet (COMObject): COMObject of the column flowsheet. main_tower (COMObject): COMObject of the main tower.

Methods:

get_feedtrays: Gets the feedtrays of the column. set_feedtray: Sets the feedtray of the column. get_numberstages: Gets the number of stages of the column. set_numberstages: Sets the number of stages of the column. run: Runs the column subflowsheet. get_convergence: Checks the convergence of the column. get_specifications: Reads the specifications of the column. set_specifications: Sets the specifications of the column.

get_convergence() bool

Checks the convergence of the column. Careful, if you check after changing the input, such as the feedtray, it does not change from the previous state. Check always after a run()

Returns:

bool: True if the column is converged. False otherwise.

get_feedtrays() str

Gets the feedtray.

Returns:

str: Feedtray.

get_numberstages() int

Reads the number of stages.

Returns:

int: Number of stages.

get_specifications() dict

Reads the specifications of the column.

Returns:

dict: Dictionary with the specifications, if they are active, their goal value and their current value.

run(reset=False) None

Runs the column subflowsheet.

Args:

reset (bool, optional): If True, resets the column before running it. Defaults to False.

set_feedtray(stream: str, level: int) None

Sets the feedtray. If the solver is deactivated, you will not see the change. Also, it unconverges the column. Remember to run() it afterwards.

Args:

stream (string): Name of the stream that is already in the column. level (int): Level of the column where the feed is set.

set_numberstages(n: int) None

Sets the number of stages.

Args:

n (int): Number of stages.

set_specifications(spec: str, value: float, units: Optional[str] = None) None

Sets the goal value of a specification.

Args:

spec (str): Name of the specification. value (float): Value to which the goal value is set. units (str, optional): Units of the specification. Defaults to None.

class pysis.flowsheet.EnergyStream(COMObject)

Bases: ProcessStream

Reads the COMObject from the simulation. This class designs an energy stream.

Args:

COMObject (COMObject): Object from the HYSYS simulation.

Methods:

get_power: Gets the power of the energy stream. set_power: Sets the power of the energy stream.

get_power(units: str = 'kW') float

Reads the power/duty of the stream.

Args:

units (str, optional): Units of the power. Defaults to “kW”.

Returns:

float: Value of the power in the specified units.

set_power(value: float, units: str = 'kW') None

Sets the power of the energy stream.

Args:

value (float): Value to set. units (str, optional): Units of the power. Defaults to “kW”.

class pysis.flowsheet.FBController(COMObject)

Bases: ProcessUnit

Feedback controller.

Args:

COMObject (COMObject): COMObject from HYSYS

Attributes:

connections (dict): Dictionary with the manipulated variable, the controlled variable, and the setpoint.

Methods:

get_connections: Gets the connections of the controller.

get_OP() float

Gets the manipulated variable of the controller.

Returns:

float: Manipulated variable value in the specified units.

get_PV(units='') float

Gets the process variable of the controller.

Returns:

float: Process variable value in the specified units. units: Units of the process variable. When unitless, leave empty. Defaults to “”.

get_SP(units='') float

Gets the setpoint of the controller.

Returns:

float: Setpoint value in the specified units. units: Units of the setpoint. When unitless, leave empty. Defaults to “”.

set_OP(value: float) None

Sets the manipulated variable of the controller.

Args:

value (float): Value to set.

set_PV(value: float, units: str = '') None

Sets the process variable of the controller.

Args:

value (float): Value to set. units (str, optional): Units of the process variable. When unitless, leave empty. Defaults to “”.

set_SP(value: float, units: str = '') None

Sets the setpoint of the controller.

Args:

value (float): Value to set. units (str, optional): Units of the setpoint. When unitless, leave empty. Defaults to “”.

class pysis.flowsheet.HeatExchanger(COMObject)

Bases: ProcessUnit

Child of process unit. Includes the connections of the heat exchanger.

Args:

COMObject (COMObject): COMObject from HYSYS.

Attributes:

connections (dict): Dictionary with the feed, product, and energy stream.

Methods:

get_connections: Reads the connections of the process unit. get_pressuredrop: Reads the pressure drop of the unit. set_pressuredrop: Sets the pressure drop of the unit. get_deltaT: Reads the deltaT of the unit. set_deltaT: Sets the deltaT of the unit.

get_connections() dict

Reads the connections of the process unit.

Returns:

dict: Dictionary that contains the feed, product and energy stream attached to the process unit.

get_deltaT(units: str = 'K') float

Read the deltaT of the unit.

Args:

units (str, optional): Units of the output. Defaults to “K”.

Returns:

float: Value of the deltaT.

get_pressuredrop(units: str = 'bar') float

Reads the pressure drop of the unit.

Args:

units (str, optional): Units of the output. Defaults to “bar”.

Returns:

float: Value of the pressure drop in the specified units.

set_deltaT(value: float, units: str = 'K')

Sets the deltaT of the unit. Normally, it is recommended to directly set the temperature in the input and output stream. But you do you.

Args:

value (float): Value of the deltaT. If “empty”, it frees the degree of freedom. units (str, optional): Units of the deltaT. Defaults to “K”.

set_pressuredrop(value: float, units: str = 'bar') None

Sets the pressure drop of the unit.

Args:

value (float): Value to set. If “empty”, it frees the degree of freedom. units (str, optional): Units of the pressure drop. Defaults to “bar”.

class pysis.flowsheet.MaterialStream(COMObject)

Bases: ProcessStream

Reads the COMObjectfrom the simulation. This class designs a material stream, which has a series of properties.

Args:

COMObject (COMObject): HYSYS COMObject.

Methods:

get_properties: Gets the properties of the material stream. set_properties: Sets the properties of the material stream. get_pressure: Gets the pressure of the material stream. set_pressure: Sets the pressure of the material stream. get_temperature: Gets the temperature of the material stream. set_temperature: Sets the temperature of the material stream. get_massflow: Gets the mass flow of the material stream. set_massflow: Sets the mass flow of the material stream. get_molarflow: Gets the molar flow of the material stream. set_molarflow: Sets the molar flow of the material stream. get_compmassflow: Gets the component mass flow of the material stream. set_compmassflow: Sets the component mass flow of the material stream. get_compmolarflow: Gets the component molar flow of the material stream. set_compmolarflow: Sets the component molar flow of the material stream. get_compmassfraction: Gets the component mass fraction of the material stream. set_compmassfraction: Sets the component mass fraction of the material stream. get_compmolarfraction: Gets the component molar fraction of the material stream. set_compmolarfraction: Sets the component molar fraction of the material stream.

get_compmassflow(units: str = 'kg/h') dict

Reads the component mass flow.

Args:

units (str, optional): Units of the read output. Defaults to “kg/h”.

Returns:

dict: Dictionary with the species as the keys and the values as the read outputs.

get_compmassfraction() dict

Reads the component mass fraction.

Returns:

dict: A dictionary of the components and their values.

get_compmolarflow(units: str = 'kgmole/h') dict

Reads the component molar flow rate.

Args:

units (str, optional): Units of the read output. Defaults to “kgmole/h”.

Returns:

dict: A dictionary of all the components and their values in the chosen units.

get_compmolarfraction() dict

Reads the component molar fraction.

Returns:

dict: A dictionary of the components and their values.

get_massflow(units: str = 'kg/h') float

Reads the mass flow.

Args:

units (str, optional): Units of the read output. Defaults to “kg/h”.

Returns:

float: Value of the output in the specified units.

get_molarflow(units: str = 'kgmole/h') float

Reads the molar flow rate.

Args:

units (str, optional): Units of the read output. Defaults to “kgmole/h”.

Returns:

float: Value of the output in the specified units.

get_pressure(units: str = 'bar') float

Read the pressure.

Args:

units (str, optional): Units of the read output. Defaults to “bar”.

Returns:

float: Value of the output in the specified units in the process stream.

get_properties(property_dict: dict) dict

Specify a dictionary with different properties and the units you desire for them. Get the properties returned in another dict.

Args:

property_dict (dict): Dictionary of properties to get. The format is {“PropertyName”:”Units”}. For properties without units, i.e., component molar flow and component mass flow, an empty string can be used. The valid properties are “PRESSURE”, “TEMPERATURE”, “MASSFLOW”, “MOLARFLOW”, “COMPMASSFLOW”, “COMPMOLARFLOW”, “COMPMASSFRACTION”, “COMPMOLARFRACTION”

Returns:

dict: Dictionary where the keys are the properties, and the elements are the values read.

get_temperature(units: str = 'K') float

Reads the temperature.

Args:

units (str, optional): Units of the read output. Defaults to “K”.

Returns:

float: Value of the output in the specified units in the process stream.

set_compmassflow(values: dict, units: str = 'kg/h') None

Sets the component mass flow.

Args:

values (dict): The format of the dictionary shall be {“Component”: Value} units (str, optional): Unit of the component mass flow. Defaults to “kg/h”.

set_compmassfraction(values: dict) None

Sets the component mass fraction.

Args:

values (dict): The format of the dictionary shall be {“Component”: Value}

set_compmolarflow(values: dict, units: str = 'kgmole/h') None

Sets the component molar flow rate.

Args:

values (dict): The format of the dictionary shall be {“Component”: Value}. units (str, optional): Units of the component molar flow rate. Defaults to “kgmole/h”.

set_compmolarfraction(values: dict) None

Sets the component molar fraction.

Args:

values (dict): The format of the dictionary shall be {“Component”: Value}

set_massflow(value: float, units: str = 'kg/h') None

Sets the mass flow.

Args:

value (float): Value of the mass flow. units (str, optional): Units of the mass flow. Defaults to “kg/h”.

set_molarflow(value: float, units: str = 'kgmole/h') None

Sets the mole flow.

Args:

value (float): Value of the molar flow rate. units (str, optional): Units of the molar flow rate. Defaults to “kgmole/h”.

set_pressure(value: float, units: str = 'bar') None

Sets the pressure of the material stream.

Args:

value (float): Value to which the pressure is set. units (str, optional): Units of the pressure. Defaults to “bar”.

set_properties(property_dict: dict) None

Specify a dictionary with different properties and the units you desire for them. Set the properties returned in another dict. If some of the properties fail to be set (Normally because the property is not free), then it will stop and return an AssertionError. Any property after the one that fails is not set.

Args:

property_dict (dict): Each element of the dict must be a tuple with (value:float, units:string). For the case of component properties, such as compmassflow, the structure is: (value:dict, unit:string) where the value dictionary has the form {“ComponentName”: value}. The valid properties are “PRESSURE”, “TEMPERATURE”, “MASSFLOW”, “MOLARFLOW”, “COMPMASSFLOW”, “COMPMOLARFLOW”, “COMPMASSFRACTION”, “COMPMOLARFRACTION”

set_temperature(value: float, units: str = 'K') None

Sets the temperature of the material stream.

Args:

value (float): Value to which the temperature is set. units (str, optional): Units of the temperature. Defaults to “K”.

class pysis.flowsheet.PFR(COMObject)

Bases: ProcessUnit

Plug flow reactor.

Args:

COMObject (COMObject): COMObject from HYSYS

Attributes:

connections (dict): Dictionary with the feed, product, and energy stream. reactions (dict): Dictionary with the reactions and their values.

Methods:

get_connections: Gets the connections of the reactor. modify_feed: Modifies the feed streams. Adds or removes a bunch of feed streams. modify_product: States which is the product stream. It cannot be left empty as far as I know. get_reactionset: Reads the name of the reaction set. set_reactionset: Sets the reaction set to use. get_volume: Returns the volume of the unit. set_volume: Sets the volume of the unit. get_length: Returns the length of the unit. set_length: Sets the length of the unit. get_diameter: Returns the diameter of the unit. set_diameter: Sets the diameter of the unit. get_ntubes: Return the number of tubes. set_ntubes: Sets the number of tubes. get_voidfraction: Return the void fraction. set_voidfraction: Sets the void fraction. get_voidvolume: Return the void volume. set_voidvolume: Sets the void volume. get_properties: Specify a dictionary with different properties and the units you desire for them. Get the properties returned in another dict. set_properties: Specify a dictionary with different properties and the units you desire for them. Set the properties returned in another dict.

get_connections() dict

Get the connections of the reactor

Returns:

dict: Returns the connections

get_diameter(units: str = 'm') float

Returns the diameter of the unit

Args:

units (str, optional): Defaults to “m”.

Returns:

float: Diameter of the tubes in the specified units

get_length(units: str = 'm') float

Returns the length of the unit

Args:

units (str, optional): Defaults to “m”.

Returns:

float: Length of the tubes in the specified units

get_ntubes() int

Return the number of tubes

Returns:

float: Return the number of tubes

get_properties(property_dict: dict) dict

Get a number of properties. Allowed keys are VOLUME, REACTIONSET, TUBELENGTH, TUBEDIAMETER, NUMBEROFTUBES, VOIDFRACTION, and VOIDVOLUME.

Args:

prop_dict (dict): Dictionary of the desired property. Each element has to have a string indicating the units. For the properties that do not have a unit, i.e., VOIDFRACTION and NUMBEROFTUBES, leave the unit an empty string, or None.

Returns:

dict: Dictionary with the properties as keys and the value in the specified units as value

get_reactionset() str

Reads the name of the reaction set

Returns:

str: Name of the reaction set.

get_voidfraction() float

Return the void fraction

Returns:

float: Void fraction

get_voidvolume(units='m3') float

Return the void volume

Args:

units (str, optional): Defaults to “m3”.

Returns:

float: Void volume in the specified units

get_volume(units: str = 'm3') float

Returns the volume of the unit

Args:

units (str, optional): Defaults to “m3”.

Returns:

float: Volume in the specified units

modify_feed(stream_group: list, movement: str) None

Modifies the feed streams. Adds or removes a bunch of feed streams

Args:

stream_group (list): List of names of the feed streams to modify movement (str): Either “Add” or “Remove”

modify_product(product_stream: COMObject) None

States which is the product stream. It cannot be left empty as far as I know.

Args:

product_stream (COMObject): COMObject which will be the product. You can get it from the flowsheet object, MatStreams dictionary, name of the stream, COMObject. For example: FS.MatStreams[“Stream1”].COMObject

set_diameter(value: float, units: str = 'm')

Set the diameter of the unit

Args:

value (float): Value to set units (str, optional): Defaults to “m”.

set_length(value: float, units: str = 'm') None

Set the length of the unit

Args:

value (float): Value to set units (str, optional): Defaults to “m”.

set_ntubes(value: int) None

Set the number of tubes

Args:

value (int): Value to set

set_properties(property_dict: dict) None

Set a number of properties. Allowed keys are VOLUME, REACTIONSET, TUBELENGTH, TUBEDIAMETER, NUMBEROFTUBES, VOIDFRACTION, and VOIDVOLUME.

Args:

prop_dict (dict): Dictionary of the desired property. Each element has to have a tuple indicating the value and units, i.e., (value,units). For the properties that do not have a unit, i.e., VOIDFRACTION and NUMBEROFTUBES, use an empty string or None as the unit.

set_reactionset(rxn_set: COMObject) None

Sets the reaction set to use

Args:

rxn_set (COMObject): COMObject of the reaction set. Tends to be in the flowsheet object, FS.ReactionSets dictionary. Use the name to access it. Consider that the reaction set must be of a compatible type

set_voidfraction(value: float) None

Set the void fraction

Args:

value (float): Value to set

set_voidvolume(value: float, units: str = 'm3') None

Sets the void volume

Args:

value (float): Value to set units (str, optional): Defaults to “m3”.

set_volume(value: float, units: str = 'm3') None

Sets the volume of the unit

Args:

value (float): Value to set units (str, optional): Defaults to “m3”.

class pysis.flowsheet.ProcessStream(COMObject)

Bases: object

Superclass of all streams in the process.

Initializes the process stream from a COMObject. Gets the connections and the name of the stream, as well as the COMObject.

Args:

COMObject (COMObject): COMObject of the HYSYS process stream.

Attributes:

COMObject (COMObject): The COMObject of the HYSYS process stream. connections (dict): A dictionary of the upstream and downstream connections. name (str): The name of the process stream.

get_connections() dict

Stores the connections of the process stream into a dictionary.

Returns:
dict: Returns a dictionary of the upstream and downstream connections.

The dictionary has two keys: “Upstream” and “Downstream”. The value for each key is a list of names of the connected operations.

class pysis.flowsheet.ProcessUnit(COMObject)

Bases: object

Superclass for all process units in the flowsheet. Contains the classification of the unit, the COMObject, and the name.

Args:

COMObject (COMObject): COMObject from HYSYS.

Attributes:

COMObject (COMObject): COMObject from HYSYS. classification (str): Classification of the process unit. name (str): Name of the process unit. type_name (str): Type name of the process unit. Used for creating new operations

class pysis.flowsheet.Simulation(path: str, version: Optional[float] = None)

Bases: object

Connects to a given simulation.

Args:

path (str): String with the raw path to the HYSYS file. If “Active”, chooses the open HYSYS flowsheet. version (float): HYSYS version number. For example, for HYSYS version 11, it will be 11.0.. Defaults to None.

Attributes:

app: HYSYS application object. case: HYSYS simulation case object. file_name (str): Name of the HYSYS file. thermo_package (str): Name of the thermodynamic package used in the simulation. comp_list (list): List of component names in the simulation. components (dict): Dictionary of components in the simulation, where keys are component names and values are COMObjects. Solver: HYSYS solver object. ReactionSets (dict): Dictionary of reaction sets in the simulation. Operations (dict): Dictionary of operations in the simulation. MatStreams (dict): Dictionary of material streams in the simulation. InputMatStreams (dict): Dictionary of input material streams in the simulation. OutputMatStreams (dict): Dictionary of output material streams in the simulation. EnerStreams (dict): Dictionary of energy streams in the simulation.

Methods:

update_flowsheet: Updates the references to the operations, material streams, and energy streams. set_visible: Sets the visibility of the flowsheet. solver_state: Sets if the solver is active or not. close: Closes the instance and the HYSYS connection. save: Saves the current state of the flowsheet. change_comp_list: Changes the active component list to that of the fluid_package specified. __str__: Returns the basic information of the flowsheet.

add_new_energy_stream(name: str, autoupdate: bool = True) None

Adds a new energy stream to the flowsheet.

Args:

name (str): Name of the new energy stream. autoupdate (bool, optional): If True, updates the flowsheet dicts after adding the energy stream. Defaults to True.

add_new_material_stream(name: str, autoupdate: bool = True) None

Adds a new material stream to the flowsheet.

Args:

name (str): Name of the new material stream. autoupdate (bool, optional): If True, updates the flowsheet dicts after adding the material stream. Defaults to True.

add_new_operation(name: str, type_name: str, autoupdate: bool = True) None

Adds a new operation to the flowsheet.

Args:

name (str): Name of the new operation. type_name (str): Type name of the new operation. These can be seen in self.Operations[i].type_name for i in self.Operations. autoupdate (bool, optional): If True, updates the flowsheet dicts after adding the operation. Defaults to True.

change_comp_list(fluid_package: COMObject) None

Changes the active component list to that of the fluid_package specified.

Args:

fluid_package (COMObject): The COMObject of the fluid package to change to. These can be seen in self.fluid_packages

close() None

Closes the instance and the HYSYS connection. If you do not close it, the task will remain and you will have to stop it from the task manager.

get_integrator_time() float

Gets the current time of the integrator. This is used for dynamic simulations.

Returns:

float: Current time of the integrator in seconds.

remove_energy_stream(name: str, autoupdate: bool = True) None

Removes an energy stream from the flowsheet.

Args:

name (str): Name of the energy stream to be removed. autoupdate (bool, optional): If True, updates the flowsheet dicts after removing the energy stream. Defaults to True.

remove_material_stream(name: str, autoupdate: bool = True) None

Removes a material stream from the flowsheet.

Args:

name (str): Name of the material stream to be removed. autoupdate (bool, optional): If True, updates the flowsheet dicts after removing the material stream. Defaults to True.

remove_operation(name: str, autoupdate: bool = True) None

Removes an operation from the flowsheet.

Args:

name (str): Name of the operation to be removed. autoupdate (bool, optional): If True, updates the flowsheet dicts after removing the operation. Defaults to True.

run_integrator() None

Runs the integrator of the solver. This is used for dynamic simulations.

run_integrator_for(time: float) None

Runs the integrator for a specified time. This is used for dynamic simulations.

Args:

time (float): Time to run the integrator for in seconds.

save() None

Saves the current state of the flowsheet.

This method saves the current state of the flowsheet by calling the Save method of the case object.

set_visible(visibility: int = 0) None

Sets the visibility of the flowsheet.

Args:

visibility (int, optional): If 1, it shows the flowsheet. If 0, it keeps it invisible. Defaults to 0.

solver_state(state: int = 1) None

Sets if the solver is active or not.

Args:

state (int, optional): If 1, the solver is active. If 0, the solver is not active. Defaults to 1.

stop_integrator() None

Stops the integrator of the solver. This is used for dynamic simulations.

update_flowsheet() None

Updates the references to the operations, mass streams, and energy streams in the flowsheet.

This method should be called in case you have created or deleted streams or units in the flowsheet. It updates the references to the operations, mass streams, and energy streams based on the changes made.

Returns:

None