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