LORENE
star_rot_lambda_grv2.C
1 /*
2  * Method Star_rot::lambda_grv2.
3  *
4  * (see file star_rot.h for documentation)
5  *
6  */
7 
8 /*
9  * Copyright (c) 2010 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 char star_rot_lambda_grv2_C[] = "$Header: /cvsroot/Lorene/C++/Source/Star/star_rot_lambda_grv2.C,v 1.4 2014/10/13 08:53:39 j_novak Exp $" ;
31 
32 /*
33  * $Id: star_rot_lambda_grv2.C,v 1.4 2014/10/13 08:53:39 j_novak Exp $
34  * $Log: star_rot_lambda_grv2.C,v $
35  * Revision 1.4 2014/10/13 08:53:39 j_novak
36  * Lorene classes and functions now belong to the namespace Lorene.
37  *
38  * Revision 1.3 2014/10/06 15:13:17 j_novak
39  * Modified #include directives to use c++ syntax.
40  *
41  * Revision 1.2 2013/06/05 15:10:43 j_novak
42  * Suppression of FINJAC sampling in r. This Jacobi(0,2) base is now
43  * available by setting colloc_r to BASE_JAC02 in the Mg3d constructor.
44  *
45  * Revision 1.1 2010/01/25 18:15:52 e_gourgoulhon
46  * First version.
47  *
48  *
49  *
50  * $Header: /cvsroot/Lorene/C++/Source/Star/star_rot_lambda_grv2.C,v 1.4 2014/10/13 08:53:39 j_novak Exp $
51  *
52  */
53 
54 // Headers C
55 #include <cmath>
56 
57 // Headers Lorene
58 #include "star_rot.h"
59 #include "proto_f77.h"
60 
61 namespace Lorene {
62 double Star_rot::lambda_grv2(const Scalar& sou_m, const Scalar& sou_q) {
63 
64  const Map_radial* mprad = dynamic_cast<const Map_radial*>( &sou_m.get_mp() ) ;
65 
66  if (mprad == 0x0) {
67  cout << "Star_rot::lambda_grv2: the mapping of sou_m does not"
68  << endl << " belong to the class Map_radial !" << endl ;
69  abort() ;
70  }
71 
72  assert( &sou_q.get_mp() == mprad ) ;
73 
74  sou_q.check_dzpuis(4) ;
75 
76  const Mg3d* mg = mprad->get_mg() ;
77  int nz = mg->get_nzone() ;
78 
79  // Construction of a Map_af which coincides with *mp on the equator
80  // ----------------------------------------------------------------
81 
82  double theta0 = M_PI / 2 ; // Equator
83  double phi0 = 0 ;
84 
85  Map_af mpaff(*mprad) ;
86 
87  for (int l=0 ; l<nz ; l++) {
88  double rmax = mprad->val_r(l, double(1), theta0, phi0) ;
89  switch ( mg->get_type_r(l) ) {
90  case RARE: {
91  double rmin = mprad->val_r(l, double(0), theta0, phi0) ;
92  mpaff.set_alpha(rmax - rmin, l) ;
93  mpaff.set_beta(rmin, l) ;
94  break ;
95  }
96 
97  case FIN: {
98  double rmin = mprad->val_r(l, double(-1), theta0, phi0) ;
99  mpaff.set_alpha( double(.5) * (rmax - rmin), l ) ;
100  mpaff.set_beta( double(.5) * (rmax + rmin), l) ;
101  break ;
102  }
103 
104 
105  case UNSURR: {
106  double rmin = mprad->val_r(l, double(-1), theta0, phi0) ;
107  double umax = double(1) / rmin ;
108  double umin = double(1) / rmax ;
109  mpaff.set_alpha( double(.5) * (umin - umax), l) ;
110  mpaff.set_beta( double(.5) * (umin + umax), l) ;
111  break ;
112  }
113 
114  default: {
115  cout << "Star_rot::lambda_grv2: unknown type_r ! " << endl ;
116  abort () ;
117  break ;
118  }
119 
120  }
121  }
122 
123 
124  // Reduced Jacobian of
125  // the transformation (r,theta,phi) <-> (dzeta,theta',phi')
126  // ------------------------------------------------------------
127 
128  Mtbl jac = 1 / ( (mprad->xsr) * (mprad->dxdr) ) ;
129  // R/x dR/dx in the nucleus
130  // R dR/dx in the shells
131  // - U/(x-1) dU/dx in the ZEC
132  for (int l=0; l<nz; l++) {
133  switch ( mg->get_type_r(l) ) {
134  case RARE: {
135  double a1 = mpaff.get_alpha()[l] ;
136  *(jac.t[l]) = *(jac.t[l]) / (a1*a1) ;
137  break ;
138  }
139 
140  case FIN: {
141  double a1 = mpaff.get_alpha()[l] ;
142  double b1 = mpaff.get_beta()[l] ;
143  assert( jac.t[l]->get_etat() == ETATQCQ ) ;
144  double* tjac = jac.t[l]->t ;
145  double* const xi = mg->get_grille3d(l)->x ;
146  for (int k=0; k<mg->get_np(l); k++) {
147  for (int j=0; j<mg->get_nt(l); j++) {
148  for (int i=0; i<mg->get_nr(l); i++) {
149  *tjac = *tjac /
150  (a1 * (a1 * xi[i] + b1) ) ;
151  tjac++ ;
152  }
153  }
154  }
155 
156  break ;
157  }
158 
159 
160  case UNSURR: {
161  double a1 = mpaff.get_alpha()[l] ;
162  *(jac.t[l]) = - *(jac.t[l]) / (a1*a1) ;
163  break ;
164  }
165 
166  default: {
167  cout << "Star_rot::lambda_grv2: unknown type_r ! " << endl ;
168  abort () ;
169  break ;
170  }
171 
172  }
173 
174  }
175 
176 
177  // Multiplication of the sources by the reduced Jacobian:
178  // -----------------------------------------------------
179 
180  Mtbl s_m(mg) ;
181  if ( sou_m.get_etat() == ETATZERO ) {
182  s_m = 0 ;
183  }
184  else{
185  assert(sou_m.get_spectral_va().get_etat() == ETATQCQ) ;
186  sou_m.get_spectral_va().coef_i() ;
187  s_m = *(sou_m.get_spectral_va().c) ;
188  }
189 
190  Mtbl s_q(mg) ;
191  if ( sou_q.get_etat() == ETATZERO ) {
192  s_q = 0 ;
193  }
194  else{
195  assert(sou_q.get_spectral_va().get_etat() == ETATQCQ) ;
196  sou_q.get_spectral_va().coef_i() ;
197  s_q = *(sou_q.get_spectral_va().c) ;
198  }
199 
200  s_m *= jac ;
201  s_q *= jac ;
202 
203 
204  // Preparations for the call to the Fortran subroutine
205  // ---------------------------------------------------
206 
207  int np1 = 1 ; // Axisymmetry enforced
208  int nt = mg->get_nt(0) ;
209  int nt2 = 2*nt - 1 ; // Number of points for the theta sampling
210  // in [0,Pi], instead of [0,Pi/2]
211 
212  // Array NDL
213  // ---------
214  int* ndl = new int[nz+4] ;
215  ndl[0] = nz ;
216  for (int l=0; l<nz; l++) {
217  ndl[1+l] = mg->get_nr(l) ;
218  }
219  ndl[1+nz] = nt2 ;
220  ndl[2+nz] = np1 ;
221  ndl[3+nz] = nz ;
222 
223  // Parameters NDR, NDT, NDP
224  // ------------------------
225  int nrmax = 0 ;
226  for (int l=0; l<nz ; l++) {
227  nrmax = ( ndl[1+l] > nrmax ) ? ndl[1+l] : nrmax ;
228  }
229  int ndr = nrmax + 5 ;
230  int ndt = nt2 + 2 ;
231  int ndp = np1 + 2 ;
232 
233  // Array ERRE
234  // ----------
235 
236  double* erre = new double [nz*ndr] ;
237 
238  for (int l=0; l<nz; l++) {
239  double a1 = mpaff.get_alpha()[l] ;
240  double b1 = mpaff.get_beta()[l] ;
241  for (int i=0; i<ndl[1+l]; i++) {
242  double xi = mg->get_grille3d(l)->x[i] ;
243  erre[ ndr*l + i ] = a1 * xi + b1 ;
244  }
245  }
246 
247  // Arrays containing the data
248  // --------------------------
249 
250  int ndrt = ndr*ndt ;
251  int ndrtp = ndr*ndt*ndp ;
252  int taille = ndrtp*nz ;
253 
254  double* tsou_m = new double[ taille ] ;
255  double* tsou_q = new double[ taille ] ;
256 
257  // Initialisation to zero :
258  for (int i=0; i<taille; i++) {
259  tsou_m[i] = 0 ;
260  tsou_q[i] = 0 ;
261  }
262 
263  // Copy of s_m into tsou_m
264  // -----------------------
265 
266  for (int l=0; l<nz; l++) {
267  for (int k=0; k<np1; k++) {
268  for (int j=0; j<nt; j++) {
269  for (int i=0; i<mg->get_nr(l); i++) {
270  double xx = s_m(l, k, j, i) ;
271  tsou_m[ndrtp*l + ndrt*k + ndr*j + i] = xx ;
272  // point symetrique par rapport au plan theta = pi/2 :
273  tsou_m[ndrtp*l + ndrt*k + ndr*(nt2-1-j) + i] = xx ;
274  }
275  }
276  }
277  }
278 
279  // Copy of s_q into tsou_q
280  // -----------------------
281 
282  for (int l=0; l<nz; l++) {
283  for (int k=0; k<np1; k++) {
284  for (int j=0; j<nt; j++) {
285  for (int i=0; i<mg->get_nr(l); i++) {
286  double xx = s_q(l, k, j, i) ;
287  tsou_q[ndrtp*l + ndrt*k + ndr*j + i] = xx ;
288  // point symetrique par rapport au plan theta = pi/2 :
289  tsou_q[ndrtp*l + ndrt*k + ndr*(nt2-1-j) + i] = xx ;
290  }
291  }
292  }
293  }
294 
295 
296  // Computation of the integrals
297  // ----------------------------
298 
299  double int_m, int_q ;
300  F77_integrale2d(ndl, &ndr, &ndt, &ndp, erre, tsou_m, &int_m) ;
301  F77_integrale2d(ndl, &ndr, &ndt, &ndp, erre, tsou_q, &int_q) ;
302 
303  // Cleaning
304  // --------
305 
306  delete [] ndl ;
307  delete [] erre ;
308  delete [] tsou_m ;
309  delete [] tsou_q ;
310 
311  // Computation of lambda
312  // ---------------------
313 
314  double lambda ;
315  if ( int_q != double(0) ) {
316  lambda = - int_m / int_q ;
317  }
318  else{
319  lambda = 0 ;
320  }
321 
322  return lambda ;
323 
324 }
325 }
Lorene::Star_rot::lambda_grv2
static double lambda_grv2(const Scalar &sou_m, const Scalar &sou_q)
Computes the coefficient which ensures that the GRV2 virial identity is satisfied.
Definition: star_rot_lambda_grv2.C:62
Lorene::Mg3d::get_np
int get_np(int l) const
Returns the number of points in the azimuthal direction ( ) in domain no. l.
Definition: grilles.h:462
Lorene::Valeur::get_etat
int get_etat() const
Returns the logical state.
Definition: valeur.h:726
Lorene::Mg3d
Multi-domain grid.
Definition: grilles.h:273
Lorene::Mg3d::get_nt
int get_nt(int l) const
Returns the number of points in the co-latitude direction ( ) in domain no. l.
Definition: grilles.h:457
Lorene
Lorene prototypes.
Definition: app_hor.h:64
Lorene::Map_radial::xsr
Coord xsr
in the nucleus; \ 1/R in the non-compactified shells; \ in the compactified outer domain.
Definition: map.h:1549
Lorene::Mtbl
Multi-domain array.
Definition: mtbl.h:118
Lorene::Map::get_mg
const Mg3d * get_mg() const
Gives the Mg3d on which the mapping is defined.
Definition: map.h:765
Lorene::Map_radial
Base class for pure radial mappings.
Definition: map.h:1536
Lorene::Map::val_r
virtual double val_r(int l, double xi, double theta, double pphi) const =0
Returns the value of the radial coordinate r for a given in a given domain.
Lorene::Mg3d::get_type_r
int get_type_r(int l) const
Returns the type of sampling in the radial direction in domain no.
Definition: grilles.h:474
Lorene::Scalar::check_dzpuis
bool check_dzpuis(int dzi) const
Returns false if the last domain is compactified and *this is not zero in this domain and dzpuis is n...
Definition: scalar.C:873
Lorene::Scalar
Tensor field of valence 0 (or component of a tensorial field).
Definition: scalar.h:387
Lorene::Tensor::get_mp
const Map & get_mp() const
Returns the mapping.
Definition: tensor.h:861
Lorene::Valeur::c
Mtbl * c
Values of the function at the points of the multi-grid
Definition: valeur.h:299
Lorene::Tbl::t
double * t
The array of double.
Definition: tbl.h:173
Lorene::Scalar::get_spectral_va
const Valeur & get_spectral_va() const
Returns va (read only version)
Definition: scalar.h:601
Lorene::Map_radial::dxdr
Coord dxdr
in the nucleus and in the non-compactified shells; \ in the compactified outer domain.
Definition: map.h:1560
Lorene::Mg3d::get_nzone
int get_nzone() const
Returns the number of domains.
Definition: grilles.h:448
Lorene::Map_af::set_beta
void set_beta(double beta0, int l)
Modifies the value of in domain no. l.
Definition: map_af.C:641
Lorene::Mg3d::get_nr
int get_nr(int l) const
Returns the number of points in the radial direction ( ) in domain no. l.
Definition: grilles.h:452
Lorene::Map_af
Affine radial mapping.
Definition: map.h:2027
Lorene::Mg3d::get_grille3d
const Grille3d * get_grille3d(int l) const
Returns a pointer on the 3D mono-grid for domain no. l.
Definition: grilles.h:500
Lorene::Scalar::get_etat
int get_etat() const
Returns the logical state ETATNONDEF (undefined), ETATZERO (null) or ETATQCQ (ordinary).
Definition: scalar.h:554
Lorene::Map_af::set_alpha
void set_alpha(double alpha0, int l)
Modifies the value of in domain no. l.
Definition: map_af.C:630
Lorene::Map_af::get_beta
const double * get_beta() const
Returns the pointer on the array beta.
Definition: map_af.C:481
Lorene::Mtbl::t
Tbl ** t
Array (size nzone ) of pointers on the Tbl 's.
Definition: mtbl.h:132
Lorene::Grille3d::x
double * x
Array of values of at the nr collocation points.
Definition: grilles.h:209
Lorene::Valeur::coef_i
void coef_i() const
Computes the physical value of *this.
Definition: valeur_coef_i.C:140
Lorene::Map_af::get_alpha
const double * get_alpha() const
Returns the pointer on the array alpha.
Definition: map_af.C:477
Lorene::Tbl::get_etat
int get_etat() const
Gives the logical state.
Definition: tbl.h:394