| 1 | /* |
| 2 | * Definition of Lorene class Mtbl |
| 3 | * |
| 4 | */ |
| 5 | |
| 6 | /* |
| 7 | * Copyright (c) 1999-2000 Jean-Alain Marck |
| 8 | * Copyright (c) 1999-2001 Eric Gourgoulhon |
| 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 as published by |
| 14 | * the Free Software Foundation; either version 2 of the License, or |
| 15 | * (at your option) any later version. |
| 16 | * |
| 17 | * LORENE is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | * GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License |
| 23 | * along with LORENE; if not, write to the Free Software |
| 24 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 25 | * |
| 26 | */ |
| 27 | |
| 28 | |
| 29 | #ifndef __MTBL_H_ |
| 30 | #define __MTBL_H_ |
| 31 | |
| 32 | /* |
| 33 | * $Id: mtbl.h,v 1.7 2014/10/13 08:52:36 j_novak Exp $ |
| 34 | * $Log: mtbl.h,v $ |
| 35 | * Revision 1.7 2014/10/13 08:52:36 j_novak |
| 36 | * Lorene classes and functions now belong to the namespace Lorene. |
| 37 | * |
| 38 | * Revision 1.6 2012/01/17 10:22:13 j_penner |
| 39 | * function added: Heaviside |
| 40 | * |
| 41 | * Revision 1.5 2004/03/22 13:12:42 j_novak |
| 42 | * Modification of comments to use doxygen instead of doc++ |
| 43 | * |
| 44 | * Revision 1.4 2003/11/06 14:43:37 e_gourgoulhon |
| 45 | * Gave a name to const arguments in certain method prototypes (e.g. |
| 46 | * constructors) to correct a bug of DOC++. |
| 47 | * |
| 48 | * Revision 1.3 2002/09/13 09:17:33 j_novak |
| 49 | * Modif. commentaires |
| 50 | * |
| 51 | * Revision 1.2 2002/06/17 14:05:17 j_novak |
| 52 | * friend functions are now also declared outside the class definition |
| 53 | * |
| 54 | * Revision 1.1.1.1 2001/11/20 15:19:27 e_gourgoulhon |
| 55 | * LORENE |
| 56 | * |
| 57 | * Revision 2.9 2000/08/16 10:29:45 eric |
| 58 | * Suppression du membre dzpuis. |
| 59 | * |
| 60 | * Revision 2.8 2000/08/04 11:40:58 eric |
| 61 | * Ajout de l'operateur (int l) et de la fonction set(int l) pour l'acces |
| 62 | * individuel aux Tbl. |
| 63 | * |
| 64 | * Revision 2.7 1999/12/02 17:55:07 phil |
| 65 | * *** empty log message *** |
| 66 | * |
| 67 | * Revision 2.6 1999/10/29 15:05:43 eric |
| 68 | * Suppression des fonctions membres min() et max(): |
| 69 | * elles deviennent des fonctions externes. |
| 70 | * Ajout de fonctions mathematiques (abs, norme, etc...). |
| 71 | * |
| 72 | * Revision 2.5 1999/10/18 15:06:25 eric |
| 73 | * La fonction membre annule() est rebaptisee annule_hard(). |
| 74 | * Introduction de la fonction membre annule(int, int). |
| 75 | * |
| 76 | * Revision 2.4 1999/10/01 10:35:58 eric |
| 77 | * Amelioration des commentaires. |
| 78 | * |
| 79 | * Revision 2.3 1999/10/01 10:08:25 eric |
| 80 | * Depoussierage |
| 81 | * Documentation. |
| 82 | * |
| 83 | * Revision 2.2 1999/03/02 18:54:50 eric |
| 84 | * Ajout de la fonction affiche_seuil. |
| 85 | * |
| 86 | * Revision 2.1 1999/02/22 15:23:49 hyc |
| 87 | * *** empty log message *** |
| 88 | * |
| 89 | * |
| 90 | * Revision 2.0 1999/01/15 09:10:39 hyc |
| 91 | * *** empty log message *** |
| 92 | * |
| 93 | * |
| 94 | * $Header: /cvsroot/Lorene/C++/Include/mtbl.h,v 1.7 2014/10/13 08:52:36 j_novak Exp $ |
| 95 | * |
| 96 | */ |
| 97 | |
| 98 | |
| 99 | // Headers Lorene |
| 100 | #include "tbl.h" |
| 101 | #include "grilles.h" |
| 102 | |
| 103 | namespace Lorene { |
| 104 | class Coord ; |
| 105 | |
| 106 | /** |
| 107 | * Multi-domain array. \ingroup (spec) |
| 108 | * |
| 109 | * This class is essentially an array of \c Tbl . It is intended to be |
| 110 | * used in conjunction with the class \c Mtbl_cf . |
| 111 | * A \c Mtbl is initialy created with a \a logical state \c NONDEF . |
| 112 | * Arithmetic operations are provided with the usual meaning (see |
| 113 | * below). |
| 114 | * |
| 115 | * @version #$Id: mtbl.h,v 1.7 2014/10/13 08:52:36 j_novak Exp $# |
| 116 | * |
| 117 | */ |
| 118 | class Mtbl { |
| 119 | |
| 120 | // Data : |
| 121 | // ----- |
| 122 | private: |
| 123 | /// Pointer on the multi-grid \c Mgd3 on which \c this is defined |
| 124 | const Mg3d* mg ; |
| 125 | /// Number of domains (zones) |
| 126 | int nzone ; |
| 127 | /// Logical state (\c ETATNONDEF , \c ETATQCQ or \c ETATZERO ). |
| 128 | int etat ; |
| 129 | |
| 130 | public: |
| 131 | /// Array (size \c nzone ) of pointers on the \c Tbl 's |
| 132 | Tbl** t; |
| 133 | |
| 134 | // Constructors - Destructor |
| 135 | // ------------------------- |
| 136 | |
| 137 | public: |
| 138 | /// Constructor |
| 139 | explicit Mtbl(const Mg3d& mgrid) ; |
| 140 | /// Constructor |
| 141 | explicit Mtbl(const Mg3d* p_mgrid) ; |
| 142 | /// Constructor from a file (see \c sauve(FILE*)) |
| 143 | Mtbl(const Mg3d&, FILE* ) ; |
| 144 | /// Constructor from a Coord |
| 145 | Mtbl(const Coord& c) ; |
| 146 | /// Copy constructor |
| 147 | Mtbl(const Mtbl& a) ; |
| 148 | /// Destructor |
| 149 | ~Mtbl() ; |
| 150 | |
| 151 | // Assignement |
| 152 | // ----------- |
| 153 | public: |
| 154 | /// Assignement to another \c Mtbl |
| 155 | void operator=(const Mtbl& ) ; |
| 156 | /// Assignement to a \c double |
| 157 | void operator=(double ) ; |
| 158 | /// Assignement to a \c int |
| 159 | void operator=(int ) ; |
| 160 | |
| 161 | // Memory management |
| 162 | // ----------------- |
| 163 | private: |
| 164 | /** Logical destructor: dellocates the memory occupied by the \c Tbl |
| 165 | * array \c t . |
| 166 | */ |
| 167 | void del_t() ; |
| 168 | |
| 169 | public: |
| 170 | |
| 171 | /** |
| 172 | * Sets the logical state to \c ETATNONDEF (undefined). |
| 173 | * Deallocates the memory occupied by the \c Tbl array \c t . |
| 174 | */ |
| 175 | void set_etat_nondef() ; |
| 176 | |
| 177 | /** |
| 178 | * Sets the logical state to \c ETATZERO (zero). |
| 179 | * Deallocates the memory occupied by the \c Tbl array \c t . |
| 180 | */ |
| 181 | void set_etat_zero() ; |
| 182 | |
| 183 | /** |
| 184 | * Sets the logical state to \c ETATQCQ (ordinary state). |
| 185 | * If the state (member \c etat ) is already \c ETATQCQ , this |
| 186 | * function does nothing. Otherwise, it performs the memory allocation |
| 187 | * for the \c Tbl array \c t . |
| 188 | */ |
| 189 | void set_etat_qcq() ; |
| 190 | |
| 191 | /** |
| 192 | * Sets the \c Mtbl to zero in a hard way. |
| 193 | * 1/ Sets the logical state to \c ETATQCQ , i.e. to an ordinary state. |
| 194 | * 2/ Allocates the memory of the \c Tbl array \c t , and fills it |
| 195 | * with zeros. NB: this function must be used for debugging purposes only. |
| 196 | * For other operations, the functions \c set_etat_zero() |
| 197 | * or \c annule(int, int) must be perferred. |
| 198 | */ |
| 199 | void annule_hard() ; |
| 200 | |
| 201 | /** |
| 202 | * Sets the \c Mtbl to zero in some domains. |
| 203 | * @param l_min [input] The \c Mtbl will be set (logically) to zero |
| 204 | * in the domains whose indices are in the range |
| 205 | * \c [l_min,l_max] . |
| 206 | * @param l_max [input] see the comments for \c l_min . |
| 207 | * |
| 208 | * Note that \c annule(0,nzone-1) is equivalent to |
| 209 | * \c set_etat_zero() . |
| 210 | */ |
| 211 | void annule(int l_min, int l_max) ; |
| 212 | |
| 213 | |
| 214 | // Access to individual elements |
| 215 | // ----------------------------- |
| 216 | public: |
| 217 | /** |
| 218 | * Read/write of the \c Tbl in a given domain. |
| 219 | * @param l [input] domain index |
| 220 | */ |
| 221 | Tbl& set(int l) { |
| 222 | assert(l < nzone) ; |
| 223 | assert(etat == ETATQCQ) ; |
| 224 | return *(t[l]) ; |
| 225 | }; |
| 226 | |
| 227 | |
| 228 | /** |
| 229 | * Read-only of the \c Tbl in a given domain. |
| 230 | * @param l [input] domain index |
| 231 | */ |
| 232 | const Tbl& operator()(int l) const { |
| 233 | assert(l < nzone) ; |
| 234 | assert(etat == ETATQCQ) ; |
| 235 | return *(t[l]) ; |
| 236 | }; |
| 237 | |
| 238 | /** |
| 239 | * Read/write of a particular element. |
| 240 | * @param l [input] domain index |
| 241 | * @param k [input] \f$\phi\f$ index |
| 242 | * @param j [input] \f$\theta\f$ index |
| 243 | * @param i [input] \e r (\f$\xi\f$) index |
| 244 | */ |
| 245 | double& set(int l, int k, int j, int i) { |
| 246 | assert(l < nzone) ; |
| 247 | assert(etat == ETATQCQ) ; |
| 248 | return (t[l])->set(k, j, i) ; |
| 249 | }; |
| 250 | |
| 251 | |
| 252 | /** |
| 253 | * Read-only of a particular element. |
| 254 | * @param l [input] domain index |
| 255 | * @param k [input] \f$\phi\f$ index |
| 256 | * @param j [input] \f$\theta\f$ index |
| 257 | * @param i [input] \e r (\f$\xi\f$) index |
| 258 | */ |
| 259 | double operator()(int l, int k, int j, int i) const { |
| 260 | assert(etat != ETATNONDEF) ; |
| 261 | assert(l < nzone) ; |
| 262 | if (etat == ETATZERO) { |
| 263 | double zero = 0. ; |
| 264 | return zero ; |
| 265 | } |
| 266 | else return (*t[l])(k, j, i) ; |
| 267 | }; |
| 268 | |
| 269 | |
| 270 | // Extraction of information |
| 271 | // ------------------------- |
| 272 | public: |
| 273 | /// Gives the \c Mg3d on which the \c Mtbl is defined |
| 274 | const Mg3d* get_mg() const { return mg ; }; |
| 275 | |
| 276 | /// Gives the logical state |
| 277 | int get_etat() const { return etat ; }; |
| 278 | |
| 279 | /// Gives the number of zones (domains) |
| 280 | int get_nzone() const { return nzone ; } ; |
| 281 | |
| 282 | // Outputs |
| 283 | // ------- |
| 284 | public: |
| 285 | /// Save in a file |
| 286 | void sauve(FILE *) const ; |
| 287 | |
| 288 | /** Prints only the values greater than a given threshold. |
| 289 | * @param ostr [input] Output stream used for the printing |
| 290 | * @param precision [input] Number of printed digits (default: 4) |
| 291 | * @param threshold [input] Value above which an array element is printed |
| 292 | * (default: 1.e-7) |
| 293 | */ |
| 294 | void affiche_seuil(ostream& ostr, int precision = 4, |
| 295 | double threshold = 1.e-7) const ; |
| 296 | /// Display |
| 297 | friend ostream& operator<<(ostream& , const Mtbl & ) ; |
| 298 | |
| 299 | // Member arithmetics |
| 300 | // ------------------ |
| 301 | public: |
| 302 | /// += Mtbl |
| 303 | void operator+=(const Mtbl & ) ; |
| 304 | /// += double |
| 305 | void operator+=(double ) ; |
| 306 | /// -= Mtbl |
| 307 | void operator-=(const Mtbl & ) ; |
| 308 | /// -= double |
| 309 | void operator-=(double ) ; |
| 310 | /// *= Mtbl |
| 311 | void operator*=(const Mtbl & ) ; |
| 312 | /// *= double |
| 313 | void operator*=(double ) ; |
| 314 | /// /= Mtbl |
| 315 | void operator/=(const Mtbl & ) ; |
| 316 | /// /= double |
| 317 | void operator/=(double ) ; |
| 318 | |
| 319 | } ; |
| 320 | ostream& operator<<(ostream& , const Mtbl & ) ; |
| 321 | |
| 322 | /** |
| 323 | * \defgroup mtbl_mat Mtbl Mathematics |
| 324 | * \ingroup (spec) |
| 325 | * |
| 326 | * @{ |
| 327 | */ |
| 328 | /// + Mtbl |
| 329 | Mtbl operator+(const Mtbl& ) ; |
| 330 | /// \c - Mtbl |
| 331 | Mtbl operator-(const Mtbl& ) ; |
| 332 | /// Mtbl + Mtbl |
| 333 | Mtbl operator+(const Mtbl&, const Mtbl& ) ; |
| 334 | /// Mtbl + double |
| 335 | Mtbl operator+(const Mtbl&, double ) ; |
| 336 | /// double + Mtbl |
| 337 | Mtbl operator+(double , const Mtbl& ) ; |
| 338 | /// Mtbl + int |
| 339 | Mtbl operator+(const Mtbl&, int ) ; |
| 340 | /// int + Mtbl |
| 341 | Mtbl operator+(int, const Mtbl& ) ; |
| 342 | /// Mtbl - Mtbl |
| 343 | Mtbl operator-(const Mtbl&, const Mtbl& ) ; |
| 344 | /// Mtbl - double |
| 345 | Mtbl operator-(const Mtbl&, double ) ; |
| 346 | /// double - Mtbl |
| 347 | Mtbl operator-(double, const Mtbl& ) ; |
| 348 | /// Mtbl - int |
| 349 | Mtbl operator-(const Mtbl&, int ) ; |
| 350 | /// int - Mtbl |
| 351 | Mtbl operator-(int, const Mtbl& ) ; |
| 352 | /// Mtbl * Mtbl |
| 353 | Mtbl operator*(const Mtbl&, const Mtbl& ) ; |
| 354 | /// Mtbl * double |
| 355 | Mtbl operator*(const Mtbl&, double ) ; |
| 356 | /// double * Mtbl |
| 357 | Mtbl operator*(double, const Mtbl& ) ; |
| 358 | /// Mtbl * int |
| 359 | Mtbl operator*(const Mtbl&, int ) ; |
| 360 | /// int * Mtbl |
| 361 | Mtbl operator*(int, const Mtbl& ) ; |
| 362 | /// Mtbl / Mtbl |
| 363 | Mtbl operator/(const Mtbl&, const Mtbl& ) ; |
| 364 | /// Mtbl / double |
| 365 | Mtbl operator/(const Mtbl&, double ) ; |
| 366 | /// double / Mtbl |
| 367 | Mtbl operator/(double, const Mtbl& ) ; |
| 368 | /// Mtbl / int |
| 369 | Mtbl operator/(const Mtbl&, int ) ; |
| 370 | /// int / Mtbl |
| 371 | Mtbl operator/(int, const Mtbl& ) ; |
| 372 | |
| 373 | /// Sine |
| 374 | Mtbl sin(const Mtbl& ) ; |
| 375 | /// Cosine |
| 376 | Mtbl cos(const Mtbl& ) ; |
| 377 | /// Tangent |
| 378 | Mtbl tan(const Mtbl& ) ; |
| 379 | /// Arcsine |
| 380 | Mtbl asin(const Mtbl& ) ; |
| 381 | /// Arccosine |
| 382 | Mtbl acos(const Mtbl& ) ; |
| 383 | /// Arctangent |
| 384 | Mtbl atan(const Mtbl& ) ; |
| 385 | /// Exponential |
| 386 | Mtbl exp(const Mtbl& ) ; |
| 387 | /// Heaviside function |
| 388 | Mtbl Heaviside(const Mtbl& ) ; |
| 389 | /// Neperian logarithm |
| 390 | Mtbl log(const Mtbl& ) ; |
| 391 | /// Neperian logarithm |
| 392 | Mtbl log(const Mtbl& ) ; |
| 393 | /// Basis 10 logarithm |
| 394 | Mtbl log10(const Mtbl& ) ; |
| 395 | /// Square root |
| 396 | Mtbl sqrt(const Mtbl& ) ; |
| 397 | /// Cube root |
| 398 | Mtbl racine_cubique (const Mtbl&) ; |
| 399 | /// Power \f${\tt Mtbl}^{\tt int}\f$ |
| 400 | Mtbl pow(const Mtbl& , int ) ; |
| 401 | /// Power \f${\tt Mtbl}^{\tt double}\f$ |
| 402 | Mtbl pow(const Mtbl& , double ) ; |
| 403 | /// Absolute value |
| 404 | Mtbl abs(const Mtbl& ) ; |
| 405 | |
| 406 | /** |
| 407 | * Maximum value of the \c Mtbl elements in all domains. |
| 408 | * @return a double |
| 409 | */ |
| 410 | double totalmax(const Mtbl& ) ; |
| 411 | |
| 412 | /** |
| 413 | * Minimum value of the \c Mtbl elements in all domain. |
| 414 | * @return a double |
| 415 | */ |
| 416 | double totalmin(const Mtbl& ) ; |
| 417 | |
| 418 | /** |
| 419 | * Maximum values of the \c Mtbl elements in each domain. |
| 420 | * @return 1-D \c Tbl of size the number of domains, the elements of which |
| 421 | * are the set of the maximum values in each domain. |
| 422 | */ |
| 423 | Tbl max(const Mtbl& ) ; |
| 424 | |
| 425 | /** |
| 426 | * Minimum values of the \c Mtbl elements in each domain. |
| 427 | * @return 1-D \c Tbl of size the number of domains, the elements of which |
| 428 | * are the set of the minimum values in each domain. |
| 429 | */ |
| 430 | Tbl min(const Mtbl& ) ; |
| 431 | |
| 432 | /** |
| 433 | * Sums of the absolute values of all the \c Mtbl elements in each domain. |
| 434 | * @return 1-D \c Tbl of size the number of domains, the elements of which |
| 435 | * are the set of the sums of the absolute values in each domain. |
| 436 | */ |
| 437 | Tbl norme(const Mtbl& ) ; |
| 438 | |
| 439 | /** |
| 440 | * Relative difference between two \c Mtbl (norme version). |
| 441 | * @return 1-D \c Tbl of size the number of domains, the elements of which |
| 442 | * are \c norme[a(l)-b(l)]/norme[b(l)] if \c b(l)!=0 and |
| 443 | * \c norme[a(l)-b(l)] if \c b(l)=0 , where \c a(l) and |
| 444 | * \c b(l) denote symbolically the values of \c a and \c b |
| 445 | * in domain no. \c l . |
| 446 | */ |
| 447 | Tbl diffrel(const Mtbl& a, const Mtbl& b) ; |
| 448 | |
| 449 | /** |
| 450 | * Relative difference between two \c Mtbl (max version). |
| 451 | * @return 1-D \c Tbl of size the number of domains, the elements of which |
| 452 | * are \c max[abs(a(l)-b(l))]/max[abs(b(l))] if \c b(l)!=0 and |
| 453 | * \c max[abs(a(l)-b(l))] if \c b(l)=0 , where \c a(l) and |
| 454 | * \c b(l) denote symbolically the values of \c a and \c b |
| 455 | * in domain no. \c l . |
| 456 | */ |
| 457 | Tbl diffrelmax(const Mtbl& a, const Mtbl& b) ; |
| 458 | |
| 459 | /**@} */ |
| 460 | |
| 461 | |
| 462 | } |
| 463 | #endif |