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