| 1 |
/* |
| 2 |
* Definition of class Ortho_poly |
| 3 |
*/ |
| 4 |
|
| 5 |
/* |
| 6 |
* Copyright (c) 2005 Eric Gourgoulhon |
| 7 |
* |
| 8 |
* This file is part of LORENE. |
| 9 |
* |
| 10 |
* LORENE is free software; you can redistribute it and/or modify |
| 11 |
* it under the terms of the GNU General Public License as published by |
| 12 |
* the Free Software Foundation; either version 2 of the License, or |
| 13 |
* (at your option) any later version. |
| 14 |
* |
| 15 |
* LORENE is distributed in the hope that it will be useful, |
| 16 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 |
* GNU General Public License for more details. |
| 19 |
* |
| 20 |
* You should have received a copy of the GNU General Public License |
| 21 |
* along with LORENE; if not, write to the Free Software |
| 22 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 23 |
* |
| 24 |
*/ |
| 25 |
|
| 26 |
/* |
| 27 |
* $Id: ortho_poly.C,v 1.3 2014/10/06 15:09:48 j_novak Exp $ |
| 28 |
* $Log: ortho_poly.C,v $ |
| 29 |
* Revision 1.3 2014/10/06 15:09:48 j_novak |
| 30 |
* Modified #include directives to use c++ syntax. |
| 31 |
* |
| 32 |
* Revision 1.2 2005/11/14 14:12:10 e_gourgoulhon |
| 33 |
* Added include <assert.h> |
| 34 |
* |
| 35 |
* Revision 1.1 2005/11/14 01:57:00 e_gourgoulhon |
| 36 |
* First version |
| 37 |
* |
| 38 |
* |
| 39 |
* $Header: /cvsroot/Lorene/School05/Monday/ortho_poly.C,v 1.3 2014/10/06 15:09:48 j_novak Exp $ |
| 40 |
* |
| 41 |
*/ |
| 42 |
|
| 43 |
#include <iostream> |
| 44 |
|
| 45 |
using namespace std ; |
| 46 |
|
| 47 |
#include <cstdlib> |
| 48 |
#include <cmath> |
| 49 |
#include <cassert> |
| 50 |
|
| 51 |
#include "ortho_poly.h" |
| 52 |
#include "grid.h" |
| 53 |
|
| 54 |
|
| 55 |
//--------------------// |
| 56 |
// Copy constructor // |
| 57 |
//--------------------// |
| 58 |
|
| 59 |
Ortho_poly::Ortho_poly(const Ortho_poly& pp) : nn(pp.nn) { |
| 60 |
|
| 61 |
// Initialization of the pointers of the derived quantities to 0x0 |
| 62 |
p_gauss_nodes = 0x0 ; |
| 63 |
p_gauss_weights = 0x0 ; |
| 64 |
p_gauss_gamma = 0x0 ; |
| 65 |
p_gauss_lobatto_nodes = 0x0 ; |
| 66 |
p_gauss_lobatto_weights = 0x0 ; |
| 67 |
p_gauss_lobatto_gamma = 0x0 ; |
| 68 |
|
| 69 |
} |
| 70 |
|
| 71 |
//---------------------------------// |
| 72 |
// Constructor for derived classes // |
| 73 |
//---------------------------------// |
| 74 |
|
| 75 |
Ortho_poly::Ortho_poly(int ni) : nn(ni) { |
| 76 |
|
| 77 |
assert(ni >= 0) ; |
| 78 |
|
| 79 |
// Initialization of the pointers of the derived quantities to 0x0 |
| 80 |
p_gauss_nodes = 0x0 ; |
| 81 |
p_gauss_weights = 0x0 ; |
| 82 |
p_gauss_gamma = 0x0 ; |
| 83 |
p_gauss_lobatto_nodes = 0x0 ; |
| 84 |
p_gauss_lobatto_weights = 0x0 ; |
| 85 |
p_gauss_lobatto_gamma = 0x0 ; |
| 86 |
|
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
//--------------// |
| 91 |
// Destructor // |
| 92 |
//--------------// |
| 93 |
|
| 94 |
Ortho_poly::~Ortho_poly() { |
| 95 |
|
| 96 |
if (p_gauss_nodes != 0x0) delete p_gauss_nodes ; |
| 97 |
if (p_gauss_weights != 0x0) delete [] p_gauss_weights ; |
| 98 |
if (p_gauss_gamma != 0x0) delete [] p_gauss_gamma ; |
| 99 |
if (p_gauss_lobatto_nodes != 0x0) delete p_gauss_lobatto_nodes ; |
| 100 |
if (p_gauss_lobatto_weights != 0x0) delete [] p_gauss_lobatto_weights ; |
| 101 |
if (p_gauss_lobatto_gamma != 0x0) delete [] p_gauss_lobatto_gamma ; |
| 102 |
|
| 103 |
} |
| 104 |
|
| 105 |
//--------------// |
| 106 |
// Assignment // |
| 107 |
//--------------// |
| 108 |
|
| 109 |
void Ortho_poly::operator=(const Ortho_poly& ) { |
| 110 |
|
| 111 |
cerr << "Ortho_poly::operator= not implemented !" << endl ; |
| 112 |
abort() ; |
| 113 |
|
| 114 |
} |
| 115 |
|
| 116 |
//-------------// |
| 117 |
// Accessors // |
| 118 |
//-------------// |
| 119 |
|
| 120 |
int Ortho_poly::n() const { |
| 121 |
|
| 122 |
return nn ; |
| 123 |
|
| 124 |
} |
| 125 |
|
| 126 |
|
| 127 |
//-------------------------------------------------// |
| 128 |
// Coefficients of Gauss interpolant polynomial // |
| 129 |
//-------------------------------------------------// |
| 130 |
|
| 131 |
void Ortho_poly::coef_interpolant_Gauss(double (*f)(double), |
| 132 |
double* cf) const { |
| 133 |
|
| 134 |
// Values of the function at the Gauss nodes |
| 135 |
|
| 136 |
double* ff = new double[nn+1] ; |
| 137 |
|
| 138 |
for (int i=0; i<=nn; i++) ff[i] = f( gauss_nodes()(i) ) ; |
| 139 |
|
| 140 |
// Computation of the coefficients |
| 141 |
|
| 142 |
for (int i=0; i<=nn; i++) { |
| 143 |
double sum = 0 ; |
| 144 |
for (int j=0; j<=nn; j++) { |
| 145 |
sum += ff[j] * operator()(i, gauss_nodes()(j) ) |
| 146 |
* gauss_weight(j) ; |
| 147 |
} |
| 148 |
cf[i] = sum / gauss_gamma(i) ; |
| 149 |
} |
| 150 |
|
| 151 |
delete [] ff ; |
| 152 |
|
| 153 |
} |
| 154 |
|
| 155 |
//--------------------------------------------------------// |
| 156 |
// Coefficients of Gauss-Lobatto interpolant polynomial // |
| 157 |
//--------------------------------------------------------// |
| 158 |
|
| 159 |
void Ortho_poly::coef_interpolant_GL(double (*f)(double), |
| 160 |
double* cf) const { |
| 161 |
|
| 162 |
// Values of the function at the Gauss-Lobatto nodes |
| 163 |
|
| 164 |
double* ff = new double[nn+1] ; |
| 165 |
|
| 166 |
for (int i=0; i<=nn; i++) ff[i] = f( gauss_lobatto_nodes()(i) ) ; |
| 167 |
|
| 168 |
// Computation of the coefficients |
| 169 |
|
| 170 |
for (int i=0; i<=nn; i++) { |
| 171 |
double sum = 0 ; |
| 172 |
for (int j=0; j<=nn; j++) { |
| 173 |
sum += ff[j] * operator()(i, gauss_lobatto_nodes()(j) ) |
| 174 |
* gauss_lobatto_weight(j) ; |
| 175 |
} |
| 176 |
cf[i] = sum / gauss_lobatto_gamma(i) ; |
| 177 |
} |
| 178 |
|
| 179 |
delete [] ff ; |
| 180 |
|
| 181 |
} |
| 182 |
|
| 183 |
//----------------------------------------// |
| 184 |
// Values of the interpolant polynomial // |
| 185 |
//----------------------------------------// |
| 186 |
|
| 187 |
double Ortho_poly::series(const double* a, double x) const { |
| 188 |
|
| 189 |
double sum = 0 ; |
| 190 |
for (int i=0; i<=nn; i++) { |
| 191 |
sum += a[i] * operator()(i, x) ; |
| 192 |
} |
| 193 |
|
| 194 |
return sum ; |
| 195 |
|
| 196 |
} |
| 197 |
|
| 198 |
|