| 1 |
/* |
| 2 |
* Code for testing the classes Sym_tensor_trans and Sym_tensor_tt. |
| 3 |
* |
| 4 |
*/ |
| 5 |
|
| 6 |
/* |
| 7 |
* Copyright (c) 2003-2004 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_sym_tensor_tt_C[] = "$Header: /cvsroot/Lorene/Codes/Test/Tensor/test_sym_tensor_tt.C,v 1.16 2014/10/13 08:54:03 j_novak Exp $" ; |
| 27 |
|
| 28 |
/* |
| 29 |
* $Id: test_sym_tensor_tt.C,v 1.16 2014/10/13 08:54:03 j_novak Exp $ |
| 30 |
* $Log: test_sym_tensor_tt.C,v $ |
| 31 |
* Revision 1.16 2014/10/13 08:54:03 j_novak |
| 32 |
* Lorene classes and functions now belong to the namespace Lorene. |
| 33 |
* |
| 34 |
* Revision 1.15 2014/10/06 15:12:56 j_novak |
| 35 |
* Modified #include directives to use c++ syntax. |
| 36 |
* |
| 37 |
* Revision 1.14 2004/02/19 22:15:55 e_gourgoulhon |
| 38 |
* New argument "comment" in functions spectral_display and diffrelmax. |
| 39 |
* |
| 40 |
* Revision 1.13 2004/02/18 18:57:38 e_gourgoulhon |
| 41 |
* Method trace() renamed the_trace(). |
| 42 |
* |
| 43 |
* Revision 1.12 2004/02/09 13:24:56 e_gourgoulhon |
| 44 |
* Added test of the TT decomposition from scratch. |
| 45 |
* Passed in the nucleus and shells only, and only for dzpuis=4. |
| 46 |
* |
| 47 |
* Revision 1.11 2004/02/05 13:46:21 e_gourgoulhon |
| 48 |
* Take into account the new dzpuis conventions for derivatives. |
| 49 |
* Tests passed in the generic case with htt dzpuis = 0, 2, 3 and 4. |
| 50 |
* |
| 51 |
* Revision 1.10 2003/11/06 10:33:41 e_gourgoulhon |
| 52 |
* Added tests for the mu part. |
| 53 |
* |
| 54 |
* Revision 1.9 2003/11/05 15:32:12 e_gourgoulhon |
| 55 |
* Use of new functions maxabs and diffrelmax acting on tensors. |
| 56 |
* |
| 57 |
* Revision 1.8 2003/11/04 23:04:43 e_gourgoulhon |
| 58 |
* First test of Sym_tensor_tt::set_rr_eta_mu. |
| 59 |
* |
| 60 |
* Revision 1.7 2003/11/04 15:01:16 e_gourgoulhon |
| 61 |
* Pretty general test for eta. |
| 62 |
* |
| 63 |
* Revision 1.6 2003/11/03 22:37:12 e_gourgoulhon |
| 64 |
* New version. |
| 65 |
* |
| 66 |
* Revision 1.5 2003/10/30 17:29:07 e_gourgoulhon |
| 67 |
* new version |
| 68 |
* |
| 69 |
* Revision 1.4 2003/10/29 13:15:26 e_gourgoulhon |
| 70 |
* Change of method name: Scalar::laplacien --> Scalar::laplacian. |
| 71 |
* |
| 72 |
* Revision 1.3 2003/10/28 21:37:22 e_gourgoulhon |
| 73 |
* New version. |
| 74 |
* |
| 75 |
* Revision 1.2 2003/10/28 12:36:52 e_gourgoulhon |
| 76 |
* improved version |
| 77 |
* |
| 78 |
* Revision 1.1 2003/10/27 10:56:57 e_gourgoulhon |
| 79 |
* Test code for class Sym_tensor_*. |
| 80 |
* |
| 81 |
* |
| 82 |
* $Header: /cvsroot/Lorene/Codes/Test/Tensor/test_sym_tensor_tt.C,v 1.16 2014/10/13 08:54:03 j_novak Exp $ |
| 83 |
* |
| 84 |
*/ |
| 85 |
|
| 86 |
// C++ headers |
| 87 |
#include "headcpp.h" |
| 88 |
|
| 89 |
// C headers |
| 90 |
#include <cstdlib> |
| 91 |
|
| 92 |
// Lorene headers |
| 93 |
#include "metric.h" |
| 94 |
#include "nbr_spx.h" |
| 95 |
#include "utilitaires.h" |
| 96 |
|
| 97 |
|
| 98 |
using namespace Lorene ; |
| 99 |
|
| 100 |
int main() { |
| 101 |
|
| 102 |
// Construction of a multi-grid (Mg3d) |
| 103 |
// ----------------------------------- |
| 104 |
|
| 105 |
int nz = 3 ; // Number of domains |
| 106 |
int nzm1 = nz - 1 ; |
| 107 |
int nr = 9 ; // Number of collocation points in r in each domain |
| 108 |
int nt = 7 ; // Number of collocation points in theta in each domain |
| 109 |
int np = 16 ; // Number of collocation points in phi in each domain |
| 110 |
int symmetry_theta = SYM ; // symmetry with respect to the equatorial plane |
| 111 |
int symmetry_phi = NONSYM ; // no symmetry in phi |
| 112 |
bool compact = true ; // external domain is compactified |
| 113 |
|
| 114 |
Mg3d mgrid(nz, nr, nt, np, symmetry_theta, symmetry_phi, compact) ; |
| 115 |
|
| 116 |
|
| 117 |
// Construction of an affine mapping (Map_af) |
| 118 |
// ------------------------------------------ |
| 119 |
|
| 120 |
// Boundaries of each domains |
| 121 |
double r_limits[] = {0., 2., 3., __infinity} ; |
| 122 |
assert( nz == 3 ) ; // since the above array described only 3 domains |
| 123 |
|
| 124 |
Map_af map(mgrid, r_limits) ; |
| 125 |
|
| 126 |
|
| 127 |
// Construction of a flat metric |
| 128 |
// ----------------------------- |
| 129 |
|
| 130 |
Metric_flat mets(map, map.get_bvect_spher()) ; // spherical representation |
| 131 |
Metric_flat metc(map, map.get_bvect_cart()) ; // Cartesian representation |
| 132 |
|
| 133 |
|
| 134 |
// Construction of a divergence free tensor field |
| 135 |
// ---------------------------------------------- |
| 136 |
|
| 137 |
const Coord& x = map.x ; |
| 138 |
const Coord& y = map.y ; |
| 139 |
const Coord& z = map.z ; |
| 140 |
const Coord& r = map.r ; |
| 141 |
const Coord& cost = map.cost ; |
| 142 |
const Coord& sint = map.sint ; |
| 143 |
const Coord& cosp = map.cosp ; |
| 144 |
const Coord& sinp = map.sinp ; |
| 145 |
const Coord& phi = map.phi ; |
| 146 |
|
| 147 |
|
| 148 |
cout << "========================================================" << endl ; |
| 149 |
cout << " Test with a constant tensor" << endl ; |
| 150 |
cout << " Cart. comp. h^{ij} = (0, 1, 2), (2,-1,3), (2,3,1) " << endl ; |
| 151 |
cout << "========================================================" << endl ; |
| 152 |
|
| 153 |
Sym_tensor_trans hhc(map, map.get_bvect_cart(), metc ) ; |
| 154 |
|
| 155 |
hhc.set(1,1) = 1 ; |
| 156 |
hhc.set(1,2) = 2 ; |
| 157 |
hhc.set(1,3) = 0 ; |
| 158 |
hhc.set(2,2) = -4 ; |
| 159 |
hhc.set(2,3) = 0 ; |
| 160 |
hhc.set(3,3) = 3 ; |
| 161 |
hhc.std_spectral_base() ; |
| 162 |
|
| 163 |
cout << "Cartesian components : hhc : " << endl ; |
| 164 |
hhc.spectral_display() ; |
| 165 |
arrete() ; |
| 166 |
|
| 167 |
Tensor tmp = hhc ; |
| 168 |
tmp.change_triad( map.get_bvect_spher() ) ; |
| 169 |
Sym_tensor_trans hhs(map, map.get_bvect_spher(), mets ) ; |
| 170 |
hhs = tmp ; |
| 171 |
|
| 172 |
cout << "Spherical components : hhs : " << endl ; |
| 173 |
hhs.spectral_display() ; |
| 174 |
arrete() ; |
| 175 |
|
| 176 |
cout << "Maxabs divergence hhc : " << endl ; |
| 177 |
maxabs( hhc.divergence(metc) ) ; |
| 178 |
cout << "Maxabs divergence hhs : " << endl ; |
| 179 |
maxabs( hhs.divergence(mets) ) ; |
| 180 |
|
| 181 |
Scalar trace = hhc.the_trace() ; |
| 182 |
cout << "Maxabs Trace of hhc : " << endl ; |
| 183 |
maxabs( trace ) ; |
| 184 |
|
| 185 |
cout << "Maxabs Trace of hhs : " << endl ; |
| 186 |
maxabs( hhs.the_trace() ) ; |
| 187 |
|
| 188 |
cout << "========================================================" << endl ; |
| 189 |
cout << " Test with the tensor" << endl ; |
| 190 |
cout << " Cart. comp. h^{ij} = d_i d_j Phi with Lap(Phi) = 0 " << endl ; |
| 191 |
cout << "========================================================" << endl ; |
| 192 |
|
| 193 |
arrete() ; |
| 194 |
|
| 195 |
Scalar pot(map) ; |
| 196 |
pot = // 1 // P_0^0 |
| 197 |
+ x // P_1^1 cos(p) |
| 198 |
+ y // P_1^1 sin(p) |
| 199 |
+ (3*z*z - r*r) // P_2^0 |
| 200 |
+ (x*x - y*y ) // P_2^2 cos(2p) |
| 201 |
+ x*y // P_2^2 sin(2p) |
| 202 |
+ x*(5*z*z-r*r) // P_3^1 cos(p) |
| 203 |
+ y*(5*z*z-r*r) // P_3^1 sin(p) |
| 204 |
+ x*(x*x-3*y*y) // P_3^3 cos(3p) |
| 205 |
+ y*(y*y-3*x*x) ; // P_3^3 sin(3p) |
| 206 |
|
| 207 |
pot.annule_domain(nzm1) ; |
| 208 |
|
| 209 |
Mtbl potced = // 1 / r // P_0^0 |
| 210 |
+ sint*cosp / pow(r,2) // P_1^1 cos(p) |
| 211 |
+ sint*sinp / pow(r,2) // P_1^1 sin(p) |
| 212 |
+ (3*cost*cost - 1) / pow(r,3) // P_2^0 |
| 213 |
+ sint*sint*cos(2*phi) / pow(r,3) // P_2^2 cos(2p) |
| 214 |
+ sint*sint*sin(2*phi) / pow(r,3) // P_2^2 sin(2p) |
| 215 |
+ sint*(15*cost*cost-3)*cosp / pow(r,4) // P_3^1 cos(p) |
| 216 |
+ sint*(15*cost*cost-3)*sinp / pow(r,4) // P_3^1 sin(p) |
| 217 |
+ pow(sint,3) * cos(3*phi) / pow(r,4) // P_3^3 cos(3p) |
| 218 |
+ pow(sint,3) * sin(3*phi) / pow(r,4) ; // P_3^3 sin(3p) |
| 219 |
|
| 220 |
pot.set_domain(nzm1) = potced(nzm1) ; |
| 221 |
pot.std_spectral_base() ; |
| 222 |
|
| 223 |
cout << "Potential : " << endl ; |
| 224 |
pot.spectral_display() ; |
| 225 |
arrete() ; |
| 226 |
|
| 227 |
cout << "Laplacian of potential : " << endl ; |
| 228 |
pot.laplacian().spectral_display() ; |
| 229 |
arrete() ; |
| 230 |
|
| 231 |
hhc.set(1,1) = pot.dsdx().dsdx() ; |
| 232 |
hhc.set(1,2) = pot.dsdx().dsdy() ; |
| 233 |
hhc.set(1,3) = pot.dsdx().dsdz() ; |
| 234 |
hhc.set(2,2) = pot.dsdy().dsdy() ; |
| 235 |
hhc.set(2,3) = pot.dsdy().dsdz() ; |
| 236 |
hhc.set(3,3) = pot.dsdz().dsdz() ; |
| 237 |
|
| 238 |
hhc.inc_dzpuis(1) ; |
| 239 |
|
| 240 |
cout << "Cartesian components : hhc : " << endl ; |
| 241 |
hhc.spectral_display() ; |
| 242 |
arrete() ; |
| 243 |
|
| 244 |
tmp = hhc ; |
| 245 |
tmp.change_triad( map.get_bvect_spher() ) ; |
| 246 |
hhs = tmp ; |
| 247 |
|
| 248 |
cout << "Spherical components : hhs : " << endl ; |
| 249 |
hhs.spectral_display() ; |
| 250 |
arrete() ; |
| 251 |
|
| 252 |
Sym_tensor hhs2 = pot.derive_con(mets).derive_con(mets) ; |
| 253 |
hhs2.inc_dzpuis(1) ; |
| 254 |
|
| 255 |
cout << "### Difference between hhs2 and hhs" << endl ; |
| 256 |
maxabs( hhs2 - hhs ) ; |
| 257 |
arrete() ; |
| 258 |
|
| 259 |
hhs = hhs2 ; |
| 260 |
|
| 261 |
Vector divc = hhc.divergence(metc) ; |
| 262 |
cout << "Divergence of hhc : " << endl ; |
| 263 |
divc.spectral_display() ; |
| 264 |
|
| 265 |
cout << "Maxabs divergence hhc : " << endl ; |
| 266 |
maxabs( divc ) ; |
| 267 |
|
| 268 |
arrete() ; |
| 269 |
|
| 270 |
Vector divs = hhs.divergence(mets) ; |
| 271 |
cout << "Divergence of hhs : " << endl ; |
| 272 |
divs.spectral_display() ; |
| 273 |
|
| 274 |
cout << "Maxabs divergence hhs : " << endl ; |
| 275 |
maxabs( divs ) ; |
| 276 |
|
| 277 |
cout << "Maxabs of trace of hhc : " << endl ; |
| 278 |
maxabs( hhc.the_trace() ) ; |
| 279 |
|
| 280 |
cout << "Maxabs of trace of hhs : " << endl ; |
| 281 |
maxabs( hhs.the_trace() ) ; |
| 282 |
|
| 283 |
arrete() ; |
| 284 |
|
| 285 |
Sym_tensor_tt htt(map, map.get_bvect_spher(), mets ) ; |
| 286 |
|
| 287 |
htt = hhs ; |
| 288 |
|
| 289 |
cout << "Eta : " << endl ; |
| 290 |
htt.eta().spectral_display() ; |
| 291 |
|
| 292 |
cout << "Mu : " << endl ; |
| 293 |
htt.mu().spectral_display() ; |
| 294 |
|
| 295 |
|
| 296 |
arrete() ; |
| 297 |
|
| 298 |
Sym_tensor_tt htt2(map, map.get_bvect_spher(), mets ) ; |
| 299 |
|
| 300 |
htt2.set_rr_eta_mu(htt(1,1), htt.eta(), htt.mu()) ; |
| 301 |
|
| 302 |
cout << "Relative difference (max) between htt2 and htt : " << endl ; |
| 303 |
diffrelmax(htt2, htt) ; |
| 304 |
|
| 305 |
cout << endl << "========================================================" << endl ; |
| 306 |
cout << " Test with an ad hoc mu" << endl ; |
| 307 |
cout << "========================================================" << endl ; |
| 308 |
|
| 309 |
arrete() ; |
| 310 |
|
| 311 |
Scalar mu0(map) ; |
| 312 |
mu0 = z * pot.get_spectral_va() ; |
| 313 |
|
| 314 |
mu0.annule_domain(nzm1) ; |
| 315 |
|
| 316 |
Mtbl mu0ced = cost * potced ; |
| 317 |
|
| 318 |
mu0.set_domain(nzm1) = mu0ced(nzm1) ; |
| 319 |
mu0.std_spectral_base() ; |
| 320 |
mu0.set_spectral_va().set_base_r(0, R_CHEBPIM_I) ; |
| 321 |
mu0.set_spectral_va().set_base_t(T_COSSIN_CI) ; |
| 322 |
mu0.set_dzpuis( htt.eta().get_dzpuis() ) ; |
| 323 |
|
| 324 |
|
| 325 |
cout << "mu0 : " << endl ; |
| 326 |
mu0.spectral_display() ; |
| 327 |
arrete() ; |
| 328 |
|
| 329 |
Sym_tensor_tt htt3 = htt ; |
| 330 |
|
| 331 |
htt3.set_rr_mu(htt(1,1), mu0) ; |
| 332 |
|
| 333 |
cout << "Eta htt3 : " << endl ; |
| 334 |
htt3.eta().spectral_display() ; |
| 335 |
|
| 336 |
cout << "Mu htt3 : " << endl ; |
| 337 |
htt3.mu().spectral_display() ; |
| 338 |
|
| 339 |
arrete() ; |
| 340 |
|
| 341 |
cout << "htt3 : " << endl ; |
| 342 |
htt3.spectral_display() ; |
| 343 |
arrete() ; |
| 344 |
|
| 345 |
Sym_tensor_tt htt4(map, map.get_bvect_spher(), mets ) ; |
| 346 |
|
| 347 |
htt4.set_rr_eta_mu(htt3(1,1), htt3.eta(), htt3.mu()) ; |
| 348 |
|
| 349 |
cout << "Relative difference (max) between htt4 and htt3 : " << endl ; |
| 350 |
diffrelmax(htt4, htt3) ; |
| 351 |
|
| 352 |
arrete() ; |
| 353 |
|
| 354 |
Sym_tensor_tt htt5 = htt3 ; |
| 355 |
htt5.set(1,1) = htt3(1,1) ; // To force the deletion of eta and mu |
| 356 |
|
| 357 |
cout << "Relative difference (max) between htt5.eta and htt3.eta : " << endl ; |
| 358 |
diffrelmax(htt5.eta(), htt3.eta()) ; |
| 359 |
cout << "Relative difference (max) between htt5.mu and htt3.mu : " << endl ; |
| 360 |
diffrelmax(htt5.mu(), htt3.mu()) ; |
| 361 |
|
| 362 |
// Test : TT decomposition of hht5 from scratch |
| 363 |
// -------------------------------------------- |
| 364 |
|
| 365 |
Sym_tensor aa = htt5 ; // initialization of a generic symmetric tensor |
| 366 |
|
| 367 |
const Sym_tensor_trans& taa = aa.transverse(mets) ; |
| 368 |
|
| 369 |
cout << "Longitudinal part of aa : \n " ; |
| 370 |
maxabs( aa.longit_pot(mets) ) ; |
| 371 |
|
| 372 |
Sym_tensor diff = aa - taa ; |
| 373 |
|
| 374 |
cout << "Difference between aa and its transverse part : \n " ; |
| 375 |
maxabs( diff ) ; |
| 376 |
|
| 377 |
const Sym_tensor_tt& ttaa = taa.tt_part() ; |
| 378 |
cout << "Trace of taa : \n" ; |
| 379 |
maxabs( taa.the_trace() ) ; |
| 380 |
|
| 381 |
diff = aa - ttaa ; |
| 382 |
cout << "Difference between aa and its TT part : \n " ; |
| 383 |
maxabs( diff ) ; |
| 384 |
|
| 385 |
|
| 386 |
return EXIT_SUCCESS ; |
| 387 |
} |