KADATH
fitschwarz.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_periodic.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
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
63 
64 #ifndef REMOVE_ALL_CHECKS
65  // Check it is a tensor
66  if (so.get_type_data() != TERM_T) {
67  cerr << "fitschwarz only defined with respect for a tensor" << endl ;
68  abort() ;
69  }
70 #endif
71 
72  // Right domain ?
73  int dom = so.get_dom() ;
74 #ifndef REMOVE_ALL_CHECKS
75  if (this != so.get_val_t().get_space().get_domain(dom)) {
76  cerr << "Domain mismatch in Domain_spheric_periodic_shell::fitschwarz (Term_eq version)" << endl ;
77  abort() ;
78  }
79 #endif
80 
81  Tensor resval (so.get_val_t(), false) ;
82  for (int i=0 ; i<so.get_val_t().get_n_comp() ; i++) {
83  Array<int> ind (so.get_val_t().indices(i)) ;
84  Val_domain value (so.get_val_t()(ind)(dom)) ;
85  if (value.check_if_zero())
86  resval.set(ind).set_domain(dom).set_zero() ;
87  else {
88  resval.set(ind).set_domain(dom) = fitschwarz(value, dim) ;
89  }
90  }
91 
92  if (so.get_p_der_t() !=0x0) {
93  Tensor resder (so.get_val_t(), false) ;
94  for (int i=0 ; i<so.get_der_t().get_n_comp() ; i++) {
95  Array<int> ind (so.get_der_t().indices(i)) ;
96  Val_domain valder (so.get_der_t()(ind)(dom)) ;
97  if (valder.check_if_zero())
98  resder.set(ind).set_domain(dom).set_zero() ;
99  else {
100  resder.set(ind).set_domain(dom) = fitschwarz(valder, dim) ;
101  }
102  }
103  return Term_eq (dom, resval, resder) ;
104  }
105  else return Term_eq (dom, resval) ;
106 }}
Val_domain fitschwarz(const Val_domain &, int) const
Fit some field with a decay (Val_domain version).
Definition: fitschwarz.cpp:29
double alpha
Relates the numerical to the physical radii.
double beta
Relates the numerical to the physical radii.
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