KADATH
fitschwarz_shell.cpp
1 /*
2  Copyright 2018 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.hpp"
22 #include "term_eq.hpp"
23 #include "scalar.hpp"
24 #include "tensor_impl.hpp"
25 #include "tensor.hpp"
26 #include "array_math.hpp"
27 namespace Kadath {
28 // Val_domain versions
29 Val_domain Domain_shell::fitschwarz (const Val_domain& so, int dim) const {
30 
31  so.coef() ;
32  Val_domain dso (der_normal(so, OUTER_BC)) ;
33 
34  Val_domain res(this) ;
35  res.base = so.base ;
36  res.allocate_coef() ;
37 
38  double rmax = alpha + beta ;
39 
40  Index pos (nbr_coefs) ;
41 
42  // Loop on harmonic
43  for (int nn=0 ; nn<nbr_coefs(1) ; nn++) {
44 
45  pos.set(1) = nn ;
46 
47  double sh = (nn==0) ? 1./pow(rmax, dim-2) : 0 ;
48  double dsh = (nn==0) ? -double(dim-2)/pow(rmax, dim-1) : 1 ;
49 
50  // Affecte to res
51  for (int i=0 ; i<nbr_coefs(0) ; i++) {
52  pos.set(0) = i ;
53  res.set_coef(pos) = (nn==0) ? so.get_coef(pos)*dsh - dso.get_coef(pos)*sh : so.get_coef(pos);
54  }
55 
56  }
57  return res ;
58 }
59 
60 
61 // Term_eq version
62 Term_eq Domain_shell::fitschwarz (const Term_eq& so, int dim) const {
63 
64  // Check it is a tensor
65  if (so.get_type_data() != TERM_T) {
66  cerr << "fitschwarz only defined with respect for a tensor" << endl ;
67  abort() ;
68  }
69 
70  // Right domain ?
71  int dom = so.get_dom() ;
72  if (this != so.get_val_t().get_space().get_domain(dom)) {
73  cerr << "Domain mismatch in Domain_shell::fitschwarz (Term_eq version)" << endl ;
74  abort() ;
75  }
76 
77  Tensor resval (so.get_val_t(), false) ;
78  for (int i=0 ; i<so.get_val_t().get_n_comp() ; i++) {
79  Array<int> ind (so.get_val_t().indices(i)) ;
80  Val_domain value (so.get_val_t()(ind)(dom)) ;
81  if (value.check_if_zero())
82  resval.set(ind).set_domain(dom).set_zero() ;
83  else {
84  resval.set(ind).set_domain(dom) = fitschwarz(value, dim) ;
85  }
86  }
87 
88  if (so.get_p_der_t() !=0x0) {
89  Tensor resder (so.get_val_t(), false) ;
90  for (int i=0 ; i<so.get_der_t().get_n_comp() ; i++) {
91  Array<int> ind (so.get_der_t().indices(i)) ;
92  Val_domain valder (so.get_der_t()(ind)(dom)) ;
93  if (valder.check_if_zero())
94  resder.set(ind).set_domain(dom).set_zero() ;
95  else {
96  resder.set(ind).set_domain(dom) = fitschwarz(valder, dim) ;
97  }
98  }
99  return Term_eq (dom, resval, resder) ;
100  }
101  else return Term_eq (dom, resval) ;
102 }}
103 
double beta
Relates the numerical to the physical radii.
Definition: spheric.hpp:559
double alpha
Relates the numerical to the physical radii.
Definition: spheric.hpp:558
Val_domain fitschwarz(const Val_domain &, int) const
Fit some field with a decay (Val_domain version).
virtual Val_domain der_normal(const Val_domain &, int) const
Normal derivative with respect to a given surface.
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
virtual Array< int > indices(int pos) const
Gives the values of the indices corresponding to a location in the array used for storage of the comp...
Definition: tensor.hpp:484
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
Base_spectral base
Spectral basis of the field.
Definition: val_domain.hpp:72
double & set_coef(const Index &pos)
Read/write the value of the field in the coefficient space.
Definition: val_domain.cpp:177
void set_zero()
Sets the Val_domain to zero (logical state to zero and arrays destroyed).
Definition: val_domain.cpp:223
void allocate_coef()
Allocates the values in the coefficient space and destroys the values in the configuration space.
Definition: val_domain.cpp:216
bool check_if_zero() const
Check whether the logical state is zero or not.
Definition: val_domain.hpp:142
void coef() const
Computes the coefficients.
Definition: val_domain.cpp:622
Array< double > get_coef() const
Definition: val_domain.hpp:136