/[ascend]/trunk/models/test/ipopt/formula.a4c
ViewVC logotype

Contents of /trunk/models/test/ipopt/formula.a4c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2329 - (show annotations) (download) (as text)
Wed Dec 22 12:52:47 2010 UTC (7 years, 11 months ago) by jpye
File MIME type: text/x-ascend
File size: 3517 byte(s)
Suppressing some console output.
Added test case that current crashes ASCEND/IPOPT with a memory error.
Issue with library.cpp not containing any way to free libascend memory.
1 (* ASCEND modelling environment
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 59 Temple Place - Suite 330,
16 Boston, MA 02111-1307, USA.
17 *)
18 REQUIRE "atoms.a4l";
19 (*
20 This model is from W A Dollase & W I Newman (1984) 'Statistically most probable
21 stoichiometric formulae', American Mineralogist (69) 553-556, accessed online at
22 http://www.minsocam.org/msa/collectors_corner/arc/formula.htm
23
24 As of 21 Dec 2010, this file crashes ASCEND if run with IPOPT as the solver.
25
26 Model written by Roger Mason, with contributions from John Pye.
27 *)
28
29
30 (*
31 A general container for the equations of Dollase & Newman
32 *)
33 MODEL formula_base;
34 n IS_A integer_constant; (* number of elements *)
35 m IS_A integer_constant; (* number of constraints *)
36 n :== 4;
37 m :== 3;
38
39 w[1..n] IS_A factor; (* weight of oxide, per cation *)
40 C[1..m][1..n] IS_A factor; (* constraint coefficients *)
41 Cs[1..m] IS_A factor; (* constraint sums *)
42 x[1..n] IS_A fraction; (* oxide component concentration *)
43 N[1..n] IS_A factor; (* numbers of moles of each oxide *)
44 k IS_A factor; (* 'normalisation factor, to be determinied' *)
45
46 y[1..n] IS_A fraction; (* given weight fraction analyte *)
47 s[1..n] IS_A factor; (* standard deviation in given weight fraction *)
48
49 (* objective function *)
50 objective: MINIMIZE SUM[ (y[i] - x[i])^2/s[i]^2 | i IN [1..n]]; (* 1 *)
51
52 (* molecular structure constraints *)
53 FOR j IN [1..m] CREATE
54 Cs[j] = SUM[ C[j][i]*N[i] | i IN [1..n]]; (* 2 *)
55 END FOR;
56
57 FOR i IN [1..n] CREATE
58 N[i] = k * x[i]/w[i]; (* 3 *)
59 END FOR;
60
61 (* sum of concentrations must equal unity *)
62 1 = SUM[ x[i] | i IN [1..n]]; (* 5 *)
63
64 END formula_base;
65
66 (*
67 A specific example implementing the above equation: plagioclase feldspar.
68 *)
69 MODEL formula REFINES formula_base;
70
71 METHODS
72 METHOD specify;
73 FIX C[1..3][1..4];
74 FIX Cs[1..4];
75 FIX w[1..4];
76 FIX y[1..4];
77 FIX s[1..4];
78
79 FIX k;
80 END specify;
81 METHOD values;
82 (* there are 8 total oxygens, *)
83 Cs[1] := 8.0;
84 C[1][1] := 0.5;
85 C[1][2] := 1.0;
86 C[1][3] := 1.5;
87 C[1][4] := 2.0;
88
89 (* four atoms in tetrahedral sites, and *)
90 Cs[2] := 4.0;
91 C[2][1] := 0.0;
92 C[2][2] := 0.0;
93 C[2][3] := 1.0;
94 C[2][4] := 1.0;
95
96 (* the sum of Na + Ca is equal to one. *)
97 Cs[3] := 1.0;
98 C[3][1] := 1.0;
99 C[3][2] := 1.0;
100 C[3][3] := 0.0;
101 C[3][4] := 0.0;
102
103 (* cation weights *)
104 w[1] := 30.9895; (* 22.9898 + 15.9994*(1/2) *)
105 w[2] := 56.0774; (* 40.078 + 15.9994 *)
106 w[3] := 50.9806; (* 26.9815 + 15.9994*(3/2) *)
107 w[4] := 60.0843; (* 28.0855 + 15.9994*(2/1) *)
108
109 y[1] := 11.19/100 {};
110 y[2] := 1.07/100 {};
111 y[3] := 20.35/100 {};
112 y[4] := 67.39/100 {};
113
114 k := 2.62925;
115
116 s[1] := 0.05 {};
117 s[2] := 0.05 {};
118 s[3] := 0.05 {};
119 s[4] := 0.05 {};
120
121 END values;
122 METHOD default_self;
123 x[1] := 11.29/100 {};
124 x[2] := 1.01/100 {};
125 x[3] := 20.31/100 {};
126 x[4] := 67.30/100 {};
127 END default_self;
128
129 METHOD on_load;
130 RUN reset;
131 RUN values;
132 RUN specify;
133 END on_load;
134
135 METHOD self_test;
136 END self_test;
137
138 END formula;

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22