Debian Codegraph @

Codes/Test/Map/test_integ.C

raw
1 /*
2 * Test program the integrale function of the Cmp class (Map_et mapping)
3 *
4 */
5
6 /*
7 * Copyright (c) 2000-2001 Eric Gourgoulhon
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_integ_C[] = "$Header: /cvsroot/Lorene/Codes/Test/Map/test_integ.C,v 1.4 2015/08/10 15:32:27 j_novak Exp $" ;
28
29 /*
30 * $Id: test_integ.C,v 1.4 2015/08/10 15:32:27 j_novak Exp $
31 * $Log: test_integ.C,v $
32 * Revision 1.4 2015/08/10 15:32:27 j_novak
33 * Better calls to Param::add_int(), to avoid weird problems (e.g. with g++ 4.8).
34 *
35 * Revision 1.3 2014/10/06 15:12:52 j_novak
36 * Modified #include directives to use c++ syntax.
37 *
38 * Revision 1.2 2003/01/09 11:07:52 j_novak
39 * headcpp.h is now compliant with C++ norm.
40 * The include files have been ordered, as well as the local_settings_linux
41 *
42 * Revision 1.1.1.1 2001/11/20 15:19:31 e_gourgoulhon
43 * LORENE
44 *
45 * Revision 1.2 2000/02/25 13:04:40 eric
46 * fact_echelle est desormais passe en double_mod dans le Param pour adapt.
47 *
48 * Revision 1.1 2000/01/17 13:59:10 eric
49 * Initial revision
50 *
51 *
52 * $Header: /cvsroot/Lorene/Codes/Test/Map/test_integ.C,v 1.4 2015/08/10 15:32:27 j_novak Exp $
53 *
54 */
55
56 // headers C
57 #include <cstdlib>
58 #include <cmath>
59
60 // headers Lorene
61 #include "type_parite.h"
62 #include "cmp.h"
63 #include "utilitaires.h"
64 #include "param.h"
65 #include "graphique.h"
66 #include "nbr_spx.h"
67
68 //******************************************************************************
69
70 void main(){
71
72 // Identification of all the subroutines called by the code :
73
74 system("ident test_integ") ;
75
76 //-----------------------------------------------------------------------
77 // Input data : number of points, types of sampling, etc...
78 //-----------------------------------------------------------------------
79
80 int nt = 25 ; // Number of points in theta
81 int np = 24 ; // Number of points in phi
82 int nz = 3 ; // Number of domains
83
84 int* nr = new int[nz];
85 int* nt_tab = new int[nz];
86 int* np_tab = new int[nz];
87 double* bornes = new double[nz+1];
88 int* type_r = new int[nz];
89
90 for (int l=0; l<nz; l++) {
91 nr[l] = 49 ; // Number of points in r
92 np_tab[l] = np ;
93 nt_tab[l] = nt ;
94 }
95
96 bornes[0] = 0. ;
97 bornes[1] = 2. ;
98 bornes[2] = 3.5 ;
99 bornes[3] = __infinity ;
100
101 type_r[0] = RARE ;
102 type_r[1] = FIN ;
103 type_r[2] = UNSURR ;
104
105 int type_t = SYM ;
106
107 int type_p = NONSYM ;
108
109 //-----------------------------------------------------------------------
110 // Construction of a multi-grid
111 //-----------------------------------------------------------------------
112
113 const Mg3d mg(nz, nr, type_r, nt_tab, type_t, np_tab, type_p) ;
114
115 //----------------------------
116 // Construction of the Map_et
117 //----------------------------
118
119 Map_et mp(mg, bornes) ;
120
121 // const Coord& r = mp.r ;
122 const Coord& x = mp.x ;
123 const Coord& y = mp.y ;
124 const Coord& z = mp.z ;
125 // const Coord& cost = mp.cost ;
126 // const Coord& sint = mp.sint ;
127 // const Coord& cosp = mp.cosp ;
128 // const Coord& sinp = mp.sinp ;
129
130 //-----------------------------------------------------------------------
131 // Construction of a Cmp to define a triaxial ellipsoid
132 //-----------------------------------------------------------------------
133
134 Cmp ent(mp) ;
135
136 double bsa = 0.7 ;
137 double csa = 0.5 ;
138 double xtri = - 0. ; // xtri = 0 <=> ellipsoid
139 double ray0 = mp.val_r(0, 1., M_PI/2, 0) ;
140
141 double a = sqrt( ray0 * (ray0 + xtri) ) ;
142 double b = bsa * a ;
143 double c = csa * a ;
144
145 cout << "a, b, c, xtri : " << a << " " << b << " " << c << " "
146 << xtri << endl ;
147
148
149 ent = 1 - (x+xtri)*x/(a*a) - (y*y)/(b*b) - (z*z)/(c*c) ;
150
151 ent.annule(nz-1) ;
152 ent.std_base_scal() ;
153
154
155 //-----------------------------------------------------------------------
156 // Adaptation of the Map_et to the Cmp
157 //-----------------------------------------------------------------------
158
159 // Save the old value of the mapping :
160 // Map_et mp_prev = mp ;
161
162 int nzet = 1 ;
163 int nitermax = 100 ;
164 int niter ;
165 double precis = 1.e-15 ;
166 int j_bord = mg.get_nt(0) - 1 ;
167 int k_bord = 0 ;
168 double fact_echelle = 1 ;
169 double fact_lamu = 1 ;
170
171 Tbl ent_limit(nzet) ;
172 ent_limit.set_etat_qcq() ;
173 ent_limit.set(0) = 0 ;
174
175 int i_one = 1 ;
176
177 Param par ;
178 par.add_int(nitermax, 0) ;
179 par.add_int(nzet, 1) ;
180 par.add_int(i_one, 2) ; // 1 = full computation
181 par.add_int(j_bord, 3) ;
182 par.add_int(k_bord, 4) ;
183 par.add_int_mod(niter) ;
184 par.add_double(precis, 0) ;
185 par.add_double(fact_lamu, 1) ;
186 par.add_double_mod(fact_echelle, 0) ;
187 par.add_tbl(ent_limit, 0) ;
188
189 mp.adapt(ent, par) ;
190
191 cout << endl << "Mapping mp (after adaptation) : " << endl ;
192 cout << mp << endl ;
193
194
195 // cout << endl << "Coefficients of the mapping functions F and G" << endl ;
196 // des_map_et(mp, 0) ;
197 // des_map_et(mp, 1) ;
198
199
200
201 //-----------------------------------------------------------------------
202 // Construction of a Cmp
203 //-----------------------------------------------------------------------
204
205 Cmp aa(mp) ;
206 // Cmp aa_ext(mp) ;
207
208
209 aa = 1 ;
210 aa.annule(nzet, nz-1) ;
211
212 // aa_ext = 1 / (r*r) ; // aa_ext = 1/r^2 in all space
213 // aa_ext.annule(0, nz-2) ; // aa_ext = 0 in intern. dom., =1/r^2 in ext. dom.
214
215 // aa = aa + aa_ext ; // aa = x*y*z*z + x*x in internal domains,
216 // aa = 1/r^2 in external domain
217
218 aa.set_dzpuis(4) ;
219
220 aa.std_base_scal() ; // Sets the standard basis for spectral expansions
221
222
223 des_coupe_y(aa, 0., -3., 3., -3., 3.,
224 "Field the integral of which is to be computed (y=0)") ;
225
226
227 cout << "Coef of aa : " << endl ;
228 aa.affiche_seuil(cout) ;
229
230 cout << endl << "Integral of aa in each domain : " << endl ;
231 cout << aa.integrale_domains() << endl ;
232
233 cout << "Integral of aa in all space : " << aa.integrale() << endl ;
234
235 cout << endl << "Once more : Integral of aa in each domain : " << endl ;
236 cout << aa.integrale_domains() << endl ;
237
238 cout << "Integral of aa in all space : " << aa.integrale() << endl ;
239
240 double int_ana = double(4)/double(3) * M_PI * a * b * c ;
241
242 cout << endl <<
243 "Analytical value of the integral (volume of the ellipsoid): "
244 << int_ana << endl ;
245 cout << "Difference computed/analytical : " << aa.integrale()/int_ana -1
246 << endl ;
247
248 // Cleaning
249 // --------
250
251 delete [] nr ;
252 delete [] nt_tab ;
253 delete [] np_tab ;
254 delete [] bornes ;
255 delete [] type_r ;
256
257 exit(EXIT_SUCCESS) ;
258
259 }
260