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 .seealso: PetscFinalize() 145c6c1daeSBarry Smith @*/ 155c6c1daeSBarry Smith PetscErrorCode PetscViewerFinalizePackage(void) 165c6c1daeSBarry Smith { 1737e93019SBarry Smith PetscErrorCode ierr; 1837e93019SBarry Smith 195c6c1daeSBarry Smith PetscFunctionBegin; 20b6dade52SBarry Smith if (Petsc_Viewer_keyval != MPI_KEYVAL_INVALID) { 2147435625SJed Brown ierr = MPI_Comm_free_keyval(&Petsc_Viewer_keyval);CHKERRQ(ierr); 22b6dade52SBarry Smith } 23b6dade52SBarry Smith if (Petsc_Viewer_Stdout_keyval != MPI_KEYVAL_INVALID) { 2447435625SJed Brown ierr = MPI_Comm_free_keyval(&Petsc_Viewer_Stdout_keyval);CHKERRQ(ierr); 25b6dade52SBarry Smith } 26b6dade52SBarry Smith if (Petsc_Viewer_Stderr_keyval != MPI_KEYVAL_INVALID) { 2747435625SJed Brown ierr = MPI_Comm_free_keyval(&Petsc_Viewer_Stderr_keyval);CHKERRQ(ierr); 28b6dade52SBarry Smith } 29b6dade52SBarry Smith if (Petsc_Viewer_Binary_keyval != MPI_KEYVAL_INVALID) { 3047435625SJed Brown ierr = MPI_Comm_free_keyval(&Petsc_Viewer_Binary_keyval);CHKERRQ(ierr); 31b6dade52SBarry Smith } 32b6dade52SBarry Smith if (Petsc_Viewer_Draw_keyval != MPI_KEYVAL_INVALID) { 3347435625SJed Brown ierr = MPI_Comm_free_keyval(&Petsc_Viewer_Draw_keyval);CHKERRQ(ierr); 34b6dade52SBarry Smith } 35b6dade52SBarry Smith #if defined(PETSC_HAVE_HDF5) 36b6dade52SBarry Smith if (Petsc_Viewer_HDF5_keyval != MPI_KEYVAL_INVALID) { 3747435625SJed Brown ierr = MPI_Comm_free_keyval(&Petsc_Viewer_HDF5_keyval);CHKERRQ(ierr); 38b6dade52SBarry Smith } 39b6dade52SBarry Smith #endif 40b6dade52SBarry Smith #if defined(PETSC_USE_SOCKETVIEWER) 41b6dade52SBarry Smith if (Petsc_Viewer_Socket_keyval != MPI_KEYVAL_INVALID) { 4247435625SJed Brown ierr = MPI_Comm_free_keyval(&Petsc_Viewer_Socket_keyval);CHKERRQ(ierr); 43b6dade52SBarry Smith } 44b6dade52SBarry Smith #endif 4537e93019SBarry Smith ierr = PetscFunctionListDestroy(&PetscViewerList);CHKERRQ(ierr); 465c6c1daeSBarry Smith PetscViewerPackageInitialized = PETSC_FALSE; 470f51fdf8SToby Isaac PetscViewerRegisterAllCalled = PETSC_FALSE; 485c6c1daeSBarry Smith PetscFunctionReturn(0); 495c6c1daeSBarry Smith } 505c6c1daeSBarry Smith 515c6c1daeSBarry Smith /*@C 525c6c1daeSBarry Smith PetscViewerInitializePackage - This function initializes everything in the main PetscViewer package. 535c6c1daeSBarry Smith 545c6c1daeSBarry Smith Level: developer 555c6c1daeSBarry Smith 565c6c1daeSBarry Smith .seealso: PetscInitialize() 575c6c1daeSBarry Smith @*/ 58607a6623SBarry Smith PetscErrorCode PetscViewerInitializePackage(void) 595c6c1daeSBarry Smith { 605c6c1daeSBarry Smith char logList[256]; 618e81d068SLisandro Dalcin PetscBool opt,pkg; 625c6c1daeSBarry Smith PetscErrorCode ierr; 635c6c1daeSBarry Smith 645c6c1daeSBarry Smith PetscFunctionBegin; 655c6c1daeSBarry Smith if (PetscViewerPackageInitialized) PetscFunctionReturn(0); 665c6c1daeSBarry Smith PetscViewerPackageInitialized = PETSC_TRUE; 675c6c1daeSBarry Smith /* Register Classes */ 685c6c1daeSBarry Smith ierr = PetscClassIdRegister("Viewer",&PETSC_VIEWER_CLASSID);CHKERRQ(ierr); 695c6c1daeSBarry Smith /* Register Constructors */ 70607a6623SBarry Smith ierr = PetscViewerRegisterAll();CHKERRQ(ierr); 715c6c1daeSBarry Smith /* Process info exclusions */ 728e81d068SLisandro Dalcin ierr = PetscOptionsGetString(NULL,NULL,"-info_exclude",logList,sizeof(logList),&opt);CHKERRQ(ierr); 735c6c1daeSBarry Smith if (opt) { 748e81d068SLisandro Dalcin ierr = PetscStrInList("viewer",logList,',',&pkg);CHKERRQ(ierr); 758e81d068SLisandro Dalcin if (pkg) {ierr = PetscInfoDeactivateClass(PETSC_VIEWER_CLASSID);CHKERRQ(ierr);} 765c6c1daeSBarry Smith } 775c6c1daeSBarry Smith /* Process summary exclusions */ 788e81d068SLisandro Dalcin ierr = PetscOptionsGetString(NULL,NULL,"-log_exclude",logList,sizeof(logList),&opt);CHKERRQ(ierr); 795c6c1daeSBarry Smith if (opt) { 808e81d068SLisandro Dalcin ierr = PetscStrInList("viewer",logList,',',&pkg);CHKERRQ(ierr); 81fa2bb9feSLisandro Dalcin if (pkg) {ierr = PetscLogEventExcludeClass(PETSC_VIEWER_CLASSID);CHKERRQ(ierr);} 825c6c1daeSBarry Smith } 835c6c1daeSBarry Smith #if defined(PETSC_HAVE_MATHEMATICA) 84607a6623SBarry Smith ierr = PetscViewerMathematicaInitializePackage();CHKERRQ(ierr); 855c6c1daeSBarry Smith #endif 868e81d068SLisandro Dalcin /* Register package finalizer */ 875c6c1daeSBarry Smith ierr = PetscRegisterFinalize(PetscViewerFinalizePackage);CHKERRQ(ierr); 885c6c1daeSBarry Smith PetscFunctionReturn(0); 895c6c1daeSBarry Smith } 905c6c1daeSBarry Smith 915c6c1daeSBarry Smith /*@ 925c6c1daeSBarry Smith PetscViewerDestroy - Destroys a PetscViewer. 935c6c1daeSBarry Smith 945c6c1daeSBarry Smith Collective on PetscViewer 955c6c1daeSBarry Smith 965c6c1daeSBarry Smith Input Parameters: 975c6c1daeSBarry Smith . viewer - the PetscViewer to be destroyed. 985c6c1daeSBarry Smith 995c6c1daeSBarry Smith Level: beginner 1005c6c1daeSBarry Smith 1015c6c1daeSBarry Smith .seealso: PetscViewerSocketOpen(), PetscViewerASCIIOpen(), PetscViewerCreate(), PetscViewerDrawOpen() 1025c6c1daeSBarry Smith 1035c6c1daeSBarry Smith @*/ 1045c6c1daeSBarry Smith PetscErrorCode PetscViewerDestroy(PetscViewer *viewer) 1055c6c1daeSBarry Smith { 1065c6c1daeSBarry Smith PetscErrorCode ierr; 1075c6c1daeSBarry Smith 1085c6c1daeSBarry Smith PetscFunctionBegin; 1095c6c1daeSBarry Smith if (!*viewer) PetscFunctionReturn(0); 1105c6c1daeSBarry Smith PetscValidHeaderSpecific(*viewer,PETSC_VIEWER_CLASSID,1); 1115c6c1daeSBarry Smith 1125c6c1daeSBarry Smith ierr = PetscViewerFlush(*viewer);CHKERRQ(ierr); 113*02c9f0b5SLisandro Dalcin if (--((PetscObject)(*viewer))->refct > 0) {*viewer = NULL; PetscFunctionReturn(0);} 1145c6c1daeSBarry Smith 115e04113cfSBarry Smith ierr = PetscObjectSAWsViewOff((PetscObject)*viewer);CHKERRQ(ierr); 1165c6c1daeSBarry Smith if ((*viewer)->ops->destroy) { 1175c6c1daeSBarry Smith ierr = (*(*viewer)->ops->destroy)(*viewer);CHKERRQ(ierr); 1185c6c1daeSBarry Smith } 1195c6c1daeSBarry Smith ierr = PetscHeaderDestroy(viewer);CHKERRQ(ierr); 1205c6c1daeSBarry Smith PetscFunctionReturn(0); 1215c6c1daeSBarry Smith } 1225c6c1daeSBarry Smith 123d7cbc13eSBarry Smith /*@C 124d7cbc13eSBarry Smith PetscViewerAndFormatCreate - Creates a PetscViewerAndFormat struct. 125d7cbc13eSBarry Smith 126d7cbc13eSBarry Smith Collective on PetscViewer 127d7cbc13eSBarry Smith 128d7cbc13eSBarry Smith Input Parameters: 129d7cbc13eSBarry Smith + viewer - the viewer 130d7cbc13eSBarry Smith - format - the format 131d7cbc13eSBarry Smith 132d7cbc13eSBarry Smith Output Parameter: 133d7cbc13eSBarry Smith . vf - viewer and format object 134d7cbc13eSBarry Smith 13595452b02SPatrick Sanan Notes: 13695452b02SPatrick Sanan This increases the reference count of the viewer so you can destroy the viewer object after this call 137d7cbc13eSBarry Smith Level: developer 138d7cbc13eSBarry Smith 139d7cbc13eSBarry Smith This is used as the context variable for many of the TS, SNES, and KSP monitor functions 140d7cbc13eSBarry Smith 141d7cbc13eSBarry Smith .seealso: PetscViewerSocketOpen(), PetscViewerASCIIOpen(), PetscViewerCreate(), PetscViewerDrawOpen(), PetscViewerAndFormatDestroy() 142d7cbc13eSBarry Smith 143d7cbc13eSBarry Smith @*/ 144d7cbc13eSBarry Smith PetscErrorCode PetscViewerAndFormatCreate(PetscViewer viewer, PetscViewerFormat format,PetscViewerAndFormat **vf) 145d7cbc13eSBarry Smith { 146d7cbc13eSBarry Smith PetscErrorCode ierr; 147d7cbc13eSBarry Smith 148d7cbc13eSBarry Smith PetscFunctionBegin; 149d7cbc13eSBarry Smith ierr = PetscObjectReference((PetscObject)viewer);CHKERRQ(ierr); 150d7cbc13eSBarry Smith ierr = PetscNew(vf);CHKERRQ(ierr); 151d7cbc13eSBarry Smith (*vf)->viewer = viewer; 152d7cbc13eSBarry Smith (*vf)->format = format; 153d7cbc13eSBarry Smith PetscFunctionReturn(0); 154d7cbc13eSBarry Smith } 155d7cbc13eSBarry Smith 156d7cbc13eSBarry Smith 157fe01d993SBarry Smith /*@C 158fe01d993SBarry Smith PetscViewerAndFormatDestroy - Destroys a PetscViewerAndFormat struct. 159fe01d993SBarry Smith 160fe01d993SBarry Smith Collective on PetscViewer 161fe01d993SBarry Smith 162fe01d993SBarry Smith Input Parameters: 163fe01d993SBarry Smith . viewer - the PetscViewerAndFormat to be destroyed. 164fe01d993SBarry Smith 165d7cbc13eSBarry Smith Level: developer 166fe01d993SBarry Smith 167d7cbc13eSBarry Smith .seealso: PetscViewerSocketOpen(), PetscViewerASCIIOpen(), PetscViewerCreate(), PetscViewerDrawOpen(), PetscViewerAndFormatCreate() 168fe01d993SBarry Smith 169fe01d993SBarry Smith @*/ 170fe01d993SBarry Smith PetscErrorCode PetscViewerAndFormatDestroy(PetscViewerAndFormat **vf) 171fe01d993SBarry Smith { 172fe01d993SBarry Smith PetscErrorCode ierr; 173fe01d993SBarry Smith 174fe01d993SBarry Smith PetscFunctionBegin; 175fe01d993SBarry Smith ierr = PetscViewerDestroy(&(*vf)->viewer);CHKERRQ(ierr); 176fe01d993SBarry Smith ierr = PetscFree(*vf);CHKERRQ(ierr); 177fe01d993SBarry Smith PetscFunctionReturn(0); 178fe01d993SBarry Smith } 179fe01d993SBarry Smith 1805c6c1daeSBarry Smith /*@C 1815c6c1daeSBarry Smith PetscViewerGetType - Returns the type of a PetscViewer. 1825c6c1daeSBarry Smith 1835c6c1daeSBarry Smith Not Collective 1845c6c1daeSBarry Smith 1855c6c1daeSBarry Smith Input Parameter: 1865c6c1daeSBarry Smith . viewer - the PetscViewer 1875c6c1daeSBarry Smith 1885c6c1daeSBarry Smith Output Parameter: 1895c6c1daeSBarry Smith . type - PetscViewer type (see below) 1905c6c1daeSBarry Smith 1915c6c1daeSBarry Smith Available Types Include: 192a2b725a8SWilliam Gropp + PETSCVIEWERSOCKET - Socket PetscViewer 1935c6c1daeSBarry Smith . PETSCVIEWERASCII - ASCII PetscViewer 1945c6c1daeSBarry Smith . PETSCVIEWERBINARY - binary file PetscViewer 1955c6c1daeSBarry Smith . PETSCVIEWERSTRING - string PetscViewer 196a2b725a8SWilliam Gropp - PETSCVIEWERDRAW - drawing PetscViewer 1975c6c1daeSBarry Smith 1985c6c1daeSBarry Smith Level: intermediate 1995c6c1daeSBarry Smith 2005c6c1daeSBarry Smith Note: 2015c6c1daeSBarry Smith See include/petscviewer.h for a complete list of PetscViewers. 2025c6c1daeSBarry Smith 2035c6c1daeSBarry Smith PetscViewerType is actually a string 2045c6c1daeSBarry Smith 2055c6c1daeSBarry Smith .seealso: PetscViewerCreate(), PetscViewerSetType(), PetscViewerType 2065c6c1daeSBarry Smith 2075c6c1daeSBarry Smith @*/ 2085c6c1daeSBarry Smith PetscErrorCode PetscViewerGetType(PetscViewer viewer,PetscViewerType *type) 2095c6c1daeSBarry Smith { 2105c6c1daeSBarry Smith PetscFunctionBegin; 2115c6c1daeSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 2125c6c1daeSBarry Smith PetscValidPointer(type,2); 2135c6c1daeSBarry Smith *type = ((PetscObject)viewer)->type_name; 2145c6c1daeSBarry Smith PetscFunctionReturn(0); 2155c6c1daeSBarry Smith } 2165c6c1daeSBarry Smith 2175c6c1daeSBarry Smith /*@C 2185c6c1daeSBarry Smith PetscViewerSetOptionsPrefix - Sets the prefix used for searching for all 2195c6c1daeSBarry Smith PetscViewer options in the database. 2205c6c1daeSBarry Smith 2215c6c1daeSBarry Smith Logically Collective on PetscViewer 2225c6c1daeSBarry Smith 2235c6c1daeSBarry Smith Input Parameter: 2245c6c1daeSBarry Smith + viewer - the PetscViewer context 2255c6c1daeSBarry Smith - prefix - the prefix to prepend to all option names 2265c6c1daeSBarry Smith 2275c6c1daeSBarry Smith Notes: 2285c6c1daeSBarry Smith A hyphen (-) must NOT be given at the beginning of the prefix name. 2295c6c1daeSBarry Smith The first character of all runtime options is AUTOMATICALLY the hyphen. 2305c6c1daeSBarry Smith 2315c6c1daeSBarry Smith Level: advanced 2325c6c1daeSBarry Smith 2335c6c1daeSBarry Smith .seealso: PetscViewerSetFromOptions() 2345c6c1daeSBarry Smith @*/ 2355c6c1daeSBarry Smith PetscErrorCode PetscViewerSetOptionsPrefix(PetscViewer viewer,const char prefix[]) 2365c6c1daeSBarry Smith { 2375c6c1daeSBarry Smith PetscErrorCode ierr; 2385c6c1daeSBarry Smith 2395c6c1daeSBarry Smith PetscFunctionBegin; 2405c6c1daeSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 2415c6c1daeSBarry Smith ierr = PetscObjectSetOptionsPrefix((PetscObject)viewer,prefix);CHKERRQ(ierr); 2425c6c1daeSBarry Smith PetscFunctionReturn(0); 2435c6c1daeSBarry Smith } 2445c6c1daeSBarry Smith 2455c6c1daeSBarry Smith /*@C 2465c6c1daeSBarry Smith PetscViewerAppendOptionsPrefix - Appends to the prefix used for searching for all 2475c6c1daeSBarry Smith PetscViewer options in the database. 2485c6c1daeSBarry Smith 2495c6c1daeSBarry Smith Logically Collective on PetscViewer 2505c6c1daeSBarry Smith 2515c6c1daeSBarry Smith Input Parameters: 2525c6c1daeSBarry Smith + viewer - the PetscViewer context 2535c6c1daeSBarry Smith - prefix - the prefix to prepend to all option names 2545c6c1daeSBarry Smith 2555c6c1daeSBarry Smith Notes: 2565c6c1daeSBarry Smith A hyphen (-) must NOT be given at the beginning of the prefix name. 2575c6c1daeSBarry Smith The first character of all runtime options is AUTOMATICALLY the hyphen. 2585c6c1daeSBarry Smith 2595c6c1daeSBarry Smith Level: advanced 2605c6c1daeSBarry Smith 2615c6c1daeSBarry Smith .seealso: PetscViewerGetOptionsPrefix() 2625c6c1daeSBarry Smith @*/ 2635c6c1daeSBarry Smith PetscErrorCode PetscViewerAppendOptionsPrefix(PetscViewer viewer,const char prefix[]) 2645c6c1daeSBarry Smith { 2655c6c1daeSBarry Smith PetscErrorCode ierr; 2665c6c1daeSBarry Smith 2675c6c1daeSBarry Smith PetscFunctionBegin; 2685c6c1daeSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 2695c6c1daeSBarry Smith ierr = PetscObjectAppendOptionsPrefix((PetscObject)viewer,prefix);CHKERRQ(ierr); 2705c6c1daeSBarry Smith PetscFunctionReturn(0); 2715c6c1daeSBarry Smith } 2725c6c1daeSBarry Smith 2735c6c1daeSBarry Smith /*@C 2745c6c1daeSBarry Smith PetscViewerGetOptionsPrefix - Sets the prefix used for searching for all 2755c6c1daeSBarry Smith PetscViewer options in the database. 2765c6c1daeSBarry Smith 2775c6c1daeSBarry Smith Not Collective 2785c6c1daeSBarry Smith 2795c6c1daeSBarry Smith Input Parameter: 2805c6c1daeSBarry Smith . viewer - the PetscViewer context 2815c6c1daeSBarry Smith 2825c6c1daeSBarry Smith Output Parameter: 2835c6c1daeSBarry Smith . prefix - pointer to the prefix string used 2845c6c1daeSBarry Smith 28595452b02SPatrick Sanan Notes: 28695452b02SPatrick Sanan On the fortran side, the user should pass in a string 'prefix' of 2875c6c1daeSBarry Smith sufficient length to hold the prefix. 2885c6c1daeSBarry Smith 2895c6c1daeSBarry Smith Level: advanced 2905c6c1daeSBarry Smith 2915c6c1daeSBarry Smith .seealso: PetscViewerAppendOptionsPrefix() 2925c6c1daeSBarry Smith @*/ 2935c6c1daeSBarry Smith PetscErrorCode PetscViewerGetOptionsPrefix(PetscViewer viewer,const char *prefix[]) 2945c6c1daeSBarry Smith { 2955c6c1daeSBarry Smith PetscErrorCode ierr; 2965c6c1daeSBarry Smith 2975c6c1daeSBarry Smith PetscFunctionBegin; 2985c6c1daeSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 2995c6c1daeSBarry Smith ierr = PetscObjectGetOptionsPrefix((PetscObject)viewer,prefix);CHKERRQ(ierr); 3005c6c1daeSBarry Smith PetscFunctionReturn(0); 3015c6c1daeSBarry Smith } 3025c6c1daeSBarry Smith 3035c6c1daeSBarry Smith /*@ 3045c6c1daeSBarry Smith PetscViewerSetUp - Sets up the internal viewer data structures for the later use. 3055c6c1daeSBarry Smith 3065c6c1daeSBarry Smith Collective on PetscViewer 3075c6c1daeSBarry Smith 3085c6c1daeSBarry Smith Input Parameters: 3095c6c1daeSBarry Smith . viewer - the PetscViewer context 3105c6c1daeSBarry Smith 3115c6c1daeSBarry Smith Notes: 3125c6c1daeSBarry Smith For basic use of the PetscViewer classes the user need not explicitly call 3135c6c1daeSBarry Smith PetscViewerSetUp(), since these actions will happen automatically. 3145c6c1daeSBarry Smith 3155c6c1daeSBarry Smith Level: advanced 3165c6c1daeSBarry Smith 3175c6c1daeSBarry Smith .seealso: PetscViewerCreate(), PetscViewerDestroy() 3185c6c1daeSBarry Smith @*/ 3195c6c1daeSBarry Smith PetscErrorCode PetscViewerSetUp(PetscViewer viewer) 3205c6c1daeSBarry Smith { 321c98fd787SBarry Smith PetscErrorCode ierr; 322c98fd787SBarry Smith 3235c6c1daeSBarry Smith PetscFunctionBegin; 3245c6c1daeSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 325c98fd787SBarry Smith if (viewer->setupcalled) PetscFunctionReturn(0); 326c98fd787SBarry Smith if (viewer->ops->setup) { 327c98fd787SBarry Smith ierr = (*viewer->ops->setup)(viewer);CHKERRQ(ierr); 328c98fd787SBarry Smith } 329c98fd787SBarry Smith viewer->setupcalled = PETSC_TRUE; 3305c6c1daeSBarry Smith PetscFunctionReturn(0); 3315c6c1daeSBarry Smith } 3325c6c1daeSBarry Smith 3335c6c1daeSBarry Smith /*@C 334fe2efc57SMark PetscViewerViewFromOptions - View from Options 335fe2efc57SMark 336fe2efc57SMark Collective on PetscViewer 337fe2efc57SMark 338fe2efc57SMark Input Parameters: 339fe2efc57SMark + A - the PetscViewer context 340736c3998SJose E. Roman . obj - Optional object 341736c3998SJose E. Roman - name - command line option 342fe2efc57SMark 343fe2efc57SMark Level: intermediate 344fe2efc57SMark .seealso: PetscViewer, PetscViewerView, PetscObjectViewFromOptions(), PetscViewerCreate() 345fe2efc57SMark @*/ 346fe2efc57SMark PetscErrorCode PetscViewerViewFromOptions(PetscViewer A,PetscObject obj,const char name[]) 347fe2efc57SMark { 348fe2efc57SMark PetscErrorCode ierr; 349fe2efc57SMark 350fe2efc57SMark PetscFunctionBegin; 351fe2efc57SMark PetscValidHeaderSpecific(A,PETSC_VIEWER_CLASSID,1); 352fe2efc57SMark ierr = PetscObjectViewFromOptions((PetscObject)A,obj,name);CHKERRQ(ierr); 353fe2efc57SMark PetscFunctionReturn(0); 354fe2efc57SMark } 355fe2efc57SMark 356fe2efc57SMark /*@C 3575c6c1daeSBarry Smith PetscViewerView - Visualizes a viewer object. 3585c6c1daeSBarry Smith 3595c6c1daeSBarry Smith Collective on PetscViewer 3605c6c1daeSBarry Smith 3615c6c1daeSBarry Smith Input Parameters: 362f0d4698bSVaclav Hapla + v - the viewer to be viewed 3635c6c1daeSBarry Smith - viewer - visualization context 3645c6c1daeSBarry Smith 3655c6c1daeSBarry Smith Notes: 3665c6c1daeSBarry Smith The available visualization contexts include 3675c6c1daeSBarry Smith + PETSC_VIEWER_STDOUT_SELF - standard output (default) 3685c6c1daeSBarry Smith . PETSC_VIEWER_STDOUT_WORLD - synchronized standard 3695c6c1daeSBarry Smith output where only the first processor opens 3705c6c1daeSBarry Smith the file. All other processors send their 3715c6c1daeSBarry Smith data to the first processor to print. 3725c6c1daeSBarry Smith - PETSC_VIEWER_DRAW_WORLD - graphical display of nonzero structure 3735c6c1daeSBarry Smith 3745c6c1daeSBarry Smith Level: beginner 3755c6c1daeSBarry Smith 3766a9046bcSBarry Smith .seealso: PetscViewerPushFormat(), PetscViewerASCIIOpen(), PetscViewerDrawOpen(), 3775c6c1daeSBarry Smith PetscViewerSocketOpen(), PetscViewerBinaryOpen(), PetscViewerLoad() 3785c6c1daeSBarry Smith @*/ 3795c6c1daeSBarry Smith PetscErrorCode PetscViewerView(PetscViewer v,PetscViewer viewer) 3805c6c1daeSBarry Smith { 3815c6c1daeSBarry Smith PetscErrorCode ierr; 3825c6c1daeSBarry Smith PetscBool iascii; 3835c6c1daeSBarry Smith PetscViewerFormat format; 384e04113cfSBarry Smith #if defined(PETSC_HAVE_SAWS) 385536b137fSBarry Smith PetscBool issaws; 3860076e027SBarry Smith #endif 3875c6c1daeSBarry Smith 3885c6c1daeSBarry Smith PetscFunctionBegin; 3895c6c1daeSBarry Smith PetscValidHeaderSpecific(v,PETSC_VIEWER_CLASSID,1); 3905c6c1daeSBarry Smith PetscValidType(v,1); 3915c6c1daeSBarry Smith if (!viewer) { 392ce94432eSBarry Smith ierr = PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)v),&viewer);CHKERRQ(ierr); 3935c6c1daeSBarry Smith } 3945c6c1daeSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,2); 3955c6c1daeSBarry Smith PetscCheckSameComm(v,1,viewer,2); 3965c6c1daeSBarry Smith 3975c6c1daeSBarry Smith ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);CHKERRQ(ierr); 398e04113cfSBarry Smith #if defined(PETSC_HAVE_SAWS) 399536b137fSBarry Smith ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERSAWS,&issaws);CHKERRQ(ierr); 4000076e027SBarry Smith #endif 4015c6c1daeSBarry Smith if (iascii) { 4025c6c1daeSBarry Smith ierr = PetscViewerGetFormat(viewer,&format);CHKERRQ(ierr); 403dae58748SBarry Smith ierr = PetscObjectPrintClassNamePrefixType((PetscObject)v,viewer);CHKERRQ(ierr); 40498c3331eSBarry Smith if (format == PETSC_VIEWER_DEFAULT || format == PETSC_VIEWER_ASCII_INFO || format == PETSC_VIEWER_ASCII_INFO_DETAIL) { 4052f234a98SBarry Smith if (v->format) { 4062f234a98SBarry Smith ierr = PetscViewerASCIIPrintf(viewer," Viewer format = %s\n",PetscViewerFormats[v->format]);CHKERRQ(ierr); 4072f234a98SBarry Smith } 4085c6c1daeSBarry Smith ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); 4092bf49c77SBarry Smith if (v->ops->view) { 4102bf49c77SBarry Smith ierr = (*v->ops->view)(v,viewer);CHKERRQ(ierr); 4115c6c1daeSBarry Smith } 4125c6c1daeSBarry Smith ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); 4135c6c1daeSBarry Smith } 414e04113cfSBarry Smith #if defined(PETSC_HAVE_SAWS) 415536b137fSBarry Smith } else if (issaws) { 4160076e027SBarry Smith if (!((PetscObject)v)->amsmem) { 417e04113cfSBarry Smith ierr = PetscObjectViewSAWs((PetscObject)v,viewer);CHKERRQ(ierr); 4180076e027SBarry Smith if (v->ops->view) { 4190076e027SBarry Smith ierr = (*v->ops->view)(v,viewer);CHKERRQ(ierr); 4200076e027SBarry Smith } 4210076e027SBarry Smith } 4220076e027SBarry Smith #endif 4235c6c1daeSBarry Smith } 4245c6c1daeSBarry Smith PetscFunctionReturn(0); 4255c6c1daeSBarry Smith } 4261d641e7bSMichael Lange 4271d641e7bSMichael Lange /*@C 4281d641e7bSMichael Lange PetscViewerRead - Reads data from a PetscViewer 4291d641e7bSMichael Lange 430d083f849SBarry Smith Collective 4311d641e7bSMichael Lange 4321d641e7bSMichael Lange Input Parameters: 4331d641e7bSMichael Lange + viewer - The viewer 4341d641e7bSMichael Lange . data - Location to write the data 435060da220SMatthew G. Knepley . num - Number of items of data to read 4361d641e7bSMichael Lange - datatype - Type of data to read 4371d641e7bSMichael Lange 438f8e4bde8SMatthew G. Knepley Output Parameters: 439060da220SMatthew G. Knepley . count - number of items of data actually read, or NULL 440f8e4bde8SMatthew G. Knepley 441632e26b4SStefano Zampini Notes: 442632e26b4SStefano Zampini If datatype is PETSC_STRING and num is negative, reads until a newline character is found, 443632e26b4SStefano Zampini until a maximum of (-num - 1) chars. 444632e26b4SStefano Zampini 4451d641e7bSMichael Lange Level: beginner 4461d641e7bSMichael Lange 4476a9046bcSBarry Smith .seealso: PetscViewerASCIIOpen(), PetscViewerPushFormat(), PetscViewerDestroy(), 4481d641e7bSMichael Lange VecView(), MatView(), VecLoad(), MatLoad(), PetscViewerBinaryGetDescriptor(), 4491d641e7bSMichael Lange PetscViewerBinaryGetInfoPointer(), PetscFileMode, PetscViewer 4501d641e7bSMichael Lange @*/ 451060da220SMatthew G. Knepley PetscErrorCode PetscViewerRead(PetscViewer viewer, void *data, PetscInt num, PetscInt *count, PetscDataType dtype) 4521d641e7bSMichael Lange { 4531d641e7bSMichael Lange PetscErrorCode ierr; 4541d641e7bSMichael Lange 4551d641e7bSMichael Lange PetscFunctionBegin; 4561d641e7bSMichael Lange PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 4571d641e7bSMichael Lange if (dtype == PETSC_STRING) { 458060da220SMatthew G. Knepley PetscInt c, i = 0, cnt; 4591d641e7bSMichael Lange char *s = (char *)data; 460632e26b4SStefano Zampini if (num >= 0) { 461060da220SMatthew G. Knepley for (c = 0; c < num; c++) { 4621d641e7bSMichael Lange /* Skip leading whitespaces */ 4639860990eSLisandro Dalcin do {ierr = (*viewer->ops->read)(viewer, &(s[i]), 1, &cnt, PETSC_CHAR);CHKERRQ(ierr); if (!cnt) break;} 464eb2700f0SMichael Lange while (s[i]=='\n' || s[i]=='\t' || s[i]==' ' || s[i]=='\0' || s[i]=='\v' || s[i]=='\f' || s[i]=='\r'); 4651d641e7bSMichael Lange i++; 4661d641e7bSMichael Lange /* Read strings one char at a time */ 4679860990eSLisandro Dalcin do {ierr = (*viewer->ops->read)(viewer, &(s[i++]), 1, &cnt, PETSC_CHAR);CHKERRQ(ierr); if (!cnt) break;} 468eb2700f0SMichael 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'); 4691d641e7bSMichael Lange /* Terminate final string */ 470060da220SMatthew G. Knepley if (c == num-1) s[i-1] = '\0'; 4711d641e7bSMichael Lange } 472632e26b4SStefano Zampini } else { 473632e26b4SStefano Zampini /* Read until a \n is encountered (-num is the max size allowed) */ 4749860990eSLisandro Dalcin do {ierr = (*viewer->ops->read)(viewer, &(s[i++]), 1, &cnt, PETSC_CHAR);CHKERRQ(ierr); if (i == -num || !cnt) break;} 475632e26b4SStefano Zampini while (s[i-1]!='\n'); 476632e26b4SStefano Zampini /* Terminate final string */ 477632e26b4SStefano Zampini s[i-1] = '\0'; 478632e26b4SStefano Zampini c = i; 479632e26b4SStefano Zampini } 480060da220SMatthew G. Knepley if (count) *count = c; 481060da220SMatthew G. Knepley else if (c < num) SETERRQ2(PetscObjectComm((PetscObject) viewer), PETSC_ERR_FILE_READ, "Insufficient data, only read %D < %D strings", c, num); 4821d641e7bSMichael Lange } else { 483060da220SMatthew G. Knepley ierr = (*viewer->ops->read)(viewer, data, num, count, dtype);CHKERRQ(ierr); 4841d641e7bSMichael Lange } 4851d641e7bSMichael Lange PetscFunctionReturn(0); 4861d641e7bSMichael Lange } 487e24fdd67SVaclav Hapla 488af684e28SVaclav Hapla /*@ 489af684e28SVaclav Hapla PetscViewerReadable - Return a flag whether the viewer can be read from 490af684e28SVaclav Hapla 491af684e28SVaclav Hapla Not Collective 492af684e28SVaclav Hapla 493af684e28SVaclav Hapla Input Parameters: 494af684e28SVaclav Hapla . viewer - the PetscViewer context 495af684e28SVaclav Hapla 496af684e28SVaclav Hapla Output Parameters: 497af684e28SVaclav Hapla . flg - PETSC_TRUE if the viewer is readable, PETSC_FALSE otherwise 498af684e28SVaclav Hapla 499af684e28SVaclav Hapla Notes: 500af684e28SVaclav Hapla PETSC_TRUE means that viewer's PetscViewerType supports reading (this holds e.g. for PETSCVIEWERBINARY) 501af684e28SVaclav Hapla and viewer is in a mode allowing reading, i.e. PetscViewerFileGetMode() 502af684e28SVaclav Hapla returns one of FILE_MODE_READ, FILE_MODE_UPDATE, FILE_MODE_APPEND_UPDATE. 503af684e28SVaclav Hapla 504af684e28SVaclav Hapla Level: intermediate 505af684e28SVaclav Hapla 506af684e28SVaclav Hapla .seealso: PetscViewerWritable(), PetscViewerCheckReadable(), PetscViewerCreate(), PetscViewerFileSetMode(), PetscViewerFileSetType() 507af684e28SVaclav Hapla @*/ 508e24fdd67SVaclav Hapla PetscErrorCode PetscViewerReadable(PetscViewer viewer, PetscBool *flg) 509e24fdd67SVaclav Hapla { 510e24fdd67SVaclav Hapla PetscErrorCode ierr; 511e24fdd67SVaclav Hapla PetscFileMode mode; 512e24fdd67SVaclav Hapla PetscErrorCode (*f)(PetscViewer,PetscFileMode*) = NULL; 513e24fdd67SVaclav Hapla 514e24fdd67SVaclav Hapla PetscFunctionBegin; 515e24fdd67SVaclav Hapla PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 516534a8f05SLisandro Dalcin PetscValidBoolPointer(flg,2); 517e24fdd67SVaclav Hapla ierr = PetscObjectQueryFunction((PetscObject)viewer, "PetscViewerFileGetMode_C", &f);CHKERRQ(ierr); 518e24fdd67SVaclav Hapla *flg = PETSC_FALSE; 519e24fdd67SVaclav Hapla if (!f) PetscFunctionReturn(0); 520e24fdd67SVaclav Hapla ierr = (*f)(viewer, &mode);CHKERRQ(ierr); 521e24fdd67SVaclav Hapla switch (mode) { 522e24fdd67SVaclav Hapla case FILE_MODE_READ: 523e24fdd67SVaclav Hapla case FILE_MODE_UPDATE: 524e24fdd67SVaclav Hapla case FILE_MODE_APPEND_UPDATE: 525e24fdd67SVaclav Hapla *flg = PETSC_TRUE; 526e24fdd67SVaclav Hapla default: break; 527e24fdd67SVaclav Hapla } 528e24fdd67SVaclav Hapla PetscFunctionReturn(0); 529e24fdd67SVaclav Hapla } 530e24fdd67SVaclav Hapla 531af684e28SVaclav Hapla /*@ 532af684e28SVaclav Hapla PetscViewerWritable - Return a flag whether the viewer can be written to 533af684e28SVaclav Hapla 534af684e28SVaclav Hapla Not Collective 535af684e28SVaclav Hapla 536af684e28SVaclav Hapla Input Parameters: 537af684e28SVaclav Hapla . viewer - the PetscViewer context 538af684e28SVaclav Hapla 539af684e28SVaclav Hapla Output Parameters: 540af684e28SVaclav Hapla . flg - PETSC_TRUE if the viewer is writable, PETSC_FALSE otherwise 541af684e28SVaclav Hapla 542af684e28SVaclav Hapla Notes: 543af684e28SVaclav Hapla PETSC_TRUE means viewer is in a mode allowing writing, i.e. PetscViewerFileGetMode() 544af684e28SVaclav Hapla returns one of FILE_MODE_WRITE, FILE_MODE_APPEND, FILE_MODE_UPDATE, FILE_MODE_APPEND_UPDATE. 545af684e28SVaclav Hapla 546af684e28SVaclav Hapla Level: intermediate 547af684e28SVaclav Hapla 548af684e28SVaclav Hapla .seealso: PetscViewerReadable(), PetscViewerCheckWritable(), PetscViewerCreate(), PetscViewerFileSetMode(), PetscViewerFileSetType() 549af684e28SVaclav Hapla @*/ 550e24fdd67SVaclav Hapla PetscErrorCode PetscViewerWritable(PetscViewer viewer, PetscBool *flg) 551e24fdd67SVaclav Hapla { 552e24fdd67SVaclav Hapla PetscErrorCode ierr; 553e24fdd67SVaclav Hapla PetscFileMode mode; 554e24fdd67SVaclav Hapla PetscErrorCode (*f)(PetscViewer,PetscFileMode*) = NULL; 555e24fdd67SVaclav Hapla 556e24fdd67SVaclav Hapla PetscFunctionBegin; 557e24fdd67SVaclav Hapla PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 558534a8f05SLisandro Dalcin PetscValidBoolPointer(flg,2); 559e24fdd67SVaclav Hapla ierr = PetscObjectQueryFunction((PetscObject)viewer, "PetscViewerFileGetMode_C", &f);CHKERRQ(ierr); 560e24fdd67SVaclav Hapla *flg = PETSC_TRUE; 561e24fdd67SVaclav Hapla if (!f) PetscFunctionReturn(0); 562e24fdd67SVaclav Hapla ierr = (*f)(viewer, &mode);CHKERRQ(ierr); 563e24fdd67SVaclav Hapla if (mode == FILE_MODE_READ) *flg = PETSC_FALSE; 564e24fdd67SVaclav Hapla PetscFunctionReturn(0); 565e24fdd67SVaclav Hapla } 566e24fdd67SVaclav Hapla 567af684e28SVaclav Hapla /*@ 568af684e28SVaclav Hapla PetscViewerCheckReadable - Check whether the viewer can be read from 569af684e28SVaclav Hapla 570af684e28SVaclav Hapla Collective 571af684e28SVaclav Hapla 572af684e28SVaclav Hapla Input Parameters: 573af684e28SVaclav Hapla . viewer - the PetscViewer context 574af684e28SVaclav Hapla 575af684e28SVaclav Hapla Level: intermediate 576af684e28SVaclav Hapla 577af684e28SVaclav Hapla .seealso: PetscViewerReadable(), PetscViewerCheckWritable(), PetscViewerCreate(), PetscViewerFileSetMode(), PetscViewerFileSetType() 578af684e28SVaclav Hapla @*/ 579d01f05b1SVaclav Hapla PetscErrorCode PetscViewerCheckReadable(PetscViewer viewer) 580d01f05b1SVaclav Hapla { 581d01f05b1SVaclav Hapla PetscBool flg; 582d01f05b1SVaclav Hapla PetscErrorCode ierr; 583d01f05b1SVaclav Hapla 584d01f05b1SVaclav Hapla PetscFunctionBegin; 5850af448b7SVaclav Hapla PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 586d01f05b1SVaclav Hapla ierr = PetscViewerReadable(viewer, &flg);CHKERRQ(ierr); 587d01f05b1SVaclav 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)"); 588d01f05b1SVaclav Hapla PetscFunctionReturn(0); 589d01f05b1SVaclav Hapla } 590d01f05b1SVaclav Hapla 591af684e28SVaclav Hapla /*@ 592af684e28SVaclav Hapla PetscViewerCheckWritable - Check whether the viewer can be written to 593af684e28SVaclav Hapla 594af684e28SVaclav Hapla Collective 595af684e28SVaclav Hapla 596af684e28SVaclav Hapla Input Parameters: 597af684e28SVaclav Hapla . viewer - the PetscViewer context 598af684e28SVaclav Hapla 599af684e28SVaclav Hapla Level: intermediate 600af684e28SVaclav Hapla 601af684e28SVaclav Hapla .seealso: PetscViewerWritable(), PetscViewerCheckReadable(), PetscViewerCreate(), PetscViewerFileSetMode(), PetscViewerFileSetType() 602af684e28SVaclav Hapla @*/ 603d01f05b1SVaclav Hapla PetscErrorCode PetscViewerCheckWritable(PetscViewer viewer) 604d01f05b1SVaclav Hapla { 605d01f05b1SVaclav Hapla PetscBool flg; 606d01f05b1SVaclav Hapla PetscErrorCode ierr; 607d01f05b1SVaclav Hapla 608d01f05b1SVaclav Hapla PetscFunctionBegin; 6090af448b7SVaclav Hapla PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 610d01f05b1SVaclav Hapla ierr = PetscViewerWritable(viewer, &flg);CHKERRQ(ierr); 611d01f05b1SVaclav Hapla if (!flg) SETERRQ(PetscObjectComm((PetscObject)viewer), PETSC_ERR_SUP, "Viewer doesn't support writing, or is in FILE_MODE_READ mode"); 612d01f05b1SVaclav Hapla PetscFunctionReturn(0); 613d01f05b1SVaclav Hapla } 614