/*@C PetscViewerMathematicaOpen - Communicates with Mathemtica using MathLink. Collective on comm Input Parameters: + comm - The MPI communicator . port - [optional] The port to connect on, or PETSC_DECIDE . machine - [optional] The machine to run Mathematica on, or NULL - mode - [optional] The connection mode, or NULL Output Parameter: . viewer - The Mathematica viewer Level: intermediate Notes: Most users should employ the following commands to access the Mathematica viewers $ $ PetscViewerMathematicaOpen(MPI_Comm comm, int port, char *machine, char *mode, PetscViewer &viewer) $ MatView(Mat matrix, PetscViewer viewer) $ $ or $ $ PetscViewerMathematicaOpen(MPI_Comm comm, int port, char *machine, char *mode, PetscViewer &viewer) $ VecView(Vec vector, PetscViewer viewer) Options Database Keys: $ -viewer_math_linkhost <machine> - The host machine for the kernel $ -viewer_math_linkname <name> - The full link name for the connection $ -viewer_math_linkport <port> - The port for the connection $ -viewer_math_mode <mode> - The mode, e.g. Launch, Connect $ -viewer_math_type <type> - The plot type, e.g. Triangulation, Vector $ -viewer_math_graphics <output> - The output type, e.g. Motif, PS, PSFile .keywords: PetscViewer, Mathematica, open .seealso: MatView(), VecView() @*/ PetscErrorCode PetscViewerMathematicaOpen(MPI_Comm comm, int port, const char machine[], const char mode[], PetscViewer *v) { PetscErrorCode ierr; PetscFunctionBegin; ierr = PetscViewerCreate(comm, v);CHKERRQ(ierr); #if 0 LinkMode linkmode; ierr = PetscViewerMathematicaSetLinkPort(*v, port);CHKERRQ(ierr); ierr = PetscViewerMathematicaSetLinkHost(*v, machine);CHKERRQ(ierr); ierr = PetscViewerMathematicaParseLinkMode_Private(mode, &linkmode);CHKERRQ(ierr); ierr = PetscViewerMathematicaSetLinkMode(*v, linkmode);CHKERRQ(ierr); #endif ierr = PetscViewerSetType(*v, PETSC_VIEWER_MATHEMATICA);CHKERRQ(ierr); PetscFunctionReturn(0); }
PetscErrorCode PetscViewerMathematicaSetFromOptions(PetscViewer v) { PetscViewer_Mathematica *vmath = (PetscViewer_Mathematica*) v->data; char linkname[256]; char modename[256]; char hostname[256]; char type[256]; PetscInt numPorts; PetscInt *ports; PetscInt numHosts; int h; char **hosts; PetscMPIInt size, rank; PetscBool opt; PetscErrorCode ierr; PetscFunctionBegin; ierr = MPI_Comm_size(PetscObjectComm((PetscObject)v), &size); CHKERRQ(ierr); ierr = MPI_Comm_rank(PetscObjectComm((PetscObject)v), &rank); CHKERRQ(ierr); /* Get link name */ ierr = PetscOptionsGetString("viewer_", "-math_linkname", linkname, 256, &opt); CHKERRQ(ierr); if (opt) { ierr = PetscViewerMathematicaSetLinkName(v, linkname); CHKERRQ(ierr); } /* Get link port */ numPorts = size; ierr = PetscMalloc1(size, &ports); CHKERRQ(ierr); ierr = PetscOptionsGetIntArray("viewer_", "-math_linkport", ports, &numPorts, &opt); CHKERRQ(ierr); if (opt) { if (numPorts > rank) snprintf(linkname, 255, "%6d", ports[rank]); else snprintf(linkname, 255, "%6d", ports[0]); ierr = PetscViewerMathematicaSetLinkName(v, linkname); CHKERRQ(ierr); } ierr = PetscFree(ports); CHKERRQ(ierr); /* Get link host */ numHosts = size; ierr = PetscMalloc1(size, &hosts); CHKERRQ(ierr); ierr = PetscOptionsGetStringArray("viewer_", "-math_linkhost", hosts, &numHosts, &opt); CHKERRQ(ierr); if (opt) { if (numHosts > rank) { ierr = PetscStrncpy(hostname, hosts[rank], 255); CHKERRQ(ierr); } else { ierr = PetscStrncpy(hostname, hosts[0], 255); CHKERRQ(ierr); } ierr = PetscViewerMathematicaSetLinkHost(v, hostname); CHKERRQ(ierr); } for (h = 0; h < numHosts; h++) { ierr = PetscFree(hosts[h]); CHKERRQ(ierr); } ierr = PetscFree(hosts); CHKERRQ(ierr); /* Get link mode */ ierr = PetscOptionsGetString("viewer_", "-math_linkmode", modename, 256, &opt); CHKERRQ(ierr); if (opt) { LinkMode mode; ierr = PetscViewerMathematicaParseLinkMode_Private(modename, &mode); CHKERRQ(ierr); ierr = PetscViewerMathematicaSetLinkMode(v, mode); CHKERRQ(ierr); } /* Get graphics type */ ierr = PetscOptionsGetString("viewer_", "-math_graphics", type, 256, &opt); CHKERRQ(ierr); if (opt) { PetscBool isMotif, isPS, isPSFile; ierr = PetscStrcasecmp(type, "Motif", &isMotif); CHKERRQ(ierr); ierr = PetscStrcasecmp(type, "PS", &isPS); CHKERRQ(ierr); ierr = PetscStrcasecmp(type, "PSFile", &isPSFile); CHKERRQ(ierr); if (isMotif) vmath->graphicsType = GRAPHICS_MOTIF; else if (isPS) vmath->graphicsType = GRAPHICS_PS_STDOUT; else if (isPSFile) vmath->graphicsType = GRAPHICS_PS_FILE; } /* Get plot type */ ierr = PetscOptionsGetString("viewer_", "-math_type", type, 256, &opt); CHKERRQ(ierr); if (opt) { PetscBool isTri, isVecTri, isVec, isSurface; ierr = PetscStrcasecmp(type, "Triangulation", &isTri); CHKERRQ(ierr); ierr = PetscStrcasecmp(type, "VectorTriangulation", &isVecTri); CHKERRQ(ierr); ierr = PetscStrcasecmp(type, "Vector", &isVec); CHKERRQ(ierr); ierr = PetscStrcasecmp(type, "Surface", &isSurface); CHKERRQ(ierr); if (isTri) vmath->plotType = MATHEMATICA_TRIANGULATION_PLOT; else if (isVecTri) vmath->plotType = MATHEMATICA_VECTOR_TRIANGULATION_PLOT; else if (isVec) vmath->plotType = MATHEMATICA_VECTOR_PLOT; else if (isSurface) vmath->plotType = MATHEMATICA_SURFACE_PLOT; } PetscFunctionReturn(0); }