Lisandro Dalcin avatar Lisandro Dalcin committed 56af433

Add IGASet{Vec|Mat}Type()

Comments (0)

Files changed (4)

 struct _p_IGA {
   PETSCHEADER(struct _IGAOps);
   IGAUserOps userops;
+  VecType    vectype;
+  MatType    mattype;
 
   PetscBool setup;
   PetscInt  dim;
 extern PetscErrorCode IGAGetDofDM(IGA iga,DM *dm_dof);
 extern PetscErrorCode IGAGetGeomDM(IGA iga,DM *dm_geom);
 
+extern PetscErrorCode IGASetVecType(IGA iga,const VecType vectype);
+extern PetscErrorCode IGASetMatType(IGA iga,const MatType mattype);
+
 extern PetscErrorCode IGACreateVec(IGA iga,Vec *vec);
 extern PetscErrorCode IGACreateMat(IGA iga,Mat *mat);
 
 #include "petiga.h"
 
+#include "private/matimpl.h"
+#include "private/dmimpl.h"
+#undef  __FUNCT__
+#define __FUNCT__ "DMSetMatType"
+static
+PetscErrorCode DMSetMatType(DM dm,const MatType mattype)
+{
+  PetscErrorCode ierr;
+  PetscFunctionBegin;
+  PetscValidHeaderSpecific(dm,DM_CLASSID,1);
+  ierr = PetscFree(dm->mattype);CHKERRQ(ierr);
+  ierr = PetscStrallocpy(mattype,&dm->mattype);CHKERRQ(ierr);
+  PetscFunctionReturn(0);
+}
+
 #undef  __FUNCT__
 #define __FUNCT__ "IGACreate"
 PetscErrorCode IGACreate(MPI_Comm comm,IGA *_iga)
   *_iga = iga;
 
   ierr = PetscNew(struct _IGAUserOps,&iga->userops);CHKERRQ(ierr);
+  iga->vectype = PETSC_NULL;
+  iga->mattype = PETSC_NULL;
 
   iga->dim = -1;
   iga->dof = -1;
   if (--((PetscObject)iga)->refct > 0) PetscFunctionReturn(0);;
   
   ierr = PetscFree(iga->userops);CHKERRQ(ierr);
+  ierr = PetscFree(iga->vectype);CHKERRQ(ierr);
+  ierr = PetscFree(iga->mattype);CHKERRQ(ierr);
   for (i=0; i<3; i++) {
     ierr = IGAAxisDestroy(&iga->axis[i]);CHKERRQ(ierr);
     ierr = IGARuleDestroy(&iga->rule[i]);CHKERRQ(ierr);
   PetscErrorCode ierr;
   PetscFunctionBegin;
   PetscValidHeaderSpecific(iga,IGA_CLASSID,1);
-  ierr = PetscObjectOptionsBegin((PetscObject)iga);CHKERRQ(ierr);
   {
-
+    PetscBool flg;
+    char vtype[256] = VECSTANDARD;
+    char mtype[256] = MATBAIJ;
+    if (iga->vectype) {ierr= PetscStrcpy(vtype,iga->vectype);CHKERRQ(ierr);}
+    if (iga->mattype) {ierr= PetscStrcpy(mtype,iga->mattype);CHKERRQ(ierr);}
+    ierr = PetscObjectOptionsBegin((PetscObject)iga);CHKERRQ(ierr);
+    ierr = PetscOptionsList("-iga_vec_type","Vector type","VecSetType",VecList,vtype,vtype,sizeof vtype,&flg);CHKERRQ(ierr);
+    if (flg) {ierr= IGASetVecType(iga,vtype);CHKERRQ(ierr);}
+    ierr = PetscOptionsList("-iga_mat_type","Matrix type","MatSetType",MatList,mtype,mtype,sizeof mtype,&flg);CHKERRQ(ierr);
+    if (flg) {ierr= IGASetMatType(iga,mtype);CHKERRQ(ierr);}
+    ierr = PetscObjectProcessOptionsHandlers((PetscObject)iga);CHKERRQ(ierr);
+    ierr = PetscOptionsEnd();CHKERRQ(ierr);
   }
-  ierr = PetscObjectProcessOptionsHandlers((PetscObject)iga);CHKERRQ(ierr);
-  ierr = PetscOptionsEnd();CHKERRQ(ierr);
   PetscFunctionReturn(0);
 }
 
     }
   }
 
+  if (!iga->vectype) {
+    const MatType vtype = VECSTANDARD;
+    ierr = PetscStrallocpy(vtype,&iga->vectype);CHKERRQ(ierr);
+  }
+  if (!iga->mattype) {
+    const MatType mtype = (iga->dof > 1) ? MATBAIJ : MATAIJ;
+    ierr = PetscStrallocpy(mtype,&iga->mattype);CHKERRQ(ierr);
+  }
+
   {
     PetscInt swidth, sizes[3];
     DMDABoundaryType btype[3];
     ierr = DMDASetStencilWidth(iga->dm_dof,swidth); CHKERRQ(ierr);
     /*ierr = DMSetOptionsPrefix(iga->dm_dof, "dof_"); CHKERRQ(ierr);*/
     /*ierr = DMSetFromOptions(iga->dm_dof); CHKERRQ(ierr);*/
+    ierr = DMSetVecType(iga->dm_dof,iga->vectype);CHKERRQ(ierr);
+    ierr = DMSetMatType(iga->dm_dof,iga->mattype);CHKERRQ(ierr);
     ierr = DMSetUp(iga->dm_dof);CHKERRQ(ierr);
   }
 
 }
 
 #undef  __FUNCT__
+#define __FUNCT__ "IGASetVecType"
+PetscErrorCode IGASetVecType(IGA iga,const VecType vectype)
+{
+  PetscErrorCode ierr;
+  PetscFunctionBegin;
+  PetscValidHeaderSpecific(iga,IGA_CLASSID,1);
+  PetscValidCharPointer(vectype,2);
+  ierr = PetscFree(iga->vectype);CHKERRQ(ierr);
+  ierr = PetscStrallocpy(vectype,&iga->vectype);CHKERRQ(ierr);
+  if (iga->dm_dof) {
+    ierr = DMSetVecType(iga->dm_dof,iga->vectype);CHKERRQ(ierr);
+  }
+  PetscFunctionReturn(0);
+}
+
+#undef  __FUNCT__
+#undef  __FUNCT__
+#define __FUNCT__ "IGASetMatType"
+PetscErrorCode IGASetMatType(IGA iga,const MatType mattype)
+{
+  PetscErrorCode ierr;
+  PetscFunctionBegin;
+  PetscValidHeaderSpecific(iga,IGA_CLASSID,1);
+  PetscValidCharPointer(mattype,2);
+  ierr = PetscFree(iga->mattype);CHKERRQ(ierr);
+  ierr = PetscStrallocpy(mattype,&iga->mattype);CHKERRQ(ierr);
+  if (iga->dm_dof) {
+    ierr = DMSetMatType(iga->dm_dof,iga->mattype);CHKERRQ(ierr);
+  }
+  PetscFunctionReturn(0);
+}
+
+#undef  __FUNCT__
 #define __FUNCT__ "IGACreateVec"
 PetscErrorCode IGACreateVec(IGA iga, Vec *vec)
 {
 #define __FUNCT__ "IGACreateMat"
 PetscErrorCode IGACreateMat(IGA iga, Mat *mat)
 {
-  const MatType mat_type = 0;
   PetscErrorCode ierr;
   PetscFunctionBegin;
   PetscValidHeaderSpecific(iga,IGA_CLASSID,1);
   PetscValidPointer(mat,2);
-  mat_type = (iga->dof > 1) ? MATBAIJ : MATAIJ;
-  ierr = DMGetMatrix(iga->dm_dof,mat_type,mat);CHKERRQ(ierr);
+  ierr = DMGetMatrix(iga->dm_dof,iga->mattype,mat);CHKERRQ(ierr);
+  ierr = MatSetOption(*mat,MAT_NEW_NONZERO_LOCATION_ERR,PETSC_TRUE);CHKERRQ(ierr);
+  /*ierr = MatSetOption(*mat,MAT_KEEP_NONZERO_PATTERN,PETSC_TRUE);CHKERRQ(ierr);*/
+  {
+    PetscInt bs;
+    ierr = DMGetBlockSize(iga->dm_dof,&bs);CHKERRQ(ierr);
+    ierr = PetscLayoutSetBlockSize((*mat)->rmap,bs);CHKERRQ(ierr);
+    ierr = PetscLayoutSetBlockSize((*mat)->cmap,bs);CHKERRQ(ierr);
+  }
+  {
+    ISLocalToGlobalMapping ltog,ltogb;
+    ierr = DMGetLocalToGlobalMapping(iga->dm_dof,&ltog);CHKERRQ(ierr);
+    ierr = DMGetLocalToGlobalMappingBlock(iga->dm_dof,&ltogb);CHKERRQ(ierr);
+    ierr = MatSetLocalToGlobalMapping(*mat,ltog,ltog);CHKERRQ(ierr);
+    ierr = MatSetLocalToGlobalMappingBlock(*mat,ltogb,ltogb);CHKERRQ(ierr);
+  }
   PetscFunctionReturn(0);
 }
 

test/Test_SNES_2D.c

   ierr = IGASetUserFunction(iga,Function,0);CHKERRQ(ierr);
   ierr = IGASetUserJacobian(iga,Jacobian,0);CHKERRQ(ierr);
 
+  ierr = IGASetFromOptions(iga);CHKERRQ(ierr);
   ierr = IGASetUp(iga);CHKERRQ(ierr);
 
   Vec x;
-ALL:
+ALL: test-all
 
 CFLAGS          = #-g3 -Wall -Wextra -Wno-unused-parameter #-Wconversion
 FFLAGS          = #-g3 -Wall -Wextra -fcheck=all
 Test_SNES_2D: Test_SNES_2D.o chkopts
 	${CLINKER} -o $@ $< ${PETIGA_LIB}
 	${RM} -f $<
+
+OPTS=-nox -malloc_debug -malloc_dump
 runex1a_1:
-	-@${MPIEXEC} -n 1 ./Test_SNES_2D -p 1 -nox -malloc_debug -malloc_dump
+	-@${MPIEXEC} -n 1 ./Test_SNES_2D ${OPTS} -N 8 -p 1 -iga_mat_type aij
+	-@${MPIEXEC} -n 1 ./Test_SNES_2D ${OPTS} -N 8 -p 1 -iga_mat_type baij
+	-@${MPIEXEC} -n 1 ./Test_SNES_2D ${OPTS} -N 8 -p 1 -iga_mat_type sbaij -pc_type none
+	-@${MPIEXEC} -n 1 ./Test_SNES_2D ${OPTS} -N 4 -p 1 -iga_mat_type dense
 runex1a_4:
-	-@${MPIEXEC} -n 4 ./Test_SNES_2D -p 1 -nox -malloc_debug -malloc_dump
+	-@${MPIEXEC} -n 4 ./Test_SNES_2D ${OPTS} -N 8 -p 1 -iga_mat_type aij
+	-@${MPIEXEC} -n 4 ./Test_SNES_2D ${OPTS} -N 8 -p 1 -iga_mat_type baij
+	-@${MPIEXEC} -n 4 ./Test_SNES_2D ${OPTS} -N 8 -p 1 -iga_mat_type sbaij -pc_type none
+	-@${MPIEXEC} -n 4 ./Test_SNES_2D ${OPTS} -N 4 -p 1 -iga_mat_type dense
 runex1b_1:
-	-@${MPIEXEC} -n 1 ./Test_SNES_2D -p 2 -nox -malloc_debug -malloc_dump
+	-@${MPIEXEC} -n 1 ./Test_SNES_2D ${OPTS} -p 2
 runex1b_4:
-	-@${MPIEXEC} -n 4 ./Test_SNES_2D -p 2 -nox -malloc_debug -malloc_dump
+	-@${MPIEXEC} -n 4 ./Test_SNES_2D ${OPTS} -p 2
 runex1c_1:
-	-@${MPIEXEC} -n 1 ./Test_SNES_2D -p 3 -nox -malloc_debug -malloc_dump
+	-@${MPIEXEC} -n 1 ./Test_SNES_2D ${OPTS} -p 3
 runex1c_4:
-	-@${MPIEXEC} -n 4 ./Test_SNES_2D -p 3 -nox -malloc_debug -malloc_dump
+	-@${MPIEXEC} -n 4 ./Test_SNES_2D ${OPTS} -p 3
 
 Test_SNES_2D = Test_SNES_2D.PETSc  \
 	       runex1a_1 runex1a_4 \
 
 TESTEXAMPLES_C = $(Test_SNES_2D)
 TESTEXAMPLES_FORTRAN =
+test-all:
+	-@${OMAKE} tree ACTION=testexamples_C PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} PETIGA_DIR=${PETIGA_DIR}
+	-@if [ "${FC}" != "" ]; then \
+          ${OMAKE} tree ACTION=testexamples_Fortran PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} PETIGA_DIR=${PETIGA_DIR}; \
+          fi
+.PHONY: test-all
 
 test-build: Test_SNES_2D.PETSc
 	-@if [ "${PETSC_WITH_BATCH}" != "" ]; then \
 	      ${MPIEXEC} -n 3 ./Test_SNES_2D -nox -malloc_debug -malloc_dump; \
 	      ${MPIEXEC} -n 4 ./Test_SNES_2D -nox -malloc_debug -malloc_dump; \
 	    fi; \
-	    ${MAKE} Test_SNES_2D.rm PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} PETIGA_DIR=${PETIGA_DIR};\
+	    ${OMAKE} Test_SNES_2D.rm PETSC_ARCH=${PETSC_ARCH} PETSC_DIR=${PETSC_DIR} PETIGA_DIR=${PETIGA_DIR}; \
 	   fi
 .PHONY:test-build
 
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.