Actual source code: ex41.c
petsc-3.8.4 2018-03-24
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;
20: PetscInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr;
21: PetscOptionsGetInt(NULL,0,"-stencil_width",&stencil_width,0);
22: PetscOptionsGetInt(NULL,0,"-dof",&dof,0);
24: 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);
25: DMSetFromOptions(da);
26: DMSetUp(da);
27: DMDAGetCorners(da,&xstart,&ystart,&zstart,&m,&n,&p);
29: DMCreateGlobalVector(da,&global);
30: DMDAVecGetArrayDOF(da,global,&vglobal);
31: for (k=zstart; k<zstart+p; k++) {
32: for (j=ystart; j<ystart+n; j++) {
33: for (i=xstart; i<xstart+m; i++) {
34: for (c=0; c<dof; c++) {
35: vglobal[k][j][i][c] = 1000*k + 100*j + 10*(i+1) + c;
36: }
37: }
38: }
39: }
40: DMDAVecRestoreArrayDOF(da,global,&vglobal);
42: DMCreateLocalVector(da,&local);
43: DMGlobalToLocalBegin(da,global,INSERT_VALUES,local);
44: DMGlobalToLocalEnd(da,global,INSERT_VALUES,local);
46: PetscSequentialPhaseBegin(PETSC_COMM_WORLD,1);
47: VecView(local,PETSC_VIEWER_STDOUT_SELF);
48: PetscSequentialPhaseEnd(PETSC_COMM_WORLD,1);
49: VecView(global,PETSC_VIEWER_STDOUT_WORLD);
51: DMDestroy(&da);
52: VecDestroy(&local);
53: VecDestroy(&global);
55: PetscFinalize();
56: return ierr;
57: }