File size: 2,658 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AddObjectsToDWSIM
{
    class createFile_oldAPI
    {
        static void Main()
        {
            // replace with DWSIM's installation directory on your computer
            System.IO.Directory.SetCurrentDirectory("C:/Program Files/DWSIM6");

            //create automation manager
            DWSIM.Automation.Automation interf = new DWSIM.Automation.Automation();

            DWSIM.Interfaces.IFlowsheet sim;

            //load *.dwxmz empty simulation file
            string fileName = "simulation_template.dwxmz";

            sim = interf.LoadFlowsheet(fileName);

            var c1 = sim.AddObject(DWSIM.Interfaces.Enums.GraphicObjects.ObjectType.Cooler, 100, 100, "COOLER-001"); 
            var e1 = sim.AddObject(DWSIM.Interfaces.Enums.GraphicObjects.ObjectType.EnergyStream, 130, 150, "HEAT_OUT");
            var m1 = sim.AddObject(DWSIM.Interfaces.Enums.GraphicObjects.ObjectType.MaterialStream, 50, 100, "INLET");
            var m2 = sim.AddObject(DWSIM.Interfaces.Enums.GraphicObjects.ObjectType.MaterialStream, 150, 100, "OUTLET");

            // create the graphic object connectors manually as they are not being drawn on screen. 

            ((dynamic)c1.GraphicObject).PositionConnectors();
            ((dynamic)m1.GraphicObject).PositionConnectors();
            ((dynamic)m2.GraphicObject).PositionConnectors();
            ((dynamic)e1.GraphicObject).PositionConnectors();

            // connect the graphic objects.

            sim.ConnectObjects(m1.GraphicObject, c1.GraphicObject, 0, 0);
            sim.ConnectObjects(c1.GraphicObject, m2.GraphicObject, 0, 0);
            sim.ConnectObjects(c1.GraphicObject, e1.GraphicObject, 0, 0);

            // create and add an instance of PR Property Package
            
            var pr = new DWSIM.Thermodynamics.PropertyPackages.PengRobinsonPropertyPackage();
            pr.ComponentName = "Peng-Robinson (PR)";
            pr.ComponentDescription = "Any Description"; // <-- important to set any text as description.

            sim.AddPropertyPackage(pr);

            m1.PropertyPackage = sim.PropertyPackages.Values.First();
            m2.PropertyPackage = sim.PropertyPackages.Values.First();
            c1.PropertyPackage = sim.PropertyPackages.Values.First();

            // request a calculation

            sim.RequestCalculation();

            // save file as dwxmz (compressed XML)

            string fileNameToSave = "created_file.dwxmz";
            interf.SaveFlowsheet(sim, fileNameToSave, true);

        }
    }
}