| 1 |
/* |
| 2 |
* Simple wave equation. |
| 3 |
* |
| 4 |
*/ |
| 5 |
|
| 6 |
/* |
| 7 |
* Copyright (c) 2003-2004 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 |
char simple_wave_C[] = "$Header: /cvsroot/Lorene/Codes/Tutorial/simple_wave.C,v 1.15 2014/10/13 08:54:04 j_novak Exp $" ; |
| 27 |
|
| 28 |
/* |
| 29 |
* $Id: simple_wave.C,v 1.15 2014/10/13 08:54:04 j_novak Exp $ |
| 30 |
* $Log: simple_wave.C,v $ |
| 31 |
* Revision 1.15 2014/10/13 08:54:04 j_novak |
| 32 |
* Lorene classes and functions now belong to the namespace Lorene. |
| 33 |
* |
| 34 |
* Revision 1.14 2005/03/25 20:39:27 e_gourgoulhon |
| 35 |
* Call to the new function des_coupe_z for Scalar's. |
| 36 |
* |
| 37 |
* Revision 1.13 2004/05/11 20:17:04 e_gourgoulhon |
| 38 |
* New prototype of des_evol. |
| 39 |
* |
| 40 |
* Revision 1.12 2004/04/06 08:26:21 j_novak |
| 41 |
* Update of the list of arguments for Evolution constructors. |
| 42 |
* |
| 43 |
* Revision 1.11 2004/02/25 16:44:57 j_novak |
| 44 |
* workflag is now allocated dynamically. |
| 45 |
* |
| 46 |
* Revision 1.10 2004/02/21 17:06:43 e_gourgoulhon |
| 47 |
* Method Scalar::point renamed Scalar::val_grid_point. |
| 48 |
* |
| 49 |
* Revision 1.9 2004/02/18 18:59:29 e_gourgoulhon |
| 50 |
* Suppressed unnecessary #include's. |
| 51 |
* |
| 52 |
* Revision 1.8 2004/02/17 22:20:49 e_gourgoulhon |
| 53 |
* Much better plots thanks to the new function des_profile_mult. |
| 54 |
* Added evolution of the central value of the field and its plot |
| 55 |
* through the new function des_evol. |
| 56 |
* |
| 57 |
* Revision 1.7 2004/02/17 09:19:08 j_novak |
| 58 |
* Cleaning of Param at the end of the code (memory leaks). |
| 59 |
* |
| 60 |
* Revision 1.6 2004/02/16 13:00:00 e_gourgoulhon |
| 61 |
* Added the C headers (not required by GNU g++ !!!). |
| 62 |
* |
| 63 |
* Revision 1.5 2004/02/15 22:08:16 e_gourgoulhon |
| 64 |
* The example with Poisson equation is now in file simple_poisson.C. |
| 65 |
* simple_wave.C contains now an example of resolution of d'Alembert |
| 66 |
* equation. The time evolution is managed thanks to the new |
| 67 |
* class Evolution_std. |
| 68 |
* |
| 69 |
* Revision 1.4 2003/12/16 06:33:31 e_gourgoulhon |
| 70 |
* Added call to method Scalar::visu_box. |
| 71 |
* |
| 72 |
* Revision 1.3 2003/12/14 21:53:26 e_gourgoulhon |
| 73 |
* Added 3D visualization of vector field through Vector::visu_arrows. |
| 74 |
* |
| 75 |
* Revision 1.2 2003/12/11 16:21:05 e_gourgoulhon |
| 76 |
* Use simplified version of Scalar::visu_section. |
| 77 |
* |
| 78 |
* Revision 1.1 2003/12/11 11:30:02 e_gourgoulhon |
| 79 |
* First version. |
| 80 |
* |
| 81 |
* |
| 82 |
* |
| 83 |
* $Header: /cvsroot/Lorene/Codes/Tutorial/simple_wave.C,v 1.15 2014/10/13 08:54:04 j_novak Exp $ |
| 84 |
* |
| 85 |
*/ |
| 86 |
|
| 87 |
// C++ headers |
| 88 |
#include "headcpp.h" |
| 89 |
|
| 90 |
// C headers |
| 91 |
#include "stdlib.h" |
| 92 |
#include "assert.h" |
| 93 |
#include "math.h" |
| 94 |
|
| 95 |
// Lorene headers |
| 96 |
#include "metric.h" |
| 97 |
#include "graphique.h" |
| 98 |
#include "param.h" |
| 99 |
#include "evolution.h" |
| 100 |
#include "utilitaires.h" |
| 101 |
|
| 102 |
|
| 103 |
using namespace Lorene ; |
| 104 |
|
| 105 |
int main() { |
| 106 |
|
| 107 |
// Setup of a multi-domain grid (Lorene class Mg3d) |
| 108 |
// ------------------------------------------------ |
| 109 |
|
| 110 |
int nz = 2 ; // Number of domains |
| 111 |
int nr = 17 ; // Number of collocation points in r in each domain |
| 112 |
int nt = 9 ; // Number of collocation points in theta in each domain |
| 113 |
int np = 8 ; // Number of collocation points in phi in each domain |
| 114 |
int symmetry_theta = SYM ; // symmetry with respect to the equatorial plane |
| 115 |
int symmetry_phi = NONSYM ; // no symmetry in phi |
| 116 |
bool compact = false ; // external domain is not compactified |
| 117 |
|
| 118 |
// Multi-domain grid construction: |
| 119 |
Mg3d mgrid(nz, nr, nt, np, symmetry_theta, symmetry_phi, compact) ; |
| 120 |
|
| 121 |
cout << mgrid << endl ; |
| 122 |
|
| 123 |
|
| 124 |
// Setup of an affine mapping : grid --> physical space (Lorene class Map_af) |
| 125 |
// -------------------------------------------------------------------------- |
| 126 |
|
| 127 |
// radial boundaries of each domain: |
| 128 |
double r_limits[] = {0., 2., 4.} ; |
| 129 |
assert( nz == 2 ) ; // since the above array described only 2 domains |
| 130 |
|
| 131 |
Map_af map(mgrid, r_limits) ; // Mapping construction |
| 132 |
|
| 133 |
cout << map << endl ; |
| 134 |
|
| 135 |
// Denomination of various coordinates associated with the mapping |
| 136 |
// --------------------------------------------------------------- |
| 137 |
|
| 138 |
const Coord& r = map.r ; // r field |
| 139 |
const Coord& x = map.x ; // x field |
| 140 |
const Coord& y = map.y ; // y field |
| 141 |
|
| 142 |
// Setup of a scalar field (initial value for the d'Alembert equation) |
| 143 |
// ------------------------------------------------------------------- |
| 144 |
|
| 145 |
Scalar uu0(map) ; // construction of an object of Lorene class Scalar |
| 146 |
|
| 147 |
uu0 = 2* exp( - r*r ) * (1 + x + x*y) ; |
| 148 |
|
| 149 |
uu0.std_spectral_base() ; // sets the bases for the spectral expansions |
| 150 |
// to the standard ones for a scalar field |
| 151 |
|
| 152 |
cout << uu0 << endl ; // prints to screen |
| 153 |
|
| 154 |
uu0.spectral_display() ; // prints the spectral expansions |
| 155 |
|
| 156 |
// 2-D visualization via PGPLOT |
| 157 |
// ---------------------------- |
| 158 |
|
| 159 |
des_coupe_z( uu0, 0., 1, "Field U") ; |
| 160 |
|
| 161 |
|
| 162 |
// 3-D visualization via OpenDX |
| 163 |
// ---------------------------- |
| 164 |
|
| 165 |
// double z0 = 0 ; // section plane : z = z0 |
| 166 |
|
| 167 |
// uu0.visu_section('z', z0, -2., 2., -1.5, 1.5, "Example of section vis.") ; |
| 168 |
|
| 169 |
// uu0.visu_box(-2., 2., -1.5, 1.5, -1., 1., "Example of volume rendering", 0x0) ; |
| 170 |
|
| 171 |
// Time evolution : d'Alembert equation |
| 172 |
// ------------------------------------ |
| 173 |
|
| 174 |
Scalar source(map) ; // source of d'Alembert equation |
| 175 |
source = 0 ; |
| 176 |
|
| 177 |
double dt = 0.02 ; // time step |
| 178 |
int bc = 2 ; // type of boundary condition : 2 = Bayliss & Turkel outgoing wave |
| 179 |
int *workflag = new int(0) ; // working flag |
| 180 |
|
| 181 |
Param par ; |
| 182 |
par.add_double(dt) ; |
| 183 |
par.add_int(bc) ; |
| 184 |
par.add_int_mod(*workflag) ; |
| 185 |
|
| 186 |
|
| 187 |
double t = 0 ; |
| 188 |
|
| 189 |
int j_min = 0 ; |
| 190 |
|
| 191 |
Evolution_std<Scalar> uu(uu0, 3, j_min, t) ; // Time evolution of U |
| 192 |
// Time evolution of the central value of U : |
| 193 |
Evolution_full<double> uu_c(uu0.val_grid_point(0,0,0,0), j_min, t) ; |
| 194 |
j_min++ ; |
| 195 |
t += dt ; |
| 196 |
|
| 197 |
uu.update(uu0, j_min, t) ; |
| 198 |
uu_c.update(uu0.val_grid_point(0,0,0,0), j_min, t) ; |
| 199 |
|
| 200 |
int j_max = 500 ; |
| 201 |
|
| 202 |
for (int j = j_min; j <= j_max ; j++) { |
| 203 |
|
| 204 |
Scalar uu_jp1 = uu[j].avance_dalembert(par, uu[j-1], source) ; |
| 205 |
|
| 206 |
t += dt ; |
| 207 |
uu.update(uu_jp1, j+1, t) ; |
| 208 |
|
| 209 |
uu_c.update(uu_jp1.val_grid_point(0,0,0,0), j+1, t) ; |
| 210 |
|
| 211 |
|
| 212 |
if ( j%2 == 0 ) { |
| 213 |
|
| 214 |
|
| 215 |
cout << "Step = " << j+1 << ", time = " << t << endl ; |
| 216 |
|
| 217 |
const Scalar* des[] = {&uu[j+1], &uu[j+1], &uu[j+1]} ; |
| 218 |
double tab_theta0[] = {0.5*M_PI, 0.5*M_PI, 0.5*M_PI} ; |
| 219 |
double tab_phi0[] = {0., 0.5*M_PI, M_PI} ; |
| 220 |
|
| 221 |
des_profile_mult(des, 3, 0., 4., tab_theta0, tab_phi0, 1., false, |
| 222 |
"U", |
| 223 |
"U in the equatorial plane for phi=0, pi/2, pi", 0) ; |
| 224 |
|
| 225 |
double tab_theta1[] = {0, 0.25*M_PI, 0.5*M_PI} ; |
| 226 |
double tab_phi1[] = {0., 0., 0.} ; |
| 227 |
|
| 228 |
des_profile_mult(des, 3, 0., 4., tab_theta1, tab_phi1, 1., false, |
| 229 |
"U", "U in the merional plane phi=0 for theta=0, pi/4, pi/2", 1) ; |
| 230 |
|
| 231 |
} |
| 232 |
} |
| 233 |
|
| 234 |
des_evol(uu_c, "U\\dc\\u", "Evolution of central value of U") ; |
| 235 |
arrete() ; |
| 236 |
|
| 237 |
|
| 238 |
// uu.visu_section('z', z0, -2., 2., -1.5, 1.5, "Potential", "uu") ; |
| 239 |
|
| 240 |
// Construction of a flat metric |
| 241 |
// ----------------------------- |
| 242 |
|
| 243 |
Metric_flat mets(map, map.get_bvect_spher()) ; // spherical representation |
| 244 |
Metric_flat metc(map, map.get_bvect_cart()) ; // Cartesian representation |
| 245 |
|
| 246 |
Vector duu = uu[j_max-1].derive_cov(metc) ; |
| 247 |
|
| 248 |
// des_coupe_vect_z(duu, 0., -2., 0.5, 2, "Gradient of potential") ; |
| 249 |
|
| 250 |
//duu.visu_arrows(-1., 1., -1., 1., -1., 1., "Gradient of potential", |
| 251 |
// "gradient") ; |
| 252 |
|
| 253 |
par.clean_all() ; |
| 254 |
|
| 255 |
return EXIT_SUCCESS ; |
| 256 |
} |
| 257 |
|
| 258 |
|
| 259 |
|