KADATH
mult_xm1_1d.cpp
1 /*
2  Copyright 2017 Philippe Grandclement
3 
4  This file is part of Kadath.
5 
6  Kadath is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Kadath is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with Kadath. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #include "base_spectral.hpp"
21 #include "headcpp.hpp"
22 #include "matrice.hpp"
23 #include "array.hpp"
24 
25 namespace Kadath {
26 int mult_xm1_1d_pasprevu (Array<double>&) {
27  cout << "mult_xm1_1d not implemented." << endl ;
28  abort() ;
29 }
30 
31 
32 int mult_xm1_1d_cheb (Array<double>& so) {
33  assert (so.get_ndim()==1) ;
34  int nr = so.get_size(0) ;
35  Array<double> res (nr) ;
36 
37  res.set(0) = -so(0) + 0.5*so(1) ;
38  res.set(1) = so(0) - so(1) + 0.5*so(2) ;
39  for (int i=2 ; i<nr-1 ; i++)
40  res.set(i) = 0.5*so(i-1) - so(i) + 0.5*so(i+1) ;
41  res.set(nr-1) = 0.5*so(nr-2) - so(nr-1) ;
42 
43  so = res ;
44  return CHEB ;
45 }
46 
47 int mult_xm1_1d_leg (Array<double>& so) {
48  assert (so.get_ndim()==1) ;
49  int nr = so.get_size(0) ;
50  Array<double> res (nr) ;
51 
52  res.set(0) = -so(0) + so(1)/3. ;
53  for (int i=1 ; i<nr-1 ; i++)
54  res.set(i) = double(i)/double(2*i-1)*so(i-1) - so(i) + double(i+1)/double(2*i+3)*so(i+1) ;
55  res.set(nr-1) = double(nr-1)/double(2*nr-3)*so(nr-2) - so(nr-1) ;
56 
57  so = res ;
58  return LEG ;
59 }
60 
61 int mult_xm1_1d (int base, Array<double>& so) {
62  static int (*mult_xm1_1d[NBR_MAX_BASE])(Array<double>&) ;
63  static bool premier_appel = true ;
64 
65  // Premier appel
66  if (premier_appel) {
67  premier_appel = false ;
68 
69  for (int i=0; i<NBR_MAX_BASE; i++)
70  mult_xm1_1d[i] = mult_xm1_1d_pasprevu ;
71 
72  mult_xm1_1d[CHEB] = mult_xm1_1d_cheb ;
73  mult_xm1_1d[LEG] = mult_xm1_1d_leg ;;
74  }
75 
76  return mult_xm1_1d[base](so) ;
77 }}