source: branches/newlanguage/sample/miscellaneous/sample_switcher.mso @ 137

Last change on this file since 137 was 137, checked in by Rafael de Pelegrini Soares, 15 years ago

Added swithcer sample

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 950 bytes
Line 
1
2using "types";
3
4Model BallWithSafetyValve
5        ATTRIBUTES
6        Info = "A fixed volume ball with a safety valve
7        for the pressure.";
8       
9    PARAMETERS
10    ValveMode as Switcher(Valid = ["closed", "opened"], Default = "closed");
11        R as Real(Unit="J/(K*mol)", Default=8.314472);
12        V as volume;
13        T as temperature;
14        Pout as pressure;
15        k as Real;
16
17        VARIABLES
18        flow_in as flow_mol;
19        flow_out as flow_mol;
20        P as pressure;
21        n as mol;
22       
23    EQUATIONS
24
25        "Ideal gas relation"
26        P*V = n*R*T;
27       
28        "Mass balance"
29        diff(n) = flow_in - flow_out;
30       
31    switch ValveMode
32        case "closed":
33                flow_out = 0 * "mol/h";
34                when P > 2*"atm" switchto "opened";
35
36        case "opened":
37                flow_out = k*sqrt(P - Pout);
38                when P < Pout * 1.1 switchto "closed";
39        end
40end
41
42FlowSheet Test
43        DEVICES
44        ball as BallWithSafetyValve;
45       
46        SET
47        ball.V = 1 * "l";
48        ball.T = 300 * "K";
49        ball.Pout = 1 * "atm";
50        ball.ValveMode = "closed";
51       
52        SPECIFY
53        ball.flow_in = 2 * "mol/h";
54       
55        INITIAL
56        ball.P = 0.8 * "atm";
57end
Note: See TracBrowser for help on using the repository browser.