LORENE
binary_dirac.C
1/*
2 * Methods of Bin_star::dirac_gauge
3 *
4 * (see file star.h for documentation)
5 *
6 */
7
8/*
9 * Copyright (c) 2005 Francois Limousin
10 *
11 * This file is part of LORENE.
12 *
13 * LORENE is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * LORENE is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with LORENE; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 *
27 */
28
29
30
31/*
32 * $Id: binary_dirac.C,v 1.4 2016/12/05 16:17:47 j_novak Exp $
33 * $Log: binary_dirac.C,v $
34 * Revision 1.4 2016/12/05 16:17:47 j_novak
35 * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
36 *
37 * Revision 1.3 2014/10/13 08:52:44 j_novak
38 * Lorene classes and functions now belong to the namespace Lorene.
39 *
40 * Revision 1.2 2006/04/11 14:25:15 f_limousin
41 * New version of the code : improvement of the computation of some
42 * critical sources, estimation of the dirac gauge, helical symmetry...
43 *
44 * Revision 1.1 2005/11/08 20:17:01 f_limousin
45 * Function used to impose Dirac gauge during an iteration.
46 *
47 *
48 * $Header: /cvsroot/Lorene/C++/Source/Binary/binary_dirac.C,v 1.4 2016/12/05 16:17:47 j_novak Exp $ *
49 */
50
51
52// Headers Lorene
53#include "tenseur.h"
54#include "binary.h"
55#include "star.h"
56#include "graphique.h"
57#include "utilitaires.h"
58#include "param.h"
59
60
61namespace Lorene {
63
64 int nz = star1.mp.get_mg()->get_nzone() ;
65 int nr = star1.mp.get_mg()->get_nr(0);
66 int nt = star1.mp.get_mg()->get_nt(0);
67 int np = star1.mp.get_mg()->get_np(0);
68
69 // Importations
70 // ------------
71
72 // Star 1
73
74 star1.hij_comp.set_triad(star1.mp.get_bvect_cart()) ;
75 Sym_tensor comp_hij1(star2.hij_auto) ;
76 comp_hij1.change_triad(star2.mp.get_bvect_cart()) ;
77 comp_hij1.change_triad(star1.mp.get_bvect_cart()) ;
78
79 assert ( *(star1.hij_comp.get_triad()) == *(comp_hij1.get_triad())) ;
80
81 for(int i=1; i<=3; i++)
82 for(int j=i; j<=3; j++) {
83 star1.hij_comp.set(i,j).set_etat_qcq() ;
84 star1.hij_comp.set(i,j).import( (comp_hij1)(i,j) ) ;
85 }
86 star1.hij_comp.std_spectral_base() ;//set the bases for spectral expansions
87
88 for(int i=1; i<=3; i++)
89 for(int j=i; j<=3; j++)
90 star1.hij.set(i,j) = star1.hij_auto(i,j) + star1.hij_comp(i,j) ;
91
92 // Star 2
93
94 star2.hij_comp.set_triad(star2.mp.get_bvect_cart()) ;
95 Sym_tensor comp_hij2(star1.hij_auto) ;
96 comp_hij2.change_triad(star1.mp.get_bvect_cart()) ;
97 comp_hij2.change_triad(star2.mp.get_bvect_cart()) ;
98
99 assert ( *(star2.hij_comp.get_triad()) == *(comp_hij2.get_triad())) ;
100
101 for(int i=1; i<=3; i++)
102 for(int j=i; j<=3; j++) {
103 star2.hij_comp.set(i,j).set_etat_qcq() ;
104 star2.hij_comp.set(i,j).import( (comp_hij2)(i,j) ) ;
105 }
106 star2.hij_comp.std_spectral_base() ;//set the bases for spectral expansions
107
108 for(int i=1; i<=3; i++)
109 for(int j=i; j<=3; j++)
110 star2.hij.set(i,j) = star2.hij_auto(i,j) + star2.hij_comp(i,j) ;
111
112 // -----------------------------------------
113 // Resolution of the Poisson equation for xi
114 // -----------------------------------------
115
116 cout << "Function Binary::dirac_gauge()" << endl ;
117
118 // Star 1
119 // ----------
120
121 int mermax = 50 ;
122 double precis = 1e-5 ;
123 double precis_poisson = 1e-14 ;
124 double relax_poisson = 1.5 ;
125 int mer_poisson = 4 ;
126
127 Scalar rr1 (star1.mp) ;
128 rr1 = star1.mp.r ;
129 Scalar rr2 (star2.mp) ;
130 rr2 = star2.mp.r ;
131
132 Vector xi1(star1.mp, CON, star1.mp.get_bvect_cart()) ;
133 xi1.set(1) = 0. ;
134 xi1.set(2) = 0. ;
135 xi1.set(3) = 0. ;
136 xi1.std_spectral_base() ;
137 Vector xi1_old(xi1) ;
138
139 Scalar ssjm1_xi11 (xi1(1)) ;
140 Scalar ssjm1_xi12 (xi1(2)) ;
141 Scalar ssjm1_xi13 (xi1(3)) ;
142
143
144 for(int mer=0; mer<mermax; mer++){
145
146 xi1_old = xi1 ;
147
148 // Function exp(-(r-r_0)^2/sigma^2)
149 // --------------------------------
150
151 double r0_1 = star1.mp.val_r(nz-2, 1, 0, 0) ;
152 double sigma = 3.*r0_1 ;
153
154 Scalar ff1 (star1.mp) ;
155 ff1 = exp( -(rr1 - r0_1)*(rr1 - r0_1)/sigma/sigma ) ;
156 for (int ii=0; ii<nz-1; ii++)
157 ff1.set_domain(ii) = 1. ;
158 ff1.set_outer_boundary(nz-1, 0) ;
159 ff1.std_spectral_base() ;
160
161 // Source
162
163 Vector source_xi1 (star1.hij.divergence(star1.flat)) ;
164 source_xi1.inc_dzpuis() ; // dzpuis = 3
165
166 double lambda = 0. ;
167 Vector source_reg1 = - (1./3. - lambda) * xi1.divergence(star1.flat)
168 .derive_con(star1.flat) ;
169 source_xi1 += source_reg1 ;
170
171 // Resolution of the Poisson equations
172
173 Cmp ssjm1xi11 (ssjm1_xi11) ;
174 Cmp ssjm1xi12 (ssjm1_xi12) ;
175 Cmp ssjm1xi13 (ssjm1_xi13) ;
176 ssjm1xi11.set_etat_qcq() ;
177 ssjm1xi12.set_etat_qcq() ;
178 ssjm1xi13.set_etat_qcq() ;
179
180 Param par_xi11 ;
181 int niter ;
182 par_xi11.add_int(mer_poisson, 0) ; // maximum number of iterations
183 par_xi11.add_double(relax_poisson, 0) ; // relaxation parameter
184 par_xi11.add_double(precis_poisson, 1) ; // required precision
185 par_xi11.add_int_mod(niter, 0) ; // number of iterations actually used
186 par_xi11.add_cmp_mod(ssjm1xi11) ;
187
188 Param par_xi12 ;
189 par_xi12.add_int(mer_poisson, 0) ; // maximum number of iterations
190 par_xi12.add_double(relax_poisson, 0) ; // relaxation parameter
191 par_xi12.add_double(precis_poisson, 1) ; // required precision
192 par_xi12.add_int_mod(niter, 0) ; // number of iterations actually used
193 par_xi12.add_cmp_mod(ssjm1xi12) ;
194
195 Param par_xi13 ;
196 par_xi13.add_int(mer_poisson, 0) ; // maximum number of iterations
197 par_xi13.add_double(relax_poisson, 0) ; // relaxation parameter
198 par_xi13.add_double(precis_poisson, 1) ; // required precision
199 par_xi13.add_int_mod(niter, 0) ; // number of iterations actually used
200 par_xi13.add_cmp_mod(ssjm1xi13) ;
201
202 source_xi1(1).poisson(par_xi11, xi1.set(1)) ;
203 source_xi1(2).poisson(par_xi12, xi1.set(2)) ;
204 source_xi1(3).poisson(par_xi13, xi1.set(3)) ;
205
206 ssjm1_xi11 = ssjm1xi11 ;
207 ssjm1_xi12 = ssjm1xi12 ;
208 ssjm1_xi13 = ssjm1xi13 ;
209
210 // Check: has the equation for xi been correctly solved ?
211 // --------------------------------------------------------------
212
213 Vector lap_xi1 = (xi1.derive_con(star1.flat)).divergence(star1.flat)
214 + lambda* xi1.divergence(star1.flat).derive_con(star1.flat) ;
215
216 Tbl tdiff_xi1_x = diffrel(lap_xi1(1), source_xi1(1)) ;
217 Tbl tdiff_xi1_y = diffrel(lap_xi1(2), source_xi1(2)) ;
218 Tbl tdiff_xi1_z = diffrel(lap_xi1(3), source_xi1(3)) ;
219
220 cout <<
221 "Relative error in the resolution of the equation for xi1 : "
222 << endl ;
223 cout << "x component : " ;
224 for (int l=0; l<nz; l++) {
225 cout << tdiff_xi1_x(l) << " " ;
226 }
227 cout << endl ;
228 cout << "y component : " ;
229 for (int l=0; l<nz; l++) {
230 cout << tdiff_xi1_y(l) << " " ;
231 }
232 cout << endl ;
233 cout << "z component : " ;
234 for (int l=0; l<nz; l++) {
235 cout << tdiff_xi1_z(l) << " " ;
236 }
237 cout << endl ;
238
239
240 double erreur = 0 ;
241 Tbl diff (diffrelmax (xi1_old(1), xi1(1))) ;
242 for (int i=1 ; i<nz ; i++)
243 if (diff(i) > erreur)
244 erreur = diff(i) ;
245
246 cout << "Step : " << mer << " Difference : " << erreur << endl ;
247 cout << "-------------------------------------" << endl ;
248 if (erreur < precis)
249 mer = mermax ;
250
251 }
252
253 // Star 2
254 // ----------
255
256 Vector xi2(star2.mp, CON, star2.mp.get_bvect_cart()) ;
257 xi2.set(1) = 0. ;
258 xi2.set(2) = 0. ;
259 xi2.set(3) = 0. ;
260 xi2.std_spectral_base() ;
261 Vector xi2_old(xi2) ;
262
263 Scalar ssjm1_xi21 (xi2(1)) ;
264 Scalar ssjm1_xi22 (xi2(2)) ;
265 Scalar ssjm1_xi23 (xi2(3)) ;
266
267
268 for(int mer=0; mer<mermax; mer++){
269
270 xi2_old = xi2 ;
271
272 // Function exp(-(r-r_0)^2/sigma^2)
273 // --------------------------------
274
275 double r0_2 = star2.mp.val_r(nz-2, 1, 0, 0) ;
276 double sigma = 3.*r0_2 ;
277
278 Scalar ff2 (star2.mp) ;
279 ff2 = exp( -(rr2 - r0_2)*(rr2 - r0_2)/sigma/sigma ) ;
280 for (int ii=0; ii<nz-1; ii++)
281 ff2.set_domain(ii) = 1. ;
282 ff2.set_outer_boundary(nz-1, 0) ;
283 ff2.std_spectral_base() ;
284
285 // Source
286
287 Vector source_xi2 (star2.hij.divergence(star2.flat)) ;
288 source_xi2.inc_dzpuis() ; // dzpuis = 3
289
290 double lambda = 0. ;
291 Vector source_reg2 = - (1./3. - lambda) * xi2.divergence(star2.flat)
292 .derive_con(star2.flat) ;
293 source_xi2 += source_reg2 ;
294
295 // Resolution of the Poisson equations
296
297 Cmp ssjm1xi21 (ssjm1_xi21) ;
298 Cmp ssjm1xi22 (ssjm1_xi22) ;
299 Cmp ssjm1xi23 (ssjm1_xi23) ;
300 ssjm1xi21.set_etat_qcq() ;
301 ssjm1xi22.set_etat_qcq() ;
302 ssjm1xi23.set_etat_qcq() ;
303
304 Param par_xi21 ;
305 int niter ;
306 par_xi21.add_int(mer_poisson, 0) ; // maximum number of iterations
307 par_xi21.add_double(relax_poisson, 0) ; // relaxation parameter
308 par_xi21.add_double(precis_poisson, 1) ; // required precision
309 par_xi21.add_int_mod(niter, 0) ; // number of iterations actually used
310 par_xi21.add_cmp_mod(ssjm1xi21) ;
311
312 Param par_xi22 ;
313 par_xi22.add_int(mer_poisson, 0) ; // maximum number of iterations
314 par_xi22.add_double(relax_poisson, 0) ; // relaxation parameter
315 par_xi22.add_double(precis_poisson, 1) ; // required precision
316 par_xi22.add_int_mod(niter, 0) ; // number of iterations actually used
317 par_xi22.add_cmp_mod(ssjm1xi22) ;
318
319 Param par_xi23 ;
320 par_xi23.add_int(mer_poisson, 0) ; // maximum number of iterations
321 par_xi23.add_double(relax_poisson, 0) ; // relaxation parameter
322 par_xi23.add_double(precis_poisson, 1) ; // required precision
323 par_xi23.add_int_mod(niter, 0) ; // number of iterations actually used
324 par_xi23.add_cmp_mod(ssjm1xi23) ;
325
326 source_xi2(1).poisson(par_xi21, xi2.set(1)) ;
327 source_xi2(2).poisson(par_xi22, xi2.set(2)) ;
328 source_xi2(3).poisson(par_xi23, xi2.set(3)) ;
329
330 ssjm1_xi21 = ssjm1xi21 ;
331 ssjm1_xi22 = ssjm1xi22 ;
332 ssjm1_xi23 = ssjm1xi23 ;
333
334 // Check: has the equation for xi been correctly solved ?
335 // --------------------------------------------------------------
336
337 Vector lap_xi2 = (xi2.derive_con(star2.flat)).divergence(star2.flat)
338 + lambda* xi2.divergence(star2.flat).derive_con(star2.flat) ;
339
340 Tbl tdiff_xi2_x = diffrel(lap_xi2(1), source_xi2(1)) ;
341 Tbl tdiff_xi2_y = diffrel(lap_xi2(2), source_xi2(2)) ;
342 Tbl tdiff_xi2_z = diffrel(lap_xi2(3), source_xi2(3)) ;
343
344 cout <<
345 "Relative error in the resolution of the equation for xi2 : "
346 << endl ;
347 cout << "x component : " ;
348 for (int l=0; l<nz; l++) {
349 cout << tdiff_xi2_x(l) << " " ;
350 }
351 cout << endl ;
352 cout << "y component : " ;
353 for (int l=0; l<nz; l++) {
354 cout << tdiff_xi2_y(l) << " " ;
355 }
356 cout << endl ;
357 cout << "z component : " ;
358 for (int l=0; l<nz; l++) {
359 cout << tdiff_xi2_z(l) << " " ;
360 }
361 cout << endl ;
362
363
364 double erreur = 0 ;
365 Tbl diff (diffrelmax (xi2_old(1), xi2(1))) ;
366 for (int i=1 ; i<nz ; i++)
367 if (diff(i) > erreur)
368 erreur = diff(i) ;
369
370 cout << "Step : " << mer << " Difference : " << erreur << endl ;
371 cout << "-------------------------------------" << endl ;
372 if (erreur < precis)
373 mer = mermax ;
374
375 }
376
377 // -----------------------------
378 // Computation of the new metric
379 // -----------------------------
380
381 // Star 1
382 // -------
383
384 Sym_tensor guu_dirac1 (star1.mp, CON, star1.mp.get_bvect_cart()) ;
385 guu_dirac1 = star1.gamma.con().derive_lie(xi1) ;
386 guu_dirac1.dec_dzpuis(2) ;
387 guu_dirac1 = guu_dirac1 + star1.gamma.con() ;
388 star1.gamma = guu_dirac1 ;
389
390 Sym_tensor gtilde_con1(star1.mp, CON, star1.mp.get_bvect_cart()) ;
391 Sym_tensor hij_dirac1(star1.mp, CON, star1.mp.get_bvect_cart()) ;
392
393 gtilde_con1 = pow(star1.gamma.determinant(), 1./3.) * guu_dirac1 ;
394 gtilde_con1.std_spectral_base() ;
395 for(int i=1; i<=3; i++)
396 for(int j=i; j<=3; j++)
397 hij_dirac1.set(i,j) = gtilde_con1(i,j) - star1.flat.con()(i,j) ;
398
399
400 star1.gtilde = gtilde_con1 ;
401 star1.psi4 = pow(star1.gamma.determinant(), 1./3.) ;
402 star1.psi4.std_spectral_base() ;
403
404 cout << "norme de h_uu avant :" << endl ;
405 for (int i=1; i<=3; i++)
406 for (int j=1; j<=i; j++) {
407 cout << " Comp. " << i << " " << j << " : " ;
408 for (int l=0; l<nz; l++){
409 cout << norme(star1.hij(i,j)/(nr*nt*np))(l) << " " ;
410 }
411 cout << endl ;
412 }
413 cout << endl ;
414
415 cout << "norme de h_uu en jauge de dirac :" << endl ;
416 for (int i=1; i<=3; i++)
417 for (int j=1; j<=i; j++) {
418 cout << " Comp. " << i << " " << j << " : " ;
419 for (int l=0; l<nz; l++){
420 cout << norme(hij_dirac1(i,j)/(nr*nt*np))(l) << " " ;
421 }
422 cout << endl ;
423 }
424 cout << endl ;
425
426
427 // Check of the Dirac gauge
428 // ------------------------
429
430 Vector hh_dirac (star1.hij.divergence(star1.flat)) ;
431 cout << "For comparaison H^i before computation = " << endl
432 << norme(hh_dirac(1))/(nr*nt*np)
433 << endl
434 << norme(hh_dirac(2))/(nr*nt*np)
435 << endl
436 << norme(hh_dirac(3))/(nr*nt*np)
437 << endl ;
438
439 Vector hh_dirac_new (hij_dirac1.divergence(star1.flat)) ;
440 cout << "Vector H^i after the computation" << endl ;
441 for (int i=1; i<=3; i++){
442 cout << " Comp. " << i << " : " << norme(hh_dirac_new(i)
443 /(nr*nt*np)) << endl ;
444 }
445
446 star1.hij_auto = star1.hij_auto + (hij_dirac1 - star1.hij) *
447 star1.decouple ;
448 star1.hij_comp = star1.hij_comp + (hij_dirac1 - star1.hij) *
449 (1 - star1.decouple) ;
450 star1.hij = hij_dirac1 ;
451
452
453 // Star 2
454 // -------
455
456 Sym_tensor guu_dirac2 (star2.mp, CON, star2.mp.get_bvect_cart()) ;
457 guu_dirac2 = star2.gamma.con().derive_lie(xi2) ;
458 guu_dirac2.dec_dzpuis(2) ;
459 guu_dirac2 = guu_dirac2 + star2.gamma.con() ;
460 star2.gamma = guu_dirac2 ;
461
462 Sym_tensor gtilde_con2(star2.mp, CON, star2.mp.get_bvect_cart()) ;
463 Sym_tensor hij_dirac2(star2.mp, CON, star2.mp.get_bvect_cart()) ;
464
465 gtilde_con2 = pow(star2.gamma.determinant(), 1./3.) * guu_dirac2 ;
466 gtilde_con2.std_spectral_base() ;
467 for(int i=1; i<=3; i++)
468 for(int j=i; j<=3; j++)
469 hij_dirac2.set(i,j) = gtilde_con2(i,j) - star2.flat.con()(i,j) ;
470
471
472 star2.gtilde = gtilde_con2 ;
473 star2.psi4 = pow(star2.gamma.determinant(), 1./3.) ;
474 star2.psi4.std_spectral_base() ;
475
476
477 star2.hij_auto = star2.hij_auto + (hij_dirac2 - star2.hij) *
478 star2.decouple ;
479 star2.hij_comp = star2.hij_comp + (hij_dirac2 - star2.hij) *
480 (1 - star2.decouple) ;
481 star2.hij = hij_dirac2 ;
482
483 //arrete() ;
484}
485}
void dirac_gauge()
Function used to impose Dirac gauge during an iteration.
Star_bin star2
Second star of the system.
Definition binary.h:83
Star_bin star1
First star of the system.
Definition binary.h:80
Component of a tensorial field *** DEPRECATED : use class Scalar instead ***.
Definition cmp.h:446
void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
Definition cmp.C:307
Parameter storage.
Definition param.h:125
void add_double(const double &x, int position=0)
Adds the the address of a new double to the list.
Definition param.C:318
void add_cmp_mod(Cmp &ti, int position=0)
Adds the address of a new modifiable Cmp to the list.
Definition param.C:1007
void add_int_mod(int &n, int position=0)
Adds the address of a new modifiable int to the list.
Definition param.C:388
void add_int(const int &n, int position=0)
Adds the address of a new int to the list.
Definition param.C:249
Tensor field of valence 0 (or component of a tensorial field).
Definition scalar.h:393
virtual void std_spectral_base()
Sets the spectral bases of the Valeur va to the standard ones for a scalar field.
Definition scalar.C:790
Tbl & set_domain(int l)
Read/write of the value in a given domain.
Definition scalar.h:621
void set_outer_boundary(int l, double x)
Sets the value of the Scalar at the outer boundary of a given domain.
const Vector & derive_con(const Metric &gam) const
Returns the "contravariant" derivative of *this with respect to some metric , by raising the index of...
Class intended to describe valence-2 symmetric tensors.
Definition sym_tensor.h:226
const Vector & divergence(const Metric &) const
Returns the divergence of this with respect to a Metric .
Definition sym_tensor.C:352
Basic array class.
Definition tbl.h:161
Tensor field of valence 1.
Definition vector.h:188
Vector poisson(double lambda, int method=6) const
Solves the vector Poisson equation with *this as a source.
virtual void std_spectral_base()
Sets the standard spectal bases of decomposition for each component.
Definition vector.C:319
const Scalar & divergence(const Metric &) const
The divergence of this with respect to a Metric .
Definition vector.C:384
Scalar & set(int)
Read/write access to a component.
Definition vector.C:299
Cmp exp(const Cmp &)
Exponential.
Definition cmp_math.C:273
Tbl diffrel(const Cmp &a, const Cmp &b)
Relative difference between two Cmp (norme version).
Definition cmp_math.C:507
Tbl norme(const Cmp &)
Sums of the absolute values of all the values of the Cmp in each domain.
Definition cmp_math.C:484
Cmp pow(const Cmp &, int)
Power .
Definition cmp_math.C:351
Tbl diffrelmax(const Cmp &a, const Cmp &b)
Relative difference between two Cmp (max version).
Definition cmp_math.C:542
virtual void dec_dzpuis(int dec=1)
Decreases by dec units the value of dzpuis and changes accordingly the values in the compactified ext...
Definition tensor.C:817
const Tensor & derive_con(const Metric &gam) const
Returns the "contravariant" derivative of this with respect to some metric , by raising the last inde...
Definition tensor.C:1023
virtual void change_triad(const Base_vect &new_triad)
Sets a new vectorial basis (triad) of decomposition and modifies the components accordingly.
virtual void inc_dzpuis(int inc=1)
Increases by inc units the value of dzpuis and changes accordingly the values in the compactified ext...
Definition tensor.C:825
const Base_vect * get_triad() const
Returns the vectorial basis (triad) on which the components are defined.
Definition tensor.h:879
Scalar & set(const Itbl &ind)
Returns the value of a component (read/write version).
Definition tensor.C:663
virtual void std_spectral_base()
Sets the standard spectal bases of decomposition for each component.
Definition tensor.C:935
Lorene prototypes.
Definition app_hor.h:67