| 1 |
/* |
| 2 |
* Main code for computing initial configuration |
| 3 |
* |
| 4 |
*/ |
| 5 |
|
| 6 |
/* |
| 7 |
* Copyright (c) 2004-2005 Francois Limousin |
| 8 |
* Jose Luis Jaramillo |
| 9 |
* |
| 10 |
* This file is part of LORENE. |
| 11 |
* |
| 12 |
* LORENE is free software; you can redistribute it and/or modify |
| 13 |
* it under the terms of the GNU General Public License version 2 |
| 14 |
* as published by the Free Software Foundation. |
| 15 |
* |
| 16 |
* LORENE is distributed in the hope that it will be useful, |
| 17 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 |
* GNU General Public License for more details. |
| 20 |
* |
| 21 |
* You should have received a copy of the GNU General Public License |
| 22 |
* along with LORENE; if not, write to the Free Software |
| 23 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 24 |
* |
| 25 |
*/ |
| 26 |
|
| 27 |
char init_coal_C[] = "$Header: /cvsroot/Lorene/Codes/Bin_hor/init_coal.C,v 1.8 2014/10/13 08:53:53 j_novak Exp $" ; |
| 28 |
|
| 29 |
/* |
| 30 |
* $Id: init_coal.C,v 1.8 2014/10/13 08:53:53 j_novak Exp $ |
| 31 |
* $Log: init_coal.C,v $ |
| 32 |
* Revision 1.8 2014/10/13 08:53:53 j_novak |
| 33 |
* Lorene classes and functions now belong to the namespace Lorene. |
| 34 |
* |
| 35 |
* Revision 1.7 2014/10/06 15:09:42 j_novak |
| 36 |
* Modified #include directives to use c++ syntax. |
| 37 |
* |
| 38 |
* Revision 1.6 2007/04/13 15:30:58 f_limousin |
| 39 |
* Lots of improvements, generalisation to an arbitrary state of |
| 40 |
* rotation, implementation of the spatial metric given by Samaya. |
| 41 |
* |
| 42 |
* Revision 1.5 2006/08/01 14:13:41 f_limousin |
| 43 |
* New version... |
| 44 |
* |
| 45 |
* Revision 1.4 2006/06/29 08:54:52 f_limousin |
| 46 |
* Boundary conditions and grid writen in resformat.dat |
| 47 |
* |
| 48 |
* Revision 1.3 2006/06/28 13:36:52 f_limousin |
| 49 |
* Convergence to a given irreductible mass |
| 50 |
* |
| 51 |
* Revision 1.2 2006/05/24 16:59:08 f_limousin |
| 52 |
* New version |
| 53 |
* |
| 54 |
* |
| 55 |
* $Header: /cvsroot/Lorene/Codes/Bin_hor/init_coal.C,v 1.8 2014/10/13 08:53:53 j_novak Exp $ |
| 56 |
* |
| 57 |
*/ |
| 58 |
|
| 59 |
//standard |
| 60 |
#include <cstdlib> |
| 61 |
#include <cmath> |
| 62 |
|
| 63 |
// LORENE |
| 64 |
#include "type_parite.h" |
| 65 |
#include "nbr_spx.h" |
| 66 |
#include "proto.h" |
| 67 |
#include "coord.h" |
| 68 |
#include "tenseur.h" |
| 69 |
#include "tensor.h" |
| 70 |
#include "isol_hor.h" |
| 71 |
#include "utilitaires.h" |
| 72 |
#include "graphique.h" |
| 73 |
|
| 74 |
|
| 75 |
using namespace Lorene ; |
| 76 |
|
| 77 |
int main() { |
| 78 |
|
| 79 |
char blabla [120] ; |
| 80 |
ifstream param_init("par_init.d") ; |
| 81 |
|
| 82 |
double precis, relax, radius, separation, lim_nn, mass_irr ; |
| 83 |
int nz, nt, np, nr1, nrp1, bound_nn, bound_psi, search_mass ; |
| 84 |
|
| 85 |
param_init.getline(blabla, 120) ; |
| 86 |
param_init.getline(blabla, 120) ; |
| 87 |
param_init >> separation ; param_init.getline(blabla, 120) ; |
| 88 |
param_init >> nz ; param_init.getline(blabla, 120) ; |
| 89 |
param_init >> nt; param_init.ignore(1000, '\n'); |
| 90 |
param_init >> np; param_init.ignore(1000, '\n'); |
| 91 |
param_init >> nr1; param_init.ignore(1000, '\n'); |
| 92 |
param_init >> nrp1; param_init.ignore(1000, '\n'); |
| 93 |
|
| 94 |
double* bornes = new double[nz+1] ; |
| 95 |
int* nr_tab = new int[nz]; |
| 96 |
int* nt_tab = new int[nz]; |
| 97 |
int* np_tab = new int[nz]; |
| 98 |
|
| 99 |
for (int l=0 ; l<nz ; l++){ |
| 100 |
if (l==1) nr_tab[1] = nr1 ; |
| 101 |
else nr_tab[l] = nrp1 ; |
| 102 |
np_tab[l] = np ; |
| 103 |
nt_tab[l] = nt ; |
| 104 |
param_init >> bornes[l] ; |
| 105 |
|
| 106 |
} |
| 107 |
radius = bornes[1] ; |
| 108 |
param_init.getline(blabla, 120) ; |
| 109 |
bornes[nz] = __infinity ; |
| 110 |
|
| 111 |
param_init >> precis ; param_init.getline(blabla, 120) ; |
| 112 |
param_init >> relax ; param_init.getline(blabla, 120) ; |
| 113 |
|
| 114 |
param_init >> bound_nn ; |
| 115 |
param_init >> lim_nn ; param_init.ignore(1000, '\n'); |
| 116 |
param_init >> bound_psi ; param_init.ignore(1000, '\n'); |
| 117 |
|
| 118 |
param_init.close() ; |
| 119 |
|
| 120 |
// Type of sampling in theta and phi : |
| 121 |
int type_t = SYM ; |
| 122 |
int type_p = NONSYM ; |
| 123 |
|
| 124 |
|
| 125 |
int* type_r = new int[nz] ; |
| 126 |
type_r[0] = RARE ; |
| 127 |
for (int l=1 ; l<nz-1 ; l++) |
| 128 |
type_r[l] = FIN ; |
| 129 |
type_r[nz-1] = UNSURR ; |
| 130 |
|
| 131 |
Mg3d grid (nz, nr_tab, type_r, nt_tab, type_t, np_tab, type_p) ; |
| 132 |
|
| 133 |
Map_af map_un (grid, bornes) ; |
| 134 |
Map_af map_deux (grid, bornes) ; |
| 135 |
|
| 136 |
map_un.set_ori (separation/2.,0, 0) ; |
| 137 |
map_deux.set_ori (-separation/2., 0, 0) ; |
| 138 |
map_deux.set_rot_phi (M_PI) ; |
| 139 |
|
| 140 |
Bin_hor bin (map_un, map_deux) ; |
| 141 |
bin.set_statiques(precis, relax, bound_nn, lim_nn, bound_psi) ; |
| 142 |
|
| 143 |
FILE* fich = fopen("static.d", "w") ; |
| 144 |
grid.sauve(fich) ; |
| 145 |
map_un.sauve(fich) ; |
| 146 |
map_deux.sauve(fich) ; |
| 147 |
bin.sauve(fich) ; |
| 148 |
fwrite_be(&bound_nn, sizeof(int), 1, fich) ; |
| 149 |
fwrite_be (&lim_nn, sizeof(double), 1, fich) ; |
| 150 |
fwrite_be(&bound_psi, sizeof(int), 1, fich) ; |
| 151 |
fclose(fich) ; |
| 152 |
|
| 153 |
|
| 154 |
// Part of coal |
| 155 |
// ------------ |
| 156 |
|
| 157 |
char nomini[120] ; |
| 158 |
double omega_init, precis_viriel; |
| 159 |
int nb_om, nb_it, bound_beta ; |
| 160 |
|
| 161 |
ifstream param_coal("par_coal.d") ; |
| 162 |
if ( !param_coal.good() ) { |
| 163 |
cout << "Problem with opening the file par_coal.d ! " << endl ; |
| 164 |
abort() ; |
| 165 |
} |
| 166 |
|
| 167 |
param_coal.ignore(1000, '\n') ; |
| 168 |
param_coal.ignore(1000, '\n') ; |
| 169 |
param_coal.getline(nomini, 80) ; |
| 170 |
param_coal >> omega_init ; param_coal.getline(blabla, 120) ; |
| 171 |
param_coal >> search_mass ; |
| 172 |
param_coal >> mass_irr ; param_coal.ignore(1000, '\n'); |
| 173 |
param_coal >> precis_viriel ; param_coal.getline(blabla, 120) ; |
| 174 |
param_coal >> relax ; param_coal.getline(blabla, 120) ; |
| 175 |
param_coal >> nb_om ; param_coal.getline(blabla, 120) ; |
| 176 |
param_coal >> nb_it ; param_coal.getline(blabla, 120) ; |
| 177 |
param_coal >> bound_beta ; param_coal.getline(blabla, 120) ; |
| 178 |
|
| 179 |
param_coal.close() ; |
| 180 |
|
| 181 |
bin.set_omega(0) ; |
| 182 |
bin.set(1).n_comp_import (bin(2)) ; |
| 183 |
bin.set(1).psi_comp_import (bin(2)) ; |
| 184 |
bin.set(1).beta_comp_import (bin(2)) ; |
| 185 |
bin.set(2).n_comp_import (bin(1)) ; |
| 186 |
bin.set(2).psi_comp_import (bin(1)) ; |
| 187 |
bin.set(2).beta_comp_import (bin(1)) ; |
| 188 |
bin.decouple() ; |
| 189 |
bin.extrinsic_curvature() ; |
| 190 |
|
| 191 |
cout << "CALCUL AVEC SEPARATION = " << separation << endl ; |
| 192 |
|
| 193 |
ofstream fich_iteration("iteration.dat") ; |
| 194 |
fich_iteration.precision(8) ; |
| 195 |
|
| 196 |
ofstream fich_correction("correction.dat") ; |
| 197 |
fich_correction.precision(8) ; |
| 198 |
|
| 199 |
ofstream fich_viriel("viriel.dat") ; |
| 200 |
fich_viriel.precision(8) ; |
| 201 |
|
| 202 |
ofstream fich_kss("kss.dat") ; |
| 203 |
fich_kss.precision(8) ; |
| 204 |
|
| 205 |
fich_iteration << "# step precision omega" << endl ; |
| 206 |
fich_correction << "# step regularisation omega" << endl ; |
| 207 |
fich_viriel << "# step viriel omega" << endl ; |
| 208 |
fich_kss << "# step kss omega" << endl ; |
| 209 |
|
| 210 |
int step = 0 ; |
| 211 |
|
| 212 |
cout << "step = " << step << endl ; |
| 213 |
double erreur = bin.coal(omega_init, relax, nb_om, nb_it, bound_nn, |
| 214 |
lim_nn, bound_psi, bound_beta, |
| 215 |
fich_iteration, fich_correction, |
| 216 |
fich_viriel, fich_kss, step, search_mass, |
| 217 |
mass_irr, 1) ; |
| 218 |
step += nb_om + nb_it ; |
| 219 |
|
| 220 |
// Convergence to the true Omega |
| 221 |
// ------------------------------ |
| 222 |
|
| 223 |
bool boucle = true ; |
| 224 |
double omega = omega_init ; |
| 225 |
|
| 226 |
while (boucle) { |
| 227 |
|
| 228 |
omega = omega * pow((2-erreur)/(2-2*erreur), 1.) ; |
| 229 |
|
| 230 |
Scalar beta_old (bin(1).get_beta_auto()(1)) ; |
| 231 |
|
| 232 |
erreur = bin.coal (omega, relax, 1, 0, bound_nn, |
| 233 |
lim_nn, bound_psi, bound_beta, |
| 234 |
fich_iteration, fich_correction, |
| 235 |
fich_viriel, fich_kss, step, search_mass, |
| 236 |
mass_irr, 1) ; |
| 237 |
|
| 238 |
double erreur_it = 0 ; |
| 239 |
Tbl diff (diffrelmax (beta_old, bin(1).get_beta_auto()(1))) ; |
| 240 |
for (int i=1 ; i<bin(1).get_mp().get_mg()->get_nzone() ; i++) |
| 241 |
if (diff(i) > erreur_it) |
| 242 |
erreur_it = diff(i) ; |
| 243 |
|
| 244 |
|
| 245 |
if (fabs(erreur) < precis_viriel && erreur_it < precis_viriel) |
| 246 |
boucle = false ; |
| 247 |
|
| 248 |
step += 1 ; |
| 249 |
|
| 250 |
} |
| 251 |
|
| 252 |
fich_iteration.close() ; |
| 253 |
fich_correction.close() ; |
| 254 |
fich_viriel.close() ; |
| 255 |
fich_kss.close() ; |
| 256 |
|
| 257 |
FILE* fich_sortie = fopen("bin.dat", "w") ; |
| 258 |
grid.sauve(fich_sortie) ; |
| 259 |
map_un.sauve(fich_sortie) ; |
| 260 |
map_deux.sauve(fich_sortie) ; |
| 261 |
bin.sauve(fich_sortie) ; |
| 262 |
fclose(fich_sortie) ; |
| 263 |
|
| 264 |
ofstream seqfich("resformat.dat") ; |
| 265 |
if ( !seqfich.good() ) { |
| 266 |
cout << "coal_bh : problem with opening the file resformat.d !" |
| 267 |
<< endl ; |
| 268 |
abort() ; |
| 269 |
} |
| 270 |
bin.write_global(seqfich, lim_nn, bound_nn, bound_psi, bound_beta) ; |
| 271 |
seqfich.close() ; |
| 272 |
|
| 273 |
delete [] nr_tab ; |
| 274 |
delete [] nt_tab ; |
| 275 |
delete [] np_tab ; |
| 276 |
delete [] type_r ; |
| 277 |
delete [] bornes ; |
| 278 |
|
| 279 |
return 1 ; |
| 280 |
} |