LORENE
xdsdx_mat.C
1/*
2 * Copyright (c) 2000-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: xdsdx_mat.C,v 1.6 2016/12/05 16:18:10 j_novak Exp $
27 * $Log: xdsdx_mat.C,v $
28 * Revision 1.6 2016/12/05 16:18:10 j_novak
29 * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
30 *
31 * Revision 1.5 2014/10/13 08:53:31 j_novak
32 * Lorene classes and functions now belong to the namespace Lorene.
33 *
34 * Revision 1.4 2014/10/06 15:16:11 j_novak
35 * Modified #include directives to use c++ syntax.
36 *
37 * Revision 1.3 2007/06/21 20:07:16 k_taniguchi
38 * nmax increased to 200
39 *
40 * Revision 1.2 2002/10/16 14:37:12 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:28 e_gourgoulhon
45 * LORENE
46 *
47 * Revision 2.0 2000/03/16 16:23:17 phil
48 * *** empty log message ***
49 *
50 *
51 * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/PDE/xdsdx_mat.C,v 1.6 2016/12/05 16:18:10 j_novak Exp $
52 *
53 */
54
55/*
56 * Routine renvoyan la matrice de l'operateur x f' = s
57 * Pour l != 1 le resultat est donne en s est donne en Chebyshev et
58 * f en Gelerkin (T_i + T_{i+1} pour l pair et (2*i+3)T_i + (2*i+1)T_{i+1} pour
59 * l impair.
60 * Pour l=1 pas de probleme de singularite on reste donc en Chebyshev.
61 */
62
63//fichiers includes
64#include <cstdio>
65#include <cstdlib>
66
67#include "matrice.h"
68#include "type_parite.h"
69#include "proto.h"
70
71 //-----------------------------------
72 // Routine pour les cas non prevus --
73 //-----------------------------------
74
75namespace Lorene {
76Matrice _xdsdx_mat_pas_prevu(int n, int) {
77 cout << "xdsdx_mat pas prevu..." << endl ;
78 cout << "n : " << n << endl ;
79 abort() ;
80 exit(-1) ;
81 Matrice res(1, 1) ; // On ne passe jamais ici de toute facon !
82 return res;
83}
84
85
86 //-------------------------
87 //-- CAS R_CHEBP -----
88 //--------------------------
89
90
91Matrice _xdsdx_mat_r_chebp (int n, int) {
92 const int nmax = 200 ;// Nombre de Matrices stockees
93 static Matrice* tab[nmax] ; // les matrices calculees
94 static int nb_dejafait = 0 ; // nbre de matrices calculees
95 static int nr_dejafait[nmax] ;
96
97 int indice = -1 ;
98
99 // On determine si la matrice a deja ete calculee :
100 for (int conte=0 ; conte<nb_dejafait ; conte ++)
101 if (nr_dejafait[conte] == n)
102 indice = conte ;
103
104 // Calcul a faire :
105 if (indice == -1) {
106 if (nb_dejafait >= nmax) {
107 cout << "_laplacien_nul_mat_r_chebp : trop de matrices" << endl ;
108 abort() ;
109 exit (-1) ;
110 }
111
112 nr_dejafait[nb_dejafait] = n ;
113
114 Matrice res(n-1, n-1) ;
115 res.set_etat_qcq() ;
116
117 double* xdsdx = new double[n] ;
118
119 for (int i=0 ; i<n-1 ; i++) {
120 for (int j=0 ; j<n ; j++)
121 xdsdx[j] = 0 ;
122 xdsdx[i] = 1 ;
123 xdsdx[i+1] = 1 ;
124 xdsdx_1d (n, &xdsdx, R_CHEBP) ;
125
126 for (int j=0 ; j<n-1 ; j++)
127 res.set(j, i) = xdsdx[j] ;
128 }
129 delete [] xdsdx ;
130 tab[nb_dejafait] = new Matrice(res) ;
131 nb_dejafait ++ ;
132 return res ;
133 }
134
135 else
136 return *tab[indice] ;
137}
138
139
140
141 //------------------------
142 //-- CAS R_CHEBI ----
143 //------------------------
144
145
146Matrice _xdsdx_mat_r_chebi (int n, int l) {
147 const int nmax = 200 ;// Nombre de Matrices stockees
148 static Matrice* tab[nmax] ; // les matrices calculees
149 static int nb_dejafait = 0 ; // nbre de matrices calculees
150 static int nr_dejafait[nmax] ;
151 static int nl_dejafait[nmax] ;
152
153 int indice = -1 ;
154 // On separe les cas l=1 et l != 1
155 int indic_l = (l == 1) ? 1 : 2 ;
156
157 // On determine si la matrice a deja ete calculee :
158 for (int conte=0 ; conte<nb_dejafait ; conte ++)
159 if ((nr_dejafait[conte] == n) && (nl_dejafait[conte] == indic_l))
160 indice = conte ;
161
162 // Calcul a faire :
163 if (indice == -1) {
164 if (nb_dejafait >= nmax) {
165 cout << "_laplacien_nul_mat_r_chebp : trop de matrices" << endl ;
166 abort() ;
167 exit (-1) ;
168 }
169
170 nr_dejafait[nb_dejafait] = n ;
171 nl_dejafait[nb_dejafait] = indic_l ;
172
173 // non degenere pour l=1
174 int taille = (l==1) ? n : n-1 ;
175 Matrice res(taille, taille) ;
176 res.set_etat_qcq() ;
177
178 double* xdsdx = new double[n] ;
179
180 for (int i=0 ; i<taille ; i++) {
181 for (int j=0 ; j<n ; j++)
182 xdsdx[j] = 0 ;
183
184 // Gelerkin ou Chebyshev ?
185 if (taille == n) {
186 xdsdx[i] = 1 ;
187 }
188 else {
189 xdsdx[i] = 2*i+3 ;
190 xdsdx[i+1] = 2*i+1 ;
191 }
192 xdsdx_1d (n, &xdsdx, R_CHEBI) ; // appel dans le cas impair
193
194 for (int j=0 ; j<taille ; j++)
195 res.set(j, i) = xdsdx[j] ;
196 }
197
198 delete [] xdsdx ;
199 tab[nb_dejafait] = new Matrice(res) ;
200 nb_dejafait ++ ;
201 return res ;
202 }
203
204 else
205 return *tab[indice] ;
206}
207
208
209 //--------------------------
210 //- La routine a appeler ---
211 //----------------------------
212Matrice xdsdx_mat(int n, int l, int base_r)
213{
214
215 // Routines de derivation
216 static Matrice (*xdsdx_mat[MAX_BASE])(int, int) ;
217 static int nap = 0 ;
218
219 // Premier appel
220 if (nap==0) {
221 nap = 1 ;
222 for (int i=0 ; i<MAX_BASE ; i++) {
223 xdsdx_mat[i] = _xdsdx_mat_pas_prevu ;
224 }
225 // Les routines existantes
226 xdsdx_mat[R_CHEBP >> TRA_R] = _xdsdx_mat_r_chebp ;
227 xdsdx_mat[R_CHEBI >> TRA_R] = _xdsdx_mat_r_chebi ;
228 }
229
230 Matrice res(xdsdx_mat[base_r](n, l)) ;
231 return res ;
232}
233
234}
Matrix handling.
Definition matrice.h:152
#define MAX_BASE
Nombre max. de bases differentes.
#define R_CHEBI
base de Cheb. impaire (rare) seulement
#define TRA_R
Translation en R, used for a bitwise shift (in hex).
#define R_CHEBP
base de Cheb. paire (rare) seulement
Lorene prototypes.
Definition app_hor.h:67