Debian Codegraph @

Codes/Test/Poisson_scal/test_map_et_poisson.C

raw
1 /*
2 * Test program for the resolution of Poisson equation
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_poisson_C[] = "$Header: /cvsroot/Lorene/Codes/Test/Poisson_scal/test_map_et_poisson.C,v 1.3 2014/10/06 15:12:54 j_novak Exp $" ;
28
29 /*
30 * $Id: test_map_et_poisson.C,v 1.3 2014/10/06 15:12:54 j_novak Exp $
31 * $Log: test_map_et_poisson.C,v $
32 * Revision 1.3 2014/10/06 15:12:54 j_novak
33 * Modified #include directives to use c++ syntax.
34 *
35 * Revision 1.2 2003/01/09 11:07:55 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.3 2000/02/09 15:44:50 eric
43 * Modif affichage.
44 *
45 * Revision 1.2 2000/02/09 15:35:18 eric
46 * Suppression de l'appel a rho.set_dzpuis(4) dans le cas d'une
47 * source a support compact.
48 *
49 * Revision 1.1 2000/01/05 10:11:19 eric
50 * Initial revision
51 *
52 *
53 * $Header: /cvsroot/Lorene/Codes/Test/Poisson_scal/test_map_et_poisson.C,v 1.3 2014/10/06 15:12:54 j_novak Exp $
54 *
55 */
56
57 // headers C
58 #include <cstdlib>
59 #include <cmath>
60
61 // headers Lorene
62 #include "type_parite.h"
63 #include "cmp.h"
64 #include "utilitaires.h"
65 #include "graphique.h"
66 #include "param.h"
67 #include "nbr_spx.h"
68
69 //******************************************************************************
70
71 void main(){
72
73 // Identification of all the subroutines called by the code :
74
75 system("ident test_map_et_poisson") ;
76
77
78 //-----------------------------------------------------------------------
79 // Input data : number of points, types of sampling, etc...
80 //-----------------------------------------------------------------------
81
82 int nt = 17 ; // Number of points in theta
83 int np = 16 ; // Number of points in phi
84 int nz = 3 ; // Number of domains
85
86 int* nr = new int[nz];
87 int* nt_tab = new int[nz];
88 int* np_tab = new int[nz];
89 double* bornes = new double[nz+1];
90 int* type_r = new int[nz];
91
92 for (int l=0; l<nz; l++) {
93 nr[l] = 25 ; // Number of points in r
94 np_tab[l] = np ;
95 nt_tab[l] = nt ;
96 }
97
98 bornes[0] = 0. ;
99 bornes[1] = 2. ;
100 bornes[2] = 3. ;
101 bornes[3] = __infinity ;
102
103 type_r[0] = RARE ;
104 type_r[1] = FIN ;
105 type_r[2] = UNSURR ;
106
107 int type_t = SYM ;
108
109 int type_p = NONSYM ;
110
111
112 //-----------------------------------------------------------------------
113 // Construction of a multi-grid
114 //-----------------------------------------------------------------------
115
116 type_t = SYM ;
117 type_p = NONSYM ;
118
119 Mg3d mg(nz, nr, type_r, nt_tab, type_t, np_tab, type_p) ;
120
121 cout << endl << "Grid mg : " << mg << endl ;
122
123 //-----------------------------------------------------------------------
124 // Construction of a pure angular mapping of class Map_af
125 //-----------------------------------------------------------------------
126
127 Map_af mp0( *(mg.get_angu()), bornes ) ;
128
129 cout << endl << "Mapping mp0 : " << endl ;
130 cout << mp0 << endl ;
131
132 const Coord& cost0 = mp0.cost ;
133 const Coord& sint0 = mp0.sint ;
134 const Coord& cosp0 = mp0.cosp ;
135 const Coord& sinp0 = mp0.sinp ;
136
137 //-----------------------------------------------------------------------
138 // Functions F_l and G_l corresponding to a triaxial ellipsoid
139 //-----------------------------------------------------------------------
140
141 //---------------------------
142 // Triaxial ellipsoid x^2/a^2 + y^2/b^2 + z^2/c^2 = 1
143 //---------------------------
144
145 Valeur ff0( *(mg.get_angu()) ) ;
146 Valeur gg0( *(mg.get_angu()) ) ;
147
148 double bsa = 0.9 ; // axis ratio b/a
149 double csa = 0.8 ; // axis ratio c/a
150
151 gg0 = 1. / sqrt( sint0*sint0 * ( cosp0*cosp0 + sinp0*sinp0 / (bsa*bsa) )
152 + cost0*cost0 / (csa*csa) ) - 1. ;
153 gg0.annule(nz-2, nz-1) ; // 0 in the external domains
154
155 gg0.std_base_scal() ;
156
157 // F in domain 0 :
158 ff0.set_etat_c_qcq() ;
159 ff0.c->set_etat_qcq() ;
160 ff0.annule(0) ; // the ellipsoid contains only even m
161
162 // F in other domains is deduced from G by maching domain l and domain l+1 :
163
164 const double* alpha = mp0.get_alpha() ;
165
166 for (int l=1; l<nz-1; l++) {
167 *(ff0.c->t[l]) = alpha[l-1] / alpha[l] * (*(gg0.c->t[l-1])) ;
168 }
169
170 ff0.annule(nz-1) ;
171
172 ff0.std_base_scal() ;
173
174 //----------------------------
175 // Construction of the Map_et
176 //----------------------------
177
178 Map_et mp(mg, bornes) ;
179
180 mp.set_ff(ff0) ;
181 mp.set_gg(gg0) ;
182
183 cout << endl << "Mapping mp : " << endl ;
184 cout << mp << endl ;
185
186 for (int l=0; l<nz; l++) {
187 // des_map_et(mp, l) ;
188 }
189
190 //-----------------------------------------------------------------------
191 // Construction of a Cmp
192 //-----------------------------------------------------------------------
193
194 Cmp uu(mp) ;
195 Cmp rho(mp) ;
196 Cmp rho_ext(mp) ;
197
198 const Coord& r = mp.r ;
199 // const Coord& x = mp.x ;
200 // const Coord& y = mp.y ;
201 // const Coord& z = mp.z ;
202 // const Coord& cost = mp.cost ;
203 // const Coord& sint = mp.sint ;
204 // const Coord& cosp = mp.cosp ;
205 // const Coord& sinp = mp.sinp ;
206
207 cout << "================================" << endl ;
208 cout << " Source with compact support" << endl ;
209 cout << "================================" << endl ;
210
211 rho = 1 ;
212 rho.annule(nz-1) ;
213
214 rho.std_base_scal() ; // Sets the standard basis for spectral expansions
215
216
217 // Resolution of Poisson equation
218 // source with compact support
219 // ------------------------------
220
221 int nitermax = 100 ;
222 int niter ;
223 double lambda = 0.5 ;
224 double precis = 1.e-14 ;
225 Cmp ssj(mp) ;
226
227 Param par ;
228 par.add_int(nitermax) ;
229 par.add_int_mod(niter) ;
230 par.add_double(lambda) ;
231 par.add_double(precis, 1) ;
232 par.add_cmp_mod(ssj) ;
233
234 // Initialization for Map_et::poisson
235 ssj = 0 ;
236 uu = 0 ;
237 ssj.std_base_scal() ;
238 uu.std_base_scal() ;
239
240 rho.poisson(par, uu) ;
241
242
243 // Comparison with the analytical solution
244 // ---------------------------------------
245
246 Cmp uu_ana(mp) ;
247 Cmp uu_ana_ext(mp) ;
248
249 Mtbl rr = r ;
250 double ray = rr(nz-1, 0, 0, 0) ;
251 cout << "ray = " << ray << endl ;
252
253 uu_ana = r*r/6 - ray*ray/2 ;
254 uu_ana_ext = - pow(ray, 3) / (3*r) ;
255
256 uu_ana.annule(nz-1) ;
257 uu_ana_ext.annule(0, nz-2) ;
258 uu_ana = uu_ana + uu_ana_ext ;
259
260 cout << "diffrel uu <-> uu_ana : " << endl ;
261 cout << diffrel(uu, uu_ana) << endl ;
262
263 cout << "diffrelmax uu <-> uu_ana : " << endl ;
264 cout << diffrelmax(uu, uu_ana) << endl ;
265
266 arrete() ;
267
268
269 // Resolution of Poisson equation
270 // source with non-compact support
271 // ----------------------------------
272
273 cout << "================================" << endl ;
274 cout << " Source with extended support" << endl ;
275 cout << "================================" << endl ;
276
277 rho = 1 ;
278 rho.annule(nz-1) ;
279
280 rho_ext = pow(ray, 4) ;
281 rho_ext.annule(0, nz-2) ;
282
283 rho = rho + rho_ext ;
284 rho.set_dzpuis(4) ;
285
286 rho.std_base_scal() ; // Sets the standard basis for spectral expansions
287
288 // Initialization for Map_et::poisson
289 ssj = 0 ;
290 uu = 0 ;
291 ssj.std_base_scal() ;
292 uu.std_base_scal() ;
293
294 rho.poisson(par, uu) ;
295
296
297 // Comparison with the analytical solution
298 // ---------------------------------------
299
300 uu_ana = r*r/6 - ray*ray ;
301 uu_ana_ext = - 4*pow(ray, 3)/(3*r) + pow(ray, 4) / (2*r*r) ;
302
303 uu_ana.annule(nz-1) ;
304 uu_ana_ext.annule(0, nz-2) ;
305 uu_ana = uu_ana + uu_ana_ext ;
306
307 cout << "diffrel uu <-> uu_ana : " << endl ;
308 cout << diffrel(uu, uu_ana) << endl ;
309
310 cout << "diffrelmax uu <-> uu_ana : " << endl ;
311 cout << diffrelmax(uu, uu_ana) << endl ;
312
313 arrete() ;
314
315 // Comparison of the Laplacian of the solution
316 // with the source
317 // -------------------------------------------
318
319
320 cout << endl <<
321 "The Laplacian of the solution is computed and compared with the source:"
322 << endl ;
323
324 Cmp lap = uu.laplacien() ;
325
326 cout << "max( |lap(uu) - rho| ) " << max(abs(lap - rho)) << endl ;
327 cout << "norme( lap(uu) - rho)/norme(rho) "
328 << norme( lap - rho)/norme(rho) << endl ;
329
330
331 exit(EXIT_SUCCESS) ;
332
333 }
334