Lisandro Dalcin avatar Lisandro Dalcin committed b01beb9

Add IGAViewFromOptions()

Comments (0)

Files changed (4)

 PETSC_EXTERN PetscErrorCode IGAPrependOptionsPrefix(IGA iga,const char prefix[]);
 PETSC_EXTERN PetscErrorCode IGAAppendOptionsPrefix(IGA iga,const char prefix[]);
 PETSC_EXTERN PetscErrorCode IGASetFromOptions(IGA iga);
+PETSC_EXTERN PetscErrorCode IGAViewFromOptions(IGA iga,const char prefix[],const char option[]);
 PETSC_EXTERN PetscErrorCode IGAOptionsAlias(const char name[],const char defval[],const char alias[]);
 
 PETSC_EXTERN PetscErrorCode IGALoad(IGA iga,PetscViewer viewer);
 #FFLAGS = ${FFLAGS_STD} -pedantic -Wall -Wextra -Wimplicit-interface -g3 -fcheck=all -fbacktrace
 
 SOURCEH  = ../include/petiga.h petigabl.h petigagrid.h petigapart.h
-SOURCEC  = petiga.c petigareg.c petigaaxis.c petigarule.c petigabasis.c petigabound.c petigaelem.c petigapoint.c petigavec.c petigamat.c petigascl.c petigapcb.c petigapce.c petigapc.c petigaksp.c petigasnes.c petigats.c petigadm.c petigats2.c petigaio.c petigagrid.c petigapart.c snesfdcolor.c tsalpha2.c
+SOURCEC  = petiga.c petigareg.c petigaaxis.c petigarule.c petigabasis.c petigabound.c petigaelem.c petigapoint.c petigavec.c petigamat.c petigascl.c petigapcb.c petigapce.c petigapc.c petigaksp.c petigasnes.c petigats.c petigadm.c petigats2.c petigaio.c petigagrid.c petigapart.c petscvwopt.c snesfdcolor.c tsalpha2.c
 SOURCEF1 = petigaftn.F90 petigaval.F90
 SOURCEF2 = petigabsp.f90 petigaqdr.f90 petiga1d.f90 petiga2d.f90 petiga3d.f90
 SOURCEF  = ${SOURCEF1} ${SOURCEF2}
   PetscFunctionReturn(0);
 }
 
+#if PETSC_VERSION_LE(3,3,0)
+PETSC_EXTERN PetscErrorCode PetscOptionsGetViewer(MPI_Comm,const char[],const char[],PetscViewer*,PetscViewerFormat*,PetscBool*);
+#endif
+
+#undef  __FUNCT__
+#define __FUNCT__ "IGAViewFromOptions"
+PetscErrorCode IGAViewFromOptions(IGA iga,const char prefix[],const char option[])
+{
+
+  MPI_Comm          comm;
+  PetscViewer       viewer;
+  PetscViewerFormat format;
+  PetscBool         skipinfo = PETSC_FALSE;
+  PetscBool         flg;
+  PetscErrorCode    ierr;
+  PetscFunctionBegin;
+  PetscValidHeaderSpecific(iga,IGA_CLASSID,1);
+  ierr = PetscOptionsGetBool(NULL,"-viewer_binary_skip_info",&skipinfo,NULL);CHKERRQ(ierr);
+  ierr = PetscOptionsSetValue("-viewer_binary_skip_info","");CHKERRQ(ierr);
+  ierr = IGAGetComm(iga,&comm);CHKERRQ(ierr);
+  if (!prefix || !prefix[0]) prefix = ((PetscObject)iga)->prefix;
+  ierr = PetscOptionsGetViewer(comm,prefix,option,&viewer,&format,&flg);CHKERRQ(ierr);
+  if (!skipinfo) {ierr = PetscOptionsClearValue("-viewer_binary_skip_info");CHKERRQ(ierr);}
+  if (!flg) PetscFunctionReturn(0);
+  ierr = PetscViewerPushFormat(viewer,format);CHKERRQ(ierr);
+  ierr = IGAView(iga,viewer);CHKERRQ(ierr);
+  ierr = PetscViewerPopFormat(viewer);CHKERRQ(ierr);
+  ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);
+  PetscFunctionReturn(0);
+}
+
 #undef  __FUNCT__
 #define __FUNCT__ "IGAGetComm"
 PetscErrorCode IGAGetComm(IGA iga,MPI_Comm *comm)
 
     /* View options, handled in IGASetUp() */
     ierr = PetscOptionsName("-iga_view",       "Information on IGA context",      "IGAView",NULL);CHKERRQ(ierr);
+    ierr = PetscOptionsName("-iga_view_ascii", "Information on IGA context",      "IGAView",NULL);CHKERRQ(ierr);
     ierr = PetscOptionsName("-iga_view_info",  "Output more detailed information","IGAView",NULL);CHKERRQ(ierr);
     ierr = PetscOptionsName("-iga_view_detail","Output more detailed information","IGAView",NULL);CHKERRQ(ierr);
     ierr = PetscOptionsName("-iga_view_binary","Save to file in binary format",   "IGAView",NULL);CHKERRQ(ierr);
 }
 
 PETSC_EXTERN PetscErrorCode IGASetUp_Basic(IGA);
-PETSC_EXTERN PetscErrorCode IGASetUp_View(IGA);
 
 #undef  __FUNCT__
 #define __FUNCT__ "IGASetUp_Basic"
 
 #undef  __FUNCT__
 #define __FUNCT__ "IGASetUp_View"
-PetscErrorCode IGASetUp_View(IGA iga)
+static PetscErrorCode IGASetUp_View(IGA iga)
 {
   PetscBool      flg1,flg2,info=PETSC_FALSE;
   char           filename1[PETSC_MAX_PATH_LEN] = "";
   PetscValidHeaderSpecific(iga,IGA_CLASSID,1);
 
   ierr = PetscObjectOptionsBegin((PetscObject)iga);CHKERRQ(ierr);
-  ierr = PetscOptionsString("-iga_view",        "Information on IGA context",      "IGAView",filename1,filename1,PETSC_MAX_PATH_LEN,&flg1);CHKERRQ(ierr);
+  ierr = PetscOptionsString("-iga_view_ascii",  "Information on IGA context",      "IGAView",filename1,filename1,PETSC_MAX_PATH_LEN,&flg1);CHKERRQ(ierr);
   ierr = PetscOptionsBool(  "-iga_view_info",   "Output more detailed information","IGAView",info,&info,NULL);CHKERRQ(ierr);
   ierr = PetscOptionsBool(  "-iga_view_detail", "Output more detailed information","IGAView",info,&info,NULL);CHKERRQ(ierr);
   ierr = PetscOptionsString("-iga_view_binary", "Save to file in binary format",   "IGAView",filename2,filename2,PETSC_MAX_PATH_LEN,&flg2);CHKERRQ(ierr);
 
   ierr = IGAElementInit(iga->iterator,iga);CHKERRQ(ierr);
 
+  ierr = IGAViewFromOptions(iga,NULL,"-iga_view");CHKERRQ(ierr);
   ierr = IGASetUp_View(iga);CHKERRQ(ierr);
   PetscFunctionReturn(0);
 }
+#include <petsc.h>
+#include <petsc-private/petscimpl.h>
+#if PETSC_VERSION_LE(3,3,0)
+
+PETSC_EXTERN PetscErrorCode PetscOptionsGetViewer(MPI_Comm,const char[],const char[],PetscViewer*,PetscViewerFormat*,PetscBool*);
+
+#undef __FUNCT__
+#define __FUNCT__ "PetscEListFind"
+static PetscErrorCode PetscEListFind(PetscInt n,const char *const *list,const char *str,PetscInt *value,PetscBool *found)
+{
+  PetscInt  i;
+  PetscBool matched;
+  PetscErrorCode ierr;
+  PetscFunctionBegin;
+  if (found) *found = PETSC_FALSE;
+  for (i=0; i<n; i++) {
+    ierr = PetscStrcasecmp(str,list[i],&matched);CHKERRQ(ierr);
+    if (matched || !str[0]) {
+      if (found) *found = PETSC_TRUE;
+      *value = i;
+      break;
+    }
+  }
+  PetscFunctionReturn(0);
+}
+
+#undef __FUNCT__
+#define __FUNCT__ "PetscEnumFind"
+static PetscErrorCode PetscEnumFind(const char *const *enumlist,const char *str,PetscEnum *value,PetscBool *found)
+{
+  PetscInt       n,evalue;
+  PetscBool      efound;
+  PetscErrorCode ierr;
+  PetscFunctionBegin;
+  for (n = 0; enumlist[n]; n++) {
+    if (n > 50) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"List argument appears to be wrong or have more than 50 entries");
+  }
+  if (n < 3) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"List argument must have at least two entries: typename and type prefix");
+  n -= 3;                       /* drop enum name, prefix, and null termination */
+  ierr = PetscEListFind(n,enumlist,str,&evalue,&efound);CHKERRQ(ierr);
+  if (efound) *value = (PetscEnum)evalue;
+  if (found) *found = efound;
+  PetscFunctionReturn(0);
+}
+
+#undef __FUNCT__
+#define __FUNCT__ "PetscOptionsGetViewer"
+PetscErrorCode PetscOptionsGetViewer(MPI_Comm comm,const char pre[],const char name[],PetscViewer *viewer,PetscViewerFormat *format,PetscBool *set)
+{
+  char           value[2*PETSC_MAX_PATH_LEN];
+  PetscBool      flag;
+  PetscErrorCode ierr;
+  PetscFunctionBegin;
+  PetscValidCharPointer(name,3);
+  if (format) *format = PETSC_VIEWER_DEFAULT;
+  if (set) *set = PETSC_FALSE;
+  ierr = PetscOptionsGetString(pre,name,value,sizeof(value),&flag);CHKERRQ(ierr);
+  if (flag) {
+    if (set) *set = PETSC_TRUE;
+    if (!value[0]) {
+      ierr = PetscViewerASCIIGetStdout(comm,viewer);CHKERRQ(ierr);
+      ierr = PetscObjectReference((PetscObject)*viewer);CHKERRQ(ierr);
+    } else {
+      char       *loc0_vtype,*loc1_fname,*loc2_fmt = NULL,*loc3_fmode = NULL;
+      PetscInt   cnt;
+      const char *const PetscFileModes[] = {"READ","WRITE","APPEND","UPDATE","APPEND_UPDATE","PetscFileMode","PETSC_FILE_",0};
+      const char *const viewers[] = {PETSCVIEWERASCII,PETSCVIEWERBINARY,PETSCVIEWERDRAW,PETSCVIEWERSOCKET,PETSCVIEWERMATLAB,PETSCVIEWERAMS,PETSCVIEWERVTK,0};
+      ierr = PetscStrallocpy(value,&loc0_vtype);CHKERRQ(ierr);
+      ierr = PetscStrchr(loc0_vtype,':',&loc1_fname);CHKERRQ(ierr);
+      if (loc1_fname) {
+        *loc1_fname++ = 0;
+        ierr = PetscStrchr(loc1_fname,':',&loc2_fmt);CHKERRQ(ierr);
+      }
+      if (loc2_fmt) {
+        *loc2_fmt++ = 0;
+        ierr = PetscStrchr(loc2_fmt,':',&loc3_fmode);CHKERRQ(ierr);
+      }
+      if (loc3_fmode) *loc3_fmode++ = 0;
+      ierr = PetscStrendswithwhich(*loc0_vtype ? loc0_vtype : "ascii",viewers,&cnt);CHKERRQ(ierr);
+      if (cnt > (PetscInt) sizeof(viewers)-1) SETERRQ1(comm,PETSC_ERR_ARG_OUTOFRANGE,"Unknown viewer type: %s",loc0_vtype);
+      if (!loc1_fname) {
+        switch (cnt) {
+        case 0:
+          ierr = PetscViewerASCIIGetStdout(comm,viewer);CHKERRQ(ierr);
+          break;
+        case 1:
+          if (!(*viewer = PETSC_VIEWER_BINARY_(comm))) CHKERRQ(PETSC_ERR_PLIB);
+          break;
+        case 2:
+          if (!(*viewer = PETSC_VIEWER_DRAW_(comm))) CHKERRQ(PETSC_ERR_PLIB);
+          break;
+#if defined(PETSC_USE_SOCKET_VIEWER)
+        case 3:
+          if (!(*viewer = PETSC_VIEWER_SOCKET_(comm))) CHKERRQ(PETSC_ERR_PLIB);
+          break;
+#endif
+#if defined(PETSC_HAVE_MATLAB_ENGINE)
+        case 4:
+          if (!(*viewer = PETSC_VIEWER_MATLAB_(comm))) CHKERRQ(PETSC_ERR_PLIB);
+          break;
+#endif
+#if defined(PETSC_HAVE_AMS)
+        case 5:
+          if (!(*viewer = PETSC_VIEWER_AMS_(comm))) CHKERRQ(PETSC_ERR_PLIB);
+          break;
+#endif
+        default: SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SUP,"Unsupported viewer %s",loc0_vtype);
+        }
+        ierr = PetscObjectReference((PetscObject)*viewer);CHKERRQ(ierr);
+      } else {
+        if (loc2_fmt && !*loc1_fname && (cnt == 0)) { /* ASCII format without file name */
+          ierr = PetscViewerASCIIGetStdout(comm,viewer);CHKERRQ(ierr);
+          ierr = PetscObjectReference((PetscObject)*viewer);CHKERRQ(ierr);
+        } else {
+          PetscFileMode fmode;
+          ierr = PetscViewerCreate(comm,viewer);CHKERRQ(ierr);
+          ierr = PetscViewerSetType(*viewer,*loc0_vtype ? loc0_vtype : "ascii");CHKERRQ(ierr);
+#if defined(PETSC_HAVE_AMS)
+          ierr = PetscViewerAMSSetCommName(*viewer,loc1_fname);CHKERRQ(ierr);
+#endif
+          fmode = FILE_MODE_WRITE;
+          if (loc3_fmode && *loc3_fmode) { /* Has non-empty file mode ("write" or "append") */
+            ierr = PetscEnumFind(PetscFileModes,loc3_fmode,(PetscEnum*)&fmode,&flag);CHKERRQ(ierr);
+            if (!flag) SETERRQ1(comm,PETSC_ERR_ARG_UNKNOWN_TYPE,"Unknown file mode: %s",loc3_fmode);
+          }
+          ierr = PetscViewerFileSetMode(*viewer,flag?fmode:FILE_MODE_WRITE);CHKERRQ(ierr);
+          ierr = PetscViewerFileSetName(*viewer,loc1_fname);CHKERRQ(ierr);
+        }
+      }
+      if (loc2_fmt && *loc2_fmt) {
+        ierr = PetscEnumFind(PetscViewerFormats,loc2_fmt,(PetscEnum*)format,&flag);CHKERRQ(ierr);
+        if (!flag) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SUP,"Unknown viewer format %s",loc2_fmt);CHKERRQ(ierr);
+      }
+      ierr = PetscViewerSetUp(*viewer);CHKERRQ(ierr);
+      ierr = PetscFree(loc0_vtype);CHKERRQ(ierr);
+    }
+  }
+  PetscFunctionReturn(0);
+}
+
+#endif
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.