Skip to content

Material Stream Switch

DWSIM Plus

Available with a DWSIM Plus (Patreon) subscription.

Material stream switch: routes the inlet material stream to outlet 1 when Expression evaluates to true and to outlet 2 otherwise; the other outlet gets a copy of the inlet with zero flow.

DWSIM.UnitOperations.ExtensionPack.MaterialStreamSwitch
Assembly DWSIM.UnitOperations.ExtensionPack.dll · Object ← BaseClass ← UnitOpBaseClass ← MaterialStreamSwitch

At a glance

Material Stream Switch in the example flowsheet

Port Index Connected in the example
Inlet, material 0 Gas
Outlet, material 0 To sales
Outlet, material 1 To separator

Example

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

fs = (Flowsheet.Create("MaterialSwitchExample")
      .WithCompounds("Methane", "Propane", "N-butane")
      .WithPropertyPackage(PropertyPackages.PengRobinson))

gas = (fs.AddMaterialStream("Gas")
       .At(Q.Celsius(5.0), Q.Bar(30.0))
       .SetCompoundMolarFlow("Methane", 80.0)
       .SetCompoundMolarFlow("Propane", 15.0)
       .SetCompoundMolarFlow("N-butane", 5.0))
to_sales = fs.AddMaterialStream("To sales")
to_separator = fs.AddMaterialStream("To separator")

# Inlet variables: T (K), P (Pa), W (kg/s), M (mol/s), Q (m3/s), VF, LF, SF.
# TRUE routes the whole inlet to outlet 1, FALSE to outlet 2.
switch = (fs.AddMaterialStreamSwitch("MSW-1")
          .WithExpression("VF > 0.999")
          .ConnectFeed(gas)
          .ConnectProduct(to_sales, 0)
          .ConnectProduct(to_separator, 1))

fs.AutoLayout()
fs.Solve()

vf = gas.Object.Phases[2].Properties.molarfraction
print(f"Inlet vapor fraction = {vf:.4f}")
print(f"To sales             = {to_sales.Object.GetMassFlow():.4f} kg/s")
print(f"To separator         = {to_separator.Object.GetMassFlow():.4f} kg/s")

Output

Inlet vapor fraction = 0.9467
To sales             = 0.0000 kg/s
To separator         = 2.2354 kg/s

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

MaterialStreamSwitch(): Initializes a new default instance of the MaterialStreamSwitch class.

Initializes a new default instance of the MaterialStreamSwitch class.

public MaterialStreamSwitch()
Public Sub New()

MaterialStreamSwitch(string, string): Initializes a new instance of the MaterialStreamSwitch class with a name and description.

Initializes a new instance of the MaterialStreamSwitch class with a name and description.

Parameter Type Description
Name String The name of this unit operation.
Description String A brief description of this unit operation.
public MaterialStreamSwitch(string Name, string Description)
Public Sub New(Name As String, Description As String)

Properties

ComponentDescription: Gets or sets the CAPE-OPEN component description for this unit operation.

Gets or sets the CAPE-OPEN component description for this unit operation.

public override string ComponentDescription { get; set; }
Public Overrides Property ComponentDescription As String

ComponentName: Gets or sets the CAPE-OPEN component name for this unit operation.

Gets or sets the CAPE-OPEN component name for this unit operation.

public override string ComponentName { get; set; }
Public Overrides Property ComponentName As String

Expression: Gets or sets the logical routing expression, written with the inlet stream variables T (K), P (Pa), W (mass flow...

Gets or sets the logical routing expression, written with the inlet stream variables T (K), P (Pa), W (mass flow, kg/s), M (molar flow, mol/s), Q (volumetric flow, m3/s), and the vapor, liquid and solid phase mole fractions VF, LF and SF. True routes the inlet to outlet 1, false to outlet 2. Calculation fails if the expression is empty.

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

IsPremium: Gets a value indicating whether this unit operation is a premium (DWSIM Patreon) unit operation.

Gets a value indicating whether this unit operation is a premium (DWSIM Patreon) unit operation. Always True; the object palette lists it under the Premium category.

public bool IsPremium { get; }
Public ReadOnly Property IsPremium 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. Always False.

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

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

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

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

Methods

Calculate(object): Calculates the object.

Calculates the object.

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 of this object by round-tripping through XML serialization.

Creates a deep copy of this object by round-tripping through XML serialization.

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

CloseEditForm(): Closes the editor of this object, if it is open.

Closes the editor of this object, if it is open.

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

DeCalculate(): Decalculates the object.

Decalculates the object.

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

DisplayEditForm(): Opens the editor of this object.

Opens the editor of this object. A host that has no editor for it does nothing.

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

GetDisplayDescription(): Returns the description string for this unit operation type.

Returns the description string for this unit operation type.

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

GetDisplayName(): Returns the display name for this unit operation type.

Returns the display name for this unit operation type.

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

GetIconBitmapBytes(): Returns the raw bytes of the icon image for this unit operation.

Returns the raw bytes of the icon image for this unit operation.

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

GetPropertyDescription(string): Returns the description of the specified property.

Returns the description of the specified property.

Parameter Type Description
p String The property name.
public override string GetPropertyDescription(string p)
Public Overrides Function GetPropertyDescription(p As String) As String

LoadData(List<XElement>): Restores the unit operation state from a list of XML elements previously produced by SaveData.

Restores the unit operation state from a list of XML elements previously produced by SaveData.

Parameter Type Description
data List<XElement> The list of XElement objects containing serialized state.
public override bool LoadData(List<XElement> data)
Public Overrides Function LoadData(data As List(Of XElement)) As Boolean

SaveData(): Serializes the unit operation state to a list of XML elements for persistence.

Serializes the unit operation state to a list of XML elements for persistence.

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

UpdateEditForm(): Redraws the editor of this object with the current values, if it is open.

Redraws the editor of this object with the current values, if it is open.

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

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 EditingForm_MSSwitch f
Public f As EditingForm_MSSwitch