Actual source code: ex41.c
petsc-3.9.4 2018-09-11
2: static char help[] = "Tests mirror boundary conditions in 3-d.\n\n";
4: #include <petscdm.h>
5: #include <petscdmda.h>
7: /*
8: THIS EXAMPLE DOES NOT WORK BECAUSE MIRROR BOUNDARY IS NOT YET IMPLEMENTED FOR 3D
9: We need someone with incredible attention to detail to implement it.
10: */
12: int main(int argc,char **argv)
13: {
15: PetscInt M = 2, N = 3, P = 4,stencil_width = 1, dof = 1,m,n,p,xstart,ystart,zstart,i,j,k,c;
16: DM da;
17: Vec global,local;
18: PetscScalar ****vglobal;
19: PetscViewer sview;
21: PetscInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr;
22: PetscOptionsGetInt(NULL,0,"-stencil_width",&stencil_width,0);
23: PetscOptionsGetInt(NULL,0,"-dof",&dof,0);
25: DMDACreate3d(PETSC_COMM_WORLD,DM_BOUNDARY_MIRROR,DM_BOUNDARY_MIRROR,DM_BOUNDARY_MIRROR,DMDA_STENCIL_STAR,M,N,P,PETSC_DECIDE,PETSC_DECIDE,PETSC_DECIDE,dof,stencil_width,NULL,NULL,NULL,&da);
26: DMSetFromOptions(da);
27: DMSetUp(da);
28: DMDAGetCorners(da,&xstart,&ystart,&zstart,&m,&n,&p);
30: DMCreateGlobalVector(da,&global);
31: DMDAVecGetArrayDOF(da,global,&vglobal);
32: for (k=zstart; k<zstart+p; k++) {
33: for (j=ystart; j<ystart+n; j++) {
34: for (i=xstart; i<xstart+m; i++) {
35: for (c=0; c<dof; c++) {
36: vglobal[k][j][i][c] = 1000*k + 100*j + 10*(i+1) + c;
37: }
38: }
39: }
40: }
41: DMDAVecRestoreArrayDOF(da,global,&vglobal);
43: DMCreateLocalVector(da,&local);
44: DMGlobalToLocalBegin(da,global,INSERT_VALUES,local);
45: DMGlobalToLocalEnd(da,global,INSERT_VALUES,local);
47: PetscViewerGetSubViewer(PETSC_VIEWER_STDOUT_WORLD,PETSC_COMM_SELF,&sview);
48: VecView(local,sview);
49: PetscViewerRestoreSubViewer(PETSC_VIEWER_STDOUT_WORLD,PETSC_COMM_SELF,&sview);
50: PetscViewerFlush(PETSC_VIEWER_STDOUT_WORLD);
52: DMDestroy(&da);
53: VecDestroy(&local);
54: VecDestroy(&global);
56: PetscFinalize();
57: return ierr;
58: }
60: /*TEST
62: test:
63: TODO: need mirror support in 3d
65: TEST*/