LORENE
multx_1d.C
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
24
25/*
26 * $Id: multx_1d.C,v 1.6 2016/12/05 16:18:07 j_novak Exp $
27 * $Log: multx_1d.C,v $
28 * Revision 1.6 2016/12/05 16:18:07 j_novak
29 * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
30 *
31 * Revision 1.5 2015/03/05 08:49:32 j_novak
32 * Implemented operators with Legendre bases.
33 *
34 * Revision 1.4 2014/10/13 08:53:24 j_novak
35 * Lorene classes and functions now belong to the namespace Lorene.
36 *
37 * Revision 1.3 2014/10/06 15:16:06 j_novak
38 * Modified #include directives to use c++ syntax.
39 *
40 * Revision 1.2 2002/10/16 14:36:58 j_novak
41 * Reorganization of #include instructions of standard C++, in order to
42 * use experimental version 3 of gcc.
43 *
44 * Revision 1.1.1.1 2001/11/20 15:19:29 e_gourgoulhon
45 * LORENE
46 *
47 * Revision 2.1 1999/07/08 09:54:30 phil
48 * correction gestion memoire
49 *
50 * Revision 2.0 1999/07/07 10:15:40 phil
51 * *** empty log message ***
52 *
53 *
54 * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/Operators/multx_1d.C,v 1.6 2016/12/05 16:18:07 j_novak Exp $
55 *
56 */
57
58
59 // Includes
60#include <cstdlib>
61#include <cassert>
62
63#include "headcpp.h"
64#include "type_parite.h"
65
66
67/*
68 * Operateurs de multiplication par x
69 *
70 * Uniquement le cas R_CHEB
71 *
72 * Entree :
73 *
74 * int nr : nombre de points en r
75 * tb contient les coefficients du developpement
76 * evenetuellement e dans echelle
77 *
78 * Sortie :
79 * tb contient les coefficients du resultat...
80 */
81
82
83 //--------------------------------------
84 // Routine pour les cas non prevus -----
85 //--------------------------------------
86
87namespace Lorene {
88void _multx_1d_pas_prevu(int nr, double* tb, double *result) {
89 cout << "multx pas prevu..." << endl ;
90 cout << "Valeurs : " << tb << " " << result << endl ;
91 cout << " nr : " << nr << endl ;
92 abort() ;
93 exit(-1) ;
94}
95
96
97 //------------------
98 // cas R_CHEB ---
99 //------------------
100
101void _multx_1d_r_cheb (int nr, double* tb, double* res) {
102
103 res[0] = tb[1]/2. ;
104 res[1] = (2*tb[0]+tb[2])/2. ;
105 res[nr-1] = tb[nr-2]/2. ;
106
107 for (int i=2 ; i<nr-1 ; i++)
108 res[i] = (tb[i-1]+tb[i+1])/2. ;
109
110}
111
112
113 //----------------
114 // cas R_LEG ---
115 //----------------
116
117void _multx_1d_r_leg (int nr, double* tb, double* res) {
118
119 assert(nr > 1) ;
120 res[0] = tb[1]/3. ;
121 res[1] = tb[0]+0.4*tb[2] ;
122 res[nr-1] = double(nr-1)*tb[nr-2]/double(2*nr-3) ;
123
124 for (int i=2 ; i<nr-1 ; i++)
125 res[i] = double(i)*tb[i-1]/double(2*i-1)
126 + double(i+1)*tb[i+1]/double(2*i+3) ;
127
128}
129
130
131
132 // ----------------------
133 // La routine a appeler
134 //-----------------------
135
136void multx_1d(int nr, double **tb, int base_r)
137{
138
139 // Routines de derivation
140 static void (*multx_1d[MAX_BASE])(int, double *, double *) ;
141 static int nap = 0 ;
142
143 // Premier appel
144 if (nap==0) {
145 nap = 1 ;
146 for (int i=0 ; i<MAX_BASE ; i++) {
147 multx_1d[i] = _multx_1d_pas_prevu ;
148 }
149 // Les routines existantes
150 multx_1d[R_CHEB >> TRA_R] = _multx_1d_r_cheb ;
151 multx_1d[R_LEG >> TRA_R] = _multx_1d_r_leg ;
152 }
153
154
155 double *result = new double[nr] ;
156 multx_1d[base_r](nr, *tb, result) ;
157 delete [] (*tb) ;
158 (*tb) = result ;
159}
160
161}
#define MAX_BASE
Nombre max. de bases differentes.
#define R_LEG
base de Legendre ordinaire (fin)
#define TRA_R
Translation en R, used for a bitwise shift (in hex).
#define R_CHEB
base de Chebychev ordinaire (fin)
Lorene prototypes.
Definition app_hor.h:67