LORENE
base_val_phi_funct.C
1 /*
2  * Method of the class Base_val to get the values of the phi basis functions
3  * at the phi collocation points.
4  *
5  * (see file base_val.h for the documentation)
6  */
7 
8 /*
9  * Copyright (c) 1999-2001 Eric Gourgoulhon
10  *
11  * This file is part of LORENE.
12  *
13  * LORENE is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 2 of the License, or
16  * (at your option) any later version.
17  *
18  * LORENE is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with LORENE; if not, write to the Free Software
25  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26  *
27  */
28 
29 
30 
31 /*
32  * $Id: base_val_phi_funct.C,v 1.8 2016/12/05 16:17:44 j_novak Exp $
33  * $Log: base_val_phi_funct.C,v $
34  * Revision 1.8 2016/12/05 16:17:44 j_novak
35  * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
36  *
37  * Revision 1.7 2014/10/13 08:52:39 j_novak
38  * Lorene classes and functions now belong to the namespace Lorene.
39  *
40  * Revision 1.6 2014/10/06 15:12:57 j_novak
41  * Modified #include directives to use c++ syntax.
42  *
43  * Revision 1.5 2013/04/25 15:46:05 j_novak
44  * Added special treatment in the case np = 1, for type_p = NONSYM.
45  *
46  * Revision 1.4 2012/01/17 14:44:35 j_penner
47  * Modified phi variables to only use 16 integers in arrays
48  *
49  * Revision 1.3 2006/05/30 13:06:12 n_vasset
50  * Implemented function P_COSSIN_I in base_val_phi_funct.C
51  *
52  * Revision 1.2 2002/10/16 14:36:30 j_novak
53  * Reorganization of #include instructions of standard C++, in order to
54  * use experimental version 3 of gcc.
55  *
56  * Revision 1.1.1.1 2001/11/20 15:19:28 e_gourgoulhon
57  * LORENE
58  *
59  * Revision 1.2 1999/12/29 10:49:35 eric
60  * Methode const.
61  *
62  * Revision 1.1 1999/12/28 12:58:29 eric
63  * Initial revision
64  *
65  *
66  * $Header: /cvsroot/Lorene/C++/Source/Base_val/base_val_phi_funct.C,v 1.8 2016/12/05 16:17:44 j_novak Exp $
67  *
68  */
69 
70 // Headers C
71 #include <cstdlib>
72 #include <cmath>
73 
74 
75 // Headers Lorene
76 #include "base_val.h"
77 #include "type_parite.h"
78 #include "tbl.h"
79 
80 // Local prototypes
81 namespace Lorene {
82 void phi_funct_pas_prevu(int, double*) ;
83 void phi_funct_cossin(int, double*) ;
84 void phi_funct_cossin_p(int, double*) ;
85 void phi_funct_cossin_i(int, double*) ;
86 
87 //************************************************************************
88 // user interface : method Base_val::phi_functions
89 //************************************************************************
90 
91 const Tbl& Base_val::phi_functions(int l, int np) const {
92 
93  const int nmax = 20 ; // maximum number of couples (base_p, np)
94  static int nb_done = 0 ; // number of Tbl already computed
95  static int base_p_done[nmax] ; // phi bases already treated
96  static int np_done[nmax] ; // number of points already treated
97  static Tbl* tab[nmax] ; // result for couples (base_p, np)
98 
99  static void(*vbasecol[MAX_BASE_2])(int, double*) ; // computation routines
100 
101  static int premier_appel = 1 ;
102 
103  // Initializations at first call
104  // -----------------------------
105  if (premier_appel == 1) {
106 
107  premier_appel = 0 ;
108 
109  for (int i=0 ; i<MAX_BASE_2 ; i++) {
110  vbasecol[i] = phi_funct_pas_prevu ;
111  }
112 
113  vbasecol[P_COSSIN >> TRA_P] = phi_funct_cossin ;
114  vbasecol[P_COSSIN_P >> TRA_P] = phi_funct_cossin_p ;
115  vbasecol[P_COSSIN_I >> TRA_P] = phi_funct_cossin_p ;
116 
117  }
118 
119  // Computation
120  // -----------
121 
122  int base_p = ( b[l] & MSQ_P ) >> TRA_P ;
123 
124  // Has this couple (base_p, np) been previously considered ?
125  // ---------------------------------------------------------
126  int index = -1 ;
127  for (int i=0; i<nb_done; i++) {
128  if ( (base_p_done[i] == base_p) && (np_done[i] == np) ) {
129  index = i ;
130  }
131  }
132 
133  // If not, a new computation must be performed
134  // -------------------------------------------
135  if (index == -1) {
136  if ( nb_done >= nmax ) {
137  cout << "Base_val::phi_functions : nb_done >= nmax ! " << endl ;
138  abort() ;
139  }
140 
141  index = nb_done ;
142 
143  tab[index] = new Tbl( np+1, np ) ;
144  (tab[index])->set_etat_qcq() ;
145 
146  vbasecol[base_p](np, (tab[index])->t ) ;
147 
148  base_p_done[index] = base_p ;
149  np_done[index] = np ;
150  nb_done++ ;
151 
152  } // end of the case where the computation had to be done
153 
154 
155  return *(tab[index]) ;
156 
157 }
158 
159 
160 //************************************************************************
161 // computational subroutines
162 //************************************************************************
163 
164 //====================================
165 // Unknown case
166 //====================================
167 
168 void phi_funct_pas_prevu(int, double*) {
169 
170  cout << "Base_val::phi_functions : phi basis not implemented !"
171  << endl ;
172  abort() ;
173 
174 }
175 
176 //==============================================
177 // Basis P_COSSIN
178 //==============================================
179 
180 void phi_funct_cossin(int np, double* ff) {
181 
182  double xx = 2.*M_PI / double(np) ;
183 
184  if (np == 1) {
185  ff[0] = 1. ; // cos (0 * phi)
186  ff[1] = 0. ; // sin (0 * phi)
187  }
188  else {
189  for (int i = 0; i < np-1 ; i+=2 ) {
190  int m = i/2 ;
191  for (int k = 0; k < np ; k++ ) {
192  double phi = xx*k ;
193  ff[np*i + k] = cos(m * phi) ;
194  ff[np*(i+1) + k] = sin(m * phi) ;
195  }
196  }
197 
198  for (int k = 0; k < np ; k++ ) {
199  double phi = xx*k ;
200  ff[np*np + k] = cos(np/2 * phi) ;
201  }
202  }
203 
204 }
205 
206 //==============================================
207 // Basis P_COSSIN_P
208 //==============================================
209 
210 void phi_funct_cossin_p(int np, double* ff) {
211 
212  double xx = M_PI/double(np) ;
213 
214  for (int i = 0; i < np+1 ; i+=2 ) {
215  for (int k = 0; k < np ; k++ ) {
216  double phi = xx*k ;
217  ff[np*i+ k] = cos(i * phi);
218  }
219  }
220 
221  for (int i = 1; i < np ; i+=2 ) {
222  for (int k = 0; k < np ; k++ ) {
223  double phi = xx*k ;
224  ff[np*i+ k] = sin((i-1) * phi);
225  }
226  }
227 
228 
229 }
230 
231 //==============================================
232 // Basis P_COSSIN_I
233 //==============================================
234 
235 void phi_funct_cossin_i(int np, double* ff) {
236 
237  double xx = M_PI/double(np) ;
238 
239  for (int i = 0; i < np+1 ; i+=2 ) {
240  for (int k = 0; k < np ; k++ ) {
241  double phi = xx*k ;
242  ff[np*i+ k] = sin(i * phi);
243  }
244  }
245 
246  for (int i = 1; i < np ; i+=2 ) {
247  for (int k = 0; k < np ; k++ ) {
248  double phi = xx*k ;
249  ff[np*i+ k] = cos((i-1) * phi);
250  }
251  }
252 
253 
254 }
255 
256 }
#define MAX_BASE_2
Smaller maximum bases used for phi (and higher dimensions for now)
Definition: type_parite.h:146
#define P_COSSIN
dev. standart
Definition: type_parite.h:245
#define TRA_P
Translation en Phi, used for a bitwise shift (in hex)
Definition: type_parite.h:162
Lorene prototypes.
Definition: app_hor.h:67
#define MSQ_P
Extraction de l&#39;info sur Phi.
Definition: type_parite.h:156
Cmp cos(const Cmp &)
Cosine.
Definition: cmp_math.C:97
int * b
Array (size: nzone ) of the spectral basis in each domain.
Definition: base_val.h:334
const Tbl & phi_functions(int l, int np) const
Values of the phi basis functions at the phi collocation points.
Cmp sin(const Cmp &)
Sine.
Definition: cmp_math.C:72
#define P_COSSIN_I
dev. sur Phi = 2*phi, freq. impaires
Definition: type_parite.h:249
Basic array class.
Definition: tbl.h:164
#define P_COSSIN_P
dev. sur Phi = 2*phi, freq. paires
Definition: type_parite.h:247