Debian Codegraph @

School05/Friday/wave_impl_bc3.C

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