LORENE
cmp_deriv.C
1 /*
2  * Computations of partial derivatives d/dx, d/dy and d/dz of a Cmp.
3  */
4 
5 /*
6  * Copyright (c) 1999-2001 Eric Gourgoulhon
7  * Copyright (c) 1999-2001 Philippe Grandclement
8  *
9  * This file is part of LORENE.
10  *
11  * LORENE is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * LORENE is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with LORENE; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24  *
25  */
26 
27 
28 
29 
30 
31 
32 /*
33  * $Id: cmp_deriv.C,v 1.4 2016/12/05 16:17:48 j_novak Exp $
34  * $Log: cmp_deriv.C,v $
35  * Revision 1.4 2016/12/05 16:17:48 j_novak
36  * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
37  *
38  * Revision 1.3 2014/10/13 08:52:47 j_novak
39  * Lorene classes and functions now belong to the namespace Lorene.
40  *
41  * Revision 1.2 2014/10/06 15:13:03 j_novak
42  * Modified #include directives to use c++ syntax.
43  *
44  * Revision 1.1.1.1 2001/11/20 15:19:27 e_gourgoulhon
45  * LORENE
46  *
47  * Revision 1.7 2000/09/11 15:55:12 eric
48  * Calcul de dsdx, dsdy et dsdz: suppression des methodes Map::deriv_x, etc...
49  * et introduction des methodes Map::comp_x_from_spherical, etc...
50  *
51  * Revision 1.6 2000/02/08 14:20:14 phil
52  * vire set_etat_qcq
53  *
54  * Revision 1.5 2000/01/27 17:27:49 phil
55  * coorection etat du resultat
56  *
57  * Revision 1.4 2000/01/26 13:11:36 eric
58  * Modifs pour tenir compte du reprototypage complet des routines de derivation
59  * des mappings (Map::dsdr, etc...). Le resultat p_* est desormais alloue
60  * a l'exterieur de la routine Map::*.
61  *
62  * Revision 1.3 1999/11/29 14:38:16 eric
63  * *** empty log message ***
64  *
65  * Revision 1.2 1999/11/29 12:57:07 eric
66  * Introduction du laplacien.
67  *
68  * Revision 1.1 1999/11/25 16:28:17 eric
69  * Initial revision
70  *
71  *
72  * $Header: /cvsroot/Lorene/C++/Source/Cmp/cmp_deriv.C,v 1.4 2016/12/05 16:17:48 j_novak Exp $
73  *
74  */
75 
76 // Headers C
77 #include <cstdlib>
78 
79 // Headers Lorene
80 #include "cmp.h"
81 
82  //---------------------//
83  // d/dr //
84  //---------------------//
85 
86 namespace Lorene {
87 const Cmp& Cmp::dsdr() const {
88 
89  // Protection
90  assert(etat != ETATNONDEF) ;
91 
92  // If the derivative has not been previously computed, the
93  // computation must be done by the appropriate routine of the mapping :
94 
95  if (p_dsdr == 0x0) {
96  p_dsdr = new Cmp(mp) ;
97  mp->dsdr(*this, *p_dsdr) ;
98  }
99 
100  return *p_dsdr ;
101 
102 }
103 
104  //------------------------//
105  // 1/r d/dtheta //
106  //------------------------//
107 
108 const Cmp& Cmp::srdsdt() const {
109 
110  // Protection
111  assert(etat != ETATNONDEF) ;
112 
113  // If the derivative has not been previously computed, the
114  // computation must be done by the appropriate routine of the mapping :
115 
116  if (p_srdsdt == 0x0) {
117  p_srdsdt = new Cmp(mp) ;
118  mp->srdsdt(*this, *p_srdsdt) ;
119  }
120 
121  return *p_srdsdt ;
122 
123 }
124 
125 
126  //----------------------------------//
127  // 1/(r sin(theta) d/dphi //
128  //----------------------------------//
129 
130 const Cmp& Cmp::srstdsdp() const {
131 
132  // Protection
133  assert(etat != ETATNONDEF) ;
134 
135  // If the derivative has not been previously computed, the
136  // computation must be done by the appropriate routine of the mapping :
137 
138  if (p_srstdsdp == 0x0) {
139  p_srstdsdp = new Cmp(mp) ;
140  mp->srstdsdp(*this, *p_srstdsdp) ;
141  }
142 
143  return *p_srstdsdp ;
144 
145 }
146 
147  //---------------------//
148  // d/dx //
149  //---------------------//
150 
151 const Cmp& Cmp::dsdx() const {
152 
153  // Protection
154  assert(etat != ETATNONDEF) ;
155 
156  // If the derivative has not been previously computed, the
157  // computation must be done by the appropriate routine of the mapping :
158 
159  if (p_dsdx == 0x0) {
160  p_dsdx = new Cmp(mp) ;
162  }
163 
164  return *p_dsdx ;
165 
166 }
167 
168  //---------------------//
169  // d/dy //
170  //---------------------//
171 
172 const Cmp& Cmp::dsdy() const {
173 
174  // Protection
175  assert(etat != ETATNONDEF) ;
176 
177  // If the derivative has not been previously computed, the
178  // computation must be done by the appropriate routine of the mapping :
179 
180  if (p_dsdy == 0x0) {
181  p_dsdy = new Cmp(mp) ;
183  }
184 
185  return *p_dsdy ;
186 
187 }
188 
189  //---------------------//
190  // d/dz //
191  //---------------------//
192 
193 const Cmp& Cmp::dsdz() const {
194 
195  // Protection
196  assert(etat != ETATNONDEF) ;
197 
198  // If the derivative has not been previously computed, the
199  // computation must be done by the appropriate routine of the mapping :
200 
201  if (p_dsdz == 0x0) {
202  p_dsdz = new Cmp(mp) ;
204  }
205 
206  return *p_dsdz ;
207 
208 }
209 
210  //---------------------//
211  // d/dx^i //
212  //---------------------//
213 
214 const Cmp& Cmp::deriv(int i) const {
215 
216  switch (i) {
217 
218  case 0 : {
219  return dsdx() ;
220  }
221 
222  case 1 : {
223  return dsdy() ;
224  }
225 
226  case 2 : {
227  return dsdz() ;
228  }
229 
230  default : {
231  cout << "Cmp::deriv : index i out of range !" << endl ;
232  cout << " i = " << i << endl ;
233  abort() ;
234  return dsdx() ; // Pour satisfaire le compilateur !
235  }
236 
237  }
238 
239 }
240 
241  //---------------------//
242  // Laplacian //
243  //---------------------//
244 
245 const Cmp& Cmp::laplacien(int zec_mult_r) const {
246 
247  // Protection
248  assert(etat != ETATNONDEF) ;
249 
250  // If the Laplacian has not been previously computed, the
251  // computation must be done by the appropriate routine of the mapping :
252  if ( (p_lap == 0x0) || (zec_mult_r != ind_lap) ) {
253  if (p_lap != 0x0) {
254  delete p_lap ; // the Laplacian had been computed but with
255  // a different value of zec_mult_r
256  }
257  p_lap = new Cmp(mp) ;
258  mp->laplacien(*this, zec_mult_r, *p_lap) ;
259  ind_lap = zec_mult_r ;
260  }
261 
262  return *p_lap ;
263 
264 }
265 
266 
267 
268 
269 }
const Cmp & dsdr() const
Returns of *this .
Definition: cmp_deriv.C:87
Cmp * p_dsdy
Pointer on of *this , where .
Definition: cmp.h:484
Component of a tensorial field *** DEPRECATED : use class Scalar instead ***.
Definition: cmp.h:446
const Cmp & dsdx() const
Returns of *this , where .
Definition: cmp_deriv.C:151
int ind_lap
Power of r by which the last computed Laplacian has been multiplied in the external compactified doma...
Definition: cmp.h:498
const Cmp & srstdsdp() const
Returns of *this .
Definition: cmp_deriv.C:130
Lorene prototypes.
Definition: app_hor.h:67
virtual void dsdr(const Cmp &ci, Cmp &resu) const =0
Computes of a Cmp .
int etat
Logical state (ETATNONDEF , ETATQCQ or ETATZERO ).
Definition: cmp.h:454
const Cmp & srdsdt() const
Returns of *this .
Definition: cmp_deriv.C:108
virtual void comp_x_from_spherical(const Scalar &v_r, const Scalar &v_theta, const Scalar &v_phi, Scalar &v_x) const =0
Computes the Cartesian x component (with respect to bvect_cart ) of a vector given by its spherical c...
virtual void srdsdt(const Cmp &ci, Cmp &resu) const =0
Computes of a Cmp .
Cmp * p_lap
Pointer on the Laplacian of *this.
Definition: cmp.h:493
virtual void comp_z_from_spherical(const Scalar &v_r, const Scalar &v_theta, Scalar &v_z) const =0
Computes the Cartesian z component (with respect to bvect_cart ) of a vector given by its spherical c...
Cmp * p_srstdsdp
Pointer on of *this.
Definition: cmp.h:474
virtual void srstdsdp(const Cmp &ci, Cmp &resu) const =0
Computes of a Cmp .
const Cmp & deriv(int i) const
Returns of *this , where .
Definition: cmp_deriv.C:214
const Cmp & dsdz() const
Returns of *this , where .
Definition: cmp_deriv.C:193
const Map * mp
Reference mapping.
Definition: cmp.h:451
Cmp * p_srdsdt
Pointer on of *this.
Definition: cmp.h:472
Cmp * p_dsdz
Pointer on of *this , where .
Definition: cmp.h:489
Cmp * p_dsdr
Pointer on of *this.
Definition: cmp.h:470
Cmp(const Map &map)
Constructor from mapping.
Definition: cmp.C:211
const Cmp & dsdy() const
Returns of *this , where .
Definition: cmp_deriv.C:172
const Cmp & laplacien(int zec_mult_r=4) const
Returns the Laplacian of *this.
Definition: cmp_deriv.C:245
Cmp * p_dsdx
Pointer on of *this , where .
Definition: cmp.h:479
virtual void comp_y_from_spherical(const Scalar &v_r, const Scalar &v_theta, const Scalar &v_phi, Scalar &v_y) const =0
Computes the Cartesian y component (with respect to bvect_cart ) of a vector given by its spherical c...
virtual void laplacien(const Scalar &uu, int zec_mult_r, Scalar &lap) const =0
Computes the Laplacian of a scalar field.