202 #include "utilitaires.h" 213 : mp(&map), valence(val), triad(&triad_i), type_indice(tipe),
214 n_comp(int(
pow(3., val))){
220 for (
int i=0 ; i<
valence ; i++)
221 assert ((tipe(i) == COV) || (tipe(i) == CON)) ;
225 for (
int i=0 ; i<
n_comp ; i++)
236 : mp(&map), valence(val), triad(triad_i), type_indice(tipe),
237 n_comp(int(
pow(3., val))){
243 for (
int i=0 ; i<
valence ; i++)
244 assert ((tipe(i) == COV) || (tipe(i) == CON)) ;
248 for (
int i=0 ; i<
n_comp ; i++)
261 : mp(&map), valence(val), triad(&triad_i), type_indice(val),
262 n_comp(int(
pow(3., val))){
266 assert ((tipe == COV) || (tipe == CON)) ;
272 for (
int i=0 ; i<
n_comp ; i++)
281 mp(source.mp), valence(source.valence), triad(source.triad),
282 type_indice(source.type_indice) {
287 for (
int i=0 ; i<
n_comp ; i++) {
305 : mp(&mapping), triad(&triad_i), type_indice(fd){
311 assert( *triad_fich == *
triad) ;
321 for (
int i=0 ; i<
n_comp ; i++)
332 type_indice(0), n_comp(1) {
345 mp(&map), valence(val), triad(&triad_i), type_indice(tipe), n_comp(compo)
353 for (
int i=0 ; i<
valence ; i++)
354 assert ((tipe(i) == COV) || (tipe(i) == CON)) ;
358 for (
int i=0 ; i<
n_comp ; i++)
370 mp(&map), valence(val), triad(&triad_i), type_indice(val), n_comp(compo)
376 assert ((tipe == COV) || (tipe == CON)) ;
382 for (
int i=0 ; i<
n_comp ; i++)
398 for (
int i=0 ; i<
n_comp ; i++) {
409 for (
int i=0; i<N_MET_MAX; i++)
418 for (
int i=0; i<N_MET_MAX; i++)
425 assert( (j>=0) && (j<N_MET_MAX) ) ;
428 for (
int i=0 ; i<N_TENSOR_DEPEND ; i++)
444 assert( (i>=0) && (i<N_MET_MAX) ) ;
454 for (
int i=0; i<N_MET_MAX; i++)
466 for (
int i=0; i<N_MET_MAX; i++) {
468 if ((!deja) && (
met_depend[i] != 0x0)) nmet++ ;
470 if (nmet == N_MET_MAX) {
471 cout <<
"Too many metrics in Tensor::set_dependances" << endl ;
476 while ((conte < N_TENSOR_DEPEND) && (met.
tensor_depend[conte] != 0x0))
479 if (conte == N_TENSOR_DEPEND) {
480 cout <<
"Too many dependancies in Tensor::set_dependances " << endl ;
493 for (
int i=0 ; i<
n_comp ; i++) {
501 for (
int i=0 ; i<
n_comp ; i++) {
509 for (
int i=0 ; i<
n_comp ; i++) {
520 for (
int i=0 ; i<
n_comp ; i++) {
539 for (
int i=0 ; i<
valence ; i++)
540 assert ((idx(i)>=1) && (idx(i)<=3)) ;
542 for (
int i=0 ; i<
valence ; i++)
543 res = 3*res+(idx(i)-1) ;
550 assert ((place >= 0) && (place <
n_comp)) ;
554 for (
int i=
valence-1 ; i>=0 ; i--) {
555 res.
set(i) = div(place, 3).rem ;
556 place = int((place-res(i))/3) ;
568 for (
int i=0 ; i<
valence ; i++)
571 for (
int i=0 ; i<
n_comp ; i++) {
573 *
cmp[i] = *t.
cmp[place_t] ;
584 for (
int i=0 ; i<
valence ; i++)
587 for (
int i=0 ; i<
n_comp ; i++) {
589 *
cmp[i] += *t.
cmp[place_t] ;
600 for (
int i=0 ; i<
valence ; i++)
603 for (
int i=0 ; i<
n_comp ; i++) {
605 *
cmp[i] -= *t.
cmp[place_t] ;
689 for (
int i=0 ; i<
n_comp ; i++) {
707 cout <<
"Tensor::annule_extern_cn : \n" 709 <<
"The number of coefficients in r is too low \n" 710 <<
"to do a clean matching..." << endl ;
713 double r_min =
mp->
val_r(lrac, -1., 0., 0.) ;
714 double r_max =
mp->
val_r(lrac, 1., 0., 0.) ;
717 Itbl binom(deg+1, deg+1) ;
720 for (
int n=1; n<=deg; n++) {
722 for (
int k=1; k<=n; k++)
723 binom.
set(n,k) = binom(n-1, k) + binom(n-1, k-1) ;
731 for (
int i=deg-1; i>=0; i--) {
733 coef.
set(i) = double(r_max*(i+1)*coef(i+1)
734 + sg*binom(deg,i)*(2*deg+1)*
pow(r_min,deg-i))
740 double aa = coef(deg) ;
741 for (
int i = deg-1; i>=0; i--)
742 aa = r_min*aa + coef(i) ;
743 aa *=
pow(r_min - r_max, deg+1) ;
751 for (
int i=deg-1; i>=0; i--)
752 poly = rr*poly + coef(i) ;
753 poly *= aa*
pow((rr-r_max), deg+1) ;
757 for (
int l=0; l<lrac; l++) rac.
set_domain(l) = 1 ;
762 for (
int ic=0; ic<
n_comp; ic++) *(
cmp[ic]) *= rac ;
774 idx.
set(0) = indice1 ;
775 idx.
set(1) = indice2 ;
785 idx.
set(0) = indice1 ;
786 idx.
set(1) = indice2 ;
787 idx.
set(2) = indice3 ;
798 idx.
set(0) = indice1 ;
799 idx.
set(1) = indice2 ;
800 idx.
set(2) = indice3 ;
801 idx.
set(3) = indice4 ;
819 for (
int i=0 ; i<
n_comp ; i++)
827 for (
int i=0 ; i<
n_comp ; i++)
835 ostream& operator<<(ostream& flux,
const Tensor &source ) {
838 flux <<
"Lorene class : " <<
typeid(source).name()
839 <<
" Valence : " << source.
valence <<
'\n' ;
842 flux <<
"Vectorial basis (triad) on which the components are defined :" 848 flux <<
"Type of the indices : " ;
849 for (
int i=0 ; i<source.
valence ; i++) {
850 flux <<
"index " << i <<
" : " ;
852 flux <<
" contravariant." <<
'\n' ;
854 flux <<
" covariant." <<
'\n' ;
855 if ( i < source.
valence-1 ) flux <<
" " ;
860 for (
int i=0 ; i<source.
n_comp ; i++) {
864 "===================== Scalar field ========================= \n" ;
867 flux <<
"================ Component " ;
868 Itbl num_indices = source.
indices(i) ;
869 for (
int j=0 ; j<source.
valence ; j++) {
870 flux <<
" " << num_indices(j) ;
872 flux <<
" ================ \n" ;
876 flux << *source.
cmp[i] <<
'\n' ;
884 double thres,
int precis, ostream& ost)
const {
886 if (comment != 0x0) {
887 ost << comment <<
" : " << endl ;
890 ost <<
"Lorene class : " <<
typeid(*this).name()
891 <<
" Valence : " <<
valence <<
'\n' ;
893 for (
int ic=0; ic<
n_comp; ic++) {
897 "===================== Scalar field ========================= \n" ;
900 ost <<
"================ Component " ;
902 for (
int j=0 ; j<
valence ; j++) {
903 ost <<
" " << num_indices(j) ;
905 ost <<
" ================ \n" ;
925 for (
int i=0 ; i<
n_comp ; i++)
946 "Tensor::std_spectral_base: should not be called on a Tensor" 947 <<
" of valence 1 but on a Vector !" << endl ;
964 for (
int i=0 ; i<
n_comp ; i++) {
967 (*bases[ind(1)-1]) ) ;
970 for (
int i=0 ; i<3 ; i++) {
981 cout <<
"Tensor::std_spectral_base: the case valence = " <<
valence 982 <<
" is not treated yet !" << endl ;
1002 cout <<
"Tensor::std_spectral_base_odd: the case valence = " <<
valence 1003 <<
" is not treated yet !" << endl ;
1015 assert ((j>=0) && (j<N_MET_MAX)) ;
1027 assert ((j>=0) && (j<N_MET_MAX)) ;
1068 assert ((j>=0) && (j<N_MET_MAX)) ;
1078 for (
int i=0; i<
n_comp; i++)
1081 cout <<
"Tensor::exponential_filter_r : " << endl ;
1082 cout <<
"Only Cartesian triad is implemented!" << endl ;
1083 cout <<
"Exiting..." << endl ;
1091 for (
int i=0; i<
n_comp; i++)
1094 cout <<
"Tensor::exponential_filter_ylm : " << endl ;
1095 cout <<
"Only Cartesian triad is implemented!" << endl ;
1096 cout <<
"Exiting..." << endl ;
1104 for (
int i=0; i<
n_comp; i++)
1107 cout <<
"Tensor::exponential_filter_ylm : " << endl ;
1108 cout <<
"Only Cartesian triad is implemented!" << endl ;
1109 cout <<
"Exiting..." << endl ;
void annule_domain(int l)
Sets the Tensor to zero in a given domain.
Base_val ** std_base_vect_cart() const
Returns the standard spectral bases for the Cartesian components of a vector.
Metric for tensor calculation.
virtual void set_etat_qcq()
Sets the logical state of all components to ETATQCQ (ordinary state).
virtual const Sym_tensor & con() const
Read-only access to the contravariant representation.
virtual void operator=(const Tensor &)
Assignment to a Tensor.
int & set(int i)
Read/write of a particular element (index i ) (1D case)
int n_comp
Number of stored components, depending on the symmetry.
virtual void set_etat_zero()
Sets the logical state to ETATZERO (zero).
virtual void annule(int l_min, int l_max)
Sets the Scalar to zero in several domains.
int sym_index1() const
Number of the first symmetric index (0<= id_sym1 < valence )
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 )
virtual void del_derive_met(int) const
Logical destructor of the derivatives depending on the i-th element of met_depend ...
void set_dependance(const Metric &) const
To be used to describe the fact that the derivatives members have been calculated with met ...
const Mg3d * get_mg() const
Gives the Mg3d on which the mapping is defined.
void annule_hard()
Sets the Itbl to zero in a hard way.
double & set(int i)
Read/write of a particular element (index i) (1D case)
Tensor field of valence 0 (or component of a tensorial field).
virtual void set_etat_nondef()
Sets the logical state of all components to ETATNONDEF (undefined state).
virtual void sauve(FILE *) const
Save in a file.
Base class for coordinate mappings.
virtual Tensor * p_derive_cov(const Tensor &tens) const
Computes the covariant derivative of a tensor (with respect to the current connection).
int sym_index2() const
Number of the second symmetric index (id_sym1 < id_sym2 < valence )
Basic integer array class.
virtual void std_spectral_base()
Sets the spectral bases of the Valeur va to the standard ones for a scalar field. ...
const Base_vect * triad
Vectorial basis (triad) with respect to which the tensor components are defined.
virtual void sauve(FILE *) const
Save in a binary file.
virtual void std_spectral_base_odd()
Sets the standard odd spectal bases of decomposition for each component.
virtual void allocate_all()
Sets the logical state to ETATQCQ (ordinary state) and performs the memory allocation of all the elem...
virtual void set_etat_nondef()
Sets the logical state to ETATNONDEF (undefined).
virtual void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
int get_place_met(const Metric &) const
Returns the position of the pointer on metre in the array met_depend .
Tensor field of valence 1.
Vectorial bases (triads) with respect to which the tensorial components are defined.
Tbl & set_domain(int l)
Read/write of the value in a given domain.
virtual void exponential_filter_ylm_phi(int lzmin, int lzmax, int p_r, int p_tet, int p_phi, double alpha=-16.)
Applies exponential filters to all components (see Scalar::exponential_filter_ylm_phi )...
static Base_vect * bvect_from_file(FILE *)
Construction of a vectorial basis from a file (see sauve(FILE* ) ).
Tensor * p_derive_cov[N_MET_MAX]
Array of pointers on the covariant derivatives of this with respect to various metrics.
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 set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
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 ).
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.
void operator-=(const Tensor &)
-= Tensor
Itbl type_indice
1D array of integers (class Itbl ) of size valence containing the type of each index: COV for a cova...
const Base_vect * get_triad() const
Returns the vectorial basis (triad) on which the components are defined.
virtual int position(const Itbl &ind) const
Returns the position in the array cmp of a component given by its indices.
int get_index_type(int i) const
Gives the type (covariant or contravariant) of the index number i .
virtual void allocate_all()
Performs the memory allocation of all the elements, down to the double arrays of the Tbl s...
virtual const Connection & connect() const
Returns the connection.
Scalar ** cmp
Array of size n_comp of pointers onto the components.
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.
void sauve(FILE *) const
Save in a file.
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.
virtual void std_spectral_base_odd()
Sets the spectral bases of the Valeur va to the standard odd ones for a scalar field.
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.
Tensor * p_derive_con[N_MET_MAX]
Array of pointers on the contravariant derivatives of this with respect to various metrics...
Cmp pow(const Cmp &, int)
Power .
Tenseur contract(const Tenseur &, int id1, int id2)
Self contraction of two indices of a Tenseur .
const Tensor & derive_cov(const Metric &gam) const
Returns the covariant derivative of this with respect to some metric .
const Tensor & divergence(const Metric &gam) const
Computes the divergence of this with respect to some metric .
virtual void del_deriv() const
Deletes the derived quantities.
virtual void inc_dzpuis(int inc=1)
Increases by inc units the value of dzpuis and changes accordingly the values in the compactified ext...
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.
void set_spectral_base(const Base_val &)
Sets the spectral bases of the Valeur va
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 ~Tensor()
Destructor.
int valence
Valence of the tensor (0 = scalar, 1 = vector, etc...)
int get_nr(int l) const
Returns the number of points in the radial direction ( ) in domain no. l.
Tensor * p_divergence[N_MET_MAX]
Array of pointers on the divergence of this with respect to various metrics.
void operator+=(const Tensor &)
+= Tensor
const Tensor & derive_con(const Metric &gam) const
Returns the "contravariant" derivative of this with respect to some metric , by raising the last inde...
Bases of the spectral expansions.
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 )...
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 set_der_met_0x0(int) const
Sets all the i-th components of met_depend , p_derive_cov , etc...
const Metric * met_depend[N_MET_MAX]
Array on the Metric 's which were used to compute derived quantities, like p_derive_cov ...
Scalar & set(const Itbl &ind)
Returns the value of a component (read/write version).
void annule_extern_cn(int l_0, int deg)
Performs a smooth (C^n) transition in a given domain to zero.
const Tensor * tensor_depend[N_TENSOR_DEPEND]
Pointer on the dependancies, that means the array contains pointers on all the Tensor whom derivative...
int get_dim(int i) const
Gives the i th dimension (ie {tt dim.dim[i] )
const Scalar & operator()(const Itbl &ind) const
Returns the value of a component (read-only version).
void set_triad(const Base_vect &new_triad)
Assigns a new vectorial basis (triad) of decomposition.
virtual void set_etat_zero()
Sets the logical state of all components to ETATZERO (zero state).
Symmetric tensors (with respect to two of their arguments).
void set_der_0x0() const
Sets the pointers on derived quantities to 0x0.
int get_type_r(int l) const
Returns the type of sampling in the radial direction in domain no.
const Map *const mp
Mapping on which the numerical values at the grid points are defined.
virtual void annule(int l_min, int l_max)
Sets the Tensor to zero in several domains.
virtual void std_spectral_base()
Sets the standard spectal bases of decomposition for each component.
virtual Itbl indices(int pos) const
Returns the indices of a component given by its position in the array cmp .
Coord r
r coordinate centered on the grid
Tensor(const Map &map, int val, const Itbl &tipe, const Base_vect &triad_i)
Standard constructor.
virtual Tensor * p_divergence(const Tensor &tens) const
Computes the divergence of a tensor (with respect to the current connection).