/* * Function external to class Tensor for tensor calculus * * */ /* * 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_calculus_ext_C[] = "$Header: /cvsroot/Lorene/C++/Source/Tensor/tensor_calculus_ext.C,v 1.14 2014/10/13 08:53:44 j_novak Exp $" ; /* * $Id: tensor_calculus_ext.C,v 1.14 2014/10/13 08:53:44 j_novak Exp $ * $Log: tensor_calculus_ext.C,v $ * Revision 1.14 2014/10/13 08:53:44 j_novak * Lorene classes and functions now belong to the namespace Lorene. * * Revision 1.13 2014/10/06 15:13:20 j_novak * Modified #include directives to use c++ syntax. * * Revision 1.12 2008/12/05 08:44:02 j_novak * New flag to control the "verbosity" of maxabs. * * Revision 1.11 2004/05/13 21:32:29 e_gourgoulhon * Added functions central_value, max_all_domains, * min_all_domains and maxabs_all_domains. * * Revision 1.10 2004/02/27 21:15:34 e_gourgoulhon * Suppressed function contract_desal (since function contract has now * the boolean argument "desaliasing"). * * Revision 1.9 2004/02/19 22:11:00 e_gourgoulhon * Added argument "comment" in functions max, min, etc... * * Revision 1.8 2004/02/18 18:51:04 e_gourgoulhon * Tensorial product moved from file tensor_calculus.C, since * it is not a method of class Tensor. * * Revision 1.7 2004/02/18 15:56:23 e_gourgoulhon * -- Added function contract for double contraction. * -- Efficiency improved in functions contract: better handling of variable * "work"(work is now a reference on the relevant component of the result). * * Revision 1.6 2004/01/23 08:00:16 e_gourgoulhon * Minor modifs. in output of methods min, max, maxabs, diffrel to * better handle the display in the scalar case. * * Revision 1.5 2004/01/15 10:59:53 f_limousin * Added method contract_desal for the contraction of two tensors with desaliasing * * Revision 1.4 2004/01/14 11:38:32 f_limousin * Added method contract for one tensor * * Revision 1.3 2003/11/05 15:29:36 e_gourgoulhon * Added declaration of externa functions max, min, maxabs, * diffrel and diffrelmax. * * Revision 1.2 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.1 2003/10/06 15:13:38 e_gourgoulhon * Tensor contraction. * * * $Header: /cvsroot/Lorene/C++/Source/Tensor/tensor_calculus_ext.C,v 1.14 2014/10/13 08:53:44 j_novak Exp $ * */ // Headers C #include #include #include // Headers Lorene #include "tensor.h" //-----------------------// // Tensorial product // //-----------------------// namespace Lorene { Tensor operator*(const Tensor& t1, const Tensor& t2) { assert (t1.mp == t2.mp) ; int val_res = t1.valence + t2.valence ; Itbl tipe (val_res) ; for (int i=0 ; i=0) && (ind1=0) && (ind2= 2 ) ; assert( val2 >= 2 ) ; assert( (0<=i1) && (i1= 0) && (ind_1 < val)) ; assert ((ind_2 >= 0) && (ind_2 < val)) ; assert (ind_1 != ind_2) ; assert (source.get_index_type(ind_1) != source.get_index_type(ind_2)) ; // On veut ind_1 < ind_2 : if (ind_1 > ind_2) { int auxi = ind_2 ; ind_2 = ind_1 ; ind_1 = auxi ; } // On construit le resultat : int val_res = val - 2 ; Itbl tipe(val_res) ; for (int i=0 ; i= n_comp_b) { n_comp_max = n_comp_a ; tmax = &aa ; } else { n_comp_max = n_comp_b ; tmax = &bb ; } int nz = aa.get_mp().get_mg()->get_nzone() ; Tbl resu(n_comp_max, nz) ; resu.set_etat_qcq() ; Itbl idx(val) ; for (int ic=0; icindices(ic) ; Tbl diff = diffrel( aa(idx), bb(idx) ) ; if (n_comp_max > 1) ost << " Comp." ; for (int j=0 ; j 1) ost << " : " ; else ost << " " ; for (int l=0; l= n_comp_b) { n_comp_max = n_comp_a ; tmax = &aa ; } else { n_comp_max = n_comp_b ; tmax = &bb ; } int nz = aa.get_mp().get_mg()->get_nzone() ; Tbl resu(n_comp_max, nz) ; resu.set_etat_qcq() ; Itbl idx(val) ; for (int ic=0; icindices(ic) ; Tbl diff = diffrelmax( aa(idx), bb(idx) ) ; if (n_comp_max > 1) ost << " Comp." ; for (int j=0 ; j 1) ost << " : " ; else ost << " " ; for (int l=0; lget_nzone() ; Tbl resu(n_comp, nz) ; resu.set_etat_qcq() ; Itbl idx(val) ; for (int ic=0; ic 0) ost << " Comp." ; for (int j=0 ; j 0) ost << " : " ; else ost << " " ; for (int l=0; lget_nzone() ; Tbl resu(n_comp, nz) ; resu.set_etat_qcq() ; Itbl idx(val) ; for (int ic=0; ic 0) ost << " Comp." ; for (int j=0 ; j 0) ost << " : " ; else ost << " " ; for (int l=0; lget_nzone() ; Tbl resu(n_comp, nz) ; resu.set_etat_qcq() ; Itbl idx(val) ; for (int ic=0; ic 0) ost << " Comp." ; for (int j=0 ; j 0 ) ost << " : " ; else ost << " " ; } for (int l=0; l 0 ) ost << " Comp." ; for (int j=0 ; j 0 ) ost << " : " ; else ost << " " ; ost << aa_c << endl ; } } return resu ; } //-------------------// // max_all_domains // //-------------------// Tbl max_all_domains(const Tensor& aa, int l_excluded, const char* comment, ostream& ost) { if (comment != 0x0) ost << comment << " : " << endl ; Tbl max_dom = max(aa) ; int val = aa.get_valence() ; int n_comp = aa.get_n_comp() ; int nz = aa.get_mp().get_mg()->get_nzone() ; Tbl resu(n_comp) ; resu.set_etat_qcq() ; Itbl idx(val) ; for (int ic=0; ic x0) x0 = x ; } resu.set(ic) = x0 ; if ( comment != 0x0 ) { if ( val > 0 ) ost << " Comp." ; idx = aa.indices(ic) ; for (int j=0 ; j 0 ) ost << " : " ; else ost << " " ; ost << x0 << endl ; } } return resu ; } //-------------------// // min_all_domains // //-------------------// Tbl min_all_domains(const Tensor& aa, int l_excluded, const char* comment, ostream& ost) { if (comment != 0x0) ost << comment << " : " << endl ; Tbl min_dom = min(aa) ; int val = aa.get_valence() ; int n_comp = aa.get_n_comp() ; int nz = aa.get_mp().get_mg()->get_nzone() ; Tbl resu(n_comp) ; resu.set_etat_qcq() ; Itbl idx(val) ; for (int ic=0; ic 0 ) ost << " Comp." ; idx = aa.indices(ic) ; for (int j=0 ; j 0 ) ost << " : " ; else ost << " " ; ost << x0 << endl ; } } return resu ; } //----------------------// // maxabs_all_domains // //----------------------// Tbl maxabs_all_domains(const Tensor& aa, int l_excluded, const char* comment, ostream& ost, bool verb) { if (comment != 0x0) ost << comment << " : " << endl ; Tbl maxabs_dom = maxabs(aa, 0x0, ost, verb) ; int val = aa.get_valence() ; int n_comp = aa.get_n_comp() ; int nz = aa.get_mp().get_mg()->get_nzone() ; Tbl resu(n_comp) ; resu.set_etat_qcq() ; Itbl idx(val) ; for (int ic=0; ic x0) x0 = x ; } resu.set(ic) = x0 ; if ( comment != 0x0 ) { if ( val > 0 ) ost << " Comp." ; idx = aa.indices(ic) ; for (int j=0 ; j 0 ) ost << " : " ; else ost << " " ; ost << x0 << endl ; } } return resu ; } }