LORENE
et_magnetisation_comp.C
1 /*
2  * Computational functions for magnetized rotating equilibrium
3  *
4  * (see file et_rot_mag.h for documentation)
5  *
6  */
7 
8 /*
9  * Copyright (c) 2013 Debarati Chatterjee, Jerome Novak
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 char et_magnetisation_comp_C[] = "$Header: /cvsroot/Lorene/C++/Source/Etoile/et_magnetisation_comp.C,v 1.13 2015/06/12 12:38:25 j_novak Exp $" ;
30 
31 /*
32  * $Id: et_magnetisation_comp.C,v 1.13 2015/06/12 12:38:25 j_novak Exp $
33  * $Log: et_magnetisation_comp.C,v $
34  * Revision 1.13 2015/06/12 12:38:25 j_novak
35  * Implementation of the corrected formula for the quadrupole momentum.
36  *
37  * Revision 1.12 2014/10/21 09:23:54 j_novak
38  * Addition of global functions mass_g(), angu_mom(), grv2/3() and mom_quad().
39  *
40  * Revision 1.11 2014/10/13 08:52:57 j_novak
41  * Lorene classes and functions now belong to the namespace Lorene.
42  *
43  * Revision 1.10 2014/07/04 12:08:02 j_novak
44  * Added some filtering.
45  *
46  * Revision 1.9 2014/05/14 15:19:05 j_novak
47  * The magnetisation field is now filtered.
48  *
49  * Revision 1.8 2014/05/13 15:37:12 j_novak
50  * Updated to new magnetic units.
51  *
52  * Revision 1.7 2014/05/01 13:07:16 j_novak
53  * Fixed two bugs: in the computation of F31,F32 and the triad of U_up.
54  *
55  * Revision 1.6 2014/04/29 13:46:07 j_novak
56  * Addition of switches 'use_B_in_eos' and 'include_magnetisation' to control the model.
57  *
58  * Revision 1.5 2014/04/28 14:53:29 j_novak
59  * Minor modif.
60  *
61  * Revision 1.4 2014/04/28 12:48:13 j_novak
62  * Minor modifications.
63  *
64  * Revision 1.2 2013/12/19 17:05:40 j_novak
65  * Corrected a dzpuis problem.
66  *
67  * Revision 1.1 2013/12/13 16:36:51 j_novak
68  * Addition and computation of magnetisation terms in the Einstein equations.
69  *
70  *
71  *
72  * $Header: /cvsroot/Lorene/C++/Source/Etoile/et_magnetisation_comp.C,v 1.13 2015/06/12 12:38:25 j_novak Exp $
73  *
74  */
75 
76 // Headers C
77 #include <cstdlib>
78 #include <cmath>
79 
80 // Headers Lorene
81 #include "et_rot_mag.h"
82 #include "metric.h"
83 #include "utilitaires.h"
84 #include "param.h"
85 #include "proto_f77.h"
86 #include "unites.h"
87 
88 namespace Lorene {
89 
90  using namespace Unites_mag ;
91 
92 // Algo du papier de 1995
93 
94 void Et_magnetisation::magnet_comput(const int adapt_flag,
95  Cmp (*f_j)(const Cmp&, const double),
96  Param& par_poisson_At,
97  Param& par_poisson_Avect){
98  double relax_mag = 0.5 ;
99 
100  int Z = mp.get_mg()->get_nzone();
101 
102  bool adapt(adapt_flag) ;
103  /****************************************************************
104  * Assertion that all zones have same number of points in theta
105  ****************************************************************/
106  int nt = mp.get_mg()->get_nt(nzet-1) ;
107  for (int l=0; l<Z; l++) assert(mp.get_mg()->get_nt(l) == nt) ;
108 
109  Tbl Rsurf(nt) ;
110  Rsurf.set_etat_qcq() ;
111  mp.r.fait() ;
112  mp.tet.fait() ;
113  Mtbl* theta = mp.tet.c ;
114  const Map_radial* mpr = dynamic_cast<const Map_radial*>(&mp) ;
115  assert (mpr != 0x0) ;
116  for (int j=0; j<nt; j++)
117  Rsurf.set(j) = mpr->val_r_jk(l_surf()(0,j), xi_surf()(0,j), j, 0) ;
118 
119 
120  // Calcul de A_0t dans l'etoile (conducteur parfait)
121 
122  Cmp A_0t(- omega * A_phi) ;
123  A_0t.annule(nzet,Z-1) ;
124 
125  Tenseur ATTENS(A_t) ;
126  Tenseur APTENS(A_phi) ;
127  Tenseur BMN(-logn) ;
128  BMN = BMN + log(bbb) ;
129  BMN.set_std_base() ;
130 
131 
133  nphi.gradient_spher())());
135  nphi.gradient_spher())()) ;
137  BMN.gradient_spher())()
138  + 2*nphi()*flat_scalar_prod_desal(APTENS.gradient_spher(),
139  BMN.gradient_spher())()) ;
140 
141  Cmp ATANT(A_phi.srdsdt()); // Constrction par copie pour mapping
142 
143  ATANT.va = ATANT.va.mult_ct().ssint() ;
144 
145  Cmp ttnphi(tnphi()) ;
146  ttnphi.mult_rsint() ;
147  Cmp BLAH(- b_car()/(nnn()*nnn())*ttnphi*grad1) ;
148  BLAH -= (1+b_car()/(nnn()*nnn())*tnphi()*tnphi())*grad2 ;
149  Cmp nphisr(nphi()) ;
150  nphisr.div_r() ;
151  Cmp npgrada(2*nphisr*(A_phi.dsdr()+ATANT )) ;
152  npgrada.inc2_dzpuis() ;
153  BLAH -= grad3 + npgrada ;
154  Cmp gtt(-nnn()*nnn()+b_car()*tnphi()*tnphi()) ;
155  Cmp gtphi( - b_car()*ttnphi) ;
156 
157  // Computation of j_t thanks to Maxwell-Gauss
158  // modified to include Magnetisation
159  // components of F
160  Cmp F01 = 1/(a_car()*nnn()*nnn())*A_0t.dsdr()
161  + 1/(a_car()*nnn()*nnn())*nphi()*A_phi.dsdr() ;
162 
163  Cmp F02 = 1/(a_car()*nnn()*nnn())*A_0t.srdsdt()
164  + 1/(a_car()*nnn()*nnn())*nphi()*A_phi.srdsdt() ;
165 
166  Cmp tmp = A_phi.dsdr() / (bbb() * bbb() * a_car() );
167  tmp.div_rsint() ;
168  tmp.div_rsint() ;
169  Cmp F31 = 1/(a_car()*nnn()*nnn())*nphi()*nphi()*A_phi.dsdr()
170  + 1/(a_car()*nnn()*nnn())*nphi()*A_0t.dsdr()
171  + tmp ;
172 
173  tmp = A_phi.srdsdt() / (bbb() * bbb() * a_car() );
174  tmp.div_rsint() ;
175  tmp.div_rsint() ;
176  Cmp F32 = 1/(a_car()*nnn()*nnn())*nphi()*nphi()*A_phi.srdsdt()
177  + 1/(a_car()*nnn()*nnn())*nphi()*A_0t.srdsdt()
178  + tmp ;
179 
180  Cmp x = get_magnetisation();
181  Cmp one_minus_x = 1 - x ;
182  one_minus_x.std_base_scal() ;
183 
184  tmp = ((BLAH - A_0t.laplacien())*one_minus_x/a_car()
185  - gtphi*j_phi
186  - gtt*(F01*x.dsdr()+F02*x.srdsdt())
187  - gtphi*(F31*x.dsdr()+F32*x.srdsdt()) ) / gtt ;
188 
189  tmp.annule(nzet, Z-1) ;
190  if (adapt) {
191  j_t = tmp ;
192  }
193  else {
194  j_t.allocate_all() ;
195  for (int j=0; j<nt; j++)
196  for (int l=0; l<nzet; l++)
197  for (int i=0; i<mp.get_mg()->get_nr(l); i++)
198  j_t.set(l,0,j,i) = ( (*mp.r.c)(l,0,j,i) > Rsurf(j) ?
199  0. : tmp(l,0,j,i) ) ;
200  j_t.annule(nzet,Z-1) ;
201  }
202  j_t.std_base_scal() ;
203 
204  // Calcul du courant j_phi
205  j_phi = omega * j_t + (ener() + press())*f_j(A_phi, a_j) ;
206  j_phi.std_base_scal() ;
207 
208  // Resolution de Maxwell Ampere (-> A_phi)
209  // Calcul des termes sources avec A-t du pas precedent.
210 
212  BMN.gradient_spher())());
213 
214  Tenseur source_tAphi(mp, 1, CON, mp.get_bvect_spher()) ;
215 
216  source_tAphi.set_etat_qcq() ;
217  Cmp tjphi(j_phi) ;
218  tjphi.mult_rsint() ;
219  Cmp tgrad1(grad1) ;
220  tgrad1.mult_rsint() ;
221  Cmp d_grad4(grad4) ;
222  d_grad4.div_rsint() ;
223  source_tAphi.set(0)=0 ;
224  source_tAphi.set(1)=0 ;
225 
226 // modified to include Magnetisation
227  Cmp phifac = (F31-nphi()*F01)*x.dsdr()
228  + (F32-nphi()*F02)*x.srdsdt() ;
229  phifac.mult_rsint();
230  source_tAphi.set(2)= -b_car()*a_car()/one_minus_x
231  *(tjphi-tnphi()*j_t + phifac)
232  + b_car()/(nnn()*nnn())*(tgrad1+tnphi()*grad2)
233  + d_grad4 ;
234 
235  source_tAphi.change_triad(mp.get_bvect_cart());
236 
237  // Filtering
238  for (int i=0; i<3; i++) {
239  Scalar tmp_filter = source_tAphi(i) ;
240  tmp_filter.exponential_filter_r(0, 2, 1) ;
241  tmp_filter.exponential_filter_ylm(0, 2, 1) ;
242  source_tAphi.set(i) = tmp_filter ;
243  }
244 
245  Tenseur WORK_VECT(mp, 1, CON, mp.get_bvect_cart()) ;
246  WORK_VECT.set_etat_qcq() ;
247  for (int i=0; i<3; i++) {
248  WORK_VECT.set(i) = 0 ;
249  }
250  Tenseur WORK_SCAL(mp) ;
251  WORK_SCAL.set_etat_qcq() ;
252  WORK_SCAL.set() = 0 ;
253 
254  double lambda_mag = 0. ; // No 3D version !
255 
256  Tenseur AVECT(source_tAphi) ;
257  if (source_tAphi.get_etat() != ETATZERO) {
258 
259  for (int i=0; i<3; i++) {
260  if(source_tAphi(i).dz_nonzero()) {
261  assert( source_tAphi(i).get_dzpuis() == 4 ) ;
262  }
263  else{
264  (source_tAphi.set(i)).set_dzpuis(4) ;
265  }
266  }
267 
268  }
269 
270  source_tAphi.poisson_vect(lambda_mag, par_poisson_Avect, AVECT, WORK_VECT,
271  WORK_SCAL) ;
272  AVECT.change_triad(mp.get_bvect_spher());
273  Cmp A_phi_n(AVECT(2));
274  A_phi_n.mult_rsint() ;
275 
276  // Solution to Maxwell-Ampere : A_1
277  // modified to include Magnetisation
278  Cmp source_A_1t(-a_car()*( j_t*gtt + j_phi*gtphi
279  + gtt*(F01*x.dsdr()+F02*x.srdsdt())
280  + gtphi*(F31*x.dsdr()+F32*x.srdsdt()) )/one_minus_x
281  + BLAH);
282  Scalar tmp_filter = source_A_1t ;
283  tmp_filter.exponential_filter_r(0, 2, 1) ;
284  tmp_filter.exponential_filter_ylm(0, 2, 1) ;
285  source_A_1t = tmp_filter ;
286 
287  Cmp A_1t(mp);
288  A_1t = 0 ;
289  source_A_1t.poisson(par_poisson_At, A_1t) ;
290 
291  int L = mp.get_mg()->get_nt(0);
292 
293  Tbl MAT(L,L) ;
294  Tbl MAT_PHI(L,L);
295  Tbl VEC(L) ;
296 
297  MAT.set_etat_qcq() ;
298  VEC.set_etat_qcq() ;
299  MAT_PHI.set_etat_qcq() ;
300 
301  Tbl leg(L,2*L) ;
302  leg.set_etat_qcq() ;
303 
304  Cmp psi(mp);
305  Cmp psi2(mp);
306  psi.allocate_all() ;
307  psi2.allocate_all() ;
308 
309  for (int p=0; p<mp.get_mg()->get_np(0); p++) {
310  // leg[k,l] : legendre_l(cos(theta_k))
311  // Construction par recurrence de degre 2
312  for(int k=0;k<L;k++){
313  for(int l=0;l<2*L;l++){
314 
315  if(l==0) leg.set(k,l)=1. ;
316  if(l==1) leg.set(k,l)=cos((*theta)(l_surf()(p,k),p,k,0)) ;
317  if(l>=2) leg.set(k,l) = double(2*l-1)/double(l)
318  * cos((*theta)(l_surf()(p,k),p,k,0))
319  * leg(k,l-1)-double(l-1)/double(l)*leg(k,l-2) ;
320  }
321  }
322 
323  for(int k=0;k<L;k++){
324 
325  // Valeurs a la surface trouvees via va.val_point_jk(l,xisurf,k,p)
326 
327  VEC.set(k) = A_0t.va.val_point_jk(l_surf()(p,k), xi_surf()(p,k), k, p)
328  -A_1t.va.val_point_jk(l_surf()(p,k), xi_surf()(p,k), k, p);
329 
330  for(int l=0;l<L;l++) MAT.set(l,k) = leg(k,2*l)/pow(Rsurf(k),2*l+1);
331 
332  }
333  // appel fortran :
334 
335  int* IPIV=new int[L] ;
336  int INFO ;
337 
338  Tbl MAT_SAVE(MAT) ;
339  Tbl VEC2(L) ;
340  VEC2.set_etat_qcq() ;
341  int un = 1 ;
342 
343  F77_dgesv(&L, &un, MAT.t, &L, IPIV, VEC.t, &L, &INFO) ;
344 
345  // coeffs a_l dans VEC
346 
347  for(int k=0;k<L;k++) {VEC2.set(k)=1. ; }
348 
349  F77_dgesv(&L, &un, MAT_SAVE.t, &L, IPIV, VEC2.t, &L, &INFO) ;
350 
351  delete [] IPIV ;
352 
353  for(int nz=0;nz < Z; nz++){
354  for(int i=0;i< mp.get_mg()->get_nr(nz);i++){
355  for(int k=0;k<L;k++){
356  psi.set(nz,p,k,i) = 0. ;
357  psi2.set(nz,p,k,i) = 0. ;
358  for(int l=0;l<L;l++){
359  psi.set(nz,p,k,i) += VEC(l)*leg(k,2*l) /
360  pow((*mp.r.c)(nz,p,k,i),2*l+1);
361  psi2.set(nz,p,k,i) += VEC2(l)*leg(k,2*l)/
362  pow((*mp.r.c)(nz, p, k,i),2*l+1);
363  }
364  }
365  }
366  }
367  }
368  psi.std_base_scal() ;
369  psi2.std_base_scal() ;
370 
371  assert(psi.get_dzpuis() == 0) ;
372  int dif = A_1t.get_dzpuis() ;
373  if (dif > 0) {
374  for (int d=0; d<dif; d++) A_1t.dec_dzpuis() ;
375  }
376 
377  if (adapt) {
378  Cmp A_t_ext(A_1t + psi) ;
379  A_t_ext.annule(0,nzet-1) ;
380  A_0t += A_t_ext ;
381  }
382  else {
383  tmp = A_0t ;
384  A_0t.allocate_all() ;
385  for (int j=0; j<nt; j++)
386  for (int l=0; l<Z; l++)
387  for (int i=0; i<mp.get_mg()->get_nr(l); i++)
388  A_0t.set(l,0,j,i) = ( (*mp.r.c)(l,0,j,i) > Rsurf(j) ?
389  A_1t(l,0,j,i) + psi(l,0,j,i) : tmp(l,0,j,i) ) ;
390  }
391  A_0t.std_base_scal() ;
392 
393  tmp_filter = A_0t ;
394  tmp_filter.exponential_filter_r(0, 2, 1) ;
395  tmp_filter.exponential_filter_ylm(0, 2, 1) ;
396  A_0t = tmp_filter ;
397 
398  Valeur** asymp = A_0t.asymptot(1) ;
399 
400  double Q_0 = -4*M_PI*(*asymp[1])(Z-1,0,0,0) ; // utilise A_0t plutot que E
401  delete asymp[0] ;
402  delete asymp[1] ;
403 
404  delete [] asymp ;
405 
406  asymp = psi2.asymptot(1) ;
407 
408  double Q_2 = -4*M_PI*(*asymp[1])(Z-1,0,0,0) ; // A_2t = psi2 a l'infini
409  delete asymp[0] ;
410  delete asymp[1] ;
411 
412  delete [] asymp ;
413 
414  // solution definitive de A_t:
415 
416  double C = (Q-Q_0)/Q_2 ;
417 
418  assert(psi2.get_dzpuis() == 0) ;
419  dif = A_0t.get_dzpuis() ;
420  if (dif > 0) {
421  for (int d=0; d<dif; d++) A_0t.dec_dzpuis() ;
422  }
423  Cmp A_t_n(mp) ;
424  if (adapt) {
425  A_t_n = A_0t + C ;
426  Cmp A_t_ext(A_0t + C*psi2) ;
427  A_t_ext.annule(0,nzet-1) ;
428  A_t_n.annule(nzet,Z-1) ;
429  A_t_n += A_t_ext ;
430  }
431  else {
432  A_t_n.allocate_all() ;
433  for (int j=0; j<nt; j++)
434  for (int l=0; l<Z; l++)
435  for (int i=0; i<mp.get_mg()->get_nr(l); i++)
436  A_t_n.set(l,0,j,i) = ( (*mp.r.c)(l,0,j,i) > Rsurf(j) ?
437  A_0t(l,0,j,i) + C*psi2(l,0,j,i) :
438  A_0t(l,0,j,i) + C ) ;
439  }
440  A_t_n.std_base_scal() ;
441  tmp_filter = A_t_n ;
442  tmp_filter.exponential_filter_r(0, 2, 1) ;
443  tmp_filter.exponential_filter_ylm(0, 2, 1) ;
444  A_t_n = tmp_filter ;
445 
446  asymp = A_t_n.asymptot(1) ;
447 
448  delete asymp[0] ;
449  delete asymp[1] ;
450 
451  delete [] asymp ;
452  A_t = relax_mag*A_t_n + (1.-relax_mag)*A_t ;
453  A_phi = relax_mag*A_phi_n + (1. - relax_mag)*A_phi ;
454 
455 }
456 
457 
459  // Computes the E-M terms of the stress-energy tensor...
460 
461  Tenseur ATTENS(A_t) ;
462 
463  Tenseur APTENS(A_phi) ;
464 
466  APTENS.gradient_spher())() );
468  ATTENS.gradient_spher())() );
470  ATTENS.gradient_spher())() );
471 
472  if (ApAp.get_etat() != ETATZERO) {
473  ApAp.set().div_rsint() ;
474  ApAp.set().div_rsint() ;
475  }
476  if (ApAt.get_etat() != ETATZERO)
477  ApAt.set().div_rsint() ;
478 
479  E_em = 0.5*mu0 * ( 1/(a_car*nnn*nnn) * (AtAt + 2*tnphi*ApAt)
480  + ( (tnphi*tnphi/(a_car*nnn*nnn)) + 1/(a_car*b_car) )*ApAp );
481  Jp_em = -mu0 * (ApAt + tnphi*ApAp) /(a_car*nnn) ;
482  if (Jp_em.get_etat() != ETATZERO) Jp_em.set().mult_rsint() ;
483  Srr_em = 0 ;
484  // Stt_em = -Srr_em
485  Spp_em = E_em ;
486 
487  // ... and those corresponding to the magnetization.
488  Tenseur Efield = Elec() ;
489  Tenseur Bfield = Magn() ;
490 
491  Scalar EiEi ( flat_scalar_prod(Efield, Efield)() ) ;
492  Scalar BiBi ( flat_scalar_prod(Bfield, Bfield)() ) ;
493 
494  Vector U_up(mp, CON, mp.get_bvect_cart()) ;
495  for (int i=1; i<=3; i++)
496  U_up.set(i) = u_euler(i-1) ;
497  U_up.change_triad(mp.get_bvect_spher()) ;
498 
499  Sym_tensor gamij(mp, COV, mp.get_bvect_spher()) ;
500  for (int i=1; i<=3; i++)
501  for (int j=1; j<i; j++) {
502  gamij.set(i,j) = 0 ;
503  }
504  gamij.set(1,1) = a_car() ;
505  gamij.set(2,2) = a_car() ;
506  gamij.set(3,3) = b_car() ;
507  Metric met(gamij) ;
508  Vector Ui = U_up.down(0, met) ;
509 
510  Scalar fac = sqrt(a_car()) ;
511  Vector B_up(mp, CON, mp.get_bvect_spher()) ;
512  B_up.set(1) = Scalar(Bfield(0)) / fac ;
513  B_up.set(2) = Scalar(Bfield(1)) / fac ;
514  B_up.set(3) = 0 ;
515  Vector Bi = B_up.down(0, met) ;
516 
517  fac = Scalar(gam_euler()*gam_euler()) ;
518 
519  E_I = get_magnetisation() * EiEi / mu0 ;
520 
521  J_I = get_magnetisation() * BiBi * Ui / mu0 ;
522  Sij_I = get_magnetisation()
523  * ( (BiBi / fac) * gamij + BiBi*Ui*Ui - Bi*Bi / fac ) / mu0 ;
524 
525  for (int i=1; i<=3; i++)
526  for (int j=i; j<=3; j++)
527  Sij_I.set(i,j).set_dzpuis(0) ;
528 
529 }
530 
531  //----------------------------//
532  // Gravitational mass //
533  //----------------------------//
534 
535 double Et_magnetisation::mass_g() const {
536 
537  if (p_mass_g == 0x0) { // a new computation is required
538 
539  if (relativistic) {
540 
541  // Magnetisation: S_{rr} + S_{\theta\theta}
542  Tenseur SrrplusStt( Cmp(Sij_I(1, 1) + Sij_I(2, 2)) ) ;
543  SrrplusStt = SrrplusStt / a_car ; // S^r_r + S^\theta_\theta
544 
545  Tenseur Spp (Cmp(Sij_I(3, 3))) ; // Magnetisation: S_{\phi\phi}
546  Spp = Spp / b_car ; // S^\phi_\phi
547 
548  Cmp temp(E_I) ;
549  Tenseur E_i (temp) ;
550  Tenseur J_i (Cmp(J_I(3))) ;
551 
552  Tenseur source = nnn * (ener_euler + E_em + E_i
553  + s_euler + Spp_em + SrrplusStt + Spp) +
554  nphi * (Jp_em + J_i)
555  + 2 * bbb * (ener_euler + press) * tnphi * uuu ;
556 
557  source = a_car * bbb * source ;
558 
559  source.set_std_base() ;
560 
561  p_mass_g = new double( source().integrale() ) ;
562 
563 
564  }
565  else{ // Newtonian case
566  p_mass_g = new double( mass_b() ) ; // in the Newtonian case
567  // M_g = M_b
568  }
569  }
570 
571  return *p_mass_g ;
572 
573 }
574 
575  //----------------------------//
576  // Angular momentum //
577  //----------------------------//
578 
580 
581  if (p_angu_mom == 0x0) { // a new computation is required
582 
583  Cmp dens = uuu() ;
584 
585  dens.mult_r() ; // Multiplication by
586  dens.va = (dens.va).mult_st() ; // r sin(theta)
587 
588  if (relativistic) {
589  dens = a_car() * (b_car() * (ener_euler() + press())
590  * dens + bbb() * (Jp_em() + Cmp(J_I(3)) ) ) ;
591  }
592  else { // Newtonian case
593  dens = nbar() * dens ;
594  }
595 
596  dens.std_base_scal() ;
597 
598  p_angu_mom = new double( dens.integrale() ) ;
599 
600  }
601 
602  return *p_angu_mom ;
603 
604 }
605 
606  //----------------------------//
607  // GRV2 //
608  //----------------------------//
609 
610 double Et_magnetisation::grv2() const {
611 
612  if (p_grv2 == 0x0) { // a new computation is required
613 
614  // To get qpig:
615  using namespace Unites ;
616 
617  Tenseur Spp (Cmp(Sij_I(3, 3))) ; //S_{\phi\phi}
618  Spp = Spp / b_car ; // S^\phi_\phi
619 
620  Tenseur sou_m = 2 * qpig * a_car * (press + (ener_euler+press)
621  * uuu*uuu + Spp) ;
622 
623  Tenseur sou_q = 2 * qpig * a_car * Spp_em + 1.5 * ak_car
624  - flat_scalar_prod(logn.gradient_spher(), logn.gradient_spher() ) ;
625 
626  p_grv2 = new double( double(1) - lambda_grv2(sou_m(), sou_q()) ) ;
627 
628  }
629 
630  return *p_grv2 ;
631 
632 }
633 
634 
635  //----------------------------//
636  // GRV3 //
637  //----------------------------//
638 
639 double Et_magnetisation::grv3(ostream* ost) const {
640 
641  if (p_grv3 == 0x0) { // a new computation is required
642 
643  // To get qpig:
644  using namespace Unites ;
645 
646  Tenseur source(mp) ;
647 
648  // Gravitational term [cf. Eq. (43) of Gourgoulhon & Bonazzola
649  // ------------------ Class. Quantum Grav. 11, 443 (1994)]
650 
651  if (relativistic) {
652  Tenseur alpha = dzeta - logn ;
653  Tenseur beta = log( bbb ) ;
654  beta.set_std_base() ;
655 
656  source = 0.75 * ak_car
657  - flat_scalar_prod(logn.gradient_spher(),
658  logn.gradient_spher() )
659  + 0.5 * flat_scalar_prod(alpha.gradient_spher(),
660  beta.gradient_spher() ) ;
661 
662  Cmp aa = alpha() - 0.5 * beta() ;
663  Cmp daadt = aa.srdsdt() ; // 1/r d/dth
664 
665  // What follows is valid only for a mapping of class Map_radial :
666  const Map_radial* mpr = dynamic_cast<const Map_radial*>(&mp) ;
667  if (mpr == 0x0) {
668  cout << "Etoile_rot::grv3: the mapping does not belong"
669  << " to the class Map_radial !" << endl ;
670  abort() ;
671  }
672 
673  // Computation of 1/tan(theta) * 1/r daa/dtheta
674  if (daadt.get_etat() == ETATQCQ) {
675  Valeur& vdaadt = daadt.va ;
676  vdaadt = vdaadt.ssint() ; // division by sin(theta)
677  vdaadt = vdaadt.mult_ct() ; // multiplication by cos(theta)
678  }
679 
680  Cmp temp = aa.dsdr() + daadt ;
681  temp = ( bbb() - a_car()/bbb() ) * temp ;
682  temp.std_base_scal() ;
683 
684  // Division by r
685  Valeur& vtemp = temp.va ;
686  vtemp = vtemp.sx() ; // division by xi in the nucleus
687  // Id in the shells
688  // division by xi-1 in the ZEC
689  vtemp = (mpr->xsr) * vtemp ; // multiplication by xi/r in the nucleus
690  // by 1/r in the shells
691  // by r(xi-1) in the ZEC
692 
693  // In the ZEC, a multiplication by r has been performed instead
694  // of the division:
695  temp.set_dzpuis( temp.get_dzpuis() + 2 ) ;
696 
697  source = bbb() * source() + 0.5 * temp ;
698 
699  }
700  else{
701  source = - 0.5 * flat_scalar_prod(logn.gradient_spher(),
702  logn.gradient_spher() ) ;
703  }
704 
705  source.set_std_base() ;
706 
707  double int_grav = source().integrale() ;
708 
709  // Matter term
710  // -----------
711 
712  if (relativistic) {
713 
714  // S_{rr} + S_{\theta\theta}
715  Tenseur SrrplusStt( Cmp(Sij_I(1, 1) + Sij_I(2, 2)) ) ;
716  SrrplusStt = SrrplusStt / a_car ; // S^r_r + S^\theta_\theta
717 
718  Tenseur Spp (Cmp(Sij_I(3, 3))) ; //S_{\phi\phi}
719  Spp = Spp / b_car ; // S^\phi_\phi
720 
721  source = qpig * a_car * bbb * ( s_euler + Spp_em + SrrplusStt + Spp ) ;
722  }
723  else{
724  source = qpig * ( 3 * press + nbar * uuu * uuu ) ;
725  }
726 
727  source.set_std_base() ;
728 
729  double int_mat = source().integrale() ;
730 
731  // Virial error
732  // ------------
733  if (ost != 0x0) {
734  *ost << "Et_magnetisation::grv3 : gravitational term : " << int_grav
735  << endl ;
736  *ost << "Et_magnetisation::grv3 : matter term : " << int_mat
737  << endl ;
738  }
739 
740  p_grv3 = new double( (int_grav + int_mat) / int_mat ) ;
741 
742  }
743 
744  return *p_grv3 ;
745 
746 }
747 
748  //----------------------------//
749  // Quadrupole moment //
750  //----------------------------//
751 
753 
754  if (p_mom_quad_old == 0x0) { // a new computation is required
755 
756  // To get qpig:
757  using namespace Unites ;
758 
759  // Source for of the Poisson equation for nu
760  // -----------------------------------------
761 
762  Tenseur source(mp) ;
763 
764  if (relativistic) {
765  // S_{rr} + S_{\theta\theta}
766  Tenseur SrrplusStt( Cmp(Sij_I(1, 1) + Sij_I(2, 2)) ) ;
767  SrrplusStt = SrrplusStt / a_car ; // S^r_r + S^\theta_\theta
768 
769  Tenseur Spp (Cmp(Sij_I(3, 3))) ; //S_{\phi\phi}
770  Spp = Spp / b_car ; // S^\phi_\phi
771 
772  Cmp temp(E_I) ;
773  Tenseur E_i(temp) ;
774 
775  Tenseur beta = log(bbb) ;
776  beta.set_std_base() ;
777  source = qpig * a_car *( ener_euler + E_em + E_i
778  + s_euler + Spp_em + SrrplusStt + Spp)
779  + ak_car - flat_scalar_prod(logn.gradient_spher(),
780  logn.gradient_spher() + beta.gradient_spher()) ;
781  }
782  else {
783  source = qpig * nbar ;
784  }
785  source.set_std_base() ;
786 
787  // Multiplication by -r^2 P_2(cos(theta))
788  // [cf Eq.(7) of Salgado et al. Astron. Astrophys. 291, 155 (1994) ]
789  // ------------------------------------------------------------------
790 
791  // Multiplication by r^2 :
792  // ----------------------
793  Cmp& csource = source.set() ;
794  csource.mult_r() ;
795  csource.mult_r() ;
796  if (csource.check_dzpuis(2)) {
797  csource.inc2_dzpuis() ;
798  }
799 
800  // Muliplication by cos^2(theta) :
801  // -----------------------------
802  Cmp temp = csource ;
803 
804  // What follows is valid only for a mapping of class Map_radial :
805  assert( dynamic_cast<const Map_radial*>(&mp) != 0x0 ) ;
806 
807  if (temp.get_etat() == ETATQCQ) {
808  Valeur& vtemp = temp.va ;
809  vtemp = vtemp.mult_ct() ; // multiplication by cos(theta)
810  vtemp = vtemp.mult_ct() ; // multiplication by cos(theta)
811  }
812 
813  // Muliplication by -P_2(cos(theta)) :
814  // ----------------------------------
815  source = 0.5 * source() - 1.5 * temp ;
816 
817  // Final result
818  // ------------
819  p_mom_quad_old = new double( source().integrale() / qpig ) ;
820  }
821  return *p_mom_quad_old ;
822  }
823 
824 
826 
827  using namespace Unites ;
828 
829  if (p_mom_quad_Bo == 0x0) { // a new computation is required
830 
831  // S_{rr} + S_{\theta\theta} = A^2*(S^r_r + S^\theta_\theta)
832  Tenseur SrrplusStt( Cmp(Sij_I(1, 1) + Sij_I(2, 2)) ) ;
833 
834  Cmp dens = a_car() * press() ;
835  dens = bbb() * nnn() * (SrrplusStt() + 2*dens) ;
836  dens.mult_rsint() ;
837  dens.std_base_scal() ;
838 
839  p_mom_quad_Bo = new double( - 16. * dens.integrale() / qpig ) ;
840  }
841  return *p_mom_quad_Bo ;
842  }
843 
844 
845 
846 }
const Cmp & dsdr() const
Returns of *this .
Definition: cmp_deriv.C:84
Metric for tensor calculation.
Definition: metric.h:90
virtual double mom_quad_Bo() const
Part of the quadrupole moment.
Cmp log(const Cmp &)
Neperian logarithm.
Definition: cmp_math.C:296
Component of a tensorial field *** DEPRECATED : use class Scalar instead ***.
Definition: cmp.h:443
const Tenseur & gradient_spher() const
Returns the gradient of *this (Spherical coordinates) (scalar field only).
Definition: tenseur.C:1548
Cmp sqrt(const Cmp &)
Square root.
Definition: cmp_math.C:220
void dec_dzpuis()
Decreases by 1 the value of dzpuis and changes accordingly the values of the Cmp in the external comp...
Definition: cmp_r_manip.C:154
void annule(int l)
Sets the Cmp to zero in a given domain.
Definition: cmp.C:348
void set_std_base()
Set the standard spectal basis of decomposition for each component.
Definition: tenseur.C:1170
Multi-domain array.
Definition: mtbl.h:118
Lorene prototypes.
Definition: app_hor.h:64
Standard units of space, time and mass.
int get_etat() const
Returns the logical state.
Definition: cmp.h:896
double & set(int i)
Read/write of a particular element (index i) (1D case)
Definition: tbl.h:281
Tensor field of valence 0 (or component of a tensorial field).
Definition: scalar.h:387
Tenseur flat_scalar_prod(const Tenseur &t1, const Tenseur &t2)
Scalar product of two Tenseur when the metric is : performs the contraction of the last index of t1 w...
const Cmp & srdsdt() const
Returns of *this .
Definition: cmp_deriv.C:105
const Valeur & sx() const
Returns (r -sampling = RARE ) \ Id (r sampling = FIN ) \ (r -sampling = UNSURR ) ...
Definition: valeur_sx.C:110
virtual void exponential_filter_r(int lzmin, int lzmax, int p, double alpha=-16.)
Applies an exponential filter to the spectral coefficients in the radial direction.
Values and coefficients of a (real-value) function.
Definition: valeur.h:287
Tensor field of valence 1.
Definition: vector.h:188
Cmp cos(const Cmp &)
Cosine.
Definition: cmp_math.C:94
void div_r()
Division by r everywhere.
Definition: cmp_r_manip.C:78
void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
Definition: tbl.C:361
virtual double angu_mom() const
Angular momentum.
void mult_r()
Multiplication by r everywhere.
Definition: cmp_r_manip.C:91
Cmp & set()
Read/write for a scalar (see also operator=(const Cmp&) ).
Definition: tenseur.C:824
void change_triad(const Base_vect &new_triad)
Sets a new vectorial basis (triad) of decomposition and modifies the components accordingly.
Definition: tenseur.C:668
Tenseur flat_scalar_prod_desal(const Tenseur &t1, const Tenseur &t2)
Same as flat_scalar_prod but with desaliasing.
const Valeur & ssint() const
Returns of *this.
Definition: valeur_ssint.C:112
double * t
The array of double.
Definition: tbl.h:173
Parameter storage.
Definition: param.h:125
Base class for pure radial mappings.
Definition: map.h:1536
void mult_rsint()
Multiplication by .
Definition: cmp_r_manip.C:116
virtual double val_r_jk(int l, double xi, int j, int k) const =0
Returns the value of the radial coordinate r for a given and a given collocation point in in a give...
double integrale() const
Computes the integral over all space of *this .
Definition: cmp_integ.C:55
double val_point_jk(int l, double x, int j, int k) const
Computes the value of the field represented by *this at an arbitrary point in , but collocation point...
Definition: valeur.C:900
Coord xsr
in the nucleus; \ 1/R in the non-compactified shells; \ in the compactified outer domain...
Definition: map.h:1549
Cmp pow(const Cmp &, int)
Power .
Definition: cmp_math.C:348
void inc2_dzpuis()
Increases by 2 the value of dzpuis and changes accordingly the values of the Cmp in the external comp...
Definition: cmp_r_manip.C:192
void std_base_scal()
Sets the spectral bases of the Valeur va to the standard ones for a scalar.
Definition: cmp.C:644
virtual double mom_quad_old() const
Part of the quadrupole moment.
Cmp poisson() const
Solves the scalar Poisson equation with *this as a source.
Definition: cmp_pde.C:94
virtual double grv2() const
Error on the virial identity GRV2.
void allocate_all()
Sets the logical state to ETATQCQ (ordinary state) and performs the memory allocation of all the elem...
Definition: cmp.C:323
Tbl & set(int l)
Read/write of the value in a given domain.
Definition: cmp.h:721
int get_dzpuis() const
Returns dzpuis.
Definition: cmp.h:900
Scalar & set(const Itbl &ind)
Returns the value of a component (read/write version).
Definition: tensor.C:654
virtual void magnet_comput(const int adapt_flag, Cmp(*f_j)(const Cmp &x, const double), Param &par_poisson_At, Param &par_poisson_Avect)
Computes the electromagnetic quantities solving the Maxwell equations (6) and (7) of [Bocquet...
bool check_dzpuis(int dzi) const
Returns false if the last domain is compactified and *this is not zero in this domain and dzpuis is n...
Definition: cmp.C:715
virtual double mass_g() const
Gravitational mass.
Valeur ** asymptot(int n, const int flag=0) const
Asymptotic expansion at r = infinity.
Definition: cmp_asymptot.C:71
const Valeur & mult_ct() const
Returns applied to *this.
virtual double grv3(ostream *ost=0x0) const
Error on the virial identity GRV3.
void set_dzpuis(int)
Set a value to dzpuis.
Definition: cmp.C:654
Basic array class.
Definition: tbl.h:161
Scalar & set(int)
Read/write access to a component.
Definition: vector.C:296
void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
Definition: tenseur.C:636
virtual void exponential_filter_ylm(int lzmin, int lzmax, int p, double alpha=-16.)
Applies an exponential filter to the spectral coefficients in the angular directions.
const Cmp & laplacien(int zec_mult_r=4) const
Returns the Laplacian of *this.
Definition: cmp_deriv.C:242
Valeur va
The numerical value of the Cmp.
Definition: cmp.h:461
Class intended to describe valence-2 symmetric tensors.
Definition: sym_tensor.h:223
Standard electro-magnetic units.
Tensor handling *** DEPRECATED : use class Tensor instead ***.
Definition: tenseur.h:298
virtual void MHD_comput()
Computes the electromagnetic part of the stress-energy tensor.
Tensor down(int ind, const Metric &gam) const
Computes a new tensor by lowering an index of *this.