LORENE
lindquist.C
1 /*
2  * Copyright (c) 2000-2001 Philippe Grandclement
3  *
4  * This file is part of LORENE.
5  *
6  * LORENE 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 2 of the License, or
9  * (at your option) any later version.
10  *
11  * LORENE 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 LORENE; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  */
21 
22 
23 
24 
25 /*
26  * $Id: lindquist.C,v 1.5 2016/12/05 16:17:45 j_novak Exp $
27  * $Log: lindquist.C,v $
28  * Revision 1.5 2016/12/05 16:17:45 j_novak
29  * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
30  *
31  * Revision 1.4 2014/10/13 08:52:40 j_novak
32  * Lorene classes and functions now belong to the namespace Lorene.
33  *
34  * Revision 1.3 2014/10/06 15:12:58 j_novak
35  * Modified #include directives to use c++ syntax.
36  *
37  * Revision 1.2 2002/10/16 14:36:33 j_novak
38  * Reorganization of #include instructions of standard C++, in order to
39  * use experimental version 3 of gcc.
40  *
41  * Revision 1.1.1.1 2001/11/20 15:19:28 e_gourgoulhon
42  * LORENE
43  *
44  * Revision 2.0 2000/12/13 15:42:57 phil
45  * *** empty log message ***
46  *
47  *
48  * $Header: /cvsroot/Lorene/C++/Source/Bhole_binaire/lindquist.C,v 1.5 2016/12/05 16:17:45 j_novak Exp $
49  *
50  */
51 
52 
53 //standard
54 #include <cstdlib>
55 #include <cmath>
56 
57 // LORENE
58 #include "type_parite.h"
59 #include "nbr_spx.h"
60 #include "proto.h"
61 #include "coord.h"
62 #include "tenseur.h"
63 
64 namespace Lorene {
65 double serie_lindquist_plus (double rayon, double distance, double xa, double ya,
66  double za, double precision, double itemax) {
67 
68 
69  double result = 0.5 ;
70  double c_n = rayon ;
71  double d_n = distance/2. ;
72 
73  int indic = 1 ;
74  int conte=0 ;
75  while ((indic == 1) && (conte <= itemax)) {
76 
77  double norme_plus = sqrt ((xa+d_n)*(xa+d_n)+ya*ya+za*za) ;
78 
79  double terme = c_n * 1./norme_plus ;
80  if (fabs(terme/result) < precision)
81  indic = -1 ;
82 
83  result = result + terme ;
84 
85  c_n *= rayon/(distance/2. + d_n) ;
86  d_n = distance/2. - rayon*rayon/(distance/2.+d_n) ;
87  conte ++ ;
88  }
89 
90  if (conte > itemax)
91  result = 1 ;
92 return result ;
93 }
94 
95 double serie_lindquist_moins (double rayon, double distance, double xa, double ya,
96  double za, double precision, double itemax) {
97 
98 
99  double result = 0.5 ;
100  double c_n = rayon ;
101  double d_n = distance/2. ;
102 
103  int indic = 1 ;
104  int conte=0 ;
105  while ((indic == 1) && (conte <= itemax)) {
106 
107  double norme_plus = sqrt ((xa-d_n)*(xa-d_n)+ya*ya+za*za) ;
108 
109  double terme = c_n * 1./norme_plus ;
110  if (fabs(terme/result) < precision)
111  indic = -1 ;
112 
113  result = result + terme ;
114 
115  c_n *= rayon/(distance/2. + d_n) ;
116  d_n = distance/2. - rayon*rayon/(distance/2.+d_n) ;
117  conte ++ ;
118  }
119 
120  if (conte > itemax)
121  result = 1 ;
122 return result ;
123 }
124 
125 double adm_serie (double rayon, double distance, double precision) {
126 
127  double result = 0 ;
128  double c_n = rayon ;
129  double d_n = distance/2. ;
130 
131  int indic =1 ;
132  while (indic == 1) {
133 
134  result += 4*c_n ;
135  if (fabs(c_n/result) < precision)
136  indic = -1 ;
137 
138  c_n *= rayon/(distance/2. + d_n) ;
139  d_n = distance/2. - rayon*rayon/(distance/2.+d_n) ;
140  }
141 return result ;
142 }
143 
144 double bare_serie (double rayon, double distance, double precision) {
145 
146  double result = 0 ;
147  double c_n = rayon ;
148  double d_n = distance/2. ;
149 
150  int indic =1 ;
151  int n = 1 ;
152  while (indic == 1) {
153 
154  result += 4*c_n*n ;
155  if (fabs(c_n/result) < precision)
156  indic = -1 ;
157 
158  c_n *= rayon/(distance/2. + d_n) ;
159  d_n = distance/2. - rayon*rayon/(distance/2.+d_n) ;
160  n++ ;
161  }
162 return result ;
163 }
164 
165 void set_lindquist (Cmp& psi_un, Cmp& psi_deux, double rayon, double precision) {
166 
167  // Pour les allocations !
168  psi_un = 1 ;
169  psi_deux = 1 ;
170 
171  double distance = psi_un.get_mp()->get_ori_x()-psi_deux.get_mp()->get_ori_x() ;
172 
173  // On regarde psi 1 :
174  Mtbl xa_mtbl_un (psi_un.get_mp()->xa) ;
175  Mtbl ya_mtbl_un (psi_un.get_mp()->ya) ;
176  Mtbl za_mtbl_un (psi_un.get_mp()->za) ;
177 
178  int nz_un = psi_un.get_mp()->get_mg()->get_nzone() ;
179  for (int l=1 ; l<nz_un ; l++) {
180  int np = psi_un.get_mp()->get_mg()->get_np (l) ;
181  int nt = psi_un.get_mp()->get_mg()->get_nt (l) ;
182  int nr = psi_un.get_mp()->get_mg()->get_nr (l) ;
183  double xa, ya, za ;
184  for (int k=0 ; k<np ; k++)
185  for (int j=0 ; j<nt ; j++)
186  for (int i=0 ; i<nr ; i++) {
187  xa = xa_mtbl_un (l, k, j, i) ;
188  ya = ya_mtbl_un (l, k, j, i) ;
189  za = za_mtbl_un (l, k, j, i) ;
190 
191  psi_un.set(l, k, j, i) =
192 serie_lindquist_moins (rayon, distance, xa, ya, za, precision, 30) ;
193  }
194  }
195 
196  psi_un.set_val_inf (0.5) ;
197  psi_un.std_base_scal() ;
198 
199  // On regarde psi 2 :
200  Mtbl xa_mtbl_deux (psi_deux.get_mp()->xa) ;
201  Mtbl ya_mtbl_deux (psi_deux.get_mp()->ya) ;
202  Mtbl za_mtbl_deux (psi_deux.get_mp()->za) ;
203 
204  int nz_deux = psi_deux.get_mp()->get_mg()->get_nzone() ;
205  for (int l=1 ; l<nz_deux ; l++) {
206  int np = psi_deux.get_mp()->get_mg()->get_np (l) ;
207  int nt = psi_deux.get_mp()->get_mg()->get_nt (l) ;
208  int nr = psi_deux.get_mp()->get_mg()->get_nr (l) ;
209  double xa, ya, za ;
210  for (int k=0 ; k<np ; k++)
211  for (int j=0 ; j<nt ; j++)
212  for (int i=0 ; i<nr ; i++) {
213  xa = xa_mtbl_deux (l, k, j, i) ;
214  ya = ya_mtbl_deux (l, k, j, i) ;
215  za = za_mtbl_deux (l, k, j, i) ;
216 
217  psi_deux.set(l, k, j, i) =
218 serie_lindquist_plus (rayon, distance, xa, ya, za, precision, 30) ;
219  }
220  }
221  psi_deux.set_val_inf (0.5) ;
222  psi_deux.std_base_scal() ;
223 }
224 }
Cmp sqrt(const Cmp &)
Square root.
Definition: cmp_math.C:223
Lorene prototypes.
Definition: app_hor.h:67