/* * Solving a 1-D differential equation with spectral methods * (Chebyshev polynomials) * */ /* * Copyright (c) 2002 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 version 2 * as published by the Free Software Foundation. * * 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 cheby_C[] = "$Header: /cvsroot/Lorene/Codes/Spectral/cheby.C,v 1.6 2014/10/13 08:53:59 j_novak Exp $" ; /* * $Id: cheby.C,v 1.6 2014/10/13 08:53:59 j_novak Exp $ * $Log: cheby.C,v $ * Revision 1.6 2014/10/13 08:53:59 j_novak * Lorene classes and functions now belong to the namespace Lorene. * * Revision 1.5 2014/10/06 15:09:46 j_novak * Modified #include directives to use c++ syntax. * * Revision 1.4 2003/01/09 11:07:52 j_novak * headcpp.h is now compliant with C++ norm. * The include files have been ordered, as well as the local_settings_linux * * Revision 1.3 2002/09/24 22:10:40 e_gourgoulhon * * Added computation of infinite norm of the error for each method * * Revision 1.2 2002/09/24 13:15:31 e_gourgoulhon * * First operational version. * * Revision 1.1 2002/09/24 08:38:11 e_gourgoulhon * * Simple code for illustrating various Chebyshev spectral methods: * Galerkin, tau and collocation. * * * * $Header: /cvsroot/Lorene/Codes/Spectral/cheby.C,v 1.6 2014/10/13 08:53:59 j_novak Exp $ * */ // C headers #include #include // Lorene headers #include "map.h" #include "matrice.h" #include "graphique.h" #include "utilitaires.h" using namespace Lorene ; int main() { int nn = 5 ; // Number of Chebyshev coefficients // Grid of collocation points // -------------------------- int nbr[1] ; int nbt[1] ; int nbp[1] ; nbr[0] = nn ; // Number of degrees of freedom in r nbt[0] = 1 ; // Number of degrees of freedom in theta nbp[0] = 1 ; // Number of degrees of freedom in phi int typr[1] ; typr[0] = FIN ; // Type of sampling in r : // FIN = ordinary Chebychev sampling in [-1,1] int typt = SYM ; // Type of sampling in theta int typp = SYM ; // Type of sampling in theta Mg3d grid(1, nbr, typr, nbt, typt, nbp, typp) ; cout << "Grid of collocation points: " << grid << endl ; // Trivial mapping // --------------- double bornes[2] ; bornes[0] = -1. ; bornes[1] = 1. ; Map_af map(grid, bornes) ; Mtbl x = map.r ; cout << "Collocation points : " << x << endl ; // Source of the equation // ---------------------- Valeur ss(grid) ; double cc = - 4. * exp(1.) / (1. + exp(1.)*exp(1.)) ; ss = exp(x) + cc ; cout << "Values of the source s at the collation points : " << endl << ss << endl ; // Chebyshev expansion of the source // --------------------------------- ss.set_base_r(0, R_CHEB) ; ss.set_base_t(T_COS_P) ; ss.set_base_p(P_COSSIN_P) ; ss.coef() ; cout << "Coef of the source : " << endl ; ss.affiche_seuil(cout, 0, 4, 1.e-15) ; // Chebyshev expansion of the source with the large number of coef // --------------------------------------------------------------- nbr[0] = 33 ; Mg3d grid_big(1, nbr, typr, nbt, typt, nbp, typp) ; Map_af map_big(grid_big, bornes) ; Mtbl x_big = map_big.r ; Valeur ss_big(grid_big) ; ss_big = exp(x_big) + cc ; ss_big.set_base_r(0, R_CHEB) ; ss_big.set_base_t(T_COS_P) ; ss_big.set_base_p(P_COSSIN_P) ; ss_big.coef() ; cout << "Coef of the source with a large number of Chebyshev polynomials: " << endl ; ss_big.affiche_seuil(cout, 0, 4, 1.e-15) ; // des_coef_xi(ss_big, 0, 0, 0, 1.e-14, 0x0, "Coef of s") ; // Orthogonal projection: P_N s: Mtbl_cf cf_proj(grid, ss.base) ; cf_proj.annule_hard() ; for (int i=0; i Galerkin basis Matrice mat_gal(nn,nn-2) ; mat_gal.set_etat_qcq() ; for (int j=0; j Galerkin basis : " << mat_gal << endl ; // Transpose Matrice mat_tg = mat_gal.transpose() ; // Normalization of T_0(x) : for (int i=0; i err_max_gal ) err_max_gal = err ; file << xd << " " << yuu_exact << " " << yuu << " " << yuu - yuu_exact << endl ; } file.close() ; file.open("uu_gal_colloc.d") ; file.precision(8) ; for (int i=0; i err_max_tau ) err_max_tau = err ; file << xd << " " << yuu_exact << " " << yuu << " " << yuu - yuu_exact << " " << yuu - yuu_gal << endl ; } file.close() ; file.open("uu_tau_colloc.d") ; file.precision(8) ; for (int i=0; i err_max_psp ) err_max_psp = err ; file << xd << " " << yuu_exact << " " << yuu << " " << yuu - yuu_exact << " " << yuu - yuu_gal << " " << yuu - yuu_tau << endl ; } file.close() ; file.open("uu_psp_colloc.d") ; file.precision(8) ; for (int i=0; i