source: trunk/sample/miscellaneous/sample_calc_object.mso @ 233

Last change on this file since 233 was 217, checked in by Argimiro Resende Secchi, 17 years ago

Remove some warnings from samples.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.9 KB
Line 
1#*-------------------------------------------------------------------
2* EMSO Model Library (EML) Copyright (C) 2004 - 2007 ALSOC.
3*
4* This LIBRARY is free software; you can distribute it and/or modify
5* it under the therms of the ALSOC FREE LICENSE as available at
6* http://www.enq.ufrgs.br/alsoc.
7*
8* EMSO Copyright (C) 2004 - 2007 ALSOC, original code
9* from http://www.rps.eng.br Copyright (C) 2002-2004.
10* All rights reserved.
11*
12* EMSO is distributed under the therms of the ALSOC LICENSE as
13* available at http://www.enq.ufrgs.br/alsoc.
14*
15*--------------------------------------------------------------------
16* Sample file for for using CalcOjbects.
17*--------------------------------------------------------------------
18* Author: Rafael de Pelegrini Soares
19* $Id: sample_calc_object.mso 217 2007-03-16 01:11:56Z arge $
20*------------------------------------------------------------------*#
21
22using "types";
23
24#****************************************************
25* Model with some variables to be calculate further.
26*
27*#
28Model CalcBasic
29        PARAMETERS
30outer NoComps as Integer;
31        VARIABLES
32        T    as temperature;
33        P    as pressure;
34        z(NoComps) as fraction;
35       
36        r1 as Real(Unit='K*K');
37        r2 as Real(Unit='atm*K');
38        r3 as Real;
39end
40
41#*************************************************
42* Model with a CalcObject for the calculations
43*
44*#
45Model Calc as CalcBasic
46        PARAMETERS
47outer obj as Plugin(Type="sample");
48        dummy as Real(Default=0);
49       
50        EQUATIONS
51        r1 = obj.method1(T, dummy);
52        r2 = obj.method2(T, P);
53        r3 = obj.method3(z);
54end
55
56
57#****************************************************
58* Same as above but with the calculations
59* done by equations instead of external routines.
60* The results should be the same.
61*#
62Model Calc2 as CalcBasic
63        EQUATIONS
64        r1 = T^2;
65        r2 = T*P;
66        r3 = sum(z);
67end
68
69#*******************************************************
70* Checking if the results are the same for both
71* models (external calculations and explict equations).
72*
73* NOTE: IN ORDER TO RUN THIS EXAMPLE YOU NEED TO COMPILE
74* THE FILE calcsample.cpp IN YOUR INTERFACE DIRECTORY
75*
76*#
77FlowSheet CalcTest
78        PARAMETERS
79        obj     as Plugin(Type="sample");
80        NoComps as Integer(Default = 5);
81
82        DEVICES
83        calc1   as Calc;
84        calc2   as Calc2;
85       
86        SPECIFY
87        #calc1.T = 100 * 'K';
88        #calc1.P = 100 * 'Pa';
89        calc1.z(1:NoComps-1) = 1/NoComps;
90        calc1.r1 = 20000 * 'K*K';
91        calc1.r2 = 10000 * 'Pa*K';
92        calc1.r3 = 1;
93       
94        #calc2.T = 100 * 'K';
95        #calc2.P = 100 * 'Pa';
96        calc2.z(1:NoComps-1) = 1/NoComps;
97        calc2.r1 = 20000 * 'K*K';
98        calc2.r2 = 10000 * 'Pa*K';
99        calc2.r3 = 1;
100
101        OPTIONS
102        RelativeAccuracy = 1e-6;
103        Dynamic = false;
104end
105
106
107
108#*******************************************************
109* Checking the explict equations.
110*#
111FlowSheet Calc2Test
112        PARAMETERS
113        NoComps as Integer(Default = 5);
114       
115        DEVICES
116        calc2   as Calc2;
117       
118        SPECIFY
119        #calc2.T = 100 * 'K';
120        #calc2.P = 100 * 'Pa';
121        calc2.z(1:NoComps-1) = 1/NoComps;
122        calc2.r1 = 20000 * 'K*K';
123        calc2.r2 = 10000 * 'Pa*K';
124        calc2.r3 = 1;
125       
126        OPTIONS
127        RelativeAccuracy = 1e-6;
128        Dynamic = false;
129end
Note: See TracBrowser for help on using the repository browser.