LORENE
helmholtz_plus_mat.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: helmholtz_plus_mat.C,v 1.7 2016/12/05 16:18:09 j_novak Exp $
27  * $Log: helmholtz_plus_mat.C,v $
28  * Revision 1.7 2016/12/05 16:18:09 j_novak
29  * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
30  *
31  * Revision 1.6 2014/10/13 08:53:28 j_novak
32  * Lorene classes and functions now belong to the namespace Lorene.
33  *
34  * Revision 1.5 2014/10/06 15:16:08 j_novak
35  * Modified #include directives to use c++ syntax.
36  *
37  * Revision 1.4 2007/05/06 10:48:12 p_grandclement
38  * Modification of a few operators for the vorton project
39  *
40  * Revision 1.3 2004/01/15 09:15:37 p_grandclement
41  * Modification and addition of the Helmholtz operators
42  *
43  * Revision 1.2 2003/12/11 15:57:26 p_grandclement
44  * include stdlib.h encore ...
45  *
46  * Revision 1.1 2003/12/11 14:48:49 p_grandclement
47  * Addition of ALL (and that is a lot !) the files needed for the general elliptic solver ... UNDER DEVELOPEMENT...
48  *
49  *
50  * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/PDE/helmholtz_plus_mat.C,v 1.7 2016/12/05 16:18:09 j_novak Exp $
51  *
52  */
53 #include <cstdlib>
54 
55 #include "matrice.h"
56 #include "type_parite.h"
57 #include "proto.h"
58 
59  //-----------------------------------
60  // Routine pour les cas non prevus --
61  //-----------------------------------
62 
63 namespace Lorene {
64 Matrice _helmholtz_plus_mat_pas_prevu(int, int, double, double, double) {
65  cout << "Helmholtz plus : base not implemented..." << endl ;
66  abort() ;
67  exit(-1) ;
68  Matrice res(1, 1) ;
69  return res;
70 }
71 
72 
73 
74  //-------------------------
75  //-- CAS R_CHEBP -----
76  //--------------------------
77 
78 
79 Matrice _helmholtz_plus_mat_r_chebp (int n, int lq, double alpha, double,
80  double masse) {
81  assert (masse > 0) ;
82 
83  Matrice dd(n, n) ;
84  dd.set_etat_qcq() ;
85  Matrice xd(n, n) ;
86  xd.set_etat_qcq() ;
87  Matrice xx(n, n) ;
88  xx.set_etat_qcq() ;
89  Matrice sx2(n, n) ;
90  sx2.set_etat_qcq() ;
91 
92  double* vect = new double[n] ;
93 
94  for (int i=0 ; i<n ; i++) {
95  for (int j=0 ; j<n ; j++)
96  vect[j] = 0 ;
97  vect[i] = 1 ;
98  d2sdx2_1d (n, &vect, R_CHEBP) ;
99  for (int j=0 ; j<n ; j++)
100  dd.set(j, i) = vect[j] ;
101  }
102 
103  for (int i=0 ; i<n ; i++) {
104  for (int j=0 ; j<n ; j++)
105  vect[j] = 0 ;
106  vect[i] = 1 ;
107  sxdsdx_1d (n, &vect, R_CHEBP) ;
108  for (int j=0 ; j<n ; j++)
109  xd.set(j, i) = vect[j] ;
110  }
111 
112  for (int i=0 ; i<n ; i++) {
113  for (int j=0 ; j<n ; j++)
114  vect[j] = 0 ;
115  vect[i] = 1 ;
116  sx2_1d (n, &vect, R_CHEBP) ;
117  for (int j=0 ; j<n ; j++)
118  sx2.set(j, i) = vect[j] ;
119  }
120 
121  for (int i=0 ; i<n ; i++) {
122  for (int j=0 ; j<n ; j++)
123  xx.set(i,j) = 0 ;
124  xx.set(i, i) = 1 ;
125  }
126 
127  delete [] vect ;
128 
129  Matrice res(n, n) ;
130  res = dd+2*xd-lq*(lq+1)*sx2+masse*masse*alpha*alpha*xx ;
131 
132  return res ;
133 }
134 
135 
136  //-------------------------
137  //-- CAS R_CHEB -----
138  //------------------------
139 
140 Matrice _helmholtz_plus_mat_r_cheb (int n, int lq, double alpha, double beta,
141  double masse) {
142 
143 
144 
145  assert (masse > 0) ;
146 
147  double echelle = beta / alpha ;
148 
149  Matrice dd(n, n) ;
150  dd.set_etat_qcq() ;
151  Matrice xd(n, n) ;
152  xd.set_etat_qcq() ;
153  Matrice xx(n, n) ;
154  xx.set_etat_qcq() ;
155 
156  double* vect = new double[n] ;
157 
158  for (int i=0 ; i<n ; i++) {
159  for (int j=0 ; j<n ; j++)
160  vect[j] = 0 ;
161  vect[i] = 1 ;
162  d2sdx2_1d (n, &vect, R_CHEB) ; // appel dans le cas fin
163  vect[i] += masse*masse*alpha*alpha ;
164  for (int j=0 ; j<n ; j++)
165  dd.set(j, i) = vect[j]*echelle*echelle ;
166  }
167 
168  for (int i=0 ; i<n ; i++) {
169  for (int j=0 ; j<n ; j++)
170  vect[j] = 0 ;
171  vect[i] = 1 ;
172  d2sdx2_1d (n, &vect, R_CHEB) ; // appel dans le cas fin
173  vect[i] += masse*masse*alpha*alpha ;
174  multx_1d (n, &vect, R_CHEB) ;
175  for (int j=0 ; j<n ; j++)
176  dd.set(j, i) += 2*echelle*vect[j] ;
177  }
178 
179  for (int i=0 ; i<n ; i++) {
180  for (int j=0 ; j<n ; j++)
181  vect[j] = 0 ;
182  vect[i] = 1 ;
183  d2sdx2_1d (n, &vect, R_CHEB) ; // appel dans le cas fin
184  vect[i] += masse*masse*alpha*alpha ;
185  multx_1d (n, &vect, R_CHEB) ;
186  multx_1d (n, &vect, R_CHEB) ;
187  for (int j=0 ; j<n ; j++)
188  dd.set(j, i) += vect[j] ;
189  }
190 
191  for (int i=0 ; i<n ; i++) {
192  for (int j=0 ; j<n ; j++)
193  vect[j] = 0 ;
194  vect[i] = 1 ;
195  sxdsdx_1d (n, &vect, R_CHEB) ;
196  for (int j=0 ; j<n ; j++)
197  xd.set(j, i) = vect[j]*echelle ;
198  }
199 
200  for (int i=0 ; i<n ; i++) {
201  for (int j=0 ; j<n ; j++)
202  vect[j] = 0 ;
203  vect[i] = 1 ;
204  sxdsdx_1d (n, &vect, R_CHEB) ;
205  multx_1d (n, &vect, R_CHEB) ;
206  for (int j=0 ; j<n ; j++)
207  xd.set(j, i) += vect[j] ;
208  }
209 
210  for (int i=0 ; i<n ; i++) {
211  for (int j=0 ; j<n ; j++)
212  vect[j] = 0 ;
213  vect[i] = 1 ;
214  sx2_1d (n, &vect, R_CHEB) ;
215  for (int j=0 ; j<n ; j++)
216  xx.set(j, i) = vect[j] ;
217  }
218 
219  delete [] vect ;
220 
221  Matrice res(n, n) ;
222  res = dd+2*xd - lq*(lq+1)*xx;
223 
224  return res ;
225 }
226 
227 
228  //--------------------------
229  //- La routine a appeler ---
230  //----------------------------
231 
232 Matrice helmholtz_plus_mat(int n, int lq, double alpha, double beta, double masse,
233  int base_r)
234 {
235 
236  // Routines de derivation
237  static Matrice (*helmholtz_plus_mat[MAX_BASE])(int, int, double, double, double);
238  static int nap = 0 ;
239 
240  // Premier appel
241  if (nap==0) {
242  nap = 1 ;
243  for (int i=0 ; i<MAX_BASE ; i++) {
244  helmholtz_plus_mat[i] = _helmholtz_plus_mat_pas_prevu ;
245  }
246  // Les routines existantes
247  helmholtz_plus_mat[R_CHEB >> TRA_R] = _helmholtz_plus_mat_r_cheb ;
248  helmholtz_plus_mat[R_CHEBP >> TRA_R] = _helmholtz_plus_mat_r_chebp ;
249  }
250 
251  Matrice res(helmholtz_plus_mat[base_r](n, lq, alpha, beta, masse)) ;
252  return res ;
253 }
254 
255 }
Lorene prototypes.
Definition: app_hor.h:67
#define TRA_R
Translation en R, used for a bitwise shift (in hex)
Definition: type_parite.h:158
#define R_CHEBP
base de Cheb. paire (rare) seulement
Definition: type_parite.h:168
#define MAX_BASE
Nombre max. de bases differentes.
Definition: type_parite.h:144
#define R_CHEB
base de Chebychev ordinaire (fin)
Definition: type_parite.h:166