Debian Codegraph @

Codes/Einstein/wave_evol.C

raw
1 /*
2 * Main code for time evolution of a wave packet within maximal slicing
3 * + Dirac gauge.
4 *
5 */
6
7 /*
8 * Copyright (c) 2004 Eric Gourgoulhon & Jerome Novak
9 *
10 * This file is part of LORENE.
11 *
12 * LORENE is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2
14 * as published by the Free Software Foundation.
15 *
16 * LORENE is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with LORENE; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 *
25 */
26
27 char wave_evol_C[] = "$Header: /cvsroot/Lorene/Codes/Einstein/wave_evol.C,v 1.16 2014/10/13 08:53:56 j_novak Exp $" ;
28
29 /*
30 * $Id: wave_evol.C,v 1.16 2014/10/13 08:53:56 j_novak Exp $
31 * $Log: wave_evol.C,v $
32 * Revision 1.16 2014/10/13 08:53:56 j_novak
33 * Lorene classes and functions now belong to the namespace Lorene.
34 *
35 * Revision 1.15 2014/10/06 15:09:44 j_novak
36 * Modified #include directives to use c++ syntax.
37 *
38 * Revision 1.14 2010/10/20 08:00:43 j_novak
39 * New flag to control output on screen.
40 *
41 * Revision 1.13 2008/12/04 18:27:02 j_novak
42 * Minor modifs.
43 *
44 * Revision 1.12 2008/12/02 15:02:22 j_novak
45 * Implementation of the new constrained formalism, following Cordero et al. 2009
46 * paper. The evolution eqs. are solved as a first-order system. Not tested yet!
47 *
48 * Revision 1.11 2004/06/24 07:49:12 j_novak
49 * Using a constructor of Mg3d with variable number of points in each domain.
50 *
51 * Revision 1.10 2004/05/20 20:33:34 e_gourgoulhon
52 * Added parameters jmod_check_constraints and jmod_save,
53 * which are passed to Tslice_dirac_max::evolve.
54 *
55 * Revision 1.9 2004/05/17 20:00:09 e_gourgoulhon
56 * Added parameters ampli_tgam_dot, method_poisson_vect, precis_init,
57 * nopause from the input file. These arguments are passed to
58 * Tslice_dirac_max::initial_data_cts and Tslice_dirac_max::evolve
59 * (thanks to their new prototypes).
60 *
61 * Revision 1.8 2004/05/17 12:59:55 e_gourgoulhon
62 * Parameters of the computation are now read in file par_wave_evol.d.
63 *
64 * Revision 1.7 2004/05/05 14:51:48 e_gourgoulhon
65 * Introduced parameters ampli_init_khi and ampli_init_mu.
66 * Added some checks regarding khi and mu.
67 *
68 * Revision 1.6 2004/05/03 14:50:38 e_gourgoulhon
69 * First full version (time evolution).
70 *
71 * Revision 1.5 2004/04/30 10:53:32 e_gourgoulhon
72 * Added resolution of elliptic Einstein equations (new methods
73 * Tslice_dirac_max::solve_*) for tests at the end.
74 *
75 * Revision 1.4 2004/04/29 17:13:08 e_gourgoulhon
76 * New argument pdt to Time_slice_conf::initial_data_cts.
77 *
78 * Revision 1.3 2004/04/08 16:47:09 e_gourgoulhon
79 * Many changes.
80 *
81 * Revision 1.2 2004/04/07 07:59:22 e_gourgoulhon
82 * Added check of constraints at the end.
83 *
84 * Revision 1.1 2004/04/05 21:26:25 e_gourgoulhon
85 * First version (not ready yet !).
86 *
87 *
88 * $Header: /cvsroot/Lorene/Codes/Einstein/wave_evol.C,v 1.16 2014/10/13 08:53:56 j_novak Exp $
89 *
90 */
91
92 // C headers
93 #include <cmath>
94 #include <cstring>
95
96 // Lorene headers
97 #include "time_slice.h"
98 #include "param.h"
99 #include "nbr_spx.h"
100 #include "utilitaires.h"
101 #include "graphique.h"
102
103 using namespace Lorene ;
104
105 int main() {
106
107 //======================================================================
108 // Reading the parameters of the computation
109 //======================================================================
110
111 ifstream fpar("par_wave_evol.d") ;
112 if ( !fpar.good() ) {
113 cerr << "Problem with opening the file par_wave_evol.d ! " << endl ;
114 abort() ;
115 }
116
117 // Reading of physical paramaters
118 double ampli_init_khi, ampli_init_mu, ampli_tgam_dot ;
119 fpar.ignore(1000,'\n') ; // skip title
120 fpar >> ampli_init_khi ; fpar.ignore(1000,'\n') ;
121 fpar >> ampli_init_mu ; fpar.ignore(1000,'\n') ;
122 fpar >> ampli_tgam_dot ; fpar.ignore(1000,'\n') ;
123
124 // Reading of computational paramaters
125 int nb_time_steps, niter_elliptic, nopause, graph, graph_init,
126 method_poisson_vect, jmod_check_constraints, jmod_save ;
127 double pdt, relax_elliptic, precis_init ;
128 bool verbose ;
129 fpar.ignore(1000,'\n') ; // skip title
130 fpar >> pdt ; fpar.ignore(1000,'\n') ;
131 fpar >> nb_time_steps ; fpar.ignore(1000,'\n') ;
132 fpar >> niter_elliptic ; fpar.ignore(1000,'\n') ;
133 fpar >> relax_elliptic ; fpar.ignore(1000,'\n') ;
134 fpar >> method_poisson_vect ; fpar.ignore(1000,'\n') ;
135 fpar >> precis_init ; fpar.ignore(1000,'\n') ;
136 fpar >> nopause ; fpar.ignore(1000,'\n') ;
137 fpar >> graph ; fpar.ignore(1000,'\n') ;
138 fpar >> graph_init ; fpar.ignore(1000,'\n') ;
139 fpar >> jmod_check_constraints ; fpar.ignore(1000,'\n') ;
140 fpar >> jmod_save ; fpar.ignore(1000,'\n') ;
141 fpar >> verbose ; fpar.ignore(1000,'\n') ;
142
143 char graph_device[40] ;
144 if (graph == 0) strcpy(graph_device, "/n") ;
145 else if (graph == 1) strcpy(graph_device, "/xwin") ;
146 else if (graph == 2) strcpy(graph_device, "?") ;
147 else {
148 cerr <<
149 "Unexpected value of input parameter graph: graph = " << graph
150 << " !" << endl ;
151 abort() ;
152 }
153
154 char graph_device_init[40] ;
155 if (graph_init == 0) strcpy(graph_device_init, "/n") ;
156 else if (graph_init == 1) strcpy(graph_device_init, "/xwin") ;
157 else if (graph_init == 2) strcpy(graph_device_init, "?") ;
158 else {
159 cerr <<
160 "Unexpected value of input parameter graph: graph_init = "
161 << graph_init << " !" << endl ;
162 abort() ;
163 }
164
165
166 // Reading of multi-domain grid parameters
167 int symmetry_phi0, nz, nt, np ;
168 fpar.ignore(1000,'\n') ; // skip title
169 fpar >> symmetry_phi0 ; fpar.ignore(1000,'\n') ;
170 fpar >> nz ; fpar.ignore(1000,'\n') ;
171 fpar >> nt ; fpar.ignore(1000,'\n') ;
172 fpar >> np ; fpar.ignore(1000,'\n') ;
173 fpar.ignore(1000,'\n') ; // skip title
174 int* nr = new int[nz];
175 int* nt_tab = new int[nz];
176 int* np_tab = new int[nz];
177 double* r_limits = new double[nz+1] ;
178 for (int l=0; l<nz; l++) {
179 fpar >> nr[l];
180 fpar >> r_limits[l]; fpar.ignore(1000,'\n') ;
181 np_tab[l] = np ;
182 nt_tab[l] = nt ;
183 }
184 r_limits[nz] = __infinity ;
185
186 fpar.close() ;
187
188 cout << "Physical parameters: \n"
189 << "------------------- \n" ;
190 cout << " ampli_init_khi = " << ampli_init_khi << endl ;
191 cout << " ampli_init_mu = " << ampli_init_mu << endl ;
192 cout << " ampli_tgam_dot = " << ampli_tgam_dot << endl ;
193 cout << "Computational parameters: \n"
194 << "------------------------ \n" ;
195 cout << " pdt = " << pdt << endl ;
196 cout << " nb_time_steps = " << nb_time_steps << endl ;
197 cout << " niter_elliptic = " << niter_elliptic << endl ;
198 cout << " relax_elliptic = " << relax_elliptic << endl ;
199 cout << " method_poisson_vect = " << method_poisson_vect << endl ;
200 cout << " precis_init = " << precis_init << endl ;
201 cout << " graph_device = " << graph_device << endl ;
202 cout << " graph_device_init = " << graph_device_init << endl ;
203 cout << " jmod_check_constraints = " << jmod_check_constraints << endl ;
204 cout << " jmod_save = " << jmod_save << endl ;
205 cout << " verbose = " << verbose << endl ;
206
207 //======================================================================
208 // Construction and initialization of the various objects
209 //======================================================================
210
211 // Setup of a multi-domain grid (Lorene class Mg3d)
212 // ------------------------------------------------
213
214 // Type of r sampling :
215 int* type_r = new int[nz];
216 type_r[0] = RARE ;
217 for (int l=1; l<nz-1; l++) {
218 type_r[l] = FIN ;
219 }
220 type_r[nz-1] = UNSURR ;
221 int symmetry_theta = SYM ; // symmetry with respect to the equatorial plane
222 int symmetry_phi = (symmetry_phi0 == 1) ? SYM : NONSYM ; // symmetry in phi
223 // Multi-domain grid construction:
224 Mg3d mgrid(nz, nr, type_r, nt_tab, symmetry_theta, np_tab, symmetry_phi) ;
225
226 cout << "Computational grid :\n"
227 << "------------------ \n"
228 << " " << mgrid << endl ;
229
230
231 // Setup of an affine mapping : grid --> physical space (Lorene class Map_af)
232 // --------------------------------------------------------------------------
233
234 Map_af map(mgrid, r_limits) ; // Mapping construction
235
236 cout << "Mapping computational grid --> physical space :\n"
237 << "---------------------------------------------\n"
238 << " " << map << endl ;
239
240 // Flat metric f
241 // -------------
242
243 const Metric_flat& ff = map.flat_met_spher() ;
244
245 // Triad orthonormal with respect to the flat metric f
246 // ----------------------------------------------------
247
248 const Base_vect_spher& otriad = map.get_bvect_spher() ;
249
250
251 // Construction of a time slice with maximal slicing and Dirac gauge
252 // -----------------------------------------------------------------
253
254 Tslice_dirac_max sigmat(map, otriad, ff) ;
255
256 // Set up of potentials khi and mu
257 // -------------------------------
258
259 const Coord& x = map.x ;
260 const Coord& y = map.y ;
261 const Coord& z = map.z ;
262 const Coord& r = map.r ;
263
264 Scalar khi_init(map) ;
265
266 khi_init = ampli_init_khi * exp( - r*r ) * x*y ;
267 khi_init.set_outer_boundary(nz-1, 0.) ; // zero at spatial infinity
268
269 khi_init.std_spectral_base() ;
270
271 khi_init.spectral_display("khi_init") ;
272 if (khi_init.get_etat() == ETATQCQ)
273 des_meridian(khi_init, 0., 1.25*r_limits[nz-1], "khi_init", 1,
274 graph_device_init) ;
275
276 Scalar mu_init(map) ;
277 mu_init = ampli_init_mu * x*y* exp( - r*r ) ;
278 mu_init.set_outer_boundary(nz-1, 0.) ;
279 mu_init.std_spectral_base() ;
280 mu_init.mult_r() ;
281 mu_init.set_outer_boundary(nz-1, 0.) ;
282 mu_init.mult_cost() ;
283
284 mu_init.spectral_display("mu_init") ;
285 if (mu_init.get_etat() == ETATQCQ)
286 des_meridian(mu_init, 0., 1.25*r_limits[nz-1], "mu_init", 2,
287 graph_device_init) ;
288
289
290
291 // The potentials khi and mu are used to construct h^{ij}:
292 // ------------------------------------------------------
293
294 sigmat.set_khi_mu(khi_init, mu_init) ; // the trace h = f_{ij} h^{ij]
295 // is computed to ensure
296 // det tgam_{ij} = f
297 // sigmat.hh().transverse(ff).tt_part().khi().spectral_display("khi") ;
298 // sigmat.hh().transverse(ff).tt_part().eta().spectral_display("eta") ;
299 // sigmat.hh().transverse(ff).tt_part().mu().spectral_display("mu") ;
300
301 //======================================================================
302 // Resolution of the initial data equations within
303 // the conformal thin sandwich framework
304 //======================================================================
305
306 // u^{ij} = d/dt h^{ij}
307 Sym_tensor_trans uu_init(map, otriad, ff) ;
308
309 uu_init = ampli_tgam_dot * ( sigmat.hh()
310 - 0.33333333333333333 * sigmat.hh().trace(sigmat.tgam())
311 * sigmat.tgam().con() ) ;
312 uu_init.inc_dzpuis(2) ;
313
314 // tr K = K
315 Scalar tmp(map) ;
316 tmp.set_etat_zero() ;
317
318 arrete(nopause) ;
319
320 cout << "=======================================================\n"
321 << " Computation of initial data (Conf. Thin Sandwich)\n"
322 << "=======================================================\n" ;
323
324 sigmat.initial_data_cts(uu_init, tmp, tmp, pdt, precis_init,
325 method_poisson_vect, graph_device_init) ;
326
327 arrete(nopause) ;
328
329 sigmat.A_hh() ; // forces updates
330 sigmat.B_hh() ; //
331 sigmat.trh() ; //
332
333 cout << "Initial data : " << sigmat << endl ;
334 cout << "ADM mass : " << sigmat.adm_mass() << endl ;
335
336 // sigmat.trh().visu_section ('x', 0., -4., 4., -4., 4., "h in x=0 plane", "h_x") ;
337
338 // sigmat.trh().visu_section ('z', 0., -4., 4., -4., 4., "h in z=0 plane", "h_z") ;
339
340 // sigmat.psi().visu_section ('z', 0., -4., 4., -4., 4., "Psi in z=0 plane",
341 // "psi_z") ;
342
343 // sigmat.trh().visu_box(-4., 4.,-4., 4.,-4., 4., "h") ;
344
345 // Check of constraints:
346 sigmat.check_hamiltonian_constraint() ;
347 sigmat.check_momentum_constraint() ;
348
349 // Extra check
350 Scalar diffr = sigmat.gam().ricci_scal()
351 - ( sigmat.tgam().ricci_scal()
352 - 8.* sigmat.psi().derive_con(sigmat.tgam()).divergence(sigmat.tgam())
353 / sigmat.psi()
354 ) / sigmat.psi4() ;
355 maxabs(diffr,
356 "Error in the relation (involving psi) between the Ricci scalars of gam and tgam") ;
357
358 maxabs(sigmat.gam().cov()(1,1) / sigmat.tgam().cov()(1,1) -
359 sigmat.psi4(), "Difference between the conformal factor and psi4") ;
360
361
362 maxabs(sigmat.psi() - 1., "Psi - 1") ;
363
364 // Check of khi and mu
365
366 Sym_tensor_tt htest(map, otriad, ff) ;
367 htest.set_khi_mu(khi_init, mu_init) ;
368
369 Sym_tensor_tt htest2 = sigmat.hh().transverse(ff, 0x0, method_poisson_vect).tt_part() ;
370 htest2.dec_dzpuis(2) ;
371
372 maxabs(htest - htest2, "difference htest - htest2") ;
373
374 maxabs(htest.khi() - khi_init, "htest.khi() - khi_init") ;
375 maxabs(htest2.khi() - khi_init, "htest2.khi() - khi_init") ;
376
377 maxabs(htest.mu() - mu_init, "htest.mu() - mu_init") ;
378 maxabs(htest2.mu() - mu_init, "htest2.mu() - mu_init") ;
379
380 arrete(nopause) ;
381
382 //======================================================================
383 // Time evolution
384 //======================================================================
385
386 sigmat.evolve(pdt, nb_time_steps, niter_elliptic, relax_elliptic,
387 jmod_check_constraints, jmod_save,
388 method_poisson_vect, nopause, graph_device, verbose) ;
389
390 // Freeing dynamically allocated memory
391 // ------------------------------------
392 delete [] r_limits ;
393 delete [] nr ;
394 delete [] nt_tab ;
395 delete [] np_tab ;
396 delete [] type_r ;
397
398 return EXIT_SUCCESS ;
399 }
400