KADATH
domain_nucleus_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_nucleus_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  int lquant ;
65  if (indic) {
66  switch (baset) {
67  case COS_EVEN:
68  if ((pos(1)==0) && (mquant>0))
69  indic = false ;
70  lquant = 2*pos(1) ;
71  break ;
72  case COS_ODD:
73  if ((pos(1)==nbr_coefs(1)-1) || ((pos(1)==0) && (mquant>0)))
74  indic = false ;
75  lquant = 2*pos(1)+1 ;
76  break ;
77  case SIN_EVEN:
78  if (((pos(1)==1) && (mquant>1)) || (pos(1)==0) || (pos(1)==nbr_coefs(1)-1))
79  indic = false ;
80  lquant = 2*pos(1) ;
81  break ;
82  case SIN_ODD:
83  if (((pos(1)==0) && (mquant>1)) || (pos(1)==nbr_coefs(1)-1))
84  indic = false ;
85  lquant = 2*pos(1)+1 ;
86  break ;
87  default:
88  cerr << "Unknow theta basis in Domain_nucleus_symphi::nbr_unknowns_val_domain" << endl ;
89  abort() ;
90  }
91  }
92 
93  int max = 0;
94  if (indic) {
95  // Base in r :
96  int baser = (*so.get_base().bases_1d[0]) (pos(1), pos(2)) ;
97 
98  switch (baser) {
99  case CHEB_EVEN :
100  if ((lquant>0) && (pos(0)==0))
101  indic = false ;
102  max = nbr_coefs(0) ;
103  break ;
104  case LEG_EVEN :
105  if ((lquant>0) && (pos(0)==0))
106  indic = false ;
107  max = nbr_coefs(0) ;
108  break ;
109  case CHEB_ODD :
110  if ((lquant>1) && (pos(0)==0))
111  indic = false ;
112  max = nbr_coefs(0)-1 ;
113  break ;
114  case LEG_ODD :
115  if ((lquant>1) && (pos(0)==0))
116  indic = false ;
117  max = nbr_coefs(0)-1 ;
118  break ;
119  default:
120  cerr << "Unknow radial basis in Domain_nucleus_symphi::nbr_unknowns_val_domain" << endl ;
121  abort() ;
122  }
123  }
124 
125  // Order with respect to r :
126  int lim = 0 ;
127  switch (order) {
128  case 2 :
129  lim = max-2 ;
130  break ;
131  case 0 :
132  lim = max-1 ;
133  break ;
134  default :
135  cerr << "Unknown case in Domain_nucleus_symphi_nbr_conditions" << endl ;
136  abort() ;
137  }
138 
139 
140  if (pos(0)>lim)
141  indic = false ;
142 
143  if (indic)
144  res ++ ;
145  }
146  while (pos.inc()) ;
147  return res ;
148 }
149 
150 Array<int> Domain_nucleus_symphi::nbr_conditions (const Tensor& tt, int dom, int order, int n_cmp, Array<int>** p_cmp) const {
151 
152  int size = (n_cmp==-1) ? tt.get_n_comp() : n_cmp ;
153  Array<int> res (size) ;
154  int val = tt.get_valence() ;
155  switch (val) {
156  case 0 :
157  res.set(0) = nbr_conditions_val_domain (tt()(dom), order) ;
158  break ;
159  case 1 : {
160  bool found = false ;
161  // Cartesian basis
162  if (tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) {
163  if (n_cmp==-1) {
164  res.set(0) = nbr_conditions_val_domain (tt(1)(dom), order) ;
165  res.set(1) = nbr_conditions_val_domain (tt(2)(dom), order) ;
166  res.set(2) = nbr_conditions_val_domain (tt(3)(dom), order) ;
167  }
168  else for (int i=0 ; i<n_cmp ; i++) {
169  if ((*p_cmp[i])(0)==1)
170  res.set(i) = nbr_conditions_val_domain (tt(1)(dom), order) ;
171  if ((*p_cmp[i])(0)==2)
172  res.set(i) = nbr_conditions_val_domain (tt(2)(dom), order) ;
173  if ((*p_cmp[i])(0)==3)
174  res.set(i) = nbr_conditions_val_domain (tt(3)(dom), order) ;
175  }
176  found = true ;
177  }
178 
179  if (!found) {
180  cerr << "Unknown type of vector Domain_nucleus_symphi::nbr_conditions" << endl ;
181  abort() ;
182  }
183  }
184  break ;
185  case 2 : {
186  bool found = false ;
187  // Cartesian basis and symetric
188  if ((tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) && (tt.get_n_comp()==6)) {
189  if (n_cmp==-1) {
190  res.set(0) = nbr_conditions_val_domain (tt(1,1)(dom), order) ;
191  res.set(1) = nbr_conditions_val_domain (tt(1,2)(dom), order) ;
192  res.set(2) = nbr_conditions_val_domain (tt(1,3)(dom), order) ;
193  res.set(3) = nbr_conditions_val_domain (tt(2,2)(dom), order) ;
194  res.set(4) = nbr_conditions_val_domain (tt(2,3)(dom), order) ;
195  res.set(5) = nbr_conditions_val_domain (tt(3,3)(dom), order) ;
196  }
197  else for (int i=0 ; i<n_cmp ; i++) {
198  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==1))
199  res.set(i) = nbr_conditions_val_domain (tt(1, 1)(dom), order) ;
200  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==2))
201  res.set(i) = nbr_conditions_val_domain (tt(1, 2)(dom), order) ;
202  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==3))
203  res.set(i) = nbr_conditions_val_domain (tt(1, 3)(dom), order) ;
204  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==2))
205  res.set(i) = nbr_conditions_val_domain (tt(2, 2)(dom), order) ;
206  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==3))
207  res.set(i) = nbr_conditions_val_domain (tt(2, 3)(dom), order) ;
208  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==3))
209  res.set(i) = nbr_conditions_val_domain (tt(3, 3)(dom), order) ;
210  }
211  found = true ;
212  }
213  // Cartesian basis and not symetric
214  if ((tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) && (tt.get_n_comp()==9)) {
215  if (n_cmp==-1) {
216  res.set(0) = nbr_conditions_val_domain (tt(1,1)(dom), order) ;
217  res.set(1) = nbr_conditions_val_domain (tt(1,2)(dom), order) ;
218  res.set(2) = nbr_conditions_val_domain (tt(1,3)(dom), order) ;
219  res.set(3) = nbr_conditions_val_domain (tt(2,1)(dom), order) ;
220  res.set(4) = nbr_conditions_val_domain (tt(2,2)(dom), order) ;
221  res.set(5) = nbr_conditions_val_domain (tt(2,3)(dom), order) ;
222  res.set(6) = nbr_conditions_val_domain (tt(3,1)(dom), order) ;
223  res.set(7) = nbr_conditions_val_domain (tt(3,2)(dom), order) ;
224  res.set(8) = nbr_conditions_val_domain (tt(3,3)(dom), order) ;
225  }
226  else for (int i=0 ; i<n_cmp ; i++) {
227  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==1))
228  res.set(i) = nbr_conditions_val_domain (tt(1, 1)(dom), order) ;
229  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==2))
230  res.set(i) = nbr_conditions_val_domain (tt(1, 2)(dom), order) ;
231  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==3))
232  res.set(i) = nbr_conditions_val_domain (tt(1, 3)(dom), order) ;
233  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==1))
234  res.set(i) = nbr_conditions_val_domain (tt(2, 1)(dom), order) ;
235  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==2))
236  res.set(i) = nbr_conditions_val_domain (tt(2, 2)(dom), order) ;
237  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==3))
238  res.set(i) = nbr_conditions_val_domain (tt(2, 3)(dom), order) ;
239  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==1))
240  res.set(i) = nbr_conditions_val_domain (tt(3, 1)(dom), order) ;
241  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==2))
242  res.set(i) = nbr_conditions_val_domain (tt(3, 2)(dom), order) ;
243  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==3))
244  res.set(i) = nbr_conditions_val_domain (tt(3, 3)(dom), order) ;
245  }
246  found = true ;
247  }
248  if (!found) {
249  cerr << "Unknown type of 2-tensor Domain_nucleus_symphi::nbr_conditions" << endl ;
250  abort() ;
251  }
252  }
253  break ;
254  default :
255  cerr << "Valence " << val << " not implemented in Domain_nucleus_symphi::nbr_conditions" << endl ;
256  break ;
257  }
258  return res ;
259 }}
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