Skip to content

Commit

Permalink
v8.4.5 RC2
Browse files Browse the repository at this point in the history
  • Loading branch information
DanWBR committed May 25, 2023
1 parent 59c5c5b commit 4194e0b
Show file tree
Hide file tree
Showing 23 changed files with 97 additions and 73 deletions.
12 changes: 12 additions & 0 deletions DWSIM.FlowsheetBase/FlowsheetBase.vb
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,18 @@ Imports System.Text.RegularExpressions

End Sub


Public Sub RequestCalculation3(Obj As ISimulationObject, Wait As Boolean) Implements IFlowsheet.RequestCalculation3

If Obj Is Nothing Then
RequestCalculation2(Wait)
Else
RequestCalculation(Obj)
End If

End Sub


Public Property SelectedCompounds As Dictionary(Of String, ICompoundConstantProperties) Implements IFlowsheet.SelectedCompounds
Get
Select Case Options.CompoundOrderingMode
Expand Down
4 changes: 2 additions & 2 deletions DWSIM.FlowsheetSolver/FlowsheetSolver.vb
Original file line number Diff line number Diff line change
Expand Up @@ -1746,8 +1746,8 @@ Public Delegate Sub CustomEvent2(ByVal objinfo As CalculationArgs)

fqueue.CalculationQueue.Enqueue(objargs)

Return SolveFlowsheet(fobj, Settings.SolverMode, Nothing, False, False, Nothing, Nothing, Nothing)
'Return SolveFlowsheet(fobj, Settings.SolverMode, Nothing, True)
'Return SolveFlowsheet(fobj, Settings.SolverMode, Nothing, False, False, Nothing, Nothing, Nothing)
Return SolveFlowsheet(fobj, Settings.SolverMode, Nothing, True)

Else

Expand Down
4 changes: 4 additions & 0 deletions DWSIM.Interfaces/IFlowsheet.vb
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,11 @@
Sub DisplayBrowserWindow(url As String)

Sub DisplayDockableBrowserWindow(url As String)

Sub RequestCalculation2(Wait As Boolean)

Sub RequestCalculation3(obj As ISimulationObject, Wait As Boolean)

End Interface

''' <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1370,7 +1370,7 @@ Public Class MaterialStreamEditor
SaveViewState()

If Not IsAccumulationStream Then
MatStream.FlowSheet.RequestCalculation2(False)
MatStream.FlowSheet.RequestCalculation3(MatStream, False)
End If

End Sub
Expand Down
95 changes: 47 additions & 48 deletions DWSIM.Thermodynamics/PropertyPackages/ActivityCoefficientBase.vb
Original file line number Diff line number Diff line change
Expand Up @@ -127,57 +127,57 @@ Namespace PropertyPackages

For j As Integer = 1 To 7

If j <> 2 Then
If j <> 2 Then

Dim Vx = RET_VMOL(RET_PHASECODE(j))
Dim n As Integer = Vx.Length - 1
Dim Vx = RET_VMOL(RET_PHASECODE(j))
Dim n As Integer = Vx.Length - 1

Dim constprop = DW_GetConstantProperties()
Dim constprop = DW_GetConstantProperties()

Dim ativ(n), poy1(n), poy2(n), vex(n) As Double
Dim ativ(n), poy1(n), poy2(n), vex(n) As Double

ativ = m_act.CalcActivityCoefficients(T, Vx, Me.GetArguments())
ativ = m_act.CalcActivityCoefficients(T, Vx, Me.GetArguments())

Dim P2 As Double = P + 1
Dim P2 As Double = P + 1

Dim Psati, vli As Double
For i = 0 To n
vli = 1 / AUX_LIQDENSi(constprop(i), T) * constprop(i).Molar_Weight
If Double.IsNaN(vli) Then
vli = 1 / AUX_LIQDENSi(constprop(i), constprop(i).Normal_Boiling_Point) * constprop(i).Molar_Weight
End If
Psati = AUX_PVAPi(i, T)
poy1(i) = Math.Exp(vli * Abs(P - Psati) / (8314.47 * T))
poy2(i) = Math.Exp(vli * Abs(P2 - Psati) / (8314.47 * T))
vex(i) = (Log(poy2(i)) - Log(poy1(i))) * 8.314 * T * 1000 'm3/kmol
Next
Dim Psati, vli As Double
For i = 0 To n
vli = 1 / AUX_LIQDENSi(constprop(i), T) * constprop(i).Molar_Weight
If Double.IsNaN(vli) Then
vli = 1 / AUX_LIQDENSi(constprop(i), constprop(i).Normal_Boiling_Point) * constprop(i).Molar_Weight
End If
Psati = AUX_PVAPi(i, T)
poy1(i) = Math.Exp(vli * Abs(P - Psati) / (8314.47 * T))
poy2(i) = Math.Exp(vli * Abs(P2 - Psati) / (8314.47 * T))
vex(i) = (Log(poy2(i)) - Log(poy1(i))) * 8.314 * T * 1000 'm3/kmol
Next

i = 0
For Each subst As Interfaces.ICompound In Me.CurrentMaterialStream.Phases(j).Compounds.Values
subst.PartialVolume = vex(i)
i += 1
Next

Else

If VaporPhaseFugacityCalculationMode = VaporPhaseFugacityCalcMode.Ideal Then
Dim vapdens = AUX_VAPDENS(T, P)
For Each subst As Interfaces.ICompound In Me.CurrentMaterialStream.Phases(2).Compounds.Values
subst.PartialVolume = subst.ConstantProperties.Molar_Weight / vapdens
Next
Else
Dim partvol As New Object
partvol = Me.m_pr.CalcPartialVolume(T, P, RET_VMOL(2), RET_VKij(), RET_VTC(), RET_VPC(), RET_VW(), RET_VTB(), "V", 0.0001)
i = 0
For Each subst As Interfaces.ICompound In Me.CurrentMaterialStream.Phases(j).Compounds.Values
subst.PartialVolume = vex(i)
For Each subst As Interfaces.ICompound In Me.CurrentMaterialStream.Phases(2).Compounds.Values
subst.PartialVolume = partvol(i)
i += 1
Next

Else

If VaporPhaseFugacityCalculationMode = VaporPhaseFugacityCalcMode.Ideal Then
Dim vapdens = AUX_VAPDENS(T, P)
For Each subst As Interfaces.ICompound In Me.CurrentMaterialStream.Phases(2).Compounds.Values
subst.PartialVolume = subst.ConstantProperties.Molar_Weight / vapdens
Next
Else
Dim partvol As New Object
partvol = Me.m_pr.CalcPartialVolume(T, P, RET_VMOL(2), RET_VKij(), RET_VTC(), RET_VPC(), RET_VW(), RET_VTB(), "V", 0.0001)
i = 0
For Each subst As Interfaces.ICompound In Me.CurrentMaterialStream.Phases(2).Compounds.Values
subst.PartialVolume = partvol(i)
i += 1
Next
End If

End If

Next
End If

Next

End Sub

Expand Down Expand Up @@ -621,20 +621,19 @@ Namespace PropertyPackages
If Tr >= 1.02 Then
IObj?.SetCurrent()
IObj?.Paragraphs.Add("<m>f_i = H_i/P</m>")
lnfug(i) = Log(AUX_KHenry(Me.RET_VNAMES(i), T) / P)
IObj?.Paragraphs.Add(String.Format("Henry's Constant (H) @ {0} K: {1} Pa", T, Exp(lnfug(i)) * P))
ElseIf Tr < 0.98 Then
IObj?.Paragraphs.Add("<m>f_i = \gamma_i Poy_i P_{sat_i}/P</m>")
IObj?.Paragraphs.Add(String.Format("Activity Coefficient: {0}", ativ(i)))
IObj?.Paragraphs.Add(String.Format("Vapor Pressure (Psat) @ {0} K: {1} Pa", T, Me.AUX_PVAPi(i, T)))
IObj?.Paragraphs.Add(String.Format("Poynting Correction Factor: {0}", poy(i)))
If UseHenryConstants And HasHenryConstants(constprop(i).Name) Then
Dim hc = AUX_KHenry(constprop(i).Name, T)
IObj?.Paragraphs.Add(String.Format("Henry's Constant (H) @ {0} K: {1} Pa", T, hc))
lnfug(i) = Log(ativ(i) * hc / P) + Log(poy(i))
lnfug(i) = Log(hc / P)
Else
lnfug(i) = Log(ativ(i) * Me.AUX_PVAPi(i, T) / (P)) + Log(poy(i))
lnfug(i) = Log(AUX_PVAPi(i, T) / (P))
End If
ElseIf Tr < 0.98 Then
IObj?.Paragraphs.Add("<m>f_i = \gamma_i Poy_i P_{sat_i}/P</m>")
IObj?.Paragraphs.Add(String.Format("Activity Coefficient: {0}", ativ(i)))
IObj?.Paragraphs.Add(String.Format("Vapor Pressure (Psat) @ {0} K: {1} Pa", T, Me.AUX_PVAPi(i, T)))
IObj?.Paragraphs.Add(String.Format("Poynting Correction Factor: {0}", poy(i)))
lnfug(i) = Log(ativ(i) * Me.AUX_PVAPi(i, T) / (P)) + Log(poy(i))
IObj?.Paragraphs.Add(String.Format("Fugacity Coefficient: {0}", Exp(lnfug(i))))
Else 'do interpolation at proximity of critical point
IObj?.SetCurrent()
Expand Down
6 changes: 3 additions & 3 deletions DWSIM.Thermodynamics/PropertyPackages/CoolProp.vb
Original file line number Diff line number Diff line change
Expand Up @@ -1643,9 +1643,6 @@ Namespace PropertyPackages
Dim Tc As Double() = Me.RET_VTC()
For i = 0 To n
If T / Tc(i) >= 1 Then
IObj?.SetCurrent()
fugcoeff(i) = AUX_KHenry(Me.RET_VNAMES(i), T) / P
Else
IObj?.SetCurrent()
If UseHenryConstants And HasHenryConstants(RET_VNAMES(i)) Then
Dim hc = AUX_KHenry(RET_VNAMES(i), T)
Expand All @@ -1654,6 +1651,9 @@ Namespace PropertyPackages
Else
fugcoeff(i) = Me.AUX_PVAPi(i, T) / P
End If
Else
IObj?.SetCurrent()
fugcoeff(i) = Me.AUX_PVAPi(i, T) / P
End If
Next
Else
Expand Down
6 changes: 3 additions & 3 deletions DWSIM.Thermodynamics/PropertyPackages/Ideal.vb
Original file line number Diff line number Diff line change
Expand Up @@ -772,9 +772,6 @@ Namespace PropertyPackages
Dim Tc As Double() = Me.RET_VTC()
For i = 0 To n
If T / Tc(i) >= 1.0 Then
IObj?.SetCurrent()
fugcoeff(i) = AUX_KHenry(Me.RET_VNAMES(i), T) / P
Else
IObj?.SetCurrent()
If UseHenryConstants And HasHenryConstants(RET_VNAMES(i)) Then
Dim hc = AUX_KHenry(RET_VNAMES(i), T)
Expand All @@ -783,6 +780,9 @@ Namespace PropertyPackages
Else
fugcoeff(i) = Me.AUX_PVAPi(i, T) / P
End If
Else
IObj?.SetCurrent()
fugcoeff(i) = Me.AUX_PVAPi(i, T) / P
End If
Next
Else
Expand Down
7 changes: 5 additions & 2 deletions DWSIM.Thermodynamics/PropertyPackages/PropertyPackage.vb
Original file line number Diff line number Diff line change
Expand Up @@ -5327,8 +5327,11 @@ redirect2: IObj?.SetCurrent()
Public Function HasHenryConstants(compname As String) As Boolean

Dim CAS = Me.CurrentMaterialStream.Phases(0).Compounds(compname).ConstantProperties.CAS_Number

Return m_Henry.ContainsKey(CAS)
If CAS <> "" Then
Return m_Henry.ContainsKey(CAS)
Else
Return False
End If

End Function

Expand Down
2 changes: 1 addition & 1 deletion DWSIM.UnitOperations/EditingForms/EditingForm_AirCooler.vb
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ Public Class EditingForm_AirCooler

Sub RequestCalc()

SimObject.FlowSheet.RequestCalculation2(False)
SimObject.FlowSheet.RequestCalculation3(SimObject, False)

End Sub

Expand Down
2 changes: 1 addition & 1 deletion DWSIM.UnitOperations/EditingForms/EditingForm_Column.vb
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ Public Class EditingForm_Column

Sub RequestCalc()

'SimObject.FlowSheet.RequestCalculation2(False)
'SimObject.FlowSheet.RequestCalculation3(SimObject, False)

End Sub

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ Public Class EditingForm_ComprExpndr

Sub RequestCalc()

SimObject.FlowSheet.RequestCalculation2(False)
SimObject.FlowSheet.RequestCalculation3(SimObject, False)

End Sub

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ Public Class EditingForm_EnergyStream

Sub RequestCalc()

SimObject.FlowSheet.RequestCalculation2(False)
SimObject.FlowSheet.RequestCalculation3(SimObject, False)

End Sub

Expand Down
2 changes: 1 addition & 1 deletion DWSIM.UnitOperations/EditingForms/EditingForm_Flowsheet.vb
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ Public Class EditingForm_FlowsheetUO

Sub RequestCalc()

SimObject.FlowSheet.RequestCalculation2(False)
SimObject.FlowSheet.RequestCalculation3(SimObject, False)

End Sub

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ Public Class EditingForm_HeaterCooler

Sub RequestCalc()

SimObject.FlowSheet.RequestCalculation2(False)
SimObject.FlowSheet.RequestCalculation3(SimObject, False)

End Sub

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ Public Class EditingForm_PIDController

Sub RequestCalc()

SimObject.FlowSheet.RequestCalculation2(False)
SimObject.FlowSheet.RequestCalculation3(SimObject, False)

End Sub

Expand Down
2 changes: 1 addition & 1 deletion DWSIM.UnitOperations/EditingForms/EditingForm_Pipe.vb
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ Public Class EditingForm_Pipe

Sub RequestCalc()

SimObject.FlowSheet.RequestCalculation2(False)
SimObject.FlowSheet.RequestCalculation3(SimObject, False)

End Sub

Expand Down
2 changes: 1 addition & 1 deletion DWSIM.UnitOperations/EditingForms/EditingForm_Pump.vb
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ Public Class EditingForm_Pump

Sub RequestCalc()

SimObject.FlowSheet.RequestCalculation2(False)
SimObject.FlowSheet.RequestCalculation3(SimObject, False)

End Sub

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ Public Class EditingForm_ReactorCSTR

Sub RequestCalc()

SimObject.FlowSheet.RequestCalculation2(False)
SimObject.FlowSheet.RequestCalculation3(SimObject, False)

End Sub

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ Public Class EditingForm_ReactorPFR

Sub RequestCalc()

SimObject.FlowSheet.RequestCalculation2(False)
SimObject.FlowSheet.RequestCalculation3(SimObject, False)

End Sub

Expand Down
2 changes: 1 addition & 1 deletion DWSIM.UnitOperations/EditingForms/EditingForm_Splitter.vb
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ Public Class EditingForm_Splitter

Sub RequestCalc()

SimObject.FlowSheet.RequestCalculation2(False)
SimObject.FlowSheet.RequestCalculation3(SimObject, False)

End Sub

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ Public Class EditingForm_SpreadsheetUO

Sub RequestCalc()

SimObject.FlowSheet.RequestCalculation2(False)
SimObject.FlowSheet.RequestCalculation3(SimObject, False)

End Sub

Expand Down
2 changes: 1 addition & 1 deletion DWSIM.UnitOperations/EditingForms/EditingForm_Valve.vb
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ Public Class EditingForm_Valve

Sub RequestCalc()

SimObject.FlowSheet.RequestCalculation2(False)
SimObject.FlowSheet.RequestCalculation3(SimObject, False)

End Sub

Expand Down
6 changes: 6 additions & 0 deletions DWSIM/Forms/Flowsheet/FormFlowsheet.vb
Original file line number Diff line number Diff line change
Expand Up @@ -3295,6 +3295,12 @@ Public Class FormFlowsheet

End Sub

Public Sub RequestCalculation3(obj As ISimulationObject, Wait As Boolean) Implements IFlowsheet.RequestCalculation3

RequestFlowsheetCalculation(obj, Wait)

End Sub

Public Function GetUtility(uttype As Enums.FlowsheetUtility) As IAttachedUtility Implements IFlowsheet.GetUtility
Select Case uttype
Case FlowsheetUtility.NaturalGasHydrates
Expand Down

0 comments on commit 4194e0b

Please sign in to comment.