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