LORENE
cmp_raccord_externe.C
1 /*
2  * Copyright (c) 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: cmp_raccord_externe.C,v 1.5 2016/12/05 16:17:49 j_novak Exp $
27  * $Log: cmp_raccord_externe.C,v $
28  * Revision 1.5 2016/12/05 16:17:49 j_novak
29  * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
30  *
31  * Revision 1.4 2014/10/13 08:52:48 j_novak
32  * Lorene classes and functions now belong to the namespace Lorene.
33  *
34  * Revision 1.3 2014/10/06 15:13:04 j_novak
35  * Modified #include directives to use c++ syntax.
36  *
37  * Revision 1.2 2003/10/03 15:58:45 j_novak
38  * Cleaning of some headers
39  *
40  * Revision 1.1.1.1 2001/11/20 15:19:27 e_gourgoulhon
41  * LORENE
42  *
43  * Revision 2.2 2001/10/10 13:53:27 eric
44  * Modif Joachim: sqrt(2) --> sqrt(double(2))
45  *
46  * Revision 2.1 2001/04/02 12:16:39 phil
47  * *** empty log message ***
48  *
49  * Revision 2.0 2001/03/30 13:37:32 phil
50  * *** empty log message ***
51  *
52  *
53  * $Header: /cvsroot/Lorene/C++/Source/Cmp/cmp_raccord_externe.C,v 1.5 2016/12/05 16:17:49 j_novak Exp $
54  *
55  */
56 
57 
58 
59 //standard
60 #include <cstdlib>
61 #include <cmath>
62 
63 // LORENE
64 #include "matrice.h"
65 #include "cmp.h"
66 #include "proto.h"
67 
68 
69 // Calcul des Cnp
70 namespace Lorene {
71 int cnp (int n, int p) {
72 
73  assert (p<=n) ;
74 
75  if ((p==0) || (p==n))
76  return 1 ;
77  else {
78  int fact_un = 1 ;
79  for (int conte=n ; conte >n-p ; conte --)
80  fact_un *= conte ;
81 
82  int fact_deux = 1 ;
83  for (int conte = 1 ; conte<p+1 ; conte++)
84  fact_deux *= conte ;
85 
86  return int(fact_un/fact_deux) ;
87  }
88 }
89 
90 // Fait le raccord dans la zec ...
91 // Suppose (pour le moment, le meme nbre de points sur les angles ...)
92 // et que la zone precedente est une coquille
93 
94 void Cmp::raccord_externe (int power, int nbre, int lmax) {
95 
96  va.coef() ;
97  va.ylm() ;
98 
99  Base_val base_devel (va.base) ;
100  int base_r, m_quant, l_quant ;
101 
102  // Confort :
103  int zone = mp->get_mg()->get_nzone()-2 ;
104  int nt = mp->get_mg()->get_nt(zone) ;
105  int np = mp->get_mg()->get_np(zone) ;
106  int nr = mp->get_mg()->get_nr(zone) ;
107 
108  // Le mapping doit etre affine :
109  const Map_af* map = dynamic_cast<const Map_af*>(mp) ;
110  if (map == 0x0) {
111  cout << "Le mapping doit etre affine" << endl ;
112  abort() ;
113  }
114 
115  // Mappinhg en r
116  double alpha = map->get_alpha()[zone] ;
117  double beta = map->get_beta()[zone] ;
118 
119  // Mapping en 1/r
120  double new_alpha = -alpha/(beta*beta-alpha*alpha) ;
121  double new_beta = beta/(beta*beta-alpha*alpha) ;
122 
123  // Mapping dans la zec :
124  double alpha_zec = map->get_alpha()[zone+1] ;
125 
126  // Maintenant on construit les matrices de passage :
127  // Celle de ksi a T
128  Matrice tksi (nbre, nbre) ;
129  tksi.set_etat_qcq() ;
130 
131  // Premier polynome
132  tksi.set(0, 0) = sqrt(double(2)) ;
133  for (int i=1 ; i<nbre ; i++)
134  tksi.set(0, i) = 0 ;
135 
136  //Second polynome
137  tksi.set(1, 0) = 0 ;
138  tksi.set(1, 1) = sqrt(double(2)) ;
139  for (int i=2 ; i<nbre ; i++)
140  tksi.set(1, i) = 0 ;
141 
142  // On recurre :
143  for (int lig=2 ; lig<nbre ; lig++) {
144  tksi.set(lig, 0) = -tksi(lig-2, 0) ;
145  for (int col=1 ; col<nbre ; col++)
146  tksi.set(lig, col) = 2*tksi(lig-1, col-1)-tksi(lig-2, col) ;
147  }
148 
149  // Celle de u/new_alpha a ksi :
150  Matrice ksiu (nbre, nbre) ;
151  ksiu.set_etat_qcq() ;
152 
153  for (int lig=0 ; lig<nbre ; lig++) {
154  for (int col=0 ; col<=lig ; col++)
155  ksiu.set(lig, col) = cnp(lig, col)*
156  pow(-new_beta/new_alpha, lig-col) ;
157  for (int col = lig+1 ; col<nbre ; col++)
158  ksiu.set(lig, col) = 0 ;
159  }
160 
161  // La matrice totale :
162  Matrice tu (nbre, nbre) ;
163  tu.set_etat_qcq() ;
164  double somme ;
165  for (int lig=0 ; lig<nbre ; lig++)
166  for (int col=0 ; col<nbre ; col++) {
167  somme = 0 ;
168  for (int m=0 ; m<nbre ; m++)
169  somme += tksi(lig, m)*ksiu(m, col) ;
170  tu.set(lig, col) = somme ;
171  }
172 
173  // On calcul les coefficients de u^n dans la zec
174  Tbl coef_u (nbre+lmax, nr) ;
175  coef_u.set_etat_qcq() ;
176  int* dege = new int [3] ;
177  dege[0] = 1 ; dege[1] = 1 ; dege[2] = nr ;
178  double* ti = new double [nr] ;
179 
180  for (int puiss=0 ; puiss<nbre+lmax ; puiss++) {
181  for (int i=0 ; i<nr ; i++)
182  ti[i] = pow(-cos(M_PI*i/(nr-1))-1, puiss) ;
183  cfrcheb (dege, dege, ti, dege, ti) ;
184  for (int i=0 ; i<nr ; i++)
185  coef_u.set(puiss, i) = ti[i] ;
186  }
187 
188  // Avant d entrer dans la boucle :
189  dege[2] = nbre ;
190  double *coloc = new double[nbre] ;
191  double *auxi = new double [1] ;
192 
193  Tbl coef_zec (np+2, nt, nr) ;
194  coef_zec.annule_hard() ;
195 
196  // Boucle sur les harmoniques :
197 
198  for (int k=0 ; k<np+2 ; k++)
199  for (int j=0 ; j<nt ; j++)
200  if (nullite_plm (j, nt, k, np, base_devel)==1) {
201  donne_lm (zone+2, zone+1, j, k, base_devel, m_quant,
202  l_quant, base_r) ;
203  if (l_quant <= lmax) {
204 
205  // On bosse :
206  // On recupere les valeus aux points de colocation en 1/r :
207  double ksi, air ;
208  for (int i=0 ; i<nbre ; i++) {
209  ksi = -cos(M_PI*i/(nbre-1)) ;
210  air = 1./(new_alpha*ksi+new_beta) ;
211  ksi = (air-beta)/alpha ;
212  for (int m=0 ; m<nr ; m++)
213  ti[m] = (*va.c_cf)(zone, k, j, m) ;
214  som_r_cheb (ti, nr, 1, 1, ksi, auxi) ;
215  coloc[i] = auxi[0]/
216  pow (-new_alpha*cos(M_PI*i/(nbre-1))+new_beta, power+l_quant);
217  }
218 
219  cfrcheb (dege, dege, coloc, dege, coloc) ;
220 
221  Tbl expansion (nbre) ;
222  expansion.set_etat_qcq() ;
223  for (int i=0 ; i<nbre ; i++) {
224  somme = 0 ;
225  for (int m=0 ; m<nbre ; m++)
226  somme += coloc[m]*tu(m, i) ;
227  expansion.set(i) = somme ;
228  }
229 
230  for (int i=0 ; i<nr ; i++) {
231  somme = 0 ;
232  for (int m=0 ; m<nbre ; m++)
233  somme += coef_u(m+l_quant, i)*expansion(m)*
234  pow(alpha_zec, m+l_quant)/
235  pow(new_alpha, m) ;
236  coef_zec.set(k, j, i) = somme ;
237  }
238  }
239  }
240 
241  va.set_etat_cf_qcq() ;
242  va.c_cf->set_etat_qcq() ;
243  va.c_cf->t[zone+1]->set_etat_qcq() ;
244 
245  for (int k=0 ; k<np+2 ; k++)
246  for (int j=0 ; j<nt ; j++)
247  for (int i=0 ; i<nr ; i++)
248  va.c_cf->set(zone+1, k, j, i) = coef_zec(k, j, i) ;
249 
250  set_dzpuis(power) ;
251  va.ylm_i() ;
252 
253  delete[] auxi ;
254  delete [] dege ;
255  delete [] ti ;
256  delete [] coloc ;
257 }
258 }
Mtbl_cf * c_cf
Coefficients of the spectral expansion of the function.
Definition: valeur.h:312
const double * get_alpha() const
Returns the pointer on the array alpha.
Definition: map_af.C:607
void ylm_i()
Inverse of ylm()
Definition: valeur_ylm_i.C:134
int get_np(int l) const
Returns the number of points in the azimuthal direction ( ) in domain no. l.
Definition: grilles.h:479
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:715
void coef() const
Computes the coeffcients of *this.
Definition: valeur_coef.C:151
Cmp sqrt(const Cmp &)
Square root.
Definition: cmp_math.C:223
Lorene prototypes.
Definition: app_hor.h:67
Tbl & set(int l)
Read/write of the Tbl containing the coefficients in a given domain.
Definition: mtbl_cf.h:304
void ylm()
Computes the coefficients of *this.
Definition: valeur_ylm.C:141
const Mg3d * get_mg() const
Gives the Mg3d on which the mapping is defined.
Definition: map.h:783
double & set(int i)
Read/write of a particular element (index i) (1D case)
Definition: tbl.h:301
void raccord_externe(int puis, int nbre, int lmax)
Matching of the external domain with the outermost shell.
Cmp cos(const Cmp &)
Cosine.
Definition: cmp_math.C:97
void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
Definition: tbl.C:364
Matrix handling.
Definition: matrice.h:152
Base_val base
Bases on which the spectral expansion is performed.
Definition: valeur.h:315
const double * get_beta() const
Returns the pointer on the array beta.
Definition: map_af.C:611
int get_nzone() const
Returns the number of domains.
Definition: grilles.h:465
void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
Definition: mtbl_cf.C:303
Cmp pow(const Cmp &, int)
Power .
Definition: cmp_math.C:351
double & set(int j, int i)
Read/write of a particuliar element.
Definition: matrice.h:277
int get_nr(int l) const
Returns the number of points in the radial direction ( ) in domain no. l.
Definition: grilles.h:469
Bases of the spectral expansions.
Definition: base_val.h:325
Affine radial mapping.
Definition: map.h:2048
const Map * mp
Reference mapping.
Definition: cmp.h:451
void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
Definition: matrice.C:178
void set_dzpuis(int)
Set a value to dzpuis.
Definition: cmp.C:657
Basic array class.
Definition: tbl.h:164
int get_nt(int l) const
Returns the number of points in the co-latitude direction ( ) in domain no. l.
Definition: grilles.h:474
void annule_hard()
Sets the Tbl to zero in a hard way.
Definition: tbl.C:375
Valeur va
The numerical value of the Cmp.
Definition: cmp.h:464
Tbl ** t
Array (size nzone ) of pointers on the Tbl &#39;s which contain the spectral coefficients in each domain...
Definition: mtbl_cf.h:215