| 1 |
/* |
| 2 |
* Test of Metric and Connection classes through the Schwarzschild metric |
| 3 |
* |
| 4 |
*/ |
| 5 |
|
| 6 |
/* |
| 7 |
* Copyright (c) 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_schwarzschild_C[] = "$Header: /cvsroot/Lorene/Codes/Test/Metric/test_schwarzschild.C,v 1.4 2014/10/13 08:54:01 j_novak Exp $" ; |
| 27 |
|
| 28 |
/* |
| 29 |
* $Id: test_schwarzschild.C,v 1.4 2014/10/13 08:54:01 j_novak Exp $ |
| 30 |
* $Log: test_schwarzschild.C,v $ |
| 31 |
* Revision 1.4 2014/10/13 08:54:01 j_novak |
| 32 |
* Lorene classes and functions now belong to the namespace Lorene. |
| 33 |
* |
| 34 |
* Revision 1.3 2014/10/06 15:12:53 j_novak |
| 35 |
* Modified #include directives to use c++ syntax. |
| 36 |
* |
| 37 |
* Revision 1.2 2004/01/28 15:27:59 e_gourgoulhon |
| 38 |
* Minor modifs. |
| 39 |
* |
| 40 |
* Revision 1.1 2004/01/27 14:46:22 e_gourgoulhon |
| 41 |
* First version of test_schwarzschild. |
| 42 |
* |
| 43 |
* |
| 44 |
* $Header: /cvsroot/Lorene/Codes/Test/Metric/test_schwarzschild.C,v 1.4 2014/10/13 08:54:01 j_novak Exp $ |
| 45 |
* |
| 46 |
*/ |
| 47 |
|
| 48 |
// C++ headers |
| 49 |
#include "headcpp.h" |
| 50 |
|
| 51 |
// C headers |
| 52 |
#include <cstdlib> |
| 53 |
#include <cmath> |
| 54 |
|
| 55 |
// Lorene headers |
| 56 |
#include "metric.h" |
| 57 |
#include "nbr_spx.h" |
| 58 |
#include "graphique.h" |
| 59 |
#include "utilitaires.h" |
| 60 |
#include "proto.h" |
| 61 |
|
| 62 |
using namespace Lorene ; |
| 63 |
|
| 64 |
int main() { |
| 65 |
|
| 66 |
// Setup of a multi-domain grid (Lorene class Mg3d) |
| 67 |
// ------------------------------------------------ |
| 68 |
|
| 69 |
int nz = 3 ; // Number of domains |
| 70 |
int nr = 17 ; // Number of collocation points in r in each domain |
| 71 |
int nt = 5 ; // Number of collocation points in theta in each domain |
| 72 |
int np = 4 ; // Number of collocation points in phi in each domain |
| 73 |
int symmetry_theta = SYM ; // symmetry with respect to the equatorial plane |
| 74 |
int symmetry_phi = NONSYM ; // no symmetry in phi |
| 75 |
bool compact = true ; // external domain is compactified |
| 76 |
|
| 77 |
// Multi-domain grid construction: |
| 78 |
Mg3d mgrid(nz, nr, nt, np, symmetry_theta, symmetry_phi, compact) ; |
| 79 |
|
| 80 |
cout << mgrid << endl ; |
| 81 |
|
| 82 |
|
| 83 |
// Setup of an affine mapping : grid --> physical space (Lorene class Map_af) |
| 84 |
// -------------------------------------------------------------------------- |
| 85 |
|
| 86 |
// radial boundaries of each domain: |
| 87 |
double r_limits[] = {0., 2., 3., __infinity} ; |
| 88 |
assert( nz == 3 ) ; // since the above array describes only 3 domains |
| 89 |
|
| 90 |
Map_af map(mgrid, r_limits) ; // Mapping construction |
| 91 |
|
| 92 |
cout << map << endl ; |
| 93 |
|
| 94 |
// Denomination of various coordinates associated with the mapping |
| 95 |
// --------------------------------------------------------------- |
| 96 |
|
| 97 |
const Coord& r = map.r ; // r field |
| 98 |
|
| 99 |
// Schwarzschild metric in isotropic coordinates |
| 100 |
// ---------------------------------------------- |
| 101 |
|
| 102 |
// Total mass = twice the radius at the horizon |
| 103 |
double mm = 2. * map.val_r(0, 1., 0., 0.) ; |
| 104 |
|
| 105 |
// Conformal factor |
| 106 |
Scalar psi4(map) ; |
| 107 |
psi4 = pow( 1 + mm / (2*r), 4) ; |
| 108 |
psi4.set_domain(0) = 1 ; |
| 109 |
psi4.std_spectral_base() ; |
| 110 |
|
| 111 |
|
| 112 |
// Spatial metric |
| 113 |
|
| 114 |
const Metric_flat& fmet = map.flat_met_spher() ; |
| 115 |
|
| 116 |
Sym_tensor gij_spher = psi4 * fmet.cov() ; |
| 117 |
|
| 118 |
Metric gam(gij_spher) ; // construction from the covariant components |
| 119 |
|
| 120 |
cout << gam << endl ; |
| 121 |
arrete() ; |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
// Test: covariant derivative of the metric / flat metric: |
| 126 |
|
| 127 |
const Tensor& dg_cov = gam.cov().derive_cov( fmet ) ; |
| 128 |
|
| 129 |
Vector dpsi4 = psi4.derive_cov( fmet ) ; |
| 130 |
Tensor_sym d_gij_schw = fmet.cov() * dpsi4 ; |
| 131 |
|
| 132 |
Tensor diff_dg = dg_cov - d_gij_schw ; |
| 133 |
cout << "Error on the covariant derivative of the metric / flat metric:" << endl ; |
| 134 |
// diff_dg.spectral_display() ; |
| 135 |
maxabs(diff_dg) ; |
| 136 |
arrete() ; |
| 137 |
|
| 138 |
// Test: Connection symbols Delta |
| 139 |
// ------------------------------ |
| 140 |
const Tensor_sym& delta = gam.connect().get_delta() ; |
| 141 |
cout << "Connection (delta) : " << endl ; |
| 142 |
delta.spectral_display() ; |
| 143 |
maxabs(delta) ; |
| 144 |
|
| 145 |
Scalar diff = delta(1,1,1) - 0.5 * dpsi4(1) / psi4 ; |
| 146 |
cout << "Error on Delta^r_rr: \n " ; maxabs(diff) ; |
| 147 |
|
| 148 |
diff = delta(1,2,1) - 0 ; |
| 149 |
cout << "Error on Delta^r_rt: \n " ; maxabs(diff) ; |
| 150 |
diff = delta(1,3,1) - 0 ; |
| 151 |
cout << "Error on Delta^r_rp: \n " ; maxabs(diff) ; |
| 152 |
|
| 153 |
diff = delta(1,2,2) + 0.5 * dpsi4(1) / psi4 ; |
| 154 |
cout << "Error on Delta^r_tt: \n " ; maxabs(diff) ; |
| 155 |
|
| 156 |
diff = delta(1,3,2) - 0 ; |
| 157 |
cout << "Error on Delta^r_tp: \n " ; maxabs(diff) ; |
| 158 |
|
| 159 |
diff = delta(2,1,1) - 0 ; |
| 160 |
cout << "Error on Delta^t_rr: \n " ; maxabs(diff) ; |
| 161 |
|
| 162 |
diff = delta(2,2,1) - 0.5 * dpsi4(1) / psi4 ; |
| 163 |
cout << "Error on Delta^t_rt: \n " ; maxabs(diff) ; |
| 164 |
|
| 165 |
diff = delta(2,3,1) - 0 ; |
| 166 |
cout << "Error on Delta^t_rp: \n " ; maxabs(diff) ; |
| 167 |
|
| 168 |
diff = delta(2,2,2) - 0 ; |
| 169 |
cout << "Error on Delta^t_tt: \n " ; maxabs(diff) ; |
| 170 |
|
| 171 |
diff = delta(2,3,2) - 0 ; |
| 172 |
cout << "Error on Delta^t_tp: \n " ; maxabs(diff) ; |
| 173 |
|
| 174 |
diff = delta(2,3,3) - 0 ; |
| 175 |
cout << "Error on Delta^t_pp: \n " ; maxabs(diff) ; |
| 176 |
|
| 177 |
diff = delta(3,1,1) - 0 ; |
| 178 |
cout << "Error on Delta^p_rr: \n " ; maxabs(diff) ; |
| 179 |
|
| 180 |
diff = delta(3,2,1) - 0 ; |
| 181 |
cout << "Error on Delta^p_rt: \n " ; maxabs(diff) ; |
| 182 |
|
| 183 |
diff = delta(3,3,1) - 0.5 * dpsi4(1) / psi4 ; |
| 184 |
cout << "Error on Delta^p_rp: \n " ; maxabs(diff) ; |
| 185 |
|
| 186 |
arrete() ; |
| 187 |
|
| 188 |
// Test: covariant derivative of the metric / itself: |
| 189 |
// -------------------------------------------------- |
| 190 |
|
| 191 |
const Tensor& dg_auto = gam.cov().derive_cov( gam ) ; |
| 192 |
|
| 193 |
cout << "Error on the covariant derivative of the metric / itself:" << endl ; |
| 194 |
maxabs(dg_auto) ; |
| 195 |
arrete() ; |
| 196 |
|
| 197 |
// Lapse function |
| 198 |
// -------------- |
| 199 |
|
| 200 |
Scalar nn(map) ; |
| 201 |
|
| 202 |
nn = (1 - mm / (2*r) ) / (1 + mm / (2*r) ) ; |
| 203 |
|
| 204 |
nn.set_domain(0) = 1 ; |
| 205 |
|
| 206 |
nn.std_spectral_base() ; |
| 207 |
|
| 208 |
cout << "Lapse N : " << nn << endl ; |
| 209 |
arrete() ; |
| 210 |
|
| 211 |
// Hamiltonian constraint |
| 212 |
// ---------------------- |
| 213 |
|
| 214 |
const Tensor& ricci = gam.ricci() ; |
| 215 |
|
| 216 |
const Scalar& ricci_scal = gam.ricci_scal() ; |
| 217 |
|
| 218 |
cout << "Hamiltonian constraint (Ricci scalar) : " << endl ; |
| 219 |
ricci_scal.spectral_display() ; |
| 220 |
maxabs(ricci_scal) ; |
| 221 |
arrete() ; |
| 222 |
|
| 223 |
// Dynamical Einstein equations |
| 224 |
//----------------------------- |
| 225 |
|
| 226 |
Sym_tensor dyn1 = - (nn.derive_cov(gam)).derive_cov(gam) ; |
| 227 |
|
| 228 |
Sym_tensor dyn2 = nn * ricci ; |
| 229 |
|
| 230 |
Sym_tensor dyn_einstein = dyn1 + dyn2 ; |
| 231 |
|
| 232 |
cout << "Dynamical Einstein equations:" << endl ; |
| 233 |
dyn_einstein.spectral_display() ; |
| 234 |
maxabs(dyn_einstein) ; |
| 235 |
|
| 236 |
cout << "maxabs(dyn1) : " << endl ; |
| 237 |
maxabs(dyn1) ; |
| 238 |
cout << "maxabs(dyn2) : " << endl ; |
| 239 |
maxabs(dyn2) ; |
| 240 |
|
| 241 |
cout << "Relative error:" << endl ; |
| 242 |
diffrel(dyn2, -dyn1) ; |
| 243 |
|
| 244 |
return EXIT_SUCCESS ; |
| 245 |
|
| 246 |
} |