| 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 coal_seq_C[] = "$Header: /cvsroot/Lorene/Codes/Bin_hor/coal_seq.C,v 1.8 2014/10/13 08:53:53 j_novak Exp $" ; |
| 28 |
|
| 29 |
/* |
| 30 |
* $Id: coal_seq.C,v 1.8 2014/10/13 08:53:53 j_novak Exp $ |
| 31 |
* $Log: coal_seq.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:41 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/coal_seq.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_seq("par_seq.d") ; |
| 81 |
|
| 82 |
double precis, relax, radius, separ, lim_nn ; |
| 83 |
int nz, nt, np, nr1, nrp1, bound_nn, bound_psi ; |
| 84 |
double omega_init, precis_viriel, separ_min, separ_max, mass_irr ; |
| 85 |
int nb_om, nb_it, bound_beta, nb_conf, search_mass ; |
| 86 |
|
| 87 |
param_seq.getline(blabla, 120) ; |
| 88 |
param_seq.getline(blabla, 120) ; |
| 89 |
param_seq >> nt; param_seq.ignore(1000, '\n'); |
| 90 |
param_seq >> np; param_seq.ignore(1000, '\n'); |
| 91 |
param_seq >> nr1; param_seq.ignore(1000, '\n'); |
| 92 |
param_seq >> nrp1; param_seq.ignore(1000, '\n'); |
| 93 |
param_seq >> precis ; param_seq.getline(blabla, 120) ; |
| 94 |
param_seq >> relax ; param_seq.getline(blabla, 120) ; |
| 95 |
param_seq >> bound_nn ; |
| 96 |
param_seq >> lim_nn ; param_seq.ignore(1000, '\n'); |
| 97 |
param_seq >> bound_psi ; param_seq.ignore(1000, '\n'); |
| 98 |
param_seq >> omega_init ; param_seq.getline(blabla, 120) ; |
| 99 |
param_seq >> search_mass ; |
| 100 |
param_seq >> mass_irr ; param_seq.ignore(1000, '\n'); |
| 101 |
param_seq >> precis_viriel ; param_seq.getline(blabla, 120) ; |
| 102 |
param_seq >> nb_om ; param_seq.getline(blabla, 120) ; |
| 103 |
param_seq >> nb_it ; param_seq.getline(blabla, 120) ; |
| 104 |
param_seq >> bound_beta ; param_seq.getline(blabla, 120) ; |
| 105 |
param_seq >> nb_conf ; param_seq.getline(blabla, 120) ; |
| 106 |
param_seq >> separ_min ; param_seq.getline(blabla, 120) ; |
| 107 |
param_seq >> separ_max ; param_seq.getline(blabla, 120) ; |
| 108 |
|
| 109 |
if (nb_conf <=1) { |
| 110 |
cout << "too small value of nb_conf" << endl ; |
| 111 |
abort() ; |
| 112 |
} |
| 113 |
|
| 114 |
param_seq.close() ; |
| 115 |
|
| 116 |
for (int conf=0; conf<nb_conf; conf++){ |
| 117 |
separ = separ_min + conf * (separ_max-separ_min)/(nb_conf-1) ; |
| 118 |
|
| 119 |
// To improve ??? |
| 120 |
if (separ < 16) omega_init = 0.03 ; |
| 121 |
else omega_init = 0.015 ; |
| 122 |
|
| 123 |
|
| 124 |
if (separ <= 7){ |
| 125 |
cout << "too small value of separation" << endl ; |
| 126 |
abort() ; |
| 127 |
} |
| 128 |
|
| 129 |
if (separ > 30){ |
| 130 |
cout << "too large value of separation" << endl ; |
| 131 |
abort() ; |
| 132 |
} |
| 133 |
|
| 134 |
if (separ <= 16) nz = 6 ; |
| 135 |
else nz = 7 ; |
| 136 |
|
| 137 |
|
| 138 |
double* bornes = new double[nz+1] ; |
| 139 |
int* nr_tab = new int[nz]; |
| 140 |
int* nt_tab = new int[nz]; |
| 141 |
int* np_tab = new int[nz]; |
| 142 |
|
| 143 |
for (int l=0 ; l<nz ; l++){ |
| 144 |
if (l==1) nr_tab[1] = nr1 ; |
| 145 |
else nr_tab[l] = nrp1 ; |
| 146 |
np_tab[l] = np ; |
| 147 |
nt_tab[l] = nt ; |
| 148 |
} |
| 149 |
bornes[0] = 0 ; |
| 150 |
bornes[1] = 1 ; |
| 151 |
bornes[2] = 2 ; |
| 152 |
bornes[3] = 4 ; |
| 153 |
if (separ >=10) bornes[4] = 8 ; |
| 154 |
else{ |
| 155 |
bornes[4] = 6 ; |
| 156 |
bornes[5] = 12 ; |
| 157 |
} |
| 158 |
if (separ >=10 && separ <= 14) bornes[5] = 16 ; |
| 159 |
if (separ > 14 && separ <= 16) bornes[5] = 18 ; |
| 160 |
if (separ > 16 && separ <= 18){ |
| 161 |
bornes[5] = 14 ; |
| 162 |
bornes[6] = 28 ; |
| 163 |
} |
| 164 |
if (separ > 18){ |
| 165 |
bornes[5] = 16 ; |
| 166 |
bornes[6] = 32 ; |
| 167 |
} |
| 168 |
bornes[nz] = __infinity ; |
| 169 |
|
| 170 |
radius = 1. ; |
| 171 |
|
| 172 |
// Type of sampling in theta and phi : |
| 173 |
int type_t = SYM ; |
| 174 |
int type_p = NONSYM ; |
| 175 |
|
| 176 |
int* type_r = new int[nz] ; |
| 177 |
type_r[0] = RARE ; |
| 178 |
for (int l=1 ; l<nz-1 ; l++) |
| 179 |
type_r[l] = FIN ; |
| 180 |
type_r[nz-1] = UNSURR ; |
| 181 |
|
| 182 |
Mg3d grid (nz, nr_tab, type_r, nt_tab, type_t, np_tab, type_p) ; |
| 183 |
|
| 184 |
Map_af map_un (grid, bornes) ; |
| 185 |
Map_af map_deux (grid, bornes) ; |
| 186 |
|
| 187 |
map_un.set_ori (separ/2.,0, 0) ; |
| 188 |
map_deux.set_ori (-separ/2., 0, 0) ; |
| 189 |
map_deux.set_rot_phi (M_PI) ; |
| 190 |
|
| 191 |
cout << map_un << endl ; |
| 192 |
|
| 193 |
Bin_hor bin (map_un, map_deux) ; |
| 194 |
bin.set_statiques(precis, relax, bound_nn, lim_nn, bound_psi) ; |
| 195 |
|
| 196 |
char name[40] ; |
| 197 |
sprintf(name, "static_%e.d", separ) ; |
| 198 |
|
| 199 |
FILE* fich = fopen(name, "w") ; |
| 200 |
grid.sauve(fich) ; |
| 201 |
map_un.sauve(fich) ; |
| 202 |
map_deux.sauve(fich) ; |
| 203 |
bin.sauve(fich) ; |
| 204 |
fwrite_be(&bound_nn, sizeof(int), 1, fich) ; |
| 205 |
fwrite_be (&lim_nn, sizeof(double), 1, fich) ; |
| 206 |
fwrite_be(&bound_psi, sizeof(int), 1, fich) ; |
| 207 |
fclose(fich) ; |
| 208 |
|
| 209 |
// Drawings |
| 210 |
const Coord& r = bin(1).get_mp().r ; // r field |
| 211 |
Mtbl usr = 1 / r ; |
| 212 |
Scalar unsr(bin(1).get_mp()) ; |
| 213 |
unsr = usr ; |
| 214 |
|
| 215 |
Scalar temp = 1. + unsr ; |
| 216 |
temp.std_spectral_base() ; |
| 217 |
|
| 218 |
// Part of coal |
| 219 |
// ------------ |
| 220 |
|
| 221 |
bin.set_omega(0) ; |
| 222 |
bin.set(1).n_comp_import (bin(2)) ; |
| 223 |
bin.set(1).psi_comp_import (bin(2)) ; |
| 224 |
bin.set(1).beta_comp_import (bin(2)) ; |
| 225 |
bin.set(2).n_comp_import (bin(1)) ; |
| 226 |
bin.set(2).psi_comp_import (bin(1)) ; |
| 227 |
bin.set(2).beta_comp_import (bin(1)) ; |
| 228 |
bin.decouple() ; |
| 229 |
bin.extrinsic_curvature() ; |
| 230 |
|
| 231 |
cout << "CALCUL AVEC SEPARATION = " << separ << endl ; |
| 232 |
|
| 233 |
sprintf(name, "iteration_%e.dat", separ) ; |
| 234 |
ofstream fich_iteration(name) ; |
| 235 |
fich_iteration.precision(8) ; |
| 236 |
|
| 237 |
sprintf(name, "correction_%e.dat", separ) ; |
| 238 |
ofstream fich_correction(name) ; |
| 239 |
fich_correction.precision(8) ; |
| 240 |
|
| 241 |
sprintf(name, "viriel_%e.dat", separ) ; |
| 242 |
ofstream fich_viriel(name) ; |
| 243 |
fich_viriel.precision(8) ; |
| 244 |
|
| 245 |
|
| 246 |
sprintf(name, "kss_%e.dat", separ) ; |
| 247 |
ofstream fich_kss(name) ; |
| 248 |
fich_kss.precision(8) ; |
| 249 |
|
| 250 |
fich_iteration << "# step precision omega" << endl ; |
| 251 |
fich_correction << "# step regularisation omega" << endl ; |
| 252 |
fich_viriel << "# step viriel omega" << endl ; |
| 253 |
fich_kss << "# step kss omega" << endl ; |
| 254 |
|
| 255 |
int step = 0 ; |
| 256 |
|
| 257 |
cout << "step = " << step << endl ; |
| 258 |
double erreur = bin.coal(omega_init, relax, nb_om, nb_it, bound_nn, |
| 259 |
lim_nn, bound_psi, bound_beta, |
| 260 |
fich_iteration, fich_correction, |
| 261 |
fich_viriel, fich_kss, step, search_mass, |
| 262 |
mass_irr, 1) ; |
| 263 |
|
| 264 |
step += nb_om + nb_it ; |
| 265 |
|
| 266 |
|
| 267 |
// Convergence to the true Omega |
| 268 |
// ------------------------------ |
| 269 |
|
| 270 |
bool boucle = true ; |
| 271 |
double omega = omega_init ; |
| 272 |
|
| 273 |
while (boucle) { |
| 274 |
|
| 275 |
omega = omega * pow((2-erreur)/(2-2*erreur), 1.) ; |
| 276 |
|
| 277 |
Scalar beta_old (bin(1).get_beta_auto()(1)) ; |
| 278 |
|
| 279 |
erreur = bin.coal (omega, relax, 1, 0, bound_nn, |
| 280 |
lim_nn, bound_psi, bound_beta, |
| 281 |
fich_iteration, fich_correction, |
| 282 |
fich_viriel, fich_kss, step, search_mass, |
| 283 |
mass_irr, 1) ; |
| 284 |
|
| 285 |
double erreur_it = 0 ; |
| 286 |
Tbl diff (diffrelmax (beta_old, bin(1).get_beta_auto()(1))) ; |
| 287 |
for (int i=1 ; i<bin(1).get_mp().get_mg()->get_nzone() ; i++) |
| 288 |
if (diff(i) > erreur_it) |
| 289 |
erreur_it = diff(i) ; |
| 290 |
|
| 291 |
if (fabs(erreur) < precis_viriel && erreur_it < precis_viriel) |
| 292 |
boucle = false ; |
| 293 |
|
| 294 |
step += 1 ; |
| 295 |
|
| 296 |
} |
| 297 |
|
| 298 |
fich_iteration.close() ; |
| 299 |
fich_correction.close() ; |
| 300 |
fich_viriel.close() ; |
| 301 |
fich_kss.close() ; |
| 302 |
|
| 303 |
sprintf(name, "bin_%e.dat", separ) ; |
| 304 |
FILE* fich_sortie = fopen(name, "w") ; |
| 305 |
grid.sauve(fich_sortie) ; |
| 306 |
map_un.sauve(fich_sortie) ; |
| 307 |
map_deux.sauve(fich_sortie) ; |
| 308 |
bin.sauve(fich_sortie) ; |
| 309 |
fclose(fich_sortie) ; |
| 310 |
|
| 311 |
|
| 312 |
sprintf(name, "resformat_%e.dat", separ) ; |
| 313 |
ofstream seqfich(name) ; |
| 314 |
if ( !seqfich.good() ) { |
| 315 |
cout << "coal_bh : problem with opening the file resformat.d !" |
| 316 |
<< endl ; |
| 317 |
abort() ; |
| 318 |
} |
| 319 |
bin.write_global(seqfich, lim_nn, bound_nn, bound_psi, bound_beta) ; |
| 320 |
seqfich.close() ; |
| 321 |
|
| 322 |
delete [] nr_tab ; |
| 323 |
delete [] nt_tab ; |
| 324 |
delete [] np_tab ; |
| 325 |
delete [] type_r ; |
| 326 |
delete [] bornes ; |
| 327 |
} |
| 328 |
|
| 329 |
return 1 ; |
| 330 |
} |