| 1 |
/* |
| 2 |
* Code for testing the class Vector_divfree. |
| 3 |
* |
| 4 |
*/ |
| 5 |
|
| 6 |
/* |
| 7 |
* Copyright (c) 2003 Eric Gourgoulhon & Jerome Novak |
| 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 version 2 |
| 13 |
* as published by the Free Software Foundation. |
| 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 test_vector_df_C[] = "$Header: /cvsroot/Lorene/Codes/Test/Tensor/test_vector_df.C,v 1.9 2014/10/13 08:54:03 j_novak Exp $" ; |
| 27 |
|
| 28 |
/* |
| 29 |
* $Id: test_vector_df.C,v 1.9 2014/10/13 08:54:03 j_novak Exp $ |
| 30 |
* $Log: test_vector_df.C,v $ |
| 31 |
* Revision 1.9 2014/10/13 08:54:03 j_novak |
| 32 |
* Lorene classes and functions now belong to the namespace Lorene. |
| 33 |
* |
| 34 |
* Revision 1.8 2014/10/06 15:12:56 j_novak |
| 35 |
* Modified #include directives to use c++ syntax. |
| 36 |
* |
| 37 |
* Revision 1.7 2008/08/27 08:54:28 jl_cornou |
| 38 |
* Added test for angular potential A |
| 39 |
* |
| 40 |
* Revision 1.6 2003/10/29 11:06:50 e_gourgoulhon |
| 41 |
* dec2_dzpuis() replaced by dec_dzpuis(2). |
| 42 |
* |
| 43 |
* Revision 1.5 2003/10/28 21:37:02 e_gourgoulhon |
| 44 |
* Change the name of the global char[] for code identification. |
| 45 |
* |
| 46 |
* Revision 1.4 2003/10/20 10:14:08 e_gourgoulhon |
| 47 |
* Added test with more general vectors. |
| 48 |
* |
| 49 |
* Revision 1.3 2003/10/19 20:05:07 e_gourgoulhon |
| 50 |
* Change of the argument list of Scalar::spectral_display |
| 51 |
* (cout now default). |
| 52 |
* |
| 53 |
* Revision 1.2 2003/10/17 16:33:36 e_gourgoulhon |
| 54 |
* Added more tests. |
| 55 |
* |
| 56 |
* Revision 1.1 2003/10/16 21:39:43 e_gourgoulhon |
| 57 |
* Test code for class Vector_divfree. |
| 58 |
* |
| 59 |
* |
| 60 |
* |
| 61 |
* $Header: /cvsroot/Lorene/Codes/Test/Tensor/test_vector_df.C,v 1.9 2014/10/13 08:54:03 j_novak Exp $ |
| 62 |
* |
| 63 |
*/ |
| 64 |
|
| 65 |
// C++ headers |
| 66 |
#include "headcpp.h" |
| 67 |
|
| 68 |
// C headers |
| 69 |
#include <cstdlib> |
| 70 |
|
| 71 |
// Lorene headers |
| 72 |
#include "metric.h" |
| 73 |
#include "nbr_spx.h" |
| 74 |
#include "utilitaires.h" |
| 75 |
|
| 76 |
|
| 77 |
using namespace Lorene ; |
| 78 |
|
| 79 |
int main() { |
| 80 |
|
| 81 |
// Construction of a multi-grid (Mg3d) |
| 82 |
// ----------------------------------- |
| 83 |
|
| 84 |
int nz = 3 ; // Number of domains |
| 85 |
int nzm1 = nz - 1 ; |
| 86 |
int nr = 17 ; // Number of collocation points in r in each domain |
| 87 |
int nt = 17 ; // Number of collocation points in theta in each domain |
| 88 |
int np = 32 ; // Number of collocation points in phi in each domain |
| 89 |
int symmetry_theta = SYM ; // symmetry with respect to the equatorial plane |
| 90 |
int symmetry_phi = NONSYM ; // no symmetry in phi |
| 91 |
bool compact = true ; // external domain is compactified |
| 92 |
|
| 93 |
Mg3d mgrid(nz, nr, nt, np, symmetry_theta, symmetry_phi, compact) ; |
| 94 |
|
| 95 |
|
| 96 |
// Construction of an affine mapping (Map_af) |
| 97 |
// ------------------------------------------ |
| 98 |
|
| 99 |
// Boundaries of each domains |
| 100 |
double r_limits[] = {0., 1., 2., __infinity} ; |
| 101 |
assert( nz == 3 ) ; // since the above array described only 3 domains |
| 102 |
|
| 103 |
Map_af map(mgrid, r_limits) ; |
| 104 |
|
| 105 |
|
| 106 |
// Construction of a flat metric |
| 107 |
// ----------------------------- |
| 108 |
|
| 109 |
Metric_flat mets(map, map.get_bvect_spher()) ; // spherical representation |
| 110 |
Metric_flat metc(map, map.get_bvect_cart()) ; // Cartesian representation |
| 111 |
|
| 112 |
|
| 113 |
// Construction of a divergence free vector field |
| 114 |
// ---------------------------------------------- |
| 115 |
|
| 116 |
const Coord& x = map.x ; |
| 117 |
const Coord& y = map.y ; |
| 118 |
const Coord& z = map.z ; |
| 119 |
const Coord& r = map.r ; |
| 120 |
const Coord& cost = map.cost ; |
| 121 |
const Coord& sint = map.sint ; |
| 122 |
const Coord& cosp = map.cosp ; |
| 123 |
const Coord& sinp = map.sinp ; |
| 124 |
|
| 125 |
|
| 126 |
cout << "========================================================" << endl ; |
| 127 |
cout << " Test with a constant vector" << endl ; |
| 128 |
cout << " Cartesian comp.: V^i = (1, 1, 0)" << endl ; |
| 129 |
cout << "========================================================" << endl ; |
| 130 |
|
| 131 |
Vector_divfree vvc(map, map.get_bvect_cart(), metc ) ; |
| 132 |
|
| 133 |
vvc.set(1) = 1 ; |
| 134 |
vvc.set(2) = 1 ; |
| 135 |
vvc.set(3) = 0 ; |
| 136 |
vvc.std_spectral_base() ; |
| 137 |
|
| 138 |
Vector_divfree vvs = vvc ; |
| 139 |
vvs.change_triad( map.get_bvect_spher() ) ; |
| 140 |
|
| 141 |
cout << "Spherical components : vvs : " << endl ; |
| 142 |
vvs.spectral_display() ; |
| 143 |
arrete() ; |
| 144 |
|
| 145 |
cout << "eta : " << endl ; |
| 146 |
cout << "----" << endl ; |
| 147 |
vvs.eta().spectral_display() ; |
| 148 |
arrete() ; |
| 149 |
|
| 150 |
cout << "mu : " << endl ; |
| 151 |
cout << "----" << endl ; |
| 152 |
vvs.mu().spectral_display() ; |
| 153 |
|
| 154 |
cout << "Norme divergence vvc : " << norme( vvc.divergence(metc) ) << endl ; |
| 155 |
cout << "Norme divergence vvs : " << norme( vvs.divergence(mets) ) << endl ; |
| 156 |
cout << "Max divergence vvc : " << max( abs(vvc.divergence(metc)) ) << endl ; |
| 157 |
cout << "Max divergence vvs : " << max( abs(vvs.divergence(mets)) ) << endl ; |
| 158 |
arrete() ; |
| 159 |
|
| 160 |
Vector_divfree vvs2(map, map.get_bvect_spher(), mets ) ; |
| 161 |
vvs2.set_vr_eta_mu(vvs(1), vvs.eta(), vvs.mu()) ; |
| 162 |
Vector diff = vvs - vvs2 ; |
| 163 |
cout << "diff : " << endl ; |
| 164 |
for (int i=1; i<=3; i++) { |
| 165 |
cout << "Component " << i << " : " << endl ; |
| 166 |
diff(i).spectral_display() ; |
| 167 |
cout << " norme: " << norme(diff(i)) << endl ; |
| 168 |
arrete() ; |
| 169 |
} |
| 170 |
|
| 171 |
|
| 172 |
cout << "========================================================" << endl ; |
| 173 |
cout << " Test with a rotation vector" << endl ; |
| 174 |
cout << " Cartesian comp.: V^i = (-y, x, 0)" << endl ; |
| 175 |
cout << "========================================================" << endl ; |
| 176 |
|
| 177 |
vvc.set(1) = -y ; |
| 178 |
vvc.set(2) = x ; |
| 179 |
vvc.set(3) = 0 ; |
| 180 |
vvc.annule_domain(nzm1) ; |
| 181 |
vvc.std_spectral_base() ; |
| 182 |
vvs.set_triad( map.get_bvect_cart() ) ; |
| 183 |
vvs = vvc ; |
| 184 |
vvs.change_triad( map.get_bvect_spher() ) ; |
| 185 |
|
| 186 |
cout << "Cartesian components : vvc : " << endl ; |
| 187 |
vvc.spectral_display() ; |
| 188 |
arrete() ; |
| 189 |
|
| 190 |
cout << "Spherical components : vvs : " << endl ; |
| 191 |
vvs.spectral_display() ; |
| 192 |
arrete() ; |
| 193 |
|
| 194 |
cout << "eta : " << endl ; |
| 195 |
cout << "----" << endl ; |
| 196 |
vvs.eta().spectral_display() ; |
| 197 |
arrete() ; |
| 198 |
|
| 199 |
cout << "mu : " << endl ; |
| 200 |
cout << "----" << endl ; |
| 201 |
vvs.mu().spectral_display() ; |
| 202 |
|
| 203 |
cout << "Norme divergence vvc : " << norme( vvc.divergence(metc) ) << endl ; |
| 204 |
cout << "Norme divergence vvs : " << norme( vvs.divergence(mets) ) << endl ; |
| 205 |
cout << "Max divergence vvc : " << max( abs(vvc.divergence(metc)) ) << endl ; |
| 206 |
cout << "Max divergence vvs : " << max( abs(vvs.divergence(mets)) ) << endl ; |
| 207 |
arrete() ; |
| 208 |
|
| 209 |
vvs2.set_vr_eta_mu(vvs(1), vvs.eta(), vvs.mu()) ; |
| 210 |
diff = vvs - vvs2 ; |
| 211 |
cout << "diff : " << endl ; |
| 212 |
for (int i=1; i<=3; i++) { |
| 213 |
cout << "Component " << i << " : " << endl ; |
| 214 |
diff(i).spectral_display() ; |
| 215 |
cout << " norme: " << norme(diff(i)) << endl ; |
| 216 |
arrete() ; |
| 217 |
} |
| 218 |
|
| 219 |
|
| 220 |
cout << "========================================================" << endl ; |
| 221 |
cout << " Test with a pretty general vector" << endl ; |
| 222 |
cout << " V = curl(A) " << endl ; |
| 223 |
cout << "========================================================" << endl ; |
| 224 |
|
| 225 |
Vector aa(map, CON, map.get_bvect_cart()) ; |
| 226 |
aa.set(1) = x + x*y - 3*z*z ; |
| 227 |
aa.set(2) = z*z*x - 2 *y + 1 ; |
| 228 |
aa.set(3) = z* ( 1 + x*x - y + x + x*y + z*z ) ; |
| 229 |
aa.annule_domain(nzm1) ; |
| 230 |
|
| 231 |
|
| 232 |
Mtbl tced = sint*cosp / (r*r) + cost*cost / (r*r*r) ; |
| 233 |
aa.set(1).set_domain(nzm1) = tced(nzm1) ; |
| 234 |
|
| 235 |
tced = 1 / (r*r) + cost*cost*sint*sinp / (r*r*r) ; |
| 236 |
aa.set(2).set_domain(nzm1) = tced(nzm1) ; |
| 237 |
|
| 238 |
tced = cost / (r*r) + cost*sint*cosp / (r*r*r) ; |
| 239 |
aa.set(3).set_domain(nzm1) = tced(nzm1) ; |
| 240 |
|
| 241 |
aa.std_spectral_base() ; |
| 242 |
|
| 243 |
// cout << "aa : " << endl ; |
| 244 |
// aa.spectral_display(1.e-14) ; |
| 245 |
// arrete() ; |
| 246 |
|
| 247 |
|
| 248 |
// Curl of aa: |
| 249 |
vvc.set(1) = aa(3).dsdy() - aa(2).dsdz() ; |
| 250 |
vvc.set(2) = aa(1).dsdz() - aa(3).dsdx() ; |
| 251 |
vvc.set(3) = aa(2).dsdx() - aa(1).dsdy() ; |
| 252 |
vvc.dec_dzpuis(2) ; |
| 253 |
|
| 254 |
vvs.set_triad( map.get_bvect_cart() ) ; |
| 255 |
vvs = vvc ; |
| 256 |
vvs.change_triad( map.get_bvect_spher() ) ; |
| 257 |
|
| 258 |
cout << "Cartesian components : vvc : " << endl ; |
| 259 |
vvc.spectral_display() ; |
| 260 |
arrete() ; |
| 261 |
|
| 262 |
cout << "Spherical components : vvs : " << endl ; |
| 263 |
vvs.spectral_display() ; |
| 264 |
arrete() ; |
| 265 |
|
| 266 |
cout << "eta : " << endl ; |
| 267 |
cout << "----" << endl ; |
| 268 |
vvs.eta().spectral_display() ; |
| 269 |
arrete() ; |
| 270 |
|
| 271 |
cout << "mu : " << endl ; |
| 272 |
cout << "----" << endl ; |
| 273 |
vvs.mu().spectral_display() ; |
| 274 |
|
| 275 |
cout << "Norme divergence vvc : " << norme( vvc.divergence(metc) ) << endl ; |
| 276 |
cout << "Norme divergence vvs : " << norme( vvs.divergence(mets) ) << endl ; |
| 277 |
cout << "Max divergence vvc : " << max( abs(vvc.divergence(metc)) ) << endl ; |
| 278 |
cout << "Max divergence vvs : " << max( abs(vvs.divergence(mets)) ) << endl ; |
| 279 |
|
| 280 |
Valeur vdiv = vvs.divergence(mets).get_spectral_va() ; |
| 281 |
vdiv.coef() ; |
| 282 |
cout << "Max cf vdiv : " << max(abs(*(vdiv.c_cf))) << endl ; |
| 283 |
// vdiv.display_coef(1.e-12) ; |
| 284 |
|
| 285 |
arrete() ; |
| 286 |
|
| 287 |
vvs2.set_vr_eta_mu(vvs(1), vvs.eta(), vvs.mu()) ; |
| 288 |
diff = vvs - vvs2 ; |
| 289 |
cout << "diff : " << endl ; |
| 290 |
for (int i=1; i<=3; i++) { |
| 291 |
cout << "Component " << i << " : " << endl ; |
| 292 |
diff(i).spectral_display() ; |
| 293 |
cout << " norme: " << norme(diff(i)) << endl ; |
| 294 |
arrete() ; |
| 295 |
} |
| 296 |
|
| 297 |
|
| 298 |
return EXIT_SUCCESS ; |
| 299 |
} |