KADATH
ope_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 "headcpp.hpp"
21 #include "val_domain.hpp"
22 #include "scalar.hpp"
23 #include "tensor_impl.hpp"
24 
25 namespace Kadath {
27  int var, const Array<double>& in, Base_spectral& base_out) const {
28 
29  Array<double> res (in.get_dimensions()) ;
30 
31  int after = 1 ;
32  for (int i=0 ; i<var ; i++)
33  after *= in.get_size(i) ;
34 
35  int before = 1 ;
36  for (int i=var+1 ; i<ndim ; i++)
37  before *= in.get_size(i) ;
38 
39  int nbr = in.get_size(var) ;
40 
41  Array_iterator index_base (bases_1d[var]->get_dimensions()) ;
42 
43  Array_iterator demarre(in.get_dimensions()) ;
44  Array_iterator loop_before (in.get_dimensions()) ;
45 
46  Array_iterator lit (in.get_dimensions()) ;
47  Array_iterator put (in.get_dimensions()) ;
48 
49  Array<double> tab_1d (nbr) ;
50 
51  // Loop on dimensions before
52  for (int i=0 ; i<before ; i++) {
53 
54  demarre.set(loop_before) ;
55  // On get la base
56 
57  int base = (*bases_1d[var])(index_base) ;
58  // Loop on dimensions after :
59  for (int j=0 ; j<after ; j++) {
60 
61  lit.set(demarre) ;
62  for (int k=0 ; k<nbr ; k++) {
63  tab_1d.set(k) = in(lit) ;
64  lit.inc(after) ;
65  }
66  // Transformation
67  base_out.bases_1d[var]->set(index_base) = func(base, tab_1d) ;
68 
69  // On range :
70  put.set(demarre) ;
71  for (int k=0 ; k<nbr ; k++) {
72  res.set(put) = tab_1d(k) ;
73  put.inc(after) ;
74  }
75 
76  demarre.inc() ;
77  }
78  index_base.inc() ;
79  loop_before.inc1( var+1) ;
80  }
81 
82  return res ;
83 }
84 
85 }
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
Class for storing the basis of decompositions of a field.
Bases_container bases_1d
Arrays containing the various basis of decomposition.
int ndim
Number of dimensions.
Array< double > ope_1d(int(*function)(int, Array< double > &), int var, const Array< double > &so, Base_spectral &base) const
One-dimensional operator acting in the coefficient space.
Definition: ope_1d.cpp:26