Date: 2022-03-31T15:29:04+00:00

Actual source code: test1.c
slepc-3.17.0 2022-03-31
Report Typos and Errors

      1: /*
      2:    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      3:    SLEPc - Scalable Library for Eigenvalue Problem Computations
      4:    Copyright (c) 2002-, Universitat Politecnica de Valencia, Spain

      6:    This file is part of SLEPc.
      7:    SLEPc is distributed under a 2-clause BSD license (see LICENSE).
      8:    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      9: */

     11: static char help[] = "Test RG interface functions.\n\n";

     13: #include <slepcrg.h>

     15: #define NPOINTS 10
     16: #define NVERTEX 7

     18: int main(int argc,char **argv)
     19: {
     20:   RG             rg;
     21:   PetscInt       i,inside,nv;
     22:   PetscBool      triv;
     23:   PetscReal      re,im,a,b,c,d;
     24:   PetscScalar    ar,ai,cr[NPOINTS],ci[NPOINTS],vr[NVERTEX],vi[NVERTEX],*pr,*pi;

     26:   SlepcInitialize(&argc,&argv,(char*)0,help);
     27:   RGCreate(PETSC_COMM_WORLD,&rg);

     29:   /* ellipse */
     30:   RGSetType(rg,RGELLIPSE);
     31:   RGIsTrivial(rg,&triv);
     33:   RGEllipseSetParameters(rg,1.1,2,0.1);
     34:   RGSetFromOptions(rg);
     35:   RGIsTrivial(rg,&triv);
     37:   RGView(rg,NULL);
     38:   RGViewFromOptions(rg,NULL,"-rg_ellipse_view");
     39:   re = 0.1; im = 0.3;
     40: #if defined(PETSC_USE_COMPLEX)
     41:   ar = PetscCMPLX(re,im);
     42: #else
     43:   ar = re; ai = im;
     44: #endif
     45:   RGCheckInside(rg,1,&ar,&ai,&inside);
     46:   PetscPrintf(PETSC_COMM_WORLD,"Point (%g,%g) is %s the region\n",(double)re,(double)im,(inside>=0)?"inside":"outside");

     48:   RGComputeBoundingBox(rg,&a,&b,&c,&d);
     49:   PetscPrintf(PETSC_COMM_WORLD,"The bounding box is [%g,%g]x[%g,%g]\n",(double)a,(double)b,(double)c,(double)d);

     51:   PetscPrintf(PETSC_COMM_WORLD,"Contour points: ");
     52:   RGComputeContour(rg,NPOINTS,cr,ci);
     53:   for (i=0;i<NPOINTS;i++) {
     54: #if defined(PETSC_USE_COMPLEX)
     55:     re = PetscRealPart(cr[i]);
     56:     im = PetscImaginaryPart(cr[i]);
     57: #else
     58:     re = cr[i];
     59:     im = ci[i];
     60: #endif
     61:     PetscPrintf(PETSC_COMM_WORLD,"(%.3g,%.3g) ",(double)re,(double)im);
     62:   }
     63:   PetscPrintf(PETSC_COMM_WORLD,"\n");

     65:   /* interval */
     66:   RGSetType(rg,RGINTERVAL);
     67:   RGIsTrivial(rg,&triv);
     69:   RGIntervalSetEndpoints(rg,-1,1,-0.1,0.1);
     70:   RGSetFromOptions(rg);
     71:   RGIsTrivial(rg,&triv);
     73:   RGView(rg,NULL);
     74:   RGViewFromOptions(rg,NULL,"-rg_interval_view");
     75:   re = 0.2; im = 0;
     76: #if defined(PETSC_USE_COMPLEX)
     77:   ar = PetscCMPLX(re,im);
     78: #else
     79:   ar = re; ai = im;
     80: #endif
     81:   RGCheckInside(rg,1,&ar,&ai,&inside);
     82:   PetscPrintf(PETSC_COMM_WORLD,"Point (%g,%g) is %s the region\n",(double)re,(double)im,(inside>=0)?"inside":"outside");

     84:   RGComputeBoundingBox(rg,&a,&b,&c,&d);
     85:   PetscPrintf(PETSC_COMM_WORLD,"The bounding box is [%g,%g]x[%g,%g]\n",(double)a,(double)b,(double)c,(double)d);

     87:   PetscPrintf(PETSC_COMM_WORLD,"Contour points: ");
     88:   RGComputeContour(rg,NPOINTS,cr,ci);
     89:   for (i=0;i<NPOINTS;i++) {
     90: #if defined(PETSC_USE_COMPLEX)
     91:     re = PetscRealPart(cr[i]);
     92:     im = PetscImaginaryPart(cr[i]);
     93: #else
     94:     re = cr[i];
     95:     im = ci[i];
     96: #endif
     97:     PetscPrintf(PETSC_COMM_WORLD,"(%.3g,%.3g) ",(double)re,(double)im);
     98:   }
     99:   PetscPrintf(PETSC_COMM_WORLD,"\n");

    101:   /* polygon */
    102: #if defined(PETSC_USE_COMPLEX)
    103:   vr[0] = PetscCMPLX(0.0,2.0);
    104:   vr[1] = PetscCMPLX(1.0,4.0);
    105:   vr[2] = PetscCMPLX(2.0,5.0);
    106:   vr[3] = PetscCMPLX(4.0,3.0);
    107:   vr[4] = PetscCMPLX(5.0,4.0);
    108:   vr[5] = PetscCMPLX(6.0,1.0);
    109:   vr[6] = PetscCMPLX(2.0,0.0);
    110: #else
    111:   vr[0] = 0.0; vi[0] = 1.0;
    112:   vr[1] = 0.0; vi[1] = -1.0;
    113:   vr[2] = 0.6; vi[2] = -0.8;
    114:   vr[3] = 1.0; vi[3] = -1.0;
    115:   vr[4] = 2.0; vi[4] = 0.0;
    116:   vr[5] = 1.0; vi[5] = 1.0;
    117:   vr[6] = 0.6; vi[6] = 0.8;
    118: #endif
    119:   RGSetType(rg,RGPOLYGON);
    120:   RGIsTrivial(rg,&triv);
    122:   RGPolygonSetVertices(rg,NVERTEX,vr,vi);
    123:   RGSetFromOptions(rg);
    124:   RGIsTrivial(rg,&triv);
    126:   RGView(rg,NULL);
    127:   RGViewFromOptions(rg,NULL,"-rg_polygon_view");
    128:   re = 5; im = 0.9;
    129: #if defined(PETSC_USE_COMPLEX)
    130:   ar = PetscCMPLX(re,im);
    131: #else
    132:   ar = re; ai = im;
    133: #endif
    134:   RGCheckInside(rg,1,&ar,&ai,&inside);
    135:   PetscPrintf(PETSC_COMM_WORLD,"Point (%g,%g) is %s the region\n",(double)re,(double)im,(inside>=0)?"inside":"outside");

    137:   RGComputeBoundingBox(rg,&a,&b,&c,&d);
    138:   PetscPrintf(PETSC_COMM_WORLD,"The bounding box is [%g,%g]x[%g,%g]\n",(double)a,(double)b,(double)c,(double)d);

    140:   PetscPrintf(PETSC_COMM_WORLD,"Contour points: ");
    141:   RGComputeContour(rg,NPOINTS,cr,ci);
    142:   for (i=0;i<NPOINTS;i++) {
    143: #if defined(PETSC_USE_COMPLEX)
    144:     re = PetscRealPart(cr[i]);
    145:     im = PetscImaginaryPart(cr[i]);
    146: #else
    147:     re = cr[i];
    148:     im = ci[i];
    149: #endif
    150:     PetscPrintf(PETSC_COMM_WORLD,"(%.3g,%.3g) ",(double)re,(double)im);
    151:   }
    152:   PetscPrintf(PETSC_COMM_WORLD,"\n");

    154:   /* check vertices */
    155:   RGPolygonGetVertices(rg,&nv,&pr,&pi);
    157:   for (i=0;i<nv;i++) {
    158: #if !defined(PETSC_USE_COMPLEX)
    159:     if (pr[i]!=vr[i] || pi[i]!=vi[i])
    160: #else
    161:     if (pr[i]!=vr[i])
    162: #endif
    163:        SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_PLIB,"Vertex number %" PetscInt_FMT " does not match",i);
    164:   }

    166:   PetscFree(pr);
    167: #if !defined(PETSC_USE_COMPLEX)
    168:   PetscFree(pi);
    169: #endif
    170:   RGDestroy(&rg);
    171:   SlepcFinalize();
    172:   return 0;
    173: }

    175: /*TEST

    177:    test:
    178:       suffix: 1
    179:       requires: !complex

    181:    test:
    182:       suffix: 1_complex
    183:       requires: complex

    185:    test:
    186:       suffix: 2
    187:       requires: !complex
    188:       args: -rg_ellipse_view draw:tikz:ellipse.tikz -rg_interval_view draw:tikz:interval.tikz -rg_polygon_view draw:tikz:polygon.tikz
    189:       filter: cat - ellipse.tikz interval.tikz polygon.tikz
    190:       requires: !single

    192:    test:
    193:       suffix: 2_complex
    194:       requires: complex !single
    195:       args: -rg_ellipse_view draw:tikz:ellipse.tikz -rg_interval_view draw:tikz:interval.tikz -rg_polygon_view draw:tikz:polygon.tikz
    196:       filter: cat - ellipse.tikz interval.tikz polygon.tikz

    198: TEST*/