KADATH
domain_polar_periodic_nucleus_nbr_unknowns.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 "polar_periodic.hpp"
22 #include "point.hpp"
23 #include "array_math.hpp"
24 #include "scalar.hpp"
25 #include "tensor_impl.hpp"
26 #include "tensor.hpp"
27 
28 namespace Kadath {
30 
31  int res = 0 ;
32  Index pos (nbr_coefs) ;
33  do {
34  bool indic = true ;
35 
36  // Base in time
37  int basetime = (*so.get_base().bases_1d[2]) (0) ;
38  switch (basetime) {
39  case COS:
40  break ;
41  case SIN:
42  if ((pos(2)==0) || (pos(2)==nbr_coefs(2)-1))
43  indic = false ;
44  break ;
45  default:
46  cerr << "Unknow time basis in Domain_polar_polar_nucleus::nbr_unknowns_val_domain" << endl ;
47  abort() ;
48  }
49 
50  // Get base in theta :
51  int baset = (*so.get_base().bases_1d[1]) (pos(2)) ;
52  int lquant ;
53  switch (baset) {
54  case COS_EVEN:
55  lquant = 2*pos(1) ;
56  break ;
57  case COS_ODD:
58  if (pos(1)==nbr_coefs(1)-1)
59  indic = false ;
60  lquant = 2*pos(1)+1 ;
61  break ;
62  case SIN_EVEN:
63  if ((pos(1)==0) || (pos(1)==nbr_coefs(1)-1))
64  indic = false ;
65  lquant = 2*pos(1) ;
66  break ;
67  case SIN_ODD:
68  if (pos(1)==nbr_coefs(1)-1)
69  indic = false ;
70  lquant = 2*pos(1)+1 ;
71  break ;
72  default:
73  cerr << "Unknow theta basis in Domain_polar_periodic_nucleus::nbr_unknowns_val_domain" << endl ;
74  abort() ;
75  }
76 
77  if (indic) {
78 
79  // Base in r :
80  int baser = (*so.get_base().bases_1d[0]) (pos(1), pos(2)) ;
81  switch (baser) {
82  case CHEB_EVEN :
83  if ((pos(0)==0) && (lquant>llim))
84  indic = false ;
85  break ;
86  case LEG_EVEN :
87  if ((pos(0)==0) && (lquant>llim))
88  indic = false ;
89  break ;
90  case CHEB_ODD :
91  if (((pos(0)==0) && (lquant>llim)) || (pos(0) == nbr_coefs(0)-1))
92  indic = false ;
93  break ;
94  case LEG_ODD :
95  if (((pos(0)==0) && (lquant>llim)) || (pos(0) == nbr_coefs(0)-1))
96  indic = false ;
97  break ;
98  default :
99  cerr << "Unknown base in Domain_polar_periodic_nucleus::nbr_unknowns_val_domain" << endl ;
100  abort() ;
101  }
102  }
103 
104  if (indic)
105  res ++ ;
106  }
107  while (pos.inc()) ;
108 
109  return res ;
110 }
111 
112 int Domain_polar_periodic_nucleus::nbr_unknowns (const Tensor& tt, int dom) const {
113 
114  // Check right domain
115  assert (tt.get_space().get_domain(dom)==this) ;
116 
117  int res = 0 ;
118  int val = tt.get_valence() ;
119  switch (val) {
120  case 0 :
121  res += nbr_unknowns_val_domain (tt()(dom), 0) ;
122  break ;
123  case 1 :
124  res += nbr_unknowns_val_domain (tt(1)(dom), 2) ;
125  res += nbr_unknowns_val_domain (tt(2)(dom), 2) ;
126  res += nbr_unknowns_val_domain (tt(3)(dom), 2) ;
127  break ;
128  case 2 :
129  if (tt.get_n_comp()==6) {
130  res += nbr_unknowns_val_domain (tt(1,1)(dom), 2) ;
131  res += nbr_unknowns_val_domain (tt(1,2)(dom), 2) ;
132  res += nbr_unknowns_val_domain (tt(1,3)(dom), 2) ;
133  res += nbr_unknowns_val_domain (tt(2,2)(dom), 2) ;
134  res += nbr_unknowns_val_domain (tt(2,3)(dom), 2) ;
135  res += nbr_unknowns_val_domain (tt(3,3)(dom), 2) ;
136  }
137  else {
138  res += nbr_unknowns_val_domain (tt(1,1)(dom), 2) ;
139  res += nbr_unknowns_val_domain (tt(1,2)(dom), 2) ;
140  res += nbr_unknowns_val_domain (tt(1,3)(dom), 2) ;
141  res += nbr_unknowns_val_domain (tt(2,1)(dom), 2) ;
142  res += nbr_unknowns_val_domain (tt(2,2)(dom), 2) ;
143  res += nbr_unknowns_val_domain (tt(2,3)(dom), 2) ;
144  res += nbr_unknowns_val_domain (tt(3,1)(dom), 2) ;
145  res += nbr_unknowns_val_domain (tt(3,2)(dom), 2) ;
146  res += nbr_unknowns_val_domain (tt(3,3)(dom), 2) ;
147  }
148  break ;
149  default :
150  cerr << "Valence " << val << " not implemented in Domain_polar_periodic_nucleus::nbr_unknowns" << endl ;
151  break ;
152  }
153  return res ;
154 }}
Bases_container bases_1d
Arrays containing the various basis of decomposition.
int nbr_unknowns_val_domain(const Val_domain &so, int llim) const
Computes the number of true unknowns of a Val_domain.
virtual int nbr_unknowns(const Tensor &, int) const
Computes the number of true unknowns of a Tensor, in a given domain.
Dim_array nbr_coefs
Number of coefficients.
Definition: space.hpp:66
Class that gives the position inside a multi-dimensional Array.
Definition: index.hpp:38
bool inc(int increm, int var=0)
Increments the position of the Index.
Definition: index.hpp:99
const Domain * get_domain(int i) const
returns a pointer on the domain.
Definition: space.hpp:1385
Tensor handling.
Definition: tensor.hpp:149
int get_n_comp() const
Returns the number of stored components.
Definition: tensor.hpp:514
int get_valence() const
Returns the valence.
Definition: tensor.hpp:509
const Space & get_space() const
Returns the Space.
Definition: tensor.hpp:499
Class for storing the basis of decompositions of a field and its values on both the configuration and...
Definition: val_domain.hpp:69
const Base_spectral & get_base() const
Returns the basis of decomposition.
Definition: val_domain.hpp:122