| 1 |
/* |
| 2 |
* Copyright (c) 1999-2001 Philippe Grandclement |
| 3 |
* |
| 4 |
* This file is part of LORENE. |
| 5 |
* |
| 6 |
* LORENE is free software; you can redistribute it and/or modify |
| 7 |
* it under the terms of the GNU General Public License as published by |
| 8 |
* the Free Software Foundation; either version 2 of the License, or |
| 9 |
* (at your option) any later version. |
| 10 |
* |
| 11 |
* LORENE is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
* GNU General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU General Public License |
| 17 |
* along with LORENE; if not, write to the Free Software |
| 18 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 |
* |
| 20 |
*/ |
| 21 |
|
| 22 |
|
| 23 |
char multx_1d_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Operators/multx_1d.C,v 1.5 2015/03/05 08:49:32 j_novak Exp $" ; |
| 24 |
|
| 25 |
/* |
| 26 |
* $Id: multx_1d.C,v 1.5 2015/03/05 08:49:32 j_novak Exp $ |
| 27 |
* $Log: multx_1d.C,v $ |
| 28 |
* Revision 1.5 2015/03/05 08:49:32 j_novak |
| 29 |
* Implemented operators with Legendre bases. |
| 30 |
* |
| 31 |
* Revision 1.4 2014/10/13 08:53:24 j_novak |
| 32 |
* Lorene classes and functions now belong to the namespace Lorene. |
| 33 |
* |
| 34 |
* Revision 1.3 2014/10/06 15:16:06 j_novak |
| 35 |
* Modified #include directives to use c++ syntax. |
| 36 |
* |
| 37 |
* Revision 1.2 2002/10/16 14:36:58 j_novak |
| 38 |
* Reorganization of #include instructions of standard C++, in order to |
| 39 |
* use experimental version 3 of gcc. |
| 40 |
* |
| 41 |
* Revision 1.1.1.1 2001/11/20 15:19:29 e_gourgoulhon |
| 42 |
* LORENE |
| 43 |
* |
| 44 |
* Revision 2.1 1999/07/08 09:54:30 phil |
| 45 |
* correction gestion memoire |
| 46 |
* |
| 47 |
* Revision 2.0 1999/07/07 10:15:40 phil |
| 48 |
* *** empty log message *** |
| 49 |
* |
| 50 |
* |
| 51 |
* $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Operators/multx_1d.C,v 1.5 2015/03/05 08:49:32 j_novak Exp $ |
| 52 |
* |
| 53 |
*/ |
| 54 |
|
| 55 |
|
| 56 |
// Includes |
| 57 |
#include <cstdlib> |
| 58 |
#include <cassert> |
| 59 |
|
| 60 |
#include "headcpp.h" |
| 61 |
#include "type_parite.h" |
| 62 |
|
| 63 |
|
| 64 |
/* |
| 65 |
* Operateurs de multiplication par x |
| 66 |
* |
| 67 |
* Uniquement le cas R_CHEB |
| 68 |
* |
| 69 |
* Entree : |
| 70 |
* |
| 71 |
* int nr : nombre de points en r |
| 72 |
* tb contient les coefficients du developpement |
| 73 |
* evenetuellement e dans echelle |
| 74 |
* |
| 75 |
* Sortie : |
| 76 |
* tb contient les coefficients du resultat... |
| 77 |
*/ |
| 78 |
|
| 79 |
|
| 80 |
//-------------------------------------- |
| 81 |
// Routine pour les cas non prevus ----- |
| 82 |
//-------------------------------------- |
| 83 |
|
| 84 |
namespace Lorene { |
| 85 |
void _multx_1d_pas_prevu(int nr, double* tb, double *result) { |
| 86 |
cout << "multx pas prevu..." << endl ; |
| 87 |
cout << "Valeurs : " << tb << " " << result << endl ; |
| 88 |
cout << " nr : " << nr << endl ; |
| 89 |
abort() ; |
| 90 |
exit(-1) ; |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
//------------------ |
| 95 |
// cas R_CHEB --- |
| 96 |
//------------------ |
| 97 |
|
| 98 |
void _multx_1d_r_cheb (int nr, double* tb, double* res) { |
| 99 |
|
| 100 |
res[0] = tb[1]/2. ; |
| 101 |
res[1] = (2*tb[0]+tb[2])/2. ; |
| 102 |
res[nr-1] = tb[nr-2]/2. ; |
| 103 |
|
| 104 |
for (int i=2 ; i<nr-1 ; i++) |
| 105 |
res[i] = (tb[i-1]+tb[i+1])/2. ; |
| 106 |
|
| 107 |
} |
| 108 |
|
| 109 |
|
| 110 |
//---------------- |
| 111 |
// cas R_LEG --- |
| 112 |
//---------------- |
| 113 |
|
| 114 |
void _multx_1d_r_leg (int nr, double* tb, double* res) { |
| 115 |
|
| 116 |
assert(nr > 1) ; |
| 117 |
res[0] = tb[1]/3. ; |
| 118 |
res[1] = tb[0]+0.4*tb[2] ; |
| 119 |
res[nr-1] = double(nr-1)*tb[nr-2]/double(2*nr-3) ; |
| 120 |
|
| 121 |
for (int i=2 ; i<nr-1 ; i++) |
| 122 |
res[i] = double(i)*tb[i-1]/double(2*i-1) |
| 123 |
+ double(i+1)*tb[i+1]/double(2*i+3) ; |
| 124 |
|
| 125 |
} |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
// ---------------------- |
| 130 |
// La routine a appeler |
| 131 |
//----------------------- |
| 132 |
|
| 133 |
void multx_1d(int nr, double **tb, int base_r) |
| 134 |
{ |
| 135 |
|
| 136 |
// Routines de derivation |
| 137 |
static void (*multx_1d[MAX_BASE])(int, double *, double *) ; |
| 138 |
static int nap = 0 ; |
| 139 |
|
| 140 |
// Premier appel |
| 141 |
if (nap==0) { |
| 142 |
nap = 1 ; |
| 143 |
for (int i=0 ; i<MAX_BASE ; i++) { |
| 144 |
multx_1d[i] = _multx_1d_pas_prevu ; |
| 145 |
} |
| 146 |
// Les routines existantes |
| 147 |
multx_1d[R_CHEB >> TRA_R] = _multx_1d_r_cheb ; |
| 148 |
multx_1d[R_LEG >> TRA_R] = _multx_1d_r_leg ; |
| 149 |
} |
| 150 |
|
| 151 |
|
| 152 |
double *result = new double[nr] ; |
| 153 |
multx_1d[base_r](nr, *tb, result) ; |
| 154 |
delete [] (*tb) ; |
| 155 |
(*tb) = result ; |
| 156 |
} |
| 157 |
|
| 158 |
} |