KADATH
ope_fit_waves.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 "ope_eq.hpp"
21 #include "scalar.hpp"
22 #include "tensor_impl.hpp"
23 #include "param.hpp"
24 #include "system_of_eqs.hpp"
25 #include <gsl/gsl_sf_bessel.h>
26 #include "spheric.hpp"
27 namespace Kadath {
28 Array<double> mat_leg_even (int, int) ;
29 Array<double> mat_leg_odd (int, int) ;
30 
31 Term_eq one (const Space& space, int mm, int ll, const Term_eq& omega, const Param& parfit) {
32 
33  int dom = omega.get_dom() ;
34 
35  Scalar valr (space) ;
36  Scalar derr (space) ;
37  valr.set_domain(dom) = 1 ;
38  derr.set_domain(dom) = 0 ;
39 
40  return Term_eq(dom, valr, derr) ;
41 }
42 
43 
44 Term_eq fjl (const Space& space, int mm, int ll, const Term_eq& omega, const Param& parfit) {
45 
46  double rmatch = parfit.get_double(0) ;
47  int dom = omega.get_dom() ;
48 
49  Scalar valr (space) ;
50  Scalar derr (space) ;
51  valr.set_domain(dom) = space.get_domain(dom)->get_radius() ;
52  valr.std_base() ;
53  derr.set_domain(dom) = 0 ;
54  derr.std_base() ;
55  Term_eq rr (dom, valr, derr) ;
56  valr.set_domain(dom) = rmatch ;
57  valr.std_base() ;
58  Term_eq rm (dom, valr, derr) ;
59 
60  if (mm==0) {
61  Term_eq res (pow(rm/rr, ll+1)) ;
62  return res ;
63  }
64  else {
65 
66  Term_eq res (bessel_jl(mm*rr*omega, ll) / bessel_jl(mm*rm*omega, ll)) ;
67  return res ;
68  }
69 }
70 
71 
72 Term_eq fyl (const Space& space, int mm, int ll, const Term_eq& omega, const Param& parfit) {
73 
74  double rmatch = parfit.get_double(0) ;
75  int dom = omega.get_dom() ;
76 
77  Scalar valr (space) ;
78  Scalar derr (space) ;
79  valr.set_domain(dom) = space.get_domain(dom)->get_radius() ;
80  valr.std_base() ;
81  derr.set_domain(dom) = 0 ;
82  derr.std_base() ;
83  Term_eq rr (dom, valr, derr) ;
84  valr.set_domain(dom) = rmatch ;
85  valr.std_base() ;
86  Term_eq rm (dom, valr, derr) ;
87 
88  if (mm==0) {
89  return (pow(rm/rr, (ll+1))) ;
90  }
91  else {
92  return (bessel_yl(mm*rr*omega, ll) / bessel_yl(mm*rm*omega, ll)) ;
93  }
94 
95 }
96 
97 
98 Ope_fit_waves::Ope_fit_waves (const System_of_eqs* zesys, Ope_eq* target, Ope_eq* omega) : Ope_eq(zesys, target->get_dom(), 2) {
99  parts[0] = target ;
100  parts[1] = omega ;
101 }
102 
104 }
105 
107 
108  Term_eq target (parts[0]->action()) ;
109  Term_eq omega (parts[1]->action()) ;
110 
111  const Domain_shell* pshell = dynamic_cast<const Domain_shell*> (syst->get_space().get_domain(dom)) ;
112  if (pshell==0x0) {
113  cerr << "Ope_fit_waves called in bad domain" << endl ;
114  abort() ;
115  }
116 
117 
118  return pshell->bc_waves (target, omega) ;
119 
120 /* bool doder = ((target.der_t==0x0) || (omega.der_d==0x0)) ? false : true ;
121 
122  // Check if so is a tensor
123  if (target.type_data != TERM_T) {
124  cerr << "Ope_fit_waves::action only defined for a tensor" << endl ;
125  abort() ;
126  }
127  int valence = target.val_t->get_valence() ;
128  if ((valence !=0) && (target.val_t->get_triad()!=target.val_t->get_space().get_bvect_cart())) {
129  cerr << "Ope_fit_waves::action only defined for Cartesian tensorial basis of decompostion" << endl ;
130  abort() ;
131  }
132 
133  double rmatch = syst->get_space().get_domain(dom)->get_rmax() ;
134  Param parfit ;
135  parfit.add_double (rmatch, 0) ;
136  const Domain* zedom = syst->get_space().get_domain(dom) ;
137 
138  Array<double> peven (mat_leg_even(zedom->get_nbr_coefs()(1), zedom->get_nbr_coefs()(2))) ;
139  Array<double> podd (mat_leg_odd(zedom->get_nbr_coefs()(1), zedom->get_nbr_coefs()(2))) ;
140 
141  Term_eq res (target) ;
142 
143  // Computation component by components...
144  for (int i=0 ; i<target.val_t->get_n_comp() ; i++) {
145  Array<int> ind (target.val_t->indices(i)) ;
146  // Sym or not sym ?
147  int sym = 1 ;
148  for (int n=0 ; n<ind.set_size(0) ; n++)
149  if (ind(n)==3)
150  sym *= -1 ;
151  if (sym==1) {
152  // Sym case
153  Term_eq res_cmp (zedom->harmonics_sym(target(ind), omega, OUTER_BC, fyl, parfit, peven)) ;
154  res.val_t->set(ind) = (*res_cmp.val_t)() ;
155  if (doder) {
156  res.der_t->set(ind) = (*res_cmp.der_t)() ;
157  }
158  }
159  else {
160  // Asym case
161  Term_eq res_cmp (zedom->harmonics_asym(target(ind), omega, OUTER_BC, fyl, parfit, podd)) ;
162  res.val_t->set(ind) = (*res_cmp.val_t)() ;
163  if (doder) {
164  res.der_t->set(ind) = (*res_cmp.der_t)() ;
165  }
166  }
167 
168  if ((*target.val_t)(ind)(dom).check_if_zero())
169  res.val_t->set(ind).set_domain(dom).set_zero() ;
170  else
171  res.val_t->set(ind).set_domain(dom).set_base() = (*target.val_t)(ind)(dom).get_base() ;
172  if (doder) {
173  if ((*target.der_t)(ind)(dom).check_if_zero())
174  res.der_t->set(ind).set_domain(dom).set_zero() ;
175  else
176  res.der_t->set(ind).set_domain(dom).set_base() = (*target.der_t)(ind)(dom).get_base() ;
177  }
178  }
179 
180  return res ;*/
181 }
182 
183 }
Class for a spherical shell and a symmetry with respect to the plane .
Definition: spheric.hpp:555
Term_eq bc_waves(const Term_eq &gamma, const Term_eq &omega) const
Gives an matching of the spatial metric, based on homogeneous solutions of outgoing waves.
Definition: bc_waves.cpp:33
Val_domain const & get_radius() const
Returns the generalized radius.
Definition: space.hpp:1465
Abstract class that describes the various operators that can appear in the equations.
Definition: ope_eq.hpp:32
const System_of_eqs * syst
The associated System_of_eqs.
Definition: ope_eq.hpp:35
MMPtr_array< Ope_eq > parts
Pointers of the various parts of the current operator.
Definition: ope_eq.hpp:38
int dom
Index of the Domain where the operator is defined.
Definition: ope_eq.hpp:36
Term_eq action() const override
Computes the action of the current Ope_eq using its various parts.
Ope_fit_waves(const System_of_eqs *syst, Ope_eq *so, Ope_eq *ome)
Constructor.
~Ope_fit_waves() override
Destructor.
Parameter storage.
Definition: param.hpp:30
const double & get_double(int position=0) const
Returns the reference of a double stored in the list.
Definition: param.cpp:148
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
void std_base()
Sets the standard basis of decomposition.
Definition: scalar.hpp:399
The Space class is an ensemble of domains describing the whole space of the computation.
Definition: space.hpp:1362
const Domain * get_domain(int i) const
returns a pointer on the domain.
Definition: space.hpp:1385
Class used to describe and solve a system of equations.
const Space & get_space() const
Returns the space.
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