LORENE
valeur_equipot_out.C
1 /*
2  * Method of the class Valeur to compute an equipotential surface
3  * (outward search)
4  *
5  * (see file valeur.h for the documentation).
6  */
7 
8 /*
9  * Copyright (c) 2000-2001 Eric Gourgoulhon
10  *
11  * This file is part of LORENE.
12  *
13  * LORENE is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 2 of the License, or
16  * (at your option) any later version.
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 /*
33  * $Id: valeur_equipot_out.C,v 1.6 2016/12/05 16:18:20 j_novak Exp $
34  * $Log: valeur_equipot_out.C,v $
35  * Revision 1.6 2016/12/05 16:18:20 j_novak
36  * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
37  *
38  * Revision 1.5 2014/10/13 08:53:50 j_novak
39  * Lorene classes and functions now belong to the namespace Lorene.
40  *
41  * Revision 1.4 2014/10/06 15:13:23 j_novak
42  * Modified #include directives to use c++ syntax.
43  *
44  * Revision 1.3 2003/12/19 15:05:57 j_novak
45  * Added some initializations
46  *
47  * Revision 1.2 2002/10/16 14:37:15 j_novak
48  * Reorganization of #include instructions of standard C++, in order to
49  * use experimental version 3 of gcc.
50  *
51  * Revision 1.1.1.1 2001/11/20 15:19:27 e_gourgoulhon
52  * LORENE
53  *
54  * Revision 2.2 2001/01/08 10:48:27 eric
55  * Version moins severe avec les discontinuites entre les domaines
56  * (on a remplace un abort() par un warning).
57  *
58  * Revision 2.1 2000/11/10 15:20:55 eric
59  * Les 1.e-14 sont remplaces par precis0 = precis.
60  *
61  * Revision 2.0 2000/11/10 13:32:19 eric
62  * *** empty log message ***
63  *
64  *
65  * $Header: /cvsroot/Lorene/C++/Source/Valeur/valeur_equipot_out.C,v 1.6 2016/12/05 16:18:20 j_novak Exp $
66  *
67  */
68 
69 // Headers C
70 #include <cstdlib>
71 #include <cmath>
72 
73 // Headers Lorene
74 #include "valeur.h"
75 #include "itbl.h"
76 #include "param.h"
77 #include "nbr_spx.h"
78 #include "utilitaires.h"
79 
80 // Local prototypes
81 namespace Lorene {
82 double valeur_equipot_fonc(double, const Param&) ;
83 
84 //****************************************************************************
85 
86 void Valeur::equipot_outward(double uu0, int nz_search, double precis,
87  int nitermax, int& niter, Itbl& l_iso,
88  Tbl& xi_iso) const {
89 
90 
91  int nz = mg->get_nzone() ;
92  int nt = mg->get_nt(0) ;
93  int np = mg->get_np(0) ;
94 
95  double precis0 = precis ;
96 
97  // Protections
98  // -----------
99  assert(etat == ETATQCQ) ;
100  assert(nz_search > 0) ;
101  assert(nz_search <= nz) ;
102  for (int l=1; l<nz_search; l++) {
103  assert( mg->get_nt(l) == nt ) ;
104  assert( mg->get_np(l) == np ) ;
105  }
106 
107  coef() ; // the spectral coefficients are required
108 
109  l_iso.set_etat_qcq() ;
110  xi_iso.set_etat_qcq() ;
111 
112  Param parf ;
113  int j, k, l2 ;
114  parf.add_int_mod(j, 0) ;
115  parf.add_int_mod(k, 1) ;
116  parf.add_int_mod(l2, 2) ;
117  parf.add_double(uu0) ;
118  parf.add_mtbl_cf(*c_cf) ;
119 
120 
121  // Loop of phi and theta
122  // ---------------------
123 
124  niter = 0 ;
125 
126  for (k=0; k<np; k++) {
127 
128  for (j=0; j<nt; j++) {
129 
130 
131 // 1. Recherche du point de collocation en r (l2,i2) egal a ou situe
132 // immediatement apres r_iso(phi,theta)
133 
134  int i2 = 0 ;
135  l2 = nz ;
136  for (int l=0; l<nz_search; l++) {
137  int nr = mg->get_nr(l) ;
138 
139  for (int i=0; i<nr; i++) {
140  double uux = (*this)(l, k, j, i) ;
141  if ( ( (uux < uu0) || ( fabs(uux-uu0) < precis0 ) ) &&
142  (uux != __infinity) ) {
143  l2 = l ; // on a trouve le point
144  i2 = i ; //
145  break ;
146  }
147  }
148 
149  if (l2 == l) break ;
150  } // fin de la boucle sur les zones
151 
152  if (l2==nz) {
153  cout <<
154  "Valeur::equipot_outward: the point uu < uu0 has not been found"
155  << endl ;
156  cout << " for the phi index " << k
157  << " and the theta index " << j << endl ;
158  cout << " uu0 = " << uu0 << endl ;
159  abort () ;
160  }
161 
162 // 2. Point precedent (l2,i3)
163  int i3 = 0 ;
164  if (i2 != 0) { // on reste dans la meme zone
165  i3 = i2 - 1 ;
166  }
167  else {
168  if (l2 != 0) { // on change de zone
169 
170  l2-- ;
171  i2 = mg->get_nr(l2) - 1 ;
172 
173  double uux = (*this)(l2, k, j, i2) ;
174 
175  if ( ( fabs(uux-uu0) > precis0 ) ) {
176  // the field may slightly discontinuous:
177  cout <<
178  "Valeur::equipot_outward: WARNING: potentially discontinuous field !"
179  << endl ;
180  cout << " k, j : " << k << " " << j << endl ;
181  cout << " uux, uu0 : " << uux << " " << uu0 << endl ;
182  }
183 
184  l_iso.set(k, j) = l2 ;
185  xi_iso.set(k, j) = (mg->get_grille3d(l2))->x[i2] ;
186  continue ; // theta suivant
187 
188  }
189  else { // l2 = 0, i2 = 0
190  cout <<
191  "Valeur::equipot_outward: the field has some negative value at the center !"
192  << endl ;
193  cout << " k, j : " << k << " " << j << endl ;
194  cout << " uu0 : " << uu0 << endl ;
195  abort () ;
196  }
197  }
198 
199  l_iso.set(k, j) = l2 ;
200 
201  double x2 = (mg->get_grille3d(l2))->x[i2] ;
202  double x3 = (mg->get_grille3d(l2))->x[i3] ;
203 
204  double y2 = (*this)(l2, k, j, i2) - uu0 ;
205 
206 // 3. Recherche de x0
207 
208  int niter0 = 0 ;
209  if (fabs(y2) < precis0) {
210  xi_iso.set(k, j) = x2 ;
211  }
212  else {
213  xi_iso.set(k, j) = zerosec(valeur_equipot_fonc, parf, x2, x3, precis,
214  nitermax, niter0 ) ;
215  }
216 
217  niter = ( niter0 > niter ) ? niter0 : niter ;
218 
219  } // fin de la boucle sur theta
220  } // fin de la boucle sur phi
221 
222 }
223 
224 }
const Grille3d * get_grille3d(int l) const
Returns a pointer on the 3D mono-grid for domain no. l.
Definition: grilles.h:517
Mtbl_cf * c_cf
Coefficients of the spectral expansion of the function.
Definition: valeur.h:312
int & set(int i)
Read/write of a particular element (index i ) (1D case)
Definition: itbl.h:247
int get_np(int l) const
Returns the number of points in the azimuthal direction ( ) in domain no. l.
Definition: grilles.h:479
void coef() const
Computes the coeffcients of *this.
Definition: valeur_coef.C:151
Lorene prototypes.
Definition: app_hor.h:67
double & set(int i)
Read/write of a particular element (index i) (1D case)
Definition: tbl.h:301
Basic integer array class.
Definition: itbl.h:122
void add_mtbl_cf(const Mtbl_cf &mi, int position=0)
Adds the address of a new Mtbl_cf to the list.
Definition: param.C:1282
double zerosec(double(*f)(double, const Param &), const Param &par, double a, double b, double precis, int nitermax, int &niter, bool abort=true)
Finding the zero a function.
Definition: zerosec.C:92
void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
Definition: tbl.C:364
const Mg3d * mg
Multi-grid Mgd3 on which this is defined.
Definition: valeur.h:302
Parameter storage.
Definition: param.h:125
int get_nzone() const
Returns the number of domains.
Definition: grilles.h:465
void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
Definition: itbl.C:264
int get_nr(int l) const
Returns the number of points in the radial direction ( ) in domain no. l.
Definition: grilles.h:469
void equipot_outward(double uu0, int nz_search, double precis, int nitermax, int &niter, Itbl &l_iso, Tbl &xi_iso) const
Determines an equipotential surface of the field represented by *this (outward search).
void add_double(const double &x, int position=0)
Adds the the address of a new double to the list.
Definition: param.C:318
int etat
Logical state (ETATNONDEF , ETATQCQ or ETATZERO ).
Definition: valeur.h:305
Basic array class.
Definition: tbl.h:164
int get_nt(int l) const
Returns the number of points in the co-latitude direction ( ) in domain no. l.
Definition: grilles.h:474
void add_int_mod(int &n, int position=0)
Adds the address of a new modifiable int to the list.
Definition: param.C:388