Actual source code: trajvisualization.c
petsc-3.7.3 2016-08-01
2: #include <petsc/private/tsimpl.h> /*I "petscts.h" I*/
6: static PetscErrorCode OutputBIN(const char *filename,PetscViewer *viewer)
7: {
11: PetscViewerCreate(PETSC_COMM_WORLD,viewer);
12: PetscViewerSetType(*viewer,PETSCVIEWERBINARY);
13: PetscViewerFileSetMode(*viewer,FILE_MODE_WRITE);
14: PetscViewerFileSetName(*viewer,filename);
15: return(0);
16: }
20: static PetscErrorCode TSTrajectorySet_Visualization(TSTrajectory tj,TS ts,PetscInt stepnum,PetscReal time,Vec X)
21: {
22: PetscViewer viewer;
23: char filename[PETSC_MAX_PATH_LEN];
24: PetscReal tprev;
28: TSGetTotalSteps(ts,&stepnum);
29: if (stepnum == 0) {
30: PetscMPIInt rank;
31: MPI_Comm_rank(PetscObjectComm((PetscObject)ts),&rank);
32: if (!rank) {
33: PetscRMTree("Visualization-data");
34: PetscMkdir("Visualization-data");
35: }
36: PetscSNPrintf(filename,sizeof(filename),"Visualization-data/SA-%06d.bin",stepnum);
37: OutputBIN(filename,&viewer);
38: VecView(X,viewer);
39: PetscViewerBinaryWrite(viewer,&time,1,PETSC_REAL,PETSC_FALSE);
40: PetscViewerDestroy(&viewer);
41: return(0);
42: }
43: PetscSNPrintf(filename,sizeof(filename),"Visualization-data/SA-%06d.bin",stepnum);
44: OutputBIN(filename,&viewer);
45: VecView(X,viewer);
46: PetscViewerBinaryWrite(viewer,&time,1,PETSC_REAL,PETSC_FALSE);
48: TSGetPrevTime(ts,&tprev);
49: PetscViewerBinaryWrite(viewer,&tprev,1,PETSC_REAL,PETSC_FALSE);
51: PetscViewerDestroy(&viewer);
52: return(0);
53: }
55: /*MC
56: TSTRAJECTORYVISUALIZATION - Stores each solution of the ODE/DAE in a file
58: Level: intermediate
60: .seealso: TSTrajectoryCreate(), TS, TSTrajectorySetType()
62: M*/
65: PETSC_EXTERN PetscErrorCode TSTrajectoryCreate_Visualization(TSTrajectory tj,TS ts)
66: {
68: tj->ops->set = TSTrajectorySet_Visualization;
69: return(0);
70: }