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¶

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¶
-
User guide
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.
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. |
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.
ObjectClass: Gets or sets the simulation object class category (Switches).
Gets or sets the simulation object class category (Switches).
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.
Methods¶
Calculate(object): Calculates the object.
Calculates the object.
| Parameter | Type | Description |
|---|---|---|
args |
Object |
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.
CloseEditForm(): Closes the editor of this object, if it is open.
Closes the editor of this object, if it is open.
DeCalculate(): Decalculates the object.
Decalculates the object.
DisplayEditForm(): Opens the editor of this object.
Opens the editor of this object. A host that has no editor for it does nothing.
GetDisplayDescription(): Returns the localized description string for this object type.
Returns the localized description string for this object type.
GetDisplayName(): Returns the localized display name for this object type.
Returns the localized display name for this object type.
GetIconBitmapBytes(): Returns the raw bytes of the icon image for this switch.
Returns the raw bytes of the icon image for this switch.
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. |
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 |
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. |
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. |
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. |
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.
Fields¶