/* read a problem from a file; use %g for integers to avoid int conflicts */ problem *get_problem (FILE *f, double tol) { cs_di *T, *A, *C ; int sym, m, n, mn, nz1, nz2 ; problem *Prob ; Prob = cs_di_calloc (1, sizeof (problem)) ; if (!Prob) return (NULL) ; T = cs_di_load (f) ; /* load triplet matrix T from a file */ Prob->A = A = cs_di_compress (T) ; /* A = compressed-column form of T */ cs_di_spfree (T) ; /* clear T */ if (!cs_di_dupl (A)) return (free_problem (Prob)) ; /* sum up duplicates */ Prob->sym = sym = is_sym (A) ; /* determine if A is symmetric */ m = A->m ; n = A->n ; mn = CS_MAX (m,n) ; nz1 = A->p [n] ; cs_di_dropzeros (A) ; /* drop zero entries */ nz2 = A->p [n] ; if (tol > 0) cs_di_droptol (A, tol) ; /* drop tiny entries (just to test) */ Prob->C = C = sym ? make_sym (A) : A ; /* C = A + triu(A,1)', or C=A */ if (!C) return (free_problem (Prob)) ; printf ("\n--- Matrix: %g-by-%g, nnz: %g (sym: %g: nnz %g), norm: %8.2e\n", (double) m, (double) n, (double) (A->p [n]), (double) sym, (double) (sym ? C->p [n] : 0), cs_di_norm (C)) ; if (nz1 != nz2) printf ("zero entries dropped: %g\n", (double) (nz1 - nz2)); if (nz2 != A->p [n]) printf ("tiny entries dropped: %g\n", (double) (nz2 - A->p [n])) ; Prob->b = cs_di_malloc (mn, sizeof (double)) ; Prob->x = cs_di_malloc (mn, sizeof (double)) ; Prob->resid = cs_di_malloc (mn, sizeof (double)) ; return ((!Prob->b || !Prob->x || !Prob->resid) ? free_problem (Prob) : Prob) ; }
/* Initialize a sparse Jacobian for the solver. */ int KINKluSetJacGraph(KINMem kin_memory, cs_di *jac){ //check inputs if(!kin_memory||!jac) return 1; //grab the linear solver memory block KINKluMem kin_klu_mem=(KINKluMem)kin_memory->kin_lmem; if(!kin_klu_mem) return 1; //grab needed kinklu objects cs_di *kin_klu_jac=kin_klu_mem->jac; //check whether the jacobian data has already been allocated. if so, free it. if(kin_klu_jac){ cs_di_spfree(kin_klu_jac); kin_klu_jac=NULL; } //check if the input jacobian is in triplet form. compress if so. if(CS_TRIPLET(jac)){ kin_klu_jac=cs_di_compress(jac); if(!kin_klu_jac) return 1; cs_di_spfree(jac); jac = kin_klu_jac; return 0; } //assign the input jacobian to the kinklu jacobian kin_klu_mem->jac=jac; //return success return 0; };