Debian Codegraph @

Codes/Test/Map/test_map_et_deriv.C

raw
1 /*
2 * Test program the derivative functions of the Cmp class with a Map_et mapping
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_map_et_deriv_C[] = "$Header: /cvsroot/Lorene/Codes/Test/Map/test_map_et_deriv.C,v 1.3 2014/10/06 15:12:53 j_novak Exp $" ;
28
29 /*
30 * $Id: test_map_et_deriv.C,v 1.3 2014/10/06 15:12:53 j_novak Exp $
31 * $Log: test_map_et_deriv.C,v $
32 * Revision 1.3 2014/10/06 15:12:53 j_novak
33 * Modified #include directives to use c++ syntax.
34 *
35 * Revision 1.2 2003/01/09 11:07:53 j_novak
36 * headcpp.h is now compliant with C++ norm.
37 * The include files have been ordered, as well as the local_settings_linux
38 *
39 * Revision 1.1.1.1 2001/11/20 15:19:31 e_gourgoulhon
40 * LORENE
41 *
42 * Revision 1.2 2000/01/28 08:43:01 eric
43 * Identification du code au debut.
44 *
45 * Revision 1.1 2000/01/27 15:16:16 eric
46 * Initial revision
47 *
48 *
49 * $Header: /cvsroot/Lorene/Codes/Test/Map/test_map_et_deriv.C,v 1.3 2014/10/06 15:12:53 j_novak Exp $
50 *
51 */
52
53
54 // headers C
55 #include <cstdlib>
56 #include <cmath>
57
58 // headers Lorene
59 #include "type_parite.h"
60 #include "cmp.h"
61 #include "utilitaires.h"
62 #include "param.h"
63 #include "nbr_spx.h"
64
65 //******************************************************************************
66
67 void main(){
68
69 // Identification of all the subroutines called by the code :
70
71 system("ident test_map_et_deriv") ;
72
73 //-----------------------------------------------------------------------
74 // Input data : number of points, types of sampling, etc...
75 //-----------------------------------------------------------------------
76
77 int nt = 25 ; // Number of points in theta
78 int np = 24 ; // Number of points in phi
79 int nz = 3 ; // Number of domains
80
81 int* nr = new int[nz];
82 int* nt_tab = new int[nz];
83 int* np_tab = new int[nz];
84 double* bornes = new double[nz+1];
85 int* type_r = new int[nz];
86
87 for (int l=0; l<nz; l++) {
88 nr[l] = 33 ; // Number of points in r
89 np_tab[l] = np ;
90 nt_tab[l] = nt ;
91 }
92
93 bornes[0] = 0. ;
94 bornes[1] = 2. ;
95 bornes[2] = 3.5 ;
96 bornes[3] = __infinity ;
97
98 type_r[0] = RARE ;
99 type_r[1] = FIN ;
100 type_r[2] = UNSURR ;
101
102 int type_t = SYM ;
103
104 int type_p = NONSYM ;
105
106
107
108 //-----------------------------------------------------------------------
109 // Construction of a multi-grid
110 //-----------------------------------------------------------------------
111
112 type_t = SYM ;
113 type_p = NONSYM ;
114
115 const Mg3d mg(nz, nr, type_r, nt_tab, type_t, np_tab, type_p) ;
116
117 //-----------------------------------------------------------------------
118 // Construction of a pure angular mapping of class Map_af
119 //-----------------------------------------------------------------------
120
121 Map_af mp0( *(mg.get_angu()), bornes ) ;
122
123 cout << endl << "Mapping mp0 : " << endl ;
124 cout << mp0 << endl ;
125
126 const Coord& cost0 = mp0.cost ;
127 const Coord& sint0 = mp0.sint ;
128 const Coord& cosp0 = mp0.cosp ;
129 const Coord& sinp0 = mp0.sinp ;
130
131 //-----------------------------------------------------------------------
132 // Functions F_l and G_l corresponding to a triaxial ellipsoid
133 //-----------------------------------------------------------------------
134
135 //---------------------------
136 // Triaxial ellipsoid x^2/a^2 + y^2/b^2 + z^2/c^2 = 1
137 //---------------------------
138
139 Valeur ff0( *(mg.get_angu()) ) ;
140 Valeur gg0( *(mg.get_angu()) ) ;
141
142 double bsa = 0.8 ; // axis ratio b/a
143 double csa = 0.6 ; // axis ratio c/a
144
145 gg0 = 1. / sqrt( sint0*sint0 * ( cosp0*cosp0 + sinp0*sinp0 / (bsa*bsa) )
146 + cost0*cost0 / (csa*csa) ) - 1. ;
147 gg0.annule(nz-2, nz-1) ; // 0 in the external domains
148
149 gg0.std_base_scal() ;
150
151 // F in domain 0 :
152 ff0.set_etat_c_qcq() ;
153 ff0.c->set_etat_qcq() ;
154 ff0.annule(0) ; // the ellipsoid contains only even m
155
156 // F in other domains is deduced from G by maching domain l and domain l+1 :
157
158 const double* alpha = mp0.get_alpha() ;
159
160 for (int l=1; l<nz-1; l++) {
161 *(ff0.c->t[l]) = alpha[l-1] / alpha[l] * (*(gg0.c->t[l-1])) ;
162 }
163
164 ff0.annule(nz-1) ;
165
166 ff0.std_base_scal() ;
167
168 //----------------------------
169 // Construction of the Map_et
170 //----------------------------
171
172 Map_et mp(mg, bornes) ;
173
174 mp.set_ff(ff0) ;
175 mp.set_gg(gg0) ;
176
177 cout << endl << "Mapping mp : " << endl ;
178 cout << mp << endl ;
179
180 const Coord& r = mp.r ;
181 const Coord& x = mp.x ;
182 const Coord& y = mp.y ;
183 const Coord& z = mp.z ;
184 const Coord& cost = mp.cost ;
185 const Coord& sint = mp.sint ;
186 const Coord& cosp = mp.cosp ;
187 const Coord& sinp = mp.sinp ;
188
189 //-----------------------------------------------------------------------
190 // Construction of a Cmp
191 //-----------------------------------------------------------------------
192
193 Cmp aa(mp) ;
194 Cmp aa_ext(mp) ;
195 Cmp da_ana(mp) ;
196 Cmp da_ana_ext(mp) ;
197 Cmp da(mp) ;
198
199 aa = x*y*z*z + y ;
200 aa_ext = 1 / (r*r) ;
201
202 aa.annule(nz-1) ;
203 aa_ext.annule(0, nz-2) ;
204
205 aa = aa + aa_ext ;
206
207 aa.std_base_scal() ; // Sets the standard basis for spectral expansions
208
209 // cout << "Coefficients of aa = x y z^2 + y (in ZEC : aa = 1/r^2) : " << endl ;
210 // aa.affiche_seuil(cout) ;
211 // arrete() ;
212
213 // Computation of da/dx
214 // --------------------
215
216 da = aa.dsdx() ;
217
218 // Analytical expression for da/dx :
219 da_ana = y*z*z ;
220 da_ana_ext = - 2 * sint * cosp / r ;
221
222 da_ana.annule(nz-1) ;
223 da_ana_ext.annule(0, nz-2) ;
224
225 da_ana = da_ana + da_ana_ext ;
226 da_ana.set_dzpuis(2) ;
227 da_ana.std_base_scal() ;
228
229 // cout << "Coefficients of da/dx : " << endl ;
230 // da.affiche_seuil(cout, 0, 4, 1e-4) ;
231
232 // cout << "Coefficients of da/dx analytical : " << endl ;
233 // da_ana.affiche_seuil(cout, 0, 4, 1e-4) ;
234
235 cout << "Relative difference da/dx <-> da/dx analytical : " << endl ;
236 cout << diffrel(da, da_ana) << endl ;
237
238 cout << "Difference coefficients da/dx <-> da/dx analytical : " << endl ;
239 (da.va).coef() ;
240 (da_ana.va).coef() ;
241 Mtbl_cf diff = *((da.va).c_cf) - *((da_ana.va).c_cf) ;
242 cout << norme(diff) / norme( *((da_ana.va).c_cf) ) << endl ;
243
244 // Computation of da/dy
245 // --------------------
246
247 da = aa.dsdy() ;
248
249 // Analytical expression for da/dy :
250 da_ana = x*z*z + 1 ;
251 da_ana_ext = - 2 * sint * sinp / r ;
252
253 da_ana.annule(nz-1) ;
254 da_ana_ext.annule(0, nz-2) ;
255
256 da_ana = da_ana + da_ana_ext ;
257 da_ana.set_dzpuis(2) ;
258 da_ana.std_base_scal() ;
259
260 // cout << "Coefficients of da/dy : " << endl ;
261 // da.affiche_seuil(cout, 0, 4, 1e-4) ;
262
263 // cout << "Coefficients of da/dy analytical : " << endl ;
264 // da_ana.affiche_seuil(cout, 0, 4, 1e-4) ;
265
266 cout << "Relative difference da/dy <-> da/dy analytical : " << endl ;
267 cout << diffrel(da, da_ana) << endl ;
268
269 cout << "Difference coefficients da/dy <-> da/dy analytical : " << endl ;
270 (da.va).coef() ;
271 (da_ana.va).coef() ;
272 diff = *((da.va).c_cf) - *((da_ana.va).c_cf) ;
273 cout << norme(diff) / norme( *((da_ana.va).c_cf) ) << endl ;
274
275 // Computation of da/dz
276 // --------------------
277
278 da = aa.dsdz() ;
279
280 // Analytical expression for da/dz :
281 da_ana = 2*z*x*y ;
282 da_ana_ext = - 2 * cost / r ;
283
284 da_ana.annule(nz-1) ;
285 da_ana_ext.annule(0, nz-2) ;
286
287 da_ana = da_ana + da_ana_ext ;
288 da_ana.set_dzpuis(2) ;
289 (da_ana.va).set_base( (da.va).base ) ;
290
291 // cout << "Coefficients of da/dz : " << endl ;
292 // da.affiche_seuil(cout, 0, 4, 1e-4) ;
293
294 // cout << "Coefficients of da/dz analytical : " << endl ;
295 // da_ana.affiche_seuil(cout, 0, 4, 1e-4) ;
296
297 cout << "Relative difference da/dz <-> da/dz analytical : " << endl ;
298 cout << diffrel(da, da_ana) << endl ;
299
300 cout << "Difference coefficients da/dz <-> da/dz analytical : " << endl ;
301 (da.va).coef() ;
302 (da_ana.va).coef() ;
303 diff = *((da.va).c_cf) - *((da_ana.va).c_cf) ;
304 cout << norme(diff) / norme( *((da_ana.va).c_cf) ) << endl ;
305
306 // Cleaning
307 // --------
308
309 delete [] nr ;
310 delete [] nt_tab ;
311 delete [] np_tab ;
312 delete [] bornes ;
313 delete [] type_r ;
314
315 exit(EXIT_SUCCESS) ;
316
317 }
318