tenseur_sym_operateur.C
/*
* Copyright (c) 1999-2001 Philippe Grandclement
* Copyright (c) 1999-2001 Eric Gourgoulhon
* Copyright (c) 2002 Jerome Novak
*
* 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 tenseur_sym_operateur_C[] = "$Header: /cvsroot/Lorene/C++/Source/Tenseur/tenseur_sym_operateur.C,v 1.8 2014/10/13 08:53:43 j_novak Exp $" ;
/*
* $Id: tenseur_sym_operateur.C,v 1.8 2014/10/13 08:53:43 j_novak Exp $
* $Log: tenseur_sym_operateur.C,v $
* Revision 1.8 2014/10/13 08:53:43 j_novak
* Lorene classes and functions now belong to the namespace Lorene.
*
* Revision 1.7 2014/10/06 15:13:19 j_novak
* Modified #include directives to use c++ syntax.
*
* Revision 1.6 2003/03/03 19:41:34 f_limousin
* Suppression of an assert on a metric associated with a tensor.
*
* Revision 1.5 2002/10/16 14:37:15 j_novak
* Reorganization of #include instructions of standard C++, in order to
* use experimental version 3 of gcc.
*
* Revision 1.4 2002/09/10 13:44:17 j_novak
* The method "manipule" of one indice has been removed for Tenseur_sym objects
* (the result cannot be a Tenseur_sym).
* The method "sans_trace" now computes the traceless part of a Tenseur (or
* Tenseur_sym) of valence 2.
*
* Revision 1.3 2002/09/06 14:49:26 j_novak
* Added method lie_derive for Tenseur and Tenseur_sym.
* Corrected various errors for derive_cov and arithmetic.
*
* Revision 1.2 2002/08/07 16:14:12 j_novak
* class Tenseur can now also handle tensor densities, this should be transparent to older codes
*
* Revision 1.1.1.1 2001/11/20 15:19:30 e_gourgoulhon
* LORENE
*
* Revision 2.2 2000/02/09 19:32:22 eric
* MODIF IMPORTANTE: la triade de decomposition est desormais passee en
* argument des constructeurs.
*
* Revision 2.1 2000/01/11 11:15:08 eric
* Gestion de la base vectorielle (triad).
*
* Revision 2.0 1999/12/02 17:19:02 phil
* *** empty log message ***
*
*
* $Header: /cvsroot/Lorene/C++/Source/Tenseur/tenseur_sym_operateur.C,v 1.8 2014/10/13 08:53:43 j_novak Exp $
*
*/
// Headers C
#include <cstdlib>
#include <cassert>
#include <cmath>
// Headers Lorene
#include "tenseur.h"
#include "metrique.h"
namespace Lorene {
Tenseur_sym operator*(const Tenseur& t1, const Tenseur_sym& t2) {
assert ((t1.get_etat() != ETATNONDEF) && (t2.etat != ETATNONDEF)) ;
assert (t1.get_mp() == t2.mp) ;
int val_res = t1.get_valence() + t2.valence ;
double poids_res = t1.get_poids() + t2.poids ;
poids_res = (fabs(poids_res) < 1.e-10 ? 0. : poids_res) ;
const Metrique* met_res = 0x0 ;
if (poids_res != 0.) {
// assert((t1.get_metric() != 0x0) || (t2.metric != 0x0)) ;
if (t1.get_metric() != 0x0) met_res = t1.get_metric() ;
else met_res = t2.metric ;
}
Itbl tipe (val_res) ;
tipe.set_etat_qcq() ;
for (int i=0 ; i<t1.get_valence() ; i++)
tipe.set(i) = t1.get_type_indice(i) ;
for (int i=0 ; i<t2.valence ; i++)
tipe.set(i+t1.get_valence()) = t2.type_indice(i) ;
if ( t1.get_valence() != 0 ) {
assert ( *(t1.get_triad()) == *(t2.get_triad()) ) ;
}
Tenseur_sym res(*t1.get_mp(), val_res, tipe, *(t2.get_triad()),
met_res, poids_res) ;
if ((t1.get_etat() == ETATZERO) || (t2.etat == ETATZERO))
res.set_etat_zero() ;
else {
res.set_etat_qcq() ;
Itbl jeux_indice_t1 (t1.get_valence()) ;
jeux_indice_t1.set_etat_qcq() ;
Itbl jeux_indice_t2 (t2.valence) ;
jeux_indice_t2.set_etat_qcq() ;
for (int i=0 ; i<res.n_comp ; i++) {
Itbl jeux_indice_res(res.donne_indices(i)) ;
for (int j=0 ; j<t1.get_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.get_valence()) ;
res.set(jeux_indice_res) = t1(jeux_indice_t1)*t2(jeux_indice_t2) ;
}
}
return res ;
}
Tenseur_sym manipule (const Tenseur_sym& t1, const Metrique& met) {
Tenseur* auxi ;
Tenseur* auxi_old = new Tenseur(t1) ;
for (int i=0 ; i<t1.valence ; i++) {
auxi = new Tenseur(manipule(*auxi_old, met, i)) ;
delete auxi_old ;
auxi_old = new Tenseur(*auxi) ;
delete auxi ;
}
Tenseur_sym result(*auxi_old) ;
delete auxi_old ;
return result ;
}
Tenseur_sym lie_derive (const Tenseur_sym& t, const Tenseur& x,
const Metrique* met)
{
assert ( (t.get_etat() != ETATNONDEF) && (x.get_etat() != ETATNONDEF) ) ;
assert(x.get_valence() == 1) ;
assert(x.get_type_indice(0) == CON) ;
assert(x.get_poids() == 0.) ;
assert(t.get_mp() == x.get_mp()) ;
int val = t.get_valence() ;
double poids = t.get_poids() ;
Itbl tipe (val+1) ;
tipe.set_etat_qcq() ;
tipe.set(0) = COV ;
Itbl tipx(2) ;
tipx.set_etat_qcq() ;
tipx.set(0) = COV ;
tipx.set(1) = CON ;
for (int i=0 ; i<val ; i++)
tipe.set(i+1) = t.get_type_indice(i) ;
Tenseur_sym dt(*t.get_mp(), val+1, tipe, *t.get_triad(), t.get_metric(),
poids) ;
Tenseur dx(*x.get_mp(), 2, tipx, x.get_triad()) ;
if (met == 0x0) {
dx = x.gradient() ;
dt = t.gradient() ;
}
else {
dx = x.derive_cov(*met) ;
dt = t.derive_cov(*met) ;
}
Tenseur_sym resu(contract(x,0,dt,0)) ;
Tenseur* auxi ;
if ((val!=0)&&(t.get_etat()!=ETATZERO)&&(x.get_etat()!=ETATZERO)) {
assert(t.get_triad()->identify() == x.get_triad()->identify()) ;
for (int i=0 ; i<val ; i++) {
if (t.get_type_indice(i) == COV) {
auxi = new Tenseur(contract(t,i,dx,1)) ;
Itbl indices_aux(val) ;
indices_aux.set_etat_qcq() ;
for (int j=0 ; j<resu.get_n_comp() ; j++) {
Itbl indices (resu.donne_indices(j)) ;
indices_aux.set(val-1) = indices(i) ;
for (int idx=0 ; idx<val-1 ; idx++)
if (idx<i)
indices_aux.set(idx) = indices(idx) ;
else
indices_aux.set(idx) = indices(idx+1) ;
resu.set(indices) += (*auxi)(indices_aux) ;
}
}
else {
auxi = new Tenseur(contract(t,i,dx,0)) ;
Itbl indices_aux(val) ;
indices_aux.set_etat_qcq() ;
//On range comme il faut :
for (int j=0 ; j<resu.get_n_comp() ; j++) {
Itbl indices (resu.donne_indices(j)) ;
indices_aux.set(val-1) = indices(i) ;
for (int idx=0 ; idx<val-1 ; idx++)
if (idx<i)
indices_aux.set(idx) = indices(idx) ;
else
indices_aux.set(idx) = indices(idx+1) ;
resu.set(indices) -= (*auxi)(indices_aux) ;
}
}
delete auxi ;
}
}
if ((poids != 0.)&&(t.get_etat()!=ETATZERO)&&(x.get_etat()!=ETATZERO))
resu = resu + poids*contract(dx,0,1)*t ;
return resu ;
}
Tenseur_sym sans_trace(const Tenseur_sym& t, const Metrique& metre)
{
assert(t.get_etat() != ETATNONDEF) ;
assert(metre.get_etat() != ETATNONDEF) ;
assert(t.get_valence() == 2) ;
Tenseur_sym resu(t) ;
if (resu.get_etat() == ETATZERO) return resu ;
assert(resu.get_etat() == ETATQCQ) ;
int t0 = t.get_type_indice(0) ;
int t1 = t.get_type_indice(1) ;
Itbl mix(2) ;
mix.set_etat_qcq() ;
mix.set(0) = (t0 == t1 ? -t0 : t0) ;
mix.set(1) = t1 ;
Tenseur tmp(*t.get_mp(), 2, mix, *t.get_triad(), t.get_metric(),
t.get_poids()) ;
if (t0 == t1)
tmp = manipule(t, metre, 0) ;
else
tmp = t ;
Tenseur trace(contract(tmp, 0, 1)) ;
if (t0 == t1) {
switch (t0) {
case COV : {
resu = resu - 1./3.*trace * metre.cov() ;
break ;
}
case CON : {
resu = resu - 1./3.*trace * metre.con() ;
break ;
}
default :
cout << "Erreur bizarre dans sans_trace!" << endl ;
abort() ;
break ;
}
}
else {
Tenseur_sym delta(*t.get_mp(), 2, mix, *t.get_triad(),
t.get_metric(), t.get_poids()) ;
delta.set_etat_qcq() ;
for (int i=0; i<3; i++)
for (int j=i; j<3; j++)
delta.set(i,j) = (i==j ? 1 : 0) ;
resu = resu - trace/3. * delta ;
}
resu.set_std_base() ;
return resu ;
}
}
Lorene::Base_vect::identify
virtual int identify() const =0
Returns a number to identify the sub-classe of Base_vect the object belongs to.
Lorene::Itbl
Basic integer array class.
Definition itbl.h:122
Lorene::Itbl::set_etat_qcq
void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
Definition itbl.C:261
Lorene::Itbl::set
int & set(int i)
Read/write of a particular element (index i ) (1D case).
Definition itbl.h:247
Lorene::Tenseur_sym
Class intended to describe tensors with a symmetry on the two last indices *** DEPRECATED : use class...
Definition tenseur.h:1253
Lorene::Tenseur_sym::Tenseur_sym
Tenseur_sym(const Map &map, int val, const Itbl &tipe, const Base_vect &triad_i, const Metrique *met=0x0, double weight=0)
Standard constructor.
Definition tenseur_sym.C:96
Lorene::Tenseur_sym::donne_indices
virtual Itbl donne_indices(int place) const
Returns the indices of a component given by its position in the Cmp 1-D array c .
Definition tenseur_sym.C:252
Lorene::Tenseur
Tensor handling *** DEPRECATED : use class Tensor instead ***.
Definition tenseur.h:301
Lorene::Tenseur::get_triad
const Base_vect * get_triad() const
Returns the vectorial basis (triad) on which the components are defined.
Definition tenseur.h:704
Lorene::Tenseur::set
Cmp & set()
Read/write for a scalar (see also operator=(const Cmp&) ).
Definition tenseur.C:824
Lorene::Tenseur::get_type_indice
int get_type_indice(int i) const
Returns the type of the index number i .
Definition tenseur.h:726
Lorene::Tenseur::metric
const Metrique * metric
For tensor densities: the metric defining the conformal factor.
Definition tenseur.h:325
Lorene::Tenseur::mp
const Map *const mp
Reference mapping.
Definition tenseur.h:306
Lorene::Tenseur::derive_cov
const Tenseur & derive_cov(const Metrique &met) const
Returns the covariant derivative of *this , with respect to met .
Definition tenseur.C:1554
Lorene::Tenseur::set_etat_qcq
void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
Definition tenseur.C:636
Lorene::Tenseur::Tenseur
Tenseur(const Map &map, const Metrique *met=0x0, double weight=0)
Constructor for a scalar field.
Definition tenseur.C:209
Lorene::Tenseur::get_mp
const Map * get_mp() const
Returns pointer on the mapping.
Definition tenseur.h:699
Lorene::Tenseur::get_poids
double get_poids() const
Returns the weight.
Definition tenseur.h:738
Lorene::Tenseur::gradient
const Tenseur & gradient() const
Returns the gradient of *this (Cartesian coordinates).
Definition tenseur.C:1542
Lorene::Tenseur::n_comp
int n_comp
Number of components, depending on the symmetry.
Definition tenseur.h:320
Lorene::Tenseur::set_std_base
void set_std_base()
Set the standard spectal basis of decomposition for each component.
Definition tenseur.C:1170
Lorene::Tenseur::set_etat_zero
void set_etat_zero()
Sets the logical state to ETATZERO (zero state).
Definition tenseur.C:645
Lorene::Tenseur::type_indice
Itbl type_indice
Array of size valence contening the type of each index, COV for a covariant one and CON for a contrav...
Definition tenseur.h:318
Lorene::Tenseur::valence
int valence
Valence.
Definition tenseur.h:307
Lorene::Tenseur::etat
int etat
Logical state ETATZERO , ETATQCQ or ETATNONDEF.
Definition tenseur.h:321
Lorene::Tenseur::poids
double poids
For tensor densities: the weight.
Definition tenseur.h:323
Lorene::Tenseur::get_valence
int get_valence() const
Returns the valence.
Definition tenseur.h:710
Lorene::Tenseur::get_metric
const Metrique * get_metric() const
Returns a pointer on the metric defining the conformal factor for tensor densities.
Definition tenseur.h:745
Lorene::Tenseur::get_n_comp
int get_n_comp() const
Returns the number of components.
Definition tenseur.h:713
Lorene::Tenseur::get_etat
int get_etat() const
Returns the logical state.
Definition tenseur.h:707
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::sans_trace
Tenseur sans_trace(const Tenseur &tens, const Metrique &metre)
Computes the traceless part of a Tenseur of valence 2.
Definition tenseur_operateur.C:897
Lorene::contract
Tenseur contract(const Tenseur &, int id1, int id2)
Self contraction of two indices of a Tenseur .
Definition tenseur_operateur.C:279
Lorene::lie_derive
Tenseur lie_derive(const Tenseur &t, const Tenseur &x, const Metrique *=0x0)
Lie Derivative of t with respect to x .
Definition tenseur_operateur.C:816
Lorene::manipule
Tenseur manipule(const Tenseur &, const Metrique &, int idx)
Raise or lower the index idx depending on its type, using the given Metrique .
Definition tenseur_operateur.C:509
Lorene
Lorene prototypes.
Definition app_hor.h:64
Lorene::x
Coord x
x coordinate centered on the grid
Definition map.h:726