LORENE
solp_helmholtz_minus.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 char solp_helmholtz_minus_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/PDE/solp_helmholtz_minus.C,v 1.9 2014/10/13 08:53:31 j_novak Exp $" ;
24 
25 /*
26  * $Id: solp_helmholtz_minus.C,v 1.9 2014/10/13 08:53:31 j_novak Exp $
27  * $Log: solp_helmholtz_minus.C,v $
28  * Revision 1.9 2014/10/13 08:53:31 j_novak
29  * Lorene classes and functions now belong to the namespace Lorene.
30  *
31  * Revision 1.8 2014/10/06 15:16:10 j_novak
32  * Modified #include directives to use c++ syntax.
33  *
34  * Revision 1.7 2008/07/10 11:20:33 p_grandclement
35  * mistake fixed in solh_helmholtz_minus
36  *
37  * Revision 1.6 2008/07/09 06:51:58 p_grandclement
38  * some corrections to helmholtz minus in the nucleus
39  *
40  * Revision 1.5 2008/07/08 11:45:28 p_grandclement
41  * Add helmholtz_minus in the nucleus
42  *
43  * Revision 1.4 2008/02/18 13:53:45 j_novak
44  * Removal of special indentation instructions.
45  *
46  * Revision 1.3 2004/08/24 09:14:44 p_grandclement
47  * Addition of some new operators, like Poisson in 2d... It now requieres the
48  * GSL library to work.
49  *
50  * Also, the way a variable change is stored by a Param_elliptic is changed and
51  * no longer uses Change_var but rather 2 Scalars. The codes using that feature
52  * will requiere some modification. (It should concern only the ones about monopoles)
53  *
54  * Revision 1.2 2004/01/15 09:15:37 p_grandclement
55  * Modification and addition of the Helmholtz operators
56  *
57  * Revision 1.1 2003/12/11 14:48:49 p_grandclement
58  * Addition of ALL (and that is a lot !) the files needed for the general elliptic solver ... UNDER DEVELOPEMENT...
59  *
60  *
61  * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/PDE/solp_helmholtz_minus.C,v 1.9 2014/10/13 08:53:31 j_novak Exp $
62  *
63  */
64 
65 //fichiers includes
66 #include <cstdio>
67 #include <cstdlib>
68 #include <cmath>
69 
70 #include "matrice.h"
71 #include "type_parite.h"
72 #include "proto.h"
73 
74  //------------------------------------
75  // Routine pour les cas non prevus --
76  //------------------------------------
77 namespace Lorene {
78 Tbl _solp_helmholtz_minus_pas_prevu (const Matrice &, const Matrice &,
79  const Tbl &, double, double, int) {
80  cout << " Solution homogene pas prevue ..... : "<< endl ;
81  abort() ;
82  exit(-1) ;
83  Tbl res(1) ;
84  return res;
85 }
86 
87 
88 
89  //-------------------
90  //-- R_CHEBU ------
91  //-------------------
92 
93 
94 Tbl _solp_helmholtz_minus_r_chebu (const Matrice &lap, const Matrice &nondege,
95  const Tbl &source, double, double, int) {
96 
97  int n = lap.get_dim(0)+2 ;
98  int dege = n-nondege.get_dim(0) ;
99  assert (dege==3) ;
100 
101  Tbl source_cl (cl_helmholtz_minus(source, R_CHEBU)) ;
102 
103  Tbl so(n-dege) ;
104  so.set_etat_qcq() ;
105  for (int i=0 ; i<n-dege ; i++)
106  so.set(i) = source_cl(i);
107 
108  Tbl sol (nondege.inverse(so)) ;
109 
110  Tbl res(n) ;
111  res.annule_hard() ;
112  for (int i=1 ; i<n-2 ; i++) {
113  res.set(i) += sol(i-1)*(2*i+3) ;
114  res.set(i+1) += -sol(i-1)*(4*i+4) ;
115  res.set(i+2) += sol(i-1)*(2*i+1) ;
116  }
117 
118  return res ;
119 }
120 
121 
122  //-------------------
123  //-- R_CHEB -----
124  //-------------------
125 Tbl _solp_helmholtz_minus_r_cheb (const Matrice &lap, const Matrice &nondege,
126  const Tbl &source, double alpha, double beta, int) {
127 
128  int n = lap.get_dim(0) ;
129  int dege = n-nondege.get_dim(0) ;
130  assert (dege ==2) ;
131 
132  Tbl source_aux(source*alpha*alpha) ;
133  Tbl xso(source_aux) ;
134  Tbl xxso(source_aux) ;
135  multx_1d(n, &xso.t, R_CHEB) ;
136  multx_1d(n, &xxso.t, R_CHEB) ;
137  multx_1d(n, &xxso.t, R_CHEB) ;
138  source_aux = beta*beta/alpha/alpha*source_aux+2*beta/alpha*xso+xxso ;
139 
140  source_aux = cl_helmholtz_minus (source_aux, R_CHEB) ;
141 
142  Tbl so(n-dege) ;
143  so.set_etat_qcq() ;
144  for (int i=0 ; i<n-dege ; i++)
145  so.set(i) = source_aux(i) ;
146 
147  Tbl auxi(nondege.inverse(so)) ;
148 
149  Tbl res(n) ;
150  res.set_etat_qcq() ;
151  for (int i=dege ; i<n ; i++)
152  res.set(i) = auxi(i-dege) ;
153 
154  for (int i=0 ; i<dege ; i++)
155  res.set(i) = 0 ;
156  return res ;
157 }
158 
159 
160  //-------------------
161  //-- R_CHEBP -----
162  //-------------------
163 Tbl _solp_helmholtz_minus_r_chebp (const Matrice &, const Matrice &nondege,
164  const Tbl &source, double alpha, double, int lq) {
165 
166 
167  int dege = (lq==0) ? 1 : 2 ;
168  int n = nondege.get_dim(0) + dege ;
169  Tbl source_cl (cl_helmholtz_minus(source*alpha*alpha, R_CHEBP)) ;
170 
171  Tbl so(n-dege) ;
172  so.set_etat_qcq() ;
173  for (int i=0 ; i<n-dege ; i++)
174  so.set(i) = source_cl(i);
175 
176  Tbl sol (nondege.inverse(so)) ;
177 
178  Tbl res(n) ;
179  res.annule_hard() ;
180  if (dege==2) {
181  for (int i=1 ; i<n-1 ; i++) {
182  res.set(i) += sol(i-1) ;
183  res.set(i+1) += sol(i-1) ;
184  }
185 }
186  else {
187  for (int i=1 ; i<n ; i++)
188  res.set(i) = sol(i-1) ;
189  }
190 return res ;
191 }
192 
193  //-------------------
194  //-- R_CHEBI -----
195  //-------------------
196 Tbl _solp_helmholtz_minus_r_chebi (const Matrice &, const Matrice &nondege,
197  const Tbl &source, double alpha, double, int lq) {
198 
199  int dege = (lq==1) ? 1 : 2 ;
200  int n = nondege.get_dim(0) + dege ;
201  Tbl source_cl (cl_helmholtz_minus(source*alpha*alpha, R_CHEBI)) ;
202 
203  Tbl so(n-dege) ;
204  so.set_etat_qcq() ;
205  for (int i=0 ; i<n-dege ; i++)
206  so.set(i) = source_cl(i);
207 
208  Tbl sol (nondege.inverse(so)) ;
209 
210  Tbl res(n) ;
211  res.annule_hard() ;
212  if (dege==2) {
213  for (int i=1 ; i<n-1 ; i++) {
214  res.set(i) += (2*i+3)*sol(i-1) ;
215  res.set(i+1) += (2*i+1)*sol(i-1) ;
216  }
217 }
218  else {
219  for (int i=1 ; i<n ; i++)
220  res.set(i) = sol(i-1) ;
221  }
222 
223 return res ;
224 
225 }
226 
227  //-------------------
228  //-- Fonction ----
229  //-------------------
230 
231 
232 Tbl solp_helmholtz_minus (const Matrice &lap, const Matrice &nondege,
233  const Tbl &source, double alpha, double beta, int lq,
234  int base_r) {
235 
236  // Routines de derivation
237  static Tbl (*solp_helmholtz_minus[MAX_BASE]) (const Matrice&, const Matrice&,
238  const Tbl&, double, double, int) ;
239  static int nap = 0 ;
240 
241  // Premier appel
242  if (nap==0) {
243  nap = 1 ;
244  for (int i=0 ; i<MAX_BASE ; i++) {
245  solp_helmholtz_minus[i] = _solp_helmholtz_minus_pas_prevu ;
246  }
247  // Les routines existantes
248  solp_helmholtz_minus[R_CHEB >> TRA_R] = _solp_helmholtz_minus_r_cheb ;
249  solp_helmholtz_minus[R_CHEBU >> TRA_R] = _solp_helmholtz_minus_r_chebu ;
250  solp_helmholtz_minus[R_CHEBP >> TRA_R] = _solp_helmholtz_minus_r_chebp ;
251  solp_helmholtz_minus[R_CHEBI >> TRA_R] = _solp_helmholtz_minus_r_chebi ;
252  }
253 
254  Tbl res(solp_helmholtz_minus[base_r] (lap, nondege, source, alpha, beta, lq)) ;
255  return res ;
256 }
257 }
int get_dim(int i) const
Gives the i-th dimension (ie dim.dim[i])
Definition: tbl.h:403
#define MAX_BASE
Nombre max. de bases differentes.
Definition: type_parite.h:144
#define R_CHEBU
base de Chebychev ordinaire (fin), dev. en 1/r
Definition: type_parite.h:180
#define R_CHEBI
base de Cheb. impaire (rare) seulement
Definition: type_parite.h:170
#define TRA_R
Translation en R, used for a bitwise shift (in hex)
Definition: type_parite.h:158
#define R_CHEB
base de Chebychev ordinaire (fin)
Definition: type_parite.h:166
#define R_CHEBP
base de Cheb. paire (rare) seulement
Definition: type_parite.h:168
Lorene prototypes.
Definition: app_hor.h:64