LORENE
map_star_deriv.C
1 /*
2  * Computations of Scalar partial derivatives for a Map_star mapping
3  */
4 
5 /*
6  *
7  * This file is part of LORENE.
8  *
9  * LORENE is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * LORENE is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with LORENE; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22  *
23  */
24 
25 // Header Lorene
26 #include "map.h"
27 #include "valeur.h"
28 #include "tensor.h"
29 
30 
31 
32 
33 namespace Lorene{
34  //---------------------//
35  // d/dr //
36  //---------------------//
37 
38 
39 void Map_star::dsdr(const Scalar& uu, Scalar& resu) const {
40 
41  assert (uu.get_etat() != ETATNONDEF) ;
42  assert (uu.get_mp().get_mg() == mg) ;
43 
44 
45  if (uu.get_etat() == ETATZERO) {
46  resu.set_etat_zero() ;
47  }
48  else {
49  assert( uu.get_etat() == ETATQCQ ) ;
50 
51  const Valeur& uuva = uu.get_spectral_va() ;
52 
53  uuva.coef() ; // (uu.va).c_cf is up to date
54 
55  int nz = mg->get_nzone() ;
56  int nzm1 = nz - 1 ;
57 
58  if ( uu.get_dzpuis() == 0 ) {
59  resu = uuva.dsdx() * dxdr ; // dxdr = dxi/dR, - dxi/dU (ZEC)
60 
61  if (mg->get_type_r(nzm1) == UNSURR) {
62  resu.set_dzpuis(2) ; // r^2 d/dr has been computed in the
63  // external domain
64  }
65  }
66  else {
67  int dzp = uu.get_dzpuis() ;
68 
69  resu = uuva.dsdx() * dxdr ;
70  if (mg->get_type_r(nzm1) == UNSURR) {
71  resu.annule_domain(nzm1) ; // zero in the CED
72 
73  // Special treatment in the CED
74  Valeur tmp_ced = - uuva.dsdx() ;
75  tmp_ced.annule(0, nz-2) ; // only non zero in the CED
76  tmp_ced.mult_xm1_zec() ;
77  tmp_ced.set(nzm1) -= dzp * uuva(nzm1) ;
78 
79  // Recombination shells + CED :
80  resu.set_spectral_va() += tmp_ced ;
81  }
82  resu.set_dzpuis(dzp+1) ;
83 
84  }
85 
86  resu.set_spectral_base( uuva.dsdx().get_base() ) ; // same basis as d/dxi
87 
88  }
89 
90 }
91 
92  //-----------------------------------//
93  // 1/sin(theta) d/dphi //
94  //-----------------------------------//
95 void Map_star::stdsdp(const Scalar& ci, Scalar& resu) const {
96 
97  assert (ci.get_etat() != ETATNONDEF) ;
98  assert (ci.get_mp().get_mg() == mg) ;
99 
100  if (ci.get_etat() == ETATZERO) {
101  resu.set_etat_zero() ;
102  }
103  else {
104 
105  assert( ci.get_etat() == ETATQCQ ) ;
106 
107  // Computation of 1/sin(theta) df/dphi' ---> stdfdp
108  // ----------------------------
109 
110  const Valeur& stdfdp = ci.get_spectral_va().stdsdp() ;
111 
112 
113  // Computation of 1/(dR/dxi) 1/sin(theta) dR/dphi' df/dx ----> adfdx
114  // -------------------------------------------
115 
116  Valeur adfdx = ci.get_spectral_va().dsdx() ; // df/dx
117 
118  Base_val sauve_base = adfdx.get_base() ;
119 
120  adfdx = adfdx * dxdr * stdrdp ; // df/dx / (dR/dx) * 1/sin(th) dR/dphi'
121 
122  adfdx.set_base( sauve_base ) ;
123 
124  // Final result
125  // ------------
126 
127  resu = stdfdp - adfdx ;
128 
129  }
130 
131  resu.set_dzpuis( ci.get_dzpuis() ) ; // dzpuis unchanged
132 
133 }
134 
135 
136  //------------------------------------//
137  // 1/(r sin(theta)) d/dphi //
138  //------------------------------------//
139 
140 void Map_star::srstdsdp(const Scalar& uu, Scalar& resu) const {
141 
142  assert (uu.get_etat() != ETATNONDEF) ;
143  assert (uu.get_mp().get_mg() == mg) ;
144 
145  if (uu.get_etat() == ETATZERO) {
146  resu.set_etat_zero() ;
147  }
148  else {
149 
150  assert( uu.get_etat() == ETATQCQ ) ;
151 
152  const Valeur& uuva = uu.get_spectral_va() ;
153  uuva.coef() ; // (uu.va).c_cf is up to date
154 
155  int nz = mg->get_nzone() ;
156  int nzm1 = nz - 1 ;
157 
158  // Computation of 1/(R sin(theta')) df/dphi' ---> srstdfdp
159  // -----------------------------------------
160 
161  Valeur srstdfdp = uuva ;
162 
163  srstdfdp = srstdfdp.dsdp() ; // d/dphi
164  srstdfdp = srstdfdp.ssint() ; // 1/sin(theta)
165  srstdfdp = srstdfdp.sx() ; // 1/xi, Id, 1/(xi-1)
166 
167  Base_val sauve_base( srstdfdp.base ) ;
168 
169  srstdfdp = srstdfdp * xsr ; // xi/R, 1/R, (xi-1)/U
170 
171  srstdfdp.base = sauve_base ; // The above operation does not change the basis
172 
173  // Computation of 1/(dR/dx) 1/(R sin(theta') dR/dphi' df/dx --> bdfdx
174  // --------------------------------------------------------
175  Valeur bdfdx = uuva ;
176 
177  bdfdx = bdfdx.dsdx() ; // df/dx
178 
179  sauve_base = bdfdx.base ;
180  bdfdx = bdfdx * dxdr * srstdrdp ;
181  bdfdx.base = sauve_base ;
182 
183 
184  if (uu.get_dzpuis() == 0) {
185 
186  //Final result
187 
188  resu = srstdfdp - bdfdx ;
189 
190 
191  if (mg->get_type_r(nz-1) == UNSURR) {
192  resu.set_dzpuis(2) ; // r d/dtheta has been computed in
193  // the external domain
194  }
195  }
196 
197  else {
198  assert(mg->get_type_r(nzm1) == UNSURR) ;
199 
200  int dzp = uu.get_dzpuis() ;
201 
202  Valeur tmp = srstdfdp - bdfdx ;
203  tmp.annule(nzm1) ;
204 
205  // Special treatment in the CED
206 
207  Valeur tmp_ced = - bdfdx ;
208  tmp_ced.annule(0, nz-2) ; // only non zero in the CED
209 
210  tmp_ced = tmp_ced.mult_x() ; // xi, Id, (xi-1)
211  //s Base_val sauve_base( tmp_ced.get_base() ) ;
212  tmp_ced = tmp_ced / xsr ; // xi/R, 1/R, (xi-1)/U
213 
214  tmp_ced = tmp_ced + uuva.dsdp().ssint() ;
215  tmp_ced.annule(0, nz-2) ; // only non zero in the CED
216 
217  // Recombination shells + CED :
218  resu = tmp + tmp_ced ;
219 
220  resu.set_dzpuis(dzp+1) ;
221  }
222  }
223 }
224 
225 
226  //------------------------//
227  // d/dtheta //
228  //------------------------//
229 
230 
231 void Map_star::dsdt(const Scalar& ci, Scalar& resu) const {
232 
233  assert (ci.get_etat() != ETATNONDEF) ;
234  assert (ci.get_mp().get_mg() == mg) ;
235 
236  if (ci.get_etat() == ETATZERO) {
237  resu.set_etat_zero() ;
238  }
239  else {
240 
241  assert( ci.get_etat() == ETATQCQ ) ;
242 
243  // Computation of df/dtheta' ---> dfdt
244  // ----------------------------
245 
246  const Valeur& dfdt = ci.get_spectral_va().dsdt() ;
247 
248 
249  // Computation of 1/(dR/dxi) dR/dtheta' df/dx ----> adfdx
250  // -------------------------------------------
251 
252  Valeur adfdx = ci.get_spectral_va().dsdx() ; // df/dx
253 
254  Base_val sauve_base = adfdx.get_base() ;
255 
256  adfdx = adfdx * dxdr * drdt ; // df/dx / (dR/dx) * dR/dtheta'
257 
258  adfdx.set_base( sauve_base ) ;
259 
260  // Final result
261  // ------------
262 
263  resu = dfdt - adfdx ;
264 
265  }
266 
267  resu.set_dzpuis( ci.get_dzpuis() ) ; // dzpuis unchanged
268 
269 }
270 
271 void Map_star::srdsdt(const Scalar& uu, Scalar& resu) const {
272  assert (uu.get_etat() != ETATNONDEF) ;
273  assert (uu.get_mp().get_mg() == mg) ;
274 
275  if (uu.get_etat() == ETATZERO) {
276  resu.set_etat_zero() ;
277  }
278  else {
279 
280  assert( uu.get_etat() == ETATQCQ ) ;
281 
282  const Valeur& uuva = uu.get_spectral_va() ;
283  uuva.coef() ; // (uu.va).c_cf is up to date
284 
285  int nz = mg->get_nzone() ;
286  int nzm1 = nz - 1 ;
287 
288  // Computation of 1/R df/dtheta' ---> srdfdt
289  // ----------------------------
290  Valeur srdfdt = uuva ;
291 
292  srdfdt = srdfdt.dsdt() ; // d/dtheta'
293 
294  srdfdt = srdfdt.sx() ; // 1/xi, Id, 1/(xi-1)
295 
296  Base_val sauve_base( srdfdt.base ) ;
297 
298  srdfdt = srdfdt * xsr ; // xi/R, 1/R, (xi-1)/U
299 
300  srdfdt.base = sauve_base ; // The above operation does not change the basis
301  // Computation of 1/(dR/dx) 1/R dR/dtheta' df/dx ----> adfdx
302  // ----------------------------------------------
303 
304  Valeur adfdx = uuva ;
305 
306  adfdx = adfdx.dsdx() ; // df/dx
307 
308  sauve_base = adfdx.base ;
309  adfdx = adfdx * dxdr * srdrdt ; // 1/(dR/dx) 1/R dR/dtheta' df/dx
310  adfdx.base = sauve_base ;
311 
312  if (uu.get_dzpuis() == 0) {
313 
314  // Final result
315  // ------------
316 
317  resu = srdfdt - adfdx ;
318 
319  //s int nz = mg->get_nzone() ;
320  if (mg->get_type_r(nz-1) == UNSURR) {
321  resu.set_dzpuis(2) ; // r^2 (1/r d/dtheta) has been computed in
322  // the external domain
323  }
324 
325  }
326 
327  else {
328  assert(mg->get_type_r(nzm1) == UNSURR) ;
329 
330  int dzp = uu.get_dzpuis() ;
331 
332  Valeur tmp = srdfdt - adfdx ;
333  tmp.annule(nzm1) ;
334 
335  // Special treatment in the CED
336  //-----------------------------
337 
338  Valeur tmp_ced = - adfdx ;
339 
340  tmp_ced.annule(0, nz-2) ; // only non zero in the CED
341 
342  tmp_ced = tmp_ced.mult_x() ; // xi, Id, (xi-1)
343  //s Base_val sauve_base( tmp_ced.get_base() ) ;
344  tmp_ced = tmp_ced / xsr ; // xi/R, 1/R, (xi-1)/U
345 
346  tmp_ced = tmp_ced + uuva.dsdt() ;
347  tmp_ced.annule(0, nz-2) ; // only non zero in the CED
348 
349  // Recombination shells + CED :
350  resu = tmp + tmp_ced ;
351 
352  resu.set_dzpuis(dzp+1) ;
353  }
354 
355  }
356 
357 }
358 
359 }
void annule_domain(int l)
Sets the Tensor to zero in a given domain.
Definition: tensor.C:675
const Valeur & dsdt() const
Returns of *this.
Definition: valeur_dsdt.C:115
const Valeur & dsdx() const
Returns of *this.
Definition: valeur_dsdx.C:114
void coef() const
Computes the coeffcients of *this.
Definition: valeur_coef.C:151
virtual void set_etat_zero()
Sets the logical state to ETATZERO (zero).
Definition: scalar.C:330
Lorene prototypes.
Definition: app_hor.h:67
const Mg3d * get_mg() const
Gives the Mg3d on which the mapping is defined.
Definition: map.h:777
Tensor field of valence 0 (or component of a tensorial field).
Definition: scalar.h:393
const Valeur & dsdp() const
Returns of *this.
Definition: valeur_dsdp.C:101
void mult_xm1_zec()
Applies the following operator to *this : \ Id (r sampling = RARE, FIN ) \ (r -sampling = UNSURR ) ...
const Valeur & sx() const
Returns (r -sampling = RARE ) \ Id (r sampling = FIN ) \ (r -sampling = UNSURR ) ...
Definition: valeur_sx.C:113
const Scalar & dsdx() const
Returns of *this , where .
Definition: scalar_deriv.C:266
Values and coefficients of a (real-value) function.
Definition: valeur.h:297
int get_etat() const
Returns the logical state ETATNONDEF (undefined), ETATZERO (null) or ETATQCQ (ordinary).
Definition: scalar.h:560
void annule(int l)
Sets the Valeur to zero in a given domain.
Definition: valeur.C:747
void set_base(const Base_val &)
Sets the bases for spectral expansions (member base )
Definition: valeur.C:813
Coord srstdrdp
in the nucleus and in the non-compactified shells; \ in the compactified outer domain.
Definition: map.h:1607
void set_dzpuis(int)
Modifies the dzpuis flag.
Definition: scalar.C:814
const Valeur & mult_x() const
Returns (r -sampling = RARE ) \ Id (r sampling = FIN ) \ (r -sampling = UNSURR ) ...
Coord stdrdp
in the nucleus and in the non-compactified shells; \ in the compactified external domain (CED)...
Definition: map.h:1591
const Valeur & ssint() const
Returns of *this.
Definition: valeur_ssint.C:115
Coord dxdr
in the nucleus and in the non-compactified shells; \ in the compactified outer domain.
Definition: map.h:1575
virtual void stdsdp(const Scalar &, Scalar &) const
Computes of a Scalar .
Base_val base
Bases on which the spectral expansion is performed.
Definition: valeur.h:315
int get_dzpuis() const
Returns dzpuis.
Definition: scalar.h:563
const Valeur & stdsdp() const
Returns of *this.
Definition: valeur_stdsdp.C:63
int get_nzone() const
Returns the number of domains.
Definition: grilles.h:465
Coord xsr
in the nucleus; \ 1/R in the non-compactified shells; \ in the compactified outer domain...
Definition: map.h:1564
Coord drdt
in the nucleus and in the non-compactified shells; \ in the compactified external domain (CED)...
Definition: map.h:1583
void set_spectral_base(const Base_val &)
Sets the spectral bases of the Valeur va
Definition: scalar.C:803
const Mg3d * mg
Pointer on the multi-grid Mgd3 on which this is defined.
Definition: map.h:688
Bases of the spectral expansions.
Definition: base_val.h:325
virtual void srdsdt(const Scalar &, Scalar &) const
Computes of a Scalar.
virtual void srstdsdp(const Scalar &, Scalar &) const
Computes of a Scalar.
Valeur & set_spectral_va()
Returns va (read/write version)
Definition: scalar.h:610
int get_type_r(int l) const
Returns the type of sampling in the radial direction in domain no.
Definition: grilles.h:491
Coord srdrdt
in the nucleus and in the non-compactified shells; \ in the compactified outer domain.
Definition: map.h:1599
const Map & get_mp() const
Returns the mapping.
Definition: tensor.h:874
virtual void dsdr(const Scalar &ci, Scalar &resu) const
Computes of a Scalar.
const Valeur & get_spectral_va() const
Returns va (read only version)
Definition: scalar.h:607
virtual void dsdt(const Scalar &, Scalar &) const
Computes of a Scalar .
const Base_val & get_base() const
Return the bases for spectral expansions (member base )
Definition: valeur.h:490
Tbl & set(int l)
Read/write of the value in a given domain (configuration space).
Definition: valeur.h:373