KADATH
domain_shell_symphi_nbr_conditions.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 namespace Kadath {
28 
29  int res = 0 ;
30 
31  Index pos (nbr_coefs) ;
32  do {
33  bool indic = true ;
34 
35  int mquant ;
36  // Base in phi
37  int basep = (*so.get_base().bases_1d[2]) (0) ;
38  switch (basep) {
39  case COS_EVEN:
40  mquant = 2*pos(2) ;
41  break ;
42  case COS_ODD:
43  if (pos(2)==nbr_coefs(2)-1)
44  indic = false ;
45  mquant = 2*pos(2)+1 ;
46  break ;
47  case SIN_EVEN:
48  if ((pos(2)==0) || (pos(2)==nbr_coefs(2)-1))
49  indic = false ;
50  mquant = 2*pos(2) ;
51  break ;
52  case SIN_ODD:
53  if (pos(2)==nbr_coefs(2)-1)
54  indic = false ;
55  mquant = 2*pos(2)+1 ;
56  break ;
57  default:
58  cerr << "Unknow phi basis in Domain_shell_symphi::nbr_unknowns_val_domain" << endl ;
59  abort() ;
60  }
61 
62  // Get base in theta :
63  int baset = (*so.get_base().bases_1d[1]) (pos(2)) ;
64  if (indic) {
65  switch (baset) {
66  case COS_EVEN:
67  if ((pos(1)==0) && (mquant>0))
68  indic = false ;
69  break ;
70  case COS_ODD:
71  if ((pos(1)==nbr_coefs(1)-1) || ((pos(1)==0) && (mquant>0)))
72  indic = false ;
73  break ;
74  case SIN_EVEN:
75  if (((pos(1)==1) && (mquant>1)) || (pos(1)==0) || (pos(1)==nbr_coefs(1)-1))
76  indic = false ;
77  break ;
78  case SIN_ODD:
79  if (((pos(1)==0) && (mquant>1)) || (pos(1)==nbr_coefs(1)-1))
80  indic = false ;
81  break ;
82  default:
83  cerr << "Unknow theta basis in Domain_shell_symphi::nbr_unknowns_val_domain" << endl ;
84  abort() ;
85  }
86  }
87 
88  // Order with respect to r :
89  if (pos(0)>nbr_coefs(0)-order-1)
90  indic = false ;
91 
92 
93  if (indic)
94  res ++ ;
95  }
96  while (pos.inc()) ;
97  return res ;
98 }
99 
100 Array<int> Domain_shell_symphi::nbr_conditions (const Tensor& tt, int dom, int order, int n_cmp, Array<int>** p_cmp) const {
101 
102  int size = (n_cmp==-1) ? tt.get_n_comp() : n_cmp ;
103  Array<int> res (size) ;
104  int val = tt.get_valence() ;
105  switch (val) {
106  case 0 :
107  res.set(0) = nbr_conditions_val_domain (tt()(dom), order) ;
108  break ;
109  case 1 : {
110  bool found = false ;
111  // Cartesian basis
112  if (tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) {
113  if (n_cmp==-1) {
114  res.set(0) = nbr_conditions_val_domain (tt(1)(dom), order) ;
115  res.set(1) = nbr_conditions_val_domain (tt(2)(dom), order) ;
116  res.set(2) = nbr_conditions_val_domain (tt(3)(dom), order) ;
117  }
118  else for (int i=0 ; i<n_cmp ; i++) {
119  if ((*p_cmp[i])(0)==1)
120  res.set(i) = nbr_conditions_val_domain (tt(1)(dom), order) ;
121  if ((*p_cmp[i])(0)==2)
122  res.set(i) = nbr_conditions_val_domain (tt(2)(dom), order) ;
123  if ((*p_cmp[i])(0)==3)
124  res.set(i) = nbr_conditions_val_domain (tt(3)(dom), order) ;
125  }
126  found = true ;
127  }
128 
129  if (!found) {
130  cerr << "Unknown type of vector Domain_shell_symphi::nbr_conditions" << endl ;
131  abort() ;
132  }
133  }
134  break ;
135  case 2 : {
136  bool found = false ;
137  // Cartesian basis and symetric
138  if ((tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) && (tt.get_n_comp()==6)) {
139  if (n_cmp==-1) {
140  res.set(0) = nbr_conditions_val_domain (tt(1,1)(dom), order) ;
141  res.set(1) = nbr_conditions_val_domain (tt(1,2)(dom), order) ;
142  res.set(2) = nbr_conditions_val_domain (tt(1,3)(dom), order) ;
143  res.set(3) = nbr_conditions_val_domain (tt(2,2)(dom), order) ;
144  res.set(4) = nbr_conditions_val_domain (tt(2,3)(dom), order) ;
145  res.set(5) = nbr_conditions_val_domain (tt(3,3)(dom), order) ;
146  }
147  else for (int i=0 ; i<n_cmp ; i++) {
148  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==1))
149  res.set(i) = nbr_conditions_val_domain (tt(1, 1)(dom), order) ;
150  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==2))
151  res.set(i) = nbr_conditions_val_domain (tt(1, 2)(dom), order) ;
152  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==3))
153  res.set(i) = nbr_conditions_val_domain (tt(1, 3)(dom), order) ;
154  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==2))
155  res.set(i) = nbr_conditions_val_domain (tt(2, 2)(dom), order) ;
156  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==3))
157  res.set(i) = nbr_conditions_val_domain (tt(2, 3)(dom), order) ;
158  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==3))
159  res.set(i) = nbr_conditions_val_domain (tt(3, 3)(dom), order) ;
160  }
161  found = true ;
162  }
163  // Cartesian basis and not symetric
164  if ((tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) && (tt.get_n_comp()==9)) {
165  if (n_cmp==-1) {
166  res.set(0) = nbr_conditions_val_domain (tt(1,1)(dom), order) ;
167  res.set(1) = nbr_conditions_val_domain (tt(1,2)(dom), order) ;
168  res.set(2) = nbr_conditions_val_domain (tt(1,3)(dom), order) ;
169  res.set(3) = nbr_conditions_val_domain (tt(2,1)(dom), order) ;
170  res.set(4) = nbr_conditions_val_domain (tt(2,2)(dom), order) ;
171  res.set(5) = nbr_conditions_val_domain (tt(2,3)(dom), order) ;
172  res.set(6) = nbr_conditions_val_domain (tt(3,1)(dom), order) ;
173  res.set(7) = nbr_conditions_val_domain (tt(3,2)(dom), order) ;
174  res.set(8) = nbr_conditions_val_domain (tt(3,3)(dom), order) ;
175  }
176  else for (int i=0 ; i<n_cmp ; i++) {
177  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==1))
178  res.set(i) = nbr_conditions_val_domain (tt(1, 1)(dom), order) ;
179  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==2))
180  res.set(i) = nbr_conditions_val_domain (tt(1, 2)(dom), order) ;
181  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==3))
182  res.set(i) = nbr_conditions_val_domain (tt(1, 3)(dom), order) ;
183  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==1))
184  res.set(i) = nbr_conditions_val_domain (tt(2, 1)(dom), order) ;
185  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==2))
186  res.set(i) = nbr_conditions_val_domain (tt(2, 2)(dom), order) ;
187  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==3))
188  res.set(i) = nbr_conditions_val_domain (tt(2, 3)(dom), order) ;
189  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==1))
190  res.set(i) = nbr_conditions_val_domain (tt(3, 1)(dom), order) ;
191  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==2))
192  res.set(i) = nbr_conditions_val_domain (tt(3, 2)(dom), order) ;
193  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==3))
194  res.set(i) = nbr_conditions_val_domain (tt(3, 3)(dom), order) ;
195  }
196  found = true ;
197  }
198  if (!found) {
199  cerr << "Unknown type of 2-tensor Domain_shell_symphi::nbr_conditions" << endl ;
200  abort() ;
201  }
202  }
203  break ;
204  default :
205  cerr << "Valence " << val << " not implemented in Domain_shell_symphi::nbr_conditions" << endl ;
206  break ;
207  }
208  return res ;
209 }}
reference set(const Index &pos)
Read/write of an element.
Definition: array.hpp: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_conditions_val_domain(const Val_domain &eq, int order) const
Computes number of discretized equations associated with a given tensorial equation in the bulk.
virtual Array< int > nbr_conditions(const Tensor &, int, int, int n_cmp=-1, Array< int > **p_cmp=0x0) const
Computes number of discretized equations associated with a given tensorial equation in the bulk.
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
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
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