solp.C

00001 /*
00002  *   Copyright (c) 1999-2001 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 as published by
00008  *   the Free Software Foundation; either version 2 of the License, or
00009  *   (at your option) any later version.
00010  *
00011  *   LORENE is distributed in the hope that it will be useful,
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *   GNU General Public License for more details.
00015  *
00016  *   You should have received a copy of the GNU General Public License
00017  *   along with LORENE; if not, write to the Free Software
00018  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  */
00021 
00022 
00023 char solp_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/PDE/solp.C,v 1.9 2008/07/11 13:20:54 j_novak Exp $" ;
00024 
00025 /*
00026  * $Id: solp.C,v 1.9 2008/07/11 13:20:54 j_novak Exp $
00027  * $Log: solp.C,v $
00028  * Revision 1.9  2008/07/11 13:20:54  j_novak
00029  * Miscellaneous functions for the wave equation.
00030  *
00031  * Revision 1.8  2008/02/18 13:53:44  j_novak
00032  * Removal of special indentation instructions.
00033  *
00034  * Revision 1.7  2007/12/12 12:30:49  jl_cornou
00035  * *** empty log message ***
00036  *
00037  * Revision 1.6  2004/10/05 15:44:21  j_novak
00038  * Minor speed enhancements.
00039  *
00040  * Revision 1.5  2004/02/20 10:55:23  j_novak
00041  * The versions dzpuis 5 -> 3 has been improved and polished. Should be
00042  * operational now...
00043  *
00044  * Revision 1.4  2004/02/09 08:55:31  j_novak
00045  * Corrected error in the arguments of _solp_r_chebu_cinq
00046  *
00047  * Revision 1.3  2004/02/06 10:53:54  j_novak
00048  * New dzpuis = 5 -> dzpuis = 3 case (not ready yet).
00049  *
00050  * Revision 1.2  2002/10/16 14:37:12  j_novak
00051  * Reorganization of #include instructions of standard C++, in order to
00052  * use experimental version 3 of gcc.
00053  *
00054  * Revision 1.1.1.1  2001/11/20 15:19:28  e_gourgoulhon
00055  * LORENE
00056  *
00057  * Revision 2.14  2000/09/07  12:54:42  phil
00058  * *** empty log message ***
00059  *
00060  * Revision 2.13  2000/05/22  13:41:50  phil
00061  * ajout du cas dzpuis == 3 ;
00062  *
00063  * Revision 2.12  1999/11/30  17:45:04  phil
00064  * changement prototypage
00065  *
00066  * Revision 2.11  1999/10/12  09:44:44  phil
00067  * *** empty log message ***
00068  *
00069  * Revision 2.10  1999/10/12  09:37:54  phil
00070  * passage en const Matreice&
00071  *
00072  * Revision 2.9  1999/07/08  09:54:58  phil
00073  * changement appel de multx_1d
00074  *
00075  * Revision 2.8  1999/07/07  10:05:20  phil
00076  * Passage aux operateurs 1d
00077  * /
00078  *
00079  * Revision 2.7  1999/07/02  15:04:48  phil
00080  * *** empty log message ***
00081  *
00082  * Revision 2.6  1999/06/23  16:21:59  phil
00083  * *** empty log message ***
00084  *
00085  * Revision 2.5  1999/06/23  12:35:06  phil
00086  * ajout de dzpuis = 2
00087  *
00088  * Revision 2.4  1999/04/07  15:07:18  phil
00089  * *** empty log message ***
00090  *
00091  * Revision 2.3  1999/04/07  15:06:14  phil
00092  * Changement de calcul pour (-1)^n
00093  *
00094  * Revision 2.2  1999/04/07  14:55:46  phil
00095  * Changement prototypage
00096  *
00097  * Revision 2.1  1999/04/07  14:36:38  phil
00098  * passage par reference
00099  *
00100  * Revision 2.0  1999/04/07  14:11:24  phil
00101  * *** empty log message ***
00102  *
00103  *
00104  * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/PDE/solp.C,v 1.9 2008/07/11 13:20:54 j_novak Exp $
00105  *
00106  */
00107 
00108 //fichiers includes
00109 #include <stdio.h>
00110 #include <stdlib.h>
00111 #include <math.h>
00112 
00113 #include "matrice.h"
00114 #include "type_parite.h"
00115 #include "proto.h"
00116 
00117 /*
00118  * Calcul une solution particuliere a : Lap X = Y
00119  * 
00120  * Entree :
00121  *  lap : matrice de l'operateur
00122  *  nondege : matrice non degeneree associee
00123  *  alpha et beta : voire mapping
00124  *  source : Tbl contenant les coefficients en r de Y
00125  *  puis : puissance dans la ZEC
00126  * Sortie :
00127  *  Tbl contenant les coefficients de X
00128  * 
00129  * 
00130  */
00131         //------------------------------------
00132         // Routine pour les cas non prevus --
00133         //------------------------------------
00134 Tbl _solp_pas_prevu (const Matrice &lap, const Matrice &nondege, double alpha, 
00135             double beta, const Tbl &source, int puis) {
00136     cout << " Solution particuliere pas prevue ..... : "<< endl ;
00137     cout << " Laplacien : " << endl << lap << endl ;
00138     cout << " Non degenere  : " << endl << nondege << endl ;
00139     cout << " Source : " << &source << endl ;
00140     cout << " Alpha : " << alpha << endl ;
00141     cout << " Beta : " << beta << endl ;
00142     cout << " Puiss : " << puis << endl ;
00143     abort() ;
00144     exit(-1) ;
00145     Tbl res(1) ;
00146     return res;
00147 }
00148     
00149     
00150         //-------------------
00151            //--  R_CHEB   ------
00152           //-------------------
00153 
00154 Tbl _solp_r_cheb (const Matrice &lap, const Matrice &nondege, double alpha, 
00155           double beta, const Tbl &source, int) {
00156     
00157     int n = lap.get_dim(0) ;      
00158     int dege = n-nondege.get_dim(0) ;
00159     assert (dege ==2) ;
00160     
00161     Tbl source_aux(source*alpha*alpha) ;
00162     Tbl xso(source_aux) ;
00163     Tbl xxso(source_aux) ;
00164     multx_1d(n, &xso.t, R_CHEB) ;
00165     multx_1d(n, &xxso.t, R_CHEB) ;
00166     multx_1d(n, &xxso.t, R_CHEB) ;
00167     source_aux = beta*beta/alpha/alpha*source_aux+2*beta/alpha*xso+xxso ;
00168     source_aux = combinaison(source_aux, 0, R_CHEB) ;
00169     
00170     Tbl so(n-dege) ;
00171     so.set_etat_qcq() ;
00172     for (int i=0 ; i<n-dege ; i++)
00173     so.set(i) = source_aux(i) ;
00174     
00175     Tbl auxi(nondege.inverse(so)) ;
00176     
00177     Tbl res(n) ;
00178     res.set_etat_qcq() ;
00179     for (int i=dege ; i<n ; i++)
00180     res.set(i) = auxi(i-dege) ;
00181         
00182     for (int i=0 ; i<dege ; i++)
00183     res.set(i) = 0 ;
00184     return res ;
00185 }
00186     
00187         //-------------------
00188            //--  R_JACO02 ------
00189           //-------------------
00190 
00191 Tbl _solp_r_jaco02 (const Matrice &lap, const Matrice &nondege, double alpha, 
00192           double, const Tbl &source, int) {
00193     
00194     int n = lap.get_dim(0) ;      
00195     int dege = n-nondege.get_dim(0) ;
00196     assert (dege ==2) ;
00197     
00198     Tbl source_aux(source*alpha*alpha) ;
00199     source_aux = combinaison(source_aux, 0, R_JACO02) ;
00200     
00201     Tbl so(n-dege) ;
00202     so.set_etat_qcq() ;
00203     for (int i=0 ; i<n-dege ; i++)
00204     so.set(i) = source_aux(i) ;
00205     
00206     Tbl auxi(nondege.inverse(so)) ;
00207     
00208     Tbl res(n) ;
00209     res.set_etat_qcq() ;
00210     for (int i=dege ; i<n ; i++)
00211     res.set(i) = auxi(i-dege) ;
00212         
00213     for (int i=0 ; i<dege ; i++)
00214     res.set(i) = 0 ;
00215     return res ;
00216 }
00217     
00218 
00219         //-------------------
00220            //--  R_CHEBP   -----
00221           //-------------------
00222 
00223 Tbl _solp_r_chebp (const Matrice &lap, const Matrice &nondege, double alpha, 
00224             double , const Tbl &source, int) {
00225     
00226     int n = lap.get_dim(0) ;      
00227     int dege = n-nondege.get_dim(0) ;
00228     assert ((dege==2) || (dege == 1)) ;
00229     Tbl source_aux(alpha*alpha*source) ;
00230     source_aux = combinaison(source_aux, 0, R_CHEBP) ;
00231     
00232     Tbl so(n-dege) ;
00233     so.set_etat_qcq() ;
00234     for (int i=0 ; i<n-dege ; i++)
00235     so.set(i) = source_aux(i);
00236    
00237     Tbl auxi(nondege.inverse(so)) ;
00238     
00239     Tbl res(n) ;
00240     res.set_etat_qcq() ;
00241     for (int i=dege ; i<n ; i++)
00242     res.set(i) = auxi(i-dege) ;
00243         
00244     for (int i=0 ; i<dege ; i++)
00245     res.set(i) = 0 ;
00246     
00247     if (dege==2) {
00248     double somme = 0 ;
00249     for (int i=0 ; i<n ; i++)
00250         if (i%2 == 0)
00251         somme -= res(i) ;
00252         else somme += res(i) ;
00253     res.set(0) = somme ;
00254     return res ;
00255     }
00256     else return res ;
00257 }
00258     
00259     
00260             //-------------------
00261            //--  R_CHEBI   -----
00262           //-------------------
00263     
00264 Tbl _solp_r_chebi (const Matrice &lap, const Matrice &nondege, double alpha, 
00265             double,  const Tbl &source, int) {
00266    
00267 
00268     int n = lap.get_dim(0) ;      
00269     int dege = n-nondege.get_dim(0) ;
00270     assert ((dege == 2) || (dege ==1)) ;
00271     Tbl source_aux(source*alpha*alpha) ;
00272     source_aux = combinaison(source_aux, 0, R_CHEBI) ;
00273     
00274     Tbl so(n-dege) ;
00275     so.set_etat_qcq() ;
00276     for (int i=0 ; i<n-dege ; i++)
00277     so.set(i) = source_aux(i);
00278    
00279     Tbl auxi(nondege.inverse(so)) ;
00280     
00281     Tbl res(n) ;
00282     res.set_etat_qcq() ;
00283     for (int i=dege ; i<n ; i++)
00284     res.set(i) = auxi(i-dege) ;
00285         
00286     for (int i=0 ; i<dege ; i++)
00287     res.set(i) = 0 ;
00288     
00289     if (dege==2) {
00290     double somme = 0 ;
00291     for (int i=0 ; i<n ; i++)
00292         if (i%2 == 0)
00293         somme -= (2*i+1)*res(i) ;
00294         else somme += (2*i+1)*res(i) ;
00295     res.set(0) = somme ;
00296     return res ;
00297     }
00298     else return res ;
00299 }   
00300     
00301     
00302     
00303             //-------------------
00304            //--  R_CHEBU   -----
00305           //-------------------
00306 
00307 Tbl _solp_r_chebu (const Matrice &lap, const Matrice &nondege, double alpha, 
00308             double, const Tbl &source, int puis) {
00309     int n = lap.get_dim(0) ;
00310     Tbl res(n) ;
00311     res.set_etat_qcq() ;
00312     
00313     switch (puis) {
00314     case 5 :
00315         res = _solp_r_chebu_cinq (lap, nondege, source) ;
00316         break ;
00317     case 4 :
00318         res = _solp_r_chebu_quatre (lap, nondege, alpha, source) ;
00319         break ;
00320     case 3 :
00321         res = _solp_r_chebu_trois (lap, nondege, alpha, source) ;
00322         break ;
00323     case 2 :
00324         res = _solp_r_chebu_deux (lap, nondege, source) ;
00325         break ;
00326     default :
00327         abort() ;
00328         exit(-1) ;
00329     }
00330 return res ;
00331 }
00332 
00333 
00334 // Cas dzpuis = 4 ;
00335 Tbl _solp_r_chebu_quatre (const Matrice &lap, const Matrice &nondege, double alpha, 
00336                 const Tbl &source) {
00337     
00338     int n = lap.get_dim(0) ;      
00339     int dege = n-nondege.get_dim(0) ;
00340     assert ((dege==3) || (dege ==2)) ;
00341     Tbl source_aux(source*alpha*alpha) ;
00342     source_aux = combinaison(source_aux, 4, R_CHEBU) ;
00343     
00344     Tbl so(n-dege) ;
00345     so.set_etat_qcq() ;
00346     for (int i=0 ; i<n-dege ; i++)
00347     so.set(i) = source_aux(i);
00348    
00349     Tbl auxi(nondege.inverse(so)) ;
00350     
00351     Tbl res(n) ;
00352     res.set_etat_qcq() ;
00353     for (int i=dege ; i<n ; i++)
00354     res.set(i) = auxi(i-dege) ;
00355         
00356     for (int i=0 ; i<dege ; i++)
00357     res.set(i) = 0 ;
00358       
00359     if (dege==3) {
00360     double somme = 0 ;
00361     for (int i=0 ; i<n ; i++)
00362         somme += i*i*res(i) ;
00363     double somme_deux = somme ;
00364     for (int i=0 ; i<n ; i++)
00365         somme_deux -= res(i) ;
00366     res.set(1) = -somme ;
00367     res.set(0) = somme_deux ;
00368     return res ;
00369     }
00370     else {
00371     double somme = 0 ;
00372     for (int i=0 ; i<n ; i++)
00373         somme += res(i) ;
00374     res.set(0) = -somme ;
00375     return res ;
00376     }
00377 }   
00378 
00379 // Cas dzpuis = 3 ;
00380 Tbl _solp_r_chebu_trois (const Matrice &lap, const Matrice &nondege, double alpha, 
00381                 const Tbl &source) {
00382     
00383     int n = lap.get_dim(0) ;      
00384     int dege = n-nondege.get_dim(0) ;
00385     assert (dege ==2) ;
00386     
00387     Tbl source_aux(source*alpha) ;
00388     source_aux = combinaison(source_aux, 3, R_CHEBU) ;
00389     
00390     Tbl so(n-dege) ;
00391     so.set_etat_qcq() ;
00392     for (int i=0 ; i<n-dege ; i++)
00393     so.set(i) = source_aux(i);
00394    
00395     Tbl auxi(nondege.inverse(so)) ;
00396     
00397     Tbl res(n) ;
00398     res.set_etat_qcq() ;
00399     for (int i=dege ; i<n ; i++)
00400     res.set(i) = auxi(i-dege) ;
00401         
00402     for (int i=0 ; i<dege ; i++)
00403     res.set(i) = 0 ;
00404       
00405     double somme = 0 ;
00406     for (int i=0 ; i<n ; i++)
00407     somme += res(i) ;
00408     res.set(0) = -somme ;
00409     return res ;
00410 }
00411 
00412     
00413 // Cas dzpuis = 2 ;
00414 Tbl _solp_r_chebu_deux (const Matrice &lap, const Matrice &nondege, 
00415             const Tbl &source) {
00416     
00417     int n = lap.get_dim(0) ;      
00418     int dege = n-nondege.get_dim(0) ;
00419     assert ((dege==1) || (dege ==2)) ;
00420     Tbl source_aux(combinaison(source, 2, R_CHEBU)) ;
00421     
00422     Tbl so(n-dege) ;
00423     so.set_etat_qcq() ;
00424     for (int i=0 ; i<n-dege ; i++)
00425     so.set(i) = source_aux(i);
00426     
00427     Tbl auxi(nondege.inverse(so)) ;
00428     
00429     Tbl res(n) ;
00430     res.set_etat_qcq() ;
00431     for (int i=dege ; i<n ; i++)
00432     res.set(i) = auxi(i-dege) ;
00433         
00434     for (int i=0 ; i<dege ; i++)
00435     res.set(i) = 0 ;
00436     
00437     if (dege == 2) {
00438     double somme = 0 ;
00439     for (int i=0 ; i<n ; i++)
00440         somme+=res(i) ;
00441     
00442     res.set(0) = -somme ;
00443     }
00444     
00445     return res ;
00446 }
00447 
00448 // Cas dzpuis = 5 ;
00449 Tbl _solp_r_chebu_cinq (const Matrice &lap, const Matrice &nondege, 
00450             const Tbl &source) {
00451     
00452     int n = lap.get_dim(0) ;      
00453     int dege = n-nondege.get_dim(0) ;
00454 
00455     Tbl source_aux(combinaison(source, 5, R_CHEBU)) ;
00456     
00457     Tbl so(n-dege) ;
00458     so.set_etat_qcq() ;
00459     for (int i=0 ; i<n-dege ; i++)
00460     so.set(i) = source_aux(i);
00461     
00462     Tbl auxi(nondege.inverse(so)) ;
00463     
00464     Tbl res(n) ;
00465     res.set_etat_qcq() ;
00466     for (int i=dege ; i<n ; i++)
00467     res.set(i) = auxi(i-dege) ;
00468         
00469     for (int i=0 ; i<dege ; i++)
00470     res.set(i) = 0 ;
00471     
00472     if (dege == 2) {
00473     double somme = 0 ;
00474     for (int i=0 ; i<n ; i++)
00475         somme+=res(i) ;
00476     
00477     res.set(0) = -somme ;
00478     }
00479     
00480     return res ;
00481 }
00482 
00483 
00484             //-------------------
00485            //--  Fonction   ----
00486           //-------------------
00487           
00488           
00489 Tbl solp(const Matrice &lap, const Matrice &nondege, double alpha,
00490         double beta, const Tbl &source, int puis, int base_r) {
00491 
00492         // Routines de derivation
00493     static Tbl (*solp[MAX_BASE])(const Matrice&, const Matrice&, double, double,
00494                      const Tbl&, int) ;
00495     static int nap = 0 ;
00496 
00497         // Premier appel
00498     if (nap==0) {
00499     nap = 1 ;
00500     for (int i=0 ; i<MAX_BASE ; i++) {
00501         solp[i] = _solp_pas_prevu ;
00502     }
00503         // Les routines existantes
00504     solp[R_CHEB >> TRA_R] = _solp_r_cheb ;
00505     solp[R_CHEBU >> TRA_R] = _solp_r_chebu ;
00506     solp[R_CHEBP >> TRA_R] = _solp_r_chebp ;
00507     solp[R_CHEBI >> TRA_R] = _solp_r_chebi ;
00508     solp[R_JACO02 >> TRA_R] = _solp_r_jaco02 ;
00509     }
00510     
00511     return solp[base_r](lap, nondege, alpha, beta, source, puis) ;
00512 }

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