KADATH
domain_compact_symphi_affecte_tau.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 {
27 void Domain_compact_symphi::affecte_tau_val_domain (Val_domain& so, const Array<double>& values, int& conte) const {
28 
29  so.allocate_coef() ;
30  *so.cf = 0. ;
31  Index pos_cf (nbr_coefs) ;
32 
33  // Positions of the Galerkin basis
34  Index pos_gal_t (nbr_coefs) ;
35  double fact_t ;
36 
37 
38  int kmin, kmax ;
39  // Base in phi
40  int basep = (*so.get_base().bases_1d[2]) (0) ;
41  switch (basep) {
42  case COS_EVEN:
43  kmin = 0 ;
44  kmax = nbr_coefs(2)-1 ;
45  break ;
46  case COS_ODD:
47  kmin = 0 ;
48  kmax = nbr_coefs(2)-2 ;
49  break ;
50  case SIN_EVEN:
51  kmin = 1 ;
52  kmax = nbr_coefs(2)-2 ;
53  break ;
54  case SIN_ODD:
55  kmin = 0 ;
56  kmax = nbr_coefs(2)-2 ;
57  break ;
58  default:
59  cerr << "Unknow phi basis in Domain_compact_symphi::affecte_tau_val_domain" << endl ;
60  abort() ;
61  }
62 
63 
64 
65  // Loop on phi :
66  for (int k=kmin ; k<=kmax ; k++) {
67 
68  pos_cf.set(2) = k ;
69 
70  int mquant ;
71  switch (basep) {
72  case COS_EVEN:
73  mquant = 2*k ;
74  break ;
75  case COS_ODD:
76  mquant = 2*k+1 ;
77  break ;
78  case SIN_EVEN:
79  mquant = 2*k ;
80  break ;
81  case SIN_ODD:
82  mquant = 2*k+1 ;
83  break ;
84  default:
85  cerr << "Unknow phi basis in Domain_compact_symphi::affecte_tau_val_domain" << endl ;
86  abort() ;
87  }
88 
89  // Loop on theta
90  int baset = (*so.get_base().bases_1d[1]) (k) ;
91  for (int j=0 ; j<nbr_coefs(1) ; j++) {
92  int baser = (*so.get_base().bases_1d[0]) (j, k) ;
93  pos_cf.set(1) = j ;
94  // Loop on r :
95  for (int i=0 ; i<nbr_coefs(0) ; i++) {
96  pos_cf.set(0) = i ;
97  switch (baset) {
98  case COS_EVEN :
99  // No galerkin :
100  if (mquant==0) {
101  so.cf->set(pos_cf) += values(conte) ;
102  conte ++ ;
103  }
104  else if (j!=0) {
105  // Galerkin basis
106  pos_gal_t = pos_cf ;
107  pos_gal_t.set(1) = 0 ;
108  fact_t = -1. ;
109  so.cf->set(pos_cf) += values(conte) ;
110  so.cf->set(pos_gal_t) += fact_t*values(conte) ;
111  conte ++ ;
112  }
113  break ;
114  case COS_ODD:
115  if (j!=nbr_coefs(1)-1) {
116  if (mquant==0) {
117  so.cf->set(pos_cf) += values(conte) ;
118  conte ++ ;
119  }
120  else if (j!=0) {
121  // Galerkin basis
122  pos_gal_t = pos_cf ;
123  pos_gal_t.set(1) = 0 ;
124  fact_t = -1. ;
125  so.cf->set(pos_cf) += values(conte) ;
126  so.cf->set(pos_gal_t) += fact_t*values(conte) ;
127  conte ++ ;
128  }
129  }
130  break ;
131  case SIN_EVEN:
132  if ((j!=0) && (j!=nbr_coefs(1)-1)) {
133  if (mquant<=1) {
134  so.cf->set(pos_cf) += values(conte) ;
135  conte ++ ;
136  }
137  else if (j!=1) {
138  // Galerkin basis
139  pos_gal_t = pos_cf ;
140  pos_gal_t.set(1) = 1 ;
141  fact_t = -j ;
142  so.cf->set(pos_cf) += values(conte) ;
143  so.cf->set(pos_gal_t) += fact_t*values(conte) ;
144  conte ++ ;
145  }
146  }
147  break ;
148  case SIN_ODD:
149  if (j!=nbr_coefs(1)-1) {
150  if (mquant<=1) {
151  so.cf->set(pos_cf) += values(conte) ;
152  conte ++ ;
153  }
154  else if (j!=0) {
155  // Galerkin basis
156  pos_gal_t = pos_cf ;
157  pos_gal_t.set(1) = 0 ;
158  fact_t = -(2.*j+1) ;
159  so.cf->set(pos_cf) += values(conte) ;
160  so.cf->set(pos_gal_t) += fact_t*values(conte) ;
161  conte ++ ;
162  }
163  }
164  break ;
165  default:
166  cerr << "Unknow theta basis in Domain_compact_symphi::affecte_tau_val_domain" << endl ;
167  abort() ;
168  }
169  }
170  }
171  }
172 }
173 
174 void Domain_compact_symphi::affecte_tau (Tensor& tt, int dom, const Array<double>& cf, int& pos_cf) const {
175 
176  // Check right domain
177  assert (tt.get_space().get_domain(dom)==this) ;
178 
179  int val = tt.get_valence() ;
180  switch (val) {
181  case 0 :
182  affecte_tau_val_domain (tt.set().set_domain(dom), cf, pos_cf) ;
183  break ;
184  case 1 : {
185  bool found = false ;
186  // Cartesian basis
187  if (tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) {
188  affecte_tau_val_domain (tt.set(1).set_domain(dom), cf, pos_cf) ;
189  affecte_tau_val_domain (tt.set(2).set_domain(dom), cf, pos_cf) ;
190  affecte_tau_val_domain (tt.set(3).set_domain(dom), cf, pos_cf) ;
191  found = true ;
192  }
193 
194  if (!found) {
195  cerr << "Unknown type of vector Domain_compact_symphi::affecte_tau" << endl ;
196  abort() ;
197  }
198  }
199  break ;
200  case 2 : {
201  bool found = false ;
202  // Cartesian basis and symetric
203  if ((tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) && (tt.get_n_comp()==6)) {
204  affecte_tau_val_domain (tt.set(1,1).set_domain(dom), cf, pos_cf) ;
205  affecte_tau_val_domain (tt.set(1,2).set_domain(dom), cf, pos_cf) ;
206  affecte_tau_val_domain (tt.set(1,3).set_domain(dom), cf, pos_cf) ;
207  affecte_tau_val_domain (tt.set(2,2).set_domain(dom), cf, pos_cf) ;
208  affecte_tau_val_domain (tt.set(2,3).set_domain(dom), cf, pos_cf) ;
209  affecte_tau_val_domain (tt.set(3,3).set_domain(dom), cf, pos_cf) ;
210  found = true ;
211  }
212  // Cartesian basis and not symetric
213  if ((tt.get_basis().get_basis(dom)==CARTESIAN_BASIS) && (tt.get_n_comp()==9)) {
214  affecte_tau_val_domain (tt.set(1,1).set_domain(dom), cf, pos_cf) ;
215  affecte_tau_val_domain (tt.set(1,2).set_domain(dom), cf, pos_cf) ;
216  affecte_tau_val_domain (tt.set(1,3).set_domain(dom), cf, pos_cf) ;
217  affecte_tau_val_domain (tt.set(2,1).set_domain(dom), cf, pos_cf) ;
218  affecte_tau_val_domain (tt.set(2,2).set_domain(dom), cf, pos_cf) ;
219  affecte_tau_val_domain (tt.set(2,3).set_domain(dom), cf, pos_cf) ;
220  affecte_tau_val_domain (tt.set(3,1).set_domain(dom), cf, pos_cf) ;
221  affecte_tau_val_domain (tt.set(3,2).set_domain(dom), cf, pos_cf) ;
222  affecte_tau_val_domain (tt.set(3,3).set_domain(dom), cf, pos_cf) ;
223  found = true ;
224  }
225  if (!found) {
226  cerr << "Unknown type of 2-tensor Domain_compact_symphi::affecte_tau" << endl ;
227  abort() ;
228  }
229  }
230  break ;
231  default :
232  cerr << "Valence " << val << " not implemented in Domain_compact_symphi::affecte_tau" << endl ;
233  break ;
234  }
235 }}
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 void affecte_tau(Tensor &, int, const Array< double > &, int &) const
Affects some coefficients to a Tensor.
void affecte_tau_val_domain(Val_domain &so, const Array< double > &cf, int &pos_cf) const
Affects some coefficients to a Val_domain.
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
int & set(int i)
Read/write of the position in a given dimension.
Definition: index.hpp:72
Val_domain & set_domain(int)
Read/write of a particular Val_domain.
Definition: scalar.hpp:555
const Domain * get_domain(int i) const
returns a pointer on the domain.
Definition: space.hpp:1385
Tensor handling.
Definition: tensor.hpp:149
Scalar & set(const Array< int > &ind)
Returns the value of a component (read/write version).
Definition: tensor_impl.hpp:91
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
const Space & get_space() const
Returns the Space.
Definition: tensor.hpp:499
Class for storing the basis of decompositions of a field and its values on both the configuration and...
Definition: val_domain.hpp:69
void allocate_coef()
Allocates the values in the coefficient space and destroys the values in the configuration space.
Definition: val_domain.cpp:216
Array< double > * cf
Pointer on the Array of the values in the coefficients space.
Definition: val_domain.hpp:77
const Base_spectral & get_base() const
Returns the basis of decomposition.
Definition: val_domain.hpp:122