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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
'    DWSIM Interface definitions
'    Copyright 2010-2021 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/>.

''' <summary>
''' The IFlowsheet interface is the main interface which should be implemented by the Flowsheet class. 
''' It provides direct access to the various flowsheet components and helper functions to manipulate objects.
''' </summary>
<InterfaceType(ComInterfaceType.InterfaceIsIDispatch)>
Public Interface IFlowsheet

    Enum MessageType
        Information
        Warning
        GeneralError
        Tip
        Other
    End Enum

    Property DynamicMode As Boolean

    Property FileDatabaseProvider As IFileDatabaseProvider

    Property DynamicsManager As IDynamicsManager

    Property ExtraProperties As Dynamic.ExpandoObject

    Function GetApplicationObject() As Object

    Property AvailableCompounds As Dictionary(Of String, ICompoundConstantProperties)

    Property ExternalSolvers As Dictionary(Of String, IExternalSolverIdentification)

    Function SaveToXML() As XDocument

    Property FilePath As String

    Property RedirectMessages As Boolean

    ReadOnly Property UtilityPlugins As Dictionary(Of String, IUtilityPlugin)

    Property MasterUnitOp As ISimulationObject

    Property GraphicObjects As Dictionary(Of String, IGraphicObject)

    Property PropertyPackages As Dictionary(Of String, IPropertyPackage)

    Property AvailablePropertyPackages As Dictionary(Of String, IPropertyPackage)

    Property AvailableSystemsOfUnits As List(Of IUnitsOfMeasure)

    Property Reactions As Dictionary(Of String, IReaction)

    Property ReactionSets As Dictionary(Of String, IReactionSet)

    Property SelectedCompounds As Dictionary(Of String, ICompoundConstantProperties)

    Property SimulationObjects As Dictionary(Of String, ISimulationObject)

    Property StoredSolutions As Dictionary(Of String, List(Of XElement))

    Property Charts As Dictionary(Of String, IChart)

    Property WatchItems As List(Of IWatchItem)

    Sub ShowMessage(ByVal text As String, ByVal mtype As MessageType, Optional ByVal exceptionID As String = "")

    Sub ShowDebugInfo(ByVal text As String, ByVal level As Integer)

    Sub CheckStatus()

    Sub RequestCalculation(Optional ByVal sender As ISimulationObject = Nothing, Optional ByVal ChangeCalculationOrder As Boolean = False)

    Function GetTranslatedString(text As String, locale As String) As String

    Function GetTranslatedString(text As String) As String

    ReadOnly Property FlowsheetOptions As IFlowsheetOptions

    Function GetFlowsheetSimulationObject(tag As String) As ISimulationObject

    Function GetSelectedFlowsheetSimulationObject(tag As String) As ISimulationObject

    Function GetObject(name As String) As ISimulationObject

    Function GetCompound(name As String) As ICompoundConstantProperties

    Function GetPropertyPackage(name As String) As IPropertyPackage

    Function GetReaction(name As String) As IReaction

    Function GetReactionSet(name As String) As IReactionSet

    Sub AutoLayout()

    Sub NaturalLayout()

    Sub DisplayForm(form As Object)

    Sub UpdateOpenEditForms()

    Sub ConnectObjects(gobjfrom As IGraphicObject, gobjto As IGraphicObject, fromidx As Integer, toidx As Integer)

    Sub DisconnectObjects(gobjfrom As IGraphicObject, gobjto As IGraphicObject)

    Function GetFlowsheetBag() As IFlowsheetBag

    Sub AddCompoundsToMaterialStream(stream As IMaterialStream)

    Function AddObject(t As Enums.GraphicObjects.ObjectType, xcoord As Integer, ycoord As Integer, tag As String) As ISimulationObject

    Function AddObject(t As Enums.GraphicObjects.ObjectType, xcoord As Integer, ycoord As Integer, id As String, tag As String) As ISimulationObject

    Sub AddGraphicObject(obj As IGraphicObject)

    Sub AddSimulationObject(obj As ISimulationObject)

    Function GetUtility(uttype As Enums.FlowsheetUtility) As IAttachedUtility

    Function GetSurface() As Object

    Function GetSurfaceControl() As Object

    Function GetNewInstance() As IFlowsheet

    Sub AddPropertyPackage(obj As IPropertyPackage)

    Property MasterFlowsheet As IFlowsheet

    Sub AddUndoRedoAction(action As IUndoRedoAction)

    Sub UpdateSpreadsheet(act As Action)

    Sub WriteSpreadsheetVariables(act As Action)

    Function GetSpreadsheetData(range As String) As List(Of String())

    Function GetSpreadsheetFormat(range As String) As List(Of String())

    Property MobileCompatibilityMode As Boolean

    Property Message As String

    Sub SetMessageListener(act As Action(Of String, MessageType))

    Property Solved As Boolean

    Property ErrorMessage As String

    Sub RunCodeOnUIThread(act As Action)

    Function GetDockPanel() As Object

    Sub LoadFromXML(xdoc As XDocument)

    Sub Initialize()

    Sub Reset()

    Sub DeleteSelectedObject(sender As Object, e As EventArgs, gobj As IGraphicObject, Optional confirmation As Boolean = True, Optional triggercalc As Boolean = False)

    Sub ProcessScripts(eventType As Enums.Scripts.EventType, objectType As Enums.Scripts.ObjectType, obj As String)

    Property Scripts As Dictionary(Of String, IScript)

    Sub UpdateInterface()

    Sub UpdateInformation()

    Sub RefreshInterface()

    Function GetFlowsheetSurfaceWidth() As Integer

    Function GetFlowsheetSurfaceHeight() As Integer

    Function ChangeCalculationOrder(objects As List(Of String)) As List(Of String)

    Function GetProcessData() As List(Of XElement)

    Sub LoadProcessData(data As List(Of XElement))

    Function GetSpreadsheetObject() As Object

    Sub SetTranslateTextExternalFunction(act As Func(Of String, String))

    Function GetScriptText(name As String) As String

    Sub RunScript(name As String)

    Function GetSimulationFilePath() As String

    Function GetSimulationFileDirectory() As String

    Sub ClearLog()

    Property PythonPreprocessor() As Action(Of String)

    Property SupressMessages As Boolean

    Sub RequestSave()

    Sub RequestSaveWithDirectory(directory As String)

    Sub RequestSaveWithPath(filepath As String)

    Sub ToggleFlowsheetAnimation()

    Function RunCodeOnUIThread2(act As Action) As Task

    Property WeatherProvider As IWeatherProvider

    ''' <summary>
    ''' Creates a Conversion reaction object.
    ''' </summary>
    ''' <param name="name">Name/ID of the reaction</param>
    ''' <param name="description">Description of the reaction</param>
    ''' <param name="compounds_and_stoichcoeffs">Compound names and stoichiometric coefficients</param>
    ''' <param name="basecompound">Name of the base reaction compound</param>
    ''' <param name="reactionphase">Reaction phase ('Mixture', 'Vapor', 'Liquid' or 'Solid')</param>
    ''' <param name="conversionExpression">Expression for evaluating conversion of the base compound as a function of temperature in K.</param>
    Function CreateConversionReaction(name As String, description As String,
                                      compounds_and_stoichcoeffs As Dictionary(Of String, Double),
                                      basecompound As String, reactionphase As String,
                                      conversionExpression As String) As IReaction

    ''' <summary>
    ''' Creates an Equilibrium reaction object.
    ''' </summary>
    ''' <param name="name">Name/ID of the reaction</param>
    ''' <param name="description">Description of the reaction</param>
    ''' <param name="compounds_and_stoichcoeffs">Compound names and stoichiometric coefficients</param>
    ''' <param name="basecompound">Name of the base reaction compound</param>
    ''' <param name="reactionphase">Reaction phase ('Mixture', 'Vapor', 'Liquid' or 'Solid')</param>
    ''' <param name="basis">Reaction basis ('Activity', 'Fugacity', 'Molar Concentration', 'Molar Fraction', 'Mass Concentration', 'Mass Fraction' or 'Partial Pressure')</param>
    ''' <param name="lnKeq_fT">Expression for evaulating the equilibrium constant as a function of temperature in K. Will use gibbs energy of formation if empty.</param>
    ''' <param name="Tapproach">Temperature value that will be added or removed to the system temperature in order to evaluate the equilibrium constant</param>
    ''' <param name="units">Basis units. See the list of <see cref="SharedClasses.SystemsOfUnits.Units.GetUnitSet()">supported units</see></param>
    Function CreateEquilibriumReaction(name As String, description As String,
                                      compounds_and_stoichcoeffs As Dictionary(Of String, Double),
                                      basecompound As String, reactionphase As String,
                                      basis As String, units As String, Tapproach As Double, lnKeq_fT As String) As IReaction

    ''' <summary>
    ''' Creates a Kinetic reaction object.
    ''' </summary>
    ''' <param name="name">Name/ID of the reaction</param>
    ''' <param name="description">Description of the reaction</param>
    ''' <param name="compounds_and_stoichcoeffs">Compound names and stoichiometric coefficients</param>
    ''' <param name="directorders">Compound names and direct order coefficients</param>
    ''' <param name="reverseorders">Compound names and reverse order coefficients</param>
    ''' <param name="basecompound">Name of the base reaction compound</param>
    ''' <param name="reactionphase">Reaction phase ('Mixture', 'Vapor', 'Liquid' or 'Solid')</param>
    ''' <param name="basis">Reaction basis ('Activity', 'Fugacity', 'Molar Concentration', 'Molar Fraction', 'Mass Concentration', 'Mass Fraction' or 'Partial Pressure')</param>
    ''' <param name="amountunits">Amount units. See the list of <see cref="SharedClasses.SystemsOfUnits.Units.GetUnitSet()">supported units</see></param>
    ''' <param name="rateunits">Rate units. See the list of <see cref="SharedClasses.SystemsOfUnits.Units.GetUnitSet()">supported units</see></param>
    ''' <param name="Aforward">Arrhenius forward reaction's A parameter. Ignored if Expr_forward is not empty.</param>
    ''' <param name="Eforward">Arrhenius forward reaction's E parameter. Ignored if Expr_forward is not empty.</param>
    ''' <param name="Areverse">Arrhenius reverse reaction's A parameter. Ignored if Expr_reverse is not empty.</param>
    ''' <param name="Ereverse">Arrhenius reverse reaction's E parameter. Ignored if Expr_reverse is not empty.</param>
    ''' <param name="Expr_forward">User-defined expression for forward reaction kinetics as a function of temperature in K. Will use Arrhenius if empty.</param>
    ''' <param name="Expr_reverse">User-defined expression for reverse reaction kinetics as a function of temperature in K. Will use Arrhenius if empty.</param>
    ''' <returns></returns>
    Function CreateKineticReaction(name As String, description As String,
                                    compounds_and_stoichcoeffs As Dictionary(Of String, Double),
                                    directorders As Dictionary(Of String, Double),
                                    reverseorders As Dictionary(Of String, Double),
                                    basecompound As String, reactionphase As String,
                                    basis As String, amountunits As String, rateunits As String,
                                    Aforward As Double, Eforward As Double, Areverse As Double, Ereverse As Double,
                                    Expr_forward As String, Expr_reverse As String) As IReaction

    ''' <summary>
    ''' Creates a Heterogeneous Catalytic reaction object.
    ''' </summary>
    ''' <param name="name">Name/ID of the reaction</param>
    ''' <param name="description">Description of the reaction</param>
    ''' <param name="compounds_and_stoichcoeffs">Compound names and stoichiometric coefficients</param>
    ''' <param name="basecompound">Name of the base reaction compound</param>
    ''' <param name="reactionphase">Reaction phase ('Mixture', 'Vapor', 'Liquid' or 'Solid')</param>
    ''' <param name="basis">Reaction basis ('Activity', 'Fugacity', 'Molar Concentration', 'Molar Fraction', 'Mass Concentration', 'Mass Fraction' or 'Partial Pressure')</param>
    ''' <param name="amountunits">Amount units. See the list of <see cref="SharedClasses.SystemsOfUnits.Units.GetUnitSet()">supported units</see></param>
    ''' <param name="rateunits">Rate units. See the list of <see cref="SharedClasses.SystemsOfUnits.Units.GetUnitSet()">supported units</see></param>
    ''' <param name="numeratorExpression">Numerator expression</param>
    ''' <param name="denominatorExpression">Denominator expression</param>
    ''' <returns>Reaction object</returns>
    Function CreateHetCatReaction(name As String, description As String,
                                    compounds_and_stoichcoeffs As Dictionary(Of String, Double),
                                    basecompound As String, reactionphase As String,
                                    basis As String, amountunits As String, rateunits As String,
                                    numeratorExpression As String, denominatorExpression As String) As IReaction

    ''' <summary>
    ''' Creates a Reaction Set object.
    ''' </summary>
    ''' <param name="name">Name/ID of the reaction set</param>
    ''' <param name="description">Description</param>
    ''' <returns></returns>
    Function CreateReactionSet(name As String, description As String) As IReactionSet

    ''' <summary>
    ''' Add a reaction to the flowsheet.
    ''' </summary>
    ''' <param name="reaction">reaction object</param>
    Sub AddReaction(reaction As IReaction)

    ''' <summary>
    ''' Add a reaction set to the flowsheet.
    ''' </summary>
    ''' <param name="reactionSet">reaction set object</param>
    Sub AddReactionSet(reactionSet As IReactionSet)

    ''' <summary>
    ''' Adds a reaction to a reaction set.
    ''' </summary>
    ''' <param name="reactionID">reaction ID</param>
    ''' <param name="reactionSetID">reaction set ID</param>
    ''' <param name="enabled">True if the reaction is to be active in the reaction set</param>
    ''' <param name="rank">Rank  (0, 1, 2, 3...) of the reaction in the reaction set</param>
    Sub AddReactionToSet(reactionID As String, reactionSetID As String, enabled As Boolean, rank As Integer)

    ''' <summary>
    ''' Gets a list of all available Property Packages.
    ''' </summary>
    ''' <returns>A list containing the names of the available property packages.</returns>
    Function GetAvailablePropertyPackages() As List(Of String)

    ''' <summary>
    ''' Creates and returns a new Property Package.
    ''' </summary>
    ''' <param name="name">Name of the Property Package as returned by <see cref="GetAvailablePropertyPackages">GetAvailablePropertyPackages</see></param>
    ''' <returns></returns>
    Function CreatePropertyPackage(name As String) As IPropertyPackage

    ''' <summary>
    ''' Creates and adds a Property Package to the flowsheet.
    ''' </summary>
    ''' <param name="name">Name of the Property Package as returned by <see cref="GetAvailablePropertyPackages">GetAvailablePropertyPackages</see>.</param>
    ''' <returns></returns>
    Function CreateAndAddPropertyPackage(name As String) As IPropertyPackage

    ''' <summary>
    ''' Adds a compound to the flowsheet.
    ''' </summary>
    ''' <param name="compname">Compound name exactly as in the database.</param>
    ''' <returns></returns>
    Function AddCompound(compname As String) As ICompoundConstantProperties

    Sub SetDirtyStatus()

    Function GetAvailableFlowsheetObjectTypeNames() As Array

    Function AddFlowsheetObject(typename As String, objname As String) As ISimulationObject

    Sub DisplayBrowserWindow(url As String)

    Sub DisplayDockableBrowserWindow(url As String)

    Sub RequestCalculation2(Wait As Boolean)

    Sub RequestCalculation3(obj As ISimulationObject, Wait As Boolean)

    Function RequestCalculationAndWait() As List(Of Exception)

    Property MessagesLog As List(Of String)

    Property AvailableExternalUnitOperations As Dictionary(Of String, IExternalUnitOperation)

    Property AvailableSimulationObjects As Dictionary(Of String, ISimulationObject)

    Function GetSnapshot(type As Enums.SnapshotType, Optional obj As ISimulationObject = Nothing) As XDocument

    Sub RestoreSnapshot(data As XDocument, type As Enums.SnapshotType)

    Sub RegisterSnapshot(stype As Enums.SnapshotType, Optional obj As ISimulationObject = Nothing)

    Sub ResetCalculationStatus()

    Sub CloseOpenEditForms()

    Function Clone() As IFlowsheet

    Property Results As IFlowsheetResults

    Property GHGEmissionCompositions As Dictionary(Of String, IGHGComposition)

    Function GetResultIDs() As List(Of String)

    Function GetResultValue(id As String) As Double

    Function GetResultUnits(id As String) As String

    Property ParticleSizeDistributions As List(Of ISolidParticleSizeDistribution)

    Sub ReleaseResources()

    Sub UpdateMassAndEnergyBalance()

End Interface

''' <summary>
''' This is an interface which provides direct access to collections of flowsheet objects.
''' </summary>
<InterfaceType(ComInterfaceType.InterfaceIsIDispatch)>
Public Interface IFlowsheetBag

    Property SimulationObjects As Dictionary(Of String, ISimulationObject)

    Property GraphicObjects As Dictionary(Of String, IGraphicObject)

    Property Compounds As Dictionary(Of String, ICompoundConstantProperties)

    Property PropertyPackages As Dictionary(Of String, IPropertyPackage)

    Property Reactions As Dictionary(Of String, IReaction)

    Property ReactionSets As Dictionary(Of String, IReactionSet)

    Sub SaveToXML(file As String)

    Sub UpdateProcessData(xdoc As XDocument)

    Function GetSurface() As Object

    'For COM compatibility

    Property SimulationObjectsArray As ISimulationObject()

    Property GraphicObjectsArray As IGraphicObject()

    Property CompoundsArray As ICompoundConstantProperties()

    Property PropertyPackagesArray As IPropertyPackage()

    Property ReactionsArray As IReaction()

    Property ReactionSetsArray As IReactionSet()

End Interface

''' <summary>
''' This is an interface which defines helper functions to a Flowsheet GUI implementation.
''' </summary>
<InterfaceType(ComInterfaceType.InterfaceIsIDispatch)>
Public Interface IFlowsheetGUI

    Sub ShowMessage(ByVal text As String, ByVal mtype As IFlowsheet.MessageType, Optional ByVal exceptionID As String = "")

    Sub ShowDebugInfo(ByVal text As String, ByVal level As Integer)

    Sub CheckStatus()

    Function GetTranslatedString(text As String, locale As String) As String

    Function GetTranslatedString(text As String) As String

    Sub ProcessScripts(eventType As Enums.Scripts.EventType, objectType As Enums.Scripts.ObjectType, obj As String)

    Sub UpdateInterface()

    Sub UpdateInformation()

End Interface

''' <summary>
''' This interface defines the calculation queue to be used by the flowsheet solver.
''' </summary>
<InterfaceType(ComInterfaceType.InterfaceIsIDispatch)>
Public Interface IFlowsheetCalculationQueue

    Property CalculationQueue As Queue(Of ICalculationArgs)

End Interface

<InterfaceType(ComInterfaceType.InterfaceIsIDispatch)>
Public Interface ICalculationArgs

    Property Sender As String
    Property Calculated As Boolean
    Property Tag As String
    Property Name As String
    Property ObjectType As Enums.GraphicObjects.ObjectType

End Interface