KADATH
domain_polar_periodic_nucleus_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 "polar_periodic.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 {
29 int Domain_polar_periodic_nucleus::nbr_conditions_val_domain (const Val_domain& so, int llim, int order) const {
30  int res = 0 ;
31 
32  Index pos (nbr_coefs) ;
33  do {
34  bool indic = true ;
35 
36  // Base in time
37  int basetime = (*so.get_base().bases_1d[2]) (0) ;
38  switch (basetime) {
39  case COS:
40  break ;
41  case SIN:
42  if ((pos(2)==0) || (pos(2)==nbr_coefs(2)-1))
43  indic = false ;
44  break ;
45  default:
46  cerr << "Unknow time basis in Domain_polar_polar_nucleus::nbr_conditions_val_domain" << endl ;
47  abort() ;
48  }
49 
50 
51 
52  // Get base in theta :
53  int baset = (*so.get_base().bases_1d[1]) (pos(2)) ;
54  int lquant ;
55  switch (baset) {
56  case COS_EVEN:
57  lquant = 2*pos(1) ;
58  break ;
59  case COS_ODD:
60  if (pos(1)==nbr_coefs(1)-1)
61  indic = false ;
62  lquant = 2*pos(1)+1 ;
63  break ;
64  case SIN_EVEN:
65  if ((pos(1)==0) || (pos(1)==nbr_coefs(1)-1))
66  indic = false ;
67  lquant = 2*pos(1) ;
68  break ;
69  case SIN_ODD:
70  if (pos(1)==nbr_coefs(1)-1)
71  indic = false ;
72  lquant = 2*pos(1)+1 ;
73  break ;
74  default:
75  cerr << "Unknow theta basis in Domain_polar_periodic_nucleus::nbr_conditions_val_domain" << endl ;
76  abort() ;
77  }
78  int max = 0 ;
79  if (indic) {
80  // Base in r :
81  int baser = (*so.get_base().bases_1d[0]) (pos(1), pos(2)) ;
82  switch (baser) {
83  case CHEB_EVEN :
84  if ((pos(0)==0) && (lquant>llim))
85  indic = false ;
86  max = nbr_coefs(0) ;
87  break ;
88  case LEG_EVEN :
89  if ((pos(0)==0) && (lquant>llim))
90  indic = false ;
91  max = nbr_coefs(0) ;
92  break ;
93  case CHEB_ODD :
94  if (((pos(0)==0) && (lquant>llim)) || (pos(0) == nbr_coefs(0)-1))
95  indic = false ;
96  max = nbr_coefs(0)-1 ;
97  break ;
98  case LEG_ODD :
99  if (((pos(0)==0) && (lquant>llim)) || (pos(0) == nbr_coefs(0)-1))
100  indic = false ;
101  max = nbr_coefs(0)-1 ;
102  break ;
103  default :
104  cerr << "Unknown base in Domain_polar_periodic_nucleus::nbr_conditions_val_domain" << endl ;
105  abort() ;
106  }
107  }
108 
109  // Order with respect to r :
110  int lim = 0 ;
111  switch (order) {
112  case 2 :
113  lim = max-1 ;
114  break ;
115  case 0 :
116  lim = max ;
117  break ;
118  default :
119  cerr << "Unknown case in Domain_polar_periodic_nucleus_nbr_conditions" << endl ;
120  abort() ;
121  }
122 
123  if (pos(0)>=lim)
124  indic = false ;
125 
126  if (indic)
127  res ++ ;
128 
129  }
130  while (pos.inc()) ;
131 
132  return res ;
133 }
134 
135 Array<int> Domain_polar_periodic_nucleus::nbr_conditions (const Tensor& tt, int dom, int order, int n_cmp, Array<int>** p_cmp) const {
136 
137  int size = (n_cmp==-1) ? tt.get_n_comp() : n_cmp ;
138  Array<int> res (size) ;
139  int val = tt.get_valence() ;
140  switch (val) {
141  case 0 :
142  res.set(0) = nbr_conditions_val_domain (tt()(dom), 0, order) ;
143  break ;
144  case 1 :
145  if (n_cmp==-1) {
146  res.set(0) = nbr_conditions_val_domain (tt(1)(dom), 2, order) ;
147  res.set(1) = nbr_conditions_val_domain (tt(2)(dom), 2, order) ;
148  res.set(2) = nbr_conditions_val_domain (tt(3)(dom), 2, order) ;
149  }
150  else for (int i=0 ; i<n_cmp ; i++) {
151  if ((*p_cmp[i])(0)==1)
152  res.set(i) = nbr_conditions_val_domain (tt(1)(dom), 2, order) ;
153  if ((*p_cmp[i])(0)==2)
154  res.set(i) = nbr_conditions_val_domain (tt(2)(dom), 2, order) ;
155  if ((*p_cmp[i])(0)==3)
156  res.set(i) = nbr_conditions_val_domain (tt(3)(dom), 2, order) ;
157  }
158  break ;
159  case 2 :
160  if (tt.get_n_comp()==6) {
161  if (n_cmp==-1) {
162  res.set(0) = nbr_conditions_val_domain (tt(1,1)(dom), 2, order) ;
163  res.set(1) = nbr_conditions_val_domain (tt(1,2)(dom), 2, order) ;
164  res.set(2) = nbr_conditions_val_domain (tt(1,3)(dom), 2, order) ;
165  res.set(3) = nbr_conditions_val_domain (tt(2,2)(dom), 2, order) ;
166  res.set(4) = nbr_conditions_val_domain (tt(2,3)(dom), 2, order) ;
167  res.set(5) = nbr_conditions_val_domain (tt(3,3)(dom), 2, order) ;
168  }
169  else for (int i=0 ; i<n_cmp ; i++) {
170  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==1))
171  res.set(i) = nbr_conditions_val_domain (tt(1, 1)(dom), 2, order) ;
172  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==2))
173  res.set(i) = nbr_conditions_val_domain (tt(1, 2)(dom), 2, order) ;
174  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==3))
175  res.set(i) = nbr_conditions_val_domain (tt(1, 3)(dom), 2, order) ;
176  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==2))
177  res.set(i) = nbr_conditions_val_domain (tt(2, 2)(dom), 2, order) ;
178  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==3))
179  res.set(i) = nbr_conditions_val_domain (tt(2, 3)(dom), 2, order) ;
180  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==3))
181  res.set(i) = nbr_conditions_val_domain (tt(3, 3)(dom), 2, order) ;
182  }
183  }
184  // not symetric
185  if (tt.get_n_comp()==9) {
186  if (n_cmp==-1) {
187  res.set(0) = nbr_conditions_val_domain (tt(1,1)(dom), 2, order) ;
188  res.set(1) = nbr_conditions_val_domain (tt(1,2)(dom), 2, order) ;
189  res.set(2) = nbr_conditions_val_domain (tt(1,3)(dom), 2, order) ;
190  res.set(3) = nbr_conditions_val_domain (tt(2,1)(dom), 2, order) ;
191  res.set(4) = nbr_conditions_val_domain (tt(2,2)(dom), 2, order) ;
192  res.set(5) = nbr_conditions_val_domain (tt(2,3)(dom), 2, order) ;
193  res.set(6) = nbr_conditions_val_domain (tt(3,1)(dom), 2, order) ;
194  res.set(7) = nbr_conditions_val_domain (tt(3,2)(dom), 2, order) ;
195  res.set(8) = nbr_conditions_val_domain (tt(3,3)(dom), 2, 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), 2, 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), 2, 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), 2, order) ;
204  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==1))
205  res.set(i) = nbr_conditions_val_domain (tt(2, 1)(dom), 2, order) ;
206  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==2))
207  res.set(i) = nbr_conditions_val_domain (tt(2, 2)(dom), 2, order) ;
208  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==3))
209  res.set(i) = nbr_conditions_val_domain (tt(2, 3)(dom), 2, order) ;
210  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==1))
211  res.set(i) = nbr_conditions_val_domain (tt(3, 1)(dom), 2, order) ;
212  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==2))
213  res.set(i) = nbr_conditions_val_domain (tt(3, 2)(dom), 2, order) ;
214  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==3))
215  res.set(i) = nbr_conditions_val_domain (tt(3, 3)(dom), 2, order) ;
216  }
217  }
218  break ;
219  default :
220  cerr << "Valence " << val << " not implemented in Domain_polar_periodic_nucleus::nbr_conditions" << endl ;
221  break ;
222  }
223  return res ;
224 }}
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.
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.
int nbr_conditions_val_domain(const Val_domain &so, int llim, int order) 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
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