Debian Codegraph @

Codes/Test/Poisson_vect/vect_inf.C

raw
1 /*
2 * Test for the vectorial Poisson equation for a discontinuous 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_inf_C[] = "$Header: /cvsroot/Lorene/Codes/Test/Poisson_vect/vect_inf.C,v 1.3 2014/10/06 15:12:55 j_novak Exp $" ;
27
28 /*
29 * $Id: vect_inf.C,v 1.3 2014/10/06 15:12:55 j_novak Exp $
30 * $Log: vect_inf.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:57:18 phil
42 * Initial revision
43 *
44 *
45 * $Header: /cvsroot/Lorene/Codes/Test/Poisson_vect/vect_inf.C,v 1.3 2014/10/06 15:12:55 j_novak Exp $
46 *
47 */
48
49 // LORENE
50
51 #include "type_parite.h"
52 #include "nbr_spx.h"
53 #include "grilles.h"
54 #include "map.h"
55 #include "valeur.h"
56 #include "utilitaires.h"
57 #include "coord.h"
58 #include "cmp.h"
59 #include "graphique.h"
60 #include "proto.h"
61 #include "tenseur.h"
62 #include "base_vect.h"
63 #include "param.h"
64
65 //standard
66 #include <ctime>
67 #include <cstdlib>
68 #include <cstdio>
69 #include <cmath>
70
71 void main() {
72
73 int symetrie = NONSYM ;
74 double lambda = 1./3. ;
75 int n=4 ;
76
77 // Construction de la grille ...
78 int nz = 3 ;
79 double R = (nz-1) ;
80
81 //Construction du mapping :
82 double* bornes = new double[nz+1] ;
83 for (int i=0 ; i<nz ; i++)
84 bornes[i] = i ;
85 bornes[nz] = __infinity ;
86
87 // echantillonnage en phi :
88 int* np = new int [nz] ;
89 for (int l=0 ; l<nz ; l++)
90 np[l] = 8 ;
91 int type_p = symetrie ;
92
93 // echantillonnage en theta :
94 int* nt = new int [nz] ;
95 for (int l=0 ; l<nz ; l++)
96 nt[l] = 9 ;
97 int type_t = SYM ;
98 int* nr = new int[nz] ;
99 int* type_r = new int[nz] ;
100 int nbrer ;
101
102 cin >> nbrer ;
103
104 // echantillonage en r :
105
106 for (int l=0 ; l<nz ; l++)
107 nr[l] = nbrer ;
108
109 type_r[0] = RARE ;
110 for (int l=1 ; l<nz-1 ; l++)
111 type_r[l] = FIN ;
112 type_r[nz-1] = UNSURR ;
113
114 Mg3d grille (nz, nr, type_r, nt, type_t, np, type_p) ;
115
116
117 Map_af mapping(grille, bornes) ;
118
119
120 // Construction de la source .
121
122 Coord& x = mapping.x ;
123 Coord& y = mapping.y ;
124 Coord& z = mapping.z ;
125 Coord& r = mapping.r ;
126
127 Mtbl a_cont (&grille) ;
128 a_cont = -(4.+n)/2./pow(R, 6.+n) ;
129 Mtbl b_cont (&grille) ;
130 b_cont = (6.+n)/2./pow(R, 4.+n) ;
131
132 // Composante x
133 Valeur val_x(&grille) ;
134 val_x = x*((54+18*lambda)*a_cont*pow(r, 4.)+
135 (28+12*lambda)*b_cont*pow(r, 2.))
136 + lambda*pow(x, 3.)*(24*a_cont*pow(r, 2.)+8*b_cont) ;
137 // ZEC ...
138 Valeur val_x_zec(&grille) ;
139 val_x_zec = n*(n-3-3*lambda)*x/pow(r, n)+
140 n*(n+2)*lambda*pow(x, 3.)/pow(r, n+2.) ;
141 for (int k=0 ; k<np[nz-1] ; k++)
142 for (int j=0 ; j<nt[nz-1] ; j++)
143 val_x_zec.set(nz-1, k, j, nr[nz-1]-1) = 0. ;
144 *(val_x.c->t[nz-1]) = *(val_x_zec.c->t[nz-1]) ;
145
146 // Composante y
147 Valeur val_y(&grille) ;
148 val_y = lambda*y*(6*a_cont*pow(r, 4.)+4*b_cont*pow(r, 2.))
149 +lambda*pow(x, 2.)*y*(24*a_cont*pow(r, 2.)+8*b_cont);
150 // ZEC ...
151 Valeur val_y_zec(&grille) ;
152 val_y_zec = -lambda*n*y/pow(r, n)+lambda*n*(n+2)*pow(x, 2.)*y/pow(r, n+2.) ;
153 for (int k=0 ; k<np[nz-1] ; k++)
154 for (int j=0 ; j<nt[nz-1] ; j++)
155 val_y_zec.set(nz-1, k, j, nr[nz-1]-1) = 0. ;
156 *(val_y.c->t[nz-1]) = *(val_y_zec.c->t[nz-1]) ;
157
158 // Composante z
159 Valeur val_z(&grille) ;
160 val_z = lambda*z*(6*a_cont*pow(r, 4.)+4*b_cont*pow(r, 2.))
161 +lambda*pow(x, 2.)*z*(24*a_cont*pow(r, 2.)+8*b_cont);
162 // ZEC ...
163 Valeur val_z_zec(&grille) ;
164 val_z_zec = -lambda*n*z/pow(r, n)+lambda*n*(n+2)*pow(x, 2.)*z/pow(r, n+2.) ;
165 for (int k=0 ; k<np[nz-1] ; k++)
166 for (int j=0 ; j<nt[nz-1] ; j++)
167 val_z_zec.set(nz-1, k, j, nr[nz-1]-1) = 0. ;
168 *(val_z.c->t[nz-1]) = *(val_z_zec.c->t[nz-1]) ;
169
170 // On construit le vecteur ...
171 Tenseur source (mapping, 1, CON, mapping.get_bvect_cart()) ;
172 source.set_etat_qcq() ;
173 source.set(0) = val_x ;
174 source.set(1) = val_y ;
175 source.set(2) = val_z ;
176 for (int i=0 ; i<3 ; i++)
177 source.set(i).set_dzpuis(2) ;
178 source.set_std_base() ;
179
180
181 // On construit la solution analytique
182 // Composante x
183 Valeur sol_x(&grille) ;
184 sol_x = x*(a_cont*pow(r, 6.)+b_cont*pow(r, 4.)) ;
185
186 // ZEC ...
187 Valeur sol_x_zec(&grille) ;
188 sol_x_zec = x/pow(r, n) ;
189 for (int k=0 ; k<np[nz-1] ; k++)
190 for (int j=0 ; j<nt[nz-1] ; j++)
191 sol_x_zec.set(nz-1, k, j, nr[nz-1]-1) = 0. ;
192 *(sol_x.c->t[nz-1]) = *(sol_x_zec.c->t[nz-1]) ;
193
194 // On construit le vecteur ...
195 Tenseur soluce(mapping, 1, CON, mapping.get_bvect_cart()) ;
196 soluce.set_etat_qcq() ;
197 soluce.set(0) = sol_x ;
198 soluce.set(1) = 0 ;
199 soluce.set(2) = 0 ;
200 for (int i=0 ; i<3 ; i++)
201 soluce.set(i).set_dzpuis(0) ;
202 soluce.set_std_base() ;
203
204 Tenseur vect_auxi (mapping, 1, CON, mapping.get_bvect_cart()) ;
205 vect_auxi.set_etat_qcq() ;
206 Tenseur scal_auxi (mapping) ;
207 scal_auxi.set_etat_qcq() ;
208
209 Tenseur shibata (source.poisson_vect(lambda, vect_auxi, scal_auxi)) ;
210
211 cout << "Shibata" << endl ;
212 for (int i=0 ; i<3 ; i++)
213 cout << "Composante " << i << " : " <<
214 diffrelmax(shibata(i), soluce(i)) << endl ;
215 cout <<"-------------------------------------------" << endl ;
216
217 delete [] nr ;
218 delete [] nt ;
219 delete [] np ;
220 delete [] type_r ;
221 delete [] bornes ;
222 }