LORENE
comb_lin_cpt.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 char comb_lin_cpt_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/PDE/comb_lin_cpt.C,v 1.4 2014/10/13 08:53:28 j_novak Exp $" ;
24 
25 /*
26  * $Id: comb_lin_cpt.C,v 1.4 2014/10/13 08:53:28 j_novak Exp $
27  * $Log: comb_lin_cpt.C,v $
28  * Revision 1.4 2014/10/13 08:53:28 j_novak
29  * Lorene classes and functions now belong to the namespace Lorene.
30  *
31  * Revision 1.3 2014/10/06 15:16:08 j_novak
32  * Modified #include directives to use c++ syntax.
33  *
34  * Revision 1.2 2002/10/16 14:37:11 j_novak
35  * Reorganization of #include instructions of standard C++, in order to
36  * use experimental version 3 of gcc.
37  *
38  * Revision 1.1.1.1 2001/11/20 15:19:28 e_gourgoulhon
39  * LORENE
40  *
41  * Revision 2.1 2000/11/22 19:29:50 eric
42  * Changement de nom_C en comb_lin_cpt_C
43  * Nettoyage des includes
44  *
45  * Revision 2.0 2000/03/16 16:25:18 phil
46  * *** empty log message ***
47  *
48  *
49  * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/PDE/comb_lin_cpt.C,v 1.4 2014/10/13 08:53:28 j_novak Exp $
50  *
51  */
52 
53 // Headers C
54 #include <cstdlib>
55 
56 // Headers Lorene
57 #include "matrice.h"
58 
59 /*
60  * Gestion des CL permettant de mettre a bande les operateurs associes a poisson
61  * compact. Version pour les sources et les matrices des operateurs.
62  */
63 
64 
65 // Version Matrice --> Matrice
66 namespace Lorene {
67 Matrice _cl_cpt_pas_prevu (const Matrice &source, int) {
68  cout << "Combinaison lineaire pas prevu..." << endl ;
69  cout << "Source : " << source << endl ;
70  abort() ;
71  return source;
72 }
73 
74 
75  //-------------------
76  //-- R_CHEBP -----
77  //-------------------
78 
79 
80 Matrice _cl_cpt_r_chebp (const Matrice &source, int) {
81 
82  int n = source.get_dim(0) ;
83  assert (n == source.get_dim(1)) ;
84 
85  Matrice barre(source) ;
86  int dirac = 1 ;
87  for (int i=0 ; i<n-2 ; i++) {
88  for (int j=0 ; j<n ; j++)
89  barre.set(i, j) = ((1+dirac)*source(i, j)-source(i+2, j))/(i+1) ;
90  if (i==0) dirac = 0 ;
91  }
92 
93  Matrice res(barre) ;
94  for (int i=0 ; i<n-4 ; i++)
95  for (int j=0 ; j<n ; j++)
96  res.set(i, j) = barre(i, j)-barre(i+2, j) ;
97 
98  res.set_band(4, 1) ;
99  res.set_lu() ;
100  return res ;
101 }
102 
103  //-------------------
104  //-- R_CHEBI -----
105  //-------------------
106 
107 
108 Matrice _cl_cpt_r_chebi (const Matrice &source, int l) {
109  int n = source.get_dim(0) ;
110  assert (n == source.get_dim(1)) ;
111 
112  Matrice barre(source) ;
113  for (int i=0 ; i<n-2 ; i++)
114  for (int j=0 ; j<n ; j++)
115  barre.set(i, j) = (source(i, j)-source(i+1, j))/(i+1) ;
116 
117  Matrice res(barre) ;
118  for (int i=0 ; i<n-4 ; i++)
119  for (int j=0 ; j<n ; j++)
120  res.set(i, j) = barre(i, j)-barre(i+2, j) ;
121 
122  if (l==1)
123  res.set_band(3, 0) ;
124  else
125  res.set_band(3, 1) ;
126  res.set_lu() ;
127  return res ;
128 
129 }
130 
131 
132  //-------------------------
133  //- La routine a appeler ---
134  //---------------------------
135 
136 Matrice combinaison_cpt (const Matrice &source, int l, int base_r) {
137 
138  // Routines de derivation
139  static Matrice (*combinaison_cpt[MAX_BASE])
140  (const Matrice &, int) ;
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  combinaison_cpt[i] = _cl_cpt_pas_prevu ;
148  }
149  // Les routines existantes
150  combinaison_cpt[R_CHEBP >> TRA_R] = _cl_cpt_r_chebp ;
151  combinaison_cpt[R_CHEBI >> TRA_R] = _cl_cpt_r_chebi ;
152  }
153 
154  Matrice res(combinaison_cpt[base_r](source, l)) ;
155  return res ;
156 }
157 
158  //--------------------------------------------------------------
159  // Version Tbl
160  //--------------------------------------------------------------
161 
162 
163 
164 Tbl _cl_cpt_pas_prevu(const Tbl& tb) {
165  cout << "combinaison_nul_pas_prevu " << endl ;
166  cout << "tb : " << tb << endl ;
167  abort() ;
168  return tb ;
169 }
170 
171 
172  //-------------------
173  //-- R_CHEBP -----
174  //-------------------
175 Tbl _cl_cpt_r_chebp(const Tbl& tb) {
176 
177  assert (tb.get_etat() != ETATNONDEF) ;
178  int n=tb.get_dim(0) ;
179 
180  Tbl barre(tb) ;
181  int dirac = 1 ;
182  for (int i=0 ; i<n-2 ; i++) {
183  barre.set(i) = ((1+dirac)*tb(i)-tb(i+2))/(i+1) ;
184  if (i==0) dirac = 0 ;
185  }
186 
187  Tbl res(barre) ;
188  for (int i=0 ; i<n-4 ; i++)
189  res.set(i) = barre(i)-barre(i+2) ;
190 
191  return res ;
192 }
193 
194 
195 
196  //-------------------
197  //-- R_CHEBI -----
198  //-------------------
199 Tbl _cl_cpt_r_chebi(const Tbl& tb) {
200 
201  assert (tb.get_etat() != ETATNONDEF) ;
202  int n=tb.get_dim(0) ;
203 
204  Tbl barre(tb) ;
205  for (int i=0 ; i<n-2 ; i++)
206  barre.set(i) = (tb(i)-tb(i+1))/(i+1) ;
207 
208  Tbl res(barre) ;
209  for (int i=0 ; i<n-4 ; i++)
210  res.set(i) = barre(i)-barre(i+2) ;
211 
212  return res ;
213 }
214 
215 
216  //----------------------------
217  //- Routine a appeler ---
218  //------------------------------
219 
220 Tbl combinaison_cpt (const Tbl &source, int base_r) {
221 
222  // Routines de derivation
223  static Tbl (*combinaison_cpt[MAX_BASE])(const Tbl&) ;
224  static int nap = 0 ;
225 
226  // Premier appel
227  if (nap==0) {
228  nap = 1 ;
229  for (int i=0 ; i<MAX_BASE ; i++) {
230  combinaison_cpt[i] = _cl_cpt_pas_prevu ;
231  }
232  // Les routines existantes
233  combinaison_cpt[R_CHEBP >> TRA_R] = _cl_cpt_r_chebp ;
234  combinaison_cpt[R_CHEBI >> TRA_R] = _cl_cpt_r_chebi ;
235  }
236 
237  Tbl res(combinaison_cpt[base_r](source)) ;
238  return res ;
239 }
240 
241 }
Lorene prototypes.
Definition: app_hor.h:64
#define TRA_R
Translation en R, used for a bitwise shift (in hex)
Definition: type_parite.h:158
#define R_CHEBI
base de Cheb. impaire (rare) seulement
Definition: type_parite.h:170
#define R_CHEBP
base de Cheb. paire (rare) seulement
Definition: type_parite.h:168
int get_dim(int i) const
Returns the dimension of the matrix.
Definition: matrice.C:260
#define MAX_BASE
Nombre max. de bases differentes.
Definition: type_parite.h:144