tensor_calculus_ext.C

00001 /*
00002  *  Function external to class Tensor for tensor calculus
00003  *
00004  *
00005  */
00006 
00007 /*
00008  *   Copyright (c) 2003-2004 Eric Gourgoulhon & Jerome Novak
00009  *
00010  *   Copyright (c) 1999-2001 Philippe Grandclement (for preceding class Tenseur)
00011  *
00012  *   This file is part of LORENE.
00013  *
00014  *   LORENE is free software; you can redistribute it and/or modify
00015  *   it under the terms of the GNU General Public License as published by
00016  *   the Free Software Foundation; either version 2 of the License, or
00017  *   (at your option) any later version.
00018  *
00019  *   LORENE is distributed in the hope that it will be useful,
00020  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00021  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022  *   GNU General Public License for more details.
00023  *
00024  *   You should have received a copy of the GNU General Public License
00025  *   along with LORENE; if not, write to the Free Software
00026  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00027  *
00028  */
00029 
00030 
00031 char tensor_calculus_ext_C[] = "$Header: /cvsroot/Lorene/C++/Source/Tensor/tensor_calculus_ext.C,v 1.12 2008/12/05 08:44:02 j_novak Exp $" ;
00032 
00033 /*
00034  * $Id: tensor_calculus_ext.C,v 1.12 2008/12/05 08:44:02 j_novak Exp $
00035  * $Log: tensor_calculus_ext.C,v $
00036  * Revision 1.12  2008/12/05 08:44:02  j_novak
00037  * New flag to control the "verbosity" of maxabs.
00038  *
00039  * Revision 1.11  2004/05/13 21:32:29  e_gourgoulhon
00040  * Added functions central_value, max_all_domains,
00041  *  min_all_domains and maxabs_all_domains.
00042  *
00043  * Revision 1.10  2004/02/27 21:15:34  e_gourgoulhon
00044  * Suppressed function contract_desal (since function contract has now
00045  * the boolean argument "desaliasing").
00046  *
00047  * Revision 1.9  2004/02/19 22:11:00  e_gourgoulhon
00048  * Added argument "comment" in functions max, min, etc...
00049  *
00050  * Revision 1.8  2004/02/18 18:51:04  e_gourgoulhon
00051  * Tensorial product moved from file tensor_calculus.C, since
00052  * it is not a method of class Tensor.
00053  *
00054  * Revision 1.7  2004/02/18 15:56:23  e_gourgoulhon
00055  * -- Added function contract for double contraction.
00056  * -- Efficiency improved in functions contract: better handling of variable
00057  *    "work"(work is now a reference on the relevant component of the result).
00058  *
00059  * Revision 1.6  2004/01/23 08:00:16  e_gourgoulhon
00060  * Minor modifs. in output of methods min, max, maxabs, diffrel to
00061  * better handle the display in the scalar case.
00062  *
00063  * Revision 1.5  2004/01/15 10:59:53  f_limousin
00064  * Added method contract_desal for the contraction of two tensors with desaliasing
00065  *
00066  * Revision 1.4  2004/01/14 11:38:32  f_limousin
00067  * Added method contract for one tensor
00068  *
00069  * Revision 1.3  2003/11/05 15:29:36  e_gourgoulhon
00070  *  Added declaration of externa functions max, min, maxabs,
00071  * diffrel and diffrelmax.
00072  *
00073  * Revision 1.2  2003/10/11 16:47:10  e_gourgoulhon
00074  * Suppressed the call to Ibtl::set_etat_qcq() after the construction
00075  * of the Itbl's, thanks to the new property of the Itbl class.
00076  *
00077  * Revision 1.1  2003/10/06 15:13:38  e_gourgoulhon
00078  * Tensor contraction.
00079  *
00080  *
00081  * $Header: /cvsroot/Lorene/C++/Source/Tensor/tensor_calculus_ext.C,v 1.12 2008/12/05 08:44:02 j_novak Exp $
00082  *
00083  */
00084 
00085 // Headers C
00086 #include <stdlib.h>
00087 #include <assert.h>
00088 #include <math.h>
00089 
00090 // Headers Lorene
00091 #include "tensor.h"
00092 
00093 
00094 
00095                 //-----------------------//
00096                 //   Tensorial product   //
00097                 //-----------------------//
00098 
00099 
00100 Tensor operator*(const Tensor& t1, const Tensor& t2) {
00101    
00102     assert (t1.mp == t2.mp) ;
00103     
00104     int val_res = t1.valence + t2.valence ;
00105      
00106     Itbl tipe (val_res) ;
00107   
00108     for (int i=0 ; i<t1.valence ; i++)
00109     tipe.set(i) = t1.type_indice(i) ;
00110     for (int i=0 ; i<t2.valence ; i++)
00111     tipe.set(i+t1.valence) = t2.type_indice(i) ;
00112     
00113     
00114     if ( (t1.valence != 0) && (t2.valence != 0) ) {
00115     assert ( *(t1.get_triad()) == *(t2.get_triad()) ) ;
00116     }
00117     
00118     const Base_vect* triad_res ; 
00119     if (t1.valence != 0) {
00120     triad_res = t1.get_triad() ; 
00121     }
00122     else{
00123     triad_res = t2.get_triad() ; 
00124     }
00125     
00126     Tensor res(*t1.mp, val_res, tipe, triad_res) ;
00127     
00128     Itbl jeux_indice_t1 (t1.valence) ;
00129     Itbl jeux_indice_t2 (t2.valence) ;
00130         
00131     for (int i=0 ; i<res.n_comp ; i++) {
00132     Itbl jeux_indice_res(res.indices(i)) ;
00133     for (int j=0 ; j<t1.valence ; j++)
00134         jeux_indice_t1.set(j) = jeux_indice_res(j) ;
00135     for (int j=0 ; j<t2.valence ; j++)
00136         jeux_indice_t2.set(j) = jeux_indice_res(j+t1.valence) ;
00137     
00138     res.set(jeux_indice_res) = t1(jeux_indice_t1)*t2(jeux_indice_t2) ;
00139     }
00140     
00141     return res ;
00142 }
00143 
00144 
00145 
00146 
00147                 //------------------//
00148                 //   Contraction    //
00149                 //------------------//
00150 
00151 // Contraction on one index
00152 // ------------------------
00153 Tensor contract(const Tensor& t1, int ind1, const Tensor& t2, int ind2,
00154                 bool desaliasing) {
00155     
00156     int val1 = t1.get_valence() ; 
00157     int val2 = t2.get_valence() ; 
00158 
00159     // Verifs :
00160     assert((ind1>=0) && (ind1<val1)) ;
00161     assert((ind2>=0) && (ind2<val2)) ;
00162     assert(t1.get_mp() == t2.get_mp()) ;
00163     
00164     // Contraction possible ?
00165     if ( (val1 != 0) && (val2 != 0) ) {
00166         assert ( *(t1.get_triad()) == *(t2.get_triad()) ) ;
00167     }
00168     assert (t1.get_index_type(ind1) != t2.get_index_type(ind2)) ;
00169     
00170     int val_res = val1 + val2 - 2;
00171     
00172     Itbl tipe(val_res) ;
00173 
00174     for (int i=0 ; i<ind1 ; i++)
00175         tipe.set(i) = t1.get_index_type(i) ;
00176     for (int i=ind1 ; i<val1-1 ; i++)
00177         tipe.set(i) = t1.get_index_type(i+1) ;
00178     for (int i=val1-1 ; i<val1+ind2-1 ; i++)
00179         tipe.set(i) = t2.get_index_type(i-val1+1) ;
00180     for (int i = val1+ind2-1 ; i<val_res ; i++)
00181         tipe.set(i) = t2.get_index_type(i-val1+2) ;
00182     
00183     const Base_vect* triad_res = (val_res == 0) ? 0x0 : t1.get_triad() ; 
00184 
00185     Tensor res(t1.get_mp(), val_res, tipe, triad_res) ;
00186     
00187     // Boucle sur les composantes de res :
00188     
00189     Itbl jeux_indice_t1(val1) ;
00190     Itbl jeux_indice_t2(val2) ;
00191     
00192     for (int i=0 ; i<res.get_n_comp() ; i++) {
00193     
00194         Itbl jeux_indice_res(res.indices(i)) ;
00195         
00196         for (int j=0 ; j<ind1 ; j++)
00197             jeux_indice_t1.set(j) = jeux_indice_res(j) ;
00198             
00199         for (int j=ind1+1 ; j<val1 ; j++)
00200             jeux_indice_t1.set(j) = jeux_indice_res(j-1) ;
00201 
00202         for (int j=0 ; j<ind2 ; j++)
00203             jeux_indice_t2.set(j) = jeux_indice_res(val1+j-1) ;
00204 
00205         for (int j=ind2+1 ; j<val2 ; j++)
00206             jeux_indice_t2.set(j) = jeux_indice_res(val1+j-2) ;
00207     
00208         Scalar& work = res.set(jeux_indice_res) ;
00209         work.set_etat_zero() ;
00210 
00211         for (int j=1 ; j<=3 ; j++) {
00212             jeux_indice_t1.set(ind1) = j ;
00213             jeux_indice_t2.set(ind2) = j ;
00214             if (desaliasing) {
00215                 work += t1(jeux_indice_t1) % t2(jeux_indice_t2) ;
00216             }
00217             else {
00218                 work += t1(jeux_indice_t1) * t2(jeux_indice_t2) ;
00219             }
00220         }
00221         
00222     }
00223     
00224     return res ;
00225 }
00226 
00227 
00228 
00229 // Contraction on two indices
00230 // --------------------------
00231 Tensor contract(const Tensor& t1, int i1, int j1, 
00232                 const Tensor& t2, int i2, int j2,
00233                 bool desaliasing) {
00234     
00235     int val1 = t1.get_valence() ; 
00236     int val2 = t2.get_valence() ; 
00237 
00238     // Verifs :
00239     assert( val1 >= 2 ) ; 
00240     assert( val2 >= 2 ) ; 
00241     assert( (0<=i1) && (i1<j1) && (j1<val1) ) ;
00242     assert( (0<=i2) && (i2<j2) && (j2<val2) ) ;
00243     assert( t1.get_mp() == t2.get_mp() ) ;
00244     
00245     // Contraction possible ?
00246     assert( *(t1.get_triad()) == *(t2.get_triad()) ) ;
00247     assert( t1.get_index_type(i1) != t2.get_index_type(i2) ) ;
00248     assert( t1.get_index_type(j1) != t2.get_index_type(j2) ) ;
00249     
00250     int val_res = val1 + val2 - 4 ;
00251     
00252     Itbl tipe(val_res) ;
00253 
00254     for (int i=0 ; i<i1 ; i++) 
00255         tipe.set(i) = t1.get_index_type(i) ;
00256 
00257     for (int i=i1 ; i<j1-1 ; i++) 
00258         tipe.set(i) = t1.get_index_type(i+1) ;
00259 
00260     for (int i=j1-1 ; i<val1-2 ; i++) 
00261         tipe.set(i) = t1.get_index_type(i+2) ;
00262 
00263     for (int i=val1-2 ; i<val1-2+i2 ; i++)
00264         tipe.set(i) = t2.get_index_type(i-val1+2) ;
00265         
00266     for (int i=val1-2+i2 ; i<val1+j2-3 ; i++)
00267         tipe.set(i) = t2.get_index_type(i-val1+3) ;
00268     
00269     for (int i=val1+j2-3 ; i<val_res ; i++) 
00270         tipe.set(i) = t2.get_index_type(i-val1+4) ;
00271     
00272     const Base_vect* triad_res = (val_res == 0) ? 0x0 : t1.get_triad() ; 
00273 
00274     Tensor res(t1.get_mp(), val_res, tipe, triad_res) ;
00275     
00276     // Boucle sur les composantes de res :
00277     
00278     Itbl jeux_indice_t1(val1) ;
00279     Itbl jeux_indice_t2(val2) ;
00280     
00281     for (int ic=0 ; ic<res.get_n_comp() ; ic++) {
00282     
00283         Itbl jeux_indice_res(res.indices(ic)) ;
00284         
00285         for (int k=0 ; k<i1 ; k++)
00286             jeux_indice_t1.set(k) = jeux_indice_res(k) ;
00287             
00288         for (int k=i1+1 ; k<j1 ; k++)
00289             jeux_indice_t1.set(k) = jeux_indice_res(k-1) ;
00290 
00291         for (int k=j1+1 ; k<val1 ; k++)
00292             jeux_indice_t1.set(k) = jeux_indice_res(k-2) ;
00293 
00294         for (int k=0 ; k<i2 ; k++)
00295             jeux_indice_t2.set(k) = jeux_indice_res(val1+k-2) ;
00296 
00297         for (int k=i2+1 ; k<j2 ; k++)
00298             jeux_indice_t2.set(k) = jeux_indice_res(val1+k-3) ;
00299     
00300         for (int k=j2+1 ; k<val2 ; k++)
00301             jeux_indice_t2.set(k) = jeux_indice_res(val1+k-4) ;
00302     
00303         Scalar& work = res.set(jeux_indice_res) ;
00304         work.set_etat_zero() ;
00305 
00306         for (int i=1 ; i<=3 ; i++) {
00307 
00308             jeux_indice_t1.set(i1) = i ; 
00309             jeux_indice_t2.set(i2) = i ; 
00310             
00311             for (int j=1 ; j<=3 ; j++) {
00312 
00313                 jeux_indice_t1.set(j1) = j ;
00314                 jeux_indice_t2.set(j2) = j ;
00315             
00316                 if (desaliasing) {
00317                     work += t1(jeux_indice_t1) % t2(jeux_indice_t2) ;
00318                 }
00319                 else {
00320                     work += t1(jeux_indice_t1) * t2(jeux_indice_t2) ;
00321                 }
00322             }
00323         }
00324         
00325     }
00326     
00327     return res ;
00328 }
00329 
00330 
00331 
00332 
00333 Tensor contract(const Tensor& source, int ind_1, int ind_2) {
00334     
00335     int val = source.get_valence() ;   
00336 
00337     // Les verifications :
00338     assert ((ind_1 >= 0) && (ind_1 < val)) ;
00339     assert ((ind_2 >= 0) && (ind_2 < val)) ;
00340     assert (ind_1 != ind_2) ;
00341     assert (source.get_index_type(ind_1) != source.get_index_type(ind_2)) ;
00342 
00343     // On veut ind_1 < ind_2 :
00344     if (ind_1 > ind_2) {
00345         int auxi = ind_2 ;
00346         ind_2 = ind_1 ;
00347         ind_1 = auxi ;
00348     }
00349     
00350     // On construit le resultat :
00351     int val_res = val - 2 ;
00352    
00353     Itbl tipe(val_res) ;
00354     
00355     for (int i=0 ; i<ind_1 ; i++)
00356         tipe.set(i) = source.get_index_type(i) ;
00357     for (int i=ind_1 ; i<ind_2-1 ; i++)
00358         tipe.set(i) = source.get_index_type(i+1) ;
00359     for (int i = ind_2-1 ; i<val_res ; i++)
00360         tipe.set(i) = source.get_index_type(i+2) ;
00361     
00362     Tensor res(source.get_mp(), val_res, tipe, source.get_triad()) ; 
00363     
00364     // Boucle sur les composantes de res :
00365     
00366     Itbl jeux_indice_source(val) ;
00367     
00368     for (int i=0 ; i<res.get_n_comp() ; i++) {
00369 
00370         Itbl jeux_indice_res(res.indices(i)) ;
00371         
00372         for (int j=0 ; j<ind_1 ; j++)
00373             jeux_indice_source.set(j) = jeux_indice_res(j) ;
00374         for (int j=ind_1+1 ; j<ind_2 ; j++)
00375             jeux_indice_source.set(j) = jeux_indice_res(j-1) ;
00376         for (int j=ind_2+1 ; j<val ; j++)
00377             jeux_indice_source.set(j) = jeux_indice_res(j-2) ;
00378         
00379         Scalar& work = res.set(jeux_indice_res) ;
00380         work.set_etat_zero() ;
00381 
00382         for (int j=1 ; j<=3 ; j++) {
00383             jeux_indice_source.set(ind_1) = j ;
00384             jeux_indice_source.set(ind_2) = j ;
00385             work += source(jeux_indice_source) ;
00386         }
00387         
00388     }
00389     
00390     return res ;
00391 }
00392 
00393 
00394 
00395 
00396                 //------------------//
00397                 //     diffrel      //
00398                 //------------------//
00399 
00400 
00401 Tbl diffrel(const Tensor& aa, const Tensor& bb, const char* comment,
00402             ostream& ost) {
00403 
00404         if (comment != 0x0) ost << comment << " : " << endl ; 
00405 
00406     int val = aa.get_valence() ; 
00407 
00408     assert(bb.get_valence() == val) ; 
00409     
00410     int n_comp_a = aa.get_n_comp() ; 
00411     int n_comp_b = bb.get_n_comp() ; 
00412     
00413     const Tensor* tmax ; 
00414     int n_comp_max ; 
00415     if (n_comp_a >= n_comp_b) {
00416         n_comp_max = n_comp_a ; 
00417         tmax = &aa ; 
00418     }
00419     else {
00420         n_comp_max = n_comp_b ; 
00421         tmax = &bb ; 
00422     }
00423     
00424     int nz = aa.get_mp().get_mg()->get_nzone() ; 
00425     Tbl resu(n_comp_max, nz) ; 
00426     resu.set_etat_qcq() ; 
00427 
00428     Itbl idx(val) ; 
00429     
00430     for (int ic=0; ic<n_comp_max; ic++) {
00431         idx = tmax->indices(ic) ; 
00432         Tbl diff = diffrel( aa(idx), bb(idx) ) ; 
00433         
00434         if (n_comp_max > 1) ost << "   Comp." ; 
00435         for (int j=0 ; j<val ; j++) {
00436             ost << " " << idx(j) ;
00437         }
00438         if (n_comp_max > 1) ost << " : " ; 
00439                 else ost << "   " ;
00440         for (int l=0; l<nz; l++) {
00441             ost << "  " << diff(l) ;
00442             resu.set(ic, l) = diff(l) ; 
00443         }
00444         ost << "\n" ; 
00445         
00446     }
00447     
00448     return resu ; 
00449 }
00450 
00451 
00452                 //--------------------//
00453                 //     diffrelmax     //
00454                 //--------------------//
00455 
00456 
00457 Tbl diffrelmax(const Tensor& aa, const Tensor& bb, const char* comment,
00458                ostream& ost) {
00459 
00460         if (comment != 0x0) ost << comment << " : " << endl ; 
00461 
00462     int val = aa.get_valence() ; 
00463 
00464     assert(bb.get_valence() == val) ; 
00465     
00466     int n_comp_a = aa.get_n_comp() ; 
00467     int n_comp_b = bb.get_n_comp() ; 
00468     
00469     const Tensor* tmax ; 
00470     int n_comp_max ; 
00471     if (n_comp_a >= n_comp_b) {
00472         n_comp_max = n_comp_a ; 
00473         tmax = &aa ; 
00474     }
00475     else {
00476         n_comp_max = n_comp_b ; 
00477         tmax = &bb ; 
00478     }
00479     
00480     int nz = aa.get_mp().get_mg()->get_nzone() ; 
00481     Tbl resu(n_comp_max, nz) ; 
00482     resu.set_etat_qcq() ; 
00483 
00484     Itbl idx(val) ; 
00485     
00486     for (int ic=0; ic<n_comp_max; ic++) {
00487         idx = tmax->indices(ic) ; 
00488         Tbl diff = diffrelmax( aa(idx), bb(idx) ) ; 
00489         
00490         if (n_comp_max > 1) ost << "   Comp." ; 
00491         for (int j=0 ; j<val ; j++) {
00492             ost << " " << idx(j) ;
00493         }
00494         if (n_comp_max > 1) ost << " : " ; 
00495                 else ost << "   " ;
00496         for (int l=0; l<nz; l++) {
00497             ost << "  " << diff(l) ;
00498             resu.set(ic, l) = diff(l) ; 
00499         }
00500         ost << "\n" ; 
00501         
00502     }
00503     
00504     return resu ; 
00505 }
00506 
00507 
00508 
00509                 //----------------//
00510                 //     max    //
00511                 //----------------//
00512 
00513 
00514 Tbl max(const Tensor& aa, const char* comment, ostream& ost) {
00515 
00516         if (comment != 0x0) ost << comment << " : " << endl ; 
00517 
00518     int val = aa.get_valence() ; 
00519 
00520     int n_comp = aa.get_n_comp() ; 
00521     
00522     int nz = aa.get_mp().get_mg()->get_nzone() ; 
00523     Tbl resu(n_comp, nz) ; 
00524     resu.set_etat_qcq() ; 
00525 
00526     Itbl idx(val) ; 
00527     
00528     for (int ic=0; ic<n_comp; ic++) {
00529 
00530         idx = aa.indices(ic) ; 
00531         Tbl diff = max( aa(idx) ) ; 
00532         
00533         if (val > 0) ost << "   Comp." ; 
00534         for (int j=0 ; j<val ; j++) {
00535             ost << " " << idx(j) ;
00536         }
00537         if (val > 0) ost << " : " ; 
00538                 else ost << "   " ;
00539         for (int l=0; l<nz; l++) {
00540             ost << "  " << diff(l) ;
00541             resu.set(ic, l) = diff(l) ; 
00542         }
00543         ost << "\n" ; 
00544         
00545     }
00546     
00547     return resu ; 
00548 }
00549 
00550 
00551 
00552                 //----------------//
00553                 //     min    //
00554                 //----------------//
00555 
00556 
00557 Tbl min(const Tensor& aa, const char* comment, ostream& ost) {
00558 
00559         if (comment != 0x0) ost << comment << " : " << endl ; 
00560 
00561     int val = aa.get_valence() ; 
00562 
00563     int n_comp = aa.get_n_comp() ; 
00564     
00565     int nz = aa.get_mp().get_mg()->get_nzone() ; 
00566     Tbl resu(n_comp, nz) ; 
00567     resu.set_etat_qcq() ; 
00568 
00569     Itbl idx(val) ; 
00570     
00571     for (int ic=0; ic<n_comp; ic++) {
00572 
00573         idx = aa.indices(ic) ; 
00574         Tbl diff = min( aa(idx) ) ; 
00575         
00576         if (val > 0) ost << "   Comp." ; 
00577         for (int j=0 ; j<val ; j++) {
00578             ost << " " << idx(j) ;
00579         }
00580         if (val > 0) ost << " : " ; 
00581                 else ost << "   " ;
00582         for (int l=0; l<nz; l++) {
00583             ost << "  " << diff(l) ;
00584             resu.set(ic, l) = diff(l) ; 
00585         }
00586         ost << "\n" ; 
00587         
00588     }
00589     
00590     return resu ; 
00591 }
00592 
00593 
00594                 //--------------------//
00595                 //     maxabs         //
00596                 //--------------------//
00597 
00598 
00599 Tbl maxabs(const Tensor& aa, const char* comment, ostream& ost, bool verb) {
00600 
00601         if (comment != 0x0) ost << comment << " : " << endl ; 
00602 
00603     int val = aa.get_valence() ; 
00604 
00605     int n_comp = aa.get_n_comp() ; 
00606     
00607     int nz = aa.get_mp().get_mg()->get_nzone() ; 
00608     Tbl resu(n_comp, nz) ; 
00609     resu.set_etat_qcq() ; 
00610 
00611     Itbl idx(val) ; 
00612     
00613     for (int ic=0; ic<n_comp; ic++) {
00614 
00615         idx = aa.indices(ic) ; 
00616         Tbl diff = max( abs( aa(idx) ) ) ; 
00617         
00618         if (verb) {
00619         if (val > 0) ost << "   Comp." ; 
00620         for (int j=0 ; j<val ; j++) {
00621             ost << " " << idx(j) ;
00622                 }
00623         if (val > 0 ) ost << " : " ; 
00624                 else ost << "   " ; 
00625         }
00626         for (int l=0; l<nz; l++) {
00627         if (verb) ost << "  " << diff(l) ;
00628         resu.set(ic, l) = diff(l) ; 
00629         }
00630         if (verb) ost << "\n" ; 
00631         
00632     }
00633     
00634     return resu ; 
00635 }
00636 
00637 
00638         //-------------------//
00639         //  Central value    //
00640         //-------------------//
00641 
00642 Tbl central_value(const Tensor& aa, const char* comment, ostream& ost) {
00643 
00644     if (comment != 0x0) ost << comment << " : " << endl ; 
00645 
00646     int val = aa.get_valence() ; 
00647     int n_comp = aa.get_n_comp() ; 
00648     
00649     Tbl resu(n_comp) ; 
00650     resu.set_etat_qcq() ; 
00651 
00652     Itbl idx(val) ; 
00653     
00654     for (int ic=0; ic<n_comp; ic++) {
00655 
00656         idx = aa.indices(ic) ;
00657         double aa_c = aa(idx).val_grid_point(0,0,0,0) ; 
00658         resu.set(ic) = aa_c ; 
00659         
00660         if ( comment != 0x0 ) {
00661             if ( val > 0 ) ost << "   Comp." ; 
00662                 for (int j=0 ; j<val ; j++) {
00663                     ost << " " << idx(j) ;
00664             }
00665             if (val > 0 ) ost << " : " ; 
00666                 else ost << "   " ; 
00667             ost << aa_c << endl ; 
00668         }
00669         
00670     }
00671     
00672     return resu ; 
00673 }
00674     
00675 
00676         //-------------------//
00677         //  max_all_domains  //
00678         //-------------------//
00679 
00680 Tbl max_all_domains(const Tensor& aa, int l_excluded, const char* comment, 
00681         ostream& ost) {
00682 
00683     if (comment != 0x0) ost << comment << " : " << endl ; 
00684 
00685     Tbl max_dom = max(aa) ; 
00686     
00687     int val = aa.get_valence() ; 
00688     int n_comp = aa.get_n_comp() ; 
00689     int nz = aa.get_mp().get_mg()->get_nzone() ; 
00690     
00691     Tbl resu(n_comp) ; 
00692     resu.set_etat_qcq() ; 
00693 
00694     Itbl idx(val) ; 
00695     
00696     for (int ic=0; ic<n_comp; ic++) {
00697 
00698         double x0 ; 
00699         if (l_excluded != 0) x0 = max_dom(ic, 0) ;
00700         else x0 = max_dom(ic, 1) ; 
00701         for (int l=0; l<nz; l++) {
00702             if (l == l_excluded) continue ; 
00703             double x = max_dom(ic,l) ; 
00704             if (x > x0) x0 = x ; 
00705         }
00706         
00707         resu.set(ic) = x0 ; 
00708         
00709         if ( comment != 0x0 ) {
00710             if ( val > 0 ) ost << "   Comp." ; 
00711                 idx = aa.indices(ic) ;
00712                 for (int j=0 ; j<val ; j++) {
00713                     ost << " " << idx(j) ;
00714             }
00715             if (val > 0 ) ost << " : " ; 
00716                 else ost << "   " ; 
00717             ost << x0 << endl ; 
00718         }
00719         
00720     }
00721     
00722     return resu ; 
00723         
00724 }
00725 
00726         //-------------------//
00727         //  min_all_domains  //
00728         //-------------------//
00729 
00730 Tbl min_all_domains(const Tensor& aa, int l_excluded, const char* comment, 
00731         ostream& ost) {
00732 
00733     if (comment != 0x0) ost << comment << " : " << endl ; 
00734 
00735     Tbl min_dom = min(aa) ; 
00736     
00737     int val = aa.get_valence() ; 
00738     int n_comp = aa.get_n_comp() ; 
00739     int nz = aa.get_mp().get_mg()->get_nzone() ; 
00740     
00741     Tbl resu(n_comp) ; 
00742     resu.set_etat_qcq() ; 
00743 
00744     Itbl idx(val) ; 
00745     
00746     for (int ic=0; ic<n_comp; ic++) {
00747 
00748         double x0 ; 
00749         if (l_excluded != 0) x0 = min_dom(ic, 0) ;
00750         else x0 = min_dom(ic, 1) ; 
00751         for (int l=0; l<nz; l++) {
00752             if (l == l_excluded) continue ; 
00753             double x = min_dom(ic,l) ; 
00754             if (x < x0) x0 = x ; 
00755         }
00756         
00757         resu.set(ic) = x0 ; 
00758         
00759         if ( comment != 0x0 ) {
00760             if ( val > 0 ) ost << "   Comp." ; 
00761                 idx = aa.indices(ic) ;
00762                 for (int j=0 ; j<val ; j++) {
00763                     ost << " " << idx(j) ;
00764             }
00765             if (val > 0 ) ost << " : " ; 
00766                 else ost << "   " ; 
00767             ost << x0 << endl ; 
00768         }
00769         
00770     }
00771     
00772     return resu ; 
00773         
00774 }
00775 
00776 
00777         //----------------------//
00778         //  maxabs_all_domains  //
00779         //----------------------//
00780 
00781 Tbl maxabs_all_domains(const Tensor& aa, int l_excluded, const char* comment, 
00782         ostream& ost, bool verb) {
00783 
00784     if (comment != 0x0) ost << comment << " : " << endl ; 
00785 
00786     Tbl maxabs_dom = maxabs(aa, 0x0, ost, verb) ; 
00787     
00788     int val = aa.get_valence() ; 
00789     int n_comp = aa.get_n_comp() ; 
00790     int nz = aa.get_mp().get_mg()->get_nzone() ; 
00791     
00792     Tbl resu(n_comp) ; 
00793     resu.set_etat_qcq() ; 
00794 
00795     Itbl idx(val) ; 
00796     
00797     for (int ic=0; ic<n_comp; ic++) {
00798 
00799         double x0 ; 
00800         if (l_excluded != 0) x0 = maxabs_dom(ic, 0) ;
00801         else x0 = maxabs_dom(ic, 1) ; 
00802         for (int l=0; l<nz; l++) {
00803             if (l == l_excluded) continue ; 
00804             double x = maxabs_dom(ic,l) ; 
00805             if (x > x0) x0 = x ; 
00806         }
00807         
00808         resu.set(ic) = x0 ; 
00809         
00810         if ( comment != 0x0 ) {
00811             if ( val > 0 ) ost << "   Comp." ; 
00812                 idx = aa.indices(ic) ;
00813                 for (int j=0 ; j<val ; j++) {
00814                     ost << " " << idx(j) ;
00815             }
00816             if (val > 0 ) ost << " : " ; 
00817                 else ost << "   " ; 
00818             ost << x0 << endl ; 
00819         }
00820         
00821     }
00822     
00823     return resu ; 
00824         
00825 }
00826 
00827 
00828 

Generated on Tue Feb 7 01:35:21 2012 for LORENE by  doxygen 1.4.6