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