| 1 |
/* |
| 2 |
* Test of arithmetic Scalar & Mtbl and Scalar & Coord |
| 3 |
* |
| 4 |
*/ |
| 5 |
|
| 6 |
/* |
| 7 |
* Copyright (c) 2005 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 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 |
/* |
| 27 |
* $Id: test_scalar_mtbl.C,v 1.4 2014/10/13 08:54:03 j_novak Exp $ |
| 28 |
* $Log: test_scalar_mtbl.C,v $ |
| 29 |
* Revision 1.4 2014/10/13 08:54:03 j_novak |
| 30 |
* Lorene classes and functions now belong to the namespace Lorene. |
| 31 |
* |
| 32 |
* Revision 1.3 2014/10/06 15:12:56 j_novak |
| 33 |
* Modified #include directives to use c++ syntax. |
| 34 |
* |
| 35 |
* Revision 1.2 2005/11/17 16:32:35 e_gourgoulhon |
| 36 |
* Added test of ETATZERO and ETATUN cases. |
| 37 |
* |
| 38 |
* Revision 1.1 2005/11/17 15:31:53 e_gourgoulhon |
| 39 |
* Code for testing Scalar / Mtbl (or Coord) new arithmetics. |
| 40 |
* |
| 41 |
* |
| 42 |
* $Header: /cvsroot/Lorene/Codes/Test/Tensor/test_scalar_mtbl.C,v 1.4 2014/10/13 08:54:03 j_novak Exp $ |
| 43 |
* |
| 44 |
*/ |
| 45 |
|
| 46 |
// C headers |
| 47 |
#include <cstdlib> |
| 48 |
#include <cassert> |
| 49 |
#include <cmath> |
| 50 |
|
| 51 |
// Lorene headers |
| 52 |
#include "headcpp.h" // standard input/output C++ headers (iostream, fstream) |
| 53 |
#include "tensor.h" // classes Tensor, etc... |
| 54 |
#include "nbr_spx.h" // defines infinity as an ordinary number: __infinity |
| 55 |
#include "graphique.h" // for graphical outputs |
| 56 |
#include "utilitaires.h" // utilities |
| 57 |
|
| 58 |
using namespace Lorene ; |
| 59 |
|
| 60 |
int main() { |
| 61 |
|
| 62 |
// Setup of a multi-domain grid (Lorene class Mg3d) |
| 63 |
// ------------------------------------------------ |
| 64 |
|
| 65 |
int nz = 3 ; // Number of domains |
| 66 |
int nr = 17 ; // Number of collocation points in r in each domain |
| 67 |
int nt = 9 ; // Number of collocation points in theta in each domain |
| 68 |
int np = 8 ; // Number of collocation points in phi in each domain |
| 69 |
int symmetry_theta = SYM ; // symmetry with respect to the equatorial plane |
| 70 |
int symmetry_phi = NONSYM ; // no symmetry in phi |
| 71 |
bool compact = true ; // external domain is compactified |
| 72 |
|
| 73 |
// Multi-domain grid construction: |
| 74 |
|
| 75 |
Mg3d mgrid(nz, nr, nt, np, symmetry_theta, symmetry_phi, compact) ; |
| 76 |
|
| 77 |
cout << mgrid << endl ; |
| 78 |
|
| 79 |
|
| 80 |
// Setup of an affine mapping : grid --> physical space (Lorene class Map_af) |
| 81 |
// -------------------------------------------------------------------------- |
| 82 |
|
| 83 |
// radial boundaries of each domain: |
| 84 |
double r_limits[] = {0., 1., 2., __infinity} ; |
| 85 |
assert( nz == 3 ) ; // since the above array describes only 3 domains |
| 86 |
|
| 87 |
Map_af map(mgrid, r_limits) ; // Mapping construction |
| 88 |
|
| 89 |
cout << map << endl ; |
| 90 |
|
| 91 |
// Denomination of various coordinates associated with the mapping |
| 92 |
// --------------------------------------------------------------- |
| 93 |
|
| 94 |
const Coord& r = map.r ; |
| 95 |
const Coord& x = map.x ; |
| 96 |
const Coord& y = map.y ; |
| 97 |
const Coord& z = map.z ; |
| 98 |
|
| 99 |
// Some scalar field to be used as a conformal factor |
| 100 |
// -------------------------------------------------- |
| 101 |
|
| 102 |
Scalar aa(map) ; |
| 103 |
|
| 104 |
aa = 1 + y*y ; |
| 105 |
|
| 106 |
aa.std_spectral_base() ; // Standar polynomial bases will be used |
| 107 |
// to perform the spectral expansions |
| 108 |
|
| 109 |
cout << endl << "aa : " << endl ; |
| 110 |
aa.spectral_display() ; |
| 111 |
|
| 112 |
Scalar bb = aa * x ; |
| 113 |
|
| 114 |
bb.std_spectral_base() ; |
| 115 |
//cout << endl << "bb : " << endl ; |
| 116 |
//bb.spectral_display() ; |
| 117 |
|
| 118 |
Scalar bb0(map) ; |
| 119 |
|
| 120 |
bb0 = (1+y*y) * x ; |
| 121 |
cout << "test Scalar * Coord : " << max(abs(bb-bb0)) << endl ; |
| 122 |
|
| 123 |
bb = x * aa ; |
| 124 |
bb0 = x * (1+y*y) ; |
| 125 |
cout << "test Coord * Scalar : " << max(abs(bb-bb0)) << endl ; |
| 126 |
|
| 127 |
bb = aa / (1+x*x) ; |
| 128 |
bb0 = (1+y*y) / (1+x*x) ; |
| 129 |
cout << "test Scalar / Mtbl : " << max(abs(bb-bb0)) << endl ; |
| 130 |
|
| 131 |
bb = x / aa ; |
| 132 |
bb0 = x / (1+y*y) ; |
| 133 |
cout << "test Coord / Scalar : " << max(abs(bb-bb0)) << endl ; |
| 134 |
|
| 135 |
bb = x + aa ; |
| 136 |
bb0 = x + (1+y*y) ; |
| 137 |
cout << "test Coord + Scalar : " << max(abs(bb-bb0)) << endl ; |
| 138 |
|
| 139 |
bb = aa + x ; |
| 140 |
bb0 = x + (1+y*y) ; |
| 141 |
cout << "test Scalar + Coord : " << max(abs(bb-bb0)) << endl ; |
| 142 |
|
| 143 |
bb = x - aa ; |
| 144 |
bb0 = x - (1+y*y) ; |
| 145 |
cout << "test Coord - Scalar : " << max(abs(bb-bb0)) << endl ; |
| 146 |
|
| 147 |
bb = aa - x ; |
| 148 |
bb0 = (1+y*y) - x ; |
| 149 |
cout << "test Scalar - Coord : " << max(abs(bb-bb0)) << endl ; |
| 150 |
|
| 151 |
|
| 152 |
arrete() ; |
| 153 |
|
| 154 |
// Special case ETATUN |
| 155 |
|
| 156 |
cout << endl << "Special case ETATUN : " << endl ; |
| 157 |
aa.set_etat_one() ; |
| 158 |
bb = aa * x ; |
| 159 |
bb0 = x ; |
| 160 |
cout << "test Scalar(1) * Coord : " << max(abs(bb-bb0)) << endl ; |
| 161 |
|
| 162 |
bb = x * aa ; |
| 163 |
bb0 = x ; |
| 164 |
cout << "test Coord * Scalar(1) : " << max(abs(bb-bb0)) << endl ; |
| 165 |
|
| 166 |
bb = aa / (1+x*x) ; |
| 167 |
bb0 = 1 / (1+x*x) ; |
| 168 |
cout << "test Scalar(1) / Mtbl : " << max(abs(bb-bb0)) << endl ; |
| 169 |
|
| 170 |
bb = x / aa ; |
| 171 |
bb0 = x ; |
| 172 |
cout << "test Coord / Scalar(1) : " << max(abs(bb-bb0)) << endl ; |
| 173 |
|
| 174 |
bb = x + aa ; |
| 175 |
bb0 = x + 1 ; |
| 176 |
cout << "test Coord + Scalar(1) : " << max(abs(bb-bb0)) << endl ; |
| 177 |
|
| 178 |
bb = aa + x ; |
| 179 |
bb0 = x + 1 ; |
| 180 |
cout << "test Scalar(1) + Coord : " << max(abs(bb-bb0)) << endl ; |
| 181 |
|
| 182 |
bb = x - aa ; |
| 183 |
bb0 = x - 1 ; |
| 184 |
cout << "test Coord - Scalar(1) : " << max(abs(bb-bb0)) << endl ; |
| 185 |
|
| 186 |
bb = aa - x ; |
| 187 |
bb0 = 1 - x ; |
| 188 |
cout << "test Scalar(1) - Coord : " << max(abs(bb-bb0)) << endl ; |
| 189 |
|
| 190 |
|
| 191 |
// Special case ETATZERO |
| 192 |
|
| 193 |
cout << endl << "Special case ETATZERO : " << endl ; |
| 194 |
aa.set_etat_zero() ; |
| 195 |
bb = aa * x ; |
| 196 |
bb0 = 0 ; |
| 197 |
cout << "test Scalar(0) * Coord : " << max(abs(bb-bb0)) << endl ; |
| 198 |
|
| 199 |
bb = x * aa ; |
| 200 |
bb0 = 0 ; |
| 201 |
cout << "test Coord * Scalar(0) : " << max(abs(bb-bb0)) << endl ; |
| 202 |
|
| 203 |
bb = aa / (1+x*x) ; |
| 204 |
bb0 = 0 ; |
| 205 |
cout << "test Scalar(0) / Mtbl : " << max(abs(bb-bb0)) << endl ; |
| 206 |
|
| 207 |
bb = x + aa ; |
| 208 |
bb0 = x ; |
| 209 |
cout << "test Coord + Scalar(0) : " << max(abs(bb-bb0)) << endl ; |
| 210 |
|
| 211 |
bb = aa + x ; |
| 212 |
bb0 = x ; |
| 213 |
cout << "test Scalar(0) + Coord : " << max(abs(bb-bb0)) << endl ; |
| 214 |
|
| 215 |
bb = x - aa ; |
| 216 |
bb0 = x ; |
| 217 |
cout << "test Coord - Scalar(0) : " << max(abs(bb-bb0)) << endl ; |
| 218 |
|
| 219 |
bb = aa - x ; |
| 220 |
bb0 = - x ; |
| 221 |
cout << "test Scalar(0) - Coord : " << max(abs(bb-bb0)) << endl ; |
| 222 |
|
| 223 |
arrete() ; |
| 224 |
|
| 225 |
Mtbl mc(mgrid) ; |
| 226 |
mc.set_etat_zero() ; |
| 227 |
|
| 228 |
aa = 1 + y*y ; |
| 229 |
|
| 230 |
bb = aa * mc ; |
| 231 |
bb0 = 0 ; |
| 232 |
cout << "test Scalar * Mtbl(0) : " << max(abs(bb-bb0)) << endl ; |
| 233 |
|
| 234 |
bb = mc * aa ; |
| 235 |
bb0 = 0 ; |
| 236 |
cout << "test Mtbl(0) * Scalar : " << max(abs(bb-bb0)) << endl ; |
| 237 |
|
| 238 |
bb = mc / aa ; |
| 239 |
bb0 = 0 ; |
| 240 |
cout << "test Mtbl(0) / Scalar : " << max(abs(bb-bb0)) << endl ; |
| 241 |
|
| 242 |
bb = mc + aa ; |
| 243 |
bb0 = (1+y*y) ; |
| 244 |
cout << "test Mtbl(0) + Scalar : " << max(abs(bb-bb0)) << endl ; |
| 245 |
|
| 246 |
bb = aa + mc ; |
| 247 |
bb0 = (1+y*y) ; |
| 248 |
cout << "test Scalar + Mtbl(0) : " << max(abs(bb-bb0)) << endl ; |
| 249 |
|
| 250 |
bb = mc - aa ; |
| 251 |
bb0 = - (1+y*y) ; |
| 252 |
cout << "test Mtbl(0) - Scalar : " << max(abs(bb-bb0)) << endl ; |
| 253 |
|
| 254 |
bb = aa - mc ; |
| 255 |
bb0 = (1+y*y) ; |
| 256 |
cout << "test Scalar - Mtbl(0) : " << max(abs(bb-bb0)) << endl ; |
| 257 |
|
| 258 |
arrete() ; |
| 259 |
|
| 260 |
// Special case ETATUN |
| 261 |
|
| 262 |
cout << endl << "Special case Scalar = ETATUN and Mtbl = ETATZERO: " << endl ; |
| 263 |
aa.set_etat_one() ; |
| 264 |
|
| 265 |
bb = aa * mc ; |
| 266 |
bb0 = 0 ; |
| 267 |
cout << "test Scalar(1) * Mtbl(0) : " << max(abs(bb-bb0)) << endl ; |
| 268 |
|
| 269 |
bb = mc * aa ; |
| 270 |
bb0 = 0 ; |
| 271 |
cout << "test Mtbl(0) * Scalar(1) : " << max(abs(bb-bb0)) << endl ; |
| 272 |
|
| 273 |
bb = mc / aa ; |
| 274 |
bb0 = 0 ; |
| 275 |
cout << "test Mtbl(0) / Scalar(1) : " << max(abs(bb-bb0)) << endl ; |
| 276 |
|
| 277 |
bb = mc + aa ; |
| 278 |
bb0 = 1 ; |
| 279 |
cout << "test Mtbl(0) + Scalar(1) : " << max(abs(bb-bb0)) << endl ; |
| 280 |
|
| 281 |
bb = aa + mc ; |
| 282 |
bb0 = 1 ; |
| 283 |
cout << "test Scalar(1) + Mtbl(0) : " << max(abs(bb-bb0)) << endl ; |
| 284 |
|
| 285 |
bb = mc - aa ; |
| 286 |
bb0 = - 1 ; |
| 287 |
cout << "test Mtbl(0) - Scalar(1) : " << max(abs(bb-bb0)) << endl ; |
| 288 |
|
| 289 |
bb = aa - mc ; |
| 290 |
bb0 = 1 ; |
| 291 |
cout << "test Scalar(1) - Mtbl(0) : " << max(abs(bb-bb0)) << endl ; |
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
return EXIT_SUCCESS ; |
| 296 |
|
| 297 |
} |