ope_poisson_2d_solp.C

00001 /*
00002  *   Copyright (c) 2004 Philippe Grandclement
00003  *
00004  *   This file is part of LORENE.
00005  *
00006  *   LORENE is free software; you can redistribute it and/or modify
00007  *   it under the terms of the GNU General Public License version 2
00008  *   as published by the Free Software Foundation.
00009  *
00010  *   LORENE is distributed in the hope that it will be useful,
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *   GNU General Public License for more details.
00014  *
00015  *   You should have received a copy of the GNU General Public License
00016  *   along with LORENE; if not, write to the Free Software
00017  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018  *
00019  */
00020 
00021 char ope_poisson_2d_solp_C[] = "$Header: /cvsroot/Lorene/C++/Source/Ope_elementary/Ope_poisson_2d/ope_poisson_2d_solp.C,v 1.1 2004/08/24 09:14:47 p_grandclement Exp $" ;
00022 
00023 /*
00024  * $Id: ope_poisson_2d_solp.C,v 1.1 2004/08/24 09:14:47 p_grandclement Exp $
00025  * $Header: /cvsroot/Lorene/C++/Source/Ope_elementary/Ope_poisson_2d/ope_poisson_2d_solp.C,v 1.1 2004/08/24 09:14:47 p_grandclement Exp $
00026  *
00027  */
00028 #include <math.h>
00029 #include <stdlib.h>
00030 
00031 #include "proto.h"
00032 #include "ope_elementary.h"
00033 //--------------------------------------------------
00034 // Version Tbl --> Tbl a 1D pour la source 
00035 //--------------------------------------------------
00036 
00037 
00038 Tbl _cl_poisson_2d_pas_prevu (const Tbl &source, int puis) {
00039      cout << "Combinaison lineaire pas prevue..." << endl ;
00040     cout << "source : " << &source << endl ;
00041     cout << "dzpuis : " << puis << endl ;
00042     abort() ;
00043     exit(-1) ;
00044     return source;
00045 }
00046 
00047 
00048 
00049         //-------------------
00050            //--  R_CHEB  -------
00051           //--------------------
00052 
00053 Tbl _cl_poisson_2d_r_cheb (const Tbl &source, int) {
00054     Tbl barre(source) ;
00055     int n = source.get_dim(0) ;
00056     
00057     int dirac = 1 ;
00058     for (int i=0 ; i<n-2 ; i++) {
00059         barre.set(i) = ((1+dirac)*source(i)-source(i+2))
00060                 /(i+1) ;
00061     if (i==0) dirac = 0 ;
00062     }
00063     
00064     Tbl res(barre) ;
00065     for (int i=0 ; i<n-4 ; i++)
00066         res.set(i) = barre(i)-barre(i+2) ;
00067    return res ;        
00068 }
00069 
00070         //-------------------
00071            //--  R_CHEBP   -----
00072           //-------------------
00073 
00074 Tbl _cl_poisson_2d_r_chebp (const Tbl &source, int) {
00075     Tbl barre(source) ;
00076     int n = source.get_dim(0) ;
00077     
00078     int dirac = 1 ;
00079     for (int i=0 ; i<n-2 ; i++) {
00080         barre.set(i) = (1+dirac)*source(i)-source(i+2) ;
00081     if (i==0) dirac = 0 ;
00082     }
00083 
00084     Tbl tilde(barre) ;
00085     for (int i=0 ; i<n-4 ; i++)
00086         tilde.set(i) = barre(i)-barre(i+2) ;
00087 
00088     Tbl res(tilde) ;
00089     for (int i=0 ; i<n-4 ; i++)
00090         res.set(i) = tilde(i)-tilde(i+1) ;
00091     
00092    return res ;
00093 }
00094 
00095 
00096         //-------------------
00097            //--  R_CHEBI   -----
00098           //-------------------
00099 
00100 Tbl _cl_poisson_2d_r_chebi (const Tbl &source, int) {
00101     Tbl barre(source) ;
00102     int n = source.get_dim(0) ;
00103     
00104     for (int i=0 ; i<n-2 ; i++)
00105         barre.set(i) = source(i)-source(i+2) ;
00106 
00107     Tbl tilde(barre) ;
00108     for (int i=0 ; i<n-4 ; i++)
00109         tilde.set(i) = barre(i)-barre(i+2) ;    
00110 
00111     Tbl res(tilde) ;
00112     for (int i=0 ; i<n-4 ; i++)
00113         res.set(i) = tilde(i)-tilde(i+1) ;
00114     
00115    return res ;
00116 }
00117 
00118 
00119         //-------------------
00120            //--  R_CHEBU   -----
00121           //-------------------
00122 Tbl _cl_poisson_2d_r_chebu_quatre(const Tbl&) ;
00123 Tbl _cl_poisson_2d_r_chebu_trois(const Tbl&) ;
00124 Tbl _cl_poisson_2d_r_chebu_deux(const Tbl&) ;
00125 
00126 Tbl _cl_poisson_2d_r_chebu (const Tbl &source, int puis) {
00127     
00128     int n=source.get_dim(0) ;
00129     Tbl res(n) ;
00130     res.set_etat_qcq() ;
00131     
00132     switch(puis) {
00133     case 4 :
00134         res = _cl_poisson_2d_r_chebu_quatre(source) ;
00135         break ;
00136     case 3 :
00137         res = _cl_poisson_2d_r_chebu_trois (source) ;
00138         break ;
00139     case 2 :
00140         res = _cl_poisson_2d_r_chebu_deux(source) ;
00141         break ;
00142     
00143     default :
00144         abort() ;
00145         exit(-1) ;    
00146     }
00147    return res ;
00148 }
00149 
00150 // Cas dzpuis = 4 ;
00151 Tbl _cl_poisson_2d_r_chebu_quatre (const Tbl &source) {
00152     Tbl barre(source) ;
00153     int n = source.get_dim(0) ;
00154     
00155     int dirac = 1 ;
00156     for (int i=0 ; i<n-2 ; i++) {
00157          barre.set(i) = ((1+dirac)*source(i)-source(i+2)) ;
00158     if (i==0) dirac = 0 ;
00159     }
00160     
00161     Tbl tilde(barre) ;
00162     for (int i=0 ; i<n-4 ; i++)
00163         tilde.set(i) = (barre(i)-barre(i+2)) ;
00164         
00165     Tbl prime(tilde) ;
00166     for (int i=0 ; i<n-4 ; i++)
00167         prime.set(i) = (tilde(i)-tilde(i+1)) ;
00168     
00169      Tbl res(prime) ;
00170     for (int i=0 ; i<n-4 ; i++)
00171         res.set(i) = (prime(i)-prime(i+2)) ;
00172  
00173    return res ;
00174 }
00175 // cas dzpuis = 3
00176 Tbl _cl_poisson_2d_r_chebu_trois (const Tbl &source) {
00177     Tbl barre(source) ;
00178     int n = source.get_dim(0) ;
00179     
00180     int dirac = 1 ;
00181     for (int i=0 ; i<n-2 ; i++) {
00182          barre.set(i) = ((1+dirac)*source(i)-source(i+2)) ;
00183     if (i==0) dirac = 0 ;
00184     }
00185     
00186     Tbl tilde(barre) ;
00187     for (int i=0 ; i<n-4 ; i++)
00188         tilde.set(i) = (barre(i)-barre(i+2)) ;
00189         
00190     Tbl res(tilde) ;
00191     for (int i=0 ; i<n-4 ; i++)
00192         res.set(i) = (tilde(i)+tilde(i+1)) ;
00193  
00194    return res ;
00195 }
00196 
00197 // Cas dzpuis = 2 ;
00198 Tbl _cl_poisson_2d_r_chebu_deux (const Tbl &source) {
00199     Tbl barre(source) ;
00200     int n = source.get_dim(0) ;
00201     
00202     int dirac = 1 ;
00203     for (int i=0 ; i<n-2 ; i++) {
00204          barre.set(i) = ((1+dirac)*source(i)-source(i+2)) ;
00205     if (i==0) dirac = 0 ;
00206     }
00207     
00208     Tbl tilde(barre) ;
00209     for (int i=0 ; i<n-4 ; i++)
00210         tilde.set(i) = (barre(i)-barre(i+2)) ;
00211         
00212     Tbl res(tilde) ;
00213     for (int i=0 ; i<n-4 ; i++)
00214         res.set(i) = (tilde(i)+tilde(i+1)) ;
00215    return res ;
00216 }
00217 
00218 
00219         //----------------------------
00220            //- Routine a appeler        ---
00221           //------------------------------
00222 
00223 Tbl cl_poisson_2d (const Tbl &source, int puis, int base_r) {
00224     
00225         // Routines de derivation
00226     static Tbl (*cl_poisson_2d[MAX_BASE])(const Tbl &, int) ;
00227     static int nap = 0 ;
00228 
00229         // Premier appel
00230     if (nap==0) {
00231     nap = 1 ;
00232     for (int i=0 ; i<MAX_BASE ; i++) {
00233         cl_poisson_2d[i] = _cl_poisson_2d_pas_prevu ;
00234     }
00235         // Les routines existantes
00236     cl_poisson_2d[R_CHEB >> TRA_R] = _cl_poisson_2d_r_cheb ;
00237     cl_poisson_2d[R_CHEBU >> TRA_R] = _cl_poisson_2d_r_chebu ;
00238     cl_poisson_2d[R_CHEBP >> TRA_R] = _cl_poisson_2d_r_chebp ;
00239     cl_poisson_2d[R_CHEBI >> TRA_R] = _cl_poisson_2d_r_chebi ;
00240     }
00241     
00242     Tbl res(cl_poisson_2d[base_r](source, puis)) ;
00243     return res ;
00244 }
00245 
00246 
00247         //------------------------------------
00248         // Routine pour les cas non prevus --
00249         //------------------------------------
00250 Tbl _solp_poisson_2d_pas_prevu (const Matrice &, const Matrice &,
00251                 double,  double, const Tbl &, int) {
00252     cout << " Solution homogene pas prevue ..... : "<< endl ;
00253     abort() ;
00254     exit(-1) ;
00255     Tbl res(1) ;
00256     return res;
00257 }
00258     
00259     
00260         //-------------------
00261            //--  R_CHEB   ------
00262           //-------------------
00263 
00264 Tbl _solp_poisson_2d_r_cheb (const Matrice &lap, const Matrice &nondege, 
00265                  double alpha, double beta, 
00266                  const Tbl &source, int) {
00267     
00268     int n = lap.get_dim(0) ;      
00269     int dege = n-nondege.get_dim(0) ;
00270     assert (dege ==2) ;
00271     
00272     Tbl source_aux(source*alpha*alpha) ;
00273     Tbl xso(source_aux) ;
00274     Tbl xxso(source_aux) ;
00275     multx_1d(n, &xso.t, R_CHEB) ;
00276     multx_1d(n, &xxso.t, R_CHEB) ;
00277     multx_1d(n, &xxso.t, R_CHEB) ;
00278     source_aux = beta*beta/alpha/alpha*source_aux+2*beta/alpha*xso+xxso ;
00279     source_aux = cl_poisson_2d(source_aux, 0, R_CHEB) ;
00280     
00281     Tbl so(n-dege) ;
00282     so.set_etat_qcq() ;
00283     for (int i=0 ; i<n-dege ; i++)
00284     so.set(i) = source_aux(i) ;
00285     
00286     Tbl auxi(nondege.inverse(so)) ;
00287     
00288     Tbl res(n) ;
00289     res.set_etat_qcq() ;
00290     for (int i=dege ; i<n ; i++)
00291     res.set(i) = auxi(i-dege) ;
00292         
00293     for (int i=0 ; i<dege ; i++)
00294     res.set(i) = 0 ;
00295     return res ;
00296 }
00297     
00298     
00299         //-------------------
00300            //--  R_CHEBP   -----
00301           //-------------------
00302 
00303 Tbl _solp_poisson_2d_r_chebp (const Matrice &lap, const Matrice &nondege, 
00304                   double alpha, double , const Tbl &source, int) {
00305     
00306     int n = lap.get_dim(0) ;      
00307     int dege = n-nondege.get_dim(0) ;
00308     assert ((dege==2) || (dege == 1)) ;
00309     Tbl source_aux(alpha*alpha*source) ;
00310     source_aux = cl_poisson_2d(source_aux, 0, R_CHEBP) ;
00311     
00312     Tbl so(n-dege) ;
00313     so.set_etat_qcq() ;
00314     for (int i=0 ; i<n-dege ; i++)
00315     so.set(i) = source_aux(i);
00316    
00317     Tbl auxi(nondege.inverse(so)) ;
00318     
00319     Tbl res(n) ;
00320     res.set_etat_qcq() ;
00321     for (int i=dege ; i<n ; i++)
00322     res.set(i) = auxi(i-dege) ;
00323         
00324     for (int i=0 ; i<dege ; i++)
00325     res.set(i) = 0 ;
00326     
00327     if (dege==2) {
00328     double somme = 0 ;
00329     for (int i=0 ; i<n ; i++)
00330         if (i%2 == 0)
00331         somme -= res(i) ;
00332         else somme += res(i) ;
00333     res.set(0) = somme ;
00334     return res ;
00335     }
00336     else return res ;
00337 }
00338     
00339     
00340             //-------------------
00341            //--  R_CHEBI   -----
00342           //-------------------
00343     
00344 Tbl _solp_poisson_2d_r_chebi (const Matrice &lap, const Matrice &nondege, 
00345                   double alpha, double, const Tbl &source, int) {
00346    
00347 
00348     int n = lap.get_dim(0) ;      
00349     int dege = n-nondege.get_dim(0) ;
00350     assert ((dege == 2) || (dege ==1)) ;
00351     Tbl source_aux(source*alpha*alpha) ;
00352     source_aux = cl_poisson_2d(source_aux, 0, R_CHEBI) ;
00353     
00354     Tbl so(n-dege) ;
00355     so.set_etat_qcq() ;
00356     for (int i=0 ; i<n-dege ; i++)
00357     so.set(i) = source_aux(i);
00358    
00359     Tbl auxi(nondege.inverse(so)) ;
00360     
00361     Tbl res(n) ;
00362     res.set_etat_qcq() ;
00363     for (int i=dege ; i<n ; i++)
00364     res.set(i) = auxi(i-dege) ;
00365         
00366     for (int i=0 ; i<dege ; i++)
00367     res.set(i) = 0 ;
00368     
00369     if (dege==2) {
00370     double somme = 0 ;
00371     for (int i=0 ; i<n ; i++)
00372         if (i%2 == 0)
00373         somme -= (2*i+1)*res(i) ;
00374         else somme += (2*i+1)*res(i) ;
00375     res.set(0) = somme ;
00376     return res ;
00377     }
00378     else return res ;
00379 }   
00380     
00381     
00382     
00383             //-------------------
00384            //--  R_CHEBU   -----
00385           //-------------------
00386 Tbl _solp_poisson_2d_r_chebu_quatre (const Matrice&, const Matrice&, 
00387                      double, const Tbl&) ;
00388 Tbl _solp_poisson_2d_r_chebu_trois (const Matrice&, const Matrice&, 
00389                      double, const Tbl&) ;
00390 Tbl _solp_poisson_2d_r_chebu_deux (const Matrice&, const Matrice&, 
00391                    const Tbl&) ;
00392 
00393 Tbl _solp_poisson_2d_r_chebu (const Matrice &lap, const Matrice &nondege, 
00394                  double alpha, double, 
00395                  const Tbl &source, int puis) {
00396     int n = lap.get_dim(0) ;
00397     Tbl res(n) ;
00398     res.set_etat_qcq() ;
00399     
00400     switch (puis) {
00401 
00402     case 4 :
00403         res = _solp_poisson_2d_r_chebu_quatre 
00404           (lap, nondege, alpha, source) ;
00405         break ;
00406     case 3 :
00407         res = _solp_poisson_2d_r_chebu_trois 
00408           (lap, nondege, alpha, source) ;
00409         break ;
00410     case 2 :
00411         res = _solp_poisson_2d_r_chebu_deux 
00412           (lap, nondege, source) ;
00413         break ;
00414     default :
00415         abort() ;
00416         exit(-1) ;
00417     }
00418 return res ;
00419 }
00420 
00421 
00422 // Cas dzpuis = 4 ;
00423 Tbl _solp_poisson_2d_r_chebu_quatre (const Matrice &lap, const Matrice &nondege, 
00424                      double alpha, const Tbl &source) {
00425     
00426     int n = lap.get_dim(0) ;      
00427     int dege = n-nondege.get_dim(0) ;
00428     assert ((dege==3) || (dege ==2)) ;
00429     Tbl source_aux(source*alpha*alpha) ;
00430     source_aux = cl_poisson_2d(source_aux, 4, R_CHEBU) ;
00431     
00432     Tbl so(n-dege) ;
00433     so.set_etat_qcq() ;
00434     for (int i=0 ; i<n-dege ; i++)
00435     so.set(i) = source_aux(i);
00436    
00437     Tbl auxi(nondege.inverse(so)) ;
00438     
00439     Tbl res(n) ;
00440     res.set_etat_qcq() ;
00441     for (int i=dege ; i<n ; i++)
00442     res.set(i) = auxi(i-dege) ;
00443         
00444     for (int i=0 ; i<dege ; i++)
00445     res.set(i) = 0 ;
00446       
00447     if (dege==3) {
00448     double somme = 0 ;
00449     for (int i=0 ; i<n ; i++)
00450         somme += i*i*res(i) ;
00451     double somme_deux = somme ;
00452     for (int i=0 ; i<n ; i++)
00453         somme_deux -= res(i) ;
00454     res.set(1) = -somme ;
00455     res.set(0) = somme_deux ;
00456     return res ;
00457     }
00458     else {
00459     double somme = 0 ;
00460     for (int i=0 ; i<n ; i++)
00461         somme += res(i) ;
00462     res.set(0) = -somme ;
00463     return res ;
00464     }
00465 }   
00466 
00467 // Cas dzpuis = 3 ;
00468 Tbl _solp_poisson_2d_r_chebu_trois (const Matrice &lap, const Matrice &nondege, 
00469                     double alpha, const Tbl &source) {
00470     
00471     int n = lap.get_dim(0) ;      
00472     int dege = n-nondege.get_dim(0) ;
00473     assert (dege ==2) ;
00474     
00475     Tbl source_aux(source*alpha) ;
00476     source_aux = cl_poisson_2d(source_aux, 3, R_CHEBU) ;
00477     
00478     Tbl so(n-dege) ;
00479     so.set_etat_qcq() ;
00480     for (int i=0 ; i<n-dege ; i++)
00481     so.set(i) = source_aux(i);
00482    
00483     Tbl auxi(nondege.inverse(so)) ;
00484     
00485     Tbl res(n) ;
00486     res.set_etat_qcq() ;
00487     for (int i=dege ; i<n ; i++)
00488     res.set(i) = auxi(i-dege) ;
00489         
00490     for (int i=0 ; i<dege ; i++)
00491     res.set(i) = 0 ;
00492       
00493     double somme = 0 ;
00494     for (int i=0 ; i<n ; i++)
00495     somme += res(i) ;
00496     res.set(0) = -somme ;
00497     return res ;
00498 }
00499 
00500     
00501 // Cas dzpuis = 2 ;
00502 Tbl _solp_poisson_2d_r_chebu_deux (const Matrice &lap, const Matrice &nondege, 
00503                    const Tbl &source) {
00504     
00505     int n = lap.get_dim(0) ;      
00506     int dege = n-nondege.get_dim(0) ;
00507     assert ((dege==1) || (dege ==2)) ;
00508     Tbl source_aux(cl_poisson_2d(source, 2, R_CHEBU)) ;
00509     
00510     Tbl so(n-dege) ;
00511     so.set_etat_qcq() ;
00512     for (int i=0 ; i<n-dege ; i++)
00513     so.set(i) = source_aux(i);
00514     
00515     Tbl auxi(nondege.inverse(so)) ;
00516     
00517     Tbl res(n) ;
00518     res.set_etat_qcq() ;
00519     for (int i=dege ; i<n ; i++)
00520     res.set(i) = auxi(i-dege) ;
00521         
00522     for (int i=0 ; i<dege ; i++)
00523     res.set(i) = 0 ;
00524     
00525     if (dege == 2) {
00526     double somme = 0 ;
00527     for (int i=0 ; i<n ; i++)
00528         somme+=res(i) ;
00529     
00530     res.set(0) = -somme ;
00531     }
00532     
00533     return res ;
00534 }
00535 
00536 
00537 Tbl Ope_poisson_2d::get_solp (const Tbl& so) const {
00538 
00539   if (non_dege == 0x0)
00540     do_non_dege() ;
00541 
00542   // Routines de derivation
00543   static Tbl (*solp_poisson_2d[MAX_BASE]) (const Matrice&, const Matrice&,
00544                        double, double,const Tbl&, int) ;
00545   static int nap = 0 ;
00546   
00547   // Premier appel
00548   if (nap==0) {
00549     nap = 1 ;
00550     for (int i=0 ; i<MAX_BASE ; i++) {
00551       solp_poisson_2d[i] = _solp_poisson_2d_pas_prevu ;
00552     }
00553     // Les routines existantes
00554     solp_poisson_2d[R_CHEB >> TRA_R] = _solp_poisson_2d_r_cheb ;
00555     solp_poisson_2d[R_CHEBP >> TRA_R] = _solp_poisson_2d_r_chebp ;
00556     solp_poisson_2d[R_CHEBI >> TRA_R] = _solp_poisson_2d_r_chebi ;
00557     solp_poisson_2d[R_CHEBU >> TRA_R] = _solp_poisson_2d_r_chebu ;
00558   }
00559   
00560   Tbl res(solp_poisson_2d[base_r] (*ope_mat, *non_dege, 
00561                    alpha, beta, so, dzpuis)) ;
00562   
00563   Tbl valeurs (val_solp (res, alpha, base_r)) ;
00564   valeurs *= sqrt(double(2)) ;
00565   sp_plus = valeurs(0) ;
00566   sp_minus = valeurs(1) ;
00567   dsp_plus = valeurs(2) ;
00568   dsp_minus = valeurs(3) ;
00569   
00570   return res ;
00571 }

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