Debian Codegraph @

C++/Source/Cmp/cmp_manip.C

raw
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 cmp_manip_C[] = "$Header: /cvsroot/Lorene/C++/Source/Cmp/cmp_manip.C,v 1.6 2014/10/13 08:52:47 j_novak Exp $" ;
24
25 /*
26 * $Id: cmp_manip.C,v 1.6 2014/10/13 08:52:47 j_novak Exp $
27 * $Log: cmp_manip.C,v $
28 * Revision 1.6 2014/10/13 08:52:47 j_novak
29 * Lorene classes and functions now belong to the namespace Lorene.
30 *
31 * Revision 1.5 2014/10/06 15:13:03 j_novak
32 * Modified #include directives to use c++ syntax.
33 *
34 * Revision 1.4 2008/08/19 06:41:59 j_novak
35 * Minor modifications to avoid warnings with gcc 4.3. Most of them concern
36 * cast-type operations, and constant strings that must be defined as const char*
37 *
38 * Revision 1.3 2003/10/23 09:41:27 p_grandclement
39 * small modif of set_val_hor (one can work at the origin now)
40 *
41 * Revision 1.2 2003/10/03 15:58:44 j_novak
42 * Cleaning of some headers
43 *
44 * Revision 1.1.1.1 2001/11/20 15:19:27 e_gourgoulhon
45 * LORENE
46 *
47 * Revision 2.2 2001/05/25 09:29:58 phil
48 * ajout de filtre_phi
49 *
50 * Revision 2.1 2001/02/12 18:08:51 phil
51 * ajout de fixe_decroissance
52 *
53 * Revision 2.0 2000/10/19 09:23:37 phil
54 * *** empty log message ***
55 *
56 *
57 * $Header: /cvsroot/Lorene/C++/Source/Cmp/cmp_manip.C,v 1.6 2014/10/13 08:52:47 j_novak Exp $
58 *
59 */
60
61 //standard
62 #include <cstdlib>
63 #include <cmath>
64
65 // Lorene
66 #include "cmp.h"
67 #include "proto.h"
68
69 /*
70 * Annule les n derniers coefficients en r dans la derniere zone
71 */
72
73 namespace Lorene {
74 void Cmp::filtre (int n) {
75
76 assert (etat != ETATNONDEF) ;
77 if (etat == ETATZERO)
78 return ;
79
80 int nz = mp->get_mg()->get_nzone() ;
81 int np = mp->get_mg()->get_np(nz-1) ;
82 int nt = mp->get_mg()->get_nt(nz-1) ;
83 int nr = mp->get_mg()->get_nr(nz-1) ;
84
85 del_deriv() ;
86
87 va.coef() ;
88 va.set_etat_cf_qcq() ;
89
90 for (int k=0 ; k<np+1 ; k++)
91 if (k!=1)
92 for (int j=0 ; j<nt ; j++)
93 for (int i=nr-1 ; i>nr-1-n ; i--)
94 va.c_cf->set(nz-1, k, j, i) = 0 ;
95 }
96
97 /*
98 * Annule les n derniers coefficients en phi dans zone nz
99 */
100
101 void Cmp::filtre_phi (int n, int nz) {
102 assert (etat != ETATNONDEF) ;
103 if (etat == ETATZERO)
104 return ;
105
106 del_deriv() ;
107
108 va.coef() ;
109 va.set_etat_cf_qcq() ;
110 int np = mp->get_mg()->get_np(nz) ;
111 int nt = mp->get_mg()->get_nt(nz) ;
112 int nr = mp->get_mg()->get_nr(nz) ;
113
114 for (int k=np+1-n ; k<np+1 ; k++)
115 for (int j=0 ; j<nt ; j++)
116 for (int i=0 ; i<nr ; i++)
117 va.c_cf->set(nz, k, j, i) = 0 ;
118 }
119
120 /*
121 * Fixe la valeur a l'infini (si la derniere zone est compactifiee)
122 * d'un Cmp a val
123 * Utile quand on a affaire a des nan0x10000000
124 */
125
126 void Cmp::set_val_inf (double val) {
127
128 assert (etat != ETATNONDEF) ;
129 if (etat == ETATZERO) {
130 if (val == 0)
131 return ;
132 else
133 annule_hard() ;
134 }
135 del_deriv() ;
136
137 int nz = mp->get_mg()->get_nzone() ;
138
139 // On verifie la compactification
140 assert (mp->get_mg()->get_type_r(nz-1) == UNSURR) ;
141
142 int nr = mp->get_mg()->get_nr(nz-1) ;
143 int nt = mp->get_mg()->get_nt(nz-1) ;
144 int np = mp->get_mg()->get_np(nz-1) ;
145
146 va.coef_i() ;
147 va.set_etat_c_qcq() ;
148
149 for (int k=0 ; k<np ; k++)
150 for (int j=0 ; j<nt ; j++)
151 va.set(nz-1, k, j, nr-1) = val ;
152 }
153
154 /*
155 * Fixe la valeur d'un Cmp a val, sur la frontiere interne de la coquille zone.
156 * Utile quand on a affaire a des nan0x10000000
157 */
158
159 void Cmp::set_val_hor (double val, int zone) {
160
161 assert (etat != ETATNONDEF) ;
162 if (etat == ETATZERO) {
163 if (val == 0)
164 return ;
165 else
166 annule_hard() ;
167 }
168 assert (zone < mp->get_mg()->get_nzone()) ;
169 del_deriv() ;
170
171 int nt = mp->get_mg()->get_nt(zone) ;
172 int np = mp->get_mg()->get_np(zone) ;
173
174 va.coef_i() ;
175 va.set_etat_c_qcq() ;
176
177 for (int k=0 ; k<np ; k++)
178 for (int j=0 ; j<nt ; j++)
179 va.set(zone, k, j, 0) = val ;
180 }
181
182 /*
183 * Permet de fixer la decroissance du cmp a l infini en viurant les
184 * termes en 1/r^n
185 */
186 void Cmp::fixe_decroissance (int puis) {
187
188 if (puis<dzpuis)
189 return ;
190 else {
191
192 int nbre = puis-dzpuis ;
193
194 // le confort avant tout ! (c'est bien le confort ...)
195 int nz = mp->get_mg()->get_nzone() ;
196 int np = mp->get_mg()->get_np(nz-1) ;
197 int nt = mp->get_mg()->get_nt(nz-1) ;
198 int nr = mp->get_mg()->get_nr(nz-1) ;
199
200 const Map_af* map = dynamic_cast<const Map_af*>(mp) ;
201 if (map == 0x0) {
202 cout << "Le mapping doit etre affine" << endl ;
203 abort() ;
204 }
205
206 double alpha = map->get_alpha()[nz-1] ;
207
208 Cmp courant (*this) ;
209
210 va.coef() ;
211 va.set_etat_cf_qcq() ;
212
213 for (int conte=0 ; conte<nbre ; conte++) {
214
215 int base_r = courant.va.base.get_base_r(nz-1) ;
216
217 courant.va.coef() ;
218
219 // On calcul les coefficients de 1/r^conte
220 double* coloc = new double [nr] ;
221 int * deg = new int[3] ;
222 deg[0] = 1 ;
223 deg[1] = 1 ;
224 deg[2] = nr ;
225
226 for (int i=0 ; i<nr ; i++)
227 coloc[i] =pow(alpha, double(conte))*
228 pow(-1-cos(M_PI*i/(nr-1)), double(conte)) ;
229
230 cfrcheb(deg, deg, coloc, deg, coloc) ;
231
232 for (int k=0 ; k<np+1 ; k++)
233 if (k != 1)
234 for (int j=0 ; j<nt ; j++) {
235
236 // On doit determiner le coefficient du truc courant :
237 double* coef = new double [nr] ;
238 double* auxi = new double[1] ;
239 for (int i=0 ; i<nr ; i++)
240 coef[i] = (*courant.va.c_cf)(nz-1, k, j, i) ;
241 switch (base_r) {
242 case R_CHEBU :
243 som_r_chebu (coef, nr, 1, 1, 1, auxi) ;
244 break ;
245 default :
246 som_r_pas_prevu (coef, nr, 1, 1, 1, auxi) ;
247 break ;
248 }
249
250 // On modifie le cmp courant :
251 courant.va.coef() ;
252 courant.va.set_etat_cf_qcq() ;
253 courant.va.c_cf->set(nz-1, k, j, 0) -= *auxi ;
254
255 for (int i=0 ; i<nr ; i++)
256 this->va.c_cf->set(nz-1, k, j, i) -= *auxi * coloc[i] ;
257
258
259 delete [] coef ;
260 delete [] auxi ;
261 }
262 delete [] coloc ;
263 delete [] deg ;
264
265 courant.mult_r_zec() ;
266 }
267 }
268 }
269 }