Debian Codegraph @

Export/BinNS/read_bin_ns.C

raw
1 /*
2 * Reads binary neutron star initial data, exporting Lorene structures
3 * onto standard C arrays (double[]) on a Cartesian grid.
4 */
5
6 /*
7 * Copyright (c) 2002 Eric Gourgoulhon
8 * Copyright (c) 2002 Keisuke Taniguchi
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 read_bin_ns_C[] = "$Header: /cvsroot/Lorene/Export/BinNS/read_bin_ns.C,v 1.5 2014/10/13 08:54:05 j_novak Exp $" ;
28
29 /*
30 * $Id: read_bin_ns.C,v 1.5 2014/10/13 08:54:05 j_novak Exp $
31 * $Log: read_bin_ns.C,v $
32 * Revision 1.5 2014/10/13 08:54:05 j_novak
33 * Lorene classes and functions now belong to the namespace Lorene.
34 *
35 * Revision 1.4 2014/10/06 15:09:47 j_novak
36 * Modified #include directives to use c++ syntax.
37 *
38 * Revision 1.3 2003/01/09 11:08:00 j_novak
39 * headcpp.h is now compliant with C++ norm.
40 * The include files have been ordered, as well as the local_settings_linux
41 *
42 * Revision 1.2 2002/01/15 09:35:33 e_gourgoulhon
43 * Added README file
44 * Suppressed outputs/inputs in read_bin_ns.C
45 *
46 * Revision 1.1 2002/01/11 17:16:14 e_gourgoulhon
47 * Main code and documentation for exporting binary neutron stars
48 *
49 *
50 * $Header: /cvsroot/Lorene/Export/BinNS/read_bin_ns.C,v 1.5 2014/10/13 08:54:05 j_novak Exp $
51 *
52 */
53
54 // C headers
55 #include <cstdlib>
56
57 // Definition of Bin_NS class
58 #include "bin_ns.h"
59
60 using namespace Lorene ;
61
62 int main() {
63
64 // Reads Cartesian grid parameters
65 // -------------------------------
66 ifstream fparam("read_bin_ns.par") ;
67 char comment[120] ;
68 char datafile[120] ;
69 int nx, ny, nz ;
70 double x_min, x_max, y_min, y_max, z_min, z_max ;
71 fparam.getline(comment, 120) ;
72 fparam.getline(comment, 120) ;
73 fparam.getline(datafile, 120) ;
74 fparam.getline(comment, 120) ;
75 fparam.getline(comment, 120) ;
76 fparam.getline(comment, 120) ;
77 fparam >> nx ; fparam.getline(comment, 120) ;
78 fparam >> ny ; fparam.getline(comment, 120) ;
79 fparam >> nz ; fparam.getline(comment, 120) ;
80 fparam >> x_min ; fparam >> x_max ; fparam.getline(comment, 120) ;
81 fparam >> y_min ; fparam >> y_max ; fparam.getline(comment, 120) ;
82 fparam >> z_min ; fparam >> z_max ; fparam.getline(comment, 120) ;
83 fparam.close() ;
84
85 cout << "File containing the initial data on the spectral grid:"
86 << endl ;
87 cout << datafile << endl << endl ;
88 cout << "Cartesian grid : " << endl ;
89 cout << "---------------- " << endl ;
90 cout << " Number of points in the x direction : " << nx << endl ;
91 cout << " Number of points in the y direction : " << ny << endl ;
92 cout << " Number of points in the z direction : " << nz << endl ;
93 cout << " x_min, x_max : " << x_min << " , " << x_max << endl ;
94 cout << " y_min, y_max : " << y_min << " , " << y_max << endl ;
95 cout << " z_min, z_max : " << z_min << " , " << z_max << endl ;
96
97 // Construction of the Cartesian grid
98 // ----------------------------------
99
100 int nbp = nx*ny*nz ;
101 double* const xi = new double[nbp] ;
102 double* const yi = new double[nbp] ;
103 double* const zi = new double[nbp] ;
104
105 double dx = (x_max - x_min) / double(nx - 1) ;
106 double dy = (y_max - y_min) / double(ny - 1) ;
107 double dz = (z_max - z_min) / double(nz - 1) ;
108
109 double* pxi = xi ;
110 double* pyi = yi ;
111 double* pzi = zi ;
112
113 for (int k=0; k<nz; k++) {
114
115 double z = z_min + dz * k ;
116
117 for (int j=0; j<ny; j++) {
118
119 double y = y_min + dy * j ;
120
121 for (int i=0; i<nx; i++) {
122
123 *pxi = x_min + dx * i ;
124 *pyi = y ;
125 *pzi = z ;
126
127 pxi++ ;
128 pyi++ ;
129 pzi++ ;
130 }
131 }
132 }
133
134 // Read of the initial data file and computation of the
135 // fields at the Cartesian grid points
136 // ----------------------------------------------------
137
138 Bin_NS binary(nbp, xi, yi, zi, datafile) ;
139
140 cout << endl << binary << endl ;
141
142
143 // Save in a binary file
144 // ---------------------
145 FILE* finib = fopen("inib.d", "w") ;
146 binary.save_bin(finib) ;
147 fclose( finib ) ;
148
149 // Save in a formatted file
150 // ------------------------
151 ofstream finif("inif.d") ;
152 binary.save_form(finif) ;
153 finif.close() ;
154
155 // Create a new object from a binary file
156 //---------------------------------------
157 // finib = fopen("inib.d", "r") ;
158 // Bin_NS binary2(finib) ;
159 // fclose( finib ) ;
160
161 // cout << endl << "Binary read in the binary file : " << binary2 << endl ;
162
163 // finib = fopen("inib2.d", "w") ;
164 // binary2.save_bin(finib) ;
165 // fclose( finib ) ;
166
167 // Create a new object from a formatted file
168 //---------------------------------------
169 // ifstream finif3("inif.d") ;
170 // Bin_NS binary3(finif3) ;
171 // finif3.close() ;
172
173 // cout << endl << "Binary read in the formatted file : " << binary3 << endl ;
174
175 // finif.open("inif3.d") ;
176 // binary3.save_form(finif) ;
177 // finif.close() ;
178
179 // Clean exit
180 // ----------
181
182 delete [] xi ;
183 delete [] yi ;
184 delete [] zi ;
185
186 return EXIT_SUCCESS ;
187 }