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