Skip to content
This repository has been archived by the owner on Jun 17, 2020. It is now read-only.

Commit

Permalink
Fixed CAPE-OPEN UO validation/calculation; Fixed a bug with valve sizing
Browse files Browse the repository at this point in the history
  • Loading branch information
DanWBR committed Nov 29, 2017
1 parent 0e93d05 commit b587ccd
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 45 deletions.
88 changes: 45 additions & 43 deletions DWSIM.UnitOperations/Unit Operations/CapeOpenUO.vb
Original file line number Diff line number Diff line change
Expand Up @@ -1055,60 +1055,62 @@ Namespace UnitOperations
Dim ecu As CapeOpen.ECapeUser = myuo
Me.FlowSheet.ShowMessage(Me.GraphicObject.Tag & ": CAPE-OPEN Exception " & ecu.code & " at " & ecu.interfaceName & ":" & ecu.scope & ". Reason: " & ecu.description, IFlowsheet.MessageType.GeneralError)
End Try
'My.Application.ActiveSimulation = Me.FlowSheet
myuo.Validate(msg)
If myuo.ValStatus = CapeValidationStatus.CAPE_VALID Then
Try
For Each c As Interfaces.IConnectionPoint In Me.GraphicObject.OutputConnectors
If c.IsAttached And c.Type = ConType.ConOut Then
Dim mat As MaterialStream = FlowSheet.SimulationObjects(c.AttachedConnector.AttachedTo.Name)
mat.ClearAllProps()
End If
Next
RestorePorts()
myuo.Calculate()
UpdateParams()
For Each c As Interfaces.IConnectionPoint In Me.GraphicObject.OutputConnectors
If c.IsAttached And c.Type = ConType.ConOut Then
Dim mat As MaterialStream = FlowSheet.SimulationObjects(c.AttachedConnector.AttachedTo.Name)
mat.PropertyPackage.CurrentMaterialStream = mat
For Each subst As Compound In mat.Phases(0).Compounds.Values
subst.MassFraction = mat.PropertyPackage.AUX_CONVERT_MOL_TO_MASS(subst.Name, 0)
Next
End If
Next

For Each c As Interfaces.IConnectionPoint In Me.GraphicObject.OutputConnectors
If c.IsAttached And c.Type = ConType.ConOut Then
Dim mat As MaterialStream = FlowSheet.SimulationObjects(c.AttachedConnector.AttachedTo.Name)
mat.ClearAllProps()
End If
Next

RestorePorts()

Try
myuo.Validate(msg)
If Not myuo.ValStatus = CapeValidationStatus.CAPE_VALID Then
Me.FlowSheet.ShowMessage(Me.GraphicObject.Tag + ": CAPE-OPEN Unit Operation not validated. Reason: " + msg, IFlowsheet.MessageType.GeneralError)
For Each c As Interfaces.IConnectionPoint In Me.GraphicObject.OutputConnectors
If c.Type = ConType.ConEn And c.IsAttached Then
c.AttachedConnector.AttachedTo.Calculated = True
If c.Type = ConType.ConEn Then
If c.IsAttached Then c.AttachedConnector.AttachedTo.Calculated = False
End If
Next
Dim ur As CapeOpen.ICapeUnitReport = _couo
If Not ur Is Nothing Then
Dim reps As String() = ur.reports
For Each r As String In reps
ur.selectedReport = r
Dim msg2 As String = ""
ur.ProduceReport(msg2)
Throw New Exception("CAPE-OPEN Unit Operation not validated. Reason: " + msg)
End If
myuo.Calculate()
UpdateParams()
For Each c As Interfaces.IConnectionPoint In Me.GraphicObject.OutputConnectors
If c.IsAttached And c.Type = ConType.ConOut Then
Dim mat As MaterialStream = FlowSheet.SimulationObjects(c.AttachedConnector.AttachedTo.Name)
mat.PropertyPackage.CurrentMaterialStream = mat
For Each subst As Compound In mat.Phases(0).Compounds.Values
subst.MassFraction = mat.PropertyPackage.AUX_CONVERT_MOL_TO_MASS(subst.Name, 0)
Next
End If
Catch ex As Exception
For Each c As Interfaces.IConnectionPoint In Me.GraphicObject.OutputConnectors
If c.Type = ConType.ConEn Then
If c.IsAttached Then c.AttachedConnector.AttachedTo.Calculated = False
End If
Next
For Each c As Interfaces.IConnectionPoint In Me.GraphicObject.OutputConnectors
If c.Type = ConType.ConEn And c.IsAttached Then
c.AttachedConnector.AttachedTo.Calculated = True
End If
Next
Dim ur As CapeOpen.ICapeUnitReport = _couo
If Not ur Is Nothing Then
Dim reps As String() = ur.reports
For Each r As String In reps
ur.selectedReport = r
Dim msg2 As String = ""
ur.ProduceReport(msg2)
Next
Dim ecu As CapeOpen.ECapeUser = myuo
Me.FlowSheet.ShowMessage(Me.GraphicObject.Tag & ": CAPE-OPEN Exception " & ecu.code & " at " & ecu.interfaceName & ":" & ecu.scope & ". Reason: " & ecu.description, IFlowsheet.MessageType.GeneralError)
Throw ex
End Try
Else
Me.FlowSheet.ShowMessage(Me.GraphicObject.Tag + ": CO Unit not validated. Reason: " + msg, IFlowsheet.MessageType.GeneralError)
End If
Catch ex As Exception
For Each c As Interfaces.IConnectionPoint In Me.GraphicObject.OutputConnectors
If c.Type = ConType.ConEn Then
If c.IsAttached Then c.AttachedConnector.AttachedTo.Calculated = False
End If
Next
End If
Dim ecu As CapeOpen.ECapeUser = myuo
Me.FlowSheet.ShowMessage(Me.GraphicObject.Tag & ": CAPE-OPEN Exception " & ecu.code & " at " & ecu.interfaceName & ":" & ecu.scope & ". Reason: " & ecu.description, IFlowsheet.MessageType.GeneralError)
Throw ex
End Try
End If

End Sub
Expand Down
4 changes: 2 additions & 2 deletions DWSIM.UnitOperations/Unit Operations/Valve.vb
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,15 @@ Namespace UnitOperations

If vf = 0.0# Then
'size for liquid
Cv = (volf * 15850.3) / ((DeltaP * 0.000145038) / (rho / 1000)) ^ 0.5
Cv = (volf * 15850.3) / ((DeltaP.GetValueOrDefault * 0.000145038) / (rho / 1000)) ^ 0.5
ElseIf vf = 1.0# Then
'size for vapor
C1 = 20 '18 to 37
Dim f1 As Double = Math.Sin((3417 / C1) * (Math.Abs(DeltaP.GetValueOrDefault) / Pi) ^ 0.5 / 57.2958)
Cv = (Wi * 7936.64) / 1.06 / (rho * 0.062428 * Pi * 0.000145038) ^ 0.5 / f1
Else
'size for liquid
Cv = (1 - vf) * (volf * 15850.3) / ((DeltaP * 0.000145038) / (rho / 1000)) ^ 0.5
Cv = (1 - vf) * (volf * 15850.3) / ((DeltaP.GetValueOrDefault * 0.000145038) / (rho / 1000)) ^ 0.5
'size for vapor
C1 = 20 '18 to 37
Dim f1 As Double = Math.Sin((3417 / C1) * (Math.Abs(DeltaP.GetValueOrDefault) / Pi) ^ 0.5 / 57.2958)
Expand Down

0 comments on commit b587ccd

Please sign in to comment.