1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
|
/*
* Copyright (c) 2004 Jerome Novak
*
* This file is part of LORENE.
*
* LORENE is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* LORENE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LORENE; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
char dsdx_1d_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/Operators/dsdx_1d.C,v 1.9 2015/03/25 15:03:00 j_novak Exp $" ;
/*
* $Id: dsdx_1d.C,v 1.9 2015/03/25 15:03:00 j_novak Exp $
* $Log: dsdx_1d.C,v $
* Revision 1.9 2015/03/25 15:03:00 j_novak
* Correction of a bug...
*
* Revision 1.8 2015/03/05 08:49:31 j_novak
* Implemented operators with Legendre bases.
*
* Revision 1.7 2014/10/13 08:53:23 j_novak
* Lorene classes and functions now belong to the namespace Lorene.
*
* Revision 1.6 2014/10/06 15:16:06 j_novak
* Modified #include directives to use c++ syntax.
*
* Revision 1.5 2007/12/12 12:30:48 jl_cornou
* *** empty log message ***
*
* Revision 1.4 2007/12/11 15:28:18 jl_cornou
* Jacobi(0,2) polynomials partially implemented
*
* Revision 1.3 2006/04/10 15:19:20 j_novak
* New definition of 1D operators dsdx and sx in the nucleus (bases R_CHEBP and
* R_CHEBI).
*
* Revision 1.2 2005/01/10 16:34:53 j_novak
* New class for 1D mono-domain differential operators.
*
* Revision 1.1 2004/02/06 10:53:53 j_novak
* New dzpuis = 5 -> dzpuis = 3 case (not ready yet).
*
*
* $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Operators/dsdx_1d.C,v 1.9 2015/03/25 15:03:00 j_novak Exp $
*
*/
#include <cmath>
#include <cstdlib>
#include "type_parite.h"
#include "headcpp.h"
#include "proto.h"
/*
* Routine appliquant l'operateur dsdx.
*
* Entree : tb contient les coefficients du developpement
* int nr : nombre de points en r.
*
* Sortie : tb contient dsdx
*
*/
//----------------------------------
// Routine pour les cas non prevus --
//----------------------------------
namespace Lorene {
void _dsdx_1d_pas_prevu(int nr, double* tb, double *xo) {
cout << "dsdx pas prevu..." << endl ;
cout << "Nombre de points : " << nr << endl ;
cout << "Valeurs : " << tb << " " << xo <<endl ;
abort() ;
exit(-1) ;
}
//----------------
// cas R_CHEBU ---
//----------------
void _dsdx_1d_r_chebu(int nr, double* tb, double *xo)
{
double som ;
xo[nr-1] = 0 ;
som = 2*(nr-1) * tb[nr-1] ;
xo[nr-2] = som ;
for (int i = nr-4 ; i >= 0 ; i -= 2 ) {
som += 2*(i+1) * tb[i+1] ;
xo[i] = som ;
} // Fin de la premiere boucle sur r
som = 2*(nr-2) * tb[nr-2] ;
xo[nr-3] = som ;
for (int i = nr-5 ; i >= 0 ; i -= 2 ) {
som += 2*(i+1) * tb[i+1] ;
xo[i] = som ;
} // Fin de la deuxieme boucle sur r
xo[0] *= .5 ;
}
//----------------
// cas R_JACO02 --
//----------------
void _dsdx_1d_r_jaco02(int nr, double* tb, double *xo)
{
double som ;
xo[nr-1] = 0 ;
for (int i = 0 ; i < nr-1 ; i++ ) {
som = 0 ;
for ( int j = i+1 ; j < nr ; j++ ) {
som += (1 - pow(double(-1),(j-i))*(i+1)*(i+2)/double((j+1)*(j+2)))*tb[j] ;
} // Fin de la boucle auxiliaire
xo[i] = (i+1.5)*som ;
} // Fin de la boucle sur R
}
//----------------
// cas R_CHEBI ---
//----------------
void _dsdx_1d_r_chebi(int nr, double* tb, double *xo)
{
double som ;
xo[nr-1] = 0 ;
som = 2*(2*nr-3) * tb[nr-2] ;
xo[nr-2] = som ;
for (int i = nr-3 ; i >= 0 ; i -- ) {
som += 2*(2*i+1) * tb[i] ;
xo[i] = som ;
}
xo[0] *= .5 ;
}
//----------------
// cas R_CHEBP ---
//----------------
void _dsdx_1d_r_chebp(int nr, double* tb, double *xo)
{
double som ;
xo[nr-1] = 0 ;
som = 4*(nr-1) * tb[nr-1] ;
xo[nr-2] = som ;
for (int i = nr-3 ; i >= 0 ; i --) {
som += 4*(i+1) * tb[i+1] ;
xo[i] = som ;
}
}
//--------------
// cas R_LEG ---
//--------------
void _dsdx_1d_r_leg(int nr, double* tb, double *xo)
{
double som ;
xo[nr-1] = 0 ;
som = tb[nr-1] ;
xo[nr-2] = double(2*nr-3)*som ;
for (int i = nr-4 ; i >= 0 ; i -= 2 ) {
som += tb[i+1] ;
xo[i] = double(2*i+1)*som ;
} // Fin de la premiere boucle sur r
som = tb[nr-2] ;
if (nr > 2) xo[nr-3] = double(2*nr-5)*som ;
for (int i = nr-5 ; i >= 0 ; i -= 2 ) {
som += tb[i+1] ;
xo[i] = double(2*i+1)*som ;
} // Fin de la deuxieme boucle sur r
}
//---------------
// cas R_LEGI ---
//---------------
void _dsdx_1d_r_legi(int nr, double* tb, double *xo)
{
double som ;
xo[nr-1] = 0 ;
som = tb[nr-2] ;
if (nr > 1) xo[nr-2] = double(4*nr-7)*som ;
for (int i = nr-3 ; i >= 0 ; i -- ) {
som += tb[i] ;
xo[i] = double(4*i+1)*som ;
}
}
//---------------
// cas R_LEGP ---
//---------------
void _dsdx_1d_r_legp(int nr, double* tb, double *xo)
{
double som ;
xo[nr-1] = 0 ;
som = tb[nr-1] ;
if (nr > 1) xo[nr-2] = double(4*nr-5)*som ;
for (int i = nr-3 ; i >= 0 ; i --) {
som += tb[i+1] ;
xo[i] = double(4*i+3)*som ;
}
}
// ---------------------
// La routine a appeler
//----------------------
void dsdx_1d(int nr, double** tb, int base_r)
{
// Routines de derivation
static void (*dsdx_1d[MAX_BASE])(int, double*, double *) ;
static int nap = 0 ;
// Premier appel
if (nap==0) {
nap = 1 ;
for (int i=0 ; i<MAX_BASE ; i++) {
dsdx_1d[i] = _dsdx_1d_pas_prevu ;
}
// Les routines existantes
dsdx_1d[R_CHEBU >> TRA_R] = _dsdx_1d_r_chebu ;
dsdx_1d[R_CHEBP >> TRA_R] = _dsdx_1d_r_chebp ;
dsdx_1d[R_CHEBI >> TRA_R] = _dsdx_1d_r_chebi ;
dsdx_1d[R_CHEB >> TRA_R] = _dsdx_1d_r_cheb ;
dsdx_1d[R_LEGP >> TRA_R] = _dsdx_1d_r_legp ;
dsdx_1d[R_LEGI >> TRA_R] = _dsdx_1d_r_legi ;
dsdx_1d[R_LEG >> TRA_R] = _dsdx_1d_r_leg ;
dsdx_1d[R_JACO02 >> TRA_R] = _dsdx_1d_r_jaco02 ;
}
double *result = new double[nr] ;
dsdx_1d[base_r](nr, *tb, result) ;
delete [] (*tb) ;
(*tb) = result ;
}
}
|