tensor_sym_calculus.C
/*
* Tensor calculus for class Tensor_sym
*
*
*/
/*
* Copyright (c) 2004 Eric Gourgoulhon & Jerome Novak
*
* Copyright (c) 1999-2001 Philippe Grandclement (for preceding class Tenseur)
*
* This file is part of LORENE.
*
* LORENE is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* LORENE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LORENE; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
char tensor_sym_calculus_C[] = "$Header: /cvsroot/Lorene/C++/Source/Tensor/tensor_sym_calculus.C,v 1.5 2014/10/13 08:53:44 j_novak Exp $" ;
/*
* $Id: tensor_sym_calculus.C,v 1.5 2014/10/13 08:53:44 j_novak Exp $
* $Log: tensor_sym_calculus.C,v $
* Revision 1.5 2014/10/13 08:53:44 j_novak
* Lorene classes and functions now belong to the namespace Lorene.
*
* Revision 1.4 2014/10/06 15:13:20 j_novak
* Modified #include directives to use c++ syntax.
*
* Revision 1.3 2004/02/26 22:50:33 e_gourgoulhon
* Added methods derive_cov, derive_con and derive_lie.
*
* Revision 1.2 2004/01/30 12:44:53 e_gourgoulhon
* Added Tensor_sym operator*(const Tensor_sym&, const Tensor_sym& ).
*
* Revision 1.1 2004/01/08 09:22:40 e_gourgoulhon
* First version.
*
*
* $Header: /cvsroot/Lorene/C++/Source/Tensor/tensor_sym_calculus.C,v 1.5 2014/10/13 08:53:44 j_novak Exp $
*
*/
// Headers C
#include <cstdlib>
#include <cassert>
#include <cmath>
// Headers Lorene
#include "tensor.h"
// Tensorial product
//------------------
namespace Lorene {
Tensor_sym operator*(const Tensor_sym& t1, const Tensor& t2) {
assert (t1.mp == t2.mp) ;
int val_res = t1.valence + t2.valence ;
Itbl tipe(val_res) ;
for (int i=0 ; i<t1.valence ; i++)
tipe.set(i) = t1.type_indice(i) ;
for (int i=0 ; i<t2.valence ; i++)
tipe.set(i+t1.valence) = t2.type_indice(i) ;
const Base_vect* triad_res = t1.get_triad() ;
if ( t2.valence != 0 ) {
assert ( *(t2.get_triad()) == *triad_res ) ;
}
Tensor_sym res(*t1.mp, val_res, tipe, *triad_res, t1.sym_index1(),
t1.sym_index2()) ;
Itbl jeux_indice_t1(t1.valence) ;
Itbl jeux_indice_t2(t2.valence) ;
for (int i=0 ; i<res.n_comp ; i++) {
Itbl jeux_indice_res(res.indices(i)) ;
for (int j=0 ; j<t1.valence ; j++)
jeux_indice_t1.set(j) = jeux_indice_res(j) ;
for (int j=0 ; j<t2.valence ; j++)
jeux_indice_t2.set(j) = jeux_indice_res(j+t1.valence) ;
res.set(jeux_indice_res) = t1(jeux_indice_t1)*t2(jeux_indice_t2) ;
}
return res ;
}
Tensor_sym operator*(const Tensor& t1, const Tensor_sym& t2) {
assert (t1.mp == t2.mp) ;
int val_res = t1.valence + t2.valence ;
Itbl tipe(val_res) ;
for (int i=0 ; i<t1.valence ; i++)
tipe.set(i) = t1.type_indice(i) ;
for (int i=0 ; i<t2.valence ; i++)
tipe.set(i+t1.valence) = t2.type_indice(i) ;
const Base_vect* triad_res = t2.get_triad() ;
if ( t1.valence != 0 ) {
assert ( *(t1.get_triad()) == *triad_res ) ;
}
int ids1 = t2.sym_index1() + t1.valence ; // symmetry index 1 of the result
int ids2 = t2.sym_index2() + t1.valence ; // symmetry index 2 of the result
Tensor_sym res(*t2.mp, val_res, tipe, *triad_res, ids1, ids2) ;
Itbl jeux_indice_t1(t1.valence) ;
Itbl jeux_indice_t2(t2.valence) ;
for (int i=0 ; i<res.n_comp ; i++) {
Itbl jeux_indice_res(res.indices(i)) ;
for (int j=0 ; j<t1.valence ; j++)
jeux_indice_t1.set(j) = jeux_indice_res(j) ;
for (int j=0 ; j<t2.valence ; j++)
jeux_indice_t2.set(j) = jeux_indice_res(j+t1.valence) ;
res.set(jeux_indice_res) = t1(jeux_indice_t1)*t2(jeux_indice_t2) ;
}
return res ;
}
Tensor_sym operator*(const Tensor_sym& t1, const Tensor_sym& t2) {
assert (t1.mp == t2.mp) ;
int val_res = t1.valence + t2.valence ;
Itbl tipe(val_res) ;
for (int i=0 ; i<t1.valence ; i++)
tipe.set(i) = t1.type_indice(i) ;
for (int i=0 ; i<t2.valence ; i++)
tipe.set(i+t1.valence) = t2.type_indice(i) ;
const Base_vect* triad_res = t1.get_triad() ;
assert ( *(t2.get_triad()) == *triad_res ) ;
Tensor_sym res(*t1.mp, val_res, tipe, *triad_res, t1.sym_index1(),
t1.sym_index2()) ;
Itbl jeux_indice_t1(t1.valence) ;
Itbl jeux_indice_t2(t2.valence) ;
for (int i=0 ; i<res.n_comp ; i++) {
Itbl jeux_indice_res(res.indices(i)) ;
for (int j=0 ; j<t1.valence ; j++)
jeux_indice_t1.set(j) = jeux_indice_res(j) ;
for (int j=0 ; j<t2.valence ; j++)
jeux_indice_t2.set(j) = jeux_indice_res(j+t1.valence) ;
res.set(jeux_indice_res) = t1(jeux_indice_t1)*t2(jeux_indice_t2) ;
}
return res ;
}
//--------------------------//
// Covariant derivatives //
//--------------------------//
const Tensor_sym& Tensor_sym::derive_cov(const Metric& gam) const {
const Tensor_sym* p_resu =
dynamic_cast<const Tensor_sym*>( &(Tensor::derive_cov(gam)) ) ;
assert(p_resu != 0x0) ;
return *p_resu ;
}
const Tensor_sym& Tensor_sym::derive_con(const Metric& gam) const {
const Tensor_sym* p_resu =
dynamic_cast<const Tensor_sym*>( &(Tensor::derive_con(gam)) ) ;
assert(p_resu != 0x0) ;
return *p_resu ;
}
//--------------------------//
// Lie derivative //
//--------------------------//
Tensor_sym Tensor_sym::derive_lie(const Vector& vv) const {
Tensor_sym resu(*mp, valence, type_indice, *triad, id_sym1, id_sym2) ;
compute_derive_lie(vv, resu) ;
return resu ;
}
}
Lorene::Base_vect
Vectorial bases (triads) with respect to which the tensorial components are defined.
Definition base_vect.h:105
Lorene::Itbl
Basic integer array class.
Definition itbl.h:122
Lorene::Itbl::set
int & set(int i)
Read/write of a particular element (index i ) (1D case).
Definition itbl.h:247
Lorene::operator*
Base_val operator*(const Base_val &, const Base_val &)
This operator is used when calling multiplication or division of Valeur .
Definition base_val_mult.C:102
Lorene::Tensor_sym::derive_lie
Tensor_sym derive_lie(const Vector &v) const
Computes the Lie derivative of this with respect to some vector field v.
Definition tensor_sym_calculus.C:219
Lorene::Tensor_sym::sym_index1
int sym_index1() const
Number of the first symmetric index (0<= id_sym1 < valence ).
Definition tensor.h:1149
Lorene::Tensor_sym::derive_cov
const Tensor_sym & derive_cov(const Metric &gam) const
Returns the covariant derivative of this with respect to some metric .
Definition tensor_sym_calculus.C:192
Lorene::Tensor::mp
const Map *const mp
Mapping on which the numerical values at the grid points are defined.
Definition tensor.h:295
Lorene::Tensor_sym::indices
virtual Itbl indices(int pos) const
Returns the indices of a component given by its position in the array cmp .
Definition tensor_sym.C:310
Lorene::Tensor_sym::sym_index2
int sym_index2() const
Number of the second symmetric index (id_sym1 < id_sym2 < valence ).
Definition tensor.h:1154
Lorene::Tensor::derive_con
const Tensor & derive_con(const Metric &gam) const
Returns the "contravariant" derivative of this with respect to some metric , by raising the last inde...
Definition tensor.C:1014
Lorene::Tensor_sym::id_sym1
int id_sym1
Number of the first symmetric index (0<= id_sym1 < valence ).
Definition tensor.h:1044
Lorene::Tensor::Tensor
Tensor(const Map &map, int val, const Itbl &tipe, const Base_vect &triad_i)
Standard constructor.
Definition tensor.C:202
Lorene::Tensor::valence
int valence
Valence of the tensor (0 = scalar, 1 = vector, etc...).
Definition tensor.h:298
Lorene::Tensor_sym::Tensor_sym
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:69
Lorene::Tensor_sym::id_sym2
int id_sym2
Number of the second symmetric index (id_sym1 < id_sym2 < valence ).
Definition tensor.h:1049
Lorene::Tensor::compute_derive_lie
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...
Definition tensor_calculus.C:339
Lorene::Tensor::get_triad
const Base_vect * get_triad() const
Returns the vectorial basis (triad) on which the components are defined.
Definition tensor.h:866
Lorene::Tensor::n_comp
int n_comp
Number of stored components, depending on the symmetry.
Definition tensor.h:312
Lorene::Tensor_sym::derive_con
const Tensor_sym & derive_con(const Metric &gam) const
Returns the "contravariant" derivative of this with respect to some metric , by raising the last inde...
Definition tensor_sym_calculus.C:204
Lorene::Tensor::derive_cov
const Tensor & derive_cov(const Metric &gam) const
Returns the covariant derivative of this with respect to some metric .
Definition tensor.C:1002
Lorene::Tensor::type_indice
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:310
Lorene::Tensor::set
Scalar & set(const Itbl &ind)
Returns the value of a component (read/write version).
Definition tensor.C:654
Lorene::Tensor::triad
const Base_vect * triad
Vectorial basis (triad) with respect to which the tensor components are defined.
Definition tensor.h:303
Lorene
Lorene prototypes.
Definition app_hor.h:64