Debian Codegraph @

School05/Friday/sol_wave_expl.C

raw
1 /*****************************************************************************
2
3 Explicit wave-equation solver in spherical symmetry
4
5 ******************************************************************************/
6
7 #include <cmath>
8
9 // Lorene headers
10 #include "tensor.h"
11 #include "utilitaires.h"
12 #include "graphique.h"
13
14 using namespace Lorene ;
15
16 int main() {
17
18 // Construction of a multi-grid (Mg3d)
19 // -----------------------------------
20
21 const int nz = 1 ; // Only a nucleus
22 int nr;
23 cout << "Enter nr: " << endl ;
24 cin >> nr ; // Number of collocation points in r
25 int nt = 1 ; // Number of collocation points in theta
26 int np = 1 ; // Number of collocation points in phi
27 int symmetry_theta = SYM ; // symmetry with respect to the equatorial plane
28 int symmetry_phi = SYM ; // symmetry in phi
29
30 Mg3d mgrid(nz, nr, nt, np, symmetry_theta, symmetry_phi, false) ;
31
32 // Construction of an affine mapping (Map_af)
33 // ------------------------------------------
34
35 double Rlim = 2. ;
36
37 // Boundaries of each domains
38 double r_limits[] = {0., Rlim} ;
39
40 Map_af map(mgrid, r_limits) ;
41 const Coord& r = map.r ;
42
43 // Setup of initial profile
44 //-------------------------
45
46 double sigma = 9;
47 Scalar phim1(map) ;
48 phim1 = exp(-sigma*r*r) - exp(-sigma*Rlim*Rlim) ;
49 phim1.std_spectral_base() ;
50 Scalar phi = phim1 ;
51 double dt ;
52 cout << "Enter dt: " << endl ;
53 cin >> dt ;
54 int iter = 0 ;
55 int ndes = int(Rlim / dt) / 200 + 1; //Frequency for drawings
56
57 // Definition of the "homogeneous solution"
58 //-----------------------------------------
59
60 Scalar phi_hom(map) ;
61 phi_hom.annule_hard() ;
62 phi_hom.set_outer_boundary(nz-1, 1.) ;
63 phi_hom.std_spectral_base() ;
64 double d_hom = phi_hom.dsdr().val_grid_point(nz-1, 0, 0, nr-1) ;
65 double a_bound = 3./(2.*dt) + 1./Rlim ; //For the boundary conditions
66 double b_bound = 1. ; // here Sommerfeld outgoing
67 double c_bound = 0. ; // condition
68
69 //-----------------------------------------
70 // Main loop
71 //-----------------------------------------
72 for (double tps=0.; tps<4.*Rlim; tps += dt) {
73
74 // Simple forward Euler explicit scheme
75 //-------------------------------------
76 Scalar phip1 = 2*phi - phim1 + dt*dt*phi.laplacian() ;
77 phip1.set_dzpuis(0) ;
78
79 // Imposing boundary conditions
80 //-----------------------------
81 c_bound = (4*phi.val_grid_point(nz-1, 0, 0, nr-1)
82 - phim1.val_grid_point(nz-1, 0, 0, nr-1) ) /(2*dt) ;
83 double lambda = (c_bound - a_bound*phip1.val_grid_point(nz-1, 0, 0, nr-1)
84 - b_bound*phip1.dsdr().val_grid_point(nz-1, 0, 0, nr-1)) /
85 ( a_bound + b_bound*d_hom) ;
86 phip1 += lambda*phi_hom ;
87
88 // Drawing
89 //--------
90 if (iter%ndes == 0)
91 des_meridian(phip1, 0., Rlim, "\\gf", 1) ;
92
93 // Preparation for next step
94 //--------------------------
95 iter++ ;
96 phim1 = phi ;
97 phi = phip1 ;
98 }
99
100 return EXIT_SUCCESS ;
101 }