KADATH
domain_bispheric_rect_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 "bispheric.hpp"
22 #include "scalar.hpp"
23 #include "tensor_impl.hpp"
24 #include "tensor.hpp"
25 
26 namespace Kadath {
28 
29  int res = 0 ;
30  int basep = (*so.get_base().bases_1d[2]) (0) ;
31 
32  Index pos (nbr_coefs) ;
33  do {
34  bool indic = true ;
35  switch (basep) {
36  case COS :
37  // Last odd ones
38  if ((pos(2)%2==1) && (pos(1)==nbr_coefs(1)-1))
39  indic = false ;
40  // Regularity for even ones :
41  if ((pos(2)!=0) && (pos(2)%2==0) && (pos(1)==0))
42  indic = false ;
43  break ;
44  case SIN :
45  // sin(0)
46  if ((pos(2)==0) || (pos(2)==nbr_coefs(2)-1))
47  indic = false ;
48  // Last odd ones :
49  if ((pos(2)%2==1) && (pos(1)==nbr_coefs(1)-1))
50  indic = false ;
51  // Regularity for even ones :
52  if ((pos(2)%2==0) && (pos(1)==0))
53  indic = false ;
54  break ;
55  default :
56  cerr << "Unknown phi basis in Domain_bispheric_rect::nbr_unknowns_val_domain" << endl ;
57  abort() ;
58  }
59  if (indic)
60  res ++ ;
61  }
62  while (pos.inc()) ;
63 
64  return res ;
65 }
66 
67 int Domain_bispheric_rect::nbr_unknowns (const Tensor& tt, int dom) const {
68 
69  // Check right domain
70  assert (tt.get_space().get_domain(dom)==this) ;
71 
72  int res = 0 ;
73  int val = tt.get_valence() ;
74  switch (val) {
75  case 0 :
76  res += nbr_unknowns_val_domain (tt()(dom)) ;
77  break ;
78  case 1 : {
79  bool found = false ;
80  // Cartesian basis
81  if (tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) {
82  res += nbr_unknowns_val_domain (tt(1)(dom)) ;
83  res += nbr_unknowns_val_domain (tt(2)(dom)) ;
84  res += nbr_unknowns_val_domain (tt(3)(dom)) ;
85  found = true ;
86  }
87  if (!found) {
88  cerr << "Unknown type of vector Domain_bispheric_rect::nbr_unknowns" << endl ;
89  abort() ;
90  }
91  }
92  break ;
93  case 2 : {
94  bool found = false ;
95  // Cartesian basis and symetric
96  if ((tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) && (tt.get_n_comp()==6)) {
97  res += nbr_unknowns_val_domain (tt(1,1)(dom)) ;
98  res += nbr_unknowns_val_domain (tt(1,2)(dom)) ;
99  res += nbr_unknowns_val_domain (tt(1,3)(dom)) ;
100  res += nbr_unknowns_val_domain (tt(2,2)(dom)) ;
101  res += nbr_unknowns_val_domain (tt(2,3)(dom)) ;
102  res += nbr_unknowns_val_domain (tt(3,3)(dom)) ;
103  found = true ;
104  }
105  // Cartesian basis and not symetric
106  if ((tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) && (tt.get_n_comp()==9)) {
107  for (int i=1 ; i<=3 ; i++)
108  for (int j=1 ; j<=3 ; j++)
109  res += nbr_unknowns_val_domain (tt(i,j)(dom)) ;
110  found = true ;
111  }
112  if (!found) {
113  cerr << "Unknown type of 2-tensor Domain_bispheric_rect::nbr_unknowns" << endl ;
114  abort() ;
115  }
116  }
117  break ;
118  default :
119  cerr << "Valence " << val << " not implemented in Domain_bispheric_rect::nbr_unknowns" << endl ;
120  break ;
121  }
122  return res ;
123 }}
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