Skip to content

Specification

Represents a Spec (specification) block that copies a property from a source simulation object, evaluates an optional mathematical expression using that value, and writes the result to a target simulation object. Optionally clamps the result within configurable minimum/maximum bounds.

DWSIM.UnitOperations.SpecialOps.Spec
Assembly DWSIM.UnitOperations.dll · Object ← BaseClass ← SpecialOpBaseClass ← Spec

At a glance

Specification 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("SpecExample")
      .WithCompound("Water")
      .WithPropertyPackage(PropertyPackages.SteamTables))

cw = (fs.AddMaterialStream("CW supply")
      .At(Q.Celsius(28.0), Q.Bar(3.0))
      .WithMassFlow(Q.KgPerSecond(20.0)))
hot = (fs.AddMaterialStream("Hot water")
       .At(Q.Celsius(90.0), Q.Bar(2.0))
       .WithMassFlow(Q.KgPerSecond(3.0)))
cooled = fs.AddMaterialStream("Cooled water")
duty = fs.AddEnergyStream("C-1 duty")

cooler = (fs.AddCooler("C-1")
          .WithOutletTemperature(Q.Celsius(50.0))    # overwritten by the spec
          .ConnectFeed(hot)
          .ConnectProduct(cooled)
          .ConnectEnergyProduct(duty))

builder = fs.AddUnitOperation(ObjectType.OT_Spec, "SPEC-1")
spec = builder.Object.__implementation__

def link(info, obj, prop, role):
    info.ID = obj.Object.Name
    info.Name = obj.Object.GraphicObject.Tag
    info.PropertyName = prop
    info.ObjectType = obj.Object.GetDisplayName()
    obj.Object.IsSpecAttached = True          # what the editor does when you pick an object
    obj.Object.AttachedSpecId = spec.Name
    obj.Object.SpecVarType = role

spec.SourceObjectData = SpecialOpObjectInfo()
spec.TargetObjectData = SpecialOpObjectInfo()
link(spec.SourceObjectData, cw, "PROP_MS_0", SpecVarType.Source)       # X: CW temperature
link(spec.TargetObjectData, cooler, "PROP_CL_2", SpecVarType.Target)   # Y: cooler outlet temperature
spec.SourceObject = cw.Object
spec.TargetObject = cooler.Object
spec.GraphicObject.__implementation__.ConnectedToSv = cw.Object.GraphicObject      # drawing links
spec.GraphicObject.__implementation__.ConnectedToTv = cooler.Object.GraphicObject
spec.Expression = "X + 10"     # Y = X + 10, in the flowsheet display units (C here)

# Run the spec right before the cooler is calculated, so the cooler uses the new value.
fs.Inner.FlowsheetOptions.SpecCalculationMode = SpecCalcMode.BeforeTargetObject

fs.AutoLayout()
fs.Solve()

t_cw = cw.TemperatureK - 273.15
t_out = cooled.TemperatureK - 273.15
print(f"CW supply temperature = {t_cw:.2f} C")
print(f"Cooler outlet         = {t_out:.2f} C")
print(f"Approach              = {t_out - t_cw:.2f} K")
print(f"Heat removed          = {cooler.HeatRemovedKW:.1f} kW")

Output

CW supply temperature = 28.00 C
Cooler outlet         = 38.00 C
Approach              = 10.00 K
Heat removed          = 653.1 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
SpecMin Target Variable Minimum yes
SpecMax Target Variable Maximum yes
Expression result

Learn more

API members

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

Constructors

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

Initializes a new default instance of the Spec class.

public Spec()
Public Sub New()

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

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

Parameter Type Description
name String The display name of the spec block.
description String A brief description of the block.
public Spec(string name, string description)
Public Sub New(name As String, description As String)

Properties

CalculateTargetObject: Gets or sets whether the target simulation object should be recalculated after the specification is applied.

Gets or sets whether the target simulation object should be recalculated after the specification is applied.

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

ExpContext: Gets or sets the expression evaluation context providing variable bindings and math imports (not serialized).

Gets or sets the expression evaluation context providing variable bindings and math imports (not serialized).

public ExpressionEvaluator.VariableTable ExpContext { get; set; }
Public Property ExpContext As ExpressionEvaluator.VariableTable

Expr: Gets or sets the compiled generic expression object used to evaluate the specification formula (not serialized).

Gets or sets the compiled generic expression object used to evaluate the specification formula (not serialized).

public CompiledExpression Expr { get; set; }
Public Property Expr As CompiledExpression

Expression: Gets or sets the mathematical expression string evaluated by this spec block (variables: X = source value, Y =...

Gets or sets the mathematical expression string evaluated by this spec block (variables: X = source value, Y = target value).

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

HasPropertiesForDynamicMode: Gets a value indicating whether this block exposes properties for dynamic mode.

Gets a value indicating whether this block exposes properties for dynamic mode.

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

MaxVal: Gets or sets the optional upper bound clamping value applied to the evaluated expression result.

Gets or sets the optional upper bound clamping value applied to the evaluated expression result.

public double? MaxVal { get; set; }
Public Property MaxVal As Double?

MinVal: Gets or sets the optional lower bound clamping value applied to the evaluated expression result.

Gets or sets the optional lower bound clamping value applied to the evaluated expression result.

public double? MinVal { get; set; }
Public Property MinVal As Double?

MobileCompatible: Gets a value indicating whether this block is compatible with the DWSIM mobile interface.

Gets a value indicating whether this block is compatible with the DWSIM mobile interface.

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

SourceObject: Gets or sets the source simulation object instance (not serialized).

Gets or sets the source simulation object instance (not serialized).

public BaseClass SourceObject { get; set; }
Public Property SourceObject As BaseClass

SourceObjectData: Gets or sets the metadata describing the source simulation object and property whose value is read.

Gets or sets the metadata describing the source simulation object and property whose value is read.

public SpecialOpObjectInfo SourceObjectData { get; set; }
Public Property SourceObjectData As SpecialOpObjectInfo

Status: Gets or sets a status message describing the outcome of the last calculation attempt.

Gets or sets a status message describing the outcome of the last calculation attempt.

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

SupportsDynamicMode: Gets a value indicating whether this block supports dynamic simulation mode.

Gets a value indicating whether this block supports dynamic simulation mode.

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

TargetObject: Gets or sets the target simulation object instance (not serialized).

Gets or sets the target simulation object instance (not serialized).

public BaseClass TargetObject { get; set; }
Public Property TargetObject As BaseClass

TargetObjectData: Gets or sets the metadata describing the target simulation object and property that receives the expression result.

Gets or sets the metadata describing the target simulation object and property that receives the expression result.

public SpecialOpObjectInfo TargetObjectData { get; set; }
Public Property TargetObjectData As SpecialOpObjectInfo

Methods

Calculate(object): Evaluates the expression and writes the result to the target simulation object's property.

Evaluates the expression and writes the result to the target simulation object's property. Clamps the result within MinVal and MaxVal if both are set.

Parameter Type Description
args Object Optional calculation arguments (not used).
public override void Calculate(object args = null)
Public Overrides Sub Calculate(args As Object = Nothing)

CloneXML(): Creates a deep copy of this spec block via XML serialization.

Creates a deep copy of this spec block via XML serialization.

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

CloseEditForm(): Closes and disposes the editing form for this spec block if it is open.

Closes and disposes the editing form for this spec block if it is open.

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

DisplayEditForm(): Opens or activates the editing form for this spec block.

Opens or activates the editing form for this spec block.

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

GetDisplayDescription(): Returns the localized display description for the spec block type.

Returns the localized display description for the spec block type.

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

GetDisplayName(): Returns the localized display name for the spec block type.

Returns the localized display name for the spec block type.

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

GetIconBitmapBytes(): Returns the raw bytes of the spec block icon image resource.

Returns the raw bytes of the spec block icon image resource.

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

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

Returns the list of property identifiers available for this spec block. The expression is text, so it is listed only under ALL: the numeric lists that adjusts and sensitivity analyses offer leave it out.

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.

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

GetSourceVarUnit(): Returns the unit string for the source variable in the active unit system.

Returns the unit string for the source variable in the active unit system.

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

GetSourceVarValue(): Returns the current value of the source variable in the active unit system.

Returns the current value of the source variable in the active unit system.

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

GetTargetVarUnit(): Returns the unit string for the target variable in the active unit system.

Returns the unit string for the target variable in the active unit system.

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

GetTargetVarValue(): Returns the current value of the target variable in the active unit system.

Returns the current value of the target variable in the active unit system.

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

LoadData(List<XElement>): Restores the spec block state from a list of XML elements.

Restores the spec block state from a list of XML elements.

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

ParseExpression(): Compiles and evaluates the expression string using the current source (X) and target (Y) variable values.

Compiles and evaluates the expression string using the current source (X) and target (Y) variable values.

public double ParseExpression()
Public Function ParseExpression() As Double

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

Serializes the spec block state to a list of XML elements for persistence.

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

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

Sets the value of the specified property.

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

SetTargetVarValue(double?): Writes a value to the target variable of the configured target simulation object.

Writes a value to the target variable of the configured target simulation object.

Parameter Type Description
val Nullable<Double> The value to assign, expressed in the active unit system.
public object SetTargetVarValue(double? val)
Public Function SetTargetVarValue(val As Double?) As Object

UpdateEditForm(): Refreshes the displayed data in the editing form if it is currently open.

Refreshes the displayed data in the editing form if it is currently open.

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

Fields

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

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

public object f
Public f As Object