Exemple #1
0
PetscErrorCode MyPetscReadExodusII(MPI_Comm comm,const char filename[],DM dmBody,DM dmFS)
{
  ALE::Obj<PETSC_MESH_TYPE>               meshBody,meshFS;
  typedef ALE::Mesh<PetscInt,PetscScalar> FlexMesh;
  //typedef std::set<FlexMesh::point_type>  PointSet;
  //ALE::Obj<FlexMesh>  boundarymesh;
  PetscMPIInt         rank;
  int                 CPU_word_size = 0;
  int                 IO_word_size  = 0;
  PetscBool           interpolate   = PETSC_FALSE;
  int               **connect = PETSC_NULL;
  int                 exoid;
  char                title[MAX_LINE_LENGTH+1];
  float               version;
  int                 num_dim,num_nodes = 0,num_elem = 0;
  int                 num_eb = 0,num_ns = 0,num_ss = 0;
  PetscErrorCode      ierr;
  //const char          known_elements[] = "tri,tri3,triangle,triangle3,quad,quad4,tet,tet4,tetra,tetra4,hex,hex8";
  float              *x = PETSC_NULL,*y = PETSC_NULL,*z = PETSC_NULL;
  PetscBool           debug = PETSC_FALSE;

  PetscFunctionBegin;
  ierr = PetscOptionsGetBool(PETSC_NULL,"-interpolate",&interpolate,PETSC_NULL);CHKERRQ(ierr);

  /*
    Get the sieve meshes from the dms
  */
  ierr = DMMeshGetMesh(dmBody,meshBody);CHKERRQ(ierr);
  ierr = DMMeshGetMesh(dmFS,meshFS);CHKERRQ(ierr);
  rank = meshBody->commRank();

  /*
    Open EXODUS II file and read basic informations on rank 0,
    then broadcast to all nodes
  */
  if (rank == 0) {
    exoid = ex_open(filename,EX_READ,&CPU_word_size,&IO_word_size,&version);CHKERRQ(!exoid);
    ierr = ex_get_init(exoid,title,&num_dim,&num_nodes,&num_elem,&num_eb,&num_ns,&num_ss);CHKERRQ(ierr);
    if (num_eb == 0) {
      SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"Exodus file does not contain any element block\n");
    }
    ierr = PetscMalloc3(num_nodes,float,&x,num_nodes,float,&y,num_nodes,float,&z);CHKERRQ(ierr);
    ierr = ex_get_coord(exoid,x,y,z);CHKERRQ(ierr);
  }
Exemple #2
0
int main (int argc,char ** argv) {
  DM             dmBody,dmFS;
  DM             dmBodyDist,dmFSDist;
  ALE::Obj<PETSC_MESH_TYPE> meshBody,meshBodyDist,meshFS,meshFSDist;
  PetscBool      inflag,outflag;
  char           infilename[PETSC_MAX_PATH_LEN+1],outfilename[PETSC_MAX_PATH_LEN+1];
  PetscViewer    viewer;
  int            rank,numproc;
  PetscErrorCode ierr;

  ierr = PetscInitialize(&argc,&argv,(char *)0,help);CHKERRQ(ierr);
  ierr = PetscOptionsGetString(PETSC_NULL,"-i",infilename,PETSC_MAX_PATH_LEN,&inflag);CHKERRQ(ierr);
  ierr = MPI_Comm_size(PETSC_COMM_WORLD,&numproc);
  ierr = MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
  if (inflag) {
    ierr = MyDMMeshCreateExodus(PETSC_COMM_WORLD,infilename,&dmBody,&dmFS);CHKERRQ(ierr);
    ierr = DMMeshGetMesh(dmBody,meshBody);CHKERRQ(ierr);
    meshBody->view("meshBody");

    ierr = DMMeshGetMesh(dmFS,meshFS);CHKERRQ(ierr);
    meshFS->view("meshFS");

    if (numproc > 1) {
      ierr = DMMeshDistribute(dmBody,PETSC_NULL,&dmBodyDist);CHKERRQ(ierr);
      //ierr = DMMeshDistribute(dmFS,PETSC_NULL,&dmFSDist);CHKERRQ(ierr);
      ierr = DMMeshGetMesh(dmBodyDist,meshBodyDist);CHKERRQ(ierr);
      meshBodyDist->view("meshBodyDist");
      //ierr = DMMeshGetMesh(dmFSDist,meshFSDist);CHKERRQ(ierr);
      //meshFSDist->view("meshFS");

      //ierr = DMDestroy(&dmBodyDist);CHKERRQ(ierr);
      //ierr = DMDestroy(&dmFSDist);CHKERRQ(ierr);
    }

    //ierr = DMDestroy(&dmBody);CHKERRQ(ierr);
    //ierr = DMDestroy(&dmFS);CHKERRQ(ierr);
  } else {
    ierr = PetscPrintf(PETSC_COMM_WORLD,"No file name given\n");CHKERRQ(ierr);
  }
  ierr = PetscFinalize();
  return 0;
}
Exemple #3
0
PetscErrorCode DMMeshConvertOverlapToSF(DM dm, PetscSF *sf)
{
    ALE::Obj<PETSC_MESH_TYPE> mesh;
    PetscInt                  *local;
    PetscSFNode               *remote;
    PetscInt                  numPoints;
    PetscErrorCode            ierr;

    PetscFunctionBegin;
    ierr = PetscSFCreate(((PetscObject) dm)->comm, sf);
    CHKERRQ(ierr);
    ierr = DMMeshGetMesh(dm, mesh);
    CHKERRQ(ierr);
    {
        /* The local points have degree 1
             We use the recv overlap
        */
        ALE::Obj<PETSC_MESH_TYPE::recv_overlap_type> overlap = mesh->getRecvOverlap();

        numPoints = overlap->getNumPoints();
        ierr      = PetscMalloc(numPoints * sizeof(PetscInt), &local);
        CHKERRQ(ierr);
        ierr      = PetscMalloc(numPoints * sizeof(PetscSFNode), &remote);
        CHKERRQ(ierr);
        for (PetscInt r = 0, i = 0; r < overlap->getNumRanks(); ++r) {
            const PetscInt                                                      rank   = overlap->getRank(r);
            const PETSC_MESH_TYPE::recv_overlap_type::supportSequence::iterator cBegin = overlap->supportBegin(rank);
            const PETSC_MESH_TYPE::recv_overlap_type::supportSequence::iterator cEnd   = overlap->supportEnd(rank);

            for (PETSC_MESH_TYPE::recv_overlap_type::supportSequence::iterator c_iter = cBegin; c_iter != cEnd; ++c_iter, ++i) {
                local[i]        = *c_iter;
                remote[i].rank  = rank;
                remote[i].index = c_iter.color();
            }
        }
        ierr = PetscSFSetGraph(*sf, numPoints, numPoints, local, PETSC_OWN_POINTER, remote, PETSC_OWN_POINTER);
        CHKERRQ(ierr);
        ierr = PetscSFView(*sf, NULL);
        CHKERRQ(ierr);
    }
    PetscFunctionReturn(0);
}
Exemple #4
0
int main (int argc,char ** argv) {
  DM              dmBody,dmFS;
  PetscBool       inflag;
  char            infilename[PETSC_MAX_PATH_LEN+1];
  PetscErrorCode  ierr;
  SectionReal     sec1;
  Mat             mat1;
  PetscInt        dof=1;
  int             rank;
  PetscInt        cell,face,conesize,my_num_cells,my_num_faces,my_num_vertices;
  PetscInt        i,j,c,d,k;
  PetscReal      *m_array;


  ierr = PetscInitialize(&argc,&argv,(char *)0,help);CHKERRQ(ierr);
  ierr = MPI_Comm_rank(PETSC_COMM_WORLD,&rank);

  ierr = PetscOptionsGetString(PETSC_NULL,"-i",infilename,PETSC_MAX_PATH_LEN,&inflag);CHKERRQ(ierr);
  if (!inflag) {
    ierr = PetscPrintf(PETSC_COMM_WORLD,"No file name given\n");CHKERRQ(ierr);
    PetscFinalize();
    return 0;
  }

  /*
    Reads a mesh
  */  
  ierr = DMMeshCreateExodusNG(PETSC_COMM_WORLD,infilename,&dmBody,&dmFS);CHKERRQ(ierr);

  ierr = PetscOptionsGetInt(PETSC_NULL,"-dof",&dof,PETSC_NULL);CHKERRQ(ierr);
  ierr = DMMeshSetMaxDof(dmBody,dof);CHKERRQ(ierr);
  ierr = DMMeshSetMaxDof(dmFS,dof);CHKERRQ(ierr);

  /*
    Testing matrices
  */
  {
    ALE::Obj<PETSC_MESH_TYPE> meshBody,meshFS;
    ierr = DMMeshGetMesh(dmBody,meshBody);CHKERRQ(ierr);
    ierr = DMMeshGetMesh(dmFS,meshFS);CHKERRQ(ierr);
    my_num_cells    = meshBody->heightStratum(0)->size();
    my_num_vertices = meshBody->depthStratum(0)->size();
    my_num_faces    = meshFS->heightStratum(0)->size();
  }


  ierr = DMMeshGetVertexSectionReal(dmBody,"sec1",dof,&sec1);CHKERRQ(ierr);
  ierr = DMMeshCreateMatrix(dmBody,sec1,MATMPIAIJ,&mat1);CHKERRQ(ierr);  
  for (cell = 0; cell < my_num_cells; cell++) {
    ierr = DMMeshGetConeSize(dmBody,cell,&conesize);CHKERRQ(ierr);
    ierr = PetscMalloc(conesize*dof*conesize*dof*sizeof(PetscReal),&m_array);CHKERRQ(ierr);
    for (k = 0,i = 0; i < conesize; i++) {
      for (c = 0; c < dof; c++) {
        for (j = 0; j < conesize; j++) {
          for (d = 0; d < dof; d++,k++) {
            m_array[k] = 1.;
          }
        }
      }
    }
    ierr = DMMeshAssembleMatrix(mat1,dmBody,sec1,cell,m_array,ADD_VALUES);CHKERRQ(ierr);        
    ierr = PetscFree(m_array);CHKERRQ(ierr);
  }
  ierr = MatAssemblyBegin(mat1,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
  ierr = MatAssemblyEnd(mat1,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
  ierr = PetscPrintf(PETSC_COMM_WORLD,"\n==================== Matrix on body mesh\n");
  ierr = MatView(mat1,PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr);
  
  ierr = MatZeroEntries(mat1);CHKERRQ(ierr);
  for (face = 0; face < my_num_faces; face++) {
    ierr = DMMeshGetConeSize(dmFS,face,&conesize);CHKERRQ(ierr);
    ierr = PetscMalloc(conesize*dof*conesize*dof*sizeof(PetscReal),&m_array);CHKERRQ(ierr);
    for (k = 0,i = 0; i < conesize; i++) {
      for (c = 0; c < dof; c++) {
        for (j = 0; j < conesize; j++) {
          for (d = 0; d < dof; d++,k++) {
            m_array[k] = 1.;
          }
        }
      }
    }
    ierr = DMMeshAssembleMatrix(mat1,dmFS,sec1,face,m_array,ADD_VALUES);CHKERRQ(ierr);        
    ierr = PetscFree(m_array);CHKERRQ(ierr);
    ierr = MatAssemblyBegin(mat1,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
    ierr = MatAssemblyEnd(mat1,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
    ierr = PetscPrintf(PETSC_COMM_WORLD,"\n==================== Matrix on FS mesh\n");
    ierr = MatView(mat1,PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr);
  }    

  ierr = SectionRealDestroy(&sec1);CHKERRQ(ierr);
  ierr = MatDestroy(&mat1);CHKERRQ(ierr);
  ierr = DMDestroy(&dmBody);CHKERRQ(ierr);  
  ierr = DMDestroy(&dmFS);CHKERRQ(ierr);  

  ierr = PetscFinalize();
  return 0;
}