LORENE
cmp_manip.C
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() ;
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 }
Lorene::Mg3d::get_np
int get_np(int l) const
Returns the number of points in the azimuthal direction ( ) in domain no. l.
Definition: grilles.h:462
Lorene::Valeur::set_etat_cf_qcq
void set_etat_cf_qcq()
Sets the logical state to ETATQCQ (ordinary state) for values in the configuration space (Mtbl_cf c_c...
Definition: valeur.C:712
Lorene::Valeur::set_etat_c_qcq
void set_etat_c_qcq()
Sets the logical state to ETATQCQ (ordinary state) for values in the configuration space (Mtbl c ).
Definition: valeur.C:701
Lorene::Cmp::del_deriv
void del_deriv()
Logical destructor of the derivatives.
Definition: cmp.C:265
Lorene::Valeur::c_cf
Mtbl_cf * c_cf
Coefficients of the spectral expansion of the function.
Definition: valeur.h:302
Lorene::Mg3d::get_nt
int get_nt(int l) const
Returns the number of points in the co-latitude direction ( ) in domain no. l.
Definition: grilles.h:457
Lorene
Lorene prototypes.
Definition: app_hor.h:64
Lorene::Cmp::filtre_phi
void filtre_phi(int n, int zone)
Sets the n lasts coefficients in to 0 in the domain zone .
Definition: cmp_manip.C:101
Lorene::Cmp::va
Valeur va
The numerical value of the Cmp
Definition: cmp.h:464
Lorene::Map::get_mg
const Mg3d * get_mg() const
Gives the Mg3d on which the mapping is defined.
Definition: map.h:765
Lorene::Cmp::etat
int etat
Logical state (ETATNONDEF , ETATQCQ or ETATZERO ).
Definition: cmp.h:454
Lorene::Mg3d::get_type_r
int get_type_r(int l) const
Returns the type of sampling in the radial direction in domain no.
Definition: grilles.h:474
Lorene::pow
Cmp pow(const Cmp &, int)
Power .
Definition: cmp_math.C:348
Lorene::Mtbl_cf::set
Tbl & set(int l)
Read/write of the Tbl containing the coefficients in a given domain.
Definition: mtbl_cf.h:294
Lorene::Valeur::coef
void coef() const
Computes the coeffcients of *this.
Definition: valeur_coef.C:148
Lorene::Cmp::mult_r_zec
void mult_r_zec()
Multiplication by r in the external compactified domain (ZEC)
Definition: cmp_r_manip.C:103
Lorene::Cmp::annule_hard
void annule_hard()
Sets the Cmp to zero in a hard way.
Definition: cmp.C:338
Lorene::Cmp
Component of a tensorial field *** DEPRECATED : use class Scalar instead ***.
Definition: cmp.h:446
Lorene::Cmp::filtre
void filtre(int n)
Sets the n lasts coefficients in r to 0 in the external domain.
Definition: cmp_manip.C:74
Lorene::Cmp::dzpuis
int dzpuis
Power of r by which the quantity represented by this must be divided in the external compactified z...
Definition: cmp.h:461
Lorene::Mg3d::get_nzone
int get_nzone() const
Returns the number of domains.
Definition: grilles.h:448
Lorene::Cmp::set_val_inf
void set_val_inf(double val)
Sets the value of the Cmp to val at infinity.
Definition: cmp_manip.C:126
Lorene::Mg3d::get_nr
int get_nr(int l) const
Returns the number of points in the radial direction ( ) in domain no. l.
Definition: grilles.h:452
Lorene::Map_af
Affine radial mapping.
Definition: map.h:2027
Lorene::Cmp::fixe_decroissance
void fixe_decroissance(int puis)
Substracts all the components behaving like in the external domain, with n strictly lower than puis ...
Definition: cmp_manip.C:186
Lorene::cos
Cmp cos(const Cmp &)
Cosine.
Definition: cmp_math.C:94
Lorene::Cmp::set_val_hor
void set_val_hor(double val, int zone)
Sets the value of the Cmp to val on the inner boudary of the shell number zone .This is usefull for d...
Definition: cmp_manip.C:159
Lorene::Base_val::get_base_r
int get_base_r(int l) const
Returns the expansion basis for r ( ) functions in the domain of index l (e.g.
Definition: base_val.h:400
Lorene::Cmp::mp
const Map * mp
Reference mapping.
Definition: cmp.h:451
Lorene::Valeur::coef_i
void coef_i() const
Computes the physical value of *this.
Definition: valeur_coef_i.C:140
Lorene::Valeur::base
Base_val base
Bases on which the spectral expansion is performed.
Definition: valeur.h:305
Lorene::Valeur::set
Tbl & set(int l)
Read/write of the value in a given domain (configuration space).
Definition: valeur.h:363
Lorene::Map_af::get_alpha
const double * get_alpha() const
Returns the pointer on the array alpha.
Definition: map_af.C:477
R_CHEBU
#define R_CHEBU
base de Chebychev ordinaire (fin), dev. en 1/r
Definition: type_parite.h:180