static char help[] = "Test GLVis high-order support with DMDAs\n\n"; #include #include #include #include static PetscErrorCode MapPoint(PetscScalar xyz[],PetscScalar mxyz[]) { PetscScalar x,y,z,x2,y2,z2; x = xyz[0]; y = xyz[1]; z = xyz[2]; x2 = x*x; y2 = y*y; z2 = z*z; mxyz[0] = x*PetscSqrtScalar(1.0-y2/2.0-z2/2.0 + y2*z2/3.0); mxyz[1] = y*PetscSqrtScalar(1.0-z2/2.0-x2/2.0 + z2*x2/3.0); mxyz[2] = z*PetscSqrtScalar(1.0-x2/2.0-y2/2.0 + x2*y2/3.0); return 0; } static PetscErrorCode test_3d(PetscInt cells[], PetscBool plex, PetscBool ho) { DM dm; Vec v; PetscScalar *c; PetscInt nl,i; PetscReal u[3] = {1.0,1.0,1.0}, l[3] = {-1.0,-1.0,-1.0}; PetscFunctionBeginUser; if (ho) { u[0] = 2.*cells[0]; u[1] = 2.*cells[1]; u[2] = 2.*cells[2]; l[0] = 0.; l[1] = 0.; l[2] = 0.; } if (plex) { PetscCall(DMCreate(PETSC_COMM_WORLD, &dm)); PetscCall(DMSetType(dm, DMPLEX)); PetscCall(DMSetFromOptions(dm)); } else { PetscCall(DMDACreate3d(PETSC_COMM_WORLD,DM_BOUNDARY_NONE,DM_BOUNDARY_NONE,DM_BOUNDARY_NONE,DMDA_STENCIL_BOX,cells[0]+1,cells[1]+1,cells[2]+1,PETSC_DECIDE,PETSC_DECIDE,PETSC_DECIDE,1,1,NULL,NULL,NULL,&dm)); } PetscCall(DMSetUp(dm)); if (!plex) { PetscCall(DMDASetUniformCoordinates(dm,l[0],u[0],l[1],u[1],l[2],u[2])); } if (ho) { /* each element mapped to a sphere */ DM cdm; Vec cv; PetscSection cSec; DMDACoor3d ***_coords; PetscScalar shift[3],*cptr; PetscInt nel,dof = 3,nex,ney,nez,gx = 0,gy = 0,gz = 0; PetscInt i,j,k,pi,pj,pk; PetscReal *nodes,*weights; char name[256]; PetscCall(PetscOptionsGetInt(NULL,NULL,"-order",&dof,NULL)); dof += 1; PetscCall(PetscMalloc1(dof,&nodes)); PetscCall(PetscMalloc1(dof,&weights)); PetscCall(PetscDTGaussLobattoLegendreQuadrature(dof,PETSCGAUSSLOBATTOLEGENDRE_VIA_LINEAR_ALGEBRA,nodes,weights)); PetscCall(DMGetCoordinatesLocal(dm,&cv)); PetscCall(DMGetCoordinateDM(dm,&cdm)); if (plex) { PetscInt cEnd,cStart; PetscCall(DMPlexGetHeightStratum(dm,0,&cStart,&cEnd)); PetscCall(DMGetCoordinateSection(dm,&cSec)); nel = cEnd - cStart; nex = nel; ney = 1; nez = 1; } else { PetscCall(DMDAVecGetArray(cdm,cv,&_coords)); PetscCall(DMDAGetElementsCorners(dm,&gx,&gy,&gz)); PetscCall(DMDAGetElementsSizes(dm,&nex,&ney,&nez)); nel = nex*ney*nez; } PetscCall(VecCreate(PETSC_COMM_WORLD,&v)); PetscCall(VecSetSizes(v,3*dof*dof*dof*nel,PETSC_DECIDE)); PetscCall(VecSetType(v,VECSTANDARD)); PetscCall(VecGetArray(v,&c)); cptr = c; for (k=gz;k