Date: 2013-07-02T14:38:13+00:00

Actual source code: view.c
petsc-3.4.2 2013-07-02

      2: #include <petsc-private/viewerimpl.h>  /*I "petscviewer.h" I*/

      4: PetscClassId PETSC_VIEWER_CLASSID;

      6: static PetscBool PetscViewerPackageInitialized = PETSC_FALSE;
      9: /*@C
     10:   PetscViewerFinalizePackage - This function destroys everything in the Petsc interface to Mathematica. It is
     11:   called from PetscFinalize().

     13:   Level: developer

     15: .keywords: Petsc, destroy, package, mathematica
     16: .seealso: PetscFinalize()
     17: @*/
     18: PetscErrorCode  PetscViewerFinalizePackage(void)
     19: {

     23:   PetscFunctionListDestroy(&PetscViewerList);
     24:   PetscViewerPackageInitialized = PETSC_FALSE;
     25:   return(0);
     26: }

     30: /*@C
     31:   PetscViewerInitializePackage - This function initializes everything in the main PetscViewer package.

     33:   Level: developer

     35: .keywords: Petsc, initialize, package
     36: .seealso: PetscInitialize()
     37: @*/
     38: PetscErrorCode  PetscViewerInitializePackage(void)
     39: {
     40:   char           logList[256];
     41:   char           *className;
     42:   PetscBool      opt;

     46:   if (PetscViewerPackageInitialized) return(0);
     47:   PetscViewerPackageInitialized = PETSC_TRUE;
     48:   /* Register Classes */
     49:   PetscClassIdRegister("Viewer",&PETSC_VIEWER_CLASSID);

     51:   /* Register Constructors */
     52:   PetscViewerRegisterAll();

     54:   /* Process info exclusions */
     55:   PetscOptionsGetString(NULL, "-info_exclude", logList, 256, &opt);
     56:   if (opt) {
     57:     PetscStrstr(logList, "viewer", &className);
     58:     if (className) {
     59:       PetscInfoDeactivateClass(0);
     60:     }
     61:   }
     62:   /* Process summary exclusions */
     63:   PetscOptionsGetString(NULL, "-log_summary_exclude", logList, 256, &opt);
     64:   if (opt) {
     65:     PetscStrstr(logList, "viewer", &className);
     66:     if (className) {
     67:       PetscLogEventDeactivateClass(0);
     68:     }
     69:   }
     70: #if defined(PETSC_HAVE_MATHEMATICA)
     71:   PetscViewerMathematicaInitializePackage();
     72: #endif
     73:   PetscRegisterFinalize(PetscViewerFinalizePackage);
     74:   return(0);
     75: }

     79: /*@
     80:    PetscViewerDestroy - Destroys a PetscViewer.

     82:    Collective on PetscViewer

     84:    Input Parameters:
     85: .  viewer - the PetscViewer to be destroyed.

     87:    Level: beginner

     89: .seealso: PetscViewerSocketOpen(), PetscViewerASCIIOpen(), PetscViewerCreate(), PetscViewerDrawOpen()

     91: @*/
     92: PetscErrorCode  PetscViewerDestroy(PetscViewer *viewer)
     93: {

     97:   if (!*viewer) return(0);

    100:   PetscViewerFlush(*viewer);
    101:   if (--((PetscObject)(*viewer))->refct > 0) {*viewer = 0; return(0);}

    103:   PetscObjectAMSViewOff((PetscObject)*viewer);
    104:   if ((*viewer)->ops->destroy) {
    105:     (*(*viewer)->ops->destroy)(*viewer);
    106:   }
    107:   PetscHeaderDestroy(viewer);
    108:   return(0);
    109: }

    113: /*@C
    114:    PetscViewerGetType - Returns the type of a PetscViewer.

    116:    Not Collective

    118:    Input Parameter:
    119: .   viewer - the PetscViewer

    121:    Output Parameter:
    122: .  type - PetscViewer type (see below)

    124:    Available Types Include:
    125: .  PETSCVIEWERSOCKET - Socket PetscViewer
    126: .  PETSCVIEWERASCII - ASCII PetscViewer
    127: .  PETSCVIEWERBINARY - binary file PetscViewer
    128: .  PETSCVIEWERSTRING - string PetscViewer
    129: .  PETSCVIEWERDRAW - drawing PetscViewer

    131:    Level: intermediate

    133:    Note:
    134:    See include/petscviewer.h for a complete list of PetscViewers.

    136:    PetscViewerType is actually a string

    138: .seealso: PetscViewerCreate(), PetscViewerSetType(), PetscViewerType

    140: @*/
    141: PetscErrorCode  PetscViewerGetType(PetscViewer viewer,PetscViewerType *type)
    142: {
    146:   *type = ((PetscObject)viewer)->type_name;
    147:   return(0);
    148: }

    152: /*@C
    153:    PetscViewerSetOptionsPrefix - Sets the prefix used for searching for all
    154:    PetscViewer options in the database.

    156:    Logically Collective on PetscViewer

    158:    Input Parameter:
    159: +  viewer - the PetscViewer context
    160: -  prefix - the prefix to prepend to all option names

    162:    Notes:
    163:    A hyphen (-) must NOT be given at the beginning of the prefix name.
    164:    The first character of all runtime options is AUTOMATICALLY the hyphen.

    166:    Level: advanced

    168: .keywords: PetscViewer, set, options, prefix, database

    170: .seealso: PetscViewerSetFromOptions()
    171: @*/
    172: PetscErrorCode  PetscViewerSetOptionsPrefix(PetscViewer viewer,const char prefix[])
    173: {

    178:   PetscObjectSetOptionsPrefix((PetscObject)viewer,prefix);
    179:   return(0);
    180: }

    184: /*@C
    185:    PetscViewerAppendOptionsPrefix - Appends to the prefix used for searching for all
    186:    PetscViewer options in the database.

    188:    Logically Collective on PetscViewer

    190:    Input Parameters:
    191: +  viewer - the PetscViewer context
    192: -  prefix - the prefix to prepend to all option names

    194:    Notes:
    195:    A hyphen (-) must NOT be given at the beginning of the prefix name.
    196:    The first character of all runtime options is AUTOMATICALLY the hyphen.

    198:    Level: advanced

    200: .keywords: PetscViewer, append, options, prefix, database

    202: .seealso: PetscViewerGetOptionsPrefix()
    203: @*/
    204: PetscErrorCode  PetscViewerAppendOptionsPrefix(PetscViewer viewer,const char prefix[])
    205: {

    210:   PetscObjectAppendOptionsPrefix((PetscObject)viewer,prefix);
    211:   return(0);
    212: }

    216: /*@C
    217:    PetscViewerGetOptionsPrefix - Sets the prefix used for searching for all
    218:    PetscViewer options in the database.

    220:    Not Collective

    222:    Input Parameter:
    223: .  viewer - the PetscViewer context

    225:    Output Parameter:
    226: .  prefix - pointer to the prefix string used

    228:    Notes: On the fortran side, the user should pass in a string 'prefix' of
    229:    sufficient length to hold the prefix.

    231:    Level: advanced

    233: .keywords: PetscViewer, get, options, prefix, database

    235: .seealso: PetscViewerAppendOptionsPrefix()
    236: @*/
    237: PetscErrorCode  PetscViewerGetOptionsPrefix(PetscViewer viewer,const char *prefix[])
    238: {

    243:   PetscObjectGetOptionsPrefix((PetscObject)viewer,prefix);
    244:   return(0);
    245: }

    249: /*@
    250:    PetscViewerSetUp - Sets up the internal viewer data structures for the later use.

    252:    Collective on PetscViewer

    254:    Input Parameters:
    255: .  viewer - the PetscViewer context

    257:    Notes:
    258:    For basic use of the PetscViewer classes the user need not explicitly call
    259:    PetscViewerSetUp(), since these actions will happen automatically.

    261:    Level: advanced

    263: .keywords: PetscViewer, setup

    265: .seealso: PetscViewerCreate(), PetscViewerDestroy()
    266: @*/
    267: PetscErrorCode  PetscViewerSetUp(PetscViewer viewer)
    268: {
    271:   return(0);
    272: }

    276: /*@C
    277:    PetscViewerView - Visualizes a viewer object.

    279:    Collective on PetscViewer

    281:    Input Parameters:
    282: +  v - the viewer
    283: -  viewer - visualization context

    285:   Notes:
    286:   The available visualization contexts include
    287: +    PETSC_VIEWER_STDOUT_SELF - standard output (default)
    288: .    PETSC_VIEWER_STDOUT_WORLD - synchronized standard
    289:         output where only the first processor opens
    290:         the file.  All other processors send their
    291:         data to the first processor to print.
    292: -     PETSC_VIEWER_DRAW_WORLD - graphical display of nonzero structure

    294:    Level: beginner

    296: .seealso: PetscViewerSetFormat(), PetscViewerASCIIOpen(), PetscViewerDrawOpen(),
    297:           PetscViewerSocketOpen(), PetscViewerBinaryOpen(), PetscViewerLoad()
    298: @*/
    299: PetscErrorCode  PetscViewerView(PetscViewer v,PetscViewer viewer)
    300: {
    301:   PetscErrorCode    ierr;
    302:   PetscBool         iascii;
    303:   PetscViewerFormat format;

    308:   if (!viewer) {
    309:     PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)v),&viewer);
    310:   }

    314:   PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);
    315:   if (iascii) {
    316:     PetscViewerGetFormat(viewer,&format);
    317:     if (format == PETSC_VIEWER_DEFAULT || format == PETSC_VIEWER_ASCII_INFO || format == PETSC_VIEWER_ASCII_INFO_DETAIL) {
    318:       PetscObjectPrintClassNamePrefixType((PetscObject)v,viewer,"PetscViewer Object");
    319:       if (v->format) {
    320:         PetscViewerASCIIPrintf(viewer,"  Viewer format = %s\n",PetscViewerFormats[v->format]);
    321:       }
    322:       PetscViewerASCIIPushTab(viewer);
    323:       if (v->ops->view) {
    324:         (*v->ops->view)(v,viewer);
    325:       }
    326:       PetscViewerASCIIPopTab(viewer);
    327:     }
    328:   }
    329:   return(0);
    330: }