Skip to content
This repository has been archived by the owner on May 18, 2019. It is now read-only.

Commit

Permalink
fix colprts for sparse matrixes: ida and kinsol
Browse files Browse the repository at this point in the history
  • Loading branch information
Willi Braun authored and OpenModelica-Hudson committed Jan 12, 2017
1 parent ba209b7 commit 23f4cf8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
21 changes: 16 additions & 5 deletions SimulationRuntime/c/simulation/solver/ida_solver.c
Original file line number Diff line number Diff line change
Expand Up @@ -1338,15 +1338,26 @@ static int jacobianOwnNumIDA(long int Neq, double tt, double cj,
/* Element function for sparse matrix set */
static void setJacElementKluSparse(int row, int col, double value, int nth, SlsMat spJac)
{
if (col > 0){
if (spJac->colptrs[col] == 0){
if (col > 0 && spJac->colptrs[col] == 0){
spJac->colptrs[col] = nth;
}
}
spJac->rowvals[nth] = row;
spJac->data[nth] = value;
}

/* finish sparse matrix, by fixing colprts */
static void finishSparseColPtr(SlsMat mat)
{
int i;
for(i=1; i<mat->N+1; ++i){
if (mat->colptrs[i] == 0){
mat->colptrs[i] = mat->colptrs[i-1];
}
}
/* finish matrix colptrs */
mat->colptrs[mat->N] = mat->NNZ;
}

/*
* function calculates a jacobian matrix by
* numerical method finite differences with coloring
Expand Down Expand Up @@ -1447,8 +1458,8 @@ int jacobianSparseNumIDA(double tt, N_Vector yy, N_Vector yp, N_Vector rr, SlsMa
}
}
}
/* finish matrix colptrs */
Jac->colptrs[idaData->N] = idaData->NNZ;
finishSparseColPtr(Jac);


unsetContext(data);

Expand Down
21 changes: 16 additions & 5 deletions SimulationRuntime/c/simulation/solver/kinsolSolver.c
Original file line number Diff line number Diff line change
Expand Up @@ -362,15 +362,26 @@ int nlsDenseJac(long int N, N_Vector vecX, N_Vector vecFX, DlsMat Jac, void *use
/* Element function for sparse matrix set */
static void setJacElementKluSparse(int row, int col, double value, int nth, SlsMat spJac)
{
if (col > 0){
if (spJac->colptrs[col] == 0){
if (col > 0 && spJac->colptrs[col] == 0){
spJac->colptrs[col] = nth;
}
}
spJac->rowvals[nth] = row;
spJac->data[nth] = value;
}

/* finish sparse matrix, by fixing colprts */
static void finishSparseColPtr(SlsMat mat)
{
int i;
for(i=1; i<mat->N+1; ++i){
if (mat->colptrs[i] == 0){
mat->colptrs[i] = mat->colptrs[i-1];
}
}
/* finish matrix colptrs */
mat->colptrs[mat->N] = mat->NNZ;
}

/*
* function calculates a jacobian matrix by
* numerical method finite differences with coloring
Expand Down Expand Up @@ -434,8 +445,8 @@ int nlsSparseJac(N_Vector vecX, N_Vector vecFX, SlsMat Jac, void *userData, N_Ve
}
}
}
/* finish matrix colptrs */
Jac->colptrs[kinsolData->size] = kinsolData->nnz;
/* finish sparse matrix */
finishSparseColPtr(Jac);

/* debug */
if (ACTIVE_STREAM(LOG_NLS_JAC)){
Expand Down

0 comments on commit 23f4cf8

Please sign in to comment.