KADATH
domain_compact_nbr_conditions_boundary.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 
22 #include "spheric.hpp"
23 #include "scalar.hpp"
24 #include "tensor_impl.hpp"
25 #include "tensor.hpp"
26 
27 namespace Kadath {
29  int res = 0 ;
30 
31  for (int j=0 ; j<nbr_coefs(1) ; j++) {
32  bool indic = true ;
33  // Get base in theta :
34  int baset = (*so.get_base().bases_1d[1])(0) ;
35  switch (baset) {
36  case COS_EVEN:
37  if ((j==0) && (mquant!=0))
38  indic = false ;
39  break ;
40  case COS_ODD:
41  if ((j==nbr_coefs(1)-1) || ((j==0) && (mquant!=0)))
42  indic = false ;
43  break ;
44  case SIN_EVEN:
45  if (((j==1) && (mquant>1)) ||(j==0) || (j==nbr_coefs(1)-1))
46  indic = false ;
47  break ;
48  case SIN_ODD:
49  if (((j==0) && (mquant>1)) || (j==nbr_coefs(1)-1))
50  indic = false ;
51  break ;
52  default:
53  cerr << "Unknow theta basis in Domain_compact::nbr_conditions_val_boundary_mquant" << endl ;
54  abort() ;
55  }
56 
57  if (indic)
58  res ++ ;
59  }
60  return res ;
61 }
62 
64 
65  int res = 0 ;
66  int kmin = 2*mlim + 2 ;
67 
68  for (int k=0 ; k<nbr_coefs(2) ; k++)
69  for (int j=0 ; j<nbr_coefs(1) ; j++) {
70  bool indic = true ;
71  // True coef in phi ?
72  if ((k==1) || (k==nbr_coefs(2)-1))
73  indic = false ;
74  // Get base in theta :
75  int baset = (*so.get_base().bases_1d[1])(k) ;
76  switch (baset) {
77  case COS_EVEN:
78  if ((j==0) && (k>=kmin))
79  indic = false ;
80  break ;
81  case COS_ODD:
82  if ((j==nbr_coefs(1)-1) || ((j==0) && (k>=kmin)))
83  indic = false ;
84  break ;
85  case SIN_EVEN:
86  if (((j==1)&&(k>=kmin+2)) || (j==0) || (j==nbr_coefs(1)-1))
87  indic = false ;
88  break ;
89  case SIN_ODD:
90  if (((j==0)&&(k>=kmin+2))||(j==nbr_coefs(1)-1))
91  indic = false ;
92  break ;
93  default:
94  cerr << "Unknow theta basis in Domain_compact::nbr_conditions_val_boundary" << endl ;
95  abort() ;
96  }
97 
98  if (indic)
99  res ++ ;
100  }
101  return res ;
102 }
103 
104 Array<int> Domain_compact::nbr_conditions_boundary (const Tensor& tt, int dom, int bound, int n_cmp, Array<int>** p_cmp) const {
105 
106  // Check boundary
107  if ((bound!=INNER_BC) && (bound!=OUTER_BC)) {
108  cerr << "Unknown boundary in Domain_compact::nbr_conditions_boundary" << endl ;
109  abort() ;
110  }
111 
112  int size = (n_cmp==-1) ? tt.get_n_comp() : n_cmp ;
113  Array<int> res (size) ;
114  int val = tt.get_valence() ;
115  switch (val) {
116  case 0 :
117  if (tt.is_m_quant_affected()) {
118  // Special case for bosonic field
120  } else {
121  if (!tt.is_m_order_affected())
122  res.set(0) = nbr_conditions_val_domain_boundary (tt()(dom), 0) ;
123  else
125  }
126  break ;
127  case 1 : {
128  bool found = false ;
129  // Cartesian basis
130  if (tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) {
131  if (n_cmp==-1) {
132  res.set(0) = nbr_conditions_val_domain_boundary (tt(1)(dom), 0) ;
133  res.set(1) = nbr_conditions_val_domain_boundary (tt(2)(dom), 0) ;
134  res.set(2) = nbr_conditions_val_domain_boundary (tt(3)(dom), 0) ;
135  }
136  else for (int i=0 ; i<n_cmp ; i++) {
137  if ((*p_cmp[i])(0)==1)
138  res.set(i) = nbr_conditions_val_domain_boundary (tt(1)(dom), 0) ;
139  if ((*p_cmp[i])(0)==2)
140  res.set(i) = nbr_conditions_val_domain_boundary (tt(2)(dom), 0) ;
141  if ((*p_cmp[i])(0)==3)
142  res.set(i) = nbr_conditions_val_domain_boundary (tt(3)(dom), 0) ;
143  }
144  found = true ;
145  }
146  // Spherical coordinates
147  if (tt.get_basis().get_basis(dom)==SPHERICAL_BASIS) {
148  if (n_cmp==-1) {
149  res.set(0) = nbr_conditions_val_domain_boundary (tt(1)(dom), 0) ;
150  res.set(1) = nbr_conditions_val_domain_boundary (tt(2)(dom), 1) ;
151  res.set(2) = nbr_conditions_val_domain_boundary (tt(3)(dom), 1) ;
152  }
153  else for (int i=0 ; i<n_cmp ; i++) {
154  if ((*p_cmp[i])(0)==1)
155  res.set(i) = nbr_conditions_val_domain_boundary (tt(1)(dom), 0) ;
156  if ((*p_cmp[i])(0)==2)
157  res.set(i) = nbr_conditions_val_domain_boundary (tt(2)(dom), 1) ;
158  if ((*p_cmp[i])(0)==3)
159  res.set(i) = nbr_conditions_val_domain_boundary (tt(3)(dom), 1) ;
160  }
161  found = true ;
162  }
163  if (!found) {
164  cerr << "Unknown type of vector Domain_compact::nbr_conditions_boundary" << endl ;
165  abort() ;
166  }
167  }
168  break ;
169  case 2 : {
170  bool found = false ;
171  // Cartesian basis and symetric
172  if ((tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) && (tt.get_n_comp()==6)) {
173  if (n_cmp==-1) {
174  res.set(0) = nbr_conditions_val_domain_boundary (tt(1,1)(dom), 0) ;
175  res.set(1) = nbr_conditions_val_domain_boundary (tt(1,2)(dom), 0) ;
176  res.set(2) = nbr_conditions_val_domain_boundary (tt(1,3)(dom), 0) ;
177  res.set(3) = nbr_conditions_val_domain_boundary (tt(2,2)(dom), 0) ;
178  res.set(4) = nbr_conditions_val_domain_boundary (tt(2,3)(dom), 0) ;
179  res.set(5) = nbr_conditions_val_domain_boundary (tt(3,3)(dom), 0) ;
180  }
181  else for (int i=0 ; i<n_cmp ; i++) {
182  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==1))
183  res.set(i) = nbr_conditions_val_domain_boundary (tt(1, 1)(dom), 0) ;
184  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==2))
185  res.set(i) = nbr_conditions_val_domain_boundary (tt(1, 2)(dom), 0) ;
186  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==3))
187  res.set(i) = nbr_conditions_val_domain_boundary (tt(1, 3)(dom), 0) ;
188  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==2))
189  res.set(i) = nbr_conditions_val_domain_boundary (tt(2, 2)(dom), 0) ;
190  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==3))
191  res.set(i) = nbr_conditions_val_domain_boundary (tt(2, 3)(dom), 0) ;
192  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==3))
193  res.set(i) = nbr_conditions_val_domain_boundary (tt(3, 3)(dom), 0) ;
194  }
195  found = true ;
196  }
197  // Cartesian basis and not symetric
198  if ((tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) && (tt.get_n_comp()==9)) {
199  if (n_cmp==-1) {
200  res.set(0) = nbr_conditions_val_domain_boundary (tt(1,1)(dom), 0) ;
201  res.set(1) = nbr_conditions_val_domain_boundary (tt(1,2)(dom), 0) ;
202  res.set(2) = nbr_conditions_val_domain_boundary (tt(1,3)(dom), 0) ;
203  res.set(3) = nbr_conditions_val_domain_boundary (tt(2,1)(dom), 0) ;
204  res.set(4) = nbr_conditions_val_domain_boundary (tt(2,2)(dom), 0) ;
205  res.set(5) = nbr_conditions_val_domain_boundary (tt(2,3)(dom), 0) ;
206  res.set(6) = nbr_conditions_val_domain_boundary (tt(3,1)(dom), 0) ;
207  res.set(7) = nbr_conditions_val_domain_boundary (tt(3,2)(dom), 0) ;
208  res.set(8) = nbr_conditions_val_domain_boundary (tt(3,3)(dom), 0) ;
209  }
210  else for (int i=0 ; i<n_cmp ; i++) {
211  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==1))
212  res.set(i) = nbr_conditions_val_domain_boundary (tt(1, 1)(dom), 0) ;
213  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==2))
214  res.set(i) = nbr_conditions_val_domain_boundary (tt(1, 2)(dom), 0) ;
215  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==3))
216  res.set(i) = nbr_conditions_val_domain_boundary (tt(1, 3)(dom), 0) ;
217  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==1))
218  res.set(i) = nbr_conditions_val_domain_boundary (tt(2, 1)(dom), 0) ;
219  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==2))
220  res.set(i) = nbr_conditions_val_domain_boundary (tt(2, 2)(dom), 0) ;
221  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==3))
222  res.set(i) = nbr_conditions_val_domain_boundary (tt(2, 3)(dom), 0) ;
223  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==1))
224  res.set(i) = nbr_conditions_val_domain_boundary (tt(3, 1)(dom), 0) ;
225  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==2))
226  res.set(i) = nbr_conditions_val_domain_boundary (tt(3, 2)(dom), 0) ;
227  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==3))
228  res.set(i) = nbr_conditions_val_domain_boundary (tt(3, 3)(dom), 0) ;
229  }
230  found = true ;
231  }
232  // Spherical coordinates and symetric
233  if ((tt.get_basis().get_basis(dom)==SPHERICAL_BASIS) && (tt.get_n_comp()==6)) {
234  if (n_cmp==-1) {
235  res.set(0) = nbr_conditions_val_domain_boundary (tt(1,1)(dom), 0) ;
236  res.set(1) = nbr_conditions_val_domain_boundary (tt(1,2)(dom), 1) ;
237  res.set(2) = nbr_conditions_val_domain_boundary (tt(1,3)(dom), 1) ;
238  res.set(3) = nbr_conditions_val_domain_boundary (tt(2,2)(dom), 2) ;
239  res.set(4) = nbr_conditions_val_domain_boundary (tt(2,3)(dom), 2) ;
240  res.set(5) = nbr_conditions_val_domain_boundary (tt(3,3)(dom), 2) ;
241  }
242  else for (int i=0 ; i<n_cmp ; i++) {
243  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==1))
244  res.set(i) = nbr_conditions_val_domain_boundary (tt(1, 1)(dom), 0) ;
245  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==2))
246  res.set(i) = nbr_conditions_val_domain_boundary (tt(1, 2)(dom), 1) ;
247  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==3))
248  res.set(i) = nbr_conditions_val_domain_boundary (tt(1, 3)(dom), 1) ;
249  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==2))
250  res.set(i) = nbr_conditions_val_domain_boundary (tt(2, 2)(dom), 2) ;
251  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==3))
252  res.set(i) = nbr_conditions_val_domain_boundary (tt(2, 3)(dom), 2) ;
253  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==3))
254  res.set(i) = nbr_conditions_val_domain_boundary (tt(3, 3)(dom), 2) ;
255  }
256  found = true ;
257  }
258  // Spherical coordinates and not symetric
259  if ((tt.get_basis().get_basis(dom)==SPHERICAL_BASIS) && (tt.get_n_comp()==9)) {
260  if (n_cmp==-1) {
261  res.set(0) = nbr_conditions_val_domain_boundary (tt(1,1)(dom), 0) ;
262  res.set(1) = nbr_conditions_val_domain_boundary (tt(1,2)(dom), 1) ;
263  res.set(2) = nbr_conditions_val_domain_boundary (tt(1,3)(dom), 1) ;
264  res.set(3) = nbr_conditions_val_domain_boundary (tt(2,1)(dom), 1) ;
265  res.set(4) = nbr_conditions_val_domain_boundary (tt(2,2)(dom), 2) ;
266  res.set(5) = nbr_conditions_val_domain_boundary (tt(2,3)(dom), 2) ;
267  res.set(6) = nbr_conditions_val_domain_boundary (tt(3,1)(dom), 1) ;
268  res.set(7) = nbr_conditions_val_domain_boundary (tt(3,2)(dom), 2) ;
269  res.set(8) = nbr_conditions_val_domain_boundary (tt(3,3)(dom), 2) ;
270 
271  }
272  else for (int i=0 ; i<n_cmp ; i++) {
273  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==1))
274  res.set(i) = nbr_conditions_val_domain_boundary (tt(1, 1)(dom), 0) ;
275  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==2))
276  res.set(i) = nbr_conditions_val_domain_boundary (tt(1, 2)(dom), 1) ;
277  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==3))
278  res.set(i) = nbr_conditions_val_domain_boundary (tt(1, 3)(dom), 1) ;
279  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==1))
280  res.set(i) = nbr_conditions_val_domain_boundary (tt(2, 1)(dom), 1) ;
281  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==2))
282  res.set(i) = nbr_conditions_val_domain_boundary (tt(2, 2)(dom), 2) ;
283  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==3))
284  res.set(i) = nbr_conditions_val_domain_boundary (tt(2, 3)(dom), 2) ;
285  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==1))
286  res.set(i) = nbr_conditions_val_domain_boundary (tt(3, 1)(dom), 1) ;
287  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==2))
288  res.set(i) = nbr_conditions_val_domain_boundary (tt(3, 2)(dom), 2) ;
289  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==3))
290  res.set(i) = nbr_conditions_val_domain_boundary (tt(3, 3)(dom), 2) ;
291  }
292  found = true ;
293  }
294  if (!found) {
295  cerr << "Unknown type of 2-tensor Domain_compact::nbr_conditions_boundary" << endl ;
296  abort() ;
297  }
298  }
299  break ;
300  default :
301  cerr << "Valence " << val << " not implemented in Domain_compact::nbr_conditions_boundary" << endl ;
302  break ;
303  }
304  return res ;
305 }}
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(const Val_domain &eq, int mlim) const
Computes number of discretized equations associated with a given equation on a boundary.
int nbr_conditions_val_domain_boundary_mquant(const Val_domain &eq, int mquant) const
Computes number of discretized equations associated with a given equation on a boundary.
virtual Array< int > nbr_conditions_boundary(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
int get_m_order() const
Returns .
Definition: tensor.hpp:737
int get_m_quant() const
Returns .
Definition: tensor.hpp:747
Tensor handling.
Definition: tensor.hpp:149
bool is_m_order_affected() const
Checks whether the additional parameter order is affected (not very used).
Definition: tensor.hpp:323
const Param_tensor & get_parameters() const
Returns a pointer on the possible additional parameter.
Definition: tensor.hpp:311
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
bool is_m_quant_affected() const
Checks whether the additional parameter is affected (used for boson stars for instance).
Definition: tensor.hpp:326
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