Debian Codegraph @

Export/BinBH/visu_1d.C

raw
1 /*
2 * Reads from a file a binary black hole configuration on a Cartesian grid
3 * (created by readinit), extract one field and save it in a formatted
4 * file for producing plots with Grace.
5 *
6 */
7
8 /*
9 * Copyright (c) 2002 Eric Gourgoulhon
10 *
11 * This file is part of LORENE.
12 *
13 * LORENE is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License version 2
15 * as published by the Free Software Foundation.
16 *
17 * LORENE is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with LORENE; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
26 */
27
28 char visu_1d_C[] = "$Header: /cvsroot/Lorene/Export/BinBH/visu_1d.C,v 1.4 2014/10/13 08:54:04 j_novak Exp $" ;
29
30 /*
31 * $Id: visu_1d.C,v 1.4 2014/10/13 08:54:04 j_novak Exp $
32 * $Log: visu_1d.C,v $
33 * Revision 1.4 2014/10/13 08:54:04 j_novak
34 * Lorene classes and functions now belong to the namespace Lorene.
35 *
36 * Revision 1.3 2014/10/06 15:09:46 j_novak
37 * Modified #include directives to use c++ syntax.
38 *
39 * Revision 1.2 2003/01/09 11:07:59 j_novak
40 * headcpp.h is now compliant with C++ norm.
41 * The include files have been ordered, as well as the local_settings_linux
42 *
43 * Revision 1.1 2002/03/20 08:24:56 e_gourgoulhon
44 * Added the derivatives of Psi.
45 *
46 *
47 *
48 *
49 * $Header: /cvsroot/Lorene/Export/BinBH/visu_1d.C,v 1.4 2014/10/13 08:54:04 j_novak Exp $
50 *
51 */
52
53 // C headers
54 #include <cstdlib>
55 #include <cmath>
56
57 // Definition of Bin_BH class
58 #include "bin_bh.h"
59
60
61 using namespace Lorene ;
62
63 int main() {
64
65 // Reads Cartesian grid parameters
66 // -------------------------------
67 ifstream fparam("readinit.par") ;
68 char comment[120] ;
69 char datafile[120] ;
70 int nx, ny, nz, fill ;
71 double x_min, x_max, y_min, y_max, z_min, z_max ;
72 fparam.getline(comment, 120) ;
73 fparam.getline(comment, 120) ;
74 fparam.getline(datafile, 120) ;
75 fparam.getline(comment, 120) ;
76 fparam.getline(comment, 120) ;
77 fparam.getline(comment, 120) ;
78 fparam >> fill ; fparam.getline(comment, 120) ;
79 fparam >> nx ; fparam.getline(comment, 120) ;
80 fparam >> ny ; fparam.getline(comment, 120) ;
81 fparam >> nz ; fparam.getline(comment, 120) ;
82 fparam >> x_min ; fparam >> x_max ; fparam.getline(comment, 120) ;
83 fparam >> y_min ; fparam >> y_max ; fparam.getline(comment, 120) ;
84 fparam >> z_min ; fparam >> z_max ; fparam.getline(comment, 120) ;
85 fparam.close() ;
86
87 cout << "File containing the initial data on the Cartesian grid:"
88 << endl ;
89 cout << "bin_bh.d" << endl << endl ;
90 cout << "Cartesian grid : " << endl ;
91 cout << "---------------- " << endl ;
92 cout << " Number of points in the x direction : " << nx << endl ;
93 cout << " Number of points in the y direction : " << ny << endl ;
94 cout << " Number of points in the z direction : " << nz << endl ;
95 cout << " x_min, x_max : " << x_min << " , " << x_max << endl ;
96 cout << " y_min, y_max : " << y_min << " , " << y_max << endl ;
97 cout << " z_min, z_max : " << z_min << " , " << z_max << endl ;
98
99 // Construction of the Cartesian grid
100 // ----------------------------------
101
102 double* const xx = new double[nx] ;
103 double* const yy = new double[ny] ;
104 double* const zz = new double[nz] ;
105
106 double dx = (nx == 1) ? 0 : (x_max - x_min) / double(nx - 1) ;
107 double dy = (ny == 1) ? 0 : (y_max - y_min) / double(ny - 1) ;
108 double dz = (nz == 1) ? 0 : (z_max - z_min) / double(nz - 1) ;
109
110 for (int i=0; i<nx; i++) {
111 xx[i] = x_min + dx * i ;
112 }
113
114 for (int i=0; i<ny; i++) {
115 yy[i] = y_min + dy * i ;
116 }
117
118 for (int i=0; i<nz; i++) {
119 zz[i] = z_min + dz * i ;
120 }
121
122 // Read configuration from file
123 FILE* fichbin = fopen("binbh.d", "r") ;
124 Bin_BH binary(fichbin) ;
125 fclose(fichbin) ;
126
127 cout << endl << "Configuration read in file: " << endl ;
128 cout << binary << endl ;
129
130 cout << "Type of profiles : " << endl ;
131 cout << "---------------- " << endl ;
132 cout << " 1 : along x, for all y, at fixed value of z" << endl ;
133 cout << " 2 : along x, for all z, at fixed value of y" << endl ;
134 cout << " 3 : along y, for all x, at fixed value of z" << endl ;
135 cout << " 4 : along y, for all z, at fixed value of x" << endl ;
136 cout << " 5 : along z, for all x, at fixed value of y" << endl ;
137 cout << " 6 : along z, for all y, at fixed value of x" << endl ;
138 cout << "Your choice ?" << endl ;
139 int type_plot ;
140 cin >> type_plot ;
141 int indplane ;
142 switch (type_plot) {
143 case 1 : case 3 : {
144 cout << "z index (defining the plot plane) ?" << endl ;
145 cin >> indplane ;
146 if ( (indplane<0) || (indplane>=nz) ) {
147 cout << "visu_1d: z index out of range !" << endl ;
148 abort() ;
149 }
150 break ;
151 }
152
153 case 2 : case 5 : {
154 cout << "y index (defining the plot plane) ?" << endl ;
155 cin >> indplane ;
156 if ( (indplane<0) || (indplane>=ny) ) {
157 cout << "visu_1d: y index out of range !" << endl ;
158 abort() ;
159 }
160 break ;
161 }
162
163 case 4 : case 6 : {
164 cout << "x index (defining the plot plane) ?" << endl ;
165 cin >> indplane ;
166 if ( (indplane<0) || (indplane>=nx) ) {
167 cout << "visu_1d: x index out of range !" << endl ;
168 abort() ;
169 }
170 break ;
171 }
172
173 default : {
174 cout << "visu_1d: Invalid type of profiles !" << endl ;
175 abort() ;
176 }
177
178 }
179
180
181 ofstream fich("plot.d") ;
182
183 fich.precision(8) ;
184 fich.setf(ios::scientific, ios::floatfield) ;
185
186 fich << "# " << binary.dist << " dist [a]" << endl ;
187 fich << "# nx, ny, nz : " << nx << " " << ny << " " << nz << endl ;
188 fich << "# x_min, dx : " << x_min << " " << dx << endl ;
189 fich << "# y_min, dy : " << y_min << " " << dy << endl ;
190 fich << "# z_min, dz : " << z_min << " " << dz << endl ;
191
192 const double* uu = binary.nnn ;
193
194 switch (type_plot) {
195
196 case 1 : {
197
198 for (int i=0; i<nx; i++) {
199 fich << xx[i] ;
200 for (int j=0; j<ny; j++) {
201 int index = indplane*nx*ny + j*nx + i ;
202 fich << " " << uu[index] ;
203 }
204 fich << endl ;
205 }
206 break ;
207 }
208
209 case 2 : {
210
211 for (int i=0; i<nx; i++) {
212 fich << xx[i] ;
213 for (int j=0; j<nz; j++) {
214 int index = j*nx*ny + indplane*nx + i ;
215 fich << " " << uu[index] ;
216 }
217 fich << endl ;
218 }
219 break ;
220 }
221
222 case 3 : {
223
224 for (int i=0; i<ny; i++) {
225 fich << yy[i] ;
226 for (int j=0; j<nx; j++) {
227 int index = indplane*nx*ny + i*nx + j ;
228 fich << " " << uu[index] ;
229 }
230 fich << endl ;
231 }
232 break ;
233 }
234
235 case 4 : {
236
237 for (int i=0; i<ny; i++) {
238 fich << yy[i] ;
239 for (int j=0; j<nz; j++) {
240 int index = j*nx*ny + i*nx + indplane ;
241 fich << " " << uu[index] ;
242 }
243 fich << endl ;
244 }
245 break ;
246 }
247
248 case 5 : {
249
250 for (int i=0; i<nz; i++) {
251 fich << zz[i] ;
252 for (int j=0; j<nx; j++) {
253 int index = i*nx*ny + indplane*nx + j ;
254 fich << " " << uu[index] ;
255 }
256 fich << endl ;
257 }
258 break ;
259 }
260
261 case 6 : {
262
263 for (int i=0; i<nz; i++) {
264 fich << zz[i] ;
265 for (int j=0; j<ny; j++) {
266 int index = i*nx*ny + j*nx + indplane ;
267 fich << " " << uu[index] ;
268 }
269 fich << endl ;
270 }
271 break ;
272 }
273
274 default : {
275 cout << "visu_1d: Invalid type of profiles !" << endl ;
276 abort() ;
277 }
278
279
280 }
281 fich.close() ;
282
283
284 // Clean exit
285 // ----------
286
287 delete [] xx ;
288 delete [] yy ;
289 delete [] zz ;
290
291 return EXIT_SUCCESS ;
292
293 }
294