Debian Codegraph @

Codes/Test/Tenseur/test_tenseur_contract.C

raw
1 /*
2 * Test program the contract and flat_scalar_prod operations on Tenseur's
3 *
4 */
5
6 /*
7 * Copyright (c) 2000-2001 Eric Gourgoulhon
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 as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * LORENE is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with LORENE; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 *
25 */
26
27 char test_tenseur_contract_C[] = "$Header: /cvsroot/Lorene/Codes/Test/Tenseur/test_tenseur_contract.C,v 1.6 2014/10/13 08:54:03 j_novak Exp $" ;
28
29 /*
30 * $Id: test_tenseur_contract.C,v 1.6 2014/10/13 08:54:03 j_novak Exp $
31 * $Log: test_tenseur_contract.C,v $
32 * Revision 1.6 2014/10/13 08:54:03 j_novak
33 * Lorene classes and functions now belong to the namespace Lorene.
34 *
35 * Revision 1.5 2014/10/06 15:12:55 j_novak
36 * Modified #include directives to use c++ syntax.
37 *
38 * Revision 1.4 2008/08/27 08:54:07 jl_cornou
39 * Tests for angular potential A added
40 *
41 * Revision 1.3 2003/01/09 11:07:59 j_novak
42 * headcpp.h is now compliant with C++ norm.
43 * The include files have been ordered, as well as the local_settings_linux
44 *
45 * Revision 1.2 2002/08/08 15:10:45 j_novak
46 * The flag "plat" has been added to the class Metrique to show flat metrics.
47 *
48 * Revision 1.1.1.1 2001/11/20 15:19:31 e_gourgoulhon
49 * LORENE
50 *
51 * Revision 1.1 2000/02/01 14:56:14 eric
52 * Initial revision
53 *
54 *
55 * $Header: /cvsroot/Lorene/Codes/Test/Tenseur/test_tenseur_contract.C,v 1.6 2014/10/13 08:54:03 j_novak Exp $
56 *
57 */
58
59 // headers C
60 #include <cstdlib>
61 #include <cmath>
62
63 // headers Lorene
64 #include "type_parite.h"
65 #include "tenseur.h"
66 #include "utilitaires.h"
67 #include "nbr_spx.h"
68
69 //******************************************************************************
70
71 using namespace Lorene ;
72
73 int main(){
74
75 // Identification of all the subroutines called by the code :
76
77 system("ident test_tenseur_contract") ;
78
79 //-----------------------------------------------------------------------
80 // Input data : number of points, types of sampling, etc...
81 //-----------------------------------------------------------------------
82
83 int nt = 7 ; // Number of points in theta
84 int np = 6 ; // Number of points in phi
85 int nz = 3 ; // Number of domains
86
87 int* nr = new int[nz];
88 int* nt_tab = new int[nz];
89 int* np_tab = new int[nz];
90 double* bornes = new double[nz+1];
91 int* type_r = new int[nz];
92
93 for (int l=0; l<nz; l++) {
94 nr[l] = 9 ; // Number of points in r
95 np_tab[l] = np ;
96 nt_tab[l] = nt ;
97 }
98
99 bornes[0] = 0. ;
100 bornes[1] = 2. ;
101 bornes[2] = 3.5 ;
102 bornes[3] = __infinity ;
103
104 type_r[0] = RARE ;
105 type_r[1] = FIN ;
106 type_r[2] = UNSURR ;
107
108 int type_t = SYM ;
109
110 int type_p = NONSYM ;
111
112
113
114 //-----------------------------------------------------------------------
115 // Construction of a multi-grid
116 //-----------------------------------------------------------------------
117
118 type_t = SYM ;
119 type_p = NONSYM ;
120
121 const Mg3d mg(nz, nr, type_r, nt_tab, type_t, np_tab, type_p) ;
122
123 //-----------------------------------------------------------------------
124 // Construction of a mapping
125 //-----------------------------------------------------------------------
126
127 const Map_af mp(mg, bornes) ;
128
129 const Coord& r = mp.r ;
130 // const Coord& x = mp.x ;
131 // const Coord& y = mp.y ;
132 // const Coord& z = mp.z ;
133 // const Coord& cost = mp.cost ;
134 // const Coord& sint = mp.sint ;
135 // const Coord& cosp = mp.cosp ;
136 // const Coord& sinp = mp.sinp ;
137
138 //-----------------------------------------------------------------------
139 // Construction of a Cmp
140 //-----------------------------------------------------------------------
141
142 Cmp aa(mp) ;
143
144 aa = r*r ;
145 aa.annule(nz-1) ;
146 aa.std_base_scal() ;
147
148 //-----------------------------------------------------------------------
149 // Scalar product of two vectors
150 //-----------------------------------------------------------------------
151
152 Tenseur uu(mp, 1, COV, mp.get_bvect_cart()) ;
153 Tenseur vv(mp, 1, CON, mp.get_bvect_cart()) ;
154
155 uu.set_etat_qcq() ;
156
157 uu.set(0) = aa ;
158 uu.set(1) = - aa ;
159 uu.set(2) = 4 * aa ;
160
161 vv.set_etat_qcq() ;
162
163 vv.set(0) = -3 * aa ;
164 vv.set(1) = aa ;
165 vv.set(2) = 2 * aa ;
166
167
168 cout << endl << "Test scalar product of two vectors" << endl
169 << "==================================" << endl ;
170
171 Tenseur scal0( 4 * aa * aa ) ;
172 Tenseur scal1( uu(0) * vv(0) + uu(1) * vv(1) + uu(2) * vv(2) ) ;
173 Tenseur scal2 = contract(uu, 0, vv, 0) ;
174 Tenseur scal3 = flat_scalar_prod(uu, vv) ;
175
176 cout << "diff scal1 / scal0 : " << diffrel(scal1(), scal0()) << endl ;
177 cout << "diff scal2 / scal0 : " << diffrel(scal2(), scal0()) << endl ;
178 cout << "diff scal3 / scal0 : " << diffrel(scal3(), scal0()) << endl ;
179 cout << "diff scal2 / scal3 : " << diffrel(scal2(), scal3()) << endl ;
180
181 Tenseur diff = scal2 - scal3 ;
182 diff().affiche_seuil(cout, 1) ;
183
184 //-----------------------------------------------------------------------
185 // Scalar product of a rank 2 tensor and a vector
186 //-----------------------------------------------------------------------
187
188 Tenseur kk(mp, 2, COV, mp.get_bvect_cart()) ;
189
190 kk.set_etat_qcq() ;
191
192 kk.set(0, 0) = 1 ;
193 kk.set(0, 1) = 2 ;
194 kk.set(0, 2) = 3 ;
195 kk.set(1, 0) = 4 ;
196 kk.set(1, 1) = 5 ;
197 kk.set(1, 2) = 6 ;
198 kk.set(2, 0) = 7 ;
199 kk.set(2, 1) = 8 ;
200 kk.set(2, 2) = 9 ;
201
202 cout << endl << "Test scalar product of a rank 2 tensor and a vector" << endl
203 << "===================================================" << endl ;
204
205 Tenseur res0(mp, 1, COV, mp.get_bvect_cart()) ;
206 res0.set_etat_qcq() ;
207
208 res0.set(0) = 5 * aa ;
209 res0.set(1) = 5 * aa ;
210 res0.set(2) = 5 * aa ;
211
212 Tenseur res2 = contract(kk, 1, vv, 0) ;
213 Tenseur res3 = flat_scalar_prod(kk, vv) ;
214
215 cout << "diff res2 / res0 : " << endl
216 << diffrel(res2(0), res0(0)) << endl
217 << diffrel(res2(1), res0(1)) << endl
218 << diffrel(res2(2), res0(2)) << endl ;
219
220 cout << "diff res3 / res0 : " << endl
221 << diffrel(res3(0), res0(0)) << endl
222 << diffrel(res3(1), res0(1)) << endl
223 << diffrel(res3(2), res0(2)) << endl ;
224
225 cout << "diff res3 / res2 : " << endl
226 << diffrel(res3(0), res2(0)) << endl
227 << diffrel(res3(1), res2(1)) << endl
228 << diffrel(res3(2), res2(2)) << endl ;
229
230 Tenseur vdiff = res2 - res3 ;
231 vdiff(0).affiche_seuil(cout, 1) ;
232 vdiff(1).affiche_seuil(cout, 1) ;
233 vdiff(2).affiche_seuil(cout, 1) ;
234
235
236 // Cleaning
237 // --------
238
239 delete [] nr ;
240 delete [] nt_tab ;
241 delete [] np_tab ;
242 delete [] bornes ;
243 delete [] type_r ;
244
245 exit(EXIT_SUCCESS) ;
246
247 }
248