| 1 |
/* |
| 2 |
* Test program the derivative functions of the Cmp class with a Map_af 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_map_af_deriv_C[] = "$Header: /cvsroot/Lorene/Codes/Test/Map/test_map_af_deriv.C,v 1.5 2014/10/13 08:54:01 j_novak Exp $" ; |
| 28 |
|
| 29 |
/* |
| 30 |
* $Id: test_map_af_deriv.C,v 1.5 2014/10/13 08:54:01 j_novak Exp $ |
| 31 |
* $Log: test_map_af_deriv.C,v $ |
| 32 |
* Revision 1.5 2014/10/13 08:54:01 j_novak |
| 33 |
* Lorene classes and functions now belong to the namespace Lorene. |
| 34 |
* |
| 35 |
* Revision 1.4 2014/10/06 15:12:52 j_novak |
| 36 |
* Modified #include directives to use c++ syntax. |
| 37 |
* |
| 38 |
* Revision 1.3 2004/01/22 16:18:52 e_gourgoulhon |
| 39 |
* void main() --> int main(). |
| 40 |
* |
| 41 |
* Revision 1.2 2003/01/09 11:07:53 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.2 2000/01/28 08:48:00 eric |
| 49 |
* Identification du code au debut |
| 50 |
* |
| 51 |
* Revision 1.1 2000/01/27 15:25:29 eric |
| 52 |
* Initial revision |
| 53 |
* |
| 54 |
* |
| 55 |
* $Header: /cvsroot/Lorene/Codes/Test/Map/test_map_af_deriv.C,v 1.5 2014/10/13 08:54:01 j_novak Exp $ |
| 56 |
* |
| 57 |
*/ |
| 58 |
|
| 59 |
// headers C |
| 60 |
#include <cstdlib> |
| 61 |
#include <cmath> |
| 62 |
|
| 63 |
// headers Lorene |
| 64 |
#include "type_parite.h" |
| 65 |
#include "cmp.h" |
| 66 |
#include "utilitaires.h" |
| 67 |
#include "param.h" |
| 68 |
#include "graphique.h" |
| 69 |
#include "nbr_spx.h" |
| 70 |
|
| 71 |
//****************************************************************************** |
| 72 |
|
| 73 |
using namespace Lorene ; |
| 74 |
|
| 75 |
int main(){ |
| 76 |
|
| 77 |
// Identification of all the subroutines called by the code : |
| 78 |
|
| 79 |
system("ident test_map_af_deriv") ; |
| 80 |
|
| 81 |
//----------------------------------------------------------------------- |
| 82 |
// Input data : number of points, types of sampling, etc... |
| 83 |
//----------------------------------------------------------------------- |
| 84 |
|
| 85 |
int nt = 7 ; // Number of points in theta |
| 86 |
int np = 8 ; // Number of points in phi |
| 87 |
int nz = 3 ; // Number of domains |
| 88 |
|
| 89 |
int* nr = new int[nz]; |
| 90 |
int* nt_tab = new int[nz]; |
| 91 |
int* np_tab = new int[nz]; |
| 92 |
double* bornes = new double[nz+1]; |
| 93 |
int* type_r = new int[nz]; |
| 94 |
|
| 95 |
for (int l=0; l<nz; l++) { |
| 96 |
nr[l] = 9 ; // Number of points in r |
| 97 |
np_tab[l] = np ; |
| 98 |
nt_tab[l] = nt ; |
| 99 |
} |
| 100 |
|
| 101 |
bornes[0] = 0. ; |
| 102 |
bornes[1] = 2. ; |
| 103 |
bornes[2] = 3.5 ; |
| 104 |
bornes[3] = __infinity ; |
| 105 |
|
| 106 |
type_r[0] = RARE ; |
| 107 |
type_r[1] = FIN ; |
| 108 |
type_r[2] = UNSURR ; |
| 109 |
|
| 110 |
int type_t = SYM ; |
| 111 |
|
| 112 |
int type_p = NONSYM ; |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
//----------------------------------------------------------------------- |
| 117 |
// Construction of a multi-grid |
| 118 |
//----------------------------------------------------------------------- |
| 119 |
|
| 120 |
type_t = SYM ; |
| 121 |
type_p = NONSYM ; |
| 122 |
|
| 123 |
const Mg3d mg(nz, nr, type_r, nt_tab, type_t, np_tab, type_p) ; |
| 124 |
|
| 125 |
//---------------------------- |
| 126 |
// Construction of the Map_af |
| 127 |
//---------------------------- |
| 128 |
|
| 129 |
Map_af mp(mg, bornes) ; |
| 130 |
|
| 131 |
const Coord& r = mp.r ; |
| 132 |
const Coord& x = mp.x ; |
| 133 |
const Coord& y = mp.y ; |
| 134 |
const Coord& z = mp.z ; |
| 135 |
const Coord& cost = mp.cost ; |
| 136 |
const Coord& sint = mp.sint ; |
| 137 |
const Coord& cosp = mp.cosp ; |
| 138 |
const Coord& sinp = mp.sinp ; |
| 139 |
|
| 140 |
//----------------------------------------------------------------------- |
| 141 |
// Construction of a Cmp |
| 142 |
//----------------------------------------------------------------------- |
| 143 |
|
| 144 |
Cmp aa(mp) ; |
| 145 |
Cmp aa_ext(mp) ; |
| 146 |
Cmp da_ana(mp) ; |
| 147 |
Cmp da_ana_ext(mp) ; |
| 148 |
Cmp da(mp) ; |
| 149 |
|
| 150 |
aa = x*y*z*z + y ; |
| 151 |
aa_ext = 1 / (r*r) ; |
| 152 |
|
| 153 |
aa.annule(nz-1) ; |
| 154 |
aa_ext.annule(0, nz-2) ; |
| 155 |
|
| 156 |
aa = aa + aa_ext ; |
| 157 |
|
| 158 |
aa.std_base_scal() ; // Sets the standard basis for spectral expansions |
| 159 |
|
| 160 |
cout << "Coefficients of aa = x y z^2 + y (in ZEC : aa = 1/r^2) : " << endl ; |
| 161 |
aa.affiche_seuil(cout) ; |
| 162 |
|
| 163 |
arrete() ; |
| 164 |
|
| 165 |
// Computation of da/dx |
| 166 |
// -------------------- |
| 167 |
|
| 168 |
da = aa.dsdx() ; |
| 169 |
|
| 170 |
// Analytical expression for da/dx : |
| 171 |
da_ana = y*z*z ; |
| 172 |
da_ana_ext = - 2 * sint * cosp / r ; |
| 173 |
|
| 174 |
da_ana.annule(nz-1) ; |
| 175 |
da_ana_ext.annule(0, nz-2) ; |
| 176 |
|
| 177 |
da_ana = da_ana + da_ana_ext ; |
| 178 |
da_ana.set_dzpuis(2) ; |
| 179 |
da_ana.std_base_scal() ; |
| 180 |
|
| 181 |
cout << "Coefficients of da/dx : " << endl ; |
| 182 |
da.affiche_seuil(cout) ; |
| 183 |
|
| 184 |
cout << "Coefficients of da/dx analytical : " << endl ; |
| 185 |
da_ana.affiche_seuil(cout) ; |
| 186 |
|
| 187 |
cout << "Relative difference da/dx <-> da/dx analytical : " << endl ; |
| 188 |
cout << diffrel(da, da_ana) << endl ; |
| 189 |
|
| 190 |
cout << "Difference coefficients da/dx <-> da/dx analytical : " << endl ; |
| 191 |
(da.va).coef() ; |
| 192 |
(da_ana.va).coef() ; |
| 193 |
Mtbl_cf diff = *((da.va).c_cf) - *((da_ana.va).c_cf) ; |
| 194 |
diff.affiche_seuil(cout) ; |
| 195 |
|
| 196 |
arrete() ; |
| 197 |
|
| 198 |
// Computation of da/dy |
| 199 |
// -------------------- |
| 200 |
|
| 201 |
da = aa.dsdy() ; |
| 202 |
|
| 203 |
// Analytical expression for da/dy : |
| 204 |
da_ana = x*z*z + 1 ; |
| 205 |
da_ana_ext = - 2 * sint * sinp / r ; |
| 206 |
|
| 207 |
da_ana.annule(nz-1) ; |
| 208 |
da_ana_ext.annule(0, nz-2) ; |
| 209 |
|
| 210 |
da_ana = da_ana + da_ana_ext ; |
| 211 |
da_ana.set_dzpuis(2) ; |
| 212 |
da_ana.std_base_scal() ; |
| 213 |
|
| 214 |
cout << "Coefficients of da/dy : " << endl ; |
| 215 |
da.affiche_seuil(cout) ; |
| 216 |
|
| 217 |
cout << "Coefficients of da/dy analytical : " << endl ; |
| 218 |
da_ana.affiche_seuil(cout) ; |
| 219 |
|
| 220 |
cout << "Relative difference da/dy <-> da/dy analytical : " << endl ; |
| 221 |
cout << diffrel(da, da_ana) << endl ; |
| 222 |
|
| 223 |
cout << "Difference coefficients da/dy <-> da/dy analytical : " << endl ; |
| 224 |
(da.va).coef() ; |
| 225 |
(da_ana.va).coef() ; |
| 226 |
diff = *((da.va).c_cf) - *((da_ana.va).c_cf) ; |
| 227 |
diff.affiche_seuil(cout) ; |
| 228 |
|
| 229 |
arrete() ; |
| 230 |
|
| 231 |
// Computation of da/dz |
| 232 |
// -------------------- |
| 233 |
|
| 234 |
da = aa.dsdz() ; |
| 235 |
|
| 236 |
// Analytical expression for da/dz : |
| 237 |
da_ana = 2*z*x*y ; |
| 238 |
da_ana_ext = - 2 * cost / r ; |
| 239 |
|
| 240 |
da_ana.annule(nz-1) ; |
| 241 |
da_ana_ext.annule(0, nz-2) ; |
| 242 |
|
| 243 |
da_ana = da_ana + da_ana_ext ; |
| 244 |
da_ana.set_dzpuis(2) ; |
| 245 |
(da_ana.va).set_base( (da.va).base ) ; |
| 246 |
|
| 247 |
cout << "Coefficients of da/dz : " << endl ; |
| 248 |
da.affiche_seuil(cout) ; |
| 249 |
|
| 250 |
cout << "Coefficients of da/dz analytical : " << endl ; |
| 251 |
da_ana.affiche_seuil(cout) ; |
| 252 |
|
| 253 |
cout << "Relative difference da/dz <-> da/dz analytical : " << endl ; |
| 254 |
cout << diffrel(da, da_ana) << endl ; |
| 255 |
|
| 256 |
cout << "Difference coefficients da/dz <-> da/dz analytical : " << endl ; |
| 257 |
(da.va).coef() ; |
| 258 |
(da_ana.va).coef() ; |
| 259 |
diff = *((da.va).c_cf) - *((da_ana.va).c_cf) ; |
| 260 |
diff.affiche_seuil(cout) ; |
| 261 |
|
| 262 |
// Cleaning |
| 263 |
// -------- |
| 264 |
|
| 265 |
delete [] nr ; |
| 266 |
delete [] nt_tab ; |
| 267 |
delete [] np_tab ; |
| 268 |
delete [] bornes ; |
| 269 |
delete [] type_r ; |
| 270 |
|
| 271 |
return EXIT_SUCCESS ; |
| 272 |
|
| 273 |
} |
| 274 |
|