33 char tenseur_C[] =
"$Header: /cvsroot/Lorene/C++/Source/Tenseur/tenseur.C,v 1.14 2012/04/02 09:57:21 j_novak Exp $" ;
35 char tenseur_C[] =
"$Header: /cvsroot/Lorene/C++/Source/Tenseur/tenseur.C,v 1.15 2014/10/13 08:53:41 j_novak Exp $" ;
199 #include "metrique.h" 200 #include "utilitaires.h" 217 for (
int i=0; i<N_MET_MAX; i++) {
226 mp(&map), valence(0), triad(0x0),
227 type_indice(0), n_comp(1), etat(ETATNONDEF), poids(weight),
241 mp(ci.get_mp()), valence(0), triad(0x0),
242 type_indice(0), n_comp(1), etat(ci.get_etat()), poids(weight),
245 assert(ci.
get_etat() != ETATNONDEF) ;
251 assert( ci.
get_etat() == ETATQCQ ) ;
263 const Base_vect& triad_i,
const Metrique* met,
double weight)
264 : mp(&map), valence(val), triad(&triad_i), type_indice(tipe),
265 n_comp(int(
pow(3., val))), etat(ETATNONDEF), poids(weight),
272 for (
int i=0 ; i<
valence ; i++)
273 assert ((tipe(i) == COV) || (tipe(i) == CON)) ;
277 for (
int i=0 ; i<
n_comp ; i++)
285 const Base_vect* triad_i,
const Metrique* met,
double weight)
286 : mp(&map), valence(val), triad(triad_i), type_indice(tipe),
287 n_comp(int(
pow(3., val))), etat(ETATNONDEF), poids(weight),
294 for (
int i=0 ; i<
valence ; i++)
295 assert ((tipe(i) == COV) || (tipe(i) == CON)) ;
303 for (
int i=0 ; i<
n_comp ; i++)
314 const Metrique* met,
double weight)
315 : mp(&map), valence(val), triad(&triad_i), type_indice(val),
316 n_comp(int(
pow(3., val))), etat (ETATNONDEF), poids(weight),
321 assert ((tipe == COV) || (tipe == CON)) ;
327 for (
int i=0 ; i<
n_comp ; i++)
335 mp(source.mp), valence(source.valence), triad(source.triad),
336 type_indice(source.type_indice), etat (source.etat), poids(source.poids),
337 metric(source.metric) {
344 for (
int i=0 ; i<
n_comp ; i++) {
346 if (source.
c[place_source] == 0x0)
349 c[i] =
new Cmp(*source.
c[place_source]) ;
364 for (
int i=0; i<N_MET_MAX; i++) {
383 mp(source.mp), valence(source.valence), triad(source.triad),
384 type_indice(source.type_indice), etat(source.etat),
385 poids(source.poids), metric(source.metric) {
391 for (
int i=0 ; i<
n_comp ; i++) {
393 if (source.
c[place_source] == 0x0)
396 c[i] =
new Cmp(*source.
c[place_source]) ;
408 for (
int i=0; i<N_MET_MAX; i++) {
429 : mp(&mapping), triad(&triad_i), type_indice(fd),
436 assert( *triad_fich == *
triad) ;
447 for (
int i=0 ; i<
n_comp ; i++)
450 for (
int i=0 ; i<
n_comp ; i++)
465 : mp(&mapping), type_indice(fd), metric(met){
481 if (
etat == ETATQCQ) {
502 const Base_vect& triad_i,
const Metrique* met,
double weight) :
503 mp(&map), valence(val), triad(&triad_i), type_indice(tipe), n_comp(compo),
504 etat (ETATNONDEF), poids(weight), metric(met) {
511 for (
int i=0 ; i<
valence ; i++)
512 assert ((tipe(i) == COV) || (tipe(i) == CON)) ;
516 for (
int i=0 ; i<
n_comp ; i++)
526 const Base_vect& triad_i,
const Metrique* met,
double weight) :
527 mp(&map), valence(val), triad(&triad_i), type_indice(val), n_comp(compo),
528 etat (ETATNONDEF), poids(weight), metric(met) {
532 assert ((tipe == COV) || (tipe == CON)) ;
538 for (
int i=0 ; i<
n_comp ; i++)
563 for (
int i=0 ; i<
n_comp ; i++)
572 assert( (j>=0) && (j<N_MET_MAX) ) ;
575 for (
int i=0 ; i<N_DEPEND ; i++)
590 for (
int i=0; i<N_MET_MAX; i++)
608 for (
int i=0; i<N_MET_MAX; i++)
616 for (
int i=0; i<N_MET_MAX; i++)
628 for (
int i=0; i<N_MET_MAX; i++) {
630 if ((!deja) && (
met_depend[i] != 0x0)) nmet++ ;
632 if (nmet == N_MET_MAX) {
633 cout <<
"Too many metrics in Tenseur::set_dependances" << endl ;
638 while ((conte < N_DEPEND) && (met.dependances[conte] != 0x0))
641 if (conte == N_DEPEND) {
642 cout <<
"Too many dependancies in Tenseur::set_dependances " << endl ;
646 met.dependances[conte] = this ;
655 for (
int i=0 ; i<
n_comp ; i++)
676 for (
int i=0 ; i<
n_comp ; i++) {
711 for (
int i=0 ; i<
valence ; i++)
712 assert ((idx(i)>=0) && (idx(i)<3)) ;
714 for (
int i=0 ; i<
valence ; i++)
722 assert ((place >= 0) && (place <
n_comp)) ;
727 for (
int i=
valence-1 ; i>=0 ; i--) {
728 res.
set(i) = div(place, 3).rem ;
729 place = int((place-res(i))/3) ;
742 for (
int i=0 ; i<
valence ; i++)
758 for (
int i=0 ; i<
n_comp ; i++) {
760 if (t.
c[place_t] == 0x0)
763 *
c[i] = *t.
c[place_t] ;
769 cout <<
"Unknown state in Tenseur::operator= " << endl ;
801 cout <<
"Unknown state in Tenseur::operator= " << endl ;
812 if (x ==
double(0)) {
843 assert(
etat == ETATQCQ) ;
854 assert (
etat == ETATQCQ) ;
855 assert ((ind >= 0) && (ind < 3)) ;
865 assert (
etat == ETATQCQ) ;
866 assert ((ind1 >= 0) && (ind1 < 3)) ;
867 assert ((ind2 >= 0) && (ind2 < 3)) ;
884 assert (
etat == ETATQCQ) ;
885 assert ((ind1 >= 0) && (ind1 < 3)) ;
886 assert ((ind2 >= 0) && (ind2 < 3)) ;
887 assert ((ind3 >= 0) && (ind3 < 3)) ;
891 indices.
set(0) = ind1 ;
892 indices.
set(1) = ind2 ;
893 indices.
set(2) = ind3 ;
906 assert (
etat == ETATQCQ) ;
907 for (
int i=0 ; i<
valence ; i++)
908 assert ((indices(i)>=0) && (indices(i)<3)) ;
929 assert(
etat != ETATNONDEF ) ;
931 if (
etat == ETATZERO ) {
935 assert(
etat == ETATQCQ ) ;
938 for (
int i=0 ; i<
n_comp ; i++) {
945 for (
int j=0; j<N_MET_MAX; j++) {
963 if (
etat == ETATQCQ)
return *
c[0] ;
969 cout <<
"Undefined Tensor in Tenseur::operator() ..." << endl ;
980 cout <<
"Unknown state in Tenseur::operator()" << endl ;
990 assert ((indice>=0) && (indice<3)) ;
993 if (
etat == ETATQCQ)
return *
c[indice] ;
999 cout <<
"Undefined Tensor in Tenseur::operator(int) ..." << endl ;
1009 cout <<
"Unknown state in Tenseur::operator(int)" << endl ;
1018 assert ((indice1>=0) && (indice1<3)) ;
1019 assert ((indice2>=0) && (indice2<3)) ;
1022 if (
etat == ETATQCQ) {
1025 idx.
set(0) = indice1 ;
1026 idx.
set(1) = indice2 ;
1033 cout <<
"Undefined Tensor in Tenseur::operator(int, int) ..." << endl ;
1043 cout <<
"Unknown state in Tenseur::operator(int, int)" << endl ;
1052 assert ((indice1>=0) && (indice1<3)) ;
1053 assert ((indice2>=0) && (indice2<3)) ;
1054 assert ((indice3>=0) && (indice3<3)) ;
1057 if (
etat == ETATQCQ) {
1060 idx.
set(0) = indice1 ;
1061 idx.
set(1) = indice2 ;
1062 idx.
set(2) = indice3 ;
1069 cout <<
"Undefined Tensor in Tenseur::operator(int, int, int) ..." << endl ;
1079 cout <<
"Unknown state in Tenseur::operator(int, int, int)" << endl ;
1091 for (
int i=0 ; i<
valence ; i++)
1092 assert ((indices(i)>=0) && (indices(i)<3)) ;
1094 if (
etat == ETATQCQ) {
1101 cout <<
"Undefined Tensor in Tenseur::operator(const Itbl&) ..." << endl ;
1111 cout <<
"Unknown state in Tenseur::operator(const Itbl& )" << endl ;
1122 if (
etat == ETATZERO) {
1126 assert(
etat == ETATQCQ) ;
1128 for (
int i=0 ; i<
n_comp ; i++)
1135 if (
etat == ETATZERO) {
1139 assert(
etat == ETATQCQ) ;
1141 for (
int i=0 ; i<
n_comp ; i++)
1148 if (
etat == ETATZERO) {
1152 assert(
etat == ETATQCQ) ;
1154 for (
int i=0 ; i<
n_comp ; i++)
1161 if (
etat == ETATZERO) {
1165 assert(
etat == ETATQCQ) ;
1167 for (
int i=0 ; i<
n_comp ; i++)
1174 if (
etat == ETATZERO) {
1178 assert(
etat == ETATQCQ) ;
1180 for (
int i=0 ; i<
n_comp ; i++)
1188 if (
etat == ETATZERO) {
1192 assert(
etat == ETATQCQ) ;
1206 for (
int i=0 ; i<3 ; i++)
1207 (
c[i]->va).set_base( *bases[i] ) ;
1208 for (
int i=0 ; i<3 ; i++)
1216 for (
int i=0 ; i<3 ; i++)
1217 (
c[i]->va).set_base( *bases[i] ) ;
1218 for (
int i=0 ; i<3 ; i++)
1234 for (
int i=0 ; i<
n_comp ; i++) {
1236 (
c[i]->
va).set_base( (*bases[indices(0)]) *
1237 (*bases[indices(1)]) ) ;
1239 for (
int i=0 ; i<3 ; i++)
1249 for (
int i=0 ; i<
n_comp ; i++) {
1251 (
c[i]->
va).set_base( (*bases[indices(0)]) *
1252 (*bases[indices(1)]) ) ;
1254 for (
int i=0 ; i<3 ; i++)
1263 "Tenseur::set_std_base() : the case valence = " <<
valence 1264 <<
" is not treated !" << endl ;
1272 ostream& operator<<(ostream& flux,
const Tenseur &source ) {
1274 flux <<
"Valence : " << source.
valence << endl ;
1276 flux <<
"Tensor density of weight " << source.
poids << endl ;
1279 flux <<
"Vectorial basis (triad) on which the components are defined :" 1285 flux <<
"Type of the indices : " << endl ;
1286 for (
int i=0 ; i<source.
valence ; i++) {
1287 flux <<
"Index " << i <<
" : " ;
1289 flux <<
" contravariant." << endl ;
1291 flux <<
" covariant." << endl ;
1294 switch (source.
etat) {
1297 flux <<
"Null Tenseur. " << endl ;
1302 flux <<
"Undefined Tenseur. " << endl ;
1307 for (
int i=0 ; i<source.
n_comp ; i++) {
1310 flux <<
"Component " ;
1313 for (
int j=0 ; j<source.
valence ; j++)
1314 flux <<
" " << num_indices(j) ;
1318 flux <<
" : " << endl ;
1319 flux <<
"-------------" << endl ;
1322 if (source.
c[i] != 0x0)
1323 flux << *source.
c[i] << endl ;
1325 flux <<
"Unknown component ... " << endl ;
1331 cout <<
"Unknown case in operator<< (ostream&, const Tenseur&)" << endl ;
1337 flux <<
" -----------------------------------------------------" << endl ;
1353 if (
etat == ETATQCQ)
1354 for (
int i=0 ; i<
n_comp ; i++)
1363 assert (
etat != ETATNONDEF) ;
1373 for (
int i=0 ; i<
valence ; i++)
1385 if (
etat == ETATZERO)
1398 for (
int m=0 ; m<
valence ; m++)
1399 indices_source.
set(m) = indices_res(m+1) ;
1402 (*this)(indices_source).deriv(indices_res(0)) ;
1410 assert (
etat != ETATNONDEF) ;
1420 "Tenseur::fait_gradient_spher : the valence must be zero !" 1428 if (
etat == ETATZERO) {
1432 assert(
etat == ETATQCQ ) ;
1447 assert (
etat != ETATNONDEF) ;
1461 for (
int i=0 ; i<
valence ; i++) {
1472 indices_gamma.
set(0) = indices(0) ;
1473 indices_gamma.
set(1) = indices(i+1) ;
1476 indices_gamma.
set(idx) = indices(idx-1) ;
1478 indices_gamma.
set(idx) = indices(idx) ;
1493 indices_gamma.
set(0) = indices(i+1) ;
1494 indices_gamma.
set(1) = indices(0) ;
1497 indices_gamma.
set(idx) = indices(idx-1) ;
1499 indices_gamma.
set(idx) = indices(idx) ;
1547 for (
int indice=1 ; indice<
valence ; indice++) {
1550 auxi =
new Tenseur(*auxi_old) ;
Itbl type_indice
Array of size valence contening the type of each index, COV for a covariant one and CON for a contrav...
const Cmp & dsdr() const
Returns of *this .
const Map *const mp
Reference mapping.
double get_poids() const
Returns the weight.
const Base_vect * triad
Vectorial basis (triad) with respect to which the tensor components are defined.
Base_val ** std_base_vect_cart() const
Returns the standard spectral bases for the Cartesian components of a vector.
virtual ~Tenseur()
Destructor.
void annule(int l)
Sets the Tenseur to zero in a given domain.
int get_place_met(const Metrique &metre) const
Returns the position of the pointer on metre in the array met_depend .
Component of a tensorial field *** DEPRECATED : use class Scalar instead ***.
int & set(int i)
Read/write of a particular element (index i ) (1D case)
void dec2_dzpuis()
dzpuis -= 2 ;
const Tenseur & gradient_spher() const
Returns the gradient of *this (Spherical coordinates) (scalar field only).
void set_triad(const Base_vect &new_triad)
Assigns a new vectorial basis (triad) of decomposition.
const Cmp & cmp_zero() const
Returns the null Cmp defined on *this.
int n_comp
Number of components, depending on the symmetry.
void dec_dzpuis()
Decreases by 1 the value of dzpuis and changes accordingly the values of the Cmp in the external comp...
void annule(int l)
Sets the Cmp to zero in a given domain.
void set_poids(double weight)
Sets the weight for a tensor density.
void set_std_base()
Set the standard spectal basis of decomposition for each component.
Class intended to describe tensors with a symmetry on the two last indices *** DEPRECATED : use class...
const Cmp & srstdsdp() const
Returns of *this .
const Base_vect_spher & get_bvect_spher() const
Returns the orthonormal vectorial basis associated with the coordinates of the mapping.
int get_ndim() const
Gives the number of dimensions (ie dim.ndim )
const Mg3d * get_mg() const
Gives the Mg3d on which the mapping is defined.
int get_etat() const
Returns the logical state.
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.
virtual void sauve(FILE *) const
Save in a file.
Base class for coordinate mappings.
int etat
Logical state ETATZERO , ETATQCQ or ETATNONDEF.
const Cmp & srdsdt() const
Returns of *this .
virtual Itbl donne_indices(int place) const
Returns the indices of a component given by its position in the Cmp 1-D array c . ...
void mult_r_zec()
Multiplication by r in the external compactified domain (ZEC)
void new_der_met()
Builds the arrays met_depend , p_derive_cov , p_derive_con and p_carre_scal and fills them with null ...
Basic integer array class.
const Tenseur & derive_con(const Metrique &) const
Returns the contravariant derivative of *this , with respect to met .
Vectorial bases (triads) with respect to which the tensorial components are defined.
virtual void change_basis(Tenseur &) const =0
Change the basis in which the components of a tensor are expressed.
virtual void fait_gradient() const
Calculates, if needed, the gradient of *this .
void inc_dzpuis()
dzpuis += 1 ;
const Cmp & operator()() const
Read only for a scalar.
static Base_vect * bvect_from_file(FILE *)
Construction of a vectorial basis from a file (see sauve(FILE* ) ).
void inc2_dzpuis()
dzpuis += 2 ;
void del_t()
Logical destructor.
virtual void operator=(const Tenseur &tens)
Assignment to another Tenseur.
void set_metric(const Metrique &met)
Sets the pointer on the metric for a tensor density.
void inc_dzpuis()
Increases by the value of dzpuis and changes accordingly the values of the Cmp in the external compac...
Tenseur * p_gradient_spher
Pointer on the gradient of *this in a spherical orthonormal basis (scalar field only).
void del_derive_met(int i) const
Logical destructor of the derivatives depending on the i-th element of *met_depend ...
Cmp & set()
Read/write for a scalar (see also operator=(const Cmp&) ).
void change_triad(const Base_vect &new_triad)
Sets a new vectorial basis (triad) of decomposition and modifies the components accordingly.
virtual void fait_derive_cov(const Metrique &met, int i) const
Calculates, if needed, the covariant derivative of *this , with respect to met .
void sauve(FILE *) const
Save in a file.
Tenseur * p_gradient
Pointer on the gradient of *this .
void mult_r_zec()
Multiplication by r in the external zone.
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 Base_vect * get_triad() const
Returns the vectorial basis (triad) on which the components are defined.
bool verif() const
Returns false for a tensor density without a defined metric.
void sauve(FILE *) const
Save in a file.
double poids
For tensor densities: the weight.
Base_val ** std_base_vect_spher() const
Returns the standard spectral bases for the spherical components of a vector.
int get_nzone() const
Returns the number of domains.
virtual int identify() const =0
Returns a number to identify the sub-classe of Base_vect the object belongs to.
Tenseur ** p_derive_con
Array of pointers on the contravariant derivatives of *this with respect to the corresponding metric...
virtual void fait_derive_con(const Metrique &, int i) const
Calculates, if needed, the contravariant derivative of *this , with respect to met ...
void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
friend Tenseur contract(const Tenseur &, int id1, int id2)
Self contraction of two indices of a Tenseur .
void dec2_dzpuis()
Decreases by 2 the value of dzpuis and changes accordingly the values of the Cmp in the external comp...
void fait_carre_scal(const Metrique &, int i) const
Calculates, if needed, the scalar square of *this , with respect to met .
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.
Cmp pow(const Cmp &, int)
Power .
const Metrique ** met_depend
Array of pointers on the Metrique 's used to calculate derivatives members.
void inc2_dzpuis()
Increases by 2 the value of dzpuis and changes accordingly the values of the Cmp in the external comp...
void std_base_scal()
Sets the spectral bases of the Valeur va to the standard ones for a scalar.
void set_der_0x0() const
Sets the pointers of all the derivatives to zero.
int fread_be(int *aa, int size, int nb, FILE *fich)
Reads integer(s) from a binary file according to the big endian convention.
Tenseur(const Map &map, const Metrique *met=0x0, double weight=0)
Constructor for a scalar field.
void allocate_all()
Sets the logical state to ETATQCQ (ordinary state) and performs the memory allocation of all the elem...
Bases of the spectral expansions.
void allocate_all()
Sets the logical state to ETATQCQ (ordinary state) and performs the memory allocation of all the elem...
const Base_vect_cart & get_bvect_cart() const
Returns the Cartesian basis associated with the coordinates (x,y,z) of the mapping, i.e.
void dec_dzpuis()
dzpuis -= 1 ;
void set_dependance(const Metrique &met) const
To be used to describe the fact that the derivatives members have been calculated with met ...
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...
const Metrique * metric
For tensor densities: the metric defining the conformal factor.
friend Tenseur manipule(const Tenseur &, const Metrique &, int idx)
Raise or lower the index idx depending on its type, using the given Metrique .
int get_dim(int i) const
Gives the i th dimension (ie {tt dim.dim[i] )
Tenseur ** p_derive_cov
Array of pointers on the covariant derivatives of *this with respect to the corresponding metric in ...
const Tenseur & carre_scal(const Metrique &) const
Returns the scalar square of *this , with respect to met .
void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
const Tenseur & derive_cov(const Metrique &met) const
Returns the covariant derivative of *this , with respect to met .
void del_derive() const
Logical destructor of all the derivatives.
void set_etat_zero()
Sets the logical state to ETATZERO (zero state).
Valeur va
The numerical value of the Cmp.
Tenseur ** p_carre_scal
Array of pointers on the scalar squares of *this with respect to the corresponding metric in *met_de...
void fait_gradient_spher() const
Calculates, if needed, the gradient of *this in a spherical orthonormal basis (scalar field only)...
Tensor handling *** DEPRECATED : use class Tensor instead ***.
void set_etat_nondef()
Sets the logical state to ETATNONDEF (undefined state).
const Tenseur & gradient() const
Returns the gradient of *this (Cartesian coordinates)