Debian Codegraph @

Codes/Bin_hor/coal_bh.C

raw
1 /*
2 * Main code for computation of binary black hole quasiequilibrium
3 * configuration
4 *
5 *
6 */
7
8 /*
9 * Copyright (c) 2004-2005 Francois Limousin
10 * Jose Luis Jaramillo
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 version 2
16 * as published by the Free Software Foundation.
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 coal_bh_C[] = "$Header: /cvsroot/Lorene/Codes/Bin_hor/coal_bh.C,v 1.14 2014/10/13 08:53:53 j_novak Exp $" ;
30
31 /*
32 * $Id: coal_bh.C,v 1.14 2014/10/13 08:53:53 j_novak Exp $
33 * $Log: coal_bh.C,v $
34 * Revision 1.14 2014/10/13 08:53:53 j_novak
35 * Lorene classes and functions now belong to the namespace Lorene.
36 *
37 * Revision 1.13 2014/10/06 15:09:41 j_novak
38 * Modified #include directives to use c++ syntax.
39 *
40 * Revision 1.12 2007/04/13 15:30:58 f_limousin
41 * Lots of improvements, generalisation to an arbitrary state of
42 * rotation, implementation of the spatial metric given by Samaya.
43 *
44 * Revision 1.11 2006/08/01 14:13:41 f_limousin
45 * New version...
46 *
47 * Revision 1.10 2006/06/29 08:54:51 f_limousin
48 * Boundary conditions and grid writen in resformat.dat
49 *
50 * Revision 1.9 2006/06/28 13:36:52 f_limousin
51 * Convergence to a given irreductible mass
52 *
53 * Revision 1.8 2006/05/24 16:59:08 f_limousin
54 * New version
55 *
56 * Revision 1.6 2005/06/09 16:17:21 f_limousin
57 * Many different changes.
58 *
59 * Revision 1.4 2005/03/10 16:57:02 f_limousin
60 * Improve the convergence of the code coal_bh.
61 *
62 * Revision 1.3 2005/03/04 09:41:34 f_limousin
63 * New construction of the object Bin_hor
64 *
65 * Revision 1.2 2005/02/25 12:32:35 f_limousin
66 * The boundary conditions for psi, N and beta are now parameters in
67 * par_init.d and par_coal.d.
68 *
69 * Revision 1.1 2004/12/31 15:42:50 f_limousin
70 * First version
71 *
72 *
73 * $Header: /cvsroot/Lorene/Codes/Bin_hor/coal_bh.C,v 1.14 2014/10/13 08:53:53 j_novak Exp $
74 *
75 */
76
77
78 //standard
79 #include <cstdlib>
80 #include <cmath>
81
82 // LORENE
83 #include "type_parite.h"
84 #include "nbr_spx.h"
85 #include "proto.h"
86 #include "coord.h"
87 #include "tenseur.h"
88 #include "tensor.h"
89 #include "isol_hor.h"
90 #include "utilitaires.h"
91 #include "graphique.h"
92
93 using namespace Lorene ;
94
95 int main() {
96
97 char blabla [120] ;
98 char nomini[120] ;
99 double omega_init, relax, precis_viriel, lim_nn, mass_irr, alpha ;
100 int nb_om, nb_it, bound_nn, bound_psi, bound_beta, search_mass ;
101
102 ifstream param("par_coal.d") ;
103 if ( !param.good() ) {
104 cout << "Problem with opening the file par_coal.d ! " << endl ;
105 abort() ;
106 }
107 param.ignore(1000, '\n') ;
108 param.ignore(1000, '\n') ;
109 param.getline(nomini, 80) ;
110 param >> omega_init ; param.getline(blabla, 120) ;
111 param >> search_mass ;
112 param >> mass_irr ; param.ignore(1000, '\n');
113 param >> precis_viriel ; param.getline(blabla, 120) ;
114 param >> relax ; param.getline(blabla, 120) ;
115 param >> nb_om ; param.getline(blabla, 120) ;
116 param >> nb_it ; param.getline(blabla, 120) ;
117 param >> bound_beta ; param.getline(blabla, 120) ;
118 param >> alpha ; param.getline(blabla, 120) ;
119
120 param.close() ;
121
122 FILE* fich = fopen(nomini, "r") ;
123 Mg3d grid (fich) ;
124 Map_af map_un (grid, fich) ;
125 Map_af map_deux (grid, fich) ;
126 Bin_hor bin(map_un, map_deux, fich) ;
127 fread_be(&bound_nn, sizeof(int), 1, fich) ;
128 fread_be(&lim_nn, sizeof(double), 1, fich) ;
129 fread_be(&bound_psi, sizeof(int), 1, fich) ;
130 fclose(fich) ;
131
132 bin.set_omega(0) ;
133 bin.set(1).n_comp_import (bin(2)) ;
134 bin.set(1).psi_comp_import (bin(2)) ;
135 bin.set(1).beta_comp_import (bin(2)) ;
136 bin.set(2).n_comp_import (bin(1)) ;
137 bin.set(2).psi_comp_import (bin(1)) ;
138 bin.set(2).beta_comp_import (bin(1)) ;
139 bin.decouple() ;
140 bin.extrinsic_curvature() ;
141
142
143 double separation = bin(1).get_mp().get_ori_x() -
144 bin(2).get_mp().get_ori_x() ;
145
146 cout << "CALCUL AVEC SEPARATION = " << separation << endl ;
147
148 ofstream fich_iteration("iteration.dat") ;
149 fich_iteration.precision(8) ;
150
151 ofstream fich_correction("correction.dat") ;
152 fich_correction.precision(8) ;
153
154 ofstream fich_viriel("viriel.dat") ;
155 fich_viriel.precision(8) ;
156
157 ofstream fich_kss("kss.dat") ;
158 fich_kss.precision(8) ;
159
160 fich_iteration << "# step precision omega" << endl ;
161 fich_correction << "# step regularisation omega" << endl ;
162 fich_viriel << "# step viriel omega" << endl ;
163 fich_kss << "# step kss omega" << endl ;
164
165 int step = 0 ;
166
167 double omega_eff = alpha * omega_init ;
168
169 cout << "step = " << step << endl ;
170 double erreur = bin.coal(omega_init, relax, nb_om, nb_it, bound_nn,
171 lim_nn, bound_psi, bound_beta, omega_eff, alpha,
172 fich_iteration, fich_correction,
173 fich_viriel, fich_kss, step, search_mass,
174 mass_irr, 1) ;
175 step += nb_om + nb_it ;
176
177 // Convergence to the true Omega
178 // ------------------------------
179
180 bool boucle = true ;
181 double omega = omega_init ;
182
183 while (boucle) {
184
185 omega = omega * pow((2-erreur)/(2-2*erreur), 1.) ;
186
187 double om_loc = bin(1).omega_hor() ;
188 double diff_om = alpha * omega - om_loc ;
189
190 if (omega_eff != 0)
191 omega_eff = omega_eff * pow((2-diff_om)/(2-2*diff_om), 4.) ;
192 else
193 omega_eff = 0.5*diff_om ;
194
195 Scalar beta_old (bin(1).get_beta_auto()(1)) ;
196
197 erreur = bin.coal (omega, relax, 1, 0, bound_nn,
198 lim_nn, bound_psi, bound_beta, omega_eff, alpha,
199 fich_iteration, fich_correction,
200 fich_viriel, fich_kss, step, search_mass,
201 mass_irr, 1) ;
202
203 double erreur_it = 0 ;
204 Tbl diff (diffrelmax (beta_old, bin(1).get_beta_auto()(1))) ;
205 for (int i=1 ; i<bin(1).get_mp().get_mg()->get_nzone() ; i++)
206 if (diff(i) > erreur_it)
207 erreur_it = diff(i) ;
208
209
210 if (fabs(erreur) < precis_viriel && erreur_it < precis_viriel)
211 boucle = false ;
212
213 step += 1 ;
214
215 }
216
217 fich_iteration.close() ;
218 fich_correction.close() ;
219 fich_viriel.close() ;
220 fich_kss.close() ;
221
222 FILE* fich_sortie = fopen("bin.dat", "w") ;
223 grid.sauve(fich_sortie) ;
224 map_un.sauve(fich_sortie) ;
225 map_deux.sauve(fich_sortie) ;
226 bin.sauve(fich_sortie) ;
227 fclose(fich_sortie) ;
228
229
230 ofstream seqfich("resformat.dat") ;
231 if ( !seqfich.good() ) {
232 cout << "coal_bh : problem with opening the file resformat.d !"
233 << endl ;
234 abort() ;
235 }
236 bin.write_global(seqfich, lim_nn, bound_nn, bound_psi, bound_beta, alpha) ;
237 seqfich.close() ;
238
239 return EXIT_SUCCESS ;
240 }