KADATH
fithor.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 "utilities.hpp"
22 
23 #include "bispheric.hpp"
24 #include "param.hpp"
25 #include "term_eq.hpp"
26 #include "scalar.hpp"
27 #include "tensor_impl.hpp"
28 #include "vector.hpp"
29 
30 namespace Kadath {
32 
33  Val_domain constante (this) ;
34  constante.allocate_conf() ;
35 
36  Index pos (nbr_points) ;
37  Index poshor (nbr_points) ;
38  do {
39  poshor.set(0) = 0 ;
40  poshor.set(1) = pos(1) ;
41  poshor.set(2) = pos(2) ;
42 
43  constante.set(pos) = so(poshor) ;
44  }
45  while (pos.inc()) ;
46 
47  double rhor = aa / sinh(fabs(eta_minus)) ;
48  double xc = aa*cosh(eta_minus)/sinh(eta_minus) ;
49 
50  Val_domain radloc2 ((get_cart(1)-xc)*(get_cart(1)-xc)+get_cart(2)*get_cart(2)+get_cart(3)*get_cart(3)) ;
51 
52  Val_domain result (constante*rhor*rhor/radloc2) ;
53  result.set_base() = so.get_base() ;
54  return result ;
55 }
56 
57 
59  // Check it is a tensor
60  if (so.get_type_data() != TERM_T) {
61  cerr << "fithor only defined with respect for a tensor" << endl ;
62  abort() ;
63  }
64 
65  // Right domain ?
66  int dom = so.get_dom() ;
67  if (this != so.get_val_t().get_space().get_domain(dom)) {
68  cerr << "Domain mismatch in Domain_bispheric_rect::fithor (Term_eq version)" << endl ;
69  abort() ;
70  }
71  int valence = so.get_val_t().get_valence() ;
72 
73  // Scalar ?
74  if ((valence!=0) && (valence!=1)) {
75  cerr << "Domain_bispheric_chi_first::fithor not definded for valence= " << valence << endl ;
76  abort() ;
77  }
78 
79  if (valence==0) {
80  Scalar resval (so.get_val_t(), false) ;
81  Val_domain value (so.get_val_t()()(dom)) ;
82  if (value.check_if_zero())
83  resval.set().set_domain(dom).set_zero() ;
84  else
85  resval.set().set_domain(dom) = fithor(value) ;
86 
87  if (so.get_p_der_t() !=0x0) {
88  Scalar resder (so.get_der_t(), false) ;
89  Val_domain valder (so.get_der_t()()(dom)) ;
90  if (valder.check_if_zero())
91  resder.set().set_domain(dom).set_zero() ;
92  else
93  resder.set().set_domain(dom) = fithor(valder) ;
94  return Term_eq (dom, resval, resder) ;
95  }
96  else return Term_eq (dom, resval) ;
97  }
98 
99 
100  if (valence==1) {
101  Vector resval (so.get_val_t().get_space(), so.get_val_t().get_index_type(0), so.get_val_t().get_basis()) ;
102  for (int i=1 ; i<=3 ; i++) {
103  Val_domain value (so.get_val_t()(i)(dom)) ;
104  if (value.check_if_zero())
105  resval.set(i).set_domain(dom).set_zero() ;
106  else
107  resval.set(i).set_domain(dom) = fithor(value) ;
108  }
109 
110  if (so.get_val_t().is_name_affected()) {
111  resval.set_name_affected() ;
112  resval.set_name_ind(0, so.get_val_t().get_name_ind()[0]) ;
113  }
114 
115  if (so.get_p_der_t() !=0x0) {
116  Vector resder (so.get_der_t().get_space(), so.get_der_t().get_index_type(0), so.get_der_t().get_basis()) ;
117  for (int i=1 ; i<=3 ; i++) {
118  Val_domain valder (so.get_der_t()(i)(dom)) ;
119  if (valder.check_if_zero())
120  resder.set(i).set_domain(dom).set_zero() ;
121  else
122  resder.set(i).set_domain(dom) = fithor(valder) ;
123  }
124  if (so.get_der_t().is_name_affected()) {
125  resder.set_name_affected() ;
126  resder.set_name_ind(0, so.get_val_t().get_name_ind()[0]) ;
127  }
128  return Term_eq (dom, resval, resder) ;
129  }
130  else return Term_eq (dom, resval) ;
131  }
132 
133  abort() ;
134 }
135 
137 
138 
139  Val_domain constante (this) ;
140  constante.allocate_conf() ;
141 
142  Index pos (nbr_points) ;
143  Index poshor (nbr_points) ;
144  do {
145  poshor.set(0) = 0 ;
146  poshor.set(1) = pos(1) ;
147  poshor.set(2) = pos(2) ;
148 
149  constante.set(pos) = so(poshor) ;
150  }
151  while (pos.inc()) ;
152 
153  double rhor = aa / sinh(fabs(eta_lim)) ;
154  double xc = aa*cosh(eta_lim)/sinh(eta_lim) ;
155 
156  Val_domain radloc2 ((get_cart(1)-xc)*(get_cart(1)-xc)+get_cart(2)*get_cart(2)+get_cart(3)*get_cart(3)) ;
157 
158 
159  Val_domain result (constante*rhor*rhor/radloc2) ;
160  result.set_base() = so.get_base() ;
161  return result ;
162 }
163 
164 
166  // Check it is a tensor
167  if (so.get_type_data() != TERM_T) {
168  cerr << "fithor only defined with respect for a tensor" << endl ;
169  abort() ;
170  }
171 
172  // Right domain ?
173  int dom = so.get_dom() ;
174  if (this != so.get_val_t().get_space().get_domain(dom)) {
175  cerr << "Domain mismatch in Domain_bispheric_chi_first::fithor (Term_eq version)" << endl ;
176  abort() ;
177  }
178 
179  int valence = so.get_val_t().get_valence() ;
180 
181  // Scalar ?
182  if ((valence!=0) && (valence!=1)) {
183  cerr << "Domain_bispheric_chi_first::fithor not definded for valence= " << valence << endl ;
184  abort() ;
185  }
186 
187  if (valence==0) {
188  Scalar resval (so.get_val_t(), false) ;
189  Val_domain value (so.get_val_t()()(dom)) ;
190  if (value.check_if_zero())
191  resval.set().set_domain(dom).set_zero() ;
192  else
193  resval.set().set_domain(dom) = fithor(value) ;
194 
195  if (so.get_p_der_t() !=0x0) {
196  Scalar resder (so.get_der_t(), false) ;
197  Val_domain valder (so.get_der_t()()(dom)) ;
198  if (valder.check_if_zero())
199  resder.set().set_domain(dom).set_zero() ;
200  else
201  resder.set().set_domain(dom) = fithor(valder) ;
202  return Term_eq (dom, resval, resder) ;
203  }
204  else return Term_eq (dom, resval) ;
205  }
206 
207 
208  if (valence==1) {
209  Vector resval (so.get_val_t().get_space(), so.get_val_t().get_index_type(0), so.get_val_t().get_basis()) ;
210  for (int i=1 ; i<=3 ; i++) {
211  Val_domain value (so.get_val_t()(i)(dom)) ;
212  if (value.check_if_zero())
213  resval.set(i).set_domain(dom).set_zero() ;
214  else
215  resval.set(i).set_domain(dom) = fithor(value) ;
216  }
217  if (so.get_val_t().is_name_affected()) {
218  resval.set_name_affected() ;
219  resval.set_name_ind(0, so.get_val_t().get_name_ind()[0]) ;
220  }
221 
222  if (so.get_p_der_t() !=0x0) {
223  Vector resder (so.get_der_t().get_space(), so.get_der_t().get_index_type(0), so.get_der_t().get_basis()) ;
224  for (int i=1 ; i<=3 ; i++) {
225  Val_domain valder (so.get_der_t()(i)(dom)) ;
226  if (valder.check_if_zero())
227  resder.set(i).set_domain(dom).set_zero() ;
228  else
229  resder.set(i).set_domain(dom) = fithor(valder) ;
230  }
231 
232  if (so.get_der_t().is_name_affected()) {
233  resder.set_name_affected() ;
234  resder.set_name_ind(0, so.get_der_t().get_name_ind()[0]) ;
235  }
236  return Term_eq (dom, resval, resder) ;
237  }
238  else return Term_eq (dom, resval) ;
239  }
240 
241  abort() ;
242 
243 }
244 }
245 
double aa
Distance scale .
Definition: bispheric.hpp:463
Term_eq fithor(const Term_eq &so) const
Returns a fit in with respect to the inner spherical boundary.
Definition: fithor.cpp:165
double eta_lim
Lower bound for .
Definition: bispheric.hpp:464
double eta_minus
associated with .
Definition: bispheric.hpp:69
double aa
Distance scale .
Definition: bispheric.hpp:67
Term_eq fithor(const Term_eq &so) const
Returns a fit in with respect to the inner spherical boundary.
Definition: fithor.cpp:58
Dim_array nbr_points
Number of colocation points.
Definition: space.hpp:65
Val_domain const & get_cart(int i) const
Returns a Cartesian coordinates.
Definition: space.hpp:1471
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
bool inc(int increm, int var=0)
Increments the position of the Index.
Definition: index.hpp:99
The class Scalar does not really implements scalars in the mathematical sense but rather tensorial co...
Definition: scalar.hpp:67
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
void set_name_ind(int dd, char name)
Sets the name of one index ; the names must have been affected first.
void set_name_affected()
Affects the name of the indices.
Definition: tensor.hpp:435
Scalar & set(const Array< int > &ind)
Returns the value of a component (read/write version).
Definition: tensor_impl.hpp:91
char const * get_name_ind() const
Definition: tensor.hpp:424
int get_index_type(int i) const
Gives the type (covariant or contravariant) of a given index.
Definition: tensor.hpp:526
const Base_tensor & get_basis() const
Returns the vectorial basis (triad) on which the components are defined.
Definition: tensor.hpp:504
int get_valence() const
Returns the valence.
Definition: tensor.hpp:509
bool is_name_affected() const
Check whether the names of the indices have been affected.
Definition: tensor.hpp:429
const Space & get_space() const
Returns the Space.
Definition: tensor.hpp:499
This class is intended to describe the manage objects appearing in the equations.
Definition: term_eq.hpp:62
int get_dom() const
Definition: term_eq.hpp:135
int get_type_data() const
Definition: term_eq.hpp:131
const Tensor * get_p_der_t() const
Definition: term_eq.hpp:127
Tensor const & get_val_t() const
Definition: term_eq.hpp:355
Tensor const & get_der_t() const
Definition: term_eq.hpp:369
Class for storing the basis of decompositions of a field and its values on both the configuration and...
Definition: val_domain.hpp:69
void set_zero()
Sets the Val_domain to zero (logical state to zero and arrays destroyed).
Definition: val_domain.cpp:223
bool check_if_zero() const
Check whether the logical state is zero or not.
Definition: val_domain.hpp:142
double & set(const Index &pos)
Read/write the value of the field in the configuration space.
Definition: val_domain.cpp:171
Base_spectral & set_base()
Sets the basis of decomposition.
Definition: val_domain.hpp:126
void allocate_conf()
Allocates the values in the configuration space and destroys the values in the coefficients space.
Definition: val_domain.cpp:209
const Base_spectral & get_base() const
Returns the basis of decomposition.
Definition: val_domain.hpp:122
A class derived from Tensor to deal specificaly with objects of valence 1 (and so also 1-forms).
Definition: vector.hpp:41
Scalar & set(int)
Read/write access to a component.