KADATH
coef.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 "array.hpp"
22 #include "array.hpp"
23 #include "array_math.hpp"
24 
25 namespace Kadath {
26 void coef_1d (int, Array<double>&) ;
27 
28 void Base_spectral::coef_dim (int dim, int nbr_coef, Array<double> *& inout) const {
29 
30  Dim_array res_out(inout->get_dimensions()) ;
31  res_out.set(dim) = nbr_coef ;
32  Array<double> res (res_out) ;
33 
34  int after = 1 ;
35  for (int i=0 ; i<dim ; i++)
36  after *= inout->get_size(i) ;
37 
38  int before = 1 ;
39  for (int i=dim+1 ; i<ndim ; i++)
40  before *= inout->get_size(i) ;
41 
42  int nbr_conf = inout->get_size(dim) ;
43  int nbr = (nbr_coef > nbr_conf) ? nbr_coef : nbr_conf ;
44 
45  Array_iterator index_base (bases_1d[dim]->get_dimensions()) ;
46 
47  Array_iterator demarre_conf (inout->get_dimensions()) ;
48  Array_iterator demarre_coef (res_out) ;
49 
50  Array_iterator loop_before_conf (inout->get_dimensions()) ;
51  Array_iterator loop_before_out (res_out) ;
52 
53  Array_iterator lit_in (inout->get_dimensions()) ;
54  Array_iterator put_out (res_out) ;
55 
56  Array<double> tab_1d (nbr) ;
57 
58  // Loop on dimensions before
59  for (int i=0 ; i<before ; i++) {
60 
61  demarre_conf.set(loop_before_conf) ;
62  demarre_coef.set(loop_before_out) ;
63  // On get la base
64 
65  int base = (*bases_1d[dim])(index_base) ;
66  // Loop on dimensions after :
67  for (int j=0 ; j<after ; j++) {
68 
69  lit_in = demarre_conf ;
70  for (int k=0 ; k<nbr_conf ; k++) {
71  tab_1d.set(k) = (*inout)(lit_in) ;
72  lit_in.inc(after) ;
73  }
74 
75  // Transformation
76  coef_1d(base, tab_1d) ;
77 
78  // On range :
79  put_out.set(demarre_coef) ;
80  for (int k=0 ; k<nbr_coef ; k++) {
81  res.set(put_out) = tab_1d(k) ;
82  put_out.inc(after) ;
83  }
84  demarre_conf.inc() ;
85  demarre_coef.inc() ;
86  }
87  index_base.inc() ;
88  loop_before_conf.inc1( dim+1) ;
89  loop_before_out.inc1( dim+1) ;
90  }
91 
92  delete inout ;
93  inout = new Array<double>(res) ;
94 }
95 
96 Array<double> Base_spectral::coef (const Dim_array& in_coef, const Array<double>& coloc) const {
97  // Recopie
98  Array<double>* cf = new Array<double> (coloc) ;
99  for (int d=ndim-1 ; d>=0 ; d--)
100  coef_dim(d, in_coef(d), cf) ;
101  Array<double> res (*cf) ;
102  delete cf ;
103  return res ;
104 }
105 
106 }
107 
Version of the Index class optimized for incremental access to Array components.
bool inc(int increm, int var=0)
Increments the position of the Array_iterator.
Array_iterator & set(Array_iterator const &_so)
Set the position of the iterator at the same as the one of the source.
bool inc1(int var)
Optimized unit increment with respect to the passed index number.
reference set(const Index &pos)
Read/write of an element.
Definition: array.hpp:186
int get_size(int i) const
Returns the size of a given dimension.
Definition: array.hpp:331
const Dim_array & get_dimensions() const
Returns the Dim_array of the Array.
Definition: array.hpp:335
Array< double > coef(const Dim_array &nbr_coefs, const Array< double > &so) const
Definition: coef.cpp:96
Bases_container bases_1d
Arrays containing the various basis of decomposition.
void coef_dim(int var, int nbr, Array< double > *&tab) const
Definition: coef.cpp:28
int ndim
Number of dimensions.
Class for storing the dimensions of an array.
Definition: dim_array.hpp:34
int & set(int i)
Read/write of the size of a given dimension.
Definition: dim_array.hpp:54