void nlSparseMatrixConstruct( NLSparseMatrix* M, NLuint m, NLuint n, NLenum storage ) { NLuint i ; M->m = m ; M->n = n ; M->storage = storage ; if(storage & NL_MATRIX_STORE_ROWS) { M->row = NL_NEW_ARRAY(NLRowColumn, m) ; for(i=0; i<n; i++) { nlRowColumnConstruct(&(M->row[i])) ; } } else { M->row = NULL ; } if(storage & NL_MATRIX_STORE_COLUMNS) { M->column = NL_NEW_ARRAY(NLRowColumn, n) ; for(i=0; i<n; i++) { nlRowColumnConstruct(&(M->column[i])) ; } } else { M->column = NULL ; } M->diag_size = MIN(m,n) ; M->diag = NL_NEW_ARRAY(NLdouble, M->diag_size) ; }
void nlBeginMatrix() { NLuint i ; NLuint n = 0 ; NLenum storage = NL_MATRIX_STORE_ROWS ; nlTransition(NL_STATE_SYSTEM, NL_STATE_MATRIX) ; if(!nlCurrentContext->matrix_already_set) { for(i=0; i<nlCurrentContext->nb_variables; i++) { if(!nlCurrentContext->variable[i].locked) { nlCurrentContext->variable[i].index = n ; n++ ; } else { nlCurrentContext->variable[i].index = ~0 ; } } nlCurrentContext->n = n ; /* SSOR preconditioner requires rows and columns */ if(nlCurrentContext->preconditioner == NL_PRECOND_SSOR) { storage = (storage | NL_MATRIX_STORE_COLUMNS) ; } /* a least squares problem results in a symmetric matrix */ if(nlCurrentContext->least_squares && !nlSolverIsCNC(nlCurrentContext->solver)) { nlCurrentContext->symmetric = NL_TRUE ; } if(nlCurrentContext->symmetric) { storage = (storage | NL_MATRIX_STORE_SYMMETRIC) ; } /* SuperLU storage does not support symmetric storage */ if( nlCurrentContext->solver == NL_SUPERLU_EXT || nlCurrentContext->solver == NL_PERM_SUPERLU_EXT || nlCurrentContext->solver == NL_SYMMETRIC_SUPERLU_EXT ) { storage = (storage & ~NL_MATRIX_STORE_SYMMETRIC) ; } /* CHOLMOD storage requires columns */ if(nlCurrentContext->solver == NL_CHOLMOD_EXT) { storage = (storage & ~NL_MATRIX_STORE_ROWS) ; storage = (storage | NL_MATRIX_STORE_COLUMNS) ; } nlSparseMatrixConstruct(&nlCurrentContext->M, n, n, storage) ; nlCurrentContext->alloc_M = NL_TRUE ; nlCurrentContext->x = NL_NEW_ARRAY(NLdouble, n) ; nlCurrentContext->alloc_x = NL_TRUE ; nlCurrentContext->b = NL_NEW_ARRAY(NLdouble, n) ; nlCurrentContext->alloc_b = NL_TRUE ; nlVariablesToVector() ; nlRowColumnConstruct(&nlCurrentContext->af) ; nlCurrentContext->alloc_af = NL_TRUE ; nlRowColumnConstruct(&nlCurrentContext->al) ; nlCurrentContext->alloc_al = NL_TRUE ; nlRowColumnConstruct(&nlCurrentContext->xl) ; nlCurrentContext->alloc_xl = NL_TRUE ; nlCurrentContext->current_row = 0 ; } else { nl_assert(nlCurrentContext->alloc_M) ; nl_assert(nlCurrentContext->alloc_x) ; nl_assert(nlCurrentContext->alloc_b) ; nlRowColumnConstruct(&nlCurrentContext->af) ; nlCurrentContext->alloc_af = NL_TRUE ; nlRowColumnConstruct(&nlCurrentContext->al) ; nlCurrentContext->alloc_al = NL_TRUE ; nlRowColumnConstruct(&nlCurrentContext->xl) ; nlCurrentContext->alloc_xl = NL_TRUE ; nlCurrentContext->current_row = 0 ; } }