Debian Codegraph @

Codes/Test/Evolution/test_evol.C

raw
1 /*
2 * Main code for test of template class Evolution
3 *
4 * (see file evolution.h for documentation).
5 *
6 */
7
8 /*
9 * Copyright (c) 2004 Eric Gourgoulhon & Jerome Novak
10 *
11 * This file is part of LORENE.
12 *
13 * LORENE is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License version 2
15 * as published by the Free Software Foundation.
16 *
17 * LORENE is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with LORENE; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
26 */
27
28 char test_evol_C[] = "$Header: /cvsroot/Lorene/Codes/Test/Evolution/test_evol.C,v 1.8 2014/10/13 08:54:01 j_novak Exp $" ;
29
30 /*
31 * $Id: test_evol.C,v 1.8 2014/10/13 08:54:01 j_novak Exp $
32 * $Log: test_evol.C,v $
33 * Revision 1.8 2014/10/13 08:54:01 j_novak
34 * Lorene classes and functions now belong to the namespace Lorene.
35 *
36 * Revision 1.7 2014/10/06 15:12:52 j_novak
37 * Modified #include directives to use c++ syntax.
38 *
39 * Revision 1.6 2008/09/19 13:24:30 j_novak
40 * Added the third-order scheme for the time derivativre computation.
41 *
42 * Revision 1.5 2004/03/26 08:24:03 e_gourgoulhon
43 * Takes into account the new setting of class Evolution.
44 *
45 * Revision 1.4 2004/03/06 21:13:52 e_gourgoulhon
46 * Added test of time derivation.
47 *
48 * Revision 1.3 2004/02/16 10:30:04 e_gourgoulhon
49 * Added #include <math.h>
50 *
51 * Revision 1.2 2004/02/15 22:01:36 e_gourgoulhon
52 * New version to take into account the split of Evolution
53 * into Evolution_full and Evolution_std.
54 *
55 * Revision 1.1 2004/02/13 15:54:03 e_gourgoulhon
56 * First version.
57 *
58 *
59 * $Header: /cvsroot/Lorene/Codes/Test/Evolution/test_evol.C,v 1.8 2014/10/13 08:54:01 j_novak Exp $
60 *
61 */
62
63 // C++ headers
64 #include "headcpp.h"
65
66 // C headers
67 #include <cstdlib>
68 #include <cmath>
69
70 // Lorene headers
71 #include "evolution.h"
72 #include "tensor.h"
73 #include "utilitaires.h"
74
75 using namespace Lorene ;
76
77 int main() {
78
79
80 //------------------------------------------------
81 // Test with a double
82 //------------------------------------------------
83
84 Evolution_full<double> aa(1.) ;
85 Evolution_std<double> bb(1., 3) ;
86 Evolution_std<double> bb1(1., 3) ;
87 Evolution_std<double> bb3(1., 4) ;
88
89 cout << "aa[0] : " << aa[0] << endl ;
90 cout << "bb[0] : " << bb[0] << endl ;
91
92 // Test of time derivative:
93
94 double dt = 0.01 ;
95 double t = dt ;
96 double diffa = 0 ;
97 double diffb = 0 ;
98 double diffb1 = 0 ;
99 double diffb3 = 0 ;
100 for (int j=1; j<400; j++) {
101
102 cout << "j = " << j << " t = " << t << " :" << endl ;
103 double f = cos( t ) ;
104 double df = - sin( t ) ;
105 aa.update(f, j, t) ;
106 bb.update(f, j, t) ;
107 bb1.update(f, j, t) ;
108 bb3.update(f, j, t) ;
109
110 if (j>2) {
111 double dfa = fabs( aa.time_derive(j) - df );
112 double dfb = fabs( bb.time_derive(j) - df );
113 double dfb1 = fabs( bb1.time_derive(j,1) - df );
114 double dfb3 = fabs( bb3.time_derive(j,3) - df );
115 if (dfa>diffa) diffa = dfa ;
116 if (dfb>diffb) diffb = dfb ;
117 if (dfb1>diffb1) diffb1 = dfb1 ;
118 if (dfb3>diffb3) diffb3 = dfb3 ;
119 cout << "Error time derivative aa, bb, bb1, bb3 : " << dfa << " " <<
120 dfb << " " << dfb1 << " " << dfb3 << endl ;
121 }
122
123 t += dt ;
124 }
125 cout << endl << "Max error on time derivative aa (Evolution_full, 2nd-order) : "
126 << diffa << endl ;
127 cout << "Max error on time derivative bb (Evolution_std, 2nd-order): "
128 << diffb << endl ;
129 cout << "Max error on time derivative bb1 (Evolution_std, 1st-order) : "
130 << diffb1 << endl ;
131 cout << "Max error on time derivative bb3 (Evolution_std, 3rd-order) : "
132 << diffb3 << endl ;
133 arrete() ;
134
135 Evolution_std<double> cc(2., 3) ;
136
137 for (int j=1; j<20; j++) {
138
139 double t_j = double(j) / double(10) ;
140 cc.update(sqrt(double(j)), j, t_j) ;
141
142 cout << "time : " << cc.get_time(j) << " : " ;
143 if (j==1) cout << cc[0] << " " << cc[1] << endl ;
144 if (j>=2) cout << cc[j-2] << " " << cc[j-1] << " " << cc[j] << endl ;
145
146
147 }
148 cout << endl ;
149
150 arrete() ;
151
152
153 // Setup of a multi-domain grid (Lorene class Mg3d)
154 // ------------------------------------------------
155
156 int nz = 2 ; // Number of domains
157 int nr = 7 ; // Number of collocation points in r in each domain
158 int nt = 5 ; // Number of collocation points in theta in each domain
159 int np = 8 ; // Number of collocation points in phi in each domain
160 int symmetry_theta = SYM ; // symmetry with respect to the equatorial plane
161 int symmetry_phi = NONSYM ; // no symmetry in phi
162 bool compact = false ; // external domain is not compactified
163
164 // Multi-domain grid construction:
165 Mg3d mgrid(nz, nr, nt, np, symmetry_theta, symmetry_phi, compact) ;
166
167 // Setup of an affine mapping : grid --> physical space (Lorene class Map_af)
168 // --------------------------------------------------------------------------
169
170 // radial boundaries of each domain:
171 double r_limits[] = {0., 0.5, 1.} ;
172 assert( nz == 2 ) ; // since the above array described only 2 domains
173
174 Map_af map(mgrid, r_limits) ; // Mapping construction
175
176 // Denomination of various coordinates associated with the mapping
177 // ---------------------------------------------------------------
178
179 const Coord& r = map.r ; // r field
180 const Coord& x = map.x ; // x field
181 const Coord& y = map.y ; // y field
182
183 // Setup of a scalar field (source of the Poisson equation)
184 // --------------------------------------------------------
185
186 Scalar source(map) ; // construction of an object of Lorene class Scalar
187
188 source = 2* exp( - r*r ) * (1 + x + x*y) ;
189
190 source.std_spectral_base() ; // sets the bases for the spectral expansions
191 // to the standard ones for a scalar field
192
193
194 Evolution_std<Scalar> evol(source, 3) ;
195
196 cout << evol[0] << endl ;
197
198 for (int j=0; j<20; j++) {
199
200 double t_j = double(j) / double(10) ;
201 Scalar tmp(map) ;
202 tmp = sqrt(t_j) ;
203 tmp.std_spectral_base() ;
204 evol.update(tmp, j, t_j) ;
205
206 evol[j].spectral_display() ;
207
208 }
209 cout << endl ;
210
211
212 return EXIT_SUCCESS ;
213
214 }