Exemplo n.º 1
0
hypre_StructMatrix *
hypre_StructMatrixCreate( MPI_Comm             comm,
                          hypre_StructGrid    *grid,
                          hypre_StructStencil *user_stencil )
{
    hypre_StructMatrix  *matrix;

    int                  i;

    matrix = hypre_CTAlloc(hypre_StructMatrix, 1);

    hypre_StructMatrixComm(matrix)        = comm;
    hypre_StructGridRef(grid, &hypre_StructMatrixGrid(matrix));
    hypre_StructMatrixUserStencil(matrix) =
        hypre_StructStencilRef(user_stencil);
    hypre_StructMatrixDataAlloced(matrix) = 1;
    hypre_StructMatrixRefCount(matrix)    = 1;

    /* set defaults */
    hypre_StructMatrixSymmetric(matrix) = 0;
    for (i = 0; i < 6; i++)
        hypre_StructMatrixNumGhost(matrix)[i] = 0;

    return matrix;
}
Exemplo n.º 2
0
int
hypre_StructMatrixDestroy( hypre_StructMatrix *matrix )
{
    int  i;
    int  ierr = 0;

    if (matrix)
    {
        hypre_StructMatrixRefCount(matrix) --;
        if (hypre_StructMatrixRefCount(matrix) == 0)
        {
            if (hypre_StructMatrixDataAlloced(matrix))
            {
                hypre_SharedTFree(hypre_StructMatrixData(matrix));
            }
            hypre_CommPkgDestroy(hypre_StructMatrixCommPkg(matrix));

            hypre_ForBoxI(i, hypre_StructMatrixDataSpace(matrix))
            hypre_TFree(hypre_StructMatrixDataIndices(matrix)[i]);
            hypre_TFree(hypre_StructMatrixDataIndices(matrix));

            hypre_BoxArrayDestroy(hypre_StructMatrixDataSpace(matrix));

            hypre_TFree(hypre_StructMatrixSymmElements(matrix));
            hypre_StructStencilDestroy(hypre_StructMatrixUserStencil(matrix));
            hypre_StructStencilDestroy(hypre_StructMatrixStencil(matrix));
            hypre_StructGridDestroy(hypre_StructMatrixGrid(matrix));

            hypre_TFree(matrix);
        }
    }

    return ierr;
}
Exemplo n.º 3
0
hypre_StructMatrix *
hypre_StructMatrixCreateMask( hypre_StructMatrix *matrix,
                              int                 num_stencil_indices,
                              int                *stencil_indices     )
{
   hypre_StructMatrix   *mask;

   hypre_StructStencil  *stencil;
   hypre_Index          *stencil_shape;
   int                   stencil_size;
   hypre_Index          *mask_stencil_shape;
   int                   mask_stencil_size;

   hypre_BoxArray       *data_space;
   int                 **data_indices;
   int                 **mask_data_indices;

   int                   i, j;

   stencil       = hypre_StructMatrixStencil(matrix);
   stencil_shape = hypre_StructStencilShape(stencil);
   stencil_size  = hypre_StructStencilSize(stencil);

   mask = hypre_CTAlloc(hypre_StructMatrix, 1);

   hypre_StructMatrixComm(mask) = hypre_StructMatrixComm(matrix);

   hypre_StructGridRef(hypre_StructMatrixGrid(matrix),
                       &hypre_StructMatrixGrid(mask));

   hypre_StructMatrixUserStencil(mask) =
      hypre_StructStencilRef(hypre_StructMatrixUserStencil(matrix));

   mask_stencil_size  = num_stencil_indices;
   mask_stencil_shape = hypre_CTAlloc(hypre_Index, num_stencil_indices);
   for (i = 0; i < num_stencil_indices; i++)
   {
      hypre_CopyIndex(stencil_shape[stencil_indices[i]],
                      mask_stencil_shape[i]);
   }
   hypre_StructMatrixStencil(mask) =
      hypre_StructStencilCreate(hypre_StructStencilDim(stencil),
                                mask_stencil_size,
                                mask_stencil_shape);

   hypre_StructMatrixNumValues(mask) = hypre_StructMatrixNumValues(matrix);

   hypre_StructMatrixDataSpace(mask) =
      hypre_BoxArrayDuplicate(hypre_StructMatrixDataSpace(matrix));

   hypre_StructMatrixData(mask) = hypre_StructMatrixData(matrix);
   hypre_StructMatrixDataAlloced(mask) = 0;
   hypre_StructMatrixDataSize(mask) = hypre_StructMatrixDataSize(matrix);
   data_space   = hypre_StructMatrixDataSpace(matrix);
   data_indices = hypre_StructMatrixDataIndices(matrix);
   mask_data_indices = hypre_CTAlloc(int *, hypre_BoxArraySize(data_space));
   hypre_ForBoxI(i, data_space)
      {
         mask_data_indices[i] = hypre_TAlloc(int, num_stencil_indices);
         for (j = 0; j < num_stencil_indices; j++)
         {
            mask_data_indices[i][j] = data_indices[i][stencil_indices[j]];
         }
      }