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