189 #include "metrique.h" 190 #include "utilitaires.h" 207 for (
int i=0; i<N_MET_MAX; i++) {
216 mp(&map), valence(0), triad(0x0),
217 type_indice(0), n_comp(1), etat(ETATNONDEF), poids(weight),
231 mp(ci.get_mp()), valence(0), triad(0x0),
232 type_indice(0), n_comp(1), etat(ci.get_etat()), poids(weight),
235 assert(ci.
get_etat() != ETATNONDEF) ;
241 assert( ci.
get_etat() == ETATQCQ ) ;
253 const Base_vect& triad_i,
const Metrique* met,
double weight)
254 : mp(&map), valence(val), triad(&triad_i), type_indice(tipe),
255 n_comp(int(
pow(3., val))), etat(ETATNONDEF), poids(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)
276 : mp(&map), valence(val), triad(triad_i), type_indice(tipe),
277 n_comp(int(
pow(3., val))), etat(ETATNONDEF), poids(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)
305 : mp(&map), valence(val), triad(&triad_i), type_indice(val),
306 n_comp(int(
pow(3., val))), etat (ETATNONDEF), poids(weight),
311 assert ((tipe == COV) || (tipe == CON)) ;
317 for (
int i=0 ; i<
n_comp ; i++)
325 mp(source.mp), valence(source.valence), triad(source.triad),
326 type_indice(source.type_indice), etat (source.etat), poids(source.poids),
327 metric(source.metric) {
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++) {
373 mp(source.mp), valence(source.valence), triad(source.triad),
374 type_indice(source.type_indice), etat(source.etat),
375 poids(source.poids), metric(source.metric) {
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++) {
419 : mp(&mapping), triad(&triad_i), type_indice(fd),
426 assert( *triad_fich == *
triad) ;
437 for (
int i=0 ; i<
n_comp ; i++)
440 for (
int i=0 ; i<
n_comp ; i++)
455 : mp(&mapping), type_indice(fd), metric(met){
471 if (
etat == ETATQCQ) {
492 const Base_vect& triad_i,
const Metrique* met,
double weight) :
493 mp(&map), valence(val), triad(&triad_i), type_indice(tipe), n_comp(compo),
494 etat (ETATNONDEF), poids(weight), metric(met) {
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) :
517 mp(&map), valence(val), triad(&triad_i), type_indice(val), n_comp(compo),
518 etat (ETATNONDEF), poids(weight), metric(met) {
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++) {
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)) ;
919 assert(
etat != ETATNONDEF ) ;
921 if (
etat == ETATZERO ) {
925 assert(
etat == ETATQCQ ) ;
928 for (
int i=0 ; i<
n_comp ; i++) {
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 ;
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 ;
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 ;
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 ;
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 ;
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++)
1125 if (
etat == ETATZERO) {
1129 assert(
etat == ETATQCQ) ;
1131 for (
int i=0 ; i<
n_comp ; i++)
1138 if (
etat == ETATZERO) {
1142 assert(
etat == ETATQCQ) ;
1144 for (
int i=0 ; i<
n_comp ; i++)
1151 if (
etat == ETATZERO) {
1155 assert(
etat == ETATQCQ) ;
1157 for (
int i=0 ; i<
n_comp ; i++)
1164 if (
etat == ETATZERO) {
1168 assert(
etat == ETATQCQ) ;
1170 for (
int i=0 ; i<
n_comp ; i++)
1178 if (
etat == ETATZERO) {
1182 assert(
etat == ETATQCQ) ;
1196 for (
int i=0 ; i<3 ; i++)
1197 (
c[i]->va).set_base( *bases[i] ) ;
1198 for (
int i=0 ; i<3 ; i++)
1206 for (
int i=0 ; i<3 ; i++)
1207 (
c[i]->va).set_base( *bases[i] ) ;
1208 for (
int i=0 ; i<3 ; i++)
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++)
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 ;
1262 ostream& 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) ;
1466 indices_gamma.
set(idx) = indices(idx-1) ;
1468 indices_gamma.
set(idx) = indices(idx) ;
1483 indices_gamma.
set(0) = indices(i+1) ;
1484 indices_gamma.
set(1) = indices(0) ;
1487 indices_gamma.
set(idx) = indices(idx-1) ;
1489 indices_gamma.
set(idx) = indices(idx) ;
1537 for (
int indice=1 ; indice<
valence ; indice++) {
1540 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)