| 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 |
char base_val_phi_funct_C[] = "$Header: /cvsroot/Lorene/C++/Source/Base_val/base_val_phi_funct.C,v 1.7 2014/10/13 08:52:39 j_novak Exp $" ; |
| 30 |
|
| 31 |
/* |
| 32 |
* $Id: base_val_phi_funct.C,v 1.7 2014/10/13 08:52:39 j_novak Exp $ |
| 33 |
* $Log: base_val_phi_funct.C,v $ |
| 34 |
* Revision 1.7 2014/10/13 08:52:39 j_novak |
| 35 |
* Lorene classes and functions now belong to the namespace Lorene. |
| 36 |
* |
| 37 |
* Revision 1.6 2014/10/06 15:12:57 j_novak |
| 38 |
* Modified #include directives to use c++ syntax. |
| 39 |
* |
| 40 |
* Revision 1.5 2013/04/25 15:46:05 j_novak |
| 41 |
* Added special treatment in the case np = 1, for type_p = NONSYM. |
| 42 |
* |
| 43 |
* Revision 1.4 2012/01/17 14:44:35 j_penner |
| 44 |
* Modified phi variables to only use 16 integers in arrays |
| 45 |
* |
| 46 |
* Revision 1.3 2006/05/30 13:06:12 n_vasset |
| 47 |
* Implemented function P_COSSIN_I in base_val_phi_funct.C |
| 48 |
* |
| 49 |
* Revision 1.2 2002/10/16 14:36:30 j_novak |
| 50 |
* Reorganization of #include instructions of standard C++, in order to |
| 51 |
* use experimental version 3 of gcc. |
| 52 |
* |
| 53 |
* Revision 1.1.1.1 2001/11/20 15:19:28 e_gourgoulhon |
| 54 |
* LORENE |
| 55 |
* |
| 56 |
* Revision 1.2 1999/12/29 10:49:35 eric |
| 57 |
* Methode const. |
| 58 |
* |
| 59 |
* Revision 1.1 1999/12/28 12:58:29 eric |
| 60 |
* Initial revision |
| 61 |
* |
| 62 |
* |
| 63 |
* $Header: /cvsroot/Lorene/C++/Source/Base_val/base_val_phi_funct.C,v 1.7 2014/10/13 08:52:39 j_novak Exp $ |
| 64 |
* |
| 65 |
*/ |
| 66 |
|
| 67 |
// Headers C |
| 68 |
#include <cstdlib> |
| 69 |
#include <cmath> |
| 70 |
|
| 71 |
|
| 72 |
// Headers Lorene |
| 73 |
#include "base_val.h" |
| 74 |
#include "type_parite.h" |
| 75 |
#include "tbl.h" |
| 76 |
|
| 77 |
// Local prototypes |
| 78 |
namespace Lorene { |
| 79 |
void phi_funct_pas_prevu(int, double*) ; |
| 80 |
void phi_funct_cossin(int, double*) ; |
| 81 |
void phi_funct_cossin_p(int, double*) ; |
| 82 |
void phi_funct_cossin_i(int, double*) ; |
| 83 |
|
| 84 |
//************************************************************************ |
| 85 |
// user interface : method Base_val::phi_functions |
| 86 |
//************************************************************************ |
| 87 |
|
| 88 |
const Tbl& Base_val::phi_functions(int l, int np) const { |
| 89 |
|
| 90 |
const int nmax = 20 ; // maximum number of couples (base_p, np) |
| 91 |
static int nb_done = 0 ; // number of Tbl already computed |
| 92 |
static int base_p_done[nmax] ; // phi bases already treated |
| 93 |
static int np_done[nmax] ; // number of points already treated |
| 94 |
static Tbl* tab[nmax] ; // result for couples (base_p, np) |
| 95 |
|
| 96 |
static void(*vbasecol[MAX_BASE_2])(int, double*) ; // computation routines |
| 97 |
|
| 98 |
static int premier_appel = 1 ; |
| 99 |
|
| 100 |
// Initializations at first call |
| 101 |
// ----------------------------- |
| 102 |
if (premier_appel == 1) { |
| 103 |
|
| 104 |
premier_appel = 0 ; |
| 105 |
|
| 106 |
for (int i=0 ; i<MAX_BASE_2 ; i++) { |
| 107 |
vbasecol[i] = phi_funct_pas_prevu ; |
| 108 |
} |
| 109 |
|
| 110 |
vbasecol[P_COSSIN >> TRA_P] = phi_funct_cossin ; |
| 111 |
vbasecol[P_COSSIN_P >> TRA_P] = phi_funct_cossin_p ; |
| 112 |
vbasecol[P_COSSIN_I >> TRA_P] = phi_funct_cossin_p ; |
| 113 |
|
| 114 |
} |
| 115 |
|
| 116 |
// Computation |
| 117 |
// ----------- |
| 118 |
|
| 119 |
int base_p = ( b[l] & MSQ_P ) >> TRA_P ; |
| 120 |
|
| 121 |
// Has this couple (base_p, np) been previously considered ? |
| 122 |
// --------------------------------------------------------- |
| 123 |
int index = -1 ; |
| 124 |
for (int i=0; i<nb_done; i++) { |
| 125 |
if ( (base_p_done[i] == base_p) && (np_done[i] == np) ) { |
| 126 |
index = i ; |
| 127 |
} |
| 128 |
} |
| 129 |
|
| 130 |
// If not, a new computation must be performed |
| 131 |
// ------------------------------------------- |
| 132 |
if (index == -1) { |
| 133 |
if ( nb_done >= nmax ) { |
| 134 |
cout << "Base_val::phi_functions : nb_done >= nmax ! " << endl ; |
| 135 |
abort() ; |
| 136 |
} |
| 137 |
|
| 138 |
index = nb_done ; |
| 139 |
|
| 140 |
tab[index] = new Tbl( np+1, np ) ; |
| 141 |
(tab[index])->set_etat_qcq() ; |
| 142 |
|
| 143 |
vbasecol[base_p](np, (tab[index])->t ) ; |
| 144 |
|
| 145 |
base_p_done[index] = base_p ; |
| 146 |
np_done[index] = np ; |
| 147 |
nb_done++ ; |
| 148 |
|
| 149 |
} // end of the case where the computation had to be done |
| 150 |
|
| 151 |
|
| 152 |
return *(tab[index]) ; |
| 153 |
|
| 154 |
} |
| 155 |
|
| 156 |
|
| 157 |
//************************************************************************ |
| 158 |
// computational subroutines |
| 159 |
//************************************************************************ |
| 160 |
|
| 161 |
//==================================== |
| 162 |
// Unknown case |
| 163 |
//==================================== |
| 164 |
|
| 165 |
void phi_funct_pas_prevu(int, double*) { |
| 166 |
|
| 167 |
cout << "Base_val::phi_functions : phi basis not implemented !" |
| 168 |
<< endl ; |
| 169 |
abort() ; |
| 170 |
|
| 171 |
} |
| 172 |
|
| 173 |
//============================================== |
| 174 |
// Basis P_COSSIN |
| 175 |
//============================================== |
| 176 |
|
| 177 |
void phi_funct_cossin(int np, double* ff) { |
| 178 |
|
| 179 |
double xx = 2.*M_PI / double(np) ; |
| 180 |
|
| 181 |
if (np == 1) { |
| 182 |
ff[0] = 1. ; // cos (0 * phi) |
| 183 |
ff[1] = 0. ; // sin (0 * phi) |
| 184 |
} |
| 185 |
else { |
| 186 |
for (int i = 0; i < np-1 ; i+=2 ) { |
| 187 |
int m = i/2 ; |
| 188 |
for (int k = 0; k < np ; k++ ) { |
| 189 |
double phi = xx*k ; |
| 190 |
ff[np*i + k] = cos(m * phi) ; |
| 191 |
ff[np*(i+1) + k] = sin(m * phi) ; |
| 192 |
} |
| 193 |
} |
| 194 |
|
| 195 |
for (int k = 0; k < np ; k++ ) { |
| 196 |
double phi = xx*k ; |
| 197 |
ff[np*np + k] = cos(np/2 * phi) ; |
| 198 |
} |
| 199 |
} |
| 200 |
|
| 201 |
} |
| 202 |
|
| 203 |
//============================================== |
| 204 |
// Basis P_COSSIN_P |
| 205 |
//============================================== |
| 206 |
|
| 207 |
void phi_funct_cossin_p(int np, double* ff) { |
| 208 |
|
| 209 |
double xx = M_PI/double(np) ; |
| 210 |
|
| 211 |
for (int i = 0; i < np+1 ; i+=2 ) { |
| 212 |
for (int k = 0; k < np ; k++ ) { |
| 213 |
double phi = xx*k ; |
| 214 |
ff[np*i+ k] = cos(i * phi); |
| 215 |
} |
| 216 |
} |
| 217 |
|
| 218 |
for (int i = 1; i < np ; i+=2 ) { |
| 219 |
for (int k = 0; k < np ; k++ ) { |
| 220 |
double phi = xx*k ; |
| 221 |
ff[np*i+ k] = sin((i-1) * phi); |
| 222 |
} |
| 223 |
} |
| 224 |
|
| 225 |
|
| 226 |
} |
| 227 |
|
| 228 |
//============================================== |
| 229 |
// Basis P_COSSIN_I |
| 230 |
//============================================== |
| 231 |
|
| 232 |
void phi_funct_cossin_i(int np, double* ff) { |
| 233 |
|
| 234 |
double xx = M_PI/double(np) ; |
| 235 |
|
| 236 |
for (int i = 0; i < np+1 ; i+=2 ) { |
| 237 |
for (int k = 0; k < np ; k++ ) { |
| 238 |
double phi = xx*k ; |
| 239 |
ff[np*i+ k] = sin(i * phi); |
| 240 |
} |
| 241 |
} |
| 242 |
|
| 243 |
for (int i = 1; i < np ; i+=2 ) { |
| 244 |
for (int k = 0; k < np ; k++ ) { |
| 245 |
double phi = xx*k ; |
| 246 |
ff[np*i+ k] = cos((i-1) * phi); |
| 247 |
} |
| 248 |
} |
| 249 |
|
| 250 |
|
| 251 |
} |
| 252 |
|
| 253 |
} |