15c6c1daeSBarry Smith 2af0996ceSBarry Smith #include <petsc/private/viewerimpl.h> /*I "petscviewer.h" I*/ 3798534f6SMatthew G. Knepley #include <petscdraw.h> 45c6c1daeSBarry Smith 55c6c1daeSBarry Smith PetscClassId PETSC_VIEWER_CLASSID; 65c6c1daeSBarry Smith 75c6c1daeSBarry Smith static PetscBool PetscViewerPackageInitialized = PETSC_FALSE; 85c6c1daeSBarry Smith /*@C 9b6dade52SBarry Smith PetscViewerFinalizePackage - This function destroys any global objects created in the Petsc viewers. It is 105c6c1daeSBarry Smith called from PetscFinalize(). 115c6c1daeSBarry Smith 125c6c1daeSBarry Smith Level: developer 135c6c1daeSBarry Smith 145c6c1daeSBarry Smith .seealso: PetscFinalize() 155c6c1daeSBarry Smith @*/ 165c6c1daeSBarry Smith PetscErrorCode PetscViewerFinalizePackage(void) 175c6c1daeSBarry Smith { 185c6c1daeSBarry Smith PetscFunctionBegin; 19b6dade52SBarry Smith if (Petsc_Viewer_keyval != MPI_KEYVAL_INVALID) { 205f80ce2aSJacob Faibussowitsch CHKERRMPI(MPI_Comm_free_keyval(&Petsc_Viewer_keyval)); 21b6dade52SBarry Smith } 22b6dade52SBarry Smith if (Petsc_Viewer_Stdout_keyval != MPI_KEYVAL_INVALID) { 235f80ce2aSJacob Faibussowitsch CHKERRMPI(MPI_Comm_free_keyval(&Petsc_Viewer_Stdout_keyval)); 24b6dade52SBarry Smith } 25b6dade52SBarry Smith if (Petsc_Viewer_Stderr_keyval != MPI_KEYVAL_INVALID) { 265f80ce2aSJacob Faibussowitsch CHKERRMPI(MPI_Comm_free_keyval(&Petsc_Viewer_Stderr_keyval)); 27b6dade52SBarry Smith } 28b6dade52SBarry Smith if (Petsc_Viewer_Binary_keyval != MPI_KEYVAL_INVALID) { 295f80ce2aSJacob Faibussowitsch CHKERRMPI(MPI_Comm_free_keyval(&Petsc_Viewer_Binary_keyval)); 30b6dade52SBarry Smith } 31b6dade52SBarry Smith if (Petsc_Viewer_Draw_keyval != MPI_KEYVAL_INVALID) { 325f80ce2aSJacob Faibussowitsch CHKERRMPI(MPI_Comm_free_keyval(&Petsc_Viewer_Draw_keyval)); 33b6dade52SBarry Smith } 34b6dade52SBarry Smith #if defined(PETSC_HAVE_HDF5) 35b6dade52SBarry Smith if (Petsc_Viewer_HDF5_keyval != MPI_KEYVAL_INVALID) { 365f80ce2aSJacob Faibussowitsch CHKERRMPI(MPI_Comm_free_keyval(&Petsc_Viewer_HDF5_keyval)); 37b6dade52SBarry Smith } 38b6dade52SBarry Smith #endif 39b6dade52SBarry Smith #if defined(PETSC_USE_SOCKETVIEWER) 40b6dade52SBarry Smith if (Petsc_Viewer_Socket_keyval != MPI_KEYVAL_INVALID) { 415f80ce2aSJacob Faibussowitsch CHKERRMPI(MPI_Comm_free_keyval(&Petsc_Viewer_Socket_keyval)); 42b6dade52SBarry Smith } 43b6dade52SBarry Smith #endif 445f80ce2aSJacob Faibussowitsch CHKERRQ(PetscFunctionListDestroy(&PetscViewerList)); 455c6c1daeSBarry Smith PetscViewerPackageInitialized = PETSC_FALSE; 460f51fdf8SToby Isaac PetscViewerRegisterAllCalled = PETSC_FALSE; 475c6c1daeSBarry Smith PetscFunctionReturn(0); 485c6c1daeSBarry Smith } 495c6c1daeSBarry Smith 505c6c1daeSBarry Smith /*@C 515c6c1daeSBarry Smith PetscViewerInitializePackage - This function initializes everything in the main PetscViewer package. 525c6c1daeSBarry Smith 535c6c1daeSBarry Smith Level: developer 545c6c1daeSBarry Smith 555c6c1daeSBarry Smith .seealso: PetscInitialize() 565c6c1daeSBarry Smith @*/ 57607a6623SBarry Smith PetscErrorCode PetscViewerInitializePackage(void) 585c6c1daeSBarry Smith { 595c6c1daeSBarry Smith char logList[256]; 608e81d068SLisandro Dalcin PetscBool opt,pkg; 615c6c1daeSBarry Smith 625c6c1daeSBarry Smith PetscFunctionBegin; 635c6c1daeSBarry Smith if (PetscViewerPackageInitialized) PetscFunctionReturn(0); 645c6c1daeSBarry Smith PetscViewerPackageInitialized = PETSC_TRUE; 655c6c1daeSBarry Smith /* Register Classes */ 665f80ce2aSJacob Faibussowitsch CHKERRQ(PetscClassIdRegister("Viewer",&PETSC_VIEWER_CLASSID)); 675c6c1daeSBarry Smith /* Register Constructors */ 685f80ce2aSJacob Faibussowitsch CHKERRQ(PetscViewerRegisterAll()); 69e94e781bSJacob Faibussowitsch /* Process Info */ 70e94e781bSJacob Faibussowitsch { 71e94e781bSJacob Faibussowitsch PetscClassId classids[1]; 72e94e781bSJacob Faibussowitsch 73e94e781bSJacob Faibussowitsch classids[0] = PETSC_VIEWER_CLASSID; 745f80ce2aSJacob Faibussowitsch CHKERRQ(PetscInfoProcessClass("viewer", 1, classids)); 755c6c1daeSBarry Smith } 765c6c1daeSBarry Smith /* Process summary exclusions */ 775f80ce2aSJacob Faibussowitsch CHKERRQ(PetscOptionsGetString(NULL,NULL,"-log_exclude",logList,sizeof(logList),&opt)); 785c6c1daeSBarry Smith if (opt) { 795f80ce2aSJacob Faibussowitsch CHKERRQ(PetscStrInList("viewer",logList,',',&pkg)); 805f80ce2aSJacob Faibussowitsch if (pkg) CHKERRQ(PetscLogEventExcludeClass(PETSC_VIEWER_CLASSID)); 815c6c1daeSBarry Smith } 825c6c1daeSBarry Smith #if defined(PETSC_HAVE_MATHEMATICA) 835f80ce2aSJacob Faibussowitsch CHKERRQ(PetscViewerMathematicaInitializePackage()); 845c6c1daeSBarry Smith #endif 858e81d068SLisandro Dalcin /* Register package finalizer */ 865f80ce2aSJacob Faibussowitsch CHKERRQ(PetscRegisterFinalize(PetscViewerFinalizePackage)); 875c6c1daeSBarry Smith PetscFunctionReturn(0); 885c6c1daeSBarry Smith } 895c6c1daeSBarry Smith 905c6c1daeSBarry Smith /*@ 915c6c1daeSBarry Smith PetscViewerDestroy - Destroys a PetscViewer. 925c6c1daeSBarry Smith 935c6c1daeSBarry Smith Collective on PetscViewer 945c6c1daeSBarry Smith 955c6c1daeSBarry Smith Input Parameters: 965c6c1daeSBarry Smith . viewer - the PetscViewer to be destroyed. 975c6c1daeSBarry Smith 985c6c1daeSBarry Smith Level: beginner 995c6c1daeSBarry Smith 1005c6c1daeSBarry Smith .seealso: PetscViewerSocketOpen(), PetscViewerASCIIOpen(), PetscViewerCreate(), PetscViewerDrawOpen() 1015c6c1daeSBarry Smith 1025c6c1daeSBarry Smith @*/ 1035c6c1daeSBarry Smith PetscErrorCode PetscViewerDestroy(PetscViewer *viewer) 1045c6c1daeSBarry Smith { 1055c6c1daeSBarry Smith PetscFunctionBegin; 1065c6c1daeSBarry Smith if (!*viewer) PetscFunctionReturn(0); 1075c6c1daeSBarry Smith PetscValidHeaderSpecific(*viewer,PETSC_VIEWER_CLASSID,1); 1085c6c1daeSBarry Smith 1095f80ce2aSJacob Faibussowitsch CHKERRQ(PetscViewerFlush(*viewer)); 11002c9f0b5SLisandro Dalcin if (--((PetscObject)(*viewer))->refct > 0) {*viewer = NULL; PetscFunctionReturn(0);} 1115c6c1daeSBarry Smith 1125f80ce2aSJacob Faibussowitsch CHKERRQ(PetscObjectSAWsViewOff((PetscObject)*viewer)); 1135c6c1daeSBarry Smith if ((*viewer)->ops->destroy) { 1145f80ce2aSJacob Faibussowitsch CHKERRQ((*(*viewer)->ops->destroy)(*viewer)); 1155c6c1daeSBarry Smith } 1165f80ce2aSJacob Faibussowitsch CHKERRQ(PetscHeaderDestroy(viewer)); 1175c6c1daeSBarry Smith PetscFunctionReturn(0); 1185c6c1daeSBarry Smith } 1195c6c1daeSBarry Smith 120d7cbc13eSBarry Smith /*@C 121d7cbc13eSBarry Smith PetscViewerAndFormatCreate - Creates a PetscViewerAndFormat struct. 122d7cbc13eSBarry Smith 123d7cbc13eSBarry Smith Collective on PetscViewer 124d7cbc13eSBarry Smith 125d7cbc13eSBarry Smith Input Parameters: 126d7cbc13eSBarry Smith + viewer - the viewer 127d7cbc13eSBarry Smith - format - the format 128d7cbc13eSBarry Smith 129d7cbc13eSBarry Smith Output Parameter: 130d7cbc13eSBarry Smith . vf - viewer and format object 131d7cbc13eSBarry Smith 13295452b02SPatrick Sanan Notes: 13395452b02SPatrick Sanan This increases the reference count of the viewer so you can destroy the viewer object after this call 134d7cbc13eSBarry Smith Level: developer 135d7cbc13eSBarry Smith 136d7cbc13eSBarry Smith This is used as the context variable for many of the TS, SNES, and KSP monitor functions 137d7cbc13eSBarry Smith 138d7cbc13eSBarry Smith .seealso: PetscViewerSocketOpen(), PetscViewerASCIIOpen(), PetscViewerCreate(), PetscViewerDrawOpen(), PetscViewerAndFormatDestroy() 139d7cbc13eSBarry Smith 140d7cbc13eSBarry Smith @*/ 141d7cbc13eSBarry Smith PetscErrorCode PetscViewerAndFormatCreate(PetscViewer viewer, PetscViewerFormat format, PetscViewerAndFormat **vf) 142d7cbc13eSBarry Smith { 143d7cbc13eSBarry Smith PetscFunctionBegin; 1445f80ce2aSJacob Faibussowitsch CHKERRQ(PetscObjectReference((PetscObject)viewer)); 1455f80ce2aSJacob Faibussowitsch CHKERRQ(PetscNew(vf)); 146d7cbc13eSBarry Smith (*vf)->viewer = viewer; 147d7cbc13eSBarry Smith (*vf)->format = format; 148798534f6SMatthew G. Knepley (*vf)->lg = NULL; 149798534f6SMatthew G. Knepley (*vf)->data = NULL; 150d7cbc13eSBarry Smith PetscFunctionReturn(0); 151d7cbc13eSBarry Smith } 152d7cbc13eSBarry Smith 153fe01d993SBarry Smith /*@C 154fe01d993SBarry Smith PetscViewerAndFormatDestroy - Destroys a PetscViewerAndFormat struct. 155fe01d993SBarry Smith 156fe01d993SBarry Smith Collective on PetscViewer 157fe01d993SBarry Smith 158fe01d993SBarry Smith Input Parameters: 159798534f6SMatthew G. Knepley . vf - the PetscViewerAndFormat to be destroyed. 160fe01d993SBarry Smith 161d7cbc13eSBarry Smith Level: developer 162fe01d993SBarry Smith 163d7cbc13eSBarry Smith .seealso: PetscViewerSocketOpen(), PetscViewerASCIIOpen(), PetscViewerCreate(), PetscViewerDrawOpen(), PetscViewerAndFormatCreate() 164fe01d993SBarry Smith @*/ 165fe01d993SBarry Smith PetscErrorCode PetscViewerAndFormatDestroy(PetscViewerAndFormat **vf) 166fe01d993SBarry Smith { 167fe01d993SBarry Smith PetscFunctionBegin; 1685f80ce2aSJacob Faibussowitsch CHKERRQ(PetscViewerDestroy(&(*vf)->viewer)); 1695f80ce2aSJacob Faibussowitsch CHKERRQ(PetscDrawLGDestroy(&(*vf)->lg)); 1705f80ce2aSJacob Faibussowitsch CHKERRQ(PetscFree(*vf)); 171fe01d993SBarry Smith PetscFunctionReturn(0); 172fe01d993SBarry Smith } 173fe01d993SBarry Smith 1745c6c1daeSBarry Smith /*@C 1755c6c1daeSBarry Smith PetscViewerGetType - Returns the type of a PetscViewer. 1765c6c1daeSBarry Smith 1775c6c1daeSBarry Smith Not Collective 1785c6c1daeSBarry Smith 1795c6c1daeSBarry Smith Input Parameter: 1805c6c1daeSBarry Smith . viewer - the PetscViewer 1815c6c1daeSBarry Smith 1825c6c1daeSBarry Smith Output Parameter: 1835c6c1daeSBarry Smith . type - PetscViewer type (see below) 1845c6c1daeSBarry Smith 1855c6c1daeSBarry Smith Available Types Include: 186a2b725a8SWilliam Gropp + PETSCVIEWERSOCKET - Socket PetscViewer 1875c6c1daeSBarry Smith . PETSCVIEWERASCII - ASCII PetscViewer 1885c6c1daeSBarry Smith . PETSCVIEWERBINARY - binary file PetscViewer 1895c6c1daeSBarry Smith . PETSCVIEWERSTRING - string PetscViewer 190a2b725a8SWilliam Gropp - PETSCVIEWERDRAW - drawing PetscViewer 1915c6c1daeSBarry Smith 1925c6c1daeSBarry Smith Level: intermediate 1935c6c1daeSBarry Smith 1945c6c1daeSBarry Smith Note: 1955c6c1daeSBarry Smith See include/petscviewer.h for a complete list of PetscViewers. 1965c6c1daeSBarry Smith 1975c6c1daeSBarry Smith PetscViewerType is actually a string 1985c6c1daeSBarry Smith 1995c6c1daeSBarry Smith .seealso: PetscViewerCreate(), PetscViewerSetType(), PetscViewerType 2005c6c1daeSBarry Smith 2015c6c1daeSBarry Smith @*/ 2025c6c1daeSBarry Smith PetscErrorCode PetscViewerGetType(PetscViewer viewer,PetscViewerType *type) 2035c6c1daeSBarry Smith { 2045c6c1daeSBarry Smith PetscFunctionBegin; 2055c6c1daeSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 2065c6c1daeSBarry Smith PetscValidPointer(type,2); 2075c6c1daeSBarry Smith *type = ((PetscObject)viewer)->type_name; 2085c6c1daeSBarry Smith PetscFunctionReturn(0); 2095c6c1daeSBarry Smith } 2105c6c1daeSBarry Smith 2115c6c1daeSBarry Smith /*@C 2125c6c1daeSBarry Smith PetscViewerSetOptionsPrefix - Sets the prefix used for searching for all 2135c6c1daeSBarry Smith PetscViewer options in the database. 2145c6c1daeSBarry Smith 2155c6c1daeSBarry Smith Logically Collective on PetscViewer 2165c6c1daeSBarry Smith 217d8d19677SJose E. Roman Input Parameters: 2185c6c1daeSBarry Smith + viewer - the PetscViewer context 2195c6c1daeSBarry Smith - prefix - the prefix to prepend to all option names 2205c6c1daeSBarry Smith 2215c6c1daeSBarry Smith Notes: 2225c6c1daeSBarry Smith A hyphen (-) must NOT be given at the beginning of the prefix name. 2235c6c1daeSBarry Smith The first character of all runtime options is AUTOMATICALLY the hyphen. 2245c6c1daeSBarry Smith 2255c6c1daeSBarry Smith Level: advanced 2265c6c1daeSBarry Smith 2275c6c1daeSBarry Smith .seealso: PetscViewerSetFromOptions() 2285c6c1daeSBarry Smith @*/ 2295c6c1daeSBarry Smith PetscErrorCode PetscViewerSetOptionsPrefix(PetscViewer viewer,const char prefix[]) 2305c6c1daeSBarry Smith { 2315c6c1daeSBarry Smith PetscFunctionBegin; 2325c6c1daeSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 2335f80ce2aSJacob Faibussowitsch CHKERRQ(PetscObjectSetOptionsPrefix((PetscObject)viewer,prefix)); 2345c6c1daeSBarry Smith PetscFunctionReturn(0); 2355c6c1daeSBarry Smith } 2365c6c1daeSBarry Smith 2375c6c1daeSBarry Smith /*@C 2385c6c1daeSBarry Smith PetscViewerAppendOptionsPrefix - Appends to the prefix used for searching for all 2395c6c1daeSBarry Smith PetscViewer options in the database. 2405c6c1daeSBarry Smith 2415c6c1daeSBarry Smith Logically Collective on PetscViewer 2425c6c1daeSBarry Smith 2435c6c1daeSBarry Smith Input Parameters: 2445c6c1daeSBarry Smith + viewer - the PetscViewer context 2455c6c1daeSBarry Smith - prefix - the prefix to prepend to all option names 2465c6c1daeSBarry Smith 2475c6c1daeSBarry Smith Notes: 2485c6c1daeSBarry Smith A hyphen (-) must NOT be given at the beginning of the prefix name. 2495c6c1daeSBarry Smith The first character of all runtime options is AUTOMATICALLY the hyphen. 2505c6c1daeSBarry Smith 2515c6c1daeSBarry Smith Level: advanced 2525c6c1daeSBarry Smith 2535c6c1daeSBarry Smith .seealso: PetscViewerGetOptionsPrefix() 2545c6c1daeSBarry Smith @*/ 2555c6c1daeSBarry Smith PetscErrorCode PetscViewerAppendOptionsPrefix(PetscViewer viewer,const char prefix[]) 2565c6c1daeSBarry Smith { 2575c6c1daeSBarry Smith PetscFunctionBegin; 2585c6c1daeSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 2595f80ce2aSJacob Faibussowitsch CHKERRQ(PetscObjectAppendOptionsPrefix((PetscObject)viewer,prefix)); 2605c6c1daeSBarry Smith PetscFunctionReturn(0); 2615c6c1daeSBarry Smith } 2625c6c1daeSBarry Smith 2635c6c1daeSBarry Smith /*@C 2645c6c1daeSBarry Smith PetscViewerGetOptionsPrefix - Sets the prefix used for searching for all 2655c6c1daeSBarry Smith PetscViewer options in the database. 2665c6c1daeSBarry Smith 2675c6c1daeSBarry Smith Not Collective 2685c6c1daeSBarry Smith 2695c6c1daeSBarry Smith Input Parameter: 2705c6c1daeSBarry Smith . viewer - the PetscViewer context 2715c6c1daeSBarry Smith 2725c6c1daeSBarry Smith Output Parameter: 2735c6c1daeSBarry Smith . prefix - pointer to the prefix string used 2745c6c1daeSBarry Smith 27595452b02SPatrick Sanan Notes: 27695452b02SPatrick Sanan On the fortran side, the user should pass in a string 'prefix' of 2775c6c1daeSBarry Smith sufficient length to hold the prefix. 2785c6c1daeSBarry Smith 2795c6c1daeSBarry Smith Level: advanced 2805c6c1daeSBarry Smith 2815c6c1daeSBarry Smith .seealso: PetscViewerAppendOptionsPrefix() 2825c6c1daeSBarry Smith @*/ 2835c6c1daeSBarry Smith PetscErrorCode PetscViewerGetOptionsPrefix(PetscViewer viewer,const char *prefix[]) 2845c6c1daeSBarry Smith { 2855c6c1daeSBarry Smith PetscFunctionBegin; 2865c6c1daeSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 2875f80ce2aSJacob Faibussowitsch CHKERRQ(PetscObjectGetOptionsPrefix((PetscObject)viewer,prefix)); 2885c6c1daeSBarry Smith PetscFunctionReturn(0); 2895c6c1daeSBarry Smith } 2905c6c1daeSBarry Smith 2915c6c1daeSBarry Smith /*@ 2925c6c1daeSBarry Smith PetscViewerSetUp - Sets up the internal viewer data structures for the later use. 2935c6c1daeSBarry Smith 2945c6c1daeSBarry Smith Collective on PetscViewer 2955c6c1daeSBarry Smith 2965c6c1daeSBarry Smith Input Parameters: 2975c6c1daeSBarry Smith . viewer - the PetscViewer context 2985c6c1daeSBarry Smith 2995c6c1daeSBarry Smith Notes: 3005c6c1daeSBarry Smith For basic use of the PetscViewer classes the user need not explicitly call 3015c6c1daeSBarry Smith PetscViewerSetUp(), since these actions will happen automatically. 3025c6c1daeSBarry Smith 3035c6c1daeSBarry Smith Level: advanced 3045c6c1daeSBarry Smith 3055c6c1daeSBarry Smith .seealso: PetscViewerCreate(), PetscViewerDestroy() 3065c6c1daeSBarry Smith @*/ 3075c6c1daeSBarry Smith PetscErrorCode PetscViewerSetUp(PetscViewer viewer) 3085c6c1daeSBarry Smith { 3095c6c1daeSBarry Smith PetscFunctionBegin; 3105c6c1daeSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 311c98fd787SBarry Smith if (viewer->setupcalled) PetscFunctionReturn(0); 312c98fd787SBarry Smith if (viewer->ops->setup) { 3135f80ce2aSJacob Faibussowitsch CHKERRQ((*viewer->ops->setup)(viewer)); 314c98fd787SBarry Smith } 315c98fd787SBarry Smith viewer->setupcalled = PETSC_TRUE; 3165c6c1daeSBarry Smith PetscFunctionReturn(0); 3175c6c1daeSBarry Smith } 3185c6c1daeSBarry Smith 3195c6c1daeSBarry Smith /*@C 320fe2efc57SMark PetscViewerViewFromOptions - View from Options 321fe2efc57SMark 322fe2efc57SMark Collective on PetscViewer 323fe2efc57SMark 324fe2efc57SMark Input Parameters: 325fe2efc57SMark + A - the PetscViewer context 326736c3998SJose E. Roman . obj - Optional object 327736c3998SJose E. Roman - name - command line option 328fe2efc57SMark 329fe2efc57SMark Level: intermediate 330fe2efc57SMark .seealso: PetscViewer, PetscViewerView, PetscObjectViewFromOptions(), PetscViewerCreate() 331fe2efc57SMark @*/ 332fe2efc57SMark PetscErrorCode PetscViewerViewFromOptions(PetscViewer A,PetscObject obj,const char name[]) 333fe2efc57SMark { 334fe2efc57SMark PetscFunctionBegin; 335fe2efc57SMark PetscValidHeaderSpecific(A,PETSC_VIEWER_CLASSID,1); 3365f80ce2aSJacob Faibussowitsch CHKERRQ(PetscObjectViewFromOptions((PetscObject)A,obj,name)); 337fe2efc57SMark PetscFunctionReturn(0); 338fe2efc57SMark } 339fe2efc57SMark 340fe2efc57SMark /*@C 3415c6c1daeSBarry Smith PetscViewerView - Visualizes a viewer object. 3425c6c1daeSBarry Smith 3435c6c1daeSBarry Smith Collective on PetscViewer 3445c6c1daeSBarry Smith 3455c6c1daeSBarry Smith Input Parameters: 346f0d4698bSVaclav Hapla + v - the viewer to be viewed 3475c6c1daeSBarry Smith - viewer - visualization context 3485c6c1daeSBarry Smith 3495c6c1daeSBarry Smith Notes: 3505c6c1daeSBarry Smith The available visualization contexts include 3515c6c1daeSBarry Smith + PETSC_VIEWER_STDOUT_SELF - standard output (default) 3525c6c1daeSBarry Smith . PETSC_VIEWER_STDOUT_WORLD - synchronized standard 3535c6c1daeSBarry Smith output where only the first processor opens 3545c6c1daeSBarry Smith the file. All other processors send their 3555c6c1daeSBarry Smith data to the first processor to print. 3565c6c1daeSBarry Smith - PETSC_VIEWER_DRAW_WORLD - graphical display of nonzero structure 3575c6c1daeSBarry Smith 3585c6c1daeSBarry Smith Level: beginner 3595c6c1daeSBarry Smith 3606a9046bcSBarry Smith .seealso: PetscViewerPushFormat(), PetscViewerASCIIOpen(), PetscViewerDrawOpen(), 3615c6c1daeSBarry Smith PetscViewerSocketOpen(), PetscViewerBinaryOpen(), PetscViewerLoad() 3625c6c1daeSBarry Smith @*/ 3635c6c1daeSBarry Smith PetscErrorCode PetscViewerView(PetscViewer v,PetscViewer viewer) 3645c6c1daeSBarry Smith { 3655c6c1daeSBarry Smith PetscBool iascii; 3665c6c1daeSBarry Smith PetscViewerFormat format; 367e04113cfSBarry Smith #if defined(PETSC_HAVE_SAWS) 368536b137fSBarry Smith PetscBool issaws; 3690076e027SBarry Smith #endif 3705c6c1daeSBarry Smith 3715c6c1daeSBarry Smith PetscFunctionBegin; 3725c6c1daeSBarry Smith PetscValidHeaderSpecific(v,PETSC_VIEWER_CLASSID,1); 3735c6c1daeSBarry Smith PetscValidType(v,1); 3745c6c1daeSBarry Smith if (!viewer) { 3755f80ce2aSJacob Faibussowitsch CHKERRQ(PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)v),&viewer)); 3765c6c1daeSBarry Smith } 3775c6c1daeSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,2); 3785c6c1daeSBarry Smith PetscCheckSameComm(v,1,viewer,2); 3795c6c1daeSBarry Smith 3805f80ce2aSJacob Faibussowitsch CHKERRQ(PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii)); 381e04113cfSBarry Smith #if defined(PETSC_HAVE_SAWS) 3825f80ce2aSJacob Faibussowitsch CHKERRQ(PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERSAWS,&issaws)); 3830076e027SBarry Smith #endif 3845c6c1daeSBarry Smith if (iascii) { 3855f80ce2aSJacob Faibussowitsch CHKERRQ(PetscViewerGetFormat(viewer,&format)); 3865f80ce2aSJacob Faibussowitsch CHKERRQ(PetscObjectPrintClassNamePrefixType((PetscObject)v,viewer)); 38798c3331eSBarry Smith if (format == PETSC_VIEWER_DEFAULT || format == PETSC_VIEWER_ASCII_INFO || format == PETSC_VIEWER_ASCII_INFO_DETAIL) { 3882f234a98SBarry Smith if (v->format) { 3895f80ce2aSJacob Faibussowitsch CHKERRQ(PetscViewerASCIIPrintf(viewer," Viewer format = %s\n",PetscViewerFormats[v->format])); 3902f234a98SBarry Smith } 3915f80ce2aSJacob Faibussowitsch CHKERRQ(PetscViewerASCIIPushTab(viewer)); 3922bf49c77SBarry Smith if (v->ops->view) { 3935f80ce2aSJacob Faibussowitsch CHKERRQ((*v->ops->view)(v,viewer)); 3945c6c1daeSBarry Smith } 3955f80ce2aSJacob Faibussowitsch CHKERRQ(PetscViewerASCIIPopTab(viewer)); 3965c6c1daeSBarry Smith } 397e04113cfSBarry Smith #if defined(PETSC_HAVE_SAWS) 398536b137fSBarry Smith } else if (issaws) { 3990076e027SBarry Smith if (!((PetscObject)v)->amsmem) { 4005f80ce2aSJacob Faibussowitsch CHKERRQ(PetscObjectViewSAWs((PetscObject)v,viewer)); 4010076e027SBarry Smith if (v->ops->view) { 4025f80ce2aSJacob Faibussowitsch CHKERRQ((*v->ops->view)(v,viewer)); 4030076e027SBarry Smith } 4040076e027SBarry Smith } 4050076e027SBarry Smith #endif 4065c6c1daeSBarry Smith } 4075c6c1daeSBarry Smith PetscFunctionReturn(0); 4085c6c1daeSBarry Smith } 4091d641e7bSMichael Lange 4101d641e7bSMichael Lange /*@C 4111d641e7bSMichael Lange PetscViewerRead - Reads data from a PetscViewer 4121d641e7bSMichael Lange 413d083f849SBarry Smith Collective 4141d641e7bSMichael Lange 4151d641e7bSMichael Lange Input Parameters: 4161d641e7bSMichael Lange + viewer - The viewer 4171d641e7bSMichael Lange . data - Location to write the data 418060da220SMatthew G. Knepley . num - Number of items of data to read 4191d641e7bSMichael Lange - datatype - Type of data to read 4201d641e7bSMichael Lange 421f8e4bde8SMatthew G. Knepley Output Parameters: 422060da220SMatthew G. Knepley . count - number of items of data actually read, or NULL 423f8e4bde8SMatthew G. Knepley 424632e26b4SStefano Zampini Notes: 425632e26b4SStefano Zampini If datatype is PETSC_STRING and num is negative, reads until a newline character is found, 426632e26b4SStefano Zampini until a maximum of (-num - 1) chars. 427632e26b4SStefano Zampini 4281d641e7bSMichael Lange Level: beginner 4291d641e7bSMichael Lange 4306a9046bcSBarry Smith .seealso: PetscViewerASCIIOpen(), PetscViewerPushFormat(), PetscViewerDestroy(), 4311d641e7bSMichael Lange VecView(), MatView(), VecLoad(), MatLoad(), PetscViewerBinaryGetDescriptor(), 4321d641e7bSMichael Lange PetscViewerBinaryGetInfoPointer(), PetscFileMode, PetscViewer 4331d641e7bSMichael Lange @*/ 434060da220SMatthew G. Knepley PetscErrorCode PetscViewerRead(PetscViewer viewer, void *data, PetscInt num, PetscInt *count, PetscDataType dtype) 4351d641e7bSMichael Lange { 4361d641e7bSMichael Lange PetscFunctionBegin; 4371d641e7bSMichael Lange PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 4381d641e7bSMichael Lange if (dtype == PETSC_STRING) { 439060da220SMatthew G. Knepley PetscInt c, i = 0, cnt; 4401d641e7bSMichael Lange char *s = (char *)data; 441632e26b4SStefano Zampini if (num >= 0) { 442060da220SMatthew G. Knepley for (c = 0; c < num; c++) { 4431d641e7bSMichael Lange /* Skip leading whitespaces */ 4445f80ce2aSJacob Faibussowitsch do {CHKERRQ((*viewer->ops->read)(viewer, &(s[i]), 1, &cnt, PETSC_CHAR)); if (!cnt) break;} 445eb2700f0SMichael Lange while (s[i]=='\n' || s[i]=='\t' || s[i]==' ' || s[i]=='\0' || s[i]=='\v' || s[i]=='\f' || s[i]=='\r'); 4461d641e7bSMichael Lange i++; 4471d641e7bSMichael Lange /* Read strings one char at a time */ 4485f80ce2aSJacob Faibussowitsch do {CHKERRQ((*viewer->ops->read)(viewer, &(s[i++]), 1, &cnt, PETSC_CHAR)); if (!cnt) break;} 449eb2700f0SMichael 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'); 4501d641e7bSMichael Lange /* Terminate final string */ 451060da220SMatthew G. Knepley if (c == num-1) s[i-1] = '\0'; 4521d641e7bSMichael Lange } 453632e26b4SStefano Zampini } else { 454632e26b4SStefano Zampini /* Read until a \n is encountered (-num is the max size allowed) */ 4555f80ce2aSJacob Faibussowitsch do {CHKERRQ((*viewer->ops->read)(viewer, &(s[i++]), 1, &cnt, PETSC_CHAR)); if (i == -num || !cnt) break;} 456632e26b4SStefano Zampini while (s[i-1]!='\n'); 457632e26b4SStefano Zampini /* Terminate final string */ 458632e26b4SStefano Zampini s[i-1] = '\0'; 459632e26b4SStefano Zampini c = i; 460632e26b4SStefano Zampini } 461060da220SMatthew G. Knepley if (count) *count = c; 4622c71b3e2SJacob Faibussowitsch else PetscCheckFalse(c < num,PetscObjectComm((PetscObject) viewer), PETSC_ERR_FILE_READ, "Insufficient data, only read %" PetscInt_FMT " < %" PetscInt_FMT " strings", c, num); 4631d641e7bSMichael Lange } else { 4645f80ce2aSJacob Faibussowitsch CHKERRQ((*viewer->ops->read)(viewer, data, num, count, dtype)); 4651d641e7bSMichael Lange } 4661d641e7bSMichael Lange PetscFunctionReturn(0); 4671d641e7bSMichael Lange } 468e24fdd67SVaclav Hapla 469af684e28SVaclav Hapla /*@ 470af684e28SVaclav Hapla PetscViewerReadable - Return a flag whether the viewer can be read from 471af684e28SVaclav Hapla 472af684e28SVaclav Hapla Not Collective 473af684e28SVaclav Hapla 474af684e28SVaclav Hapla Input Parameters: 475af684e28SVaclav Hapla . viewer - the PetscViewer context 476af684e28SVaclav Hapla 477af684e28SVaclav Hapla Output Parameters: 478af684e28SVaclav Hapla . flg - PETSC_TRUE if the viewer is readable, PETSC_FALSE otherwise 479af684e28SVaclav Hapla 480af684e28SVaclav Hapla Notes: 481af684e28SVaclav Hapla PETSC_TRUE means that viewer's PetscViewerType supports reading (this holds e.g. for PETSCVIEWERBINARY) 482af684e28SVaclav Hapla and viewer is in a mode allowing reading, i.e. PetscViewerFileGetMode() 483af684e28SVaclav Hapla returns one of FILE_MODE_READ, FILE_MODE_UPDATE, FILE_MODE_APPEND_UPDATE. 484af684e28SVaclav Hapla 485af684e28SVaclav Hapla Level: intermediate 486af684e28SVaclav Hapla 487af684e28SVaclav Hapla .seealso: PetscViewerWritable(), PetscViewerCheckReadable(), PetscViewerCreate(), PetscViewerFileSetMode(), PetscViewerFileSetType() 488af684e28SVaclav Hapla @*/ 489e24fdd67SVaclav Hapla PetscErrorCode PetscViewerReadable(PetscViewer viewer, PetscBool *flg) 490e24fdd67SVaclav Hapla { 491e24fdd67SVaclav Hapla PetscFileMode mode; 492e24fdd67SVaclav Hapla PetscErrorCode (*f)(PetscViewer,PetscFileMode*) = NULL; 493e24fdd67SVaclav Hapla 494e24fdd67SVaclav Hapla PetscFunctionBegin; 495e24fdd67SVaclav Hapla PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 496534a8f05SLisandro Dalcin PetscValidBoolPointer(flg,2); 4975f80ce2aSJacob Faibussowitsch CHKERRQ(PetscObjectQueryFunction((PetscObject)viewer, "PetscViewerFileGetMode_C", &f)); 498e24fdd67SVaclav Hapla *flg = PETSC_FALSE; 499e24fdd67SVaclav Hapla if (!f) PetscFunctionReturn(0); 5005f80ce2aSJacob Faibussowitsch CHKERRQ((*f)(viewer, &mode)); 501e24fdd67SVaclav Hapla switch (mode) { 502e24fdd67SVaclav Hapla case FILE_MODE_READ: 503e24fdd67SVaclav Hapla case FILE_MODE_UPDATE: 504e24fdd67SVaclav Hapla case FILE_MODE_APPEND_UPDATE: 505e24fdd67SVaclav Hapla *flg = PETSC_TRUE; 506e24fdd67SVaclav Hapla default: break; 507e24fdd67SVaclav Hapla } 508e24fdd67SVaclav Hapla PetscFunctionReturn(0); 509e24fdd67SVaclav Hapla } 510e24fdd67SVaclav Hapla 511af684e28SVaclav Hapla /*@ 512af684e28SVaclav Hapla PetscViewerWritable - Return a flag whether the viewer can be written to 513af684e28SVaclav Hapla 514af684e28SVaclav Hapla Not Collective 515af684e28SVaclav Hapla 516af684e28SVaclav Hapla Input Parameters: 517af684e28SVaclav Hapla . viewer - the PetscViewer context 518af684e28SVaclav Hapla 519af684e28SVaclav Hapla Output Parameters: 520af684e28SVaclav Hapla . flg - PETSC_TRUE if the viewer is writable, PETSC_FALSE otherwise 521af684e28SVaclav Hapla 522af684e28SVaclav Hapla Notes: 523af684e28SVaclav Hapla PETSC_TRUE means viewer is in a mode allowing writing, i.e. PetscViewerFileGetMode() 524af684e28SVaclav Hapla returns one of FILE_MODE_WRITE, FILE_MODE_APPEND, FILE_MODE_UPDATE, FILE_MODE_APPEND_UPDATE. 525af684e28SVaclav Hapla 526af684e28SVaclav Hapla Level: intermediate 527af684e28SVaclav Hapla 528af684e28SVaclav Hapla .seealso: PetscViewerReadable(), PetscViewerCheckWritable(), PetscViewerCreate(), PetscViewerFileSetMode(), PetscViewerFileSetType() 529af684e28SVaclav Hapla @*/ 530e24fdd67SVaclav Hapla PetscErrorCode PetscViewerWritable(PetscViewer viewer, PetscBool *flg) 531e24fdd67SVaclav Hapla { 532e24fdd67SVaclav Hapla PetscFileMode mode; 533e24fdd67SVaclav Hapla PetscErrorCode (*f)(PetscViewer,PetscFileMode*) = NULL; 534e24fdd67SVaclav Hapla 535e24fdd67SVaclav Hapla PetscFunctionBegin; 536e24fdd67SVaclav Hapla PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 537534a8f05SLisandro Dalcin PetscValidBoolPointer(flg,2); 5385f80ce2aSJacob Faibussowitsch CHKERRQ(PetscObjectQueryFunction((PetscObject)viewer, "PetscViewerFileGetMode_C", &f)); 539e24fdd67SVaclav Hapla *flg = PETSC_TRUE; 540e24fdd67SVaclav Hapla if (!f) PetscFunctionReturn(0); 5415f80ce2aSJacob Faibussowitsch CHKERRQ((*f)(viewer, &mode)); 542e24fdd67SVaclav Hapla if (mode == FILE_MODE_READ) *flg = PETSC_FALSE; 543e24fdd67SVaclav Hapla PetscFunctionReturn(0); 544e24fdd67SVaclav Hapla } 545e24fdd67SVaclav Hapla 546af684e28SVaclav Hapla /*@ 547af684e28SVaclav Hapla PetscViewerCheckReadable - Check whether the viewer can be read from 548af684e28SVaclav Hapla 549af684e28SVaclav Hapla Collective 550af684e28SVaclav Hapla 551af684e28SVaclav Hapla Input Parameters: 552af684e28SVaclav Hapla . viewer - the PetscViewer context 553af684e28SVaclav Hapla 554af684e28SVaclav Hapla Level: intermediate 555af684e28SVaclav Hapla 556af684e28SVaclav Hapla .seealso: PetscViewerReadable(), PetscViewerCheckWritable(), PetscViewerCreate(), PetscViewerFileSetMode(), PetscViewerFileSetType() 557af684e28SVaclav Hapla @*/ 558d01f05b1SVaclav Hapla PetscErrorCode PetscViewerCheckReadable(PetscViewer viewer) 559d01f05b1SVaclav Hapla { 560d01f05b1SVaclav Hapla PetscBool flg; 561d01f05b1SVaclav Hapla 562d01f05b1SVaclav Hapla PetscFunctionBegin; 5630af448b7SVaclav Hapla PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 5645f80ce2aSJacob Faibussowitsch CHKERRQ(PetscViewerReadable(viewer, &flg)); 565*28b400f6SJacob Faibussowitsch PetscCheck(flg,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)"); 566d01f05b1SVaclav Hapla PetscFunctionReturn(0); 567d01f05b1SVaclav Hapla } 568d01f05b1SVaclav Hapla 569af684e28SVaclav Hapla /*@ 570af684e28SVaclav Hapla PetscViewerCheckWritable - Check whether the viewer can be written to 571af684e28SVaclav Hapla 572af684e28SVaclav Hapla Collective 573af684e28SVaclav Hapla 574af684e28SVaclav Hapla Input Parameters: 575af684e28SVaclav Hapla . viewer - the PetscViewer context 576af684e28SVaclav Hapla 577af684e28SVaclav Hapla Level: intermediate 578af684e28SVaclav Hapla 579af684e28SVaclav Hapla .seealso: PetscViewerWritable(), PetscViewerCheckReadable(), PetscViewerCreate(), PetscViewerFileSetMode(), PetscViewerFileSetType() 580af684e28SVaclav Hapla @*/ 581d01f05b1SVaclav Hapla PetscErrorCode PetscViewerCheckWritable(PetscViewer viewer) 582d01f05b1SVaclav Hapla { 583d01f05b1SVaclav Hapla PetscBool flg; 584d01f05b1SVaclav Hapla 585d01f05b1SVaclav Hapla PetscFunctionBegin; 5860af448b7SVaclav Hapla PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 5875f80ce2aSJacob Faibussowitsch CHKERRQ(PetscViewerWritable(viewer, &flg)); 588*28b400f6SJacob Faibussowitsch PetscCheck(flg,PetscObjectComm((PetscObject)viewer), PETSC_ERR_SUP, "Viewer doesn't support writing, or is in FILE_MODE_READ mode"); 589d01f05b1SVaclav Hapla PetscFunctionReturn(0); 590d01f05b1SVaclav Hapla } 591