Skip to content

Switch

Logical block that writes one of two values to a property of another flowsheet object: when IsOn is True it applies OnValue, otherwise OffValue, to the property SelectedProperty of the object named by SelectedObjectID.

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

At a glance

Switch in the example flowsheet

This object has no stream connections; it acts on other objects through their properties.

Example

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

fs = (Flowsheet.Create("SwitchExample")
      .WithCompound("Water")
      .WithPropertyPackage(PropertyPackages.SteamTables))

feed = fs.AddMaterialStream("Cold water").At(Q.Celsius(20.0), Q.Bar(2.0)).WithMassFlow(Q.KgPerSecond(2.0))
product = fs.AddMaterialStream("Warm water")
duty = fs.AddEnergyStream("Steam duty")
heater = (fs.AddHeater("H-1").WithHeatAdded(Q.Kilowatts(0.0))
          .ConnectFeed(feed).ConnectProduct(product).ConnectEnergyFeed(duty, 1))

builder = fs.AddUnitOperation(ObjectType.Switch, "HS-1")
switch = builder.Object.__implementation__
switch.SelectedObjectID = heater.Object.Name
switch.SelectedProperty = "PROP_HT_3"        # heat added
switch.SelectedPropertyUnits = "kW"
switch.OnValue = 400.0                       # kW with the steam on
switch.OffValue = 0.0

fs.AutoLayout()

switch.IsOn = False
switch.Calculate()                           # what a click does; the solver does not run it
fs.Solve()
q_off, t_off = heater.HeatDutyKW, product.TemperatureK - 273.15

switch.IsOn = True
switch.Calculate()
fs.Solve()
q_on, t_on = heater.HeatDutyKW, product.TemperatureK - 273.15

print(f"Switch off: duty {q_off:.0f} kW, outlet {t_off:.2f} C")
print(f"Switch on:  duty {q_on:.0f} kW, outlet {t_on:.2f} C")
print(f"Temperature rise = {t_on - t_off:.2f} K (m.cp.dT estimate {400.0 / (2.0 * 4.18):.2f} K)")

Output

Switch off: duty 0 kW, outlet 20.00 C
Switch on:  duty 400 kW, outlet 67.84 C
Temperature rise = 47.84 K (m.cp.dT estimate 47.85 K)

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
IsOn Switch State (1 = On, 0 = Off) yes
OnValue Value When On kW yes
OffValue Value When Off kW yes
AppliedValue Applied Value kW result
SelectedObjectTag Switched Object result
SelectedProperty Switched Property result
SelectedPropertyUnits Value Units result

Learn more

API members

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

Constructors

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

Initializes a new default instance of the Switch class.

public Switch()
Public Sub New()

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

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

Parameter Type Description
name String The name of this switch.
description String A brief description of this switch.
public Switch(string name, string description)
Public Sub New(name As String, description As String)

Properties

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

Gets a value indicating whether this switch 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 (Switches).

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

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

SupportsDynamicMode: Gets a value indicating whether this switch can run in dynamic simulation mode.

Gets a value indicating whether this switch can run in dynamic simulation mode. Always True.

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

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 localized description string for this object type.

Returns the localized description string for this object type.

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

GetDisplayName(): Returns the localized display name for this object type.

Returns the localized display name for this object type.

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

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

Returns the raw bytes of the icon image for this switch.

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

GetProperties(PropertyType): Returns the list of property identifiers available for this switch.

Returns the list of property identifiers available for this switch. The object and property it switches are text and are listed only under ALL.

Parameter Type Description
proptype PropertyType The type of properties to retrieve.
public override string[] GetProperties(PropertyType proptype)
Public Overrides Function GetProperties(proptype As PropertyType) As String()

GetPropertyDescription(string): Readable names for the property identifiers, which are the .NET property names.

Readable names for the property identifiers, which are the .NET property names.

Parameter Type Description
prop String
public override string GetPropertyDescription(string prop)
Public Overrides Function GetPropertyDescription(prop As String) 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 The property identifier string.
su IUnitsOfMeasure The unit system to use; defaults to SI if not provided.
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. The on, off and applied values come in the units the target object uses for the switched property in the given unit system (SI when none is given).

Parameter Type Description
prop String The property identifier string.
su IUnitsOfMeasure The unit system to use; defaults to SI if not provided.
public override object GetPropertyValue(string prop, IUnitsOfMeasure su = null)
Public Overrides Function GetPropertyValue(prop As String, su As IUnitsOfMeasure = Nothing) As Object

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

Sets the value of the specified property. The on and off values are taken in the units the target object uses for the switched property in the given unit system (SI when none is given).

Parameter Type Description
prop String The property identifier string.
propval Object The new value to assign.
su IUnitsOfMeasure The unit system of the supplied value; defaults to SI if not provided.
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(): 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 switch, if any.

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

public object f
Public f As Object