KADATH
domain_shell_outer_adapted_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 "adapted.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  int kmin = 2*mlim + 2 ;
33 
34  Index pos (nbr_coefs) ;
35  do {
36  bool indic = true ;
37  // True coef in phi ?
38  if ((pos(2)==1) || (pos(2)==nbr_coefs(2)-1))
39  indic = false ;
40  // Get base in theta :
41  int baset = (*so.get_base().bases_1d[1]) (pos(2)) ;
42  switch (baset) {
43  case COS_EVEN:
44  if ((pos(1)==0) && (pos(2)>=kmin))
45  indic = false ;
46  break ;
47  case COS_ODD:
48  if ((pos(1)==nbr_coefs(1)-1) || ((pos(1)==0) && (pos(2)>=kmin)))
49  indic = false ;
50  break ;
51  case SIN_EVEN:
52  if (((pos(1)==1)&&(pos(2)>=kmin+2)) || (pos(1)==0) || (pos(1)==nbr_coefs(1)-1))
53  indic = false ;
54  break ;
55  case SIN_ODD:
56  if (((pos(1)==0)&&(pos(2)>=kmin+2)) || (pos(1)==nbr_coefs(1)-1))
57  indic = false ;
58  break ;
59  default:
60  cerr << "Unknow theta basis in Domain_shell_outer_adapted::nbr_unknowns_val_domain" << endl ;
61  abort() ;
62  }
63  if (indic)
64  res ++ ;
65  }
66  while (pos.inc()) ;
67 
68  return res ;
69 }
70 
71 int Domain_shell_outer_adapted::nbr_unknowns (const Tensor& tt, int dom) const {
72 
73  // Check right domain
74  assert (tt.get_space().get_domain(dom)==this) ;
75 
76  int res = 0 ;
77  int val = tt.get_valence() ;
78  switch (val) {
79  case 0 :
80  res += nbr_unknowns_val_domain (tt()(dom), 0) ;
81  break ;
82  case 1 : {
83  bool found = false ;
84  // Cartesian basis
85  if (tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) {
86  res += nbr_unknowns_val_domain (tt(1)(dom), 0) ;
87  res += nbr_unknowns_val_domain (tt(2)(dom), 0) ;
88  res += nbr_unknowns_val_domain (tt(3)(dom), 0) ;
89  found = true ;
90  }
91  // Spherical coordinates
92  if (tt.get_basis().get_basis(dom)==SPHERICAL_BASIS) {
93  res += nbr_unknowns_val_domain (tt(1)(dom), 0) ;
94  res += nbr_unknowns_val_domain (tt(2)(dom), 1) ;
95  res += nbr_unknowns_val_domain (tt(3)(dom), 1) ;
96  found = true ;
97  }
98  if (!found) {
99  cerr << "Unknown type of vector Domain_shell_outer_adapted::nbr_unknowns" << endl ;
100  abort() ;
101  }
102  }
103  break ;
104  case 2 : {
105  bool found = false ;
106  // Cartesian basis and symetric
107  if ((tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) && (tt.get_n_comp()==6)) {
108  res += nbr_unknowns_val_domain (tt(1,1)(dom), 0) ;
109  res += nbr_unknowns_val_domain (tt(1,2)(dom), 0) ;
110  res += nbr_unknowns_val_domain (tt(1,3)(dom), 0) ;
111  res += nbr_unknowns_val_domain (tt(2,2)(dom), 0) ;
112  res += nbr_unknowns_val_domain (tt(2,3)(dom), 0) ;
113  res += nbr_unknowns_val_domain (tt(3,3)(dom), 0) ;
114  found = true ;
115  }
116  // Cartesian basis and not symetric
117  if ((tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) && (tt.get_n_comp()==9)) {
118  for (int i=1 ; i<=3 ; i++)
119  for (int j=1 ; j<=3 ; j++)
120  res += nbr_unknowns_val_domain (tt(i,j)(dom), 0) ;
121  found = true ;
122  }
123  // Spherical coordinates and symetric
124  if ((tt.get_basis().get_basis(dom)==SPHERICAL_BASIS) && (tt.get_n_comp()==6)) {
125  res += nbr_unknowns_val_domain (tt(1,1)(dom), 0) ;
126  res += nbr_unknowns_val_domain (tt(1,2)(dom), 1) ;
127  res += nbr_unknowns_val_domain (tt(1,3)(dom), 1) ;
128  res += nbr_unknowns_val_domain (tt(2,2)(dom), 2) ;
129  res += nbr_unknowns_val_domain (tt(2,3)(dom), 2) ;
130  res += nbr_unknowns_val_domain (tt(3,3)(dom), 2) ;
131  found = true ;
132  }
133  // Spherical coordinates and not symetric
134  if ((tt.get_basis().get_basis(dom)==SPHERICAL_BASIS) && (tt.get_n_comp()==9)) {
135  res += nbr_unknowns_val_domain (tt(1,1)(dom), 0) ;
136  res += nbr_unknowns_val_domain (tt(1,2)(dom), 1) ;
137  res += nbr_unknowns_val_domain (tt(1,3)(dom), 1) ;
138  res += nbr_unknowns_val_domain (tt(2,1)(dom), 1) ;
139  res += nbr_unknowns_val_domain (tt(2,2)(dom), 2) ;
140  res += nbr_unknowns_val_domain (tt(2,3)(dom), 2) ;
141  res += nbr_unknowns_val_domain (tt(3,1)(dom), 1) ;
142  res += nbr_unknowns_val_domain (tt(3,2)(dom), 2) ;
143  res += nbr_unknowns_val_domain (tt(3,3)(dom), 2) ;
144  found = true ;
145  }
146  if (!found) {
147  cerr << "Unknown type of 2-tensor Domain_shell_outer_adapted::nbr_unknowns" << endl ;
148  abort() ;
149  }
150  }
151  break ;
152  default :
153  cerr << "Valence " << val << " not implemented in Domain_shell_outer_adapted::nbr_unknowns" << endl ;
154  break ;
155  }
156  return res ;
157 }
158 }
159 
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
virtual int nbr_unknowns(const Tensor &, int) const
Computes the number of true unknowns of a Tensor, in a given domain.
int nbr_unknowns_val_domain(const Val_domain &so, int mlim) const
Computes the number of true unknowns of a Val_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