示例#1
0
void Helmholtz( DistSparseMatrix<F>& H, Int nx, Int ny, F shift )
{
    DEBUG_CSE
    typedef Base<F> Real;
    const Int n = nx*ny;
    Zeros( H, n, n );

    const Real hxInv = nx+1;
    const Real hyInv = ny+1;
    const Real hxInvSquared = hxInv*hxInv;
    const Real hyInvSquared = hyInv*hyInv;
    const F mainTerm = 2*(hxInvSquared+hyInvSquared) - shift;

    const Int localHeight = H.LocalHeight();
    H.Reserve( 5*localHeight );
    for( Int iLoc=0; iLoc<localHeight; ++iLoc )
    {
        const Int i = H.GlobalRow(iLoc);
        const Int x = i % nx;
        const Int y = i/nx;

        H.QueueUpdate( i, i, mainTerm );
        if( x != 0 )
            H.QueueUpdate( i, i-1, -hxInvSquared );
        if( x != nx-1 )
            H.QueueUpdate( i, i+1, -hxInvSquared );
        if( y != 0 )
            H.QueueUpdate( i, i-nx, -hyInvSquared );
        if( y != ny-1 )
            H.QueueUpdate( i, i+nx, -hyInvSquared );
    }
    H.ProcessQueues();
}
示例#2
0
void EntrywiseMap
( const DistSparseMatrix<S>& A,
        DistSparseMatrix<T>& B, 
        function<T(S)> func )
{
    DEBUG_CSE
    const Int numEntries = A.vals_.size();
    const Int numRemoteEntries = A.remoteVals_.size();

    B.distGraph_ = A.distGraph_;
    B.vals_.resize( numEntries );
    for( Int k=0; k<numEntries; ++k )
        B.vals_[k] = func(A.vals_[k]);
    B.remoteVals_.resize( numRemoteEntries );
    for( Int k=0; k<numRemoteEntries; ++k )
        B.remoteVals_[k] = func(A.remoteVals_[k]);
    B.ProcessQueues();
}
示例#3
0
void Helmholtz( DistSparseMatrix<F>& H, Int n, F shift )
{
    DEBUG_CSE
    typedef Base<F> Real;
    Zeros( H, n, n );

    const Real hInv = n+1; 
    const Real hInvSquared = hInv*hInv;
    const F mainTerm = 2*hInvSquared - shift;

    const Int localHeight = H.LocalHeight(); 
    H.Reserve( 3*localHeight );
    for( Int iLoc=0; iLoc<localHeight; ++iLoc )
    {
        const Int i = H.GlobalRow(iLoc);
        H.QueueUpdate( i, i, mainTerm );
        if( i != 0 )
            H.QueueUpdate( i, i-1, -hInvSquared );
        if( i != n-1 )
            H.QueueUpdate( i, i+1, -hInvSquared );
    }
    H.ProcessQueues();
}
示例#4
0
void JordanCholesky( DistSparseMatrix<T>& A, Int n )
{
    DEBUG_ONLY(CSE cse("JordanCholesky"))
    Zeros( A, n, n );

    const Int localHeight = A.LocalHeight();
    A.Reserve( 3*localHeight );

    for( Int iLoc=0; iLoc<localHeight; ++iLoc )
    {
        const Int i = A.GlobalRow(iLoc);
        if( i == 0 )
            A.QueueUpdate( i, i, T(1) );
        else
            A.QueueUpdate( i, i, T(5) );

        if( i > 0 )
            A.QueueUpdate( i, i-1, T(2) );
        if( i < n-1 )
            A.QueueUpdate( i, i+1, T(2) );
    }
    A.ProcessQueues();
}