Debian Codegraph @

Codes/Test/Tensor/test_connect.C

raw
1 /*
2 * Code for testing the covariant derivatives through the Connection class.
3 *
4 */
5
6 /*
7 * Copyright (c) 2003 Eric Gourgoulhon & Jerome Novak
8 *
9 * This file is part of LORENE.
10 *
11 * LORENE is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2
13 * as published by the Free Software Foundation.
14 *
15 * LORENE is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with LORENE; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 *
24 */
25
26 char test_connect_C[] = "$Header: /cvsroot/Lorene/Codes/Test/Tensor/test_connect.C,v 1.10 2014/10/13 08:54:03 j_novak Exp $" ;
27
28 /*
29 * $Id: test_connect.C,v 1.10 2014/10/13 08:54:03 j_novak Exp $
30 * $Log: test_connect.C,v $
31 * Revision 1.10 2014/10/13 08:54:03 j_novak
32 * Lorene classes and functions now belong to the namespace Lorene.
33 *
34 * Revision 1.9 2014/10/06 15:12:55 j_novak
35 * Modified #include directives to use c++ syntax.
36 *
37 * Revision 1.8 2004/02/18 18:54:44 e_gourgoulhon
38 * Method Tensor::scontract renamed Tensor::trace.
39 *
40 * Revision 1.7 2003/12/27 15:03:31 e_gourgoulhon
41 * New tests (new index convention of covariant derivatives).
42 *
43 * Revision 1.6 2003/10/19 20:05:07 e_gourgoulhon
44 * Change of the argument list of Scalar::spectral_display
45 * (cout now default).
46 *
47 * Revision 1.5 2003/10/15 10:47:01 e_gourgoulhon
48 * Reorganised the arrete()'s.
49 *
50 * Revision 1.4 2003/10/06 20:53:16 e_gourgoulhon
51 * New version: constructs flat_metric and calls Tensor::derive_cov.
52 *
53 * Revision 1.3 2003/10/05 21:18:08 e_gourgoulhon
54 * Added test onto a vector field.
55 *
56 * Revision 1.2 2003/10/03 14:27:51 e_gourgoulhon
57 * First non trivial test (successfull !).
58 *
59 * Revision 1.1 2003/10/02 21:33:02 e_gourgoulhon
60 * Test code for Connection.
61 *
62 *
63 *
64 * $Header: /cvsroot/Lorene/Codes/Test/Tensor/test_connect.C,v 1.10 2014/10/13 08:54:03 j_novak Exp $
65 *
66 */
67
68 // C++ headers
69 #include "headcpp.h"
70
71 // C headers
72 #include <cstdlib>
73
74 // Lorene headers
75 #include "metric.h"
76 #include "nbr_spx.h"
77 #include "utilitaires.h"
78
79
80 using namespace Lorene ;
81
82 int main() {
83
84 int arret = 0 ;
85
86 // Construction of a multi-grid (Mg3d)
87 // -----------------------------------
88
89 int nz = 3 ; // Number of domains
90 int nr = 9 ; // Number of collocation points in r in each domain
91 int nt = 5 ; // Number of collocation points in theta in each domain
92 int np = 12 ; // Number of collocation points in phi in each domain
93 int symmetry_theta = SYM ; // symmetry with respect to the equatorial plane
94 int symmetry_phi = NONSYM ; // no symmetry in phi
95 bool compact = true ; // external domain is compactified
96
97 Mg3d mgrid(nz, nr, nt, np, symmetry_theta, symmetry_phi, compact) ;
98
99
100 // Construction of an affine mapping (Map_af)
101 // ------------------------------------------
102
103 // Boundaries of each domains
104 double r_limits[] = {0., 2., 3., __infinity} ;
105 assert( nz == 3 ) ; // since the above array described only 3 domains
106
107 Map_af map(mgrid, r_limits) ;
108
109
110 // Construction of a flat metric
111 // -----------------------------
112
113 Metric_flat mets(map, map.get_bvect_spher()) ; // spherical representation
114 Metric_flat metc(map, map.get_bvect_cart()) ; // Cartesian representation
115
116
117 // Construction of a flat connection
118 // ---------------------------------
119
120 // Representation on a spherical orthonormal basis
121 Connection_fspher ders(map, map.get_bvect_spher()) ;
122
123 // Representation on a Cartesian orthonormal basis
124 Connection_fcart derc(map, map.get_bvect_cart()) ;
125
126
127 cout << endl <<
128 "================ TEST FOR A SCALAR FIELD =================\n" ;
129
130
131 // Construction of a scalar field (Scalar)
132 // ---------------------------------------
133
134 const Coord& x = map.x ;
135 const Coord& y = map.y ;
136 const Coord& z = map.z ;
137 const Coord& r = map.r ;
138 const Coord& sint = map.sint ;
139 const Coord& sinp = map.sinp ;
140
141 Scalar uu(map) ;
142 Scalar tmp(map) ;
143
144 uu = x ;
145 tmp = sint * sinp / r ;
146 int nzm1 = nz-1 ;
147 uu.set_domain(nzm1) = tmp.domain(nzm1) ; // y/r^2 in the external domain
148
149 uu.std_spectral_base() ; // sets the standard spectral basis for
150 // expansion of a scalar field
151
152 cout << "uu : " << endl ;
153 uu.spectral_display() ;
154 arrete(arret) ;
155
156 // Gradient of the scalar field
157 // ----------------------------
158
159 Vector duuc = uu.derive_cov(metc) ;
160
161 cout << "duuc : " << endl ;
162 duuc.spectral_display() ;
163
164 arrete(arret) ;
165
166 Vector duus = uu.derive_cov(mets) ;
167
168 cout << "duus : " << endl ;
169 duus.spectral_display() ;
170
171 arrete(arret) ;
172
173 // Test
174 // ----
175
176 Vector duus_c = duus ;
177 duus_c.change_triad( map.get_bvect_cart() ) ;
178
179 Vector diffc = duus_c - duuc ;
180
181 cout << "maxabs( diffc ) : " << maxabs(diffc) << endl ;
182 arrete() ;
183
184
185 Vector duuc_s = duuc ;
186 duuc_s.change_triad( map.get_bvect_spher() ) ;
187
188 Vector diffs = duuc_s - duus ;
189
190 cout << "maxabs(diffs) : " << maxabs(diffs) << endl ;
191
192 arrete() ;
193
194 cout << endl <<
195 "================ TEST FOR A VECTOR FIELD =================\n" ;
196
197 Vector vvc(map, COV, map.get_bvect_cart()) ;
198
199 vvc.set(1) = x + x*x*y - y ;
200 vvc.set(2) = x*x + z*z * y ;
201 vvc.set(3) = z + x * z ;
202 vvc.annule_domain(nzm1) ;
203
204 vvc.std_spectral_base() ;
205
206 Tensor dvvc_ana(map, 2, COV, map.get_bvect_cart()) ;
207 dvvc_ana.set(1,1) = 1 + 2*x*y ;
208 dvvc_ana.set(1,2) = x*x - 1 ;
209 dvvc_ana.set(1,3) = 0 ;
210 dvvc_ana.set(2,1) = 2*x ;
211 dvvc_ana.set(2,2) = z*z ;
212 dvvc_ana.set(2,3) = 2*z*y ;
213 dvvc_ana.set(3,1) = z ;
214 dvvc_ana.set(3,2) = 0;
215 dvvc_ana.set(3,3) = 1 + x ;
216 dvvc_ana.annule_domain(nzm1) ;
217 dvvc_ana.std_spectral_base() ;
218
219 Tensor dvvc = vvc.derive_cov(metc) ;
220
221 Tensor diffvvc_ana = dvvc - dvvc_ana ;
222 cout << "Maxabs(dvvc - dvvc_ana) : " << maxabs(diffvvc_ana) << endl ;
223 arrete() ;
224
225 Vector vvs = vvc ;
226 vvs.change_triad( map.get_bvect_spher() ) ;
227
228 Tensor dvvs = vvs.derive_cov(mets) ;
229
230 Tensor dvvs_c = dvvs ;
231 dvvs_c.change_triad( map.get_bvect_cart() ) ;
232
233 Tensor diffvvc = dvvs_c - dvvc ;
234
235 cout << "Maxabs(dvvs_c - dvvc) : \n" ;
236 maxabs(diffvvc) ;
237 arrete() ;
238
239
240 Tensor dvvc_s = dvvc ;
241 dvvc_s.change_triad( map.get_bvect_spher() ) ;
242
243 Tensor diffvvs = dvvc_s - dvvs ;
244
245 cout << "Maxabs(dvvc_s - dvvs) : \n" ;
246 maxabs(diffvvs) ;
247 arrete() ;
248
249 // Divergence
250 // ----------
251 Vector uvvc = vvc.up(0, metc) ;
252 Scalar divc = uvvc.divergence(metc) ;
253 Tensor udvvc = dvvc.up(0, metc) ;
254 Scalar diffdivc = divc - Scalar( udvvc.trace(0,1) ) ;
255 cout << "Error on the divergence (Cart.): " << endl ;
256 maxabs(diffdivc) ;
257
258 Vector uvvs = vvs.up(0, mets) ;
259 Scalar divs = uvvs.divergence(mets) ;
260 Tensor udvvs = dvvs.up(0, mets) ;
261 Scalar diffdivs = divs - Scalar( udvvs.trace(0,1) ) ;
262 cout << "Error on the divergence (spher.): " << endl ;
263 maxabs(diffdivs) ;
264
265
266 cout << endl <<
267 "================ TEST FOR A RANK 2 TENSOR FIELD =================\n" ;
268
269 Tensor ddvvc_ana(map, 3, COV, map.get_bvect_cart()) ;
270
271 ddvvc_ana.set(1,1,1) = 2*y ;
272 ddvvc_ana.set(1,1,2) = 2*x ;
273 ddvvc_ana.set(1,1,3) = 0 ;
274
275 ddvvc_ana.set(1,2,1) = 2*x ;
276 ddvvc_ana.set(1,2,2) = 0 ;
277 ddvvc_ana.set(1,2,3) = 0 ;
278
279 ddvvc_ana.set(1,3,1) = 0 ;
280 ddvvc_ana.set(1,3,2) = 0 ;
281 ddvvc_ana.set(1,3,3) = 0 ;
282
283 ddvvc_ana.set(2,1,1) = 2 ;
284 ddvvc_ana.set(2,1,2) = 0 ;
285 ddvvc_ana.set(2,1,3) = 0 ;
286
287 ddvvc_ana.set(2,2,1) = 0 ;
288 ddvvc_ana.set(2,2,2) = 0 ;
289 ddvvc_ana.set(2,2,3) = 2*z ;
290
291 ddvvc_ana.set(2,3,1) = 0 ;
292 ddvvc_ana.set(2,3,2) = 2*z ;
293 ddvvc_ana.set(2,3,3) = 2*y ;
294
295 ddvvc_ana.set(3,1,1) = 0 ;
296 ddvvc_ana.set(3,1,2) = 0 ;
297 ddvvc_ana.set(3,1,3) = 1 ;
298
299 ddvvc_ana.set(3,2,1) = 0;
300 ddvvc_ana.set(3,2,2) = 0;
301 ddvvc_ana.set(3,2,3) = 0;
302
303 ddvvc_ana.set(3,3,1) = 1 ;
304 ddvvc_ana.set(3,3,2) = 0 ;
305 ddvvc_ana.set(3,3,3) = 0 ;
306
307 ddvvc_ana.annule_domain(nzm1) ;
308
309 Tensor ddvvc = dvvc.derive_cov(metc) ;
310
311 Tensor diffddvvc_ana = ddvvc - ddvvc_ana ;
312 cout << "Maxabs(ddvvc - ddvvc_ana) : \n" ;
313 maxabs(diffddvvc_ana) ;
314 arrete() ;
315
316 Tensor ddvvs = dvvs.derive_cov(mets) ;
317
318 // Tensor ddvvs_c = ddvvs ;
319 // ddvvs_c.change_triad( map.get_bvect_cart() ) ;
320 // Tensor diffddvvc = ddvvs_c - ddvvc ;
321 // cout << "Maxabs(ddvvs_c - ddvvc) : \n" ;
322 // maxabs(diffddvvc) ;
323 // arrete() ;
324
325 // Tensor ddvvc_s = ddvvc ;
326 // ddvvc_s.change_triad( map.get_bvect_spher() ) ;
327 // Tensor diffddvvs = ddvvc_s - ddvvs ;
328 // cout << "Maxabs(ddvvc_s - ddvvs) : \n" ;
329 // maxabs(diffddvvs) ;
330 // arrete() ;
331
332 // Divergence
333 // ----------
334
335 Tensor u1dvvc = dvvc.up(1, metc) ;
336 Vector div_udvvc = u1dvvc.divergence(metc) ;
337 Tensor uddvvc = ddvvc.up(1, metc) ;
338 cout << "div_udvvc : \n " << endl ;
339 div_udvvc.spectral_display() ;
340 Vector diff_div_udvvc = div_udvvc - uddvvc.trace(1,2) ;
341 cout << "Error on the divergence (Cart.): " << endl ;
342 maxabs(diff_div_udvvc) ;
343
344 return EXIT_SUCCESS ;
345 }