LORENE
et_bin_bhns_extr_max.C
1 /*
2  * Method of class Et_bin_bhns_extr to search the position of the maximum
3  * enthalpy
4  *
5  * (see file et_bin_bhns_extr.h for documentation).
6  *
7  */
8 
9 /*
10  * Copyright (c) 2004 Keisuke Taniguchi
11  *
12  * This file is part of LORENE.
13  *
14  * LORENE is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License version 2
16  * as published by the Free Software Foundation.
17  *
18  * LORENE is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with LORENE; if not, write to the Free Software
25  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26  *
27  */
28 
29 
30 
31 /*
32  * $Id: et_bin_bhns_extr_max.C,v 1.4 2016/12/05 16:17:52 j_novak Exp $
33  * $Log: et_bin_bhns_extr_max.C,v $
34  * Revision 1.4 2016/12/05 16:17:52 j_novak
35  * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
36  *
37  * Revision 1.3 2014/10/13 08:52:55 j_novak
38  * Lorene classes and functions now belong to the namespace Lorene.
39  *
40  * Revision 1.2 2014/10/06 15:13:07 j_novak
41  * Modified #include directives to use c++ syntax.
42  *
43  * Revision 1.1 2004/11/30 20:50:24 k_taniguchi
44  * *** empty log message ***
45  *
46  *
47  * $Header: /cvsroot/Lorene/C++/Source/Etoile/et_bin_bhns_extr_max.C,v 1.4 2016/12/05 16:17:52 j_novak Exp $
48  *
49  */
50 
51 // C headers
52 #include <cmath>
53 
54 // Lorene headers
55 #include "et_bin_bhns_extr.h"
56 //#include "utilitaires.h"
57 
58 namespace Lorene {
59 void Et_bin_bhns_extr::ent_max_search(double& xx, double& yy) const {
60 
61  //------------------------------------------------------------------//
62  // Calculate the derivative of the enthalpy field //
63  //------------------------------------------------------------------//
64 
65  const Tenseur& dent = ent.gradient() ;
66 
67  double xxp = 0. ; // Position of the x-coordinate, initialized to zero
68  double yyp = 0. ; // Position of the y-coordinate, initialized to zero
69  double xtmp, ytmp ;
70  int mm, nn ; // Number of steps to the x and y directions
71  double rr = 0. ; // r coordinate, initialized to zero
72  double pp = M_PI/2. ; // phi coordinate, initialized to M_PI/2.
73  double dval_x ; // Direction of dent(0) (1 or -1)
74  double dval_y ; // Direction of dent(1) (1 or -1)
75  double ss ;
76 
77  while ( fabs(dent(0).val_point(rr, M_PI/2., pp)) > 1.e-15 ||
78  fabs(dent(1).val_point(rr, M_PI/2., pp)) > 5.e-15) {
79 
80  double dx = 1. ; // Step interval to the x-direction, initialized to 1
81  double dy = 1. ; // Step interval to the y-direction, initialized to 1
82  double diff_dent_x ;
83  double diff_dent_y ;
84 
85  while ( dy > 1.e-15 ) {
86 
87  diff_dent_y = 1. ;
88  nn = 0 ;
89  dy = 0.1 * dy ;
90 
91  rr = sqrt( xxp*xxp + yyp*yyp ) ;
92 
93  if ( xxp == 0. ) {
94  pp = M_PI/2. ; // There is a possibility of (pp = 1.5*M_PI)
95  }
96  else {
97  pp = acos( xxp / rr ) ;
98  }
99 
100  dval_y = dent(1).val_point(rr, M_PI/2., pp) ;
101 
102  if ( dval_y > 0. ) {
103  ss = 1. ;
104  }
105  else {
106  ss = -1. ;
107  }
108 
109  while( diff_dent_y > 1.e-15 ) {
110 
111  nn++ ;
112  ytmp = yyp + ss * nn * dy ;
113 
114  rr = sqrt( xxp*xxp + ytmp*ytmp ) ;
115 
116  if ( xxp == 0. ) {
117  if ( ss > 0. ) {
118  pp = M_PI/2. ;
119  }
120  else {
121  pp = 1.5*M_PI ;
122  }
123  }
124  else {
125  pp = acos( xxp / rr ) ;
126  }
127 
128  diff_dent_y = ss * dent(1).val_point(rr, M_PI/2., pp) ;
129 
130  }
131  yyp += ss * (nn - 1) * dy ;
132 
133  }
134 
135  while ( dx > 1.e-15 ) {
136 
137  diff_dent_x = 1. ;
138  mm = 0 ;
139  dx = 0.1 * dx ;
140 
141  rr = sqrt( xxp*xxp + yyp*yyp ) ;
142 
143  if ( xxp == 0. ) {
144  pp = M_PI/2. ; // There is a possibility of (pp = 1.5*M_PI)
145  }
146  else {
147  pp = acos( xxp / rr ) ;
148  }
149 
150  dval_x = dent(0).val_point(rr, M_PI/2., pp) ;
151 
152  if ( dval_x > 0. ) {
153  ss = 1. ;
154  }
155  else {
156  ss = -1. ;
157  }
158 
159  while( diff_dent_x > 1.e-15 ) {
160 
161  mm++ ;
162  xtmp = xxp + ss * mm * dx ;
163 
164  rr = sqrt( xtmp*xtmp + yyp*yyp ) ;
165 
166  if ( xtmp == 0. ) {
167  if ( ss > 0. ) {
168  pp = M_PI/2. ;
169  }
170  else {
171  pp = 1.5*M_PI ;
172  }
173  }
174  else {
175  pp = acos( xtmp / rr ) ;
176  }
177 
178  diff_dent_x = ss * dent(0).val_point(rr, M_PI/2., pp) ;
179 
180  }
181  xxp += ss * (mm - 1) * dx ;
182 
183  }
184  }
185 
186  xx = xxp ;
187  yy = yyp ;
188 
189 }
190 }
Cmp sqrt(const Cmp &)
Square root.
Definition: cmp_math.C:223
Lorene prototypes.
Definition: app_hor.h:67
void ent_max_search(double &xx, double &yy) const
Searches the position of the maximum enthalpy.
Tenseur ent
Log-enthalpy (relativistic case) or specific enthalpy (Newtonian case)
Definition: etoile.h:460
Cmp acos(const Cmp &)
Arccosine.
Definition: cmp_math.C:172
Tensor handling *** DEPRECATED : use class Tensor instead ***.
Definition: tenseur.h:304
const Tenseur & gradient() const
Returns the gradient of *this (Cartesian coordinates)
Definition: tenseur.C:1558