KADATH
domain_bispheric_chi_first_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 "bispheric.hpp"
23 #include "scalar.hpp"
24 #include "tensor_impl.hpp"
25 #include "tensor.hpp"
26 
27 namespace Kadath {
29 
30  int res = 0 ;
31  int basep = (*so.get_base().bases_1d[2]) (0) ;
32 
33  if ((bound==INNER_BC) || (bound==OUTER_BC)) {
34  Index pos (nbr_coefs) ;
35  // Loop on phi :
36  for (int k=0 ; k<nbr_coefs(2) ; k++) {
37  pos.set(2) = k ;
38  // Loop on chi ;
39  for (int j=0 ; j<nbr_coefs(1) ; j++) {
40  pos.set(1) = j ;
41  bool indic = true ;
42  switch (basep) {
43  case COS :
44  // Last odd ones
45  if ((pos(2)%2==1) && (pos(1)==nbr_coefs(1)-1))
46  indic = false ;
47  // Regularity for even ones :
48  if ((pos(2)!=0) && (pos(2)%2==0) && (pos(1)==0))
49  indic = false ;
50  break ;
51  case SIN :
52  // sin(0)
53  if ((pos(2)==0) || (pos(2)==nbr_coefs(2)-1))
54  indic = false ;
55  // Last odd ones :
56  if ((pos(2)%2==1) && (pos(1)==nbr_coefs(1)-1))
57  indic = false ;
58  // Regularity for even ones :
59  if ((pos(2)%2==0) && (pos(1)==0))
60  indic = false ;
61  break ;
62  default :
63  cerr << "Unknwon phi basis in Domain_bispheric_chi_first::nbr_conditions_val_boundary" << endl ;
64  abort() ;
65  }
66 
67  if (indic)
68  res ++ ;
69  }
70  }
71  }
72 
73  if (bound==CHI_ONE_BC)
74  res = (basep==COS) ? nbr_coefs(2)*(nbr_coefs(0)-2) : (nbr_coefs(2)-2)*(nbr_coefs(0)-2) ;
75 
76  return res ;
77 }
78 
79 Array<int> Domain_bispheric_chi_first::nbr_conditions_boundary (const Tensor& tt, int dom, int bound, int n_cmp, Array<int>** p_cmp) const {
80 
81  // Check boundary
82  if ((bound!=INNER_BC) && (bound!=CHI_ONE_BC) && (bound!=OUTER_BC)) {
83  cerr << "Unknown boundary in Domain_bispheric_chi_first::nbr_conditions_boundary" << endl ;
84  abort() ;
85  }
86 
87  int size = (n_cmp==-1) ? tt.get_n_comp() : n_cmp ;
88  Array<int> res (size) ;
89  int val = tt.get_valence() ;
90  switch (val) {
91  case 0 :
92  res.set(0) = nbr_conditions_val_domain_boundary (tt()(dom), bound) ;
93  break ;
94  case 1 : {
95  bool found = false ;
96  // Cartesian basis
97  if (tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) {
98  if (n_cmp==-1) {
99  res.set(0) = nbr_conditions_val_domain_boundary (tt(1)(dom), bound) ;
100  res.set(1) = nbr_conditions_val_domain_boundary (tt(2)(dom), bound) ;
101  res.set(2) = nbr_conditions_val_domain_boundary (tt(3)(dom), bound) ;
102  }
103  else for (int i=0 ; i<n_cmp ; i++) {
104  if ((*p_cmp[i])(0)==1)
105  res.set(i) = nbr_conditions_val_domain_boundary (tt(1)(dom), bound) ;
106  if ((*p_cmp[i])(0)==2)
107  res.set(i) = nbr_conditions_val_domain_boundary (tt(2)(dom), bound) ;
108  if ((*p_cmp[i])(0)==3)
109  res.set(i) = nbr_conditions_val_domain_boundary (tt(3)(dom), bound) ;
110  }
111  found = true ;
112  }
113  if (!found) {
114  cerr << "Unknown type of vector Domain_bispheric_chi_first::nbr_conditions_boundary" << endl ;
115  abort() ;
116  }
117  }
118  break ;
119  case 2 : {
120  bool found = false ;
121  // Cartesian basis and symetric
122  if ((tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) && (tt.get_n_comp()==6)) {
123  if (n_cmp==-1) {
124  res.set(0) = nbr_conditions_val_domain_boundary (tt(1,1)(dom), bound) ;
125  res.set(1) = nbr_conditions_val_domain_boundary (tt(1,2)(dom), bound) ;
126  res.set(2) = nbr_conditions_val_domain_boundary (tt(1,3)(dom), bound) ;
127  res.set(3) = nbr_conditions_val_domain_boundary (tt(2,2)(dom), bound) ;
128  res.set(4) = nbr_conditions_val_domain_boundary (tt(2,3)(dom), bound) ;
129  res.set(5) = nbr_conditions_val_domain_boundary (tt(3,3)(dom), bound) ;
130  }
131  else for (int i=0 ; i<n_cmp ; i++) {
132  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==1))
133  res.set(i) = nbr_conditions_val_domain_boundary (tt(1, 1)(dom), bound) ;
134  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==2))
135  res.set(i) = nbr_conditions_val_domain_boundary (tt(1, 2)(dom), bound) ;
136  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==3))
137  res.set(i) = nbr_conditions_val_domain_boundary (tt(1, 3)(dom), bound) ;
138  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==2))
139  res.set(i) = nbr_conditions_val_domain_boundary (tt(2, 2)(dom), bound) ;
140  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==3))
141  res.set(i) = nbr_conditions_val_domain_boundary (tt(2, 3)(dom), bound) ;
142  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==3))
143  res.set(i) = nbr_conditions_val_domain_boundary (tt(3, 3)(dom), bound) ;
144  }
145  found = true ;
146  }
147  // Cartesian basis and not symetric
148  if ((tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) && (tt.get_n_comp()==9)) {
149  if (n_cmp==-1) {
150  res.set(0) = nbr_conditions_val_domain_boundary (tt(1,1)(dom), bound) ;
151  res.set(1) = nbr_conditions_val_domain_boundary (tt(1,2)(dom), bound) ;
152  res.set(2) = nbr_conditions_val_domain_boundary (tt(1,3)(dom), bound) ;
153  res.set(3) = nbr_conditions_val_domain_boundary (tt(2,1)(dom), bound) ;
154  res.set(4) = nbr_conditions_val_domain_boundary (tt(2,2)(dom), bound) ;
155  res.set(5) = nbr_conditions_val_domain_boundary (tt(2,3)(dom), bound) ;
156  res.set(6) = nbr_conditions_val_domain_boundary (tt(3,1)(dom), bound) ;
157  res.set(7) = nbr_conditions_val_domain_boundary (tt(3,2)(dom), bound) ;
158  res.set(8) = nbr_conditions_val_domain_boundary (tt(3,3)(dom), bound) ;
159  }
160  else for (int i=0 ; i<n_cmp ; i++) {
161  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==1))
162  res.set(i) = nbr_conditions_val_domain_boundary (tt(1, 1)(dom), bound) ;
163  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==2))
164  res.set(i) = nbr_conditions_val_domain_boundary (tt(1, 2)(dom), bound) ;
165  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==3))
166  res.set(i) = nbr_conditions_val_domain_boundary (tt(1, 3)(dom), bound) ;
167  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==1))
168  res.set(i) = nbr_conditions_val_domain_boundary (tt(2, 1)(dom), bound) ;
169  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==2))
170  res.set(i) = nbr_conditions_val_domain_boundary (tt(2, 2)(dom), bound) ;
171  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==3))
172  res.set(i) = nbr_conditions_val_domain_boundary (tt(2, 3)(dom), bound) ;
173  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==1))
174  res.set(i) = nbr_conditions_val_domain_boundary (tt(3, 1)(dom), bound) ;
175  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==2))
176  res.set(i) = nbr_conditions_val_domain_boundary (tt(3, 2)(dom), bound) ;
177  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==3))
178  res.set(i) = nbr_conditions_val_domain_boundary (tt(3, 3)(dom), bound) ;
179  }
180  found = true ;
181  }
182  if (!found) {
183  cerr << "Unknown type of 2-tensor Domain_bispheric_chi_first::nbr_conditions_boundary" << endl ;
184  abort() ;
185  }
186  }
187  break ;
188  default :
189  cerr << "Valence " << val << " not implemented in Domain_bispheric_chi_first::nbr_conditions_boundary" << endl ;
190  break ;
191  }
192  return res ;
193 }}
194 
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
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.
int nbr_conditions_val_domain_boundary(const Val_domain &eq, int bound) const
Computes number of discretized equations associated with a given 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