-
-
Notifications
You must be signed in to change notification settings - Fork 89
/
FormCompoundCreator.vb
3595 lines (3051 loc) · 158 KB
/
FormCompoundCreator.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Imports com.ggasoftware.indigo
'http://www.ggasoftware.com/opensource/indigo
' Copyright 2011 Daniel Wagner O. de Medeiros
' 2013 Gregor Reichert
' This file is part of DWSIM.
'
' DWSIM is free software: you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation, either version 3 of the License, or
' (at your option) any later version.
'
' DWSIM is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' GNU General Public License for more details.
'
' You should have received a copy of the GNU General Public License
' along with DWSIM. If not, see <http://www.gnu.org/licenses/>.
Imports DWSIM.Thermodynamics.PropertyPackages.Auxiliary
Imports DWSIM.Thermodynamics.Utilities.Hypos.Methods
Imports DWSIM.MathOps.MathEx.Common
Imports System.IO
Imports System.Runtime.Serialization.Formatters.Binary
Imports System.Math
Imports Microsoft.VisualBasic.FileIO
Imports System.Globalization
Imports DWSIM.Simulate365.Models
Imports DWSIM.Interfaces
Imports DWSIM.SharedClassesCSharp.FilePicker
Public Class FormCompoundCreator
Inherits Form
Public su As New SystemsOfUnits.Units
Public nf As String
Public methods As HYP
Public jb As New Joback
Friend m_props As PROPS
Public mycase As New CompoundGeneratorCase
Public simulate365File As S365File = Nothing
Friend loaded As Boolean = False
Friend PureUNIFACCompound As Boolean = True
Friend isDWSimSaved As Boolean = True
Friend isUserDBSaved As Boolean = True
Private forceclose As Boolean = False
Private populating As Boolean = False
Private UNIFAClines, MODFACLines, JOBACKlines, ElementLines As New List(Of String)
Private Sub FormCompoundCreator_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ExtensionMethods.ChangeDefaultFont(Me)
Me.MenuStrip1.Visible = False
graphCPIG.GraphPane.Border.IsVisible = False
graphLIQCP.GraphPane.Border.IsVisible = False
graphLIQDENS.GraphPane.Border.IsVisible = False
graphLIQTC.GraphPane.Border.IsVisible = False
graphLIQVISC.GraphPane.Border.IsVisible = False
graphPVAP.GraphPane.Border.IsVisible = False
graphSOLIDCP.GraphPane.Border.IsVisible = False
graphSOLIDDENS.GraphPane.Border.IsVisible = False
'Grid UNIFAC
Dim pathsep = System.IO.Path.DirectorySeparatorChar
Dim picpath As String = My.Application.Info.DirectoryPath & pathsep & "data" & pathsep & "unifac" & pathsep
Dim i As Integer
Dim ID, GroupType, GroupName, S, TT As String
Dim L As Boolean = True
Using filestr As IO.Stream = System.Reflection.Assembly.GetAssembly(jb.GetType).GetManifestResourceStream("DWSIM.Thermodynamics.unifac.txt")
Using parser As New TextFieldParser(filestr)
While Not parser.EndOfData
UNIFAClines.Add(parser.ReadLine())
End While
End Using
End Using
L = True
GroupName = UNIFAClines(2).Split(",")(2)
With Me.GridUNIFAC.Rows
.Clear()
For i = 2 To UNIFAClines.Count - 1
S = picpath & UNIFAClines(i).Split(",")(7) & ".png"
If Not My.Computer.FileSystem.FileExists(S) Then S = picpath & "Empty.png"
.Add(New Object() {" ", " ", CInt(0), Image.FromFile(S)})
.Item(.Count - 1).HeaderCell.Value = "ID " & UNIFAClines(i).Split(",")(1) 'SubGroup
.Item(.Count - 1).Cells(0).Value = UNIFAClines(i).Split(",")(2) 'MainGroup
.Item(.Count - 1).Cells(1).Value = UNIFAClines(i).Split(",")(3) 'SubGroup
TT = "Rk / Qk: " & UNIFAClines(i).Split(",")(4) & " / " & UNIFAClines(i).Split(",")(5) & vbCrLf &
"Example Compound: " & UNIFAClines(i).Split(",")(6) & vbCrLf &
"Joback subgroups: " & UNIFAClines(i).Split(",")(8)
.Item(.Count - 1).Cells(3).Tag = {S, TT, UNIFAClines(i).Split(",")(1)}
If GroupName <> UNIFAClines(i).Split(",")(2) Then
L = Not L
GroupName = UNIFAClines(i).Split(",")(2)
End If
If L Then
.Item(.Count - 1).Cells(0).Style.BackColor = Color.FromArgb(230, 230, 200)
.Item(.Count - 1).Cells(1).Style.BackColor = Color.FromArgb(230, 230, 200)
Else
.Item(.Count - 1).Cells(0).Style.BackColor = Color.FromArgb(200, 230, 230)
.Item(.Count - 1).Cells(1).Style.BackColor = Color.FromArgb(200, 230, 230)
End If
Next
End With
'Grid MODFAC
L = True
Using filestr As IO.Stream = System.Reflection.Assembly.GetAssembly(jb.GetType).GetManifestResourceStream("DWSIM.Thermodynamics.modfac.txt")
Using parser As New TextFieldParser(filestr)
While Not parser.EndOfData
MODFACLines.Add(parser.ReadLine())
End While
End Using
End Using
Dim cult As Globalization.CultureInfo = New Globalization.CultureInfo("en-US")
Dim fields As String()
Dim delimiter As String = ";"
Dim maingroup As Integer = 1
Dim mainname As String = ""
Me.GridMODFAC.Rows.Clear()
Using filestr As IO.Stream = System.Reflection.Assembly.GetAssembly(jb.GetType).GetManifestResourceStream("DWSIM.Thermodynamics.modfac.txt")
Using parser As New TextFieldParser(filestr)
parser.SetDelimiters(delimiter)
parser.ReadLine()
While Not parser.EndOfData
fields = parser.ReadFields()
With Me.GridMODFAC.Rows
S = picpath & fields(6) & ".png"
If Not My.Computer.FileSystem.FileExists(S) Then S = picpath & "Empty.png"
.Add(New Object() {CInt(0), CInt(0), CInt(0), Image.FromFile(S)})
.Item(.Count - 1).HeaderCell.Value = "ID " & fields(3)
.Item(.Count - 1).Cells(0).Value = fields(1)
.Item(.Count - 1).Cells(1).Value = fields(2)
.Item(.Count - 1).Cells(2).Value = 0
TT = "Rk / Qk: " & fields(4) & " / " & fields(5) & vbCrLf &
"Example Compound: " & fields(6) & vbCrLf & fields(7)
.Item(.Count - 1).Cells(3).Tag = {S, TT, fields(3)}
If L Then
.Item(.Count - 1).Cells(0).Style.BackColor = Color.FromArgb(230, 230, 200)
.Item(.Count - 1).Cells(1).Style.BackColor = Color.FromArgb(230, 230, 200)
Else
.Item(.Count - 1).Cells(0).Style.BackColor = Color.FromArgb(200, 230, 230)
.Item(.Count - 1).Cells(1).Style.BackColor = Color.FromArgb(200, 230, 230)
End If
End With
End While
End Using
End Using
'Grid NIST-MODFAC
L = True
Using filestr As IO.Stream = System.Reflection.Assembly.GetAssembly(jb.GetType).GetManifestResourceStream("DWSIM.Thermodynamics.NIST-MODFAC_RiQi.txt")
Using parser As New TextFieldParser(filestr)
While Not parser.EndOfData
MODFACLines.Add(parser.ReadLine())
End While
End Using
End Using
delimiter = vbTab
Me.GridNISTMODFAC.Rows.Clear()
Using filestr As IO.Stream = System.Reflection.Assembly.GetAssembly(jb.GetType).GetManifestResourceStream("DWSIM.Thermodynamics.NIST-MODFAC_RiQi.txt")
Using parser As New TextFieldParser(filestr)
parser.SetDelimiters(delimiter)
parser.ReadLine()
parser.ReadLine()
While Not parser.EndOfData
fields = parser.ReadFields()
If fields(0).StartsWith("(") Then
maingroup = fields(0).Split(")")(0).Substring(1)
mainname = fields(0).Trim().Split(")")(1).Trim
L = Not L
Else
With Me.GridNISTMODFAC.Rows
S = picpath & fields(4) & ".png"
If Not My.Computer.FileSystem.FileExists(S) Then S = picpath & "Empty.png"
.Add(New Object() {CInt(0), CInt(0), CInt(0), Image.FromFile(S)})
.Item(.Count - 1).HeaderCell.Value = "ID " & fields(0)
.Item(.Count - 1).Cells(0).Value = mainname
.Item(.Count - 1).Cells(1).Value = fields(1)
.Item(.Count - 1).Cells(2).Value = 0
TT = "Rk / Qk: " & fields(2) & " / " & fields(3) & vbCrLf &
"Example Compound: " & fields(4) & vbCrLf & fields(5)
.Item(.Count - 1).Cells(3).Tag = {S, TT, fields(0)}
If L Then
.Item(.Count - 1).Cells(0).Style.BackColor = Color.FromArgb(230, 230, 200)
.Item(.Count - 1).Cells(1).Style.BackColor = Color.FromArgb(230, 230, 200)
Else
.Item(.Count - 1).Cells(0).Style.BackColor = Color.FromArgb(200, 230, 230)
.Item(.Count - 1).Cells(1).Style.BackColor = Color.FromArgb(200, 230, 230)
End If
End With
End If
End While
End Using
End Using
'Grid Joback
Using filestr As IO.Stream = System.Reflection.Assembly.GetAssembly(jb.GetType).GetManifestResourceStream("DWSIM.Thermodynamics.JobackGroups.txt")
Using parser As New TextFieldParser(filestr)
While Not parser.EndOfData
JOBACKlines.Add(parser.ReadLine())
End While
End Using
End Using
GroupType = ""
With Me.GridJoback.Rows
.Clear()
For i = 1 To JOBACKlines.Count - 1
ID = JOBACKlines(i).Split(";")(0)
If Not ID = "X" Then
.Add(New Object())
.Item(.Count - 1).HeaderCell.Value = "ID " & ID
.Item(.Count - 1).Cells(0).Value = GroupType
GroupName = JOBACKlines(i).Split(";")(1)
.Item(.Count - 1).Cells(1).Value = GroupName
If L Then
.Item(.Count - 1).Cells(0).Style.BackColor = Color.FromArgb(200, 230, 230)
Else
.Item(.Count - 1).Cells(0).Style.BackColor = Color.FromArgb(230, 230, 200)
End If
Else
GroupType = JOBACKlines(i).Split(";")(1)
L = Not L
End If
Next
End With
'Grid addition Elements
Using filestr As IO.Stream = System.Reflection.Assembly.GetAssembly(jb.GetType).GetManifestResourceStream("DWSIM.Thermodynamics.Elements.txt")
Using parser As New TextFieldParser(filestr)
While Not parser.EndOfData
ElementLines.Add(parser.ReadLine())
End While
End Using
End Using
With Me.AddAtomDataGrid.Rows
.Clear()
For i = 1 To ElementLines.Count - 1
.Add(New Object())
.Item(.Count - 1).Cells(0).Value = ElementLines(i).Split(";")(2)
.Item(.Count - 1).Cells(0).ToolTipText = "Element # " & ElementLines(i).Split(";")(0) & vbCrLf &
ElementLines(i).Split(";")(1) & vbCrLf & "MW: " & ElementLines(i).Split(";")(3)
Next
End With
With mycase
.cp.VaporPressureEquation = 0
.cp.IdealgasCpEquation = 0
.cp.LiquidHeatCapacityEquation = 0
.cp.LiquidDensityEquation = 0
.cp.LiquidViscosityEquation = 0
.cp.LiquidThermalConductivityEquation = 0
End With
cbEqPVAP.SelectedIndex = 0
cbEqCPIG.SelectedIndex = 0
cbEqCPLiquid.SelectedIndex = 0
cbEqLIQDENS.SelectedIndex = 0
cbEqLIQVISC.SelectedIndex = 0
cbEqSolidDENS.SelectedIndex = 0
cbEqCpS.SelectedIndex = 0
cbEqTCLiquid.SelectedIndex = 0
Me.cbUnits.Items.Clear()
For Each su2 In CType(Me.MdiParent, FormMain).AvailableUnitSystems.Values
Me.cbUnits.Items.Add(su2.Name)
Next
Me.cbUnits.SelectedIndex = 0
Me.TextBoxID.Text = New Random().Next(100000)
UpdateUnits()
End Sub
Private Sub FormCompoundCreator_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
Dim x = MessageBox.Show(DWSIM.App.GetLocalString("Desejasalvarasaltera"), DWSIM.App.GetLocalString("Fechando") & " " & Me.Text, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question)
If x = MsgBoxResult.Yes Then
FormMain.SaveFile(False)
ElseIf x = MsgBoxResult.Cancel Then
FormMain.CancelClosing = True
e.Cancel = True
End If
End Sub
Sub WriteData()
Dim i As Integer
With mycase
Me.Text = .Filename
If .su.temperature IsNot Nothing Then
Me.su = .su
If Not CType(Me.MdiParent, FormMain).AvailableUnitSystems.ContainsKey(.su.Name) Then
If Not TypeOf .su Is SystemsOfUnits.SI And Not _
TypeOf .su Is SystemsOfUnits.CGS And Not _
TypeOf .su Is SystemsOfUnits.English Then
CType(Me.MdiParent, FormMain).AvailableUnitSystems.Add(.su.Name, .su)
End If
Me.cbUnits.Items.Add(mycase.su.Name)
Else
UpdateUnits()
End If
Else
.su = Me.su
End If
If cbUnits.Items.Contains(.su.Name) Then
cbUnits.SelectedIndex = cbUnits.Items.IndexOf(.su.Name)
Else
cbUnits.SelectedIndex = 0
End If
UpdateUnits()
tsmiIgnoreUnsupportedGroups.Checked = .IgnoreUnsupportedGroups
TextBoxID.Text = .cp.ID
TextBoxName.Text = .cp.Name
TextBoxComments.Text = .cp.Comments
CheckBoxMW.Checked = .CalcMW
CheckBoxNBP.Checked = .CalcNBP
CheckBoxAF.Checked = .CalcAF
CheckBoxCSAF.Checked = .CalcCSAF
CheckBoxCSLV.Checked = .CalcCSMV
CheckBoxCSSP.Checked = .CalcCSSP
CheckBoxTc.Checked = .CalcTC
CheckBoxPc.Checked = .CalcPC
CheckBoxZc.Checked = .CalcZC
CheckBoxZRa.Checked = .CalcZRA
CheckBoxDHF.Checked = .CalcHF
CheckBoxDGF.Checked = .CalcGF
CheckBoxMeltingTemp.Checked = .CalcMP
CheckBoxEnthOfFusion.Checked = .CalcEM
'tbDBPath.Text = .database
TextBoxAF.Text = .cp.Acentric_Factor
TextBoxCAS.Text = .cp.CAS_Number
TextBoxCSAF.Text = .cp.Chao_Seader_Acentricity
TextBoxCSLV.Text = .cp.Chao_Seader_Liquid_Molar_Volume
TextBoxCSSP.Text = .cp.Chao_Seader_Solubility_Parameter
TextBoxDGF.Text = SystemsOfUnits.Converter.ConvertFromSI(su.enthalpy, .cp.IG_Gibbs_Energy_of_Formation_25C).ToString("N2")
TextBoxDHF.Text = SystemsOfUnits.Converter.ConvertFromSI(su.enthalpy, .cp.IG_Enthalpy_of_Formation_25C).ToString("N2")
TextBoxFormula.Text = .cp.Formula
TextBoxMW.Text = .cp.Molar_Weight
TextBoxNBP.Text = SystemsOfUnits.Converter.ConvertFromSI(su.temperature, .cp.Normal_Boiling_Point)
TextBoxPc.Text = SystemsOfUnits.Converter.ConvertFromSI(su.pressure, .cp.Critical_Pressure)
TextBoxUNIQUAC_Q.Text = .cp.UNIQUAC_Q
TextBoxUNIQUAC_R.Text = .cp.UNIQUAC_R
TextBoxTc.Text = SystemsOfUnits.Converter.ConvertFromSI(su.temperature, .cp.Critical_Temperature)
TextBoxVTCPR.Text = .cp.PR_Volume_Translation_Coefficient
TextBoxVTCSRK.Text = .cp.SRK_Volume_Translation_Coefficient
TextBoxZc.Text = .cp.Critical_Compressibility
TextBoxZRa.Text = .cp.Z_Rackett
TextBoxMeltingTemp.Text = SystemsOfUnits.Converter.ConvertFromSI(su.temperature, .cp.TemperatureOfFusion)
TextBoxEnthOfFusion.Text = SystemsOfUnits.Converter.ConvertFromSI(su.enthalpy, .cp.EnthalpyOfFusionAtTf)
TextBoxSMILES.Text = .cp.SMILES
If Not .cp.SMILES = "" Then
RenderSMILES()
End If
If .RegressPVAP Then rbRegressPVAP.Checked = True
If .RegressCPIG Then rbRegressCPIG.Checked = True
If .RegressCPLiquid Then rbRegressCPLiquid.Checked = True
If .RegressLDENS Then rbRegressLIQDENS.Checked = True
If .RegressLVISC Then rbRegressLIQVISC.Checked = True
If .RegressCpS Then rbRegressSolidCp.Checked = True
If .RegressRoS Then rbRegressSolidDens.Checked = True
If .RegressLTC Then rbRegressTCLiquid.Checked = True
If .EqPVAP Then rbCoeffPVAP.Checked = True
If .EqCPIG Then rbCoeffCPIG.Checked = True
If .EqCPLiquid Then rbCoeffCPLiquid.Checked = True
If .EqLDENS Then rbCoeffLIQDENS.Checked = True
If .EqLVISC Then rbCoeffLIQVISC.Checked = True
If .EqCpS Then rbCoeffSolidCp.Checked = True
If .EqSDens Then rbCoeffSolidDens.Checked = True
If .EqLTC Then rbCoeffTCLiquid.Checked = True
AtomDataGrid.Rows.Clear()
For i = 0 To .cp.Elements.Count - 1
AtomDataGrid.Rows.Add(New Object() { .cp.Elements.GetKey(i), .cp.Elements.GetByIndex(i)})
Next
If Integer.TryParse(.cp.VaporPressureEquation, New Integer) Then
For Each it As Object In cbEqPVAP.Items
If it.ToString.Split(":")(0) = .cp.VaporPressureEquation Then
cbEqPVAP.SelectedIndex = cbEqPVAP.Items.IndexOf(it)
Exit For
End If
Next
Else
cbEqPVAP.SelectedIndex = cbEqPVAP.Items.Count - 1
tbUserDefEqPVAP.Text = .cp.VaporPressureEquation
End If
If Integer.TryParse(.cp.IdealgasCpEquation, New Integer) Then
For Each it As Object In cbEqCPIG.Items
If it.ToString.Split(":")(0) = .cp.IdealgasCpEquation Then
cbEqCPIG.SelectedIndex = cbEqCPIG.Items.IndexOf(it)
Exit For
End If
Next
Else
cbEqCPIG.SelectedIndex = cbEqCPIG.Items.Count - 1
tbUserDefCPIGEq.Text = .cp.IdealgasCpEquation
End If
If Integer.TryParse(.cp.LiquidHeatCapacityEquation, New Integer) Then
For Each it As Object In cbEqCPLiquid.Items
If it.ToString.Split(":")(0) = .cp.LiquidHeatCapacityEquation Then
cbEqCPLiquid.SelectedIndex = cbEqCPLiquid.Items.IndexOf(it)
Exit For
End If
Next
Else
cbEqCPLiquid.SelectedIndex = cbEqCPLiquid.Items.Count - 1
tbUserDefCPLEq.Text = .cp.LiquidHeatCapacityEquation
End If
If Integer.TryParse(.cp.LiquidDensityEquation, New Integer) Then
For Each it As Object In cbEqLIQDENS.Items
If it.ToString.Split(":")(0) = .cp.LiquidDensityEquation Then
cbEqLIQDENS.SelectedIndex = cbEqLIQDENS.Items.IndexOf(it)
Exit For
End If
Next
Else
cbEqLIQDENS.SelectedIndex = cbEqLIQDENS.Items.Count - 1
tbUserDefDensLiqEq.Text = .cp.LiquidDensityEquation
End If
If Integer.TryParse(.cp.LiquidViscosityEquation, New Integer) Then
For Each it As Object In cbEqLIQVISC.Items
If it.ToString.Split(":")(0) = .cp.LiquidViscosityEquation Then
cbEqLIQVISC.SelectedIndex = cbEqLIQVISC.Items.IndexOf(it)
Exit For
End If
Next
Else
cbEqLIQVISC.SelectedIndex = cbEqLIQVISC.Items.Count - 1
tbUserDefLiqViscEq.Text = .cp.LiquidViscosityEquation
End If
If Integer.TryParse(.cp.LiquidThermalConductivityEquation, New Integer) Then
For Each it As Object In cbEqTCLiquid.Items
If it.ToString.Split(":")(0) = .cp.LiquidThermalConductivityEquation Then
cbEqTCLiquid.SelectedIndex = cbEqTCLiquid.Items.IndexOf(it)
Exit For
End If
Next
Else
cbEqTCLiquid.SelectedIndex = cbEqTCLiquid.Items.Count - 1
tbUserDefTCEq.Text = .cp.LiquidThermalConductivityEquation
End If
For Each it As Object In cbEqCpS.Items
If it.ToString.Split(":")(0) = .cp.SolidHeatCapacityEquation Then
cbEqCpS.SelectedIndex = cbEqCpS.Items.IndexOf(it)
Exit For
End If
Next
For Each it As Object In cbEqSolidDENS.Items
If it.ToString.Split(":")(0) = .cp.SolidDensityEquation Then
cbEqSolidDENS.SelectedIndex = cbEqSolidDENS.Items.IndexOf(it)
Exit For
End If
Next
tbCpS_A.Text = .cp.Solid_Heat_Capacity_Const_A
tbCpS_B.Text = .cp.Solid_Heat_Capacity_Const_B
tbCpS_C.Text = .cp.Solid_Heat_Capacity_Const_C
tbCpS_D.Text = .cp.Solid_Heat_Capacity_Const_D
tbCpS_E.Text = .cp.Solid_Heat_Capacity_Const_E
tbRoS_A.Text = .cp.Solid_Density_Const_A
tbRoS_B.Text = .cp.Solid_Density_Const_B
tbRoS_C.Text = .cp.Solid_Density_Const_C
tbRoS_D.Text = .cp.Solid_Density_Const_D
tbRoS_E.Text = .cp.Solid_Density_Const_E
tbPVAP_A.Text = .cp.Vapor_Pressure_Constant_A
tbPVAP_B.Text = .cp.Vapor_Pressure_Constant_B
tbPVAP_C.Text = .cp.Vapor_Pressure_Constant_C
tbPVAP_D.Text = .cp.Vapor_Pressure_Constant_D
tbPVAP_E.Text = .cp.Vapor_Pressure_Constant_E
tbCPIG_A.Text = .cp.Ideal_Gas_Heat_Capacity_Const_A
tbCPIG_B.Text = .cp.Ideal_Gas_Heat_Capacity_Const_B
tbCPIG_C.Text = .cp.Ideal_Gas_Heat_Capacity_Const_C
tbCPIG_D.Text = .cp.Ideal_Gas_Heat_Capacity_Const_D
tbCPIG_E.Text = .cp.Ideal_Gas_Heat_Capacity_Const_E
tbCPLiquid_A.Text = .cp.Liquid_Heat_Capacity_Const_A
tbCPLiquid_B.Text = .cp.Liquid_Heat_Capacity_Const_B
tbCPLiquid_C.Text = .cp.Liquid_Heat_Capacity_Const_C
tbCPLiquid_D.Text = .cp.Liquid_Heat_Capacity_Const_D
tbCPLiquid_E.Text = .cp.Liquid_Heat_Capacity_Const_E
tbLIQDENS_A.Text = .cp.Liquid_Density_Const_A
tbLIQDENS_B.Text = .cp.Liquid_Density_Const_B
tbLIQDENS_C.Text = .cp.Liquid_Density_Const_C
tbLIQDENS_D.Text = .cp.Liquid_Density_Const_D
tbLIQDENS_E.Text = .cp.Liquid_Density_Const_E
tbLIQVISC_A.Text = .cp.Liquid_Viscosity_Const_A
tbLIQVISC_B.Text = .cp.Liquid_Viscosity_Const_B
tbLIQVISC_C.Text = .cp.Liquid_Viscosity_Const_C
tbLIQVISC_D.Text = .cp.Liquid_Viscosity_Const_D
tbLIQVISC_E.Text = .cp.Liquid_Viscosity_Const_E
tbTCLiquid_A.Text = .cp.Liquid_Thermal_Conductivity_Const_A
tbTCLiquid_B.Text = .cp.Liquid_Thermal_Conductivity_Const_B
tbTCLiquid_C.Text = .cp.Liquid_Thermal_Conductivity_Const_C
tbTCLiquid_D.Text = .cp.Liquid_Thermal_Conductivity_Const_D
tbTCLiquid_E.Text = .cp.Liquid_Thermal_Conductivity_Const_E
populating = True
For Each r As DataGridViewRow In Me.GridUNIFAC.Rows
If .cp.UNIFACGroups(r.Cells(1).Value) <> "" Then r.Cells(2).Value = .cp.UNIFACGroups(r.Cells(1).Value) 'old file format - Subgroup name
If .cp.UNIFACGroups(r.Cells(3).Tag(2)) <> "" Then r.Cells(2).Value = .cp.UNIFACGroups(r.Cells(3).Tag(2)) 'new file format - Subgroup ID
If r.Cells(2).Value > 0 Then
r.Cells(2).Style.BackColor = Color.PaleGreen
Else
r.Cells(2).Style.BackColor = Color.White
End If
Next
For Each r As DataGridViewRow In Me.GridMODFAC.Rows
If .cp.MODFACGroups(r.Cells(1).Value) <> "" Then r.Cells(2).Value = .cp.MODFACGroups(r.Cells(1).Value) 'old file format - Subgroup name
If .cp.MODFACGroups(r.Cells(3).Tag(2)) <> "" Then r.Cells(2).Value = .cp.MODFACGroups(r.Cells(3).Tag(2)) 'new file format - Subgroup ID
If r.Cells(2).Value > 0 Then
r.Cells(2).Style.BackColor = Color.PaleGreen
Else
r.Cells(2).Style.BackColor = Color.White
End If
Next
If .cp.NISTMODFACGroups Is Nothing Then
.cp.NISTMODFACGroups = New SortedList
End If
For Each r As DataGridViewRow In Me.GridNISTMODFAC.Rows
If .cp.NISTMODFACGroups(r.Cells(1).Value) <> "" Then r.Cells(2).Value = .cp.NISTMODFACGroups(r.Cells(1).Value) 'old file format - Subgroup name
If .cp.NISTMODFACGroups(r.Cells(3).Tag(2)) <> "" Then r.Cells(2).Value = .cp.NISTMODFACGroups(r.Cells(3).Tag(2)) 'new file format - Subgroup ID
If r.Cells(2).Value > 0 Then
r.Cells(2).Style.BackColor = Color.PaleGreen
Else
r.Cells(2).Style.BackColor = Color.White
End If
Next
FillUnifacSubGroups()
'check for updated elements when loading older files and create them if not existing
If .JobackGroups Is Nothing Then .JobackGroups = New ArrayList()
If .AdditionalAtoms Is Nothing Then .AdditionalAtoms = New ArrayList
If .DataRoS Is Nothing Then .DataRoS = New ArrayList
If .DataCpS Is Nothing Then .DataCpS = New ArrayList
If .DataCPLiquid Is Nothing Then .DataCPLiquid = New ArrayList
If .DataLTC Is Nothing Then .DataLTC = New ArrayList
'populating Joback Grid with additional Joback groups
For i = 0 To .JobackGroups.Count - 1
Me.GridJoback.Rows.Item(.JobackGroups.Item(i)(0)).Cells(3).Value = .JobackGroups.Item(i)(1)
If .JobackGroups.Item(i)(1) > 0 Then PureUNIFACCompound = False
Next
'populating AtomGrid with additional Atoms
For i = 0 To .AdditionalAtoms.Count - 1
Me.AddAtomDataGrid.Rows(.AdditionalAtoms.Item(i)(0)).Cells(1).Value = .AdditionalAtoms.Item(i)(1)
Next
populating = False
Me.GridExpDataPVAP.Rows.Clear()
For i = 0 To .DataPVAP.Count - 1
Me.GridExpDataPVAP.Rows.Add(New Object() {SystemsOfUnits.Converter.ConvertFromSI(su.temperature, .DataPVAP(i)(0)), SystemsOfUnits.Converter.ConvertFromSI(su.pressure, .DataPVAP(i)(1))})
Next
Me.GridExpDataCPIG.Rows.Clear()
For i = 0 To .DataCPIG.Count - 1
Me.GridExpDataCPIG.Rows.Add(New Object() {SystemsOfUnits.Converter.ConvertFromSI(su.temperature, .DataCPIG(i)(0)), SystemsOfUnits.Converter.ConvertFromSI(su.heatCapacityCp, .DataCPIG(i)(1))})
Next
Me.GridExpDataCPLiquid.Rows.Clear()
For i = 0 To .DataCPLiquid.Count - 1
Me.GridExpDataCPLiquid.Rows.Add(New Object() {SystemsOfUnits.Converter.ConvertFromSI(su.temperature, .DataCPLiquid(i)(0)), SystemsOfUnits.Converter.ConvertFromSI(su.heatCapacityCp, .DataCPLiquid(i)(1))})
Next
Me.GridExpDataLIQDENS.Rows.Clear()
For i = 0 To .DataLDENS.Count - 1
Me.GridExpDataLIQDENS.Rows.Add(New Object() {SystemsOfUnits.Converter.ConvertFromSI(su.temperature, .DataLDENS(i)(0)), SystemsOfUnits.Converter.ConvertFromSI(su.density, .DataLDENS(i)(1))})
Next
Me.GridExpDataLIQVISC.Rows.Clear()
For i = 0 To .DataLVISC.Count - 1
Me.GridExpDataLIQVISC.Rows.Add(New Object() {SystemsOfUnits.Converter.ConvertFromSI(su.temperature, .DataLVISC(i)(0)), SystemsOfUnits.Converter.ConvertFromSI(su.viscosity, .DataLVISC(i)(1))})
Next
Me.GridExpDataTCLiquid.Rows.Clear()
For i = 0 To .DataLTC.Count - 1
Me.GridExpDataTCLiquid.Rows.Add(New Object() {SystemsOfUnits.Converter.ConvertFromSI(su.temperature, .DataLTC(i)(0)), SystemsOfUnits.Converter.ConvertFromSI(su.thermalConductivity, .DataLTC(i)(1))})
Next
Me.GridExpDataRoS.Rows.Clear()
For i = 0 To .DataRoS.Count - 1
Me.GridExpDataRoS.Rows.Add(New Object() {SystemsOfUnits.Converter.ConvertFromSI(su.temperature, .DataRoS(i)(0)), SystemsOfUnits.Converter.ConvertFromSI(su.density, .DataRoS(i)(1)) * .cp.Molar_Weight})
Next
Me.GridExpDataCpS.Rows.Clear()
For i = 0 To .DataCpS.Count - 1
Me.GridExpDataCpS.Rows.Add(New Object() {SystemsOfUnits.Converter.ConvertFromSI(su.temperature, .DataCpS(i)(0)), SystemsOfUnits.Converter.ConvertFromSI(su.heatCapacityCp, .DataCpS(i)(1)) / .cp.Molar_Weight})
Next
If .RegressOKPVAP Then tbStatusPVAP.Text = "OK" Else tbStatusPVAP.Text = .ErrorMsgPVAP
If .RegressOKCPIG Then tbStatusCPIG.Text = "OK" Else tbStatusCPIG.Text = .ErrorMsgCPIG
If .RegressOKCPLiquid Then tbStatusCPLiquid.Text = "OK" Else tbStatusCPLiquid.Text = .ErrorMsgCPLiquid
If .RegressOKLDENS Then tbStatusLIQDENS.Text = "OK" Else tbStatusLIQDENS.Text = .ErrorMsgLDENS
If .RegressOKLVISC Then tbStatusLIQVISC.Text = "OK" Else tbStatusLIQVISC.Text = .ErrorMsgLVISC
If .RegressOKRoS Then tbStatusSolidDens.Text = "OK" Else tbStatusSolidDens.Text = .ErrorMsgRoS
If .RegressOKCpS Then tbStatusSolidCp.Text = "OK" Else tbStatusSolidCp.Text = .ErrorMsgCpS
If .RegressOKLTC Then tbStatusTCLiquid.Text = "OK" Else tbStatusTCLiquid.Text = .ErrorMsgLTC
CheckDataStatus()
End With
End Sub
Sub FillUnifacSubGroups()
'fill Joback groups table with UNIFAC subgoups
Dim k, ugc, usgc, usgid, oc As Integer
Dim JG, JSG As String
For Each r As DataGridViewRow In Me.GridJoback.Rows
r.Cells(2).Value = Nothing
Next
For Each r As DataGridViewRow In Me.GridUNIFAC.Rows
'Joback groups from UNIFAC subgroups
If r.Cells(2).Value > 0 Then
ugc = mycase.cp.UNIFACGroups(r.Cells(3).Tag(2))
JG = UNIFAClines(r.Index + 2).Split(",")(8) 'Joback Subgroup List
For k = 0 To 3
JSG = JG.Split("/")(k)
If Not JSG = "" Then
usgc = JSG.Split(":")(0) 'Joback subgroup count
usgid = JSG.Split(":")(1) 'Joback subgroup ID
oc = Me.GridJoback.Rows.Item(usgid - 1).Cells(2).Value
Me.GridJoback.Rows.Item(usgid - 1).Cells(2).Value = oc + usgc * ugc
End If
Next
End If
Next
End Sub
Sub StoreData()
With mycase
.su = Me.su
.cp.ID = TextBoxID.Text
.cp.Name = TextBoxName.Text
.cp.Comments = TextBoxComments.Text
.cp.OriginalDB = "User"
.cp.CurrentDB = "User"
.cp.IsBlackOil = False
.cp.Acentric_Factor = CheckEmptyTextBox(TextBoxAF)
.cp.CAS_Number = TextBoxCAS.Text
.cp.CompCreatorStudyFile = .Filename
.cp.Chao_Seader_Acentricity = CheckEmptyTextBox(TextBoxCSAF)
.cp.Chao_Seader_Liquid_Molar_Volume = CheckEmptyTextBox(TextBoxCSLV)
.cp.Chao_Seader_Solubility_Parameter = CheckEmptyTextBox(TextBoxCSSP)
.cp.IG_Gibbs_Energy_of_Formation_25C = SystemsOfUnits.Converter.ConvertToSI(su.enthalpy, CheckEmptyTextBox(TextBoxDGF))
.cp.IG_Enthalpy_of_Formation_25C = SystemsOfUnits.Converter.ConvertToSI(su.enthalpy, CheckEmptyTextBox(TextBoxDHF))
.cp.Formula = TextBoxFormula.Text
.cp.Molar_Weight = CheckEmptyTextBox(TextBoxMW)
.cp.Normal_Boiling_Point = SystemsOfUnits.Converter.ConvertToSI(su.temperature, CheckEmptyTextBox(TextBoxNBP))
.cp.Critical_Pressure = SystemsOfUnits.Converter.ConvertToSI(su.pressure, CheckEmptyTextBox(TextBoxPc))
.cp.UNIQUAC_Q = CheckEmptyTextBox(TextBoxUNIQUAC_Q)
.cp.UNIQUAC_R = CheckEmptyTextBox(TextBoxUNIQUAC_R)
.cp.Critical_Temperature = SystemsOfUnits.Converter.ConvertToSI(su.temperature, CheckEmptyTextBox(TextBoxTc))
.cp.PR_Volume_Translation_Coefficient = CheckEmptyTextBox(TextBoxVTCPR)
.cp.SRK_Volume_Translation_Coefficient = CheckEmptyTextBox(TextBoxVTCSRK)
.cp.Critical_Compressibility = CheckEmptyTextBox(TextBoxZc)
.cp.Z_Rackett = CheckEmptyTextBox(TextBoxZRa)
.cp.SMILES = TextBoxSMILES.Text
.cp.TemperatureOfFusion = SystemsOfUnits.Converter.ConvertToSI(su.temperature, CheckEmptyTextBox(TextBoxMeltingTemp))
.cp.EnthalpyOfFusionAtTf = SystemsOfUnits.Converter.ConvertToSI(su.enthalpy, CheckEmptyTextBox(TextBoxEnthOfFusion))
.RegressPVAP = rbRegressPVAP.Checked
.RegressCPIG = rbRegressCPIG.Checked
.RegressCPLiquid = rbRegressCPLiquid.Checked
.RegressLDENS = rbRegressLIQDENS.Checked
.RegressLVISC = rbRegressLIQVISC.Checked
.RegressRoS = rbRegressSolidDens.Checked
.RegressCpS = rbRegressSolidCp.Checked
.RegressLTC = rbRegressTCLiquid.Checked
.EqPVAP = rbCoeffPVAP.Checked
.EqCPIG = rbCoeffCPIG.Checked
.EqCPLiquid = rbCoeffCPLiquid.Checked
.EqLDENS = rbCoeffLIQDENS.Checked
.EqLVISC = rbCoeffLIQVISC.Checked
.EqSDens = rbCoeffSolidDens.Checked
.EqCpS = rbCoeffSolidCp.Checked
.EqLTC = rbCoeffTCLiquid.Checked
.CalcMW = CheckBoxMW.Checked
.CalcNBP = CheckBoxNBP.Checked
.CalcAF = CheckBoxAF.Checked
.CalcCSAF = CheckBoxCSAF.Checked
.CalcCSMV = CheckBoxCSLV.Checked
.CalcCSSP = CheckBoxCSSP.Checked
.CalcTC = CheckBoxTc.Checked
.CalcPC = CheckBoxPc.Checked
.CalcZC = CheckBoxZc.Checked
.CalcZRA = CheckBoxZRa.Checked
.CalcHF = CheckBoxDHF.Checked
.CalcGF = CheckBoxDGF.Checked
.CalcMP = CheckBoxMeltingTemp.Checked
.CalcEM = CheckBoxEnthOfFusion.Checked
.cp.VaporPressureEquation = cbEqPVAP.SelectedItem.ToString.Split(":")(0)
If .cp.VaporPressureEquation = "1000" Then .cp.VaporPressureEquation = tbUserDefEqPVAP.Text
.cp.LiquidDensityEquation = cbEqLIQDENS.SelectedItem.ToString.Split(":")(0)
If .cp.LiquidDensityEquation = "1000" Then .cp.LiquidDensityEquation = tbUserDefDensLiqEq.Text
.cp.LiquidViscosityEquation = cbEqLIQVISC.SelectedItem.ToString.Split(":")(0)
If .cp.LiquidViscosityEquation = "1000" Then .cp.LiquidViscosityEquation = tbUserDefLiqViscEq.Text
.cp.SolidHeatCapacityEquation = cbEqCpS.SelectedIndex.ToString.Split(":")(0)
.cp.SolidDensityEquation = cbEqSolidDENS.SelectedIndex.ToString.Split(":")(0)
.cp.IdealgasCpEquation = cbEqCPIG.SelectedItem.ToString.Split(":")(0)
If .cp.IdealgasCpEquation = "1000" Then .cp.IdealgasCpEquation = tbUserDefCPIGEq.Text
.cp.LiquidHeatCapacityEquation = cbEqCPLiquid.SelectedItem.ToString.Split(":")(0)
If .cp.LiquidHeatCapacityEquation = "1000" Then .cp.LiquidHeatCapacityEquation = tbUserDefCPLEq.Text
.cp.LiquidThermalConductivityEquation = cbEqTCLiquid.SelectedItem.ToString.Split(":")(0)
If .cp.LiquidThermalConductivityEquation = "1000" Then .cp.LiquidThermalConductivityEquation = tbUserDefTCEq.Text
.cp.Solid_Heat_Capacity_Const_A = CheckEmptyCell(tbCpS_A.Text)
.cp.Solid_Heat_Capacity_Const_B = CheckEmptyCell(tbCpS_B.Text)
.cp.Solid_Heat_Capacity_Const_C = CheckEmptyCell(tbCpS_C.Text)
.cp.Solid_Heat_Capacity_Const_D = CheckEmptyCell(tbCpS_D.Text)
.cp.Solid_Heat_Capacity_Const_E = CheckEmptyCell(tbCpS_E.Text)
.cp.Solid_Heat_Capacity_Tmin = 0
.cp.Solid_Heat_Capacity_Tmax = .cp.TemperatureOfFusion
.cp.Solid_Density_Const_A = CheckEmptyCell(tbRoS_A.Text)
.cp.Solid_Density_Const_B = CheckEmptyCell(tbRoS_B.Text)
.cp.Solid_Density_Const_C = CheckEmptyCell(tbRoS_C.Text)
.cp.Solid_Density_Const_D = CheckEmptyCell(tbRoS_D.Text)
.cp.Solid_Density_Const_E = CheckEmptyCell(tbRoS_E.Text)
.cp.Solid_Density_Tmin = 0
.cp.Solid_Density_Tmax = .cp.TemperatureOfFusion
.cp.Vapor_Pressure_Constant_A = CheckEmptyCell(tbPVAP_A.Text)
.cp.Vapor_Pressure_Constant_B = CheckEmptyCell(tbPVAP_B.Text)
.cp.Vapor_Pressure_Constant_C = CheckEmptyCell(tbPVAP_C.Text)
.cp.Vapor_Pressure_Constant_D = CheckEmptyCell(tbPVAP_D.Text)
.cp.Vapor_Pressure_Constant_E = CheckEmptyCell(tbPVAP_E.Text)
.cp.Ideal_Gas_Heat_Capacity_Const_A = CheckEmptyCell(tbCPIG_A.Text)
.cp.Ideal_Gas_Heat_Capacity_Const_B = CheckEmptyCell(tbCPIG_B.Text)
.cp.Ideal_Gas_Heat_Capacity_Const_C = CheckEmptyCell(tbCPIG_C.Text)
.cp.Ideal_Gas_Heat_Capacity_Const_D = CheckEmptyCell(tbCPIG_D.Text)
.cp.Ideal_Gas_Heat_Capacity_Const_E = CheckEmptyCell(tbCPIG_E.Text)
.cp.Liquid_Heat_Capacity_Const_A = CheckEmptyCell(tbCPLiquid_A.Text)
.cp.Liquid_Heat_Capacity_Const_B = CheckEmptyCell(tbCPLiquid_B.Text)
.cp.Liquid_Heat_Capacity_Const_C = CheckEmptyCell(tbCPLiquid_C.Text)
.cp.Liquid_Heat_Capacity_Const_D = CheckEmptyCell(tbCPLiquid_D.Text)
.cp.Liquid_Heat_Capacity_Const_E = CheckEmptyCell(tbCPLiquid_E.Text)
.cp.Liquid_Density_Const_A = CheckEmptyCell(tbLIQDENS_A.Text)
.cp.Liquid_Density_Const_B = CheckEmptyCell(tbLIQDENS_B.Text)
.cp.Liquid_Density_Const_C = CheckEmptyCell(tbLIQDENS_C.Text)
.cp.Liquid_Density_Const_D = CheckEmptyCell(tbLIQDENS_D.Text)
.cp.Liquid_Density_Const_E = CheckEmptyCell(tbLIQDENS_E.Text)
.cp.Liquid_Viscosity_Const_A = CheckEmptyCell(tbLIQVISC_A.Text)
.cp.Liquid_Viscosity_Const_B = CheckEmptyCell(tbLIQVISC_B.Text)
.cp.Liquid_Viscosity_Const_C = CheckEmptyCell(tbLIQVISC_C.Text)
.cp.Liquid_Viscosity_Const_D = CheckEmptyCell(tbLIQVISC_D.Text)
.cp.Liquid_Viscosity_Const_E = CheckEmptyCell(tbLIQVISC_E.Text)
.cp.Liquid_Thermal_Conductivity_Const_A = CheckEmptyCell(tbTCLiquid_A.Text)
.cp.Liquid_Thermal_Conductivity_Const_B = CheckEmptyCell(tbTCLiquid_B.Text)
.cp.Liquid_Thermal_Conductivity_Const_C = CheckEmptyCell(tbTCLiquid_C.Text)
.cp.Liquid_Thermal_Conductivity_Const_D = CheckEmptyCell(tbTCLiquid_D.Text)
.cp.Liquid_Thermal_Conductivity_Const_E = CheckEmptyCell(tbTCLiquid_E.Text)
.cp.UNIFACGroups.Clear()
For Each r As DataGridViewRow In Me.GridUNIFAC.Rows
If CInt(r.Cells(2).Value) <> 0 Then .cp.UNIFACGroups(r.Cells(3).Tag(2)) = r.Cells(2).Value
Next
.cp.MODFACGroups.Clear()
For Each r As DataGridViewRow In Me.GridMODFAC.Rows
If CInt(r.Cells(2).Value) <> 0 Then .cp.MODFACGroups(r.Cells(3).Tag(2)) = r.Cells(2).Value
Next
.cp.NISTMODFACGroups.Clear()
For Each r As DataGridViewRow In Me.GridNISTMODFAC.Rows
If CInt(r.Cells(2).Value) <> 0 Then .cp.NISTMODFACGroups(r.Cells(3).Tag(2)) = r.Cells(2).Value
Next
Dim JC As Integer
If mycase.JobackGroups Is Nothing Then .JobackGroups = New ArrayList 'for old file versions where field was not defined
.JobackGroups.Clear()
For Each r As DataGridViewRow In Me.GridJoback.Rows
JC = r.Cells(3).Value
If JC > 0 Then .JobackGroups.Add(New Integer() {r.Index, JC})
Next
If mycase.AdditionalAtoms Is Nothing Then .AdditionalAtoms = New ArrayList
.AdditionalAtoms.Clear()
For Each r As DataGridViewRow In AddAtomDataGrid.Rows
JC = r.Cells(1).Value
If JC > 0 Then .AdditionalAtoms.Add(New Integer() {r.Index, JC})
Next
.cp.Elements.Clear()
For Each r As DataGridViewRow In Me.AtomDataGrid.Rows
.cp.Elements.Add(r.Cells(0).Value, r.Cells(1).Value)
Next
mycase.DataPVAP.Clear()
For Each row As DataGridViewRow In Me.GridExpDataPVAP.Rows
If row.Index < Me.GridExpDataPVAP.Rows.Count - 1 Then mycase.DataPVAP.Add(New Double() {SystemsOfUnits.Converter.ConvertToSI(su.temperature, row.Cells(0).Value), SystemsOfUnits.Converter.ConvertToSI(su.pressure, row.Cells(1).Value)})
Next
mycase.DataCPIG.Clear()
For Each row As DataGridViewRow In Me.GridExpDataCPIG.Rows
If row.Index < Me.GridExpDataCPIG.Rows.Count - 1 Then mycase.DataCPIG.Add(New Double() {SystemsOfUnits.Converter.ConvertToSI(su.temperature, row.Cells(0).Value), SystemsOfUnits.Converter.ConvertToSI(su.heatCapacityCp, row.Cells(1).Value)})
Next
mycase.DataCPLiquid.Clear()
For Each row As DataGridViewRow In Me.GridExpDataCPLiquid.Rows
If row.Index < Me.GridExpDataCPLiquid.Rows.Count - 1 Then mycase.DataCPLiquid.Add(New Double() {SystemsOfUnits.Converter.ConvertToSI(su.temperature, row.Cells(0).Value), SystemsOfUnits.Converter.ConvertToSI(su.heatCapacityCp, row.Cells(1).Value)})
Next
mycase.DataLDENS.Clear()
For Each row As DataGridViewRow In Me.GridExpDataLIQDENS.Rows
If row.Index < Me.GridExpDataLIQDENS.Rows.Count - 1 Then mycase.DataLDENS.Add(New Double() {SystemsOfUnits.Converter.ConvertToSI(su.temperature, row.Cells(0).Value), SystemsOfUnits.Converter.ConvertToSI(su.density, row.Cells(1).Value)})
Next
mycase.DataLVISC.Clear()
For Each row As DataGridViewRow In Me.GridExpDataLIQVISC.Rows
If row.Index < Me.GridExpDataLIQVISC.Rows.Count - 1 Then mycase.DataLVISC.Add(New Double() {SystemsOfUnits.Converter.ConvertToSI(su.temperature, row.Cells(0).Value), SystemsOfUnits.Converter.ConvertToSI(su.viscosity, row.Cells(1).Value)})
Next
mycase.DataRoS.Clear()
For Each row As DataGridViewRow In Me.GridExpDataRoS.Rows
If row.Index < Me.GridExpDataRoS.Rows.Count - 1 Then mycase.DataRoS.Add(New Double() {SystemsOfUnits.Converter.ConvertToSI(su.temperature, row.Cells(0).Value), SystemsOfUnits.Converter.ConvertToSI(su.density, row.Cells(1).Value) / .cp.Molar_Weight})
Next
mycase.DataCpS.Clear()
For Each row As DataGridViewRow In Me.GridExpDataCpS.Rows
If row.Index < Me.GridExpDataCpS.Rows.Count - 1 Then mycase.DataCpS.Add(New Double() {SystemsOfUnits.Converter.ConvertToSI(su.temperature, row.Cells(0).Value), SystemsOfUnits.Converter.ConvertToSI(su.heatCapacityCp, row.Cells(1).Value) * .cp.Molar_Weight})
Next
mycase.DataLTC.Clear()
For Each row As DataGridViewRow In Me.GridExpDataTCLiquid.Rows
If row.Index < Me.GridExpDataTCLiquid.Rows.Count - 1 Then mycase.DataLTC.Add(New Double() {SystemsOfUnits.Converter.ConvertToSI(su.temperature, row.Cells(0).Value), SystemsOfUnits.Converter.ConvertToSI(su.thermalConductivity, row.Cells(1).Value)})
Next
End With
End Sub
Function CheckEmptyCell(ByVal val As String) As Double
Try
CheckEmptyCell = val
Catch ex As Exception
CheckEmptyCell = Nothing
End Try
End Function
Function CheckEmptyTextBox(tb As TextBox) As Double
If Double.TryParse(tb.Text, New Double) Then Return tb.Text Else Return 0.0#
End Function
Function CheckValidDF(ByVal val As String) As Boolean
Dim DN As Double
Try
DN = val
CheckValidDF = True
Catch ex As Exception
CheckValidDF = False
End Try
End Function
Private Sub CalcJobackParams()
If loaded Then
loaded = False 'prevent recalculation due to edit field event procedures
jb = New Joback
methods = New HYP()
'get UNIFAC group amounts
Dim vn As New ArrayList
For Each row As DataGridViewRow In GridUNIFAC.Rows
If Not row.Cells(2).Value Is Nothing Then
vn.Add(Integer.Parse(row.Cells(2).Value))
Else
vn.Add(0)
End If
Next
Dim vnd As Int32() = vn.ToArray(Type.GetType("System.Int32"))
'get Joback group amounts
Dim JC, UC, GC As Integer 'JC=UnifacGroupCount; UC=UnifacGroupCount; GC=GlobalGroupCount
Dim JG As New ArrayList
PureUNIFACCompound = True
For Each r As DataGridViewRow In Me.GridJoback.Rows
JC = r.Cells(3).Value 'additional Joback groups
UC = r.Cells(2).Value 'Joback groups from UNIFAC subgoups
JG.Add(JC + UC)
GC += JC + UC
If JC > 0 Then PureUNIFACCompound = False
Next
Dim JGD As Int32() = JG.ToArray(Type.GetType("System.Int32"))
'Calculate atoms list
Dim ACL As New Dictionary(Of String, Integer) ' => Atom Count List
Dim Sy As String 'Element Symbol
Dim AC As Integer 'Atom count
Dim Formula As String
Dim SpecialDefinition As Boolean = False 'special definition -> no joback calculation possible
ACL = jb.GetAtomCountList(JGD) 'Atoms from Joback groups
'add additional atoms from datatable
For Each r As DataGridViewRow In Me.AddAtomDataGrid.Rows
Sy = r.Cells(0).Value
AC = r.Cells(1).Value
If AC > 0 Then
PureUNIFACCompound = False
SpecialDefinition = True
If Not ACL.ContainsKey(Sy) Then