32 char tensor_C[] =
"$Header: /cvsroot/Lorene/C++/Source/Tensor/tensor.C,v 1.43 2014/10/13 08:53:44 j_novak Exp $" ;
193 #include "utilitaires.h"
204 : mp(&map), valence(val), triad(&triad_i), type_indice(tipe),
205 n_comp(int(
pow(3., val))){
211 for (
int i=0 ; i<
valence ; i++)
212 assert ((tipe(i) == COV) || (tipe(i) == CON)) ;
216 for (
int i=0 ; i<
n_comp ; i++)
227 : mp(&map), valence(val), triad(triad_i), type_indice(tipe),
228 n_comp(int(
pow(3., val))){
234 for (
int i=0 ; i<
valence ; i++)
235 assert ((tipe(i) == COV) || (tipe(i) == CON)) ;
239 for (
int i=0 ; i<
n_comp ; i++)
252 : mp(&map), valence(val), triad(&triad_i), type_indice(val),
253 n_comp(int(
pow(3., val))){
257 assert ((tipe == COV) || (tipe == CON)) ;
263 for (
int i=0 ; i<
n_comp ; i++)
272 mp(source.mp), valence(source.valence), triad(source.triad),
273 type_indice(source.type_indice) {
278 for (
int i=0 ; i<
n_comp ; i++) {
296 : mp(&mapping), triad(&triad_i), type_indice(fd){
302 assert( *triad_fich == *
triad) ;
312 for (
int i=0 ; i<
n_comp ; i++)
323 type_indice(0), n_comp(1) {
336 mp(&map), valence(val), triad(&triad_i), type_indice(tipe), n_comp(compo)
344 for (
int i=0 ; i<
valence ; i++)
345 assert ((tipe(i) == COV) || (tipe(i) == CON)) ;
349 for (
int i=0 ; i<
n_comp ; i++)
361 mp(&map), valence(val), triad(&triad_i), type_indice(val), n_comp(compo)
367 assert ((tipe == COV) || (tipe == CON)) ;
373 for (
int i=0 ; i<
n_comp ; i++)
389 for (
int i=0 ; i<
n_comp ; i++) {
400 for (
int i=0; i<N_MET_MAX; i++)
409 for (
int i=0; i<N_MET_MAX; i++)
416 assert( (j>=0) && (j<N_MET_MAX) ) ;
419 for (
int i=0 ; i<N_TENSOR_DEPEND ; i++)
435 assert( (i>=0) && (i<N_MET_MAX) ) ;
445 for (
int i=0; i<N_MET_MAX; i++)
457 for (
int i=0; i<N_MET_MAX; i++) {
459 if ((!deja) && (
met_depend[i] != 0x0)) nmet++ ;
461 if (nmet == N_MET_MAX) {
462 cout <<
"Too many metrics in Tensor::set_dependances" << endl ;
467 while ((conte < N_TENSOR_DEPEND) && (met.
tensor_depend[conte] != 0x0))
470 if (conte == N_TENSOR_DEPEND) {
471 cout <<
"Too many dependancies in Tensor::set_dependances " << endl ;
484 for (
int i=0 ; i<
n_comp ; i++) {
492 for (
int i=0 ; i<
n_comp ; i++) {
500 for (
int i=0 ; i<
n_comp ; i++) {
511 for (
int i=0 ; i<
n_comp ; i++) {
530 for (
int i=0 ; i<
valence ; i++)
531 assert ((idx(i)>=1) && (idx(i)<=3)) ;
533 for (
int i=0 ; i<
valence ; i++)
534 res = 3*res+(idx(i)-1) ;
541 assert ((place >= 0) && (place <
n_comp)) ;
545 for (
int i=
valence-1 ; i>=0 ; i--) {
546 res.
set(i) = div(place, 3).rem ;
547 place = int((place-res(i))/3) ;
559 for (
int i=0 ; i<
valence ; i++)
562 for (
int i=0 ; i<
n_comp ; i++) {
564 *
cmp[i] = *t.
cmp[place_t] ;
575 for (
int i=0 ; i<
valence ; i++)
578 for (
int i=0 ; i<
n_comp ; i++) {
580 *
cmp[i] += *t.
cmp[place_t] ;
591 for (
int i=0 ; i<
valence ; i++)
594 for (
int i=0 ; i<
n_comp ; i++) {
596 *
cmp[i] -= *t.
cmp[place_t] ;
680 for (
int i=0 ; i<
n_comp ; i++) {
698 cout <<
"Tensor::annule_extern_cn : \n"
700 <<
"The number of coefficients in r is too low \n"
701 <<
"to do a clean matching..." << endl ;
704 double r_min =
mp->
val_r(lrac, -1., 0., 0.) ;
705 double r_max =
mp->
val_r(lrac, 1., 0., 0.) ;
708 Itbl binom(deg+1, deg+1) ;
711 for (
int n=1; n<=deg; n++) {
713 for (
int k=1; k<=n; k++)
714 binom.
set(n,k) = binom(n-1, k) + binom(n-1, k-1) ;
722 for (
int i=deg-1; i>=0; i--) {
724 coef.
set(i) = double(r_max*(i+1)*coef(i+1)
725 + sg*binom(deg,i)*(2*deg+1)*
pow(r_min,deg-i))
731 double aa = coef(deg) ;
732 for (
int i = deg-1; i>=0; i--)
733 aa = r_min*aa + coef(i) ;
734 aa *=
pow(r_min - r_max, deg+1) ;
742 for (
int i=deg-1; i>=0; i--)
743 poly = rr*poly + coef(i) ;
744 poly *= aa*
pow((rr-r_max), deg+1) ;
748 for (
int l=0; l<lrac; l++) rac.
set_domain(l) = 1 ;
753 for (
int ic=0; ic<
n_comp; ic++) *(
cmp[ic]) *= rac ;
765 idx.
set(0) = indice1 ;
766 idx.
set(1) = indice2 ;
776 idx.
set(0) = indice1 ;
777 idx.
set(1) = indice2 ;
778 idx.
set(2) = indice3 ;
789 idx.
set(0) = indice1 ;
790 idx.
set(1) = indice2 ;
791 idx.
set(2) = indice3 ;
792 idx.
set(3) = indice4 ;
810 for (
int i=0 ; i<
n_comp ; i++)
818 for (
int i=0 ; i<
n_comp ; i++)
826 ostream& operator<<(ostream& flux,
const Tensor &source ) {
829 flux <<
"Lorene class : " <<
typeid(source).name()
830 <<
" Valence : " << source.
valence <<
'\n' ;
833 flux <<
"Vectorial basis (triad) on which the components are defined :"
839 flux <<
"Type of the indices : " ;
840 for (
int i=0 ; i<source.
valence ; i++) {
841 flux <<
"index " << i <<
" : " ;
843 flux <<
" contravariant." <<
'\n' ;
845 flux <<
" covariant." <<
'\n' ;
846 if ( i < source.
valence-1 ) flux <<
" " ;
851 for (
int i=0 ; i<source.
n_comp ; i++) {
855 "===================== Scalar field ========================= \n" ;
858 flux <<
"================ Component " ;
859 Itbl num_indices = source.
indices(i) ;
860 for (
int j=0 ; j<source.
valence ; j++) {
861 flux <<
" " << num_indices(j) ;
863 flux <<
" ================ \n" ;
867 flux << *source.
cmp[i] <<
'\n' ;
875 double thres,
int precis, ostream& ost)
const {
877 if (comment != 0x0) {
878 ost << comment <<
" : " << endl ;
881 ost <<
"Lorene class : " <<
typeid(*this).name()
882 <<
" Valence : " <<
valence <<
'\n' ;
884 for (
int ic=0; ic<
n_comp; ic++) {
888 "===================== Scalar field ========================= \n" ;
891 ost <<
"================ Component " ;
893 for (
int j=0 ; j<
valence ; j++) {
894 ost <<
" " << num_indices(j) ;
896 ost <<
" ================ \n" ;
916 for (
int i=0 ; i<
n_comp ; i++)
937 "Tensor::std_spectral_base: should not be called on a Tensor"
938 <<
" of valence 1 but on a Vector !" << endl ;
955 for (
int i=0 ; i<
n_comp ; i++) {
958 (*bases[ind(1)-1]) ) ;
961 for (
int i=0 ; i<3 ; i++) {
972 cout <<
"Tensor::std_spectral_base: the case valence = " <<
valence
973 <<
" is not treated yet !" << endl ;
993 cout <<
"Tensor::std_spectral_base_odd: the case valence = " <<
valence
994 <<
" is not treated yet !" << endl ;
1006 assert ((j>=0) && (j<N_MET_MAX)) ;
1018 assert ((j>=0) && (j<N_MET_MAX)) ;
1059 assert ((j>=0) && (j<N_MET_MAX)) ;
1069 for (
int i=0; i<
n_comp; i++)
1072 cout <<
"Tensor::exponential_filter_r : " << endl ;
1073 cout <<
"Only Cartesian triad is implemented!" << endl ;
1074 cout <<
"Exiting..." << endl ;
1082 for (
int i=0; i<
n_comp; i++)
1085 cout <<
"Tensor::exponential_filter_ylm : " << endl ;
1086 cout <<
"Only Cartesian triad is implemented!" << endl ;
1087 cout <<
"Exiting..." << endl ;
void set_dependance(const Metric &) const
To be used to describe the fact that the derivatives members have been calculated with met .
void sauve(FILE *) const
Save in a file.
virtual void spectral_display(const char *comment=0x0, double threshold=1.e-7, int precision=4, ostream &ostr=cout) const
Displays the spectral coefficients and the associated basis functions.
double & set(int i)
Read/write of a particular element (index i) (1D case)
Bases of the spectral expansions.
virtual void exponential_filter_r(int lzmin, int lzmax, int p, double alpha=-16.)
Applies exponential filters to all components (see Scalar::exponential_filter_r ).
const Tensor & derive_cov(const Metric &gam) const
Returns the covariant derivative of this with respect to some metric .
Metric for tensor calculation.
virtual void std_spectral_base_odd()
Sets the spectral bases of the Valeur va to the standard odd ones for a scalar field.
void set_spectral_base(const Base_val &)
Sets the spectral bases of the Valeur va
virtual void set_etat_nondef()
Sets the logical state of all components to ETATNONDEF (undefined state).
Symmetric tensors (with respect to two of their arguments).
virtual void del_deriv() const
Deletes the derived quantities.
int & set(int i)
Read/write of a particular element (index i ) (1D case)
virtual Tensor * p_divergence(const Tensor &tens) const
Computes the divergence of a tensor (with respect to the current connection).
const Scalar & operator()(const Itbl &ind) const
Returns the value of a component (read-only version).
int sym_index1() const
Number of the first symmetric index (0<= id_sym1 < valence )
virtual ~Tensor()
Destructor.
static Base_vect * bvect_from_file(FILE *)
Construction of a vectorial basis from a file (see sauve(FILE* ) ).
virtual void set_etat_zero()
Sets the logical state of all components to ETATZERO (zero state).
void annule_extern_cn(int l_0, int deg)
Performs a smooth (C^n) transition in a given domain to zero.
const Base_vect_spher & get_bvect_spher() const
Returns the orthonormal vectorial basis associated with the coordinates of the mapping.
const Mg3d * get_mg() const
Gives the Mg3d on which the mapping is defined.
int get_dim(int i) const
Gives the i th dimension (ie {tt dim.dim[i] )
void set_der_0x0() const
Sets the pointers on derived quantities to 0x0.
virtual void annule(int l_min, int l_max)
Sets the Tensor to zero in several domains.
virtual void dec_dzpuis(int dec=1)
Decreases by dec units the value of dzpuis and changes accordingly the values in the compactified ext...
void operator+=(const Tensor &)
+= Tensor
Coord r
r coordinate centered on the grid
Scalar ** cmp
Array of size n_comp of pointers onto the components.
int get_place_met(const Metric &) const
Returns the position of the pointer on metre in the array met_depend .
Tensor * p_derive_con[N_MET_MAX]
Array of pointers on the contravariant derivatives of this with respect to various metrics.
virtual double val_r(int l, double xi, double theta, double pphi) const =0
Returns the value of the radial coordinate r for a given in a given domain.
int get_type_r(int l) const
Returns the type of sampling in the radial direction in domain no.
const Metric * met_depend[N_MET_MAX]
Array on the Metric 's which were used to compute derived quantities, like p_derive_cov ,...
const Tensor * tensor_depend[N_TENSOR_DEPEND]
Pointer on the dependancies, that means the array contains pointers on all the Tensor whom derivative...
Basic integer array class.
Tensor field of valence 0 (or component of a tensorial field).
Cmp pow(const Cmp &, int)
Power .
void annule_domain(int l)
Sets the Tensor to zero in a given domain.
void annule_hard()
Sets the Itbl to zero in a hard way.
Tensor * p_divergence[N_MET_MAX]
Array of pointers on the divergence of this with respect to various metrics.
virtual int identify() const =0
Returns a number to identify the sub-classe of Base_vect the object belongs to.
int get_ndim() const
Gives the number of dimensions (ie dim.ndim )
virtual void set_etat_qcq()
Sets the logical state of all components to ETATQCQ (ordinary state).
virtual void operator=(const Tensor &)
Assignment to a Tensor.
void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
Scalar & set(const Itbl &ind)
Returns the value of a component (read/write version).
virtual int position(const Itbl &ind) const
Returns the position in the array cmp of a component given by its indices.
const Map *const mp
Mapping on which the numerical values at the grid points are defined.
virtual const Sym_tensor & con() const
Read-only access to the contravariant representation.
virtual void std_spectral_base()
Sets the standard spectal bases of decomposition for each component.
virtual void sauve(FILE *) const
Save in a file.
virtual Tensor * p_derive_cov(const Tensor &tens) const
Computes the covariant derivative of a tensor (with respect to the current connection).
virtual void allocate_all()
Sets the logical state to ETATQCQ (ordinary state) and performs the memory allocation of all the elem...
int get_nzone() const
Returns the number of domains.
int get_index_type(int i) const
Gives the type (covariant or contravariant) of the index number i .
const Base_vect * triad
Vectorial basis (triad) with respect to which the tensor components are defined.
int get_nr(int l) const
Returns the number of points in the radial direction ( ) in domain no. l.
int fread_be(int *aa, int size, int nb, FILE *fich)
Reads integer(s) from a binary file according to the big endian convention.
virtual void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
const Base_vect_cart & get_bvect_cart() const
Returns the Cartesian basis associated with the coordinates (x,y,z) of the mapping,...
virtual void exponential_filter_ylm(int lzmin, int lzmax, int p, double alpha=-16.)
Applies exponential filters to all components (see Scalar::exponential_filter_ylm ).
virtual void annule(int l_min, int l_max)
Sets the Scalar to zero in several domains.
Base_val ** std_base_vect_cart() const
Returns the standard spectral bases for the Cartesian components of a vector.
virtual void set_etat_zero()
Sets the logical state to ETATZERO (zero).
Tensor field of valence 1.
Tensor(const Map &map, int val, const Itbl &tipe, const Base_vect &triad_i)
Standard constructor.
const Tensor & derive_con(const Metric &gam) const
Returns the "contravariant" derivative of this with respect to some metric , by raising the last inde...
const Tensor & divergence(const Metric &gam) const
Computes the divergence of this with respect to some metric .
Itbl type_indice
1D array of integers (class Itbl ) of size valence containing the type of each index: COV for a cov...
void set_der_met_0x0(int) const
Sets all the i-th components of met_depend , p_derive_cov , etc...
virtual Itbl indices(int pos) const
Returns the indices of a component given by its position in the array cmp .
Tensor * p_derive_cov[N_MET_MAX]
Array of pointers on the covariant derivatives of this with respect to various metrics.
int valence
Valence of the tensor (0 = scalar, 1 = vector, etc...)
const Base_vect * get_triad() const
Returns the vectorial basis (triad) on which the components are defined.
int sym_index2() const
Number of the second symmetric index (id_sym1 < id_sym2 < valence )
virtual void inc_dzpuis(int inc=1)
Increases by inc units the value of dzpuis and changes accordingly the values in the compactified ext...
Tbl & set_domain(int l)
Read/write of the value in a given domain.
virtual void std_spectral_base()
Sets the spectral bases of the Valeur va to the standard ones for a scalar field.
virtual void spectral_display(const char *comment=0x0, double threshold=1.e-7, int precision=4, ostream &ostr=cout) const
Displays the spectral coefficients and the associated basis functions of each component.
virtual void allocate_all()
Performs the memory allocation of all the elements, down to the double arrays of the Tbl s.
virtual void del_derive_met(int) const
Logical destructor of the derivatives depending on the i-th element of met_depend .
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.
virtual void std_spectral_base_odd()
Sets the standard odd spectal bases of decomposition for each component.
Base_val ** std_base_vect_spher() const
Returns the standard spectral bases for the spherical components of a vector.
void set_triad(const Base_vect &new_triad)
Assigns a new vectorial basis (triad) of decomposition.
virtual void set_etat_nondef()
Sets the logical state to ETATNONDEF (undefined).
int n_comp
Number of stored components, depending on the symmetry.
Base class for coordinate mappings.
Vectorial bases (triads) with respect to which the tensorial components are defined.
virtual void sauve(FILE *) const
Save in a binary file.
void operator-=(const Tensor &)
-= Tensor
virtual const Connection & connect() const
Returns the connection.
Tenseur contract(const Tenseur &, int id1, int id2)
Self contraction of two indices of a Tenseur .