15c6c1daeSBarry Smith 2af0996ceSBarry Smith #include <petsc/private/viewerimpl.h> /*I "petscviewer.h" I*/ 35c6c1daeSBarry Smith 45c6c1daeSBarry Smith PetscClassId PETSC_VIEWER_CLASSID; 55c6c1daeSBarry Smith 65c6c1daeSBarry Smith static PetscBool PetscViewerPackageInitialized = PETSC_FALSE; 75c6c1daeSBarry Smith /*@C 8b6dade52SBarry Smith PetscViewerFinalizePackage - This function destroys any global objects created in the Petsc viewers. It is 95c6c1daeSBarry Smith called from PetscFinalize(). 105c6c1daeSBarry Smith 115c6c1daeSBarry Smith Level: developer 125c6c1daeSBarry Smith 135c6c1daeSBarry Smith .keywords: Petsc, destroy, package, mathematica 145c6c1daeSBarry Smith .seealso: PetscFinalize() 155c6c1daeSBarry Smith @*/ 165c6c1daeSBarry Smith PetscErrorCode PetscViewerFinalizePackage(void) 175c6c1daeSBarry Smith { 1837e93019SBarry Smith PetscErrorCode ierr; 1937e93019SBarry Smith 205c6c1daeSBarry Smith PetscFunctionBegin; 21b6dade52SBarry Smith if (Petsc_Viewer_keyval != MPI_KEYVAL_INVALID) { 2247435625SJed Brown ierr = MPI_Comm_free_keyval(&Petsc_Viewer_keyval);CHKERRQ(ierr); 23b6dade52SBarry Smith } 24b6dade52SBarry Smith if (Petsc_Viewer_Stdout_keyval != MPI_KEYVAL_INVALID) { 2547435625SJed Brown ierr = MPI_Comm_free_keyval(&Petsc_Viewer_Stdout_keyval);CHKERRQ(ierr); 26b6dade52SBarry Smith } 27b6dade52SBarry Smith if (Petsc_Viewer_Stderr_keyval != MPI_KEYVAL_INVALID) { 2847435625SJed Brown ierr = MPI_Comm_free_keyval(&Petsc_Viewer_Stderr_keyval);CHKERRQ(ierr); 29b6dade52SBarry Smith } 30b6dade52SBarry Smith if (Petsc_Viewer_Binary_keyval != MPI_KEYVAL_INVALID) { 3147435625SJed Brown ierr = MPI_Comm_free_keyval(&Petsc_Viewer_Binary_keyval);CHKERRQ(ierr); 32b6dade52SBarry Smith } 33b6dade52SBarry Smith if (Petsc_Viewer_Draw_keyval != MPI_KEYVAL_INVALID) { 3447435625SJed Brown ierr = MPI_Comm_free_keyval(&Petsc_Viewer_Draw_keyval);CHKERRQ(ierr); 35b6dade52SBarry Smith } 36b6dade52SBarry Smith #if defined(PETSC_HAVE_HDF5) 37b6dade52SBarry Smith if (Petsc_Viewer_HDF5_keyval != MPI_KEYVAL_INVALID) { 3847435625SJed Brown ierr = MPI_Comm_free_keyval(&Petsc_Viewer_HDF5_keyval);CHKERRQ(ierr); 39b6dade52SBarry Smith } 40b6dade52SBarry Smith #endif 41b6dade52SBarry Smith #if defined(PETSC_USE_SOCKETVIEWER) 42b6dade52SBarry Smith if (Petsc_Viewer_Socket_keyval != MPI_KEYVAL_INVALID) { 4347435625SJed Brown ierr = MPI_Comm_free_keyval(&Petsc_Viewer_Socket_keyval);CHKERRQ(ierr); 44b6dade52SBarry Smith } 45b6dade52SBarry Smith #endif 4637e93019SBarry Smith ierr = PetscFunctionListDestroy(&PetscViewerList);CHKERRQ(ierr); 475c6c1daeSBarry Smith PetscViewerPackageInitialized = PETSC_FALSE; 480f51fdf8SToby Isaac PetscViewerRegisterAllCalled = PETSC_FALSE; 495c6c1daeSBarry Smith PetscFunctionReturn(0); 505c6c1daeSBarry Smith } 515c6c1daeSBarry Smith 525c6c1daeSBarry Smith /*@C 535c6c1daeSBarry Smith PetscViewerInitializePackage - This function initializes everything in the main PetscViewer package. 545c6c1daeSBarry Smith 555c6c1daeSBarry Smith Level: developer 565c6c1daeSBarry Smith 575c6c1daeSBarry Smith .keywords: Petsc, initialize, package 585c6c1daeSBarry Smith .seealso: PetscInitialize() 595c6c1daeSBarry Smith @*/ 60607a6623SBarry Smith PetscErrorCode PetscViewerInitializePackage(void) 615c6c1daeSBarry Smith { 625c6c1daeSBarry Smith char logList[256]; 638e81d068SLisandro Dalcin PetscBool opt,pkg; 645c6c1daeSBarry Smith PetscErrorCode ierr; 655c6c1daeSBarry Smith 665c6c1daeSBarry Smith PetscFunctionBegin; 675c6c1daeSBarry Smith if (PetscViewerPackageInitialized) PetscFunctionReturn(0); 685c6c1daeSBarry Smith PetscViewerPackageInitialized = PETSC_TRUE; 695c6c1daeSBarry Smith /* Register Classes */ 705c6c1daeSBarry Smith ierr = PetscClassIdRegister("Viewer",&PETSC_VIEWER_CLASSID);CHKERRQ(ierr); 715c6c1daeSBarry Smith /* Register Constructors */ 72607a6623SBarry Smith ierr = PetscViewerRegisterAll();CHKERRQ(ierr); 735c6c1daeSBarry Smith /* Process info exclusions */ 748e81d068SLisandro Dalcin ierr = PetscOptionsGetString(NULL,NULL,"-info_exclude",logList,sizeof(logList),&opt);CHKERRQ(ierr); 755c6c1daeSBarry Smith if (opt) { 768e81d068SLisandro Dalcin ierr = PetscStrInList("viewer",logList,',',&pkg);CHKERRQ(ierr); 778e81d068SLisandro Dalcin if (pkg) {ierr = PetscInfoDeactivateClass(PETSC_VIEWER_CLASSID);CHKERRQ(ierr);} 785c6c1daeSBarry Smith } 795c6c1daeSBarry Smith /* Process summary exclusions */ 808e81d068SLisandro Dalcin ierr = PetscOptionsGetString(NULL,NULL,"-log_exclude",logList,sizeof(logList),&opt);CHKERRQ(ierr); 815c6c1daeSBarry Smith if (opt) { 828e81d068SLisandro Dalcin ierr = PetscStrInList("viewer",logList,',',&pkg);CHKERRQ(ierr); 83fa2bb9feSLisandro Dalcin if (pkg) {ierr = PetscLogEventExcludeClass(PETSC_VIEWER_CLASSID);CHKERRQ(ierr);} 845c6c1daeSBarry Smith } 855c6c1daeSBarry Smith #if defined(PETSC_HAVE_MATHEMATICA) 86607a6623SBarry Smith ierr = PetscViewerMathematicaInitializePackage();CHKERRQ(ierr); 875c6c1daeSBarry Smith #endif 888e81d068SLisandro Dalcin /* Register package finalizer */ 895c6c1daeSBarry Smith ierr = PetscRegisterFinalize(PetscViewerFinalizePackage);CHKERRQ(ierr); 905c6c1daeSBarry Smith PetscFunctionReturn(0); 915c6c1daeSBarry Smith } 925c6c1daeSBarry Smith 935c6c1daeSBarry Smith /*@ 945c6c1daeSBarry Smith PetscViewerDestroy - Destroys a PetscViewer. 955c6c1daeSBarry Smith 965c6c1daeSBarry Smith Collective on PetscViewer 975c6c1daeSBarry Smith 985c6c1daeSBarry Smith Input Parameters: 995c6c1daeSBarry Smith . viewer - the PetscViewer to be destroyed. 1005c6c1daeSBarry Smith 1015c6c1daeSBarry Smith Level: beginner 1025c6c1daeSBarry Smith 1035c6c1daeSBarry Smith .seealso: PetscViewerSocketOpen(), PetscViewerASCIIOpen(), PetscViewerCreate(), PetscViewerDrawOpen() 1045c6c1daeSBarry Smith 1055c6c1daeSBarry Smith @*/ 1065c6c1daeSBarry Smith PetscErrorCode PetscViewerDestroy(PetscViewer *viewer) 1075c6c1daeSBarry Smith { 1085c6c1daeSBarry Smith PetscErrorCode ierr; 1095c6c1daeSBarry Smith 1105c6c1daeSBarry Smith PetscFunctionBegin; 1115c6c1daeSBarry Smith if (!*viewer) PetscFunctionReturn(0); 1125c6c1daeSBarry Smith PetscValidHeaderSpecific(*viewer,PETSC_VIEWER_CLASSID,1); 1135c6c1daeSBarry Smith 1145c6c1daeSBarry Smith ierr = PetscViewerFlush(*viewer);CHKERRQ(ierr); 1155c6c1daeSBarry Smith if (--((PetscObject)(*viewer))->refct > 0) {*viewer = 0; PetscFunctionReturn(0);} 1165c6c1daeSBarry Smith 117e04113cfSBarry Smith ierr = PetscObjectSAWsViewOff((PetscObject)*viewer);CHKERRQ(ierr); 1185c6c1daeSBarry Smith if ((*viewer)->ops->destroy) { 1195c6c1daeSBarry Smith ierr = (*(*viewer)->ops->destroy)(*viewer);CHKERRQ(ierr); 1205c6c1daeSBarry Smith } 1215c6c1daeSBarry Smith ierr = PetscHeaderDestroy(viewer);CHKERRQ(ierr); 1225c6c1daeSBarry Smith PetscFunctionReturn(0); 1235c6c1daeSBarry Smith } 1245c6c1daeSBarry Smith 125d7cbc13eSBarry Smith /*@C 126d7cbc13eSBarry Smith PetscViewerAndFormatCreate - Creates a PetscViewerAndFormat struct. 127d7cbc13eSBarry Smith 128d7cbc13eSBarry Smith Collective on PetscViewer 129d7cbc13eSBarry Smith 130d7cbc13eSBarry Smith Input Parameters: 131d7cbc13eSBarry Smith + viewer - the viewer 132d7cbc13eSBarry Smith - format - the format 133d7cbc13eSBarry Smith 134d7cbc13eSBarry Smith Output Parameter: 135d7cbc13eSBarry Smith . vf - viewer and format object 136d7cbc13eSBarry Smith 13795452b02SPatrick Sanan Notes: 13895452b02SPatrick Sanan This increases the reference count of the viewer so you can destroy the viewer object after this call 139d7cbc13eSBarry Smith Level: developer 140d7cbc13eSBarry Smith 141d7cbc13eSBarry Smith This is used as the context variable for many of the TS, SNES, and KSP monitor functions 142d7cbc13eSBarry Smith 143d7cbc13eSBarry Smith .seealso: PetscViewerSocketOpen(), PetscViewerASCIIOpen(), PetscViewerCreate(), PetscViewerDrawOpen(), PetscViewerAndFormatDestroy() 144d7cbc13eSBarry Smith 145d7cbc13eSBarry Smith @*/ 146d7cbc13eSBarry Smith PetscErrorCode PetscViewerAndFormatCreate(PetscViewer viewer, PetscViewerFormat format,PetscViewerAndFormat **vf) 147d7cbc13eSBarry Smith { 148d7cbc13eSBarry Smith PetscErrorCode ierr; 149d7cbc13eSBarry Smith 150d7cbc13eSBarry Smith PetscFunctionBegin; 151d7cbc13eSBarry Smith ierr = PetscObjectReference((PetscObject)viewer);CHKERRQ(ierr); 152d7cbc13eSBarry Smith ierr = PetscNew(vf);CHKERRQ(ierr); 153d7cbc13eSBarry Smith (*vf)->viewer = viewer; 154d7cbc13eSBarry Smith (*vf)->format = format; 155d7cbc13eSBarry Smith PetscFunctionReturn(0); 156d7cbc13eSBarry Smith } 157d7cbc13eSBarry Smith 158d7cbc13eSBarry Smith 159fe01d993SBarry Smith /*@C 160fe01d993SBarry Smith PetscViewerAndFormatDestroy - Destroys a PetscViewerAndFormat struct. 161fe01d993SBarry Smith 162fe01d993SBarry Smith Collective on PetscViewer 163fe01d993SBarry Smith 164fe01d993SBarry Smith Input Parameters: 165fe01d993SBarry Smith . viewer - the PetscViewerAndFormat to be destroyed. 166fe01d993SBarry Smith 167d7cbc13eSBarry Smith Level: developer 168fe01d993SBarry Smith 169d7cbc13eSBarry Smith .seealso: PetscViewerSocketOpen(), PetscViewerASCIIOpen(), PetscViewerCreate(), PetscViewerDrawOpen(), PetscViewerAndFormatCreate() 170fe01d993SBarry Smith 171fe01d993SBarry Smith @*/ 172fe01d993SBarry Smith PetscErrorCode PetscViewerAndFormatDestroy(PetscViewerAndFormat **vf) 173fe01d993SBarry Smith { 174fe01d993SBarry Smith PetscErrorCode ierr; 175fe01d993SBarry Smith 176fe01d993SBarry Smith PetscFunctionBegin; 177fe01d993SBarry Smith ierr = PetscViewerDestroy(&(*vf)->viewer);CHKERRQ(ierr); 178fe01d993SBarry Smith ierr = PetscFree(*vf);CHKERRQ(ierr); 179fe01d993SBarry Smith PetscFunctionReturn(0); 180fe01d993SBarry Smith } 181fe01d993SBarry Smith 1825c6c1daeSBarry Smith /*@C 1835c6c1daeSBarry Smith PetscViewerGetType - Returns the type of a PetscViewer. 1845c6c1daeSBarry Smith 1855c6c1daeSBarry Smith Not Collective 1865c6c1daeSBarry Smith 1875c6c1daeSBarry Smith Input Parameter: 1885c6c1daeSBarry Smith . viewer - the PetscViewer 1895c6c1daeSBarry Smith 1905c6c1daeSBarry Smith Output Parameter: 1915c6c1daeSBarry Smith . type - PetscViewer type (see below) 1925c6c1daeSBarry Smith 1935c6c1daeSBarry Smith Available Types Include: 194*a2b725a8SWilliam Gropp + PETSCVIEWERSOCKET - Socket PetscViewer 1955c6c1daeSBarry Smith . PETSCVIEWERASCII - ASCII PetscViewer 1965c6c1daeSBarry Smith . PETSCVIEWERBINARY - binary file PetscViewer 1975c6c1daeSBarry Smith . PETSCVIEWERSTRING - string PetscViewer 198*a2b725a8SWilliam Gropp - PETSCVIEWERDRAW - drawing PetscViewer 1995c6c1daeSBarry Smith 2005c6c1daeSBarry Smith Level: intermediate 2015c6c1daeSBarry Smith 2025c6c1daeSBarry Smith Note: 2035c6c1daeSBarry Smith See include/petscviewer.h for a complete list of PetscViewers. 2045c6c1daeSBarry Smith 2055c6c1daeSBarry Smith PetscViewerType is actually a string 2065c6c1daeSBarry Smith 2075c6c1daeSBarry Smith .seealso: PetscViewerCreate(), PetscViewerSetType(), PetscViewerType 2085c6c1daeSBarry Smith 2095c6c1daeSBarry Smith @*/ 2105c6c1daeSBarry Smith PetscErrorCode PetscViewerGetType(PetscViewer viewer,PetscViewerType *type) 2115c6c1daeSBarry Smith { 2125c6c1daeSBarry Smith PetscFunctionBegin; 2135c6c1daeSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 2145c6c1daeSBarry Smith PetscValidPointer(type,2); 2155c6c1daeSBarry Smith *type = ((PetscObject)viewer)->type_name; 2165c6c1daeSBarry Smith PetscFunctionReturn(0); 2175c6c1daeSBarry Smith } 2185c6c1daeSBarry Smith 2195c6c1daeSBarry Smith /*@C 2205c6c1daeSBarry Smith PetscViewerSetOptionsPrefix - Sets the prefix used for searching for all 2215c6c1daeSBarry Smith PetscViewer options in the database. 2225c6c1daeSBarry Smith 2235c6c1daeSBarry Smith Logically Collective on PetscViewer 2245c6c1daeSBarry Smith 2255c6c1daeSBarry Smith Input Parameter: 2265c6c1daeSBarry Smith + viewer - the PetscViewer context 2275c6c1daeSBarry Smith - prefix - the prefix to prepend to all option names 2285c6c1daeSBarry Smith 2295c6c1daeSBarry Smith Notes: 2305c6c1daeSBarry Smith A hyphen (-) must NOT be given at the beginning of the prefix name. 2315c6c1daeSBarry Smith The first character of all runtime options is AUTOMATICALLY the hyphen. 2325c6c1daeSBarry Smith 2335c6c1daeSBarry Smith Level: advanced 2345c6c1daeSBarry Smith 2355c6c1daeSBarry Smith .keywords: PetscViewer, set, options, prefix, database 2365c6c1daeSBarry Smith 2375c6c1daeSBarry Smith .seealso: PetscViewerSetFromOptions() 2385c6c1daeSBarry Smith @*/ 2395c6c1daeSBarry Smith PetscErrorCode PetscViewerSetOptionsPrefix(PetscViewer viewer,const char prefix[]) 2405c6c1daeSBarry Smith { 2415c6c1daeSBarry Smith PetscErrorCode ierr; 2425c6c1daeSBarry Smith 2435c6c1daeSBarry Smith PetscFunctionBegin; 2445c6c1daeSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 2455c6c1daeSBarry Smith ierr = PetscObjectSetOptionsPrefix((PetscObject)viewer,prefix);CHKERRQ(ierr); 2465c6c1daeSBarry Smith PetscFunctionReturn(0); 2475c6c1daeSBarry Smith } 2485c6c1daeSBarry Smith 2495c6c1daeSBarry Smith /*@C 2505c6c1daeSBarry Smith PetscViewerAppendOptionsPrefix - Appends to the prefix used for searching for all 2515c6c1daeSBarry Smith PetscViewer options in the database. 2525c6c1daeSBarry Smith 2535c6c1daeSBarry Smith Logically Collective on PetscViewer 2545c6c1daeSBarry Smith 2555c6c1daeSBarry Smith Input Parameters: 2565c6c1daeSBarry Smith + viewer - the PetscViewer context 2575c6c1daeSBarry Smith - prefix - the prefix to prepend to all option names 2585c6c1daeSBarry Smith 2595c6c1daeSBarry Smith Notes: 2605c6c1daeSBarry Smith A hyphen (-) must NOT be given at the beginning of the prefix name. 2615c6c1daeSBarry Smith The first character of all runtime options is AUTOMATICALLY the hyphen. 2625c6c1daeSBarry Smith 2635c6c1daeSBarry Smith Level: advanced 2645c6c1daeSBarry Smith 2655c6c1daeSBarry Smith .keywords: PetscViewer, append, options, prefix, database 2665c6c1daeSBarry Smith 2675c6c1daeSBarry Smith .seealso: PetscViewerGetOptionsPrefix() 2685c6c1daeSBarry Smith @*/ 2695c6c1daeSBarry Smith PetscErrorCode PetscViewerAppendOptionsPrefix(PetscViewer viewer,const char prefix[]) 2705c6c1daeSBarry Smith { 2715c6c1daeSBarry Smith PetscErrorCode ierr; 2725c6c1daeSBarry Smith 2735c6c1daeSBarry Smith PetscFunctionBegin; 2745c6c1daeSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 2755c6c1daeSBarry Smith ierr = PetscObjectAppendOptionsPrefix((PetscObject)viewer,prefix);CHKERRQ(ierr); 2765c6c1daeSBarry Smith PetscFunctionReturn(0); 2775c6c1daeSBarry Smith } 2785c6c1daeSBarry Smith 2795c6c1daeSBarry Smith /*@C 2805c6c1daeSBarry Smith PetscViewerGetOptionsPrefix - Sets the prefix used for searching for all 2815c6c1daeSBarry Smith PetscViewer options in the database. 2825c6c1daeSBarry Smith 2835c6c1daeSBarry Smith Not Collective 2845c6c1daeSBarry Smith 2855c6c1daeSBarry Smith Input Parameter: 2865c6c1daeSBarry Smith . viewer - the PetscViewer context 2875c6c1daeSBarry Smith 2885c6c1daeSBarry Smith Output Parameter: 2895c6c1daeSBarry Smith . prefix - pointer to the prefix string used 2905c6c1daeSBarry Smith 29195452b02SPatrick Sanan Notes: 29295452b02SPatrick Sanan On the fortran side, the user should pass in a string 'prefix' of 2935c6c1daeSBarry Smith sufficient length to hold the prefix. 2945c6c1daeSBarry Smith 2955c6c1daeSBarry Smith Level: advanced 2965c6c1daeSBarry Smith 2975c6c1daeSBarry Smith .keywords: PetscViewer, get, options, prefix, database 2985c6c1daeSBarry Smith 2995c6c1daeSBarry Smith .seealso: PetscViewerAppendOptionsPrefix() 3005c6c1daeSBarry Smith @*/ 3015c6c1daeSBarry Smith PetscErrorCode PetscViewerGetOptionsPrefix(PetscViewer viewer,const char *prefix[]) 3025c6c1daeSBarry Smith { 3035c6c1daeSBarry Smith PetscErrorCode ierr; 3045c6c1daeSBarry Smith 3055c6c1daeSBarry Smith PetscFunctionBegin; 3065c6c1daeSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 3075c6c1daeSBarry Smith ierr = PetscObjectGetOptionsPrefix((PetscObject)viewer,prefix);CHKERRQ(ierr); 3085c6c1daeSBarry Smith PetscFunctionReturn(0); 3095c6c1daeSBarry Smith } 3105c6c1daeSBarry Smith 3115c6c1daeSBarry Smith /*@ 3125c6c1daeSBarry Smith PetscViewerSetUp - Sets up the internal viewer data structures for the later use. 3135c6c1daeSBarry Smith 3145c6c1daeSBarry Smith Collective on PetscViewer 3155c6c1daeSBarry Smith 3165c6c1daeSBarry Smith Input Parameters: 3175c6c1daeSBarry Smith . viewer - the PetscViewer context 3185c6c1daeSBarry Smith 3195c6c1daeSBarry Smith Notes: 3205c6c1daeSBarry Smith For basic use of the PetscViewer classes the user need not explicitly call 3215c6c1daeSBarry Smith PetscViewerSetUp(), since these actions will happen automatically. 3225c6c1daeSBarry Smith 3235c6c1daeSBarry Smith Level: advanced 3245c6c1daeSBarry Smith 3255c6c1daeSBarry Smith .keywords: PetscViewer, setup 3265c6c1daeSBarry Smith 3275c6c1daeSBarry Smith .seealso: PetscViewerCreate(), PetscViewerDestroy() 3285c6c1daeSBarry Smith @*/ 3295c6c1daeSBarry Smith PetscErrorCode PetscViewerSetUp(PetscViewer viewer) 3305c6c1daeSBarry Smith { 331c98fd787SBarry Smith PetscErrorCode ierr; 332c98fd787SBarry Smith 3335c6c1daeSBarry Smith PetscFunctionBegin; 3345c6c1daeSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 335c98fd787SBarry Smith if (viewer->setupcalled) PetscFunctionReturn(0); 336c98fd787SBarry Smith if (viewer->ops->setup) { 337c98fd787SBarry Smith ierr = (*viewer->ops->setup)(viewer);CHKERRQ(ierr); 338c98fd787SBarry Smith } 339c98fd787SBarry Smith viewer->setupcalled = PETSC_TRUE; 3405c6c1daeSBarry Smith PetscFunctionReturn(0); 3415c6c1daeSBarry Smith } 3425c6c1daeSBarry Smith 3435c6c1daeSBarry Smith /*@C 3445c6c1daeSBarry Smith PetscViewerView - Visualizes a viewer object. 3455c6c1daeSBarry Smith 3465c6c1daeSBarry Smith Collective on PetscViewer 3475c6c1daeSBarry Smith 3485c6c1daeSBarry Smith Input Parameters: 3495c6c1daeSBarry Smith + v - the viewer 3505c6c1daeSBarry Smith - viewer - visualization context 3515c6c1daeSBarry Smith 3525c6c1daeSBarry Smith Notes: 3535c6c1daeSBarry Smith The available visualization contexts include 3545c6c1daeSBarry Smith + PETSC_VIEWER_STDOUT_SELF - standard output (default) 3555c6c1daeSBarry Smith . PETSC_VIEWER_STDOUT_WORLD - synchronized standard 3565c6c1daeSBarry Smith output where only the first processor opens 3575c6c1daeSBarry Smith the file. All other processors send their 3585c6c1daeSBarry Smith data to the first processor to print. 3595c6c1daeSBarry Smith - PETSC_VIEWER_DRAW_WORLD - graphical display of nonzero structure 3605c6c1daeSBarry Smith 3615c6c1daeSBarry Smith Level: beginner 3625c6c1daeSBarry Smith 3636a9046bcSBarry Smith .seealso: PetscViewerPushFormat(), PetscViewerASCIIOpen(), PetscViewerDrawOpen(), 3645c6c1daeSBarry Smith PetscViewerSocketOpen(), PetscViewerBinaryOpen(), PetscViewerLoad() 3655c6c1daeSBarry Smith @*/ 3665c6c1daeSBarry Smith PetscErrorCode PetscViewerView(PetscViewer v,PetscViewer viewer) 3675c6c1daeSBarry Smith { 3685c6c1daeSBarry Smith PetscErrorCode ierr; 3695c6c1daeSBarry Smith PetscBool iascii; 3705c6c1daeSBarry Smith PetscViewerFormat format; 371e04113cfSBarry Smith #if defined(PETSC_HAVE_SAWS) 372536b137fSBarry Smith PetscBool issaws; 3730076e027SBarry Smith #endif 3745c6c1daeSBarry Smith 3755c6c1daeSBarry Smith PetscFunctionBegin; 3765c6c1daeSBarry Smith PetscValidHeaderSpecific(v,PETSC_VIEWER_CLASSID,1); 3775c6c1daeSBarry Smith PetscValidType(v,1); 3785c6c1daeSBarry Smith if (!viewer) { 379ce94432eSBarry Smith ierr = PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)v),&viewer);CHKERRQ(ierr); 3805c6c1daeSBarry Smith } 3815c6c1daeSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,2); 3825c6c1daeSBarry Smith PetscCheckSameComm(v,1,viewer,2); 3835c6c1daeSBarry Smith 3845c6c1daeSBarry Smith ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);CHKERRQ(ierr); 385e04113cfSBarry Smith #if defined(PETSC_HAVE_SAWS) 386536b137fSBarry Smith ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERSAWS,&issaws);CHKERRQ(ierr); 3870076e027SBarry Smith #endif 3885c6c1daeSBarry Smith if (iascii) { 3895c6c1daeSBarry Smith ierr = PetscViewerGetFormat(viewer,&format);CHKERRQ(ierr); 390dae58748SBarry Smith ierr = PetscObjectPrintClassNamePrefixType((PetscObject)v,viewer);CHKERRQ(ierr); 39198c3331eSBarry Smith if (format == PETSC_VIEWER_DEFAULT || format == PETSC_VIEWER_ASCII_INFO || format == PETSC_VIEWER_ASCII_INFO_DETAIL) { 3922f234a98SBarry Smith if (v->format) { 3932f234a98SBarry Smith ierr = PetscViewerASCIIPrintf(viewer," Viewer format = %s\n",PetscViewerFormats[v->format]);CHKERRQ(ierr); 3942f234a98SBarry Smith } 3955c6c1daeSBarry Smith ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); 3962bf49c77SBarry Smith if (v->ops->view) { 3972bf49c77SBarry Smith ierr = (*v->ops->view)(v,viewer);CHKERRQ(ierr); 3985c6c1daeSBarry Smith } 3995c6c1daeSBarry Smith ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); 4005c6c1daeSBarry Smith } 401e04113cfSBarry Smith #if defined(PETSC_HAVE_SAWS) 402536b137fSBarry Smith } else if (issaws) { 4030076e027SBarry Smith if (!((PetscObject)v)->amsmem) { 404e04113cfSBarry Smith ierr = PetscObjectViewSAWs((PetscObject)v,viewer);CHKERRQ(ierr); 4050076e027SBarry Smith if (v->ops->view) { 4060076e027SBarry Smith ierr = (*v->ops->view)(v,viewer);CHKERRQ(ierr); 4070076e027SBarry Smith } 4080076e027SBarry Smith } 4090076e027SBarry Smith #endif 4105c6c1daeSBarry Smith } 4115c6c1daeSBarry Smith PetscFunctionReturn(0); 4125c6c1daeSBarry Smith } 4131d641e7bSMichael Lange 4141d641e7bSMichael Lange /*@C 4151d641e7bSMichael Lange PetscViewerRead - Reads data from a PetscViewer 4161d641e7bSMichael Lange 4171d641e7bSMichael Lange Collective on MPI_Comm 4181d641e7bSMichael Lange 4191d641e7bSMichael Lange Input Parameters: 4201d641e7bSMichael Lange + viewer - The viewer 4211d641e7bSMichael Lange . data - Location to write the data 422060da220SMatthew G. Knepley . num - Number of items of data to read 4231d641e7bSMichael Lange - datatype - Type of data to read 4241d641e7bSMichael Lange 425f8e4bde8SMatthew G. Knepley Output Parameters: 426060da220SMatthew G. Knepley . count - number of items of data actually read, or NULL 427f8e4bde8SMatthew G. Knepley 428632e26b4SStefano Zampini Notes: 429632e26b4SStefano Zampini If datatype is PETSC_STRING and num is negative, reads until a newline character is found, 430632e26b4SStefano Zampini until a maximum of (-num - 1) chars. 431632e26b4SStefano Zampini 4321d641e7bSMichael Lange Level: beginner 4331d641e7bSMichael Lange 4341d641e7bSMichael Lange Concepts: binary files, ascii files 4351d641e7bSMichael Lange 4366a9046bcSBarry Smith .seealso: PetscViewerASCIIOpen(), PetscViewerPushFormat(), PetscViewerDestroy(), 4371d641e7bSMichael Lange VecView(), MatView(), VecLoad(), MatLoad(), PetscViewerBinaryGetDescriptor(), 4381d641e7bSMichael Lange PetscViewerBinaryGetInfoPointer(), PetscFileMode, PetscViewer 4391d641e7bSMichael Lange @*/ 440060da220SMatthew G. Knepley PetscErrorCode PetscViewerRead(PetscViewer viewer, void *data, PetscInt num, PetscInt *count, PetscDataType dtype) 4411d641e7bSMichael Lange { 4421d641e7bSMichael Lange PetscErrorCode ierr; 4431d641e7bSMichael Lange 4441d641e7bSMichael Lange PetscFunctionBegin; 4451d641e7bSMichael Lange PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 4461d641e7bSMichael Lange if (dtype == PETSC_STRING) { 447060da220SMatthew G. Knepley PetscInt c, i = 0, cnt; 4481d641e7bSMichael Lange char *s = (char *)data; 449632e26b4SStefano Zampini if (num >= 0) { 450060da220SMatthew G. Knepley for (c = 0; c < num; c++) { 4511d641e7bSMichael Lange /* Skip leading whitespaces */ 452060da220SMatthew G. Knepley do {ierr = (*viewer->ops->read)(viewer, &(s[i]), 1, &cnt, PETSC_CHAR);CHKERRQ(ierr); if (count && !cnt) break;} 453eb2700f0SMichael Lange while (s[i]=='\n' || s[i]=='\t' || s[i]==' ' || s[i]=='\0' || s[i]=='\v' || s[i]=='\f' || s[i]=='\r'); 4541d641e7bSMichael Lange i++; 4551d641e7bSMichael Lange /* Read strings one char at a time */ 456060da220SMatthew G. Knepley do {ierr = (*viewer->ops->read)(viewer, &(s[i++]), 1, &cnt, PETSC_CHAR);CHKERRQ(ierr); if (count && !cnt) break;} 457eb2700f0SMichael Lange while (s[i-1]!='\n' && s[i-1]!='\t' && s[i-1]!=' ' && s[i-1]!='\0' && s[i-1]!='\v' && s[i-1]!='\f' && s[i-1]!='\r'); 4581d641e7bSMichael Lange /* Terminate final string */ 459060da220SMatthew G. Knepley if (c == num-1) s[i-1] = '\0'; 4601d641e7bSMichael Lange } 461632e26b4SStefano Zampini } else { 462632e26b4SStefano Zampini /* Read until a \n is encountered (-num is the max size allowed) */ 463632e26b4SStefano Zampini do {ierr = (*viewer->ops->read)(viewer, &(s[i++]), 1, &cnt, PETSC_CHAR);CHKERRQ(ierr); if (i == -num && !cnt) break;} 464632e26b4SStefano Zampini while (s[i-1]!='\n'); 465632e26b4SStefano Zampini /* Terminate final string */ 466632e26b4SStefano Zampini s[i-1] = '\0'; 467632e26b4SStefano Zampini c = i; 468632e26b4SStefano Zampini } 469060da220SMatthew G. Knepley if (count) *count = c; 470060da220SMatthew G. Knepley else if (c < num) SETERRQ2(PetscObjectComm((PetscObject) viewer), PETSC_ERR_FILE_READ, "Insufficient data, only read %D < %D strings", c, num); 4711d641e7bSMichael Lange } else { 472060da220SMatthew G. Knepley ierr = (*viewer->ops->read)(viewer, data, num, count, dtype);CHKERRQ(ierr); 4731d641e7bSMichael Lange } 4741d641e7bSMichael Lange PetscFunctionReturn(0); 4751d641e7bSMichael Lange } 476e24fdd67SVaclav Hapla 477af684e28SVaclav Hapla /*@ 478af684e28SVaclav Hapla PetscViewerReadable - Return a flag whether the viewer can be read from 479af684e28SVaclav Hapla 480af684e28SVaclav Hapla Not Collective 481af684e28SVaclav Hapla 482af684e28SVaclav Hapla Input Parameters: 483af684e28SVaclav Hapla . viewer - the PetscViewer context 484af684e28SVaclav Hapla 485af684e28SVaclav Hapla Output Parameters: 486af684e28SVaclav Hapla . flg - PETSC_TRUE if the viewer is readable, PETSC_FALSE otherwise 487af684e28SVaclav Hapla 488af684e28SVaclav Hapla Notes: 489af684e28SVaclav Hapla PETSC_TRUE means that viewer's PetscViewerType supports reading (this holds e.g. for PETSCVIEWERBINARY) 490af684e28SVaclav Hapla and viewer is in a mode allowing reading, i.e. PetscViewerFileGetMode() 491af684e28SVaclav Hapla returns one of FILE_MODE_READ, FILE_MODE_UPDATE, FILE_MODE_APPEND_UPDATE. 492af684e28SVaclav Hapla 493af684e28SVaclav Hapla Level: intermediate 494af684e28SVaclav Hapla 495af684e28SVaclav Hapla .seealso: PetscViewerWritable(), PetscViewerCheckReadable(), PetscViewerCreate(), PetscViewerFileSetMode(), PetscViewerFileSetType() 496af684e28SVaclav Hapla @*/ 497e24fdd67SVaclav Hapla PetscErrorCode PetscViewerReadable(PetscViewer viewer, PetscBool *flg) 498e24fdd67SVaclav Hapla { 499e24fdd67SVaclav Hapla PetscErrorCode ierr; 500e24fdd67SVaclav Hapla PetscFileMode mode; 501e24fdd67SVaclav Hapla PetscErrorCode (*f)(PetscViewer,PetscFileMode*) = NULL; 502e24fdd67SVaclav Hapla 503e24fdd67SVaclav Hapla PetscFunctionBegin; 504e24fdd67SVaclav Hapla PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 505e24fdd67SVaclav Hapla PetscValidIntPointer(flg,2); 506e24fdd67SVaclav Hapla ierr = PetscObjectQueryFunction((PetscObject)viewer, "PetscViewerFileGetMode_C", &f);CHKERRQ(ierr); 507e24fdd67SVaclav Hapla *flg = PETSC_FALSE; 508e24fdd67SVaclav Hapla if (!f) PetscFunctionReturn(0); 509e24fdd67SVaclav Hapla ierr = (*f)(viewer, &mode);CHKERRQ(ierr); 510e24fdd67SVaclav Hapla switch (mode) { 511e24fdd67SVaclav Hapla case FILE_MODE_READ: 512e24fdd67SVaclav Hapla case FILE_MODE_UPDATE: 513e24fdd67SVaclav Hapla case FILE_MODE_APPEND_UPDATE: 514e24fdd67SVaclav Hapla *flg = PETSC_TRUE; 515e24fdd67SVaclav Hapla default: break; 516e24fdd67SVaclav Hapla } 517e24fdd67SVaclav Hapla PetscFunctionReturn(0); 518e24fdd67SVaclav Hapla } 519e24fdd67SVaclav Hapla 520af684e28SVaclav Hapla /*@ 521af684e28SVaclav Hapla PetscViewerWritable - Return a flag whether the viewer can be written to 522af684e28SVaclav Hapla 523af684e28SVaclav Hapla Not Collective 524af684e28SVaclav Hapla 525af684e28SVaclav Hapla Input Parameters: 526af684e28SVaclav Hapla . viewer - the PetscViewer context 527af684e28SVaclav Hapla 528af684e28SVaclav Hapla Output Parameters: 529af684e28SVaclav Hapla . flg - PETSC_TRUE if the viewer is writable, PETSC_FALSE otherwise 530af684e28SVaclav Hapla 531af684e28SVaclav Hapla Notes: 532af684e28SVaclav Hapla PETSC_TRUE means viewer is in a mode allowing writing, i.e. PetscViewerFileGetMode() 533af684e28SVaclav Hapla returns one of FILE_MODE_WRITE, FILE_MODE_APPEND, FILE_MODE_UPDATE, FILE_MODE_APPEND_UPDATE. 534af684e28SVaclav Hapla 535af684e28SVaclav Hapla Level: intermediate 536af684e28SVaclav Hapla 537af684e28SVaclav Hapla .seealso: PetscViewerReadable(), PetscViewerCheckWritable(), PetscViewerCreate(), PetscViewerFileSetMode(), PetscViewerFileSetType() 538af684e28SVaclav Hapla @*/ 539e24fdd67SVaclav Hapla PetscErrorCode PetscViewerWritable(PetscViewer viewer, PetscBool *flg) 540e24fdd67SVaclav Hapla { 541e24fdd67SVaclav Hapla PetscErrorCode ierr; 542e24fdd67SVaclav Hapla PetscFileMode mode; 543e24fdd67SVaclav Hapla PetscErrorCode (*f)(PetscViewer,PetscFileMode*) = NULL; 544e24fdd67SVaclav Hapla 545e24fdd67SVaclav Hapla PetscFunctionBegin; 546e24fdd67SVaclav Hapla PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 547e24fdd67SVaclav Hapla PetscValidIntPointer(flg,2); 548e24fdd67SVaclav Hapla ierr = PetscObjectQueryFunction((PetscObject)viewer, "PetscViewerFileGetMode_C", &f);CHKERRQ(ierr); 549e24fdd67SVaclav Hapla *flg = PETSC_TRUE; 550e24fdd67SVaclav Hapla if (!f) PetscFunctionReturn(0); 551e24fdd67SVaclav Hapla ierr = (*f)(viewer, &mode);CHKERRQ(ierr); 552e24fdd67SVaclav Hapla if (mode == FILE_MODE_READ) *flg = PETSC_FALSE; 553e24fdd67SVaclav Hapla PetscFunctionReturn(0); 554e24fdd67SVaclav Hapla } 555e24fdd67SVaclav Hapla 556af684e28SVaclav Hapla /*@ 557af684e28SVaclav Hapla PetscViewerCheckReadable - Check whether the viewer can be read from 558af684e28SVaclav Hapla 559af684e28SVaclav Hapla Collective 560af684e28SVaclav Hapla 561af684e28SVaclav Hapla Input Parameters: 562af684e28SVaclav Hapla . viewer - the PetscViewer context 563af684e28SVaclav Hapla 564af684e28SVaclav Hapla Level: intermediate 565af684e28SVaclav Hapla 566af684e28SVaclav Hapla .seealso: PetscViewerReadable(), PetscViewerCheckWritable(), PetscViewerCreate(), PetscViewerFileSetMode(), PetscViewerFileSetType() 567af684e28SVaclav Hapla @*/ 568d01f05b1SVaclav Hapla PetscErrorCode PetscViewerCheckReadable(PetscViewer viewer) 569d01f05b1SVaclav Hapla { 570d01f05b1SVaclav Hapla PetscBool flg; 571d01f05b1SVaclav Hapla PetscErrorCode ierr; 572d01f05b1SVaclav Hapla 573d01f05b1SVaclav Hapla PetscFunctionBegin; 5740af448b7SVaclav Hapla PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 575d01f05b1SVaclav Hapla ierr = PetscViewerReadable(viewer, &flg);CHKERRQ(ierr); 576d01f05b1SVaclav Hapla if (!flg) SETERRQ(PetscObjectComm((PetscObject)viewer), PETSC_ERR_SUP, "Viewer doesn't support reading, or is not in reading mode (FILE_MODE_READ, FILE_MODE_UPDATE, FILE_MODE_APPEND_UPDATE)"); 577d01f05b1SVaclav Hapla PetscFunctionReturn(0); 578d01f05b1SVaclav Hapla } 579d01f05b1SVaclav Hapla 580af684e28SVaclav Hapla /*@ 581af684e28SVaclav Hapla PetscViewerCheckWritable - Check whether the viewer can be written to 582af684e28SVaclav Hapla 583af684e28SVaclav Hapla Collective 584af684e28SVaclav Hapla 585af684e28SVaclav Hapla Input Parameters: 586af684e28SVaclav Hapla . viewer - the PetscViewer context 587af684e28SVaclav Hapla 588af684e28SVaclav Hapla Level: intermediate 589af684e28SVaclav Hapla 590af684e28SVaclav Hapla .seealso: PetscViewerWritable(), PetscViewerCheckReadable(), PetscViewerCreate(), PetscViewerFileSetMode(), PetscViewerFileSetType() 591af684e28SVaclav Hapla @*/ 592d01f05b1SVaclav Hapla PetscErrorCode PetscViewerCheckWritable(PetscViewer viewer) 593d01f05b1SVaclav Hapla { 594d01f05b1SVaclav Hapla PetscBool flg; 595d01f05b1SVaclav Hapla PetscErrorCode ierr; 596d01f05b1SVaclav Hapla 597d01f05b1SVaclav Hapla PetscFunctionBegin; 5980af448b7SVaclav Hapla PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 599d01f05b1SVaclav Hapla ierr = PetscViewerWritable(viewer, &flg);CHKERRQ(ierr); 600d01f05b1SVaclav Hapla if (!flg) SETERRQ(PetscObjectComm((PetscObject)viewer), PETSC_ERR_SUP, "Viewer doesn't support writing, or is in FILE_MODE_READ mode"); 601d01f05b1SVaclav Hapla PetscFunctionReturn(0); 602d01f05b1SVaclav Hapla } 603