/* * Methods of class Tensor * * (see file tensor.h for documentation) * */ /* * Copyright (c) 2003-2004 Eric Gourgoulhon & Jerome Novak * * Copyright (c) 1999-2001 Philippe Grandclement (for preceding class Tenseur) * * This file is part of LORENE. * * LORENE is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * LORENE is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with LORENE; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ char tensor_C[] = "$Header: /cvsroot/Lorene/C++/Source/Tensor/tensor.C,v 1.43 2014/10/13 08:53:44 j_novak Exp $" ; /* * $Id: tensor.C,v 1.43 2014/10/13 08:53:44 j_novak Exp $ * $Log: tensor.C,v $ * Revision 1.43 2014/10/13 08:53:44 j_novak * Lorene classes and functions now belong to the namespace Lorene. * * Revision 1.42 2014/10/06 15:13:20 j_novak * Modified #include directives to use c++ syntax. * * Revision 1.41 2013/06/05 15:43:49 j_novak * Suppression of leg_spectral_base() * * Revision 1.40 2013/01/11 15:44:54 j_novak * Addition of Legendre bases (part 2). * * Revision 1.39 2007/12/21 16:07:08 j_novak * Methods to filter Tensor, Vector and Sym_tensor objects. * * Revision 1.38 2005/10/25 08:56:38 p_grandclement * addition of std_spectral_base in the case of odd functions near the origin * * Revision 1.37 2005/05/18 11:45:44 j_novak * Added del_deriv() calls at the end of inc/dec_dzpuis. * * Revision 1.36 2004/07/08 12:21:53 j_novak * Replaced tensor::annule_extern_c2 with tensor::annule_extern_cn for a * more general transition. * * Revision 1.35 2004/06/17 06:55:07 e_gourgoulhon * Added method annule_extern_c2. * * Revision 1.34 2004/03/04 09:47:51 e_gourgoulhon * Method annule_domain(int, int): added call to virtual function * del_deriv() at the end ! * * Revision 1.33 2004/02/27 21:14:27 e_gourgoulhon * Modif of method derive_con to create proper type of the result. * * Revision 1.32 2004/02/19 22:10:14 e_gourgoulhon * Added argument "comment" in method spectral_display. * * Revision 1.31 2004/02/05 15:03:47 e_gourgoulhon * Corrected bug in method derive_con(). * * Revision 1.30 2004/01/27 13:05:11 j_novak * Removed the method Tensor::mult_r_ced() * * Revision 1.29 2004/01/19 16:32:13 e_gourgoulhon * Added operator()(int, int, int, int) and set(int, int, int, int) * for direct access to components of valence 4 tensors. * * Revision 1.28 2004/01/04 20:55:23 e_gourgoulhon * Method spectral_display(): added printing of type of class (through typeid). * * Revision 1.27 2003/12/30 23:09:47 e_gourgoulhon * Change in methods derive_cov() and divergence() to take into account * the change of name: Metric::get_connect() --> Metric::connect(). * * Revision 1.26 2003/12/27 15:01:50 e_gourgoulhon * Method derive_con(): the position of the derivation index has * been changed from the first one to the last one. * * Revision 1.25 2003/11/03 22:34:41 e_gourgoulhon * Method dec_dzpuis: changed the name of argument dec --> decrem * (in order not to shadow some globally defined dec). * * Revision 1.24 2003/10/29 11:02:54 e_gourgoulhon * Functions dec_dzpuis and inc_dzpuis have now an integer argument to * specify by which amount dzpuis is to be increased. * Accordingly methods dec2_dzpuis and inc2_dzpuis have been suppressed * * Revision 1.23 2003/10/27 10:49:48 e_gourgoulhon * Slightly modified operator<<. * * Revision 1.22 2003/10/19 19:57:00 e_gourgoulhon * -- Added new method spectral_display * -- slightly rearranged the operator<< * * Revision 1.21 2003/10/16 15:27:46 e_gourgoulhon * Name of method annule(int ) changed to annule_domain(int ). * * Revision 1.20 2003/10/16 14:21:36 j_novak * The calculation of the divergence of a Tensor is now possible. * * Revision 1.19 2003/10/13 13:52:40 j_novak * Better managment of derived quantities. * * Revision 1.18 2003/10/11 16:47:10 e_gourgoulhon * Suppressed the call to Ibtl::set_etat_qcq() after the construction * of the Itbl's, thanks to the new property of the Itbl class. * * Revision 1.17 2003/10/11 14:48:40 e_gourgoulhon * Line 344: suppressed assert(resu == -1) * and added a break command to quit the loop. * * Revision 1.16 2003/10/08 14:24:09 j_novak * replaced mult_r_zec with mult_r_ced * * Revision 1.15 2003/10/07 15:25:38 e_gourgoulhon * Added call to del_derive_met in del_deriv(). * * Revision 1.14 2003/10/07 09:10:00 j_novak * Use of ::contract instead of up() * * Revision 1.13 2003/10/06 20:51:43 e_gourgoulhon * In methods set: changed name "indices" to "idx" to avoid shadowing * of class member. * * Revision 1.12 2003/10/06 16:17:31 j_novak * Calculation of contravariant derivative and Ricci scalar. * * Revision 1.11 2003/10/06 13:58:48 j_novak * The memory management has been improved. * Implementation of the covariant derivative with respect to the exact Tensor * type. * * Revision 1.10 2003/10/05 21:11:22 e_gourgoulhon * - Added method std_spectral_base(). * - Removed method change_triad() from this file. * * Revision 1.9 2003/10/03 15:09:38 j_novak * Improved display * * Revision 1.8 2003/10/03 11:21:48 j_novak * More methods for the class Metric * * Revision 1.7 2003/10/01 11:56:31 e_gourgoulhon * Corrected error: '=' replaced by '==' in two assert tests. * * Revision 1.6 2003/09/30 08:38:23 j_novak * added a header typeinfo * * Revision 1.5 2003/09/29 12:52:57 j_novak * Methods for changing the triad are implemented. * * Revision 1.4 2003/09/26 14:33:53 j_novak * Arithmetic functions for the class Tensor * * Revision 1.3 2003/09/24 15:10:54 j_novak * Suppression of the etat flag in class Tensor (still present in Scalar) * * Revision 1.2 2003/09/23 08:52:17 e_gourgoulhon * new version * * Revision 1.1 2003/09/22 12:52:51 e_gourgoulhon * First version: not ready yet ! * * * $Header: /cvsroot/Lorene/C++/Source/Tensor/tensor.C,v 1.43 2014/10/13 08:53:44 j_novak Exp $ * */ // Headers C #include #include #include // Headers Lorene #include "metric.h" #include "utilitaires.h" //--------------// // Constructors // //--------------// // Standard constructor // -------------------- namespace Lorene { Tensor::Tensor(const Map& map, int val, const Itbl& tipe, const Base_vect& triad_i) : mp(&map), valence(val), triad(&triad_i), type_indice(tipe), n_comp(int(pow(3., val))){ // Des verifs : assert (valence >= 0) ; assert (tipe.get_ndim() == 1) ; assert (valence == tipe.get_dim(0)) ; for (int i=0 ; i= 0) ; assert (tipe.get_ndim() == 1) ; assert (valence == tipe.get_dim(0)) ; for (int i=0 ; i= 0) ; assert ((tipe == COV) || (tipe == CON)) ; type_indice = tipe ; cmp = new Scalar*[n_comp] ; for (int i=0 ; iget_mg()), fd) ; set_der_0x0() ; } // Constructor for a scalar field: to be used by the derived // class {\tt Scalar} //----------------------------------------------------------- Tensor::Tensor(const Map& map) : mp(&map), valence(0), triad(0x0), type_indice(0), n_comp(1) { cmp = new Scalar*[n_comp] ; cmp[0] = 0x0 ; set_der_0x0() ; } // Constructor used by the derived classes // --------------------------------------- Tensor::Tensor (const Map& map, int val, const Itbl& tipe, int compo, const Base_vect& triad_i) : mp(&map), valence(val), triad(&triad_i), type_indice(tipe), n_comp(compo) { // Des verifs : assert (valence >= 0) ; assert (tipe.get_ndim() == 1) ; assert (n_comp > 0) ; assert (valence == tipe.get_dim(0)) ; for (int i=0 ; i= 0) ; assert (n_comp >= 0) ; assert ((tipe == COV) || (tipe == CON)) ; type_indice = tipe ; cmp = new Scalar*[n_comp] ; for (int i=0 ; i=0) && (jtensor_depend[i] == this) met_depend[j]->tensor_depend[i] = 0x0 ; if (p_derive_cov[j] != 0x0) delete p_derive_cov[j] ; if (p_derive_con[j] != 0x0) delete p_derive_con[j] ; if (p_divergence[j] != 0x0) delete p_divergence[j] ; set_der_met_0x0(j) ; } } void Tensor::set_der_met_0x0(int i) const { assert( (i>=0) && (iset_etat_qcq() ; } } void Tensor::set_etat_nondef() { del_deriv() ; for (int i=0 ; iset_etat_nondef() ; } } void Tensor::set_etat_zero() { del_deriv() ; for (int i=0 ; iset_etat_zero() ; } } // Allocates everything // -------------------- void Tensor::allocate_all() { del_deriv() ; for (int i=0 ; iallocate_all() ; } } void Tensor::set_triad(const Base_vect& bi) { triad = &bi ; } int Tensor::position (const Itbl& idx) const { assert (idx.get_ndim() == 1) ; assert (idx.get_dim(0) == valence) ; for (int i=0 ; i=1) && (idx(i)<=3)) ; int res = 0 ; for (int i=0 ; i= 0) && (place < n_comp)) ; Itbl res(valence) ; for (int i=valence-1 ; i>=0 ; i--) { res.set(i) = div(place, 3).rem ; place = int((place-res(i))/3) ; res.set(i)++ ; } return res ; } void Tensor::operator=(const Tensor& t) { assert (valence == t.valence) ; triad = t.triad ; for (int i=0 ; iget_mg()->get_nzone()-1) ) { set_etat_zero() ; return ; } // Annulation des composantes: for (int i=0 ; iannule(l_min, l_max) ; } // The derived members are no longer up to date: del_deriv() ; } void Tensor::annule_extern_cn(int lrac, int deg) { // Not applicable in the nucleus nor the CED: assert( mp->get_mg()->get_type_r(lrac) == FIN ) ; int nz = mp->get_mg()->get_nzone() ; #ifndef NDEBUG if ((2*deg+1) >= mp->get_mg()->get_nr(lrac)) cout << "Tensor::annule_extern_cn : \n" << "WARNING!! \n" << "The number of coefficients in r is too low \n" << "to do a clean matching..." << endl ; #endif // Boundary of domain lrac double r_min = mp->val_r(lrac, -1., 0., 0.) ; double r_max = mp->val_r(lrac, 1., 0., 0.) ; //Definition of binomial coefficients array Itbl binom(deg+1, deg+1) ; binom.annule_hard() ; binom.set(0,0) = 1 ; for (int n=1; n<=deg; n++) { binom.set(n,0) = 1 ; for (int k=1; k<=n; k++) binom.set(n,k) = binom(n-1, k) + binom(n-1, k-1) ; } // Coefficient of the second polynomial factor Tbl coef(deg+1) ; coef.set_etat_qcq() ; coef.set(deg) = 1 ; int sg = -1 ; for (int i=deg-1; i>=0; i--) { coef.set(i) = double(r_max*(i+1)*coef(i+1) + sg*binom(deg,i)*(2*deg+1)*pow(r_min,deg-i)) / double(deg+i+1) ; sg *= -1 ; } // Normalization to have 1 at r_min double aa = coef(deg) ; for (int i = deg-1; i>=0; i--) aa = r_min*aa + coef(i) ; aa *= pow(r_min - r_max, deg+1) ; aa = 1/aa ; Mtbl mr = mp->r ; Tbl rr = mr(lrac) ; Tbl poly(rr) ; poly = coef(deg) ; for (int i=deg-1; i>=0; i--) poly = rr*poly + coef(i) ; poly *= aa*pow((rr-r_max), deg+1) ; Scalar rac(*mp) ; rac.allocate_all() ; for (int l=0; ldec_dzpuis(decrem) ; del_deriv() ; } void Tensor::inc_dzpuis(int inc) { for (int i=0 ; iinc_dzpuis(inc) ; del_deriv() ; } // Le cout : ostream& operator<<(ostream& flux, const Tensor &source ) { flux << '\n' ; flux << "Lorene class : " << typeid(source).name() << " Valence : " << source.valence << '\n' ; if (source.get_triad() != 0x0) { flux << "Vectorial basis (triad) on which the components are defined :" << '\n' ; flux << *(source.get_triad()) << '\n' ; } if (source.valence != 0) { flux << "Type of the indices : " ; for (int i=0 ; ispectral_display(0x0, thres, precis, ost) ; ost << '\n' ; } } void Tensor::sauve(FILE* fd) const { type_indice.sauve(fd) ; // type des composantes fwrite_be(&valence, sizeof(int), 1, fd) ; // la valence if (valence != 0) { triad->sauve(fd) ; // Vectorial basis } fwrite_be(&n_comp, sizeof(int), 1, fd) ; // nbre composantes for (int i=0 ; isauve(fd) ; } // Sets the standard spectal bases of decomposition for each component void Tensor::std_spectral_base() { switch (valence) { case 0 : { cmp[0]->std_spectral_base() ; break ; } case 1 : { cout << "Tensor::std_spectral_base: should not be called on a Tensor" << " of valence 1 but on a Vector !" << endl ; abort() ; break ; } case 2 : { Base_val** bases = 0x0 ; if( triad->identify() == (mp->get_bvect_cart()).identify() ) { bases = mp->get_mg()->std_base_vect_cart() ; } else { assert( triad->identify() == (mp->get_bvect_spher()).identify()) ; bases = mp->get_mg()->std_base_vect_spher() ; } Itbl ind(2) ; for (int i=0 ; iset_spectral_base( (*bases[ind(0)-1]) * (*bases[ind(1)-1]) ) ; } for (int i=0 ; i<3 ; i++) { delete bases[i] ; } delete [] bases ; break ; } default : { cout << "Tensor::std_spectral_base: the case valence = " << valence << " is not treated yet !" << endl ; abort() ; break ; } } } // Sets the standard spectal bases of decomposition for each component (odd in the nucleus) void Tensor::std_spectral_base_odd() { switch (valence) { case 0 : { cmp[0]->std_spectral_base_odd() ; break ; } default : { cout << "Tensor::std_spectral_base_odd: the case valence = " << valence << " is not treated yet !" << endl ; abort() ; break ; } } } const Tensor& Tensor::derive_cov(const Metric& metre) const { set_dependance(metre) ; int j = get_place_met(metre) ; assert ((j>=0) && (j=0) && (j(this) ; if (tsym != 0x0) { // symmetric case, preserved by derive_con const Tensor& dercov = derive_cov(metre) ; Itbl type_ind = dercov.get_index_type() ; type_ind.set(valence) = CON ; p_derive_con[j] = new Tensor_sym(*mp, valence+1, type_ind, *triad, tsym->sym_index1(), tsym->sym_index2()) ; *(p_derive_con[j]) = contract(dercov, valence, metre.con(), 0) ; // valence is the number of the last index of derive_cov // (the "derivation" index) } else { // general case, no symmetry p_derive_con[j] = new Tensor( contract(derive_cov(metre), valence, metre.con(), 0) ) ; // valence is the number of the last index of derive_cov // (the "derivation" index) } } } return *p_derive_con[j] ; } const Tensor& Tensor::divergence(const Metric& metre) const { set_dependance(metre) ; int j = get_place_met(metre) ; assert ((j>=0) && (jidentify() == (mp->get_bvect_cart()).identify() ) for (int i=0; iexponential_filter_r(lzmin, lzmax, p, alpha) ; else { cout << "Tensor::exponential_filter_r : " << endl ; cout << "Only Cartesian triad is implemented!" << endl ; cout << "Exiting..." << endl ; abort() ; } } void Tensor::exponential_filter_ylm(int lzmin, int lzmax, int p, double alpha) { if( triad->identify() == (mp->get_bvect_cart()).identify() ) for (int i=0; iexponential_filter_ylm(lzmin, lzmax, p, alpha) ; else { cout << "Tensor::exponential_filter_ylm : " << endl ; cout << "Only Cartesian triad is implemented!" << endl ; cout << "Exiting..." << endl ; abort() ; } } }