190#include "utilitaires.h"
207 for (
int i=0; i<N_MET_MAX; i++) {
235 assert(ci.
get_etat() != ETATNONDEF) ;
241 assert( ci.
get_etat() == ETATQCQ ) ;
253 const Base_vect& triad_i,
const Metrique* met,
double weight)
262 for (
int i=0 ; i<
valence ; i++)
263 assert ((tipe(i) == COV) || (tipe(i) == CON)) ;
267 for (
int i=0 ; i<
n_comp ; i++)
275 const Base_vect* triad_i,
const Metrique* met,
double weight)
284 for (
int i=0 ; i<
valence ; i++)
285 assert ((tipe(i) == COV) || (tipe(i) == CON)) ;
293 for (
int i=0 ; i<
n_comp ; i++)
304 const Metrique* met,
double weight)
311 assert ((tipe == COV) || (tipe == CON)) ;
317 for (
int i=0 ; i<
n_comp ; i++)
334 for (
int i=0 ; i<
n_comp ; i++) {
336 if (source.
c[place_source] == 0x0)
339 c[i] =
new Cmp(*source.
c[place_source]) ;
354 for (
int i=0; i<N_MET_MAX; i++) {
381 for (
int i=0 ; i<
n_comp ; i++) {
383 if (source.
c[place_source] == 0x0)
386 c[i] =
new Cmp(*source.
c[place_source]) ;
398 for (
int i=0; i<N_MET_MAX; i++) {
426 assert( *triad_fich == *
triad) ;
437 for (
int i=0 ; i<
n_comp ; i++)
440 for (
int i=0 ; i<
n_comp ; i++)
441 c[i] =
new Cmp(*
mp, *
mp->get_mg(), fd) ;
471 if (
etat == ETATQCQ) {
472 c[0] =
new Cmp(*
mp, *
mp->get_mg(), fd) ;
492 const Base_vect& triad_i,
const Metrique* met,
double weight) :
501 for (
int i=0 ; i<
valence ; i++)
502 assert ((tipe(i) == COV) || (tipe(i) == CON)) ;
506 for (
int i=0 ; i<
n_comp ; i++)
516 const Base_vect& triad_i,
const Metrique* met,
double weight) :
522 assert ((tipe == COV) || (tipe == CON)) ;
528 for (
int i=0 ; i<
n_comp ; i++)
553 for (
int i=0 ; i<
n_comp ; i++)
562 assert( (j>=0) && (j<N_MET_MAX) ) ;
565 for (
int i=0 ; i<N_DEPEND ; i++)
580 for (
int i=0; i<N_MET_MAX; i++)
598 for (
int i=0; i<N_MET_MAX; i++)
606 for (
int i=0; i<N_MET_MAX; i++)
618 for (
int i=0; i<N_MET_MAX; i++) {
620 if ((!deja) && (
met_depend[i] != 0x0)) nmet++ ;
622 if (nmet == N_MET_MAX) {
623 cout <<
"Too many metrics in Tenseur::set_dependances" << endl ;
628 while ((conte < N_DEPEND) && (met.dependances[conte] != 0x0))
631 if (conte == N_DEPEND) {
632 cout <<
"Too many dependancies in Tenseur::set_dependances " << endl ;
636 met.dependances[conte] = this ;
645 for (
int i=0 ; i<
n_comp ; i++)
666 for (
int i=0 ; i<
n_comp ; i++) {
667 c[i]->allocate_all() ;
701 for (
int i=0 ; i<
valence ; i++)
702 assert ((idx(i)>=0) && (idx(i)<3)) ;
704 for (
int i=0 ; i<
valence ; i++)
712 assert ((place >= 0) && (place <
n_comp)) ;
717 for (
int i=
valence-1 ; i>=0 ; i--) {
718 res.
set(i) = div(place, 3).rem ;
719 place = int((place-res(i))/3) ;
732 for (
int i=0 ; i<
valence ; i++)
748 for (
int i=0 ; i<
n_comp ; i++) {
750 if (t.
c[place_t] == 0x0)
753 *
c[i] = *t.
c[place_t] ;
759 cout <<
"Unknown state in Tenseur::operator= " << endl ;
791 cout <<
"Unknown state in Tenseur::operator= " << endl ;
802 if (
x ==
double(0)) {
833 assert(
etat == ETATQCQ) ;
844 assert (
etat == ETATQCQ) ;
845 assert ((ind >= 0) && (ind < 3)) ;
855 assert (
etat == ETATQCQ) ;
856 assert ((ind1 >= 0) && (ind1 < 3)) ;
857 assert ((ind2 >= 0) && (ind2 < 3)) ;
874 assert (
etat == ETATQCQ) ;
875 assert ((ind1 >= 0) && (ind1 < 3)) ;
876 assert ((ind2 >= 0) && (ind2 < 3)) ;
877 assert ((ind3 >= 0) && (ind3 < 3)) ;
881 indices.
set(0) = ind1 ;
882 indices.
set(1) = ind2 ;
883 indices.
set(2) = ind3 ;
896 assert (
etat == ETATQCQ) ;
897 for (
int i=0 ; i<
valence ; i++)
898 assert ((indices(i)>=0) && (indices(i)<3)) ;
914 if ( (l_min == 0) && (l_max ==
mp->get_mg()->get_nzone()-1) ) {
919 assert(
etat != ETATNONDEF ) ;
921 if (
etat == ETATZERO ) {
925 assert(
etat == ETATQCQ ) ;
928 for (
int i=0 ; i<
n_comp ; i++) {
929 c[i]->annule(l_min, l_max) ;
935 for (
int j=0; j<N_MET_MAX; j++) {
953 if (
etat == ETATQCQ)
return *
c[0] ;
959 cout <<
"Undefined Tensor in Tenseur::operator() ..." << endl ;
965 return mp->cmp_zero() ;
970 cout <<
"Unknown state in Tenseur::operator()" << endl ;
980 assert ((indice>=0) && (indice<3)) ;
983 if (
etat == ETATQCQ)
return *
c[indice] ;
989 cout <<
"Undefined Tensor in Tenseur::operator(int) ..." << endl ;
995 return mp->cmp_zero() ;
999 cout <<
"Unknown state in Tenseur::operator(int)" << endl ;
1008 assert ((indice1>=0) && (indice1<3)) ;
1009 assert ((indice2>=0) && (indice2<3)) ;
1012 if (
etat == ETATQCQ) {
1015 idx.
set(0) = indice1 ;
1016 idx.
set(1) = indice2 ;
1023 cout <<
"Undefined Tensor in Tenseur::operator(int, int) ..." << endl ;
1029 return mp->cmp_zero() ;
1033 cout <<
"Unknown state in Tenseur::operator(int, int)" << endl ;
1042 assert ((indice1>=0) && (indice1<3)) ;
1043 assert ((indice2>=0) && (indice2<3)) ;
1044 assert ((indice3>=0) && (indice3<3)) ;
1047 if (
etat == ETATQCQ) {
1050 idx.
set(0) = indice1 ;
1051 idx.
set(1) = indice2 ;
1052 idx.
set(2) = indice3 ;
1059 cout <<
"Undefined Tensor in Tenseur::operator(int, int, int) ..." << endl ;
1065 return mp->cmp_zero() ;
1069 cout <<
"Unknown state in Tenseur::operator(int, int, int)" << endl ;
1081 for (
int i=0 ; i<
valence ; i++)
1082 assert ((indices(i)>=0) && (indices(i)<3)) ;
1084 if (
etat == ETATQCQ) {
1091 cout <<
"Undefined Tensor in Tenseur::operator(const Itbl&) ..." << endl ;
1097 return mp->cmp_zero() ;
1101 cout <<
"Unknown state in Tenseur::operator(const Itbl& )" << endl ;
1112 if (
etat == ETATZERO) {
1116 assert(
etat == ETATQCQ) ;
1118 for (
int i=0 ; i<
n_comp ; i++)
1120 c[i]->dec_dzpuis() ;
1125 if (
etat == ETATZERO) {
1129 assert(
etat == ETATQCQ) ;
1131 for (
int i=0 ; i<
n_comp ; i++)
1133 c[i]->inc_dzpuis() ;
1138 if (
etat == ETATZERO) {
1142 assert(
etat == ETATQCQ) ;
1144 for (
int i=0 ; i<
n_comp ; i++)
1146 c[i]->dec2_dzpuis() ;
1151 if (
etat == ETATZERO) {
1155 assert(
etat == ETATQCQ) ;
1157 for (
int i=0 ; i<
n_comp ; i++)
1159 c[i]->inc2_dzpuis() ;
1164 if (
etat == ETATZERO) {
1168 assert(
etat == ETATQCQ) ;
1170 for (
int i=0 ; i<
n_comp ; i++)
1172 c[i]->mult_r_zec() ;
1178 if (
etat == ETATZERO) {
1182 assert(
etat == ETATQCQ) ;
1186 c[0]->std_base_scal() ;
1192 if (
triad->identify() == (
mp->get_bvect_cart()).identify() ) {
1194 Base_val** bases =
mp->get_mg()->std_base_vect_cart() ;
1196 for (
int i=0 ; i<3 ; i++)
1197 (
c[i]->va).set_base( *bases[i] ) ;
1198 for (
int i=0 ; i<3 ; i++)
1203 assert(
triad->identify() == (
mp->get_bvect_spher()).identify()) ;
1204 Base_val** bases =
mp->get_mg()->std_base_vect_spher() ;
1206 for (
int i=0 ; i<3 ; i++)
1207 (
c[i]->va).set_base( *bases[i] ) ;
1208 for (
int i=0 ; i<3 ; i++)
1218 if(
triad->identify() == (
mp->get_bvect_cart()).identify() ) {
1220 Base_val** bases =
mp->get_mg()->std_base_vect_cart() ;
1224 for (
int i=0 ; i<
n_comp ; i++) {
1226 (
c[i]->va).set_base( (*bases[indices(0)]) *
1227 (*bases[indices(1)]) ) ;
1229 for (
int i=0 ; i<3 ; i++)
1234 assert(
triad->identify() == (
mp->get_bvect_spher()).identify()) ;
1235 Base_val** bases =
mp->get_mg()->std_base_vect_spher() ;
1239 for (
int i=0 ; i<
n_comp ; i++) {
1241 (
c[i]->va).set_base( (*bases[indices(0)]) *
1242 (*bases[indices(1)]) ) ;
1244 for (
int i=0 ; i<3 ; i++)
1253 "Tenseur::set_std_base() : the case valence = " <<
valence
1254 <<
" is not treated !" << endl ;
1262ostream& operator<<(ostream& flux,
const Tenseur &source ) {
1264 flux <<
"Valence : " << source.
valence << endl ;
1266 flux <<
"Tensor density of weight " << source.
poids << endl ;
1269 flux <<
"Vectorial basis (triad) on which the components are defined :"
1275 flux <<
"Type of the indices : " << endl ;
1276 for (
int i=0 ; i<source.
valence ; i++) {
1277 flux <<
"Index " << i <<
" : " ;
1279 flux <<
" contravariant." << endl ;
1281 flux <<
" covariant." << endl ;
1284 switch (source.
etat) {
1287 flux <<
"Null Tenseur. " << endl ;
1292 flux <<
"Undefined Tenseur. " << endl ;
1297 for (
int i=0 ; i<source.
n_comp ; i++) {
1300 flux <<
"Component " ;
1303 for (
int j=0 ; j<source.
valence ; j++)
1304 flux <<
" " << num_indices(j) ;
1308 flux <<
" : " << endl ;
1309 flux <<
"-------------" << endl ;
1312 if (source.
c[i] != 0x0)
1313 flux << *source.
c[i] << endl ;
1315 flux <<
"Unknown component ... " << endl ;
1321 cout <<
"Unknown case in operator<< (ostream&, const Tenseur&)" << endl ;
1327 flux <<
" -----------------------------------------------------" << endl ;
1343 if (
etat == ETATQCQ)
1344 for (
int i=0 ; i<
n_comp ; i++)
1353 assert (
etat != ETATNONDEF) ;
1363 for (
int i=0 ; i<
valence ; i++)
1375 if (
etat == ETATZERO)
1388 for (
int m=0 ; m<
valence ; m++)
1389 indices_source.
set(m) = indices_res(m+1) ;
1392 (*this)(indices_source).deriv(indices_res(0)) ;
1400 assert (
etat != ETATNONDEF) ;
1410 "Tenseur::fait_gradient_spher : the valence must be zero !"
1418 if (
etat == ETATZERO) {
1422 assert(
etat == ETATQCQ ) ;
1437 assert (
etat != ETATNONDEF) ;
1451 for (
int i=0 ; i<
valence ; i++) {
1462 indices_gamma.
set(0) = indices(0) ;
1463 indices_gamma.
set(1) = indices(i+1) ;
1464 for (
int idx=2 ; idx<
p_derive_cov[ind]->valence ; idx++)
1466 indices_gamma.
set(idx) = indices(idx-1) ;
1468 indices_gamma.
set(idx) = indices(idx) ;
1470 p_derive_cov[ind]->set(indices) -= (*auxi)(indices_gamma) ;
1483 indices_gamma.
set(0) = indices(i+1) ;
1484 indices_gamma.
set(1) = indices(0) ;
1485 for (
int idx=2 ; idx<
p_derive_cov[ind]->valence ; idx++)
1487 indices_gamma.
set(idx) = indices(idx-1) ;
1489 indices_gamma.
set(idx) = indices(idx) ;
1490 p_derive_cov[ind]->set(indices) += (*auxi)(indices_gamma) ;
1537 for (
int indice=1 ; indice<
valence ; indice++) {
1540 auxi =
new Tenseur(*auxi_old) ;
Bases of the spectral expansions.
Vectorial bases (triads) with respect to which the tensorial components are defined.
static Base_vect * bvect_from_file(FILE *)
Construction of a vectorial basis from a file (see sauve(FILE* ) ).
virtual void change_basis(Tenseur &) const =0
Change the basis in which the components of a tensor are expressed.
Component of a tensorial field *** DEPRECATED : use class Scalar instead ***.
int get_etat() const
Returns the logical state.
Basic integer array class.
void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
int get_dim(int i) const
Gives the i th dimension (ie {tt dim.dim[i] ).
int & set(int i)
Read/write of a particular element (index i ) (1D case).
int get_ndim() const
Gives the number of dimensions (ie dim.ndim ).
virtual int donne_place(const Itbl &idx) const
Returns the position in the Cmp 1-D array c of a component given by its indices.
Tensor handling *** DEPRECATED : use class Tensor instead ***.
const Base_vect * get_triad() const
Returns the vectorial basis (triad) on which the components are defined.
virtual Itbl donne_indices(int place) const
Returns the indices of a component given by its position in the Cmp 1-D array c .
Cmp & set()
Read/write for a scalar (see also operator=(const Cmp&) ).
Tenseur ** p_derive_con
Array of pointers on the contravariant derivatives of *this with respect to the corresponding metri...
void fait_carre_scal(const Metrique &, int i) const
Calculates, if needed, the scalar square of *this , with respect to met .
void allocate_all()
Sets the logical state to ETATQCQ (ordinary state) and performs the memory allocation of all the elem...
const Metrique * metric
For tensor densities: the metric defining the conformal factor.
void fait_gradient_spher() const
Calculates, if needed, the gradient of *this in a spherical orthonormal basis (scalar field only).
void sauve(FILE *) const
Save in a file.
virtual void operator=(const Tenseur &tens)
Assignment to another Tenseur.
Tenseur * p_gradient_spher
Pointer on the gradient of *this in a spherical orthonormal basis (scalar field only).
const Map *const mp
Reference mapping.
void inc_dzpuis()
dzpuis += 1 ;
virtual void fait_gradient() const
Calculates, if needed, the gradient of *this .
const Metrique ** met_depend
Array of pointers on the Metrique 's used to calculate derivatives members.
virtual int donne_place(const Itbl &idx) const
Returns the position in the Cmp 1-D array c of a component given by its indices.
const Tenseur & derive_cov(const Metrique &met) const
Returns the covariant derivative of *this , with respect to met .
void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
Tenseur(const Map &map, const Metrique *met=0x0, double weight=0)
Constructor for a scalar field.
void annule(int l)
Sets the Tenseur to zero in a given domain.
const Map * get_mp() const
Returns pointer on the mapping.
void dec2_dzpuis()
dzpuis -= 2 ;
Tenseur ** p_carre_scal
Array of pointers on the scalar squares of *this with respect to the corresponding metric in *met_d...
double get_poids() const
Returns the weight.
int get_place_met(const Metrique &metre) const
Returns the position of the pointer on metre in the array met_depend .
void dec_dzpuis()
dzpuis -= 1 ;
const Tenseur & derive_con(const Metrique &) const
Returns the contravariant derivative of *this , with respect to met .
const Base_vect * triad
Vectorial basis (triad) with respect to which the tensor components are defined.
const Tenseur & gradient() const
Returns the gradient of *this (Cartesian coordinates).
virtual ~Tenseur()
Destructor.
friend Tenseur contract(const Tenseur &, int id1, int id2)
Self contraction of two indices of a Tenseur .
int n_comp
Number of components, depending on the symmetry.
void new_der_met()
Builds the arrays met_depend , p_derive_cov , p_derive_con and p_carre_scal and fills them with null ...
void set_std_base()
Set the standard spectal basis of decomposition for each component.
void set_etat_zero()
Sets the logical state to ETATZERO (zero state).
void set_poids(double weight)
Sets the weight for a tensor density.
void mult_r_zec()
Multiplication by r in the external zone.
Itbl type_indice
Array of size valence contening the type of each index, COV for a covariant one and CON for a contrav...
void del_derive() const
Logical destructor of all the derivatives.
bool verif() const
Returns false for a tensor density without a defined metric.
const Cmp & operator()() const
Read only for a scalar.
void set_metric(const Metrique &met)
Sets the pointer on the metric for a tensor density.
void inc2_dzpuis()
dzpuis += 2 ;
const Tenseur & gradient_spher() const
Returns the gradient of *this (Spherical coordinates) (scalar field only).
void del_derive_met(int i) const
Logical destructor of the derivatives depending on the i-th element of *met_depend .
int etat
Logical state ETATZERO , ETATQCQ or ETATNONDEF.
double poids
For tensor densities: the weight.
void set_der_met_0x0(int i) const
Sets the pointers of the derivatives depending on the i-th element of *met_depend to zero (as well as...
Tenseur ** p_derive_cov
Array of pointers on the covariant derivatives of *this with respect to the corresponding metric in...
friend Tenseur manipule(const Tenseur &, const Metrique &, int idx)
Raise or lower the index idx depending on its type, using the given Metrique .
void set_der_0x0() const
Sets the pointers of all the derivatives to zero.
void change_triad(const Base_vect &new_triad)
Sets a new vectorial basis (triad) of decomposition and modifies the components accordingly.
void set_triad(const Base_vect &new_triad)
Assigns a new vectorial basis (triad) of decomposition.
void set_etat_nondef()
Sets the logical state to ETATNONDEF (undefined state).
Tenseur * p_gradient
Pointer on the gradient of *this .
void set_dependance(const Metrique &met) const
To be used to describe the fact that the derivatives members have been calculated with met .
void del_t()
Logical destructor.
virtual void fait_derive_cov(const Metrique &met, int i) const
Calculates, if needed, the covariant derivative of *this , with respect to met .
int get_etat() const
Returns the logical state.
const Tenseur & carre_scal(const Metrique &) const
Returns the scalar square of *this , with respect to met .
virtual void fait_derive_con(const Metrique &, int i) const
Calculates, if needed, the contravariant derivative of *this , with respect to met .
Cmp pow(const Cmp &, int)
Power .
int fread_be(int *aa, int size, int nb, FILE *fich)
Reads integer(s) from a binary file according to the big endian convention.
int fwrite_be(const int *aa, int size, int nb, FILE *fich)
Writes integer(s) into a binary file according to the big endian convention.
Map(const Mg3d &)
Constructor from a multi-domain 3D grid.
Coord x
x coordinate centered on the grid