connection_fcart.C
/*
* Methods of class Connection_fcart.
*
* (see file connection.h for documentation)
*
*/
/*
* Copyright (c) 2003-2004 Eric Gourgoulhon & 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 version 2
* as published by the Free Software Foundation.
*
* 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 connection_fcart_C[] = "$Header: /cvsroot/Lorene/C++/Source/Connection/connection_fcart.C,v 1.14 2014/10/13 08:52:50 j_novak Exp $" ;
/*
* $Id: connection_fcart.C,v 1.14 2014/10/13 08:52:50 j_novak Exp $
* $Log: connection_fcart.C,v $
* Revision 1.14 2014/10/13 08:52:50 j_novak
* Lorene classes and functions now belong to the namespace Lorene.
*
* Revision 1.13 2014/10/06 15:13:04 j_novak
* Modified #include directives to use c++ syntax.
*
* Revision 1.12 2004/01/28 13:25:40 j_novak
* The ced_mult_r arguments have been suppressed from the Scalar::*dsd* methods.
* In the div/mult _r_dzpuis, there is no more default value.
*
* Revision 1.11 2004/01/04 21:00:50 e_gourgoulhon
* Better handling of tensor symmetries in methods p_derive_cov() and
* p_divergence() (thanks to the new class Tensor_sym).
*
* Revision 1.10 2004/01/01 11:24:04 e_gourgoulhon
* Full reorganization of method p_derive_cov: the main loop is now
* on the indices of the *output* tensor (to take into account
* symmetries in the input and output tensors).
*
* Revision 1.9 2003/12/27 14:59:52 e_gourgoulhon
* -- Method derive_cov() suppressed.
* -- Change of the position of the derivation index from the first one
* to the last one in methods p_derive_cov() and p_divergence().
*
* Revision 1.8 2003/10/17 13:46:15 j_novak
* The argument is now between 1 and 3 (instead of 0->2)
*
* Revision 1.7 2003/10/16 21:37:08 e_gourgoulhon
* Corrected deriv index in divergence.
*
* Revision 1.6 2003/10/16 15:26:03 e_gourgoulhon
* Suppressed unsued variable
*
* Revision 1.5 2003/10/16 14:21:36 j_novak
* The calculation of the divergence of a Tensor is now possible.
*
* Revision 1.4 2003/10/11 16:45:43 e_gourgoulhon
* Suppressed the call to Itbl::set_etat_qcq() after
* the construction of the Itbl's.
*
* Revision 1.3 2003/10/11 14:39:50 e_gourgoulhon
* Suppressed declaration of unusued arguments in some methods.
*
* Revision 1.2 2003/10/06 13:58:46 j_novak
* The memory management has been improved.
* Implementation of the covariant derivative with respect to the exact Tensor
* type.
*
* Revision 1.1 2003/10/03 14:11:48 e_gourgoulhon
* Methods of class Connection_fcart.
*
*
*
* $Header: /cvsroot/Lorene/C++/Source/Connection/connection_fcart.C,v 1.14 2014/10/13 08:52:50 j_novak Exp $
*
*/
// C++ headers
#include "headcpp.h"
// C headers
#include <cstdlib>
// Lorene headers
#include "connection.h"
//------------------------------//
// Constructors //
//------------------------------//
// Contructor from a Cartesian flat-metric-orthonormal basis
namespace Lorene {
Connection_fcart::Connection_fcart(const Map& mpi, const Base_vect_cart& bi)
: Connection_flat(mpi, bi) {
}
// Copy constructor
Connection_fcart::Connection_fcart(const Connection_fcart& ci)
: Connection_flat(ci) {
}
//----------------------------//
// Destructor //
//----------------------------//
Connection_fcart::~Connection_fcart(){
}
//--------------------------------//
// Mutators / assignment //
//--------------------------------//
void Connection_fcart::operator=(const Connection_fcart& ) {
cout << "Connection_fcart::operator= : not implemented yet !" << endl ;
abort() ;
}
//-----------------------------//
// Computational methods //
//-----------------------------//
// Covariant derivative, returning a pointer.
//-------------------------------------------
Tensor* Connection_fcart::p_derive_cov(const Tensor& uu) const {
// Notations: suffix 0 in name <=> input tensor
// suffix 1 in name <=> output tensor
int valence0 = uu.get_valence() ;
int valence1 = valence0 + 1 ;
int valence1m1 = valence1 - 1 ; // same as valence0, but introduced for
// the sake of clarity
// Protections
// -----------
if (valence0 >= 1) {
assert(uu.get_triad() == triad) ;
}
// Creation of the result (pointer)
// --------------------------------
Tensor* resu ;
// If uu is a Scalar, the result is a vector
if (valence0 == 0)
resu = new Vector(*mp, COV, triad) ;
else {
// Type of indices of the result :
Itbl tipe(valence1) ;
const Itbl& tipeuu = uu.get_index_type() ;
for (int id = 0; id<valence0; id++) {
tipe.set(id) = tipeuu(id) ; // First indices = same as uu
}
tipe.set(valence1m1) = COV ; // last index is the derivation index
// if uu is a Tensor_sym, the result is also a Tensor_sym:
const Tensor* puu = &uu ;
const Tensor_sym* puus = dynamic_cast<const Tensor_sym*>(puu) ;
if ( puus != 0x0 ) { // the input tensor is symmetric
resu = new Tensor_sym(*mp, valence1, tipe, *triad,
puus->sym_index1(), puus->sym_index2()) ;
}
else {
resu = new Tensor(*mp, valence1, tipe, *triad) ; // no symmetry
}
}
int ncomp1 = resu->get_n_comp() ;
Itbl ind1(valence1) ; // working Itbl to store the indices of resu
Itbl ind0(valence0) ; // working Itbl to store the indices of uu
// Loop on all the components of the output tensor
// -----------------------------------------------
for (int ic=0; ic<ncomp1; ic++) {
// indices corresponding to the component no. ic in the output tensor
ind1 = resu->indices(ic) ;
// Component no. ic:
Scalar& cresu = resu->set(ind1) ;
// Indices of the input tensor
for (int id = 0; id < valence0; id++) {
ind0.set(id) = ind1(id) ;
}
// Value of last index (derivation index)
int k = ind1(valence1m1) ;
// Partial derivation with respect to x^k:
cresu = (uu(ind0)).deriv(k) ;
}
// C'est fini !
// -----------
return resu ;
}
// Divergence, returning a pointer.
//---------------------------------
Tensor* Connection_fcart::p_divergence(const Tensor& uu) const {
// Notations: suffix 0 in name <=> input tensor
// suffix 1 in name <=> output tensor
int valence0 = uu.get_valence() ;
int valence1 = valence0 - 1 ;
// Protections
// -----------
assert (valence0 >= 1) ;
assert (uu.get_triad() == triad) ;
// Last index must be contravariant:
assert (uu.get_index_type(valence0-1) == CON) ;
// Creation of the pointer on the result tensor
// --------------------------------------------
Tensor* resu ;
if (valence0 == 1) // if u is a Vector, the result is a Scalar
resu = new Scalar(*mp) ;
else {
// Type of indices of the result :
Itbl tipe(valence1) ;
const Itbl& tipeuu = uu.get_index_type() ;
for (int id = 0; id<valence1; id++) {
tipe.set(id) = tipeuu(id) ; // type of remaining indices =
} // same as uu indices
if (valence0 == 2) { // if u is a rank 2 tensor, the result is a Vector
resu = new Vector(*mp, tipe(0), *triad) ;
}
else {
// if uu is a Tensor_sym, the result might be also a Tensor_sym:
const Tensor* puu = &uu ;
const Tensor_sym* puus = dynamic_cast<const Tensor_sym*>(puu) ;
if ( puus != 0x0 ) { // the input tensor is symmetric
if (puus->sym_index2() != valence0 - 1) {
// the symmetry is preserved:
if (valence1 == 2) {
resu = new Sym_tensor(*mp, tipe, *triad) ;
}
else {
resu = new Tensor_sym(*mp, valence1, tipe, *triad,
puus->sym_index1(), puus->sym_index2()) ;
}
}
else { // the symmetry is lost:
resu = new Tensor(*mp, valence1, tipe, *triad) ;
}
}
else { // no symmetry in the input tensor:
resu = new Tensor(*mp, valence1, tipe, *triad) ;
}
}
}
int ncomp1 = resu->get_n_comp() ;
Itbl ind0(valence0) ; // working Itbl to store the indices of uu
Itbl ind1(valence1) ; // working Itbl to store the indices of resu
// Loop on all the components of the output tensor
for (int ic=0; ic<ncomp1; ic++) {
ind1 = resu->indices(ic) ;
Scalar& cresu = resu->set(ind1) ;
cresu.set_etat_zero() ;
for (int k=1; k<=3; k++) {
// indices (ind1,k) in the input tensor
for (int id = 0; id < valence1; id++) {
ind0.set(id) = ind1(id) ;
}
ind0.set(valence0-1) = k ;
cresu += uu(ind0).deriv(k) ; //Addition of dT^i/dx^i
}
}
// C'est fini !
// -----------
return resu ;
}
}
Lorene::Base_vect_cart
Cartesian vectorial bases (triads).
Definition base_vect.h:201
Lorene::Connection_fcart::operator=
void operator=(const Connection_fcart &)
Assignment to another Connection_fcart.
Definition connection_fcart.C:136
Lorene::Connection_fcart::Connection_fcart
Connection_fcart(const Map &, const Base_vect_cart &)
Contructor from a Cartesian flat-metric-orthonormal basis.
Definition connection_fcart.C:109
Lorene::Connection_fcart::~Connection_fcart
virtual ~Connection_fcart()
destructor
Definition connection_fcart.C:126
Lorene::Connection_fcart::p_divergence
virtual Tensor * p_divergence(const Tensor &tens) const
Computes the divergence of a tensor (with respect to the current connection).
Definition connection_fcart.C:238
Lorene::Connection_fcart::p_derive_cov
virtual Tensor * p_derive_cov(const Tensor &tens) const
Computes the covariant derivative of a tensor (with respect to the current connection).
Definition connection_fcart.C:152
Lorene::Connection_flat::Connection_flat
Connection_flat(const Map &, const Base_vect &)
Contructor from a triad, has to be defined in the derived classes.
Definition connection_flat.C:77
Lorene::Connection::triad
const Base_vect *const triad
Triad with respect to which the connection coefficients are defined.
Definition connection.h:124
Lorene::Connection::mp
const Map *const mp
Reference mapping.
Definition connection.h:119
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::Scalar
Tensor field of valence 0 (or component of a tensorial field).
Definition scalar.h:387
Lorene::Scalar::set_etat_zero
virtual void set_etat_zero()
Sets the logical state to ETATZERO (zero).
Definition scalar.C:324
Lorene::Sym_tensor
Class intended to describe valence-2 symmetric tensors.
Definition sym_tensor.h:223
Lorene::Tensor_sym
Symmetric tensors (with respect to two of their arguments).
Definition tensor.h:1037
Lorene::Tensor
Tensor handling.
Definition tensor.h:288
Lorene::Vector
Tensor field of valence 1.
Definition vector.h:188
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::get_index_type
int get_index_type(int i) const
Gives the type (covariant or contravariant) of the index number i .
Definition tensor.h:886
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::get_valence
int get_valence() const
Returns the valence.
Definition tensor.h:869
Lorene::Tensor::indices
virtual Itbl indices(int pos) const
Returns the indices of a component given by its position in the array cmp .
Definition tensor.C:539
Lorene::Tensor::get_n_comp
int get_n_comp() const
Returns the number of stored components.
Definition tensor.h:872
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::set
Scalar & set(const Itbl &ind)
Returns the value of a component (read/write version).
Definition tensor.C:654
Lorene
Lorene prototypes.
Definition app_hor.h:64
Lorene::Map
Map(const Mg3d &)
Constructor from a multi-domain 3D grid.
Definition map.C:139