Debian Codegraph @

C++/Source/Etoile/et_rot_mag_mag.C

raw
1 /*
2 * Computes magnetic fields and derived quantities for rotating equilibrium
3 *
4 * (see file et_rot_mag.h for documentation)
5 *
6 */
7
8 /*
9 * Copyright (c) 2002 Emmanuel Marcq
10 * Copyright (c) 2002 Jerome Novak
11 *
12 * This file is part of LORENE.
13 *
14 * LORENE is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * LORENE is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with LORENE; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 *
28 */
29
30 char et_rot_mag_mag_C[] = "$Header: /cvsroot/Lorene/C++/Source/Etoile/et_rot_mag_mag.C,v 1.17 2014/10/13 08:52:58 j_novak Exp $" ;
31
32 /*
33 * $Id: et_rot_mag_mag.C,v 1.17 2014/10/13 08:52:58 j_novak Exp $
34 * $Log: et_rot_mag_mag.C,v $
35 * Revision 1.17 2014/10/13 08:52:58 j_novak
36 * Lorene classes and functions now belong to the namespace Lorene.
37 *
38 * Revision 1.16 2014/09/03 15:33:42 j_novak
39 * Filtering of Maxwell sources is now optional.
40 *
41 * Revision 1.15 2014/07/04 12:15:12 j_novak
42 * Added filtering.
43 *
44 * Revision 1.14 2005/06/03 15:31:56 j_novak
45 * Better computation when more than one point in phi.
46 *
47 * Revision 1.13 2003/10/03 15:58:47 j_novak
48 * Cleaning of some headers
49 *
50 * Revision 1.12 2002/09/09 13:00:39 e_gourgoulhon
51 * Modification of declaration of Fortran 77 prototypes for
52 * a better portability (in particular on IBM AIX systems):
53 * All Fortran subroutine names are now written F77_* and are
54 * defined in the new file C++/Include/proto_f77.h.
55 *
56 * Revision 1.11 2002/06/05 15:15:59 j_novak
57 * The case of non-adapted mapping is treated.
58 * parmag.d and parrot.d have been merged.
59 *
60 * Revision 1.10 2002/06/03 13:23:16 j_novak
61 * The case when the mapping is not adapted is now treated
62 *
63 * Revision 1.9 2002/06/03 13:00:45 e_marcq
64 *
65 * conduc parameter read in parmag.d
66 *
67 * Revision 1.7 2002/05/20 10:31:59 j_novak
68 * *** empty log message ***
69 *
70 * Revision 1.6 2002/05/17 15:08:01 e_marcq
71 *
72 * Rotation progressive plug-in, units corrected, Q and a_j new member data
73 *
74 * Revision 1.5 2002/05/16 10:02:09 j_novak
75 * Errors in stress energy tensor corrected
76 *
77 * Revision 1.4 2002/05/15 09:54:00 j_novak
78 * First operational version
79 *
80 * Revision 1.3 2002/05/14 13:38:36 e_marcq
81 *
82 *
83 * Unit update, new outputs
84 *
85 * Revision 1.1 2002/05/10 09:26:52 j_novak
86 * Added new class Et_rot_mag for magnetized rotating neutron stars (under development)
87 *
88 *
89 * $Header: /cvsroot/Lorene/C++/Source/Etoile/et_rot_mag_mag.C,v 1.17 2014/10/13 08:52:58 j_novak Exp $
90 *
91 */
92
93 // Headers C
94 #include <cstdlib>
95 #include <cmath>
96
97 // Headers Lorene
98 #include "et_rot_mag.h"
99 #include "utilitaires.h"
100 #include "param.h"
101 #include "proto_f77.h"
102 #include "graphique.h"
103 #include "tensor.h"
104
105 namespace Lorene {
106 // Local prototype (for drawings only)
107 Cmp raccord_c1(const Cmp& uu, int l1) ;
108
109 // Algo du papier de 1995
110
111 void Et_rot_mag::magnet_comput(const int adapt_flag,
112 Cmp (*f_j)(const Cmp&, const double),
113 Param& par_poisson_At,
114 Param& par_poisson_Avect){
115 double relax_mag = 0.5 ;
116
117 int mag_filter = 0 ;
118 if (par_poisson_At.get_n_int() > 1)
119 mag_filter = par_poisson_At.get_int(1) ;
120
121 int Z = mp.get_mg()->get_nzone();
122
123 if(is_conduct()) {
124 bool adapt(adapt_flag) ;
125 /****************************************************************
126 * Assertion that all zones have same number of points in theta
127 ****************************************************************/
128 int nt = mp.get_mg()->get_nt(nzet-1) ;
129 for (int l=0; l<Z; l++) assert(mp.get_mg()->get_nt(l) == nt) ;
130
131 Tbl Rsurf(nt) ;
132 Rsurf.set_etat_qcq() ;
133 mp.r.fait() ;
134 mp.tet.fait() ;
135 Mtbl* theta = mp.tet.c ;
136 const Map_radial* mpr = dynamic_cast<const Map_radial*>(&mp) ;
137 assert (mpr != 0x0) ;
138 for (int j=0; j<nt; j++)
139 Rsurf.set(j) = mpr->val_r_jk(l_surf()(0,j), xi_surf()(0,j), j, 0) ;
140
141
142 // Calcul de A_0t dans l'etoile (conducteur parfait)
143
144 Cmp A_0t(- omega * A_phi) ;
145 //A_0t.annule(nzet,Z-1) ;
146
147 Tenseur ATTENS(A_t) ;
148 Tenseur APTENS(A_phi) ;
149 Tenseur BMN(-logn) ;
150 BMN = BMN + log(bbb) ;
151 BMN.set_std_base() ;
152
153
154 Cmp grad1(flat_scalar_prod_desal(ATTENS.gradient_spher(),
155 nphi.gradient_spher())());
156 Cmp grad2(flat_scalar_prod_desal(APTENS.gradient_spher(),
157 nphi.gradient_spher())()) ;
158 Cmp grad3(flat_scalar_prod_desal(ATTENS.gradient_spher(),
159 BMN.gradient_spher())()
160 + 2*nphi()*flat_scalar_prod_desal(APTENS.gradient_spher(),
161 BMN.gradient_spher())()) ;
162
163 Cmp ATANT(A_phi.srdsdt()); // Constrction par copie pour mapping
164
165 ATANT.va = ATANT.va.mult_ct().ssint() ;
166
167 Cmp ttnphi(tnphi()) ;
168 ttnphi.mult_rsint() ;
169 Cmp BLAH(- b_car()/(nnn()*nnn())*ttnphi*grad1) ;
170 BLAH -= (1+b_car()/(nnn()*nnn())*tnphi()*tnphi())*grad2 ;
171 Cmp nphisr(nphi()) ;
172 nphisr.div_r() ;
173 Cmp npgrada(2*nphisr*(A_phi.dsdr()+ATANT )) ;
174 npgrada.inc2_dzpuis() ;
175 BLAH -= grad3 + npgrada ;
176 Cmp gtt(-nnn()*nnn()+b_car()*tnphi()*tnphi()) ;
177 Cmp gtphi( - b_car()*ttnphi) ;
178
179 // Calcul de j_t grace a Maxwell-Gauss
180 Cmp tmp(((BLAH - A_0t.laplacien())/a_car() - gtphi*j_phi)
181 / gtt);
182 tmp.annule(nzet, Z-1) ;
183 if (adapt) {
184 j_t = tmp ;
185 }
186 else {
187 j_t.allocate_all() ;
188 for (int j=0; j<nt; j++)
189 for (int l=0; l<nzet; l++)
190 for (int i=0; i<mp.get_mg()->get_nr(l); i++)
191 j_t.set(l,0,j,i) = ( (*mp.r.c)(l,0,j,i) > Rsurf(j) ?
192 0. : tmp(l,0,j,i) ) ;
193 j_t.annule(nzet,Z-1) ;
194 }
195 j_t.std_base_scal() ;
196
197 // Calcul du courant j_phi
198 j_phi = omega * j_t + (ener() + press())*f_j(A_phi, a_j) ;
199 j_phi.std_base_scal() ;
200
201 // Resolution de Maxwell Ampere (-> A_phi)
202 // Calcul des termes sources avec A-t du pas precedent.
203
204 Cmp grad4(flat_scalar_prod_desal(APTENS.gradient_spher(),
205 BMN.gradient_spher())());
206
207 Tenseur source_tAphi(mp, 1, CON, mp.get_bvect_spher()) ;
208
209 source_tAphi.set_etat_qcq() ;
210 Cmp tjphi(j_phi) ;
211 tjphi.mult_rsint() ;
212 Cmp tgrad1(grad1) ;
213 tgrad1.mult_rsint() ;
214 Cmp d_grad4(grad4) ;
215 d_grad4.div_rsint() ;
216 source_tAphi.set(0)=0 ;
217 source_tAphi.set(1)=0 ;
218 source_tAphi.set(2)= -b_car()*a_car()*(tjphi-tnphi()*j_t)
219 + b_car()/(nnn()*nnn())*(tgrad1+tnphi()*grad2)+d_grad4 ;
220
221 source_tAphi.change_triad(mp.get_bvect_cart());
222 if (mag_filter == 1) {
223 for (int i=0; i<3; i++) {
224 Scalar tmp_filter = source_tAphi(i) ;
225 tmp_filter.exponential_filter_r(0, 2, 1) ;
226 tmp_filter.exponential_filter_ylm(0, 2, 1) ;
227 source_tAphi.set(i) = tmp_filter ;
228 }
229 }
230
231
232 Tenseur WORK_VECT(mp, 1, CON, mp.get_bvect_cart()) ;
233 WORK_VECT.set_etat_qcq() ;
234 for (int i=0; i<3; i++) {
235 WORK_VECT.set(i) = 0 ;
236 }
237 Tenseur WORK_SCAL(mp) ;
238 WORK_SCAL.set_etat_qcq() ;
239 WORK_SCAL.set() = 0 ;
240
241 double lambda_mag = 0. ; // No 3D version !
242
243 Tenseur AVECT(source_tAphi) ;
244 if (source_tAphi.get_etat() != ETATZERO) {
245
246 for (int i=0; i<3; i++) {
247 if(source_tAphi(i).dz_nonzero()) {
248 assert( source_tAphi(i).get_dzpuis() == 4 ) ;
249 }
250 else{
251 (source_tAphi.set(i)).set_dzpuis(4) ;
252 }
253 }
254
255 }
256 source_tAphi.poisson_vect(lambda_mag, par_poisson_Avect, AVECT, WORK_VECT,
257 WORK_SCAL) ;
258 AVECT.change_triad(mp.get_bvect_spher());
259 Cmp A_phi_n(AVECT(2));
260 A_phi_n.mult_rsint() ;
261
262 // Resolution de Maxwell-Ampere : A_1
263
264 Cmp source_A_1t(-a_car()*(j_t*gtt + j_phi*gtphi) + BLAH);
265 if (mag_filter == 1) {
266 Scalar tmp_filter = source_A_1t ;
267 tmp_filter.exponential_filter_r(0, 2, 1) ;
268 tmp_filter.exponential_filter_ylm(0, 2, 1) ;
269 source_A_1t = tmp_filter ;
270 }
271
272 Cmp A_1t(mp);
273 A_1t = 0 ;
274 source_A_1t.poisson(par_poisson_At, A_1t) ;
275
276 int L = mp.get_mg()->get_nt(0) ;
277
278 Tbl MAT(L,L) ;
279 Tbl MAT_PHI(L,L);
280 Tbl VEC(L) ;
281
282 MAT.set_etat_qcq() ;
283 VEC.set_etat_qcq() ;
284 MAT_PHI.set_etat_qcq() ;
285
286 Tbl leg(L,2*L) ;
287 leg.set_etat_qcq() ;
288
289 Cmp psi(mp);
290 Cmp psi2(mp);
291 Cmp psi3(mp);
292 psi.allocate_all() ;
293 psi2.allocate_all() ;
294 psi3.allocate_all() ;
295
296 Tbl VEC3(L) ;
297 VEC3.set_etat_qcq() ;
298 for (int i=0; i<L; i++)
299 VEC3.set(i) = 1. / double(i+1) ;
300
301 for (int p=0; p<mp.get_mg()->get_np(0); p++) {
302 // leg[k,l] : legendre_l(cos(theta_k))
303 // Construction par recurrence de degre 2
304 for(int k=0;k<L;k++){
305 for(int l=0;l<2*L;l++){
306
307 if(l==0) leg.set(k,l)=1. ;
308 if(l==1) leg.set(k,l)=cos((*theta)(l_surf()(p,k),p,k,0)) ;
309 if(l>=2) leg.set(k,l) = double(2*l-1)/double(l)
310 * cos((*theta)(l_surf()(p,k),p,k,0))
311 * leg(k,l-1)-double(l-1)/double(l)*leg(k,l-2) ;
312 }
313 }
314
315 for(int k=0;k<L;k++){
316
317 // Valeurs a la surface trouvees via va.val_point_jk(l,xisurf,k,p)
318
319 VEC.set(k) = A_0t.va.val_point_jk(l_surf()(p,k), xi_surf()(p,k), k, p)
320 -A_1t.va.val_point_jk(l_surf()(p,k), xi_surf()(p,k), k, p);
321
322 for(int l=0;l<L;l++) MAT.set(l,k) = leg(k,2*l)/pow(Rsurf(k),2*l+1);
323
324 }
325 // appel fortran :
326
327 int* IPIV=new int[L] ;
328 int INFO ;
329
330 Tbl MAT_SAVE(MAT) ;
331 Tbl VEC2(L) ;
332 VEC2.set_etat_qcq() ;
333 int un = 1 ;
334
335 F77_dgesv(&L, &un, MAT.t, &L, IPIV, VEC.t, &L, &INFO) ;
336
337 // coeffs a_l dans VEC
338
339 for(int k=0;k<L;k++) {VEC2.set(k)=1. ; }
340
341 F77_dgesv(&L, &un, MAT_SAVE.t, &L, IPIV, VEC2.t, &L, &INFO) ;
342
343 delete [] IPIV ;
344
345 for(int nz=0;nz < Z; nz++){
346 for(int i=0;i< mp.get_mg()->get_nr(nz);i++){
347 for(int k=0;k<L;k++){
348 psi.set(nz,p,k,i) = 0. ;
349 psi2.set(nz,p,k,i) = 0. ;
350 psi3.set(nz,p,k,i) = 0. ;
351 for(int l=0;l<L;l++){
352 psi.set(nz,p,k,i) += VEC(l)*leg(k,2*l) /
353 pow((*mp.r.c)(nz,p,k,i),2*l+1);
354 psi2.set(nz,p,k,i) += VEC2(l)*leg(k,2*l)/
355 pow((*mp.r.c)(nz, p, k,i),2*l+1);
356 psi3.set(nz,p,k,i) += VEC3(l)*leg(k,2*l)/
357 (pow((*mp.r.c)(nz, p, k,i),2*l+1)) ;
358 }
359 }
360 }
361 }
362 }
363 psi.std_base_scal() ;
364 psi2.std_base_scal() ;
365
366 assert(psi.get_dzpuis() == 0) ;
367 int dif = A_1t.get_dzpuis() ;
368 if (dif > 0) {
369 for (int d=0; d<dif; d++) A_1t.dec_dzpuis() ;
370 }
371
372 if (adapt) {
373 Cmp A_t_ext(A_1t + psi) ;
374 A_t_ext.annule(0,nzet-1) ;
375 A_0t += A_t_ext ;
376 }
377 else {
378 tmp = A_0t ;
379 A_0t.allocate_all() ;
380 for (int j=0; j<nt; j++)
381 for (int l=0; l<Z; l++)
382 for (int i=0; i<mp.get_mg()->get_nr(l); i++)
383 A_0t.set(l,0,j,i) = ( (*mp.r.c)(l,0,j,i) > Rsurf(j) ?
384 A_1t(l,0,j,i) + psi(l,0,j,i) : tmp(l,0,j,i) ) ;
385 }
386 A_0t.std_base_scal() ;
387
388 if (mag_filter == 1) {
389 Scalar tmp_filter = A_0t ;
390 tmp_filter.exponential_filter_r(0, 2, 1) ;
391 tmp_filter.exponential_filter_ylm(0, 2, 1) ;
392 A_0t = tmp_filter ;
393 }
394
395 Valeur** asymp = A_0t.asymptot(1) ;
396
397 double Q_0 = -4*M_PI*(*asymp[1])(Z-1,0,0,0) ; // utilise A_0t plutot que E
398 delete asymp[0] ;
399 delete asymp[1] ;
400
401 delete [] asymp ;
402
403 asymp = psi2.asymptot(1) ;
404
405 double Q_2 = -4*M_PI*(*asymp[1])(Z-1,0,0,0) ; // A_2t = psi2 a l'infini
406 delete asymp[0] ;
407 delete asymp[1] ;
408
409 delete [] asymp ;
410
411 // solution definitive de A_t:
412
413 double C = (Q-Q_0)/Q_2 ;
414
415 assert(psi2.get_dzpuis() == 0) ;
416 dif = A_0t.get_dzpuis() ;
417 if (dif > 0) {
418 for (int d=0; d<dif; d++) A_0t.dec_dzpuis() ;
419 }
420 Cmp A_t_n(mp) ;
421 if (adapt) {
422 A_t_n = A_0t + C ;
423 Cmp A_t_ext(A_0t + C*psi2) ;
424 A_t_ext.annule(0,nzet-1) ;
425 A_t_n.annule(nzet,Z-1) ;
426 A_t_n += A_t_ext ;
427 }
428 else {
429 A_t_n.allocate_all() ;
430 for (int j=0; j<nt; j++)
431 for (int l=0; l<Z; l++)
432 for (int i=0; i<mp.get_mg()->get_nr(l); i++) {
433 A_t_n.set(l,0,j,i) = ( (*mp.r.c)(l,0,j,i) > Rsurf(j) ?
434 A_0t(l,0,j,i) + C*psi2(l,0,j,i) :
435 A_0t(l,0,j,i) + C ) ;
436 }
437 }
438 A_t_n.std_base_scal() ;
439 if (mag_filter == 1) {
440 Scalar tmp_filter = A_t_n ;
441 tmp_filter.exponential_filter_r(0, 2, 1) ;
442 tmp_filter.exponential_filter_ylm(0, 2, 1) ;
443 A_t_n = tmp_filter ;
444 }
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 } // End of perfect conductor case
456
457 else
458 {
459
460 /***************
461 * CAS ISOLANT *
462 ***************/
463
464 // Calcul de j_t
465 j_t = Q*nbar() + (ener()+press())*f_j(omega* A_phi - A_t,a_j) ;
466 j_t.annule(nzet,Z-1) ;
467 j_t.std_base_scal() ;
468
469 // Calcul de j_phi
470 j_phi = omega * j_t ;
471 j_phi.std_base_scal() ;
472
473 // Resolution de A_t
474
475 Tenseur ATTENS(A_t) ;
476 Tenseur APTENS(A_phi) ;
477 Tenseur BMN(-logn) ;
478 BMN = BMN + log(bbb) ;
479 BMN.set_std_base() ;
480
481
482 Cmp grad1(flat_scalar_prod_desal(ATTENS.gradient_spher(),
483 nphi.gradient_spher())());
484 Cmp grad2(flat_scalar_prod_desal(APTENS.gradient_spher(),
485 nphi.gradient_spher())()) ;
486 Cmp grad3(flat_scalar_prod_desal(ATTENS.gradient_spher(),
487 BMN.gradient_spher())()
488 + 2*nphi()*flat_scalar_prod_desal(APTENS.gradient_spher(),
489 BMN.gradient_spher())()) ;
490
491 Cmp ATANT(A_phi.srdsdt());
492
493 ATANT.va = ATANT.va.mult_ct().ssint() ;
494
495 Cmp ttnphi(tnphi()) ;
496 ttnphi.mult_rsint() ;
497 Cmp BLAH(- b_car()/(nnn()*nnn())*ttnphi*grad1) ;
498 BLAH -= (1+b_car()/(nnn()*nnn())*tnphi()*tnphi())*grad2 ;
499 Cmp nphisr(nphi()) ;
500 nphisr.div_r() ;
501 Cmp npgrada(2*nphisr*(A_phi.dsdr()+ATANT )) ;
502 npgrada.inc2_dzpuis() ;
503 BLAH -= grad3 + npgrada ;
504 Cmp gtt(-nnn()*nnn()+b_car()*tnphi()*tnphi()) ;
505 Cmp gtphi( - b_car()*ttnphi) ;
506
507 Cmp source_A_t_n(mp);
508 if (relativistic) {
509 source_A_t_n = (-a_car()*(j_t*gtt + j_phi*gtphi) + BLAH);
510 source_A_t_n.std_base_scal();}
511 else{
512 source_A_t_n = j_t;}
513
514 Cmp A_t_n(A_t) ;
515 A_t_n = 0 ;
516 A_t_n.std_base_scal() ;
517
518 source_A_t_n.poisson(par_poisson_At, A_t_n) ;
519
520 // Resolution de A_phi
521
522 Cmp grad4(flat_scalar_prod_desal(APTENS.gradient_spher(),
523 BMN.gradient_spher())());
524
525 Tenseur source_tAphi(mp, 1, CON, mp.get_bvect_spher()) ;
526
527 source_tAphi.set_etat_qcq() ;
528
529 Cmp tjphi(j_phi) ;
530 tjphi.mult_rsint() ;
531 Cmp tgrad1(grad1) ;
532 tgrad1.mult_rsint() ;
533 Cmp d_grad4(grad4) ;
534 d_grad4.div_rsint() ;
535 source_tAphi.set(0)=0 ;
536 source_tAphi.set(1)=0 ;
537
538 if (relativistic) {
539 source_tAphi.set(2)= -b_car()*a_car()*(tjphi-tnphi()*j_t)
540 + b_car()/(nnn()*nnn())*(tgrad1+tnphi()*grad2)+d_grad4 ;}
541 else{
542 source_tAphi.set(2)= - tjphi ;}
543
544 source_tAphi.change_triad(mp.get_bvect_cart());
545
546 Tenseur WORK_VECT(mp, 1, CON, mp.get_bvect_cart()) ;
547 WORK_VECT.set_etat_qcq() ;
548 for (int i=0; i<3; i++) {
549 WORK_VECT.set(i) = 0 ;
550 }
551 Tenseur WORK_SCAL(mp) ;
552 WORK_SCAL.set_etat_qcq() ;
553 WORK_SCAL.set() = 0 ;
554
555 double lambda_mag = 0. ; // No 3D version !
556
557 Tenseur AVECT(source_tAphi) ;
558 if (source_tAphi.get_etat() != ETATZERO) {
559
560 for (int i=0; i<3; i++) {
561 if(source_tAphi(i).dz_nonzero()) {
562 assert( source_tAphi(i).get_dzpuis() == 4 ) ;
563 }
564 else{
565 (source_tAphi.set(i)).set_dzpuis(4) ;
566 }
567 }
568
569 }
570 source_tAphi.poisson_vect(lambda_mag, par_poisson_Avect, AVECT, WORK_VECT,
571 WORK_SCAL) ;
572 AVECT.change_triad(mp.get_bvect_spher());
573 Cmp A_phi_n(AVECT(2));
574 A_phi_n.mult_rsint() ;
575
576 // Relaxation
577
578 A_t = relax_mag*A_t_n + (1.-relax_mag)*A_t ;
579 A_phi = relax_mag*A_phi_n + (1. - relax_mag)*A_phi ;
580
581 }
582
583
584 }
585
586
587
588
589
590
591
592
593
594
595
596
597
598 }