Debian Codegraph @

Export/BinBH/readinit.C

raw
1 /*
2 * Reads binary black hole initial data, exporting Lorene structures
3 * onto standard C arrays (double[]) on a Cartesian grid.
4 */
5
6 /*
7 * Copyright (c) 2001-2002 Eric Gourgoulhon
8 *
9 * This file is part of LORENE.
10 *
11 * LORENE is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2
13 * as published by the Free Software Foundation.
14 *
15 * LORENE is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with LORENE; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 *
24 */
25
26 char readinit_C[] = "$Header: /cvsroot/Lorene/Export/BinBH/readinit.C,v 1.8 2014/10/13 08:54:04 j_novak Exp $" ;
27
28 /*
29 * $Id: readinit.C,v 1.8 2014/10/13 08:54:04 j_novak Exp $
30 * $Log: readinit.C,v $
31 * Revision 1.8 2014/10/13 08:54:04 j_novak
32 * Lorene classes and functions now belong to the namespace Lorene.
33 *
34 * Revision 1.7 2014/10/06 15:09:46 j_novak
35 * Modified #include directives to use c++ syntax.
36 *
37 * Revision 1.6 2003/01/09 11:07:59 j_novak
38 * headcpp.h is now compliant with C++ norm.
39 * The include files have been ordered, as well as the local_settings_linux
40 *
41 * Revision 1.5 2002/03/20 08:24:56 e_gourgoulhon
42 * Added the derivatives of Psi.
43 *
44 * Revision 1.4 2002/02/06 14:54:44 e_gourgoulhon
45 * Update of bibliographical references
46 *
47 * Revision 1.3 2002/01/09 16:32:57 e_gourgoulhon
48 * Added the parameter fill in readinit.par
49 * Suppressed the multiple outputs in files ini* via method sauve
50 * Output directly written in readinit.C
51 *
52 * Revision 1.2 2001/12/18 09:08:14 e_gourgoulhon
53 * Adds the filling of the holes interiors
54 *
55 * Revision 1.1 2001/12/14 08:59:18 e_gourgoulhon
56 * Exportation of Lorene Bhole_binaire object to a Cartesian grid
57 *
58 *
59 * $Header: /cvsroot/Lorene/Export/BinBH/readinit.C,v 1.8 2014/10/13 08:54:04 j_novak Exp $
60 *
61 */
62
63 // C headers
64 #include <cstdlib>
65
66 // Definition of Bin_BH class
67 #include "bin_bh.h"
68
69 using namespace Lorene ;
70
71 int main() {
72
73 // Reads Cartesian grid parameters
74 // -------------------------------
75 ifstream fparam("readinit.par") ;
76 char comment[120] ;
77 char datafile[120] ;
78 int nx, ny, nz, fill ;
79 double x_min, x_max, y_min, y_max, z_min, z_max ;
80 fparam.getline(comment, 120) ;
81 fparam.getline(comment, 120) ;
82 fparam.getline(datafile, 120) ;
83 fparam.getline(comment, 120) ;
84 fparam.getline(comment, 120) ;
85 fparam.getline(comment, 120) ;
86 fparam >> fill ; fparam.getline(comment, 120) ;
87 fparam >> nx ; fparam.getline(comment, 120) ;
88 fparam >> ny ; fparam.getline(comment, 120) ;
89 fparam >> nz ; fparam.getline(comment, 120) ;
90 fparam >> x_min ; fparam >> x_max ; fparam.getline(comment, 120) ;
91 fparam >> y_min ; fparam >> y_max ; fparam.getline(comment, 120) ;
92 fparam >> z_min ; fparam >> z_max ; fparam.getline(comment, 120) ;
93 fparam.close() ;
94
95 cout << "File containing the initial data on the spectral grid:"
96 << endl ;
97 cout << datafile << endl << endl ;
98 cout << "Cartesian grid : " << endl ;
99 cout << "---------------- " << endl ;
100 cout << " Number of points in the x direction : " << nx << endl ;
101 cout << " Number of points in the y direction : " << ny << endl ;
102 cout << " Number of points in the z direction : " << nz << endl ;
103 cout << " x_min, x_max : " << x_min << " , " << x_max << endl ;
104 cout << " y_min, y_max : " << y_min << " , " << y_max << endl ;
105 cout << " z_min, z_max : " << z_min << " , " << z_max << endl ;
106
107 // Construction of the Cartesian grid
108 // ----------------------------------
109
110 int nbp = nx*ny*nz ;
111 double* const xi = new double[nbp] ;
112 double* const yi = new double[nbp] ;
113 double* const zi = new double[nbp] ;
114
115 double dx = (nx == 1) ? 0 : (x_max - x_min) / double(nx - 1) ;
116 double dy = (ny == 1) ? 0 : (y_max - y_min) / double(ny - 1) ;
117 double dz = (nz == 1) ? 0 : (z_max - z_min) / double(nz - 1) ;
118
119 double* pxi = xi ;
120 double* pyi = yi ;
121 double* pzi = zi ;
122
123 for (int k=0; k<nz; k++) {
124
125 double z = z_min + dz * k ;
126
127 for (int j=0; j<ny; j++) {
128
129 double y = y_min + dy * j ;
130
131 for (int i=0; i<nx; i++) {
132
133 *pxi = x_min + dx * i ;
134 *pyi = y ;
135 *pzi = z ;
136
137 pxi++ ;
138 pyi++ ;
139 pzi++ ;
140 }
141 }
142 }
143
144 // Read of the initial data file and computation of the
145 // fields at the Cartesian grid points
146 // ----------------------------------------------------
147
148 Bin_BH binary(nbp, xi, yi, zi, fill, datafile) ;
149
150 cout << binary << endl ;
151
152 ofstream fich("readout.d") ;
153
154 fich.precision(13) ;
155 fich.setf(ios::scientific, ios::floatfield) ;
156
157 fich << binary.dist << " dist [a]" << endl ;
158 fich << "nx, ny, nz : " << nx << " " << ny << " " << nz << endl ;
159 fich << "x_min, dx : " << x_min << " " << dx << endl ;
160 fich << "y_min, dy : " << y_min << " " << dy << endl ;
161 fich << "z_min, dz : " << z_min << " " << dz << endl ;
162
163 int index = 0 ;
164
165 for (int k=0; k<nz; k++) {
166
167 for (int j=0; j<ny; j++) {
168
169 for (int i=0; i<nx; i++) {
170
171 fich << i
172 << " " << binary.g_xx[index] << " " << binary.g_xy[index] << " " << binary.g_xz[index]
173 << " " << binary.g_yy[index] << " " << binary.g_yz[index] << " " << binary.g_zz[index]
174 << " " << binary.k_xx[index] << " " << binary.k_xy[index] << " " << binary.k_xz[index]
175 << " " << binary.k_yy[index] << " " << binary.k_yz[index] << " " << binary.k_zz[index]
176 << " " << binary.beta_x[index] << " " << binary.beta_y[index]
177 << " " << binary.beta_z[index] << " " << binary.nnn[index] << endl ;
178
179 index++ ;
180
181 }
182 }
183
184 }
185
186
187 fich.close() ;
188
189
190
191 // Save in a binary file
192 // ---------------------
193 FILE* finib = fopen("binbh.d", "w") ;
194 binary.save_bin(finib) ;
195 fclose( finib ) ;
196
197 // Save in a formatted file
198 // ------------------------
199 // ofstream finif("inif.d") ;
200 // binary.save_form(finif) ;
201 // finif.close() ;
202
203
204 // Clean exit
205 // ----------
206
207 delete [] xi ;
208 delete [] yi ;
209 delete [] zi ;
210
211 return EXIT_SUCCESS ;
212
213 }