Debian Codegraph @

Codes/Test/Poisson_scal/test_poisson_spherique.C

raw
1 /*
2 * Test of scalar Poisson equation for a spherical non-compact source
3 *
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 test_poisson_spherique_C[] = "$Header: /cvsroot/Lorene/Codes/Test/Poisson_scal/test_poisson_spherique.C,v 1.5 2014/10/13 08:54:02 j_novak Exp $" ;
28
29 /*
30 * $Id: test_poisson_spherique.C,v 1.5 2014/10/13 08:54:02 j_novak Exp $
31 * $Log: test_poisson_spherique.C,v $
32 * Revision 1.5 2014/10/13 08:54:02 j_novak
33 * Lorene classes and functions now belong to the namespace Lorene.
34 *
35 * Revision 1.4 2014/10/06 15:12:54 j_novak
36 * Modified #include directives to use c++ syntax.
37 *
38 * Revision 1.3 2008/01/28 16:08:47 j_novak
39 * Changed return type of main from void to int
40 *
41 * Revision 1.2 2003/01/09 11:07:55 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.1.1.1 2001/11/20 15:19:31 e_gourgoulhon
46 * LORENE
47 *
48 * Revision 1.1 2000/02/15 14:54:42 phil
49 * Initial revision
50 *
51 *
52 * $Header: /cvsroot/Lorene/Codes/Test/Poisson_scal/test_poisson_spherique.C,v 1.5 2014/10/13 08:54:02 j_novak Exp $
53 *
54 */
55
56 // LORENE
57
58 #include "type_parite.h"
59 #include "nbr_spx.h"
60 #include "grilles.h"
61 #include "map.h"
62 #include "valeur.h"
63 #include "proto.h"
64 #include "coord.h"
65 #include "cmp.h"
66 #include "graphique.h"
67
68 //standard
69 #include <ctime>
70 #include <cstdlib>
71 #include <cstdio>
72 #include <cmath>
73
74 using namespace Lorene ;
75
76 int main() {
77 int symetrie = SYM ;
78 int puis_zec = 2 ;
79
80 // Construction de la grille ...
81 int nz = 3 ;
82 double R = (nz-1) ;
83
84 //Construction du mapping :
85 double* bornes = new double[nz+1] ;
86 for (int i=0 ; i<nz ; i++)
87 bornes[i] = i ;
88 bornes[nz] = __infinity ;
89
90 // echantillonnage en phi :
91 int* np = new int [nz] ;
92 for (int l=0 ; l<nz ; l++)
93 np[l] = 1 ;
94 int type_p = symetrie ;
95
96 // echantillonnage en theta :
97 int* nt = new int [nz] ;
98 for (int l=0 ; l<nz ; l++)
99 nt[l] = 1 ;
100 int type_t = SYM ;
101
102 int nbrer ;
103 cin >> nbrer;
104
105 // echantillonage en r :
106 int* nr = new int [nz] ;
107 for (int l=0 ; l<nz ; l++)
108 nr[l] = nbrer ;
109
110
111 int* type_r = new int[nz] ;
112 type_r[0] = RARE ;
113 for (int l=1 ; l<nz-1 ; l++)
114 type_r[l] = FIN ;
115 type_r[nz-1] = UNSURR ;
116
117 Mg3d grille (nz, nr, type_r, nt, type_t, np, type_p) ;
118
119
120 Map_af mapping(grille, bornes) ;
121
122
123 // Construction de la source .
124 Coord& r = mapping.r ;
125
126 // Composante x
127 Valeur val_x(&grille) ;
128 val_x = R-pow(r, 2.)/R ;
129
130 // ZEC ...
131 Valeur val_x_zec(&grille) ;
132 val_x_zec = pow(R, 5.)/pow(r, 4-puis_zec) ;
133 *(val_x.c->t[nz-1]) = *(val_x_zec.c->t[nz-1]) ;
134
135 Cmp source(mapping) ;
136 source = val_x ;
137 source.set_dzpuis(puis_zec) ;
138 source.std_base_scal() ;
139
140
141 // On construit la solution analytique
142
143 // Composante x
144 Valeur sol_x(&grille) ;
145 sol_x = R/6.*pow(r, 2.)-pow(r, 4.)/20./R-3./4.*pow(R, 3.) ;
146
147 // ZEC ...
148 Valeur sol_x_zec(&grille) ;
149 sol_x_zec = pow(R, 5.)/2./pow(r, 2.)-17./15.*pow(R, 4.)/r ;
150 for (int k=0 ; k<np[nz-1] ; k++)
151 for (int j=0 ; j<nt[nz-1] ; j++)
152 sol_x_zec.set(nz-1, k, j, nr[nz-1]-1) = 0. ;
153 *(sol_x.c->t[nz-1]) = *(sol_x_zec.c->t[nz-1]) ;
154
155
156 // On construit le vecteur ...
157 Cmp soluce(mapping) ;
158 soluce = sol_x ;
159 soluce.set_dzpuis(0) ;
160 soluce.std_base_scal() ;
161
162 Cmp sol_poisson(source.poisson()) ;
163
164 cout << nr[0] << endl ;
165 cout <<"Erreur : " << endl ;
166 cout << diffrelmax(sol_poisson, soluce) << endl ;
167
168 delete [] nr ;
169 delete [] nt ;
170 delete [] np ;
171 delete [] type_r ;
172 delete [] bornes ;
173 }