KADATH
div_1mx2.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_1mx2_1d_pasprevu (Array<double>&) {
26  cout << "div_1mx2_1d not implemented." << endl ;
27  abort() ;
28 }
29 
30 
31 int div_1mx2_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 = 0 ;
36  for (int n=0 ; n<nr ; n++)
37  for (int p=n+2 ; p<nr ; p+=2)
38  res.set(n) += -2*(p-n)*so(p) ;
39  res.set(0) *= 0.5 ;
40 
41  so = res ;
42  return CHEB ;
43 }
44 
45 int div_1mx2_1d_cheb_even (Array<double>& so) {
46  assert (so.get_ndim()==1) ;
47  int nr = so.get_size(0) ;
48  Array<double> res (nr) ;
49  res = 0 ;
50  for (int n=0 ; n<nr ; n++)
51  for (int p=n+1 ; p<nr ; p++)
52  res.set(n) += -4*(p-n)*so(p) ;
53  res.set(0) *= 0.5 ;
54 
55  so = res ;
56  return CHEB_EVEN ;
57 }
58 
59 int div_1mx2_1d_cheb_odd (Array<double>& so) {
60  assert (so.get_ndim()==1) ;
61  int nr = so.get_size(0) ;
62  Array<double> res (nr) ;
63  res = 0 ;
64  for (int n=0 ; n<nr ; n++)
65  for (int p=n+1 ; p<nr ; p++)
66  res.set(n) += -4*(p-n)*so(p) ;
67 
68  so = res ;
69  return CHEB_ODD ;
70 }
71 
72 int div_1mx2_1d (int base, Array<double>& so) {
73  static int (*div_1mx2_1d[NBR_MAX_BASE])(Array<double>&) ;
74  static bool premier_appel = true ;
75 
76  // Premier appel
77  if (premier_appel) {
78  premier_appel = false ;
79 
80  for (int i=0; i<NBR_MAX_BASE; i++)
81  div_1mx2_1d[i] = div_1mx2_1d_pasprevu ;
82 
83  div_1mx2_1d[CHEB] = div_1mx2_1d_cheb ;
84  div_1mx2_1d[CHEB_EVEN] = div_1mx2_1d_cheb_even ;
85  div_1mx2_1d[CHEB_ODD] = div_1mx2_1d_cheb_odd ;
86  }
87 
88  return div_1mx2_1d[base](so) ;
89 }}