| 1 |
/* |
| 2 |
* Test program for Map_radial::poisson_compact |
| 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_poisson_compact_C[] = "$Header: /cvsroot/Lorene/Codes/Test/Poisson_compact/test_poisson_compact.C,v 1.4 2015/08/10 15:32:27 j_novak Exp $" ; |
| 28 |
|
| 29 |
/* |
| 30 |
* $Id: test_poisson_compact.C,v 1.4 2015/08/10 15:32:27 j_novak Exp $ |
| 31 |
* $Log: test_poisson_compact.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:54 j_novak |
| 36 |
* Modified #include directives to use c++ syntax. |
| 37 |
* |
| 38 |
* Revision 1.2 2003/01/09 11:07:54 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.4 2000/02/25 09:56:04 eric |
| 46 |
* Nouveau constructeur de Tenseur (triade passee en argument) |
| 47 |
* fact_echelle est desormais passe en double_mod dans le Param. |
| 48 |
* |
| 49 |
* Revision 1.3 2000/01/27 16:04:50 eric |
| 50 |
* Suppression lecture des parametres dans un fichier. |
| 51 |
* |
| 52 |
* Revision 1.2 2000/01/14 17:35:33 eric |
| 53 |
* Annulation de la source avant l'appel a Map_radial::poisson_compact. |
| 54 |
* |
| 55 |
* Revision 1.1 2000/01/13 16:45:10 eric |
| 56 |
* Initial revision |
| 57 |
* |
| 58 |
* |
| 59 |
* $Header: /cvsroot/Lorene/Codes/Test/Poisson_compact/test_poisson_compact.C,v 1.4 2015/08/10 15:32:27 j_novak Exp $ |
| 60 |
* |
| 61 |
*/ |
| 62 |
|
| 63 |
|
| 64 |
// version of 13.01.2000 |
| 65 |
|
| 66 |
// headers C |
| 67 |
#include <cstdlib> |
| 68 |
#include <cmath> |
| 69 |
|
| 70 |
// headers Lorene |
| 71 |
#include "tenseur.h" |
| 72 |
#include "param.h" |
| 73 |
#include "utilitaires.h" |
| 74 |
#include "nbr_spx.h" |
| 75 |
|
| 76 |
//****************************************************************************** |
| 77 |
|
| 78 |
void main(){ |
| 79 |
|
| 80 |
// Identification of all the subroutines called by the code : |
| 81 |
|
| 82 |
system("ident test_poisson_compact") ; |
| 83 |
|
| 84 |
//----------------------------------------------------------------------- |
| 85 |
// Input data : number of points, types of sampling, etc... |
| 86 |
//----------------------------------------------------------------------- |
| 87 |
|
| 88 |
int nt = 17 ; // Number of points in theta |
| 89 |
int np = 16 ; // Number of points in phi |
| 90 |
int nz = 3 ; // Number of domains |
| 91 |
|
| 92 |
int* nr = new int[nz]; |
| 93 |
int* nt_tab = new int[nz]; |
| 94 |
int* np_tab = new int[nz]; |
| 95 |
double* bornes = new double[nz+1]; |
| 96 |
int* type_r = new int[nz]; |
| 97 |
|
| 98 |
for (int l=0; l<nz; l++) { |
| 99 |
nr[l] = 25 ; // Number of points in r |
| 100 |
np_tab[l] = np ; |
| 101 |
nt_tab[l] = nt ; |
| 102 |
} |
| 103 |
|
| 104 |
bornes[0] = 0. ; |
| 105 |
bornes[1] = 2. ; |
| 106 |
bornes[2] = 3. ; |
| 107 |
bornes[3] = __infinity ; |
| 108 |
|
| 109 |
type_r[0] = RARE ; |
| 110 |
type_r[1] = FIN ; |
| 111 |
type_r[2] = UNSURR ; |
| 112 |
|
| 113 |
int type_t = SYM ; |
| 114 |
|
| 115 |
int type_p = NONSYM ; |
| 116 |
|
| 117 |
//----------------------------------------------------------------------- |
| 118 |
// Construction of a multi-grid |
| 119 |
//----------------------------------------------------------------------- |
| 120 |
|
| 121 |
type_t = SYM ; |
| 122 |
type_p = NONSYM ; |
| 123 |
|
| 124 |
Mg3d mg(nz, nr, type_r, nt_tab, type_t, np_tab, type_p) ; |
| 125 |
|
| 126 |
cout << endl << "Grid mg : " << mg << endl ; |
| 127 |
|
| 128 |
//---------------------------- |
| 129 |
// Construction of the Map_et |
| 130 |
//---------------------------- |
| 131 |
|
| 132 |
Map_et mp(mg, bornes) ; |
| 133 |
|
| 134 |
const Coord& r = mp.r ; |
| 135 |
const Coord& x = mp.x ; |
| 136 |
const Coord& y = mp.y ; |
| 137 |
const Coord& z = mp.z ; |
| 138 |
// const Coord& cost = mp.cost ; |
| 139 |
const Coord& sint = mp.sint ; |
| 140 |
// const Coord& cosp = mp.cosp ; |
| 141 |
// const Coord& sinp = mp.sinp ; |
| 142 |
|
| 143 |
//----------------------------------------------------------------------- |
| 144 |
// Construction of a Cmp |
| 145 |
//----------------------------------------------------------------------- |
| 146 |
|
| 147 |
Cmp ent(mp) ; |
| 148 |
|
| 149 |
double bsa = 0.9 ; |
| 150 |
double csa = 0.8 ; |
| 151 |
double xtri = - 0. ; |
| 152 |
double ray0 = mp.val_r(0, 1., M_PI/2, 0) ; |
| 153 |
|
| 154 |
double a = sqrt( ray0 * (ray0 + xtri) ) ; |
| 155 |
double b = bsa * a ; |
| 156 |
double c = csa * a ; |
| 157 |
|
| 158 |
cout << "a, b, c, xtri : " << a << " " << b << " " << c << " " |
| 159 |
<< xtri << endl ; |
| 160 |
|
| 161 |
|
| 162 |
ent = 1 - (x+xtri)*x/(a*a) - (y*y)/(b*b) - (z*z)/(c*c) ; |
| 163 |
|
| 164 |
ent.annule(nz-1) ; |
| 165 |
ent.std_base_scal() ; |
| 166 |
|
| 167 |
|
| 168 |
//----------------------------------------------------------------------- |
| 169 |
// Adaptation of the Map_et to the Cmp |
| 170 |
//----------------------------------------------------------------------- |
| 171 |
|
| 172 |
// Save the old value of the mapping : |
| 173 |
Map_et mp_prev = mp ; |
| 174 |
|
| 175 |
int nzet = 1 ; |
| 176 |
int nitermax = 100 ; |
| 177 |
int niter ; |
| 178 |
double precis = 1.e-15 ; |
| 179 |
int j_bord = mg.get_nt(0) - 1 ; |
| 180 |
int k_bord = 0 ; |
| 181 |
double fact_echelle = 1 ; |
| 182 |
double fact_lamu = 1 ; |
| 183 |
|
| 184 |
Tbl ent_limit(nzet) ; |
| 185 |
ent_limit.set_etat_qcq() ; |
| 186 |
ent_limit.set(0) = 0 ; |
| 187 |
|
| 188 |
int i_one = 1 ; |
| 189 |
|
| 190 |
Param par ; |
| 191 |
par.add_int(nitermax, 0) ; |
| 192 |
par.add_int(nzet, 1) ; |
| 193 |
par.add_int(i_one, 2) ; // 1 = full computation |
| 194 |
par.add_int(j_bord, 3) ; |
| 195 |
par.add_int(k_bord, 4) ; |
| 196 |
par.add_int_mod(niter) ; |
| 197 |
par.add_double(precis, 0) ; |
| 198 |
par.add_double(fact_lamu, 1) ; |
| 199 |
par.add_double_mod(fact_echelle, 0) ; |
| 200 |
par.add_tbl(ent_limit, 0) ; |
| 201 |
|
| 202 |
mp.adapt(ent, par) ; |
| 203 |
|
| 204 |
cout << endl << "Mapping mp (after adaptation) : " << endl ; |
| 205 |
cout << mp << endl ; |
| 206 |
|
| 207 |
cout << endl << "Coefficients of the mapping functions F and G" << endl ; |
| 208 |
// des_map_et(mp, 0) ; |
| 209 |
// des_map_et(mp, 1) ; |
| 210 |
|
| 211 |
|
| 212 |
// Computation of the field ent at the new collocation points |
| 213 |
// ---------------------------------------------------------- |
| 214 |
|
| 215 |
mp.reevaluate(&mp_prev, nz-1, ent) ; |
| 216 |
|
| 217 |
|
| 218 |
// des_coupe_x(ent, 0., -3., 3., -3., 3., "Enthalpy (x=0)", |
| 219 |
// &ent, 25) ; |
| 220 |
// des_coupe_y(ent, 0., -3., 3., -3., 3., "Enthalpy (y=0)", |
| 221 |
// &ent, 25) ; |
| 222 |
// des_coupe_z(ent, 0., -3., 3., -3., 3., "Enthalpy (z=0)", |
| 223 |
// &ent, 25) ; |
| 224 |
|
| 225 |
//----------------------------------------------------------------------- |
| 226 |
// Resolution of the continuity equation |
| 227 |
//----------------------------------------------------------------------- |
| 228 |
|
| 229 |
Cmp psi(mp) ; // velocity scalar potential |
| 230 |
|
| 231 |
double gamma = 2 ; |
| 232 |
|
| 233 |
Cmp aa = (gamma-1) * ent ; |
| 234 |
|
| 235 |
Tenseur ent1(ent) ; |
| 236 |
Tenseur bb = ent1.gradient_spher() ; |
| 237 |
bb.annule(1, nz-1) ; |
| 238 |
|
| 239 |
double omega = 1. ; |
| 240 |
|
| 241 |
Tenseur vit_rot(mp, 1, CON, mp.get_bvect_spher()) ; |
| 242 |
vit_rot.set_etat_qcq() ; |
| 243 |
vit_rot.set(0) = 0 ; |
| 244 |
vit_rot.set(1) = 0 ; |
| 245 |
vit_rot.set(2) = omega * r * sint ; |
| 246 |
vit_rot.annule(1, nz-1) ; |
| 247 |
|
| 248 |
Tenseur source1 = contract(vit_rot, 0, bb, 0) ; |
| 249 |
|
| 250 |
double relax = 0.5 ; |
| 251 |
nitermax = 100 ; |
| 252 |
precis = 1.e-8 ; |
| 253 |
|
| 254 |
Param par_com ; |
| 255 |
par_com.add_int(nitermax) ; |
| 256 |
par_com.add_int_mod(niter) ; |
| 257 |
par_com.add_double(precis, 0) ; |
| 258 |
par_com.add_double(relax, 1) ; |
| 259 |
|
| 260 |
psi = 0 ; |
| 261 |
|
| 262 |
mp.poisson_compact(source1(), aa, bb, par_com, psi) ; |
| 263 |
|
| 264 |
cout << "Coef of psi : " << endl ; |
| 265 |
(psi.va).affiche_seuil(cout) ; |
| 266 |
|
| 267 |
//----------------------------------------------------------------------- |
| 268 |
// Test: does the solution satisfies to the equation ? |
| 269 |
//----------------------------------------------------------------------- |
| 270 |
|
| 271 |
Tenseur psi1(psi) ; |
| 272 |
Tenseur dpsi = psi1.gradient_spher() ; |
| 273 |
Cmp bdpsi = bb(0)*dpsi(0) + bb(1)*dpsi(1) + bb(2)*dpsi(2) ; |
| 274 |
|
| 275 |
cout << "Coef of bdpsi : " << endl ; |
| 276 |
(bdpsi.va).affiche_seuil(cout) ; |
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
Cmp source = source1() ; |
| 281 |
source.set_dzpuis(4) ; |
| 282 |
source.annule(1, nz-1) ; |
| 283 |
|
| 284 |
Cmp op_psi = aa * psi.laplacien() + bdpsi ; |
| 285 |
|
| 286 |
cout << "Coef of op_psi : " << endl ; |
| 287 |
(op_psi.va).affiche_seuil(cout) ; |
| 288 |
|
| 289 |
Cmp diff = op_psi - source ; |
| 290 |
|
| 291 |
cout << "Coef of diff : " << endl ; |
| 292 |
(diff.va).affiche_seuil(cout) ; |
| 293 |
|
| 294 |
cout << "diffrel(op_psi, source) : " << endl ; |
| 295 |
cout << diffrel(op_psi, source) << endl ; |
| 296 |
|
| 297 |
cout << "diffrelmax(op_psi, source) : " << endl ; |
| 298 |
cout << diffrelmax(op_psi, source) << endl ; |
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
// Cleaning |
| 303 |
// -------- |
| 304 |
|
| 305 |
delete [] nr ; |
| 306 |
delete [] nt_tab ; |
| 307 |
delete [] np_tab ; |
| 308 |
delete [] bornes ; |
| 309 |
delete [] type_r ; |
| 310 |
|
| 311 |
exit(EXIT_SUCCESS) ; |
| 312 |
|
| 313 |
} |
| 314 |
|