KADATH
space_bin_fake.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 "bin_fake.hpp"
22 #include "utilities.hpp"
23 #include "point.hpp"
24 #include "scalar.hpp"
25 #include "tensor_impl.hpp"
26 #include "system_of_eqs.hpp"
27 #include "name_tools.hpp"
28 namespace Kadath {
29 
30 double eta_lim_chi (double chi, double rext, double a, double eta_c) ;
31 double chi_lim_eta (double chi, double rext, double a, double chi_c) ;
32 
33 double zerosec(double (*f)(double, const Param&), const Param& parf,
34  double x1, double x2, double precis, int nitermax, int& niter) ;
35 
36 
37 double func_afake (double aa, const Param& par) {
38  double r1 = par.get_double(0) ;
39  double r2 = par.get_double(1) ;
40  double d = par.get_double(2) ;
41  return (sqrt(aa*aa+r1*r1)+sqrt(aa*aa+r2*r2)-d) ;
42 }
43 
44 Space_bin_fake::Space_bin_fake (int ttype, double dist, double r1, double r2, double rbi, double rext, int nr) {
45 
46  ndim = 3 ;
47 
48  nbr_domains = 9;
49  type_base = ttype ;
50  domains = new Domain* [nbr_domains] ;
51 
52  Dim_array res (ndim) ;
53  res.set(0) = nr ; res.set(1) = nr ; res.set(2) = nr-1 ;
54  Dim_array res_bi(ndim) ;
55  res_bi.set(0) = nr ; res_bi.set(1) = nr ; res_bi.set(2) = nr ;
56 
57  // Bispheric :
58  // Computation of aa
59  Param par_a ;
60  par_a.add_double(r1,0) ;
61  par_a.add_double(r2,1) ;
62  par_a.add_double(dist,2) ;
63  double a_min = 0 ;
64  double a_max = dist/2. ;
65  double precis = PRECISION ;
66  int nitermax = 500 ;
67  int niter ;
68  double aa = zerosec(func_afake, par_a, a_min, a_max, precis, nitermax, niter) ;
69  double eta_plus = asinh(aa/r2) ;
70  double eta_minus = -asinh(aa/r1) ;
71 
72  double chi_c = 2*atan(aa/rbi) ;
73  double eta_c = log((1+rbi/aa)/(rbi/aa-1)) ;
74  double eta_lim = eta_c/2. ;
75  double chi_lim = chi_lim_eta (eta_lim, rbi, aa, chi_c) ;
76 
77  // Star 1
78  Point center_minus (ndim) ;
79  center_minus.set(1) = aa*cosh(eta_minus)/sinh(eta_minus) ;
80  domains[0] = new Domain_nucleus (0, ttype, r1, center_minus, res) ;
81 
82  // Star 2
83  Point center_plus (ndim) ;
84  center_plus.set(1) = aa*cosh(eta_plus)/sinh(eta_plus) ;
85  domains[1] = new Domain_nucleus (1, ttype, r2, center_plus, res) ;
86 
87  // Bispheric part
88  domains[2] = new Domain_bispheric_chi_first(2, ttype, aa, eta_minus, rbi, chi_lim, res_bi) ;
89  domains[3] = new Domain_bispheric_rect(3, ttype, aa, rbi, eta_minus, -eta_lim, chi_lim, res_bi) ;
90  domains[4] = new Domain_bispheric_eta_first(4, ttype, aa, rbi, -eta_lim, eta_lim, res_bi) ;
91  domains[5] = new Domain_bispheric_rect(5, ttype, aa, rbi, eta_plus, eta_lim, chi_lim, res_bi) ;
92  domains[6] = new Domain_bispheric_chi_first(6, ttype, aa, eta_plus, rbi, chi_lim, res_bi) ;
93 
94  Point center(3) ;
95  // Shell
96  domains[7] = new Domain_shell_surr (7, ttype, rbi, rext, center, res) ;
97 
98  // Compactified domain
99  domains[8] = new Domain_compact (8, ttype, rext, center, res) ;
100 }
101 
102 
104  fread_be (&nbr_domains, sizeof(int), 1, fd) ;
105  fread_be (&ndim, sizeof(int), 1, fd) ;
106  fread_be (&type_base, sizeof(int), 1, fd) ;
107  domains = new Domain* [nbr_domains] ;
108  // Star 1
109  domains[0] = new Domain_nucleus (0, fd) ;
110 
111  //Star 2
112  domains[1] = new Domain_nucleus (1, fd) ;
113 
114  // Bispheric
115  domains[2] = new Domain_bispheric_chi_first(2, fd) ;
116  domains[3] = new Domain_bispheric_rect(3, fd) ;
117  domains[4] = new Domain_bispheric_eta_first(4, fd) ;
118  domains[5] = new Domain_bispheric_rect(5, fd) ;
119  domains[6] = new Domain_bispheric_chi_first(6, fd) ;
120 
121  // Shell
122  domains[7] = new Domain_shell_surr (7, fd) ;
123 
124  // Compactified
125  domains[8] = new Domain_compact(8, fd) ;
126 }
127 
129 }
130 
131 void Space_bin_fake::save (FILE* fd) const {
132  fwrite_be (&nbr_domains, sizeof(int), 1, fd) ;
133  fwrite_be (&ndim, sizeof(int), 1, fd) ;
134  fwrite_be (&type_base, sizeof(int), 1, fd) ;
135  for (int i=0 ; i<nbr_domains ; i++)
136  domains[i]->save(fd) ;
137 }
138 
139 
141 
142  if (dom==0) {
143  // First sphere ;
144  Array<int> res (2,2) ;
145  switch (bound) {
146  case OUTER_BC :
147  res.set(0,0) = 2 ; // Matching with chi first
148  res.set(1,0) = INNER_BC ;
149  res.set(0,1) = 3 ; // Matching with rect
150  res.set(1,1) = INNER_BC ;
151  break ;
152  default :
153  cerr << "Bad bound in Space_bin_fake::get_indices_matching_non_std" << endl ;
154  abort() ;
155  }
156  return res ;
157  }
158 
159  if (dom==1) {
160  // second sphere ;
161  Array<int> res(2, 2) ;
162  switch (bound) {
163  case OUTER_BC :
164  res.set(0,0) = 5 ; // Matching with rect
165  res.set(1,0) = INNER_BC ;
166  res.set(0,1) = 6 ; // Matching with chi_first
167  res.set(1,1) = INNER_BC ;
168  break ;
169  default :
170  cerr << "Bad bound in Space_bin_fake::get_indices_matching_non_std" << endl ; abort() ;
171  }
172  return res ;
173  }
174 
175  if (dom== 2) {
176  // first chi first :
177  Array<int> res(2,1) ;
178  switch (bound) {
179  case INNER_BC :
180  res.set(0,0) = 0 ; // First sphere
181  res.set(1,0) = OUTER_BC ;
182  break ;
183  case OUTER_BC :
184  res.set(0,0) = 7 ; // Compactified domain or first shell
185  res.set(1,0) = INNER_BC ;
186  break ;
187  default :
188  cerr << "Bad bound in Space_bin_fake::get_indices_matching_non_std" << endl ; abort() ;
189  }
190  return res ;
191  }
192 
193  if (dom==3) {
194  // first rect :
195  Array<int> res(2, 1) ;
196  switch (bound) {
197  case INNER_BC :
198  res.set(0,0) = 0 ; // First sphere
199  res.set(1,0) = OUTER_BC ;
200  break ;
201  case OUTER_BC :
202  res.set(0,0) = 7 ; // Compactified domain or first shell
203  res.set(1,0) = INNER_BC ;
204  break ;
205  default :
206  cerr << "Bad bound in Space_bin_fake::get_indices_matching_non_std" << endl ; abort() ;
207  }
208  return res ;
209  }
210 
211 
212  if (dom==4) {
213  // eta first
214  Array<int> res(2, 1) ;
215  switch (bound) {
216  case OUTER_BC :
217  res.set(0, 0) = 7 ; // Compactified domain or first shell
218  res.set(1, 0) = INNER_BC ;
219  break ;
220  default :
221  cerr << "Bad bound in Space_bin_fake::get_indices_matching_non_std" << endl ; abort() ;
222  }
223  return res ;
224  }
225 
226  if (dom==5) {
227  // second rect :
228  Array<int> res(2, 1) ;
229  switch (bound) {
230  case INNER_BC :
231  res.set(0, 0) = 1 ; // Second sphere
232  res.set(1, 0) = OUTER_BC ;
233  break ;
234  case OUTER_BC :
235  res.set(0, 0) = 7 ; // Compactified domain or first shell
236  res.set(1, 0) = INNER_BC ;
237  break ;
238  default :
239  cerr << "Bad bound in Space_bin_fake::get_indices_matching_non_std" << endl ; abort() ;
240  }
241  return res ;
242  }
243 
244  if (dom==6) {
245  // second chi first :
246  Array<int> res(2, 1) ;
247  switch (bound) {
248  case INNER_BC :
249  res.set(0,0) = 1 ; // second nucleus
250  res.set(1,0) = OUTER_BC ;
251  break ;
252  case OUTER_BC :
253  res.set(0,0) = 7 ; // Compactified domain or first shell
254  res.set(1,0) = INNER_BC ;
255  break ;
256  default :
257  cerr << "Bad bound in Space_bin_fake::get_indices_matching_non_std" << endl ;
258  abort() ;
259  }
260  return res ;
261  }
262 
263  if (dom==7) {
264  // outer shell :
265  Array<int> res(2,5) ;
266  switch (bound) {
267  case INNER_BC :
268  res.set(0,0) = 2 ; // first chi first
269  res.set(0,1) = 3 ; // first rect
270  res.set(0,2) = 4 ; // eta first
271  res.set(0,3) = 5 ; // second rect
272  res.set(0,4) = 6 ; // second chi first
273  // Outer BC for all :
274  for (int i=0 ; i<5 ; i++)
275  res.set(1,i) = OUTER_BC ;
276  break ;
277  default :
278  cerr << "Bad bound in Space_bin_fake::get_indices_matching_non_std" << endl ;
279  abort() ;
280  }
281  return res ;
282  }
283 
284  cerr << "Bad domain in Space_bispheric::get_indices_matching_non_std" << endl ;
285  abort() ;
286 }
287 
288 }
reference set(const Index &pos)
Read/write of an element.
Definition: array.hpp:186
Class for storing the dimensions of an array.
Definition: dim_array.hpp:34
int & set(int i)
Read/write of the size of a given dimension.
Definition: dim_array.hpp:54
Class for bispherical coordinates with a symmetry with respect to the plane .
Definition: bispheric.hpp:460
Class for bispherical coordinates with a symmetry with respect to the plane .
Definition: bispheric.hpp:878
Class for bispherical coordinates with a symmetry with respect to the plane .
Definition: bispheric.hpp:64
Class for a spherical compactified domain and a symmetry with respect to the plane .
Definition: spheric.hpp:1007
Class for a spherical domain containing the origin and a symmetry with respect to the plane .
Definition: spheric.hpp:66
Class for a spherical shell and a symmetry with respect to the plane .
Definition: spheric.hpp:1597
Abstract class that implements the fonctionnalities common to all the type of domains.
Definition: space.hpp:60
Parameter storage.
Definition: param.hpp:30
void add_double(double x, int position=0)
Adds the the address of a new double to the list.
Definition: param.cpp:115
The class Point is used to store the coordinates of a point.
Definition: point.hpp:30
double & set(int i)
Read/write of a coordinate.
Definition: point.hpp:47
Space_bin_fake(int ttype, double dist, double r1, double r2, double rbi, double rext, int nr)
Standard constructor.
virtual Array< int > get_indices_matching_non_std(int dom, int bound) const
Gives the number of the other domains, touching a given boundary.
virtual void save(FILE *) const
Saving function.
virtual ~Space_bin_fake()
Destructor.
int type_base
Type of basis used (i.e. using either Chebyshev or Legendre polynomials).
Definition: space.hpp:1367
int ndim
Number of dimensions (should be the same for all the Domains).
Definition: space.hpp:1366
Domain ** domains
Pointers on the various Domains.
Definition: space.hpp:1368
int nbr_domains
Number od Domains.
Definition: space.hpp:1365