| 1 |
/* |
| 2 |
* Code for testing the tensorial Poisson equation. |
| 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_tens_poisson_C[] = "$Header: /cvsroot/Lorene/Codes/Test/Tensor/test_tens_poisson.C,v 1.6 2014/10/13 08:54:03 j_novak Exp $" ; |
| 27 |
|
| 28 |
/* |
| 29 |
* $Id: test_tens_poisson.C,v 1.6 2014/10/13 08:54:03 j_novak Exp $ |
| 30 |
* $Log: test_tens_poisson.C,v $ |
| 31 |
* Revision 1.6 2014/10/13 08:54:03 j_novak |
| 32 |
* Lorene classes and functions now belong to the namespace Lorene. |
| 33 |
* |
| 34 |
* Revision 1.5 2014/10/06 15:12:56 j_novak |
| 35 |
* Modified #include directives to use c++ syntax. |
| 36 |
* |
| 37 |
* Revision 1.4 2004/02/18 18:58:36 e_gourgoulhon |
| 38 |
* Method trace() renamed the_trace(). |
| 39 |
* Tensor::trace used instead of Tensor::scontract. |
| 40 |
* |
| 41 |
* Revision 1.3 2004/02/16 12:48:51 e_gourgoulhon |
| 42 |
* Methods Scalar::dsdx(),... do no longer have any argument. |
| 43 |
* |
| 44 |
* Revision 1.2 2004/01/04 21:02:31 e_gourgoulhon |
| 45 |
* Class Tensor_delta replaced by class Tensor_sym. |
| 46 |
* |
| 47 |
* Revision 1.1 2003/11/07 17:18:24 e_gourgoulhon |
| 48 |
* First version of test_tens_poisson |
| 49 |
* |
| 50 |
* |
| 51 |
* $Header: /cvsroot/Lorene/Codes/Test/Tensor/test_tens_poisson.C,v 1.6 2014/10/13 08:54:03 j_novak Exp $ |
| 52 |
* |
| 53 |
*/ |
| 54 |
|
| 55 |
// C++ headers |
| 56 |
#include "headcpp.h" |
| 57 |
|
| 58 |
// C headers |
| 59 |
#include <cstdlib> |
| 60 |
|
| 61 |
// Lorene headers |
| 62 |
#include "metric.h" |
| 63 |
#include "nbr_spx.h" |
| 64 |
#include "utilitaires.h" |
| 65 |
|
| 66 |
|
| 67 |
using namespace Lorene ; |
| 68 |
|
| 69 |
int main() { |
| 70 |
|
| 71 |
// Construction of a multi-grid (Mg3d) |
| 72 |
// ----------------------------------- |
| 73 |
|
| 74 |
int nz = 3 ; // Number of domains |
| 75 |
int nzm1 = nz - 1 ; |
| 76 |
int nr = 9 ; // Number of collocation points in r in each domain |
| 77 |
int nt = 7 ; // Number of collocation points in theta in each domain |
| 78 |
int np = 16 ; // Number of collocation points in phi in each domain |
| 79 |
int symmetry_theta = SYM ; // symmetry with respect to the equatorial plane |
| 80 |
int symmetry_phi = NONSYM ; // no symmetry in phi |
| 81 |
bool compact = true ; // external domain is compactified |
| 82 |
|
| 83 |
Mg3d mgrid(nz, nr, nt, np, symmetry_theta, symmetry_phi, compact) ; |
| 84 |
|
| 85 |
|
| 86 |
// Construction of an affine mapping (Map_af) |
| 87 |
// ------------------------------------------ |
| 88 |
|
| 89 |
// Boundaries of each domains |
| 90 |
double r_limits[] = {0., 2., 3., __infinity} ; |
| 91 |
assert( nz == 3 ) ; // since the above array described only 3 domains |
| 92 |
|
| 93 |
Map_af map(mgrid, r_limits) ; |
| 94 |
|
| 95 |
|
| 96 |
// Construction of a flat metric |
| 97 |
// ----------------------------- |
| 98 |
|
| 99 |
Metric_flat mets(map, map.get_bvect_spher()) ; // spherical representation |
| 100 |
Metric_flat metc(map, map.get_bvect_cart()) ; // Cartesian representation |
| 101 |
|
| 102 |
|
| 103 |
// Construction of a divergence free tensor field |
| 104 |
// ---------------------------------------------- |
| 105 |
|
| 106 |
const Coord& x = map.x ; |
| 107 |
const Coord& y = map.y ; |
| 108 |
const Coord& z = map.z ; |
| 109 |
const Coord& r = map.r ; |
| 110 |
const Coord& cost = map.cost ; |
| 111 |
const Coord& sint = map.sint ; |
| 112 |
const Coord& cosp = map.cosp ; |
| 113 |
const Coord& sinp = map.sinp ; |
| 114 |
const Coord& phi = map.phi ; |
| 115 |
|
| 116 |
|
| 117 |
cout << "========================================================" << endl ; |
| 118 |
cout << " Test with the tensor" << endl ; |
| 119 |
cout << " Cart. comp. h^{ij} = d_i d_j Phi with Lap(Phi) = 0 " << endl ; |
| 120 |
cout << "========================================================" << endl ; |
| 121 |
|
| 122 |
Scalar pot(map) ; |
| 123 |
pot = 1 // P_0^0 |
| 124 |
+ x // P_1^1 cos(p) |
| 125 |
+ y // P_1^1 sin(p) |
| 126 |
+ (3*z*z - r*r) ; // P_2^0 |
| 127 |
/* + (x*x - y*y ) // P_2^2 cos(2p) |
| 128 |
+ x*y // P_2^2 sin(2p) |
| 129 |
+ x*(5*z*z-r*r) // P_3^1 cos(p) |
| 130 |
+ y*(5*z*z-r*r) // P_3^1 sin(p) |
| 131 |
+ x*(x*x-3*y*y) // P_3^3 cos(3p) |
| 132 |
+ y*(y*y-3*x*x) ; // P_3^3 sin(3p) |
| 133 |
*/ |
| 134 |
pot.annule_domain(nzm1) ; |
| 135 |
|
| 136 |
Mtbl potced = |
| 137 |
(3*cost*cost - 1) / pow(r,3) // P_2^0 |
| 138 |
+ sint*sint*cos(2*phi) / pow(r,3) // P_2^2 cos(2p) |
| 139 |
+ sint*sint*sin(2*phi) / pow(r,3) // P_2^2 sin(2p) |
| 140 |
+ sint*(15*cost*cost-3)*cosp / pow(r,4) // P_3^1 cos(p) |
| 141 |
+ sint*(15*cost*cost-3)*sinp / pow(r,4) // P_3^1 sin(p) |
| 142 |
+ pow(sint,3) * cos(3*phi) / pow(r,4) // P_3^3 cos(3p) |
| 143 |
+ pow(sint,3) * sin(3*phi) / pow(r,4) ; // P_3^3 sin(3p) |
| 144 |
|
| 145 |
//## |
| 146 |
// pot.set_domain(nzm1) = potced(nzm1) ; |
| 147 |
|
| 148 |
pot.std_spectral_base() ; |
| 149 |
|
| 150 |
cout << "Potential : " << endl ; |
| 151 |
pot.spectral_display() ; |
| 152 |
arrete() ; |
| 153 |
|
| 154 |
cout << "Laplacian of potential : " << endl ; |
| 155 |
pot.laplacian().spectral_display() ; |
| 156 |
arrete() ; |
| 157 |
|
| 158 |
Sym_tensor_tt souc(map, map.get_bvect_cart(), metc ) ; |
| 159 |
|
| 160 |
souc.set(1,1) = pot.dsdx().dsdx() ; |
| 161 |
souc.set(1,2) = pot.dsdx().dsdy() ; |
| 162 |
souc.set(1,3) = pot.dsdx().dsdz() ; |
| 163 |
souc.set(2,2) = pot.dsdy().dsdy() ; |
| 164 |
souc.set(2,3) = pot.dsdy().dsdz() ; |
| 165 |
souc.set(3,3) = pot.dsdz().dsdz() ; |
| 166 |
|
| 167 |
cout << "Cartesian components of the source : souc : " << endl ; |
| 168 |
souc.spectral_display() ; |
| 169 |
|
| 170 |
// cout << "Maxabs divergence souc : " << endl ; |
| 171 |
// maxabs( souc.divergence(metc) ) ; |
| 172 |
|
| 173 |
cout << "Maxabs of trace of souc : " << endl ; |
| 174 |
maxabs( souc.the_trace() ) ; |
| 175 |
|
| 176 |
arrete() ; |
| 177 |
|
| 178 |
Tensor tmp = souc ; |
| 179 |
tmp.change_triad( map.get_bvect_spher() ) ; |
| 180 |
Sym_tensor_tt sous(map, map.get_bvect_spher(), mets ) ; |
| 181 |
sous = tmp ; |
| 182 |
|
| 183 |
sous.inc_dzpuis(2) ; |
| 184 |
|
| 185 |
cout << "Spherical components of the source : sous : " << endl ; |
| 186 |
sous.spectral_display() ; |
| 187 |
|
| 188 |
// cout << "Maxabs divergence sous : " << endl ; |
| 189 |
// maxabs( sous.divergence(mets) ) ; |
| 190 |
|
| 191 |
cout << "Maxabs of trace of sous : " << endl ; |
| 192 |
maxabs( sous.the_trace() ) ; |
| 193 |
|
| 194 |
arrete() ; |
| 195 |
|
| 196 |
// Resolution of Poisson equation |
| 197 |
// ------------------------------ |
| 198 |
|
| 199 |
Sym_tensor_tt htts = sous.poisson() ; |
| 200 |
|
| 201 |
cout << "Solution htts (spherical components) : " << endl ; |
| 202 |
htts.spectral_display() ; |
| 203 |
|
| 204 |
cout << "Maxabs divergence htts : " << endl ; |
| 205 |
maxabs( htts.divergence(mets) ) ; |
| 206 |
|
| 207 |
cout << "Maxabs of trace of htts : " << endl ; |
| 208 |
maxabs( htts.the_trace() ) ; |
| 209 |
|
| 210 |
arrete() ; |
| 211 |
|
| 212 |
// Laplacian of the solution |
| 213 |
// ------------------------- |
| 214 |
|
| 215 |
Tensor_sym dhtts0(map, CON, CON, COV, map.get_bvect_spher(), 0, 1) ; |
| 216 |
dhtts0 = htts.derive_cov(mets) ; |
| 217 |
|
| 218 |
Tensor dhtts = dhtts0.up(2, mets) ; |
| 219 |
dhtts.dec_dzpuis(2) ; |
| 220 |
Tensor ddhtts = dhtts.derive_cov(mets) ; |
| 221 |
Sym_tensor lap_htts( ddhtts.trace(2,3) ) ; |
| 222 |
|
| 223 |
tmp = htts ; |
| 224 |
tmp.change_triad( map.get_bvect_cart() ) ; |
| 225 |
Sym_tensor_tt httc(map, map.get_bvect_cart(), metc ) ; |
| 226 |
httc = tmp ; |
| 227 |
|
| 228 |
cout << "Solution httc (Cartesian components) : " << endl ; |
| 229 |
httc.spectral_display() ; |
| 230 |
|
| 231 |
cout << "Maxabs divergence httc : " << endl ; |
| 232 |
maxabs( httc.divergence(metc) ) ; |
| 233 |
|
| 234 |
cout << "Maxabs of trace of httc : " << endl ; |
| 235 |
maxabs( httc.the_trace() ) ; |
| 236 |
|
| 237 |
arrete() ; |
| 238 |
|
| 239 |
Sym_tensor_tt lapc(map, map.get_bvect_cart(), metc ) ; |
| 240 |
|
| 241 |
lapc.set(1,1) = httc(1,1).laplacian(2) ; |
| 242 |
lapc.set(1,2) = httc(1,2).laplacian(2) ; |
| 243 |
lapc.set(1,3) = httc(1,3).laplacian(2) ; |
| 244 |
lapc.set(2,2) = httc(2,2).laplacian(2) ; |
| 245 |
lapc.set(2,3) = httc(2,3).laplacian(2) ; |
| 246 |
lapc.set(3,3) = httc(3,3).laplacian(2) ; |
| 247 |
|
| 248 |
Sym_tensor diffc = lapc - souc ; |
| 249 |
|
| 250 |
cout << "Maxabs of diffc : " << endl ; |
| 251 |
maxabs( diffc ) ; |
| 252 |
|
| 253 |
|
| 254 |
tmp = lapc ; |
| 255 |
tmp.change_triad( map.get_bvect_spher() ) ; |
| 256 |
Sym_tensor_tt laps(map, map.get_bvect_spher(), mets ) ; |
| 257 |
laps = tmp ; |
| 258 |
|
| 259 |
Sym_tensor diffs = laps - sous ; |
| 260 |
cout << "diffs : " << endl ; |
| 261 |
diffs.spectral_display() ; |
| 262 |
cout << "Maxabs of diffs : " << endl ; |
| 263 |
maxabs( diffs ) ; |
| 264 |
|
| 265 |
arrete() ; |
| 266 |
|
| 267 |
Sym_tensor difflap = lap_htts - laps ; |
| 268 |
cout << "difflap : " << endl ; |
| 269 |
difflap.spectral_display() ; |
| 270 |
cout << "Maxabs of difflap : " << endl ; |
| 271 |
maxabs( difflap ) ; |
| 272 |
|
| 273 |
|
| 274 |
return EXIT_SUCCESS ; |
| 275 |
} |