Debian Codegraph @

C++/Source/App_hor/excision_hor.C

raw
1 /*
2 * Definition of methods for the class Spheroid and its subclass App_hor
3 *
4 */
5
6 /*
7 * Copyright (c) 2009 Jose-Luis Jaramillo & Jerome Novak & Nicolas Vasset
8 *
9 * This file is part of LORENE.
10 *
11 * LORENE is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version
13 * as published by the Free Software Foundation.
14 *
15 * LORENE is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with LORENE; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 *
24 */
25
26 char excision_hor_C[] = "$Header: /cvsroot/Lorene/C++/Source/App_hor/excision_hor.C,v 1.4 2014/10/13 08:52:38 j_novak Exp $" ;
27
28 /*
29 * $Header: /cvsroot/Lorene/C++/Source/App_hor/excision_hor.C,v 1.4 2014/10/13 08:52:38 j_novak Exp $
30 *
31 */
32
33 // C headers
34 #include <cmath>
35 #include <cassert>
36
37 // Lorene headers
38 #include "excision_hor.h"
39
40 //---------------//
41 // Constructors //
42 //--------------//
43
44
45 namespace Lorene {
46 Excision_hor::Excision_hor(const Scalar& h_in, const Metric& gij, const Sym_tensor& Kij2, const Scalar& ppsi, const Scalar& nn, const Vector& beta, const Sym_tensor& Tij2, double timestep, int int_nos):
47 sph(h_in, gij, Kij2),
48 conf_fact(ppsi),
49 lapse(nn),
50 shift(beta),
51 gamij (gij),
52 Kij(Kij2),
53 delta_t(timestep),
54 no_of_steps(int_nos),
55 Tij(Tij2)
56 {
57
58 set_der_0x0() ;
59
60 }
61
62
63
64
65
66 //Copy constructor//
67
68 Excision_hor::Excision_hor(const Excision_hor &exc_in) :sph(exc_in.sph),
69 conf_fact(exc_in.conf_fact),
70 lapse(exc_in.lapse),
71 shift(exc_in.shift),
72 gamij (exc_in.gamij),
73 Kij (exc_in.Kij),
74 delta_t(exc_in.delta_t),
75 no_of_steps(exc_in.no_of_steps),
76 Tij(exc_in.Tij)
77
78 {
79 set_der_0x0() ;
80
81 }
82 //------------//
83 //Destructor //
84 //-----------//
85
86 Excision_hor::~Excision_hor()
87 {
88 del_deriv() ;
89 }
90
91 // -----------------//
92 // Memory management//
93 //------------------//
94 void Excision_hor::del_deriv() const {
95
96 if (p_get_BC_conf_fact != 0x0) delete p_get_BC_conf_fact ;
97 if (p_get_BC_bmN != 0x0) delete p_get_BC_bmN ;
98 if (p_get_BC_bpN != 0x0) delete p_get_BC_bpN ;
99 if (p_get_BC_shift != 0x0) delete p_get_BC_shift ;
100 set_der_0x0() ;
101 }
102
103 void Excision_hor::set_der_0x0() const {
104 p_get_BC_conf_fact = 0x0 ;
105 p_get_BC_bmN = 0x0 ;
106 p_get_BC_bpN = 0x0 ;
107 p_get_BC_shift = 0x0 ;
108
109 }
110
111
112
113 //---------//
114 //Accessors//
115 //---------//
116
117
118
119 // Source for the Neumann BC on the conformal factor
120 const Scalar& Excision_hor::get_BC_conf_fact() const{
121 if (p_get_BC_conf_fact == 0x0){
122 Sym_tensor gamconfcov = gamij.cov()/pow(conf_fact, 4);
123 gamconfcov.std_spectral_base();
124 Metric gamconf(gamconfcov);
125 Vector tilde_s = gamconf.radial_vect();
126 Scalar bound_psi = -((1./conf_fact)*contract((contract(Kij,1,tilde_s,0)),0, tilde_s,0));
127 bound_psi += -conf_fact*tilde_s.divergence(gamconf);
128 bound_psi = 0.25*bound_psi;
129 bound_psi += -contract(conf_fact.derive_cov(gamconf),0,tilde_s,0) + conf_fact.dsdr();
130 bound_psi.std_spectral_base();
131 bound_psi.set_spectral_va().ylm();
132 p_get_BC_conf_fact = new Scalar(bound_psi);
133
134 }
135 return *p_get_BC_conf_fact ;
136 }
137
138
139
140 // Case 0: Source of Dirichlet BC for (b-N), based on an entropy prescription.
141 // WARNING: the argument value has to be carefully fixed w.r.t initial data for (attempted) continuity.
142
143 // Case 1: Source of Dirichlet BC for (b-N), from a component of projected Einstein Equations.
144 // Requires a 2d poisson solver for a non-flat metric.
145
146
147 const Scalar& Excision_hor::get_BC_bmN(int choice_bmN, double value) const{
148 if (p_get_BC_bmN == 0x0){
149
150 switch(choice_bmN){
151
152 case 0 : {
153
154 Scalar thetaminus = sph.theta_minus();
155 Scalar theta_minus3 (lapse.get_mp());
156
157 theta_minus3.allocate_all();
158 theta_minus3.std_spectral_base();
159
160 int nz = (*lapse.get_mp().get_mg()).get_nzone();
161 int nr = (*lapse.get_mp().get_mg()).get_nr(1);
162 int nt = (*lapse.get_mp().get_mg()).get_nt(1);
163 int np = (*lapse.get_mp().get_mg()).get_np(1);
164
165
166 for (int f= 0; f<nz; f++)
167 for (int k=0; k<np; k++)
168 for (int j=0; j<nt; j++) {
169 for (int l=0; l<nr; l++) {
170
171 theta_minus3.set_grid_point(f,k,j,l) = thetaminus.val_grid_point(0,k,j,0);
172
173 }
174 }
175 if (nz >2){
176 theta_minus3.annule_domain(0);
177 theta_minus3.annule_domain(nz - 1);
178 }
179
180
181 Scalar bound_bmN(lapse.get_mp());
182 bound_bmN = - value*theta_minus3; bound_bmN.std_spectral_base();
183 bound_bmN.set_spectral_va().ylm();
184 p_get_BC_bmN = new Scalar(bound_bmN);
185 }
186
187 case 1 : {
188
189 Scalar bound_bmN(lapse.get_mp());
190 bound_bmN.allocate_all();
191 bound_bmN.std_spectral_base();
192
193 // Radial vector for the full 3-metric.
194 Vector sss = gamij.radial_vect();
195 Vector sss_down = sss.up_down(gamij);
196 Scalar bb = contract (shift,0, sss_down,0);
197 Scalar bmN3 = bb - lapse; bmN3.set_spectral_va().ylm();
198 Scalar bpN3 = bb + lapse; bpN3.set_spectral_va().ylm();
199
200 int nt = (*lapse.get_mp().get_mg()).get_nt(1);
201 int np = (*lapse.get_mp().get_mg()).get_np(1);
202
203 Scalar bmN(sph.get_hsurf().get_mp());
204 bmN.allocate_all();
205 bmN.std_spectral_base();
206 bmN.set_spectral_va().ylm();
207 Scalar bpN(sph.get_hsurf().get_mp());
208 bpN.allocate_all();
209 bpN.std_spectral_base();
210 bpN.set_spectral_va().ylm();
211
212 for (int k=0; k<np; k++)
213 for (int j=0; j<nt; j++) {
214
215 bmN.set_grid_point(0,k,j,0) = bmN3.val_grid_point(1,k,j,0);
216 bpN.set_grid_point(0,k,j,0) = bpN3.val_grid_point(1,k,j,0);
217 }
218
219 Scalar bmN_new(bmN.get_mp());
220 bmN_new.allocate_all();
221 bmN_new.std_spectral_base();
222
223 double diff_ent = 1.;
224 double precis = 1.e-9;
225 int mer_max = 200;
226 double relax = 0.;
227 for(int mer=0 ;(diff_ent > precis) && (mer<mer_max) ; mer++) {
228
229 // Calculation of some source terms.
230
231 Scalar hsurf = sph.get_hsurf();
232 hsurf.set_spectral_va().ylm();
233 const Metric_flat& fmets = hsurf.get_mp().flat_met_spher() ;
234
235 Scalar shear_up = sph.shear(); shear_up.up_down(sph.get_qab());
236
237 Scalar B_source = 0.5*contract(contract(sph.shear(),0, shear_up, 0),0,1) + 4.*M_PI*Tij.trace(sph.get_qab()); // Redo the matter terms.
238 Scalar A_source = 0.5*sph.get_ricci() - contract(sph.derive_cov2d(sph.get_ll()), 0, 1) - contract(sph.get_ll(),0, sph.get_ll().up_down(sph.get_qab()),0) - 8.*M_PI*Tij.trace(sph.get_qab()); // Redo the matter terms.
239
240 Scalar op_bmN_add = - 2.*contract(sph.derive_cov2d(bmN),0, sph.get_ll(),0) + A_source*bmN;
241
242 Scalar source_bmN = B_source*bpN - op_bmN_add;
243 source_bmN.set_spectral_va().ylm();
244
245 Scalar sqrtqh2 = sph.sqrt_q()*hsurf*hsurf;
246 sqrtqh2.set_spectral_va().ylm();
247
248 source_bmN = sqrtqh2*source_bmN;
249
250 // Conformal decomposition of the 2-metric
251
252 Sym_tensor qab_con = sph.get_qab().con();
253 qab_con = qab_con/(hsurf*hsurf); // Renormalization due to the triad still not built-in spheroid class
254 //This is provisory work.
255
256 // h^ab as q^ab = (f^ab + h^ab) / sqrt_q
257 Sym_tensor hab =(qab_con*sqrtqh2 - fmets.con()) / (hsurf*hsurf) ;
258 // for the sake of clarity
259 hab.set(1,1) = 1. ;
260 hab.set(1,2) = 0. ;
261 hab.set(1,3) = 0. ;
262 hab.std_spectral_base() ;
263 //end
264 // Complete source for the angular laplacian.
265 Scalar d_bmN = sph.derive_cov2dflat(bmN);
266 d_bmN.set_spectral_va().ylm();
267 Scalar d2_bmN = sph.derive_cov2dflat(d_bmN);
268 d2_bmN.set_spectral_va().ylm();
269
270 Scalar source_add = - hsurf*hsurf*contract(hab, 0,1, d2_bmN, 0,1) + sqrtqh2*contract(contract(qab_con,0,1,sph.delta(),1,2),0,d_bmN,0) ;
271 source_add.set_spectral_va().ylm();
272 source_bmN = source_bmN + source_add;
273 //
274
275 // System inversion
276 bmN_new = source_bmN.poisson_angu(0.);
277
278 // Actualisation of the principal variable, convergence parameter.
279 diff_ent = max(maxabs(bmN - bmN_new));
280
281 bmN = relax*bmN + (1. - relax)*bmN_new;
282
283 }
284 bound_bmN = bmN;
285 bound_bmN.set_spectral_va().ylm();
286 p_get_BC_bmN = new Scalar(bound_bmN);
287 }
288
289 }
290 }
291 return *p_get_BC_bmN ;
292
293 }
294
295
296 // Case 0: Arbitrary Dirichlet BC for (b+N), fixed by a parabolic driver towards a constant value.
297 // Case 1: Source of Dirichlet BC for (b+N), from a component of projected Einstein Equations.
298 const Scalar& Excision_hor::get_BC_bpN(int choice_bpN, double c_bpn_lap, double c_bpn_fin, Scalar *bpN_fin) const{
299 if (p_get_BC_bpN == 0x0){
300
301 switch(choice_bpN) {
302
303 case 0 : {
304
305 Vector sss = gamij.radial_vect();
306 Vector sss_down = sss.up_down(gamij);
307 Scalar bb = contract (shift,0, sss_down,0);
308 Scalar bpN = bb + lapse;
309 Scalar ff = lapse*(c_bpn_lap*bpN.lapang() + c_bpn_fin*(bpN- *bpN_fin));
310 ff.std_spectral_base();
311
312
313 // Definition of k_1
314 Scalar k_1 =delta_t*ff;
315
316 // Intermediate value of b-N, for Runge-Kutta 2nd order scheme
317 Scalar bpN_int = bpN + k_1; bpN_int.std_spectral_base();
318
319 // Recalculation of ff with intermediate values.
320 Scalar ff_int = lapse*(c_bpn_lap*bpN_int.lapang() + c_bpn_fin*bpN_int);
321
322 // Definition of k_2
323 Scalar k_2 = delta_t*ff_int;
324 k_2.std_spectral_base();
325
326 // Result of RK2 evolution
327 Scalar bound_bpN = bpN + k_2;
328 bound_bpN.std_spectral_base();
329 bound_bpN.set_spectral_va().ylm();
330
331 p_get_BC_bpN = new Scalar(bound_bpN);
332
333
334 }
335
336 case 1 : {
337
338
339 int nz = (*lapse.get_mp().get_mg()).get_nzone();
340 int nr = (*lapse.get_mp().get_mg()).get_nr(1);
341 int nt = (*lapse.get_mp().get_mg()).get_nt(1);
342 int np = (*lapse.get_mp().get_mg()).get_np(1);
343
344
345
346 Scalar bmN3 = get_BC_bmN(0, 1.); // change the argument.
347
348 Scalar bmN(sph.get_hsurf().get_mp());
349 bmN.allocate_all();
350 bmN.std_spectral_base();
351 bmN.set_spectral_va().ylm();
352
353
354
355 for (int k=0; k<np; k++)
356 for (int j=0; j<nt; j++) {
357
358
359 bmN.set_grid_point(0,k,j,0) = bmN3.val_grid_point(1,k,j,0);
360
361 }
362
363
364 Scalar bound_bpN(lapse.get_mp());
365 bound_bpN.allocate_all();
366 bound_bpN.std_spectral_base();
367
368 // Definition of source terms in relation (6) of Jaramillo et al. 2007.
369 // All is done on the spheroid of radius r=1.
370
371 Scalar shear_up = sph.shear(); shear_up.up_down(sph.get_qab());
372
373 Scalar B_source = 0.5*contract(contract(sph.shear(),0, shear_up, 0),0,1) + 4.*M_PI*Tij.trace(sph.get_qab()); // Redo the matter terms.
374 Scalar A_source = 0.5*sph.get_ricci() - contract(sph.derive_cov2d(sph.get_ll()), 0, 1) - contract(sph.get_ll(),0, sph.get_ll().up_down(sph.get_qab()),0) - 8.*M_PI*Tij.trace(sph.get_qab()); // Redo the matter terms.
375
376 // Curved 2d Laplacian of (b -N).
377
378 Sym_tensor interlap = sph.derive_cov2d(sph.derive_cov2d(bmN));
379 interlap.up(0,sph.get_qab());
380 Sym_tensor lap_bmN = contract(interlap,0,1);
381
382 Scalar op_bmN = lap_bmN - 2.*contract(sph.derive_cov2d(bmN),0, sph.get_ll(),0) + A_source*bmN;
383
384 Scalar bound_bpN2 = op_bmN/B_source;
385 bound_bpN2.std_spectral_base();
386 bound_bpN2.set_spectral_va().ylm();
387
388
389 for (int f= 0; f<nz; f++)
390 for (int k=0; k<np; k++)
391 for (int j=0; j<nt; j++) {
392 for (int l=0; l<nr; l++) {
393
394 bound_bpN.set_grid_point(f,k,j,l) = bound_bpN2.val_grid_point(0,k,j,0);
395
396 }
397 }
398 if (nz >2){
399 bound_bpN.annule_domain(0);
400 bound_bpN.annule_domain(nz - 1);
401 }
402
403
404
405 p_get_BC_bpN = new Scalar(bound_bpN);
406
407
408 }
409
410 }
411 }
412 return *p_get_BC_bpN ;
413 }
414
415
416
417
418 // Source for the Dirichlet BC on the shift
419 // The tangential shift is fixed using a parabolic driver based on the conformal Killing equation in the dynamical case.
420
421 const Vector& Excision_hor::get_BC_shift( double c_V_lap ) const{
422 if (p_get_BC_shift == 0x0){
423
424 // Radial vector for the full 3-metric.
425 Vector sss = gamij.radial_vect();
426 Vector sss_down = sss.up_down(gamij);
427
428 // // Boundary value for the radial part of the shift: parabolic driver for (b-N)
429 // Scalar bound = lapse ;
430 Scalar bb = 0.5*(*p_get_BC_bpN + *p_get_BC_bmN) ; // TO CHANGE: additional function?-> put choice-bb
431
432
433 // Tangent part of the shift, with parabolic driver
434
435
436 Vector V_par = shift - bb*sss;
437 Sym_tensor q_upup = gamij.con() - sss*sss;
438
439
440 // Calculation of the conformal 2d laplacian of V
441 Tensor q_updown = q_upup.down(1, gamij);
442 Tensor dd_V = V_par.derive_con(gamij);
443 dd_V = contract(q_updown, 1, contract(q_updown,1 ,dd_V, 0), 1);
444 Vector lap_V = contract(q_updown, 1, contract(dd_V.derive_cov(gamij),1,2), 0);
445
446 // 3d interpolation of the Ricci scalar on the surface.
447
448 Scalar ricci2 = sph.get_ricci();
449
450 // Start Mapping interpolation
451
452 Scalar ricci3 (lapse.get_mp());
453
454 ricci3.allocate_all();
455 ricci3.std_spectral_base();
456
457 int nz = (*lapse.get_mp().get_mg()).get_nzone();
458 int nr = (*lapse.get_mp().get_mg()).get_nr(1);
459 int nt = (*lapse.get_mp().get_mg()).get_nt(1);
460 int np = (*lapse.get_mp().get_mg()).get_np(1);
461
462
463 for (int f= 0; f<nz; f++)
464 for (int k=0; k<np; k++)
465 for (int j=0; j<nt; j++) {
466 for (int l=0; l<nr; l++) {
467
468 ricci3.set_grid_point(f,k,j,l) = ricci2.val_grid_point(0,k,j,0);
469
470
471 }
472 }
473 if (nz >2){
474 ricci3.annule_domain(0);
475 ricci3.annule_domain(nz - 1);
476
477 }
478 // End Mapping interpolation
479
480 // Construction of the Ricci COV tensor on the sphere
481
482 Sym_tensor ricci_t = gamij.cov() - sss_down*sss_down;
483 ricci_t = 0.5*ricci3*ricci_t;
484 ricci_t.std_spectral_base();
485
486 Tensor ricci_t_updown = contract(q_upup,0, ricci_t,0);
487
488 // Calculation of ff
489
490 Vector ffV = c_V_lap*lapse*(lap_V + contract(ricci_t_updown,1, V_par,0));
491 ffV.std_spectral_base();
492
493
494 // Definition of k_1
495 Vector k_1V =delta_t*ffV;
496
497 // Intermediate value of Npsi, for Runge-Kutta 2nd order scheme
498 if (nz >2){
499 k_1V.annule_domain(nz-1);
500 } // Patch to avoid dzpuis problems if existent.
501 Vector V_par_int = V_par + k_1V;// V_par_int.std_spectral_base();
502
503 // Recalculation of ff with intermediate values.
504
505 Sym_tensor dd_V_int = V_par_int.derive_con(gamij);
506 dd_V_int = contract(q_updown, 1, contract(q_updown,1 ,dd_V_int, 0), 1);
507 Vector lap_V_int = contract(q_updown, 1, contract(dd_V_int.derive_cov(gamij),1,2), 0);
508
509 Vector ffV_int = c_V_lap*lapse*(lap_V_int + contract(ricci_t_updown,1, V_par_int,0));
510
511 // Definition of k_2
512 Vector k_2V = delta_t*ffV_int;
513 // k_2.std_spectral_base();
514
515 // Result of RK2 evolution
516 if (nz >2){
517 k_2V.annule_domain(nz-1);
518 }
519 Vector bound_V = V_par + k_2V;
520 // bound_V.std_spectral_base();
521
522 // Construction of the total shift boundary condition
523 Vector bound_shift = bb*sss + bound_V;
524 bound_shift.std_spectral_base();
525 p_get_BC_shift = new Vector(bound_shift);
526 }
527 return *p_get_BC_shift ;
528 }
529
530
531
532 void Excision_hor::sauve(FILE* ) const {
533
534 cout << "c'est pas fait!" << endl ;
535 return ;
536
537 }
538 }