00001 /* 00002 * Definition of class Ortho_poly 00003 */ 00004 00005 /* 00006 * Copyright (c) 2005 Eric Gourgoulhon 00007 * 00008 * This file is part of LORENE. 00009 * 00010 * LORENE is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. 00014 * 00015 * LORENE is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 * GNU General Public License for more details. 00019 * 00020 * You should have received a copy of the GNU General Public License 00021 * along with LORENE; if not, write to the Free Software 00022 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00023 * 00024 */ 00025 00026 /* 00027 * $Id: ortho_poly.C,v 1.2 2005/11/14 14:12:10 e_gourgoulhon Exp $ 00028 * $Log: ortho_poly.C,v $ 00029 * Revision 1.2 2005/11/14 14:12:10 e_gourgoulhon 00030 * Added include <assert.h> 00031 * 00032 * Revision 1.1 2005/11/14 01:57:00 e_gourgoulhon 00033 * First version 00034 * 00035 * 00036 * $Header: /cvsroot/Lorene/School05/Monday/ortho_poly.C,v 1.2 2005/11/14 14:12:10 e_gourgoulhon Exp $ 00037 * 00038 */ 00039 00040 #include <iostream> 00041 00042 using namespace std ; 00043 00044 #include <stdlib.h> 00045 #include <math.h> 00046 #include <assert.h> 00047 00048 #include "ortho_poly.h" 00049 #include "grid.h" 00050 00051 00052 //--------------------// 00053 // Copy constructor // 00054 //--------------------// 00055 00056 Ortho_poly::Ortho_poly(const Ortho_poly& pp) : nn(pp.nn) { 00057 00058 // Initialization of the pointers of the derived quantities to 0x0 00059 p_gauss_nodes = 0x0 ; 00060 p_gauss_weights = 0x0 ; 00061 p_gauss_gamma = 0x0 ; 00062 p_gauss_lobatto_nodes = 0x0 ; 00063 p_gauss_lobatto_weights = 0x0 ; 00064 p_gauss_lobatto_gamma = 0x0 ; 00065 00066 } 00067 00068 //---------------------------------// 00069 // Constructor for derived classes // 00070 //---------------------------------// 00071 00072 Ortho_poly::Ortho_poly(int ni) : nn(ni) { 00073 00074 assert(ni >= 0) ; 00075 00076 // Initialization of the pointers of the derived quantities to 0x0 00077 p_gauss_nodes = 0x0 ; 00078 p_gauss_weights = 0x0 ; 00079 p_gauss_gamma = 0x0 ; 00080 p_gauss_lobatto_nodes = 0x0 ; 00081 p_gauss_lobatto_weights = 0x0 ; 00082 p_gauss_lobatto_gamma = 0x0 ; 00083 00084 } 00085 00086 00087 //--------------// 00088 // Destructor // 00089 //--------------// 00090 00091 Ortho_poly::~Ortho_poly() { 00092 00093 if (p_gauss_nodes != 0x0) delete p_gauss_nodes ; 00094 if (p_gauss_weights != 0x0) delete [] p_gauss_weights ; 00095 if (p_gauss_gamma != 0x0) delete [] p_gauss_gamma ; 00096 if (p_gauss_lobatto_nodes != 0x0) delete p_gauss_lobatto_nodes ; 00097 if (p_gauss_lobatto_weights != 0x0) delete [] p_gauss_lobatto_weights ; 00098 if (p_gauss_lobatto_gamma != 0x0) delete [] p_gauss_lobatto_gamma ; 00099 00100 } 00101 00102 //--------------// 00103 // Assignment // 00104 //--------------// 00105 00106 void Ortho_poly::operator=(const Ortho_poly& ) { 00107 00108 cerr << "Ortho_poly::operator= not implemented !" << endl ; 00109 abort() ; 00110 00111 } 00112 00113 //-------------// 00114 // Accessors // 00115 //-------------// 00116 00117 int Ortho_poly::n() const { 00118 00119 return nn ; 00120 00121 } 00122 00123 00124 //-------------------------------------------------// 00125 // Coefficients of Gauss interpolant polynomial // 00126 //-------------------------------------------------// 00127 00128 void Ortho_poly::coef_interpolant_Gauss(double (*f)(double), 00129 double* cf) const { 00130 00131 // Values of the function at the Gauss nodes 00132 00133 double* ff = new double[nn+1] ; 00134 00135 for (int i=0; i<=nn; i++) ff[i] = f( gauss_nodes()(i) ) ; 00136 00137 // Computation of the coefficients 00138 00139 for (int i=0; i<=nn; i++) { 00140 double sum = 0 ; 00141 for (int j=0; j<=nn; j++) { 00142 sum += ff[j] * operator()(i, gauss_nodes()(j) ) 00143 * gauss_weight(j) ; 00144 } 00145 cf[i] = sum / gauss_gamma(i) ; 00146 } 00147 00148 delete [] ff ; 00149 00150 } 00151 00152 //--------------------------------------------------------// 00153 // Coefficients of Gauss-Lobatto interpolant polynomial // 00154 //--------------------------------------------------------// 00155 00156 void Ortho_poly::coef_interpolant_GL(double (*f)(double), 00157 double* cf) const { 00158 00159 // Values of the function at the Gauss-Lobatto nodes 00160 00161 double* ff = new double[nn+1] ; 00162 00163 for (int i=0; i<=nn; i++) ff[i] = f( gauss_lobatto_nodes()(i) ) ; 00164 00165 // Computation of the coefficients 00166 00167 for (int i=0; i<=nn; i++) { 00168 double sum = 0 ; 00169 for (int j=0; j<=nn; j++) { 00170 sum += ff[j] * operator()(i, gauss_lobatto_nodes()(j) ) 00171 * gauss_lobatto_weight(j) ; 00172 } 00173 cf[i] = sum / gauss_lobatto_gamma(i) ; 00174 } 00175 00176 delete [] ff ; 00177 00178 } 00179 00180 //----------------------------------------// 00181 // Values of the interpolant polynomial // 00182 //----------------------------------------// 00183 00184 double Ortho_poly::series(const double* a, double x) const { 00185 00186 double sum = 0 ; 00187 for (int i=0; i<=nn; i++) { 00188 sum += a[i] * operator()(i, x) ; 00189 } 00190 00191 return sum ; 00192 00193 } 00194 00195