KADATH
domain_compact_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_compact_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  if (indic) {
67  switch (baset) {
68  case COS_EVEN:
69  if ((pos(1)==0) && (mquant>0))
70  indic = false ;
71  break ;
72  case COS_ODD:
73  if ((pos(1)==nbr_coefs(1)-1) || ((pos(1)==0) && (mquant>0)))
74  indic = false ;
75  break ;
76  case SIN_EVEN:
77  if (((pos(1)==1) && (mquant>1)) || (pos(1)==0) || (pos(1)==nbr_coefs(1)-1))
78  indic = false ;
79  break ;
80  case SIN_ODD:
81  if (((pos(1)==0) && (mquant>1)) || (pos(1)==nbr_coefs(1)-1))
82  indic = false ;
83  break ;
84  default:
85  cerr << "Unknow theta basis in Domain_compact_symphi::nbr_unknowns_val_domain" << endl ;
86  abort() ;
87  }
88  }
89 
90  if (indic)
91  res ++ ;
92  }
93  while (pos.inc()) ;
94 
95  return res ;
96 }
97 
98 int Domain_compact_symphi::nbr_unknowns (const Tensor& tt, int dom) const {
99 
100  // Check right domain
101  assert (tt.get_space().get_domain(dom)==this) ;
102 
103  int res = 0 ;
104  int val = tt.get_valence() ;
105  switch (val) {
106  case 0 :
107  res += nbr_unknowns_val_domain (tt()(dom)) ;
108  break ;
109  case 1 : {
110  bool found = false ;
111  // Cartesian basis
112  if (tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) {
113  res += nbr_unknowns_val_domain (tt(1)(dom)) ;
114  res += nbr_unknowns_val_domain (tt(2)(dom)) ;
115  res += nbr_unknowns_val_domain (tt(3)(dom)) ;
116  found = true ;
117  }
118  if (!found) {
119  cerr << "Unknown type of vector Domain_compact_symphi::nbr_unknowns" << endl ;
120  abort() ;
121  }
122  }
123  break ;
124  case 2 : {
125  bool found = false ;
126  // Cartesian basis and symetric
127  if ((tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) && (tt.get_n_comp()==6)) {
128  res += nbr_unknowns_val_domain (tt(1,1)(dom)) ;
129  res += nbr_unknowns_val_domain (tt(1,2)(dom)) ;
130  res += nbr_unknowns_val_domain (tt(1,3)(dom)) ;
131  res += nbr_unknowns_val_domain (tt(2,2)(dom)) ;
132  res += nbr_unknowns_val_domain (tt(2,3)(dom)) ;
133  res += nbr_unknowns_val_domain (tt(3,3)(dom)) ;
134  found = true ;
135  }
136  // Cartesian basis and not symetric
137  if ((tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) && (tt.get_n_comp()==9)) {
138  for (int i=1 ; i<=3 ; i++)
139  for (int j=1 ; j<=3 ; j++)
140  res += nbr_unknowns_val_domain (tt(i,j)(dom)) ;
141  found = true ;
142  }
143 
144  if (!found) {
145  cerr << "Unknown type of 2-tensor Domain_compact_symphi::nbr_unknowns" << endl ;
146  abort() ;
147  }
148  }
149  break ;
150  default :
151  cerr << "Valence " << val << " not implemented in Domain_compact_symphi::nbr_unknowns" << endl ;
152  break ;
153  }
154  return res ;
155 }}
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) 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