Skip to content

Commit

Permalink
bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
DanWBR committed Jun 10, 2022
1 parent 5a8438a commit 0942154
Show file tree
Hide file tree
Showing 10 changed files with 1,175 additions and 1,142 deletions.
7 changes: 7 additions & 0 deletions DWSIM.Thermodynamics/FlashAlgorithms/BaseFlashAlgorithm.vb
Original file line number Diff line number Diff line change
Expand Up @@ -1449,6 +1449,13 @@ will converge to this solution.")
End If
Next

For i = 0 To n - 1
If props(i).IsSolid Then
hres.SolidPhase = True
hres.SolidFraction += Vz(i)
End If
Next

If pp.ForcedSolids.Count > 0 Then
'has solids
For Each solid In pp.ForcedSolids
Expand Down
8 changes: 4 additions & 4 deletions DWSIM.Thermodynamics/FlashAlgorithms/UniversalFlash.vb
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ Namespace PropertyPackages.Auxiliary.FlashAlgorithms
If Vsolid(i) Then
Vs(i) = Vz(i)
Else
If Vp(i) > P Then
If Vp(i) < P Then
Vx(i) = Vz(i)
Else
Vy(i) = Vz(i)
Expand All @@ -530,7 +530,7 @@ Namespace PropertyPackages.Auxiliary.FlashAlgorithms
L = Vx.Sum
V = Vy.Sum

Return New Object() {L, V, Vx, Vy, ecount, 0.0#, PP, S, Vs, Ki}
Return New Object() {L, V, Vx, Vy, ecount, 0.0#, PP.RET_NullVector, S, Vs, Ki}

End Function

Expand Down Expand Up @@ -576,7 +576,7 @@ Namespace PropertyPackages.Auxiliary.FlashAlgorithms
If Vsolid(i) Then
Vs(i) = Vz(i)
Else
If Vp(i) > P Then
If Vp(i) < P Then
Vx(i) = Vz(i)
Else
Vy(i) = Vz(i)
Expand Down Expand Up @@ -634,7 +634,7 @@ Namespace PropertyPackages.Auxiliary.FlashAlgorithms
If Vsolid(i) Then
Vs(i) = Vz(i)
Else
If Vp(i) > P Then
If Vp(i) < P Then
Vx(i) = Vz(i)
Else
Vy(i) = Vz(i)
Expand Down
40 changes: 14 additions & 26 deletions DWSIM.Thermodynamics/PropertyPackages/ActivityCoefficientBase.vb
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,7 @@
' You should have received a copy of the GNU General Public License
' along with DWSIM. If not, see <http://www.gnu.org/licenses/>.


Imports System.Runtime.Serialization.Formatters.Binary
Imports System.Runtime.Serialization
Imports System.IO
Imports System.Linq
Imports System.Math
Imports CapeOpen
Imports System.Runtime.InteropServices.ComTypes
Imports iop = System.Runtime.InteropServices
Imports System.Xml.Serialization
Imports System.Runtime.Serialization.Formatters
Imports System.Threading.Tasks
Imports DWSIM.MathOps.MathEx
Imports DWSIM.Interfaces.Enums

Namespace PropertyPackages
Expand Down Expand Up @@ -369,11 +357,11 @@ Namespace PropertyPackages
Case 0 'LK
H = Me.m_lk.H_LK_MIX("L", T, P, Vx, RET_VKij(), RET_VTC, RET_VPC, RET_VW, RET_VMM, Me.RET_Hid(298.15, T, Vx))
Case 1 'Ideal
H = Me.RET_Hid(298.15, T, Vx) - Me.RET_HVAPM(Me.AUX_CONVERT_MOL_TO_MASS(Vx), T) + P / 1000 / Me.AUX_LIQDENS(T, Vx)
H = Me.RET_Hid(298.15, T, Vx) - Me.RET_HVAPM(Me.AUX_CONVERT_MOL_TO_MASS(Vx), T) + P / 1000 / Me.AUX_LIQDENS(T, Vx, P)
Case 2 'Excess
H = Me.RET_Hid(298.15, T, Vx) + P / 1000 / Me.AUX_LIQDENS(T, Vx) - Me.m_act.CalcExcessEnthalpy(T, Vx, Me.GetArguments()) / Me.AUX_MMM(Vx) - Me.RET_HVAPM(Me.AUX_CONVERT_MOL_TO_MASS(Vx), T)
H = Me.RET_Hid(298.15, T, Vx) + P / 1000 / Me.AUX_LIQDENS(T, Vx, P) - Me.m_act.CalcExcessEnthalpy(T, Vx, Me.GetArguments()) / Me.AUX_MMM(Vx) - Me.RET_HVAPM(Me.AUX_CONVERT_MOL_TO_MASS(Vx), T)
Case 3 'Experimental Liquid
H = AUX_INT_CPDTm_L(298.15, T, Me.AUX_CONVERT_MOL_TO_MASS(Vx)) + P / 1000 / Me.AUX_LIQDENS(T, Vx)
H = AUX_INT_CPDTm_L(298.15, T, Me.AUX_CONVERT_MOL_TO_MASS(Vx)) + P / 1000 / Me.AUX_LIQDENS(T, Vx, P)
End Select
ElseIf st = State.Vapor Then
Select Case EnthalpyEntropyCpCvCalculationMode
Expand All @@ -384,7 +372,7 @@ Namespace PropertyPackages
Case 2 'Excess
H = Me.RET_Hid(298.15, T, Vx)
Case 3 'Experimental Liquid
H = AUX_INT_CPDTm_L(298.15, T, Me.AUX_CONVERT_MOL_TO_MASS(Vx)) + P / 1000 / Me.AUX_LIQDENS(T, Vx) + Me.RET_HVAPM(Me.AUX_CONVERT_MOL_TO_MASS(Vx), T)
H = AUX_INT_CPDTm_L(298.15, T, Me.AUX_CONVERT_MOL_TO_MASS(Vx)) + P / 1000 / Me.AUX_LIQDENS(T, Vx, P) + Me.RET_HVAPM(Me.AUX_CONVERT_MOL_TO_MASS(Vx), T)
End Select
ElseIf st = State.Solid Then
If SolidPhaseEnthalpy_UsesCp Then
Expand All @@ -394,11 +382,11 @@ Namespace PropertyPackages
Case 0 'LK
H = Me.m_lk.H_LK_MIX("L", T, P, Vx, RET_VKij(), RET_VTC, RET_VPC, RET_VW, RET_VMM, Me.RET_Hid(298.15, T, Vx)) - RET_HFUSM(Me.AUX_CONVERT_MOL_TO_MASS(Vx), T)
Case 1 'Ideal
H = Me.RET_Hid(298.15, T, Vx) + P / 1000 / Me.AUX_LIQDENS(T, Vx) - Me.RET_HVAPM(Me.AUX_CONVERT_MOL_TO_MASS(Vx), T) - RET_HFUSM(Me.AUX_CONVERT_MOL_TO_MASS(Vx), T)
H = Me.RET_Hid(298.15, T, Vx) + P / 1000 / Me.AUX_LIQDENS(T, Vx, P) - Me.RET_HVAPM(Me.AUX_CONVERT_MOL_TO_MASS(Vx), T) - RET_HFUSM(Me.AUX_CONVERT_MOL_TO_MASS(Vx), T)
Case 2 'Excess
H = Me.RET_Hid(298.15, T, Vx) + P / 1000 / Me.AUX_LIQDENS(T, Vx) - Me.m_act.CalcExcessEnthalpy(T, Vx, Me.GetArguments()) / Me.AUX_MMM(Vx) - Me.RET_HVAPM(Me.AUX_CONVERT_MOL_TO_MASS(Vx), T) - RET_HFUSM(Me.AUX_CONVERT_MOL_TO_MASS(Vx), T)
H = Me.RET_Hid(298.15, T, Vx) + P / 1000 / Me.AUX_LIQDENS(T, Vx, P) - Me.m_act.CalcExcessEnthalpy(T, Vx, Me.GetArguments()) / Me.AUX_MMM(Vx) - Me.RET_HVAPM(Me.AUX_CONVERT_MOL_TO_MASS(Vx), T) - RET_HFUSM(Me.AUX_CONVERT_MOL_TO_MASS(Vx), T)
Case 3 'Experimental Liquid
H = AUX_INT_CPDTm_L(298.15, T, Me.AUX_CONVERT_MOL_TO_MASS(Vx)) + P / 1000 / Me.AUX_LIQDENS(T, Vx) - RET_HFUSM(Me.AUX_CONVERT_MOL_TO_MASS(Vx), T)
H = AUX_INT_CPDTm_L(298.15, T, Me.AUX_CONVERT_MOL_TO_MASS(Vx)) + P / 1000 / Me.AUX_LIQDENS(T, Vx, P) - RET_HFUSM(Me.AUX_CONVERT_MOL_TO_MASS(Vx), T)
End Select
End If
End If
Expand Down Expand Up @@ -459,11 +447,11 @@ Namespace PropertyPackages
Case 0 'LK
S = Me.m_lk.S_LK_MIX("L", T, P, Vx, RET_VKij(), RET_VTC, RET_VPC, RET_VW, RET_VMM, Me.RET_Sid(298.15, T, P, Vx))
Case 1 'Ideal
S = Me.RET_Sid(298.15, T, P, Vx) - Me.RET_HVAPM(Me.AUX_CONVERT_MOL_TO_MASS(Vx), T) / T + P / 1000 / Me.AUX_LIQDENS(T, Vx) / T
S = Me.RET_Sid(298.15, T, P, Vx) - Me.RET_HVAPM(Me.AUX_CONVERT_MOL_TO_MASS(Vx), T) / T + P / 1000 / Me.AUX_LIQDENS(T, Vx, P) / T
Case 2 'Excess
S = Me.RET_Sid(298.15, T, P, Vx) - Me.m_act.CalcExcessEnthalpy(T, Vx, Me.GetArguments()) / Me.AUX_MMM(Vx) / T + P / 1000 / Me.AUX_LIQDENS(T, Vx) / T - Me.RET_HVAPM(Me.AUX_CONVERT_MOL_TO_MASS(Vx), T) / T
S = Me.RET_Sid(298.15, T, P, Vx) - Me.m_act.CalcExcessEnthalpy(T, Vx, Me.GetArguments()) / Me.AUX_MMM(Vx) / T + P / 1000 / Me.AUX_LIQDENS(T, Vx, P) / T - Me.RET_HVAPM(Me.AUX_CONVERT_MOL_TO_MASS(Vx), T) / T
Case 3 'Experimental Liquid
S = AUX_INT_CPDTm_L(298.15, T, Me.AUX_CONVERT_MOL_TO_MASS(Vx)) / T + P / 1000 / Me.AUX_LIQDENS(T, Vx) / T
S = AUX_INT_CPDTm_L(298.15, T, Me.AUX_CONVERT_MOL_TO_MASS(Vx)) / T + P / 1000 / Me.AUX_LIQDENS(T, Vx, P) / T
End Select
ElseIf st = State.Vapor Then
Select Case EnthalpyEntropyCpCvCalculationMode
Expand All @@ -474,7 +462,7 @@ Namespace PropertyPackages
Case 2 'Excess
S = Me.RET_Sid(298.15, T, P, Vx)
Case 3 'Experimental Liquid
S = AUX_INT_CPDTm_L(298.15, T, Me.AUX_CONVERT_MOL_TO_MASS(Vx)) / T + Me.RET_HVAPM(Me.AUX_CONVERT_MOL_TO_MASS(Vx), T) / T + P / 1000 / Me.AUX_LIQDENS(T, Vx) / T
S = AUX_INT_CPDTm_L(298.15, T, Me.AUX_CONVERT_MOL_TO_MASS(Vx)) / T + Me.RET_HVAPM(Me.AUX_CONVERT_MOL_TO_MASS(Vx), T) / T + P / 1000 / Me.AUX_LIQDENS(T, Vx, P) / T
End Select
ElseIf st = State.Solid Then
If SolidPhaseEnthalpy_UsesCp Then
Expand All @@ -484,11 +472,11 @@ Namespace PropertyPackages
Case 0 'LK
S = Me.m_lk.S_LK_MIX("L", T, P, Vx, RET_VKij(), RET_VTC, RET_VPC, RET_VW, RET_VMM, Me.RET_Sid(298.15, T, P, Vx)) - Me.RET_HFUSM(Me.AUX_CONVERT_MOL_TO_MASS(Vx), T) / T
Case 1 'Ideal
S = Me.RET_Sid(298.15, T, P, Vx) + P / 1000 / Me.AUX_LIQDENS(T, Vx) / T - Me.RET_HVAPM(Me.AUX_CONVERT_MOL_TO_MASS(Vx), T) / T - Me.RET_HFUSM(Me.AUX_CONVERT_MOL_TO_MASS(Vx), T) / T
S = Me.RET_Sid(298.15, T, P, Vx) + P / 1000 / Me.AUX_LIQDENS(T, Vx, P) / T - Me.RET_HVAPM(Me.AUX_CONVERT_MOL_TO_MASS(Vx), T) / T - Me.RET_HFUSM(Me.AUX_CONVERT_MOL_TO_MASS(Vx), T) / T
Case 2 'Excess
S = Me.RET_Sid(298.15, T, P, Vx) + P / 1000 / Me.AUX_LIQDENS(T, Vx) / T - Me.m_act.CalcExcessEnthalpy(T, Vx, Me.GetArguments()) / Me.AUX_MMM(Vx) / T - Me.RET_HVAPM(Me.AUX_CONVERT_MOL_TO_MASS(Vx), T) / T - Me.RET_HFUSM(Me.AUX_CONVERT_MOL_TO_MASS(Vx), T) / T
S = Me.RET_Sid(298.15, T, P, Vx) + P / 1000 / Me.AUX_LIQDENS(T, Vx, P) / T - Me.m_act.CalcExcessEnthalpy(T, Vx, Me.GetArguments()) / Me.AUX_MMM(Vx) / T - Me.RET_HVAPM(Me.AUX_CONVERT_MOL_TO_MASS(Vx), T) / T - Me.RET_HFUSM(Me.AUX_CONVERT_MOL_TO_MASS(Vx), T) / T
Case 3 'Experimental Liquid
S = AUX_INT_CPDTm_L(298.15, T, Me.AUX_CONVERT_MOL_TO_MASS(Vx)) / T - RET_HFUSM(Me.AUX_CONVERT_MOL_TO_MASS(Vx), T) / T + P / 1000 / Me.AUX_LIQDENS(T, Vx) / T
S = AUX_INT_CPDTm_L(298.15, T, Me.AUX_CONVERT_MOL_TO_MASS(Vx)) / T - RET_HFUSM(Me.AUX_CONVERT_MOL_TO_MASS(Vx), T) / T + P / 1000 / Me.AUX_LIQDENS(T, Vx, P) / T
End Select
End If
End If
Expand Down
8 changes: 4 additions & 4 deletions DWSIM.Thermodynamics/PropertyPackages/Ideal.vb
Original file line number Diff line number Diff line change
Expand Up @@ -613,14 +613,14 @@ Namespace PropertyPackages
Dim H As Double

If st = State.Liquid Then
H = Me.m_id.H_RA_MIX("L", T, P, Vx, RET_VKij(), RET_VTC, RET_VPC, RET_VW, RET_VMM, Me.RET_Hid(298.15, T, Vx), Me.RET_VHVAP(T)) + P / 1000 / Me.AUX_LIQDENS(T, Vx)
H = Me.m_id.H_RA_MIX("L", T, P, Vx, RET_VKij(), RET_VTC, RET_VPC, RET_VW, RET_VMM, Me.RET_Hid(298.15, T, Vx), Me.RET_VHVAP(T)) + P / 1000 / Me.AUX_LIQDENS(T, Vx, P)
ElseIf st = State.Vapor Then
H = Me.m_id.H_RA_MIX("V", T, P, Vx, RET_VKij(), RET_VTC, RET_VPC, RET_VW, RET_VMM, Me.RET_Hid(298.15, T, Vx), Me.RET_VHVAP(T))
ElseIf st = State.Solid Then
If SolidPhaseEnthalpy_UsesCp Then
H = CalcSolidEnthalpyFromCp(T, Vx, DW_GetConstantProperties)
Else
H = Me.m_id.H_RA_MIX("L", T, P, Vx, RET_VKij(), RET_VTC, RET_VPC, RET_VW, RET_VMM, Me.RET_Hid(298.15, T, Vx), Me.RET_VHVAP(T)) + P / 1000 / Me.AUX_LIQDENS(T, Vx) - Me.RET_HFUSM(AUX_CONVERT_MOL_TO_MASS(Vx), T)
H = Me.m_id.H_RA_MIX("L", T, P, Vx, RET_VKij(), RET_VTC, RET_VPC, RET_VW, RET_VMM, Me.RET_Hid(298.15, T, Vx), Me.RET_VHVAP(T)) + P / 1000 / Me.AUX_LIQDENS(T, Vx, P) - Me.RET_HFUSM(AUX_CONVERT_MOL_TO_MASS(Vx), T)
End If
End If

Expand Down Expand Up @@ -699,14 +699,14 @@ Namespace PropertyPackages
Dim S As Double

If st = State.Liquid Then
S = Me.m_id.S_RA_MIX("L", T, P, Vx, RET_VKij(), RET_VTC, RET_VPC, RET_VW, RET_VMM, Me.RET_Sid(298.15, T, P, Vx), Me.RET_VHVAP(T)) + P / 1000 / Me.AUX_LIQDENS(T, Vx) / T
S = Me.m_id.S_RA_MIX("L", T, P, Vx, RET_VKij(), RET_VTC, RET_VPC, RET_VW, RET_VMM, Me.RET_Sid(298.15, T, P, Vx), Me.RET_VHVAP(T)) + P / 1000 / Me.AUX_LIQDENS(T, Vx, P) / T
ElseIf st = State.Vapor Then
S = Me.m_id.S_RA_MIX("V", T, P, Vx, RET_VKij(), RET_VTC, RET_VPC, RET_VW, RET_VMM, Me.RET_Sid(298.15, T, P, Vx), Me.RET_VHVAP(T))
ElseIf st = State.Solid Then
If SolidPhaseEnthalpy_UsesCp Then
S = CalcSolidEnthalpyFromCp(T, Vx, DW_GetConstantProperties) / T
Else
S = Me.m_id.S_RA_MIX("L", T, P, Vx, RET_VKij(), RET_VTC, RET_VPC, RET_VW, RET_VMM, Me.RET_Sid(298.15, T, P, Vx), Me.RET_VHVAP(T)) + P / 1000 / Me.AUX_LIQDENS(T, Vx) / T - Me.RET_HFUSM(AUX_CONVERT_MOL_TO_MASS(Vx), T) / T
S = Me.m_id.S_RA_MIX("L", T, P, Vx, RET_VKij(), RET_VTC, RET_VPC, RET_VW, RET_VMM, Me.RET_Sid(298.15, T, P, Vx), Me.RET_VHVAP(T)) + P / 1000 / Me.AUX_LIQDENS(T, Vx, P) / T - Me.RET_HFUSM(AUX_CONVERT_MOL_TO_MASS(Vx), T) / T
End If
End If

Expand Down
28 changes: 28 additions & 0 deletions DWSIM/Forms/CompoundCreator/FormCreateNewSolid.en.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="mscorlib" name="mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="TextBoxMW.TabIndex" type="System.Int32, mscorlib">
<value>2</value>
</data>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="Label22.Size" type="System.Drawing.Size, System.Drawing">
<value>90, 13</value>
Expand All @@ -127,21 +131,33 @@
<data name="Label17.Text" xml:space="preserve">
<value>Name</value>
</data>
<data name="TextBoxName.TabIndex" type="System.Int32, mscorlib">
<value>0</value>
</data>
<data name="Label50.Size" type="System.Drawing.Size, System.Drawing">
<value>194, 13</value>
</data>
<data name="Label50.Text" xml:space="preserve">
<value>Ideal Gas Enthalpy of Formation (298 K)</value>
</data>
<data name="TextBoxDHF.TabIndex" type="System.Int32, mscorlib">
<value>5</value>
</data>
<data name="Label53.Size" type="System.Drawing.Size, System.Drawing">
<value>216, 13</value>
</data>
<data name="Label53.Text" xml:space="preserve">
<value>Ideal Gas Gibbs Energy of Formation (298 K)</value>
</data>
<data name="TextBoxDGF.TabIndex" type="System.Int32, mscorlib">
<value>6</value>
</data>
<data name="TextBoxCp.Size" type="System.Drawing.Size, System.Drawing">
<value>96, 20</value>
</data>
<data name="TextBoxCp.TabIndex" type="System.Int32, mscorlib">
<value>4</value>
</data>
<data name="TextBoxCp.Text" xml:space="preserve">
<value>0</value>
</data>
Expand All @@ -164,6 +180,9 @@
<data name="TextBoxDensity.Size" type="System.Drawing.Size, System.Drawing">
<value>96, 20</value>
</data>
<data name="TextBoxDensity.TabIndex" type="System.Int32, mscorlib">
<value>3</value>
</data>
<data name="TextBoxDensity.Text" xml:space="preserve">
<value>0</value>
</data>
Expand All @@ -179,15 +198,24 @@
<data name="Label2.Text" xml:space="preserve">
<value>Ideal Gas Formation Data is optional and must be entered only if the compound is reactive.</value>
</data>
<data name="Button1.TabIndex" type="System.Int32, mscorlib">
<value>8</value>
</data>
<data name="Button1.Text" xml:space="preserve">
<value>Export to JSON File</value>
</data>
<data name="Button2.TabIndex" type="System.Int32, mscorlib">
<value>7</value>
</data>
<data name="Button2.Text" xml:space="preserve">
<value>Cancel</value>
</data>
<data name="Label6.Text" xml:space="preserve">
<value>Formula</value>
</data>
<data name="TextBoxFormula.TabIndex" type="System.Int32, mscorlib">
<value>1</value>
</data>
<data name="$this.Text" xml:space="preserve">
<value>Quick Create New Solid Compound</value>
</data>
Expand Down
Loading

0 comments on commit 0942154

Please sign in to comment.