Lisandro Dalcin avatar Lisandro Dalcin committed f4a2595

Add layout to IGA structure

Comments (0)

Files changed (5)

   PetscInt  node_gwidth[3];
   DM        node_dm;
 
-  AO         ao,aob;
-  LGMap      lgmap,lgmapb;
-  VecScatter g2l,l2g;
-  PetscInt   nwork;
-  Vec        vwork[16];
-  Vec        natural;
-  VecScatter n2g,g2n;
+  AO          ao,aob;
+  LGMap       lgmap,lgmapb;
+  PetscLayout map;
+  VecScatter  g2l,l2g;
+  PetscInt    nwork;
+  Vec         vwork[16];
+  Vec         natural;
+  VecScatter  n2g,g2n;
 };
 
 PETSC_EXTERN PetscClassId IGA_CLASSID;
   ierr = AODestroy(&iga->aob);CHKERRQ(ierr);
   ierr = ISLocalToGlobalMappingDestroy(&iga->lgmap);CHKERRQ(ierr);
   ierr = ISLocalToGlobalMappingDestroy(&iga->lgmapb);CHKERRQ(ierr);
+  ierr = PetscLayoutDestroy(&iga->map);CHKERRQ(ierr);
   ierr = VecScatterDestroy(&iga->g2l);CHKERRQ(ierr);
   ierr = VecScatterDestroy(&iga->l2g);CHKERRQ(ierr);
   ierr = VecDestroy(&iga->natural);CHKERRQ(ierr);
   ierr = AODestroy(&iga->aob);CHKERRQ(ierr);
   ierr = ISLocalToGlobalMappingDestroy(&iga->lgmap);CHKERRQ(ierr);
   ierr = ISLocalToGlobalMappingDestroy(&iga->lgmapb);CHKERRQ(ierr);
+  ierr = PetscLayoutDestroy(&iga->map);CHKERRQ(ierr);
   ierr = VecScatterDestroy(&iga->g2l);CHKERRQ(ierr);
   ierr = VecScatterDestroy(&iga->l2g);CHKERRQ(ierr);
   ierr = VecDestroy(&iga->natural);CHKERRQ(ierr);
     ierr = PetscObjectReference((PetscObject)iga->lgmap);CHKERRQ(ierr);
     ierr = IGA_Grid_GetLGMapBlock(grid,&iga->lgmapb);CHKERRQ(ierr);
     ierr = PetscObjectReference((PetscObject)iga->lgmapb);CHKERRQ(ierr);
+    /* build the layout */
+    ierr = IGA_Grid_GetLayout(grid,&iga->map);CHKERRQ(ierr);
+    ierr = PetscLayoutReference(iga->map,&iga->map);CHKERRQ(ierr);
     /* build global <-> local vector scatters */
     ierr = IGA_Grid_GetScatterG2L(grid,&iga->g2l);CHKERRQ(ierr);
     ierr = PetscObjectReference((PetscObject)iga->g2l);CHKERRQ(ierr);
 }
 
 #undef  __FUNCT__
+#define __FUNCT__ "IGA_Grid_GetLayout"
+PetscErrorCode IGA_Grid_GetLayout(IGA_Grid g,PetscLayout *map)
+{
+  PetscErrorCode ierr;
+  PetscFunctionBegin;
+  PetscValidPointer(g,1);
+  PetscValidPointer(map,2);
+  if (!g->map) {
+    const PetscInt *sizes = g->sizes;
+    const PetscInt *width = g->local_width;
+    PetscInt bs = g->dof;
+    PetscInt n  = bs*width[0]*width[1]*width[2];
+    PetscInt N  = bs*sizes[0]*sizes[1]*sizes[2];
+    ierr = PetscLayoutCreate(g->comm,&g->map);CHKERRQ(ierr);
+    ierr = PetscLayoutSetBlockSize(g->map,bs);CHKERRQ(ierr);
+    ierr = PetscLayoutSetLocalSize(g->map,n);CHKERRQ(ierr);
+    ierr = PetscLayoutSetSize(g->map,N);CHKERRQ(ierr);
+    ierr = IGA_Grid_GetLGMap(g,&g->lgmap);CHKERRQ(ierr);
+    ierr = IGA_Grid_GetLGMapBlock(g,&g->lgmapb);CHKERRQ(ierr);
+    ierr = PetscLayoutSetISLocalToGlobalMapping(g->map,g->lgmap);CHKERRQ(ierr);
+    ierr = PetscLayoutSetISLocalToGlobalMappingBlock(g->map,g->lgmapb);
+    ierr = PetscLayoutSetUp(g->map);CHKERRQ(ierr);
+  }
+  *map = g->map;
+  PetscFunctionReturn(0);
+}
+
+#undef  __FUNCT__
 #define __FUNCT__ "IGA_Grid_GetVecLocal"
 PetscErrorCode IGA_Grid_GetVecLocal(IGA_Grid g,const VecType vtype,Vec *lvec)
 {
 typedef struct _n_IGA_Grid *IGA_Grid;
 
 struct _n_IGA_Grid {
-  MPI_Comm   comm;
-  PetscInt   dim,dof;
-  PetscInt   sizes[3];
-  PetscInt   local_start[3];
-  PetscInt   local_width[3];
-  PetscInt   ghost_start[3];
-  PetscInt   ghost_width[3];
-  AO         ao,aob;
-  LGMap      lgmap,lgmapb;
-  Vec        lvec,gvec,nvec;
-  VecScatter g2l,l2g,g2n;
+  MPI_Comm    comm;
+  PetscInt    dim,dof;
+  PetscInt    sizes[3];
+  PetscInt    local_start[3];
+  PetscInt    local_width[3];
+  PetscInt    ghost_start[3];
+  PetscInt    ghost_width[3];
+  AO          ao,aob;
+  LGMap       lgmap,lgmapb;
+  PetscLayout map;
+  Vec         lvec,gvec,nvec;
+  VecScatter  g2l,l2g,g2n;
 };
 
 PETSC_EXTERN PetscErrorCode IGA_Grid_Create(MPI_Comm,IGA_Grid*);
 PETSC_EXTERN PetscErrorCode IGA_Grid_SetLGMapBlock(IGA_Grid,LGMap);
 PETSC_EXTERN PetscErrorCode IGA_Grid_GetLGMapBlock(IGA_Grid,LGMap*);
 PETSC_EXTERN PetscErrorCode IGA_Grid_GetLGMap(IGA_Grid,LGMap*);
+PETSC_EXTERN PetscErrorCode IGA_Grid_GetLayout(IGA_Grid,PetscLayout*);
 PETSC_EXTERN PetscErrorCode IGA_Grid_GetVecLocal  (IGA_Grid,const VecType,Vec*);
 PETSC_EXTERN PetscErrorCode IGA_Grid_GetVecGlobal (IGA_Grid,const VecType,Vec*);
 PETSC_EXTERN PetscErrorCode IGA_Grid_GetVecNatural(IGA_Grid,const VecType,Vec*);
 #endif
 
 #undef  __FUNCT__
+#define __FUNCT__ "VecClearDM"
+static PetscErrorCode VecClearDM(Vec v)
+{
+#if PETSC_VERSION_LE(3,3,0)
+  const char name[] = "DM";
+#else
+  const char name[] = "__PETSc_dm";
+#endif
+  PetscErrorCode ierr;
+  PetscFunctionBegin;
+  PetscValidHeaderSpecific(v,VEC_CLASSID,1);
+  ierr = PetscObjectCompose((PetscObject)v,name,NULL);CHKERRQ(ierr);
+  PetscFunctionReturn(0);
+}
+
+
+#undef  __FUNCT__
 #define __FUNCT__ "VecDuplicate_IGA"
 static PetscErrorCode VecDuplicate_IGA(Vec g,Vec* gg)
 {
   PetscFunctionBegin;
   ierr = PetscObjectQuery((PetscObject)g,"IGA",(PetscObject*)&iga);CHKERRQ(ierr);
   ierr = IGACreateVec(iga,gg);CHKERRQ(ierr);
-  ierr = PetscLayoutReference(g->map,&(*gg)->map);CHKERRQ(ierr);
   PetscFunctionReturn(0);
 }
 
   ierr = IGAGetNodeDM(iga,&dm);CHKERRQ(ierr);
   ierr = VecSetDM(v,dm);CHKERRQ(ierr);
   ierr = VecView_MPI_DA(v,viewer);CHKERRQ(ierr);
+  ierr = VecClearDM(v);CHKERRQ(ierr);
   PetscFunctionReturn(0);
 }
 #undef  __FUNCT__
   ierr = IGAGetNodeDM(iga,&dm);CHKERRQ(ierr);
   ierr = VecSetDM(v,dm);CHKERRQ(ierr);
   ierr = VecLoad_Default_DA(v,viewer);CHKERRQ(ierr);
+  ierr = VecClearDM(v);CHKERRQ(ierr);
   PetscFunctionReturn(0);
 }
 
 @*/
 PetscErrorCode IGACreateVec(IGA iga, Vec *vec)
 {
-  PetscInt       bs,n,N;
   PetscErrorCode ierr;
   PetscFunctionBegin;
   PetscValidHeaderSpecific(iga,IGA_CLASSID,1);
   PetscValidPointer(vec,2);
   IGACheckSetUp(iga,1);
-  /* */
-  bs = iga->dof;
-  N  = Product(iga->node_sizes);
-  n  = Product(iga->node_lwidth);
   ierr = VecCreate(((PetscObject)iga)->comm,vec);CHKERRQ(ierr);
-  ierr = VecSetSizes(*vec,n*bs,N*bs);CHKERRQ(ierr);
-  ierr = VecSetBlockSize(*vec,bs);CHKERRQ(ierr);
+  ierr = VecSetLayout(*vec,iga->map);CHKERRQ(ierr);
   ierr = VecSetType(*vec,iga->vectype);CHKERRQ(ierr);
   ierr = VecSetFromOptions(*vec);CHKERRQ(ierr);
-  ierr = VecSetLocalToGlobalMapping(*vec,iga->lgmap);CHKERRQ(ierr);
-  ierr = VecSetLocalToGlobalMappingBlock(*vec,iga->lgmapb);CHKERRQ(ierr);
   ierr = PetscObjectCompose((PetscObject)*vec,"IGA",(PetscObject)iga);CHKERRQ(ierr);
   ierr = VecSetOperation(*vec,VECOP_DUPLICATE,(void(*)(void))VecDuplicate_IGA);CHKERRQ(ierr);
   ierr = VecSetOperation(*vec,VECOP_VIEW,(void(*)(void))VecView_IGA);CHKERRQ(ierr);
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.