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); 71*e94e781bSJacob Faibussowitsch /* Process Info */ 72*e94e781bSJacob Faibussowitsch { 73*e94e781bSJacob Faibussowitsch PetscClassId classids[1]; 74*e94e781bSJacob Faibussowitsch 75*e94e781bSJacob Faibussowitsch classids[0] = PETSC_VIEWER_CLASSID; 76*e94e781bSJacob Faibussowitsch ierr = PetscInfoProcessClass("viewer", 1, classids);CHKERRQ(ierr); 775c6c1daeSBarry Smith } 785c6c1daeSBarry Smith /* Process summary exclusions */ 798e81d068SLisandro Dalcin ierr = PetscOptionsGetString(NULL,NULL,"-log_exclude",logList,sizeof(logList),&opt);CHKERRQ(ierr); 805c6c1daeSBarry Smith if (opt) { 818e81d068SLisandro Dalcin ierr = PetscStrInList("viewer",logList,',',&pkg);CHKERRQ(ierr); 82fa2bb9feSLisandro Dalcin if (pkg) {ierr = PetscLogEventExcludeClass(PETSC_VIEWER_CLASSID);CHKERRQ(ierr);} 835c6c1daeSBarry Smith } 845c6c1daeSBarry Smith #if defined(PETSC_HAVE_MATHEMATICA) 85607a6623SBarry Smith ierr = PetscViewerMathematicaInitializePackage();CHKERRQ(ierr); 865c6c1daeSBarry Smith #endif 878e81d068SLisandro Dalcin /* Register package finalizer */ 885c6c1daeSBarry Smith ierr = PetscRegisterFinalize(PetscViewerFinalizePackage);CHKERRQ(ierr); 895c6c1daeSBarry Smith PetscFunctionReturn(0); 905c6c1daeSBarry Smith } 915c6c1daeSBarry Smith 925c6c1daeSBarry Smith /*@ 935c6c1daeSBarry Smith PetscViewerDestroy - Destroys a PetscViewer. 945c6c1daeSBarry Smith 955c6c1daeSBarry Smith Collective on PetscViewer 965c6c1daeSBarry Smith 975c6c1daeSBarry Smith Input Parameters: 985c6c1daeSBarry Smith . viewer - the PetscViewer to be destroyed. 995c6c1daeSBarry Smith 1005c6c1daeSBarry Smith Level: beginner 1015c6c1daeSBarry Smith 1025c6c1daeSBarry Smith .seealso: PetscViewerSocketOpen(), PetscViewerASCIIOpen(), PetscViewerCreate(), PetscViewerDrawOpen() 1035c6c1daeSBarry Smith 1045c6c1daeSBarry Smith @*/ 1055c6c1daeSBarry Smith PetscErrorCode PetscViewerDestroy(PetscViewer *viewer) 1065c6c1daeSBarry Smith { 1075c6c1daeSBarry Smith PetscErrorCode ierr; 1085c6c1daeSBarry Smith 1095c6c1daeSBarry Smith PetscFunctionBegin; 1105c6c1daeSBarry Smith if (!*viewer) PetscFunctionReturn(0); 1115c6c1daeSBarry Smith PetscValidHeaderSpecific(*viewer,PETSC_VIEWER_CLASSID,1); 1125c6c1daeSBarry Smith 1135c6c1daeSBarry Smith ierr = PetscViewerFlush(*viewer);CHKERRQ(ierr); 11402c9f0b5SLisandro Dalcin if (--((PetscObject)(*viewer))->refct > 0) {*viewer = NULL; PetscFunctionReturn(0);} 1155c6c1daeSBarry Smith 116e04113cfSBarry Smith ierr = PetscObjectSAWsViewOff((PetscObject)*viewer);CHKERRQ(ierr); 1175c6c1daeSBarry Smith if ((*viewer)->ops->destroy) { 1185c6c1daeSBarry Smith ierr = (*(*viewer)->ops->destroy)(*viewer);CHKERRQ(ierr); 1195c6c1daeSBarry Smith } 1205c6c1daeSBarry Smith ierr = PetscHeaderDestroy(viewer);CHKERRQ(ierr); 1215c6c1daeSBarry Smith PetscFunctionReturn(0); 1225c6c1daeSBarry Smith } 1235c6c1daeSBarry Smith 124d7cbc13eSBarry Smith /*@C 125d7cbc13eSBarry Smith PetscViewerAndFormatCreate - Creates a PetscViewerAndFormat struct. 126d7cbc13eSBarry Smith 127d7cbc13eSBarry Smith Collective on PetscViewer 128d7cbc13eSBarry Smith 129d7cbc13eSBarry Smith Input Parameters: 130d7cbc13eSBarry Smith + viewer - the viewer 131d7cbc13eSBarry Smith - format - the format 132d7cbc13eSBarry Smith 133d7cbc13eSBarry Smith Output Parameter: 134d7cbc13eSBarry Smith . vf - viewer and format object 135d7cbc13eSBarry Smith 13695452b02SPatrick Sanan Notes: 13795452b02SPatrick Sanan 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: 193a2b725a8SWilliam Gropp + PETSCVIEWERSOCKET - Socket PetscViewer 1945c6c1daeSBarry Smith . PETSCVIEWERASCII - ASCII PetscViewer 1955c6c1daeSBarry Smith . PETSCVIEWERBINARY - binary file PetscViewer 1965c6c1daeSBarry Smith . PETSCVIEWERSTRING - string PetscViewer 197a2b725a8SWilliam Gropp - 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 .seealso: PetscViewerSetFromOptions() 2355c6c1daeSBarry Smith @*/ 2365c6c1daeSBarry Smith PetscErrorCode PetscViewerSetOptionsPrefix(PetscViewer viewer,const char prefix[]) 2375c6c1daeSBarry Smith { 2385c6c1daeSBarry Smith PetscErrorCode ierr; 2395c6c1daeSBarry Smith 2405c6c1daeSBarry Smith PetscFunctionBegin; 2415c6c1daeSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 2425c6c1daeSBarry Smith ierr = PetscObjectSetOptionsPrefix((PetscObject)viewer,prefix);CHKERRQ(ierr); 2435c6c1daeSBarry Smith PetscFunctionReturn(0); 2445c6c1daeSBarry Smith } 2455c6c1daeSBarry Smith 2465c6c1daeSBarry Smith /*@C 2475c6c1daeSBarry Smith PetscViewerAppendOptionsPrefix - Appends to the prefix used for searching for all 2485c6c1daeSBarry Smith PetscViewer options in the database. 2495c6c1daeSBarry Smith 2505c6c1daeSBarry Smith Logically Collective on PetscViewer 2515c6c1daeSBarry Smith 2525c6c1daeSBarry Smith Input Parameters: 2535c6c1daeSBarry Smith + viewer - the PetscViewer context 2545c6c1daeSBarry Smith - prefix - the prefix to prepend to all option names 2555c6c1daeSBarry Smith 2565c6c1daeSBarry Smith Notes: 2575c6c1daeSBarry Smith A hyphen (-) must NOT be given at the beginning of the prefix name. 2585c6c1daeSBarry Smith The first character of all runtime options is AUTOMATICALLY the hyphen. 2595c6c1daeSBarry Smith 2605c6c1daeSBarry Smith Level: advanced 2615c6c1daeSBarry Smith 2625c6c1daeSBarry Smith .seealso: PetscViewerGetOptionsPrefix() 2635c6c1daeSBarry Smith @*/ 2645c6c1daeSBarry Smith PetscErrorCode PetscViewerAppendOptionsPrefix(PetscViewer viewer,const char prefix[]) 2655c6c1daeSBarry Smith { 2665c6c1daeSBarry Smith PetscErrorCode ierr; 2675c6c1daeSBarry Smith 2685c6c1daeSBarry Smith PetscFunctionBegin; 2695c6c1daeSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 2705c6c1daeSBarry Smith ierr = PetscObjectAppendOptionsPrefix((PetscObject)viewer,prefix);CHKERRQ(ierr); 2715c6c1daeSBarry Smith PetscFunctionReturn(0); 2725c6c1daeSBarry Smith } 2735c6c1daeSBarry Smith 2745c6c1daeSBarry Smith /*@C 2755c6c1daeSBarry Smith PetscViewerGetOptionsPrefix - Sets the prefix used for searching for all 2765c6c1daeSBarry Smith PetscViewer options in the database. 2775c6c1daeSBarry Smith 2785c6c1daeSBarry Smith Not Collective 2795c6c1daeSBarry Smith 2805c6c1daeSBarry Smith Input Parameter: 2815c6c1daeSBarry Smith . viewer - the PetscViewer context 2825c6c1daeSBarry Smith 2835c6c1daeSBarry Smith Output Parameter: 2845c6c1daeSBarry Smith . prefix - pointer to the prefix string used 2855c6c1daeSBarry Smith 28695452b02SPatrick Sanan Notes: 28795452b02SPatrick Sanan On the fortran side, the user should pass in a string 'prefix' of 2885c6c1daeSBarry Smith sufficient length to hold the prefix. 2895c6c1daeSBarry Smith 2905c6c1daeSBarry Smith Level: advanced 2915c6c1daeSBarry Smith 2925c6c1daeSBarry Smith .seealso: PetscViewerAppendOptionsPrefix() 2935c6c1daeSBarry Smith @*/ 2945c6c1daeSBarry Smith PetscErrorCode PetscViewerGetOptionsPrefix(PetscViewer viewer,const char *prefix[]) 2955c6c1daeSBarry Smith { 2965c6c1daeSBarry Smith PetscErrorCode ierr; 2975c6c1daeSBarry Smith 2985c6c1daeSBarry Smith PetscFunctionBegin; 2995c6c1daeSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 3005c6c1daeSBarry Smith ierr = PetscObjectGetOptionsPrefix((PetscObject)viewer,prefix);CHKERRQ(ierr); 3015c6c1daeSBarry Smith PetscFunctionReturn(0); 3025c6c1daeSBarry Smith } 3035c6c1daeSBarry Smith 3045c6c1daeSBarry Smith /*@ 3055c6c1daeSBarry Smith PetscViewerSetUp - Sets up the internal viewer data structures for the later use. 3065c6c1daeSBarry Smith 3075c6c1daeSBarry Smith Collective on PetscViewer 3085c6c1daeSBarry Smith 3095c6c1daeSBarry Smith Input Parameters: 3105c6c1daeSBarry Smith . viewer - the PetscViewer context 3115c6c1daeSBarry Smith 3125c6c1daeSBarry Smith Notes: 3135c6c1daeSBarry Smith For basic use of the PetscViewer classes the user need not explicitly call 3145c6c1daeSBarry Smith PetscViewerSetUp(), since these actions will happen automatically. 3155c6c1daeSBarry Smith 3165c6c1daeSBarry Smith Level: advanced 3175c6c1daeSBarry Smith 3185c6c1daeSBarry Smith .seealso: PetscViewerCreate(), PetscViewerDestroy() 3195c6c1daeSBarry Smith @*/ 3205c6c1daeSBarry Smith PetscErrorCode PetscViewerSetUp(PetscViewer viewer) 3215c6c1daeSBarry Smith { 322c98fd787SBarry Smith PetscErrorCode ierr; 323c98fd787SBarry Smith 3245c6c1daeSBarry Smith PetscFunctionBegin; 3255c6c1daeSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 326c98fd787SBarry Smith if (viewer->setupcalled) PetscFunctionReturn(0); 327c98fd787SBarry Smith if (viewer->ops->setup) { 328c98fd787SBarry Smith ierr = (*viewer->ops->setup)(viewer);CHKERRQ(ierr); 329c98fd787SBarry Smith } 330c98fd787SBarry Smith viewer->setupcalled = PETSC_TRUE; 3315c6c1daeSBarry Smith PetscFunctionReturn(0); 3325c6c1daeSBarry Smith } 3335c6c1daeSBarry Smith 3345c6c1daeSBarry Smith /*@C 335fe2efc57SMark PetscViewerViewFromOptions - View from Options 336fe2efc57SMark 337fe2efc57SMark Collective on PetscViewer 338fe2efc57SMark 339fe2efc57SMark Input Parameters: 340fe2efc57SMark + A - the PetscViewer context 341736c3998SJose E. Roman . obj - Optional object 342736c3998SJose E. Roman - name - command line option 343fe2efc57SMark 344fe2efc57SMark Level: intermediate 345fe2efc57SMark .seealso: PetscViewer, PetscViewerView, PetscObjectViewFromOptions(), PetscViewerCreate() 346fe2efc57SMark @*/ 347fe2efc57SMark PetscErrorCode PetscViewerViewFromOptions(PetscViewer A,PetscObject obj,const char name[]) 348fe2efc57SMark { 349fe2efc57SMark PetscErrorCode ierr; 350fe2efc57SMark 351fe2efc57SMark PetscFunctionBegin; 352fe2efc57SMark PetscValidHeaderSpecific(A,PETSC_VIEWER_CLASSID,1); 353fe2efc57SMark ierr = PetscObjectViewFromOptions((PetscObject)A,obj,name);CHKERRQ(ierr); 354fe2efc57SMark PetscFunctionReturn(0); 355fe2efc57SMark } 356fe2efc57SMark 357fe2efc57SMark /*@C 3585c6c1daeSBarry Smith PetscViewerView - Visualizes a viewer object. 3595c6c1daeSBarry Smith 3605c6c1daeSBarry Smith Collective on PetscViewer 3615c6c1daeSBarry Smith 3625c6c1daeSBarry Smith Input Parameters: 363f0d4698bSVaclav Hapla + v - the viewer to be viewed 3645c6c1daeSBarry Smith - viewer - visualization context 3655c6c1daeSBarry Smith 3665c6c1daeSBarry Smith Notes: 3675c6c1daeSBarry Smith The available visualization contexts include 3685c6c1daeSBarry Smith + PETSC_VIEWER_STDOUT_SELF - standard output (default) 3695c6c1daeSBarry Smith . PETSC_VIEWER_STDOUT_WORLD - synchronized standard 3705c6c1daeSBarry Smith output where only the first processor opens 3715c6c1daeSBarry Smith the file. All other processors send their 3725c6c1daeSBarry Smith data to the first processor to print. 3735c6c1daeSBarry Smith - PETSC_VIEWER_DRAW_WORLD - graphical display of nonzero structure 3745c6c1daeSBarry Smith 3755c6c1daeSBarry Smith Level: beginner 3765c6c1daeSBarry Smith 3776a9046bcSBarry Smith .seealso: PetscViewerPushFormat(), PetscViewerASCIIOpen(), PetscViewerDrawOpen(), 3785c6c1daeSBarry Smith PetscViewerSocketOpen(), PetscViewerBinaryOpen(), PetscViewerLoad() 3795c6c1daeSBarry Smith @*/ 3805c6c1daeSBarry Smith PetscErrorCode PetscViewerView(PetscViewer v,PetscViewer viewer) 3815c6c1daeSBarry Smith { 3825c6c1daeSBarry Smith PetscErrorCode ierr; 3835c6c1daeSBarry Smith PetscBool iascii; 3845c6c1daeSBarry Smith PetscViewerFormat format; 385e04113cfSBarry Smith #if defined(PETSC_HAVE_SAWS) 386536b137fSBarry Smith PetscBool issaws; 3870076e027SBarry Smith #endif 3885c6c1daeSBarry Smith 3895c6c1daeSBarry Smith PetscFunctionBegin; 3905c6c1daeSBarry Smith PetscValidHeaderSpecific(v,PETSC_VIEWER_CLASSID,1); 3915c6c1daeSBarry Smith PetscValidType(v,1); 3925c6c1daeSBarry Smith if (!viewer) { 393ce94432eSBarry Smith ierr = PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)v),&viewer);CHKERRQ(ierr); 3945c6c1daeSBarry Smith } 3955c6c1daeSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,2); 3965c6c1daeSBarry Smith PetscCheckSameComm(v,1,viewer,2); 3975c6c1daeSBarry Smith 3985c6c1daeSBarry Smith ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);CHKERRQ(ierr); 399e04113cfSBarry Smith #if defined(PETSC_HAVE_SAWS) 400536b137fSBarry Smith ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERSAWS,&issaws);CHKERRQ(ierr); 4010076e027SBarry Smith #endif 4025c6c1daeSBarry Smith if (iascii) { 4035c6c1daeSBarry Smith ierr = PetscViewerGetFormat(viewer,&format);CHKERRQ(ierr); 404dae58748SBarry Smith ierr = PetscObjectPrintClassNamePrefixType((PetscObject)v,viewer);CHKERRQ(ierr); 40598c3331eSBarry Smith if (format == PETSC_VIEWER_DEFAULT || format == PETSC_VIEWER_ASCII_INFO || format == PETSC_VIEWER_ASCII_INFO_DETAIL) { 4062f234a98SBarry Smith if (v->format) { 4072f234a98SBarry Smith ierr = PetscViewerASCIIPrintf(viewer," Viewer format = %s\n",PetscViewerFormats[v->format]);CHKERRQ(ierr); 4082f234a98SBarry Smith } 4095c6c1daeSBarry Smith ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); 4102bf49c77SBarry Smith if (v->ops->view) { 4112bf49c77SBarry Smith ierr = (*v->ops->view)(v,viewer);CHKERRQ(ierr); 4125c6c1daeSBarry Smith } 4135c6c1daeSBarry Smith ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); 4145c6c1daeSBarry Smith } 415e04113cfSBarry Smith #if defined(PETSC_HAVE_SAWS) 416536b137fSBarry Smith } else if (issaws) { 4170076e027SBarry Smith if (!((PetscObject)v)->amsmem) { 418e04113cfSBarry Smith ierr = PetscObjectViewSAWs((PetscObject)v,viewer);CHKERRQ(ierr); 4190076e027SBarry Smith if (v->ops->view) { 4200076e027SBarry Smith ierr = (*v->ops->view)(v,viewer);CHKERRQ(ierr); 4210076e027SBarry Smith } 4220076e027SBarry Smith } 4230076e027SBarry Smith #endif 4245c6c1daeSBarry Smith } 4255c6c1daeSBarry Smith PetscFunctionReturn(0); 4265c6c1daeSBarry Smith } 4271d641e7bSMichael Lange 4281d641e7bSMichael Lange /*@C 4291d641e7bSMichael Lange PetscViewerRead - Reads data from a PetscViewer 4301d641e7bSMichael Lange 431d083f849SBarry Smith Collective 4321d641e7bSMichael Lange 4331d641e7bSMichael Lange Input Parameters: 4341d641e7bSMichael Lange + viewer - The viewer 4351d641e7bSMichael Lange . data - Location to write the data 436060da220SMatthew G. Knepley . num - Number of items of data to read 4371d641e7bSMichael Lange - datatype - Type of data to read 4381d641e7bSMichael Lange 439f8e4bde8SMatthew G. Knepley Output Parameters: 440060da220SMatthew G. Knepley . count - number of items of data actually read, or NULL 441f8e4bde8SMatthew G. Knepley 442632e26b4SStefano Zampini Notes: 443632e26b4SStefano Zampini If datatype is PETSC_STRING and num is negative, reads until a newline character is found, 444632e26b4SStefano Zampini until a maximum of (-num - 1) chars. 445632e26b4SStefano Zampini 4461d641e7bSMichael Lange Level: beginner 4471d641e7bSMichael Lange 4486a9046bcSBarry Smith .seealso: PetscViewerASCIIOpen(), PetscViewerPushFormat(), PetscViewerDestroy(), 4491d641e7bSMichael Lange VecView(), MatView(), VecLoad(), MatLoad(), PetscViewerBinaryGetDescriptor(), 4501d641e7bSMichael Lange PetscViewerBinaryGetInfoPointer(), PetscFileMode, PetscViewer 4511d641e7bSMichael Lange @*/ 452060da220SMatthew G. Knepley PetscErrorCode PetscViewerRead(PetscViewer viewer, void *data, PetscInt num, PetscInt *count, PetscDataType dtype) 4531d641e7bSMichael Lange { 4541d641e7bSMichael Lange PetscErrorCode ierr; 4551d641e7bSMichael Lange 4561d641e7bSMichael Lange PetscFunctionBegin; 4571d641e7bSMichael Lange PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 4581d641e7bSMichael Lange if (dtype == PETSC_STRING) { 459060da220SMatthew G. Knepley PetscInt c, i = 0, cnt; 4601d641e7bSMichael Lange char *s = (char *)data; 461632e26b4SStefano Zampini if (num >= 0) { 462060da220SMatthew G. Knepley for (c = 0; c < num; c++) { 4631d641e7bSMichael Lange /* Skip leading whitespaces */ 4649860990eSLisandro Dalcin do {ierr = (*viewer->ops->read)(viewer, &(s[i]), 1, &cnt, PETSC_CHAR);CHKERRQ(ierr); if (!cnt) break;} 465eb2700f0SMichael Lange while (s[i]=='\n' || s[i]=='\t' || s[i]==' ' || s[i]=='\0' || s[i]=='\v' || s[i]=='\f' || s[i]=='\r'); 4661d641e7bSMichael Lange i++; 4671d641e7bSMichael Lange /* Read strings one char at a time */ 4689860990eSLisandro Dalcin do {ierr = (*viewer->ops->read)(viewer, &(s[i++]), 1, &cnt, PETSC_CHAR);CHKERRQ(ierr); if (!cnt) break;} 469eb2700f0SMichael 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'); 4701d641e7bSMichael Lange /* Terminate final string */ 471060da220SMatthew G. Knepley if (c == num-1) s[i-1] = '\0'; 4721d641e7bSMichael Lange } 473632e26b4SStefano Zampini } else { 474632e26b4SStefano Zampini /* Read until a \n is encountered (-num is the max size allowed) */ 4759860990eSLisandro Dalcin do {ierr = (*viewer->ops->read)(viewer, &(s[i++]), 1, &cnt, PETSC_CHAR);CHKERRQ(ierr); if (i == -num || !cnt) break;} 476632e26b4SStefano Zampini while (s[i-1]!='\n'); 477632e26b4SStefano Zampini /* Terminate final string */ 478632e26b4SStefano Zampini s[i-1] = '\0'; 479632e26b4SStefano Zampini c = i; 480632e26b4SStefano Zampini } 481060da220SMatthew G. Knepley if (count) *count = c; 482060da220SMatthew G. Knepley else if (c < num) SETERRQ2(PetscObjectComm((PetscObject) viewer), PETSC_ERR_FILE_READ, "Insufficient data, only read %D < %D strings", c, num); 4831d641e7bSMichael Lange } else { 484060da220SMatthew G. Knepley ierr = (*viewer->ops->read)(viewer, data, num, count, dtype);CHKERRQ(ierr); 4851d641e7bSMichael Lange } 4861d641e7bSMichael Lange PetscFunctionReturn(0); 4871d641e7bSMichael Lange } 488e24fdd67SVaclav Hapla 489af684e28SVaclav Hapla /*@ 490af684e28SVaclav Hapla PetscViewerReadable - Return a flag whether the viewer can be read from 491af684e28SVaclav Hapla 492af684e28SVaclav Hapla Not Collective 493af684e28SVaclav Hapla 494af684e28SVaclav Hapla Input Parameters: 495af684e28SVaclav Hapla . viewer - the PetscViewer context 496af684e28SVaclav Hapla 497af684e28SVaclav Hapla Output Parameters: 498af684e28SVaclav Hapla . flg - PETSC_TRUE if the viewer is readable, PETSC_FALSE otherwise 499af684e28SVaclav Hapla 500af684e28SVaclav Hapla Notes: 501af684e28SVaclav Hapla PETSC_TRUE means that viewer's PetscViewerType supports reading (this holds e.g. for PETSCVIEWERBINARY) 502af684e28SVaclav Hapla and viewer is in a mode allowing reading, i.e. PetscViewerFileGetMode() 503af684e28SVaclav Hapla returns one of FILE_MODE_READ, FILE_MODE_UPDATE, FILE_MODE_APPEND_UPDATE. 504af684e28SVaclav Hapla 505af684e28SVaclav Hapla Level: intermediate 506af684e28SVaclav Hapla 507af684e28SVaclav Hapla .seealso: PetscViewerWritable(), PetscViewerCheckReadable(), PetscViewerCreate(), PetscViewerFileSetMode(), PetscViewerFileSetType() 508af684e28SVaclav Hapla @*/ 509e24fdd67SVaclav Hapla PetscErrorCode PetscViewerReadable(PetscViewer viewer, PetscBool *flg) 510e24fdd67SVaclav Hapla { 511e24fdd67SVaclav Hapla PetscErrorCode ierr; 512e24fdd67SVaclav Hapla PetscFileMode mode; 513e24fdd67SVaclav Hapla PetscErrorCode (*f)(PetscViewer,PetscFileMode*) = NULL; 514e24fdd67SVaclav Hapla 515e24fdd67SVaclav Hapla PetscFunctionBegin; 516e24fdd67SVaclav Hapla PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 517534a8f05SLisandro Dalcin PetscValidBoolPointer(flg,2); 518e24fdd67SVaclav Hapla ierr = PetscObjectQueryFunction((PetscObject)viewer, "PetscViewerFileGetMode_C", &f);CHKERRQ(ierr); 519e24fdd67SVaclav Hapla *flg = PETSC_FALSE; 520e24fdd67SVaclav Hapla if (!f) PetscFunctionReturn(0); 521e24fdd67SVaclav Hapla ierr = (*f)(viewer, &mode);CHKERRQ(ierr); 522e24fdd67SVaclav Hapla switch (mode) { 523e24fdd67SVaclav Hapla case FILE_MODE_READ: 524e24fdd67SVaclav Hapla case FILE_MODE_UPDATE: 525e24fdd67SVaclav Hapla case FILE_MODE_APPEND_UPDATE: 526e24fdd67SVaclav Hapla *flg = PETSC_TRUE; 527e24fdd67SVaclav Hapla default: break; 528e24fdd67SVaclav Hapla } 529e24fdd67SVaclav Hapla PetscFunctionReturn(0); 530e24fdd67SVaclav Hapla } 531e24fdd67SVaclav Hapla 532af684e28SVaclav Hapla /*@ 533af684e28SVaclav Hapla PetscViewerWritable - Return a flag whether the viewer can be written to 534af684e28SVaclav Hapla 535af684e28SVaclav Hapla Not Collective 536af684e28SVaclav Hapla 537af684e28SVaclav Hapla Input Parameters: 538af684e28SVaclav Hapla . viewer - the PetscViewer context 539af684e28SVaclav Hapla 540af684e28SVaclav Hapla Output Parameters: 541af684e28SVaclav Hapla . flg - PETSC_TRUE if the viewer is writable, PETSC_FALSE otherwise 542af684e28SVaclav Hapla 543af684e28SVaclav Hapla Notes: 544af684e28SVaclav Hapla PETSC_TRUE means viewer is in a mode allowing writing, i.e. PetscViewerFileGetMode() 545af684e28SVaclav Hapla returns one of FILE_MODE_WRITE, FILE_MODE_APPEND, FILE_MODE_UPDATE, FILE_MODE_APPEND_UPDATE. 546af684e28SVaclav Hapla 547af684e28SVaclav Hapla Level: intermediate 548af684e28SVaclav Hapla 549af684e28SVaclav Hapla .seealso: PetscViewerReadable(), PetscViewerCheckWritable(), PetscViewerCreate(), PetscViewerFileSetMode(), PetscViewerFileSetType() 550af684e28SVaclav Hapla @*/ 551e24fdd67SVaclav Hapla PetscErrorCode PetscViewerWritable(PetscViewer viewer, PetscBool *flg) 552e24fdd67SVaclav Hapla { 553e24fdd67SVaclav Hapla PetscErrorCode ierr; 554e24fdd67SVaclav Hapla PetscFileMode mode; 555e24fdd67SVaclav Hapla PetscErrorCode (*f)(PetscViewer,PetscFileMode*) = NULL; 556e24fdd67SVaclav Hapla 557e24fdd67SVaclav Hapla PetscFunctionBegin; 558e24fdd67SVaclav Hapla PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 559534a8f05SLisandro Dalcin PetscValidBoolPointer(flg,2); 560e24fdd67SVaclav Hapla ierr = PetscObjectQueryFunction((PetscObject)viewer, "PetscViewerFileGetMode_C", &f);CHKERRQ(ierr); 561e24fdd67SVaclav Hapla *flg = PETSC_TRUE; 562e24fdd67SVaclav Hapla if (!f) PetscFunctionReturn(0); 563e24fdd67SVaclav Hapla ierr = (*f)(viewer, &mode);CHKERRQ(ierr); 564e24fdd67SVaclav Hapla if (mode == FILE_MODE_READ) *flg = PETSC_FALSE; 565e24fdd67SVaclav Hapla PetscFunctionReturn(0); 566e24fdd67SVaclav Hapla } 567e24fdd67SVaclav Hapla 568af684e28SVaclav Hapla /*@ 569af684e28SVaclav Hapla PetscViewerCheckReadable - Check whether the viewer can be read from 570af684e28SVaclav Hapla 571af684e28SVaclav Hapla Collective 572af684e28SVaclav Hapla 573af684e28SVaclav Hapla Input Parameters: 574af684e28SVaclav Hapla . viewer - the PetscViewer context 575af684e28SVaclav Hapla 576af684e28SVaclav Hapla Level: intermediate 577af684e28SVaclav Hapla 578af684e28SVaclav Hapla .seealso: PetscViewerReadable(), PetscViewerCheckWritable(), PetscViewerCreate(), PetscViewerFileSetMode(), PetscViewerFileSetType() 579af684e28SVaclav Hapla @*/ 580d01f05b1SVaclav Hapla PetscErrorCode PetscViewerCheckReadable(PetscViewer viewer) 581d01f05b1SVaclav Hapla { 582d01f05b1SVaclav Hapla PetscBool flg; 583d01f05b1SVaclav Hapla PetscErrorCode ierr; 584d01f05b1SVaclav Hapla 585d01f05b1SVaclav Hapla PetscFunctionBegin; 5860af448b7SVaclav Hapla PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 587d01f05b1SVaclav Hapla ierr = PetscViewerReadable(viewer, &flg);CHKERRQ(ierr); 588d01f05b1SVaclav 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)"); 589d01f05b1SVaclav Hapla PetscFunctionReturn(0); 590d01f05b1SVaclav Hapla } 591d01f05b1SVaclav Hapla 592af684e28SVaclav Hapla /*@ 593af684e28SVaclav Hapla PetscViewerCheckWritable - Check whether the viewer can be written to 594af684e28SVaclav Hapla 595af684e28SVaclav Hapla Collective 596af684e28SVaclav Hapla 597af684e28SVaclav Hapla Input Parameters: 598af684e28SVaclav Hapla . viewer - the PetscViewer context 599af684e28SVaclav Hapla 600af684e28SVaclav Hapla Level: intermediate 601af684e28SVaclav Hapla 602af684e28SVaclav Hapla .seealso: PetscViewerWritable(), PetscViewerCheckReadable(), PetscViewerCreate(), PetscViewerFileSetMode(), PetscViewerFileSetType() 603af684e28SVaclav Hapla @*/ 604d01f05b1SVaclav Hapla PetscErrorCode PetscViewerCheckWritable(PetscViewer viewer) 605d01f05b1SVaclav Hapla { 606d01f05b1SVaclav Hapla PetscBool flg; 607d01f05b1SVaclav Hapla PetscErrorCode ierr; 608d01f05b1SVaclav Hapla 609d01f05b1SVaclav Hapla PetscFunctionBegin; 6100af448b7SVaclav Hapla PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 611d01f05b1SVaclav Hapla ierr = PetscViewerWritable(viewer, &flg);CHKERRQ(ierr); 612d01f05b1SVaclav Hapla if (!flg) SETERRQ(PetscObjectComm((PetscObject)viewer), PETSC_ERR_SUP, "Viewer doesn't support writing, or is in FILE_MODE_READ mode"); 613d01f05b1SVaclav Hapla PetscFunctionReturn(0); 614d01f05b1SVaclav Hapla } 615