Debian Codegraph @

School05/Friday/wave_impl.C

raw
1 /*****************************************************************************
2
3 Implicit wave-equation solver in #D with Sommerfeld boundary conditions
4
5 ******************************************************************************/
6
7 #include <cmath>
8
9 // Lorene headers
10 #include "metric.h"
11 #include "proto.h"
12 #include "graphique.h"
13 #include "diff.h"
14
15 using namespace Lorene ;
16
17 int main() {
18
19 // Construction of a multi-grid (Mg3d)
20 // -----------------------------------
21
22 const int nz = 1 ; // Only a nucleus
23 int nr;
24 cout << "Enter nr: " << endl ;
25 cin >> nr ; // Number of collocation points in r
26 int nt = 5 ; // Number of collocation points in theta
27 int np = 6 ; // Number of collocation points in phi
28 int symmetry_theta = SYM ; // symmetry with respect to the equatorial plane
29 int symmetry_phi = SYM ; // symmetry in phi
30
31 Mg3d mgrid(nz, nr, nt, np, symmetry_theta, symmetry_phi, false) ;
32
33 // Construction of an affine mapping (Map_af)
34 // ------------------------------------------
35
36 double Rlim = 2. ;
37
38 // Boundaries of each domains
39 double r_limits[] = {0., Rlim} ;
40
41 Map_af map(mgrid, r_limits) ;
42 double alpha = map.get_alpha()[0] ;
43
44 // Coordinate fields
45 const Coord& r = map.r ;
46 const Coord& x = map.x ;
47 const Coord& y = map.y ;
48
49 // Flat metric in spherical components
50 //------------------------------------
51 const Metric_flat& mets = map.flat_met_spher() ;
52
53 // Initial data
54 //-------------
55 Scalar phim1(map) ;
56 // Something should be done here ...
57 Scalar phi = phim1 ;
58
59 // Time-step & boundary conditions
60 //--------------------------------
61 double dt ;
62 cout << "Enter dt: " << endl ;
63 cin >> dt ;
64 int iter = 0 ;
65 int ndes = int(Rlim / dt) / 200 + 1;
66 // Something should be done here ...
67
68 // Some initializations
69 //---------------------
70 int l_q, m_q, base_r ;
71 double emax = -1.e33 ;
72 double emin = 1.e33 ;
73 phi.set_spectral_va().ylm() ;
74 const Base_val& base = phi.get_spectral_base() ;
75
76 //----------------------------
77 // Main loop
78 //----------------------------
79 for (double tps=0.; tps<3.*Rlim; tps += dt) {
80
81 Scalar source(map) ;
82 // Something should be done here ...
83
84 Mtbl_cf resu(mgrid, base) ;
85 resu.annule_hard() ; //Initialized to zero
86
87 // Loop on theta, phi
88 //-------------------
89 for (int k=0; k<np; k++)
90 for (int j=0; j<nt; j++)
91 if (nullite_plm(j, nt, k, np, base) == 1) {
92 base.give_quant_numbers(0, k, j, m_q, l_q, base_r) ;
93
94 // Recovering the elementary operators (Diff)
95 //------------------------------------
96 Diff_sxdsdx dx(base_r, nr) ; const Matrice& mdx = dx.get_matrice() ;
97 Diff_dsdx2 dx2(base_r, nr) ; const Matrice& md2 = dx2.get_matrice() ;
98 Diff_sx2 sx2(base_r, nr) ; const Matrice& ms2 = sx2.get_matrice() ;
99 Diff_id id(base_r, nr) ; const Matrice& mid = id.get_matrice() ;
100
101 Matrice ope(nr, nr) ;
102 // Something should be done here ... to fill the matrix + BCs + regularity
103
104 Tbl rhs(nr) ; rhs.set_etat_qcq() ;
105 for (int i=0; i<nr; i++) {
106 rhs.set(i) = (*source.get_spectral_va().c_cf)(0, k, j, i) ;
107 }
108 // Something should be done here ... BCs still!
109
110
111 // Solution of the system
112 //-----------------------
113 ope.set_lu() ;
114 Tbl sol = ope.inverse(rhs) ;
115 for (int i=0; i<nr; i++)
116 resu.set(0, k, j, i) = sol(i) ;
117 }
118
119 // Putting everything into place
120 //------------------------------
121 Scalar phip1(map) ;
122 phip1.set_etat_qcq() ;
123 phip1.set_spectral_va() = resu ;
124 phip1.set_spectral_va().ylm_i() ;
125 phi.set_spectral_va().ylm_i() ;
126 phim1.set_spectral_va().ylm_i() ;
127
128 // Energy calculation
129 //-------------------
130 Scalar dtphi = (phip1 - phim1)/(2*dt) ;
131 double ener = (dtphi*dtphi
132 + contract(phi.derive_con(mets), 0,
133 phi.derive_cov(mets), 0)).integrale() ;
134
135 emax = (ener > emax) ? ener : emax ;
136 emin = (ener < emin) ? ener : emin ;
137
138 cout << "Energy inside the grid: " << ener << endl ;
139
140 // Drawing
141 //--------
142 if (iter%ndes == 0) {
143 des_meridian(phip1, 0., Rlim, "\\gf", 1) ;
144 }
145
146 // Preparation for next step
147 //--------------------------
148 iter++ ;
149 phim1 = phi ;
150 phi = phip1 ;
151 }
152 cout << "Emin, Emax: " << emin << ", " << emax << endl ;
153 cout << "Difference: " << (emax - emin) / emax << endl ;
154
155 return EXIT_SUCCESS ;
156 }