예제 #1
0
void
assembleTransposeMatrix ( MatrixEpetra<Real>&   globalMatrix,
                          Real                  coefficient,
                          MatrixElemental&              localMatrix,
                          const CurrentFE&      currentFE1,
                          const CurrentFE&      currentFE2,
                          const DofType1&       dof1,
                          const DofType2&       dof2,
                          Int                   iblock,
                          Int                   jblock,
                          Int                   iOffset ,
                          Int                   jOffset )

{
    MatrixElemental::matrix_type localView (localMatrix.block ( jblock, iblock ) );
    localView *= coefficient;

    Int i, j;
    UInt k1, k2;

    UInt elementID1 = currentFE1.currentLocalId();
    UInt elementID2 = currentFE2.currentLocalId();

    std::vector<Int> ilist (currentFE1.nbFEDof() );
    std::vector<Int> jlist (currentFE2.nbFEDof() );

    std::vector<Real*> matPtr (currentFE1.nbFEDof() );

    for ( k1 = 0 ; k1 < currentFE1.nbFEDof() ; k1++ )
    {
        i =  k1;
        ilist[k1] = dof1.localToGlobalMap ( elementID1, i ) + iOffset ;
        matPtr[k1] = & (localView (0, i) );
    }

    for ( k2 = 0 ; k2 < currentFE2.nbFEDof() ; k2++ )
    {
        j = k2;
        jlist[k2]  = dof2.localToGlobalMap ( elementID2, j ) + jOffset ;
    }

    assert (localView.indexij ( Int (1), Int (0) ) == 1);

    globalMatrix.addToCoefficients ( currentFE1.nbFEDof(), currentFE2.nbFEDof(),
                                     ilist, jlist, &matPtr[0], Epetra_FECrsMatrix::ROW_MAJOR );

}
예제 #2
0
void
assembleMatrix ( MatrixEpetra<Real>&   globalMatrix,
                 UInt const&           elementID1,
                 UInt const&           elementID2,
                 LocalMatrixType&      localMatrix,
                 const UInt&           fe1NbDof,
                 const UInt&           fe2NbDof,
                 const DofType1&       dof1,
                 const DofType2&       dof2,
                 Int                   iOffset,
                 Int                   jOffset )

{
    // Global ID of the dofs
    std::vector<Int> iList (fe1NbDof);
    std::vector<Int> jList (fe2NbDof);

    // Raw data to insert in the matrix
    std::vector<Real*> matPtr (fe2NbDof);


    for ( UInt k1 (0) ; k1 < fe1NbDof ; k1++ )
    {
        iList[k1] = dof1.localToGlobalMap ( elementID1, k1 ) + iOffset ;
    }

    for ( UInt k2 (0) ; k2 < fe2NbDof ; k2++ )
    {
        jList[k2]  = dof2.localToGlobalMap ( elementID2, k2 ) + jOffset ;
        matPtr[k2] = & (localMatrix (static_cast<UInt> (0), k2) );
    }

    assert (localMatrix.indexij ( Int (1), Int (0) ) == 1);

    globalMatrix.addToCoefficients ( fe1NbDof, fe2NbDof, iList, jList, &matPtr[0], Epetra_FECrsMatrix::COLUMN_MAJOR );
}
예제 #3
0
PreconditionerAS<space_type,coef_space_type>::PreconditionerAS( std::string t,
                                                                space_ptrtype Xh,
                                                                coef_space_ptrtype Mh,
                                                                BoundaryConditions bcFlags,
                                                                std::string const& p,
                                                                sparse_matrix_ptrtype Pm,
                                                                double k )
    :
        M_type( AS ),
        M_Xh( Xh ),
        M_Vh(Xh->template functionSpace<0>() ),
        M_Qh(Xh->template functionSpace<1>() ),
        M_Mh( Mh ),
        M_Vh_indices( M_Vh->nLocalDofWithGhost() ),
        M_Qh_indices( M_Qh->nLocalDofWithGhost() ),
        M_Qh3_indices( Dim ),
        A(backend()->newVector(M_Vh)),
        B(backend()->newVector(M_Vh)),
        C(backend()->newVector(M_Vh)),
        M_r(backend()->newVector(M_Vh)),
        M_r_t(backend()->newVector(M_Vh)),
        M_uout(backend()->newVector(M_Vh)),
        M_diagPm(backend()->newVector(M_Vh)),
        //M_t(backend()->newVector(M_Vh)),
        U( M_Vh, "U" ),
        M_mu(M_Mh, "mu"),
        M_er(M_Mh, "er"),
        M_bcFlags( bcFlags ),
        M_prefix( p ),
        M_k(k),
        M_g(1.-k*k)
{
    tic();
    LOG(INFO) << "[PreconditionerAS] setup starts";
    this->setMatrix( Pm ); // Needed only if worldComm > 1

    // QH3 : Lagrange vectorial space type
    M_Qh3 = lag_v_space_type::New(Xh->mesh());

    M_qh3_elt = M_Qh3->element();
    M_qh_elt = M_Qh->element();
    M_vh_elt = M_Vh->element();

    // Block 11.1
    M_s = backend()->newVector(M_Qh3);
    M_y = backend()->newVector(M_Qh3);

    // Block 11.2
    M_z = backend()->newVector(M_Qh);
    M_t = backend()->newVector(M_Qh);

    // Create the interpolation and keep only the matrix
    auto pi_curl = I(_domainSpace=M_Qh3, _imageSpace=M_Vh);
    auto Igrad   = Grad( _domainSpace=M_Qh, _imageSpace=M_Vh);

    M_P = pi_curl.matPtr();
    M_C = Igrad.matPtr();

    M_Pt = backend()->newMatrix(M_Qh3,M_Vh);
    M_Ct = backend()->newMatrix(M_Qh3,M_Vh);

    M_P->transpose(M_Pt,MATRIX_TRANSPOSE_UNASSEMBLED);
    M_C->transpose(M_Ct,MATRIX_TRANSPOSE_UNASSEMBLED);

    LOG(INFO) << "size of M_C = " << M_C->size1() << ", " << M_C->size2() << std::endl;
    LOG(INFO) << "size of M_P = " << M_P->size1() << ", " << M_P->size2() << std::endl;

    // Create vector of indices to create subvectors/matrices
    std::iota( M_Vh_indices.begin(), M_Vh_indices.end(), 0 ); // Vh indices in Xh
    std::iota( M_Qh_indices.begin(), M_Qh_indices.end(), M_Vh->nLocalDofWithGhost() ); // Qh indices in Xh

    // "Components" of Qh3
    auto Qh3_dof_begin = M_Qh3->dof()->dofPointBegin();
    auto Qh3_dof_end = M_Qh3->dof()->dofPointEnd();

    int dof_comp, dof_idx;
    for( auto it = Qh3_dof_begin; it!= Qh3_dof_end; it++ )
    {
        dof_comp = it->template get<2>(); //Component
        dof_idx = it->template get<1>(); //Global index
        M_Qh3_indices[dof_comp].push_back( dof_idx );
    }

    // Subvectors for M_y (per component)
    M_y1 = M_y->createSubVector(M_Qh3_indices[0], true);
    M_y2 = M_y->createSubVector(M_Qh3_indices[1], true);
#if FEELPP_DIM == 3
    M_y3 = M_y->createSubVector(M_Qh3_indices[2], true);
#endif
    
    // Subvectors for M_s (per component)
    M_s1 = M_y->createSubVector(M_Qh3_indices[0], true);
    M_s2 = M_y->createSubVector(M_Qh3_indices[1], true);
#if FEELPP_DIM == 3
    M_s3 = M_y->createSubVector(M_Qh3_indices[2], true);
#endif

    this->setType ( t );
    toc( "[PreconditionerAS] setup done ", FLAGS_v > 0 );
}