~njansson/dolfin/hpc

« back to all changes in this revision

Viewing changes to demo/ode/homotopy/economy/test.cpp

  • Committer: Garth N. Wells
  • Date: 2008-03-29 09:34:25 UTC
  • Revision ID: gnw20@cam.ac.uk-20080329093425-3ea2vhjvccq56zvi
Add some basic build & install instructions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (C) 2005 Johan Hoffman and Anders Logg.
 
2
// Licensed under the GNU LGPL Version 2.1.
 
3
//
 
4
// First added:  2005
 
5
// Last changed: 2005-12-19
 
6
 
 
7
#include <dolfin.h>
 
8
#include "CES.h"
 
9
#include "Leontief.h"
 
10
#include "Polemarchakis.h"
 
11
#include "EavesSchmedders.h"
 
12
 
 
13
using namespace dolfin;
 
14
 
 
15
/// CES test problem from Eaves and Schmedders (rational-rational form).
 
16
/// Has 3 solutions (one real-valued):
 
17
///
 
18
///   p = (0.951883, 0.048117)
 
19
///   p = (0.026816 + 0.309611*i, 0.973184 - 0.309611*i)
 
20
///   p = (0.026816 - 0.309611*i, 0.973184 + 0.309611*i)
 
21
 
 
22
void test1()
 
23
{
 
24
  RationalRationalES ec;
 
25
  ec.solve();
 
26
}
 
27
 
 
28
/// CES test problem from Eaves and Schmedders (polynomial-rational form)
 
29
/// Has 3 solutions (one real-valued):
 
30
///
 
31
///   p = (0.951883, 0.048117)
 
32
///   p = (0.026816 + 0.309611*i, 0.973184 - 0.309611*i)
 
33
///   p = (0.026816 - 0.309611*i, 0.973184 + 0.309611*i)
 
34
 
 
35
void test2()
 
36
{
 
37
  PolynomialRationalES ec;
 
38
  ec.solve();
 
39
}
 
40
 
 
41
/// CES test problem from Eaves and Schmedders (rational-integer form)
 
42
/// Has 3 solutions (one real-valued):
 
43
///
 
44
///   p = (0.951883, 0.048117)
 
45
///   p = (0.026816 + 0.309611*i, 0.973184 - 0.309611*i)
 
46
///   p = (0.026816 - 0.309611*i, 0.973184 + 0.309611*i)
 
47
 
 
48
void test3()
 
49
{
 
50
  RationalIntegerES ec;
 
51
  ec.solve();
 
52
}
 
53
 
 
54
/// CES test problem from Eaves and Schmedders (polynomial-integer form)
 
55
/// Has 3 solutions (one real-valued):
 
56
///
 
57
///   p = (0.951883, 0.048117)
 
58
///   p = (0.026816 + 0.309611*i, 0.973184 - 0.309611*i)
 
59
///   p = (0.026816 - 0.309611*i, 0.973184 + 0.309611*i)
 
60
 
 
61
void test4()
 
62
{
 
63
  PolynomialIntegerES ec;
 
64
  ec.solve();
 
65
}
 
66
 
 
67
/// CES test problem from Eaves and Schmedders (rational-rational form).
 
68
/// Has 3 solutions (one real-valued):
 
69
///
 
70
///   p = (0.951883, 0.048117)
 
71
///   p = (0.026816 + 0.309611*i, 0.973184 - 0.309611*i)
 
72
///   p = (0.026816 - 0.309611*i, 0.973184 + 0.309611*i)
 
73
 
 
74
void test5()
 
75
{
 
76
  RationalRationalCES ec(2, 2);
 
77
 
 
78
  ec.a[0][0] = 4.0; ec.a[0][1] = 1.0;
 
79
  ec.a[1][0] = 1.0; ec.a[1][1] = 4.0;
 
80
  
 
81
  ec.w[0][0] = 10.0; ec.w[0][1] =  1.0;
 
82
  ec.w[1][0] =  1.0; ec.w[1][1] = 12.0;
 
83
  
 
84
  ec.b[0] = 0.2;
 
85
  ec.b[1] = 0.2;    
 
86
 
 
87
  ec.disp();
 
88
  ec.solve();
 
89
}
 
90
 
 
91
/// CES test problem from Eaves and Schmedders (polynomial-rational form)
 
92
/// Has 3 solutions (one real-valued):
 
93
///
 
94
///   p = (0.951883, 0.048117)
 
95
///   p = (0.026816 + 0.309611*i, 0.973184 - 0.309611*i)
 
96
///   p = (0.026816 - 0.309611*i, 0.973184 + 0.309611*i)
 
97
 
 
98
void test6()
 
99
{
 
100
  PolynomialRationalCES ec(2, 2);
 
101
 
 
102
  ec.a[0][0] = 4.0; ec.a[0][1] = 1.0;
 
103
  ec.a[1][0] = 1.0; ec.a[1][1] = 4.0;
 
104
  
 
105
  ec.w[0][0] = 10.0; ec.w[0][1] =  1.0;
 
106
  ec.w[1][0] =  1.0; ec.w[1][1] = 12.0;
 
107
  
 
108
  ec.b[0] = 0.2;
 
109
  ec.b[1] = 0.2;    
 
110
 
 
111
  ec.disp();
 
112
  ec.solve();
 
113
}
 
114
 
 
115
/// CES test problem from Eaves and Schmedders (polynomial-integer form)
 
116
/// Has 3 solutions (one real-valued):
 
117
///
 
118
///   p = (0.951883, 0.048117)
 
119
///   p = (0.026816 + 0.309611*i, 0.973184 - 0.309611*i)
 
120
///   p = (0.026816 - 0.309611*i, 0.973184 + 0.309611*i)
 
121
 
 
122
void test7()
 
123
{
 
124
  PolynomialIntegerCES ec(2, 2);
 
125
 
 
126
  ec.a[0][0] = 4.0; ec.a[0][1] = 1.0;
 
127
  ec.a[1][0] = 1.0; ec.a[1][1] = 4.0;
 
128
  
 
129
  ec.w[0][0] = 10.0; ec.w[0][1] =  1.0;
 
130
  ec.w[1][0] =  1.0; ec.w[1][1] = 12.0;
 
131
  
 
132
  ec.beta[0] = 1;
 
133
  ec.beta[1] = 1;
 
134
 
 
135
  ec.alpha = 5;
 
136
 
 
137
  ec.disp();
 
138
  ec.solve();
 
139
}
 
140
 
 
141
/// Leontief test problem (rational form)
 
142
/// Has one unique solution: p = (0.5, 0.5)
 
143
/// (Also p = (0, 1) with first equation removed)
 
144
 
 
145
void test8()
 
146
{
 
147
  Leontief ec(2, 2);
 
148
 
 
149
  ec.a[0][0] = 2.0; ec.a[0][1] = 1.0;
 
150
  ec.a[1][0] = 1.0; ec.a[1][1] = 2.0;
 
151
  
 
152
  ec.w[0][0] = 1.0; ec.w[0][1] = 2.0;
 
153
  ec.w[1][0] = 2.0; ec.w[1][1] = 1.0;
 
154
 
 
155
  ec.disp();
 
156
  ec.solve();
 
157
}
 
158
 
 
159
/// Leontief test problem (polynomial form)
 
160
/// Has one unique solution: p = (0.5, 0.5)
 
161
/// (Also p = (0, 1) with first equation removed)
 
162
 
 
163
void test9()
 
164
{
 
165
  PolynomialLeontief ec(2, 2);
 
166
 
 
167
  ec.a[0][0] = 2.0; ec.a[0][1] = 1.0;
 
168
  ec.a[1][0] = 1.0; ec.a[1][1] = 2.0;
 
169
  
 
170
  ec.w[0][0] = 1.0; ec.w[0][1] = 2.0;
 
171
  ec.w[1][0] = 2.0; ec.w[1][1] = 1.0;
 
172
 
 
173
  ec.disp();
 
174
  ec.solve();
 
175
}
 
176
 
 
177
/// Leontief test problem from Polemarchakis (rational form)
 
178
/// Has two solutions:
 
179
///
 
180
///   p = (1, 1)
 
181
///   p = (-2149/600, 1) = (-3.581667, 1)
 
182
 
 
183
void test10()
 
184
{
 
185
  Polemarchakis ec;
 
186
  ec.solve();
 
187
}
 
188
 
 
189
/// Leontief test problem from Polemarchakis (polynomial form)
 
190
/// Has two solutions:
 
191
///
 
192
///   p = (1, 1)
 
193
///   p = (-2149/600, 1) = (-3.581667, 1)
 
194
 
 
195
void test11()
 
196
{
 
197
  PolynomialPolemarchakis ec;
 
198
  ec.solve();
 
199
}
 
200
 
 
201
int main()
 
202
{
 
203
  dolfin_set("ODE method", "cg");
 
204
  dolfin_set("ODE order", 1);
 
205
  dolfin_set("ODE tolerance", 0.01);
 
206
  dolfin_set("ODE discrete tolerance", 1e-10);
 
207
  dolfin_set("ODE initial time step", 0.001);
 
208
  //dolfin_set("linear solver", "direct");
 
209
  dolfin_set("ODE adaptive samples", false);
 
210
  dolfin_set("homotopy monitoring", false);
 
211
  dolfin_set("homotopy divergence tolerance", 10.0);
 
212
  dolfin_set("homotopy randomize", false);
 
213
 
 
214
  // Test  1: CES test problem from Eaves and Schmedders (rational-rational form).
 
215
  // Test  2: CES test problem from Eaves and Schmedders (polynomial-rational form)
 
216
  // Test  3: CES test problem from Eaves and Schmedders (rational-integer form)
 
217
  // Test  4: CES test problem from Eaves and Schmedders (polynomial-integer form)
 
218
  // Test  5: CES test problem from Eaves and Schmedders (rational-rational form).
 
219
  // Test  6: CES test problem from Eaves and Schmedders (polynomial-rational form)
 
220
  // Test  7: CES test problem from Eaves and Schmedders (polynomial-integer form)
 
221
  // Test  8: Leontief test problem (rational form)
 
222
  // Test  9: Leontief test problem (polynomial form)
 
223
  // Test 10: Leontief test problem from Polemarchakis (rational form)
 
224
  // Test 11: Leontief test problem from Polemarchakis (polynomial form)
 
225
  //
 
226
  // Test 1 and 5 should give the same result (one solution).
 
227
  // Test 2 and 6 should give the same result (two solutions).
 
228
  // Test 4 and 7 should give the same result (three solution + three extra invalid)
 
229
  //
 
230
  // Test 4 and 7 find the most solutions.
 
231
  
 
232
  test7();
 
233
 
 
234
  return 0;
 
235
}