PetscErrorCode PetscViewerFileSetName_VTK(PetscViewer viewer,const char name[]) { PetscViewer_VTK *vtk = (PetscViewer_VTK*)viewer->data; PetscErrorCode ierr; PetscBool isvtk,isvts,isvtu,isvtr; size_t len; PetscFunctionBegin; ierr = PetscViewerFlush(viewer);CHKERRQ(ierr); ierr = PetscFree(vtk->filename);CHKERRQ(ierr); ierr = PetscStrlen(name,&len);CHKERRQ(ierr); ierr = PetscStrcasecmp(name+len-4,".vtk",&isvtk);CHKERRQ(ierr); ierr = PetscStrcasecmp(name+len-4,".vts",&isvts);CHKERRQ(ierr); ierr = PetscStrcasecmp(name+len-4,".vtu",&isvtu);CHKERRQ(ierr); ierr = PetscStrcasecmp(name+len-4,".vtr",&isvtr);CHKERRQ(ierr); if (isvtk) { if (viewer->format == PETSC_VIEWER_DEFAULT) {ierr = PetscViewerSetFormat(viewer,PETSC_VIEWER_ASCII_VTK);CHKERRQ(ierr);} if (viewer->format != PETSC_VIEWER_ASCII_VTK) SETERRQ2(PetscObjectComm((PetscObject)viewer),PETSC_ERR_ARG_INCOMP,"Cannot use file '%s' with format %s, should have '.vtk' extension",name,PetscViewerFormats[viewer->format]); } else if (isvts) { if (viewer->format == PETSC_VIEWER_DEFAULT) {ierr = PetscViewerSetFormat(viewer,PETSC_VIEWER_VTK_VTS);CHKERRQ(ierr);} if (viewer->format != PETSC_VIEWER_VTK_VTS) SETERRQ2(PetscObjectComm((PetscObject)viewer),PETSC_ERR_ARG_INCOMP,"Cannot use file '%s' with format %s, should have '.vts' extension",name,PetscViewerFormats[viewer->format]); } else if (isvtu) { if (viewer->format == PETSC_VIEWER_DEFAULT) {ierr = PetscViewerSetFormat(viewer,PETSC_VIEWER_VTK_VTU);CHKERRQ(ierr);} if (viewer->format != PETSC_VIEWER_VTK_VTU) SETERRQ2(PetscObjectComm((PetscObject)viewer),PETSC_ERR_ARG_INCOMP,"Cannot use file '%s' with format %s, should have '.vtu' extension",name,PetscViewerFormats[viewer->format]); } else if (isvtr) { if (viewer->format == PETSC_VIEWER_DEFAULT) {ierr = PetscViewerSetFormat(viewer,PETSC_VIEWER_VTK_VTR);CHKERRQ(ierr);} if (viewer->format != PETSC_VIEWER_VTK_VTR) SETERRQ2(PetscObjectComm((PetscObject)viewer),PETSC_ERR_ARG_INCOMP,"Cannot use file '%s' with format %s, should have '.vtr' extension",name,PetscViewerFormats[viewer->format]); } else SETERRQ1(PetscObjectComm((PetscObject)viewer),PETSC_ERR_ARG_UNKNOWN_TYPE,"File '%s' has unrecognized extension",name); ierr = PetscStrallocpy(name,&vtk->filename);CHKERRQ(ierr); PetscFunctionReturn(0); }
static PetscErrorCode PetscViewerMathematicaParseLinkMode(char *modename, LinkMode *mode) { PetscBool isCreate, isConnect, isLaunch; PetscErrorCode ierr; PetscFunctionBegin; ierr = PetscStrcasecmp(modename, "Create", &isCreate);CHKERRQ(ierr); ierr = PetscStrcasecmp(modename, "Connect", &isConnect);CHKERRQ(ierr); ierr = PetscStrcasecmp(modename, "Launch", &isLaunch);CHKERRQ(ierr); if (isCreate) *mode = MATHEMATICA_LINK_CREATE; else if (isConnect) *mode = MATHEMATICA_LINK_CONNECT; else if (isLaunch) *mode = MATHEMATICA_LINK_LAUNCH; else SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG, "Invalid Mathematica link mode: %s", modename); PetscFunctionReturn(0); }
PetscErrorCode PetscDrawUtilitySetCmap(const char colormap[],int mapsize,unsigned char R[],unsigned char G[],unsigned char B[]) { int i,j; const char *cmap_name_list[sizeof(PetscDrawCmapTable)/sizeof(PetscDrawCmapTable[0])]; PetscInt id = 0, count = (PetscInt)(sizeof(cmap_name_list)/sizeof(char*)); PetscBool reverse = PETSC_FALSE, brighten = PETSC_FALSE; PetscReal beta = 0; PetscErrorCode ierr; PetscFunctionBegin; for (i=0; i<count; i++) cmap_name_list[i] = PetscDrawCmapTable[i].name; if (colormap && colormap[0]) { PetscBool match = PETSC_FALSE; for (id=0; !match && id<count; id++) {ierr = PetscStrcasecmp(colormap,cmap_name_list[id],&match);CHKERRQ(ierr);} if (!match) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Colormap '%s' not found",colormap); } ierr = PetscOptionsGetEList(NULL,NULL,"-draw_cmap",cmap_name_list,count,&id,NULL);CHKERRQ(ierr); ierr = PetscOptionsGetBool(NULL,NULL,"-draw_cmap_reverse",&reverse,NULL);CHKERRQ(ierr); ierr = PetscOptionsGetReal(NULL,NULL,"-draw_cmap_brighten",&beta,&brighten);CHKERRQ(ierr); if (brighten && (beta <= (PetscReal)-1 || beta >= (PetscReal)+1)) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"brighten parameter %g must be in the range (-1,1)",(double)beta); if (PetscDrawCmapTable[id].cmap) { ierr = PetscDrawCmapTable[id].cmap(mapsize,R,G,B);CHKERRQ(ierr); } else { const unsigned char (*rgb)[3] = PetscDrawCmapTable[id].data; if (mapsize != 256-PETSC_DRAW_BASIC_COLORS) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_SUP,"Colormap '%s' with size %d not supported",cmap_name_list[id],mapsize); for (i=0; i<mapsize; i++) {R[i] = rgb[i][0]; G[i] = rgb[i][1]; B[i] = rgb[i][2];} } if (reverse) { i = 0; j = mapsize-1; while(i < j) { #define SWAP(a,i,j) do { unsigned char t = a[i]; a[i] = a[j]; a[j] = t; } while (0) SWAP(R,i,j); SWAP(G,i,j); SWAP(B,i,j); #undef SWAP i++; j--; } } if (brighten) { PetscReal gamma = (beta > 0.0) ? (1 - beta) : (1 / (1 + beta)); for (i=0; i<mapsize; i++) { PetscReal r = PetscPowReal((PetscReal)R[i]/255,gamma); PetscReal g = PetscPowReal((PetscReal)G[i]/255,gamma); PetscReal b = PetscPowReal((PetscReal)B[i]/255,gamma); R[i] = (unsigned char)(255*PetscMin(r,(PetscReal)1.0)); G[i] = (unsigned char)(255*PetscMin(g,(PetscReal)1.0)); B[i] = (unsigned char)(255*PetscMin(b,(PetscReal)1.0)); } } PetscFunctionReturn(0); }
/*@ EventRegLogGetEvent - This function returns the event id given the event name. Not Collective Input Parameters: + eventLog - The EventRegLog - name - The stage name Output Parameter: . event - The event id Level: intermediate .keywords: log, stage .seealso: EventRegLogRegister() @*/ PetscErrorCode PETSC_DLLEXPORT EventRegLogGetEvent(EventRegLog eventLog, const char name[], PetscLogEvent *event) { PetscTruth match; int e; PetscErrorCode ierr; PetscFunctionBegin; PetscValidCharPointer(name,2); PetscValidIntPointer(event,3); *event = -1; for(e = 0; e < eventLog->numEvents; e++) { ierr = PetscStrcasecmp(eventLog->eventInfo[e].name, name, &match);CHKERRQ(ierr); if (match) break; } if (e == eventLog->numEvents) SETERRQ1(PETSC_ERR_ARG_WRONG, "No event named %s", name); *event = e; PetscFunctionReturn(0); }
/*@C PetscStageLogGetStage - This function returns the stage id given the stage name. Not Collective Input Parameters: + stageLog - The PetscStageLog - name - The stage name Output Parameter: . stage - The stage id Level: developer .keywords: log, stage .seealso: PetscStageLogGetCurrent(), PetscStageLogRegister(), PetscLogGetStageLog() @*/ PetscErrorCode PetscStageLogGetStage(PetscStageLog stageLog, const char name[], int *stage) { PetscBool match; int s; PetscErrorCode ierr; PetscFunctionBegin; PetscValidCharPointer(name,2); PetscValidIntPointer(stage,3); *stage = -1; for(s = 0; s < stageLog->numStages; s++) { ierr = PetscStrcasecmp(stageLog->stageInfo[s].name, name, &match);CHKERRQ(ierr); if (match) break; } if (s == stageLog->numStages) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG, "No stage named %s", name); *stage = s; PetscFunctionReturn(0); }
/*@C PetscEventRegLogGetEvent - This function returns the event id given the event name. Not Collective Input Parameters: + eventLog - The PetscEventRegLog - name - The stage name Output Parameter: . event - The event id, or -1 if not found Level: developer .keywords: log, stage .seealso: PetscEventRegLogRegister() @*/ PetscErrorCode PetscEventRegLogGetEvent(PetscEventRegLog eventLog,const char name[],PetscLogEvent *event) { PetscBool match; int e; PetscErrorCode ierr; PetscFunctionBegin; PetscValidCharPointer(name,2); PetscValidIntPointer(event,3); *event = -1; for (e = 0; e < eventLog->numEvents; e++) { ierr = PetscStrcasecmp(eventLog->eventInfo[e].name,name,&match);CHKERRQ(ierr); if (match) { *event = e; break; } } 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); }