Debian Codegraph @

Codes/Test/Etoile/test_etoile.C

raw
1 /*
2 * Test program for the Etoile class
3 *
4 */
5
6 /*
7 * Copyright (c) 2000-2001 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 as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
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 test_etoile_C[] = "$Header: /cvsroot/Lorene/Codes/Test/Etoile/test_etoile.C,v 1.3 2014/10/06 15:12:52 j_novak Exp $" ;
28
29 /*
30 * $Id: test_etoile.C,v 1.3 2014/10/06 15:12:52 j_novak Exp $
31 * $Log: test_etoile.C,v $
32 * Revision 1.3 2014/10/06 15:12:52 j_novak
33 * Modified #include directives to use c++ syntax.
34 *
35 * Revision 1.2 2002/10/16 14:37:18 j_novak
36 * Reorganization of #include instructions of standard C++, in order to
37 * use experimental version 3 of gcc.
38 *
39 * Revision 1.1.1.1 2001/11/20 15:19:31 e_gourgoulhon
40 * LORENE
41 *
42 * Revision 1.2 2000/01/28 17:19:14 eric
43 * *** empty log message ***
44 *
45 * Revision 1.1 2000/01/27 16:48:01 eric
46 * Initial revision
47 *
48 *
49 * $Header: /cvsroot/Lorene/Codes/Test/Etoile/test_etoile.C,v 1.3 2014/10/06 15:12:52 j_novak Exp $
50 *
51 */
52
53 // headers C
54 #include <cstdlib>
55 #include <cmath>
56
57 // headers Lorene
58 #include "etoile.h"
59 #include "eos.h"
60 #include "utilitaires.h"
61 #include "graphique.h"
62 #include "nbr_spx.h"
63
64 //******************************************************************************
65
66 void main(){
67
68
69 { // Main block
70
71 // Identification of all the subroutines called by the code :
72
73 // system("ident test_etoile > identification.d") ;
74
75 //-----------------------------------------------------------------------
76 // Input data : number of points, types of sampling, etc...
77 //-----------------------------------------------------------------------
78
79 int nt = 7 ; // Number of points in theta
80 int np = 4 ; // Number of points in phi
81 int nz = 3 ; // Number of domains
82
83 int* nr = new int[nz];
84 int* nt_tab = new int[nz];
85 int* np_tab = new int[nz];
86 double* bornes = new double[nz+1];
87 int* type_r = new int[nz];
88
89 for (int l=0; l<nz; l++) {
90 nr[l] = 17 ;
91 np_tab[l] = np ;
92 nt_tab[l] = nt ;
93 }
94
95 bornes[0] = 0. ;
96 bornes[1] = 2. ;
97 bornes[2] = 3. ;
98 bornes[3] = __infinity ;
99
100 type_r[0] = RARE ;
101 type_r[1] = FIN ;
102 type_r[2] = UNSURR ;
103
104 int type_t = SYM ;
105
106 int type_p = NONSYM ;
107
108
109 //-----------------------------------------------------------------------
110 // Construction of a multi-grid
111 //-----------------------------------------------------------------------
112
113 Mg3d mg(nz, nr, type_r, nt_tab, type_t, np_tab, type_p) ;
114
115 cout << endl << "Grid mg : " << mg << endl ;
116
117 // Cleaning
118 // --------
119
120 delete [] nr ;
121 delete [] nt_tab ;
122 delete [] np_tab ;
123 delete [] type_r ;
124
125 //-------------------------------------------
126 // Construction of a mapping of class Map_et
127 //-------------------------------------------
128
129 Map_et mp(mg, bornes) ;
130
131 // Cleaning
132 // --------
133
134 delete [] bornes ;
135
136 // cout << endl << "Mapping mp (before adaptation) : " << endl ;
137 // cout << mp << endl ;
138
139 const Coord& r = mp.r ;
140 // const Coord& x = mp.x ;
141 // const Coord& y = mp.y ;
142 // const Coord& z = mp.z ;
143 // const Coord& cost = mp.cost ;
144 // const Coord& sint = mp.sint ;
145 // const Coord& cosp = mp.cosp ;
146 // const Coord& sinp = mp.sinp ;
147
148
149 //-----------------------------------------------------------------------
150 // Construction of an EOS
151 //-----------------------------------------------------------------------
152
153 double gamma = 2. ;
154 double kappa = 0.0332 ;
155
156 Eos_poly eos0(gamma, kappa) ;
157
158
159
160 //-----------------------------------------------------------------------
161 // Construction of a star
162 //-----------------------------------------------------------------------
163
164 int nzet = nz - 2 ; // Number of domains occupied by the star
165
166 bool relat = true ; // true = relativisitic star
167
168 Etoile star(mp, nzet, relat, eos0) ;
169
170 //-----------------------------------------------------------------------
171 // Initialization of the stellar enthalpy field
172 //-----------------------------------------------------------------------
173
174 Cmp ent0(mp) ;
175
176 double ray = mp.val_r(nzet-1, 1, M_PI/2., 0.) ;
177
178 ent0 = 1 - r*r/(ray*ray) ;
179
180 ent0.annule(nz-1) ;
181 ent0.std_base_scal() ;
182
183 star.set_enthalpy(ent0) ;
184
185 cout << star << endl ;
186
187 //-----------------------------------------------------------------------
188 // File output / input
189 //-----------------------------------------------------------------------
190
191 FILE* fich = fopen("res.d", "w") ;
192
193 mg.sauve(fich) ;
194 mp.sauve(fich) ;
195 eos0.sauve(fich) ;
196 star.sauve(fich) ;
197
198 fclose(fich) ;
199
200 fich = fopen("res.d", "r") ;
201
202 Mg3d mg1(fich) ;
203 Map_et mp1(mg1, fich) ;
204 Eos* peos1 = Eos::eos_from_file(fich) ;
205
206 Etoile star1(mp1, *peos1, fich) ;
207
208 fclose(fich) ;
209
210
211 if (*peos1 != eos0) {
212 cout << "Problem : *peos1 != eos0 !" << endl ;
213 abort() ;
214 }
215 else {
216 cout << "*peos1 == eos0 : OK " << endl ;
217 }
218
219 star1.equation_of_state() ;
220
221 // cout << endl << "star1 : " << star1 << endl ;
222
223
224 delete peos1 ;
225
226 //-----------------------------------------------------------------------
227 // Computation of a static equilibrium configuration
228 //-----------------------------------------------------------------------
229
230 cout << endl << "Computation of a static equilibrium configuration"
231 << endl << "-------------------------------------------------"
232 << endl ;
233
234 double ent_c = 0.29920935 ; // central enthalpy
235 double precis = 1.e-12 ;
236
237 star.equilibrium_spher(ent_c, precis) ;
238
239 cout << "Final mapping : " << endl ;
240 cout << mp << endl ;
241 cout << endl << "Final star : " << star << endl ;
242
243 des_profile(star.get_ent()(), 0., 1.2*ray, M_PI/2., 0., "Enthalpy") ;
244
245
246 //-----------------------------------------------------------------------
247 // The End
248 //-----------------------------------------------------------------------
249
250 } // End of main block : everything should be properly destroyed here
251
252
253 exit(EXIT_SUCCESS) ;
254
255 }
256