Esempio n. 1
0
/*--------------------------------------------------------------------------
 * hypre_SStructPMatrixInitialize
 *--------------------------------------------------------------------------*/
int
hypre_SStructPMatrixInitialize( hypre_SStructPMatrix *pmatrix )
{
    int                    nvars       = hypre_SStructPMatrixNVars(pmatrix);
    int                  **symmetric   = hypre_SStructPMatrixSymmetric(pmatrix);
    hypre_SStructPGrid    *pgrid       = hypre_SStructPMatrixPGrid(pmatrix);
    HYPRE_SStructVariable *vartypes    = hypre_SStructPGridVarTypes(pgrid);
    int                    ndim        = hypre_SStructPGridNDim(pgrid);

    int                    num_ghost[6]= {1, 1, 1, 1, 1, 1};
    hypre_StructMatrix    *smatrix;
    hypre_StructGrid      *sgrid;

    hypre_Index            varoffset;
    int                    vi, vj, d;

    for (vi = 0; vi < nvars; vi++)
    {
        /* use variable vi add_numghost */
        sgrid= hypre_SStructPGridSGrid(pgrid, vi);
        hypre_SStructVariableGetOffset(vartypes[vi], ndim, varoffset);

        for (vj = 0; vj < nvars; vj++)
        {
            smatrix = hypre_SStructPMatrixSMatrix(pmatrix, vi, vj);
            if (smatrix != NULL)
            {
                HYPRE_StructMatrixSetSymmetric(smatrix, symmetric[vi][vj]);
                hypre_StructMatrixSetNumGhost(smatrix, num_ghost);

                for (d = 0; d < 3; d++)
                {
                    hypre_StructMatrixAddNumGhost(smatrix)[2*d]=
                        hypre_IndexD(varoffset, d);
                    hypre_StructMatrixAddNumGhost(smatrix)[2*d+1]=
                        hypre_IndexD(varoffset, d);
                }

                hypre_StructMatrixInitialize(smatrix);
            }
        }
    }

    return hypre_error_flag;
}
void
CCDivGradHypreLevelSolver::allocateHypreData()
{
    // Get the MPI communicator.
#ifdef HAVE_MPI
    MPI_Comm communicator = SAMRAI_MPI::getCommunicator();
#else
    MPI_Comm communicator;
#endif

    // Setup the hypre grid.
    Pointer<PatchLevel<NDIM> > level = d_hierarchy->getPatchLevel(d_level_num);
    Pointer<CartesianGridGeometry<NDIM> > grid_geometry = d_hierarchy->getGridGeometry();
    const IntVector<NDIM>& ratio = level->getRatio();
    const IntVector<NDIM>& periodic_shift = grid_geometry->getPeriodicShift(ratio);
#ifdef DEBUG_CHECK_ASSERTIONS
    TBOX_ASSERT(periodic_shift.min() > 0);
#endif

    HYPRE_StructGridCreate(communicator, NDIM, &d_grid);
    for (PatchLevel<NDIM>::Iterator p(level); p; p++)
    {
        const Box<NDIM> patch_box = Box<NDIM>::coarsen(level->getPatch(p())->getBox(),2);
        Index<NDIM> lower = patch_box.lower();
        Index<NDIM> upper = patch_box.upper();
        HYPRE_StructGridSetExtents(d_grid, lower, upper);
    }

    int hypre_periodic_shift[3];
    for (unsigned int d = 0; d < NDIM; ++d)
    {
        hypre_periodic_shift[d] = periodic_shift(d)/2;
    }
    for (int d = NDIM; d < 3; ++d)
    {
        hypre_periodic_shift[d] = 0;
    }
    HYPRE_StructGridSetPeriodic(d_grid, hypre_periodic_shift);
    HYPRE_StructGridAssemble(d_grid);

    // Allocate stencil data and set stencil offsets.
    static const int stencil_sz = 2*NDIM+1;
#if (NDIM == 2)
    int stencil_offsets[stencil_sz][2] = {
        { -1, 0 }, { 0, -1}, { +1, 0}, { 0, +1 }, { 0, 0 }
    };
#endif
#if (NDIM == 3)
    int stencil_offsets[stencil_sz][3] = {
        { -1,  0,  0}, { 0,  -1,  0}, { 0,  0,  -1},
        { +1,  0,  0}, { 0,  +1,  0}, { 0,  0,  +1},
        { 0,  0,  0}
    };
#endif
    HYPRE_StructStencilCreate(NDIM, stencil_sz, &d_stencil);
    for (int s = 0; s < stencil_sz; ++s)
    {
        HYPRE_StructStencilSetElement(d_stencil, s, stencil_offsets[s]);
    }

    // Allocate the hypre matrix.
#if (NDIM == 2)
    int full_ghosts[2*3] = { 1, 1, 1, 1, 0, 0 };
#endif
#if (NDIM == 3)
    int full_ghosts[2*3] = { 1, 1, 1, 1, 1, 1 };
#endif
    int   no_ghosts[2*3] = { 0, 0, 0, 0, 0, 0 };

    HYPRE_StructMatrixCreate(communicator, d_grid, d_stencil, &d_matrix);
    HYPRE_StructMatrixSetNumGhost(d_matrix, full_ghosts);
    HYPRE_StructMatrixSetSymmetric(d_matrix, 0);
    HYPRE_StructMatrixInitialize(d_matrix);

    // Allocate the hypre vectors.
    HYPRE_StructVectorCreate(communicator, d_grid, &d_sol_vec);
    HYPRE_StructVectorSetNumGhost(d_sol_vec, full_ghosts);
    HYPRE_StructVectorInitialize(d_sol_vec);

    HYPRE_StructVectorCreate(communicator, d_grid, &d_rhs_vec);
    HYPRE_StructVectorSetNumGhost(d_rhs_vec, no_ghosts);
    HYPRE_StructVectorInitialize(d_rhs_vec);
    return;
}// allocateHypreData