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]; 63*8e81d068SLisandro 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 */ 74*8e81d068SLisandro Dalcin ierr = PetscOptionsGetString(NULL,NULL,"-info_exclude",logList,sizeof(logList),&opt);CHKERRQ(ierr); 755c6c1daeSBarry Smith if (opt) { 76*8e81d068SLisandro Dalcin ierr = PetscStrInList("viewer",logList,',',&pkg);CHKERRQ(ierr); 77*8e81d068SLisandro Dalcin if (pkg) {ierr = PetscInfoDeactivateClass(PETSC_VIEWER_CLASSID);CHKERRQ(ierr);} 785c6c1daeSBarry Smith } 795c6c1daeSBarry Smith /* Process summary exclusions */ 80*8e81d068SLisandro Dalcin ierr = PetscOptionsGetString(NULL,NULL,"-log_exclude",logList,sizeof(logList),&opt);CHKERRQ(ierr); 815c6c1daeSBarry Smith if (opt) { 82*8e81d068SLisandro Dalcin ierr = PetscStrInList("viewer",logList,',',&pkg);CHKERRQ(ierr); 83*8e81d068SLisandro Dalcin if (pkg) {ierr = PetscLogEventDeactivateClass(PETSC_VIEWER_CLASSID);CHKERRQ(ierr);} 845c6c1daeSBarry Smith } 855c6c1daeSBarry Smith #if defined(PETSC_HAVE_MATHEMATICA) 86607a6623SBarry Smith ierr = PetscViewerMathematicaInitializePackage();CHKERRQ(ierr); 875c6c1daeSBarry Smith #endif 88*8e81d068SLisandro 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 137d7cbc13eSBarry Smith Notes: This increases the reference count of the viewer so you can destroy the viewer object after this call 138d7cbc13eSBarry Smith Level: developer 139d7cbc13eSBarry Smith 140d7cbc13eSBarry Smith This is used as the context variable for many of the TS, SNES, and KSP monitor functions 141d7cbc13eSBarry Smith 142d7cbc13eSBarry Smith .seealso: PetscViewerSocketOpen(), PetscViewerASCIIOpen(), PetscViewerCreate(), PetscViewerDrawOpen(), PetscViewerAndFormatDestroy() 143d7cbc13eSBarry Smith 144d7cbc13eSBarry Smith @*/ 145d7cbc13eSBarry Smith PetscErrorCode PetscViewerAndFormatCreate(PetscViewer viewer, PetscViewerFormat format,PetscViewerAndFormat **vf) 146d7cbc13eSBarry Smith { 147d7cbc13eSBarry Smith PetscErrorCode ierr; 148d7cbc13eSBarry Smith 149d7cbc13eSBarry Smith PetscFunctionBegin; 150d7cbc13eSBarry Smith ierr = PetscObjectReference((PetscObject)viewer);CHKERRQ(ierr); 151d7cbc13eSBarry Smith ierr = PetscNew(vf);CHKERRQ(ierr); 152d7cbc13eSBarry Smith (*vf)->viewer = viewer; 153d7cbc13eSBarry Smith (*vf)->format = format; 154d7cbc13eSBarry Smith PetscFunctionReturn(0); 155d7cbc13eSBarry Smith } 156d7cbc13eSBarry Smith 157d7cbc13eSBarry Smith 158fe01d993SBarry Smith /*@C 159fe01d993SBarry Smith PetscViewerAndFormatDestroy - Destroys a PetscViewerAndFormat struct. 160fe01d993SBarry Smith 161fe01d993SBarry Smith Collective on PetscViewer 162fe01d993SBarry Smith 163fe01d993SBarry Smith Input Parameters: 164fe01d993SBarry Smith . viewer - the PetscViewerAndFormat to be destroyed. 165fe01d993SBarry Smith 166d7cbc13eSBarry Smith Level: developer 167fe01d993SBarry Smith 168d7cbc13eSBarry Smith .seealso: PetscViewerSocketOpen(), PetscViewerASCIIOpen(), PetscViewerCreate(), PetscViewerDrawOpen(), PetscViewerAndFormatCreate() 169fe01d993SBarry Smith 170fe01d993SBarry Smith @*/ 171fe01d993SBarry Smith PetscErrorCode PetscViewerAndFormatDestroy(PetscViewerAndFormat **vf) 172fe01d993SBarry Smith { 173fe01d993SBarry Smith PetscErrorCode ierr; 174fe01d993SBarry Smith 175fe01d993SBarry Smith PetscFunctionBegin; 176fe01d993SBarry Smith ierr = PetscViewerDestroy(&(*vf)->viewer);CHKERRQ(ierr); 177fe01d993SBarry Smith ierr = PetscFree(*vf);CHKERRQ(ierr); 178fe01d993SBarry Smith PetscFunctionReturn(0); 179fe01d993SBarry Smith } 180fe01d993SBarry Smith 1815c6c1daeSBarry Smith /*@C 1825c6c1daeSBarry Smith PetscViewerGetType - Returns the type of a PetscViewer. 1835c6c1daeSBarry Smith 1845c6c1daeSBarry Smith Not Collective 1855c6c1daeSBarry Smith 1865c6c1daeSBarry Smith Input Parameter: 1875c6c1daeSBarry Smith . viewer - the PetscViewer 1885c6c1daeSBarry Smith 1895c6c1daeSBarry Smith Output Parameter: 1905c6c1daeSBarry Smith . type - PetscViewer type (see below) 1915c6c1daeSBarry Smith 1925c6c1daeSBarry Smith Available Types Include: 1935c6c1daeSBarry Smith . PETSCVIEWERSOCKET - Socket PetscViewer 1945c6c1daeSBarry Smith . PETSCVIEWERASCII - ASCII PetscViewer 1955c6c1daeSBarry Smith . PETSCVIEWERBINARY - binary file PetscViewer 1965c6c1daeSBarry Smith . PETSCVIEWERSTRING - string PetscViewer 1975c6c1daeSBarry Smith . PETSCVIEWERDRAW - drawing PetscViewer 1985c6c1daeSBarry Smith 1995c6c1daeSBarry Smith Level: intermediate 2005c6c1daeSBarry Smith 2015c6c1daeSBarry Smith Note: 2025c6c1daeSBarry Smith See include/petscviewer.h for a complete list of PetscViewers. 2035c6c1daeSBarry Smith 2045c6c1daeSBarry Smith PetscViewerType is actually a string 2055c6c1daeSBarry Smith 2065c6c1daeSBarry Smith .seealso: PetscViewerCreate(), PetscViewerSetType(), PetscViewerType 2075c6c1daeSBarry Smith 2085c6c1daeSBarry Smith @*/ 2095c6c1daeSBarry Smith PetscErrorCode PetscViewerGetType(PetscViewer viewer,PetscViewerType *type) 2105c6c1daeSBarry Smith { 2115c6c1daeSBarry Smith PetscFunctionBegin; 2125c6c1daeSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 2135c6c1daeSBarry Smith PetscValidPointer(type,2); 2145c6c1daeSBarry Smith *type = ((PetscObject)viewer)->type_name; 2155c6c1daeSBarry Smith PetscFunctionReturn(0); 2165c6c1daeSBarry Smith } 2175c6c1daeSBarry Smith 2185c6c1daeSBarry Smith /*@C 2195c6c1daeSBarry Smith PetscViewerSetOptionsPrefix - Sets the prefix used for searching for all 2205c6c1daeSBarry Smith PetscViewer options in the database. 2215c6c1daeSBarry Smith 2225c6c1daeSBarry Smith Logically Collective on PetscViewer 2235c6c1daeSBarry Smith 2245c6c1daeSBarry Smith Input Parameter: 2255c6c1daeSBarry Smith + viewer - the PetscViewer context 2265c6c1daeSBarry Smith - prefix - the prefix to prepend to all option names 2275c6c1daeSBarry Smith 2285c6c1daeSBarry Smith Notes: 2295c6c1daeSBarry Smith A hyphen (-) must NOT be given at the beginning of the prefix name. 2305c6c1daeSBarry Smith The first character of all runtime options is AUTOMATICALLY the hyphen. 2315c6c1daeSBarry Smith 2325c6c1daeSBarry Smith Level: advanced 2335c6c1daeSBarry Smith 2345c6c1daeSBarry Smith .keywords: PetscViewer, set, options, prefix, database 2355c6c1daeSBarry Smith 2365c6c1daeSBarry Smith .seealso: PetscViewerSetFromOptions() 2375c6c1daeSBarry Smith @*/ 2385c6c1daeSBarry Smith PetscErrorCode PetscViewerSetOptionsPrefix(PetscViewer viewer,const char prefix[]) 2395c6c1daeSBarry Smith { 2405c6c1daeSBarry Smith PetscErrorCode ierr; 2415c6c1daeSBarry Smith 2425c6c1daeSBarry Smith PetscFunctionBegin; 2435c6c1daeSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 2445c6c1daeSBarry Smith ierr = PetscObjectSetOptionsPrefix((PetscObject)viewer,prefix);CHKERRQ(ierr); 2455c6c1daeSBarry Smith PetscFunctionReturn(0); 2465c6c1daeSBarry Smith } 2475c6c1daeSBarry Smith 2485c6c1daeSBarry Smith /*@C 2495c6c1daeSBarry Smith PetscViewerAppendOptionsPrefix - Appends to the prefix used for searching for all 2505c6c1daeSBarry Smith PetscViewer options in the database. 2515c6c1daeSBarry Smith 2525c6c1daeSBarry Smith Logically Collective on PetscViewer 2535c6c1daeSBarry Smith 2545c6c1daeSBarry Smith Input Parameters: 2555c6c1daeSBarry Smith + viewer - the PetscViewer context 2565c6c1daeSBarry Smith - prefix - the prefix to prepend to all option names 2575c6c1daeSBarry Smith 2585c6c1daeSBarry Smith Notes: 2595c6c1daeSBarry Smith A hyphen (-) must NOT be given at the beginning of the prefix name. 2605c6c1daeSBarry Smith The first character of all runtime options is AUTOMATICALLY the hyphen. 2615c6c1daeSBarry Smith 2625c6c1daeSBarry Smith Level: advanced 2635c6c1daeSBarry Smith 2645c6c1daeSBarry Smith .keywords: PetscViewer, append, options, prefix, database 2655c6c1daeSBarry Smith 2665c6c1daeSBarry Smith .seealso: PetscViewerGetOptionsPrefix() 2675c6c1daeSBarry Smith @*/ 2685c6c1daeSBarry Smith PetscErrorCode PetscViewerAppendOptionsPrefix(PetscViewer viewer,const char prefix[]) 2695c6c1daeSBarry Smith { 2705c6c1daeSBarry Smith PetscErrorCode ierr; 2715c6c1daeSBarry Smith 2725c6c1daeSBarry Smith PetscFunctionBegin; 2735c6c1daeSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 2745c6c1daeSBarry Smith ierr = PetscObjectAppendOptionsPrefix((PetscObject)viewer,prefix);CHKERRQ(ierr); 2755c6c1daeSBarry Smith PetscFunctionReturn(0); 2765c6c1daeSBarry Smith } 2775c6c1daeSBarry Smith 2785c6c1daeSBarry Smith /*@C 2795c6c1daeSBarry Smith PetscViewerGetOptionsPrefix - Sets the prefix used for searching for all 2805c6c1daeSBarry Smith PetscViewer options in the database. 2815c6c1daeSBarry Smith 2825c6c1daeSBarry Smith Not Collective 2835c6c1daeSBarry Smith 2845c6c1daeSBarry Smith Input Parameter: 2855c6c1daeSBarry Smith . viewer - the PetscViewer context 2865c6c1daeSBarry Smith 2875c6c1daeSBarry Smith Output Parameter: 2885c6c1daeSBarry Smith . prefix - pointer to the prefix string used 2895c6c1daeSBarry Smith 2905c6c1daeSBarry Smith Notes: On the fortran side, the user should pass in a string 'prefix' of 2915c6c1daeSBarry Smith sufficient length to hold the prefix. 2925c6c1daeSBarry Smith 2935c6c1daeSBarry Smith Level: advanced 2945c6c1daeSBarry Smith 2955c6c1daeSBarry Smith .keywords: PetscViewer, get, options, prefix, database 2965c6c1daeSBarry Smith 2975c6c1daeSBarry Smith .seealso: PetscViewerAppendOptionsPrefix() 2985c6c1daeSBarry Smith @*/ 2995c6c1daeSBarry Smith PetscErrorCode PetscViewerGetOptionsPrefix(PetscViewer viewer,const char *prefix[]) 3005c6c1daeSBarry Smith { 3015c6c1daeSBarry Smith PetscErrorCode ierr; 3025c6c1daeSBarry Smith 3035c6c1daeSBarry Smith PetscFunctionBegin; 3045c6c1daeSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 3055c6c1daeSBarry Smith ierr = PetscObjectGetOptionsPrefix((PetscObject)viewer,prefix);CHKERRQ(ierr); 3065c6c1daeSBarry Smith PetscFunctionReturn(0); 3075c6c1daeSBarry Smith } 3085c6c1daeSBarry Smith 3095c6c1daeSBarry Smith /*@ 3105c6c1daeSBarry Smith PetscViewerSetUp - Sets up the internal viewer data structures for the later use. 3115c6c1daeSBarry Smith 3125c6c1daeSBarry Smith Collective on PetscViewer 3135c6c1daeSBarry Smith 3145c6c1daeSBarry Smith Input Parameters: 3155c6c1daeSBarry Smith . viewer - the PetscViewer context 3165c6c1daeSBarry Smith 3175c6c1daeSBarry Smith Notes: 3185c6c1daeSBarry Smith For basic use of the PetscViewer classes the user need not explicitly call 3195c6c1daeSBarry Smith PetscViewerSetUp(), since these actions will happen automatically. 3205c6c1daeSBarry Smith 3215c6c1daeSBarry Smith Level: advanced 3225c6c1daeSBarry Smith 3235c6c1daeSBarry Smith .keywords: PetscViewer, setup 3245c6c1daeSBarry Smith 3255c6c1daeSBarry Smith .seealso: PetscViewerCreate(), PetscViewerDestroy() 3265c6c1daeSBarry Smith @*/ 3275c6c1daeSBarry Smith PetscErrorCode PetscViewerSetUp(PetscViewer viewer) 3285c6c1daeSBarry Smith { 329c98fd787SBarry Smith PetscErrorCode ierr; 330c98fd787SBarry Smith 3315c6c1daeSBarry Smith PetscFunctionBegin; 3325c6c1daeSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 333c98fd787SBarry Smith if (viewer->setupcalled) PetscFunctionReturn(0); 334c98fd787SBarry Smith if (viewer->ops->setup) { 335c98fd787SBarry Smith ierr = (*viewer->ops->setup)(viewer);CHKERRQ(ierr); 336c98fd787SBarry Smith } 337c98fd787SBarry Smith viewer->setupcalled = PETSC_TRUE; 3385c6c1daeSBarry Smith PetscFunctionReturn(0); 3395c6c1daeSBarry Smith } 3405c6c1daeSBarry Smith 3415c6c1daeSBarry Smith /*@C 3425c6c1daeSBarry Smith PetscViewerView - Visualizes a viewer object. 3435c6c1daeSBarry Smith 3445c6c1daeSBarry Smith Collective on PetscViewer 3455c6c1daeSBarry Smith 3465c6c1daeSBarry Smith Input Parameters: 3475c6c1daeSBarry Smith + v - the viewer 3485c6c1daeSBarry Smith - viewer - visualization context 3495c6c1daeSBarry Smith 3505c6c1daeSBarry Smith Notes: 3515c6c1daeSBarry Smith The available visualization contexts include 3525c6c1daeSBarry Smith + PETSC_VIEWER_STDOUT_SELF - standard output (default) 3535c6c1daeSBarry Smith . PETSC_VIEWER_STDOUT_WORLD - synchronized standard 3545c6c1daeSBarry Smith output where only the first processor opens 3555c6c1daeSBarry Smith the file. All other processors send their 3565c6c1daeSBarry Smith data to the first processor to print. 3575c6c1daeSBarry Smith - PETSC_VIEWER_DRAW_WORLD - graphical display of nonzero structure 3585c6c1daeSBarry Smith 3595c6c1daeSBarry Smith Level: beginner 3605c6c1daeSBarry Smith 3616a9046bcSBarry Smith .seealso: PetscViewerPushFormat(), PetscViewerASCIIOpen(), PetscViewerDrawOpen(), 3625c6c1daeSBarry Smith PetscViewerSocketOpen(), PetscViewerBinaryOpen(), PetscViewerLoad() 3635c6c1daeSBarry Smith @*/ 3645c6c1daeSBarry Smith PetscErrorCode PetscViewerView(PetscViewer v,PetscViewer viewer) 3655c6c1daeSBarry Smith { 3665c6c1daeSBarry Smith PetscErrorCode ierr; 3675c6c1daeSBarry Smith PetscBool iascii; 3685c6c1daeSBarry Smith PetscViewerFormat format; 369e04113cfSBarry Smith #if defined(PETSC_HAVE_SAWS) 370536b137fSBarry Smith PetscBool issaws; 3710076e027SBarry Smith #endif 3725c6c1daeSBarry Smith 3735c6c1daeSBarry Smith PetscFunctionBegin; 3745c6c1daeSBarry Smith PetscValidHeaderSpecific(v,PETSC_VIEWER_CLASSID,1); 3755c6c1daeSBarry Smith PetscValidType(v,1); 3765c6c1daeSBarry Smith if (!viewer) { 377ce94432eSBarry Smith ierr = PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)v),&viewer);CHKERRQ(ierr); 3785c6c1daeSBarry Smith } 3795c6c1daeSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,2); 3805c6c1daeSBarry Smith PetscCheckSameComm(v,1,viewer,2); 3815c6c1daeSBarry Smith 3825c6c1daeSBarry Smith ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);CHKERRQ(ierr); 383e04113cfSBarry Smith #if defined(PETSC_HAVE_SAWS) 384536b137fSBarry Smith ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERSAWS,&issaws);CHKERRQ(ierr); 3850076e027SBarry Smith #endif 3865c6c1daeSBarry Smith if (iascii) { 3875c6c1daeSBarry Smith ierr = PetscViewerGetFormat(viewer,&format);CHKERRQ(ierr); 388dae58748SBarry Smith ierr = PetscObjectPrintClassNamePrefixType((PetscObject)v,viewer);CHKERRQ(ierr); 38998c3331eSBarry Smith if (format == PETSC_VIEWER_DEFAULT || format == PETSC_VIEWER_ASCII_INFO || format == PETSC_VIEWER_ASCII_INFO_DETAIL) { 3902f234a98SBarry Smith if (v->format) { 3912f234a98SBarry Smith ierr = PetscViewerASCIIPrintf(viewer," Viewer format = %s\n",PetscViewerFormats[v->format]);CHKERRQ(ierr); 3922f234a98SBarry Smith } 3935c6c1daeSBarry Smith ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); 3942bf49c77SBarry Smith if (v->ops->view) { 3952bf49c77SBarry Smith ierr = (*v->ops->view)(v,viewer);CHKERRQ(ierr); 3965c6c1daeSBarry Smith } 3975c6c1daeSBarry Smith ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); 3985c6c1daeSBarry Smith } 399e04113cfSBarry Smith #if defined(PETSC_HAVE_SAWS) 400536b137fSBarry Smith } else if (issaws) { 4010076e027SBarry Smith if (!((PetscObject)v)->amsmem) { 402e04113cfSBarry Smith ierr = PetscObjectViewSAWs((PetscObject)v,viewer);CHKERRQ(ierr); 4030076e027SBarry Smith if (v->ops->view) { 4040076e027SBarry Smith ierr = (*v->ops->view)(v,viewer);CHKERRQ(ierr); 4050076e027SBarry Smith } 4060076e027SBarry Smith } 4070076e027SBarry Smith #endif 4085c6c1daeSBarry Smith } 4095c6c1daeSBarry Smith PetscFunctionReturn(0); 4105c6c1daeSBarry Smith } 4111d641e7bSMichael Lange 4121d641e7bSMichael Lange /*@C 4131d641e7bSMichael Lange PetscViewerRead - Reads data from a PetscViewer 4141d641e7bSMichael Lange 4151d641e7bSMichael Lange Collective on MPI_Comm 4161d641e7bSMichael Lange 4171d641e7bSMichael Lange Input Parameters: 4181d641e7bSMichael Lange + viewer - The viewer 4191d641e7bSMichael Lange . data - Location to write the data 420060da220SMatthew G. Knepley . num - Number of items of data to read 4211d641e7bSMichael Lange - datatype - Type of data to read 4221d641e7bSMichael Lange 423f8e4bde8SMatthew G. Knepley Output Parameters: 424060da220SMatthew G. Knepley . count - number of items of data actually read, or NULL 425f8e4bde8SMatthew G. Knepley 426632e26b4SStefano Zampini Notes: 427632e26b4SStefano Zampini If datatype is PETSC_STRING and num is negative, reads until a newline character is found, 428632e26b4SStefano Zampini until a maximum of (-num - 1) chars. 429632e26b4SStefano Zampini 4301d641e7bSMichael Lange Level: beginner 4311d641e7bSMichael Lange 4321d641e7bSMichael Lange Concepts: binary files, ascii files 4331d641e7bSMichael Lange 4346a9046bcSBarry Smith .seealso: PetscViewerASCIIOpen(), PetscViewerPushFormat(), PetscViewerDestroy(), 4351d641e7bSMichael Lange VecView(), MatView(), VecLoad(), MatLoad(), PetscViewerBinaryGetDescriptor(), 4361d641e7bSMichael Lange PetscViewerBinaryGetInfoPointer(), PetscFileMode, PetscViewer 4371d641e7bSMichael Lange @*/ 438060da220SMatthew G. Knepley PetscErrorCode PetscViewerRead(PetscViewer viewer, void *data, PetscInt num, PetscInt *count, PetscDataType dtype) 4391d641e7bSMichael Lange { 4401d641e7bSMichael Lange PetscErrorCode ierr; 4411d641e7bSMichael Lange 4421d641e7bSMichael Lange PetscFunctionBegin; 4431d641e7bSMichael Lange PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 4441d641e7bSMichael Lange if (dtype == PETSC_STRING) { 445060da220SMatthew G. Knepley PetscInt c, i = 0, cnt; 4461d641e7bSMichael Lange char *s = (char *)data; 447632e26b4SStefano Zampini if (num >= 0) { 448060da220SMatthew G. Knepley for (c = 0; c < num; c++) { 4491d641e7bSMichael Lange /* Skip leading whitespaces */ 450060da220SMatthew G. Knepley do {ierr = (*viewer->ops->read)(viewer, &(s[i]), 1, &cnt, PETSC_CHAR);CHKERRQ(ierr); if (count && !cnt) break;} 451eb2700f0SMichael Lange while (s[i]=='\n' || s[i]=='\t' || s[i]==' ' || s[i]=='\0' || s[i]=='\v' || s[i]=='\f' || s[i]=='\r'); 4521d641e7bSMichael Lange i++; 4531d641e7bSMichael Lange /* Read strings one char at a time */ 454060da220SMatthew G. Knepley do {ierr = (*viewer->ops->read)(viewer, &(s[i++]), 1, &cnt, PETSC_CHAR);CHKERRQ(ierr); if (count && !cnt) break;} 455eb2700f0SMichael 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'); 4561d641e7bSMichael Lange /* Terminate final string */ 457060da220SMatthew G. Knepley if (c == num-1) s[i-1] = '\0'; 4581d641e7bSMichael Lange } 459632e26b4SStefano Zampini } else { 460632e26b4SStefano Zampini /* Read until a \n is encountered (-num is the max size allowed) */ 461632e26b4SStefano Zampini do {ierr = (*viewer->ops->read)(viewer, &(s[i++]), 1, &cnt, PETSC_CHAR);CHKERRQ(ierr); if (i == -num && !cnt) break;} 462632e26b4SStefano Zampini while (s[i-1]!='\n'); 463632e26b4SStefano Zampini /* Terminate final string */ 464632e26b4SStefano Zampini s[i-1] = '\0'; 465632e26b4SStefano Zampini c = i; 466632e26b4SStefano Zampini } 467060da220SMatthew G. Knepley if (count) *count = c; 468060da220SMatthew G. Knepley else if (c < num) SETERRQ2(PetscObjectComm((PetscObject) viewer), PETSC_ERR_FILE_READ, "Insufficient data, only read %D < %D strings", c, num); 4691d641e7bSMichael Lange } else { 470060da220SMatthew G. Knepley ierr = (*viewer->ops->read)(viewer, data, num, count, dtype);CHKERRQ(ierr); 4711d641e7bSMichael Lange } 4721d641e7bSMichael Lange PetscFunctionReturn(0); 4731d641e7bSMichael Lange } 474