[83] | 1 | #*------------------------------------------------------------------- |
---|
| 2 | * EMSO Model Library (EML) Copyright (C) 2004 - 2007 ALSOC. |
---|
[1] | 3 | * |
---|
[83] | 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 | *-------------------------------------------------------------------- |
---|
[1] | 18 | * Author: Rafael de Pelegrini Soares |
---|
| 19 | * $Id: sample_calc_object.mso 83 2006-12-08 20:29:34Z paula $ |
---|
[83] | 20 | *------------------------------------------------------------------*# |
---|
[1] | 21 | |
---|
| 22 | using "types"; |
---|
| 23 | |
---|
| 24 | #**************************************************** |
---|
| 25 | * Model with some variables to be calculate further. |
---|
| 26 | * |
---|
| 27 | *# |
---|
| 28 | Model CalcBasic |
---|
| 29 | PARAMETERS |
---|
| 30 | ext 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; |
---|
| 39 | end |
---|
| 40 | |
---|
| 41 | #************************************************* |
---|
| 42 | * Model with a CalcObject for the calculations |
---|
| 43 | * |
---|
| 44 | *# |
---|
| 45 | Model Calc as CalcBasic |
---|
| 46 | PARAMETERS |
---|
| 47 | ext obj as CalcObject; |
---|
| 48 | |
---|
| 49 | EQUATIONS |
---|
| 50 | r1 = obj.method1(T, P); |
---|
| 51 | r2 = obj.method2(T, P); |
---|
| 52 | r3 = obj.method3(z); |
---|
| 53 | end |
---|
| 54 | |
---|
| 55 | |
---|
| 56 | #**************************************************** |
---|
| 57 | * Same as above but with the calculations |
---|
| 58 | * done by equations instead of external routines. |
---|
| 59 | * The results should be the same. |
---|
| 60 | *# |
---|
| 61 | Model Calc2 as CalcBasic |
---|
| 62 | EQUATIONS |
---|
| 63 | r1 = T^2; |
---|
| 64 | r2 = T*P; |
---|
| 65 | r3 = sum(z); |
---|
| 66 | end |
---|
| 67 | |
---|
| 68 | #******************************************************* |
---|
| 69 | * Checking if the results are the same for both |
---|
| 70 | * models (external calculations and explict equations). |
---|
[2] | 71 | * |
---|
| 72 | * NOTE: IN ORDER TO RUN THIS EXAMPLE YOU NEED TO COMPILE |
---|
| 73 | * THE FILE calcsample.cpp IN YOUR INTERFACE DIRECTORY |
---|
| 74 | * |
---|
[1] | 75 | *# |
---|
| 76 | FlowSheet CalcTest |
---|
| 77 | PARAMETERS |
---|
| 78 | obj as CalcObject(File = "calcsample"); |
---|
| 79 | NoComps as Integer(Default = 5); |
---|
| 80 | |
---|
| 81 | DEVICES |
---|
| 82 | calc1 as Calc; |
---|
| 83 | calc2 as Calc2; |
---|
| 84 | |
---|
| 85 | SPECIFY |
---|
| 86 | #calc1.T = 100 * "K"; |
---|
| 87 | #calc1.P = 100 * "Pa"; |
---|
| 88 | calc1.z(1:NoComps-1) = 1/NoComps; |
---|
| 89 | calc1.r1 = 20000 * "K*K"; |
---|
| 90 | calc1.r2 = 10000 * "Pa*K"; |
---|
| 91 | calc1.r3 = 1; |
---|
| 92 | |
---|
| 93 | #calc2.T = 100 * "K"; |
---|
| 94 | #calc2.P = 100 * "Pa"; |
---|
| 95 | calc2.z(1:NoComps-1) = 1/NoComps; |
---|
| 96 | calc2.r1 = 20000 * "K*K"; |
---|
| 97 | calc2.r2 = 10000 * "Pa*K"; |
---|
| 98 | calc2.r3 = 1; |
---|
| 99 | |
---|
| 100 | OPTIONS |
---|
| 101 | relativeAccuracy = 1e-6; |
---|
| 102 | #mode = "steady"; |
---|
| 103 | end |
---|
| 104 | |
---|
| 105 | |
---|
| 106 | |
---|
| 107 | #******************************************************* |
---|
| 108 | * Checking the explict equations. |
---|
| 109 | *# |
---|
| 110 | FlowSheet Calc2Test |
---|
| 111 | PARAMETERS |
---|
| 112 | NoComps as Integer(Default = 5); |
---|
| 113 | |
---|
| 114 | DEVICES |
---|
| 115 | calc2 as Calc2; |
---|
| 116 | |
---|
| 117 | SPECIFY |
---|
| 118 | #calc2.T = 100 * "K"; |
---|
| 119 | #calc2.P = 100 * "Pa"; |
---|
| 120 | calc2.z(1:NoComps-1) = 1/NoComps; |
---|
| 121 | calc2.r1 = 20000 * "K*K"; |
---|
| 122 | calc2.r2 = 10000 * "Pa*K"; |
---|
| 123 | calc2.r3 = 1; |
---|
| 124 | |
---|
| 125 | OPTIONS |
---|
| 126 | relativeAccuracy = 1e-6; |
---|
| 127 | mode = "steady"; |
---|
| 128 | end |
---|
| 129 | |
---|