Debian Codegraph @

Codes/Test/Poisson_scal/gibbs_comp.C

raw
1 /*
2 *
3 * Test of scalar Poisson equation for a compact non-spherical source.
4 *
5 */
6
7 /*
8 * Copyright (c) 2000-2001 Philippe Grandclement
9 *
10 * This file is part of LORENE.
11 *
12 * LORENE is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
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 gibbs_comp_C[] = "$Header: /cvsroot/Lorene/Codes/Test/Poisson_scal/gibbs_comp.C,v 1.3 2014/10/06 15:12:54 j_novak Exp $" ;
29
30 /*
31 * $Id: gibbs_comp.C,v 1.3 2014/10/06 15:12:54 j_novak Exp $
32 * $Log: gibbs_comp.C,v $
33 * Revision 1.3 2014/10/06 15:12:54 j_novak
34 * Modified #include directives to use c++ syntax.
35 *
36 * Revision 1.2 2003/01/09 11:07:54 j_novak
37 * headcpp.h is now compliant with C++ norm.
38 * The include files have been ordered, as well as the local_settings_linux
39 *
40 * Revision 1.1.1.1 2001/11/20 15:19:31 e_gourgoulhon
41 * LORENE
42 *
43 * Revision 1.1 2000/02/15 14:51:27 phil
44 * Initial revision
45 *
46 *
47 * $Header: /cvsroot/Lorene/Codes/Test/Poisson_scal/gibbs_comp.C,v 1.3 2014/10/06 15:12:54 j_novak Exp $
48 *
49 */
50
51 // LORENE
52
53 #include "itbl.h"
54 #include "type_parite.h"
55 #include "nbr_spx.h"
56 #include "grilles.h"
57 #include "map.h"
58 #include "valeur.h"
59 #include "proto.h"
60 #include "coord.h"
61 #include "cmp.h"
62 #include "graphique.h"
63
64 //standard
65 #include <ctime>
66 #include <cstdlib>
67 #include <cstdio>
68 #include <cmath>
69
70 Tbl donne_pl (int l) {
71 assert (l>=0) ;
72
73 Tbl plp1(l+1) ;
74 Tbl pl(l+1) ;
75 Tbl plm1(l+1) ;
76
77 double a, b ;
78 //Initialisation :
79 plm1.annule_hard() ;
80 plm1.set(0) = 1 ;
81 if (l==0)
82 return plm1 ;
83 assert (l != 0) ;
84
85 pl.annule_hard() ;
86 pl.set(1) = sqrt(3.) ;
87 if (l==1)
88 return pl ;
89
90 plp1.set_etat_qcq() ;
91
92 assert (l>=2) ;
93 for (int conte = 1 ; conte<l ; conte++) {
94
95 a = (conte+1)/sqrt((2*conte+1)*(2*conte+3)) ;
96 b = conte/sqrt((2*conte+1)*(2*conte-1)) ;
97
98 plp1.set(0) = -b*plm1(0) ;
99 for (int i=1 ; i<l+1 ; i++)
100 plp1.set(i) = pl(i-1)-b*plm1(i) ;
101
102 plm1 = pl ;
103 pl = plp1/a ;
104 }
105 return pl ;
106 }
107
108 void main() {
109
110 // nbres de points en r possibles ...
111 Itbl r_pos (10) ;
112 r_pos.set_etat_qcq() ;
113 r_pos.set(0) = 7 ;
114 r_pos.set(1) = 9 ;
115 r_pos.set(2) = 11 ;
116 r_pos.set(3) = 13 ;
117 r_pos.set(4) = 17 ;
118 r_pos.set(5) = 19 ;
119 r_pos.set(6) = 21 ;
120 r_pos.set(7) = 25 ;
121 r_pos.set(8) = 33 ;
122 r_pos.set(9) = 49 ;
123
124 int puis_zec = 4 ;
125
126 int l ;
127 cin >> l ;
128 assert (l>=0) ;
129
130 // Construction de la grille ...
131 int nz = 3 ;
132 double R = (nz-1) ;
133
134 //Construction du mapping :
135 double* bornes = new double[nz+1] ;
136 for (int i=0 ; i<nz ; i++)
137 bornes[i] = i ;
138 bornes[nz] = __infinity ;
139
140 //On determine le nombre de points minimal en theta :
141 int ntmin = (l%2==0) ? l/2+1 : (l+3)/2;
142 assert (ntmin <= 129) ;
143 int nbret = 0 ;
144 int conte = 0 ;
145 while (ntmin > r_pos(conte))
146 conte++ ;
147 nbret = r_pos(conte) ;
148
149 int symetrie = (l%2 == 0) ? SYM : NONSYM ;
150 int nbrep = (l%2 == 0) ? 1 : 4 ;
151 // echantillonnage en phi :
152 int* np = new int [nz] ;
153 for (int lz=0 ; lz<nz ; lz++)
154 np[lz] = nbrep ;
155 int type_p = symetrie ;
156
157 // echantillonnage en theta :
158 int* nt = new int [nz] ;
159 for (int lz=0 ; lz<nz ; lz++)
160 nt[lz] = nbret ;
161 int type_t = SYM ;
162
163 // echantillonage en r :
164 int* nr = new int [nz] ;
165 int* type_r = new int[nz] ;
166 type_r[0] = RARE ;
167 for (int lz=1 ; lz<nz-1 ; lz++)
168 type_r[lz] = FIN ;
169 type_r[nz-1] = UNSURR ;
170
171 // C'est parti pour la grande boucle (vas y Richard ...)
172 int nrmin = 2*nbret ;
173 assert (nrmin <=129) ;
174 conte = 0 ;
175 while (nrmin > r_pos(conte))
176 conte++ ;
177
178 int borne = (l%2 == 0) ? 10 : 9 ;
179
180 for (int boucle = 0 ; boucle<borne ; boucle ++) {
181
182 for (int lz=0 ; lz<nz ; lz++)
183 nr[lz] = r_pos(boucle) ;
184
185
186
187 Mg3d grille (nz, nr, type_r, nt, type_t, np, type_p) ;
188
189
190 Map_af mapping(grille, bornes) ;
191
192 Base_val** bases ;
193 bases = grille.std_base_vect_cart() ;
194
195 Base_val base(nz) ;
196
197 if (l%2 ==0)
198 base = *bases[0] ;
199 else
200 base = *bases[2] ;
201
202 for (int i=0 ; i<3 ; i++)
203 delete bases[i] ;
204 delete [] bases ;
205
206 //Les coord :
207 Coord& r = mapping.r ;
208 Coord& z = mapping.z ;
209 Coord& cost = mapping.cost ;
210
211 //Tableau contenant les coefficients du Pl considere :
212 Tbl pl (donne_pl(l)) ;
213
214 //Construction des Mtbl contenant Pl dans la zec et r^l*Pl dans ZI :
215 Mtbl pl_zec (grille) ;
216 pl_zec.annule_hard() ;
217 for (int i=l ; i>=0 ; i-=2)
218 pl_zec += pl(i)*pow(cost, double(i)) ;
219 pl_zec.annule(0, nz-2) ;
220
221 Mtbl pl_zin (grille) ;
222 pl_zin.annule_hard() ;
223 for (int i=l ; i>=0 ; i-=2)
224 pl_zin += pl(i)*pow(z, double(i))*pow(r, double(l-i)) ;
225 pl_zin.annule(nz-1, nz-1) ;
226
227 // Construction de la source.
228 Valeur val_so(&grille) ;
229 val_so = pl_zin/pow(R, 2*l+3)
230 *((2*l+5)*(2*l+3)-(2*l+3)*(4*l+10)*pow(r, 2.)/pow(R, 2.)) ;
231 val_so.annule(nz-1, nz-1) ;
232 Cmp source(mapping) ;
233 source = val_so ;
234 source.set_dzpuis(puis_zec) ;
235 source.va.set_base(base) ;
236
237 // On construit la solution analytique
238 Valeur val_sol(&grille) ;
239 val_sol = pl_zin*pow(r, 2.)/2/pow(R, 2*l+3)
240 *(2*l+5-(2*l+3)*pow(r, 2.)/pow(R, 2.)) ;
241
242 Valeur val_sol_zec(&grille) ;
243 val_sol_zec = pl_zec/pow(r, l+1) ;
244 for (int k=0 ; k<np[nz-1] ; k++)
245 for (int j=0 ; j<nt[nz-1] ; j++)
246 val_sol_zec.set(nz-1, k, j, nr[nz-1]-1) = 0. ;
247 *(val_sol.c->t[nz-1]) = *(val_sol_zec.c->t[nz-1]) ;
248
249 // On construit le vecteur ...
250 Cmp soluce(mapping) ;
251 soluce = val_sol ;
252 soluce.va.set_base(base) ;
253 soluce.set_dzpuis(0) ;
254
255 Cmp sol_poisson(source.poisson()) ;
256
257
258 cout << nr[0] << " " ;
259 Tbl erreur(diffrel(soluce, sol_poisson)) ;
260 for (int i=0 ; i<nz ; i++)
261 cout << erreur(i) << " " ;
262 cout << endl ;
263 }
264 delete [] nr ;
265 delete [] nt ;
266 delete [] np ;
267 delete [] type_r ;
268 delete [] bornes ;
269 }
270