From 43f7bede8fc85e87870bb705ff6422e5650031a5 Mon Sep 17 00:00:00 2001 From: Francesco Lannutti Date: Sat, 14 Mar 2020 23:21:26 +0100 Subject: [PATCH] Added the support for .ic statement in KLU mode --- src/maths/KLU/klusmp.c | 37 +++++++++++++++++++++++++++-------- src/spicelib/analysis/cktic.c | 21 +++++++++++++++++--- 2 files changed, 47 insertions(+), 11 deletions(-) diff --git a/src/maths/KLU/klusmp.c b/src/maths/KLU/klusmp.c index 1725fc8da..a22c4669d 100644 --- a/src/maths/KLU/klusmp.c +++ b/src/maths/KLU/klusmp.c @@ -997,15 +997,36 @@ SMPelement * SMPfindElt (SMPmatrix *eMatrix, int Row, int Col, int CreateIfMissing) { MatrixPtr Matrix = eMatrix->SPmatrix ; - ElementPtr Element ; - /* Begin `SMPfindElt'. */ - assert (IS_SPARSE (Matrix)) ; - Row = Matrix->ExtToIntRowMap [Row] ; - Col = Matrix->ExtToIntColMap [Col] ; - Element = Matrix->FirstInCol [Col] ; - Element = spcFindElementInCol (Matrix, &Element, Row, Col, CreateIfMissing) ; - return (SMPelement *)Element ; + if (eMatrix->CKTkluMODE) + { + int i ; + + Row = Matrix->ExtToIntRowMap [Row] ; + Col = Matrix->ExtToIntColMap [Col] ; + for (i = eMatrix->CKTkluAp [Col - 1] ; i < eMatrix->CKTkluAp [Col] ; i++) { + if (eMatrix->CKTkluAi [i] == Row - 1) { + if (eMatrix->CKTkluMatrixIsComplex == CKTkluMatrixReal) { + return (SMPelement *) &(eMatrix->CKTkluAx [i]) ; + } else if (eMatrix->CKTkluMatrixIsComplex == CKTkluMatrixComplex) { + return (SMPelement *) &(eMatrix->CKTkluAx_Complex [2 * i]) ; + } else { + return NULL ; + } + } + } + return NULL ; + } else { + ElementPtr Element ; + + /* Begin `SMPfindElt'. */ + assert (IS_SPARSE (Matrix)) ; + Row = Matrix->ExtToIntRowMap [Row] ; + Col = Matrix->ExtToIntColMap [Col] ; + Element = Matrix->FirstInCol [Col] ; + Element = spcFindElementInCol (Matrix, &Element, Row, Col, CreateIfMissing) ; + return (SMPelement *)Element ; + } } /* XXX The following should probably be implemented in spUtils */ diff --git a/src/spicelib/analysis/cktic.c b/src/spicelib/analysis/cktic.c index 194b29ade..448a6fcd0 100644 --- a/src/spicelib/analysis/cktic.c +++ b/src/spicelib/analysis/cktic.c @@ -25,15 +25,30 @@ CKTic(CKTcircuit *ckt) for(node = ckt->CKTnodes;node != NULL; node = node->next) { if(node->nsGiven) { - node->ptr = SMPmakeElt(ckt->CKTmatrix,node->number,node->number); + if (ckt->CKTkluMODE) { + node->ptr = (double *) SMPfindElt (ckt->CKTmatrix, node->number, node->number, 0) ; + if (node->ptr == NULL) { + printf ("Warning: The needed element doesn't exist in the matrix, but KLU mode cannot create a new element. ") ; + printf ("Please specify an existing element for .nodeset\n") ; + } + } else { + node->ptr = SMPmakeElt(ckt->CKTmatrix,node->number,node->number); + } if(node->ptr == NULL) return(E_NOMEM); ckt->CKThadNodeset = 1; ckt->CKTrhsOld[node->number] = ckt->CKTrhs[node->number] = node->nodeset; } if(node->icGiven) { if(! ( node->ptr)) { - node->ptr = SMPmakeElt(ckt->CKTmatrix,node->number, - node->number); + if (ckt->CKTkluMODE) { + node->ptr = (double *) SMPfindElt (ckt->CKTmatrix, node->number, node->number, 0) ; + if (node->ptr == NULL) { + printf ("Warning: The needed element doesn't exist in the matrix, but KLU mode cannot create a new element. ") ; + printf ("Please specify an existing element for .ic\n") ; + } + } else { + node->ptr = SMPmakeElt(ckt->CKTmatrix,node->number, node->number); + } if(node->ptr == NULL) return(E_NOMEM); } ckt->CKTrhsOld[node->number] = ckt->CKTrhs[node->number] = node->ic;