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