94 #include "grille_val.h" 95 #include "proto_f77.h" 107 assert( dynamic_cast<const Map_af*>(mp) != 0x0) ;
110 assert(lmin >= 0 && lmax <= mgrid->get_nzone()) ;
112 for (
int i=lmin; i<lmax; i++) {
113 if ((mgrid->
get_nt(i) > 1)&&(dim_spec==1)) dim_spec = 2;
114 if (mgrid->
get_np(i) > 1) dim_spec = 3;
117 cout <<
"Grille_val::compatibilite: the number of dimensions" << endl ;
118 cout <<
"of both grids do not coincide!" << endl;
122 cout <<
"Grille_val::compatibilite: the symmetries in theta" << endl ;
123 cout <<
"of both grids do not coincide!" << endl;
127 cout <<
"Grille_val::compatibilite: the symmetries in phi" << endl ;
128 cout <<
"of both grids do not coincide!" << endl;
132 bool dimension = true ;
135 double rout = (+rr)(lmax-1, 0, 0, mgrid->
get_nr(lmax-1) - 1) ;
137 dimension &= (rout <= *
zrmax) ;
140 dimension &= ((+rr)(lmin,0,0,0) >= *
zrmin) ;
145 {dimension &= (*
zrmin <= 0.) ;}
147 dimension &= (*
zrmin <= -rout ) ;}
148 dimension &= (*
xmin <= 0.) ;
149 dimension &= (*
xmax >= rout ) ;
154 {dimension &= (*
zrmin <= 0.) ;}
156 dimension &= (*
zrmin <= -rout) ;}
158 dimension &= (*
ymin <= 0.) ;
159 dimension &= (*
xmin <= -rout) ;
162 dimension &= (*
xmin <= -rout ) ;
163 dimension &= (*
ymin <= -rout ) ;
165 dimension &= (*
xmax >= rout) ;
166 dimension &= (*
ymax >= rout) ;
178 assert( dynamic_cast<const Map_af*>(mp) != 0x0) ;
183 for (
int i=lmin; i<lmax; i++) {
184 if ((mgrid->
get_nt(i) > 1)&&(dim_spec==1)) dim_spec = 2;
185 if (mgrid->
get_np(i) > 1) dim_spec = 3;
188 cout <<
"Grille_val::compatibilite: the number of dimensions" << endl ;
189 cout <<
"of both grids do not coincide!" << endl;
190 cout <<
"Spectral : " << dim_spec <<
"D, FD: " <<
dim.
ndim <<
"D" << endl ;
194 cout <<
"Grille_val::compatibilite: the symmetries in theta" << endl ;
195 cout <<
"of both grids do not coincide!" << endl;
199 cout <<
"Grille_val::compatibilite: the symmetries in phi" << endl ;
200 cout <<
"of both grids do not coincide!" << endl;
206 int i_b = mgrid->
get_nr(lmax-1) - 1 ;
208 double rmax = (+rr)(lmax-1, 0, 0, i_b) ;
209 double rmin = (+rr)(lmin, 0, 0, 0) ;
213 bool dimension = ((rmax <= (valmax)) && (rmin>= (valmin))) ;
223 assert( dynamic_cast<const Map_af*>(&mp) != 0x0) ;
226 assert(lmin >= 0 && lmax <= mgrid->get_nzone()) ;
228 for (
int i=lmin; i<lmax; i++) {
229 if ((mgrid->
get_nt(i) > 1)&&(dim_spec==1)) dim_spec = 2;
230 if (mgrid->
get_np(i) > 1) dim_spec = 3;
233 cout <<
"Grille_val::contenue_dans: the number of dimensions" << endl ;
234 cout <<
"of both grids do not coincide!" << endl;
238 cout <<
"Grille_val::contenue_dans: the symmetries in theta" << endl ;
239 cout <<
"of both grids do not coincide!" << endl;
243 cout <<
"Grille_val::contenue_dans: the symmetries in phi" << endl ;
244 cout <<
"of both grids do not coincide!" << endl;
248 bool dimension = true ;
252 double radius = (+rr)(lmax-1,0,0,mgrid->
get_nr(lmax-1)-1) ;
253 double radius2 = radius*radius ;
256 dimension &= ((+rr)(lmin,0,0,0) <= *
zrmin) ;
257 dimension &= (radius >= *
zrmax) ;
260 dimension &= ((+rr)(lmin,0,0,0)/radius < 1.e-6) ;
261 dimension &= (*
xmin >= 0.) ;
265 dimension &= (x1*x1+z1*z1 <= radius2) ;
273 dimension &= (x1*x1+y1*y1+z1*z1 <= radius2) ;
284 assert( dynamic_cast<const Map_af*>(&mp) != 0x0) ;
289 cout <<
"Grille_val::contenue_dans: the symmetries in theta" << endl ;
290 cout <<
"of both grids do not coincide!" << endl;
294 cout <<
"Grille_val::contenue_dans: the symmetries in phi" << endl ;
295 cout <<
"of both grids do not coincide!" << endl;
301 int i_b = mgrid->
get_nr(lmax-1) - 1 ;
303 double rmax = (+rr)(lmax-1, 0, 0, i_b) ;
304 double rmin = (+rr)(lmin, 0, 0, 0) ;
305 double valmin =
get_zr(0) ;
308 bool dimension = ((rmax >= valmax) && (rmin<= valmin)) ;
319 int flag,
const int type_inter)
const {
322 assert(rdep.
dim == fdep.
dim) ;
330 switch (type_inter) {
335 double* err0 =
new double[ndep+narr] ;
336 double* err1 =
new double[ndep+narr] ;
337 double* den0 =
new double[ndep+narr] ;
338 double* den1 =
new double[ndep+narr] ;
339 for (
int i=0; i<ndep; i++) {
343 for (
int i=0; i<narr; i++) err1[i] = rarr(i) ;
344 F77_insmts(ndeg, &flag, err0, err1, den0, den1) ;
345 for (
int i=0; i<narr; i++) farr.
set(i) = den1[i] ;
356 for (
int i=0; i<narr; i++) {
357 while(rdep(is) < rarr(i)) is++ ;
360 farr.
t[i] = (fdep(is)*(rdep(ip)-rarr(i)) +
361 fdep(ip)*(rarr(i)-rdep(is))) /
362 (rdep(ip)-rdep(is)) ;
369 double xr, x1, x2, x3, y1, y2, y3 ;
373 for (
int i=0; i<narr; i++) {
375 while(rdep.
t[i3] < xr) i3++ ;
393 double b = (y2 - y1) / (x2 - x1) ;
394 double a = ( (y3 - y2)/(x3 - x2) - (y2 - y1)/(x2 - x1) ) / (x3 - x1) ;
395 farr.
t[i] = c + b*(xr - x1) + a*(xr - x1)*(xr - x2) ;
401 int ndm1 = ndep - 1 ;
402 double ai(0), bi(0), ci(0), di(0) ;
407 hi.
set(0) = rdep(1) - rdep(0) ;
408 si.
set(0) = (fdep(1) - fdep(0)) / hi(0) ;
409 for (
int i=1; i<ndm1; i++) {
410 hi.
set(i) = rdep(i+1) - rdep(i) ;
411 si.
set(i) = ( fdep(i+1) - fdep(i) ) / hi(i) ;
412 pi.
set(i) = (si(i-1)*hi(i) + si(i)*hi(i-1)) / (hi(i-1) + hi(i)) ;
413 if ( si(i-1) * si(i) <= 0) yprime.
set(i) = 0. ;
415 yprime.
set(i) = pi(i) ;
416 double fsi = fabs(si(i)) ;
417 double fsim1 = fabs(si(i-1)) ;
418 if ( (fabs(pi(i)) > 2*fsim1) || (fabs(pi(i)) > 2*fsi) )
419 {
int a = (si(i) > 0 ? 1 : -1 ) ;
420 yprime.
set(i) = 2*a* ( fsim1 < fsi ? fsim1 : fsi ) ;
426 pi.
set(0) = si(0)* ( 1 + hi(0)/(hi(0) + hi(1)) )
427 - si(1) * ( hi(0) / (hi(0) + hi(1)) ) ;
428 if ( pi(0) * si(0) <= 0 ) yprime.
set(0) = 0. ;
430 yprime.
set(0) = pi(0) ;
431 if ( fabs(pi(0)) > 2*fabs(si(0)) ) yprime.
set(0) = 2*si(0) ;
433 int ndm2 = ndep - 2 ;
434 int ndm3 = ndep - 3 ;
435 pi.
set(ndm1) = si(ndm2)* ( 1 + hi(ndm2)/(hi(ndm2) + hi(ndm3)) )
436 - si(ndm3) * ( hi(ndm2) / (hi(ndm2) + hi(ndm3)) ) ;
437 if ( pi(ndm1) * si(ndm2) <= 0 ) yprime.
set(ndm1) = 0. ;
439 yprime.
set(ndm1) = pi(ndm1) ;
440 if ( fabs(pi(ndm1)) > 2*fabs(si(ndm2)) ) yprime.
set(ndm1) = 2*si(ndm2) ;
445 bool still_points = true ;
446 for (
int i=0; i<ndm1; i++) {
448 if ( rarr(ispec) < rdep(i+1) ) {
449 ai = (yprime(i) + yprime(i+1) - 2*si(i)) / (hi(i)*hi(i)) ;
450 bi = (3*si(i) - 2*yprime(i) - yprime(i+1)) / hi(i) ;
454 while ( (rarr(ispec) < rdep(i+1)) && still_points ) {
455 double hh = rarr(ispec) - rdep(i) ;
456 farr.
t[ispec] = di + hh*(ci + hh*(bi + hh*ai)) ;
457 if (ispec < narr -1) ispec++ ;
458 else still_points = false ;
466 cout <<
"Unknown type of interpolation!" << endl ;
480 const Tbl& tarr,
const int type_inter)
const 492 Tbl *fdept =
new Tbl(nrv) ;
494 Tbl intermediaire(ntv, nrm) ;
501 for (
int i=0; i<ntv; i++) {
502 for (
int j=0; j<nrv; j++) fdept->
t[j] = fdep.
t[i*nrv+j] ;
505 for (
int j=0; j<nrm; j++) intermediaire.
t[i*nrm+j] = fr.t[j] ;
509 fdept =
new Tbl(ntv) ;
512 for (
int i=0; i<nrm; i++) {
513 for (
int j=0; j<ntv; j++) fdept->
t[j] = intermediaire.
t[j*nrm+i] ;
516 for (
int j=0; j<ntm; j++) farr.
set(j,i) = fr(j) ;
522 #ifndef DOXYGEN_SHOULD_SKIP_THIS 532 int copar(
const void* a,
const void* b) {
533 double x = (
reinterpret_cast<const Point*
>(a))->x ;
534 double y = (
reinterpret_cast<const Point*
>(b))->x ;
535 return x > y ? 1 : -1 ;
539 const Tbl& tetarr,
const int type_inter)
const 545 const Tbl& rarr,
const Tbl& tarr,
const int inter_type)
const {
562 Point* zlk =
new Point[narr] ;
565 for (it=0; it < nt; it++) {
566 for (ir=0; ir < nr; ir++) {
567 zlk[inum].x = rarr(ir)*
cos(tarr(it)) ;
574 void* base =
reinterpret_cast<void*
>(zlk) ;
575 size_t nel = size_t(narr) ;
576 size_t width =
sizeof(Point) ;
577 qsort (base, nel, width, copar) ;
581 double x12 = 1e-6*(zdep(nz-1) - zdep(0)) ;
588 if ( (zlk[inum].
x - zlk[inum-1].
x) > x12 ) {ndistz++ ; }
590 }
while (inum < narr) ;
598 errarr.
set(ndistz) = zlk[inum].x ;
601 if ( (zlk[inum].
x - zlk[inum-1].
x) > x12 ) {ndistz++ ; }
603 }
while (inum < narr) ;
608 Tbl tablo(nx, ndistz) ;
610 for (
int j=0; j<nx; j++) {
611 for (
int i=0; i<nz; i++) effdep.
set(i) = fdep(j,i) ;
612 effarr =
interpol1(zdep, errarr, effdep, ijob, inter_type) ;
614 for (
int i=0; i<ndistz; i++) tablo.
set(j,i) = effarr(i) ;
621 while (inum < narr) {
622 Point* xlk =
new Point[3*nr] ;
628 xlk[nxline].x = rarr(ir)*
sin(tarr(it)) ;
631 nxline ++ ; inum ++ ;
632 inum1 = (inum < narr ? inum : 0) ;
633 }
while ( ( (zlk[inum1].
x - zlk[inum-1].
x) < x12 ) && (inum < narr)) ;
634 void* bas2 =
reinterpret_cast<void*
>(xlk) ;
635 size_t ne2 = size_t(nxline) ;
636 qsort (bas2, ne2, width, copar) ;
642 if (inum2 < nxline) {
643 if ( (xlk[inum2].
x - xlk[inum2-1].
x) > x12 ) {ndistx++ ; }
645 }
while (inum2 < nxline) ;
648 Tbl errarr2(ndistx) ;
650 Tbl effarr2(ndistx) ;
654 errarr2.
set(ndistx) = xlk[inum2].x ;
656 if (inum2 < nxline) {
657 if ( (xlk[inum2].
x - xlk[inum2-1].
x) > x12 ) {ndistx++ ; }
659 }
while (inum2 < nxline) ;
662 for (
int j=0; j<nx; j++) {
663 effdep2.
set(j) = tablo(j,indz) ;
667 effarr2 =
interpol1(xdep, errarr2, effdep2, ijob, inter_type) ;
670 for (
int i=0; i<nxline; i++) {
671 while (fabs(xlk[i].
x - xdep(iresu)) > x12 ) {
676 farr.
set(it,ir) = effdep2(iresu) ;
681 for (
int i=0; i<nxline; i++) {
682 resu = effarr2(iresu) ;
684 if ((xlk[i+1].
x-xlk[i].
x) > x12) {
690 farr.
set(it,ir) = resu ;
707 const Tbl& parr,
const int type_inter)
const {
721 Tbl *fdept =
new Tbl(ntv, nrv) ;
723 Tbl intermediaire(npv, ntm, nrm) ;
726 Tbl farr(npm, ntm, nrm) ;
729 for (
int i=0; i<npv; i++) {
730 for (
int j=0; j<ntv; j++)
731 for (
int k=0; k<nrv; k++) fdept->
t[j*nrv+k] = fdep.
t[(i*ntv+j)*nrv+k] ;
733 for (
int j=0; j<ntm; j++)
734 for (
int k=0; k<nrm; k++) intermediaire.
set(i,j,k) = fr(j,k) ;
739 fdept =
new Tbl(npv) ;
741 for (
int i=0; i<ntm; i++) {
742 for (
int j=0; j<nrm; j++) {
743 for (
int k=0; k<npv; k++) fdept->
set(k) = intermediaire(k,i,j) ;
746 for (
int k=0; k<npm; k++) farr.
set(k,i,j) = fr(k) ;
754 const Tbl& tarr,
const Tbl& parr,
const 755 int inter_type)
const {
768 Tbl farr(np, nt, nr) ;
771 bool coq = (rarr(0)/rarr(nr-1) > 1.e-6) ;
774 rarr2 =
new Tbl(2*nr) ;
776 double dr = rarr(0)/nr ;
777 for (
int i=0; i<nr; i++) rarr2->
set(i) = i*dr ;
778 for (
int i=nr; i<2*nr; i++) rarr2->
set(i) = rarr(i-nr) ;
781 int nr2 = coq ? 2*nr : nr ;
783 Tbl cylindre(nz, np, nr2) ;
785 for(
int iz=0; iz<nz; iz++) {
788 Tbl cercle(np, nr2) ;
789 for (
int iy=0; iy<ny; iy++)
790 for (
int ix=0; ix<nx; ix++)
791 carre.
set(iy,ix) = fdep(iy,ix,iz) ;
792 cercle =
interpol2c(*
x, *
y, carre, coq ? *rarr2 : rarr, parr, inter_type) ;
794 for (
int ip=0; ip<np; ip++)
795 for (
int ir=0; ir<nr2; ir++)
796 cylindre.
set(iz,ip,ir) = cercle(ip,ir) ;
799 for (
int ip=0; ip<np; ip++) {
803 for (
int ir=0; ir<nr2; ir++)
804 for (
int iz=0; iz<nz; iz++)
805 carre.
set(ir,iz) = cylindre(iz,ip,ir) ;
806 cercle =
interpol2c(*
zr, coq ? *rarr2 : rarr , carre, rarr, tarr,
808 for (
int it=0; it<nt; it++)
809 for (
int ir=0; ir<nr; ir++)
810 farr.
set(ip,it,ir) = cercle(it,ir) ;
813 if (coq)
delete rarr2 ;
int get_type_p() const
Returns the type of sampling in the direction: SYM : : symmetry with respect to the transformatio...
double * xmax
Higher boundary for x dimension.
virtual Tbl interpol2(const Tbl &fdep, const Tbl &rarr, const Tbl &tetarr, const int type_inter) const
Performs 2D interpolation.
int get_np(int l) const
Returns the number of points in the azimuthal direction ( ) in domain no. l.
virtual bool compatible(const Map *mp, const int lmax, const int lmin=0) const
Checks if the spectral grid and mapping are compatible with the Grille_val caracteristics for the int...
const Mg3d * get_mg() const
Gives the Mg3d on which the mapping is defined.
Tbl * y
Arrays containing the values of coordinate y on the nodes.
double & set(int i)
Read/write of a particular element (index i) (1D case)
Base class for coordinate mappings.
Tbl * tet
Arrays containing the values of coordinate on the nodes.
double * zrmax
Higher boundary for z (or r ) direction.
int get_type_t() const
Returns the type of sampling in the direction: SYM : : symmetry with respect to the equatorial pl...
double * zrmin
Lower boundary for z (or r ) direction.
Cmp cos(const Cmp &)
Cosine.
double * ymax
Higher boundary for y dimension.
int type_t
Type of symmetry in :
virtual bool contenue_dans(const Map &mp, const int lmax, const int lmin=0) const
Checks if Gval_cart is contained inside the spectral grid/mapping within the domains [lmin...
double * xmin
Lower boundary for x dimension.
void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
double * ymin
Lower boundary for y dimension.
int get_ndim() const
Gives the number of dimensions (ie dim.ndim)
Tbl * x
Arrays containing the values of coordinate x on the nodes.
Dim_tbl dim
Number of dimensions, size,...
double * t
The array of double.
Tbl * zr
Arrays containing the values of coordinate z (or r) on the nodes.
int get_dim(int i) const
Gives the i-th dimension (ie dim.dim[i])
virtual Tbl interpol2(const Tbl &fdep, const Tbl &rarr, const Tbl &tetarr, const int type_inter) const
Performs 2D interpolation.
Active physical coordinates and mapping derivatives.
double get_zr(const int i) const
Read-only of a particular value of the coordinate z (or r ) at the nodes.
Tbl * phi
Arrays containing the values of coordinate on the nodes.
virtual Tbl interpol3(const Tbl &fdep, const Tbl &rarr, const Tbl &tetarr, const Tbl &phiarr, const int type_inter) const
Performs 3D interpolation.
int ndim
Number of dimensions of the Tbl: can be 1, 2 or 3.
int nfantome
The number of hidden cells (same on each side)
int get_nr(int l) const
Returns the number of points in the radial direction ( ) in domain no. l.
virtual bool compatible(const Map *mp, const int lmax, const int lmin=0) const
Checks if the spectral grid and mapping are compatible with the Grille_val caracteristics for the int...
Dim_tbl dim
The dimensions of the grid.
virtual bool contenue_dans(const Map &mp, const int lmax, const int lmin=0) const
Checks if Gval_spher is contained inside the spectral grid/mapping within the domains [lmin...
Tbl interpol2c(const Tbl &xdep, const Tbl &zdep, const Tbl &fdep, const Tbl &rarr, const Tbl &tetarr, const int type_inter) const
Same as before, but the coordinates of source points are passed explicitly (xdep, zdep)...
Cmp sin(const Cmp &)
Sine.
int get_nt(int l) const
Returns the number of points in the co-latitude direction ( ) in domain no. l.
Tbl interpol1(const Tbl &rdep, const Tbl &rarr, const Tbl &fdep, int flag, const int type_inter) const
Performs 1D interpolation.
int type_p
Type of symmetry in :
int * dim
Array of dimensions (size: ndim).
Coord r
r coordinate centered on the grid
virtual Tbl interpol3(const Tbl &fdep, const Tbl &rarr, const Tbl &tetarr, const Tbl &phiarr, const int type_inter) const
Performs 3D interpolation.