111 void huntm(
const Tbl& xx,
double& x,
int& i_low) {
113 assert (xx.get_etat() == ETATQCQ) ;
114 int nx = xx.get_taille() ;
115 bool ascend = ( xx(nx-1) > xx(0) ) ;
117 if ( (i_low < 0)||(i_low>=nx) ) {
123 if ( (x >= xx(i_low)) == ascend ) {
124 if (i_low == nx -1) return ;
126 while ( (x >= xx(i_hi)) == ascend ) {
141 while ( (x < xx(i_low)) == ascend ) {
148 else i_low = i_hi - inc ;
152 while ( (i_hi - i_low) > 1) {
153 int i_med = (i_hi + i_low) / 2 ;
154 if ( (x>=xx(i_med)) == ascend ) i_low = i_med ;
157 if (x == xx(nx-1)) i_low = nx-2 ;
158 if (x == xx(0)) i_low = 0 ;
165 void interpol_linear(
const Tbl& xtab,
const Tbl& ytab,
166 double x,
int& i,
double& y) {
168 assert(ytab.dim == xtab.dim) ;
176 double y1 = ytab(i) ;
177 double y2 = ytab(i1) ;
179 double x1 = xtab(i) ;
180 double x2 = xtab(i1) ;
183 double a = (y1-y2)/x12 ;
184 double b = (x1*y2-y1*x2)/x12 ;
193 void interpol_linear_2d(
const Tbl& x1tab,
const Tbl& x2tab,
const Tbl& ytab,
194 double x1,
double x2,
int& i,
int& j,
double& y) {
196 assert(ytab.dim.ndim == 2) ;
197 assert(x1tab.dim.ndim == 1) ;
198 assert(x2tab.dim.ndim == 1) ;
199 assert(ytab.dim.dim[1] == x2tab.dim.dim[0]) ;
200 assert(ytab.dim.dim[0] == x1tab.dim.dim[0]) ;
202 huntm(x1tab, x1, i) ;
203 huntm(x2tab, x2, j) ;
209 double y11 = ytab(j,i) ;
210 double y21 = ytab(j1,i) ;
211 double y12 = ytab(j,i1) ;
213 double x11 = x1tab(i) ;
214 double x12 = x1tab(i1) ;
215 double x21 = x2tab(j) ;
216 double x22 = x2tab(j1) ;
217 double x1diff = x12-x11 ;
218 double x2diff = x22-x21 ;
220 double a = (y21-y11)/x2diff ;
221 double b = (y12-y11)/x1diff ;
223 y = y11 + (x1-x11)*b + (x2-x21)*a ;
230 void interpol_quad(
const Tbl& xtab,
const Tbl& ytab,
231 double x,
int& i,
double& y) {
233 assert(ytab.dim == xtab.dim) ;
252 y = y0*(x-x1)*(x-x2)/(x01*x02) - y1*(x-x0)*(x-x2)/(x01*x12) + y2*(x-x0)*(x-x1)/(x02*x12) ;
259 void interpol_herm(
const Tbl& xtab,
const Tbl& ytab,
const Tbl& dytab,
260 double x,
int& i,
double& y,
double& dy) {
262 assert(ytab.dim == xtab.dim) ;
263 assert(dytab.dim == xtab.dim) ;
269 double dx = xtab(i1) - xtab(i) ;
271 double u = (x - xtab(i)) / dx ;
275 y = ytab(i) * ( 2.*u3 - 3.*u2 + 1.)
276 + ytab(i1) * ( 3.*u2 - 2.*u3)
277 + dytab(i) * dx * ( u3 - 2.*u2 + u )
278 - dytab(i1) * dx * ( u2 - u3 ) ;
280 dy = 6. * ( ytab(i) / dx * ( u2 - u )
281 - ytab(i1) / dx * ( u2 - u ) )
282 + dytab(i) * ( 3.*u2 - 4.*u + 1. )
283 + dytab(i1) * ( 3.*u2 - 2.*u ) ;
290 void interpol_herm_der(
const Tbl& xtab,
const Tbl& ytab,
const Tbl& dytab,
291 double x,
int& i,
double& y,
double& dy,
double& ddy) {
293 assert(ytab.dim == xtab.dim) ;
294 assert(dytab.dim == xtab.dim) ;
302 double dx = xtab(i1) - xtab(i) ;
304 double u = (x - xtab(i)) / dx ;
308 y = ytab(i) * ( 2.*u3 - 3.*u2 + 1.)
309 + ytab(i1) * ( 3.*u2 - 2.*u3)
310 + dytab(i) * dx * ( u3 - 2.*u2 + u )
311 - dytab(i1) * dx * ( u2 - u3 ) ;
313 dy = 6. * ( ytab(i) - ytab(i1) ) * ( u2 - u ) / dx
314 + dytab(i) * ( 3.*u2 - 4.*u + 1. )
315 + dytab(i1) * ( 3.*u2 - 2.*u ) ;
317 ddy = 6 * ( ( ytab(i) - ytab(i1) ) * ( 2.*u - 1. ) / dx
318 + dytab(i) * (6.*u - 4.)
319 + dytab(i1) * (6.*u - 2.) ) / dx ;
326 void interpol_herm_2d(
const Tbl& xtab,
const Tbl& ytab,
const Tbl& ftab,
327 const Tbl& dfdxtab,
const Tbl& dfdytab,
const Tbl&
328 d2fdxdytab,
double x,
double y,
double& f,
double&
329 dfdx,
double& dfdy) {
331 assert(ytab.dim == xtab.dim) ;
332 assert(ftab.dim == xtab.dim) ;
333 assert(dfdxtab.dim == xtab.dim) ;
334 assert(dfdytab.dim == xtab.dim) ;
335 assert(d2fdxdytab.dim == xtab.dim) ;
338 nbp1 = xtab.get_dim(0);
339 nbp2 = xtab.get_dim(1);
344 while ((xtab(i_near,0) <= x) && (nbp2 > i_near)) {
351 while ((ytab(i_near,j_near) < y) && (nbp1 > j_near)) {
358 int i1 = i_near+1 ;
int j1 = j_near+1 ;
360 double dx = xtab(i1, j_near) - xtab(i_near, j_near) ;
361 double dy = ytab(i_near, j1) - ytab(i_near, j_near) ;
363 double u = (x - xtab(i_near, j_near)) / dx ;
364 double v = (y - ytab(i_near, j_near)) / dy ;
366 double u2 = u*u ;
double v2 = v*v ;
367 double u3 = u2*u ;
double v3 = v2*v ;
369 double psi0_u = 2.*u3 - 3.*u2 + 1. ;
370 double psi0_1mu = -2.*u3 + 3.*u2 ;
371 double psi1_u = u3 - 2.*u2 + u ;
372 double psi1_1mu = -u3 + u2 ;
374 double psi0_v = 2.*v3 - 3.*v2 + 1. ;
375 double psi0_1mv = -2.*v3 + 3.*v2 ;
376 double psi1_v = v3 - 2.*v2 + v ;
377 double psi1_1mv = -v3 + v2 ;
379 f = ftab(i_near, j_near) * psi0_u * psi0_v
380 + ftab(i1, j_near) * psi0_1mu * psi0_v
381 + ftab(i_near, j1) * psi0_u * psi0_1mv
382 + ftab(i1, j1) * psi0_1mu * psi0_1mv ;
384 f += (dfdxtab(i_near, j_near) * psi1_u * psi0_v
385 - dfdxtab(i1, j_near) * psi1_1mu * psi0_v
386 + dfdxtab(i_near, j1) * psi1_u * psi0_1mv
387 - dfdxtab(i1, j1) * psi1_1mu * psi0_1mv) * dx ;
389 f += (dfdytab(i_near, j_near) * psi0_u * psi1_v
390 + dfdytab(i1, j_near) * psi0_1mu * psi1_v
391 - dfdytab(i_near, j1) * psi0_u * psi1_1mv
392 - dfdytab(i1, j1) * psi0_1mu * psi1_1mv) * dy ;
394 f += (d2fdxdytab(i_near, j_near) * psi1_u * psi1_v
395 - d2fdxdytab(i1, j_near) * psi1_1mu * psi1_v
396 - d2fdxdytab(i_near, j1) * psi1_u * psi1_1mv
397 + d2fdxdytab(i1, j1) * psi1_1mu * psi1_1mv) * dx * dy ;
399 double dpsi0_u = 6.*(u2 - u) ;
400 double dpsi0_1mu = 6.*(u2 - u) ;
401 double dpsi1_u = 3.*u2 - 4.*u + 1. ;
402 double dpsi1_1mu = 3.*u2 - 2.*u ;
404 dfdx = (ftab(i_near, j_near) * dpsi0_u * psi0_v
405 - ftab(i1, j_near) * dpsi0_1mu * psi0_v
406 + ftab(i_near, j1) * dpsi0_u * psi0_1mv
407 - ftab(i1, j1) * dpsi0_1mu * psi0_1mv ) / dx;
409 dfdx += (dfdxtab(i_near, j_near) * dpsi1_u * psi0_v
410 + dfdxtab(i1, j_near) * dpsi1_1mu * psi0_v
411 + dfdxtab(i_near, j1) * dpsi1_u * psi0_1mv
412 + dfdxtab(i1, j1) * dpsi1_1mu * psi0_1mv) ;
414 dfdx += (dfdytab(i_near, j_near) * dpsi0_u * psi1_v
415 - dfdytab(i1, j_near) * dpsi0_1mu * psi1_v
416 - dfdytab(i_near, j1) * dpsi0_u * psi1_1mv
417 + dfdytab(i1, j1) * dpsi0_1mu * psi1_1mv) * dy /dx ;
419 dfdx += (d2fdxdytab(i_near, j_near) * dpsi1_u * psi1_v
420 + d2fdxdytab(i1, j_near) * dpsi1_1mu * psi1_v
421 - d2fdxdytab(i_near, j1) * dpsi1_u * psi1_1mv
422 - d2fdxdytab(i1, j1) * dpsi1_1mu * psi1_1mv) * dy ;
424 double dpsi0_v = 6.*(v2 - v) ;
425 double dpsi0_1mv = 6.*(v2 - v) ;
426 double dpsi1_v = 3.*v2 - 4.*v + 1. ;
427 double dpsi1_1mv = 3.*v2 - 2.*v ;
429 dfdy = (ftab(i_near, j_near) * psi0_u * dpsi0_v
430 + ftab(i1, j_near) * psi0_1mu * dpsi0_v
431 - ftab(i_near, j1) * psi0_u * dpsi0_1mv
432 - ftab(i1, j1) * psi0_1mu * dpsi0_1mv) / dy ;
434 dfdy += (dfdxtab(i_near, j_near) * psi1_u * dpsi0_v
435 - dfdxtab(i1, j_near) * psi1_1mu * dpsi0_v
436 - dfdxtab(i_near, j1) * psi1_u * dpsi0_1mv
437 + dfdxtab(i1, j1) * psi1_1mu * dpsi0_1mv) * dx / dy ;
439 dfdy += (dfdytab(i_near, j_near) * psi0_u * dpsi1_v
440 + dfdytab(i1, j_near) * psi0_1mu * dpsi1_v
441 + dfdytab(i_near, j1) * psi0_u * dpsi1_1mv
442 + dfdytab(i1, j1) * psi0_1mu * dpsi1_1mv) ;
444 dfdy += (d2fdxdytab(i_near, j_near) * psi1_u * dpsi1_v
445 - d2fdxdytab(i1, j_near) * psi1_1mu * dpsi1_v
446 + d2fdxdytab(i_near, j1) * psi1_u * dpsi1_1mv
447 - d2fdxdytab(i1, j1) * psi1_1mu * dpsi1_1mv) * dx ;
454 void interpol_herm_2d_sans(
const Tbl& xtab,
const Tbl& ytab,
const Tbl& ftab,
455 const Tbl& dfdxtab,
const Tbl& dfdytab,
double x,
456 double y,
double& f,
double& dfdx,
double& dfdy) {
458 assert(ytab.dim == xtab.dim) ;
459 assert(ftab.dim == xtab.dim) ;
460 assert(dfdxtab.dim == xtab.dim) ;
461 assert(dfdytab.dim == xtab.dim) ;
464 nbp1 = xtab.get_dim(0);
465 nbp2 = xtab.get_dim(1);
470 while ((xtab(i_near,0) <= x) && (nbp2 > i_near)) {
477 while ((ytab(i_near,j_near) < y) && (nbp1 > j_near)) {
484 int i1 = i_near+1 ;
int j1 = j_near+1 ;
486 double dx = xtab(i1, j_near) - xtab(i_near, j_near) ;
487 double dy = ytab(i_near, j1) - ytab(i_near, j_near) ;
489 double u = (x - xtab(i_near, j_near)) / dx ;
490 double v = (y - ytab(i_near, j_near)) / dy ;
492 double u2 = u*u ;
double v2 = v*v ;
493 double u3 = u2*u ;
double v3 = v2*v ;
495 double psi0_u = 2.*u3 - 3.*u2 + 1. ;
496 double psi0_1mu = -2.*u3 + 3.*u2 ;
497 double psi1_u = u3 - 2.*u2 + u ;
498 double psi1_1mu = -u3 + u2 ;
500 double psi0_v = 2.*v3 - 3.*v2 + 1. ;
501 double psi0_1mv = -2.*v3 + 3.*v2 ;
502 double psi1_v = v3 - 2.*v2 + v ;
503 double psi1_1mv = -v3 + v2 ;
505 f = ftab(i_near, j_near) * psi0_u * psi0_v
506 + ftab(i1, j_near) * psi0_1mu * psi0_v
507 + ftab(i_near, j1) * psi0_u * psi0_1mv
508 + ftab(i1, j1) * psi0_1mu * psi0_1mv ;
510 f += (dfdxtab(i_near, j_near) * psi1_u * psi0_v
511 - dfdxtab(i1, j_near) * psi1_1mu * psi0_v
512 + dfdxtab(i_near, j1) * psi1_u * psi0_1mv
513 - dfdxtab(i1, j1) * psi1_1mu * psi0_1mv) * dx ;
515 f += (dfdytab(i_near, j_near) * psi0_u * psi1_v
516 + dfdytab(i1, j_near) * psi0_1mu * psi1_v
517 - dfdytab(i_near, j1) * psi0_u * psi1_1mv
518 - dfdytab(i1, j1) * psi0_1mu * psi1_1mv) * dy ;
520 double dpsi0_u = 6.*(u2 - u) ;
521 double dpsi0_1mu = 6.*(u2 - u) ;
522 double dpsi1_u = 3.*u2 - 4.*u + 1. ;
523 double dpsi1_1mu = 3.*u2 - 2.*u ;
525 dfdx = (ftab(i_near, j_near) * dpsi0_u * psi0_v
526 - ftab(i1, j_near) * dpsi0_1mu * psi0_v
527 + ftab(i_near, j1) * dpsi0_u * psi0_1mv
528 - ftab(i1, j1) * dpsi0_1mu * psi0_1mv ) / dx;
530 dfdx += (dfdxtab(i_near, j_near) * dpsi1_u * psi0_v
531 + dfdxtab(i1, j_near) * dpsi1_1mu * psi0_v
532 + dfdxtab(i_near, j1) * dpsi1_u * psi0_1mv
533 + dfdxtab(i1, j1) * dpsi1_1mu * psi0_1mv) ;
535 dfdx += (dfdytab(i_near, j_near) * dpsi0_u * psi1_v
536 - dfdytab(i1, j_near) * dpsi0_1mu * psi1_v
537 - dfdytab(i_near, j1) * dpsi0_u * psi1_1mv
538 + dfdytab(i1, j1) * dpsi0_1mu * psi1_1mv) * dy /dx ;
540 double dpsi0_v = 6.*(v2 - v) ;
541 double dpsi0_1mv = 6.*(v2 - v) ;
542 double dpsi1_v = 3.*v2 - 4.*v + 1. ;
543 double dpsi1_1mv = 3.*v2 - 2.*v ;
545 dfdy = (ftab(i_near, j_near) * psi0_u * dpsi0_v
546 + ftab(i1, j_near) * psi0_1mu * dpsi0_v
547 - ftab(i_near, j1) * psi0_u * dpsi0_1mv
548 - ftab(i1, j1) * psi0_1mu * dpsi0_1mv) / dy ;
550 dfdy += (dfdxtab(i_near, j_near) * psi1_u * dpsi0_v
551 - dfdxtab(i1, j_near) * psi1_1mu * dpsi0_v
552 - dfdxtab(i_near, j1) * psi1_u * dpsi0_1mv
553 + dfdxtab(i1, j1) * psi1_1mu * dpsi0_1mv) * dx / dy ;
555 dfdy += (dfdytab(i_near, j_near) * psi0_u * dpsi1_v
556 + dfdytab(i1, j_near) * psi0_1mu * dpsi1_v
557 + dfdytab(i_near, j1) * psi0_u * dpsi1_1mv
558 + dfdytab(i1, j1) * psi0_1mu * dpsi1_1mv) ;
566 void interpol_herm_2nd_der(
const Tbl& xtab,
const Tbl& ytab,
const Tbl& dytab,
567 const Tbl& d2ytab,
double x,
int& i,
double& y,
568 double& dy,
double& d2y) {
570 assert(ytab.dim == xtab.dim) ;
571 assert(dytab.dim == xtab.dim) ;
572 assert(d2ytab.dim == xtab.dim) ;
578 double dx = xtab(i1) - xtab(i) ;
580 double u = (x - xtab(i)) / dx ;
592 y = ytab(i) * ( -6.*u5 + 15.*u4 - 10.*u3 + 1. )
593 + ytab(i1) * ( -6.*v5 + 15.*v4 - 10.*v3 + 1. )
594 + dytab(i) * dx * ( -3.*u5 + 8.*u4 -6.*u3 + u )
595 - dytab(i1) * dx * ( -3.*v5 + 8.*v4 -6.*v3 + v )
596 + d2ytab(i) * dx*dx * ( -0.5*u5 + 1.5*u4 - 1.5*u3 + 0.5*u2 )
597 + d2ytab(i1) * dx*dx * ( -0.5*v5 + 1.5*v4 - 1.5*v3 + 0.5*v2 ) ;
599 dy = 30.*( ytab(i) / dx * ( -u4 + 2.*u3 - u2 )
600 - ytab(i1) / dx * ( -v4 + 2.*v3 - v2 ) )
601 + dytab(i) * ( -15.*u4 + 32.*u3 - 18.*u2 + 1. )
602 + dytab(i1) * ( -15.*v4 + 32.*v3 - 18.*v2 + 1. )
603 + d2ytab(i) * dx * ( -2.5*u4 + 6.*u3 -4.5*u2 + u )
604 - d2ytab(i1) * dx * ( -2.5*v4 + 6.*v3 -4.5*v2 + v ) ;
606 d2y = 60.*(ytab(i)/(dx*dx) * (-2.*u3 + 3*u2 - u)
607 +ytab(i1)/(dx*dx) *(-2.*v3 + 3*v2 - v))
608 + 12.*dytab(i)/dx *(-5.*u3 + 8.*u2 - 3.*u)
609 - 12.*dytab(i1)/dx *(-5.*v3 + 8.*v2 - 3.*v)
610 + d2ytab(i) *(-10.*u3 + 18.*u2 - 9.*u + 1.)
611 + d2ytab(i1) *(-10.*v3 + 18.*v2 - 9.*v + 1.) ;
622 huntm(ytab,yy,i_low) ;
625 for (
int i=0 ; i<n_h ; i++){
626 resu.
set(i) = xytab(i_low,i) ;
638 huntm(xtab,xx,i_low) ;
641 for (
int i=0 ; i<n_h ; i++){
642 resu.
set(i) = xytab(i,i_low) ;
double & set(int i)
Read/write of a particular element (index i) (1D case)
Tbl extract_row(const Tbl &xytab, const Tbl &xtab, double xx)
Extraction of a row of a 2D Tbl
void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
int get_ndim() const
Gives the number of dimensions (ie dim.ndim)
int get_dim(int i) const
Gives the i-th dimension (ie dim.dim[i])
Tbl extract_column(const Tbl &, const Tbl &, double)
Extraction of a column of a 2D Tbl
int get_taille() const
Gives the total size (ie dim.taille)