Debian Codegraph @

Codes/Ernstbbh/ernstbbh.C

raw
1 /*
2 * Simple code for solving the Ernst equation for Kerr
3 * boundary data in rotating coordinates with Lorene.
4 * The boundary data are given on a sphere, the focus is
5 * on the treatement of the light cylinder
6 *
7 * 28.01.03
8 *
9 */
10
11 /*
12 * Copyright (c) 2002 E. Gourgoulhon, C. Klein
13 *
14 * This file is part of LORENE.
15 *
16 * LORENE is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License version 2
18 * as published by the Free Software Foundation.
19 *
20 * LORENE is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with LORENE; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 *
29 */
30
31 char name_of_this_file_C[] = "$Header: /cvsroot/Lorene/Codes/Ernstbbh/ernstbbh.C,v 1.6 2014/10/13 08:53:56 j_novak Exp $" ;
32
33 /*
34 *
35 * $Header: /cvsroot/Lorene/Codes/Ernst/ernstbbh.C
36 */
37
38 // C++ headers
39 #include "headcpp.h"
40
41 // C headers
42 #include <cstdlib>
43
44 // Lorene headers
45 #include "cmp.h"
46 #include "nbr_spx.h"
47 #include "graphique.h"
48 #include "utilitaires.h"
49
50
51
52
53
54
55 //=============================================================
56
57 using namespace Lorene ;
58
59 int main() {
60
61 // Read grid parameters from a file
62 // --------------------------------
63
64 ifstream parfile("ernstpar.d") ;
65 char blabla[80] ;
66 int nz, nr, nt, np ;
67 double mu, alpha, M, tol;
68 int MaxIt;
69
70 parfile >> nz ; parfile.getline(blabla, 80) ;
71 parfile >> nr ; parfile.getline(blabla, 80) ;
72 parfile >> nt ; parfile.getline(blabla, 80) ;
73 parfile >> np ; parfile.getline(blabla, 80) ;
74 parfile >> mu ; parfile.getline(blabla, 80) ;
75 parfile >> MaxIt ; parfile.getline(blabla, 80) ;
76 parfile >> tol ; parfile.getline(blabla, 80) ;
77 parfile >> M ; parfile.getline(blabla, 80) ;
78 parfile >> alpha ; parfile.getline(blabla, 80) ;
79 parfile.close() ;
80
81 const double c = cos(alpha);
82 // const double c2 = cos(2*alpha);
83 const double s = sin(alpha);
84 const double cc = c*c;
85 const double Mc = M*c;
86 const double J = M*M*s; // angular momentum
87 const double Om = 0.5*tan(0.5*alpha)/M; // angular velocity of the horizon
88
89 cout << "mass: " << Mc <<"\t" << J <<"\t" << Om << endl;
90
91
92 // Construction of a multi-grid (Mg3d)
93 // -----------------------------------
94
95 Mg3d mgrid(nz, nr, nt, np, SYM, SYM, true) ;
96
97 cout << "Mult_grid : " << mgrid << endl ;
98
99 // Construction of an affine mapping (Map_af)
100 // ------------------------------------------
101
102 double* r_limits = new double[nz+1] ;
103 assert( nz == 3 ) ;
104 r_limits[0] = 0 ;
105 r_limits[1] = 1 ;
106 r_limits[2] = 2 ;
107 r_limits[3] = __infinity ;
108
109 Map_af map(mgrid, r_limits) ;
110
111 // Construction of a scalar field (Cmp)
112 // ------------------------------------
113
114 const Coord& z = map.z ;
115 const Coord& r = map.r ;
116 // const Coord& cost = map.cost ;
117 // const Coord& sint = map.sint ;
118
119 Cmp U(map) ;
120 Cmp V(map) ;
121 Cmp Usource(map); // RHS for the real part of the Ernst equation
122 Cmp Vsource(map); // RHS for the imaginary part of the Ernst equation
123
124 // Auxiliary fields for the Kerr solution
125 //------------------------
126
127 Cmp F(map); // real part of the Ernst potential
128 Cmp B(map); // imaginary part of the Ernst potential
129 Cmp A(map); // metric function -g_tphi
130 Cmp Rp(map);
131 Cmp Rm(map);
132
133
134 Rp = sqrt(Mc*Mc + r*r + 2*Mc*z);
135 Rm = sqrt(Mc*Mc + r*r - 2*Mc*z);
136 Cmp X = 0.5*(Rp+Rm)/Mc;//parabolic coordinates
137 Cmp Y = 0.5*(Rp-Rm)/Mc;
138
139
140
141 Cmp N = (c*X+1)*(c*X+1)+s*s*Y*Y;
142 F = (cc*X*X+s*s*Y*Y-1)/N;
143 B = -2*s*Y/N;
144 A = 2*M*s*(1-Y*Y)*(1+c*X)/N;
145
146 for (int i=0;i<np;i++) // set at infinity
147 {
148 for(int j=0; j<nt;j++)
149 {
150 F.set(nz-1,i,j,nr-1) = 1.0;
151 B.set(nz-1,i,j,nr-1) = 0.0;
152 A.set(nz-1,i,j,nr-1) = 0.0;
153 }
154 }
155
156 Cmp Un(map); // set F=1 in the nucleus to avoid problems due to the ergosphere
157 Un = 1;
158 Un.annule(1,2);
159 F.annule(0);
160 F = F +Un;
161 F.std_base_scal();
162 B.std_base_scal();
163 // B.va.set_base_t(T_COSSIN_CI) ;
164 B.va.set_base_t(T_COS_I);
165 A.std_base_scal();
166
167
168 // rotating coordinates and functions vanishing at infinity
169 Cmp Frot(map); // F in corotating coordinates
170 Cmp Brrot(map); // B_r in corotating coordinates
171 Cmp Btrot(map); // B_theta in corotating coordinates
172 Cmp At(map); //A_theta/r/sint
173 Cmp Ft(map); //F_theta/r/sint
174 Cmp Ar(map); //A_r
175 Cmp Fr(map); //F_r
176 Cmp Omsint(map);// Omega*sin(theta)
177 Omsint = Om;
178 Omsint.std_base_scal();
179 Omsint.va = Omsint.va.mult_st();
180
181
182 Cmp Ftemp = (F+Om*A);
183 Cmp Help2 = Ftemp;
184 Ftemp.div_r();
185 Frot = (Ftemp*Ftemp-Omsint*Omsint)/F;
186 Cmp Rminus(map);// Rminus = 1/r
187 Rminus = 1;
188 Rminus.std_base_scal();
189 Rminus.div_r();
190
191 // Ftilde: F in corotating coordinates minus diverging and constant terms
192 Cmp Ftilde = Frot - Rminus*Rminus+Omsint*Omsint*(1+2*M*Rminus+2*M*M*Rminus*Rminus);
193 Ftilde.std_base_scal();
194 Ftilde.mult_r();
195 Ftilde.mult_r();
196 Ftilde.inc2_dzpuis();
197
198
199
200 At.set_etat_qcq();
201 Ft.set_etat_qcq();
202 Ar.set_etat_qcq();
203 Fr.set_etat_qcq();
204 At.va = A.va.dsdt().ssint();
205 Ft.va = F.va.dsdt().ssint();
206 Ar = A.dsdr();
207 Fr = F.dsdr();
208 Ar.dec2_dzpuis();
209 Fr.dec2_dzpuis();
210 Cmp Help1 = Ftemp*Ftemp+Omsint*Omsint;
211 Cmp Omsint2(map);// Omega*sin(theta)^2
212 Omsint2.set_etat_qcq();
213 Omsint2.va = Omsint.va.mult_st();
214 Cmp Omcost(map);// Omega*cos(theta)
215 Omcost = Om;
216 Omcost.std_base_scal();
217 Omcost.va = Omcost.va.mult_ct();
218 Brrot = Help1*At+(2*Omsint2*Help2-Help1*A)*Ft/F-2*Omcost*Help2;
219 Brrot = Brrot/F;
220 Cmp Brtilde = Brrot+2*Omcost; //Brot_r minus diverging and constant terms
221 Btrot = Help1*Ar+(2*Omsint2*Help2-Help1*A)*Fr/F;
222 Btrot.va = Btrot.va.ssint();
223 Btrot.mult_r();
224 Btrot.inc_dzpuis();
225 Btrot = -Btrot+2*Omsint*Help2;
226 Btrot = Btrot/F;
227 // Brot_theta minus diverging and constant terms
228 Cmp Bttilde = Btrot-2*Omsint-6*M*M*s*Omsint*Omsint*Omsint/Om*Rminus+4*M*Omsint*Rminus;
229
230
231
232
233
234
235
236
237 // Boundary Values
238 //-----------------------------------------------------
239
240
241
242 Valeur bcU( mgrid.get_angu());
243 Valeur bcV( mgrid.get_angu());
244 bcU.annule_hard();
245 bcV.annule_hard();
246
247 for (int m=0; m < nt; m++)
248 {
249 for (int l=0; l < np; l++)
250 {
251 bcU.set(1,l,m,0) = Ftilde(1,l,m,0);
252 bcV.set(1,l,m,0) = Brtilde(1,l,m,0);
253 }
254 }
255
256 bcU.set_base(Ftilde.va.base);
257 bcV.set_base(Brtilde.va.base);
258
259 // initial values
260 // U = 1;
261 U = Ftilde;
262 U.std_base_scal() ;
263
264 V = U;
265 V.annule_hard();
266 V.std_base_scal() ;
267 // V.va.set_base_t(T_COSSIN_CI) ;
268 V.va.set_base_t(T_COS_I);
269
270 // No stopping criterion provided for the moment
271
272 // for (int iter=0; iter < MaxIt;iter++)
273 // {
274 //
275 // cout << "Iteration " << iter << endl;
276
277 Cmp Ur = U;
278 Ur.div_r();
279 Ur.div_r();
280 Cmp Urot = Ur+Rminus*Rminus-Omsint*Omsint*(1+2*M*Rminus+2*M*M*Rminus*Rminus); //F with correct asymptotic behavior
281
282 Cmp Usource1 = 4*Omsint*Omsint*(2*M*Rminus+3*M*M*Rminus*Rminus)-4*Om*Om*(1+2*M*Rminus+2*M*M*Rminus*Rminus);
283 Cmp LHS = Frot*(Ftilde.laplacien(0)+Usource1); // test Kerr
284
285 Cmp Urr = U.dsdr();
286 Urr.div_r();
287 Cmp Utr = U.srdsdt();
288 Utr.div_r();
289 Cmp Vsr = V.dsdr();
290 Cmp Vst = V.srdsdt();
291 Vsr.dec2_dzpuis();
292 Vst.dec2_dzpuis();
293 Urr.dec2_dzpuis();
294 Utr.dec2_dzpuis();
295
296 // Test of Kerr
297 Vsr = Brtilde;
298 Vst = Bttilde;
299
300
301 Cmp Ustemp = -(Vsr-2*Omcost)*(Vsr-2*Omcost)
302 - (Vst+2*Omsint+6*Omsint*Omsint*Omsint*M*M*s*Rminus/Om-4*Omsint*M*Rminus)
303 *(Vst+2*Omsint+6*Omsint*Omsint*Omsint*M*M*s*Rminus/Om-4*Omsint*M*Rminus);
304 Ustemp.div_r();
305 Ustemp.div_r();
306 Usource = (Urr-2*Omsint*Omsint*(1+M*Rminus))*(Urr-2*Omsint*Omsint*(1+M*Rminus))
307 +(Utr-2*Omsint*Omcost*(1+2*M*Rminus+2*M*M*Rminus*Rminus))*(Utr-2*Omsint*Omcost*(1+2*M*Rminus+2*M*M*Rminus*Rminus))
308 +Ustemp;
309 Cmp test = Usource;
310
311 // cout << test << endl;
312 // arrete();
313 Usource = Usource/Urot-Usource1;
314
315
316
317 Cmp Vsource1 = (-8*Omcost*M+24*Omcost*Omsint*Omsint*M*M*s/Om)*Rminus*Rminus;
318 Vsource = (Vsr-2*Omcost)*(Urr-2*Omsint*Omsint*(1+M*Rminus))
319 +(Vst+2*Omsint+6*Omsint*Omsint*Omsint*M*M*s*Rminus/Om-4*Omsint*M*Rminus)
320 *(Utr-2*Omsint*Omcost*(1+2*M*Rminus+2*M*M*Rminus*Rminus));
321 Vsource.div_r();
322 Vsource = 2*Vsource/Urot-Vsource1;
323
324 Usource.set(0) = 1.0;
325 Vsource.set(0) = 1.0;
326 test.set(0) = 1.0;
327 LHS.set(0) = 1.0;
328 // for (int i=0;i<np;i++) // set at infinity
329 // {
330 // for(int j=0; j<nt;j++)
331 // {
332 // test.set(nz-1,i,j,nr-1) = 0.0;
333 // Usource.set(nz-1,i,j,nr-1) = 0.0;
334 // Vsource.set(nz-1,i,j,nr-1) = 0.0;
335 // }
336 // }
337 // Valeur ** Coeff = Usource.asymptot(3);
338 // cout <<*Coeff [1];
339 des_profile(test-LHS,1.0001,20.0,1.2,0);
340 // des_profile(LHS,1.0001,20.0,1.2,0);
341
342 Usource.inc2_dzpuis();
343 Usource.inc_dzpuis();
344
345
346 Cmp UV = Usource.poisson_dirichlet(bcU, 0) ;
347 UV.set(0) = 1.0;
348
349 Tbl diff = norme(abs(U-UV));
350 cout << diff(1) << " " << diff(2) << endl;
351 U = (1-mu)*U + mu*UV;
352
353 UV = Vsource.poisson_neumann(bcV, 0) ;
354 UV.set(0) = 0.0;
355 V = (1-mu)*V + mu*UV;
356
357 // }
358
359 // des_profile(U-F,1.0001,20.0,M_PI/2,0);
360 // des_profile(V-B,1.0001,20.0,0,M_PI/2);
361
362
363 // des_coupe_x(U, 0., 2, "field U at x=0") ;
364 // des_coupe_y(U, 0., 2, "field U at y=0") ;
365 // des_coupe_z(U, 0., 2, "field U at z=0") ;
366
367 // des_coupe_x(V, 0., 2, "field V at x=0") ;
368 // des_coupe_y(V, 0., 2, "field V at y=0") ;
369 // des_coupe_z(V, 0., 2, "field V at z=0") ;
370
371 return EXIT_SUCCESS ;
372
373 }