Skip to content

CAPE-OPEN Unit Operation

Hosts an external CAPE-OPEN unit operation (a COM component registered on Windows) in the flowsheet. It creates the COM object, mirrors its ports as flowsheet connectors and its parameters as a local collection, connects the attached streams to the ports, calls the component's Calculate, and saves the component state through its persistence interfaces. CAPE-OPEN unit operations run only on Windows.

DWSIM.UnitOperations.UnitOperations.CapeOpenUO
Assembly DWSIM.UnitOperations.dll · Object ← BaseClass ← UnitOpBaseClass ← CapeOpenUO

At a glance

CAPE-OPEN Unit Operation in the example flowsheet

Port Index Connected in the example
Inlet, material 0 Feed
Outlet, material 0 Product
Outlet, energy 1 Heat

Example

This code runs on every build of this site, and the output below is what it printed.

# The unit operation is a COM component registered on the machine, here the HeaterCooler
# of the free COCO simulator. The desktop application asks the user which one to host;
# a script answers through SelectorOverride before the object is created.
registered = CapeOpenUO.SearchRegisteredUnitOperations(False)
info = next(i for i in registered if i.TypeName == "COCO_COUS.HeaterCooler.1")
CapeOpenUO.SelectorOverride = System.Func[CapeOpenUnitOpInfo](lambda: info)

fs = (Flowsheet.Create("CapeOpenUOExample")
      .WithCompounds("N-hexane", "N-heptane")
      .WithPropertyPackage(PropertyPackages.PengRobinson))

feed = (fs.AddMaterialStream("Feed")
        .At(Q.Celsius(25.0), Q.Bar(2.0))
        .SetCompoundMassFlow("N-hexane", 0.9)        # kg/s
        .SetCompoundMassFlow("N-heptane", 0.6))
product = fs.AddMaterialStream("Product")
heat = fs.AddEnergyStream("Heat")

uo = fs.AddUnitOperation(ObjectType.CapeOpenUO, "CO-1")
CapeOpenUO.SelectorOverride = None           # back to the default selector

# The ports are the ones the component declares, in its own order
uo.ConnectFeed(feed, 0).ConnectProduct(product, 0)
uo.ConnectEnergyProduct(heat, 1)

# The parameters too; inputs are set by name with SetPropertyValue
co = uo.Object.__implementation__
co.SetPropertyValue("Heat duty", 135840.0)   # W
co.SetPropertyValue("Pressure drop", 0.0)    # Pa

go = co.GraphicObject
print(f"Component      = {info.Name} {info.Version} ({info.TypeName})")
print("Inlets         = " + ", ".join(f"{c.ConnectorName} ({c.Type})" for c in go.InputConnectors))
print("Outlets        = " + ", ".join(f"{c.ConnectorName} ({c.Type})" for c in go.OutputConnectors))
for name in ("Type", "Heat duty", "Pressure drop", "Thermo Version"):
    print(f"{name:<15}= {co.GetPropertyValue(name)}")

fs.AutoLayout()
fs.Solve()
p = product.Object
print(f"Product        = {p.GetTemperature() - 273.15:.1f} C, vapor fraction {p.Phases[2].Properties.molarfraction or 0.0:.3f}")
# the component writes the duty on its outlet energy port with the CAPE-OPEN sign
print(f"Heat stream    = {heat.Object.EnergyFlow:.1f} kW")

Output

Component      = HeaterCooler 3.8.0.0 (COCO_COUS.HeaterCooler.1)
Inlets         = Inlet (ConIn)
Outlets        = Outlet (ConOut), Heat (ConEn)
Type           = Heat duty
Heat duty      = 135840
Pressure drop  = 0
Thermo Version = 1.0
Product        = 65.0 C, vapor fraction 0.000
Heat stream    = -135.8 kW

DWSIM 10.2.11.0, generated 2026-10-08.

Properties

IDs accepted by GetPropertyValue, SetPropertyValue, the sensitivity analysis, the optimizer, the Adjust block and dynamic events. Units are SI; pass another unit system to GetPropertyValue to get them converted.

ID Name Unit (SI) Input
Type Component Type yes
Outlet temperature yes
Heat duty yes
Pressure drop yes
Thermo Version yes

Learn more

API members

Public members declared by this class. Inherited members are documented on the base classes.

Constructors

CapeOpenUO(): Initializes a new default instance.

Initializes a new default instance.

public CapeOpenUO()
Public Sub New()

CapeOpenUO(string, string): Initializes a new instance with a name and description.

Initializes a new instance with a name and description.

Parameter Type Description
name String
desc String
public CapeOpenUO(string name, string desc)
Public Sub New(name As String, desc As String)

CapeOpenUO(string, string, IGraphicObject, bool): Initializes a new instance with a name, description, graphic object, and optional ChemSep mode.

Initializes a new instance with a name, description, graphic object, and optional ChemSep mode.

Parameter Type Description
name String
description String
gobj IGraphicObject
chemsep Boolean
public CapeOpenUO(string name, string description, IGraphicObject gobj, bool chemsep = false)
Public Sub New(name As String, description As String, gobj As IGraphicObject, chemsep As Boolean = False)

Properties

ChemSepFinderOverride: Lets a host that is not WinForms supply ChemSep's CAPE-OPEN unit operation (from SearchRegisteredUnitOperations) for...

Lets a host that is not WinForms supply ChemSep's CAPE-OPEN unit operation (from SearchRegisteredUnitOperations) for the ChemSep-column shortcut. Leave it Nothing (the default) to keep using the built-in WinForms AddChemSepColumn path.

public static Func<CapeOpenUnitOpInfo> ChemSepFinderOverride { get; set; }
Public Shared Property ChemSepFinderOverride As Func(Of CapeOpenUnitOpInfo)

EmbeddedImageData: Gets or sets Base-64 encoded embedded image data for a custom icon.

Gets or sets Base-64 encoded embedded image data for a custom icon.

public string EmbeddedImageData { get; set; }
Public Property EmbeddedImageData As String

HasPropertiesForDynamicMode: Gets a value indicating this unit operation has no dedicated dynamic-mode properties.

Gets a value indicating this unit operation has no dedicated dynamic-mode properties.

public override bool HasPropertiesForDynamicMode { get; }
Public Overrides ReadOnly Property HasPropertiesForDynamicMode As Boolean

MobileCompatible: Gets a value indicating whether this unit operation is compatible with mobile interfaces.

Gets a value indicating whether this unit operation is compatible with mobile interfaces.

public override bool MobileCompatible { get; }
Public Overrides ReadOnly Property MobileCompatible As Boolean

ObjectClass: Gets or sets the simulation object class category (CAPEOPEN).

Gets or sets the simulation object class category (CAPEOPEN).

public override SimulationObjectClass ObjectClass { get; set; }
Public Overrides Property ObjectClass As SimulationObjectClass

ProductAssembly: Gets the file location (server path) registered by the COM unit operation, or the name of this assembly if none is...

Gets the file location (server path) registered by the COM unit operation, or the name of this assembly if none is selected.

public override string ProductAssembly { get; }
Public Overrides ReadOnly Property ProductAssembly As String

ProductAuthor: Gets the product author reported by the COM unit operation.

Gets the product author reported by the COM unit operation.

public override string ProductAuthor { get; }
Public Overrides ReadOnly Property ProductAuthor As String

ProductContactInfo: Gets the help URL registered by the COM unit operation, or the DWSIM website if none is selected.

Gets the help URL registered by the COM unit operation, or the DWSIM website if none is selected.

public override string ProductContactInfo { get; }
Public Overrides ReadOnly Property ProductContactInfo As String

ProductDescription: Gets the product description reported by the COM unit operation.

Gets the product description reported by the COM unit operation.

public override string ProductDescription { get; }
Public Overrides ReadOnly Property ProductDescription As String

ProductName: Gets the product name reported by the COM unit operation.

Gets the product name reported by the COM unit operation.

public override string ProductName { get; }
Public Overrides ReadOnly Property ProductName As String

ProductPage: Gets the vendor URL registered by the COM unit operation, or the DWSIM website if none is selected.

Gets the vendor URL registered by the COM unit operation, or the DWSIM website if none is selected.

public override string ProductPage { get; }
Public Overrides ReadOnly Property ProductPage As String

ProductVersion: Gets the component version registered by the COM unit operation, or the version of this assembly if none is selected.

Gets the component version registered by the COM unit operation, or the version of this assembly if none is selected.

public override string ProductVersion { get; }
Public Overrides ReadOnly Property ProductVersion As String

ReactionSetID: Gets or sets the ID of the reaction set used by the CAPE-OPEN unit operation.

Gets or sets the ID of the reaction set used by the CAPE-OPEN unit operation.

public string ReactionSetID { get; set; }
Public Property ReactionSetID As String

ReactionSetName: Gets or sets the name of the reaction set used by the CAPE-OPEN unit operation.

Gets or sets the name of the reaction set used by the CAPE-OPEN unit operation.

public string ReactionSetName { get; set; }
Public Property ReactionSetName As String

RecalcOutputStreams: Gets or sets whether output streams are recalculated (flashed) after the CAPE-OPEN calculation.

Gets or sets whether output streams are recalculated (flashed) after the CAPE-OPEN calculation.

public bool RecalcOutputStreams { get; set; }
Public Property RecalcOutputStreams As Boolean

SelectorOverride: Lets a host that is not WinForms supply the CAPE-OPEN unit operation to instantiate.

Lets a host that is not WinForms supply the CAPE-OPEN unit operation to instantiate. Leave it Nothing (the default) to keep using the built-in WinForms selector.

public static Func<CapeOpenUnitOpInfo> SelectorOverride { get; set; }
Public Shared Property SelectorOverride As Func(Of CapeOpenUnitOpInfo)

SupportsDynamicMode: Gets a value indicating this unit operation supports dynamic simulation mode.

Gets a value indicating this unit operation supports dynamic simulation mode.

public override bool SupportsDynamicMode { get; }
Public Overrides ReadOnly Property SupportsDynamicMode As Boolean

SupportsRestoreStateAfterError: Gets a value indicating this unit operation does not support restoring state after an error.

Gets a value indicating this unit operation does not support restoring state after an error.

public override bool SupportsRestoreStateAfterError { get; }
Public Overrides ReadOnly Property SupportsRestoreStateAfterError As Boolean

UseEmbeddedImage: Gets or sets whether the embedded image is used as the graphic object icon.

Gets or sets whether the embedded image is used as the graphic object icon.

public bool UseEmbeddedImage { get; set; }
Public Property UseEmbeddedImage As Boolean

Methods

Calculate(object): Calculates the CAPE-OPEN unit operation by marshalling data to/from the COM object.

Calculates the CAPE-OPEN unit operation by marshalling data to/from the COM object.

Parameter Type Description
args Object
public override void Calculate(object args = null)
Public Overrides Sub Calculate(args As Object = Nothing)

Clone2(): Creates a shallow clone of this CAPE-OPEN unit operation.

Creates a shallow clone of this CAPE-OPEN unit operation.

public CapeOpenUO Clone2()
Public Function Clone2() As CapeOpenUO

CloneXML(): Creates a deep copy via XML serialization.

Creates a deep copy via XML serialization.

public override object CloneXML()
Public Overrides Function CloneXML() As Object

CloseEditForm(): Closes and disposes the editing form.

Closes and disposes the editing form.

public override void CloseEditForm()
Public Overrides Sub CloseEditForm()

CreateConnectors(): Creates the graphic connectors from _ports: one inlet connector on the left side for each inlet port and...

Creates the graphic connectors from _ports: one inlet connector on the left side for each inlet port and one outlet connector on the right side for each outlet port, of material or energy type and named after the port.

public void CreateConnectors()
Public Sub CreateConnectors()

DeCalculate(): Clears all calculated results.

Clears all calculated results.

public override void DeCalculate()
Public Overrides Sub DeCalculate()

DisconnectPorts(): Disconnects every connected port of the COM component.

Disconnects every connected port of the COM component. Called when the unit operation is disposed.

public void DisconnectPorts()
Public Sub DisconnectPorts()

DisplayEditForm(): Opens or activates the editing form.

Opens or activates the editing form.

public override void DisplayEditForm()
Public Overrides Sub DisplayEditForm()

Edit(): Opens the COM component's own editor (ICapeUtilities.Edit) after reconnecting its ports, then reads back the...

Opens the COM component's own editor (ICapeUtilities.Edit) after reconnecting its ports, then reads back the parameters and ports and rebuilds the graphic connectors.

public void Edit()
Public Sub Edit()

GetCAPEOPENObject(): Returns the underlying COM CAPE-OPEN unit operation object.

Returns the underlying COM CAPE-OPEN unit operation object.

public object GetCAPEOPENObject()
Public Function GetCAPEOPENObject() As Object

GetDisplayDescription(): Returns the localised display description.

Returns the localised display description.

public override string GetDisplayDescription()
Public Overrides Function GetDisplayDescription() As String

GetDisplayName(): Returns the localised display name.

Returns the localised display name.

public override string GetDisplayName()
Public Overrides Function GetDisplayName() As String

GetIconBitmapBytes(): Returns the icon bitmap as a byte array.

Returns the icon bitmap as a byte array.

public override byte[] GetIconBitmapBytes()
Public Overrides Function GetIconBitmapBytes() As Byte()

GetManagedUnitType(string): Loads a .NET assembly and returns the first non-abstract type in it that implements ICapeUnit.

Loads a .NET assembly and returns the first non-abstract type in it that implements ICapeUnit.

Parameter Type Description
filepath String Full path of the assembly file.
public Type GetManagedUnitType(string filepath)
Public Function GetManagedUnitType(filepath As String) As Type

GetParams(): Reads the parameters of the COM component and appends a local copy of each one (real, integer, boolean, option or...

Reads the parameters of the COM component and appends a local copy of each one (real, integer, boolean, option or array, with value, default, bounds and mode) to _params.

public void GetParams()
Public Sub GetParams()

GetPorts(): Reads the ports of the COM component and appends a local copy of each one (name, description, direction and type) to...

Reads the ports of the COM component and appends a local copy of each one (name, description, direction and type) to _ports.

public void GetPorts()
Public Sub GetPorts()

GetProperties(PropertyType): Returns an array of property identifiers for the specified property type.

Returns an array of property identifiers for the specified property type.

Parameter Type Description
proptype PropertyType
public override string[] GetProperties(PropertyType proptype)
Public Overrides Function GetProperties(proptype As PropertyType) As String()

GetPropertyUnit(string, IUnitsOfMeasure): Returns the unit string for the specified property.

Returns the unit string for the specified property.

Parameter Type Description
prop String
su IUnitsOfMeasure
public override string GetPropertyUnit(string prop, IUnitsOfMeasure su = null)
Public Overrides Function GetPropertyUnit(prop As String, su As IUnitsOfMeasure = Nothing) As String

GetPropertyValue(string, IUnitsOfMeasure): Returns the value of the specified property.

Returns the value of the specified property.

Parameter Type Description
prop String
su IUnitsOfMeasure
public override object GetPropertyValue(string prop, IUnitsOfMeasure su = null)
Public Overrides Function GetPropertyValue(prop As String, su As IUnitsOfMeasure = Nothing) As Object

GetReport(IUnitsOfMeasure, CultureInfo, string): Generates a plain-text report of the CAPE-OPEN unit operation results.

Generates a plain-text report of the CAPE-OPEN unit operation results.

Parameter Type Description
su IUnitsOfMeasure
ci CultureInfo
numberformat String
public override string GetReport(IUnitsOfMeasure su, CultureInfo ci, string numberformat)
Public Overrides Function GetReport(su As IUnitsOfMeasure, ci As CultureInfo, numberformat As String) As String

Init(): Initializes the COM component (ICapeUtilities.Initialize), gives it the flowsheet as simulation context and sets its...

Initializes the COM component (ICapeUtilities.Initialize), gives it the flowsheet as simulation context and sets its name and description from the graphic object.

public void Init()
Public Sub Init()

InitNew(): Calls IPersistStreamInit.InitNew on the COM component, if it implements it, so it starts from a fresh state.

Calls IPersistStreamInit.InitNew on the COM component, if it implements it, so it starts from a fresh state. Errors are ignored.

public void InitNew()
Public Sub InitNew()

InstantiateSelected(): Instantiates the COM object for the currently selected unit operation, reading its ports and parameters.

Instantiates the COM object for the currently selected unit operation, reading its ports and parameters. Public so a host can re-run it after changing the selection.

public void InstantiateSelected()
Public Sub InstantiateSelected()

isCOUnit(Type): Returns whether the given type implements the CAPE-OPEN ICapeUnit interface.

Returns whether the given type implements the CAPE-OPEN ICapeUnit interface.

Parameter Type Description
t Type The type to test.
public object isCOUnit(Type t)
Public Function isCOUnit(t As Type) As Object

LoadData(List<XElement>): Restores the CAPE-OPEN unit operation state from XML, including persisted COM data.

Restores the CAPE-OPEN unit operation state from XML, including persisted COM data.

Parameter Type Description
data List<XElement>
public override bool LoadData(List<XElement> data)
Public Overrides Function LoadData(data As List(Of XElement)) As Boolean

PerformPostCalcValidation(): Performs post-calculation validation on the CAPE-OPEN unit operation.

Performs post-calculation validation on the CAPE-OPEN unit operation.

public override void PerformPostCalcValidation()
Public Overrides Sub PerformPostCalcValidation()

PersistLoad(StreamingContext): Restores the state of the COM component from the persisted data, through its IPersistStreamInit or IPersistStream...

Restores the state of the COM component from the persisted data, through its IPersistStreamInit or IPersistStream interface, creating the COM object first if needed. Then reads the parameters from the component or, when the component could not load its own data, writes the stored parameter values back to it.

Parameter Type Description
context StreamingContext Streaming context. Not used.
public void PersistLoad(StreamingContext context)
Public Sub PersistLoad(context As StreamingContext)

PersistSave(StreamingContext): Asks the COM component to save its state through its IPersistStreamInit or IPersistStream interface and keeps the...

Asks the COM component to save its state through its IPersistStreamInit or IPersistStream interface and keeps the bytes for SaveData. Components without either interface save nothing.

Parameter Type Description
context StreamingContext Streaming context. Not used.
public void PersistSave(StreamingContext context)
Public Sub PersistSave(context As StreamingContext)

RestoreParams(): Writes the values stored in _params back to the parameters of the COM component, skipping output parameters.

Writes the values stored in _params back to the parameters of the COM component, skipping output parameters. A value the component rejects produces a flowsheet warning.

public void RestoreParams()
Public Sub RestoreParams()

RestorePorts(): Reconnects the ports of the COM component to the flowsheet objects recorded in _ports, disconnecting any...

Reconnects the ports of the COM component to the flowsheet objects recorded in _ports, disconnecting any object a port is already connected to first.

public void RestorePorts()
Public Sub RestorePorts()

RunDynamicModel(): Performs the dynamic-mode calculation by calling the CAPE-OPEN Calculate method.

Performs the dynamic-mode calculation by calling the CAPE-OPEN Calculate method.

public override void RunDynamicModel()
Public Overrides Sub RunDynamicModel()

SaveData(): Serializes the CAPE-OPEN unit operation state to XML, including persisted COM data.

Serializes the CAPE-OPEN unit operation state to XML, including persisted COM data.

public override List<XElement> SaveData()
Public Overrides Function SaveData() As List(Of XElement)

SaveTempData(): Saves the current UO data in a temporary placeholder, so it can be loaded by another thread which will reinstantiate...

Saves the current UO data in a temporary placeholder, so it can be loaded by another thread which will reinstantiate the COM object because of interop restrictions.

public void SaveTempData()
Public Sub SaveTempData()

SearchRegisteredUnitOperations(bool): Scans HKCR and HKCU for COM classes registered under the CAPE-OPEN unit-operation category and returns their metadata.

Scans HKCR and HKCU for COM classes registered under the CAPE-OPEN unit-operation category and returns their metadata. Lives here rather than on the WinForms selector so hosts without WinForms can offer their own picker.

Parameter Type Description
chemseponly Boolean
public static List<CapeOpenUnitOpInfo> SearchRegisteredUnitOperations(bool chemseponly)
Public Shared Function SearchRegisteredUnitOperations(chemseponly As Boolean) As List(Of CapeOpenUnitOpInfo)

SetPropertyValue(string, object, IUnitsOfMeasure): Sets the value of the specified property.

Sets the value of the specified property.

Parameter Type Description
prop String
propval Object
su IUnitsOfMeasure
public override bool SetPropertyValue(string prop, object propval, IUnitsOfMeasure su = null)
Public Overrides Function SetPropertyValue(prop As String, propval As Object, su As IUnitsOfMeasure = Nothing) As Boolean

ShowForm(): Selects the CAPE-OPEN unit operation to host, through SelectorOverride when set or the WinForms...

Selects the CAPE-OPEN unit operation to host, through SelectorOverride when set or the WinForms selector dialog otherwise. A ChemSep selection also resizes the graphic object.

public void ShowForm()
Public Sub ShowForm()

Terminate(): Calls ICapeUtilities.Terminate on the COM component, if one exists.

Calls ICapeUtilities.Terminate on the COM component, if one exists.

public void Terminate()
Public Sub Terminate()

UpdateConnectorPositions(): Stores the connector offsets relative to the graphic object position in its AdditionalInfo, so the connectors keep...

Stores the connector offsets relative to the graphic object position in its AdditionalInfo, so the connectors keep their places when the object is drawn or moved.

public void UpdateConnectorPositions()
Public Sub UpdateConnectorPositions()

UpdateConnectors(): Rebuilds the graphic connectors from the current ports of the COM component (for example after its editor added or...

Rebuilds the graphic connectors from the current ports of the COM component (for example after its editor added or removed ports): disconnects all existing flowsheet connections, recreates the connectors and reconnects the streams each port reports as connected.

public void UpdateConnectors()
Public Sub UpdateConnectors()

UpdateConnectors2(): Used after loading a flowsheet: updates the type, position and name of the existing graphic connectors from the...

Used after loading a flowsheet: updates the type, position and name of the existing graphic connectors from the ports of the COM component and connects each port to the stream attached to its connector.

public void UpdateConnectors2()
Public Sub UpdateConnectors2()

UpdateEditForm(): Refreshes the editing form with updated data.

Refreshes the editing form with updated data.

public override void UpdateEditForm()
Public Overrides Sub UpdateEditForm()

UpdateParams(): Copies the current parameter values of the COM component into _params, rebuilding the local collection...

Copies the current parameter values of the COM component into _params, rebuilding the local collection first when the number of parameters changed.

public void UpdateParams()
Public Sub UpdateParams()

UpdatePorts(): Rebuilds _ports from the current ports of the COM component, including the flowsheet object each port is...

Rebuilds _ports from the current ports of the COM component, including the flowsheet object each port is connected to.

public void UpdatePorts()
Public Sub UpdatePorts()

UpdatePortsFromConnectors(): Synchronizes _ports with the graphic connectors (disconnects ports whose connector is free, connects ports...

Synchronizes _ports with the graphic connectors (disconnects ports whose connector is free, connects ports whose connector has a stream attached) and then applies the result to the COM component with RestorePorts.

public void UpdatePortsFromConnectors()
Public Sub UpdatePortsFromConnectors()

Validate(): Validates the CAPE-OPEN unit operation configuration.

Validates the CAPE-OPEN unit operation configuration.

public override void Validate()
Public Overrides Sub Validate()

Fields

_params: Local copy of the parameters of the COM component (real, integer, boolean, option and array parameters), read from...

Local copy of the parameters of the COM component (real, integer, boolean, option and array parameters), read from the component and written back to it. Not serialized.

public List<ICapeParameter> _params
Public _params As List(Of ICapeParameter)

_ports: Local copy of the ports of the COM component (name, description, direction, type and connected object), used to...

Local copy of the ports of the COM component (name, description, direction, type and connected object), used to build the flowsheet connectors and to reconnect the ports.

public List<ICapeUnitPort> _ports
Public _ports As List(Of ICapeUnitPort)

_seluo: Registry information of the hosted CAPE-OPEN unit operation (name, description, ProgID, version, vendor and...

Registry information of the hosted CAPE-OPEN unit operation (name, description, ProgID, version, vendor and location), chosen by the user or by a host selector. Used to recreate the COM object on load.

public CapeOpenUnitOpInfo _seluo
Public _seluo As CapeOpenUnitOpInfo

f: The classic (WinForms) editor window open for this unit operation, if any.

The classic (WinForms) editor window open for this unit operation, if any. Not saved with the flowsheet.

public object f
Public f As Object