LORENE
val_solp.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: val_solp.C,v 1.7 2016/12/05 16:18:10 j_novak Exp $
27  * $Log: val_solp.C,v $
28  * Revision 1.7 2016/12/05 16:18:10 j_novak
29  * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
30  *
31  * Revision 1.6 2014/10/13 08:53:31 j_novak
32  * Lorene classes and functions now belong to the namespace Lorene.
33  *
34  * Revision 1.5 2014/10/06 15:16:11 j_novak
35  * Modified #include directives to use c++ syntax.
36  *
37  * Revision 1.4 2008/02/18 13:53:45 j_novak
38  * Removal of special indentation instructions.
39  *
40  * Revision 1.3 2004/08/24 09:14:44 p_grandclement
41  * Addition of some new operators, like Poisson in 2d... It now requieres the
42  * GSL library to work.
43  *
44  * Also, the way a variable change is stored by a Param_elliptic is changed and
45  * no longer uses Change_var but rather 2 Scalars. The codes using that feature
46  * will requiere some modification. (It should concern only the ones about monopoles)
47  *
48  * Revision 1.2 2003/12/11 15:37:09 p_grandclement
49  * sqrt(2) ----> sqrt(double(2))
50  *
51  * Revision 1.1 2003/12/11 14:48:49 p_grandclement
52  * Addition of ALL (and that is a lot !) the files needed for the general elliptic solver ... UNDER DEVELOPEMENT...
53  *
54  *
55  * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/PDE/val_solp.C,v 1.7 2016/12/05 16:18:10 j_novak Exp $
56  *
57  */
58 
59 //fichiers includes
60 #include <cstdio>
61 #include <cstdlib>
62 #include <cmath>
63 
64 #include "proto.h"
65 #include "matrice.h"
66 #include "type_parite.h"
67 
68 
69  //------------------------------------
70  // Routine pour les cas non prevus --
71  //------------------------------------
72 namespace Lorene {
73 Tbl _val_solp_pas_prevu (const Tbl&, double) {
74 
75  cout << " Base_r unknown in val_solp."<< endl ;
76  abort() ;
77  exit(-1) ;
78  Tbl res(1) ;
79  return res;
80 }
81 
82 
83  //-------------------
84  //-- R_CHEB ------
85  //-------------------
86 
87 Tbl _val_solp_r_cheb (const Tbl& sp, double alpha) {
88 
89  int nr = sp.get_dim(0) ;
90  Tbl res(4) ;
91  res.annule_hard() ;
92 
93  // Solution en + 1
94  for (int i=0 ; i<nr ; i++)
95  res.set(0) += sp(i) ;
96 
97  // Solution en -1 :
98  for (int i=0 ; i<nr ; i++)
99  if (i%2 == 0)
100  res.set(1) += sp(i) ;
101  else
102  res.set(1) -= sp(i) ;
103 
104  // Derivee en +1 :
105  for (int i=0 ; i<nr ; i++)
106  res.set(2) += sp(i)*i*i/alpha ;
107 
108  // Derivee en -1 :
109  for (int i=0 ; i<nr ; i++)
110  if (i%2 == 0)
111  res.set(3) -= sp(i)*i*i/alpha ;
112  else
113  res.set(3) += sp(i)*i*i/alpha ;
114 
115  res /= sqrt(double(2)) ;
116  return res ;
117 }
118 
119  //-------------------
120  //-- R_CHEBP ------
121  //-------------------
122 
123 Tbl _val_solp_r_chebp (const Tbl& sp, double alpha) {
124 
125  int nr = sp.get_dim(0) ;
126  Tbl res(4) ;
127  res.annule_hard() ;
128 
129  // Solution en +1 :
130  for (int i=0 ; i<nr ; i++)
131  res.set(0) += sp(i) ;
132 
133  // Solution en 0 (a priori pas trop utilise)
134  for (int i=0 ; i<nr ; i++)
135  if (i%2==0)
136  res.set(1) += sp(i) ;
137  else
138  res.set(1) -= sp(i) ;
139 
140  // Derivee en +1 :
141  for (int i=0 ; i<nr ; i++)
142  res.set(2) += sp(i)*(2*i)*(2*i)/alpha ;
143 
144  // Derivee en 0
145  res.set(3) = 0 ;
146 
147  res /= sqrt(double(2)) ;
148  return res ;
149 }
150 
151 
152  //-------------------
153  //-- R_CHEBI -----
154  //-------------------
155 
156 Tbl _val_solp_r_chebi (const Tbl& sp, double alpha) {
157 
158  int nr = sp.get_dim(0) ;
159  Tbl res(4) ;
160  res.annule_hard() ;
161 
162  // Solution en +1 :
163  for (int i=0 ; i<nr ; i++)
164  res.set(0) += sp(i) ;
165 
166  // Solution en 0 :
167  res.set(1) = 0 ;
168 
169  // Derivee en +1 :
170  for (int i=0 ; i<nr ; i++)
171  res.set(2) += sp(i)*(2*i+1)*(2*i+1)/alpha ;
172 
173  // Derivee en 0 :
174  for (int i=0 ; i<nr ; i++)
175  if (i%2==0)
176  res.set(3) += (2*i+1)*sp(i) ;
177  else
178  res.set(3) -= (2*i+1)*sp(i) ;
179 
180  res /= sqrt(double(2)) ;
181  return res ;
182 }
183 
184 
185 
186  //-------------------
187  //-- R_CHEBU -----
188  //-------------------
189 
190 Tbl _val_solp_r_chebu (const Tbl& sp, double alpha) {
191 
192  int nr = sp.get_dim(0) ;
193  Tbl res(4) ;
194  res.annule_hard() ;
195 
196  // Solution en + 1
197  for (int i=0 ; i<nr ; i++)
198  res.set(0) += sp(i) ;
199 
200  // Solution en -1 :
201  for (int i=0 ; i<nr ; i++)
202  if (i%2==0)
203  res.set(1) += sp(i) ;
204  else
205  res.set(1) -= sp(i) ;
206 
207  // Derivee en +1 c'est zero ca !
208 
209  // Derivee en -1 :
210  for (int i=0 ; i<nr ; i++)
211  if (i%2==0)
212  res.set(3) += 4.*alpha*i*i*sp(i) ;
213  else
214  res.set(3) -= 4.*alpha*i*i*sp(i) ;
215 
216  res /= sqrt(double(2)) ;
217  return res ;
218 }
219 
220 
221 
222 
223  //-------------------
224  //-- Fonction ----
225  //-------------------
226 
227 
228 Tbl val_solp (const Tbl& sp, double alpha, int base_r) {
229 
230  // Routines de derivation
231  static Tbl (*val_solp[MAX_BASE])(const Tbl&, double) ;
232  static int nap = 0 ;
233 
234  // Premier appel
235  if (nap==0) {
236  nap = 1 ;
237  for (int i=0 ; i<MAX_BASE ; i++) {
238  val_solp[i] = _val_solp_pas_prevu ;
239  }
240  // Les routines existantes
241  val_solp[R_CHEB >> TRA_R] = _val_solp_r_cheb ;
242  val_solp[R_CHEBU >> TRA_R] = _val_solp_r_chebu ;
243  val_solp[R_CHEBP >> TRA_R] = _val_solp_r_chebp ;
244  val_solp[R_CHEBI >> TRA_R] = _val_solp_r_chebi ;
245  }
246 
247  Tbl res(val_solp[base_r](sp, alpha)) ;
248  return res ;
249 }
250 }
Cmp sqrt(const Cmp &)
Square root.
Definition: cmp_math.C:223
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_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
Gives the i-th dimension (ie dim.dim[i])
Definition: tbl.h:423
#define R_CHEBU
base de Chebychev ordinaire (fin), dev. en 1/r
Definition: type_parite.h:180
#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