Example #1
0
def test_sparseToSBM1():
    from siconos.numerics import sparseToSBM,getValueSBM, newFromFileSBM, printSBM, SBMtoSparse
    from scipy.sparse import csr_matrix, lil_matrix

    A = lil_matrix((100, 100))
    A.setdiag(range(100))
    A[0, :10] = range(10)
    A[1, 10:20] = A[0, :10]

    M = csr_matrix(A)

    v,SBM=sparseToSBM(2,M)

    for i in range(M.shape[0]):
        for j in range(M.shape[1]):
            assert abs(getValueSBM(SBM,i,j) - M[i,j]) < eps
Example #2
0
def test_SBMtoSparseToSBM():

    from siconos.numerics import getValueSBM, newFromFileSBM, printSBM, SBMtoSparse, sparseToSBM
    from scipy.sparse.csr import csr_matrix

    SBM1=newFromFileSBM(os.path.join(working_dir, 'data/SBM1.dat'))

    r,SPARSE = SBMtoSparse(SBM1)

    v,SBM2 = sparseToSBM(3,SPARSE)

    assert SBM1.nbblocks == SBM2.nbblocks
    assert SBM1.blocknumber0 == SBM2.blocknumber0
    assert SBM1.blocknumber1 == SBM2.blocknumber1

    for i in range(SPARSE.shape[0]):
        for j in range(SPARSE.shape[1]):
            assert (getValueSBM(SBM1,i,j) - getValueSBM(SBM2,i,j)) < eps
Example #3
0
def condensed_from_global(fcp):
    # spsolve expect the indices to be cint aka 32 bits int
    # Hence, we do some magic to cirumvent those issues.
    Mcoo = scipy.sparse.coo_matrix(fcp.M)
    Mcsc = scipy.sparse.csc_matrix(Mcoo)
    Hcoo = scipy.sparse.coo_matrix(fcp.H)
    Hcsc = scipy.sparse.csc_matrix(Hcoo)
    WW = Hcsc.T.dot(scipy.sparse.linalg.spsolve(Mcsc, Hcsc))
    qprime = fcp.H.T.dot(scipy.sparse.linalg.spsolve(Mcsc, fcp.q))

    fcp_reduced = sn.FrictionContactProblem()
    fcp_reduced.dimension = fcp.dimension
    fcp_reduced.numberOfContacts = fcp.numberOfContacts

    # this is a hack to deal with the inability of fc3d solvers to work with
    # sparse matrices
    _, Wsbm = sn.sparseToSBM(3, WW)
    fcp_reduced.M = Wsbm
    fcp_reduced.mu = fcp.mu
    fcp_reduced.q = fcp.b + qprime
    return fcp_reduced
Example #4
0
def condensed_from_global(fcp):
    # spsolve expect the indices to be cint aka 32 bits int
    # Hence, we do some magic to cirumvent those issues.
    Mcoo = scipy.sparse.coo_matrix(fcp.M)
    Mcsc = scipy.sparse.csc_matrix(Mcoo)
    Hcoo = scipy.sparse.coo_matrix(fcp.H)
    Hcsc = scipy.sparse.csc_matrix(Hcoo)
    WW = Hcsc.T.dot(scipy.sparse.linalg.spsolve(Mcsc, Hcsc))
    qprime = fcp.H.T.dot(scipy.sparse.linalg.spsolve(Mcsc, fcp.q))

    fcp_reduced = sn.FrictionContactProblem()
    fcp_reduced.dimension = fcp.dimension
    fcp_reduced.numberOfContacts = fcp.numberOfContacts

    # this is a hack to deal with the inability of fc3d solvers to work with
    # sparse matrices
    _, Wsbm = sn.sparseToSBM(3, WW)
    fcp_reduced.M = Wsbm
    fcp_reduced.mu = fcp.mu
    fcp_reduced.q = fcp.b + qprime
    return fcp_reduced
Example #5
0
def test_from_csr1():

    from siconos.numerics import sparseToSBM, getValueSBM
    from scipy.sparse.csr import csr_matrix
    
    M = csr_matrix([[1,2,3],
                    [4,5,6],
                    [7,8,9]])

    print(M.indices)
    print(M.indptr)
    print(M.data)

    r,SBM = sparseToSBM(3,M)

    assert getValueSBM(SBM,0,0) == 1
    assert getValueSBM(SBM,0,1) == 2
    assert getValueSBM(SBM,0,2) == 3
    assert getValueSBM(SBM,1,0) == 4
    assert getValueSBM(SBM,1,1) == 5
    assert getValueSBM(SBM,1,2) == 6    
    assert getValueSBM(SBM,2,0) == 7
    assert getValueSBM(SBM,2,1) == 8
    assert getValueSBM(SBM,2,2) == 9    
Example #6
0
def test_from_csr1():

    from siconos.numerics import sparseToSBM, getValueSBM
    from scipy.sparse.csr import csr_matrix

    M = csr_matrix([[1,2,3],
                    [4,5,6],
                    [7,8,9]])

    print(M.indices)
    print(M.indptr)
    print(M.data)

    r,SBM = sparseToSBM(3,M)

    assert getValueSBM(SBM,0,0) == 1
    assert getValueSBM(SBM,0,1) == 2
    assert getValueSBM(SBM,0,2) == 3
    assert getValueSBM(SBM,1,0) == 4
    assert getValueSBM(SBM,1,1) == 5
    assert getValueSBM(SBM,1,2) == 6
    assert getValueSBM(SBM,2,0) == 7
    assert getValueSBM(SBM,2,1) == 8
    assert getValueSBM(SBM,2,2) == 9