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