| 1 | /* |
| 2 | * Declaration of class Grid and derived classes |
| 3 | */ |
| 4 | |
| 5 | /* |
| 6 | * Copyright (c) 2005 Eric Gourgoulhon |
| 7 | * |
| 8 | * This file is part of LORENE. |
| 9 | * |
| 10 | * LORENE is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * LORENE is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with LORENE; if not, write to the Free Software |
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 23 | * |
| 24 | */ |
| 25 | |
| 26 | /* |
| 27 | * $Id: grid.h,v 1.1 2005/11/14 01:56:58 e_gourgoulhon Exp $ |
| 28 | * $Log: grid.h,v $ |
| 29 | * Revision 1.1 2005/11/14 01:56:58 e_gourgoulhon |
| 30 | * First version |
| 31 | * |
| 32 | * |
| 33 | * $Header: /cvsroot/Lorene/School05/Monday/grid.h,v 1.1 2005/11/14 01:56:58 e_gourgoulhon Exp $ |
| 34 | * |
| 35 | */ |
| 36 | |
| 37 | |
| 38 | #ifndef __GRID_H_ |
| 39 | #define __GRID_H_ |
| 40 | |
| 41 | //----------------------------------// |
| 42 | // class Grid // |
| 43 | //----------------------------------// |
| 44 | |
| 45 | /** Set of nodes in the interval [-1,1]. \ingroup (grid) |
| 46 | * |
| 47 | */ |
| 48 | class Grid { |
| 49 | |
| 50 | // Data : |
| 51 | // ----- |
| 52 | protected: |
| 53 | const int nn ; ///< \e N = number of nodes - 1 |
| 54 | double* xx ; ///< Values of the nodes (pointer to an array of size \c nn+1) |
| 55 | |
| 56 | // Constructors - Destructor |
| 57 | // ------------------------- |
| 58 | public: |
| 59 | /** Standard constructor. |
| 60 | * @param nb_nodes number of nodes |
| 61 | * @param xi array of size \c nb_nodes containing the abscissas of the nodes |
| 62 | */ |
| 63 | Grid(int nb_nodes, double* xi) ; |
| 64 | |
| 65 | Grid(const Grid& ) ; ///< Copy constructor |
| 66 | |
| 67 | protected: |
| 68 | /** Constructor to be used only by derived classes (hence protected) |
| 69 | * @param nb_nodes number of nodes |
| 70 | */ |
| 71 | Grid(int nb_nodes) ; |
| 72 | |
| 73 | public: |
| 74 | virtual ~Grid() ; ///< Destructor |
| 75 | |
| 76 | // Mutators / assignment |
| 77 | // --------------------- |
| 78 | public: |
| 79 | /// Assignment to another Grid |
| 80 | void operator=(const Grid&) ; |
| 81 | |
| 82 | // Accessors |
| 83 | // --------- |
| 84 | public: |
| 85 | int n() const ; ///< returns \e N, i.e. the number of nodes - 1 |
| 86 | |
| 87 | double operator()(int i) const ; ///< returns value of node no. \c i |
| 88 | |
| 89 | /** Graphical display of the node points. |
| 90 | * |
| 91 | * @param color color of the points (drawn as small circles) : |
| 92 | * \li 0 : black (background) |
| 93 | * \li 1 : white (default) |
| 94 | * \li 2 : red |
| 95 | * \li 3 : green |
| 96 | * \li 4 : blue |
| 97 | * \li 5 : cyan |
| 98 | * \li 6 : magenta |
| 99 | * \li 7 : yellow |
| 100 | * \li 8 : orange |
| 101 | * \li 9 : green + yellow |
| 102 | * \li 10 : green + cyan |
| 103 | * \li 11 : blue + cyan |
| 104 | * \li 12 : blue + magenta |
| 105 | * \li 13 : red + magenta |
| 106 | * \li 14 : dark gray |
| 107 | * \li 15 : light gray |
| 108 | * @param nfig index of the figure (in the range [0,99]) |
| 109 | * to be used for the plot: if this figure does not exist, |
| 110 | * it will be created with the device name \c device provided by the last |
| 111 | * argument. |
| 112 | * @param ymin lower bound on y of the graphical window (used only if a new |
| 113 | * figure must be created) |
| 114 | * @param ymax upper bound on y of the graphical window (used only if a new |
| 115 | * figure must be created) |
| 116 | * @param title title of the figure (used only if a new figure must be created) |
| 117 | * @param label_y y legend of the figure (used only if a new |
| 118 | * figure must be created) |
| 119 | * @param device type of graphical device (default value = 0x0, will result in |
| 120 | * interactive choice) (used only if a new |
| 121 | * figure must be created) |
| 122 | */ |
| 123 | void plot(int color = 1, int nfig = 0, double ymin = -1., |
| 124 | double ymax = 1., const char* title = 0x0, |
| 125 | const char* label_y = 0x0, const char* device = 0x0) const ; |
| 126 | |
| 127 | // Computation |
| 128 | // ----------- |
| 129 | public: |
| 130 | /** Lagrange polynomials (characteristic polynomials). |
| 131 | * The Lagrange polynomial no. \e i is the unique polynomial |
| 132 | * \f$\ell_i(x)\f$ of degree \e N such that |
| 133 | * \f$\ell_i(x_{j})=\delta_{ij}\f$. It is also called \e cardinal |
| 134 | * \e polynomial associated with the node \f$x_i\f$ |
| 135 | * @param i number of Lagrange polynomial \f$\ell_i\f$ |
| 136 | * @param x point \e x in [-1,1] where the Lagrange polynomial is to |
| 137 | * be evaluated |
| 138 | * @return value of \f$\ell_i(x)\f$ |
| 139 | */ |
| 140 | double lagrange(int i, double x) const ; |
| 141 | |
| 142 | /** Nodal polynomial. |
| 143 | * The nodal polynomoal is the unique polynomial of degree \e N + 1 |
| 144 | * and leading coefficient 1, the roots of which are the \e N +1 nodes |
| 145 | * \f$x_i\f$. |
| 146 | * |
| 147 | * @param x point \e x in [-1,1] where the Lagrange polynomial is to |
| 148 | * be evaluated |
| 149 | * @return value of the nodal polynomial at \e x |
| 150 | */ |
| 151 | double nodal_polynomial(double x) const ; |
| 152 | |
| 153 | /** Interpolation of a given function at the nodes |
| 154 | * |
| 155 | * @param (*f)(double) function to be interpolated |
| 156 | * @param x point \e x in [-1,1] where the interpolating polynomial |
| 157 | * associated with the nodes \f$x_i\f$ is to evaluated |
| 158 | * @return value of the interpolating polynomial at \e x |
| 159 | */ |
| 160 | double interpole(double (*f)(double), double x) const ; |
| 161 | |
| 162 | /// Computes (an approximate value of) the Lebesgue constant |
| 163 | double lebesgue_constant() const ; |
| 164 | |
| 165 | }; |
| 166 | |
| 167 | /// Display of an object of class \c Grid |
| 168 | ostream& operator<<(ostream& , const Grid& ) ; |
| 169 | |
| 170 | |
| 171 | //----------------------------------// |
| 172 | // class Grid_uniform // |
| 173 | //----------------------------------// |
| 174 | |
| 175 | |
| 176 | |
| 177 | /** Uniform sampling of the interval [-1,1]. \ingroup (grid) |
| 178 | * |
| 179 | */ |
| 180 | class Grid_uniform : public Grid { |
| 181 | |
| 182 | // Constructors - Destructor |
| 183 | // ------------------------- |
| 184 | public: |
| 185 | /** Standard constructor. |
| 186 | * @param nb_nodes number of nodes |
| 187 | */ |
| 188 | Grid_uniform(int nb_nodes) ; |
| 189 | |
| 190 | Grid_uniform(const Grid_uniform& ) ; ///< Copy constructor |
| 191 | |
| 192 | virtual ~Grid_uniform() ; ///< Destructor |
| 193 | |
| 194 | // Mutators / assignment |
| 195 | // --------------------- |
| 196 | public: |
| 197 | /// Assignment to another Grid_uniform |
| 198 | void operator=(const Grid_uniform&) ; |
| 199 | |
| 200 | |
| 201 | }; |
| 202 | |
| 203 | /// Display of an object of class \c Grid_uniform |
| 204 | ostream& operator<<(ostream& , const Grid_uniform& ) ; |
| 205 | |
| 206 | |
| 207 | //----------------------------------// |
| 208 | // class Grid_Legendre_Gauss // |
| 209 | //----------------------------------// |
| 210 | |
| 211 | |
| 212 | /** Legendre Gauss nodes in the interval [-1,1]. \ingroup (grid) |
| 213 | * |
| 214 | */ |
| 215 | class Grid_Legendre_Gauss : public Grid { |
| 216 | |
| 217 | // Constructors - Destructor |
| 218 | // ------------------------- |
| 219 | public: |
| 220 | /** Standard constructor. |
| 221 | * @param nb_nodes number of nodes |
| 222 | */ |
| 223 | Grid_Legendre_Gauss(int nb_nodes) ; |
| 224 | |
| 225 | Grid_Legendre_Gauss(const Grid_Legendre_Gauss& ) ; ///< Copy constructor |
| 226 | |
| 227 | virtual ~Grid_Legendre_Gauss() ; ///< Destructor |
| 228 | |
| 229 | // Mutators / assignment |
| 230 | // --------------------- |
| 231 | public: |
| 232 | /// Assignment to another Grid_Legendre_Gauss |
| 233 | void operator=(const Grid_Legendre_Gauss&) ; |
| 234 | |
| 235 | |
| 236 | }; |
| 237 | |
| 238 | /// Display of an object of class \c Grid_Legendre_Gauss |
| 239 | ostream& operator<<(ostream& , const Grid_Legendre_Gauss& ) ; |
| 240 | |
| 241 | |
| 242 | //----------------------------------// |
| 243 | // class Grid_Legendre_GL // |
| 244 | //----------------------------------// |
| 245 | |
| 246 | |
| 247 | /** Legendre Gauss-Lobatto nodes in the interval [-1,1]. \ingroup (grid) |
| 248 | * |
| 249 | */ |
| 250 | class Grid_Legendre_GL : public Grid { |
| 251 | |
| 252 | // Constructors - Destructor |
| 253 | // ------------------------- |
| 254 | public: |
| 255 | /** Standard constructor. |
| 256 | * @param nb_nodes number of nodes |
| 257 | */ |
| 258 | Grid_Legendre_GL(int nb_nodes) ; |
| 259 | |
| 260 | Grid_Legendre_GL(const Grid_Legendre_GL& ) ; ///< Copy constructor |
| 261 | |
| 262 | virtual ~Grid_Legendre_GL() ; ///< Destructor |
| 263 | |
| 264 | // Mutators / assignment |
| 265 | // --------------------- |
| 266 | public: |
| 267 | /// Assignment to another Grid_Legendre_GL |
| 268 | void operator=(const Grid_Legendre_GL&) ; |
| 269 | |
| 270 | |
| 271 | }; |
| 272 | |
| 273 | /// Display of an object of class \c Grid_Legendre_GL |
| 274 | ostream& operator<<(ostream& , const Grid_Legendre_GL& ) ; |
| 275 | |
| 276 | |
| 277 | |
| 278 | //----------------------------------// |
| 279 | // class Grid_Chebyshev_Gauss // |
| 280 | //----------------------------------// |
| 281 | |
| 282 | |
| 283 | /** Chebyshev Gauss nodes in the interval [-1,1]. \ingroup (grid) |
| 284 | * |
| 285 | */ |
| 286 | class Grid_Chebyshev_Gauss : public Grid { |
| 287 | |
| 288 | // Constructors - Destructor |
| 289 | // ------------------------- |
| 290 | public: |
| 291 | /** Standard constructor. |
| 292 | * @param nb_nodes number of nodes |
| 293 | */ |
| 294 | Grid_Chebyshev_Gauss(int nb_nodes) ; |
| 295 | |
| 296 | Grid_Chebyshev_Gauss(const Grid_Chebyshev_Gauss& ) ; ///< Copy constructor |
| 297 | |
| 298 | virtual ~Grid_Chebyshev_Gauss() ; ///< Destructor |
| 299 | |
| 300 | // Mutators / assignment |
| 301 | // --------------------- |
| 302 | public: |
| 303 | /// Assignment to another Grid_Chebyshev_Gauss |
| 304 | void operator=(const Grid_Chebyshev_Gauss&) ; |
| 305 | |
| 306 | |
| 307 | }; |
| 308 | |
| 309 | /// Display of an object of class \c Grid_Chebyshev_Gauss |
| 310 | ostream& operator<<(ostream& , const Grid_Chebyshev_Gauss& ) ; |
| 311 | |
| 312 | |
| 313 | //----------------------------------// |
| 314 | // class Grid_Chebyshev_GL // |
| 315 | //----------------------------------// |
| 316 | |
| 317 | |
| 318 | /** Chebyshev Gauss-Lobatto nodes in the interval [-1,1]. \ingroup (grid) |
| 319 | * |
| 320 | */ |
| 321 | class Grid_Chebyshev_GL : public Grid { |
| 322 | |
| 323 | // Constructors - Destructor |
| 324 | // ------------------------- |
| 325 | public: |
| 326 | /** Standard constructor. |
| 327 | * @param nb_nodes number of nodes |
| 328 | */ |
| 329 | Grid_Chebyshev_GL(int nb_nodes) ; |
| 330 | |
| 331 | Grid_Chebyshev_GL(const Grid_Chebyshev_GL& ) ; ///< Copy constructor |
| 332 | |
| 333 | virtual ~Grid_Chebyshev_GL() ; ///< Destructor |
| 334 | |
| 335 | // Mutators / assignment |
| 336 | // --------------------- |
| 337 | public: |
| 338 | /// Assignment to another Grid_Chebyshev_GL |
| 339 | void operator=(const Grid_Chebyshev_GL&) ; |
| 340 | |
| 341 | |
| 342 | }; |
| 343 | |
| 344 | /// Display of an object of class \c Grid_Chebyshev_GL |
| 345 | ostream& operator<<(ostream& , const Grid_Chebyshev_GL& ) ; |
| 346 | |
| 347 | #endif |