15c6c1daeSBarry Smith 2665c2dedSJed Brown #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 #undef __FUNCT__ 85c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerFinalizePackage" 95c6c1daeSBarry Smith /*@C 105c6c1daeSBarry Smith PetscViewerFinalizePackage - This function destroys everything in the Petsc interface to Mathematica. It is 115c6c1daeSBarry Smith called from PetscFinalize(). 125c6c1daeSBarry Smith 135c6c1daeSBarry Smith Level: developer 145c6c1daeSBarry Smith 155c6c1daeSBarry Smith .keywords: Petsc, destroy, package, mathematica 165c6c1daeSBarry Smith .seealso: PetscFinalize() 175c6c1daeSBarry Smith @*/ 185c6c1daeSBarry Smith PetscErrorCode PetscViewerFinalizePackage(void) 195c6c1daeSBarry Smith { 2037e93019SBarry Smith PetscErrorCode ierr; 2137e93019SBarry Smith 225c6c1daeSBarry Smith PetscFunctionBegin; 2337e93019SBarry Smith ierr = PetscFunctionListDestroy(&PetscViewerList);CHKERRQ(ierr); 245c6c1daeSBarry Smith PetscViewerPackageInitialized = PETSC_FALSE; 255c6c1daeSBarry Smith PetscFunctionReturn(0); 265c6c1daeSBarry Smith } 275c6c1daeSBarry Smith 285c6c1daeSBarry Smith #undef __FUNCT__ 295c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerInitializePackage" 305c6c1daeSBarry Smith /*@C 315c6c1daeSBarry Smith PetscViewerInitializePackage - This function initializes everything in the main PetscViewer package. 325c6c1daeSBarry Smith 335c6c1daeSBarry Smith Level: developer 345c6c1daeSBarry Smith 355c6c1daeSBarry Smith .keywords: Petsc, initialize, package 365c6c1daeSBarry Smith .seealso: PetscInitialize() 375c6c1daeSBarry Smith @*/ 38607a6623SBarry Smith PetscErrorCode PetscViewerInitializePackage(void) 395c6c1daeSBarry Smith { 405c6c1daeSBarry Smith char logList[256]; 415c6c1daeSBarry Smith char *className; 425c6c1daeSBarry Smith PetscBool opt; 435c6c1daeSBarry Smith PetscErrorCode ierr; 445c6c1daeSBarry Smith 455c6c1daeSBarry Smith PetscFunctionBegin; 465c6c1daeSBarry Smith if (PetscViewerPackageInitialized) PetscFunctionReturn(0); 475c6c1daeSBarry Smith PetscViewerPackageInitialized = PETSC_TRUE; 485c6c1daeSBarry Smith /* Register Classes */ 495c6c1daeSBarry Smith ierr = PetscClassIdRegister("Viewer",&PETSC_VIEWER_CLASSID);CHKERRQ(ierr); 505c6c1daeSBarry Smith 515c6c1daeSBarry Smith /* Register Constructors */ 52607a6623SBarry Smith ierr = PetscViewerRegisterAll();CHKERRQ(ierr); 535c6c1daeSBarry Smith 545c6c1daeSBarry Smith /* Process info exclusions */ 550298fd71SBarry Smith ierr = PetscOptionsGetString(NULL, "-info_exclude", logList, 256, &opt);CHKERRQ(ierr); 565c6c1daeSBarry Smith if (opt) { 575c6c1daeSBarry Smith ierr = PetscStrstr(logList, "viewer", &className);CHKERRQ(ierr); 585c6c1daeSBarry Smith if (className) { 595c6c1daeSBarry Smith ierr = PetscInfoDeactivateClass(0);CHKERRQ(ierr); 605c6c1daeSBarry Smith } 615c6c1daeSBarry Smith } 625c6c1daeSBarry Smith /* Process summary exclusions */ 630298fd71SBarry Smith ierr = PetscOptionsGetString(NULL, "-log_summary_exclude", logList, 256, &opt);CHKERRQ(ierr); 645c6c1daeSBarry Smith if (opt) { 655c6c1daeSBarry Smith ierr = PetscStrstr(logList, "viewer", &className);CHKERRQ(ierr); 665c6c1daeSBarry Smith if (className) { 675c6c1daeSBarry Smith ierr = PetscLogEventDeactivateClass(0);CHKERRQ(ierr); 685c6c1daeSBarry Smith } 695c6c1daeSBarry Smith } 705c6c1daeSBarry Smith #if defined(PETSC_HAVE_MATHEMATICA) 71607a6623SBarry Smith ierr = PetscViewerMathematicaInitializePackage();CHKERRQ(ierr); 725c6c1daeSBarry Smith #endif 735c6c1daeSBarry Smith ierr = PetscRegisterFinalize(PetscViewerFinalizePackage);CHKERRQ(ierr); 745c6c1daeSBarry Smith PetscFunctionReturn(0); 755c6c1daeSBarry Smith } 765c6c1daeSBarry Smith 775c6c1daeSBarry Smith #undef __FUNCT__ 785c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerDestroy" 795c6c1daeSBarry Smith /*@ 805c6c1daeSBarry Smith PetscViewerDestroy - Destroys a PetscViewer. 815c6c1daeSBarry Smith 825c6c1daeSBarry Smith Collective on PetscViewer 835c6c1daeSBarry Smith 845c6c1daeSBarry Smith Input Parameters: 855c6c1daeSBarry Smith . viewer - the PetscViewer to be destroyed. 865c6c1daeSBarry Smith 875c6c1daeSBarry Smith Level: beginner 885c6c1daeSBarry Smith 895c6c1daeSBarry Smith .seealso: PetscViewerSocketOpen(), PetscViewerASCIIOpen(), PetscViewerCreate(), PetscViewerDrawOpen() 905c6c1daeSBarry Smith 915c6c1daeSBarry Smith @*/ 925c6c1daeSBarry Smith PetscErrorCode PetscViewerDestroy(PetscViewer *viewer) 935c6c1daeSBarry Smith { 945c6c1daeSBarry Smith PetscErrorCode ierr; 955c6c1daeSBarry Smith 965c6c1daeSBarry Smith PetscFunctionBegin; 975c6c1daeSBarry Smith if (!*viewer) PetscFunctionReturn(0); 985c6c1daeSBarry Smith PetscValidHeaderSpecific(*viewer,PETSC_VIEWER_CLASSID,1); 995c6c1daeSBarry Smith 1005c6c1daeSBarry Smith ierr = PetscViewerFlush(*viewer);CHKERRQ(ierr); 1015c6c1daeSBarry Smith if (--((PetscObject)(*viewer))->refct > 0) {*viewer = 0; PetscFunctionReturn(0);} 1025c6c1daeSBarry Smith 103f05ece33SBarry Smith ierr = PetscObjectAMSViewOff((PetscObject)*viewer);CHKERRQ(ierr); 1045c6c1daeSBarry Smith if ((*viewer)->ops->destroy) { 1055c6c1daeSBarry Smith ierr = (*(*viewer)->ops->destroy)(*viewer);CHKERRQ(ierr); 1065c6c1daeSBarry Smith } 1075c6c1daeSBarry Smith ierr = PetscHeaderDestroy(viewer);CHKERRQ(ierr); 1085c6c1daeSBarry Smith PetscFunctionReturn(0); 1095c6c1daeSBarry Smith } 1105c6c1daeSBarry Smith 1115c6c1daeSBarry Smith #undef __FUNCT__ 1125c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerGetType" 1135c6c1daeSBarry Smith /*@C 1145c6c1daeSBarry Smith PetscViewerGetType - Returns the type of a PetscViewer. 1155c6c1daeSBarry Smith 1165c6c1daeSBarry Smith Not Collective 1175c6c1daeSBarry Smith 1185c6c1daeSBarry Smith Input Parameter: 1195c6c1daeSBarry Smith . viewer - the PetscViewer 1205c6c1daeSBarry Smith 1215c6c1daeSBarry Smith Output Parameter: 1225c6c1daeSBarry Smith . type - PetscViewer type (see below) 1235c6c1daeSBarry Smith 1245c6c1daeSBarry Smith Available Types Include: 1255c6c1daeSBarry Smith . PETSCVIEWERSOCKET - Socket PetscViewer 1265c6c1daeSBarry Smith . PETSCVIEWERASCII - ASCII PetscViewer 1275c6c1daeSBarry Smith . PETSCVIEWERBINARY - binary file PetscViewer 1285c6c1daeSBarry Smith . PETSCVIEWERSTRING - string PetscViewer 1295c6c1daeSBarry Smith . PETSCVIEWERDRAW - drawing PetscViewer 1305c6c1daeSBarry Smith 1315c6c1daeSBarry Smith Level: intermediate 1325c6c1daeSBarry Smith 1335c6c1daeSBarry Smith Note: 1345c6c1daeSBarry Smith See include/petscviewer.h for a complete list of PetscViewers. 1355c6c1daeSBarry Smith 1365c6c1daeSBarry Smith PetscViewerType is actually a string 1375c6c1daeSBarry Smith 1385c6c1daeSBarry Smith .seealso: PetscViewerCreate(), PetscViewerSetType(), PetscViewerType 1395c6c1daeSBarry Smith 1405c6c1daeSBarry Smith @*/ 1415c6c1daeSBarry Smith PetscErrorCode PetscViewerGetType(PetscViewer viewer,PetscViewerType *type) 1425c6c1daeSBarry Smith { 1435c6c1daeSBarry Smith PetscFunctionBegin; 1445c6c1daeSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 1455c6c1daeSBarry Smith PetscValidPointer(type,2); 1465c6c1daeSBarry Smith *type = ((PetscObject)viewer)->type_name; 1475c6c1daeSBarry Smith PetscFunctionReturn(0); 1485c6c1daeSBarry Smith } 1495c6c1daeSBarry Smith 1505c6c1daeSBarry Smith #undef __FUNCT__ 1515c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerSetOptionsPrefix" 1525c6c1daeSBarry Smith /*@C 1535c6c1daeSBarry Smith PetscViewerSetOptionsPrefix - Sets the prefix used for searching for all 1545c6c1daeSBarry Smith PetscViewer options in the database. 1555c6c1daeSBarry Smith 1565c6c1daeSBarry Smith Logically Collective on PetscViewer 1575c6c1daeSBarry Smith 1585c6c1daeSBarry Smith Input Parameter: 1595c6c1daeSBarry Smith + viewer - the PetscViewer context 1605c6c1daeSBarry Smith - prefix - the prefix to prepend to all option names 1615c6c1daeSBarry Smith 1625c6c1daeSBarry Smith Notes: 1635c6c1daeSBarry Smith A hyphen (-) must NOT be given at the beginning of the prefix name. 1645c6c1daeSBarry Smith The first character of all runtime options is AUTOMATICALLY the hyphen. 1655c6c1daeSBarry Smith 1665c6c1daeSBarry Smith Level: advanced 1675c6c1daeSBarry Smith 1685c6c1daeSBarry Smith .keywords: PetscViewer, set, options, prefix, database 1695c6c1daeSBarry Smith 1705c6c1daeSBarry Smith .seealso: PetscViewerSetFromOptions() 1715c6c1daeSBarry Smith @*/ 1725c6c1daeSBarry Smith PetscErrorCode PetscViewerSetOptionsPrefix(PetscViewer viewer,const char prefix[]) 1735c6c1daeSBarry Smith { 1745c6c1daeSBarry Smith PetscErrorCode ierr; 1755c6c1daeSBarry Smith 1765c6c1daeSBarry Smith PetscFunctionBegin; 1775c6c1daeSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 1785c6c1daeSBarry Smith ierr = PetscObjectSetOptionsPrefix((PetscObject)viewer,prefix);CHKERRQ(ierr); 1795c6c1daeSBarry Smith PetscFunctionReturn(0); 1805c6c1daeSBarry Smith } 1815c6c1daeSBarry Smith 1825c6c1daeSBarry Smith #undef __FUNCT__ 1835c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerAppendOptionsPrefix" 1845c6c1daeSBarry Smith /*@C 1855c6c1daeSBarry Smith PetscViewerAppendOptionsPrefix - Appends to the prefix used for searching for all 1865c6c1daeSBarry Smith PetscViewer options in the database. 1875c6c1daeSBarry Smith 1885c6c1daeSBarry Smith Logically Collective on PetscViewer 1895c6c1daeSBarry Smith 1905c6c1daeSBarry Smith Input Parameters: 1915c6c1daeSBarry Smith + viewer - the PetscViewer context 1925c6c1daeSBarry Smith - prefix - the prefix to prepend to all option names 1935c6c1daeSBarry Smith 1945c6c1daeSBarry Smith Notes: 1955c6c1daeSBarry Smith A hyphen (-) must NOT be given at the beginning of the prefix name. 1965c6c1daeSBarry Smith The first character of all runtime options is AUTOMATICALLY the hyphen. 1975c6c1daeSBarry Smith 1985c6c1daeSBarry Smith Level: advanced 1995c6c1daeSBarry Smith 2005c6c1daeSBarry Smith .keywords: PetscViewer, append, options, prefix, database 2015c6c1daeSBarry Smith 2025c6c1daeSBarry Smith .seealso: PetscViewerGetOptionsPrefix() 2035c6c1daeSBarry Smith @*/ 2045c6c1daeSBarry Smith PetscErrorCode PetscViewerAppendOptionsPrefix(PetscViewer viewer,const char prefix[]) 2055c6c1daeSBarry Smith { 2065c6c1daeSBarry Smith PetscErrorCode ierr; 2075c6c1daeSBarry Smith 2085c6c1daeSBarry Smith PetscFunctionBegin; 2095c6c1daeSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 2105c6c1daeSBarry Smith ierr = PetscObjectAppendOptionsPrefix((PetscObject)viewer,prefix);CHKERRQ(ierr); 2115c6c1daeSBarry Smith PetscFunctionReturn(0); 2125c6c1daeSBarry Smith } 2135c6c1daeSBarry Smith 2145c6c1daeSBarry Smith #undef __FUNCT__ 2155c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerGetOptionsPrefix" 2165c6c1daeSBarry Smith /*@C 2175c6c1daeSBarry Smith PetscViewerGetOptionsPrefix - Sets the prefix used for searching for all 2185c6c1daeSBarry Smith PetscViewer options in the database. 2195c6c1daeSBarry Smith 2205c6c1daeSBarry Smith Not Collective 2215c6c1daeSBarry Smith 2225c6c1daeSBarry Smith Input Parameter: 2235c6c1daeSBarry Smith . viewer - the PetscViewer context 2245c6c1daeSBarry Smith 2255c6c1daeSBarry Smith Output Parameter: 2265c6c1daeSBarry Smith . prefix - pointer to the prefix string used 2275c6c1daeSBarry Smith 2285c6c1daeSBarry Smith Notes: On the fortran side, the user should pass in a string 'prefix' of 2295c6c1daeSBarry Smith sufficient length to hold the prefix. 2305c6c1daeSBarry Smith 2315c6c1daeSBarry Smith Level: advanced 2325c6c1daeSBarry Smith 2335c6c1daeSBarry Smith .keywords: PetscViewer, get, options, prefix, database 2345c6c1daeSBarry Smith 2355c6c1daeSBarry Smith .seealso: PetscViewerAppendOptionsPrefix() 2365c6c1daeSBarry Smith @*/ 2375c6c1daeSBarry Smith PetscErrorCode PetscViewerGetOptionsPrefix(PetscViewer viewer,const char *prefix[]) 2385c6c1daeSBarry Smith { 2395c6c1daeSBarry Smith PetscErrorCode ierr; 2405c6c1daeSBarry Smith 2415c6c1daeSBarry Smith PetscFunctionBegin; 2425c6c1daeSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 2435c6c1daeSBarry Smith ierr = PetscObjectGetOptionsPrefix((PetscObject)viewer,prefix);CHKERRQ(ierr); 2445c6c1daeSBarry Smith PetscFunctionReturn(0); 2455c6c1daeSBarry Smith } 2465c6c1daeSBarry Smith 2475c6c1daeSBarry Smith #undef __FUNCT__ 2485c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerSetUp" 2495c6c1daeSBarry Smith /*@ 2505c6c1daeSBarry Smith PetscViewerSetUp - Sets up the internal viewer data structures for the later use. 2515c6c1daeSBarry Smith 2525c6c1daeSBarry Smith Collective on PetscViewer 2535c6c1daeSBarry Smith 2545c6c1daeSBarry Smith Input Parameters: 2555c6c1daeSBarry Smith . viewer - the PetscViewer context 2565c6c1daeSBarry Smith 2575c6c1daeSBarry Smith Notes: 2585c6c1daeSBarry Smith For basic use of the PetscViewer classes the user need not explicitly call 2595c6c1daeSBarry Smith PetscViewerSetUp(), since these actions will happen automatically. 2605c6c1daeSBarry Smith 2615c6c1daeSBarry Smith Level: advanced 2625c6c1daeSBarry Smith 2635c6c1daeSBarry Smith .keywords: PetscViewer, setup 2645c6c1daeSBarry Smith 2655c6c1daeSBarry Smith .seealso: PetscViewerCreate(), PetscViewerDestroy() 2665c6c1daeSBarry Smith @*/ 2675c6c1daeSBarry Smith PetscErrorCode PetscViewerSetUp(PetscViewer viewer) 2685c6c1daeSBarry Smith { 2695c6c1daeSBarry Smith PetscFunctionBegin; 2705c6c1daeSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,1); 2715c6c1daeSBarry Smith PetscFunctionReturn(0); 2725c6c1daeSBarry Smith } 2735c6c1daeSBarry Smith 2745c6c1daeSBarry Smith #undef __FUNCT__ 2755c6c1daeSBarry Smith #define __FUNCT__ "PetscViewerView" 2765c6c1daeSBarry Smith /*@C 2775c6c1daeSBarry Smith PetscViewerView - Visualizes a viewer object. 2785c6c1daeSBarry Smith 2795c6c1daeSBarry Smith Collective on PetscViewer 2805c6c1daeSBarry Smith 2815c6c1daeSBarry Smith Input Parameters: 2825c6c1daeSBarry Smith + v - the viewer 2835c6c1daeSBarry Smith - viewer - visualization context 2845c6c1daeSBarry Smith 2855c6c1daeSBarry Smith Notes: 2865c6c1daeSBarry Smith The available visualization contexts include 2875c6c1daeSBarry Smith + PETSC_VIEWER_STDOUT_SELF - standard output (default) 2885c6c1daeSBarry Smith . PETSC_VIEWER_STDOUT_WORLD - synchronized standard 2895c6c1daeSBarry Smith output where only the first processor opens 2905c6c1daeSBarry Smith the file. All other processors send their 2915c6c1daeSBarry Smith data to the first processor to print. 2925c6c1daeSBarry Smith - PETSC_VIEWER_DRAW_WORLD - graphical display of nonzero structure 2935c6c1daeSBarry Smith 2945c6c1daeSBarry Smith Level: beginner 2955c6c1daeSBarry Smith 2965c6c1daeSBarry Smith .seealso: PetscViewerSetFormat(), PetscViewerASCIIOpen(), PetscViewerDrawOpen(), 2975c6c1daeSBarry Smith PetscViewerSocketOpen(), PetscViewerBinaryOpen(), PetscViewerLoad() 2985c6c1daeSBarry Smith @*/ 2995c6c1daeSBarry Smith PetscErrorCode PetscViewerView(PetscViewer v,PetscViewer viewer) 3005c6c1daeSBarry Smith { 3015c6c1daeSBarry Smith PetscErrorCode ierr; 3025c6c1daeSBarry Smith PetscBool iascii; 3035c6c1daeSBarry Smith PetscViewerFormat format; 3045c6c1daeSBarry Smith 3055c6c1daeSBarry Smith PetscFunctionBegin; 3065c6c1daeSBarry Smith PetscValidHeaderSpecific(v,PETSC_VIEWER_CLASSID,1); 3075c6c1daeSBarry Smith PetscValidType(v,1); 3085c6c1daeSBarry Smith if (!viewer) { 309ce94432eSBarry Smith ierr = PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)v),&viewer);CHKERRQ(ierr); 3105c6c1daeSBarry Smith } 3115c6c1daeSBarry Smith PetscValidHeaderSpecific(viewer,PETSC_VIEWER_CLASSID,2); 3125c6c1daeSBarry Smith PetscCheckSameComm(v,1,viewer,2); 3135c6c1daeSBarry Smith 3145c6c1daeSBarry Smith ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);CHKERRQ(ierr); 3155c6c1daeSBarry Smith if (iascii) { 3165c6c1daeSBarry Smith ierr = PetscViewerGetFormat(viewer,&format);CHKERRQ(ierr); 3172bf49c77SBarry Smith if (format == PETSC_VIEWER_DEFAULT || format == PETSC_VIEWER_ASCII_INFO || format == PETSC_VIEWER_ASCII_INFO_DETAIL) { 318*dae58748SBarry Smith ierr = PetscObjectPrintClassNamePrefixType((PetscObject)v,viewer);CHKERRQ(ierr); 3192f234a98SBarry Smith if (v->format) { 3202f234a98SBarry Smith ierr = PetscViewerASCIIPrintf(viewer," Viewer format = %s\n",PetscViewerFormats[v->format]);CHKERRQ(ierr); 3212f234a98SBarry Smith } 3225c6c1daeSBarry Smith ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); 3232bf49c77SBarry Smith if (v->ops->view) { 3242bf49c77SBarry Smith ierr = (*v->ops->view)(v,viewer);CHKERRQ(ierr); 3255c6c1daeSBarry Smith } 3265c6c1daeSBarry Smith ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); 3275c6c1daeSBarry Smith } 3285c6c1daeSBarry Smith } 3295c6c1daeSBarry Smith PetscFunctionReturn(0); 3305c6c1daeSBarry Smith } 331