LORENE
utilitaires.h
1 /*
2  * Prototypes of various utilities for Lorene
3  *
4  */
5 
6 /*
7  * Copyright (c) 1999-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 
28 #ifndef __UTILITAIRES_H_
29 #define __UTILITAIRES_H_
30 
31 
32 /*
33  * $Id: utilitaires.h,v 1.21 2024/07/03 09:53:00 j_novak Exp $
34  * $Log: utilitaires.h,v $
35  * Revision 1.21 2024/07/03 09:53:00 j_novak
36  * Added the declaration of admissible_fft.
37  *
38  * Revision 1.20 2024/02/22 16:51:35 j_novak
39  * Added new function to read CompOSE table.
40  *
41  * Revision 1.19 2022/04/15 13:39:24 j_novak
42  * New class Eos_compose_fit to generate fitted EoSs from CompOSE tables.
43  *
44  * Revision 1.18 2022/03/22 13:36:00 j_novak
45  * Added declaration of compute_derivative to utilitaires.h
46  *
47  * Revision 1.17 2018/12/05 15:03:20 j_novak
48  * New Mg3d constructor from a formatted file.
49  *
50  * Revision 1.16 2015/01/09 15:28:52 j_novak
51  * New integration function for general non-equally-spaced grids.
52  *
53  * Revision 1.15 2014/10/13 08:52:37 j_novak
54  * Lorene classes and functions now belong to the namespace Lorene.
55  *
56  * Revision 1.14 2014/10/06 15:09:40 j_novak
57  * Modified #include directives to use c++ syntax.
58  *
59  * Revision 1.13 2014/07/04 12:09:06 j_novak
60  * New argument in zerosec(): a boolean (false by default) for aborting if the number of iteration is greater than the max.
61  *
62  * Revision 1.12 2014/04/25 10:43:50 j_novak
63  * The member 'name' is of type string now. Correction of a few const-related issues.
64  *
65  * Revision 1.11 2008/08/19 06:41:59 j_novak
66  * Minor modifications to avoid warnings with gcc 4.3. Most of them concern
67  * cast-type operations, and constant strings that must be defined as const char*
68  *
69  * Revision 1.10 2004/09/01 09:47:55 r_prix
70  * fixed/improved string-reading with read_variable(): allocates returned string
71  *
72  * Revision 1.9 2004/03/22 13:12:44 j_novak
73  * Modification of comments to use doxygen instead of doc++
74  *
75  * Revision 1.8 2003/12/17 23:12:30 r_prix
76  * replaced use of C++ <string> by standard ANSI char* to be backwards compatible
77  * with broken compilers like MIPSpro Compiler 7.2 on SGI Origin200. ;-)
78  *
79  * Revision 1.7 2003/12/05 15:05:53 r_prix
80  * added read_variable() for (C++-type) strings.
81  *
82  * Revision 1.6 2003/12/04 12:33:21 r_prix
83  * added prototypes and documentation for variable-reading functions
84  * (read_variable, load_file, load_file_buffered)
85  *
86  * Revision 1.5 2002/05/02 15:16:22 j_novak
87  * Added functions for more general bi-fluid EOS
88  *
89  * Revision 1.4 2002/04/16 08:06:44 j_novak
90  * Addition of zerosec_borne
91  *
92  * Revision 1.3 2002/04/11 09:19:46 j_novak
93  * Back to old version of zerosec
94  *
95  * Revision 1.2 2001/12/04 21:24:33 e_gourgoulhon
96  *
97  * New functions fwrite_be and fread_be for writing/reading in a
98  * binary file according to the big endian convention.
99  *
100  * Revision 1.1.1.1 2001/11/20 15:19:27 e_gourgoulhon
101  * LORENE
102  *
103  * Revision 1.6 2001/09/14 14:23:53 eric
104  * Ajout de la fonction zero_list.
105  *
106  * Revision 1.5 2001/05/29 16:11:21 eric
107  * Modif commentaires (mise en conformite Doc++ 3.4.7).
108  *
109  * Revision 1.4 1999/12/24 12:59:54 eric
110  * Ajout de la routine zero_premier.
111  *
112  * Revision 1.3 1999/12/15 15:39:42 eric
113  * *** empty log message ***
114  *
115  * Revision 1.2 1999/12/15 15:17:03 eric
116  * *** empty log message ***
117  *
118  * Revision 1.1 1999/12/15 09:41:47 eric
119  * Initial revision
120  *
121  *
122  * $Header: /cvsroot/Lorene/C++/Include/utilitaires.h,v 1.21 2024/07/03 09:53:00 j_novak Exp $
123  *
124  */
125 
126 #include <cstring>
127 #include "headcpp.h"
128 
129 namespace Lorene {
130 class Param ;
131 class Tbl ;
132 
148 void arrete(int a = 0) ;
149 
168 bool zero_premier(double (*f)(double, const Param&), const Param& par,
169  double a, double b, int n, double& a0, double& b0) ;
170 
171 
172 
196 double zerosec( double (*f)(double, const Param&), const Param& par,
197  double a, double b, double precis, int nitermax,
198  int& niter, bool abort=true) ;
199 
222 double zerosec_b( double (*f)(double, const Param&),const Param& par,
223  double a, double b, double precis, int nitermax,
224  int& niter) ;
225 
250 void zero_list( double (*f)(double, const Param&), const Param& par,
251  double xmin, double xmax, int nsub,
252  Tbl*& az, Tbl*& bz ) ;
253 
267  Tbl integ1D(const Tbl& xx, const Tbl& ff) ;
268 
280  void compute_derivative(const Tbl& xx, const Tbl& ff, Tbl& dfdx) ;
281 
283  Tbl poly_regression(const Tbl&, const Tbl&, int) ;
284 
285 
286 
304 int fwrite_be(const int* aa, int size, int nb, FILE* fich) ;
305 
323 int fwrite_be(const double* aa, int size, int nb, FILE* fich) ;
324 
342 int fread_be(int* aa, int size, int nb, FILE* fich) ;
343 
361 int fread_be(double* aa, int size, int nb, FILE* fich) ;
362 
363 
370 char *load_file(char *fname);
371 
380 char *load_file_buffered(char *fname);
381 
400 int read_variable(const char *fname, const char *var_name, char *fmt, void *varp);
401 
403 int read_variable(const char *fname, const char *var_name, int &var);
405 int read_variable(const char *fname, const char *var_name, bool &var);
407 int read_variable(const char *fname, const char *var_name, double &var);
409 int read_variable (const char *fname, const char *var_name, char **str);
410 
412 void *MyMalloc (long bytes);
413 
415 int FS_filelength (FILE *f);
416 
418 void c_est_pas_fait(const char * ) ;
419 
422  bool search_file(ifstream& infile, const string& pattern) ;
423 
426  bool read_compose_table(const string& tablename, Tbl*& p_ental, Tbl*& p_entro,
427  Tbl*& p_press, Tbl*& p_ener, Tbl*& p_nb, Tbl*& p_temp,
428  Tbl*& p_ye) ;
429 
433  bool admissible_fft(int ) ;
434 
437 }
438 #endif
void * MyMalloc(long bytes)
&#39;Improved&#39; malloc that sets memory to 0 and also auto-terminates on error.
Tbl poly_regression(const Tbl &, const Tbl &, int)
Polynomial regression, giving Chebyshev coefficients.
Lorene prototypes.
Definition: app_hor.h:67
double zerosec_b(double(*f)(double, const Param &), const Param &par, double a, double b, double precis, int nitermax, int &niter)
Finding the zero a function on a bounded domain.
Definition: zerosec_borne.C:71
double zerosec(double(*f)(double, const Param &), const Param &par, double a, double b, double precis, int nitermax, int &niter, bool abort=true)
Finding the zero a function.
Definition: zerosec.C:92
char * load_file(char *fname)
Read file into memory and returns pointer to data.
int FS_filelength(FILE *f)
A portable routine to determine the length of a file.
bool search_file(ifstream &infile, const string &pattern)
A function that searches for a pattern in a file and places the file stream after the found pattern...
Definition: misc.C:53
void zero_list(double(*f)(double, const Param &), const Param &par, double xmin, double xmax, int nsub, Tbl *&az, Tbl *&bz)
Locates approximatively all the zeros of a function in a given interval.
Definition: zero_list.C:60
bool read_compose_table(const string &tablename, Tbl *&p_ental, Tbl *&p_entro, Tbl *&p_press, Tbl *&p_ener, Tbl *&p_nb, Tbl *&p_temp, Tbl *&p_ye)
A function to read CompOSE table and return themro quantities in Lorene units.
Tbl integ1D(const Tbl &xx, const Tbl &ff)
Integrates a function defined on an unequally-spaced grid, approximating it by piecewise parabolae...
Definition: integrate_1D.C:50
void compute_derivative(const Tbl &xx, const Tbl &ff, Tbl &dfdx)
Derives a function defined on an unequally-spaced grid, approximating it by piecewise parabolae...
Definition: misc.C:64
int fwrite_be(const int *aa, int size, int nb, FILE *fich)
Writes integer(s) into a binary file according to the big endian convention.
Definition: fwrite_be.C:73
bool zero_premier(double(*f)(double, const Param &), const Param &par, double a, double b, int n, double &a0, double &b0)
Locates the sub-interval containing the first zero of a function in a given interval.
Definition: zero_premier.C:64
char * load_file_buffered(char *fname)
Returns pointer to data from a file using a buffer.
int fread_be(int *aa, int size, int nb, FILE *fich)
Reads integer(s) from a binary file according to the big endian convention.
Definition: fread_be.C:72
void c_est_pas_fait(const char *)
Helpful function to say something is not implemented yet.
int read_variable(const char *fname, const char *var_name, char *fmt, void *varp)
Reads a variable from file.
bool admissible_fft(int)
Checks whether or not a given number of degrees of freedom is compatible with the FFT transform...
void arrete(int a=0)
Setting a stop point in a code.
Definition: arrete.C:64