File size: 85,673 Bytes
b1b3bae |
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 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 |
' Flowsheet Object Base Classes
' Copyright 2008-2024 Daniel Wagner O. de Medeiros
'
' 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 System.Runtime.InteropServices
Imports System.Text
Imports DWSIM.Interfaces.Enums.GraphicObjects
Imports DWSIM.Interfaces.Enums
Imports System.Dynamic
Imports System.Reflection
Imports cv = DWSIM.SharedClasses.SystemsOfUnits.Converter
Namespace UnitOperations
<System.Serializable()> <ComVisible(True)> Public MustInherit Class BaseClass
Implements ICloneable, IDisposable, Interfaces.ICustomXMLSerialization
Implements Interfaces.ISimulationObject, Interfaces.IProductInformation
Public Const ClassId As String = ""
<System.NonSerialized()> Protected Friend m_flowsheet As Interfaces.IFlowsheet
Public Shared InitializationAction1 As Action(Of BaseClass)
Public Shared InitializationAction2 As Action(Of BaseClass)
Public Shared InitializationAction3 As Action(Of BaseClass)
Public Shared TransferAdditionalSolidDataAction As Action(Of BaseClass)
<Newtonsoft.Json.JsonIgnore> <Xml.Serialization.XmlIgnore> Public Property LastSolutionInputSnapshot As String = ""
Protected Friend _IsDirty As Boolean = True
ReadOnly Property IsDirty As Boolean Implements ISimulationObject.IsDirty
Get
Return _IsDirty
End Get
End Property
Protected Friend _CanUsePreviousResults As Boolean = False
ReadOnly Property CanUsePreviousResults As Boolean Implements ISimulationObject.CanUsePreviousResults
Get
Return _CanUsePreviousResults
End Get
End Property
Public Property DynamicsSpec As Enums.Dynamics.DynamicsSpecType = Dynamics.DynamicsSpecType.Pressure Implements ISimulationObject.DynamicsSpec
Public Property DynamicsOnly As Boolean = False Implements ISimulationObject.DynamicsOnly
Public Property ExtraProperties As New ExpandoObject Implements ISimulationObject.ExtraProperties
Public Property ExtraPropertiesUnitTypes As New ExpandoObject Implements ISimulationObject.ExtraPropertiesUnitTypes
Public Property ExtraPropertiesDescriptions As New ExpandoObject Implements ISimulationObject.ExtraPropertiesDescriptions
Public Property ExtraPropertiesTypes As New ExpandoObject Implements ISimulationObject.ExtraPropertiesTypes
Public Overridable Property Visible As Boolean = True
<NonSerialized()> <Xml.Serialization.XmlIgnore> Public LaunchExternalPropertyEditor() As Action(Of ISimulationObject)
<NonSerialized()> <Xml.Serialization.XmlIgnore> Public ExtraPropertiesEditor As Form
Public Property OverrideCalculationRoutine As Boolean = False
<System.NonSerialized()> <Xml.Serialization.XmlIgnore> Public CalculationRoutineOverride As Action
Public Property StoreDetailedDebugReport As Boolean = False
Public Property DetailedDebugReport As String
Public ReadOnly Property IsFunctional As Boolean = True Implements ISimulationObject.IsFunctional
Public Overridable Property ComponentDescription() As String = ""
Public Overridable Property ComponentName() As String = ""
Public Overrides Function ToString() As String
If GraphicObject IsNot Nothing Then
Return GraphicObject.Tag
Else
Return MyBase.ToString()
End If
End Function
''' <summary>
''' Gets the current flowsheet where this object is located.
''' </summary>
''' <value></value>
''' <returns>Flowsheet instance.</returns>
''' <remarks></remarks>
Public Overridable ReadOnly Property FlowSheet() As Interfaces.IFlowsheet
Get
If Not m_flowsheet Is Nothing Then
Return m_flowsheet
Else
Return Nothing
End If
End Get
End Property
Public Overridable Property ObjectClass As SimulationObjectClass = SimulationObjectClass.Other Implements ISimulationObject.ObjectClass
Public Overridable ReadOnly Property SupportsDynamicMode As Boolean = False Implements ISimulationObject.SupportsDynamicMode
Public Overridable ReadOnly Property HasPropertiesForDynamicMode As Boolean = False Implements ISimulationObject.HasPropertiesForDynamicMode
#Region " Constructors"
Public Sub New()
InitializationAction1?.Invoke(Me)
InitializationAction2?.Invoke(Me)
InitializationAction3?.Invoke(Me)
End Sub
Sub CreateNew()
If ExtraProperties.Count = 0 Then CreateDynamicProperties()
End Sub
#End Region
#Region " ISimulationObject"
Public Sub AddExtraProperty(pname As String, pvalue As Object) Implements ISimulationObject.AddExtraProperty
Dim col1 = DirectCast(ExtraProperties, IDictionary(Of String, Object))
If Not col1.ContainsKey(pname) Then
col1.Add(pname, pvalue)
Else
Throw New Exception("Property already exists.")
End If
End Sub
Public Sub RemoveExtraProperty(pname As String) Implements ISimulationObject.RemoveExtraProperty
Dim col1 = DirectCast(ExtraProperties, IDictionary(Of String, Object))
If col1.ContainsKey(pname) Then
col1.Remove(pname)
Else
Throw New Exception("Property doesn't exist.")
End If
End Sub
Public Sub SetExtraPropertyValue(pname As String, pvalue As Object) Implements ISimulationObject.SetExtraPropertyValue
Dim col1 = DirectCast(ExtraProperties, IDictionary(Of String, Object))
If col1.ContainsKey(pname) Then
col1(pname) = pvalue
Else
Throw New Exception("Property doesn't exist.")
End If
End Sub
Public Function GetExtraPropertyValue(pname As String) As Object Implements ISimulationObject.GetExtraPropertyValue
Dim col1 = DirectCast(ExtraProperties, IDictionary(Of String, Object))
If col1.ContainsKey(pname) Then
Return col1(pname)
Else
Throw New Exception("Property doesn't exist.")
End If
End Function
Public Sub ClearExtraProperties() Implements ISimulationObject.ClearExtraProperties
Dim col1 = DirectCast(ExtraProperties, IDictionary(Of String, Object))
Dim col2 = DirectCast(ExtraPropertiesDescriptions, IDictionary(Of String, Object))
Dim col3 = DirectCast(ExtraPropertiesUnitTypes, IDictionary(Of String, Object))
Dim col4 = DirectCast(ExtraPropertiesTypes, IDictionary(Of String, Object))
Dim toremove As New List(Of String)
For Each p In col1
If Not col2.ContainsKey(p.Key) And Not col3.ContainsKey(p.Key) Then
toremove.Add(p.Key)
End If
Next
For Each item In toremove
col1.Remove(item)
Next
End Sub
Public Sub AddDynamicProperty(pname As String, pdesc As String, pvalue As Double,
punittype As Enums.UnitOfMeasure, ptype As System.Type) Implements ISimulationObject.AddDynamicProperty
Dim col1 = DirectCast(ExtraProperties, IDictionary(Of String, Object))
Dim col2 = DirectCast(ExtraPropertiesDescriptions, IDictionary(Of String, Object))
Dim col3 = DirectCast(ExtraPropertiesUnitTypes, IDictionary(Of String, Object))
Dim col4 = DirectCast(ExtraPropertiesTypes, IDictionary(Of String, Object))
If Not col1.ContainsKey(pname) Then col1.Add(pname, pvalue)
If Not col2.ContainsKey(pname) Then col2.Add(pname, pdesc)
If Not col3.ContainsKey(pname) Then col3.Add(pname, punittype)
If Not col4.ContainsKey(pname) Then col4.Add(pname, ptype)
End Sub
Public Function SetDynamicProperty(id As String, value As Object) As Boolean Implements ISimulationObject.AddDynamicProperty
Dim col1 = DirectCast(ExtraProperties, IDictionary(Of String, Object))
col1(id) = value
Return True
End Function
Public Function GetDynamicProperty(id As String) As Object Implements ISimulationObject.GetDynamicProperty
Dim col1 = DirectCast(ExtraProperties, IDictionary(Of String, Object))
If col1.ContainsKey(id) Then Return col1(id) Else Return Nothing
End Function
Public Function GetDynamicPropertyUnitType(id As String) As Enums.UnitOfMeasure Implements ISimulationObject.GetDynamicPropertyUnitType
Dim col1 = DirectCast(ExtraPropertiesUnitTypes, IDictionary(Of String, Object))
If col1.ContainsKey(id) Then Return col1(id) Else Return Nothing
End Function
Public Sub RemoveDynamicProperty(pname As String) Implements ISimulationObject.RemoveDynamicProperty
Dim col1 = DirectCast(ExtraProperties, IDictionary(Of String, Object))
Dim col2 = DirectCast(ExtraPropertiesDescriptions, IDictionary(Of String, Object))
Dim col3 = DirectCast(ExtraPropertiesUnitTypes, IDictionary(Of String, Object))
Dim col4 = DirectCast(ExtraPropertiesTypes, IDictionary(Of String, Object))
If col1.ContainsKey(pname) Then col1.Remove(pname)
If col2.ContainsKey(pname) Then col2.Remove(pname)
If col1.ContainsKey(pname) Then col3.Remove(pname)
If col4.ContainsKey(pname) Then col4.Remove(pname)
End Sub
Public Function IsDynamicProperty(pname As String) As Boolean Implements ISimulationObject.IsDynamicProperty
Dim col1 = DirectCast(ExtraPropertiesDescriptions, IDictionary(Of String, Object))
Return col1.ContainsKey(pname)
End Function
Public Overridable Function GetChartModel(name As String) As Object Implements ISimulationObject.GetChartModel
If CreateChartAction IsNot Nothing Then
Return CreateChartAction.Invoke(name)
Else
Return Nothing
End If
End Function
Public Overridable Function GetPropertyDescription(prop As String) As String Implements ISimulationObject.GetPropertyDescription
Return "No description is available for this property."
End Function
Public Overridable Function GetReport(su As IUnitsOfMeasure, ci As Globalization.CultureInfo, numberformat As String) As String Implements ISimulationObject.GetReport
Return "No report is available for this object."
End Function
Public Overridable Function GetVersion() As Version Implements ISimulationObject.GetVersion
Return Me.GetType.Assembly.GetName.Version
End Function
Public MustOverride Function GetDisplayName() As String Implements ISimulationObject.GetDisplayName
Public MustOverride Function GetDisplayDescription() As String Implements ISimulationObject.GetDisplayDescription
Public MustOverride Function GetIconBitmap() As Object Implements ISimulationObject.GetIconBitmap
Public Overridable Function GetIconBitmapBytes() As Byte() Implements ISimulationObject.GetIconBitmapBytes
Return New Byte() {}
End Function
Protected Function GetBytesFromResource(resourcename As String) As Byte()
Dim assembly1 = Assembly.GetCallingAssembly()
Using stream = assembly1.GetManifestResourceStream(resourcename)
Dim streamLength As Integer = Convert.ToInt32(stream.Length)
Dim fileData As Byte() = New Byte(streamLength) {}
' Read the file into a byte array
stream.Read(fileData, 0, streamLength)
stream.Close()
Return fileData
End Using
End Function
<NonSerialized> Private _AttachedUtilities As New List(Of IAttachedUtility)
Public Property AttachedUtilities As List(Of IAttachedUtility) Implements ISimulationObject.AttachedUtilities
Get
If _AttachedUtilities Is Nothing Then _AttachedUtilities = New List(Of IAttachedUtility)
Return _AttachedUtilities
End Get
Set(value As List(Of IAttachedUtility))
_AttachedUtilities = value
End Set
End Property
Public Property PreferredFlashAlgorithmTag As String = "" Implements ISimulationObject.PreferredFlashAlgorithmTag
Public Property Calculated As Boolean = False Implements Interfaces.ISimulationObject.Calculated
Public Property DebugMode As Boolean = False Implements Interfaces.ISimulationObject.DebugMode
<Xml.Serialization.XmlIgnore> Public Property DebugText As String = "" Implements Interfaces.ISimulationObject.DebugText
Public Property LastUpdated As New Date Implements Interfaces.ISimulationObject.LastUpdated
''' <summary>
''' Calculates the object.
''' </summary>
''' <param name="args"></param>
''' <remarks>Use 'Solve()' to calculate the object instead.</remarks>
Public Overridable Sub Calculate(Optional ByVal args As Object = Nothing) Implements ISimulationObject.Calculate
Throw New NotImplementedException
End Sub
Public Sub DeCalculate(Optional args As Object = Nothing) Implements ISimulationObject.DeCalculate
'Throw New NotImplementedException
End Sub
Public Overridable Sub RunDynamicModel() Implements ISimulationObject.RunDynamicModel
Throw New Exception("This Unit Operation is not yet supported in Dynamic Mode.")
End Sub
Public Overridable Sub PerformPostCalcValidation() Implements ISimulationObject.PerformPostCalcValidation
If GraphicObject.ObjectType <> ObjectType.MaterialStream And GraphicObject.ObjectType <> ObjectType.EnergyStream And
GraphicObject.ObjectType <> ObjectType.OT_Adjust And GraphicObject.ObjectType <> ObjectType.OT_Spec And
GraphicObject.ObjectType <> ObjectType.OT_Recycle And GraphicObject.ObjectType <> ObjectType.OT_EnergyRecycle Then
'calculate mass balance
Dim mb As Double = 0.0#
Dim eb As Double = 0.0#
Dim mbe As Double = 0.0#
Dim ebe As Double = 0.0#
Dim mbt As Double = 0.0#
Dim ebt As Double = 0.0#
Dim mi, hi, hf As Double
Dim imsc As List(Of ISimulationObject) = GraphicObject.InputConnectors.Where(Function(x) x.IsAttached And Not (x.IsEnergyConnector Or x.Type = ConType.ConEn)).Select(Function(x) FlowSheet.SimulationObjects(x.AttachedConnector.AttachedFrom.Name)).ToList
Dim omsc As List(Of ISimulationObject) = GraphicObject.OutputConnectors.Where(Function(x) x.IsAttached And Not (x.IsEnergyConnector Or x.Type = ConType.ConEn)).Select(Function(x) FlowSheet.SimulationObjects(x.AttachedConnector.AttachedTo.Name)).ToList
For Each ims In imsc
If ims.GraphicObject.Active Then
If DirectCast(ims, IMaterialStream).DefinedFlow = FlowSpec.Mole Then
mi = Convert.ToDouble(ims.GetPropertyValue("PROP_MS_3")) / 1000.0 * Convert.ToDouble(ims.GetPropertyValue("PROP_MS_6"))
Else
mi = Convert.ToDouble(ims.GetPropertyValue("PROP_MS_2"))
End If
mb += mi
mbt += mi
hi = Convert.ToDouble(ims.GetPropertyValue("PROP_MS_7"))
eb -= mi * hi 'kg/s * kJ/kg = kJ/s = kW
ebt += Math.Abs(mi * hi)
'heats of formation
hf = DirectCast(ims, IMaterialStream).GetOverallHeatOfFormation()
eb -= hf
ebt += Math.Abs(hf)
End If
Next
For Each oms In omsc
If oms.GraphicObject.Active Then
If DirectCast(oms, IMaterialStream).DefinedFlow = FlowSpec.Mole Then
mi = Convert.ToDouble(oms.GetPropertyValue("PROP_MS_3")) / 1000.0 * Convert.ToDouble(oms.GetPropertyValue("PROP_MS_6"))
Else
mi = Convert.ToDouble(oms.GetPropertyValue("PROP_MS_2"))
End If
mb -= mi
mbt += mi
hi = Convert.ToDouble(oms.GetPropertyValue("PROP_MS_7"))
eb += mi * hi 'kg/s * kJ/kg = kJ/s = kW
ebt += Math.Abs(mi * hi)
'heats of formation
hf = DirectCast(oms, IMaterialStream).GetOverallHeatOfFormation()
eb += hf
ebt += Math.Abs(hf)
End If
Next
mbe = mb / mbt
Dim iesc As List(Of ISimulationObject) = GraphicObject.InputConnectors.Where(Function(x) x.IsAttached And (x.IsEnergyConnector Or x.Type = ConType.ConEn)).Select(Function(x) FlowSheet.SimulationObjects(x.AttachedConnector.AttachedFrom.Name)).ToList
Dim oesc As List(Of ISimulationObject) = GraphicObject.OutputConnectors.Where(Function(x) x.IsAttached And (x.IsEnergyConnector Or x.Type = ConType.ConEn)).Select(Function(x) FlowSheet.SimulationObjects(x.AttachedConnector.AttachedTo.Name)).ToList
For Each ies In iesc
If ies.GraphicObject.Active Then
eb -= Convert.ToDouble(ies.GetPropertyValue("PROP_ES_0"))
ebt += Math.Abs(Convert.ToDouble(ies.GetPropertyValue("PROP_ES_0")))
End If
Next
For Each oes In oesc
If oes.GraphicObject.Active Then
eb += Convert.ToDouble(oes.GetPropertyValue("PROP_ES_0"))
ebt += Math.Abs(Convert.ToDouble(oes.GetPropertyValue("PROP_ES_0")))
End If
Next
If GraphicObject.EnergyConnector.IsAttached Then
Dim inobj = FlowSheet.SimulationObjects(GraphicObject.EnergyConnector.AttachedConnector.AttachedFrom.Name)
If inobj.GraphicObject.IsEnergyStream And inobj.GraphicObject.Active Then
eb -= Convert.ToDouble(inobj.GetPropertyValue("PROP_ES_0"))
ebt += Math.Abs(Convert.ToDouble(inobj.GetPropertyValue("PROP_ES_0")))
End If
Dim outobj = FlowSheet.SimulationObjects(GraphicObject.EnergyConnector.AttachedConnector.AttachedTo.Name)
If outobj.GraphicObject.IsEnergyStream And outobj.GraphicObject.Active Then
eb += Convert.ToDouble(outobj.GetPropertyValue("PROP_ES_0"))
ebt += Math.Abs(Convert.ToDouble(outobj.GetPropertyValue("PROP_ES_0")))
End If
End If
If iesc.Count + oesc.Count = 0 And Not GraphicObject.EnergyConnector.IsAttached Then
eb = 0
End If
mbe = Math.Abs(mb / mbt)
ebe = Math.Abs(eb / ebt)
If FlowSheet.FlowsheetOptions.MassBalanceRelativeTolerance = 0.0 Then
FlowSheet.FlowsheetOptions.MassBalanceRelativeTolerance = 0.01
End If
If FlowSheet.FlowsheetOptions.EnergyBalanceRelativeTolerance = 0.0 Then
FlowSheet.FlowsheetOptions.EnergyBalanceRelativeTolerance = 0.01
End If
If mbe > FlowSheet.FlowsheetOptions.MassBalanceRelativeTolerance Then
If FlowSheet.FlowsheetOptions.MassBalanceCheck = WarningType.RaiseError Then
Throw New Exception(GraphicObject.Tag + ": " + FlowSheet.GetTranslatedString("MassBalanceMessage") + " (" + mbe.ToString() + " > " + FlowSheet.FlowsheetOptions.MassBalanceRelativeTolerance.ToString + ")")
ElseIf FlowSheet.FlowsheetOptions.MassBalanceCheck = WarningType.ShowWarning Then
FlowSheet.ShowMessage(GraphicObject.Tag + ": " + FlowSheet.GetTranslatedString("MassBalanceMessage") + " (" + mbe.ToString() + " > " + FlowSheet.FlowsheetOptions.MassBalanceRelativeTolerance.ToString + ")", IFlowsheet.MessageType.Warning)
End If
End If
If ebe > FlowSheet.FlowsheetOptions.EnergyBalanceRelativeTolerance Then
If FlowSheet.FlowsheetOptions.EnergyBalanceCheck = WarningType.RaiseError Then
Throw New Exception(GraphicObject.Tag + ": " + FlowSheet.GetTranslatedString("EnergyBalanceMessage") + " (" + ebe.ToString() + " > " + FlowSheet.FlowsheetOptions.EnergyBalanceRelativeTolerance.ToString + ")")
ElseIf FlowSheet.FlowsheetOptions.EnergyBalanceCheck = WarningType.ShowWarning Then
FlowSheet.ShowMessage(GraphicObject.Tag + ": " + FlowSheet.GetTranslatedString("EnergyBalanceMessage") + " (" + ebe.ToString() + " > " + FlowSheet.FlowsheetOptions.EnergyBalanceRelativeTolerance.ToString + ")", IFlowsheet.MessageType.Warning)
End If
End If
End If
End Sub
Public Overridable Sub Solve() Implements ISimulationObject.Solve
If FlowSheet.FlowsheetOptions.ForceObjectSolving Then
Calculated = False
If OverrideCalculationRoutine Then
CalculationRoutineOverride.Invoke()
Else
Calculate()
End If
Calculated = True
Else
CheckDirtyStatus()
Calculated = False
If Not CanUsePreviousResults Then Calculate()
Calculated = True
PerformPostCalcValidation()
If GraphicObject IsNot Nothing Then
If GraphicObject.ObjectType <> ObjectType.EnergyStream And GraphicObject.ObjectType <> ObjectType.MaterialStream Then
Dim xdoc = New XDocument()
xdoc.Add(New XElement("Data"))
xdoc.Element("Data").Add(SaveData())
xdoc.Element("Data").Element("Calculated").Remove()
xdoc.Element("Data").Element("LastUpdated").Remove()
LastSolutionInputSnapshot = xdoc.ToString()
xdoc = Nothing
End If
End If
End If
TransferAdditionalSolidData()
If GHGEmissionData IsNot Nothing Then
GHGEmissionData.OwnerID = Name
GHGEmissionData.Flowsheet = FlowSheet
GHGEmissionData.Update()
End If
End Sub
Public Overridable Sub TransferAdditionalSolidData()
TransferAdditionalSolidDataAction?.Invoke(Me)
End Sub
<NonSerialized> <Xml.Serialization.XmlIgnore> Public fd As DynamicsPropertyEditor
Public Overridable Sub DisplayDynamicsEditForm() Implements ISimulationObject.DisplayDynamicsEditForm
If fd Is Nothing Then
fd = New DynamicsPropertyEditor With {.SimObject = Me}
fd.ShowHint = WeifenLuo.WinFormsUI.Docking.DockState.DockRight
fd.Tag = "ObjectEditor"
Me.FlowSheet.DisplayForm(fd)
Else
If fd.IsDisposed Then
fd = New DynamicsPropertyEditor With {.SimObject = Me}
fd.ShowHint = WeifenLuo.WinFormsUI.Docking.DockState.DockRight
fd.Tag = "ObjectEditor"
Me.FlowSheet.DisplayForm(fd)
Else
fd.Activate()
End If
End If
End Sub
Public Sub UpdateDynamicsEditForm() Implements ISimulationObject.UpdateDynamicsEditForm
If fd IsNot Nothing Then
If Not fd.IsDisposed Then
fd.UIThread(Sub() fd.UpdateInfo())
End If
End If
End Sub
Public Sub CloseDynamicsEditForm() Implements ISimulationObject.CloseDynamicsEditForm
If fd IsNot Nothing Then
If Not fd.IsDisposed Then
fd.Close()
fd = Nothing
End If
End If
End Sub
Public MustOverride Sub DisplayEditForm() Implements ISimulationObject.DisplayEditForm
Public MustOverride Sub UpdateEditForm() Implements ISimulationObject.UpdateEditForm
Public Overridable Function GetEditingForm() As Form Implements ISimulationObject.GetEditingForm
Return Nothing
End Function
''' <summary>
''' Energy Flow property. Only implemented for Energy Streams.
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
<Xml.Serialization.XmlIgnore()> Overridable Property EnergyFlow() As Nullable(Of Double)
Get
Return Nothing
End Get
Set(ByVal value As Nullable(Of Double))
End Set
End Property
''' <summary>
''' Phase collection, only implemented for Material Streams.
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
<Xml.Serialization.XmlIgnore()> Public Overridable ReadOnly Property Phases() As Dictionary(Of Integer, Interfaces.IPhase)
Get
Throw New NotImplementedException
End Get
End Property
''' <summary>
''' Validates the object, checking its connections and other parameters.
''' </summary>
''' <remarks></remarks>
Public Overridable Sub Validate() Implements Interfaces.ISimulationObject.Validate
Dim vForm As Interfaces.IFlowsheet = FlowSheet
Dim vCon As Interfaces.IConnectionPoint
'Validate input connections.
For Each vCon In Me.GraphicObject.InputConnectors
If Not vCon.IsAttached Then
Throw New Exception(Me.FlowSheet.GetTranslatedString("Verifiqueasconexesdo"))
End If
Next
'Validate output connections.
For Each vCon In Me.GraphicObject.OutputConnectors
If Not vCon.IsAttached Then
Throw New Exception(Me.FlowSheet.GetTranslatedString("Verifiqueasconexesdo"))
End If
Next
End Sub
Public Overridable Function GetDebugReport() As String Implements Interfaces.ISimulationObject.GetDebugReport
Return "Error - function not implemented"
End Function
Public Sub AppendDebugLine(text As String) Implements Interfaces.ISimulationObject.AppendDebugLine
DebugText += text & vbCrLf & vbCrLf
End Sub
''' <summary>
''' Gets or sets the error message regarding the last calculation attempt.
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property ErrorMessage() As String Implements Interfaces.ISimulationObject.ErrorMessage
''' <summary>
''' Checks if a value is valid.
''' </summary>
''' <param name="val">Value to be checked.</param>
''' <param name="onlypositive">Value should be a positive double or not.</param>
''' <param name="paramname">Name of the parameter (ex. P, T, W, H etc.)</param>
''' <remarks></remarks>
Public Sub CheckSpec(val As Double, onlypositive As Boolean, paramname As String) Implements Interfaces.ISimulationObject.CheckSpec
If Not val.IsValid Then Throw New ArgumentException(Me.FlowSheet.GetTranslatedString("ErrorInvalidUOSpecValue") & " (name: " & paramname & ", value: " & val & ")")
If onlypositive Then If val.IsNegative Then Throw New ArgumentException(Me.FlowSheet.GetTranslatedString("ErrorInvalidUOSpecValue") & " (name: " & paramname & ", value: " & val & ")")
End Sub
Public Property Annotation() As String = "" Implements Interfaces.ISimulationObject.Annotation
''' <summary>
''' Checks if an Adjust operation is attached to this object.
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property IsAdjustAttached() As Boolean = False Implements Interfaces.ISimulationObject.IsAdjustAttached
''' <summary>
''' If an Adjust object is attached to this object, returns its ID.
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property AttachedAdjustId() As String = "" Implements Interfaces.ISimulationObject.AttachedAdjustId
''' <summary>
''' If an Adjust object is attached to this object, returns a variable describing how this object is used by it (manipulated, controlled or reference).
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property AdjustVarType() As Interfaces.Enums.AdjustVarType Implements Interfaces.ISimulationObject.AdjustVarType
''' <summary>
''' Checks if an Specification operation is attached to this object.
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property IsSpecAttached() As Boolean = False Implements Interfaces.ISimulationObject.IsSpecAttached
''' <summary>
''' If an Specification object is attached to this object, returns its ID.
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property AttachedSpecId() As String = "" Implements Interfaces.ISimulationObject.AttachedSpecId
''' <summary>
''' If an Specification object is attached to this object, returns a variable describing how this object is used by it (target or source).
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property SpecVarType() As Interfaces.Enums.SpecVarType Implements Interfaces.ISimulationObject.SpecVarType
''' <summary>
''' Gets or sets the graphic object representation of this object in the flowsheet.
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
<Xml.Serialization.XmlIgnore> Public Property GraphicObject() As Interfaces.IGraphicObject Implements Interfaces.ISimulationObject.GraphicObject
''' <summary>
''' Object's Unique ID (Name)
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks>This property is the same as the graphic object 'Name' property.</remarks>
Public Property Name() As String Implements Interfaces.ISimulationObject.Name
Get
Return ComponentName
End Get
Set(value As String)
ComponentName = value
End Set
End Property
Public Overridable Function GetProperties(proptype As PropertyType) As String() Implements Interfaces.ISimulationObject.GetProperties
Dim proplist As New List(Of String)
Dim col1 = DirectCast(ExtraProperties, IDictionary(Of String, Object))
Dim col2 = DirectCast(ExtraPropertiesDescriptions, IDictionary(Of String, Object))
Dim col3 = DirectCast(ExtraPropertiesUnitTypes, IDictionary(Of String, Object))
For Each p In col1
If col2.ContainsKey(p.Key) And col3.ContainsKey(p.Key) Then
If FlowSheet IsNot Nothing AndAlso FlowSheet.DynamicMode Then proplist.Add(p.Key)
Else
proplist.Add(p.Key)
End If
Next
If FlowSheet IsNot Nothing Then
If FlowSheet.FlowsheetOptions.EnableGHGEmissionsSubsystem Then
If proptype <> PropertyType.WR Then
proplist.Add("GHG Emission Factor")
proplist.Add("GHG Mass Emission")
proplist.Add("GHG Molar Emission")
proplist.Add("CO2eq GHG Mass Emission")
proplist.Add("CO2eq GHG Molar Emission")
proplist.Add("GHG Emission Reference Power Value")
End If
End If
End If
For Each item In AttachedUtilities
proplist.AddRange(item.GetPropertyList().ConvertAll(New Converter(Of String, String)(Function(s As String)
Return item.Name & ": " & s
End Function)))
Next
Return proplist.ToArray
End Function
Public Overridable Function GetPropertyUnit(prop As String, Optional su As Interfaces.IUnitsOfMeasure = Nothing) As String Implements Interfaces.ISimulationObject.GetPropertyUnit
If su Is Nothing Then
su = FlowSheet.FlowsheetOptions.SelectedUnitSystem
End If
Dim epcol = DirectCast(ExtraProperties, IDictionary(Of String, Object))
Dim epucol = DirectCast(ExtraPropertiesUnitTypes, IDictionary(Of String, Object))
If epcol.ContainsKey(prop) Then
If epucol.ContainsKey(prop) Then
Dim utype = epucol(prop)
Return su.GetCurrentUnits(utype)
Else
Return ""
End If
Else
Select Case prop
Case "GHG Emission Factor"
Return "[kg/s]/kW"
Case "GHG Mass Emission"
Return "kg/s"
Case "GHG Molar Emission"
Return "mol/s"
Case "CO2eq GHG Mass Emission"
Return "kg/s"
Case "CO2eq GHG Molar Emission"
Return "mol/s"
Case "GHG Emission Reference Power Value"
Return "kW"
End Select
End If
For Each item In AttachedUtilities
If prop.StartsWith(item.Name) Then
For Each prop1 In item.GetPropertyList()
If prop.Contains(prop1) Then Return item.GetPropertyUnits(prop.Split(": ")(1).Trim)
Next
End If
Next
Return "NF"
End Function
Public Overridable Function GetPropertyValue(prop As String, Optional su As Interfaces.IUnitsOfMeasure = Nothing) As Object Implements Interfaces.ISimulationObject.GetPropertyValue
If su Is Nothing Then
su = FlowSheet.FlowsheetOptions.SelectedUnitSystem
End If
Dim epcol = DirectCast(ExtraProperties, IDictionary(Of String, Object))
Dim epucol = DirectCast(ExtraPropertiesUnitTypes, IDictionary(Of String, Object))
If epcol.ContainsKey(prop) Then
If epucol.ContainsKey(prop) Then
Dim utype = epucol(prop)
Dim units = su.GetCurrentUnits(utype)
Return cv.ConvertFromSI(units, Convert.ToDouble(epcol(prop)))
Else
Return epcol(prop)
End If
Else
Select Case prop
Case "GHG Emission Factor"
If GHGEmissionData IsNot Nothing Then
Return cv.ConvertFromSI(su.emission_factor, GHGEmissionData.GHGEmissionFactor)
Else
Return 0.0
End If
Case "GHG Mass Emission"
If GHGEmissionData IsNot Nothing Then
Return cv.ConvertFromSI(su.massflow, GHGEmissionData.GHGEmissionMassFlow)
Else
Return 0.0
End If
Case "GHG Molar Emission"
If GHGEmissionData IsNot Nothing Then
Return cv.ConvertFromSI(su.molarflow, GHGEmissionData.GHGEmissionMolarFlow)
Else
Return 0.0
End If
Case "CO2eq GHG Mass Emission"
If GHGEmissionData IsNot Nothing Then
Return cv.ConvertFromSI(su.massflow, GHGEmissionData.CO2eqEmissionMassFlow)
Else
Return 0.0
End If
Case "CO2eq GHG Molar Emission"
If GHGEmissionData IsNot Nothing Then
Return cv.ConvertFromSI(su.molarflow, GHGEmissionData.CO2eqEmissionMolarFlow)
Else
Return 0.0
End If
Case "GHG Emission Reference Power Value"
If GHGEmissionData IsNot Nothing Then
Return cv.ConvertFromSI(su.heatflow, GetEnergyConsumption())
Else
Return 0.0
End If
End Select
End If
For Each item In AttachedUtilities
If prop.StartsWith(item.Name) Then
For Each prop1 In item.GetPropertyList()
If prop.Contains(prop1) Then Return item.GetPropertyValue(prop.Split(": ")(1).Trim)
Next
End If
Next
Return Nothing
End Function
Public Overridable Function SetPropertyValue(prop As String, propval As Object, Optional su As Interfaces.IUnitsOfMeasure = Nothing) As Boolean Implements Interfaces.ISimulationObject.SetPropertyValue
Dim epcol = DirectCast(ExtraProperties, IDictionary(Of String, Object))
If epcol.ContainsKey(prop) Then
epcol(prop) = propval
Return True
End If
For Each item In AttachedUtilities
If prop.StartsWith(item.Name) Then
For Each prop1 In item.GetPropertyList()
If prop.Contains(prop1) Then
item.SetPropertyValue(prop.Split(": ")(1).Trim, propval)
Return True
End If
Next
End If
Next
Return False
End Function
Public Overridable Function GetDefaultProperties() As String() Implements ISimulationObject.GetDefaultProperties
Return GetProperties(PropertyType.ALL)
End Function
Public Overridable Property PropertyPackage As IPropertyPackage Implements ISimulationObject.PropertyPackage
Public Function GetFlowsheet() As IFlowsheet Implements ISimulationObject.GetFlowsheet
Return FlowSheet
End Function
Public MustOverride Sub CloseEditForm() Implements ISimulationObject.CloseEditForm
Public MustOverride Function CloneXML() As Object Implements ISimulationObject.CloneXML
Public MustOverride Function CloneJSON() As Object Implements ISimulationObject.CloneJSON
Public MustOverride ReadOnly Property MobileCompatible As Boolean Implements ISimulationObject.MobileCompatible
Public Property UserDefinedChartNames As New List(Of String)
Public Property CreateChartAction As Func(Of String, Object)
Public Overridable Function GetChartModelNames() As List(Of String) Implements ISimulationObject.GetChartModelNames
If UserDefinedChartNames.Count > 0 Then
Return UserDefinedChartNames
Else
Return New List(Of String)
End If
End Function
#End Region
#Region " ICloneable"
''' <summary>
''' Clones the current object, returning a new one with identical properties.
''' </summary>
''' <returns>An object of the same type with the same properties.</returns>
''' <remarks>Properties and fields marked with the 'NonSerializable' attribute aren't cloned.</remarks>
Public Overridable Function Clone() As Object Implements System.ICloneable.Clone
Return ObjectCopy(Me)
End Function
Function ObjectCopy(ByVal obj As UnitOperations.BaseClass) As Object
Return Me.CloneXML
End Function
#End Region
#Region " IDisposable Support "
Public disposedValue As Boolean = False ' To detect redundant calls
Protected Overridable Sub Dispose(ByVal disposing As Boolean)
Me.disposedValue = True
End Sub
' This code added by Visual Basic to correctly implement the disposable pattern.
Public Overridable Sub Dispose() Implements IDisposable.Dispose
' Do not change this code. Put cleanup code in Dispose(ByVal disposing As Boolean) above.
Dispose(True)
GC.SuppressFinalize(Me)
End Sub
#End Region
#Region " IXMLSerialization"
''' <summary>
''' Loads object data stored in a collection of XML elements.
''' </summary>
''' <param name="data"></param>
''' <returns></returns>
''' <remarks></remarks>
Public Overridable Function LoadData(data As System.Collections.Generic.List(Of System.Xml.Linq.XElement)) As Boolean Implements Interfaces.ICustomXMLSerialization.LoadData
XMLSerializer.XMLSerializer.Deserialize(Me, data)
ExtraProperties = New ExpandoObject
Dim xel_d = (From xel2 As XElement In data Select xel2 Where xel2.Name = "DynamicProperties")
If Not xel_d Is Nothing Then
Dim dataDyn As List(Of XElement) = xel_d.Elements.ToList
For Each xel As XElement In dataDyn
Try
Dim propname = xel.Element("Name").Value
Dim proptype = xel.Element("PropertyType").Value
Dim ptype As Type = Type.GetType(proptype)
Dim propval = Newtonsoft.Json.JsonConvert.DeserializeObject(xel.Element("Data").Value, ptype)
DirectCast(ExtraProperties, IDictionary(Of String, Object))(propname) = propval
Catch ex As Exception
End Try
Next
End If
ExtraPropertiesDescriptions = New ExpandoObject
Dim xel_dd = (From xel2 As XElement In data Select xel2 Where xel2.Name = "DynamicPropertiesDescriptions")
If Not xel_dd Is Nothing Then
Dim dataDyn As List(Of XElement) = xel_dd.Elements.ToList
For Each xel As XElement In dataDyn
Try
Dim propname = xel.Element("Name").Value
Dim proptype = xel.Element("PropertyType").Value
Dim ptype As Type = Type.GetType(proptype)
Dim propval = Newtonsoft.Json.JsonConvert.DeserializeObject(xel.Element("Data").Value, ptype)
DirectCast(ExtraPropertiesDescriptions, IDictionary(Of String, Object))(propname) = propval
Catch ex As Exception
End Try
Next
End If
ExtraPropertiesUnitTypes = New ExpandoObject
Dim xel_ddt = (From xel2 As XElement In data Select xel2 Where xel2.Name = "DynamicPropertiesUnitTypes")
If Not xel_ddt Is Nothing Then
Dim dataDyn As List(Of XElement) = xel_ddt.Elements.ToList
For Each xel As XElement In dataDyn
Try
Dim propname = xel.Element("Name").Value
Dim proptype = xel.Element("PropertyType").Value
Dim ptype As Type = Type.GetType(proptype)
Dim propval = Newtonsoft.Json.JsonConvert.DeserializeObject(xel.Element("Data").Value, ptype)
DirectCast(ExtraPropertiesUnitTypes, IDictionary(Of String, Object))(propname) = propval
Catch ex As Exception
End Try
Next
End If
'If ExtraProperties.Count = 0 Then
CreateDynamicProperties()
'End If
Dim xel_u = (From xel2 As XElement In data Select xel2 Where xel2.Name = "AttachedUtilities")
If Not xel_u Is Nothing Then
Dim dataUtilities As List(Of XElement) = xel_u.Elements.ToList
For Each xel As XElement In dataUtilities
Try
Dim u = FlowSheet.GetUtility(xel.Element("UtilityType").Value)
u.ID = xel.Element("ID").Value
u.Name = xel.Element("Name").Value
u.AttachedTo = Me
u.Initialize()
u.LoadData(Newtonsoft.Json.JsonConvert.DeserializeObject(Of Dictionary(Of String, Object))(xel.Element("Data").Value))
Me.AttachedUtilities.Add(u)
Catch ex As Exception
FlowSheet.ShowMessage("Error restoring attached utility to " & Me.Name & ": " & ex.Message.ToString, IFlowsheet.MessageType.GeneralError)
End Try
Next
End If
If Me.Annotation = "DWSIM.DWSIM.Outros.Annotation" Then Me.Annotation = ""
If GHGEmissionData IsNot Nothing Then
GHGEmissionData.OwnerID = Name
GHGEmissionData.Flowsheet = FlowSheet
End If
Return True
End Function
''' <summary>
''' Saves object data in a collection of XML elements.
''' </summary>
''' <returns>A List of XML elements containing object data.</returns>
''' <remarks></remarks>
Public Overridable Function SaveData() As System.Collections.Generic.List(Of System.Xml.Linq.XElement) Implements Interfaces.ICustomXMLSerialization.SaveData
Dim elements As System.Collections.Generic.List(Of System.Xml.Linq.XElement) = XMLSerializer.XMLSerializer.Serialize(Me)
With elements
.Add(New XElement("DynamicProperties"))
Dim extraprops = DirectCast(ExtraProperties, IDictionary(Of String, Object))
For Each item In extraprops
Try
.Item(.Count - 1).Add(New XElement("Property", {New XElement("Name", item.Key),
New XElement("PropertyType", item.Value.GetType.ToString),
New XElement("Data", Newtonsoft.Json.JsonConvert.SerializeObject(item.Value))}))
Catch ex As Exception
End Try
Next
.Add(New XElement("DynamicPropertiesDescriptions"))
Dim extrapropsdesc = DirectCast(ExtraPropertiesDescriptions, IDictionary(Of String, Object))
For Each item In extrapropsdesc
Try
.Item(.Count - 1).Add(New XElement("Property", {New XElement("Name", item.Key),
New XElement("PropertyType", item.Value.GetType.ToString),
New XElement("Data", Newtonsoft.Json.JsonConvert.SerializeObject(item.Value))}))
Catch ex As Exception
End Try
Next
.Add(New XElement("DynamicPropertiesUnitTypes"))
Dim extrapropsunits = DirectCast(ExtraPropertiesUnitTypes, IDictionary(Of String, Object))
For Each item In extrapropsunits
Try
.Item(.Count - 1).Add(New XElement("Property", {New XElement("Name", item.Key),
New XElement("PropertyType", item.Value.GetType.ToString),
New XElement("Data", Newtonsoft.Json.JsonConvert.SerializeObject(item.Value))}))
Catch ex As Exception
End Try
Next
.Add(New XElement("AttachedUtilities"))
For Each util In AttachedUtilities
Try
.Item(.Count - 1).Add(New XElement("AttachedUtility", {New XElement("ID", util.ID),
New XElement("Name", util.Name),
New XElement("UtilityType", Convert.ToInt32(util.GetUtilityType)),
New XElement("Data", Newtonsoft.Json.JsonConvert.SerializeObject(util.SaveData))}))
Catch ex As Exception
End Try
Next
End With
Return elements
End Function
#End Region
#Region " Extras"
''' <summary>
''' Copies the object properties to the Clipboard.
''' </summary>
''' <param name="su">Units system to use.</param>
''' <param name="nf">Number format to use.</param>
''' <remarks></remarks>
Public Sub CopyDataToClipboard(su As SystemsOfUnits.Units, nf As String)
Dim DT As New DataTable
DT.Columns.Clear()
DT.Columns.Add(("Propriedade"), GetType(System.String))
DT.Columns.Add(("Valor"), GetType(System.String))
DT.Columns.Add(("Unidade"), GetType(System.String))
DT.Rows.Clear()
Dim baseobj As BaseClass
Dim properties() As String
Dim description As String
Dim objtype As ObjectType
Dim propidx, r1, r2, r3, r4, r5, r6 As Integer
r1 = 5
r2 = 12
r3 = 30
r4 = 48
r5 = 66
r6 = 84
baseobj = Me
properties = baseobj.GetProperties(Interfaces.Enums.PropertyType.ALL)
objtype = baseobj.GraphicObject.ObjectType
description = Me.FlowSheet.GetTranslatedString(baseobj.GraphicObject.Description)
If objtype = ObjectType.MaterialStream Then
Dim value As String
For propidx = 0 To r1 - 1
value = baseobj.GetPropertyValue(properties(propidx), su)
If Double.TryParse(value, New Double) Then
DT.Rows.Add(New String() {Me.FlowSheet.GetTranslatedString(properties(propidx)), Format(Double.Parse(value), nf), baseobj.GetPropertyUnit(properties(propidx), su)})
Else
DT.Rows.Add(New String() {Me.FlowSheet.GetTranslatedString(properties(propidx)), value, baseobj.GetPropertyUnit(properties(propidx), su)})
End If
Next
For propidx = r1 To r2 - 1
value = baseobj.GetPropertyValue(properties(propidx), su)
If Double.TryParse(value, New Double) Then
DT.Rows.Add(New String() {Me.FlowSheet.GetTranslatedString(properties(propidx)), Format(Double.Parse(value), nf), baseobj.GetPropertyUnit(properties(propidx), su)})
Else
DT.Rows.Add(New String() {Me.FlowSheet.GetTranslatedString(properties(propidx)), value, baseobj.GetPropertyUnit(properties(propidx), su)})
End If
Next
DT.Rows.Add(New String() {Me.FlowSheet.GetTranslatedString("FraomolarnaMistura"), "", ""})
For Each subst As Interfaces.ICompound In CType(Me, Interfaces.IMaterialStream).Phases(0).Compounds.Values
DT.Rows.Add(New String() {Me.FlowSheet.GetTranslatedString(subst.Name), Format(subst.MoleFraction.GetValueOrDefault, nf), ""})
Next
For propidx = r2 To r3 - 1
value = baseobj.GetPropertyValue(properties(propidx), su)
If Double.TryParse(value, New Double) Then
DT.Rows.Add(New String() {Me.FlowSheet.GetTranslatedString(properties(propidx)), Format(Double.Parse(value), nf), baseobj.GetPropertyUnit(properties(propidx), su)})
Else
DT.Rows.Add(New String() {Me.FlowSheet.GetTranslatedString(properties(propidx)), value, baseobj.GetPropertyUnit(properties(propidx), su)})
End If
Next
DT.Rows.Add(New String() {Me.FlowSheet.GetTranslatedString("FraomolarnaPhaseVapor"), "", ""})
For Each subst As Interfaces.ICompound In CType(Me, Interfaces.IMaterialStream).Phases(2).Compounds.Values
DT.Rows.Add(New String() {Me.FlowSheet.GetTranslatedString(subst.Name), Format(subst.MoleFraction.GetValueOrDefault, nf), ""})
Next
For propidx = r3 To r4 - 1
value = baseobj.GetPropertyValue(properties(propidx), su)
If Double.TryParse(value, New Double) Then
DT.Rows.Add(New String() {Me.FlowSheet.GetTranslatedString(properties(propidx)), Format(Double.Parse(value), nf), baseobj.GetPropertyUnit(properties(propidx), su)})
Else
DT.Rows.Add(New String() {Me.FlowSheet.GetTranslatedString(properties(propidx)), value, baseobj.GetPropertyUnit(properties(propidx), su)})
End If
Next
DT.Rows.Add(New String() {Me.FlowSheet.GetTranslatedString("FraomolarnaPhaseLquid"), "", ""})
For Each subst As Interfaces.ICompound In CType(Me, Interfaces.IMaterialStream).Phases(1).Compounds.Values
DT.Rows.Add(New String() {Me.FlowSheet.GetTranslatedString(subst.Name), Format(subst.MoleFraction.GetValueOrDefault, nf), ""})
Next
For propidx = r4 To r5 - 1
value = baseobj.GetPropertyValue(properties(propidx), su)
If Double.TryParse(value, New Double) Then
DT.Rows.Add(New String() {Me.FlowSheet.GetTranslatedString(properties(propidx)), Format(Double.Parse(value), nf), baseobj.GetPropertyUnit(properties(propidx), su)})
Else
DT.Rows.Add(New String() {Me.FlowSheet.GetTranslatedString(properties(propidx)), value, baseobj.GetPropertyUnit(properties(propidx), su)})
End If
Next
DT.Rows.Add(New String() {Me.FlowSheet.GetTranslatedString("FraomolarnaPhaseLquid"), "", ""})
For Each subst As Interfaces.ICompound In CType(Me, Interfaces.IMaterialStream).Phases(3).Compounds.Values
DT.Rows.Add(New String() {Me.FlowSheet.GetTranslatedString(subst.Name), Format(subst.MoleFraction.GetValueOrDefault, nf), ""})
Next
For propidx = r5 To r6 - 1
value = baseobj.GetPropertyValue(properties(propidx), su)
If Double.TryParse(value, New Double) Then
DT.Rows.Add(New String() {Me.FlowSheet.GetTranslatedString(properties(propidx)), Format(Double.Parse(value), nf), baseobj.GetPropertyUnit(properties(propidx), su)})
Else
DT.Rows.Add(New String() {Me.FlowSheet.GetTranslatedString(properties(propidx)), value, baseobj.GetPropertyUnit(properties(propidx), su)})
End If
Next
DT.Rows.Add(New String() {Me.FlowSheet.GetTranslatedString("FraomolarnaPhaseLquid"), "", ""})
For Each subst As Interfaces.ICompound In CType(Me, Interfaces.IMaterialStream).Phases(4).Compounds.Values
DT.Rows.Add(New String() {Me.FlowSheet.GetTranslatedString(subst.Name), Format(subst.MoleFraction.GetValueOrDefault, nf), ""})
Next
For propidx = r6 To 101
value = baseobj.GetPropertyValue(properties(propidx), su)
If Double.TryParse(value, New Double) Then
DT.Rows.Add(New String() {Me.FlowSheet.GetTranslatedString(properties(propidx)), Format(Double.Parse(value), nf), baseobj.GetPropertyUnit(properties(propidx), su)})
Else
DT.Rows.Add(New String() {Me.FlowSheet.GetTranslatedString(properties(propidx)), value, baseobj.GetPropertyUnit(properties(propidx), su)})
End If
Next
DT.Rows.Add(New String() {Me.FlowSheet.GetTranslatedString("FraomolarnaPhaseLquid"), "", ""})
For Each subst As Interfaces.ICompound In CType(Me, Interfaces.IMaterialStream).Phases(6).Compounds.Values
DT.Rows.Add(New String() {Me.FlowSheet.GetTranslatedString(subst.Name), Format(subst.MoleFraction.GetValueOrDefault, nf), ""})
Next
Else
For Each prop As String In properties
DT.Rows.Add(New String() {Me.FlowSheet.GetTranslatedString(prop), Format(baseobj.GetPropertyValue(prop, su), nf), baseobj.GetPropertyUnit(prop, su)})
Next
End If
Dim st As New StringBuilder(Me.FlowSheet.GetTranslatedString(Me.ComponentDescription) & ": " & Me.GraphicObject.Tag & vbCrLf)
For Each r As DataRow In DT.Rows
Dim l As String = ""
For Each o As Object In r.ItemArray
l += o.ToString() & vbTab
Next
st.AppendLine(l)
Next
Clipboard.SetText(st.ToString())
DT.Clear()
DT.Dispose()
DT = Nothing
End Sub
''' <summary>
''' Formats a property string, adding its units in parenthesis.
''' </summary>
''' <param name="prop">Property string</param>
''' <param name="unit">Property units</param>
''' <returns></returns>
''' <remarks></remarks>
Public Function FT(ByRef prop As String, ByVal unit As String)
Return prop & " (" & unit & ")"
End Function
''' <summary>
''' Sets the Flowsheet to which this object belongs to.
''' </summary>
''' <param name="flowsheet">Flowsheet instance.</param>
''' <remarks></remarks>
Public Sub SetFlowsheet(ByVal flowsheet As Object) Implements Interfaces.ISimulationObject.SetFlowsheet
m_flowsheet = flowsheet
If GHGEmissionData IsNot Nothing Then GHGEmissionData.Flowsheet = flowsheet
End Sub
Public Overridable Function GetStructuredReport() As List(Of Tuple(Of ReportItemType, String())) Implements ISimulationObject.GetStructuredReport
Return New List(Of Tuple(Of ReportItemType, String()))
End Function
Public Overridable Sub CreateDynamicProperties() Implements ISimulationObject.CreateDynamicProperties
End Sub
Public Sub DisplayExtraPropertiesEditForm() Implements ISimulationObject.DisplayExtraPropertiesEditForm
Dim col1 = DirectCast(ExtraProperties, IDictionary(Of String, Object))
Dim col2 = DirectCast(ExtraPropertiesDescriptions, IDictionary(Of String, Object))
Dim count As Integer = 0
For Each prop In col1
If Not col2.ContainsKey(prop.Key) Then
count += 1
End If
Next
If count > 0 Then
If ExtraPropertiesEditor Is Nothing Then
ExtraPropertiesEditor = New FormExtraProperties With {.SimObject = Me}
Me.FlowSheet.DisplayForm(ExtraPropertiesEditor)
Else
If ExtraPropertiesEditor.IsDisposed Then
ExtraPropertiesEditor = New FormExtraProperties With {.SimObject = Me}
ExtraPropertiesEditor.Tag = "ObjectEditor"
Me.FlowSheet.DisplayForm(ExtraPropertiesEditor)
Else
DirectCast(ExtraPropertiesEditor, FormExtraProperties).Activate()
End If
End If
End If
End Sub
Public Sub UpdateExtraPropertiesEditForm() Implements ISimulationObject.UpdateExtraPropertiesEditForm
If ExtraPropertiesEditor IsNot Nothing Then
If Not ExtraPropertiesEditor.IsDisposed Then
ExtraPropertiesEditor.UIThread(Sub() DirectCast(ExtraPropertiesEditor, FormExtraProperties).UpdateValues())
End If
End If
End Sub
Public Function GetDebugWriter() As StringBuilder
If StoreDetailedDebugReport Then
Dim drw As New Text.StringBuilder()
If GraphicObject IsNot Nothing Then
drw?.AppendLine("Debug Report: " + GraphicObject.Tag)
Else
drw?.AppendLine("Debug Report: " + ComponentName)
End If
drw?.AppendLine("Date: " + Date.Now.ToString())
drw?.AppendLine()
drw?.AppendLine()
drw?.AppendLine("Solver Settings: ")
drw?.AppendLine()
drw?.AppendLine(String.Format("Solver Option: {0}", GlobalSettings.Settings.SolverMode))
drw?.AppendLine(String.Format("Use Parallel CPU Acceleration: {0}", GlobalSettings.Settings.EnableParallelProcessing))
drw?.AppendLine()
drw?.AppendLine("Calculation Report: ")
drw?.AppendLine()
Return drw
Else
Return Nothing
End If
End Function
Public Sub StoreDebugReport(DebugReportWriter As StringBuilder)
If DebugReportWriter IsNot Nothing Then
DetailedDebugReport = DebugReportWriter.ToString()
End If
End Sub
Public Function GetEnergyBalanceResidual() As Double Implements ISimulationObject.GetEnergyBalanceResidual
If GraphicObject.ObjectType <> ObjectType.MaterialStream And GraphicObject.ObjectType <> ObjectType.EnergyStream And
GraphicObject.ObjectType <> ObjectType.OT_Adjust And GraphicObject.ObjectType <> ObjectType.OT_Spec And
GraphicObject.ObjectType <> ObjectType.OT_Recycle And GraphicObject.ObjectType <> ObjectType.OT_EnergyRecycle Then
Dim eb As Double = 0.0#
Dim ebe As Double = 0.0#
Dim mi, hi, hf As Double
Dim imsc As List(Of ISimulationObject) = GraphicObject.InputConnectors.Where(Function(x) x.IsAttached And Not (x.IsEnergyConnector Or x.Type = ConType.ConEn)).Select(Function(x) FlowSheet.SimulationObjects(x.AttachedConnector.AttachedFrom.Name)).ToList
Dim omsc As List(Of ISimulationObject) = GraphicObject.OutputConnectors.Where(Function(x) x.IsAttached And Not (x.IsEnergyConnector Or x.Type = ConType.ConEn)).Select(Function(x) FlowSheet.SimulationObjects(x.AttachedConnector.AttachedTo.Name)).ToList
For Each ims In imsc
If ims.GraphicObject.Active Then
If DirectCast(ims, IMaterialStream).DefinedFlow = FlowSpec.Mole Then
mi = Convert.ToDouble(ims.GetPropertyValue("PROP_MS_3")) / 1000.0 * Convert.ToDouble(ims.GetPropertyValue("PROP_MS_6"))
Else
mi = Convert.ToDouble(ims.GetPropertyValue("PROP_MS_2"))
End If
hi = Convert.ToDouble(ims.GetPropertyValue("PROP_MS_7"))
eb -= mi * hi 'kg/s * kJ/kg = kJ/s = kW
'heats of formation
hf = DirectCast(ims, IMaterialStream).GetOverallHeatOfFormation()
eb -= hf
End If
Next
For Each oms In omsc
If oms.GraphicObject.Active Then
If DirectCast(oms, IMaterialStream).DefinedFlow = FlowSpec.Mole Then
mi = Convert.ToDouble(oms.GetPropertyValue("PROP_MS_3")) / 1000.0 * Convert.ToDouble(oms.GetPropertyValue("PROP_MS_6"))
Else
mi = Convert.ToDouble(oms.GetPropertyValue("PROP_MS_2"))
End If
hi = Convert.ToDouble(oms.GetPropertyValue("PROP_MS_7"))
eb += mi * hi 'kg/s * kJ/kg = kJ/s = kW
'heats of formation
hf = DirectCast(oms, IMaterialStream).GetOverallHeatOfFormation()
eb += hf
End If
Next
Dim iesc As List(Of ISimulationObject) = GraphicObject.InputConnectors.Where(Function(x) x.IsAttached And (x.IsEnergyConnector Or x.Type = ConType.ConEn)).Select(Function(x) FlowSheet.SimulationObjects(x.AttachedConnector.AttachedFrom.Name)).ToList
Dim oesc As List(Of ISimulationObject) = GraphicObject.OutputConnectors.Where(Function(x) x.IsAttached And (x.IsEnergyConnector Or x.Type = ConType.ConEn)).Select(Function(x) FlowSheet.SimulationObjects(x.AttachedConnector.AttachedTo.Name)).ToList
For Each ies In iesc
If ies.GraphicObject.Active Then
eb -= Convert.ToDouble(ies.GetPropertyValue("PROP_ES_0"))
End If
Next
For Each oes In oesc
If oes.GraphicObject.Active Then
eb += Convert.ToDouble(oes.GetPropertyValue("PROP_ES_0"))
End If
Next
If GraphicObject.EnergyConnector.IsAttached Then
Dim inobj = FlowSheet.SimulationObjects(GraphicObject.EnergyConnector.AttachedConnector.AttachedFrom.Name)
If inobj.GraphicObject.IsEnergyStream And inobj.GraphicObject.Active Then
eb -= Convert.ToDouble(inobj.GetPropertyValue("PROP_ES_0"))
End If
Dim outobj = FlowSheet.SimulationObjects(GraphicObject.EnergyConnector.AttachedConnector.AttachedTo.Name)
If outobj.GraphicObject.IsEnergyStream And outobj.GraphicObject.Active Then
eb += Convert.ToDouble(outobj.GetPropertyValue("PROP_ES_0"))
End If
End If
'If iesc.Count + oesc.Count = 0 And Not GraphicObject.EnergyConnector.IsAttached Then
' eb = 0
'End If
Return eb
End If
Return 0
End Function
Public Function GetMassBalanceResidual() As Double Implements ISimulationObject.GetMassBalanceResidual
If GraphicObject.ObjectType <> ObjectType.MaterialStream And GraphicObject.ObjectType <> ObjectType.EnergyStream And
GraphicObject.ObjectType <> ObjectType.OT_Adjust And GraphicObject.ObjectType <> ObjectType.OT_Spec And
GraphicObject.ObjectType <> ObjectType.OT_Recycle And GraphicObject.ObjectType <> ObjectType.OT_EnergyRecycle Then
'calculate mass balance
Dim mb As Double = 0.0#
Dim mi As Double
Dim imsc As List(Of ISimulationObject) = GraphicObject.InputConnectors.Where(Function(x) x.IsAttached And Not (x.IsEnergyConnector Or x.Type = ConType.ConEn)).Select(Function(x) FlowSheet.SimulationObjects(x.AttachedConnector.AttachedFrom.Name)).ToList
Dim omsc As List(Of ISimulationObject) = GraphicObject.OutputConnectors.Where(Function(x) x.IsAttached And Not (x.IsEnergyConnector Or x.Type = ConType.ConEn)).Select(Function(x) FlowSheet.SimulationObjects(x.AttachedConnector.AttachedTo.Name)).ToList
For Each ims In imsc
If ims.GraphicObject.Active Then
If DirectCast(ims, IMaterialStream).DefinedFlow = FlowSpec.Mole Then
mi = Convert.ToDouble(ims.GetPropertyValue("PROP_MS_3")) / 1000.0 * Convert.ToDouble(ims.GetPropertyValue("PROP_MS_6"))
Else
mi = Convert.ToDouble(ims.GetPropertyValue("PROP_MS_2"))
End If
mb += mi
End If
Next
For Each oms In omsc
If oms.GraphicObject.Active Then
If DirectCast(oms, IMaterialStream).DefinedFlow = FlowSpec.Mole Then
mi = Convert.ToDouble(oms.GetPropertyValue("PROP_MS_3")) / 1000.0 * Convert.ToDouble(oms.GetPropertyValue("PROP_MS_6"))
Else
mi = Convert.ToDouble(oms.GetPropertyValue("PROP_MS_2"))
End If
mb -= mi
End If
Next
Return mb
End If
Return 0
End Function
Public Function GetPowerGeneratedOrConsumed() As Double Implements ISimulationObject.GetPowerGeneratedOrConsumed
If GraphicObject.ObjectType <> ObjectType.MaterialStream And GraphicObject.ObjectType <> ObjectType.EnergyStream And
GraphicObject.ObjectType <> ObjectType.OT_Adjust And GraphicObject.ObjectType <> ObjectType.OT_Spec And
GraphicObject.ObjectType <> ObjectType.OT_Recycle And GraphicObject.ObjectType <> ObjectType.OT_EnergyRecycle Then
Dim eb As Double = 0.0#
Dim ebe As Double = 0.0#
Dim mi, hi, hf As Double
Dim iesc As List(Of ISimulationObject) = GraphicObject.InputConnectors.Where(Function(x) x.IsAttached And (x.IsEnergyConnector Or x.Type = ConType.ConEn)).Select(Function(x) FlowSheet.SimulationObjects(x.AttachedConnector.AttachedFrom.Name)).ToList
Dim oesc As List(Of ISimulationObject) = GraphicObject.OutputConnectors.Where(Function(x) x.IsAttached And (x.IsEnergyConnector Or x.Type = ConType.ConEn)).Select(Function(x) FlowSheet.SimulationObjects(x.AttachedConnector.AttachedTo.Name)).ToList
If iesc.Count + oesc.Count = 0 Then
Dim imsc As List(Of ISimulationObject) = GraphicObject.InputConnectors.Where(Function(x) x.IsAttached And Not (x.IsEnergyConnector Or x.Type = ConType.ConEn)).Select(Function(x) FlowSheet.SimulationObjects(x.AttachedConnector.AttachedFrom.Name)).ToList
Dim omsc As List(Of ISimulationObject) = GraphicObject.OutputConnectors.Where(Function(x) x.IsAttached And Not (x.IsEnergyConnector Or x.Type = ConType.ConEn)).Select(Function(x) FlowSheet.SimulationObjects(x.AttachedConnector.AttachedTo.Name)).ToList
For Each ims In imsc
If ims.GraphicObject.Active Then
If DirectCast(ims, IMaterialStream).DefinedFlow = FlowSpec.Mole Then
mi = Convert.ToDouble(ims.GetPropertyValue("PROP_MS_3")) / 1000.0 * Convert.ToDouble(ims.GetPropertyValue("PROP_MS_6"))
Else
mi = Convert.ToDouble(ims.GetPropertyValue("PROP_MS_2"))
End If
hi = Convert.ToDouble(ims.GetPropertyValue("PROP_MS_7"))
eb -= mi * hi 'kg/s * kJ/kg = kJ/s = kW
'heats of formation
hf = DirectCast(ims, IMaterialStream).GetOverallHeatOfFormation()
eb -= hf
End If
Next
For Each oms In omsc
If oms.GraphicObject.Active Then
If DirectCast(oms, IMaterialStream).DefinedFlow = FlowSpec.Mole Then
mi = Convert.ToDouble(oms.GetPropertyValue("PROP_MS_3")) / 1000.0 * Convert.ToDouble(oms.GetPropertyValue("PROP_MS_6"))
Else
mi = Convert.ToDouble(oms.GetPropertyValue("PROP_MS_2"))
End If
hi = Convert.ToDouble(oms.GetPropertyValue("PROP_MS_7"))
eb += mi * hi 'kg/s * kJ/kg = kJ/s = kW
'heats of formation
hf = DirectCast(oms, IMaterialStream).GetOverallHeatOfFormation()
eb += hf
End If
Next
Return -eb
Else
For Each ies In iesc
If ies.GraphicObject.Active Then
eb -= Convert.ToDouble(ies.GetPropertyValue("PROP_ES_0"))
End If
Next
For Each oes In oesc
If oes.GraphicObject.Active Then
eb += Convert.ToDouble(oes.GetPropertyValue("PROP_ES_0"))
End If
Next
If GraphicObject.EnergyConnector.IsAttached Then
Dim inobj = FlowSheet.SimulationObjects(GraphicObject.EnergyConnector.AttachedConnector.AttachedFrom.Name)
If inobj.GraphicObject.IsEnergyStream And inobj.GraphicObject.Active Then
eb -= Convert.ToDouble(inobj.GetPropertyValue("PROP_ES_0"))
End If
Dim outobj = FlowSheet.SimulationObjects(GraphicObject.EnergyConnector.AttachedConnector.AttachedTo.Name)
If outobj.GraphicObject.IsEnergyStream And outobj.GraphicObject.Active Then
eb += Convert.ToDouble(outobj.GetPropertyValue("PROP_ES_0"))
End If
End If
Return eb
End If
End If
Return 0
End Function
Public Overridable Function GetDynamicResidenceTime() As Double Implements ISimulationObject.GetDynamicResidenceTime
Return Double.NaN
End Function
Public Overridable Function GetDynamicVolume() As Double Implements ISimulationObject.GetDynamicVolume
Return Double.NaN
End Function
Public Overridable Function GetDynamicContents() As Double Implements ISimulationObject.GetDynamicContents
Return Double.NaN
End Function
Public Function GetAsObject() As Object Implements ISimulationObject.GetAsObject
Return Me
End Function
#End Region
#Region " IProductInformation"
Public Overridable ReadOnly Property ProductName As String Implements IProductInformation.ProductName
Get
Return GetDisplayName()
End Get
End Property
Public Overridable ReadOnly Property ProductDescription As String Implements IProductInformation.ProductDescription
Get
Return GetDisplayDescription()
End Get
End Property
Public Overridable ReadOnly Property ProductAuthor As String Implements IProductInformation.ProductAuthor
Get
Return "Daniel Wagner"
End Get
End Property
Public Overridable ReadOnly Property ProductContactInfo As String Implements IProductInformation.ProductContactInfo
Get
Return "https://dwsim.inforside.com.br"
End Get
End Property
Public Overridable ReadOnly Property ProductPage As String Implements IProductInformation.ProductPage
Get
Return "https://dwsim.inforside.com.br"
End Get
End Property
Public Overridable ReadOnly Property ProductVersion As String Implements IProductInformation.ProductVersion
Get
Return Assembly.GetExecutingAssembly().GetName().Version.ToString()
End Get
End Property
Public Overridable ReadOnly Property ProductAssembly As String Implements IProductInformation.ProductAssembly
Get
Return Assembly.GetExecutingAssembly().GetName().Name
End Get
End Property
Public Overridable ReadOnly Property IsSource As Boolean = False Implements ISimulationObject.IsSource
Public Overridable ReadOnly Property IsSink As Boolean = False Implements ISimulationObject.IsSink
Public Property GHGEmissionData As IGHGEmitter Implements ISimulationObject.GHGEmissionData
#End Region
Public Sub ConnectFeedMaterialStream(stream As ISimulationObject, portnumber As Integer) Implements ISimulationObject.ConnectFeedMaterialStream
FlowSheet.ConnectObjects(stream.GraphicObject, GraphicObject, 0, portnumber)
End Sub
Public Sub ConnectProductMaterialStream(stream As ISimulationObject, portnumber As Integer) Implements ISimulationObject.ConnectProductMaterialStream
FlowSheet.ConnectObjects(GraphicObject, stream.GraphicObject, portnumber, 0)
End Sub
Public Sub ConnectFeedEnergyStream(stream As ISimulationObject, portnumber As Integer) Implements ISimulationObject.ConnectFeedEnergyStream
FlowSheet.ConnectObjects(stream.GraphicObject, GraphicObject, 0, portnumber)
End Sub
Public Sub ConnectProductEnergyStream(stream As ISimulationObject, portnumber As Integer) Implements ISimulationObject.ConnectProductEnergyStream
FlowSheet.ConnectObjects(GraphicObject, stream.GraphicObject, 0, portnumber)
End Sub
Public Sub ConnectEnergyStream(stream As ISimulationObject) Implements ISimulationObject.ConnectEnergyStream
If GraphicObject.EnergyConnector.Active Then
FlowSheet.ConnectObjects(GraphicObject, stream.GraphicObject, 0, 0)
Else
Dim i As Integer = 0
For Each con In GraphicObject.InputConnectors
If con.IsEnergyConnector Or con.Type = GraphicObjects.ConType.ConEn Then
FlowSheet.ConnectObjects(stream.GraphicObject, GraphicObject, 0, i)
End If
i += 1
Next
i = 0
For Each con In GraphicObject.InputConnectors
If con.IsEnergyConnector Or con.Type = GraphicObjects.ConType.ConEn Then
FlowSheet.ConnectObjects(GraphicObject, stream.GraphicObject, i, 0)
End If
i += 1
Next
End If
End Sub
Public Function GetConnectionPortsList() As List(Of String) Implements ISimulationObject.GetConnectionPortsList
Dim l As New List(Of String)
Dim i As Integer = 0
For Each con In GraphicObject.InputConnectors
l.Add(String.Format("Inlet Port #{0}, Name: {1}, Type: {2}, Connected: {3}", i, con.ConnectorName, con.Type.ToString(), con.IsAttached))
i += 1
Next
i = 0
For Each con In GraphicObject.OutputConnectors
l.Add(String.Format("Outlet Port #{0}, Name: {1}, Type: {2}, Connected: {3}", i, con.ConnectorName, con.Type.ToString(), con.IsAttached))
i += 1
Next
If GraphicObject.EnergyConnector.Active Then
Dim con = GraphicObject.EnergyConnector
l.Add(String.Format("Energy Stream Port, Name: {1}, Type: {2}, Connected: {3}", i, con.ConnectorName, con.Type.ToString(), con.IsAttached))
End If
Return l
End Function
Public Function GetConnectionPortsInfo() As List(Of IConnectionPortInfo) Implements ISimulationObject.GetConnectionPortsInfo
Dim list As New List(Of IConnectionPortInfo)
Dim i As Integer
If GraphicObject IsNot Nothing Then
i = 0
For Each con In GraphicObject.InputConnectors
Dim ci As New ConnectionPortInfo()
ci.Name = con.ConnectorName
ci.Index = i
ci.IsInput = True
ci.IsConnected = con.IsAttached
If con.IsAttached Then
ci.ConnectedObject = con.AttachedConnector.AttachedFrom.Owner
End If
list.Add(ci)
i += 1
Next
i = 0
For Each con In GraphicObject.OutputConnectors
Dim ci As New ConnectionPortInfo()
ci.Name = con.ConnectorName
ci.Index = i
ci.IsOutput = True
ci.IsConnected = con.IsAttached
If con.IsAttached Then
ci.ConnectedObject = con.AttachedConnector.AttachedTo.Owner
End If
list.Add(ci)
i += 1
Next
If GraphicObject.EnergyConnector.Active Then
Dim econ = GraphicObject.EnergyConnector
Dim ci As New ConnectionPortInfo()
ci.Name = econ.ConnectorName
ci.Index = 0
ci.IsEnergyPort = True
ci.IsConnected = econ.IsAttached
If econ.IsAttached Then
ci.ConnectedObject = econ.AttachedConnector.AttachedTo.Owner
End If
list.Add(ci)
End If
End If
Return list
End Function
Public Sub SetDirtyStatus(value As Boolean) Implements ISimulationObject.SetDirtyStatus
_IsDirty = value
SetCanUsePreviousResults(Not _IsDirty)
End Sub
Public Sub SetCanUsePreviousResults(value As Boolean) Implements ISimulationObject.SetCanUsePreviousResults
_CanUsePreviousResults = value
End Sub
Public Overridable Sub CheckDirtyStatus() Implements ISimulationObject.CheckDirtyStatus
SetDirtyStatus(True)
SetCanUsePreviousResults(False)
End Sub
Public Overridable Sub SetPropertyPackageInstance(PP As IPropertyPackage) Implements ISimulationObject.SetPropertyPackageInstance
End Sub
Public Overridable Function ClearPropertyPackageInstance() As Boolean Implements ISimulationObject.ClearPropertyPackageInstance
Return False
End Function
Public Overridable Function GetEnergyConsumption() As Double Implements ISimulationObject.GetEnergyConsumption
Return 0.0
End Function
Public Overridable Function GetPreferredGraphicObjectWidth() As Double Implements ISimulationObject.GetPreferredGraphicObjectWidth
Return 40.0
End Function
Public Overridable Function GetPreferredGraphicObjectHeight() As Double Implements ISimulationObject.GetPreferredGraphicObjectHeight
Return 40.0
End Function
End Class
End Namespace
|