LORENE
sym_tensor.C
1/*
2 * Methods of class Sym_tensor
3 *
4 * (see file tensor.h for documentation)
5 *
6 */
7
8/*
9 * Copyright (c) 2003-2004 Eric Gourgoulhon & Jerome Novak
10 *
11 * Copyright (c) 1999-2001 Philippe Grandclement (Cmp version)
12 * Copyright (c) 2000-2001 Eric Gourgoulhon (Cmp version)
13 *
14 * This file is part of LORENE.
15 *
16 * LORENE is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
20 *
21 * LORENE is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with LORENE; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 *
30 */
31
32
33
34
35/*
36 * $Id: sym_tensor.C,v 1.25 2016/12/05 16:18:17 j_novak Exp $
37 * $Log: sym_tensor.C,v $
38 * Revision 1.25 2016/12/05 16:18:17 j_novak
39 * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
40 *
41 * Revision 1.24 2014/10/13 08:53:43 j_novak
42 * Lorene classes and functions now belong to the namespace Lorene.
43 *
44 * Revision 1.23 2014/10/06 15:13:19 j_novak
45 * Modified #include directives to use c++ syntax.
46 *
47 * Revision 1.22 2007/12/21 16:07:08 j_novak
48 * Methods to filter Tensor, Vector and Sym_tensor objects.
49 *
50 * Revision 1.21 2007/12/03 13:00:00 n_vasset
51 * Adjusting memory management for new member p_tilde_c
52 *
53 * Revision 1.20 2006/06/12 07:27:20 j_novak
54 * New members concerning A and tilde{B}, dealing with the transverse part of the
55 * Sym_tensor.
56 *
57 * Revision 1.19 2005/04/04 15:25:24 j_novak
58 * Added new members www, xxx, ttt and the associated methods.
59 *
60 * Revision 1.18 2005/04/01 14:28:32 j_novak
61 * Members p_eta and p_mu are now defined in class Sym_tensor.
62 *
63 * Revision 1.17 2004/03/30 14:01:19 j_novak
64 * Copy constructors and operator= now copy the "derived" members.
65 *
66 * Revision 1.16 2004/02/26 22:48:50 e_gourgoulhon
67 * -- Method divergence: call to Tensor::divergence and cast of the
68 * result.
69 * -- Added method derive_lie.
70 *
71 * Revision 1.15 2004/01/04 20:54:00 e_gourgoulhon
72 * Sym_tensor is now a derived class of Tensor_sym.
73 * Methods indices and position have been suppressed (they are now
74 * implemented at the Tensor_sym level).
75 *
76 * Revision 1.14 2003/12/30 23:09:47 e_gourgoulhon
77 * Change in methods derive_cov() and divergence() to take into account
78 * the change of name: Metric::get_connect() --> Metric::connect().
79 *
80 * Revision 1.13 2003/11/26 21:58:15 e_gourgoulhon
81 * Added new data member p_transverse and p_longit_pot.
82 * Modified the memory management consequently.
83 *
84 * Revision 1.12 2003/10/28 12:34:08 e_gourgoulhon
85 * Corrected bug in the copy constructor and constructor from Tensor:
86 * the cmp have already been created by the (special) Tensor constructor called
87 * by these constructors.
88 *
89 * Revision 1.11 2003/10/20 14:26:03 j_novak
90 * New assignement operators.
91 *
92 * Revision 1.10 2003/10/16 14:21:36 j_novak
93 * The calculation of the divergence of a Tensor is now possible.
94 *
95 * Revision 1.9 2003/10/13 13:52:39 j_novak
96 * Better managment of derived quantities.
97 *
98 * Revision 1.8 2003/10/11 16:47:10 e_gourgoulhon
99 * Suppressed the call to Ibtl::set_etat_qcq() after the construction
100 * of the Itbl's, thanks to the new property of the Itbl class.
101 *
102 * Revision 1.7 2003/10/07 09:56:59 j_novak
103 * method Sym_tensor::inverse() implemented (but not tested!)
104 *
105 * Revision 1.6 2003/10/06 13:58:48 j_novak
106 * The memory management has been improved.
107 * Implementation of the covariant derivative with respect to the exact Tensor
108 * type.
109 *
110 * Revision 1.5 2003/10/03 11:21:48 j_novak
111 * More methods for the class Metric
112 *
113 * Revision 1.4 2003/10/02 15:45:51 j_novak
114 * New class Metric
115 *
116 * Revision 1.3 2003/10/01 15:39:43 e_gourgoulhon
117 * Added assert to insure that both indices have the same type.
118 *
119 * Revision 1.2 2003/09/26 08:05:31 j_novak
120 * New class Vector.
121 *
122 * Revision 1.1 2003/09/25 13:37:40 j_novak
123 * Symmetric tensors of valence 2 are now implemented (not tested yet).
124 *
125 *
126 * $Header: /cvsroot/Lorene/C++/Source/Tensor/sym_tensor.C,v 1.25 2016/12/05 16:18:17 j_novak Exp $
127 *
128 */
129
130// Headers C
131#include <cstdlib>
132#include <cassert>
133#include <cmath>
134
135// Headers Lorene
136#include "metric.h"
137
138 //--------------//
139 // Constructors //
140 //--------------//
141
142// Standard constructor
143// --------------------
144namespace Lorene {
145Sym_tensor::Sym_tensor(const Map& map, const Itbl& tipe,
146 const Base_vect& triad_i)
147 : Tensor_sym(map, 2, tipe, triad_i, 0, 1) {
148
149 set_der_0x0() ;
150
151}
152
153// Standard constructor when all the indices are of the same type
154// --------------------------------------------------------------
155Sym_tensor::Sym_tensor(const Map& map, int tipe, const Base_vect& triad_i)
156 : Tensor_sym(map, 2, tipe, triad_i, 0, 1) {
157
158 set_der_0x0() ;
159}
160
161// Copy constructor
162// ----------------
164 : Tensor_sym( source ) {
165
166 set_der_0x0() ;
167
168 for (int i_met = 0; i_met < N_MET_MAX; i_met++) {
169
170 if ( source.p_transverse[i_met] != 0x0 ) {
171 set_dependance( *source.met_depend[i_met] ) ;
172 int jp = get_place_met( *source.met_depend[i_met] ) ;
173 assert ((jp>=0) && (jp<N_MET_MAX)) ;
174 p_transverse[jp] =
175 new Sym_tensor_trans ( *source.p_transverse[i_met] ) ;
176 }
177
178 if ( source.p_longit_pot[i_met] != 0x0 ) {
179 set_dependance( *source.met_depend[i_met] ) ;
180 int jp = get_place_met( *source.met_depend[i_met] ) ;
181 assert ((jp>=0) && (jp<N_MET_MAX)) ;
182 p_longit_pot[jp] =
183 new Vector ( *source.p_longit_pot[i_met] ) ;
184 }
185 }
186 if (source.p_eta != 0x0) p_eta = new Scalar( *(source.p_eta) ) ;
187 if (source.p_mu != 0x0) p_mu = new Scalar( *(source.p_mu) ) ;
188 if (source.p_www != 0x0) p_www = new Scalar( *(source.p_www) ) ;
189 if (source.p_xxx != 0x0) p_xxx = new Scalar( *(source.p_xxx) ) ;
190
191}
192
193
194// Constructor from a Tensor
195// --------------------------
197 : Tensor_sym(*source.mp, 2, source.type_indice, *(source.triad),
198 0, 1) {
199
200 assert(source.valence == 2) ;
201
202 for (int ic=0 ; ic<n_comp ; ic++) {
203 int posi = source.position(indices(ic)) ;
204 *(cmp[ic]) = *(source.cmp[posi]) ;
205 }
206
207 set_der_0x0() ;
208}
209
210
211// Constructor from a file
212// -----------------------
213Sym_tensor::Sym_tensor(const Map& map, const Base_vect& triad_i, FILE* fd)
214 : Tensor_sym(map, triad_i, fd) {
215
216 assert (valence == 2) ;
217 assert (n_comp == 6) ;
218 set_der_0x0() ;
219}
220
221 //--------------//
222 // Destructor //
223 //--------------//
224
230
231
232
233 //--------------//
234 // Assignment //
235 //--------------//
236
238
239 Tensor_sym::operator=(source) ;
240
241 del_deriv() ;
242
243 for (int i_met = 0; i_met < N_MET_MAX; i_met++) {
244
245 if ( source.p_transverse[i_met] != 0x0 ) {
246 set_dependance( *source.met_depend[i_met] ) ;
247 int jp = get_place_met( *source.met_depend[i_met] ) ;
248 assert ((jp>=0) && (jp<N_MET_MAX)) ;
249 p_transverse[jp] =
250 new Sym_tensor_trans ( *source.p_transverse[i_met] ) ;
251 }
252
253 if ( source.p_longit_pot[i_met] != 0x0 ) {
254 set_dependance( *source.met_depend[i_met] ) ;
255 int jp = get_place_met( *source.met_depend[i_met] ) ;
256 assert ((jp>=0) && (jp<N_MET_MAX)) ;
257 p_longit_pot[jp] =
258 new Vector ( *source.p_longit_pot[i_met] ) ;
259 }
260
261 }
262 if (source.p_eta != 0x0) p_eta = new Scalar( *(source.p_eta) ) ;
263 if (source.p_mu != 0x0) p_mu = new Scalar( *(source.p_mu) ) ;
264 if (source.p_www != 0x0) p_www = new Scalar( *(source.p_www) ) ;
265 if (source.p_xxx != 0x0) p_xxx = new Scalar( *(source.p_xxx) ) ;
266
267}
268
269
271
273
274 del_deriv() ;
275}
276
277
279
281
282 del_deriv() ;
283}
284
285 //-------------------//
286 // Memory managment //
287 //-------------------//
288
290
291 for (int i=0; i<N_MET_MAX; i++)
292 del_derive_met(i) ;
293
294 if (p_eta != 0x0) delete p_eta ;
295 if (p_mu != 0x0) delete p_mu ;
296 if (p_www != 0x0) delete p_www ;
297 if (p_xxx != 0x0) delete p_xxx ;
298 if (p_ttt != 0x0) delete p_ttt ;
299 if (p_aaa != 0x0) delete p_aaa ;
300 if (p_tilde_b != 0x0) delete p_tilde_b ;
301 if (p_tilde_c != 0x0) delete p_tilde_c ;
302
303 set_der_0x0() ;
305
306}
307
309
310 for (int i=0; i<N_MET_MAX; i++)
311 set_der_met_0x0(i) ;
312 p_eta = 0x0 ;
313 p_mu = 0x0 ;
314 p_www = 0x0 ;
315 p_xxx = 0x0 ;
316 p_ttt = 0x0 ;
317 p_aaa = 0x0 ;
318 p_tilde_b = 0x0 ;
319 p_tilde_c = 0x0 ;
320}
321
322
323void Sym_tensor::del_derive_met(int j) const {
324
325 assert( (j>=0) && (j<N_MET_MAX) ) ;
326
327 if (met_depend[j] != 0x0) {
328 if ( p_transverse[j] != 0x0) delete p_transverse[j] ;
329 if ( p_longit_pot[j] != 0x0) delete p_longit_pot[j] ;
330
331 set_der_met_0x0(j) ;
332
334 }
335}
336
337
339
340 assert( (i>=0) && (i<N_MET_MAX) ) ;
341
342 p_transverse[i] = 0x0 ;
343 p_longit_pot[i] = 0x0 ;
344
345}
346
347
348 //----------------------------------//
349 // Computation of derived members //
350 //----------------------------------//
351
352const Vector& Sym_tensor::divergence(const Metric& gam) const {
353
354 const Vector* pvect =
355 dynamic_cast<const Vector*>( &(Tensor::divergence(gam)) ) ;
356
357 assert(pvect != 0x0) ;
358
359 return *pvect ;
360}
361
362
364
365 Sym_tensor resu(*mp, type_indice, *triad) ;
366
367 compute_derive_lie(vv, resu) ;
368
369 return resu ;
370
371}
372
373
374
376
377 //Le resultat :
378 Sym_tensor* res =
379 new Sym_tensor(*mp, -type_indice(0), *triad) ;
380
381 // le determinant :
382 Scalar determ1(*mp) ;
383 determ1 = double(1)/
384 (operator()(1, 1)*operator()(2, 2)*operator()(3, 3)
385 + operator()(1, 2)*operator()(2, 3)*operator()(1, 3)
386 + operator()(1, 3)*operator()(1, 2)*operator()(2, 3)
387 - operator()(1, 3)*operator()(2, 2)*operator()(1, 3)
388 - operator()(2, 3)*operator()(2, 3)*operator()(1, 1)
389 - operator()(3, 3)*operator()(1, 2)*operator()(1, 2) ) ;
390
391 int sgn ; // Le signe du co-facteur ...
392 int l_up, l_down, c_left, c_right ; // Coordonnees du cofacteur :
393
394 Scalar cofacteur(*mp) ;
395
396 for (int i=1 ; i<=3 ; i++) {
397 sgn = 1 ;
398 for (int j=i ; j<=3 ; j++) {
399
400 switch (j) {
401
402 case 1 : {
403 c_left = 2 ;
404 c_right = 3 ;
405 break ;
406 }
407 case 2 : {
408 c_left = 1 ;
409 c_right = 3 ;
410 break ;
411 }
412 default : {
413 c_left = 1 ;
414 c_right = 2 ;
415 break ;
416 }
417 }
418
419 switch (i) {
420
421 case 1 : {
422 l_up = 2 ;
423 l_down = 3 ;
424 break ;
425 }
426 case 2 : {
427 l_up = 1 ;
428 l_down = 3 ;
429 break ;
430 }
431 default : {
432 l_up = 1 ;
433 l_down = 2 ;
434 break ;
435 }
436 }
437
438 cofacteur = sgn*(operator()(l_up, c_left)*operator()(l_down, c_right)-
439 operator()(l_up, c_right)*operator()(l_down, c_left))*determ1 ;
440
441 res->set(i, j) = cofacteur ;
442 sgn *= -1 ;
443 }
444 }
445 return res ;
446
447}
448
449void Sym_tensor::exponential_filter_r(int lzmin, int lzmax, int p,
450 double alpha) {
451 if( triad->identify() == (mp->get_bvect_cart()).identify() )
452 for (int i=0; i<n_comp; i++)
453 cmp[i]->exponential_filter_r(lzmin, lzmax, p, alpha) ;
454 else {
455 assert( triad->identify() == (mp->get_bvect_spher()).identify()) ;
456 Scalar srr_tmp = operator()(1,1) ;
457 srr_tmp.exponential_filter_r(lzmin, lzmax, p, alpha) ;
458 Scalar eta_tmp = eta() ;
459 eta_tmp.div_r() ; //## to change one day...
460 eta_tmp.exponential_filter_r(lzmin, lzmax, p, alpha) ;
461 Scalar mu_tmp = mu() ;
462 mu_tmp.div_r() ; //## to change one day...
463 mu_tmp.exponential_filter_r(lzmin, lzmax, p, alpha) ;
464 Scalar w_tmp = www() ;
465 w_tmp.exponential_filter_r(lzmin, lzmax, p, alpha) ;
466 Scalar x_tmp = xxx() ;
467 x_tmp.exponential_filter_r(lzmin, lzmax, p, alpha) ;
468 Scalar t_tmp = ttt() ;
469 t_tmp.exponential_filter_r(lzmin, lzmax, p, alpha) ;
470 set_auxiliary(srr_tmp, eta_tmp, mu_tmp, w_tmp, x_tmp, t_tmp) ;
471 }
472}
473
474void Sym_tensor::exponential_filter_ylm(int lzmin, int lzmax, int p,
475 double alpha) {
476 if( triad->identify() == (mp->get_bvect_cart()).identify() )
477 for (int i=0; i<n_comp; i++)
478 cmp[i]->exponential_filter_ylm(lzmin, lzmax, p, alpha) ;
479 else {
480 assert( triad->identify() == (mp->get_bvect_spher()).identify()) ;
481 Scalar srr_tmp = operator()(1,1) ;
482 srr_tmp.exponential_filter_ylm(lzmin, lzmax, p, alpha) ;
483 Scalar eta_tmp = eta() ;
484 eta_tmp.div_r() ; //## to change one day...
485 eta_tmp.exponential_filter_ylm(lzmin, lzmax, p, alpha) ;
486 Scalar mu_tmp = mu() ;
487 mu_tmp.div_r() ; //## to change one day...
488 mu_tmp.exponential_filter_ylm(lzmin, lzmax, p, alpha) ;
489 Scalar w_tmp = www() ;
490 w_tmp.exponential_filter_ylm(lzmin, lzmax, p, alpha) ;
491 Scalar x_tmp = xxx() ;
492 x_tmp.exponential_filter_ylm(lzmin, lzmax, p, alpha) ;
493 Scalar t_tmp = ttt() ;
494 t_tmp.exponential_filter_ylm(lzmin, lzmax, p, alpha) ;
495 set_auxiliary(srr_tmp, eta_tmp, mu_tmp, w_tmp, x_tmp, t_tmp) ;
496 }
497}
498}
Vectorial bases (triads) with respect to which the tensorial components are defined.
Definition base_vect.h:105
Basic integer array class.
Definition itbl.h:122
Tensor field of valence 0 (or component of a tensorial field).
Definition scalar.h:393
void div_r()
Division by r everywhere; dzpuis is not changed.
virtual void exponential_filter_ylm(int lzmin, int lzmax, int p, double alpha=-16.)
Applies an exponential filter to the spectral coefficients in the angular directions.
virtual void exponential_filter_r(int lzmin, int lzmax, int p, double alpha=-16.)
Applies an exponential filter to the spectral coefficients in the radial direction.
Transverse symmetric tensors of rank 2.
Definition sym_tensor.h:611
const Scalar & xxx() const
Gives the field X (see member p_xxx ).
virtual void exponential_filter_ylm(int lzmin, int lzmax, int p, double alpha=-16.)
Applies exponential filters to all components (see Scalar::exponential_filter_ylm ).
Definition sym_tensor.C:474
virtual void del_derive_met(int i) const
Logical destructor of the derivatives depending on the i-th element of met_depend specific to the cla...
Definition sym_tensor.C:323
Sym_tensor * inverse() const
Returns a pointer on the inverse of the Sym_tensor (seen as a matrix).
Definition sym_tensor.C:375
virtual void operator=(const Sym_tensor &a)
Assignment to another Sym_tensor.
Definition sym_tensor.C:237
Scalar * p_ttt
Field T defined as .
Definition sym_tensor.h:318
Scalar * p_aaa
Field A defined from X and insensitive to the longitudinal part of the Sym_tensor (only for ).
Definition sym_tensor.h:325
void set_der_met_0x0(int i) const
Sets all the i-th components of met_depend specific to the class Sym_tensor (p_transverse ,...
Definition sym_tensor.C:338
Scalar * p_tilde_b
Field defined from and h insensitive to the longitudinal part of the Sym_tensor.
Definition sym_tensor.h:337
Scalar * p_mu
Field such that the components of the tensor are written (has only meaning with spherical component...
Definition sym_tensor.h:277
Scalar * p_tilde_c
Field defined from and h insensitive to the longitudinal part of the Sym_tensor.
Definition sym_tensor.h:349
const Scalar & ttt() const
Gives the field T (see member p_ttt ).
virtual const Scalar & eta(Param *par=0x0) const
Gives the field (see member p_eta ).
const Scalar & www() const
Gives the field W (see member p_www ).
Sym_tensor_trans * p_transverse[N_MET_MAX]
Array of the transverse part of the tensor with respect to various metrics, transverse meaning diver...
Definition sym_tensor.h:242
const Scalar & mu(Param *par=0x0) const
Gives the field (see member p_mu ).
virtual void del_deriv() const
Deletes the derived quantities.
Definition sym_tensor.C:289
Scalar * p_eta
Field such that the components of the tensor are written (has only meaning with spherical component...
Definition sym_tensor.h:263
Scalar * p_xxx
Field X such that the components and of the tensor are written (has only meaning with spherical co...
Definition sym_tensor.h:315
Sym_tensor derive_lie(const Vector &v) const
Computes the Lie derivative of this with respect to some vector field v.
Definition sym_tensor.C:363
void set_auxiliary(const Scalar &trr, const Scalar &eta_over_r, const Scalar &mu_over_r, const Scalar &www, const Scalar &xxx, const Scalar &ttt)
Assigns the component and the derived members p_eta , p_mu , p_www, p_xxx and p_ttt ,...
Sym_tensor(const Map &map, const Itbl &tipe, const Base_vect &triad_i)
Standard constructor.
Definition sym_tensor.C:145
void set_der_0x0() const
Sets the pointers on derived quantities to 0x0.
Definition sym_tensor.C:308
Scalar * p_www
Field W such that the components and of the tensor are written (has only meaning with spherical co...
Definition sym_tensor.h:296
virtual ~Sym_tensor()
Destructor.
Definition sym_tensor.C:225
Vector * p_longit_pot[N_MET_MAX]
Array of the vector potential of the longitudinal part of the tensor with respect to various metrics ...
Definition sym_tensor.h:249
const Vector & divergence(const Metric &) const
Returns the divergence of this with respect to a Metric .
Definition sym_tensor.C:352
virtual void exponential_filter_r(int lzmin, int lzmax, int p, double alpha=-16.)
Applies exponential filters to all components (see Scalar::exponential_filter_r ).
Definition sym_tensor.C:449
Tensor handling.
Definition tensor.h:294
Tensor field of valence 1.
Definition vector.h:188
virtual void del_derive_met(int) const
Logical destructor of the derivatives depending on the i-th element of met_depend .
Definition tensor.C:423
const Map *const mp
Mapping on which the numerical values at the grid points are defined.
Definition tensor.h:301
virtual Itbl indices(int pos) const
Returns the indices of a component given by its position in the array cmp .
Definition tensor_sym.C:313
virtual void operator=(const Tensor_sym &a)
Assignment to another Tensor_sym.
Definition tensor_sym.C:201
int get_place_met(const Metric &) const
Returns the position of the pointer on metre in the array met_depend .
Definition tensor.C:452
const Metric * met_depend[N_MET_MAX]
Array on the Metric 's which were used to compute derived quantities, like p_derive_cov ,...
Definition tensor.h:333
virtual int position(const Itbl &ind) const
Returns the position in the array cmp of a component given by its indices.
Definition tensor.C:534
int valence
Valence of the tensor (0 = scalar, 1 = vector, etc...).
Definition tensor.h:304
Tensor_sym(const Map &map, int val, const Itbl &tipe, const Base_vect &triad_i, int index_sym1, int index_sym2)
Standard constructor.
Definition tensor_sym.C:72
const Scalar & operator()(const Itbl &ind) const
Returns the value of a component (read-only version).
Definition tensor.C:807
void set_dependance(const Metric &) const
To be used to describe the fact that the derivatives members have been calculated with met .
Definition tensor.C:462
Scalar ** cmp
Array of size n_comp of pointers onto the components.
Definition tensor.h:321
void compute_derive_lie(const Vector &v, Tensor &resu) const
Computes the Lie derivative of this with respect to some vector field v (protected method; the public...
int n_comp
Number of stored components, depending on the symmetry.
Definition tensor.h:318
virtual void del_deriv() const
Deletes the derived quantities.
Definition tensor.C:407
const Tensor & divergence(const Metric &gam) const
Computes the divergence of this with respect to some metric .
Definition tensor.C:1064
Itbl type_indice
1D array of integers (class Itbl ) of size valence containing the type of each index: COV for a cov...
Definition tensor.h:316
Scalar & set(const Itbl &ind)
Returns the value of a component (read/write version).
Definition tensor.C:663
const Base_vect * triad
Vectorial basis (triad) with respect to which the tensor components are defined.
Definition tensor.h:309
Lorene prototypes.
Definition app_hor.h:67
Map(const Mg3d &)
Constructor from a multi-domain 3D grid.
Definition map.C:142