Debian Codegraph @

C++/Include/tensor.h

raw symbols SCIP
1 /*
2 * Definition of Lorene classes Tensor and Sym_tensor
3 *
4 */
5
6 /*
7 * Copyright (c) 2003-2004 Eric Gourgoulhon & Jerome Novak
8 *
9 * Copyright (c) 1999-2001 Philippe Grandclement (for preceding class Tenseur)
10 * Copyright (c) 2000-2001 Eric Gourgoulhon (for preceding class Tenseur)
11 * Copyright (c) 2002 Jerome Novak (for preceding class Tenseur)
12 *
13 * This file is part of LORENE.
14 *
15 * LORENE is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
19 *
20 * LORENE is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with LORENE; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 *
29 */
30
31
32 #ifndef __TENSOR_H_
33 #define __TENSOR_H_
34
35
36 /*
37 * $Id: tensor.h,v 1.61 2014/10/13 08:52:37 j_novak Exp $
38 * $Log: tensor.h,v $
39 * Revision 1.61 2014/10/13 08:52:37 j_novak
40 * Lorene classes and functions now belong to the namespace Lorene.
41 *
42 * Revision 1.60 2013/06/05 15:43:49 j_novak
43 * Suppression of leg_spectral_base()
44 *
45 * Revision 1.59 2013/01/11 15:44:54 j_novak
46 * Addition of Legendre bases (part 2).
47 *
48 * Revision 1.58 2008/12/05 08:44:02 j_novak
49 * New flag to control the "verbosity" of maxabs.
50 *
51 * Revision 1.57 2007/12/21 16:06:16 j_novak
52 * Methods to filter Tensor, Vector and Sym_tensor objects.
53 *
54 * Revision 1.56 2006/06/07 14:08:58 j_novak
55 * New methods set_index_type( / int).
56 *
57 * Revision 1.55 2005/10/25 08:56:34 p_grandclement
58 * addition of std_spectral_base in the case of odd functions near the origin
59 *
60 * Revision 1.54 2004/07/08 12:21:51 j_novak
61 * Replaced tensor::annule_extern_c2 with tensor::annule_extern_cn for a
62 * more general transition.
63 *
64 * Revision 1.53 2004/06/17 06:54:23 e_gourgoulhon
65 * Added method annule_extern_c2.
66 *
67 * Revision 1.52 2004/05/13 21:29:27 e_gourgoulhon
68 * Added (external) functions central_value, max_all_domains,
69 * min_all_domains and maxabs_all_domains.
70 *
71 * Revision 1.51 2004/03/24 14:53:39 j_novak
72 * Double declarations suppressed
73 *
74 * Revision 1.50 2004/03/22 13:12:43 j_novak
75 * Modification of comments to use doxygen instead of doc++
76 *
77 * Revision 1.49 2004/02/27 21:12:44 e_gourgoulhon
78 * Suppressed function contract_desal (since contract has now the
79 * boolean argument "desaliasing").
80 *
81 * Revision 1.48 2004/02/26 22:44:37 e_gourgoulhon
82 * -- constructor of Tensor from Map is now declared explicit.
83 * -- class Tensor: added methods compute_derive_lie and derive_lie
84 * -- class Tensor_sym: added methods derive_cov, derive_con and derive_lie.
85 *
86 * Revision 1.47 2004/02/19 22:08:51 e_gourgoulhon
87 * Added argument "comment" in method spectral_display,
88 * as well as in external functions min, max, maxabs, etc...
89 *
90 * Revision 1.46 2004/02/18 18:42:41 e_gourgoulhon
91 * -- Added methods trace.
92 * -- Method scontract suppressed ( since it is the same as trace(int, int) ).
93 *
94 * Revision 1.45 2004/02/18 15:52:39 e_gourgoulhon
95 * -- Added optional argument desaliasing in function contract.
96 * -- Added new function contract for double contraction.
97 *
98 * Revision 1.44 2004/02/16 10:48:06 e_gourgoulhon
99 * Added "class Tensor_sym;" at the beginning.
100 *
101 * Revision 1.43 2004/02/15 21:53:48 e_gourgoulhon
102 * Modif. comments: suppressed the mention *** under development ***.
103 *
104 * Revision 1.42 2004/01/30 12:44:17 e_gourgoulhon
105 * Added Tensor_sym operator*(const Tensor_sym&, const Tensor_sym& ).
106 *
107 * Revision 1.41 2004/01/27 13:05:10 j_novak
108 * Removed the method Tensor::mult_r_ced()
109 *
110 * Revision 1.40 2004/01/19 16:31:40 e_gourgoulhon
111 * Added operator()(int, int, int, int) and set(int, int, int, int)
112 * for direct access to components of valence 4 tensors.
113 *
114 * Revision 1.39 2004/01/15 11:09:27 f_limousin
115 * Modif in method contract_desal
116 *
117 * Revision 1.38 2004/01/15 11:00:44 f_limousin
118 * Added method contract_desal for the contraction of two tensors with desaliasing
119 *
120 * Revision 1.37 2004/01/14 11:39:00 f_limousin
121 * Added method contract for one tensor
122 *
123 * Revision 1.36 2004/01/08 09:21:39 e_gourgoulhon
124 * Added arithmetics of Tensor_sym.
125 * Added arithmetics with Scalar (to solve some ambiguities with respect
126 * to the Scalar arithmetics).
127 * Added Tensor_sym tensorial product.
128 *
129 * Revision 1.35 2004/01/04 20:47:37 e_gourgoulhon
130 * -- Introduction of new derived class Tensor_sym to store tensor with
131 * two symmetric indices
132 * -- Suppression of class Tensor_delta (now a special case of Tensor_sym).
133 *
134 * Revision 1.34 2003/12/27 14:58:01 e_gourgoulhon
135 * Improved documentation. In particular, better description of methods
136 * derive_cov(), derive_con() and divergence(), taking into account the
137 * new index convention for covariant derivatives.
138 *
139 * Revision 1.33 2003/12/05 16:41:05 f_limousin
140 * Added method operator*
141 *
142 * Revision 1.32 2003/11/06 14:43:37 e_gourgoulhon
143 * Gave a name to const arguments in certain method prototypes (e.g.
144 * constructors) to correct a bug of DOC++.
145 *
146 * Revision 1.31 2003/11/05 15:25:57 e_gourgoulhon
147 * Added declaration of external functions:
148 * max, min, maxabs, diffrel and diffrelmax.
149 *
150 * Revision 1.30 2003/11/03 10:58:00 j_novak
151 * Suppressed the constructor from a Sym_tensor.
152 *
153 * Revision 1.29 2003/10/29 11:00:42 e_gourgoulhon
154 * Virtual functions dec_dzpuis and inc_dzpuis have now an integer argument to
155 * specify by which amount dzpuis is to be increased.
156 * Accordingly virtual methods dec2_dzpuis and inc2_dzpuis have been suppressed.
157 *
158 * Revision 1.28 2003/10/28 21:21:50 e_gourgoulhon
159 * Member function Tensor::contract(int, int) renamed
160 * Tensor::scontract(int, int) in order not to mask
161 * the non-member function contract.
162 *
163 * Revision 1.27 2003/10/27 10:44:00 e_gourgoulhon
164 * Declaration of class Sym_tensor is now in file sym_tensor.h.
165 *
166 * Revision 1.26 2003/10/24 15:00:19 j_novak
167 * Forgotten Class declaration... thanks IBM aix!
168 *
169 * Revision 1.25 2003/10/20 14:26:02 j_novak
170 * New assignement operators.
171 *
172 * Revision 1.24 2003/10/20 09:32:10 j_novak
173 * Members p_potential and p_div_free of the Helmholtz decomposition
174 * + the method decompose_div(Metric).
175 *
176 * Revision 1.23 2003/10/19 19:47:31 e_gourgoulhon
177 * Introduced new virtual method spectral_display.
178 *
179 * Revision 1.22 2003/10/16 15:24:30 e_gourgoulhon
180 * Name of method annule(int ) changed to annule_domain(int ).
181 *
182 * Revision 1.21 2003/10/16 14:21:33 j_novak
183 * The calculation of the divergence of a Tensor is now possible.
184 *
185 * Revision 1.20 2003/10/13 13:52:39 j_novak
186 * Better managment of derived quantities.
187 *
188 * Revision 1.19 2003/10/08 14:24:08 j_novak
189 * replaced mult_r_zec with mult_r_ced
190 *
191 * Revision 1.18 2003/10/06 20:48:23 e_gourgoulhon
192 * Added methods down and up_down.
193 *
194 * Revision 1.17 2003/10/06 16:17:29 j_novak
195 * Calculation of contravariant derivative and Ricci scalar.
196 *
197 * Revision 1.16 2003/10/06 15:12:56 e_gourgoulhon
198 * Added tensor contraction and raising of index.
199 *
200 * Revision 1.15 2003/10/06 13:58:45 j_novak
201 * The memory management has been improved.
202 * Implementation of the covariant derivative with respect to the exact Tensor
203 * type.
204 *
205 * Revision 1.14 2003/10/05 21:07:27 e_gourgoulhon
206 * Method std_spectral_base() is now virtual.
207 *
208 * Revision 1.13 2003/10/03 11:21:45 j_novak
209 * More methods for the class Metric
210 *
211 * Revision 1.12 2003/10/02 15:45:48 j_novak
212 * New class Metric
213 *
214 * Revision 1.11 2003/10/01 15:41:14 e_gourgoulhon
215 * class name Delta changed to Tensor_delta.
216 *
217 * Revision 1.10 2003/10/01 13:03:52 e_gourgoulhon
218 * The method get_mp() returns now a reference (and not a pointer)
219 * onto a mapping.
220 *
221 * Revision 1.9 2003/09/29 13:48:17 j_novak
222 * New class Delta.
223 *
224 * Revision 1.8 2003/09/26 14:33:51 j_novak
225 * Arithmetic functions for the class Tensor
226 *
227 * Revision 1.7 2003/09/26 08:05:29 j_novak
228 * New class Vector.
229 *
230 * Revision 1.6 2003/09/25 21:01:50 e_gourgoulhon
231 * Improved comments.
232 *
233 * Revision 1.5 2003/09/25 13:37:38 j_novak
234 * Symmetric tensors of valence 2 are now implemented (not tested yet).
235 *
236 * Revision 1.4 2003/09/24 15:10:54 j_novak
237 * Suppression of the etat flag in class Tensor (still present in Scalar)
238 *
239 * Revision 1.3 2003/09/24 08:46:31 j_novak
240 * Added tensor.h and scalar.h to the documentation
241 *
242 * Revision 1.2 2003/09/23 08:53:11 e_gourgoulhon
243 * not ready yet
244 *
245 * Revision 1.1 2003/09/22 12:50:47 e_gourgoulhon
246 * First version: not ready yet!
247 *
248 *
249 * $Header: /cvsroot/Lorene/C++/Include/tensor.h,v 1.61 2014/10/13 08:52:37 j_novak Exp $
250 *
251 */
252
253 #define COV -1
254 #define CON +1
255
256 #define N_MET_MAX 5
257
258 // Headers Lorene
259 #include "itbl.h"
260 #include "base_vect.h"
261 #include "map.h"
262
263 namespace Lorene {
264 class Scalar ;
265 class Vector ;
266 class Tensor_sym ;
267 class Sym_tensor ;
268 class Metric ;
269
270 //-------------------------//
271 // class Tensor //
272 //-------------------------//
273
274
275 /**
276 * Tensor handling. \ingroup (tensor)
277 *
278 * This class has been devised to replace \c Tenseur and \c Cmp (the
279 * latter via the derived class \c Scalar ).
280 *
281 * The \c Tensor class is intended to store the components of a tensorial
282 * field with respect to a specific basis (triad).
283 *
284 * All this is \e 3D meaning that the indices go from 1 to 3.
285 *
286 *
287 */
288 class Tensor {
289
290 // Data :
291 // -----
292 protected:
293
294 /// Mapping on which the numerical values at the grid points are defined
295 const Map* const mp ;
296
297 /// Valence of the tensor (0 = scalar, 1 = vector, etc...)
298 int valence ;
299
300 /** Vectorial basis (triad) with respect to which the tensor
301 * components are defined.
302 */
303 const Base_vect* triad ;
304
305 /** 1D array of integers (class \c Itbl ) of size \c valence
306 * containing the type of each index:
307 * \c COV for a covariant one and \c CON for a contravariant one.
308 *
309 */
310 Itbl type_indice ;
311
312 int n_comp ; ///< Number of stored components, depending on the symmetry.
313
314 /// Array of size \c n_comp of pointers onto the components.
315 Scalar** cmp ;
316
317
318 // Derived data :
319 // ------------
320 protected:
321 /**
322 * Array on the \c Metric 's which were used to compute derived
323 * quantities, like \c p_derive_cov , etc...
324 * The i-th element of this array is the \c Metric used to
325 * compute the i-th element of \c p_derive_cov , etc..
326 */
327 mutable const Metric* met_depend[N_MET_MAX] ;
328
329 /** Array of pointers on the covariant derivatives of \c this
330 * with respect to various metrics.
331 * See the comments of \c met_depend . See also the comments
332 * of method \c derive_cov() for the index convention of the
333 * covariant derivation.
334 */
335 mutable Tensor* p_derive_cov[N_MET_MAX];
336
337 /** Array of pointers on the contravariant derivatives of \c this
338 * with respect to various metrics.
339 * See the comments of \c met_depend . See also the comments
340 * of method \c derive_con() for a precise definition of a
341 * "contravariant" derivative.
342 */
343 mutable Tensor* p_derive_con[N_MET_MAX];
344
345 /** Array of pointers on the divergence of \c this
346 * with respect to various metrics.
347 * See the comments of \c met_depend . See also the comments
348 * of method \c divergence() for a precise definition of a
349 * the divergence with respect to a given metric.
350 */
351 mutable Tensor* p_divergence[N_MET_MAX];
352
353
354 // Constructors - Destructor :
355 // -------------------------
356
357 public:
358
359 /** Standard constructor.
360 *
361 * @param map the mapping
362 * @param val valence of the tensor
363 * @param tipe 1-D array of integers (class \c Itbl )
364 * of size \c valence containing the type
365 * of each index, \c COV for a covariant one
366 * and \c CON for a contravariant one, with the
367 * following storage convention:
368 * \li \c tipe(0) : type of the first index
369 * \li \c tipe(1) : type of the second index
370 * \li and so on...
371 * @param triad_i vectorial basis (triad) with respect to which
372 * the tensor components are defined
373 */
374 Tensor(const Map& map, int val, const Itbl& tipe,
375 const Base_vect& triad_i) ;
376
377 /** Standard constructor with the triad passed as a pointer.
378 *
379 * @param map the mapping
380 * @param val valence of the tensor
381 * @param tipe 1-D array of integers (class \c Itbl )
382 * of size \c valence containing the type
383 * of each index, \c COV for a covariant one
384 * and \c CON for a contravariant one, with the
385 * following storage convention:
386 * \li \c tipe(0) : type of the first index
387 * \li \c tipe(1) : type of the second index
388 * \li and so on...
389 * @param triad_i pointer on the vectorial basis (triad) with respect
390 * to which the tensor components are defined
391 * (can be set to 0x0 for a scalar field)
392 */
393 Tensor(const Map& map, int val, const Itbl& tipe,
394 const Base_vect* triad_i) ;
395
396 /** Standard constructor when all the indices are of
397 * the same type.
398 *
399 * @param map the mapping
400 * @param val valence of the tensor
401 * @param tipe the type (\c COV or \c CON ) of the indices.
402 * @param triad_i vectorial basis (triad) with respect to which
403 * the tensor components are defined.
404 */
405 Tensor(const Map& map, int val, int tipe,
406 const Base_vect& triad_i) ;
407
408 Tensor(const Tensor&) ; ///< Copy constructor
409
410 /** Constructor from a file (see \c sauve(FILE*) ).
411 *
412 * @param map the mapping
413 * @param triad_i vectorial basis (triad) with respect to which
414 * the tensor components are defined. It will
415 * be checked that it coincides with the basis
416 * saved in the file.
417 * @param fich file which has been created by
418 * the function \c sauve(FILE*) .
419 */
420 Tensor(const Map& map, const Base_vect& triad_i, FILE* fich) ;
421
422 protected:
423 /**
424 * Constructor for a scalar field: to be used only by the derived
425 * class \c Scalar .
426 *
427 */
428 explicit Tensor(const Map& map) ;
429
430 /**
431 * Constructor to be used by derived classes, with symmetries among
432 * the components. The number of independent components is
433 * given as an argument (\c n_comp_i ), and not computed
434 * from the valence, as in the standard constructor.
435 *
436 *
437 * @param map the mapping
438 * @param val valence of the tensor
439 * @param tipe 1-D array of integers (class \c Itbl )
440 * of size \c valence containing the type
441 * of each index, \c COV for a covariant one
442 * and \c CON for a contravariant one, with the
443 * following storage convention:
444 * \li \c tipe(0) : type of the first index
445 * \li \c tipe(1) : type of the second index
446 * \li and so on...
447 * @param n_comp_i number of components to be stored
448 * @param triad_i vectorial basis (triad) with respect to which
449 * the tensor components are defined
450 */
451 Tensor(const Map& map, int val, const Itbl& tipe, int n_comp_i,
452 const Base_vect& triad_i) ;
453
454 /**
455 * Constructor used by derived classes, with symmetries among
456 * the components, when all the indices are of
457 * the same type. The number of independent components is
458 * given as a argument (\c n_comp_i ), and not computed
459 * from the valence, as in the standard constructor.
460 *
461 * @param map the mapping
462 * @param val valence of the tensor
463 * @param tipe the type of the indices.
464 * @param n_comp_i number of components to be stored
465 * @param triad_i vectorial basis (triad) with respect to which
466 * the tensor components are defined
467 */
468 Tensor(const Map& map, int val, int tipe, int n_comp_i,
469 const Base_vect& triad_i) ;
470
471
472 public:
473
474 virtual ~Tensor() ; ///< Destructor
475
476 // Memory management
477 // -----------------
478 protected:
479 virtual void del_deriv() const ; ///< Deletes the derived quantities
480
481 /// Sets the pointers on derived quantities to 0x0
482 void set_der_0x0() const ;
483
484 /**
485 * Logical destructor of the derivatives depending on the i-th
486 * element of \c met_depend .
487 */
488 virtual void del_derive_met(int) const ;
489
490 /**
491 * Sets all the i-th components of \c met_depend ,
492 * \c p_derive_cov , etc... to 0x0.
493 */
494 void set_der_met_0x0(int) const ;
495
496 /**
497 * To be used to describe the fact that the derivatives members have
498 * been calculated with \c met .
499 *
500 * First it sets a null element of \c met_depend to
501 * \c \&met and puts \c this in
502 * the list of the dependancies of \c met .
503 *
504 */
505 void set_dependance (const Metric&) const ;
506
507 /**
508 * Returns the position of the pointer on \c metre in
509 * the array \c met_depend .
510 *
511 */
512 int get_place_met(const Metric&) const ;
513
514 // Mutators / assignment
515 // ---------------------
516 public:
517 /**
518 * Sets the logical state of all components to \c ETATNONDEF
519 * (undefined state).
520 */
521 virtual void set_etat_nondef() ;
522
523 /**
524 * Sets the logical state of all components to \c ETATZERO
525 *(zero state).
526 */
527 virtual void set_etat_zero() ;
528
529 /**
530 * Sets the logical state of all components to \c ETATQCQ
531 * (ordinary state).
532 */
533 virtual void set_etat_qcq() ;
534
535 /**
536 * Performs the memory allocation of all the
537 * elements, down to the \c double arrays of the \c Tbl s.
538 * This function performs in fact recursive calls to
539 * \c set_etat_qcq()
540 * on each element of the chain \c Scalar ->
541 * \c Valeur -> \c Mtbl -> \c Tbl .
542 */
543 virtual void allocate_all() ;
544
545 /** Sets a new vectorial basis (triad) of decomposition and modifies
546 * the components accordingly.
547 */
548 virtual void change_triad(const Base_vect& new_triad) ;
549
550 /** Assigns a new vectorial basis (triad) of decomposition.
551 * NB: this function modifies only the member \c triad and
552 * leave unchanged the components (member \c cmp ). In order to
553 * change them coherently with the new basis, the function
554 * \c change_triad(const Base_vect\& ) must be called instead.
555 */
556 void set_triad(const Base_vect& new_triad) ;
557
558
559 virtual void operator=(const Tensor&) ;///< Assignment to a \c Tensor
560
561 /** Returns the value of a component (read/write version).
562 *
563 * @param ind 1-D \c Itbl of size \c valence containing the
564 * values of each index specifing the component, with the
565 * following storage convention:
566 * \li \c ind(0) : value of the first index (1, 2 or 3)
567 * \li \c ind(1) : value of the second index (1, 2 or 3)
568 * \li and so on...
569 * @return modifiable reference on the component specified by \c ind
570 *
571 */
572 Scalar& set(const Itbl& ind) ;
573
574 /** Returns the value of a component for a tensor of valence 2
575 * (read/write version).
576 *
577 * @param i1 value of the first index (1, 2 or 3)
578 * @param i2 value of the second index (1, 2 or 3)
579 *
580 * @return modifiable reference on the component specified by \c (i1,i2)
581 *
582 */
583 Scalar& set(int i1, int i2) ;
584
585
586 /** Returns the value of a component for a tensor of valence 3
587 * (read/write version).
588 *
589 * @param i1 value of the first index (1, 2 or 3)
590 * @param i2 value of the second index (1, 2 or 3)
591 * @param i3 value of the third index (1, 2 or 3)
592 *
593 * @return modifiable reference on the component specified by \c (i1,i2,i3)
594 *
595 */
596 Scalar& set(int i1, int i2, int i3) ;
597
598 /** Returns the value of a component for a tensor of valence 4
599 * (read/write version).
600 *
601 * @param i1 value of the first index (1, 2 or 3)
602 * @param i2 value of the second index (1, 2 or 3)
603 * @param i3 value of the third index (1, 2 or 3)
604 * @param i4 value of the fourth index (1, 2 or 3)
605 *
606 * @return modifiable reference on the component specified by
607 * \c (i1,i2,i3,i4)
608 *
609 */
610 Scalar& set(int i1, int i2, int i3, int i4) ;
611
612 /**
613 * Sets the \c Tensor to zero in a given domain.
614 * @param l [input] Index of the domain in which the \c Tensor
615 * will be set (logically) to zero.
616 */
617 void annule_domain(int l) ;
618
619 /**
620 * Sets the \c Tensor to zero in several domains.
621 * @param l_min [input] The \c Tensor will be set (logically)
622 * to zero
623 * in the domains whose indices are in the range
624 * \c [l_min,l_max] .
625 * @param l_max [input] see the comments for \c l_min .
626 *
627 * Note that \c annule(0,nz-1) , where \c nz is the total number
628 * of domains, is equivalent to \c set_etat_zero() .
629 */
630 virtual void annule(int l_min, int l_max) ;
631
632 /** Performs a smooth (C^n) transition in a given domain
633 * to zero.
634 * @param l_0 [input] in the domain of index l0 the tensor is
635 * multiplied by the right polynomial (of degree \e 2n+1), to
636 * ensure continuty of the function and its \e n first
637 * derivative at both ends of this domain. The tensor is unchanged
638 * in the domains \e l < \e l_0 and set to zero in domains \e l >
639 * \e l_0.
640 * @param deg [input] the degree \e n of smoothness of the
641 * transition.
642 */
643 void annule_extern_cn(int l_0, int deg) ;
644
645 /**
646 * Sets the standard spectal bases of decomposition for each component.
647 * To be used only with \c valence lower than or equal 2.
648 */
649 virtual void std_spectral_base() ;
650
651 /**
652 * Sets the standard odd spectal bases of decomposition for each component.
653 * Currently only implemented for a scalar.
654 */
655 virtual void std_spectral_base_odd() ;
656
657 /** Decreases by \c dec units the value of \c dzpuis and
658 * changes accordingly the values in the
659 * compactified external domain (CED).
660 */
661 virtual void dec_dzpuis(int dec = 1) ;
662
663 /** Increases by \c inc units the value of \c dzpuis and
664 * changes accordingly the values in the
665 * compactified external domain (CED).
666 */
667 virtual void inc_dzpuis(int inc = 1) ;
668
669 /** Applies exponential filters to all components
670 * (see \c Scalar::exponential_filter_r ). Works only for Cartesian
671 * components.
672 */
673 virtual void exponential_filter_r(int lzmin, int lzmax, int p,
674 double alpha= -16.) ;
675
676 /** Applies exponential filters to all components
677 * (see \c Scalar::exponential_filter_ylm ). Works only for Cartesian
678 * components.
679 */
680 virtual void exponential_filter_ylm(int lzmin, int lzmax, int p,
681 double alpha= -16.) ;
682
683 // Computational methods
684 // ---------------------
685
686 protected:
687 /** Computes the Lie derivative of \c this with respect to some
688 * vector field \c v (protected method; the public interface
689 * is method \c derive_lie ).
690 */
691 void compute_derive_lie(const Vector& v, Tensor& resu) const ;
692
693
694 public:
695 /** Returns the covariant derivative of \c this with respect to some
696 * metric \f$\gamma\f$.
697 * \f$T\f$ denoting the tensor represented by \c this and
698 * \f$\nabla T\f$ its covariant derivative with respect to
699 * the metric \f$\gamma\f$,
700 * the extra index (with respect to the indices of \f$T\f$)
701 * of \f$\nabla T\f$ is chosen to be the \b last one.
702 * This convention agrees with that of MTW (see Eq. (10.17) of MTW).
703 * For instance, if \f$T\f$ is a 1-form, whose components
704 * w.r.t. the triad \f$e^i\f$ are \f$T_i\f$: \f$T=T_i \; e^i\f$,
705 * then the covariant derivative of \f$T\f$ is the bilinear form
706 * \f$\nabla T\f$ whose components \f$\nabla_j T_i\f$ are
707 * such that
708 * \f[
709 * \nabla T = \nabla_j T_i \; e^i \otimes e^j
710 * \f]
711 *
712 * @param gam metric \f$\gamma\f$
713 * @return covariant derivative \f$\nabla T\f$ of \c this with
714 * respect to the connection \f$\nabla\f$ associated with the
715 * metric \f$\gamma\f$
716 */
717 const Tensor& derive_cov(const Metric& gam) const ;
718
719 /** Returns the "contravariant" derivative of \c this with respect
720 * to some metric \f$\gamma\f$, by raising the last index of the
721 * covariant derivative (cf. method \c derive_cov() ) with
722 * \f$\gamma\f$.
723 */
724 const Tensor& derive_con(const Metric& gam) const ;
725
726 /** Computes the divergence of \c this with respect to
727 * some metric \f$\gamma\f$.
728 * The divergence is taken with respect of the last index of \c this
729 * which thus must be contravariant.
730 * For instance if the tensor \f$T\f$ represented by \c this
731 * is a twice contravariant tensor, whose
732 * components w.r.t. the
733 * triad \f$e_i\f$ are \f$T^{ij}\f$: \f$T = T^{ij} \; e_i \otimes e_j\f$,
734 * the divergence of \f$T\f$ w.r.t. \f$\gamma\f$ is the vector
735 * \f[
736 * {\rm div}\, T = \nabla_k T^{ik} \; e_i
737 * \f]
738 * where \f$\nabla\f$ denotes the connection associated with the metric
739 * \f$\gamma\f$.
740 * @param gam metric \f$\gamma\f$
741 * @return divergence of \c this with respect to \f$\gamma\f$.
742 */
743 const Tensor& divergence(const Metric& gam) const ;
744
745
746 /** Computes the Lie derivative of \c this with respect to some
747 * vector field \c v
748 */
749 Tensor derive_lie(const Vector& v) const ;
750
751 /** Computes a new tensor by raising an index of \c *this
752 *
753 * @param ind index to be raised, with the
754 * following convention :
755 * \li \c ind1 = 0 : first index of the tensor
756 * \li \c ind1 = 1 : second index of the tensor
757 * \li and so on...
758 * (\c ind must be of covariant type (\c COV )).
759 * @param gam metric used to raise the index (contraction with the
760 * twice contravariant form of the metric on the index \c ind ).
761 *
762 */
763 Tensor up(int ind, const Metric& gam) const ;
764
765 /** Computes a new tensor by lowering an index of \c *this
766 *
767 * @param ind index to be lowered, with the
768 * following convention :
769 * \li \c ind1 = 0 : first index of the tensor
770 * \li \c ind1 = 1 : second index of the tensor
771 * \li and so on...
772 * (\c ind must be of covariant type (\c CON )).
773 * @param gam metric used to lower the index (contraction with the
774 * twice covariant form of the metric on the index \c ind ).
775 *
776 */
777 Tensor down(int ind, const Metric& gam) const ;
778
779 /** Computes a new tensor by raising or lowering all the indices
780 * of \c *this .
781 *
782 * @param gam metric used to lower the contravariant indices
783 * and raising the covariant ones.
784 *
785 */
786 Tensor up_down(const Metric& gam) const ;
787
788 /** Trace on two different type indices.
789 * @param ind1 first index for the contraction, with the
790 * following convention :
791 * \li \c ind1 = 0 : first index of the tensor
792 * \li \c ind1 = 1 : second index of the tensor
793 * \li and so on...
794 * @param ind2 second index for the contraction
795 */
796 Tensor trace(int ind1, int ind2) const ;
797
798 /** Trace with respect to a given metric.
799 * @param ind1 first index for the contraction, with the
800 * following convention :
801 * \li \c ind1 = 0 : first index of the tensor
802 * \li \c ind1 = 1 : second index of the tensor
803 * \li and so on...
804 * @param ind2 second index for the contraction
805 * @param gam metric used to raise or lower ind1 in order that it
806 * has a opposite type than ind2
807 */
808 Tensor trace(int ind1, int ind2, const Metric& gam) const ;
809
810 /** Trace on two different type indices for a valence 2 tensor.
811 */
812 Scalar trace() const ;
813
814 /** Trace with respect to a given metric for a valence 2 tensor.
815 * @param gam metric used to raise or lower one of the indices,
816 * in order to take the trace
817 */
818 Scalar trace(const Metric& gam) const ;
819
820
821 // Accessors
822 // ---------
823 public:
824 /**
825 * Returns the position in the array \c cmp of a
826 * component given by its indices.
827 *
828 * @param ind [input] 1-D array of integers (class \c Itbl )
829 * of size \c valence giving the
830 * values of each index specifing the component, with the
831 * following storage convention:
832 * \li \c ind(0) : value of the first index (1, 2 or 3)
833 * \li \c ind(1) : value of the second index (1, 2 or 3)
834 * \li and so on...
835 *
836 * @return position in the array \c cmp of the pointer to the
837 * \c Scalar containing the component specified by \c ind
838 */
839 virtual int position(const Itbl& ind) const ;
840
841 /**
842 * Returns the indices of a component given by its position in the
843 * array \c cmp .
844 *
845 * @param pos [input] position in the array \c cmp
846 * of the pointer to the \c Scalar representing a component
847 *
848 * @return 1-D array of integers (class \c Itbl ) of
849 * size \c valence giving the value of each index
850 * for the component located at the position \c pos in
851 * the array \c cmp, with the
852 * following storage convention:
853 * \li \c Itbl(0) : value of the first index (1, 2 or 3)
854 * \li \c Itbl(1) : value of the second index (1, 2 or 3)
855 * \li and so on...
856 */
857 virtual Itbl indices(int pos) const ;
858
859 public:
860 /// Returns the mapping.
861 const Map& get_mp() const {return *mp ;} ;
862
863 /** Returns the vectorial basis (triad) on which the components
864 * are defined.
865 */
866 const Base_vect* get_triad() const {return triad;} ;
867
868 /// Returns the valence.
869 int get_valence() const {return valence ; } ;
870
871 /// Returns the number of stored components.
872 int get_n_comp() const {return n_comp ;} ;
873
874 /**
875 * Gives the type (covariant or contravariant)
876 * of the index number \c i . \c i must be
877 * strictly lower than \c valence and obey the following
878 * convention:
879 * \li \c i = 0 : first index
880 * \li \c i = 1 : second index
881 * \li and so on...
882 *
883 * @return COV for a covariant index, CON for a
884 * contravariant one.
885 */
886 int get_index_type(int i) const {return type_indice(i) ;};
887
888 /**
889 * Returns the types of all the indices.
890 *
891 * @return 1-D array of integers (class \c Itbl ) of size \c valence
892 * containing the type of each index,
893 * \c COV for a covariant one and \c CON
894 * for a contravariant one.
895 */
896 Itbl get_index_type() const {return type_indice ; } ;
897
898 /**
899 * Sets the type of the index number \c i . \c i must be
900 * strictly lower than \c valence and obey the following
901 * convention:
902 * \li \c i = 0 : first index
903 * \li \c i = 1 : second index
904 * \li and so on...
905 *
906 * @return reference on the type that can be modified
907 * (\c COV for a covariant index, \c CON for a contravariant one)
908 */
909 int& set_index_type(int i) {return type_indice.set(i) ;};
910
911 /**
912 * Sets the types of all the indices.
913 *
914 * @return a reference on the 1-D array of integers (class \c Itbl )
915 * of size \c valence that can be modified
916 * (\c COV for a covariant one and \c CON for a contravariant one)
917 */
918 Itbl& set_index_type() {return type_indice ; } ;
919
920
921 /** Returns the value of a component (read-only version).
922 *
923 * @param ind 1-D \c Itbl of size \c valence containing the
924 * values of each index specifing the component, with the
925 * following storage convention:
926 * \li \c ind(0) : value of the first index (1, 2 or 3)
927 * \li \c ind(1) : value of the second index (1, 2 or 3)
928 * \li and so on...
929 * @return reference on the component specified by \c ind
930 *
931 */
932 const Scalar& operator()(const Itbl& ind) const ;
933
934 /** Returns the value of a component for a tensor of valence 2
935 * (read-only version).
936 *
937 * @param i1 value of the first index (1, 2 or 3)
938 * @param i2 value of the second index (1, 2 or 3)
939 *
940 * @return reference on the component specified by \c (i1,i2)
941 *
942 */
943 const Scalar& operator()(int i1, int i2) const ;
944
945 /** Returns the value of a component for a tensor of valence 3
946 * (read-only version).
947 *
948 * @param i1 value of the first index (1, 2 or 3)
949 * @param i2 value of the second index (1, 2 or 3)
950 * @param i3 value of the third index (1, 2 or 3)
951 *
952 * @return reference on the component specified by \c (i1,i2,i3)
953 *
954 */
955 const Scalar& operator()(int i1, int i2, int i3) const ;
956
957 /** Returns the value of a component for a tensor of valence 4
958 * (read-only version).
959 *
960 * @param i1 value of the first index (1, 2 or 3)
961 * @param i2 value of the second index (1, 2 or 3)
962 * @param i3 value of the third index (1, 2 or 3)
963 * @param i4 value of the fourth index (1, 2 or 3)
964 *
965 * @return reference on the component specified by \c (i1,i2,i3,i4)
966 *
967 */
968 const Scalar& operator()(int i1, int i2, int i3, int i4) const ;
969
970 // Member arithmetics
971 // ------------------
972 public:
973 void operator+=(const Tensor &) ; ///< += Tensor
974 void operator-=(const Tensor &) ; ///< -= Tensor
975
976 // Outputs
977 // -------
978 public:
979 virtual void sauve(FILE *) const ; ///< Save in a binary file
980
981 /** Displays the spectral coefficients and the associated
982 * basis functions of each component. This function shows
983 * only the values greater than a given threshold.
984 * @param comment comment to be printed at top of the display
985 * (default: 0x0 = nothing printed)
986 * @param threshold [input] Value above which a coefficient is printed
987 * (default: 1.e-7)
988 * @param precision [input] Number of printed digits (default: 4)
989 * @param ostr [input] Output stream used for the printing (default: cout)
990 */
991 virtual void spectral_display(const char* comment = 0x0,
992 double threshold = 1.e-7, int precision = 4,
993 ostream& ostr = cout) const ;
994
995 friend ostream& operator<<(ostream& , const Tensor & ) ;
996
997
998 // Friend classes
999 // ---------------
1000 friend class Scalar ;
1001 friend class Vector ;
1002 friend class Sym_tensor ;
1003 friend class Tensor_sym ;
1004 friend class Metric ;
1005
1006 // Mathematical operators
1007 // ----------------------
1008
1009 friend Scalar operator+(const Tensor&, const Scalar&) ;
1010 friend Scalar operator+(const Scalar&, const Tensor&) ;
1011 friend Scalar operator-(const Tensor&, const Scalar&) ;
1012 friend Scalar operator-(const Scalar&, const Tensor&) ;
1013 friend Tensor operator*(const Tensor&, const Tensor&) ;
1014 friend Tensor_sym operator*(const Tensor&, const Tensor_sym&) ;
1015 friend Tensor_sym operator*(const Tensor_sym&, const Tensor&) ;
1016 friend Tensor_sym operator*(const Tensor_sym&, const Tensor_sym&) ;
1017
1018 };
1019
1020
1021
1022 //-------------------------//
1023 // class Tensor_sym //
1024 //-------------------------//
1025
1026 /**
1027 * Symmetric tensors (with respect to two of their arguments).
1028 *
1029 * This subclass of \c Tensor is intended to store the components of a
1030 * tensorial field with respect to a specific basis (triad), in the case
1031 * the tensor has a valence at least 2 and is symmetric with respect
1032 * to two of its arguments (or in other words, the components are
1033 * symmetric with respect to two of their indices).
1034 * \ingroup (tensor)
1035 *
1036 */
1037 class Tensor_sym : public Tensor {
1038
1039 // Data :
1040 // -----
1041 protected:
1042
1043 /// Number of the first symmetric index (\c 0<= \c id_sym1 < \c valence )
1044 int id_sym1 ;
1045
1046 /** Number of the second symmetric index
1047 * (\c id_sym1 < \c id_sym2 < \c valence )
1048 */
1049 int id_sym2 ;
1050
1051
1052 // Constructors - Destructor :
1053 // -------------------------
1054
1055 public:
1056
1057 /** Standard constructor.
1058 *
1059 * @param map the mapping
1060 * @param val valence of the tensor (must be at least 2)
1061 * @param tipe 1-D array of integers (class \c Itbl )
1062 * of size \c valence containing the type
1063 * of each index, \c COV for a covariant one
1064 * and \c CON for a contravariant one, with the
1065 * following storage convention:
1066 * \li \c tipe(0) : type of the first index
1067 * \li \c tipe(1) : type of the second index
1068 * \li and so on...
1069 * @param triad_i vectorial basis (triad) with respect to which
1070 * the tensor components are defined
1071 * @param index_sym1 number of the first symmetric index
1072 * (\c 0<= \c index_sym1 < \c valence )
1073 * @param index_sym2 number of the second symmetric index
1074 * (\c index_sym1 < \c index_sym2 < \c valence )
1075 */
1076 Tensor_sym(const Map& map, int val, const Itbl& tipe,
1077 const Base_vect& triad_i, int index_sym1,
1078 int index_sym2) ;
1079
1080 /** Standard constructor when all the indices are of
1081 * the same type.
1082 *
1083 * @param map the mapping
1084 * @param val valence of the tensor (must be at least 2)
1085 * @param tipe the type (\c COV or \c CON ) of the indices.
1086 * @param triad_i vectorial basis (triad) with respect to which
1087 * the tensor components are defined.
1088 * @param index_sym1 number of the first symmetric index
1089 * (\c 0<= \c index_sym1 < \c valence )
1090 * @param index_sym2 number of the second symmetric index
1091 * (\c index_sym1 < \c index_sym2 < \c valence )
1092 */
1093 Tensor_sym(const Map& map, int val, int tipe, const Base_vect& triad_i,
1094 int index_sym1, int index_sym2) ;
1095
1096 /** Constructor for a valence 3 symmetric tensor.
1097 *
1098 * @param map the mapping
1099 * @param tipe0 type (\c COV or \c CON ) of the first index.
1100 * @param tipe1 type (\c COV or \c CON ) of the second index.
1101 * @param tipe2 type (\c COV or \c CON ) of the third index.
1102 * @param triad_i vectorial basis (triad) with respect to which
1103 * the tensor components are defined.
1104 * @param index_sym1 number of the first symmetric index
1105 * (\c 0<= \c index_sym1 \c <=2 )
1106 * @param index_sym2 number of the second symmetric index
1107 * (\c index_sym1 < \c index_sym2 \c <=2 )
1108 */
1109 Tensor_sym(const Map& map, int tipe0, int tipe1, int tipe2,
1110 const Base_vect& triad_i,
1111 int index_sym1, int index_sym2) ;
1112
1113 Tensor_sym(const Tensor_sym& a) ; ///< Copy constructor
1114
1115 /** Constructor from a file (see \c sauve(FILE*) ).
1116 *
1117 * @param map the mapping
1118 * @param triad_i vectorial basis (triad) with respect to which
1119 * the tensor components are defined. It will
1120 * be checked that it coincides with the basis
1121 * saved in the file.
1122 * @param fich file which has been created by
1123 * the function \c sauve(FILE*).
1124 */
1125 Tensor_sym(const Map& map, const Base_vect& triad_i, FILE* fich) ;
1126
1127 public:
1128
1129 virtual ~Tensor_sym() ; ///< Destructor
1130
1131 // Mutators / assignment
1132 // ---------------------
1133 public:
1134
1135 /// Assignment to another \c Tensor_sym
1136 virtual void operator=(const Tensor_sym& a) ;
1137
1138 /** Assignment to a \c Tensor
1139 * NB: the symmetry about the indices \c id_sym1 and
1140 * \c id_sym2 of the input tensor is assumed but is not checked
1141 */
1142 virtual void operator=(const Tensor& a) ;
1143
1144
1145 // Accessors
1146 // ---------
1147 public:
1148 /// Number of the first symmetric index (\c 0<= \c id_sym1 < \c valence )
1149 int sym_index1() const {return id_sym1;} ;
1150
1151 /** Number of the second symmetric index
1152 * (\c id_sym1 < \c id_sym2 < \c valence )
1153 */
1154 int sym_index2() const {return id_sym2;} ;
1155
1156 /**
1157 * Returns the position in the array \c cmp of a
1158 * component given by its indices.
1159 *
1160 * @param ind [input] 1-D array of integers (class \c Itbl )
1161 * of size \c valence giving the
1162 * values of each index specifing the component, with the
1163 * following storage convention:
1164 * \li \c ind(0) : value of the first index (1, 2 or 3)
1165 * \li \c ind(1) : value of the second index (1, 2 or 3)
1166 * \li and so on...
1167 *
1168 * @return position in the array \c cmp of the pointer to the
1169 * \c Scalar containing the component specified by \c ind
1170 */
1171 virtual int position(const Itbl& ind) const ;
1172
1173 /**
1174 * Returns the indices of a component given by its position in the
1175 * array \c cmp .
1176 *
1177 * @param pos [input] position in the array \c cmp
1178 * of the pointer to the \c Scalar representing a component
1179 *
1180 * @return 1-D array of integers (class \c Itbl ) of
1181 * size \c valence giving the value of each index
1182 * for the component located at the position \c pos in
1183 * the array \c cmp, with the
1184 * following storage convention:
1185 * \li \c Itbl(0) : value of the first index (1, 2 or 3)
1186 * \li \c Itbl(1) : value of the second index (1, 2 or 3)
1187 * \li and so on...
1188 */
1189 virtual Itbl indices(int pos) const ;
1190
1191
1192 // Outputs
1193 // -------
1194 public:
1195 virtual void sauve(FILE *) const ; ///< Save in a binary file
1196
1197
1198 // Tensor calculus
1199 // ---------------
1200 public:
1201
1202 /** Returns the covariant derivative of \c this with respect to some
1203 * metric \f$\gamma\f$.
1204 * \f$T\f$ denoting the tensor represented by \c this and
1205 * \f$\nabla T\f$ its covariant derivative with respect to
1206 * the metric \f$\gamma\f$,
1207 * the extra index (with respect to the indices of \f$T\f$)
1208 * of \f$\nabla T\f$ is chosen to be the \b last one.
1209 * This convention agrees with that of MTW (see Eq. (10.17) of MTW).
1210 *
1211 * @param gam metric \f$\gamma\f$
1212 * @return covariant derivative \f$\nabla T\f$ of \c this with
1213 * respect to the connection \f$\nabla\f$ associated with the
1214 * metric \f$\gamma\f$
1215 */
1216 const Tensor_sym& derive_cov(const Metric& gam) const ;
1217
1218 /** Returns the "contravariant" derivative of \c this with respect
1219 * to some metric \f$\gamma\f$, by raising the last index of the
1220 * covariant derivative (cf. method \c derive_cov() ) with
1221 * \f$\gamma\f$.
1222 */
1223 const Tensor_sym& derive_con(const Metric& gam) const ;
1224
1225 /** Computes the Lie derivative of \c this with respect to some
1226 * vector field \c v
1227 */
1228 Tensor_sym derive_lie(const Vector& v) const ;
1229
1230
1231 // Mathematical operators
1232 // ----------------------
1233
1234 friend Tensor_sym operator*(const Tensor&, const Tensor_sym&) ;
1235 friend Tensor_sym operator*(const Tensor_sym&, const Tensor&) ;
1236
1237 };
1238
1239
1240
1241 /**
1242 * \defgroup tenso_cal Tensor calculus
1243 * \ingroup (tensor)
1244 * @{
1245 */
1246
1247 /// Tensorial product
1248 Tensor operator*(const Tensor& a, const Tensor& b) ;
1249
1250 /// Tensorial product with symmetries
1251 Tensor_sym operator*(const Tensor& a, const Tensor_sym& b) ;
1252
1253 /// Tensorial product with symmetries
1254 Tensor_sym operator*(const Tensor_sym& a, const Tensor& b) ;
1255
1256 /** Tensorial product of two symmetric tensors.
1257 * NB: the output is an object of class \c Tensor_sym , with
1258 * the two symmetric indices corresponding to the symmetric indices
1259 * of tensor \c a . This means that the symmetries of tensor
1260 * \c b indices are not used in the storage, since
1261 * there is currently no class in Lorene to manage
1262 * tensors with more than two symmetric indices.
1263 */
1264 Tensor_sym operator*(const Tensor_sym& a, const Tensor_sym& b) ;
1265
1266
1267 /** Contraction of two tensors.
1268 *
1269 * @param t1 [input] first tensor
1270 * @param ind1 [input] index of the first tensor for the contraction,
1271 * obeying to the following convention :
1272 * \li \c ind1 = 0 : first index of the tensor
1273 * \li \c ind1 = 1 : second index of the tensor
1274 * \li and so on...
1275 * (\c ind1 must thus be in the range 0...t1.valence-1)
1276 * @param t2 [input] second tensor
1277 * @param ind2 [input] index of the second tensor for the contraction, with
1278 * the same convention as \c ind1
1279 * @param desaliasing [input] determines whether the products are performed
1280 * with desaliasing or not
1281 * @return tensor resulting of the contraction of the index \c ind1 of
1282 * \c t1 with the index \c ind2 of \c t2 .
1283 * NB: the types (\c COV or \c CON ) of the indices \c ind1 and
1284 * \c ind2 must be different.
1285 */
1286 Tensor contract(const Tensor& t1, int ind1, const Tensor& t2, int ind2,
1287 bool desaliasing = false) ;
1288
1289 /** Double contraction of two tensors.
1290 *
1291 * @param t1 [input] first tensor
1292 * @param ind_i1 [input] position of the first index \e i1 in the first
1293 * tensor for the contraction,
1294 * obeying to the following convention :
1295 * \li \c ind_i1 = 0 : first index of the tensor
1296 * \li \c ind_i1 = 1 : second index of the tensor
1297 * \li and so on...
1298 * (\c ind_i1 must thus be in the range 0...t1.valence-1)
1299 * @param ind_j1 [input] position of the second index \e j1 in the first
1300 * tensor for the contraction; one must have \c ind_i1 < \c ind_ j1
1301 * @param t2 [input] second tensor
1302 * @param ind_i2 [input] position of the first index \e i2 in the second
1303 * tensor for the contraction
1304 * @param ind_j2 [input] position of the second index \e j2 in the second
1305 * tensor for the contraction; one must have \c ind_i2 < \c ind_ j2
1306 * @param desaliasing [input] determines whether the products are performed
1307 * with desaliasing or not
1308 * @return tensor resulting of the contraction of the index \c ind_i1
1309 * of \c t1 with the index \c ind_i2 of \c t2 and of the
1310 * contraction of the index \c ind_j1
1311 * of \c t1 with the index \c ind_j2 of \c t2
1312 * NB: the types (\c COV or \c CON ) of the indices \c ind_i1 and
1313 * \c ind_i2 (resp. \c ind_j1 and \c ind_j2 ) must be different.
1314 */
1315 Tensor contract(const Tensor& t1, int ind_i1, int ind_j1,
1316 const Tensor& t2, int ind_i2, int ind_j2,
1317 bool desaliasing = false) ;
1318
1319
1320 /** Contraction on two indices of a single tensor (trace).
1321 *
1322 * @param t1 [input] tensor
1323 * @param ind1 [input] first index of the tensor for the contraction,
1324 * obeying to the following convention :
1325 * \li \c ind1 = 0 : first index of the tensor
1326 * \li \c ind1 = 1 : second index of the tensor
1327 * \li and so on...
1328 * (\c ind1 must thus be in the range 0...t1.valence-1)
1329 * @param ind2 [input] second index of the tensor for the contraction, with
1330 * the same convention as \c ind1
1331 * @return tensor resulting of the contraction
1332 * NB: the types (\c COV or \c CON ) of the indices \c ind1 and
1333 * \c ind2 must be different.
1334 */
1335 Tensor contract(const Tensor& t1, int ind1, int ind2) ;
1336
1337
1338 /** Maxima in each domain of the values of the tensor components
1339 * @param aa tensor
1340 * @param comment comment to be printed on \c ost before the result
1341 * (default: 0x0 = nothing printed)
1342 * @param ost output stream for a formatted output of the result
1343 * @return 2-D \c Tbl of size the number of independent components
1344 * times the number of domains, the elements \c (i,l)
1345 * of which are \c max(a(l)) , where \c a(l)
1346 * denotes symbolically the values of \c aa
1347 * in domain no. \c l and for component no.\c i .
1348 */
1349 Tbl max(const Tensor& aa, const char* comment = 0x0, ostream& ost = cout) ;
1350
1351
1352 /** Minima in each domain of the values of the tensor components
1353 * @param aa tensor
1354 * @param comment comment to be printed on \c ost before the result
1355 * (default: 0x0 = nothing printed)
1356 * @param ost output stream for a formatted output of the result
1357 * @return 2-D \c Tbl of size the number of independent components
1358 * times the number of domains, the elements \c (i,l)
1359 * of which are \c min(a(l)), where \c a(l)
1360 * denotes symbolically the values of \c aa
1361 * in domain no. \c l and for component no.\c i .
1362 */
1363 Tbl min(const Tensor& aa, const char* comment = 0x0, ostream& ost = cout) ;
1364
1365 /** Maxima in each domain of the absolute values of the tensor components
1366 * @param aa tensor
1367 * @param comment comment to be printed on \c ost before the result
1368 * (default: 0x0 = nothing printed)
1369 * @param ost output stream for a formatted output of the result
1370 * @return 2-D \c Tbl of size the number of independent components
1371 * times the number of domains, the elements \c (i,l)
1372 * of which are \c max[abs(a(l))] , where \c a(l)
1373 * denotes symbolically the values of \c aa
1374 * in domain no. \c l and for component no.\c i .
1375 */
1376 Tbl maxabs(const Tensor& aa, const char* comment = 0x0, ostream& ost = cout,
1377 bool verb = true) ;
1378
1379
1380 /** Relative difference between two \c Tensor (\f$L^1\f$ version).
1381 * @param aa first tensor
1382 * @param bb second tensor
1383 * @param comment comment to be printed on \c ost before the result
1384 * (default: 0x0 = nothing printed)
1385 * @param ost output stream for a formatted output of the result
1386 * @return 2-D \c Tbl of size the number of independent components
1387 * times the number of domains, the elements \c (i,l)
1388 * of which
1389 * are \c norme[a(l)-b(l)]/norme[b(l)] if \c b(l)!=0 and
1390 * \c norme[a(l)-b(l)] if \c b(l)=0 , where \c a(l) and
1391 * \c b(l) denote symbolically the values of \c aa and \c bb
1392 * in domain no. \c l and for component no.\c i .
1393 */
1394 Tbl diffrel(const Tensor& aa, const Tensor& bb, const char* comment = 0x0,
1395 ostream& ost = cout) ;
1396
1397 /** Relative difference between two \c Tensor (max version).
1398 * @param aa first tensor
1399 * @param bb second tensor
1400 * @param comment comment to be printed on \c ost before the result
1401 * (default: 0x0 = nothing printed)
1402 * @param ost output stream for a formatted output of the result
1403 * @return 2-D \c Tbl of size the number of independent components
1404 * times the number of domains, the elements \c (i,l)
1405 * of which
1406 * are \c max[abs(a(l)-b(l))]/max[abs(b(l))] if \c b(l)!=0 and
1407 * \c max[abs(a(l)-b(l))] if \c b(l)=0 , where \c a(l) and
1408 * \c b(l) denote symbolically the values of \c aa and \c bb
1409 * in domain no. \c l and for component no.\c i .
1410 */
1411 Tbl diffrelmax(const Tensor& aa, const Tensor& bb, const char* comment = 0x0,
1412 ostream& ost = cout) ;
1413
1414 /** Central value of each component of a tensor.
1415 * @param aa tensor
1416 * @param comment comment to be printed on \c ost
1417 * (default: 0x0 = nothing printed)
1418 * @param ost output stream for a formatted output of the result; used
1419 * only if \c comment != \c 0x0.
1420 * @return 1-D \c Tbl of size the number of independent components
1421 * (\c aa.get_ncomp()), the elements of which are the central values
1422 * of the various components.
1423 */
1424 Tbl central_value(const Tensor& aa, const char* comment = 0x0, ostream& ost = cout) ;
1425
1426 /** Maximum value of each component of a tensor over all the domains.
1427 * @param aa tensor
1428 * @param l_excluded index of domain to be excluded from the computation:
1429 * the default = -1 corresponds to no excluded domain
1430 * @param comment comment to be printed on \c ost
1431 * (default: 0x0 = nothing printed)
1432 * @param ost output stream for a formatted output of the result; used
1433 * only if \c comment != \c 0x0.
1434 * @return 1-D \c Tbl of size the number of independent components
1435 * (\c aa.get_ncomp()), the elements of which are the maximum values
1436 * of the various components.
1437 */
1438 Tbl max_all_domains(const Tensor& aa, int l_excluded = -1, const char* comment = 0x0,
1439 ostream& ost = cout) ;
1440
1441
1442 /** Minimum value of each component of a tensor over all the domains.
1443 * @param aa tensor
1444 * @param l_excluded index of domain to be excluded from the computation:
1445 * the default = -1 corresponds to no excluded domain
1446 * @param comment comment to be printed on \c ost
1447 * (default: 0x0 = nothing printed)
1448 * @param ost output stream for a formatted output of the result; used
1449 * only if \c comment != \c 0x0.
1450 * @return 1-D \c Tbl of size the number of independent components
1451 * (\c aa.get_ncomp()), the elements of which are the minimum values
1452 * of the various components.
1453 */
1454 Tbl min_all_domains(const Tensor& aa, int l_excluded = -1, const char* comment = 0x0,
1455 ostream& ost = cout) ;
1456
1457 /** Maximum of the absolute value of each component of a tensor over all the domains.
1458 * @param aa tensor
1459 * @param l_excluded index of domain to be excluded from the computation:
1460 * the default = -1 corresponds to no excluded domain
1461 * @param comment comment to be printed on \c ost
1462 * (default: 0x0 = nothing printed)
1463 * @param ost output stream for a formatted output of the result; used
1464 * only if \c comment != \c 0x0.
1465 * @return 1-D \c Tbl of size the number of independent components
1466 * (\c aa.get_ncomp()), the elements of which are the maximum of of the
1467 * absolute value of the various components.
1468 */
1469 Tbl maxabs_all_domains(const Tensor& aa, int l_excluded = -1, const char* comment = 0x0,
1470 ostream& ost = cout, bool verb = true) ;
1471
1472
1473
1474 /** @} */
1475
1476
1477 /**
1478 * \defgroup tens_ari Tensor arithmetics
1479 * \ingroup (tensor)
1480 * @{
1481 */
1482
1483 Tensor operator+(const Tensor& ) ; ///< + Tensor
1484 Tensor operator-(const Tensor& ) ; ///< \c - Tensor
1485 Tensor operator+(const Tensor& a, const Tensor& b) ; ///< Tensor + Tensor
1486
1487 /// Tensor + Scalar. The \c Tensor must be of valence 0.
1488 Scalar operator+(const Tensor& a, const Scalar& b) ;
1489
1490 /// Scalar + Tensor. The \c Tensor must be of valence 0.
1491 Scalar operator+(const Scalar& a, const Tensor& b) ;
1492
1493 Tensor operator-(const Tensor& a, const Tensor& b) ; ///< Tensor - Tensor
1494
1495 /// Tensor - Scalar. The \c Tensor must be of valence 0.
1496 Scalar operator-(const Tensor& a, const Scalar& b) ;
1497
1498 /// Scalar - Tensor. The \c Tensor must be of valence 0.
1499 Scalar operator-(const Scalar& a, const Tensor& b) ;
1500
1501 Tensor operator*(const Scalar& a , const Tensor& b) ; ///< Scalar * Tensor
1502 Tensor operator*(const Tensor& a, const Scalar& b) ; ///< Tensor * Scalar
1503 Tensor operator*(double , const Tensor&) ; ///< double * Tensor
1504 Tensor operator* (const Tensor&, double) ; ///< Tensor * double
1505 Tensor operator*(int, const Tensor &) ; ///< int* Tensor
1506 Tensor operator*(const Tensor&, int) ; ///< Tensor * int
1507 Tensor operator/(const Tensor&, const Scalar&) ; ///< Tensor / Scalar
1508 Tensor operator/(const Tensor&, double) ; ///< Tensor / double
1509 Tensor operator/(const Tensor&, int) ; ///< Tensor / int
1510
1511 //@}
1512
1513 /**
1514 * @name Tensor_sym arithmetics
1515 */
1516 //@{
1517 /** + Tensor_sym. For efficiency reasons this function is
1518 * distinct from \c Tensor \c operator+(const Tensor\& ) .
1519 */
1520 Tensor_sym operator+(const Tensor_sym&) ;
1521
1522 /** - Tensor_sym. For efficiency reasons this function is
1523 * distinct from \c Tensor \c operator+(const Tensor\& ).
1524 */
1525 Tensor_sym operator-(const Tensor_sym&) ;
1526
1527 /** Tensor_sym + Tensor_sym. For efficiency reasons this function is
1528 * distinct
1529 * from \c Tensor \c operator+(const Tensor\&, const Tensor\& ).
1530 */
1531 Tensor_sym operator+(const Tensor_sym&, const Tensor_sym&) ;
1532
1533 /** Tensor_sym - Tensor_sym. For efficiency reasons this function is
1534 * distinct
1535 * from \c Tensor \c operator-(const Tensor\&, const Tensor\&) .
1536 */
1537 Tensor_sym operator-(const Tensor_sym&, const Tensor_sym&) ;
1538
1539 /** Scalar * Tensor_sym. For efficiency reasons this function is distinct
1540 * from \c Tensor \c operator*(const Scalar\&, const Tensor\&) .
1541 */
1542 Tensor_sym operator*(const Scalar& a, const Tensor_sym& b) ;
1543
1544 /** Tensor_sym * Scalar. For efficiency reasons this function is distinct
1545 * from \c Tensor \c operator*(const Tensor\&, const Scalar\&) .
1546 */
1547 Tensor_sym operator*(const Tensor_sym& a, const Scalar& b) ;
1548
1549 /** double * Tensor_sym. For efficiency reasons this function is distinct
1550 * from \c Tensor \c operator*(double, const Tensor\&) .
1551 */
1552 Tensor_sym operator*(double, const Tensor_sym&) ;
1553
1554 /** Tensor_sym * double. For efficiency reasons this function is distinct
1555 * from \c Tensor \c operator*(const Tensor\&, double) .
1556 */
1557 Tensor_sym operator*(const Tensor_sym&, double) ;
1558
1559 /** int * Tensor_sym. For efficiency reasons this function is distinct
1560 * from \c Tensor \c operator*(int, const Tensor\&) .
1561 */
1562 Tensor_sym operator*(int, const Tensor_sym&) ;
1563
1564 /** Tensor_sym * int. For efficiency reasons this function is distinct
1565 * from \c Tensor \c operator*(const Tensor\&, int) .
1566 */
1567 Tensor_sym operator*(const Tensor_sym&, int) ;
1568
1569 /** Tensor_sym / Scalar. For efficiency reasons this function is distinct
1570 * from \c Tensor \c operator/(const Tensor\&, const Scalar\&) .
1571 */
1572 Tensor_sym operator/(const Tensor_sym&, const Scalar&) ;
1573
1574 /** Tensor_sym / double. For efficiency reasons this function is distinct
1575 * from \c Tensor \c operator/(const Tensor\&, double) .
1576 */
1577 Tensor_sym operator/(const Tensor_sym&, double) ;
1578
1579 /** Tensor_sym / int. For efficiency reasons this function is distinct
1580 * from \c Tensor \c operator/(const Tensor\&, int) .
1581 */
1582 Tensor_sym operator/(const Tensor_sym&, int) ;
1583
1584 /** @} */
1585
1586 }
1587 #include "scalar.h"
1588
1589 #include "vector.h"
1590
1591 #include "sym_tensor.h"
1592
1593
1594 #endif