Debian Codegraph @

Codes/Test/Poisson_vect/vect_cont.C

raw
1 /*
2 * Test of the vectorial Poisson equation for a continuous non-compact source
3 */
4
5 /*
6 * Copyright (c) 2000-2001 Philippe Grandclement
7 *
8 * This file is part of LORENE.
9 *
10 * LORENE is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * LORENE is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with LORENE; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 *
24 */
25
26 char vect_cont_C[] = "$Header: /cvsroot/Lorene/Codes/Test/Poisson_vect/vect_cont.C,v 1.3 2014/10/06 15:12:55 j_novak Exp $" ;
27
28 /*
29 * $Id: vect_cont.C,v 1.3 2014/10/06 15:12:55 j_novak Exp $
30 * $Log: vect_cont.C,v $
31 * Revision 1.3 2014/10/06 15:12:55 j_novak
32 * Modified #include directives to use c++ syntax.
33 *
34 * Revision 1.2 2003/01/09 11:07:56 j_novak
35 * headcpp.h is now compliant with C++ norm.
36 * The include files have been ordered, as well as the local_settings_linux
37 *
38 * Revision 1.1.1.1 2001/11/20 15:19:31 e_gourgoulhon
39 * LORENE
40 *
41 * Revision 1.1 2000/02/15 14:55:32 phil
42 * Initial revision
43 *
44 *
45 * $Header: /cvsroot/Lorene/Codes/Test/Poisson_vect/vect_cont.C,v 1.3 2014/10/06 15:12:55 j_novak Exp $
46 *
47 */
48
49
50 // LORENE
51
52 #include "type_parite.h"
53 #include "nbr_spx.h"
54 #include "grilles.h"
55 #include "map.h"
56 #include "valeur.h"
57 #include "utilitaires.h"
58 #include "coord.h"
59 #include "cmp.h"
60 #include "graphique.h"
61 #include "proto.h"
62 #include "tenseur.h"
63 #include "base_vect.h"
64 #include "param.h"
65
66 //standard
67 #include <ctime>
68 #include <cstdlib>
69 #include <cstdio>
70 #include <cmath>
71
72 Tenseur poisson_vect_oohara (const Tenseur&, double) ;
73
74 void main() {
75
76 int symetrie = NONSYM ;
77 double lambda = 1./3. ;
78 int n=1 ;
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] = 8 ;
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] = 9 ;
100 int type_t = SYM ;
101 int* nr = new int[nz] ;
102 int* type_r = new int[nz] ;
103 int nbrer ;
104
105 cin >> nbrer ;
106
107 // echantillonage en r :
108
109 for (int l=0 ; l<nz ; l++)
110 nr[l] = nbrer ;
111
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
125 Coord& x = mapping.x ;
126 Coord& y = mapping.y ;
127 Coord& z = mapping.z ;
128 Coord& r = mapping.r ;
129
130 // Composante x
131 Valeur val_x(&grille) ;
132 val_x = x/pow(R, n+5.) ;
133 // ZEC ...
134 Valeur val_x_zec(&grille) ;
135 val_x_zec = x/pow(r, n+3.) ;
136 for (int k=0 ; k<np[nz-1] ; k++)
137 for (int j=0 ; j<nt[nz-1] ; j++)
138 val_x_zec.set(nz-1, k, j, nr[nz-1]-1) = 0. ;
139 *(val_x.c->t[nz-1]) = *(val_x_zec.c->t[nz-1]) ;
140
141 // Composante y
142 Valeur val_y(&grille) ;
143 val_y = y/pow(R, n+5.) ;
144 // ZEC ...
145 Valeur val_y_zec(&grille) ;
146 val_y_zec = y/pow(r, n+3.) ;
147 for (int k=0 ; k<np[nz-1] ; k++)
148 for (int j=0 ; j<nt[nz-1] ; j++)
149 val_y_zec.set(nz-1, k, j, nr[nz-1]-1) = 0. ;
150 *(val_y.c->t[nz-1]) = *(val_y_zec.c->t[nz-1]) ;
151
152 // Composante z
153 Valeur val_z(&grille) ;
154 val_z = z/pow(R, n+5.) ;
155 // ZEC ...
156 Valeur val_z_zec(&grille) ;
157 val_z_zec = z/pow(r, n+3.) ;
158 for (int k=0 ; k<np[nz-1] ; k++)
159 for (int j=0 ; j<nt[nz-1] ; j++)
160 val_z_zec.set(nz-1, k, j, nr[nz-1]-1) = 0. ;
161 *(val_z.c->t[nz-1]) = *(val_z_zec.c->t[nz-1]) ;
162
163 // On construit le vecteur ...
164 Tenseur source (mapping, 1, CON, mapping.get_bvect_cart()) ;
165 source.set_etat_qcq() ;
166 source.set(0) = val_x ;
167 source.set(1) = val_y ;
168 source.set(2) = val_z ;
169 for (int i=0 ; i<3 ; i++)
170 source.set(i).set_dzpuis(2) ;
171 source.set_std_base() ;
172
173 //Solution analytique :
174 Mtbl a_cont (&grille) ;
175 a_cont = -(n+5)/(lambda+1)/15./n/pow(R, n) ;
176 Mtbl b_cont (&grille) ;
177 b_cont = - (n+5)/(lambda+1)/6./(n+3)/pow(R, n+3.) ;
178
179 // Composante x
180 Valeur sol_x(&grille) ;
181 sol_x = x/(1.+lambda)*pow(r, 2.)/10./pow(R, n+5.)
182 +b_cont*x ;
183 // ZEC ...
184 Valeur sol_x_zec(&grille) ;
185 sol_x_zec = x/(1.+lambda)/n/(n+3)/pow(r, n+3.)
186 + a_cont*x/pow(r, 3.) ;
187 for (int k=0 ; k<np[nz-1] ; k++)
188 for (int j=0 ; j<nt[nz-1] ; j++)
189 sol_x_zec.set(nz-1, k, j, nr[nz-1]-1) = 0. ;
190 *(sol_x.c->t[nz-1]) = *(sol_x_zec.c->t[nz-1]) ;
191
192 // Composante y
193 Valeur sol_y(&grille) ;
194 sol_y = y/(1.+lambda)*pow(r, 2.)/10./pow(R, n+5.)
195 +b_cont*y ;
196 // ZEC ...
197 Valeur sol_y_zec(&grille) ;
198 sol_y_zec = y/(1.+lambda)/n/(n+3)/pow(r, n+3.)
199 + a_cont*y/pow(r, 3.) ;
200 for (int k=0 ; k<np[nz-1] ; k++)
201 for (int j=0 ; j<nt[nz-1] ; j++)
202 sol_y_zec.set(nz-1, k, j, nr[nz-1]-1) = 0. ;
203 *(sol_y.c->t[nz-1]) = *(sol_y_zec.c->t[nz-1]) ;
204
205 // Composante z
206 Valeur sol_z(&grille) ;
207 sol_z = z/(1.+lambda)*pow(r, 2.)/10./pow(R, n+5.)
208 + b_cont*z ;
209 // ZEC ...
210 Valeur sol_z_zec(&grille) ;
211 sol_z_zec = z/(1.+lambda)/n/(n+3)/pow(r, n+3.)
212 + a_cont*z/pow(r, 3.) ;
213 for (int k=0 ; k<np[nz-1] ; k++)
214 for (int j=0 ; j<nt[nz-1] ; j++)
215 sol_z_zec.set(nz-1, k, j, nr[nz-1]-1) = 0. ;
216 *(sol_z.c->t[nz-1]) = *(sol_z_zec.c->t[nz-1]) ;
217
218 // On construit le vecteur ...
219 Tenseur soluce (mapping, 1, CON, mapping.get_bvect_cart()) ;
220 soluce.set_etat_qcq() ;
221 soluce.set(0) = sol_x ;
222 soluce.set(1) = sol_y ;
223 soluce.set(2) = sol_z ;
224 for (int i=0 ; i<3 ; i++)
225 soluce.set(i).set_dzpuis(0) ;
226 soluce.set_std_base() ;
227
228
229 Tenseur vect_auxi (mapping, 1, CON, mapping.get_bvect_cart()) ;
230 vect_auxi.set_etat_qcq() ;
231 Tenseur scal_auxi (mapping) ;
232 scal_auxi.set_etat_qcq() ;
233 Tenseur chi_auxi (mapping) ;
234 chi_auxi.set_etat_qcq() ;
235
236
237 Tenseur shibata (source.poisson_vect(lambda, vect_auxi, scal_auxi)) ;
238 Tenseur oohara (source.poisson_vect_oohara(lambda, chi_auxi)) ;
239
240 cout << "Points en r : " << nbrer << endl ;
241
242 cout << "Shibata vs analytique" << endl ;
243 for (int i=0 ; i<3 ; i++)
244 cout << diffrelmax(shibata(i), soluce(i)) << endl ;
245
246 cout << "Oohara vs analytique" << endl ;
247 for (int i=0 ; i<3 ; i++)
248 cout << diffrelmax(oohara(i), soluce(i)) << endl ;
249
250
251 delete [] nr ;
252 delete [] nt ;
253 delete [] np ;
254 delete [] type_r ;
255 delete [] bornes ;
256 }