KADATH
domain_compact_symphi_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 #include "spheric_symphi.hpp"
22 #include "array_math.hpp"
23 #include "scalar.hpp"
24 #include "tensor_impl.hpp"
25 #include "tensor.hpp"
26 
27 namespace Kadath {
29 
30  int res = 0 ;
31 
32  for (int k=0 ; k<nbr_coefs(2) ; k++)
33  for (int j=0 ; j<nbr_coefs(1) ; j++) {
34  bool indic = true ;
35 
36  int mquant ;
37  // Base in phi
38  int basep = (*so.get_base().bases_1d[2]) (0) ;
39  switch (basep) {
40  case COS_EVEN:
41  mquant = 2*k ;
42  break ;
43  case COS_ODD:
44  if (k==nbr_coefs(2)-1)
45  indic = false ;
46  mquant = 2*k+1 ;
47  break ;
48  case SIN_EVEN:
49  if ((k==0) || (k==nbr_coefs(2)-1))
50  indic = false ;
51  mquant = 2*k ;
52  break ;
53  case SIN_ODD:
54  if (k==nbr_coefs(2)-1)
55  indic = false ;
56  mquant = 2*k+1 ;
57  break ;
58  default:
59  cerr << "Unknow phi basis in Domain_compact_symphi::nbr_unknowns_val_domain" << endl ;
60  abort() ;
61  }
62 
63  // Get base in theta :
64  int baset = (*so.get_base().bases_1d[1]) (k) ;
65  if (indic) {
66  switch (baset) {
67  case COS_EVEN:
68  if ((j==0) && (mquant>0))
69  indic = false ;
70  break ;
71  case COS_ODD:
72  if ((j==nbr_coefs(1)-1) || ((j==0) && (mquant>0)))
73  indic = false ;
74  break ;
75  case SIN_EVEN:
76  if (((j==1) && (mquant>1)) || (j==0) || (j==nbr_coefs(1)-1))
77  indic = false ;
78  break ;
79  case SIN_ODD:
80  if (((j==0) && (mquant>1)) || (j==nbr_coefs(1)-1))
81  indic = false ;
82  break ;
83  default:
84  cerr << "Unknow theta basis in Domain_compact_symphi::nbr_unknowns_val_domain" << endl ;
85  abort() ;
86  }
87  }
88 
89  if (indic)
90  res ++ ;
91  }
92  return res ;
93 }
94 
95 Array<int> Domain_compact_symphi::nbr_conditions_boundary (const Tensor& tt, int dom, int bound, int n_cmp, Array<int>** p_cmp) const {
96 
97 #ifndef REMOVE_ALL_CHECKS
98  // Check boundary
99  if ((bound!=OUTER_BC) && (bound!=INNER_BC)) {
100  cerr << "Unknown boundary in Domain_compact_symphi::nbr_conditions_boundary" << endl ;
101  abort() ;
102  }
103 #endif
104 
105  int size = (n_cmp==-1) ? tt.get_n_comp() : n_cmp ;
106  Array<int> res (size) ;
107  int val = tt.get_valence() ;
108  switch (val) {
109  case 0 :
110  res.set(0) = nbr_conditions_val_domain_boundary (tt()(dom)) ;
111  break ;
112  case 1 : {
113  bool found = false ;
114  // Cartesian basis
115  if (tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) {
116  if (n_cmp==-1) {
117  res.set(0) = nbr_conditions_val_domain_boundary (tt(1)(dom)) ;
118  res.set(1) = nbr_conditions_val_domain_boundary (tt(2)(dom)) ;
119  res.set(2) = nbr_conditions_val_domain_boundary (tt(3)(dom)) ;
120  }
121  else for (int i=0 ; i<n_cmp ; i++) {
122  if ((*p_cmp[i])(0)==1)
123  res.set(i) = nbr_conditions_val_domain_boundary (tt(1)(dom)) ;
124  if ((*p_cmp[i])(0)==2)
125  res.set(i) = nbr_conditions_val_domain_boundary (tt(2)(dom)) ;
126  if ((*p_cmp[i])(0)==3)
127  res.set(i) = nbr_conditions_val_domain_boundary (tt(3)(dom)) ;
128  }
129  found = true ;
130  }
131 
132 #ifndef REMOVE_ALL_CHECKS
133  if (!found) {
134  cerr << "Unknown type of vector Domain_compact_symphi::nbr_conditions_boundary" << endl ;
135  abort() ;
136  }
137 #endif
138  }
139  break ;
140  case 2 : {
141  bool found = false ;
142  // Cartesian basis and symetric
143  if ((tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) && (tt.get_n_comp()==6)) {
144  if (n_cmp==-1) {
145  res.set(0) = nbr_conditions_val_domain_boundary (tt(1,1)(dom)) ;
146  res.set(1) = nbr_conditions_val_domain_boundary (tt(1,2)(dom)) ;
147  res.set(2) = nbr_conditions_val_domain_boundary (tt(1,3)(dom)) ;
148  res.set(3) = nbr_conditions_val_domain_boundary (tt(2,2)(dom)) ;
149  res.set(4) = nbr_conditions_val_domain_boundary (tt(2,3)(dom)) ;
150  res.set(5) = nbr_conditions_val_domain_boundary (tt(3,3)(dom)) ;
151  }
152  else for (int i=0 ; i<n_cmp ; i++) {
153  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==1))
154  res.set(i) = nbr_conditions_val_domain_boundary (tt(1, 1)(dom)) ;
155  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==2))
156  res.set(i) = nbr_conditions_val_domain_boundary (tt(1, 2)(dom)) ;
157  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==3))
158  res.set(i) = nbr_conditions_val_domain_boundary (tt(1, 3)(dom)) ;
159  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==2))
160  res.set(i) = nbr_conditions_val_domain_boundary (tt(2, 2)(dom)) ;
161  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==3))
162  res.set(i) = nbr_conditions_val_domain_boundary (tt(2, 3)(dom)) ;
163  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==3))
164  res.set(i) = nbr_conditions_val_domain_boundary (tt(3, 3)(dom)) ;
165  }
166  found = true ;
167  }
168  // Cartesian basis and not symetric
169  if ((tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) && (tt.get_n_comp()==9)) {
170  if (n_cmp==-1) {
171  res.set(0) = nbr_conditions_val_domain_boundary (tt(1,1)(dom)) ;
172  res.set(1) = nbr_conditions_val_domain_boundary (tt(1,2)(dom)) ;
173  res.set(2) = nbr_conditions_val_domain_boundary (tt(1,3)(dom)) ;
174  res.set(3) = nbr_conditions_val_domain_boundary (tt(2,1)(dom)) ;
175  res.set(4) = nbr_conditions_val_domain_boundary (tt(2,2)(dom)) ;
176  res.set(5) = nbr_conditions_val_domain_boundary (tt(2,3)(dom)) ;
177  res.set(6) = nbr_conditions_val_domain_boundary (tt(3,1)(dom)) ;
178  res.set(7) = nbr_conditions_val_domain_boundary (tt(3,2)(dom)) ;
179  res.set(8) = nbr_conditions_val_domain_boundary (tt(3,3)(dom)) ;
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)) ;
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)) ;
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)) ;
188  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==1))
189  res.set(i) = nbr_conditions_val_domain_boundary (tt(2, 1)(dom)) ;
190  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==2))
191  res.set(i) = nbr_conditions_val_domain_boundary (tt(2, 2)(dom)) ;
192  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==3))
193  res.set(i) = nbr_conditions_val_domain_boundary (tt(2, 3)(dom)) ;
194  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==1))
195  res.set(i) = nbr_conditions_val_domain_boundary (tt(3, 1)(dom)) ;
196  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==2))
197  res.set(i) = nbr_conditions_val_domain_boundary (tt(3, 2)(dom)) ;
198  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==3))
199  res.set(i) = nbr_conditions_val_domain_boundary (tt(3, 3)(dom)) ;
200  }
201  found = true ;
202  }
203 #ifndef REMOVE_ALL_CHECKS
204  if (!found) {
205  cerr << "Unknown type of 2-tensor Domain_compact_symphi::nbr_conditions_boundary" << endl ;
206  abort() ;
207  }
208 #endif
209  }
210  break ;
211  default :
212  cerr << "Valence " << val << " not implemented in Domain_compact_symphi::nbr_conditions_boundary" << endl ;
213  break ;
214  }
215  return res ;
216 }}
217 
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) 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
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