Skip to content

Flowsheet Unit Operation

Represents a Flowsheet Unit Operation that embeds a complete sub-flowsheet as a single block in the parent flowsheet. Input and output streams are mapped to corresponding streams in the sub-flowsheet, enabling modular process simulation.

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

At a glance

Flowsheet Unit Operation in the example flowsheet

Port Index Connected in the example
Inlet, material 0 Feed
Inlet, material 1
Inlet, material 2
Inlet, material 3
Inlet, material 4
Inlet, material 5
Inlet, material 6
Inlet, material 7
Inlet, material 8
Inlet, material 9
Outlet, material 0 Product
Outlet, material 1
Outlet, material 2
Outlet, material 3
Outlet, material 4
Outlet, material 5
Outlet, material 6
Outlet, material 7
Outlet, material 8
Outlet, material 9

Example

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

import os
import tempfile

# 1. The child flowsheet: heat to 80 C, then let down to 1 bar. Its feed is a
#    placeholder that the parent overwrites on every run.
child = (Flowsheet.Create("Child")
         .WithCompounds("N-hexane", "N-heptane")
         .WithPropertyPackage(PropertyPackages.PengRobinson))
c_in = (child.AddMaterialStream("In")
        .At(Q.Celsius(25.0), Q.Bar(2.0))
        .SetCompoundMolarFlow("N-hexane", 1.0)
        .SetCompoundMolarFlow("N-heptane", 1.0))
c_hot = child.AddMaterialStream("Hot")
c_out = child.AddMaterialStream("Out")
c_q = child.AddEnergyStream("Q")
(child.AddHeater("H-1").WithOutletTemperature(Q.Celsius(80.0))
 .ConnectFeed(c_in).ConnectProduct(c_hot).ConnectEnergyFeed(c_q, 1))
(child.AddValve("V-1").WithOutletPressure(Q.Bar(1.0))
 .ConnectFeed(c_hot).ConnectProduct(c_out))
child.AutoLayout()
child.Solve()
path = os.path.join(tempfile.gettempdir(), "dwsim_child_flowsheet.dwxmz")
child.Save(path)

# 2. The parent flowsheet runs the saved file as a unit operation
fs = (Flowsheet.Create("FlowsheetUOExample")
      .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")

uo = (fs.AddUnitOperation(ObjectType.FlowsheetUO, "FS-1")
      .ConnectFeed(feed, 0)
      .ConnectProduct(product, 0))
sub = uo.Object.__implementation__           # the Flowsheet unit operation
sub.SimulationFile = path
sub.InitializeInternalFlowsheet()            # loads the child flowsheet into sub.Fsheet

# Map the ports to child streams (by their internal names)
sub.InputConnections[0] = sub.Fsheet.GetFlowsheetSimulationObject("In").Name
sub.OutputConnections[0] = sub.Fsheet.GetFlowsheetSimulationObject("Out").Name

fs.AutoLayout()
fs.Solve()

p = product.Object
duty = sub.Fsheet.GetFlowsheetSimulationObject("Q").__implementation__.EnergyFlow
print(f"Product T         = {product.TemperatureK - 273.15:.2f} C")
print(f"Product P         = {product.PressurePa / 1e5:.3f} bar")
print(f"Vapor fraction    = {p.Phases[2].Properties.molarfraction:.4f}")
print(f"Child heater duty = {duty:.2f} kW")
print(f"Mass balance error= {sub.MassBalanceError:.2e} %")

Output

Product T         = 77.22 C
Product P         = 1.000 bar
Vapor fraction    = 0.0213
Child heater duty = 190.09 kW
Mass balance error= 0.00e+00 %

DWSIM 10.2.11.0, generated 2026-10-08.

Learn more

API members

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

Constructors

Flowsheet(): Initializes a new default instance.

Initializes a new default instance.

public Flowsheet()
Public Sub New()

Flowsheet(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
description String
public Flowsheet(string name, string description)
Public Sub New(name As String, description As String)

Properties

CompoundMappings: Gets or sets the dictionary mapping parent-flowsheet compound names to sub-flowsheet compound names.

Gets or sets the dictionary mapping parent-flowsheet compound names to sub-flowsheet compound names.

public Dictionary<string, string> CompoundMappings { get; set; }
Public Property CompoundMappings As Dictionary(Of String, String)

EmbeddedFileName: Gets or sets the embedded file name when the sub-flowsheet is embedded.

Gets or sets the embedded file name when the sub-flowsheet is embedded.

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

FileIsEmbedded: Gets or sets whether the sub-flowsheet file is embedded in the parent simulation file.

Gets or sets whether the sub-flowsheet file is embedded in the parent simulation file.

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

Initialized: Gets or sets whether the sub-flowsheet has been loaded into Fsheet.

Gets or sets whether the sub-flowsheet has been loaded into Fsheet. Not saved with the flowsheet.

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

InitializeOnLoad: Gets or sets whether the sub-flowsheet is initialized when the parent flowsheet loads.

Gets or sets whether the sub-flowsheet is initialized when the parent flowsheet loads.

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

InputConnections: Gets or sets the list of input stream connection IDs in the sub-flowsheet.

Gets or sets the list of input stream connection IDs in the sub-flowsheet.

public List<string> InputConnections { get; set; }
Public Property InputConnections As List(Of String)

InputParams: Gets or sets the dictionary of input parameter mappings, keyed by parameter ID.

Gets or sets the dictionary of input parameter mappings, keyed by parameter ID.

public Dictionary<string, FlowsheetUOParameter> InputParams { get; set; }
Public Property InputParams As Dictionary(Of String, FlowsheetUOParameter)

MassBalanceError: Gets or sets the mass balance error across the sub-flowsheet (fractional).

Gets or sets the mass balance error across the sub-flowsheet (fractional).

public double MassBalanceError { get; set; }
Public Property MassBalanceError As Double

MassTransferMode: Gets or sets how compound flows are transferred between parent and sub-flowsheet streams.

Gets or sets how compound flows are transferred between parent and sub-flowsheet streams.

public FlowsheetUOMassTransferMode MassTransferMode { get; set; }
Public Property MassTransferMode As FlowsheetUOMassTransferMode

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 (UserModels).

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

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

OutputConnections: Gets or sets the list of output stream connection IDs in the sub-flowsheet.

Gets or sets the list of output stream connection IDs in the sub-flowsheet.

public List<string> OutputConnections { get; set; }
Public Property OutputConnections As List(Of String)

OutputParams: Gets or sets the dictionary of output parameter mappings, keyed by parameter ID.

Gets or sets the dictionary of output parameter mappings, keyed by parameter ID.

public Dictionary<string, FlowsheetUOParameter> OutputParams { get; set; }
Public Property OutputParams As Dictionary(Of String, FlowsheetUOParameter)

RedirectOutput: Gets or sets whether output from the sub-flowsheet solver is redirected to the parent flowsheet log.

Gets or sets whether output from the sub-flowsheet solver is redirected to the parent flowsheet log.

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

SimulationFile: Gets or sets the file path to the sub-flowsheet simulation file.

Gets or sets the file path to the sub-flowsheet simulation file.

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

UpdateOnSave: Gets or sets whether the sub-flowsheet file is updated when the parent flowsheet is saved.

Gets or sets whether the sub-flowsheet file is updated when the parent flowsheet is saved.

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

Methods

AddGraphicObjects(IFlowsheet, IFlowsheet, List<XElement>, ConcurrentBag<Exception>, string, int, bool): Creates the graphic objects described by the XML elements of a saved simulation, adds them to a flowsheet and...

Creates the graphic objects described by the XML elements of a saved simulation, adds them to a flowsheet and restores their material and energy connections. Errors are collected instead of thrown.

Parameter Type Description
fs IFlowsheet The flowsheet that receives the graphic objects.
mainfs IFlowsheet The parent flowsheet, used to resolve external unit operations by description.
data List<XElement> The "GraphicObjects" XML elements of the saved simulation.
excs ConcurrentBag<Exception> Collection that receives any exception raised while loading objects or connections.
pkey String Optional prefix added to every object name (and its connection references); when not empty, duplicate tags are renumbered.
shift Int32 Optional offset added to the X and Y coordinates of every object, in drawing units.
reconnectinlets Boolean Optional. If True, inlet connections are also re-created from the source objects' free outlet ports.
public static void AddGraphicObjects(IFlowsheet fs, IFlowsheet mainfs, List<XElement> data, ConcurrentBag<Exception> excs, string pkey = "", int shift = 0, bool reconnectinlets = false)
Public Shared Sub AddGraphicObjects(fs As IFlowsheet, mainfs As IFlowsheet, data As List(Of XElement), excs As ConcurrentBag(Of Exception), pkey As String = "", shift As Integer = 0, reconnectinlets As Boolean = False)

Calculate(object): Transfers input data to the sub-flowsheet, solves it, and maps results back to the parent.

Transfers input data to the sub-flowsheet, solves it, and maps results back to the parent.

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

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()

DisplayEditForm(): Opens or activates the editing form.

Opens or activates the editing form.

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

ExtractXML(string): Extracts all files of a compressed simulation file (.dwxmz) into the system temporary folder.

Extracts all files of a compressed simulation file (.dwxmz) into the system temporary folder.

Parameter Type Description
zippath String Full path of the compressed simulation file.
public static string ExtractXML(string zippath)
Public Shared Function ExtractXML(zippath As String) As String

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

GetEditingForm(): Returns the editing form instance.

Returns the editing form instance.

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

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()

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, converted to the given unit system.

Returns the value of the specified property, converted to the given unit system.

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 flowsheet UO results.

Generates a plain-text report of the flowsheet UO 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

InitializeFlowsheet(MemoryStream, IFlowsheet, IFlowsheet): Creates and initializes a sub-flowsheet from a compressed memory stream.

Creates and initializes a sub-flowsheet from a compressed memory stream.

Parameter Type Description
compressedstream MemoryStream
form IFlowsheet
mainfs IFlowsheet
public static IFlowsheet InitializeFlowsheet(MemoryStream compressedstream, IFlowsheet form, IFlowsheet mainfs)
Public Shared Function InitializeFlowsheet(compressedstream As MemoryStream, form As IFlowsheet, mainfs As IFlowsheet) As IFlowsheet

InitializeFlowsheet(string, IFlowsheet, IFlowsheet): Creates and initializes a sub-flowsheet from the given file path.

Creates and initializes a sub-flowsheet from the given file path.

Parameter Type Description
fpath String
form IFlowsheet
mainfs IFlowsheet
public static IFlowsheet InitializeFlowsheet(string fpath, IFlowsheet form, IFlowsheet mainfs)
Public Shared Function InitializeFlowsheet(fpath As String, form As IFlowsheet, mainfs As IFlowsheet) As IFlowsheet

InitializeInternalFlowsheet(): Initializes the internal sub-flowsheet object from the simulation file or embedded data.

Initializes the internal sub-flowsheet object from the simulation file or embedded data.

public void InitializeInternalFlowsheet()
Public Sub InitializeInternalFlowsheet()

InitializeMappings(): Initialises compound mappings between parent and sub-flowsheet using name matching.

Initialises compound mappings between parent and sub-flowsheet using name matching.

public void InitializeMappings()
Public Sub InitializeMappings()

LoadData(List<XElement>): Restores the flowsheet UO state, including parameter mappings and connections, from XML.

Restores the flowsheet UO state, including parameter mappings and connections, from XML.

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

ParseFilePath(): Resolves the sub-flowsheet file path relative to the parent flowsheet file.

Resolves the sub-flowsheet file path relative to the parent flowsheet file.

public void ParseFilePath()
Public Sub ParseFilePath()

ReturnProcessData(IFlowsheetBag): Serializes the current sub-flowsheet data to a compressed memory stream.

Serializes the current sub-flowsheet data to a compressed memory stream.

Parameter Type Description
Form IFlowsheetBag
public static MemoryStream ReturnProcessData(IFlowsheetBag Form)
Public Shared Function ReturnProcessData(Form As IFlowsheetBag) As MemoryStream

SaveData(): Serializes the flowsheet UO state, including parameter mappings and connections, to XML.

Serializes the flowsheet UO state, including parameter mappings and connections, to XML.

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

SetPropertyValue(string, object, IUnitsOfMeasure): Sets the value of the specified property from the given value and unit system.

Sets the value of the specified property from the given value and unit system.

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

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

Refreshes the editing form with updated data.

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

UpdateProcessData(IFlowsheetBag, XDocument): Updates process-level data in the XML document from the given flowsheet bag.

Updates process-level data in the XML document from the given flowsheet bag.

Parameter Type Description
form IFlowsheetBag
xdoc XDocument
public static object UpdateProcessData(IFlowsheetBag form, XDocument xdoc)
Public Shared Function UpdateProcessData(form As IFlowsheetBag, xdoc As XDocument) As Object

UpdateProcessData(string): Saves the current sub-flowsheet state back to the file at the given path.

Saves the current sub-flowsheet state back to the file at the given path.

Parameter Type Description
path String
public void UpdateProcessData(string path)
Public Sub UpdateProcessData(path As String)

Fields

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

Fsheet: The sub-flowsheet loaded from the simulation file or the embedded file.

The sub-flowsheet loaded from the simulation file or the embedded file. Not saved with the flowsheet.

public IFlowsheet Fsheet
Public Fsheet As IFlowsheet