KADATH
div_xp1_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 namespace Kadath {
25 int div_xp1_1d_pasprevu (Array<double>&) {
26  cout << "div_xp1_1d not implemented." << endl ;
27  abort() ;
28 }
29 
30 
31 int div_xp1_1d_cheb (Array<double>& so) {
32  assert (so.get_ndim()==1) ;
33  int nr = so.get_size(0) ;
34  Array<double> res (nr) ;
35  res.set(nr-1) = 0 ;
36  res.set(nr-2) = 2*so(nr-1) ;
37  for (int i=nr-3 ; i>0 ; i--)
38  res.set(i) = 2*so(i+1) - 2*res(i+1) - res(i+2) ;
39 
40  double somme = 0 ;
41  for (int i=0 ; i<nr ; i++)
42  somme += (i%2==0) ? so(i) : -so(i) ;
43 
44  res.set(0) = so(0) - res(1)/2. - somme ;
45 
46  so = res ;
47  return CHEB ;
48 }
49 
50 int div_xp1_1d (int base, Array<double>& so) {
51  static int (*div_xp1_1d[NBR_MAX_BASE])(Array<double>&) ;
52  static bool premier_appel = true ;
53 
54  // Premier appel
55  if (premier_appel) {
56  premier_appel = false ;
57 
58  for (int i=0; i<NBR_MAX_BASE; i++)
59  div_xp1_1d[i] = div_xp1_1d_pasprevu ;
60 
61  div_xp1_1d[CHEB] = div_xp1_1d_cheb ;
62  }
63 
64  return div_xp1_1d[base](so) ;
65 }}