KADATH
domain_nucleus_symphi_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 "spheric_symphi.hpp"
22 #include "array_math.hpp"
23 #include "scalar.hpp"
24 #include "tensor_impl.hpp"
25 #include "tensor.hpp"
26 
27 namespace Kadath {
29 
30  int res = 0 ;
31 
32  Index pos (nbr_coefs) ;
33  do {
34  bool indic = true ;
35 
36  int mquant ;
37  // Base in phi
38  int basep = (*so.get_base().bases_1d[2]) (0) ;
39  switch (basep) {
40  case COS_EVEN:
41  mquant = 2*pos(2) ;
42  break ;
43  case COS_ODD:
44  if (pos(2)==nbr_coefs(2)-1)
45  indic = false ;
46  mquant = 2*pos(2)+1 ;
47  break ;
48  case SIN_EVEN:
49  if ((pos(2)==0) || (pos(2)==nbr_coefs(2)-1))
50  indic = false ;
51  mquant = 2*pos(2) ;
52  break ;
53  case SIN_ODD:
54  if (pos(2)==nbr_coefs(2)-1)
55  indic = false ;
56  mquant = 2*pos(2)+1 ;
57  break ;
58  default:
59  cerr << "Unknow phi basis in Domain_nucleus_symphi::nbr_unknowns_val_domain" << endl ;
60  abort() ;
61  }
62 
63 
64  // Get base in theta :
65  int baset = (*so.get_base().bases_1d[1]) (pos(2)) ;
66  int lquant ;
67  if (indic) {
68  switch (baset) {
69  case COS_EVEN:
70  if ((pos(1)==0) && (mquant>0))
71  indic = false ;
72  lquant = 2*pos(1) ;
73  break ;
74  case COS_ODD:
75  if ((pos(1)==nbr_coefs(1)-1) || ((pos(1)==0) && (mquant>0)))
76  indic = false ;
77  lquant = 2*pos(1)+1 ;
78  break ;
79  case SIN_EVEN:
80  if (((pos(1)==1) && (mquant>1)) || (pos(1)==0) || (pos(1)==nbr_coefs(1)-1))
81  indic = false ;
82  lquant = 2*pos(1) ;
83  break ;
84  case SIN_ODD:
85  if (((pos(1)==0) && (mquant>1)) || (pos(1)==nbr_coefs(1)-1))
86  indic = false ;
87  lquant = 2*pos(1)+1 ;
88  break ;
89  default:
90  cerr << "Unknow theta basis in Domain_nucleus_symphi::nbr_unknowns_val_domain" << endl ;
91  abort() ;
92  }
93  }
94 
95  if (indic) {
96  // Base in r :
97  int baser = (*so.get_base().bases_1d[0]) (pos(1), pos(2)) ;
98  switch (baser) {
99  case CHEB_EVEN :
100  if ((lquant>0) && (pos(0)==0))
101  indic = false ;
102  break ;
103  case LEG_EVEN :
104  if ((lquant>0) && (pos(0)==0))
105  indic = false ;
106  break ;
107  case CHEB_ODD :
108  if (((lquant>1) && (pos(0)==0)) || (pos(0)==nbr_coefs(0)-1))
109  indic = false ;
110  break ;
111  case LEG_ODD :
112  if (((lquant>1) && (pos(0)==0)) || (pos(0)==nbr_coefs(0)-1))
113  indic = false ;
114  break ;
115  default:
116  cerr << "Unknow radial basis in Domain_nucleus_symphi::nbr_unknowns_val_domain" << endl ;
117  abort() ;
118  }
119  }
120 
121  if (indic)
122  res ++ ;
123  }
124  while (pos.inc()) ;
125 
126  return res ;
127 }
128 
129 int Domain_nucleus_symphi::nbr_unknowns (const Tensor& tt, int dom) const {
130 
131  // Check right domain
132  assert (tt.get_space().get_domain(dom)==this) ;
133 
134  int res = 0 ;
135  int val = tt.get_valence() ;
136  switch (val) {
137  case 0 :
138  res += nbr_unknowns_val_domain (tt()(dom)) ;
139  break ;
140  case 1 : {
141  bool found = false ;
142  // Cartesian basis
143  if (tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) {
144  res += nbr_unknowns_val_domain (tt(1)(dom)) ;
145  res += nbr_unknowns_val_domain (tt(2)(dom)) ;
146  res += nbr_unknowns_val_domain (tt(3)(dom)) ;
147  found = true ;
148  }
149  if (!found) {
150  cerr << "Unknown type of vector Domain_nucleus_symphi::nbr_unknowns" << endl ;
151  abort() ;
152  }
153  }
154  break ;
155  case 2 : {
156  bool found = false ;
157  // Cartesian basis and symetric
158  if ((tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) && (tt.get_n_comp()==6)) {
159  res += nbr_unknowns_val_domain (tt(1,1)(dom)) ;
160  res += nbr_unknowns_val_domain (tt(1,2)(dom)) ;
161  res += nbr_unknowns_val_domain (tt(1,3)(dom)) ;
162  res += nbr_unknowns_val_domain (tt(2,2)(dom)) ;
163  res += nbr_unknowns_val_domain (tt(2,3)(dom)) ;
164  res += nbr_unknowns_val_domain (tt(3,3)(dom)) ;
165  found = true ;
166  }
167  // Cartesian basis and not symetric
168  if ((tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) && (tt.get_n_comp()==9)) {
169  for (int i=1 ; i<=3 ; i++)
170  for (int j=1 ; j<=3 ; j++)
171  res += nbr_unknowns_val_domain (tt(i,j)(dom)) ;
172  found = true ;
173  }
174 
175  if (!found) {
176  cerr << "Unknown type of 2-tensor Domain_nucleus_symphi::nbr_unknowns" << endl ;
177  abort() ;
178  }
179  }
180  break ;
181  default :
182  cerr << "Valence " << val << " not implemented in Domain_nucleus_symphi::nbr_unknowns" << endl ;
183  break ;
184  }
185  return res ;
186 }}
Bases_container bases_1d
Arrays containing the various basis of decomposition.
int get_basis(int nd) const
Read only the basis in a given domain.
Definition: base_tensor.hpp:93
int nbr_unknowns_val_domain(const Val_domain &so) 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
const Base_tensor & get_basis() const
Returns the vectorial basis (triad) on which the components are defined.
Definition: tensor.hpp:504
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