KADATH
coef_i.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_i_1d (int, Array<double>&) ;
27 
28 void Base_spectral::coef_i_dim (int dim, int nbr_conf, Array<double> *& inout) const {
29 
30  Dim_array res_out(inout->get_dimensions()) ;
31  res_out.set(dim) = nbr_conf ;
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_coef = 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_coef (inout->get_dimensions()) ;
48  Array_iterator demarre_conf (res_out) ;
49 
50  Array_iterator loop_before_coef (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_coef.set(loop_before_coef) ;
62  demarre_conf.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_coef ;
70  for (int k=0 ; k<nbr_coef ; k++) {
71  tab_1d.set(k) = (*inout)(lit_in) ;
72  lit_in.inc(after) ;
73  }
74 
75  // Transformation
76  coef_i_1d(base, tab_1d) ;
77 
78  // On range :
79  put_out.set(demarre_conf) ;
80  for (int k=0 ; k<nbr_conf ; 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_coef.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_i (const Dim_array& in_conf, const Array<double>& cof) const {
97  // Recopie
98  Array<double>* conf = new Array<double> (cof) ;
99  for (int d=0 ; d<ndim ; d++)
100  coef_i_dim(d, in_conf(d), conf) ;
101  Array<double> res (*conf) ;
102  delete conf ;
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
void coef_i_dim(int var, int nbr, Array< double > *&tab) const
Performs the inverse coefficient transformation for one particular variable.
Definition: coef_i.cpp:28
Array< double > coef_i(const Dim_array &nbr_points, const Array< double > &so) const
Definition: coef_i.cpp:96
Bases_container bases_1d
Arrays containing the various basis of decomposition.
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