File size: 2,455 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
Module Module1

    Sub Main()

        'create automation manager
        Dim interf As New DWSIM.Automation.Automation2()

        Dim sim As Interfaces.IFlowsheet

        sim = interf.CreateFlowsheet()

        'load Cavett's Problem simulation file
        sim = interf.LoadFlowsheet("samples" & IO.Path.DirectorySeparatorChar & "Cavett's Problem.dwxml")

        'set a listener to catch solver messages
        'sim.SetMessageListener(Sub(msg As String)
        '                           Console.WriteLine(msg)
        '                       End Sub)

        'use CAPE-OPEN interfaces to manipulate objects
        Dim feed, vap_out, liq_out As CapeOpen.ICapeThermoMaterialObject

        feed = sim.GetFlowsheetSimulationObject("2")
        vap_out = sim.GetFlowsheetSimulationObject("8")
        liq_out = sim.GetFlowsheetSimulationObject("18")

        'mass flow rate values in kg/s
        Dim flows(3) As Double

        flows(0) = 170.0#
        flows(1) = 180.0#
        flows(2) = 190.0#
        flows(3) = 200.0#

        'vapor and liquid flows
        Dim vflow, lflow As Double

        For i = 0 To flows.Length - 1
            'set feed mass flow
            feed.SetProp("totalflow", "overall", Nothing, "", "mass", New Double() {flows(i)})
            'calculate the flowsheet (run the simulation)
            Console.WriteLine("Running simulation with F = " & flows(i) & " kg/s, please wait...")
            interf.CalculateFlowsheet2(sim)
            'check for errors during the last run
            If sim.Solved = False Then
                Console.WriteLine("Error solving flowsheet: " & sim.ErrorMessage)
            End If
            'get vapor outlet mass flow value
            vflow = vap_out.GetProp("totalflow", "overall", Nothing, "", "mass")(0)
            'get liquid outlet mass flow value
            lflow = liq_out.GetProp("totalflow", "overall", Nothing, "", "mass")(0)
            'display results
            Console.WriteLine("Simulation run #" & (i + 1) & " results:" & vbCrLf & "Feed: " & flows(i) & ", Vapor: " & vflow & ", Liquid: " & lflow & " kg/s" & vbCrLf & "Mass balance error: " & (flows(i) - vflow - lflow) & " kg/s")
        Next

        interf.SaveFlowsheet2(sim, "/Users/Daniel/Desktop/savefile.dwxmz")

        Console.WriteLine("Finished OK! Press any key to close.")
        Console.ReadKey()

    End Sub

End Module