Commits

Lisandro Dalcin committed 8f003e0

DMIGA: Call VecSetDM() in created global and local vectors

  • Participants
  • Parent commits ef26220

Comments (0)

Files changed (2)

File src/petigadm.c

 #include <petiga.h>
 #include "petsc-private/dmimpl.h"
 
+#if PETSC_VERSION_LE(3,3,0)
+#undef  __FUNCT__
+#define __FUNCT__ "VecSetDM"
+static PetscErrorCode VecSetDM(Vec v,DM dm)
+{
+  PetscErrorCode ierr;
+  PetscFunctionBegin;
+  PetscValidHeaderSpecific(v,VEC_CLASSID,1);
+  if (dm) PetscValidHeaderSpecific(dm,DM_CLASSID,2);
+  ierr = PetscObjectCompose((PetscObject)v,"DM",(PetscObject)dm);CHKERRQ(ierr);
+  PetscFunctionReturn(0);
+}
+#endif
+
+#if PETSC_VERSION_(3,4,0)
+#define VecSetDM(v,dm) PetscObjectCompose((PetscObject)v,"__PETSc_dm",(PetscObject)dm)
+#endif
+
 typedef struct {
   IGA iga;
 } DM_IGA;
   if (vtype) iga->vectype = (char*)vtype;
   ierr = IGACreateVec(iga,gvec);CHKERRQ(ierr);
   if (vtype) iga->vectype = (char*)save;
+  ierr = VecSetDM(*gvec,dm);CHKERRQ(ierr);
   PetscFunctionReturn(0);
 }
 
   if (vtype) iga->vectype = (char*)vtype;
   ierr = IGACreateLocalVec(iga,lvec);CHKERRQ(ierr);
   if (vtype) iga->vectype = (char*)save;
+  ierr = VecSetDM(*lvec,dm);CHKERRQ(ierr);
   PetscFunctionReturn(0);
 }
 

File src/petigavec.c

 
 #if PETSC_VERSION_LE(3,3,0)
 #undef  __FUNCT__
+#define __FUNCT__ "VecGetDM"
+static PetscErrorCode VecGetDM(Vec v,DM *dm)
+{
+  PetscErrorCode ierr;
+  PetscFunctionBegin;
+  PetscValidHeaderSpecific(v,VEC_CLASSID,1);
+  PetscValidPointer(dm,2);
+  ierr = PetscObjectQuery((PetscObject)v,"DM",(PetscObject*)dm);CHKERRQ(ierr);
+  PetscFunctionReturn(0);
+}
+#undef  __FUNCT__
 #define __FUNCT__ "VecSetDM"
 static PetscErrorCode VecSetDM(Vec v,DM dm)
 {
 }
 #endif
 
-#if PETSC_VERSION_LE(3,4,0)
-#define VecSetDM(vec,dm) ((dm)?VecSetDM((vec),(dm)):0)
+#if PETSC_VERSION_(3,4,0)
+#define VecSetDM(v,dm) PetscObjectCompose((PetscObject)v,"__PETSc_dm",(PetscObject)dm)
 #endif
 
 
 static PetscErrorCode VecView_IGA(Vec v,PetscViewer viewer)
 {
   IGA            iga;
-  DM             dm;
+  DM             save,dm;
   PetscErrorCode ierr;
   PetscFunctionBegin;
+  ierr = VecGetDM(v,&save);CHKERRQ(ierr);
+  if (save) {ierr = PetscObjectReference((PetscObject)save);CHKERRQ(ierr);}
   ierr = PetscObjectQuery((PetscObject)v,"IGA",(PetscObject*)&iga);CHKERRQ(ierr);
   ierr = IGAGetNodeDM(iga,&dm);CHKERRQ(ierr);
   ierr = VecSetDM(v,dm);CHKERRQ(ierr);
   ierr = VecView_MPI_DA(v,viewer);CHKERRQ(ierr);
-  ierr = VecSetDM(v,NULL);CHKERRQ(ierr);
+  ierr = VecSetDM(v,save);CHKERRQ(ierr);
+  ierr = DMDestroy(&save);CHKERRQ(ierr);
   PetscFunctionReturn(0);
 }
 #undef  __FUNCT__
 static PetscErrorCode VecLoad_IGA(Vec v,PetscViewer viewer)
 {
   IGA            iga;
-  DM             dm;
+  DM             save,dm;
   PetscErrorCode ierr;
   PetscFunctionBegin;
+  ierr = VecGetDM(v,&save);CHKERRQ(ierr);
+  if (save) {ierr = PetscObjectReference((PetscObject)save);CHKERRQ(ierr);}
   ierr = PetscObjectQuery((PetscObject)v,"IGA",(PetscObject*)&iga);CHKERRQ(ierr);
   ierr = IGAGetNodeDM(iga,&dm);CHKERRQ(ierr);
   ierr = VecSetDM(v,dm);CHKERRQ(ierr);
   ierr = VecLoad_Default_DA(v,viewer);CHKERRQ(ierr);
-  ierr = VecSetDM(v,NULL);CHKERRQ(ierr);
+  ierr = VecSetDM(v,save);CHKERRQ(ierr);
+  ierr = DMDestroy(&save);CHKERRQ(ierr);
   PetscFunctionReturn(0);
 }