55 #include "utilitaires.h" 61 int nwork_colloc = 0 ;
63 double* tab_colloc[nmax] ;
70 void poly_leg (
int n,
double& poly,
double& pder,
double& polym1,
double& pderm1,
71 double& polym2,
double& pderm2,
double x) {
90 for (
int i=1 ; i<n ; i++) {
95 poly = ((2*i+1)*x*polym1 - i*polym2)/(i+1) ;
96 pder = ((2*i+1)*polym1+(2*i+1)*x*pderm1-i*pderm2)/(i+1) ;
102 void legendre_collocation_points(
int nr,
double* colloc) {
105 for (
int i=0; ((i<nwork_colloc) && (index<0)); i++)
106 if (nb_colloc[i] == nr) index = i ;
110 index = nwork_colloc ;
112 cout <<
"legendre_collocation_points: " << endl ;
113 cout <<
"too many arrays!" << endl ;
116 double*& t_colloc = tab_colloc[index] ;
117 t_colloc =
new double[nr] ;
121 double x_moins = -1 ;
122 double p_plus, dp_plus, p_plus_m1, dp_plus_m1, p_plus_m2, dp_plus_m2 ;
123 double p_moins, dp_moins, p_moins_m1, dp_moins_m1, p_moins_m2, dp_moins_m2 ;
124 double p, dp, p_m1, dp_m1, p_m2, dp_m2 ;
126 poly_leg (nr, p_plus, dp_plus, p_plus_m1, dp_plus_m1, p_plus_m2,
127 dp_plus_m2, x_plus) ;
128 poly_leg (nr, p_moins, dp_moins, p_moins_m1, dp_moins_m1, p_moins_m2,
129 dp_moins_m2, x_moins) ;
131 double det = p_plus_m1*p_moins_m2 - p_moins_m1*p_plus_m2 ;
132 double r_plus = -p_plus ;
133 double r_moins = -p_moins ;
134 double a = (r_plus*p_moins_m2 - r_moins*p_plus_m2)/det ;
135 double b = (r_moins*p_plus_m1 - r_plus*p_moins_m1)/det ;
138 double dth = M_PI/(2*nr+1) ;
139 double cd =
cos (2*dth) ;
140 double sd =
sin (2*dth) ;
141 double cs =
cos(dth) ;
142 double ss =
sin(dth) ;
144 int borne_sup = (nr%2==0) ? nr/2 : (nr+1)/2 ;
146 for (
int j=1 ; j<borne_sup ; j++) {
151 poly_leg (nr, p, dp, p_m1, dp_m1, p_m2, dp_m2, x) ;
152 double poly = p + a*p_m1 + b*p_m2 ;
153 double pder = dp + a * dp_m1 + b*dp_m2 ;
155 for (
int i=0 ; i<j ; i++)
156 sum += 1./(x-t_colloc[nr-i-1]) ;
158 double increm = -poly/(pder-sum*poly) ;
162 if ((fabs(increm) < 1.e-14) || (ite >500))
166 cout <<
"leg_ini: too many iterations..." << endl ;
169 t_colloc[nr-j-1] = x ;
170 double auxi = cs*cd-ss*sd ;
175 t_colloc[(nr-1)/2] = 0 ;
177 for (
int i=0 ; i<borne_sup ; i++)
178 t_colloc[i] = - t_colloc[nr-i-1] ;
179 nb_colloc[index] = nr ;
182 assert((index>=0)&&(index<nmax)) ;
183 for (
int i=0; i<nr; i++)
184 colloc[i] = (tab_colloc[index])[i] ;
194 void get_legendre_data(
int np, Tbl*& p_Pni, Tbl*& p_wn) {
197 for (
int i=0; ((i<nwork_leg) && (index<0)); i++)
198 if (nb_leg[i] == np) index = i ;
203 cout <<
"get_legendre_data: " << endl ;
204 cout <<
"too many transformation matrices!" << endl ;
208 tab_pni[index] =
new Tbl(np, np) ;
209 Tbl& Pni = (*tab_pni[index]) ;
211 tab_wn[index] =
new Tbl(np) ;
212 Tbl& wn = (*tab_wn[index]) ;
216 coloc.set_etat_qcq() ;
217 legendre_collocation_points(np, coloc.t) ;
219 for (
int i=0; i<np; i++) {
221 Pni.set(1, i) = coloc(i) ;
223 for (
int n=2; n<np; n++) {
224 for (
int i=0; i<np; i++) {
225 Pni.set(n,i) = (2. - 1./double(n))*coloc(i)*Pni(n-1, i)
226 - (1. - 1./double(n))*Pni(n-2, i) ;
230 for (
int j=0; j<np; j++)
231 wn.set(j) = 2./( double(np0)*double(np) * Pni(np0,j) * Pni(np0, j) ) ;
236 assert((index>=0)&&(index<nmax)) ;
237 p_Pni = tab_pni[index] ;
238 p_wn = tab_wn[index] ;
Cmp cos(const Cmp &)
Cosine.
Cmp sin(const Cmp &)
Sine.