KADATH
domain_bispheric_rect_nbr_conditions_boundary_one_side.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  if (bound==INNER_BC) {
33  Index pos (nbr_coefs) ;
34  // Loop on phi :
35  for (int k=0 ; k<nbr_coefs(2) ; k++) {
36  pos.set(2) = k ;
37  // Loop on chi ;
38  for (int j=0 ; j<nbr_coefs(1) ; j++) {
39  pos.set(1) = j ;
40  bool indic = true ;
41  switch (basep) {
42  case COS :
43  // Last odd ones
44  if ((pos(2)%2==1) && (pos(1)==nbr_coefs(1)-1))
45  indic = false ;
46  // Regularity for even ones :
47  if ((pos(2)!=0) && (pos(2)%2==0) && (pos(1)==0))
48  indic = false ;
49  break ;
50  case SIN :
51  // sin(0)
52  if ((pos(2)==0) || (pos(2)==nbr_coefs(2)-1))
53  indic = false ;
54  // Last odd ones :
55  if ((pos(2)%2==1) && (pos(1)==nbr_coefs(1)-1))
56  indic = false ;
57  // Regularity for even ones :
58  if ((pos(2)%2==0) && (pos(1)==0))
59  indic = false ;
60  break ;
61  default :
62  cerr << "Unknwon phi basis in Domain_bispheric_rect::nbr_conditions_val_boundary" << endl ;
63  abort() ;
64  }
65 
66  if (indic)
67  res ++ ;
68  }
69  }
70  }
71 
72  if (bound==ETA_PLUS_BC) {
73  for (int k=0 ; k<nbr_coefs(2) ; k++)
74  for (int j=0 ; j<nbr_coefs(1) ; j++) {
75  bool true_other = true ;
76  switch (basep) {
77  case COS :
78  // Last odd ones
79  if ((k%2==1) && (j==nbr_coefs(1)-2))
80  true_other = false ;
81  // Regularity for even ones :
82  if ((k!=0) && (k%2==0) && (j==0))
83  true_other = false ;
84  if (j==nbr_coefs(1)-1)
85  true_other = false ;
86  break ;
87  case SIN :
88  // sin(0)
89  if ((k==0) || (k==nbr_coefs(2)-1))
90  true_other = false ;
91  // Last odd ones :
92  if ((k%2==1) && (j==nbr_coefs(1)-2))
93  true_other = false ;
94  // Regularity for even ones :
95  if ((k%2==0) && (j==0))
96  true_other = false ;
97  if (j==nbr_coefs(1)-1)
98  true_other = false ;
99  break ;
100  default :
101  cerr << "Unknwon phi basis in Domain_bispheric_rect::nbr_conditions_vall_boundary" << endl ;
102  abort() ;
103  }
104  if (true_other)
105  res ++ ;
106  }
107  }
108 
109  if (bound==CHI_ONE_BC)
110  res = (basep==COS) ? nbr_coefs(2)*(nbr_coefs(0)-1) : (nbr_coefs(2)-2)*(nbr_coefs(0)-1) ;
111 
112  if (bound==OUTER_BC)
113  res = (basep==COS) ? nbr_coefs(2) : (nbr_coefs(2)-2) ;
114 
115  return res ;
116 }
117 
118 Array<int> Domain_bispheric_rect::nbr_conditions_boundary_one_side (const Tensor& tt, int dom, int bound, int n_cmp, Array<int>** p_cmp) const {
119 
120  // Check boundary
121  if ((bound!=INNER_BC) && (bound!=CHI_ONE_BC) && (bound!=ETA_PLUS_BC) && (bound!=OUTER_BC)) {
122  cerr << "Unknown boundary in Domain_bispheric_rect::nbr_conditions_boundary_one_side" << endl ;
123  abort() ;
124  }
125 
126  int size = (n_cmp==-1) ? tt.get_n_comp() : n_cmp ;
127  Array<int> res (size) ;
128  int val = tt.get_valence() ;
129  switch (val) {
130  case 0 :
131  res.set(0) = nbr_conditions_val_domain_boundary_one_side (tt()(dom), bound) ;
132  break ;
133  case 1 : {
134  bool found = false ;
135  // Cartesian basis
136  if (tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) {
137  if (n_cmp==-1) {
138  res.set(0) = nbr_conditions_val_domain_boundary_one_side (tt(1)(dom), bound) ;
139  res.set(1) = nbr_conditions_val_domain_boundary_one_side (tt(2)(dom), bound) ;
140  res.set(2) = nbr_conditions_val_domain_boundary_one_side (tt(3)(dom), bound) ;
141  }
142  else for (int i=0 ; i<n_cmp ; i++) {
143  if ((*p_cmp[i])(0)==1)
144  res.set(i) = nbr_conditions_val_domain_boundary_one_side (tt(1)(dom), bound) ;
145  if ((*p_cmp[i])(0)==2)
146  res.set(i) = nbr_conditions_val_domain_boundary_one_side (tt(2)(dom), bound) ;
147  if ((*p_cmp[i])(0)==3)
148  res.set(i) = nbr_conditions_val_domain_boundary_one_side (tt(3)(dom), bound) ;
149  }
150  found = true ;
151  }
152  if (!found) {
153  cerr << "Unknown type of vector Domain_bispheric_rect::nbr_conditions_boundary_one_side" << endl ;
154  abort() ;
155  }
156  }
157  break ;
158  case 2 : {
159  bool found = false ;
160  // Cartesian basis and symetric
161  if ((tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) && (tt.get_n_comp()==6)) {
162  if (n_cmp==-1) {
163  res.set(0) = nbr_conditions_val_domain_boundary_one_side (tt(1,1)(dom), bound) ;
164  res.set(1) = nbr_conditions_val_domain_boundary_one_side (tt(1,2)(dom), bound) ;
165  res.set(2) = nbr_conditions_val_domain_boundary_one_side (tt(1,3)(dom), bound) ;
166  res.set(3) = nbr_conditions_val_domain_boundary_one_side (tt(2,2)(dom), bound) ;
167  res.set(4) = nbr_conditions_val_domain_boundary_one_side (tt(2,3)(dom), bound) ;
168  res.set(5) = nbr_conditions_val_domain_boundary_one_side (tt(3,3)(dom), bound) ;
169  }
170  else for (int i=0 ; i<n_cmp ; i++) {
171  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==1))
172  res.set(i) = nbr_conditions_val_domain_boundary_one_side (tt(1, 1)(dom), bound) ;
173  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==2))
174  res.set(i) = nbr_conditions_val_domain_boundary_one_side (tt(1, 2)(dom), bound) ;
175  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==3))
176  res.set(i) = nbr_conditions_val_domain_boundary_one_side (tt(1, 3)(dom), bound) ;
177  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==2))
178  res.set(i) = nbr_conditions_val_domain_boundary_one_side (tt(2, 2)(dom), bound) ;
179  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==3))
180  res.set(i) = nbr_conditions_val_domain_boundary_one_side (tt(2, 3)(dom), bound) ;
181  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==3))
182  res.set(i) = nbr_conditions_val_domain_boundary_one_side (tt(3, 3)(dom), bound) ;
183  }
184  found = true ;
185  }
186  // Cartesian basis and not symetric
187  if ((tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) && (tt.get_n_comp()==9)) {
188  if (n_cmp==-1) {
189  res.set(0) = nbr_conditions_val_domain_boundary_one_side (tt(1,1)(dom), bound) ;
190  res.set(1) = nbr_conditions_val_domain_boundary_one_side (tt(1,2)(dom), bound) ;
191  res.set(2) = nbr_conditions_val_domain_boundary_one_side (tt(1,3)(dom), bound) ;
192  res.set(3) = nbr_conditions_val_domain_boundary_one_side (tt(2,1)(dom), bound) ;
193  res.set(4) = nbr_conditions_val_domain_boundary_one_side (tt(2,2)(dom), bound) ;
194  res.set(5) = nbr_conditions_val_domain_boundary_one_side (tt(2,3)(dom), bound) ;
195  res.set(6) = nbr_conditions_val_domain_boundary_one_side (tt(3,1)(dom), bound) ;
196  res.set(7) = nbr_conditions_val_domain_boundary_one_side (tt(3,2)(dom), bound) ;
197  res.set(8) = nbr_conditions_val_domain_boundary_one_side (tt(3,3)(dom), bound) ;
198  }
199  else for (int i=0 ; i<n_cmp ; i++) {
200  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==1))
201  res.set(i) = nbr_conditions_val_domain_boundary_one_side (tt(1, 1)(dom), bound) ;
202  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==2))
203  res.set(i) = nbr_conditions_val_domain_boundary_one_side (tt(1, 2)(dom), bound) ;
204  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==3))
205  res.set(i) = nbr_conditions_val_domain_boundary_one_side (tt(1, 3)(dom), bound) ;
206  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==1))
207  res.set(i) = nbr_conditions_val_domain_boundary_one_side (tt(2, 1)(dom), bound) ;
208  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==2))
209  res.set(i) = nbr_conditions_val_domain_boundary_one_side (tt(2, 2)(dom), bound) ;
210  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==3))
211  res.set(i) = nbr_conditions_val_domain_boundary_one_side (tt(2, 3)(dom), bound) ;
212  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==1))
213  res.set(i) = nbr_conditions_val_domain_boundary_one_side (tt(3, 1)(dom), bound) ;
214  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==2))
215  res.set(i) = nbr_conditions_val_domain_boundary_one_side (tt(3, 2)(dom), bound) ;
216  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==3))
217  res.set(i) = nbr_conditions_val_domain_boundary_one_side (tt(3, 3)(dom), bound) ;
218  }
219  found = true ;
220  }
221  if (!found) {
222  cerr << "Unknown type of 2-tensor Domain_bispheric_rect::nbr_conditions_boundary_one_side" << endl ;
223  abort() ;
224  }
225  }
226  break ;
227  default :
228  cerr << "Valence " << val << " not implemented in Domain_bispheric_rect::nbr_conditions_boundary_one_side" << endl ;
229  break ;
230  }
231  return res ;
232 }}
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_boundary_one_side(const Val_domain &eq, int bound) const
Computes number of discretized equations associated with a given equation on a boundary,...
virtual Array< int > nbr_conditions_boundary_one_side(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 on a boundary.
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
int & set(int i)
Read/write of the position in a given dimension.
Definition: index.hpp:72
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