Debian Codegraph @

Export/C++/Source/bin_bh.C

raw
1 /*
2 * Methods of class Bin_BH (binary black hole exportation)
3 *
4 * (see file bin_bh.h for documentation).
5 */
6
7 /*
8 * Copyright (c) 2001 Eric Gourgoulhon
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 bin_bh_C[] = "$Header: /cvsroot/Lorene/Export/C++/Source/bin_bh.C,v 1.4 2014/10/13 08:54:05 j_novak Exp $" ;
28
29 /*
30 * $Id: bin_bh.C,v 1.4 2014/10/13 08:54:05 j_novak Exp $
31 * $Log: bin_bh.C,v $
32 * Revision 1.4 2014/10/13 08:54:05 j_novak
33 * Lorene classes and functions now belong to the namespace Lorene.
34 *
35 * Revision 1.3 2006/09/12 08:04:05 j_novak
36 * Removal of the include path Export/C++/Include, updating of the relevant
37 * source files in Export/C++/Source.
38 *
39 * Revision 1.2 2002/03/20 08:24:56 e_gourgoulhon
40 * Added the derivatives of Psi.
41 *
42 * Revision 1.1 2001/12/18 22:27:04 e_gourgoulhon
43 * Exportation of Lorene structures
44 *
45 *
46 *
47 * $Header: /cvsroot/Lorene/Export/C++/Source/bin_bh.C,v 1.4 2014/10/13 08:54:05 j_novak Exp $
48 *
49 */
50
51
52 #include "../Include/bin_bh.h"
53
54 //-----------------------------------------//
55 // Constructor from a binary file //
56 //-----------------------------------------//
57
58 namespace Lorene {
59 Bin_BH::Bin_BH(FILE* fich) {
60
61 fread(&omega, sizeof(double), 1, fich) ;
62 fread(&dist, sizeof(double), 1, fich) ;
63 fread(&radius2, sizeof(double), 1, fich) ;
64 fread(&np, sizeof(int), 1, fich) ;
65
66 alloc_memory() ;
67
68 fread(xx, sizeof(double), np, fich) ;
69 fread(yy, sizeof(double), np, fich) ;
70 fread(zz, sizeof(double), np, fich) ;
71 fread(nnn, sizeof(double), np, fich) ;
72 fread(beta_x, sizeof(double), np, fich) ;
73 fread(beta_y, sizeof(double), np, fich) ;
74 fread(beta_z, sizeof(double), np, fich) ;
75 fread(g_xx, sizeof(double), np, fich) ;
76 fread(g_xy, sizeof(double), np, fich) ;
77 fread(g_xz, sizeof(double), np, fich) ;
78 fread(g_yy, sizeof(double), np, fich) ;
79 fread(g_yz, sizeof(double), np, fich) ;
80 fread(g_zz, sizeof(double), np, fich) ;
81 fread(k_xx, sizeof(double), np, fich) ;
82 fread(k_xy, sizeof(double), np, fich) ;
83 fread(k_xz, sizeof(double), np, fich) ;
84 fread(k_yy, sizeof(double), np, fich) ;
85 fread(k_yz, sizeof(double), np, fich) ;
86 fread(k_zz, sizeof(double), np, fich) ;
87 fread(dpsi_x, sizeof(double), np, fich) ;
88 fread(dpsi_y, sizeof(double), np, fich) ;
89 fread(dpsi_z, sizeof(double), np, fich) ;
90 fread(d2psi_xx, sizeof(double), np, fich) ;
91 fread(d2psi_xy, sizeof(double), np, fich) ;
92 fread(d2psi_xz, sizeof(double), np, fich) ;
93 fread(d2psi_yy, sizeof(double), np, fich) ;
94 fread(d2psi_yz, sizeof(double), np, fich) ;
95 fread(d2psi_zz, sizeof(double), np, fich) ;
96
97
98 }
99
100 //--------------------------------------------//
101 // Constructor from a formatted file //
102 //--------------------------------------------//
103
104 Bin_BH::Bin_BH(ifstream& fich) {
105
106
107 char comment[120] ;
108
109 fich >> omega ; fich.getline(comment, 120) ;
110 fich >> dist ; fich.getline(comment, 120) ;
111 fich >> radius2 ; fich.getline(comment, 120) ;
112 fich >> np ; fich.getline(comment, 120) ;
113
114 alloc_memory() ;
115
116 double* field[] = {xx, yy, zz, nnn, beta_x, beta_y, beta_z,
117 g_xx, g_xy, g_xz, g_yy, g_yz, g_zz,
118 k_xx, k_xy, k_xz, k_yy, k_yz, k_zz,
119 dpsi_x, dpsi_y, dpsi_z,
120 d2psi_xx, d2psi_xy, d2psi_xz,
121 d2psi_yy, d2psi_yz, d2psi_zz} ;
122
123 for (int j=0; j<28; j++) {
124
125 double* pdata = field[j] ;
126
127 for (int i=0; i<np; i++) {
128 fich >> *pdata ;
129 pdata++ ;
130 }
131 }
132
133 }
134
135
136
137
138 //--------------------------//
139 // Destructor //
140 //--------------------------//
141
142
143 Bin_BH::~Bin_BH() {
144
145 delete [] xx ;
146 delete [] yy ;
147 delete [] zz ;
148
149 delete [] nnn ;
150
151 delete [] beta_x ;
152 delete [] beta_y ;
153 delete [] beta_z ;
154
155 delete [] g_xx ;
156 delete [] g_xy ;
157 delete [] g_xz ;
158 delete [] g_yy ;
159 delete [] g_yz ;
160 delete [] g_zz ;
161
162 delete [] k_xx ;
163 delete [] k_xy ;
164 delete [] k_xz ;
165 delete [] k_yy ;
166 delete [] k_yz ;
167 delete [] k_zz ;
168
169 delete [] dpsi_x ;
170 delete [] dpsi_y ;
171 delete [] dpsi_z ;
172
173 delete [] d2psi_xx ;
174 delete [] d2psi_xy ;
175 delete [] d2psi_xz ;
176 delete [] d2psi_yy ;
177 delete [] d2psi_yz ;
178 delete [] d2psi_zz ;
179
180 }
181
182
183 //--------------------------//
184 // Memory allocation //
185 //--------------------------//
186
187 void Bin_BH::alloc_memory() {
188
189 xx = new double[np] ;
190 yy = new double[np] ;
191 zz = new double[np] ;
192
193 nnn = new double[np] ;
194
195 beta_x = new double[np] ;
196 beta_y = new double[np] ;
197 beta_z = new double[np] ;
198
199 g_xx = new double[np] ;
200 g_xy = new double[np] ;
201 g_xz = new double[np] ;
202 g_yy = new double[np] ;
203 g_yz = new double[np] ;
204 g_zz = new double[np] ;
205
206 k_xx = new double[np] ;
207 k_xy = new double[np] ;
208 k_xz = new double[np] ;
209 k_yy = new double[np] ;
210 k_yz = new double[np] ;
211 k_zz = new double[np] ;
212
213 dpsi_x = new double[np] ;
214 dpsi_y = new double[np] ;
215 dpsi_z = new double[np] ;
216
217 d2psi_xx = new double[np] ;
218 d2psi_xy = new double[np] ;
219 d2psi_xz = new double[np] ;
220 d2psi_yy = new double[np] ;
221 d2psi_yz = new double[np] ;
222 d2psi_zz = new double[np] ;
223 }
224
225 //--------------------------//
226 // Outputs //
227 //--------------------------//
228
229 ostream& operator<<(ostream& ost, const Bin_BH& bb) {
230
231 ost << "Binary black hole system :" << endl ;
232 ost << "--------------------------" << endl ;
233 ost << " Separation d/a : " << bb.dist << endl ;
234 ost << " Omega : " << bb.omega << " / a" << endl ;
235 ost << " Size of black hole 2 : " << bb.radius2 << " a" << endl ;
236
237 return ost ;
238 }
239
240
241 //----------------------------------//
242 // Save in a binary file //
243 //----------------------------------//
244
245 void Bin_BH::save_bin(FILE* fresu) const {
246
247 fwrite(&omega, sizeof(double), 1, fresu) ;
248 fwrite(&dist, sizeof(double), 1, fresu) ;
249 fwrite(&radius2, sizeof(double), 1, fresu) ;
250 fwrite(&np, sizeof(int), 1, fresu) ;
251 fwrite(xx, sizeof(double), np, fresu) ;
252 fwrite(yy, sizeof(double), np, fresu) ;
253 fwrite(zz, sizeof(double), np, fresu) ;
254 fwrite(nnn, sizeof(double), np, fresu) ;
255 fwrite(beta_x, sizeof(double), np, fresu) ;
256 fwrite(beta_y, sizeof(double), np, fresu) ;
257 fwrite(beta_z, sizeof(double), np, fresu) ;
258 fwrite(g_xx, sizeof(double), np, fresu) ;
259 fwrite(g_xy, sizeof(double), np, fresu) ;
260 fwrite(g_xz, sizeof(double), np, fresu) ;
261 fwrite(g_yy, sizeof(double), np, fresu) ;
262 fwrite(g_yz, sizeof(double), np, fresu) ;
263 fwrite(g_zz, sizeof(double), np, fresu) ;
264 fwrite(k_xx, sizeof(double), np, fresu) ;
265 fwrite(k_xy, sizeof(double), np, fresu) ;
266 fwrite(k_xz, sizeof(double), np, fresu) ;
267 fwrite(k_yy, sizeof(double), np, fresu) ;
268 fwrite(k_yz, sizeof(double), np, fresu) ;
269 fwrite(k_zz, sizeof(double), np, fresu) ;
270 fwrite(dpsi_x, sizeof(double), np, fresu) ;
271 fwrite(dpsi_y, sizeof(double), np, fresu) ;
272 fwrite(dpsi_z, sizeof(double), np, fresu) ;
273 fwrite(d2psi_xx, sizeof(double), np, fresu) ;
274 fwrite(d2psi_xy, sizeof(double), np, fresu) ;
275 fwrite(d2psi_xz, sizeof(double), np, fresu) ;
276 fwrite(d2psi_yy, sizeof(double), np, fresu) ;
277 fwrite(d2psi_yz, sizeof(double), np, fresu) ;
278 fwrite(d2psi_zz, sizeof(double), np, fresu) ;
279
280 }
281
282
283 //----------------------------------//
284 // Save in a formatted file //
285 //----------------------------------//
286
287 void Bin_BH::save_form(ofstream& fich) const {
288
289 fich.precision(13) ;
290 fich.setf(ios::scientific, ios::floatfield) ;
291
292 fich << omega << " Omega [a^{-1}]" << endl ;
293 fich << dist << " dist [a]" << endl ;
294 fich << radius2 << " radius2 [a]" << endl ;
295 fich << np << " Number of grid points" << endl ;
296
297 int dpl = 6 ; // number of data per line
298
299 int nlines = np / dpl ; // number of filled lines
300 int reste = np - nlines * dpl ; // number of remaining data
301
302 const double* field[] = {xx, yy, zz, nnn, beta_x, beta_y, beta_z,
303 g_xx, g_xy, g_xz, g_yy, g_yz, g_zz,
304 k_xx, k_xy, k_xz, k_yy, k_yz, k_zz,
305 dpsi_x, dpsi_y, dpsi_z,
306 d2psi_xx, d2psi_xy, d2psi_xz,
307 d2psi_yy, d2psi_yz, d2psi_zz} ;
308
309
310 for (int j=0; j<28; j++) {
311
312 const double* pdata = field[j] ;
313
314 for (int line = 0; line < nlines; line++) {
315 for (int i=0; i<dpl; i++) {
316 fich << *pdata << " " ;
317 pdata++ ;
318 }
319 fich << endl ;
320 }
321 for (int i=0; i<reste; i++) {
322 fich << *pdata << " " ;
323 pdata++ ;
324 }
325 fich << endl ;
326
327 }
328
329 }
330
331 }