| 1 | /****************************************************************************/ |
| 2 | /* This file is part of FreeFEM. */ |
| 3 | /* */ |
| 4 | /* FreeFEM is free software: you can redistribute it and/or modify */ |
| 5 | /* it under the terms of the GNU Lesser General Public License as */ |
| 6 | /* published by the Free Software Foundation, either version 3 of */ |
| 7 | /* the License, or (at your option) any later version. */ |
| 8 | /* */ |
| 9 | /* FreeFEM is distributed in the hope that it will be useful, */ |
| 10 | /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ |
| 11 | /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ |
| 12 | /* GNU Lesser General Public License for more details. */ |
| 13 | /* */ |
| 14 | /* You should have received a copy of the GNU Lesser General Public License */ |
| 15 | /* along with FreeFEM. If not, see <http://www.gnu.org/licenses/>. */ |
| 16 | /****************************************************************************/ |
| 17 | // SUMMARY : ... |
| 18 | // LICENSE : LGPLv3 |
| 19 | // ORG : LJLL Universite Pierre et Marie Curie, Paris, FRANCE |
| 20 | // AUTHORS : Frederic Hecht |
| 21 | // E-MAIL : [email protected] |
| 22 | |
| 23 | #ifndef _DEFS_H_ |
| 24 | #define _DEFS_H_ |
| 25 | |
| 26 | #ifndef GLIB |
| 27 | #define GLIB |
| 28 | |
| 29 | #include <iostream> |
| 30 | #include <fstream> |
| 31 | #include <cstdlib> |
| 32 | #include <cstdio> |
| 33 | #include <stddef.h> |
| 34 | #include <cmath> |
| 35 | #include <cstring> |
| 36 | #include <list> |
| 37 | using namespace std; |
| 38 | |
| 39 | #endif |
| 40 | |
| 41 | // Define simple constants |
| 42 | #ifndef Pi |
| 43 | #define Pi (3.141592653589793) |
| 44 | #endif |
| 45 | #ifndef TINY // used in BrentLS and Matrix |
| 46 | #define TINY 1.0e-20 |
| 47 | #endif |
| 48 | #ifndef True |
| 49 | #define True (1) |
| 50 | #endif |
| 51 | #ifndef False |
| 52 | #define False (0) |
| 53 | #endif |
| 54 | #ifndef Yes |
| 55 | #define Yes (1) |
| 56 | #endif |
| 57 | #ifndef No |
| 58 | #define No (0) |
| 59 | #endif |
| 60 | |
| 61 | // Define some simple template functions |
| 62 | #ifndef Sgn |
| 63 | #define Sgn(x) ((x) < 0 ? -1.0 : 1.0) |
| 64 | #endif |
| 65 | #ifndef Abs |
| 66 | #define Abs(x) ((x) < 0 ? -(x) : (x)) |
| 67 | #endif |
| 68 | #ifndef Max |
| 69 | #define Max(x, y) ((x) > (y) ? (x) : (y)) |
| 70 | #endif |
| 71 | #ifndef Min |
| 72 | #define Min(x, y) ((x) < (y) ? (x) : (y)) |
| 73 | #endif |
| 74 | |
| 75 | #ifndef inValidSize |
| 76 | #define inValidSize( ) cerr << "Warning: incompatible sizes!" << endl; |
| 77 | #endif |
| 78 | |
| 79 | // Lists operations |
| 80 | |
| 81 | /*! |
| 82 | * \brief Display list |
| 83 | * \param l List |
| 84 | */ |
| 85 | template< class Type > |
| 86 | void display(list< Type > l) { |
| 87 | typename list< Type >::iterator il; |
| 88 | for (il = l.begin( ); il != l.end( ); ++il) cout << (*il) << " "; |
| 89 | cout << endl; |
| 90 | } |
| 91 | |
| 92 | /*! |
| 93 | * \brief Normalize list |
| 94 | * \param l List |
| 95 | */ |
| 96 | template< class Type > |
| 97 | list< Type > normalize(list< Type > l) { |
| 98 | list< Type > v(l); |
| 99 | Type scale = l.front( ); |
| 100 | typename list< Type >::iterator il; |
| 101 | |
| 102 | if (scale == 0) { |
| 103 | cerr << "First element is zero, cannot be normed! \n"; |
| 104 | return v; |
| 105 | } else { |
| 106 | for (il = v.begin( ); il != v.end( ); ++il) *il /= scale; |
| 107 | return v; |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | #endif //_DEFS_H_ |