Actual source code: ex8.c
petsc-3.13.6 2020-09-29
1: static char help[] = "Test parallel ruotines for GLVis\n\n";
3: #include <petscdmshell.h>
4: #include <petsc/private/glvisvecimpl.h>
6: PetscErrorCode VecView_Shell(Vec v, PetscViewer viewer)
7: {
8: PetscViewerFormat format;
9: PetscBool isglvis,isascii;
13: PetscViewerGetFormat(viewer,&format);
14: PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERGLVIS,&isglvis);
15: PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&isascii);
16: if (isglvis) {
17: DM dm;
19: VecGetDM(v,&dm);
20: /* DMView() cannot be tested, as DMView_Shell defaults to VecView */
21: if (!dm) return(0);
22: VecView_GLVis(v,viewer);
23: } else if (isascii) {
24: const char* name;
25: PetscInt n;
27: VecGetLocalSize(v,&n);
28: PetscObjectGetName((PetscObject)v,&name);
29: if (!PetscGlobalRank) {
30: PetscViewerASCIIPrintf(viewer,"Hello from rank 0 -> vector name %s, size %D\n",name,n);
31: }
32: }
33: return(0);
34: }
36: PetscErrorCode DMSetUpGLVisViewer_Shell(PetscObject odm, PetscViewer viewer)
37: {
38: DM dm = (DM)odm;
39: Vec V;
40: PetscInt dim = 2;
41: const char *fec_type = { "testme" };
45: DMCreateGlobalVector(dm,&V);
46: PetscObjectSetName((PetscObject)V,"sample");
47: PetscViewerGLVisSetFields(viewer,1,&fec_type,&dim,NULL,(PetscObject*)&V,NULL,NULL);
48: VecDestroy(&V);
49: return(0);
50: }
52: int main(int argc, char **argv)
53: {
54: DM dm;
55: Vec v;
58: PetscInitialize(&argc,&argv,NULL,help);if (ierr) return ierr;
59: DMShellCreate(PETSC_COMM_WORLD,&dm);
60: PetscObjectComposeFunction((PetscObject)dm,"DMSetUpGLVisViewer_C",DMSetUpGLVisViewer_Shell);
61: VecCreateMPI(PETSC_COMM_WORLD,1,PETSC_DECIDE,&v);
62: PetscObjectSetName((PetscObject)v,"seed");
63: VecSetOperation(v,VECOP_VIEW,(void (*)(void))VecView_Shell);
64: DMShellSetGlobalVector(dm,v);
65: VecDestroy(&v);
66: DMViewFromOptions(dm,NULL,"-dm_view");
67: DMGetGlobalVector(dm,&v);
68: VecViewFromOptions(v,NULL,"-vec_view");
69: DMRestoreGlobalVector(dm,&v);
70: DMDestroy(&dm);
71: PetscFinalize();
72: return ierr;
73: }
75: /*TEST
77: test:
78: suffix: glvis_par
79: nsize: {{1 2}}
80: args: -dm_view glvis: -vec_view glvis:
81: output_file: output/ex8_glvis.out
83: TEST*/