KADATH
domain_polar_periodic_shell_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 "polar_periodic.hpp"
22 #include "point.hpp"
23 #include "array_math.hpp"
24 #include "scalar.hpp"
25 #include "tensor_impl.hpp"
26 #include "tensor.hpp"
27 
28 namespace Kadath {
30  int res = 0 ;
31 
32  Index pos (nbr_coefs) ;
33  do {
34  bool indic = true ;
35 
36  // Base in time
37  int basetime = (*so.get_base().bases_1d[2]) (0) ;
38  switch (basetime) {
39  case COS:
40  break ;
41  case SIN:
42  if ((pos(2)==0) || (pos(2)==nbr_coefs(2)-1))
43  indic = false ;
44  break ;
45  default:
46  cerr << "Unknow time basis in Domain_polar_polar_shell::nbr_conditions_val_domain" << endl ;
47  abort() ;
48  }
49 
50 
51 
52  // Get base in theta :
53  int baset = (*so.get_base().bases_1d[1]) (pos(2)) ;
54  switch (baset) {
55  case COS_EVEN:
56  break ;
57  case COS_ODD:
58  if (pos(1)==nbr_coefs(1)-1)
59  indic = false ;
60  break ;
61  case SIN_EVEN:
62  if ((pos(1)==0) || (pos(1)==nbr_coefs(1)-1))
63  indic = false ;
64  break ;
65  case SIN_ODD:
66  if (pos(1)==nbr_coefs(1)-1)
67  indic = false ;
68  break ;
69  default:
70  cerr << "Unknow theta basis in Domain_polar_periodic_shell::nbr_conditions_val_domain" << endl ;
71  abort() ;
72  }
73 
74  // Order with respect to r :
75  int lim = 0 ;
76  switch (order) {
77  case 2 :
78  lim = nbr_coefs(0)-2 ;
79  break ;
80  case 0 :
81  lim = nbr_coefs(0) ;
82  break ;
83  default :
84  cerr << "Unknown case in Domain_polar_periodic_shell_nbr_conditions" << endl ;
85  abort() ;
86  }
87 
88  if (pos(0)>=lim)
89  indic = false ;
90 
91  if (indic)
92  res ++ ;
93 
94  }
95  while (pos.inc()) ;
96 
97  return res ;
98 }
99 
100 Array<int> Domain_polar_periodic_shell::nbr_conditions (const Tensor& tt, int dom, int order, int n_cmp, Array<int>** p_cmp) const {
101 
102  int size = (n_cmp==-1) ? tt.get_n_comp() : n_cmp ;
103  Array<int> res (size) ;
104  int val = tt.get_valence() ;
105  switch (val) {
106  case 0 :
107  res.set(0) = nbr_conditions_val_domain (tt()(dom), order) ;
108  break ;
109  case 1 :
110  if (n_cmp==-1) {
111  res.set(0) = nbr_conditions_val_domain (tt(1)(dom), order) ;
112  res.set(1) = nbr_conditions_val_domain (tt(2)(dom), order) ;
113  res.set(2) = nbr_conditions_val_domain (tt(3)(dom), order) ;
114  }
115  else for (int i=0 ; i<n_cmp ; i++) {
116  if ((*p_cmp[i])(0)==1)
117  res.set(i) = nbr_conditions_val_domain (tt(1)(dom), order) ;
118  if ((*p_cmp[i])(0)==2)
119  res.set(i) = nbr_conditions_val_domain (tt(2)(dom), order) ;
120  if ((*p_cmp[i])(0)==3)
121  res.set(i) = nbr_conditions_val_domain (tt(3)(dom), order) ;
122  }
123  break ;
124  case 2 :
125  if (tt.get_n_comp()==6) {
126  if (n_cmp==-1) {
127  res.set(0) = nbr_conditions_val_domain (tt(1,1)(dom), order) ;
128  res.set(1) = nbr_conditions_val_domain (tt(1,2)(dom), order) ;
129  res.set(2) = nbr_conditions_val_domain (tt(1,3)(dom), order) ;
130  res.set(3) = nbr_conditions_val_domain (tt(2,2)(dom), order) ;
131  res.set(4) = nbr_conditions_val_domain (tt(2,3)(dom), order) ;
132  res.set(5) = nbr_conditions_val_domain (tt(3,3)(dom), order) ;
133  }
134  else for (int i=0 ; i<n_cmp ; i++) {
135  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==1))
136  res.set(i) = nbr_conditions_val_domain (tt(1, 1)(dom), order) ;
137  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==2))
138  res.set(i) = nbr_conditions_val_domain (tt(1, 2)(dom), order) ;
139  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==3))
140  res.set(i) = nbr_conditions_val_domain (tt(1, 3)(dom), order) ;
141  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==2))
142  res.set(i) = nbr_conditions_val_domain (tt(2, 2)(dom), order) ;
143  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==3))
144  res.set(i) = nbr_conditions_val_domain (tt(2, 3)(dom), order) ;
145  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==3))
146  res.set(i) = nbr_conditions_val_domain (tt(3, 3)(dom), order) ;
147  }
148  }
149  // not symetric
150  if (tt.get_n_comp()==9) {
151  if (n_cmp==-1) {
152  res.set(0) = nbr_conditions_val_domain (tt(1,1)(dom), order) ;
153  res.set(1) = nbr_conditions_val_domain (tt(1,2)(dom), order) ;
154  res.set(2) = nbr_conditions_val_domain (tt(1,3)(dom), order) ;
155  res.set(3) = nbr_conditions_val_domain (tt(2,1)(dom), order) ;
156  res.set(4) = nbr_conditions_val_domain (tt(2,2)(dom), order) ;
157  res.set(5) = nbr_conditions_val_domain (tt(2,3)(dom), order) ;
158  res.set(6) = nbr_conditions_val_domain (tt(3,1)(dom), order) ;
159  res.set(7) = nbr_conditions_val_domain (tt(3,2)(dom), order) ;
160  res.set(8) = nbr_conditions_val_domain (tt(3,3)(dom), order) ;
161  }
162  else for (int i=0 ; i<n_cmp ; i++) {
163  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==1))
164  res.set(i) = nbr_conditions_val_domain (tt(1, 1)(dom), order) ;
165  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==2))
166  res.set(i) = nbr_conditions_val_domain (tt(1, 2)(dom), order) ;
167  if (((*p_cmp[i])(0)==1) && ((*p_cmp[i])(1)==3))
168  res.set(i) = nbr_conditions_val_domain (tt(1, 3)(dom), order) ;
169  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==1))
170  res.set(i) = nbr_conditions_val_domain (tt(2, 1)(dom), order) ;
171  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==2))
172  res.set(i) = nbr_conditions_val_domain (tt(2, 2)(dom), order) ;
173  if (((*p_cmp[i])(0)==2) && ((*p_cmp[i])(1)==3))
174  res.set(i) = nbr_conditions_val_domain (tt(2, 3)(dom), order) ;
175  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==1))
176  res.set(i) = nbr_conditions_val_domain (tt(3, 1)(dom), order) ;
177  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==2))
178  res.set(i) = nbr_conditions_val_domain (tt(3, 2)(dom), order) ;
179  if (((*p_cmp[i])(0)==3) && ((*p_cmp[i])(1)==3))
180  res.set(i) = nbr_conditions_val_domain (tt(3, 3)(dom), order) ;
181  }
182  }
183  break ;
184  default :
185  cerr << "Valence " << val << " not implemented in Domain_polar_periodic_shell::nbr_conditions" << endl ;
186  break ;
187  }
188  return res ;
189 }}
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.
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 &so, 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
Class that gives the position inside a multi-dimensional Array.
Definition: index.hpp:38
bool inc(int increm, int var=0)
Increments the position of the Index.
Definition: index.hpp:99
Tensor handling.
Definition: tensor.hpp:149
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