diff --git a/src/ciderlib/oned/oneadmit.c b/src/ciderlib/oned/oneadmit.c index 2e0b607fa..a8c7ea7b8 100644 --- a/src/ciderlib/oned/oneadmit.c +++ b/src/ciderlib/oned/oneadmit.c @@ -119,7 +119,7 @@ NUMDadmittance(ONEdevice *pDevice, double omega, SPcomplex *yd) #ifdef KLU if (pDevice->matrix->CKTkluMODE) { - pDevice->matrix->SMPkluMatrix->KLUmatrixIsComplex = CKTkluMatrixComplex ; + pDevice->matrix->SMPkluMatrix->KLUmatrixIsComplex = KLUMatrixComplex ; } else { #endif @@ -315,7 +315,7 @@ NBJTadmittance(ONEdevice *pDevice, double omega, SPcomplex *yIeVce, #ifdef KLU if (pDevice->matrix->CKTkluMODE) { - pDevice->matrix->SMPkluMatrix->KLUmatrixIsComplex = CKTkluMatrixComplex ; + pDevice->matrix->SMPkluMatrix->KLUmatrixIsComplex = KLUMatrixComplex ; } else { #endif @@ -580,7 +580,7 @@ NUMDys(ONEdevice *pDevice, SPcomplex *s, SPcomplex *yd) #ifdef KLU if (pDevice->matrix->CKTkluMODE) { - pDevice->matrix->SMPkluMatrix->KLUmatrixIsComplex = CKTkluMatrixComplex ; + pDevice->matrix->SMPkluMatrix->KLUmatrixIsComplex = KLUMatrixComplex ; } else { #endif @@ -667,7 +667,7 @@ NBJTys(ONEdevice *pDevice, SPcomplex *s, SPcomplex *yIeVce, #ifdef KLU if (pDevice->matrix->CKTkluMODE) { - pDevice->matrix->SMPkluMatrix->KLUmatrixIsComplex = CKTkluMatrixComplex ; + pDevice->matrix->SMPkluMatrix->KLUmatrixIsComplex = KLUMatrixComplex ; } else { #endif diff --git a/src/ciderlib/oned/onecont.c b/src/ciderlib/oned/onecont.c index 705dec16e..30e270df4 100644 --- a/src/ciderlib/oned/onecont.c +++ b/src/ciderlib/oned/onecont.c @@ -251,77 +251,6 @@ ONE_jacBuild(ONEdevice *pDevice) } #ifdef KLU -/* -#define CREATE_KLU_BINDING_TABLE_CIDER(ptr, binding, a, b) \ - printf ("Swapping Pointer %s: (%d,%d)\n", #ptr, a, b) ; \ - if ((a > 0) && (b > 0)) { \ - if (pNode->binding != NULL) { \ - if (pNode->binding->CSC_Complex != NULL) { \ - printf (" Looking for the Pointer: %p\n", pNode->binding->CSC_Complex) ; \ - qsort (BindStructCSC, nz, sizeof(BindKluElementCOO), BindKluCompareCSC) ; \ - i.COO = NULL ; \ - i.CSC_Complex = pNode->binding->CSC_Complex ; \ - matched = (BindKluElementCOO *) bsearch (&i, BindStructCSC, nz, sizeof(BindKluElementCOO), BindKluCompareCSC) ; \ - if (matched != NULL) { \ - printf (" Found the Old Pointer\n") ; \ - pNode->ptr = pNode->binding->CSC_Complex ; \ - } else { \ - i.COO = pNode->ptr ; \ - i.CSC_Complex = NULL ; \ - matched = (BindKluElementCOO *) bsearch (&i, BindStruct, nz, sizeof(BindKluElementCOO), BindKluCompareCOO) ; \ - if (matched != NULL) { \ - printf (" Looking for the Pointer 1\n") ; \ - pNode->binding = matched ; \ - pNode->ptr = matched->CSC_Complex ; \ - } else { \ - printf (" Leaving the Pointer as is\n") ; \ - } \ - } \ - } else { \ - printf (" Looking for the Pointer 2\n") ; \ - i.COO = pNode->ptr ; \ - i.CSC_Complex = NULL ; \ - matched = (BindKluElementCOO *) bsearch (&i, BindStruct, nz, sizeof(BindKluElementCOO), BindKluCompareCOO) ; \ - pNode->binding = matched ; \ - pNode->ptr = matched->CSC_Complex ; \ - } \ - } else { \ - printf (" Looking for the Pointer 3\n") ; \ - i.COO = pNode->ptr ; \ - i.CSC_Complex = NULL ; \ - matched = (BindKluElementCOO *) bsearch (&i, BindStruct, nz, sizeof(BindKluElementCOO), BindKluCompareCOO) ; \ - pNode->binding = matched ; \ - pNode->ptr = matched->CSC_Complex ; \ - } \ - } -*/ - -/* -#define CREATE_KLU_BINDING_TABLE_CIDER_TO_REAL(ptr, binding, a, b) \ - if ((a > 0) && (b > 0)) { \ - printf ("Macro\n") ; \ - if (pNode->binding) { \ - printf ("IF: %p\n", pNode->binding) ; \ - printf ("COO: %p\n", pNode->binding->COO) ; \ - printf ("CSC: %p\n", pNode->binding->CSC) ; \ - if (pNode->binding->CSC_Complex) { \ - printf ("CSC_Complex: %p\n", pNode->binding->CSC_Complex) ; \ - pNode->ptr = pNode->binding->CSC_Complex ; \ - } else { \ - i = pNode->ptr ; \ - matched = (BindKluElementCOO *) bsearch (&i, BindStruct, nz, sizeof(BindKluElementCOO), BindKluCompareCOO) ; \ - pNode->binding = matched ; \ - pNode->ptr = matched->CSC_Complex ; \ - } \ - } else { \ - i = pNode->ptr ; \ - matched = (BindKluElementCOO *) bsearch (&i, BindStruct, nz, sizeof(BindKluElementCOO), BindKluCompareCOO) ; \ - pNode->binding = matched ; \ - pNode->ptr = matched->CSC_Complex ; \ - } \ - } -*/ - void ONEbindCSC (ONEdevice *pDevice) { @@ -331,13 +260,13 @@ ONEbindCSC (ONEdevice *pDevice) int psiEqn, nEqn, pEqn; /* scratch for deref'd eqn numbers */ int psiEqnL=0, nEqnL=0, pEqnL=0; int psiEqnR=0, nEqnR=0, pEqnR=0; - BindKluElementCOO i, *matched, *BindStruct, *BindStructCSC ; + BindElementKLUforCIDER i, *matched, *BindStruct, *BindStructCSC ; size_t nz ; - BindStruct = pDevice->matrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + BindStruct = pDevice->matrix->SMPkluMatrix->KLUmatrixBindStructForCIDER ; nz = pDevice->matrix->SMPkluMatrix->KLUmatrixNZ ; - BindStructCSC = (BindKluElementCOO *) malloc (nz * sizeof(BindKluElementCOO)) ; + BindStructCSC = (BindElementKLUforCIDER *) malloc (nz * sizeof (BindElementKLUforCIDER)) ; for (index = 0 ; index < (int)nz ; index++) { BindStructCSC [index] = BindStruct [index] ; } diff --git a/src/ciderlib/oned/onepoiss.c b/src/ciderlib/oned/onepoiss.c index 30552e1d1..37d48328e 100644 --- a/src/ciderlib/oned/onepoiss.c +++ b/src/ciderlib/oned/onepoiss.c @@ -70,64 +70,19 @@ ONEQjacBuild(ONEdevice *pDevice) } #ifdef KLU -/* -#define CREATE_KLU_BINDING_TABLE_CIDER(ptr, binding, a, b) \ - printf ("Swapping Pointer %s: (%d,%d)\n", #ptr, a, b) ; \ - if ((a > 0) && (b > 0)) { \ - if (pNode->binding != NULL) { \ - if (pNode->binding->CSC_Complex != NULL) { \ - printf (" Looking for the Pointer: %p\n", pNode->binding->CSC_Complex) ; \ - qsort (BindStructCSC, nz, sizeof(BindKluElementCOO), BindKluCompareCSC) ; \ - i.COO = NULL ; \ - i.CSC_Complex = pNode->binding->CSC_Complex ; \ - matched = (BindKluElementCOO *) bsearch (&i, BindStructCSC, nz, sizeof(BindKluElementCOO), BindKluCompareCSC) ; \ - if (matched != NULL) { \ - printf (" Found the Old Pointer\n") ; \ - pNode->ptr = pNode->binding->CSC_Complex ; \ - } else { \ - i.COO = pNode->ptr ; \ - i.CSC_Complex = NULL ; \ - matched = (BindKluElementCOO *) bsearch (&i, BindStruct, nz, sizeof(BindKluElementCOO), BindKluCompareCOO) ; \ - if (matched != NULL) { \ - printf (" Looking for the Pointer 1\n") ; \ - pNode->binding = matched ; \ - pNode->ptr = matched->CSC_Complex ; \ - } else { \ - printf (" Leaving the Pointer as is\n") ; \ - } \ - } \ - } else { \ - printf (" Looking for the Pointer 2\n") ; \ - i.COO = pNode->ptr ; \ - i.CSC_Complex = NULL ; \ - matched = (BindKluElementCOO *) bsearch (&i, BindStruct, nz, sizeof(BindKluElementCOO), BindKluCompareCOO) ; \ - pNode->binding = matched ; \ - pNode->ptr = matched->CSC_Complex ; \ - } \ - } else { \ - printf (" Looking for the Pointer 3\n") ; \ - i.COO = pNode->ptr ; \ - i.CSC_Complex = NULL ; \ - matched = (BindKluElementCOO *) bsearch (&i, BindStruct, nz, sizeof(BindKluElementCOO), BindKluCompareCOO) ; \ - pNode->binding = matched ; \ - pNode->ptr = matched->CSC_Complex ; \ - } \ - } -*/ - void ONEQbindCSC (ONEdevice *pDevice) { ONEelem *pElem ; ONEnode *pNode, *pNode1 ; int index ; - BindKluElementCOO i, *matched, *BindStruct, *BindStructCSC ; + BindElementKLUforCIDER i, *matched, *BindStruct, *BindStructCSC ; size_t nz ; - BindStruct = pDevice->matrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + BindStruct = pDevice->matrix->SMPkluMatrix->KLUmatrixBindStructForCIDER ; nz = pDevice->matrix->SMPkluMatrix->KLUmatrixNZ ; - BindStructCSC = (BindKluElementCOO *) malloc (nz * sizeof(BindKluElementCOO)) ; + BindStructCSC = (BindElementKLUforCIDER *) malloc (nz * sizeof (BindElementKLUforCIDER)) ; for (index = 0 ; index < (int)nz ; index++) { BindStructCSC [index] = BindStruct [index] ; } diff --git a/src/ciderlib/oned/onesolve.c b/src/ciderlib/oned/onesolve.c index e360d1044..e446e1e89 100644 --- a/src/ciderlib/oned/onesolve.c +++ b/src/ciderlib/oned/onesolve.c @@ -592,7 +592,7 @@ ONEequilSolve(ONEdevice *pDevice) #ifdef KLU pDevice->matrix->CKTkluMODE = CKTkluON ; /* Francesco Lannutti - To be sustitued with a value coming from the uplevel */ - error = SMPnewMatrixKLUforCIDER (pDevice->matrix, pDevice->numEqns, CKTkluMatrixReal) ; + error = SMPnewMatrixKLUforCIDER (pDevice->matrix, pDevice->numEqns, KLUmatrixReal) ; #else error = SMPnewMatrixForCIDER (pDevice->matrix, pDevice->numEqns, 0) ; #endif @@ -605,7 +605,7 @@ ONEequilSolve(ONEdevice *pDevice) #ifdef KLU if (pDevice->matrix->CKTkluMODE) { - pDevice->matrix->SMPkluMatrix->KLUmatrixIsComplex = CKTkluMatrixReal ; + pDevice->matrix->SMPkluMatrix->KLUmatrixIsComplex = KLUmatrixReal ; } else { #endif @@ -636,7 +636,8 @@ ONEequilSolve(ONEdevice *pDevice) } } printf ("CIDER: KLU to be fixed: spElementCount\n") ; - pDevice->numOrigEquil = 0 ; // Francesco Lannutti - Fix for KLU + pDevice->numOrigEquil = 0 ; //pDevice->matrix->SMPkluMatrix->KLUmatrixNumeric->lnz + pDevice->matrix->SMPkluMatrix->KLUmatrixNumeric->unz + //+ pDevice->matrix->SMPkluMatrix->KLUmatrixNumeric->nzoff ; } else { pDevice->numOrigEquil = spElementCount (pDevice->matrix->SPmatrix) ; } @@ -666,9 +667,8 @@ ONEequilSolve(ONEdevice *pDevice) #ifdef KLU if (pDevice->matrix->CKTkluMODE) { - // Francesco Lannutti - Fix for KLU - printf ("CIDER: KLU to be fixed: spFillinCount\n") ; - pDevice->numFillEquil = 0 ; + pDevice->numFillEquil = pDevice->matrix->SMPkluMatrix->KLUmatrixNumeric->lnz + pDevice->matrix->SMPkluMatrix->KLUmatrixNumeric->unz + + pDevice->matrix->SMPkluMatrix->KLUmatrixNumeric->nzoff - (int)pDevice->matrix->SMPkluMatrix->KLUmatrixNZ ; } else { #endif @@ -752,7 +752,7 @@ ONEbiasSolve(ONEdevice *pDevice, int iterationLimit, #ifdef KLU pDevice->matrix->CKTkluMODE = CKTkluON ; /* Francesco Lannutti - To be sustitued with a value coming from the uplevel */ - error = SMPnewMatrixKLUforCIDER (pDevice->matrix, pDevice->numEqns, CKTkluMatrixComplex) ; + error = SMPnewMatrixKLUforCIDER (pDevice->matrix, pDevice->numEqns, KLUMatrixComplex) ; #else error = SMPnewMatrixForCIDER (pDevice->matrix, pDevice->numEqns, 1) ; #endif @@ -796,7 +796,7 @@ ONEbiasSolve(ONEdevice *pDevice, int iterationLimit, #ifdef KLU if (pDevice->matrix->CKTkluMODE) { - pDevice->matrix->SMPkluMatrix->KLUmatrixIsComplex = CKTkluMatrixReal ; + pDevice->matrix->SMPkluMatrix->KLUmatrixIsComplex = KLUmatrixReal ; } else { #endif @@ -826,9 +826,8 @@ ONEbiasSolve(ONEdevice *pDevice, int iterationLimit, #ifdef KLU if (pDevice->matrix->CKTkluMODE) { - // Francesco Lannutti - Fix for KLU - printf ("CIDER: KLU to be fixed: spFillinCount\n") ; - pDevice->numFillBias = 0 ; + pDevice->numFillBias = pDevice->matrix->SMPkluMatrix->KLUmatrixNumeric->lnz + pDevice->matrix->SMPkluMatrix->KLUmatrixNumeric->unz + + pDevice->matrix->SMPkluMatrix->KLUmatrixNumeric->nzoff - (int)pDevice->matrix->SMPkluMatrix->KLUmatrixNZ ; } else { #endif diff --git a/src/ciderlib/twod/twoadmit.c b/src/ciderlib/twod/twoadmit.c index 058e93976..1c2fbc193 100644 --- a/src/ciderlib/twod/twoadmit.c +++ b/src/ciderlib/twod/twoadmit.c @@ -105,7 +105,7 @@ NUMD2admittance(TWOdevice *pDevice, double omega, SPcomplex *yd) #ifdef KLU if (pDevice->matrix->CKTkluMODE) { // Francesco Lannutti - To be completed - pDevice->matrix->SMPkluMatrix->KLUmatrixIsComplex = CKTkluMatrixComplex ; + pDevice->matrix->SMPkluMatrix->KLUmatrixIsComplex = KLUMatrixComplex ; } else { #endif @@ -292,7 +292,7 @@ NBJT2admittance(TWOdevice *pDevice, double omega, SPcomplex *yIeVce, #ifdef KLU if (pDevice->matrix->CKTkluMODE) { // Francesco Lannutti - To be completed - pDevice->matrix->SMPkluMatrix->KLUmatrixIsComplex = CKTkluMatrixComplex ; + pDevice->matrix->SMPkluMatrix->KLUmatrixIsComplex = KLUMatrixComplex ; } else { #endif @@ -577,7 +577,7 @@ NUMOSadmittance(TWOdevice *pDevice, double omega, struct mosAdmittances *yAc) #ifdef KLU if (pDevice->matrix->CKTkluMODE) { // Francesco Lannutti - To be completed - pDevice->matrix->SMPkluMatrix->KLUmatrixIsComplex = CKTkluMatrixComplex ; + pDevice->matrix->SMPkluMatrix->KLUmatrixIsComplex = KLUMatrixComplex ; } else { #endif @@ -1180,7 +1180,7 @@ NUMD2ys(TWOdevice *pDevice, SPcomplex *s, SPcomplex *yIn) #ifdef KLU if (pDevice->matrix->CKTkluMODE) { // Francesco Lannutti - To be completed - pDevice->matrix->SMPkluMatrix->KLUmatrixIsComplex = CKTkluMatrixComplex ; + pDevice->matrix->SMPkluMatrix->KLUmatrixIsComplex = KLUMatrixComplex ; } else { #endif @@ -1277,7 +1277,7 @@ NBJT2ys(TWOdevice *pDevice, SPcomplex *s, SPcomplex *yIeVce, SPcomplex *yIcVce, #ifdef KLU if (pDevice->matrix->CKTkluMODE) { // Francesco Lannutti - To be completed - pDevice->matrix->SMPkluMatrix->KLUmatrixIsComplex = CKTkluMatrixComplex ; + pDevice->matrix->SMPkluMatrix->KLUmatrixIsComplex = KLUMatrixComplex ; } else { #endif @@ -1399,7 +1399,7 @@ NUMOSys(TWOdevice *pDevice, SPcomplex *s, struct mosAdmittances *yAc) #ifdef KLU if (pDevice->matrix->CKTkluMODE) { // Francesco Lannutti - To be completed - pDevice->matrix->SMPkluMatrix->KLUmatrixIsComplex = CKTkluMatrixComplex ; + pDevice->matrix->SMPkluMatrix->KLUmatrixIsComplex = KLUMatrixComplex ; } else { #endif diff --git a/src/ciderlib/twod/twocont.c b/src/ciderlib/twod/twocont.c index 087fd8c06..c1673c6f8 100644 --- a/src/ciderlib/twod/twocont.c +++ b/src/ciderlib/twod/twocont.c @@ -902,7 +902,7 @@ TWObindCSC (TWOdevice *pDevice) TWOelem *pElem; TWOnode *pNode; TWOchannel *pCh; - BindKluElementCOO i, *matched, *BindStruct, *BindStructCSC ; + BindElementKLUforCIDER i, *matched, *BindStruct, *BindStructCSC ; int index ; size_t nz ; @@ -916,10 +916,10 @@ TWObindCSC (TWOdevice *pDevice) int psiEqnInM = 0, psiEqnInP = 0; /* scratch for deref'd surface eqns */ int psiEqnOxM = 0, psiEqnOxP = 0; /* M= more negative, P= more positive */ - BindStruct = pDevice->matrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + BindStruct = pDevice->matrix->SMPkluMatrix->KLUmatrixBindStructForCIDER ; nz = pDevice->matrix->SMPkluMatrix->KLUmatrixNZ ; - BindStructCSC = (BindKluElementCOO *) malloc (nz * sizeof(BindKluElementCOO)) ; + BindStructCSC = (BindElementKLUforCIDER *) malloc (nz * sizeof (BindElementKLUforCIDER)) ; for (index = 0 ; index < (int)nz ; index++) { BindStructCSC [index] = BindStruct [index] ; } diff --git a/src/ciderlib/twod/twoncont.c b/src/ciderlib/twod/twoncont.c index 4884a3944..be782b390 100644 --- a/src/ciderlib/twod/twoncont.c +++ b/src/ciderlib/twod/twoncont.c @@ -577,7 +577,7 @@ TWONbindCSC (TWOdevice *pDevice) TWOelem *pElem; TWOnode *pNode; TWOchannel *pCh; - BindKluElementCOO i, *matched, *BindStruct, *BindStructCSC ; + BindElementKLUforCIDER i, *matched, *BindStruct, *BindStructCSC ; int index ; size_t nz ; @@ -591,10 +591,10 @@ TWONbindCSC (TWOdevice *pDevice) int psiEqnInM = 0, psiEqnInP = 0; /* scratch for deref'd surface eqns */ int psiEqnOxM = 0, psiEqnOxP = 0; /* M= more negative, P= more positive */ - BindStruct = pDevice->matrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + BindStruct = pDevice->matrix->SMPkluMatrix->KLUmatrixBindStructForCIDER ; nz = pDevice->matrix->SMPkluMatrix->KLUmatrixNZ ; - BindStructCSC = (BindKluElementCOO *) malloc (nz * sizeof(BindKluElementCOO)) ; + BindStructCSC = (BindElementKLUforCIDER *) malloc (nz * sizeof (BindElementKLUforCIDER)) ; for (index = 0 ; index < (int)nz ; index++) { BindStructCSC [index] = BindStruct [index] ; } diff --git a/src/ciderlib/twod/twopcont.c b/src/ciderlib/twod/twopcont.c index f1166f088..60053ec6d 100644 --- a/src/ciderlib/twod/twopcont.c +++ b/src/ciderlib/twod/twopcont.c @@ -577,7 +577,7 @@ TWOPbindCSC (TWOdevice *pDevice) TWOelem *pElem; TWOnode *pNode; TWOchannel *pCh; - BindKluElementCOO i, *matched, *BindStruct, *BindStructCSC ; + BindElementKLUforCIDER i, *matched, *BindStruct, *BindStructCSC ; int index ; size_t nz ; @@ -591,10 +591,10 @@ TWOPbindCSC (TWOdevice *pDevice) int psiEqnInM = 0, psiEqnInP = 0; /* scratch for deref'd surface eqns */ int psiEqnOxM = 0, psiEqnOxP = 0; /* M= more negative, P= more positive */ - BindStruct = pDevice->matrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + BindStruct = pDevice->matrix->SMPkluMatrix->KLUmatrixBindStructForCIDER ; nz = pDevice->matrix->SMPkluMatrix->KLUmatrixNZ ; - BindStructCSC = (BindKluElementCOO *) malloc (nz * sizeof(BindKluElementCOO)) ; + BindStructCSC = (BindElementKLUforCIDER *) malloc (nz * sizeof (BindElementKLUforCIDER)) ; for (index = 0 ; index < (int)nz ; index++) { BindStructCSC [index] = BindStruct [index] ; } diff --git a/src/ciderlib/twod/twopoiss.c b/src/ciderlib/twod/twopoiss.c index fd39d53ea..1cb28d3bc 100644 --- a/src/ciderlib/twod/twopoiss.c +++ b/src/ciderlib/twod/twopoiss.c @@ -165,13 +165,13 @@ TWOQbindCSC (TWOdevice *pDevice) TWOnode *pNode, *pNode1; int eIndex, nIndex; int index ; - BindKluElementCOO i, *matched, *BindStruct, *BindStructCSC ; + BindElementKLUforCIDER i, *matched, *BindStruct, *BindStructCSC ; size_t nz ; - BindStruct = pDevice->matrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + BindStruct = pDevice->matrix->SMPkluMatrix->KLUmatrixBindStructForCIDER ; nz = pDevice->matrix->SMPkluMatrix->KLUmatrixNZ ; - BindStructCSC = (BindKluElementCOO *) malloc (nz * sizeof(BindKluElementCOO)) ; + BindStructCSC = (BindElementKLUforCIDER *) malloc (nz * sizeof (BindElementKLUforCIDER)) ; for (index = 0 ; index < (int)nz ; index++) { BindStructCSC [index] = BindStruct [index] ; } diff --git a/src/ciderlib/twod/twosolve.c b/src/ciderlib/twod/twosolve.c index 53dfe6c43..8f75d8fb7 100644 --- a/src/ciderlib/twod/twosolve.c +++ b/src/ciderlib/twod/twosolve.c @@ -505,7 +505,7 @@ int TWOequilSolve(TWOdevice *pDevice) #ifdef KLU pDevice->matrix->CKTkluMODE = CKTkluON ; /* Francesco Lannutti - To be sustitued with a value coming from the uplevel */ - error = SMPnewMatrixKLUforCIDER (pDevice->matrix, pDevice->numEqns, CKTkluMatrixReal) ; + error = SMPnewMatrixKLUforCIDER (pDevice->matrix, pDevice->numEqns, KLUmatrixReal) ; #else error = SMPnewMatrixForCIDER (pDevice->matrix, pDevice->numEqns, 0) ; #endif @@ -519,7 +519,7 @@ int TWOequilSolve(TWOdevice *pDevice) #ifdef KLU if (pDevice->matrix->CKTkluMODE) { - pDevice->matrix->SMPkluMatrix->KLUmatrixIsComplex = CKTkluMatrixReal ; + pDevice->matrix->SMPkluMatrix->KLUmatrixIsComplex = KLUmatrixReal ; } else { #endif @@ -550,7 +550,8 @@ int TWOequilSolve(TWOdevice *pDevice) } } printf ("CIDER: KLU to be fixed: spElementCount\n") ; - pDevice->numOrigEquil = 0 ; // Francesco Lannutti - Fix for KLU + pDevice->numOrigEquil = 0 ; //pDevice->matrix->SMPkluMatrix->KLUmatrixNumeric->lnz + pDevice->matrix->SMPkluMatrix->KLUmatrixNumeric->unz + //+ pDevice->matrix->SMPkluMatrix->KLUmatrixNumeric->nzoff ; } else { pDevice->numOrigEquil = spElementCount (pDevice->matrix->SPmatrix) ; } @@ -580,9 +581,8 @@ int TWOequilSolve(TWOdevice *pDevice) #ifdef KLU if (pDevice->matrix->CKTkluMODE) { - // Francesco Lannutti - Fix for KLU - printf ("CIDER: KLU to be fixed: spFillinCount\n") ; - pDevice->numFillEquil = 0 ; + pDevice->numFillEquil = pDevice->matrix->SMPkluMatrix->KLUmatrixNumeric->lnz + pDevice->matrix->SMPkluMatrix->KLUmatrixNumeric->unz + + pDevice->matrix->SMPkluMatrix->KLUmatrixNumeric->nzoff - (int)pDevice->matrix->SMPkluMatrix->KLUmatrixNZ ; } else { #endif @@ -666,7 +666,7 @@ TWObiasSolve(TWOdevice *pDevice, int iterationLimit, BOOLEAN tranAnalysis, #ifdef KLU pDevice->matrix->CKTkluMODE = CKTkluON ; /* Francesco Lannutti - To be sustitued with a value coming from the uplevel */ - error = SMPnewMatrixKLUforCIDER (pDevice->matrix, pDevice->numEqns, CKTkluMatrixComplex) ; + error = SMPnewMatrixKLUforCIDER (pDevice->matrix, pDevice->numEqns, KLUMatrixComplex) ; #else error = SMPnewMatrixForCIDER (pDevice->matrix, pDevice->numEqns, 1) ; #endif @@ -708,7 +708,9 @@ TWObiasSolve(TWOdevice *pDevice, int iterationLimit, BOOLEAN tranAnalysis, return ; // Francesco Lannutti - Fix KLU return values } } - pDevice->numOrigBias = 0 ; // Francesco Lannutti - Fix for KLU + printf ("CIDER: KLU to be fixed: spElementCount\n") ; + pDevice->numOrigBias = 0 ; //pDevice->matrix->SMPkluMatrix->KLUmatrixNumeric->lnz + pDevice->matrix->SMPkluMatrix->KLUmatrixNumeric->unz + //+ pDevice->matrix->SMPkluMatrix->KLUmatrixNumeric->nzoff ; } else { pDevice->numOrigBias = spElementCount(pDevice->matrix->SPmatrix); } @@ -723,7 +725,7 @@ TWObiasSolve(TWOdevice *pDevice, int iterationLimit, BOOLEAN tranAnalysis, #ifdef KLU if (pDevice->matrix->CKTkluMODE) { - pDevice->matrix->SMPkluMatrix->KLUmatrixIsComplex = CKTkluMatrixReal ; + pDevice->matrix->SMPkluMatrix->KLUmatrixIsComplex = KLUmatrixReal ; } else { #endif @@ -753,13 +755,12 @@ TWObiasSolve(TWOdevice *pDevice, int iterationLimit, BOOLEAN tranAnalysis, #ifdef KLU if (pDevice->matrix->CKTkluMODE) { - // Francesco Lannutti - Fix for KLU - printf ("CIDER: KLU to be fixed: spFillinCount\n") ; - pDevice->numFillBias = 0 ; + pDevice->numFillBias = pDevice->matrix->SMPkluMatrix->KLUmatrixNumeric->lnz + pDevice->matrix->SMPkluMatrix->KLUmatrixNumeric->unz + + pDevice->matrix->SMPkluMatrix->KLUmatrixNumeric->nzoff - (int)pDevice->matrix->SMPkluMatrix->KLUmatrixNZ ; } else { #endif - pDevice->numFillBias = spFillinCount (pDevice->matrix->SPmatrix) ; // Francesco Lannutti - Fix for KLU + pDevice->numFillBias = spFillinCount (pDevice->matrix->SPmatrix) ; #ifdef KLU } diff --git a/src/include/ngspice/cktdefs.h b/src/include/ngspice/cktdefs.h index b4cbef2ee..6aa65744d 100644 --- a/src/include/ngspice/cktdefs.h +++ b/src/include/ngspice/cktdefs.h @@ -328,7 +328,7 @@ struct CKTcircuit { #ifdef KLU unsigned int CKTkluMODE:1; - unsigned int CKTkluMemGrowFactor : 1 ; + double CKTkluMemGrowFactor ; #endif }; diff --git a/src/include/ngspice/klu-binding.h b/src/include/ngspice/klu-binding.h index 5166399bc..6fde520fd 100644 --- a/src/include/ngspice/klu-binding.h +++ b/src/include/ngspice/klu-binding.h @@ -1,101 +1,118 @@ #ifndef _KLU_BINDING_H #define _KLU_BINDING_H +#include "ngspice/klu.h" + #define CREATE_KLU_BINDING_TABLE(ptr, binding, a, b) \ - if ((here->a != 0) && (here->b != 0)) { \ - i = here->ptr ; \ - matched = (BindElement *) bsearch (&i, BindStruct, nz, sizeof(BindElement), BindCompare) ; \ + if ((here->a > 0) && (here->b > 0)) { \ + i.COO = here->ptr ; \ + i.CSC = NULL ; \ + i.CSC_Complex = NULL ; \ + matched = (BindElement *) bsearch (&i, BindStruct, nz, sizeof (BindElement), BindCompare) ; \ + if (matched == NULL) { \ + printf ("Ptr %p not found in BindStruct Table\n", here->ptr) ; \ + } \ here->binding = matched ; \ here->ptr = matched->CSC ; \ } #define CONVERT_KLU_BINDING_TABLE_TO_COMPLEX(ptr, binding, a, b) \ - if ((here->a != 0) && (here->b != 0)) \ + if ((here->a > 0) && (here->b > 0)) \ here->ptr = here->binding->CSC_Complex ; #define CONVERT_KLU_BINDING_TABLE_TO_REAL(ptr, binding, a, b) \ - if ((here->a != 0) && (here->b != 0)) \ + if ((here->a > 0) && (here->b > 0)) \ here->ptr = here->binding->CSC ; #ifdef XSPICE #define CREATE_KLU_BINDING_TABLE_XSPICE_OUTPUTS(ptr, binding, a, b) \ - if ((smp_data_out->a != 0) && (smp_data_out->b != 0)) { \ - i = smp_data_out->ptr ; \ - matched = (BindElement *) bsearch (&i, BindStruct, nz, sizeof(BindElement), BindCompare) ; \ + if ((smp_data_out->a > 0) && (smp_data_out->b > 0)) { \ + i.COO = smp_data_out->ptr ; \ + i.CSC = NULL ; \ + i.CSC_Complex = NULL ; \ + matched = (BindElement *) bsearch (&i, BindStruct, nz, sizeof (BindElement), BindCompare) ; \ smp_data_out->binding = matched ; \ smp_data_out->ptr = matched->CSC ; \ } #define CONVERT_KLU_BINDING_TABLE_TO_COMPLEX_XSPICE_OUTPUTS(ptr, binding, a, b) \ - if ((smp_data_out->a != 0) && (smp_data_out->b != 0)) \ + if ((smp_data_out->a > 0) && (smp_data_out->b > 0)) \ smp_data_out->ptr = smp_data_out->binding->CSC_Complex ; #define CONVERT_KLU_BINDING_TABLE_TO_REAL_XSPICE_OUTPUTS(ptr, binding, a, b) \ - if ((smp_data_out->a != 0) && (smp_data_out->b != 0)) \ + if ((smp_data_out->a > 0) && (smp_data_out->b > 0)) \ smp_data_out->ptr = smp_data_out->binding->CSC ; #define CREATE_KLU_BINDING_TABLE_XSPICE_INPUTS_E(ptr, binding, a, b) \ - if ((smp_data_out->a != 0) && (smp_data_cntl->b != 0)) { \ - i = smp_data_out->input[k].port[l].ptr ; \ - matched = (BindElement *) bsearch (&i, BindStruct, nz, sizeof(BindElement), BindCompare) ; \ + if ((smp_data_out->a > 0) && (smp_data_cntl->b > 0)) { \ + i.COO = smp_data_out->input[k].port[l].ptr ; \ + i.CSC = NULL ; \ + i.CSC_Complex = NULL ; \ + matched = (BindElement *) bsearch (&i, BindStruct, nz, sizeof (BindElement), BindCompare) ; \ smp_data_out->input[k].port[l].e.binding = matched ; \ smp_data_out->input[k].port[l].ptr = matched->CSC ; \ } #define CONVERT_KLU_BINDING_TABLE_TO_COMPLEX_XSPICE_INPUTS_E(ptr, binding, a, b) \ - if ((smp_data_out->a != 0) && (smp_data_cntl->b != 0)) \ + if ((smp_data_out->a > 0) && (smp_data_cntl->b > 0)) \ smp_data_out->input[k].port[l].ptr = smp_data_out->input[k].port[l].e.binding->CSC_Complex ; #define CONVERT_KLU_BINDING_TABLE_TO_REAL_XSPICE_INPUTS_E(ptr, binding, a, b) \ - if ((smp_data_out->a != 0) && (smp_data_cntl->b != 0)) \ + if ((smp_data_out->a > 0) && (smp_data_cntl->b > 0)) \ smp_data_out->input[k].port[l].ptr = smp_data_out->input[k].port[l].e.binding->CSC ; #define CREATE_KLU_BINDING_TABLE_XSPICE_INPUTS_F(ptr, binding, a, b) \ - if ((smp_data_out->a != 0) && (smp_data_cntl->b != 0)) { \ - i = smp_data_out->input[k].port[l].ptr ; \ - matched = (BindElement *) bsearch (&i, BindStruct, nz, sizeof(BindElement), BindCompare) ; \ + if ((smp_data_out->a > 0) && (smp_data_cntl->b > 0)) { \ + i.COO = smp_data_out->input[k].port[l].ptr ; \ + i.CSC = NULL ; \ + i.CSC_Complex = NULL ; \ + matched = (BindElement *) bsearch (&i, BindStruct, nz, sizeof (BindElement), BindCompare) ; \ smp_data_out->input[k].port[l].f.binding = matched ; \ smp_data_out->input[k].port[l].ptr = matched->CSC ; \ } #define CONVERT_KLU_BINDING_TABLE_TO_COMPLEX_XSPICE_INPUTS_F(ptr, binding, a, b) \ - if ((smp_data_out->a != 0) && (smp_data_cntl->b != 0)) \ + if ((smp_data_out->a > 0) && (smp_data_cntl->b > 0)) \ smp_data_out->input[k].port[l].ptr = smp_data_out->input[k].port[l].f.binding->CSC_Complex ; #define CONVERT_KLU_BINDING_TABLE_TO_REAL_XSPICE_INPUTS_F(ptr, binding, a, b) \ - if ((smp_data_out->a != 0) && (smp_data_cntl->b != 0)) \ + if ((smp_data_out->a > 0) && (smp_data_cntl->b > 0)) \ smp_data_out->input[k].port[l].ptr = smp_data_out->input[k].port[l].f.binding->CSC ; #define CREATE_KLU_BINDING_TABLE_XSPICE_INPUTS_G(ptr, binding, a, b) \ - if ((smp_data_out->a != 0) && (smp_data_cntl->b != 0)) { \ - i = smp_data_out->input[k].port[l].ptr ; \ - matched = (BindElement *) bsearch (&i, BindStruct, nz, sizeof(BindElement), BindCompare) ; \ + if ((smp_data_out->a > 0) && (smp_data_cntl->b > 0)) { \ + i.COO = smp_data_out->input[k].port[l].ptr ; \ + i.CSC = NULL ; \ + i.CSC_Complex = NULL ; \ + matched = (BindElement *) bsearch (&i, BindStruct, nz, sizeof (BindElement), BindCompare) ; \ smp_data_out->input[k].port[l].g.binding = matched ; \ smp_data_out->input[k].port[l].ptr = matched->CSC ; \ } #define CONVERT_KLU_BINDING_TABLE_TO_COMPLEX_XSPICE_INPUTS_G(ptr, binding, a, b) \ - if ((smp_data_out->a != 0) && (smp_data_cntl->b != 0)) \ + if ((smp_data_out->a > 0) && (smp_data_cntl->b > 0)) \ smp_data_out->input[k].port[l].ptr = smp_data_out->input[k].port[l].g.binding->CSC_Complex ; #define CONVERT_KLU_BINDING_TABLE_TO_REAL_XSPICE_INPUTS_G(ptr, binding, a, b) \ - if ((smp_data_out->a != 0) && (smp_data_cntl->b != 0)) \ + if ((smp_data_out->a > 0) && (smp_data_cntl->b > 0)) \ smp_data_out->input[k].port[l].ptr = smp_data_out->input[k].port[l].g.binding->CSC ; #define CREATE_KLU_BINDING_TABLE_XSPICE_INPUTS_H(ptr, binding, a, b) \ - if ((smp_data_out->a != 0) && (smp_data_cntl->b != 0)) { \ - i = smp_data_out->input[k].port[l].ptr ; \ - matched = (BindElement *) bsearch (&i, BindStruct, nz, sizeof(BindElement), BindCompare) ; \ + if ((smp_data_out->a > 0) && (smp_data_cntl->b > 0)) { \ + i.COO = smp_data_out->input[k].port[l].ptr ; \ + i.CSC = NULL ; \ + i.CSC_Complex = NULL ; \ + matched = (BindElement *) bsearch (&i, BindStruct, nz, sizeof (BindElement), BindCompare) ; \ smp_data_out->input[k].port[l].h.binding = matched ; \ smp_data_out->input[k].port[l].ptr = matched->CSC ; \ } #define CONVERT_KLU_BINDING_TABLE_TO_COMPLEX_XSPICE_INPUTS_H(ptr, binding, a, b) \ - if ((smp_data_out->a != 0) && (smp_data_cntl->b != 0)) \ + if ((smp_data_out->a > 0) && (smp_data_cntl->b > 0)) \ smp_data_out->input[k].port[l].ptr = smp_data_out->input[k].port[l].h.binding->CSC_Complex ; #define CONVERT_KLU_BINDING_TABLE_TO_REAL_XSPICE_INPUTS_H(ptr, binding, a, b) \ - if ((smp_data_out->a != 0) && (smp_data_cntl->b != 0)) \ + if ((smp_data_out->a > 0) && (smp_data_cntl->b > 0)) \ smp_data_out->input[k].port[l].ptr = smp_data_out->input[k].port[l].h.binding->CSC ; #endif @@ -104,34 +121,35 @@ if ((a > 0) && (b > 0)) { \ if (pNode->binding != NULL) { \ if (pNode->binding->CSC_Complex != NULL) { \ - qsort (BindStructCSC, nz, sizeof(BindKluElementCOO), BindKluCompareCSC) ; \ - i.COO = NULL ; \ - i.CSC_Complex = pNode->binding->CSC_Complex ; \ - matched = (BindKluElementCOO *) bsearch (&i, BindStructCSC, nz, sizeof(BindKluElementCOO), BindKluCompareCSC) ; \ - if (matched == NULL) { \ - i.COO = pNode->ptr ; \ - i.CSC_Complex = NULL ; \ - matched = (BindKluElementCOO *) bsearch (&i, BindStruct, nz, sizeof(BindKluElementCOO), BindKluCompareCOO) ; \ - if (matched != NULL) { \ - pNode->binding = matched ; \ - pNode->ptr = matched->CSC_Complex ; \ - } \ - } \ - } else { \ - i.COO = pNode->ptr ; \ - i.CSC_Complex = NULL ; \ - matched = (BindKluElementCOO *) bsearch (&i, BindStruct, nz, sizeof(BindKluElementCOO), BindKluCompareCOO) ; \ + qsort (BindStructCSC, nz, sizeof (BindElementKLUforCIDER), BindKluCompareCSCKLUforCIDER) ; \ + i.COO = NULL ; \ + i.CSC_Complex = pNode->binding->CSC_Complex ; \ + matched = (BindElementKLUforCIDER *) bsearch (&i, BindStructCSC, nz, sizeof (BindElementKLUforCIDER), BindKluCompareCSCKLUforCIDER) ; \ + if (matched == NULL) { \ + i.COO = pNode->ptr ; \ + i.CSC_Complex = NULL ; \ + matched = (BindElementKLUforCIDER *) bsearch (&i, BindStruct, nz, sizeof (BindElementKLUforCIDER), BindCompareKLUforCIDER) ; \ + if (matched != NULL) { \ + pNode->binding = matched ; \ + pNode->ptr = matched->CSC_Complex ; \ + } \ + } \ + } else { \ + i.COO = pNode->ptr ; \ + i.CSC_Complex = NULL ; \ + matched = (BindElementKLUforCIDER *) bsearch (&i, BindStruct, nz, sizeof (BindElementKLUforCIDER), BindCompareKLUforCIDER) ; \ pNode->binding = matched ; \ - pNode->ptr = matched->CSC_Complex ; \ - } \ - } else { \ + pNode->ptr = matched->CSC_Complex ; \ + } \ + } else { \ i.COO = pNode->ptr ; \ - i.CSC_Complex = NULL ; \ - matched = (BindKluElementCOO *) bsearch (&i, BindStruct, nz, sizeof(BindKluElementCOO), BindKluCompareCOO) ; \ - pNode->binding = matched ; \ - pNode->ptr = matched->CSC_Complex ; \ - } \ + i.CSC_Complex = NULL ; \ + matched = (BindElementKLUforCIDER *) bsearch (&i, BindStruct, nz, sizeof (BindElementKLUforCIDER), BindCompareKLUforCIDER) ; \ + pNode->binding = matched ; \ + pNode->ptr = matched->CSC_Complex ; \ + } \ } #endif #endif + diff --git a/src/include/ngspice/klu.h b/src/include/ngspice/klu.h index 0a54106e2..f46eccc15 100644 --- a/src/include/ngspice/klu.h +++ b/src/include/ngspice/klu.h @@ -935,34 +935,63 @@ int klu_z_convert_matrix_in_CSR klu_common *Common ) ; +typedef struct sBindElement { + double *COO ; + double *CSC ; + double *CSC_Complex ; +} BindElement ; + #ifdef CIDER -typedef struct sBindKluElementCOO { +typedef struct sBindElementKLUforCIDER { double *COO ; double *CSC_Complex ; -} BindKluElementCOO ; +} BindElementKLUforCIDER ; +#endif -int BindKluCompareCOO (const void *a, const void *b) ; -int BindKluCompareCSC (const void *a, const void *b) ; +typedef struct sKluLinkedListCOO { + unsigned int row ; + unsigned int col ; + double *pointer ; + struct sKluLinkedListCOO *next ; +} KluLinkedListCOO ; + +int BindCompare (const void *a, const void *b) ; + +#ifdef CIDER +int BindCompareKLUforCIDER (const void *a, const void *b) ; +int BindKluCompareCSCKLUforCIDER (const void *a, const void *b) ; +#endif typedef struct sKLUmatrix { - klu_common *KLUmatrixCommon ; /* KLU common object */ - klu_symbolic *KLUmatrixSymbolic ; /* KLU symbolic object */ - klu_numeric *KLUmatrixNumeric ; /* KLU numeric object */ - int *KLUmatrixAp ; /* KLU column pointer */ - int *KLUmatrixAi ; /* KLU row pointer */ - double *KLUmatrixAxComplex ; /* KLU Complex Elements */ - unsigned int KLUmatrixIsComplex:1 ; /* KLU Matrix Is Complex Flag */ - double *KLUmatrixIntermediateComplex ; /* KLU iRHS Intermediate for Solve Complex Step */ - unsigned int KLUmatrixN ; /* KLU N, copied */ - unsigned int KLUmatrixNZ ; /* KLU nz, copied for AC Analysis */ - int *KLUmatrixColCOO ; /* KLU Col Index for COO storage */ - int *KLUmatrixRowCOO ; /* KLU Row Index for COO storage */ - double *KLUmatrixValueComplexCOO ; /* KLU Complex Elements for COO storage */ - BindKluElementCOO *KLUmatrixBindStructCOO ; /* KLU COO Binding Structure */ - double *KLUmatrixTrashCOO ; /* KLU COO Trash Pointer for Ground Node not Stored in the Matrix */ -} KLUmatrix ; + klu_common *KLUmatrixCommon ; /* KLU common object */ + klu_symbolic *KLUmatrixSymbolic ; /* KLU symbolic object */ + klu_numeric *KLUmatrixNumeric ; /* KLU numeric object */ + int *KLUmatrixAp ; /* KLU column pointer */ + int *KLUmatrixAi ; /* KLU row pointer */ + double *KLUmatrixAx ; /* KLU Real Elements */ + double *KLUmatrixAxComplex ; /* KLU Complex Elements */ + unsigned int KLUmatrixIsComplex:1 ; /* KLU Matrix Is Complex Flag */ + #define KLUmatrixReal 0 /* KLU Matrix Real definition */ + #define KLUMatrixComplex 1 /* KLU Matrix Complex definition */ + double *KLUmatrixIntermediate ; /* KLU RHS Intermediate for Solve Real Step */ + double *KLUmatrixIntermediateComplex ; /* KLU iRHS Intermediate for Solve Complex Step */ + unsigned int KLUmatrixN ; /* KLU N */ + unsigned int KLUmatrixNZ ; /* KLU nz */ + BindElement *KLUmatrixBindStructCOO ; /* KLU COO Binding Structure */ + KluLinkedListCOO *KLUmatrixLinkedListCOO ; /* KLU COO in Linked List Format for Initial Parsing */ + unsigned int KLUmatrixLinkedListNZ ; /* KLU nz for the Initial Parsing */ + double *KLUmatrixTrashCOO ; /* KLU COO Trash Pointer for Ground Node not Stored in the Matrix */ + double **KLUmatrixDiag ; /* KLU pointer to diagonal element to perform Gmin */ + +#ifdef CIDER + int *KLUmatrixColCOOforCIDER ; /* KLU Col Index for COO storage (for CIDER) */ + int *KLUmatrixRowCOOforCIDER ; /* KLU Row Index for COO storage (for CIDER) */ + double *KLUmatrixValueComplexCOOforCIDER ; /* KLU Complex Elements for COO storage (for CIDER) */ + BindElementKLUforCIDER *KLUmatrixBindStructForCIDER ; /* KLU COO Binding Structure (for CIDER) */ #endif +} KLUmatrix ; + /* ========================================================================== */ /* === KLU version ========================================================== */ /* ========================================================================== */ diff --git a/src/include/ngspice/onemesh.h b/src/include/ngspice/onemesh.h index 6228ab825..e70d95cf3 100644 --- a/src/include/ngspice/onemesh.h +++ b/src/include/ngspice/onemesh.h @@ -38,10 +38,10 @@ typedef struct sONEelem { double *KLUrightLeftNode ; double *KLUrightRightNode ; - BindKluElementCOO *KLUleftLeftNodeBinding ; - BindKluElementCOO *KLUleftRightNodeBinding ; - BindKluElementCOO *KLUrightLeftNodeBinding ; - BindKluElementCOO *KLUrightRightNodeBinding ; + BindElementKLUforCIDER *KLUleftLeftNodeBinding ; + BindElementKLUforCIDER *KLUleftRightNodeBinding ; + BindElementKLUforCIDER *KLUrightLeftNodeBinding ; + BindElementKLUforCIDER *KLUrightRightNodeBinding ; #endif @@ -132,29 +132,29 @@ typedef struct sONEnode { double *fPNiP1; #ifdef KLU - BindKluElementCOO *fPsiPsiiM1Binding ; - BindKluElementCOO *fPsiPsiBinding ; - BindKluElementCOO *fPsiPsiiP1Binding ; - BindKluElementCOO *fPsiNBinding ; - BindKluElementCOO *fPsiPBinding ; - BindKluElementCOO *fNPsiiM1Binding ; - BindKluElementCOO *fNPsiBinding ; - BindKluElementCOO *fNPsiiP1Binding ; - BindKluElementCOO *fNNiM1Binding ; - BindKluElementCOO *fNNBinding ; - BindKluElementCOO *fNNiP1Binding ; - BindKluElementCOO *fNPiM1Binding ; - BindKluElementCOO *fNPBinding ; - BindKluElementCOO *fNPiP1Binding ; - BindKluElementCOO *fPPsiiM1Binding ; - BindKluElementCOO *fPPsiBinding ; - BindKluElementCOO *fPPsiiP1Binding ; - BindKluElementCOO *fPPiM1Binding ; - BindKluElementCOO *fPPBinding ; - BindKluElementCOO *fPPiP1Binding ; - BindKluElementCOO *fPNiM1Binding ; - BindKluElementCOO *fPNBinding ; - BindKluElementCOO *fPNiP1Binding ; + BindElementKLUforCIDER *fPsiPsiiM1Binding ; + BindElementKLUforCIDER *fPsiPsiBinding ; + BindElementKLUforCIDER *fPsiPsiiP1Binding ; + BindElementKLUforCIDER *fPsiNBinding ; + BindElementKLUforCIDER *fPsiPBinding ; + BindElementKLUforCIDER *fNPsiiM1Binding ; + BindElementKLUforCIDER *fNPsiBinding ; + BindElementKLUforCIDER *fNPsiiP1Binding ; + BindElementKLUforCIDER *fNNiM1Binding ; + BindElementKLUforCIDER *fNNBinding ; + BindElementKLUforCIDER *fNNiP1Binding ; + BindElementKLUforCIDER *fNPiM1Binding ; + BindElementKLUforCIDER *fNPBinding ; + BindElementKLUforCIDER *fNPiP1Binding ; + BindElementKLUforCIDER *fPPsiiM1Binding ; + BindElementKLUforCIDER *fPPsiBinding ; + BindElementKLUforCIDER *fPPsiiP1Binding ; + BindElementKLUforCIDER *fPPiM1Binding ; + BindElementKLUforCIDER *fPPBinding ; + BindElementKLUforCIDER *fPPiP1Binding ; + BindElementKLUforCIDER *fPNiM1Binding ; + BindElementKLUforCIDER *fPNBinding ; + BindElementKLUforCIDER *fPNiP1Binding ; #endif } ONEnode; diff --git a/src/include/ngspice/smpdefs.h b/src/include/ngspice/smpdefs.h index 2b8a40ff4..f6cf5a28d 100644 --- a/src/include/ngspice/smpdefs.h +++ b/src/include/ngspice/smpdefs.h @@ -28,39 +28,19 @@ typedef struct sSMPmatrix { MatrixFrame *SPmatrix ; /* pointer to sparse matrix */ #ifdef KLU - klu_common *CKTkluCommon ; /* KLU common object */ - klu_symbolic *CKTkluSymbolic ; /* KLU symbolic object */ - klu_numeric *CKTkluNumeric ; /* KLU numeric object */ - int *CKTkluAp ; /* KLU column pointer */ - int *CKTkluAi ; /* KLU row pointer */ - double *CKTkluAx ; /* KLU Real Elements */ - double *CKTkluAx_Complex ; /* KLU Complex Elements */ - unsigned int CKTkluMatrixIsComplex:1 ; /* KLU Matrix Is Complex Flag */ - #define CKTkluMatrixReal 0 /* KLU Matrix Real definition */ - #define CKTkluMatrixComplex 1 /* KLU Matrix Complex definition */ - double *CKTkluIntermediate ; /* KLU RHS Intermediate for Solve Real Step */ - double *CKTkluIntermediate_Complex ; /* KLU iRHS Intermediate for Solve Complex Step */ - BindElement *CKTbindStruct ; /* KLU - Sparse Binding Structure */ - double **CKTdiag_CSC ; /* KLU pointer to diagonal element to perform Gmin */ - int CKTkluN ; /* KLU N, copied */ - int CKTklunz ; /* KLU nz, copied for AC Analysis */ + KLUmatrix *SMPkluMatrix ; /* KLU Pointer to the KLU Matrix Data Structure (only for CIDER, for the moment) */ unsigned int CKTkluMODE:1 ; /* KLU MODE parameter to enable KLU or not from the heuristic */ #define CKTkluON 1 /* KLU MODE ON definition */ #define CKTkluOFF 0 /* KLU MODE OFF definition */ - -#ifdef CIDER - KLUmatrix *SMPkluMatrix ; /* KLU Pointer to the KLU Matrix Data Structure (only for CIDER, for the moment) */ -#endif - + double CKTkluMemGrowFactor ; /* KLU Memory Grow Factor - default = 1.2 */ #endif } SMPmatrix ; #ifdef KLU -void SMPmatrix_CSC (SMPmatrix *) ; -void SMPnnz (SMPmatrix *) ; void spDeterminant_KLU (SMPmatrix *, int *, double *, double *) ; +void SMPconvertCOOtoCSC (SMPmatrix *) ; #ifdef CIDER void SMPsolveKLUforCIDER (SMPmatrix *, double [], double [], double [], double []) ; @@ -74,9 +54,10 @@ int SMPluFacKLUforCIDER (SMPmatrix *) ; void SMPprintKLUforCIDER (SMPmatrix *, char *) ; #endif +#else +int SMPaddElt (SMPmatrix *, int, int, double) ; #endif -int SMPaddElt( SMPmatrix *, int , int , double ); double * SMPmakeElt( SMPmatrix * , int , int ); void SMPcClear( SMPmatrix *); void SMPclear( SMPmatrix *); @@ -112,3 +93,4 @@ void SMPsolveForCIDER (SMPmatrix *, double [], double []) ; #endif #endif + diff --git a/src/include/ngspice/spmatrix.h b/src/include/ngspice/spmatrix.h index 5ffd418b2..5c23e34d4 100644 --- a/src/include/ngspice/spmatrix.h +++ b/src/include/ngspice/spmatrix.h @@ -296,20 +296,7 @@ extern void spMultTransposed(MatrixPtr,spREAL*,spREAL*,spREAL*,spREAL*); extern void spSolve( MatrixPtr, spREAL*, spREAL*, spREAL*, spREAL* ); extern void spSolveTransposed(MatrixPtr,spREAL*,spREAL*,spREAL*,spREAL*); -/* Francesco Lannutti - CSC Data Structure Conversion */ -#ifdef KLU -typedef struct sBindElement { - double *Sparse ; - double *CSC ; - double *CSC_Complex ; -} BindElement ; - -extern int WriteCol_original (MatrixPtr, int, spREAL *, spREAL *, int *, BindElement *, spREAL **) ; -extern int WriteCol_original_dump (MatrixPtr, int, spREAL *, int *, unsigned int) ; -extern void spMatrix_CSC (MatrixPtr, int *, int *, double *, double *, int, BindElement *, double **) ; -extern void spMatrix_CSC_dump (MatrixPtr, unsigned int, char *) ; -extern void spRHS_CSC_dump (spREAL *, char *, MatrixPtr) ; -#endif /* ------------------------------------------------------ */ #endif /* spOKAY */ + diff --git a/src/include/ngspice/tskdefs.h b/src/include/ngspice/tskdefs.h index 7f624d5e2..9d59bd4b4 100644 --- a/src/include/ngspice/tskdefs.h +++ b/src/include/ngspice/tskdefs.h @@ -76,7 +76,7 @@ struct TSKtask { #ifdef KLU unsigned int TSKkluMODE:1; - unsigned int TSKkluMemGrowFactor : 1 ; + double TSKkluMemGrowFactor ; #endif }; diff --git a/src/include/ngspice/twomesh.h b/src/include/ngspice/twomesh.h index 6c07a777e..19de88655 100644 --- a/src/include/ngspice/twomesh.h +++ b/src/include/ngspice/twomesh.h @@ -55,11 +55,10 @@ typedef struct sTWOelem double *KLUrightLeftNode ; double *KLUrightRightNode ; - BindKluElementCOO *KLUleftLeftNodeBinding ; - BindKluElementCOO *KLUleftRightNodeBinding ; - BindKluElementCOO *KLUrightLeftNodeBinding ; - BindKluElementCOO *KLUrightRightNodeBinding ; - + BindElementKLUforCIDER *KLUleftLeftNodeBinding ; + BindElementKLUforCIDER *KLUleftRightNodeBinding ; + BindElementKLUforCIDER *KLUrightLeftNodeBinding ; + BindElementKLUforCIDER *KLUrightRightNodeBinding ; #endif } TWOelem; @@ -213,63 +212,63 @@ typedef struct sTWOnode { double *fPPsiOxP1; #ifdef KLU - BindKluElementCOO *fPsiPsiBinding ; - BindKluElementCOO *fPsiNBinding ; - BindKluElementCOO *fPsiPBinding ; - BindKluElementCOO *fNPsiBinding ; - BindKluElementCOO *fNNBinding ; - BindKluElementCOO *fNPBinding ; - BindKluElementCOO *fPPsiBinding ; - BindKluElementCOO *fPNBinding ; - BindKluElementCOO *fPPBinding ; - BindKluElementCOO *fPsiPsiiP1Binding ; - BindKluElementCOO *fPsiPsijP1Binding ; - BindKluElementCOO *fNPsiiP1Binding ; - BindKluElementCOO *fNNiP1Binding ; - BindKluElementCOO *fNPsijP1Binding ; - BindKluElementCOO *fNNjP1Binding ; - BindKluElementCOO *fPPsiiP1Binding ; - BindKluElementCOO *fPPiP1Binding ; - BindKluElementCOO *fPPsijP1Binding ; - BindKluElementCOO *fPPjP1Binding ; - BindKluElementCOO *fNPsiiP1jP1Binding ; - BindKluElementCOO *fNNiP1jP1Binding ; - BindKluElementCOO *fPPsiiP1jP1Binding ; - BindKluElementCOO *fPPiP1jP1Binding ; - BindKluElementCOO *fPsiPsiiM1Binding ; - BindKluElementCOO *fNPsiiM1Binding ; - BindKluElementCOO *fNNiM1Binding ; - BindKluElementCOO *fPPsiiM1Binding ; - BindKluElementCOO *fPPiM1Binding ; - BindKluElementCOO *fNPsiiM1jP1Binding ; - BindKluElementCOO *fNNiM1jP1Binding ; - BindKluElementCOO *fPPsiiM1jP1Binding ; - BindKluElementCOO *fPPiM1jP1Binding ; - BindKluElementCOO *fPsiPsijM1Binding ; - BindKluElementCOO *fNPsijM1Binding ; - BindKluElementCOO *fNNjM1Binding ; - BindKluElementCOO *fPPsijM1Binding ; - BindKluElementCOO *fPPjM1Binding ; - BindKluElementCOO *fNPsiiM1jM1Binding ; - BindKluElementCOO *fNNiM1jM1Binding ; - BindKluElementCOO *fPPsiiM1jM1Binding ; - BindKluElementCOO *fPPiM1jM1Binding ; - BindKluElementCOO *fNPsiiP1jM1Binding ; - BindKluElementCOO *fNNiP1jM1Binding ; - BindKluElementCOO *fPPsiiP1jM1Binding ; - BindKluElementCOO *fPPiP1jM1Binding ; - BindKluElementCOO *fNPsiInBinding ; - BindKluElementCOO *fNPsiInP1Binding ; - BindKluElementCOO *fNPsiOxBinding ; - BindKluElementCOO *fNPsiOxP1Binding ; - BindKluElementCOO *fPPsiInBinding ; - BindKluElementCOO *fPPsiInP1Binding ; - BindKluElementCOO *fPPsiOxBinding ; - BindKluElementCOO *fPPsiOxP1Binding ; - BindKluElementCOO *fNPsiInM1Binding ; - BindKluElementCOO *fNPsiOxM1Binding ; - BindKluElementCOO *fPPsiInM1Binding ; - BindKluElementCOO *fPPsiOxM1Binding ; + BindElementKLUforCIDER *fPsiPsiBinding ; + BindElementKLUforCIDER *fPsiNBinding ; + BindElementKLUforCIDER *fPsiPBinding ; + BindElementKLUforCIDER *fNPsiBinding ; + BindElementKLUforCIDER *fNNBinding ; + BindElementKLUforCIDER *fNPBinding ; + BindElementKLUforCIDER *fPPsiBinding ; + BindElementKLUforCIDER *fPNBinding ; + BindElementKLUforCIDER *fPPBinding ; + BindElementKLUforCIDER *fPsiPsiiP1Binding ; + BindElementKLUforCIDER *fPsiPsijP1Binding ; + BindElementKLUforCIDER *fNPsiiP1Binding ; + BindElementKLUforCIDER *fNNiP1Binding ; + BindElementKLUforCIDER *fNPsijP1Binding ; + BindElementKLUforCIDER *fNNjP1Binding ; + BindElementKLUforCIDER *fPPsiiP1Binding ; + BindElementKLUforCIDER *fPPiP1Binding ; + BindElementKLUforCIDER *fPPsijP1Binding ; + BindElementKLUforCIDER *fPPjP1Binding ; + BindElementKLUforCIDER *fNPsiiP1jP1Binding ; + BindElementKLUforCIDER *fNNiP1jP1Binding ; + BindElementKLUforCIDER *fPPsiiP1jP1Binding ; + BindElementKLUforCIDER *fPPiP1jP1Binding ; + BindElementKLUforCIDER *fPsiPsiiM1Binding ; + BindElementKLUforCIDER *fNPsiiM1Binding ; + BindElementKLUforCIDER *fNNiM1Binding ; + BindElementKLUforCIDER *fPPsiiM1Binding ; + BindElementKLUforCIDER *fPPiM1Binding ; + BindElementKLUforCIDER *fNPsiiM1jP1Binding ; + BindElementKLUforCIDER *fNNiM1jP1Binding ; + BindElementKLUforCIDER *fPPsiiM1jP1Binding ; + BindElementKLUforCIDER *fPPiM1jP1Binding ; + BindElementKLUforCIDER *fPsiPsijM1Binding ; + BindElementKLUforCIDER *fNPsijM1Binding ; + BindElementKLUforCIDER *fNNjM1Binding ; + BindElementKLUforCIDER *fPPsijM1Binding ; + BindElementKLUforCIDER *fPPjM1Binding ; + BindElementKLUforCIDER *fNPsiiM1jM1Binding ; + BindElementKLUforCIDER *fNNiM1jM1Binding ; + BindElementKLUforCIDER *fPPsiiM1jM1Binding ; + BindElementKLUforCIDER *fPPiM1jM1Binding ; + BindElementKLUforCIDER *fNPsiiP1jM1Binding ; + BindElementKLUforCIDER *fNNiP1jM1Binding ; + BindElementKLUforCIDER *fPPsiiP1jM1Binding ; + BindElementKLUforCIDER *fPPiP1jM1Binding ; + BindElementKLUforCIDER *fNPsiInBinding ; + BindElementKLUforCIDER *fNPsiInP1Binding ; + BindElementKLUforCIDER *fNPsiOxBinding ; + BindElementKLUforCIDER *fNPsiOxP1Binding ; + BindElementKLUforCIDER *fPPsiInBinding ; + BindElementKLUforCIDER *fPPsiInP1Binding ; + BindElementKLUforCIDER *fPPsiOxBinding ; + BindElementKLUforCIDER *fPPsiOxP1Binding ; + BindElementKLUforCIDER *fNPsiInM1Binding ; + BindElementKLUforCIDER *fNPsiOxM1Binding ; + BindElementKLUforCIDER *fPPsiInM1Binding ; + BindElementKLUforCIDER *fPPsiOxM1Binding ; #endif } TWOnode; diff --git a/src/maths/KLU/klu_defaults.c b/src/maths/KLU/klu_defaults.c index 0369a37f3..22b0ed2f0 100644 --- a/src/maths/KLU/klu_defaults.c +++ b/src/maths/KLU/klu_defaults.c @@ -18,8 +18,8 @@ Int KLU_defaults /* parameters */ Common->tol = 0.001 ; /* pivot tolerance for diagonal */ - Common->memgrow = 1.2; /* realloc size ratio increase for LU factors */ - Common->initmem_amd = 1.2 ; /* init. mem with AMD: c*nnz(L) + n */ + Common->memgrow = 10; /* realloc size ratio increase for LU factors */ + Common->initmem_amd = 10 ; /* init. mem with AMD: c*nnz(L) + n */ Common->initmem = 10 ; /* init. mem otherwise: c*nnz(A) + n */ Common->btf = TRUE ; /* use BTF pre-ordering, or not */ Common->maxwork = 0 ; /* no limit to work done by btf_order */ diff --git a/src/maths/KLU/klusmp.c b/src/maths/KLU/klusmp.c index ab6bb77fc..3b0ed9cc2 100644 --- a/src/maths/KLU/klusmp.c +++ b/src/maths/KLU/klusmp.c @@ -1,98 +1,7 @@ -/* - * Spice3 COMPATIBILITY MODULE - * - * Author: Advising professor: - * Kenneth S. Kundert Alberto Sangiovanni-Vincentelli - * UC Berkeley - * - * This module contains routines that make Sparse1.3 a direct - * replacement for the SMP sparse matrix package in Spice3c1 or Spice3d1. - * Sparse1.3 is in general a faster and more robust package than SMP. - * These advantages become significant on large circuits. - * - * >>> User accessible functions contained in this file: - * SMPaddElt - * SMPmakeElt - * SMPcClear - * SMPclear - * SMPcLUfac - * SMPluFac - * SMPcReorder - * SMPreorder - * SMPcaSolve - * SMPcSolve - * SMPsolve - * SMPmatSize - * SMPnewMatrix - * SMPdestroy - * SMPpreOrder - * SMPprint - * SMPgetError - * SMPcProdDiag - * LoadGmin - * SMPfindElt - * SMPcombine - * SMPcCombine - */ - -/* - * To replace SMP with Sparse, rename the file spSpice3.h to - * spMatrix.h and place Sparse in a subdirectory of SPICE called - * `sparse'. Then on UNIX compile Sparse by executing `make spice'. - * If not on UNIX, after compiling Sparse and creating the sparse.a - * archive, compile this file (spSMP.c) and spSMP.o to the archive, - * then copy sparse.a into the SPICE main directory and rename it - * SMP.a. Finally link SPICE. - * - * To be compatible with SPICE, the following Sparse compiler options - * (in spConfig.h) should be set as shown below: - * - * EXPANDABLE YES - * TRANSLATE NO - * INITIALIZE NO or YES, YES for use with test prog. - * DIAGONAL_PIVOTING YES - * MODIFIED_MARKOWITZ NO - * DELETE NO - * STRIP NO - * MODIFIED_NODAL YES - * QUAD_ELEMENT NO - * TRANSPOSE YES - * SCALING NO - * DOCUMENTATION YES - * MULTIPLICATION NO - * DETERMINANT YES - * STABILITY NO - * CONDITION NO - * PSEUDOCONDITION NO - * DEBUG YES - * - * spREAL double - */ - -/* - * Revision and copyright information. - * - * Copyright (c) 1985,86,87,88,89,90 - * by Kenneth S. Kundert and the University of California. - * - * Permission to use, copy, modify, and distribute this software and its - * documentation for any purpose and without fee is hereby granted, provided - * that the above copyright notice appear in all copies and supporting - * documentation and that the authors and the University of California - * are properly credited. The authors and the University of California - * make no representations as to the suitability of this software for - * any purpose. It is provided `as is', without express or implied warranty. - */ - -/* - * IMPORTS - * - * >>> Import descriptions: - * spMatrix.h - * Sparse macros and declarations. - * SMPdefs.h - * Spice3's matrix macro definitions. - */ +/* KLU to SMP Interface + * Francesco Lannutti + * July 2020 +*/ #include "ngspice/config.h" #include @@ -108,33 +17,14 @@ extern double scalbn(double, int); extern double logb(double); #endif -static void LoadGmin_CSC (double **diag, int n, double Gmin) ; +static void LoadGmin_CSC (double **diag, unsigned int n, double Gmin) ; static void LoadGmin (SMPmatrix *eMatrix, double Gmin) ; -void -SMPmatrix_CSC (SMPmatrix *Matrix) -{ - spMatrix_CSC (Matrix->SPmatrix, Matrix->CKTkluAp, Matrix->CKTkluAi, Matrix->CKTkluAx, - Matrix->CKTkluAx_Complex, Matrix->CKTkluN, Matrix->CKTbindStruct, Matrix->CKTdiag_CSC) ; - -// spMatrix_CSC_dump (Matrix->SPmatrix, 1, NULL) ; - - return ; -} - -void -SMPnnz (SMPmatrix *Matrix) -{ - Matrix->CKTklunz = Matrix->SPmatrix->Elements ; - - return ; -} - -#ifdef CIDER typedef struct sElement { - unsigned int row ; - unsigned int col ; - double *pointer ; + unsigned int row ; + unsigned int col ; + double *pointer ; + unsigned int group ; } Element ; static int @@ -189,10 +79,23 @@ Compress (unsigned int *Ai, unsigned int *Bp, unsigned int n, unsigned int nz) } int -BindKluCompareCOO (const void *a, const void *b) +BindCompare (const void *a, const void *b) { - BindKluElementCOO *A = (BindKluElementCOO *) a ; - BindKluElementCOO *B = (BindKluElementCOO *) b ; + BindElement *A = (BindElement *) a ; + BindElement *B = (BindElement *) b ; + + return + (A->COO > B->COO) ? 1 : + (A->COO < B->COO) ? -1 : + 0 ; +} + +#ifdef CIDER +int +BindCompareKLUforCIDER (const void *a, const void *b) +{ + BindElementKLUforCIDER *A = (BindElementKLUforCIDER *) a ; + BindElementKLUforCIDER *B = (BindElementKLUforCIDER *) b ; return (A->COO > B->COO) ? 1 : @@ -201,57 +104,179 @@ BindKluCompareCOO (const void *a, const void *b) } int -BindKluCompareCSC (const void *a, const void *b) +BindKluCompareCSCKLUforCIDER (const void *a, const void *b) { - BindKluElementCOO *A = (BindKluElementCOO *) a ; - BindKluElementCOO *B = (BindKluElementCOO *) b ; + BindElementKLUforCIDER *A = (BindElementKLUforCIDER *) a ; + BindElementKLUforCIDER *B = (BindElementKLUforCIDER *) b ; return (A->CSC_Complex > B->CSC_Complex) ? 1 : (A->CSC_Complex < B->CSC_Complex) ? -1 : 0 ; } +#endif + +void SMPconvertCOOtoCSC (SMPmatrix *Matrix) +{ + Element *MatrixCOO ; + KluLinkedListCOO *current, *temp ; + unsigned int *Ap_COO, current_group, i, j ; + + /* Allocate the compressed COO elements */ + MatrixCOO = (Element *) malloc (Matrix->SMPkluMatrix->KLUmatrixLinkedListNZ * sizeof (Element)) ; + + /* Populate the compressed COO elements and COO value of Binding Table */ + /* Delete the Linked List in the meantime */ + i = 0 ; + temp = Matrix->SMPkluMatrix->KLUmatrixLinkedListCOO ; + while (temp != NULL) { + MatrixCOO [i].row = temp->row ; + MatrixCOO [i].col = temp->col ; + MatrixCOO [i].pointer = temp->pointer ; + MatrixCOO [i].group = 0 ; + current = temp ; + temp = temp->next ; + free (current) ; + current = NULL ; + i++ ; + } + + /* Order the MatrixCOO along the columns */ + qsort (MatrixCOO, Matrix->SMPkluMatrix->KLUmatrixLinkedListNZ, sizeof (Element), CompareColumn) ; + + /* Order the MatrixCOO along the rows */ + i = 0 ; + while (i < Matrix->SMPkluMatrix->KLUmatrixLinkedListNZ) + { + /* Look for the next column */ + for (j = i + 1 ; j < Matrix->SMPkluMatrix->KLUmatrixLinkedListNZ ; j++) + { + if (MatrixCOO [j].col != MatrixCOO [i].col) + { + break ; + } + } + + qsort (MatrixCOO + i, j - i, sizeof (Element), CompareRow) ; + + i = j ; + } + + /* Assign labels to avoid duplicates */ + for (i = 0, j = 1 ; i < Matrix->SMPkluMatrix->KLUmatrixLinkedListNZ - 1 ; i++, j++) { + if ((MatrixCOO [i].col == MatrixCOO [j].col) && (MatrixCOO [i].row == MatrixCOO [j].row)) { + // If col and row are the same + MatrixCOO [j].group = MatrixCOO [i].group ; + } else if ((MatrixCOO [i].col != MatrixCOO [j].col) || (MatrixCOO [i].row != MatrixCOO [j].row)) { + // If or col either row are different, it isn't a duplicate, so assign the next label and store it in 'nz' + MatrixCOO [j].group = MatrixCOO [i].group + 1 ; + } else { + printf ("Error: Strange behavior during label assignment\n") ; + } + } + + /* Assign N and NZ */ + Matrix->SMPkluMatrix->KLUmatrixN = (unsigned int)MatrixCOO [Matrix->SMPkluMatrix->KLUmatrixLinkedListNZ - 1].col + 1 ; + Matrix->SMPkluMatrix->KLUmatrixNZ = MatrixCOO [Matrix->SMPkluMatrix->KLUmatrixLinkedListNZ - 1].group + 1 ; + + /* Allocate Diag Gmin CSC Vector */ + Matrix->SMPkluMatrix->KLUmatrixDiag = (double **) malloc (Matrix->SMPkluMatrix->KLUmatrixN * sizeof (double *)) ; + for (i = 0 ; i < Matrix->SMPkluMatrix->KLUmatrixN ; i++) { + Matrix->SMPkluMatrix->KLUmatrixDiag [i] = NULL ; + } + + /* Allocate the temporary COO Column Index */ + Ap_COO = (unsigned int *) malloc (Matrix->SMPkluMatrix->KLUmatrixNZ * sizeof (unsigned int)) ; + + /* Allocate the needed KLU data structures */ + Matrix->SMPkluMatrix->KLUmatrixAp = (int *) malloc ((Matrix->SMPkluMatrix->KLUmatrixN + 1) * sizeof (int)) ; + Matrix->SMPkluMatrix->KLUmatrixAi = (int *) malloc (Matrix->SMPkluMatrix->KLUmatrixNZ * sizeof (int)) ; + Matrix->SMPkluMatrix->KLUmatrixBindStructCOO = (BindElement *) malloc (Matrix->SMPkluMatrix->KLUmatrixLinkedListNZ * sizeof (BindElement)) ; + Matrix->SMPkluMatrix->KLUmatrixAx = (double *) malloc (Matrix->SMPkluMatrix->KLUmatrixNZ * sizeof (double)) ; + Matrix->SMPkluMatrix->KLUmatrixAxComplex = (double *) malloc (2 * Matrix->SMPkluMatrix->KLUmatrixNZ * sizeof (double)) ; + Matrix->SMPkluMatrix->KLUmatrixIntermediate = (double *) malloc (Matrix->SMPkluMatrix->KLUmatrixN * sizeof (double)) ; + Matrix->SMPkluMatrix->KLUmatrixIntermediateComplex = (double *) malloc (2 * Matrix->SMPkluMatrix->KLUmatrixN * sizeof (double)) ; + + /* Copy back the Matrix in partial CSC */ + for (i = 0, current_group = 0 ; i < Matrix->SMPkluMatrix->KLUmatrixLinkedListNZ ; i++) + { + if (MatrixCOO [i].group > current_group) { + current_group = MatrixCOO [i].group ; + } + + Ap_COO [current_group] = MatrixCOO [i].col ; + Matrix->SMPkluMatrix->KLUmatrixAi [current_group] = (int)MatrixCOO [i].row ; + Matrix->SMPkluMatrix->KLUmatrixBindStructCOO [i].COO = MatrixCOO [i].pointer ; + Matrix->SMPkluMatrix->KLUmatrixBindStructCOO [i].CSC = &(Matrix->SMPkluMatrix->KLUmatrixAx [current_group]) ; + Matrix->SMPkluMatrix->KLUmatrixBindStructCOO [i].CSC_Complex = &(Matrix->SMPkluMatrix->KLUmatrixAxComplex [2 * current_group]) ; + if (MatrixCOO [i].col == MatrixCOO [i].row) { + Matrix->SMPkluMatrix->KLUmatrixDiag [MatrixCOO [i].col] = Matrix->SMPkluMatrix->KLUmatrixBindStructCOO [i].CSC ; + } + } + + /* Compress the COO Column Index to CSC Column Index */ + Compress (Ap_COO, (unsigned int *)Matrix->SMPkluMatrix->KLUmatrixAp, Matrix->SMPkluMatrix->KLUmatrixN, Matrix->SMPkluMatrix->KLUmatrixNZ) ; + + /* Free the temporary stuff */ + free (Ap_COO) ; + free (MatrixCOO) ; + + /* Sort the Binding Table */ + qsort (Matrix->SMPkluMatrix->KLUmatrixBindStructCOO, Matrix->SMPkluMatrix->KLUmatrixLinkedListNZ, sizeof (BindElement), BindCompare) ; + + /* Set the Matrix as Real */ + Matrix->SMPkluMatrix->KLUmatrixIsComplex = KLUmatrixReal ; + + return ; +} + +#ifdef CIDER +typedef struct sElementKLUforCIDER { + unsigned int row ; + unsigned int col ; + double *pointer ; +} ElementKLUforCIDER ; void SMPconvertCOOtoCSCKLUforCIDER (SMPmatrix *Matrix) { - Element *MatrixCOO ; + ElementKLUforCIDER *MatrixCOO ; unsigned int *Ap_COO, i, j, nz ; /* Count the non-zero elements and store it */ nz = 0 ; for (i = 0 ; i < Matrix->SMPkluMatrix->KLUmatrixN * Matrix->SMPkluMatrix->KLUmatrixN ; i++) { - if ((Matrix->SMPkluMatrix->KLUmatrixRowCOO [i] != -1) && (Matrix->SMPkluMatrix->KLUmatrixColCOO [i] != -1)) { + if ((Matrix->SMPkluMatrix->KLUmatrixRowCOOforCIDER [i] != -1) && (Matrix->SMPkluMatrix->KLUmatrixColCOOforCIDER [i] != -1)) { nz++ ; } } Matrix->SMPkluMatrix->KLUmatrixNZ = nz ; /* Allocate the compressed COO elements */ - MatrixCOO = (Element *) malloc (nz * sizeof(Element)) ; + MatrixCOO = (ElementKLUforCIDER *) malloc (nz * sizeof (ElementKLUforCIDER)) ; /* Allocate the temporary COO Column Index */ - Ap_COO = (unsigned int *) malloc (nz * sizeof(unsigned int)) ; + Ap_COO = (unsigned int *) malloc (nz * sizeof (unsigned int)) ; /* Allocate the needed KLU data structures */ - Matrix->SMPkluMatrix->KLUmatrixAp = (int *) malloc ((Matrix->SMPkluMatrix->KLUmatrixN + 1) * sizeof(int)) ; - Matrix->SMPkluMatrix->KLUmatrixAi = (int *) malloc (nz * sizeof(int)) ; - Matrix->SMPkluMatrix->KLUmatrixBindStructCOO = (BindKluElementCOO *) malloc (nz * sizeof(BindKluElementCOO)) ; - Matrix->SMPkluMatrix->KLUmatrixAxComplex = (double *) malloc (2 * nz * sizeof(double)) ; - Matrix->SMPkluMatrix->KLUmatrixIntermediateComplex = (double *) malloc (2 * Matrix->SMPkluMatrix->KLUmatrixN * sizeof(double)) ; + Matrix->SMPkluMatrix->KLUmatrixAp = (int *) malloc ((Matrix->SMPkluMatrix->KLUmatrixN + 1) * sizeof (int)) ; + Matrix->SMPkluMatrix->KLUmatrixAi = (int *) malloc (nz * sizeof (int)) ; + Matrix->SMPkluMatrix->KLUmatrixBindStructForCIDER = (BindElementKLUforCIDER *) malloc (nz * sizeof (BindElementKLUforCIDER)) ; + Matrix->SMPkluMatrix->KLUmatrixAxComplex = (double *) malloc (2 * nz * sizeof (double)) ; + Matrix->SMPkluMatrix->KLUmatrixIntermediateComplex = (double *) malloc (2 * Matrix->SMPkluMatrix->KLUmatrixN * sizeof (double)) ; /* Populate the compressed COO elements and COO value of Binding Table */ j = 0 ; for (i = 0 ; i < Matrix->SMPkluMatrix->KLUmatrixN * Matrix->SMPkluMatrix->KLUmatrixN ; i++) { - if ((Matrix->SMPkluMatrix->KLUmatrixRowCOO [i] != -1) && (Matrix->SMPkluMatrix->KLUmatrixColCOO [i] != -1)) { - MatrixCOO [j].row = (unsigned int)Matrix->SMPkluMatrix->KLUmatrixRowCOO [i] ; - MatrixCOO [j].col = (unsigned int)Matrix->SMPkluMatrix->KLUmatrixColCOO [i] ; - MatrixCOO [j].pointer = &(Matrix->SMPkluMatrix->KLUmatrixValueComplexCOO [2 * i]) ; + if ((Matrix->SMPkluMatrix->KLUmatrixRowCOOforCIDER [i] != -1) && (Matrix->SMPkluMatrix->KLUmatrixColCOOforCIDER [i] != -1)) { + MatrixCOO [j].row = (unsigned int)Matrix->SMPkluMatrix->KLUmatrixRowCOOforCIDER [i] ; + MatrixCOO [j].col = (unsigned int)Matrix->SMPkluMatrix->KLUmatrixColCOOforCIDER [i] ; + MatrixCOO [j].pointer = &(Matrix->SMPkluMatrix->KLUmatrixValueComplexCOOforCIDER [2 * i]) ; j++ ; } } /* Order the MatrixCOO along the columns */ - qsort (MatrixCOO, nz, sizeof(Element), CompareColumn) ; + qsort (MatrixCOO, nz, sizeof (ElementKLUforCIDER), CompareColumn) ; /* Order the MatrixCOO along the rows */ i = 0 ; @@ -266,7 +291,7 @@ void SMPconvertCOOtoCSCKLUforCIDER (SMPmatrix *Matrix) } } - qsort (MatrixCOO + i, j - i, sizeof(Element), CompareRow) ; + qsort (MatrixCOO + i, j - i, sizeof (ElementKLUforCIDER), CompareRow) ; i = j ; } @@ -276,8 +301,8 @@ void SMPconvertCOOtoCSCKLUforCIDER (SMPmatrix *Matrix) { Ap_COO [i] = MatrixCOO [i].col ; Matrix->SMPkluMatrix->KLUmatrixAi [i] = (int)MatrixCOO [i].row ; - Matrix->SMPkluMatrix->KLUmatrixBindStructCOO [i].COO = MatrixCOO [i].pointer ; - Matrix->SMPkluMatrix->KLUmatrixBindStructCOO [i].CSC_Complex = &(Matrix->SMPkluMatrix->KLUmatrixAxComplex [2 * i]) ; + Matrix->SMPkluMatrix->KLUmatrixBindStructForCIDER [i].COO = MatrixCOO [i].pointer ; + Matrix->SMPkluMatrix->KLUmatrixBindStructForCIDER [i].CSC_Complex = &(Matrix->SMPkluMatrix->KLUmatrixAxComplex [2 * i]) ; } /* Compress the COO Column Index to CSC Column Index */ @@ -288,29 +313,38 @@ void SMPconvertCOOtoCSCKLUforCIDER (SMPmatrix *Matrix) free (MatrixCOO) ; /* Sort the Binding Table */ - qsort (Matrix->SMPkluMatrix->KLUmatrixBindStructCOO, nz, sizeof(BindKluElementCOO), BindKluCompareCOO) ; + qsort (Matrix->SMPkluMatrix->KLUmatrixBindStructForCIDER, nz, sizeof (BindElementKLUforCIDER), BindCompareKLUforCIDER) ; return ; } #endif -/* - * SMPaddElt() - */ -int -SMPaddElt (SMPmatrix *Matrix, int Row, int Col, double Value) -{ - *spGetElement (Matrix->SPmatrix, Row, Col) = Value ; - return spError (Matrix->SPmatrix) ; -} - /* * SMPmakeElt() */ double * SMPmakeElt (SMPmatrix *Matrix, int Row, int Col) { - return spGetElement (Matrix->SPmatrix, Row, Col) ; + KluLinkedListCOO *temp ; + + if (Matrix->CKTkluMODE) { + if ((Row > 0) && (Col > 0)) { + Row = Row - 1 ; + Col = Col - 1 ; + temp = (KluLinkedListCOO *) malloc (sizeof (KluLinkedListCOO)) ; + temp->row = (unsigned int)Row ; + temp->col = (unsigned int)Col ; + temp->pointer = (double *) malloc (sizeof (double)) ; + temp->next = Matrix->SMPkluMatrix->KLUmatrixLinkedListCOO ; + Matrix->SMPkluMatrix->KLUmatrixLinkedListCOO = temp ; + Matrix->SMPkluMatrix->KLUmatrixLinkedListNZ++ ; + return temp->pointer ; + } else { + return Matrix->SMPkluMatrix->KLUmatrixTrashCOO ; + } + } else { + return spGetElement (Matrix->SPmatrix, Row, Col) ; + } } #ifdef CIDER @@ -321,9 +355,9 @@ SMPmakeEltKLUforCIDER (SMPmatrix *Matrix, int Row, int Col) if ((Row > 0) && (Col > 0)) { Row = Row - 1 ; Col = Col - 1 ; - Matrix->SMPkluMatrix->KLUmatrixRowCOO [Row * (int)Matrix->SMPkluMatrix->KLUmatrixN + Col] = Row ; - Matrix->SMPkluMatrix->KLUmatrixColCOO [Row * (int)Matrix->SMPkluMatrix->KLUmatrixN + Col] = Col ; - return &(Matrix->SMPkluMatrix->KLUmatrixValueComplexCOO [2 * (Row * (int)Matrix->SMPkluMatrix->KLUmatrixN + Col)]) ; + Matrix->SMPkluMatrix->KLUmatrixRowCOOforCIDER [Row * (int)Matrix->SMPkluMatrix->KLUmatrixN + Col] = Row ; + Matrix->SMPkluMatrix->KLUmatrixColCOOforCIDER [Row * (int)Matrix->SMPkluMatrix->KLUmatrixN + Col] = Col ; + return &(Matrix->SMPkluMatrix->KLUmatrixValueComplexCOOforCIDER [2 * (Row * (int)Matrix->SMPkluMatrix->KLUmatrixN + Col)]) ; } else { return Matrix->SMPkluMatrix->KLUmatrixTrashCOO ; } @@ -340,14 +374,12 @@ SMPmakeEltKLUforCIDER (SMPmatrix *Matrix, int Row, int Col) void SMPcClear (SMPmatrix *Matrix) { - int i ; + unsigned int i ; + if (Matrix->CKTkluMODE) { - spClear (Matrix->SPmatrix) ; - if (Matrix->CKTkluAx_Complex != NULL) - { - for (i = 0 ; i < 2 * Matrix->CKTklunz ; i++) - Matrix->CKTkluAx_Complex [i] = 0 ; + for (i = 0 ; i < 2 * Matrix->SMPkluMatrix->KLUmatrixNZ ; i++) { + Matrix->SMPkluMatrix->KLUmatrixAxComplex [i] = 0 ; } } else { spClear (Matrix->SPmatrix) ; @@ -361,14 +393,12 @@ SMPcClear (SMPmatrix *Matrix) void SMPclear (SMPmatrix *Matrix) { - int i ; + unsigned int i ; + if (Matrix->CKTkluMODE) { - spClear (Matrix->SPmatrix) ; - if (Matrix->CKTkluAx != NULL) - { - for (i = 0 ; i < Matrix->CKTklunz ; i++) - Matrix->CKTkluAx [i] = 0 ; + for (i = 0 ; i < Matrix->SMPkluMatrix->KLUmatrixNZ ; i++) { + Matrix->SMPkluMatrix->KLUmatrixAx [i] = 0 ; } } else { spClear (Matrix->SPmatrix) ; @@ -403,24 +433,23 @@ SMPcLUfac (SMPmatrix *Matrix, double PivTol) if (Matrix->CKTkluMODE) { - spSetComplex (Matrix->SPmatrix) ; - ret = klu_z_refactor (Matrix->CKTkluAp, Matrix->CKTkluAi, Matrix->CKTkluAx_Complex, - Matrix->CKTkluSymbolic, Matrix->CKTkluNumeric, Matrix->CKTkluCommon) ; + ret = klu_z_refactor (Matrix->SMPkluMatrix->KLUmatrixAp, Matrix->SMPkluMatrix->KLUmatrixAi, Matrix->SMPkluMatrix->KLUmatrixAxComplex, + Matrix->SMPkluMatrix->KLUmatrixSymbolic, Matrix->SMPkluMatrix->KLUmatrixNumeric, Matrix->SMPkluMatrix->KLUmatrixCommon) ; if (ret == 0) { - if (Matrix->CKTkluCommon->status == KLU_SINGULAR) { + if (Matrix->SMPkluMatrix->KLUmatrixCommon->status == KLU_SINGULAR) { fprintf (stderr, "Warning (ReFactor): KLU Matrix is SINGULAR\n") ; return E_SINGULAR ; } - if (Matrix->CKTkluCommon == NULL) { + if (Matrix->SMPkluMatrix->KLUmatrixCommon == NULL) { fprintf (stderr, "Error (ReFactor): KLUcommon object is NULL. A problem occurred\n") ; } - if (Matrix->CKTkluCommon->status == KLU_EMPTY_MATRIX) + if (Matrix->SMPkluMatrix->KLUmatrixCommon->status == KLU_EMPTY_MATRIX) { fprintf (stderr, "Error (ReFactor): KLU Matrix is empty\n") ; } - if (Matrix->CKTkluNumeric == NULL) { + if (Matrix->SMPkluMatrix->KLUmatrixNumeric == NULL) { fprintf (stderr, "Error (ReFactor): KLUnumeric object is NULL. A problem occurred\n") ; } return 1 ; @@ -447,25 +476,25 @@ SMPluFac (SMPmatrix *Matrix, double PivTol, double Gmin) if (Matrix->CKTkluMODE) { - spSetReal (Matrix->SPmatrix) ; - LoadGmin_CSC (Matrix->CKTdiag_CSC, Matrix->CKTkluN, Gmin) ; - ret = klu_refactor (Matrix->CKTkluAp, Matrix->CKTkluAi, Matrix->CKTkluAx, - Matrix->CKTkluSymbolic, Matrix->CKTkluNumeric, Matrix->CKTkluCommon) ; + LoadGmin_CSC (Matrix->SMPkluMatrix->KLUmatrixDiag, Matrix->SMPkluMatrix->KLUmatrixN, Gmin) ; + + ret = klu_refactor (Matrix->SMPkluMatrix->KLUmatrixAp, Matrix->SMPkluMatrix->KLUmatrixAi, Matrix->SMPkluMatrix->KLUmatrixAx, + Matrix->SMPkluMatrix->KLUmatrixSymbolic, Matrix->SMPkluMatrix->KLUmatrixNumeric, Matrix->SMPkluMatrix->KLUmatrixCommon) ; if (ret == 0) { - if (Matrix->CKTkluCommon->status == KLU_SINGULAR) { + if (Matrix->SMPkluMatrix->KLUmatrixCommon->status == KLU_SINGULAR) { fprintf (stderr, "Warning (ReFactor): KLU Matrix is SINGULAR\n") ; return E_SINGULAR ; } - if (Matrix->CKTkluCommon == NULL) { + if (Matrix->SMPkluMatrix->KLUmatrixCommon == NULL) { fprintf (stderr, "Error (ReFactor): KLUcommon object is NULL. A problem occurred\n") ; } - if (Matrix->CKTkluCommon->status == KLU_EMPTY_MATRIX) + if (Matrix->SMPkluMatrix->KLUmatrixCommon->status == KLU_EMPTY_MATRIX) { fprintf (stderr, "Error (ReFactor): KLU Matrix is empty\n") ; } - if (Matrix->CKTkluNumeric == NULL) { + if (Matrix->SMPkluMatrix->KLUmatrixNumeric == NULL) { fprintf (stderr, "Error (ReFactor): KLUnumeric object is NULL. A problem occurred\n") ; } return 1 ; @@ -511,19 +540,19 @@ SMPluFacKLUforCIDER (SMPmatrix *Matrix) if (ret == 0) { - if (Matrix->CKTkluCommon->status == KLU_SINGULAR) { - fprintf (stderr, "Warning (ReFactor) (CIDER): KLU Matrix is SINGULAR\n") ; + if (Matrix->SMPkluMatrix->KLUmatrixCommon->status == KLU_SINGULAR) { + fprintf (stderr, "Warning (ReFactor): KLU Matrix is SINGULAR\n") ; return E_SINGULAR ; } - if (Matrix->CKTkluCommon == NULL) { - fprintf (stderr, "Error (ReFactor) (CIDER): KLUcommon object is NULL. A problem occurred\n") ; + if (Matrix->SMPkluMatrix->KLUmatrixCommon == NULL) { + fprintf (stderr, "Error (ReFactor): KLUcommon object is NULL. A problem occurred\n") ; } - if (Matrix->CKTkluCommon->status == KLU_EMPTY_MATRIX) + if (Matrix->SMPkluMatrix->KLUmatrixCommon->status == KLU_EMPTY_MATRIX) { - fprintf (stderr, "Error (ReFactor) (CIDER): KLU Matrix is empty\n") ; + fprintf (stderr, "Error (ReFactor): KLU Matrix is empty\n") ; } - if (Matrix->CKTkluNumeric == NULL) { - fprintf (stderr, "Error (ReFactor) (CIDER): KLUnumeric object is NULL. A problem occurred\n") ; + if (Matrix->SMPkluMatrix->KLUmatrixNumeric == NULL) { + fprintf (stderr, "Error (ReFactor): KLUnumeric object is NULL. A problem occurred\n") ; } return 1 ; } else { @@ -544,30 +573,29 @@ SMPcReorder (SMPmatrix *Matrix, double PivTol, double PivRel, int *NumSwaps) { if (Matrix->CKTkluMODE) { - *NumSwaps = 1 ; - spSetComplex (Matrix->SPmatrix) ; - Matrix->CKTkluCommon->tol = PivTol ; + Matrix->SMPkluMatrix->KLUmatrixCommon->tol = PivTol ; - if (Matrix->CKTkluNumeric != NULL) - { - klu_z_free_numeric (&(Matrix->CKTkluNumeric), Matrix->CKTkluCommon) ; + if (Matrix->SMPkluMatrix->KLUmatrixNumeric != NULL) { + klu_free_numeric (&(Matrix->SMPkluMatrix->KLUmatrixNumeric), Matrix->SMPkluMatrix->KLUmatrixCommon) ; } - Matrix->CKTkluNumeric = klu_z_factor (Matrix->CKTkluAp, Matrix->CKTkluAi, Matrix->CKTkluAx_Complex, Matrix->CKTkluSymbolic, Matrix->CKTkluCommon) ; + Matrix->SMPkluMatrix->KLUmatrixNumeric = klu_z_factor (Matrix->SMPkluMatrix->KLUmatrixAp, Matrix->SMPkluMatrix->KLUmatrixAi, + Matrix->SMPkluMatrix->KLUmatrixAxComplex, Matrix->SMPkluMatrix->KLUmatrixSymbolic, + Matrix->SMPkluMatrix->KLUmatrixCommon) ; - if (Matrix->CKTkluNumeric == NULL) + if (Matrix->SMPkluMatrix->KLUmatrixNumeric == NULL) { fprintf (stderr, "Error (Factor): KLUnumeric object is NULL. A problem occurred\n") ; - if (Matrix->CKTkluCommon->status == KLU_SINGULAR) { + if (Matrix->SMPkluMatrix->KLUmatrixCommon->status == KLU_SINGULAR) { fprintf (stderr, "Warning (Factor): KLU Matrix is SINGULAR\n") ; return 0 ; } - if (Matrix->CKTkluCommon == NULL) { + if (Matrix->SMPkluMatrix->KLUmatrixCommon == NULL) { fprintf (stderr, "Error (Factor): KLUcommon object is NULL. A problem occurred\n") ; } - if (Matrix->CKTkluCommon->status == KLU_EMPTY_MATRIX) { + if (Matrix->SMPkluMatrix->KLUmatrixCommon->status == KLU_EMPTY_MATRIX) { fprintf (stderr, "Error (Factor): KLU Matrix is empty\n") ; } - if (Matrix->CKTkluSymbolic == NULL) { + if (Matrix->SMPkluMatrix->KLUmatrixSymbolic == NULL) { fprintf (stderr, "Error (Factor): KLUsymbolic object is NULL. A problem occurred\n") ; } return 1 ; @@ -590,30 +618,31 @@ SMPreorder (SMPmatrix *Matrix, double PivTol, double PivRel, double Gmin) { if (Matrix->CKTkluMODE) { - spSetReal (Matrix->SPmatrix) ; - LoadGmin_CSC (Matrix->CKTdiag_CSC, Matrix->CKTkluN, Gmin) ; - Matrix->CKTkluCommon->tol = PivTol ; + LoadGmin_CSC (Matrix->SMPkluMatrix->KLUmatrixDiag, Matrix->SMPkluMatrix->KLUmatrixN, Gmin) ; + Matrix->SMPkluMatrix->KLUmatrixCommon->tol = PivTol ; - if (Matrix->CKTkluNumeric != NULL) - { - klu_free_numeric (&(Matrix->CKTkluNumeric), Matrix->CKTkluCommon) ; + if (Matrix->SMPkluMatrix->KLUmatrixNumeric != NULL) { + klu_free_numeric (&(Matrix->SMPkluMatrix->KLUmatrixNumeric), Matrix->SMPkluMatrix->KLUmatrixCommon) ; } - Matrix->CKTkluNumeric = klu_factor (Matrix->CKTkluAp, Matrix->CKTkluAi, Matrix->CKTkluAx, Matrix->CKTkluSymbolic, Matrix->CKTkluCommon) ; - if (Matrix->CKTkluNumeric == NULL) + Matrix->SMPkluMatrix->KLUmatrixNumeric = klu_factor (Matrix->SMPkluMatrix->KLUmatrixAp, Matrix->SMPkluMatrix->KLUmatrixAi, + Matrix->SMPkluMatrix->KLUmatrixAx, Matrix->SMPkluMatrix->KLUmatrixSymbolic, + Matrix->SMPkluMatrix->KLUmatrixCommon) ; + + if (Matrix->SMPkluMatrix->KLUmatrixNumeric == NULL) { fprintf (stderr, "Error (Factor): KLUnumeric object is NULL. A problem occurred\n") ; - if (Matrix->CKTkluCommon->status == KLU_SINGULAR) { + if (Matrix->SMPkluMatrix->KLUmatrixCommon->status == KLU_SINGULAR) { fprintf (stderr, "Warning (Factor): KLU Matrix is SINGULAR\n") ; return 0 ; } - if (Matrix->CKTkluCommon == NULL) { + if (Matrix->SMPkluMatrix->KLUmatrixCommon == NULL) { fprintf (stderr, "Error (Factor): KLUcommon object is NULL. A problem occurred\n") ; } - if (Matrix->CKTkluCommon->status == KLU_EMPTY_MATRIX) { + if (Matrix->SMPkluMatrix->KLUmatrixCommon->status == KLU_EMPTY_MATRIX) { fprintf (stderr, "Error (Factor): KLU Matrix is empty\n") ; } - if (Matrix->CKTkluSymbolic == NULL) { + if (Matrix->SMPkluMatrix->KLUmatrixSymbolic == NULL) { fprintf (stderr, "Error (Factor): KLUsymbolic object is NULL. A problem occurred\n") ; } return 1 ; @@ -660,21 +689,22 @@ SMPreorderKLUforCIDER (SMPmatrix *Matrix) /* Free the Real Matrix Storage */ free (KLUmatrixAx) ; } + if (Matrix->SMPkluMatrix->KLUmatrixNumeric == NULL) { - fprintf (stderr, "Error (Factor) (CIDER): KLUnumeric object is NULL. A problem occurred\n") ; - if (Matrix->CKTkluCommon->status == KLU_SINGULAR) { + fprintf (stderr, "Error (Factor): KLUnumeric object is NULL. A problem occurred\n") ; + if (Matrix->SMPkluMatrix->KLUmatrixCommon->status == KLU_SINGULAR) { fprintf (stderr, "Warning (Factor): KLU Matrix is SINGULAR\n") ; return 0 ; } - if (Matrix->CKTkluCommon == NULL) { - fprintf (stderr, "Error (Factor) (CIDER): KLUcommon object is NULL. A problem occurred\n") ; + if (Matrix->SMPkluMatrix->KLUmatrixCommon == NULL) { + fprintf (stderr, "Error (Factor): KLUcommon object is NULL. A problem occurred\n") ; } - if (Matrix->CKTkluCommon->status == KLU_EMPTY_MATRIX) { - fprintf (stderr, "Error (Factor) (CIDER): KLU Matrix is empty\n") ; + if (Matrix->SMPkluMatrix->KLUmatrixCommon->status == KLU_EMPTY_MATRIX) { + fprintf (stderr, "Error (Factor): KLU Matrix is empty\n") ; } - if (Matrix->CKTkluSymbolic == NULL) { - fprintf (stderr, "Error (Factor) (CIDER): KLUsymbolic object is NULL. A problem occurred\n") ; + if (Matrix->SMPkluMatrix->KLUmatrixSymbolic == NULL) { + fprintf (stderr, "Error (Factor): KLUsymbolic object is NULL. A problem occurred\n") ; } return 1 ; } else { @@ -692,27 +722,27 @@ SMPreorderKLUforCIDER (SMPmatrix *Matrix) void SMPcaSolve (SMPmatrix *Matrix, double RHS[], double iRHS[], double Spare[], double iSpare[]) { - int ret, i, *pExtOrder ; + int ret ; + unsigned int i ; NG_IGNORE (iSpare) ; NG_IGNORE (Spare) ; if (Matrix->CKTkluMODE) { - pExtOrder = &Matrix->SPmatrix->IntToExtRowMap [Matrix->CKTkluN] ; - for (i = 2 * Matrix->CKTkluN - 1 ; i > 0 ; i -= 2) + for (i = 0 ; i < Matrix->SMPkluMatrix->KLUmatrixN ; i++) { - Matrix->CKTkluIntermediate_Complex [i] = iRHS [*(pExtOrder)] ; - Matrix->CKTkluIntermediate_Complex [i - 1] = RHS [*(pExtOrder--)] ; + Matrix->SMPkluMatrix->KLUmatrixIntermediateComplex [2 * i] = RHS [i + 1] ; + Matrix->SMPkluMatrix->KLUmatrixIntermediateComplex [2 * i + 1] = iRHS [i + 1] ; } - ret = klu_z_tsolve (Matrix->CKTkluSymbolic, Matrix->CKTkluNumeric, Matrix->CKTkluN, 1, Matrix->CKTkluIntermediate_Complex, 0, Matrix->CKTkluCommon) ; + ret = klu_z_solve (Matrix->SMPkluMatrix->KLUmatrixSymbolic, Matrix->SMPkluMatrix->KLUmatrixNumeric, (int)Matrix->SMPkluMatrix->KLUmatrixN, 1, + Matrix->SMPkluMatrix->KLUmatrixIntermediateComplex, Matrix->SMPkluMatrix->KLUmatrixCommon) ; - pExtOrder = &Matrix->SPmatrix->IntToExtColMap [Matrix->CKTkluN] ; - for (i = 2 * Matrix->CKTkluN - 1 ; i > 0 ; i -= 2) + for (i = 0 ; i < Matrix->SMPkluMatrix->KLUmatrixN ; i++) { - iRHS [*(pExtOrder)] = Matrix->CKTkluIntermediate_Complex [i] ; - RHS [*(pExtOrder--)] = Matrix->CKTkluIntermediate_Complex [i - 1] ; + RHS [i + 1] = Matrix->SMPkluMatrix->KLUmatrixIntermediateComplex [2 * i] ; + iRHS [i + 1] = Matrix->SMPkluMatrix->KLUmatrixIntermediateComplex [2 * i + 1] ; } } else { spSolveTransposed (Matrix->SPmatrix, RHS, RHS, iRHS, iRHS) ; @@ -726,35 +756,82 @@ SMPcaSolve (SMPmatrix *Matrix, double RHS[], double iRHS[], double Spare[], doub void SMPcSolve (SMPmatrix *Matrix, double RHS[], double iRHS[], double Spare[], double iSpare[]) { - int ret, i, *pExtOrder ; + int ret ; + unsigned int i ; NG_IGNORE (iSpare) ; NG_IGNORE (Spare) ; if (Matrix->CKTkluMODE) { - pExtOrder = &Matrix->SPmatrix->IntToExtRowMap [Matrix->CKTkluN] ; - for (i = 2 * Matrix->CKTkluN - 1 ; i > 0 ; i -= 2) + for (i = 0 ; i < Matrix->SMPkluMatrix->KLUmatrixN ; i++) { - Matrix->CKTkluIntermediate_Complex [i] = iRHS [*(pExtOrder)] ; - Matrix->CKTkluIntermediate_Complex [i - 1] = RHS [*(pExtOrder--)] ; + Matrix->SMPkluMatrix->KLUmatrixIntermediateComplex [2 * i] = RHS [i + 1] ; + Matrix->SMPkluMatrix->KLUmatrixIntermediateComplex [2 * i + 1] = iRHS [i + 1] ; } - ret = klu_z_solve (Matrix->CKTkluSymbolic, Matrix->CKTkluNumeric, Matrix->CKTkluN, 1, Matrix->CKTkluIntermediate_Complex, Matrix->CKTkluCommon) ; + ret = klu_z_solve (Matrix->SMPkluMatrix->KLUmatrixSymbolic, Matrix->SMPkluMatrix->KLUmatrixNumeric, (int)Matrix->SMPkluMatrix->KLUmatrixN, 1, + Matrix->SMPkluMatrix->KLUmatrixIntermediateComplex, Matrix->SMPkluMatrix->KLUmatrixCommon) ; - pExtOrder = &Matrix->SPmatrix->IntToExtColMap [Matrix->CKTkluN] ; - for (i = 2 * Matrix->CKTkluN - 1 ; i > 0 ; i -= 2) + for (i = 0 ; i < Matrix->SMPkluMatrix->KLUmatrixN ; i++) { - iRHS [*(pExtOrder)] = Matrix->CKTkluIntermediate_Complex [i] ; - RHS [*(pExtOrder--)] = Matrix->CKTkluIntermediate_Complex [i - 1] ; + RHS [i + 1] = Matrix->SMPkluMatrix->KLUmatrixIntermediateComplex [2 * i] ; + iRHS [i + 1] = Matrix->SMPkluMatrix->KLUmatrixIntermediateComplex [2 * i + 1] ; } - } else { - spSolve (Matrix->SPmatrix, RHS, RHS, iRHS, iRHS) ; } } +/* + * SMPsolve() + */ + +void +SMPsolve (SMPmatrix *Matrix, double RHS[], double Spare[]) +{ + int ret ; + unsigned int i ; + + NG_IGNORE (Spare) ; + + if (Matrix->CKTkluMODE) + { + for (i = 0 ; i < Matrix->SMPkluMatrix->KLUmatrixN ; i++) { + Matrix->SMPkluMatrix->KLUmatrixIntermediate [i] = RHS [i + 1] ; + } + + ret = klu_solve (Matrix->SMPkluMatrix->KLUmatrixSymbolic, Matrix->SMPkluMatrix->KLUmatrixNumeric, (int)Matrix->SMPkluMatrix->KLUmatrixN, 1, + Matrix->SMPkluMatrix->KLUmatrixIntermediate, Matrix->SMPkluMatrix->KLUmatrixCommon) ; + + if (ret == 0) + { + if (Matrix->SMPkluMatrix->KLUmatrixCommon->status == KLU_SINGULAR) { + fprintf (stderr, "Warning (Solve): KLU Matrix is SINGULAR\n") ; + } + if (Matrix->SMPkluMatrix->KLUmatrixCommon == NULL) { + fprintf (stderr, "Error (Solve): KLUcommon object is NULL. A problem occurred\n") ; + } + if (Matrix->SMPkluMatrix->KLUmatrixCommon->status == KLU_EMPTY_MATRIX) + { + fprintf (stderr, "Error (Solve): KLU Matrix is empty\n") ; + } + if (Matrix->SMPkluMatrix->KLUmatrixNumeric == NULL) { + fprintf (stderr, "Error (Solve): KLUnumeric object is NULL. A problem occurred\n") ; + } + if (Matrix->SMPkluMatrix->KLUmatrixSymbolic == NULL) { + fprintf (stderr, "Error (Solve): KLUsymbolic object is NULL. A problem occurred\n") ; + } + } + + for (i = 0 ; i < Matrix->SMPkluMatrix->KLUmatrixN ; i++) { + RHS [i + 1] = Matrix->SMPkluMatrix->KLUmatrixIntermediate [i] ; + } + } else { + spSolve (Matrix->SPmatrix, RHS, RHS, NULL, NULL) ; + } +} + #ifdef CIDER void SMPsolveKLUforCIDER (SMPmatrix *Matrix, double RHS[], double RHSsolution[], double iRHS[], double iRHSsolution[]) @@ -806,40 +883,17 @@ SMPsolveKLUforCIDER (SMPmatrix *Matrix, double RHS[], double RHSsolution[], doub } #endif -/* - * SMPsolve() - */ - -void -SMPsolve (SMPmatrix *Matrix, double RHS[], double Spare[]) -{ - int ret, i, *pExtOrder ; - - NG_IGNORE (Spare) ; - - if (Matrix->CKTkluMODE) { - - pExtOrder = &Matrix->SPmatrix->IntToExtRowMap [Matrix->CKTkluN] ; - for (i = Matrix->CKTkluN - 1 ; i >= 0 ; i--) - Matrix->CKTkluIntermediate [i] = RHS [*(pExtOrder--)] ; - - ret = klu_solve (Matrix->CKTkluSymbolic, Matrix->CKTkluNumeric, Matrix->CKTkluN, 1, Matrix->CKTkluIntermediate, Matrix->CKTkluCommon) ; - - pExtOrder = &Matrix->SPmatrix->IntToExtColMap [Matrix->CKTkluN] ; - for (i = Matrix->CKTkluN - 1 ; i >= 0 ; i--) - RHS [*(pExtOrder--)] = Matrix->CKTkluIntermediate [i] ; - } else { - spSolve (Matrix->SPmatrix, RHS, RHS, NULL, NULL) ; - } -} - /* * SMPmatSize() */ int SMPmatSize (SMPmatrix *Matrix) { - return spGetSize (Matrix->SPmatrix, 1) ; + if (Matrix->CKTkluMODE) { + return (int)Matrix->SMPkluMatrix->KLUmatrixN ; + } else { + return spGetSize (Matrix->SPmatrix, 1) ; + } } /* @@ -849,8 +903,41 @@ int SMPnewMatrix (SMPmatrix *Matrix, int size) { int Error ; - Matrix->SPmatrix = spCreate (size, 1, &Error) ; - return Error ; + + if (Matrix->CKTkluMODE) { + /* Allocate the KLU Matrix Data Structure */ + Matrix->SMPkluMatrix = (KLUmatrix *) malloc (sizeof (KLUmatrix)) ; + Matrix->SMPkluMatrix->KLUmatrixLinkedListNZ = 0 ; + Matrix->SMPkluMatrix->KLUmatrixLinkedListCOO = NULL ; + + /* Initialize the KLU Matrix Internal Pointers */ + Matrix->SMPkluMatrix->KLUmatrixCommon = (klu_common *) malloc (sizeof (klu_common)) ; ; + Matrix->SMPkluMatrix->KLUmatrixSymbolic = NULL ; + Matrix->SMPkluMatrix->KLUmatrixNumeric = NULL ; + Matrix->SMPkluMatrix->KLUmatrixAp = NULL ; + Matrix->SMPkluMatrix->KLUmatrixAi = NULL ; + Matrix->SMPkluMatrix->KLUmatrixAx = NULL ; + Matrix->SMPkluMatrix->KLUmatrixAxComplex = NULL ; + Matrix->SMPkluMatrix->KLUmatrixIsComplex = KLUmatrixReal ; + Matrix->SMPkluMatrix->KLUmatrixIntermediate = NULL ; + Matrix->SMPkluMatrix->KLUmatrixIntermediateComplex = NULL ; + Matrix->SMPkluMatrix->KLUmatrixNZ = 0 ; + Matrix->SMPkluMatrix->KLUmatrixBindStructCOO = NULL ; + Matrix->SMPkluMatrix->KLUmatrixDiag = NULL ; + + /* Initialize the KLU Common Data Structure */ + klu_defaults (Matrix->SMPkluMatrix->KLUmatrixCommon) ; + Matrix->SMPkluMatrix->KLUmatrixCommon->memgrow = Matrix->CKTkluMemGrowFactor ; + + /* Allocate KLU data structures */ + Matrix->SMPkluMatrix->KLUmatrixN = (unsigned int)size ; + Matrix->SMPkluMatrix->KLUmatrixTrashCOO = (double *) malloc (sizeof (double)) ; + + return spOKAY ; + } else { + Matrix->SPmatrix = spCreate (size, 1, &Error) ; + return Error ; + } } #ifdef CIDER @@ -872,29 +959,29 @@ SMPnewMatrixKLUforCIDER (SMPmatrix *Matrix, int size, unsigned int KLUmatrixIsCo Matrix->SMPkluMatrix->KLUmatrixAi = NULL ; Matrix->SMPkluMatrix->KLUmatrixAxComplex = NULL ; if (KLUmatrixIsComplex) { - Matrix->SMPkluMatrix->KLUmatrixIsComplex = CKTkluMatrixComplex ; + Matrix->SMPkluMatrix->KLUmatrixIsComplex = KLUMatrixComplex ; } else { - Matrix->SMPkluMatrix->KLUmatrixIsComplex = CKTkluMatrixReal ; + Matrix->SMPkluMatrix->KLUmatrixIsComplex = KLUmatrixReal ; } Matrix->SMPkluMatrix->KLUmatrixIntermediateComplex = NULL ; Matrix->SMPkluMatrix->KLUmatrixNZ = 0 ; - Matrix->SMPkluMatrix->KLUmatrixBindStructCOO = NULL ; - Matrix->SMPkluMatrix->KLUmatrixValueComplexCOO = NULL ; + Matrix->SMPkluMatrix->KLUmatrixBindStructForCIDER = NULL ; + Matrix->SMPkluMatrix->KLUmatrixValueComplexCOOforCIDER = NULL ; /* Initialize the KLU Common Data Structure */ klu_defaults (Matrix->SMPkluMatrix->KLUmatrixCommon) ; /* Allocate KLU data structures */ Matrix->SMPkluMatrix->KLUmatrixN = (unsigned int)size ; - Matrix->SMPkluMatrix->KLUmatrixColCOO = (int *) malloc (Matrix->SMPkluMatrix->KLUmatrixN * Matrix->SMPkluMatrix->KLUmatrixN * sizeof(int)) ; - Matrix->SMPkluMatrix->KLUmatrixRowCOO = (int *) malloc (Matrix->SMPkluMatrix->KLUmatrixN * Matrix->SMPkluMatrix->KLUmatrixN * sizeof(int)) ; + Matrix->SMPkluMatrix->KLUmatrixColCOOforCIDER = (int *) malloc (Matrix->SMPkluMatrix->KLUmatrixN * Matrix->SMPkluMatrix->KLUmatrixN * sizeof(int)) ; + Matrix->SMPkluMatrix->KLUmatrixRowCOOforCIDER = (int *) malloc (Matrix->SMPkluMatrix->KLUmatrixN * Matrix->SMPkluMatrix->KLUmatrixN * sizeof(int)) ; Matrix->SMPkluMatrix->KLUmatrixTrashCOO = (double *) malloc (sizeof(double)) ; - Matrix->SMPkluMatrix->KLUmatrixValueComplexCOO = (double *) malloc (2 * Matrix->SMPkluMatrix->KLUmatrixN * Matrix->SMPkluMatrix->KLUmatrixN * sizeof(double)) ; + Matrix->SMPkluMatrix->KLUmatrixValueComplexCOOforCIDER = (double *) malloc (2 * Matrix->SMPkluMatrix->KLUmatrixN * Matrix->SMPkluMatrix->KLUmatrixN * sizeof(double)) ; /* Pre-set the values of Row and Col */ for (i = 0 ; i < Matrix->SMPkluMatrix->KLUmatrixN * Matrix->SMPkluMatrix->KLUmatrixN ; i++) { - Matrix->SMPkluMatrix->KLUmatrixRowCOO [i] = -1 ; - Matrix->SMPkluMatrix->KLUmatrixColCOO [i] = -1 ; + Matrix->SMPkluMatrix->KLUmatrixRowCOOforCIDER [i] = -1 ; + Matrix->SMPkluMatrix->KLUmatrixColCOOforCIDER [i] = -1 ; } return spOKAY ; @@ -912,30 +999,28 @@ SMPnewMatrixKLUforCIDER (SMPmatrix *Matrix, int size, unsigned int KLUmatrixIsCo void SMPdestroy (SMPmatrix *Matrix) { - spDestroy (Matrix->SPmatrix) ; - if (Matrix->CKTkluMODE) { - klu_free_numeric (&(Matrix->CKTkluNumeric), Matrix->CKTkluCommon) ; - klu_free_symbolic (&(Matrix->CKTkluSymbolic), Matrix->CKTkluCommon) ; - free (Matrix->CKTkluAp) ; - free (Matrix->CKTkluAi) ; - free (Matrix->CKTkluAx) ; - free (Matrix->CKTkluIntermediate) ; - free (Matrix->CKTbindStruct) ; - free (Matrix->CKTdiag_CSC) ; - free (Matrix->CKTkluAx_Complex) ; - free (Matrix->CKTkluIntermediate_Complex) ; - Matrix->CKTkluNumeric = NULL ; - Matrix->CKTkluSymbolic = NULL ; - Matrix->CKTkluAp = NULL ; - Matrix->CKTkluAi = NULL ; - Matrix->CKTkluAx = NULL ; - Matrix->CKTkluIntermediate = NULL ; - Matrix->CKTbindStruct = NULL ; - Matrix->CKTdiag_CSC = NULL ; - Matrix->CKTkluAx_Complex = NULL ; - Matrix->CKTkluIntermediate_Complex = NULL ; + klu_free_numeric (&(Matrix->SMPkluMatrix->KLUmatrixNumeric), Matrix->SMPkluMatrix->KLUmatrixCommon) ; + klu_free_symbolic (&(Matrix->SMPkluMatrix->KLUmatrixSymbolic), Matrix->SMPkluMatrix->KLUmatrixCommon) ; + free (Matrix->SMPkluMatrix->KLUmatrixAp) ; + free (Matrix->SMPkluMatrix->KLUmatrixAi) ; + free (Matrix->SMPkluMatrix->KLUmatrixAx) ; + free (Matrix->SMPkluMatrix->KLUmatrixAxComplex) ; + free (Matrix->SMPkluMatrix->KLUmatrixIntermediate) ; + free (Matrix->SMPkluMatrix->KLUmatrixIntermediateComplex) ; + free (Matrix->SMPkluMatrix->KLUmatrixBindStructCOO) ; + free (Matrix->SMPkluMatrix->KLUmatrixTrashCOO) ; + Matrix->SMPkluMatrix->KLUmatrixAp = NULL ; + Matrix->SMPkluMatrix->KLUmatrixAi = NULL ; + Matrix->SMPkluMatrix->KLUmatrixAx = NULL ; + Matrix->SMPkluMatrix->KLUmatrixAxComplex = NULL ; + Matrix->SMPkluMatrix->KLUmatrixIntermediate = NULL ; + Matrix->SMPkluMatrix->KLUmatrixIntermediateComplex = NULL ; + Matrix->SMPkluMatrix->KLUmatrixBindStructCOO = NULL ; + Matrix->SMPkluMatrix->KLUmatrixTrashCOO = NULL ; + } else { + spDestroy (Matrix->SPmatrix) ; } } @@ -951,19 +1036,19 @@ SMPdestroyKLUforCIDER (SMPmatrix *Matrix) free (Matrix->SMPkluMatrix->KLUmatrixAi) ; free (Matrix->SMPkluMatrix->KLUmatrixAxComplex) ; free (Matrix->SMPkluMatrix->KLUmatrixIntermediateComplex) ; - free (Matrix->SMPkluMatrix->KLUmatrixBindStructCOO) ; - free (Matrix->SMPkluMatrix->KLUmatrixColCOO) ; - free (Matrix->SMPkluMatrix->KLUmatrixRowCOO) ; - free (Matrix->SMPkluMatrix->KLUmatrixValueComplexCOO) ; + free (Matrix->SMPkluMatrix->KLUmatrixBindStructForCIDER) ; + free (Matrix->SMPkluMatrix->KLUmatrixColCOOforCIDER) ; + free (Matrix->SMPkluMatrix->KLUmatrixRowCOOforCIDER) ; + free (Matrix->SMPkluMatrix->KLUmatrixValueComplexCOOforCIDER) ; free (Matrix->SMPkluMatrix->KLUmatrixTrashCOO) ; Matrix->SMPkluMatrix->KLUmatrixAp = NULL ; Matrix->SMPkluMatrix->KLUmatrixAi = NULL ; Matrix->SMPkluMatrix->KLUmatrixAxComplex = NULL ; Matrix->SMPkluMatrix->KLUmatrixIntermediateComplex = NULL ; - Matrix->SMPkluMatrix->KLUmatrixBindStructCOO = NULL ; - Matrix->SMPkluMatrix->KLUmatrixColCOO = NULL ; - Matrix->SMPkluMatrix->KLUmatrixRowCOO = NULL ; - Matrix->SMPkluMatrix->KLUmatrixValueComplexCOO = NULL ; + Matrix->SMPkluMatrix->KLUmatrixBindStructForCIDER = NULL ; + Matrix->SMPkluMatrix->KLUmatrixColCOOforCIDER = NULL ; + Matrix->SMPkluMatrix->KLUmatrixRowCOOforCIDER = NULL ; + Matrix->SMPkluMatrix->KLUmatrixValueComplexCOOforCIDER = NULL ; Matrix->SMPkluMatrix->KLUmatrixTrashCOO = NULL ; } else { spDestroy (Matrix->SPmatrix) ; @@ -980,11 +1065,13 @@ SMPpreOrder (SMPmatrix *Matrix) { if (Matrix->CKTkluMODE) { - Matrix->CKTkluSymbolic = klu_analyze (Matrix->CKTkluN, Matrix->CKTkluAp, Matrix->CKTkluAi, Matrix->CKTkluCommon) ; + Matrix->SMPkluMatrix->KLUmatrixSymbolic = klu_analyze ((int)Matrix->SMPkluMatrix->KLUmatrixN, Matrix->SMPkluMatrix->KLUmatrixAp, + Matrix->SMPkluMatrix->KLUmatrixAi, Matrix->SMPkluMatrix->KLUmatrixCommon) ; - if (Matrix->CKTkluSymbolic == NULL) + if (Matrix->SMPkluMatrix->KLUmatrixSymbolic == NULL) { - if (Matrix->CKTkluCommon->status == KLU_EMPTY_MATRIX) + fprintf (stderr, "Error (PreOrder): KLUsymbolic object is NULL. A problem occurred\n") ; + if (Matrix->SMPkluMatrix->KLUmatrixCommon->status == KLU_EMPTY_MATRIX) { return 0 ; } @@ -1018,11 +1105,13 @@ SMPprint (SMPmatrix *Matrix, char *Filename) { if (Matrix->CKTkluMODE) { - if (Matrix->CKTkluMatrixIsComplex) + if (Matrix->SMPkluMatrix->KLUmatrixIsComplex) { - klu_z_print (Matrix->CKTkluAp, Matrix->CKTkluAi, Matrix->CKTkluAx_Complex, Matrix->CKTkluN, Matrix->SPmatrix->IntToExtRowMap, Matrix->SPmatrix->IntToExtColMap) ; + klu_z_print (Matrix->SMPkluMatrix->KLUmatrixAp, Matrix->SMPkluMatrix->KLUmatrixAi, Matrix->SMPkluMatrix->KLUmatrixAxComplex, + (int)Matrix->SMPkluMatrix->KLUmatrixN, NULL, NULL) ; } else { - klu_print (Matrix->CKTkluAp, Matrix->CKTkluAi, Matrix->CKTkluAx, Matrix->CKTkluN, Matrix->SPmatrix->IntToExtRowMap, Matrix->SPmatrix->IntToExtColMap) ; + klu_print (Matrix->SMPkluMatrix->KLUmatrixAp, Matrix->SMPkluMatrix->KLUmatrixAi, Matrix->SMPkluMatrix->KLUmatrixAx, + (int)Matrix->SMPkluMatrix->KLUmatrixN, NULL, NULL) ; } } else { if (Filename) @@ -1077,8 +1166,8 @@ SMPgetError (SMPmatrix *Matrix, int *Col, int *Row) { if (Matrix->CKTkluMODE) { - *Row = Matrix->SPmatrix->IntToExtRowMap [Matrix->CKTkluCommon->singular_col + 1] ; - *Col = Matrix->SPmatrix->IntToExtColMap [Matrix->CKTkluCommon->singular_col + 1] ; + *Row = Matrix->SMPkluMatrix->KLUmatrixCommon->singular_col + 1 ; + *Col = Matrix->SMPkluMatrix->KLUmatrixCommon->singular_col + 1 ; } else { spWhereSingular (Matrix->SPmatrix, Row, Col) ; } @@ -1099,32 +1188,32 @@ spDeterminant_KLU (SMPmatrix *Matrix, int *pExponent, RealNumber *pDeterminant, *pExponent = 0 ; - if (Matrix->CKTkluCommon->status == KLU_SINGULAR) + if (Matrix->SMPkluMatrix->KLUmatrixCommon->status == KLU_SINGULAR) { *pDeterminant = 0.0 ; - if (Matrix->CKTkluMatrixIsComplex == CKTkluMatrixComplex) + if (Matrix->SMPkluMatrix->KLUmatrixIsComplex == KLUMatrixComplex) { *piDeterminant = 0.0 ; } return ; } - Size = Matrix->CKTkluN ; + Size = (int)Matrix->SMPkluMatrix->KLUmatrixN ; I = 0 ; - P = (int *) malloc ((size_t)Matrix->CKTkluN * sizeof (int)) ; - Q = (int *) malloc ((size_t)Matrix->CKTkluN * sizeof (int)) ; + P = (int *) malloc ((size_t)Matrix->SMPkluMatrix->KLUmatrixN * sizeof (int)) ; + Q = (int *) malloc ((size_t)Matrix->SMPkluMatrix->KLUmatrixN * sizeof (int)) ; - Ux = (double *) malloc ((size_t)Matrix->CKTkluN * sizeof (double)) ; + Ux = (double *) malloc ((size_t)Matrix->SMPkluMatrix->KLUmatrixN * sizeof (double)) ; - Rs = (double *) malloc ((size_t)Matrix->CKTkluN * sizeof (double)) ; + Rs = (double *) malloc ((size_t)Matrix->SMPkluMatrix->KLUmatrixN * sizeof (double)) ; - if (Matrix->CKTkluMatrixIsComplex == CKTkluMatrixComplex) /* Complex Case. */ + if (Matrix->SMPkluMatrix->KLUmatrixIsComplex == KLUMatrixComplex) /* Complex Case. */ { cDeterminant.Real = 1.0 ; cDeterminant.Imag = 0.0 ; - Uz = (double *) malloc ((size_t)Matrix->CKTkluN * sizeof (double)) ; + Uz = (double *) malloc ((size_t)Matrix->SMPkluMatrix->KLUmatrixN * sizeof (double)) ; /* int *Lp, *Li, *Up, *Ui, *Fp, *Fi, *P, *Q ; double *Lx, *Lz, *Ux, *Uz, *Fx, *Fz, *Rs ; @@ -1147,7 +1236,7 @@ spDeterminant_KLU (SMPmatrix *Matrix, int *pExponent, RealNumber *pDeterminant, P, Q, Rs, NULL, Matrix->CKTkluCommon) ; */ - klu_z_extract_Udiag (Matrix->CKTkluNumeric, Matrix->CKTkluSymbolic, Ux, Uz, P, Q, Rs, Matrix->CKTkluCommon) ; + klu_z_extract_Udiag (Matrix->SMPkluMatrix->KLUmatrixNumeric, Matrix->SMPkluMatrix->KLUmatrixSymbolic, Ux, Uz, P, Q, Rs, Matrix->SMPkluMatrix->KLUmatrixCommon) ; /* for (I = 0 ; I < Matrix->CKTkluNumeric->lnz ; I++) { @@ -1168,7 +1257,7 @@ spDeterminant_KLU (SMPmatrix *Matrix, int *pExponent, RealNumber *pDeterminant, } */ nSwapP = 0 ; - for (I = 0 ; I < Matrix->CKTkluN ; I++) + for (I = 0 ; I < (int)Matrix->SMPkluMatrix->KLUmatrixN ; I++) { if (P [I] != I) { @@ -1178,7 +1267,7 @@ spDeterminant_KLU (SMPmatrix *Matrix, int *pExponent, RealNumber *pDeterminant, nSwapP /= 2 ; nSwapQ = 0 ; - for (I = 0 ; I < Matrix->CKTkluN ; I++) + for (I = 0 ; I < (int)Matrix->SMPkluMatrix->KLUmatrixN ; I++) { if (Q [I] != I) { @@ -1269,10 +1358,10 @@ spDeterminant_KLU (SMPmatrix *Matrix, int *pExponent, RealNumber *pDeterminant, /* Real Case. */ *pDeterminant = 1.0 ; - klu_extract_Udiag (Matrix->CKTkluNumeric, Matrix->CKTkluSymbolic, Ux, P, Q, Rs, Matrix->CKTkluCommon) ; + klu_extract_Udiag (Matrix->SMPkluMatrix->KLUmatrixNumeric, Matrix->SMPkluMatrix->KLUmatrixSymbolic, Ux, P, Q, Rs, Matrix->SMPkluMatrix->KLUmatrixCommon) ; nSwapP = 0 ; - for (I = 0 ; I < Matrix->CKTkluN ; I++) + for (I = 0 ; I < (int)Matrix->SMPkluMatrix->KLUmatrixN ; I++) { if (P [I] != I) { @@ -1282,7 +1371,7 @@ spDeterminant_KLU (SMPmatrix *Matrix, int *pExponent, RealNumber *pDeterminant, nSwapP /= 2 ; nSwapQ = 0 ; - for (I = 0 ; I < Matrix->CKTkluN ; I++) + for (I = 0 ; I < (int)Matrix->SMPkluMatrix->KLUmatrixN ; I++) { if (Q [I] != I) { @@ -1469,14 +1558,18 @@ SMPcDProd (SMPmatrix *Matrix, SPcomplex *pMantissa, int *pExponent) static void -LoadGmin_CSC (double **diag, int n, double Gmin) +LoadGmin_CSC (double **diag, unsigned int n, double Gmin) { - int i ; + unsigned int i ; - if (Gmin != 0.0) - for (i = 0 ; i < n ; i++) - if (diag [i] != NULL) + if (Gmin != 0.0) { + for (i = 0 ; i < n ; i++) { + if (diag [i] != NULL) { + // Not all the elements on the diagonal are present, when the circuit is parsed *(diag [i]) += Gmin ; + } + } + } } static void @@ -1522,20 +1615,18 @@ SMPfindElt (SMPmatrix *eMatrix, int Row, int Col, int CreateIfMissing) { int i ; - Row = Matrix->ExtToIntRowMap [Row] ; - Col = Matrix->ExtToIntColMap [Col] ; Row = Row - 1 ; Col = Col - 1 ; if ((Row < 0) || (Col < 0)) { printf ("Error: Cannot find an element with row '%d' and column '%d' in the KLU matrix\n", Row, Col) ; return NULL ; } - for (i = eMatrix->CKTkluAp [Col] ; i < eMatrix->CKTkluAp [Col + 1] ; i++) { - if (eMatrix->CKTkluAi [i] == Row) { - if (eMatrix->CKTkluMatrixIsComplex == CKTkluMatrixReal) { - return (SMPelement *) &(eMatrix->CKTkluAx [i]) ; - } else if (eMatrix->CKTkluMatrixIsComplex == CKTkluMatrixComplex) { - return (SMPelement *) &(eMatrix->CKTkluAx_Complex [2 * i]) ; + for (i = eMatrix->SMPkluMatrix->KLUmatrixAp [Col] ; i < eMatrix->SMPkluMatrix->KLUmatrixAp [Col + 1] ; i++) { + if (eMatrix->SMPkluMatrix->KLUmatrixAi [i] == Row) { + if (eMatrix->SMPkluMatrix->KLUmatrixIsComplex == KLUmatrixReal) { + return (SMPelement *) &(eMatrix->SMPkluMatrix->KLUmatrixAx [i]) ; + } else if (eMatrix->SMPkluMatrix->KLUmatrixIsComplex == KLUMatrixComplex) { + return (SMPelement *) &(eMatrix->SMPkluMatrix->KLUmatrixAxComplex [2 * i]) ; } else { return NULL ; } @@ -1566,18 +1657,17 @@ SMPcZeroCol (SMPmatrix *eMatrix, int Col) MatrixPtr Matrix = eMatrix->SPmatrix ; ElementPtr Element ; - Col = Matrix->ExtToIntColMap [Col] ; - if (eMatrix->CKTkluMODE) { int i ; - for (i = eMatrix->CKTkluAp [Col - 1] ; i < eMatrix->CKTkluAp [Col] ; i++) + for (i = eMatrix->SMPkluMatrix->KLUmatrixAp [Col - 1] ; i < eMatrix->SMPkluMatrix->KLUmatrixAp [Col] ; i++) { - eMatrix->CKTkluAx_Complex [2 * i] = 0 ; - eMatrix->CKTkluAx_Complex [2 * i + 1] = 0 ; + eMatrix->SMPkluMatrix->KLUmatrixAxComplex [2 * i] = 0 ; + eMatrix->SMPkluMatrix->KLUmatrixAxComplex [2 * i + 1] = 0 ; } return 0 ; } else { + Col = Matrix->ExtToIntColMap [Col] ; for (Element = Matrix->FirstInCol [Col] ; Element != NULL ; Element = Element->NextInCol) { Element->Real = 0.0 ; @@ -1661,11 +1751,13 @@ SMPconstMult (SMPmatrix *Matrix, double constant) { if (Matrix->CKTkluMODE) { - if (Matrix->CKTkluMatrixIsComplex) + if (Matrix->SMPkluMatrix->KLUmatrixIsComplex) { - klu_z_constant_multiply (Matrix->CKTkluAp, Matrix->CKTkluAx_Complex, Matrix->CKTkluN, Matrix->CKTkluCommon, constant) ; + klu_z_constant_multiply (Matrix->SMPkluMatrix->KLUmatrixAp, Matrix->SMPkluMatrix->KLUmatrixAxComplex, + (int)Matrix->SMPkluMatrix->KLUmatrixN, Matrix->SMPkluMatrix->KLUmatrixCommon, constant) ; } else { - klu_constant_multiply (Matrix->CKTkluAp, Matrix->CKTkluAx, Matrix->CKTkluN, Matrix->CKTkluCommon, constant) ; + klu_constant_multiply (Matrix->SMPkluMatrix->KLUmatrixAp, Matrix->SMPkluMatrix->KLUmatrixAx, + (int)Matrix->SMPkluMatrix->KLUmatrixN, Matrix->SMPkluMatrix->KLUmatrixCommon, constant) ; } } else { spConstMult (Matrix->SPmatrix, constant) ; @@ -1683,20 +1775,22 @@ SMPmultiply (SMPmatrix *Matrix, double *RHS, double *Solution, double *iRHS, dou int *Ap_CSR, *Ai_CSR ; double *Ax_CSR ; - Ap_CSR = (int *) malloc ((size_t)(Matrix->CKTkluN + 1) * sizeof (int)) ; - Ai_CSR = (int *) malloc ((size_t)Matrix->CKTklunz * sizeof (int)) ; + Ap_CSR = (int *) malloc ((size_t)(Matrix->SMPkluMatrix->KLUmatrixN + 1) * sizeof (int)) ; + Ai_CSR = (int *) malloc ((size_t)Matrix->SMPkluMatrix->KLUmatrixNZ * sizeof (int)) ; - if (Matrix->CKTkluMatrixIsComplex) + if (Matrix->SMPkluMatrix->KLUmatrixIsComplex) { - Ax_CSR = (double *) malloc ((size_t)(2 * Matrix->CKTklunz) * sizeof (double)) ; - klu_z_convert_matrix_in_CSR (Matrix->CKTkluAp, Matrix->CKTkluAi, Matrix->CKTkluAx_Complex, Ap_CSR, Ai_CSR, Ax_CSR, Matrix->CKTkluN, Matrix->CKTklunz, Matrix->CKTkluCommon) ; - klu_z_matrix_vector_multiply (Ap_CSR, Ai_CSR, Ax_CSR, RHS, Solution, iRHS, iSolution, Matrix->SPmatrix->IntToExtRowMap, - Matrix->SPmatrix->IntToExtColMap, Matrix->CKTkluN, Matrix->CKTkluCommon) ; + Ax_CSR = (double *) malloc ((size_t)(2 * Matrix->SMPkluMatrix->KLUmatrixNZ) * sizeof (double)) ; + klu_z_convert_matrix_in_CSR (Matrix->SMPkluMatrix->KLUmatrixAp, Matrix->SMPkluMatrix->KLUmatrixAi, Matrix->SMPkluMatrix->KLUmatrixAxComplex, Ap_CSR, + Ai_CSR, Ax_CSR, (int)Matrix->SMPkluMatrix->KLUmatrixN, (int)Matrix->SMPkluMatrix->KLUmatrixNZ, Matrix->SMPkluMatrix->KLUmatrixCommon) ; + klu_z_matrix_vector_multiply (Ap_CSR, Ai_CSR, Ax_CSR, RHS, Solution, iRHS, iSolution, NULL, NULL, + (int)Matrix->SMPkluMatrix->KLUmatrixN, Matrix->SMPkluMatrix->KLUmatrixCommon) ; } else { - Ax_CSR = (double *) malloc ((size_t)Matrix->CKTklunz * sizeof (double)) ; - klu_convert_matrix_in_CSR (Matrix->CKTkluAp, Matrix->CKTkluAi, Matrix->CKTkluAx, Ap_CSR, Ai_CSR, Ax_CSR, Matrix->CKTkluN, Matrix->CKTklunz, Matrix->CKTkluCommon) ; - klu_matrix_vector_multiply (Ap_CSR, Ai_CSR, Ax_CSR, RHS, Solution, Matrix->SPmatrix->IntToExtRowMap, - Matrix->SPmatrix->IntToExtColMap, Matrix->CKTkluN, Matrix->CKTkluCommon) ; + Ax_CSR = (double *) malloc ((size_t)Matrix->SMPkluMatrix->KLUmatrixNZ * sizeof (double)) ; + klu_convert_matrix_in_CSR (Matrix->SMPkluMatrix->KLUmatrixAp, Matrix->SMPkluMatrix->KLUmatrixAi, Matrix->SMPkluMatrix->KLUmatrixAx, Ap_CSR, Ai_CSR, + Ax_CSR, (int)Matrix->SMPkluMatrix->KLUmatrixN, (int)Matrix->SMPkluMatrix->KLUmatrixNZ, Matrix->SMPkluMatrix->KLUmatrixCommon) ; + klu_matrix_vector_multiply (Ap_CSR, Ai_CSR, Ax_CSR, RHS, Solution, NULL, NULL, + (int)Matrix->SMPkluMatrix->KLUmatrixN, Matrix->SMPkluMatrix->KLUmatrixCommon) ; iSolution = iRHS ; } @@ -1707,3 +1801,4 @@ SMPmultiply (SMPmatrix *Matrix, double *RHS, double *Solution, double *iRHS, dou spMultiply (Matrix->SPmatrix, RHS, Solution, iRHS, iSolution) ; } } + diff --git a/src/maths/ni/niinit.c b/src/maths/ni/niinit.c index 968562f43..1a1817e2c 100644 --- a/src/maths/ni/niinit.c +++ b/src/maths/ni/niinit.c @@ -32,25 +32,11 @@ NIinit(CKTcircuit *ckt) ckt->CKTmatrix = TMALLOC (SMPmatrix, 1) ; #ifdef KLU - ckt->CKTmatrix->CKTkluCommon = TMALLOC (klu_common, 1) ; - ckt->CKTmatrix->CKTkluSymbolic = NULL ; - ckt->CKTmatrix->CKTkluNumeric = NULL ; - ckt->CKTmatrix->CKTkluAp = NULL ; - ckt->CKTmatrix->CKTkluAi = NULL ; - ckt->CKTmatrix->CKTkluAx = NULL ; - ckt->CKTmatrix->CKTkluMatrixIsComplex = CKTkluMatrixReal ; - ckt->CKTmatrix->CKTkluIntermediate = NULL ; - ckt->CKTmatrix->CKTkluIntermediate_Complex = NULL ; - ckt->CKTmatrix->CKTbindStruct = NULL ; - ckt->CKTmatrix->CKTdiag_CSC = NULL ; - ckt->CKTmatrix->CKTkluN = 0 ; - ckt->CKTmatrix->CKTklunz = 0 ; ckt->CKTmatrix->CKTkluMODE = ckt->CKTkluMODE ; /* TO BE SUBSTITUTED WITH THE HEURISTICS */ - - klu_defaults (ckt->CKTmatrix->CKTkluCommon) ; - ckt->CKTmatrix->CKTkluCommon->memgrow = ckt->CKTkluMemGrowFactor ; + ckt->CKTmatrix->CKTkluMemGrowFactor = ckt->CKTkluMemGrowFactor ; #endif ckt->CKTniState = NIUNINITIALIZED; return SMPnewMatrix(ckt->CKTmatrix, 0); } + diff --git a/src/maths/sparse/Makefile.am b/src/maths/sparse/Makefile.am index b4e75e995..8f5be082c 100644 --- a/src/maths/sparse/Makefile.am +++ b/src/maths/sparse/Makefile.am @@ -13,10 +13,7 @@ libsparse_la_SOURCES = \ spsolve.c \ sputils.c - -if KLU_WANTED -libsparse_la_SOURCES += spCSC.c -else +if !KLU_WANTED libsparse_la_SOURCES += spsmp.c endif @@ -24,3 +21,4 @@ AM_CPPFLAGS = @AM_CPPFLAGS@ -I$(top_srcdir)/src/include AM_CFLAGS = $(STATIC) MAINTAINERCLEANFILES = Makefile.in + diff --git a/src/maths/sparse/spCSC.c b/src/maths/sparse/spCSC.c deleted file mode 100644 index 8e00648ae..000000000 --- a/src/maths/sparse/spCSC.c +++ /dev/null @@ -1,174 +0,0 @@ -/* Sparse Matrix to CSC Matrix Conversion Routines - * Including Dump Routines - * - * Author: Francesco Lannutti 2011-2012 - * - * Instructions: - * spMatrix_CSC_dump and spRHS_CSC_dump are the dump routines; - * insert them in a point in your code after that the Sparse Matrix - * is filled in to dump the whole matrix in the CSC format. - * To solve correctly the resulting CSC linear system, it's crucial - * to perform another inversion of the Solution Vector following this code: - * - * pExtOrder = IntToExtColMap [n] ; - * for (i = n - 1 ; i >= 0 ; i--) - * RHS [*(pExtOrder--)] = Intermediate [i] ; - */ - -/* Includes */ -#include "ngspice/spmatrix.h" -#include "spdefs.h" - -/* Body */ -int -WriteCol_original (MatrixPtr Matrix, int Col, spREAL *CSC_Element, spREAL *CSC_Element_Complex, int *CSC_Row, BindElement *BindSparseCSC, spREAL **diag) -{ - int i ; - ElementPtr current ; - - i = 0 ; - current = Matrix->FirstInCol [Col] ; - - while (current != NULL) { - BindSparseCSC [i].Sparse = (double *)current ; - BindSparseCSC [i].CSC = &(CSC_Element [i]) ; - BindSparseCSC [i].CSC_Complex = &(CSC_Element_Complex [2 * i]) ; - CSC_Row [i] = (current->Row) - 1 ; - if (CSC_Row [i] == Col - 1) - diag [0] = &(CSC_Element [i]) ; - i++ ; - current = current->NextInCol ; - } - - return i ; -} - -int -WriteCol_original_dump (MatrixPtr Matrix, int Col, spREAL *CSC_Element, int *CSC_Row, unsigned int complex) -{ - int i ; - ElementPtr current ; - i = 0 ; - current = Matrix->FirstInCol [Col] ; - - while (current != NULL) - { - if (complex) - { - CSC_Element [2 * i] = current->Real ; - CSC_Element [2 * i + 1] = current->Imag ; - } else { - CSC_Element [i] = current->Real ; - } - CSC_Row [i] = (current->Row) - 1 ; - i++ ; - current = current->NextInCol ; - } - - return i ; -} - -void -spMatrix_CSC (MatrixPtr Matrix, int *Ap, int *Ai, double *Ax, double *Ax_Complex, int n, BindElement *BindSparseCSC, double **diag) -{ - int offset, i ; - - offset = 0 ; - Ap[0] = offset ; - for (i = 1 ; i <= n ; i++) { - offset += WriteCol_original (Matrix, i, (spREAL *)(Ax + offset), (spREAL *)(Ax_Complex + 2 * offset), - (int *)(Ai + offset), BindSparseCSC + offset, (spREAL **)(diag + (i - 1))) ; - - Ap[i] = offset ; - } -} - -void -spMatrix_CSC_dump (MatrixPtr Matrix, unsigned int complex, char *CSC_output) -{ - FILE *output ; - int offset, i, j, *Ap, *Ai, n, nz ; - double *Ax ; - - n = spGetSize (Matrix, 1) ; - nz = Matrix->Elements ; - Ap = (int *) SP_MALLOC (int, n + 1) ; - Ai = (int *) SP_MALLOC (int, nz) ; - if (complex) - { - Ax = (double *) SP_MALLOC (double, 2 * nz) ; - } else { - Ax = (double *) SP_MALLOC (double, nz) ; - } - - offset = 0 ; - Ap [0] = offset ; - for (i = 1 ; i <= n ; i++) { - offset += WriteCol_original_dump (Matrix, i, (spREAL *)(Ax + offset), (int *)(Ai + offset), complex) ; - Ap [i] = offset ; - } - - if (!complex && CSC_output != NULL) - { - output = fopen (CSC_output, "w") ; - fprintf (output, "%%%%MatrixMarket matrix coordinate real general\n") ; - fprintf (output, "%%-------------------------------------------------------------------------------\n") ; - fprintf (output, "%% Transient Matrix Dump\n%% Family: ISCAS Circuit\n") ; - fprintf (output, "%%-------------------------------------------------------------------------------\n") ; - fprintf (output, "%d %d %d\n", n, n, offset) ; - for (i = 0 ; i < n ; i++) - for (j = Ap [i] ; j < Ap [i + 1] ; j++) - fprintf (output, "%d %d %-.9g\n", Ai [j] + 1, i + 1, Ax [j]) ; - fclose (output) ; - - output = fopen ("IntToExtColMap.txt", "w") ; - for (i = 1 ; i <= n ; i++) - fprintf (output, "%d\n", Matrix->IntToExtColMap [i]) ; - fclose (output) ; - } else { - fprintf (stderr, "CSC Matrix converted from SPARSE 1.3 matrix\n") ; - for (i = 0 ; i < n ; i++) - { - for (j = Ap [i] ; j < Ap [i + 1] ; j++) - { - if (complex) - { - fprintf (stderr, "Row: %d\tCol: %d\tValue: %-.9g j%-.9g\n", Ai [j] + 1, i + 1, Ax [2 * j], Ax [2 * j + 1]) ; - } else { - fprintf (stderr, "Row: %d\tCol: %d\tValue: %-.9g\n", Ai [j] + 1, i + 1, Ax [j]) ; - } - } - } - } - - SP_FREE (Ap) ; - SP_FREE (Ai) ; - SP_FREE (Ax) ; -} - -void -spRHS_CSC_dump (RealNumber *RHS, char *CSC_output_b, MatrixPtr Matrix) -{ - FILE *output ; - int i, n, *pExtOrder ; - double *Intermediate ; - - n = spGetSize (Matrix, 1) ; - Intermediate = (double *) SP_MALLOC (double, n) ; - - pExtOrder = &Matrix->IntToExtRowMap [n] ; - for (i = n - 1 ; i >= 0 ; i--) - Intermediate [i] = RHS [*(pExtOrder--)] ; - - output = fopen (CSC_output_b, "w") ; - fprintf (output, "%%%%MatrixMarket matrix array real general\n") ; - fprintf (output, "%%-------------------------------------------------------------------------------\n") ; - fprintf (output, "%% Transient RHS Vector Dump\n%% Family: ISCAS Circuit\n") ; - fprintf (output, "%%-------------------------------------------------------------------------------\n") ; - fprintf (output, "%d %d\n", n, 1) ; - for (i = 1 ; i < n + 1 ; i++) - fprintf (output, "%-.9g\n", Intermediate [i]) ; - fclose (output) ; - - SP_FREE (Intermediate) ; -} diff --git a/src/spicelib/analysis/acan.c b/src/spicelib/analysis/acan.c index be35efd1f..1943a9576 100644 --- a/src/spicelib/analysis/acan.c +++ b/src/spicelib/analysis/acan.c @@ -259,13 +259,13 @@ ACan(CKTcircuit* ckt, int restart) if (ckt->CKTmatrix->CKTkluMODE) { /* Conversion from Real Matrix to Complex Matrix */ - if (!ckt->CKTmatrix->CKTkluMatrixIsComplex) + if (!ckt->CKTmatrix->SMPkluMatrix->KLUmatrixIsComplex) { for (i = 0 ; i < DEVmaxnum ; i++) if (DEVices [i] && DEVices [i]->DEVbindCSCComplex && ckt->CKThead [i]) DEVices [i]->DEVbindCSCComplex (ckt->CKThead [i], ckt) ; - ckt->CKTmatrix->CKTkluMatrixIsComplex = CKTkluMatrixComplex ; + ckt->CKTmatrix->SMPkluMatrix->KLUmatrixIsComplex = KLUMatrixComplex ; } } #endif @@ -290,7 +290,7 @@ ACan(CKTcircuit* ckt, int restart) if (DEVices [i] && DEVices [i]->DEVbindCSCComplexToReal && ckt->CKThead [i]) DEVices [i]->DEVbindCSCComplexToReal (ckt->CKThead [i], ckt) ; - ckt->CKTmatrix->CKTkluMatrixIsComplex = CKTkluMatrixReal ; + ckt->CKTmatrix->SMPkluMatrix->KLUmatrixIsComplex = KLUmatrixReal ; } #endif @@ -331,7 +331,7 @@ ACan(CKTcircuit* ckt, int restart) if (DEVices [i] && DEVices [i]->DEVbindCSCComplex && ckt->CKThead [i]) DEVices [i]->DEVbindCSCComplex (ckt->CKThead [i], ckt) ; - ckt->CKTmatrix->CKTkluMatrixIsComplex = CKTkluMatrixComplex ; + ckt->CKTmatrix->SMPkluMatrix->KLUmatrixIsComplex = KLUMatrixComplex ; } #endif @@ -443,7 +443,7 @@ endsweep: if (DEVices [i] && DEVices [i]->DEVbindCSCComplexToReal && ckt->CKThead [i]) DEVices [i]->DEVbindCSCComplexToReal (ckt->CKThead [i], ckt) ; - ckt->CKTmatrix->CKTkluMatrixIsComplex = CKTkluMatrixReal ; + ckt->CKTmatrix->SMPkluMatrix->KLUmatrixIsComplex = KLUmatrixReal ; } #endif diff --git a/src/spicelib/analysis/cktacct.c b/src/spicelib/analysis/cktacct.c index 161b68dc4..52a38c0a2 100644 --- a/src/spicelib/analysis/cktacct.c +++ b/src/spicelib/analysis/cktacct.c @@ -40,7 +40,16 @@ CKTacct(CKTcircuit *ckt, JOB *anal, int which, IFvalue *val) break; case OPT_ORIGNZ: if ( ckt->CKTmatrix != NULL ) { + +#ifdef KLU + if (ckt->CKTkluMODE) + val->iValue = (int)ckt->CKTmatrix->SMPkluMatrix->KLUmatrixNZ ; + else + val->iValue = spOriginalCount (ckt->CKTmatrix->SPmatrix) ; +#else val->iValue = spOriginalCount(ckt->CKTmatrix->SPmatrix); +#endif + } else { val->iValue = 0; } @@ -49,7 +58,8 @@ CKTacct(CKTcircuit *ckt, JOB *anal, int which, IFvalue *val) if ( ckt->CKTmatrix != NULL ) { #ifdef KLU if (ckt->CKTmatrix->CKTkluMODE) - val->iValue = ckt->CKTmatrix->CKTkluNumeric->lnz + ckt->CKTmatrix->CKTkluNumeric->unz + ckt->CKTmatrix->CKTkluNumeric->nzoff - ckt->CKTmatrix->CKTklunz ; + val->iValue = ckt->CKTmatrix->SMPkluMatrix->KLUmatrixNumeric->lnz + ckt->CKTmatrix->SMPkluMatrix->KLUmatrixNumeric->unz + + ckt->CKTmatrix->SMPkluMatrix->KLUmatrixNumeric->nzoff - (int)ckt->CKTmatrix->SMPkluMatrix->KLUmatrixNZ ; else val->iValue = spFillinCount(ckt->CKTmatrix->SPmatrix); #else @@ -63,7 +73,8 @@ CKTacct(CKTcircuit *ckt, JOB *anal, int which, IFvalue *val) if ( ckt->CKTmatrix != NULL ) { #ifdef KLU if (ckt->CKTmatrix->CKTkluMODE) - val->iValue = ckt->CKTmatrix->CKTkluNumeric->lnz + ckt->CKTmatrix->CKTkluNumeric->unz + ckt->CKTmatrix->CKTkluNumeric->nzoff ; + val->iValue = ckt->CKTmatrix->SMPkluMatrix->KLUmatrixNumeric->lnz + ckt->CKTmatrix->SMPkluMatrix->KLUmatrixNumeric->unz + + ckt->CKTmatrix->SMPkluMatrix->KLUmatrixNumeric->nzoff ; else val->iValue = spElementCount(ckt->CKTmatrix->SPmatrix); #else diff --git a/src/spicelib/analysis/cktpzset.c b/src/spicelib/analysis/cktpzset.c index 3762cbef2..ae8da2928 100644 --- a/src/spicelib/analysis/cktpzset.c +++ b/src/spicelib/analysis/cktpzset.c @@ -14,21 +14,6 @@ Copyright 1990 Regents of the University of California. All rights reserved. #include "ngspice/devdefs.h" #include "ngspice/sperror.h" -#ifdef KLU -#include - -static -int -BindCompare (const void *a, const void *b) -{ - BindElement *A, *B ; - A = (BindElement *)a ; - B = (BindElement *)b ; - - return ((int)(A->Sparse - B->Sparse)) ; -} -#endif - int CKTpzSetup(CKTcircuit *ckt, int type) { @@ -104,35 +89,12 @@ CKTpzSetup(CKTcircuit *ckt, int type) job->PZnumswaps = 1; #ifdef KLU - if (ckt->CKTmatrix->CKTkluMODE) + if (matrix->CKTkluMODE) { fprintf (stderr, "Using KLU as Direct Linear Solver\n") ; - int i ; - int n = SMPmatSize (ckt->CKTmatrix) ; - ckt->CKTmatrix->CKTkluN = n ; - - SMPnnz (ckt->CKTmatrix) ; - int nz = ckt->CKTmatrix->CKTklunz ; - - ckt->CKTmatrix->CKTkluAp = TMALLOC (int, n + 1) ; - ckt->CKTmatrix->CKTkluAi = TMALLOC (int, nz) ; - ckt->CKTmatrix->CKTkluAx = TMALLOC (double, nz) ; - ckt->CKTmatrix->CKTkluIntermediate = TMALLOC (double, n) ; - - ckt->CKTmatrix->CKTbindStruct = TMALLOC (BindElement, nz) ; - - ckt->CKTmatrix->CKTdiag_CSC = TMALLOC (double *, n) ; - - /* Complex Stuff needed for AC Analysis */ - ckt->CKTmatrix->CKTkluAx_Complex = TMALLOC (double, 2 * nz) ; - ckt->CKTmatrix->CKTkluIntermediate_Complex = TMALLOC (double, 2 * n) ; - - /* Binding Table from Sparse to CSC Format Creation */ - SMPmatrix_CSC (ckt->CKTmatrix) ; - - /* Binding Table Sorting */ - qsort (ckt->CKTmatrix->CKTbindStruct, (size_t)nz, sizeof(BindElement), BindCompare) ; + /* Convert the COO Storage to CSC for KLU and Fill the Binding Table */ + SMPconvertCOOtoCSC (matrix) ; /* KLU Pointers Assignment */ for (i = 0 ; i < DEVmaxnum ; i++) @@ -140,34 +102,48 @@ CKTpzSetup(CKTcircuit *ckt, int type) DEVices [i]->DEVbindCSC (ckt->CKThead [i], ckt) ; /* ReOrder */ - error = SMPpreOrder (ckt->CKTmatrix) ; + error = SMPpreOrder (matrix) ; if (error) { fprintf (stderr, "Error during ReOrdering\n") ; } - /* Conversion from Real Matrix to Complex Matrix */ + /* Conversion from Real Circuit Matrix to Complex Circuit Matrix */ for (i = 0 ; i < DEVmaxnum ; i++) if (DEVices [i] && DEVices [i]->DEVbindCSCComplex && ckt->CKThead [i]) DEVices [i]->DEVbindCSCComplex (ckt->CKThead [i], ckt) ; - ckt->CKTmatrix->CKTkluMatrixIsComplex = CKTkluMatrixComplex ; + matrix->SMPkluMatrix->KLUmatrixIsComplex = KLUMatrixComplex ; /* Input Pos */ - if ((input_pos != 0) && (solution_col != 0)) + if ((input_pos > 0) && (solution_col > 0)) { - double *j ; + BindElement j, *matched ; - j = job->PZdrive_pptr ; - job->PZdrive_pptr = ((BindElement *) bsearch (&j, ckt->CKTmatrix->CKTbindStruct, (size_t)nz, sizeof(BindElement), BindCompare))->CSC_Complex ; + j.COO = job->PZdrive_pptr ; + j.CSC = NULL ; + j.CSC_Complex = NULL ; + matched = (BindElement *) bsearch (&j, matrix->SMPkluMatrix->KLUmatrixBindStructCOO, + matrix->SMPkluMatrix->KLUmatrixLinkedListNZ, sizeof (BindElement), BindCompare) ; + if (matched == NULL) { + printf ("Ptr %p not found in BindStruct Table\n", job->PZdrive_pptr) ; + } + job->PZdrive_pptr = matched->CSC_Complex ; } /* Input Neg */ - if ((input_neg != 0) && (solution_col != 0)) + if ((input_neg > 0) && (solution_col > 0)) { - double *j ; + BindElement j, *matched ; - j = job->PZdrive_nptr ; - job->PZdrive_nptr = ((BindElement *) bsearch (&j, ckt->CKTmatrix->CKTbindStruct, (size_t)nz, sizeof(BindElement), BindCompare))->CSC_Complex ; + j.COO = job->PZdrive_nptr ; + j.CSC = NULL ; + j.CSC_Complex = NULL ; + matched = (BindElement *) bsearch (&j, matrix->SMPkluMatrix->KLUmatrixBindStructCOO, + matrix->SMPkluMatrix->KLUmatrixLinkedListNZ, sizeof (BindElement), BindCompare) ; + if (matched == NULL) { + printf ("Ptr %p not found in BindStruct Table\n", job->PZdrive_nptr) ; + } + job->PZdrive_nptr = matched->CSC_Complex ; } } else { fprintf (stderr, "Using SPARSE 1.3 as Direct Linear Solver\n") ; @@ -180,3 +156,4 @@ CKTpzSetup(CKTcircuit *ckt, int type) return OK; } + diff --git a/src/spicelib/analysis/cktsens.c b/src/spicelib/analysis/cktsens.c index a66ce101c..555462857 100644 --- a/src/spicelib/analysis/cktsens.c +++ b/src/spicelib/analysis/cktsens.c @@ -45,22 +45,6 @@ static double inc_freq(double freq, int type, double step_size); } -#ifdef KLU -#include - -static -int -BindCompare (const void *a, const void *b) -{ - BindElement *A, *B ; - A = (BindElement *)a ; - B = (BindElement *)b ; - - return ((int)(A->Sparse - B->Sparse)) ; -} -#endif - - /* * Procedure: * @@ -117,7 +101,7 @@ int sens_sens(CKTcircuit *ckt, int restart) SMPmatrix *saved_matrix = NULL; #ifdef KLU - int nz, size_CSC; + int size_CSC ; #endif #ifndef notdef @@ -173,33 +157,14 @@ int sens_sens(CKTcircuit *ckt, int restart) /* Create the perturbation matrix */ delta_Y = TMALLOC(SMPmatrix, 1); -#ifdef KLU - delta_Y->CKTkluSymbolic = NULL; - delta_Y->CKTkluNumeric = NULL; - delta_Y->CKTkluAp = NULL; - delta_Y->CKTkluAi = NULL; - delta_Y->CKTkluAx = NULL; - delta_Y->CKTkluMatrixIsComplex = CKTkluMatrixReal; - delta_Y->CKTkluIntermediate = NULL; - delta_Y->CKTkluIntermediate_Complex = NULL; - delta_Y->CKTbindStruct = NULL; - delta_Y->CKTdiag_CSC = NULL; - delta_Y->CKTkluN = 0; - delta_Y->CKTklunz = 0; - delta_Y->CKTkluMODE = ckt->CKTkluMODE; - - if (ckt->CKTkluMODE) { - delta_Y->CKTkluCommon = TMALLOC(klu_common, 1); - klu_defaults(delta_Y->CKTkluCommon); - } else { - delta_Y->CKTkluCommon = NULL; - } -#endif - error = SMPnewMatrix(delta_Y, size); if (error) return error; +#ifdef KLU + delta_Y->SMPkluMatrix->KLUmatrixDiag = NULL ; +#endif + // SMPprint(delta_Y, NULL); size += 1; @@ -300,15 +265,15 @@ int sens_sens(CKTcircuit *ckt, int restart) #ifdef KLU if (ckt->CKTkluMODE) { - /* Convert the KLU matrix to complex */ - for (i = 0 ; i < Y->CKTklunz ; i++) { - Y->CKTkluAx_Complex [2 * i] = Y->CKTkluAx [i]; - Y->CKTkluAx_Complex [2 * i + 1] = 0.0; + /* Convert the KLU Circuit Matrix to Complex */ + for (i = 0 ; i < (int)Y->SMPkluMatrix->KLUmatrixNZ ; i++) { + Y->SMPkluMatrix->KLUmatrixAxComplex [2 * i] = Y->SMPkluMatrix->KLUmatrixAx [i] ; + Y->SMPkluMatrix->KLUmatrixAxComplex [2 * i + 1] = 0.0 ; } - Y->CKTkluMatrixIsComplex = CKTkluMatrixComplex; + Y->SMPkluMatrix->KLUmatrixIsComplex = KLUMatrixComplex ; - SMPcReorder(Y, ckt->CKTpivotAbsTol, ckt->CKTpivotRelTol, &size_CSC); // size_CSC is just a placeholder here + SMPcReorder (Y, ckt->CKTpivotAbsTol, ckt->CKTpivotRelTol, &size_CSC) ; // size_CSC is just a placeholder here } #endif @@ -378,14 +343,14 @@ int sens_sens(CKTcircuit *ckt, int restart) /* ReOrder */ error = SMPpreOrder (ckt->CKTmatrix) ; - /* Conversion from Real Matrix to Complex Matrix */ - if (!ckt->CKTmatrix->CKTkluMatrixIsComplex) + /* Conversion from Real Circuit Matrix to Complex Circuit Matrix */ + if (!ckt->CKTmatrix->SMPkluMatrix->KLUmatrixIsComplex) { for (i = 0 ; i < DEVmaxnum ; i++) if (DEVices [i] && DEVices [i]->DEVbindCSCComplex && ckt->CKThead [i]) DEVices [i]->DEVbindCSCComplex (ckt->CKThead [i], ckt) ; - ckt->CKTmatrix->CKTkluMatrixIsComplex = CKTkluMatrixComplex ; + ckt->CKTmatrix->SMPkluMatrix->KLUmatrixIsComplex = KLUMatrixComplex ; } } #endif @@ -470,43 +435,23 @@ int sens_sens(CKTcircuit *ckt, int restart) #ifdef KLU if (ckt->CKTmatrix->CKTkluMODE) { - size_CSC = SMPmatSize (ckt->CKTmatrix) ; - ckt->CKTmatrix->CKTkluN = size_CSC ; + /* Populate the delta_Y KLU Matrix */ - SMPnnz (ckt->CKTmatrix) ; - nz = ckt->CKTmatrix->CKTklunz ; - - ckt->CKTmatrix->CKTkluAp = TMALLOC (int, size_CSC + 1) ; - ckt->CKTmatrix->CKTkluAi = TMALLOC (int, nz) ; - ckt->CKTmatrix->CKTkluAx = TMALLOC (double, nz) ; - ckt->CKTmatrix->CKTkluIntermediate = TMALLOC (double, size_CSC) ; - - ckt->CKTmatrix->CKTbindStruct = TMALLOC (BindElement, nz) ; - - ckt->CKTmatrix->CKTdiag_CSC = TMALLOC (double *, size_CSC) ; - - /* Complex Stuff needed for AC Analysis */ - ckt->CKTmatrix->CKTkluAx_Complex = TMALLOC (double, 2 * nz) ; - ckt->CKTmatrix->CKTkluIntermediate_Complex = TMALLOC (double, 2 * size_CSC) ; - - /* Binding Table from Sparse to CSC Format Creation */ - SMPmatrix_CSC (ckt->CKTmatrix) ; - - /* Binding Table Sorting */ - qsort (ckt->CKTmatrix->CKTbindStruct, (size_t)nz, sizeof(BindElement), BindCompare) ; + /* Convert the COO Storage to CSC for KLU and Fill the Binding Table */ + SMPconvertCOOtoCSC (delta_Y) ; /* KLU Pointers Assignment */ if (DEVices [sg->dev]->DEVbindCSC) DEVices [sg->dev]->DEVbindCSC (sg->model, ckt) ; - ckt->CKTmatrix->CKTkluMatrixIsComplex = CKTkluMatrixReal ; + delta_Y->SMPkluMatrix->KLUmatrixIsComplex = KLUmatrixReal ; /* Clear KLU Vectors */ - for (i = 0 ; i < nz ; i++) + for (i = 0 ; i < (int)delta_Y->SMPkluMatrix->KLUmatrixNZ ; i++) { - ckt->CKTmatrix->CKTkluAx [i] = 0 ; - ckt->CKTmatrix->CKTkluAx_Complex [2 * i] = 0 ; - ckt->CKTmatrix->CKTkluAx_Complex [2 * i + 1] = 0 ; + delta_Y->SMPkluMatrix->KLUmatrixAx [i] = 0 ; + delta_Y->SMPkluMatrix->KLUmatrixAxComplex [2 * i] = 0 ; + delta_Y->SMPkluMatrix->KLUmatrixAxComplex [2 * i + 1] = 0 ; } } #endif @@ -529,7 +474,7 @@ int sens_sens(CKTcircuit *ckt, int restart) if (DEVices [sg->dev]->DEVbindCSCComplex) DEVices [sg->dev]->DEVbindCSCComplex (sg->model, ckt) ; - ckt->CKTmatrix->CKTkluMatrixIsComplex = CKTkluMatrixComplex ; + delta_Y->SMPkluMatrix->KLUmatrixIsComplex = KLUMatrixComplex ; } } #endif diff --git a/src/spicelib/analysis/cktsetup.c b/src/spicelib/analysis/cktsetup.c index 8997de36f..76470de0d 100644 --- a/src/spicelib/analysis/cktsetup.c +++ b/src/spicelib/analysis/cktsetup.c @@ -31,21 +31,6 @@ int nthreads; return(E_NOMEM);\ } -#ifdef KLU -#include - -static -int -BindCompare (const void *a, const void *b) -{ - BindElement *A, *B ; - A = (BindElement *)a ; - B = (BindElement *)b ; - - return ((int)(A->Sparse - B->Sparse)) ; -} -#endif - int CKTsetup(CKTcircuit *ckt) { @@ -123,6 +108,23 @@ CKTsetup(CKTcircuit *ckt) } } +#ifdef KLU + if (ckt->CKTmatrix->CKTkluMODE) + { + fprintf (stderr, "Using KLU as Direct Linear Solver\n") ; + + /* Convert the COO Storage to CSC for KLU and Fill the Binding Table */ + SMPconvertCOOtoCSC (matrix) ; + + /* Assign the KLU Pointers */ + for (i = 0 ; i < DEVmaxnum ; i++) + if (DEVices [i] && DEVices [i]->DEVbindCSC && ckt->CKThead [i]) + DEVices [i]->DEVbindCSC (ckt->CKThead [i], ckt) ; + } else { + fprintf (stderr, "Using SPARSE 1.3 as Direct Linear Solver\n") ; + } +#endif + for(i=0;i<=MAX(2,ckt->CKTmaxOrder)+1;i++) { /* dctran needs 3 states as minimum */ CKALLOC(ckt->CKTstates[i],ckt->CKTnumStates,double); } @@ -171,48 +173,6 @@ CKTsetup(CKTcircuit *ckt) /* gtri - end - Setup for adding rshunt option resistors */ #endif -#ifdef KLU - if (ckt->CKTmatrix->CKTkluMODE) - { - fprintf (stderr, "Using KLU as Direct Linear Solver\n") ; - - int i ; - int n = SMPmatSize (ckt->CKTmatrix) ; - ckt->CKTmatrix->CKTkluN = n ; - - SMPnnz (ckt->CKTmatrix) ; - int nz = ckt->CKTmatrix->CKTklunz ; - - ckt->CKTmatrix->CKTkluAp = TMALLOC (int, n + 1) ; - ckt->CKTmatrix->CKTkluAi = TMALLOC (int, nz) ; - ckt->CKTmatrix->CKTkluAx = TMALLOC (double, nz) ; - ckt->CKTmatrix->CKTkluIntermediate = TMALLOC (double, n) ; - - ckt->CKTmatrix->CKTbindStruct = TMALLOC (BindElement, nz) ; - - ckt->CKTmatrix->CKTdiag_CSC = TMALLOC (double *, n) ; - - /* Complex Stuff needed for AC Analysis */ - ckt->CKTmatrix->CKTkluAx_Complex = TMALLOC (double, 2 * nz) ; - ckt->CKTmatrix->CKTkluIntermediate_Complex = TMALLOC (double, 2 * n) ; - - /* Binding Table from Sparse to CSC Format Creation */ - SMPmatrix_CSC (ckt->CKTmatrix) ; - - /* Binding Table Sorting */ - qsort (ckt->CKTmatrix->CKTbindStruct, (size_t)nz, sizeof(BindElement), BindCompare) ; - - /* KLU Pointers Assignment */ - for (i = 0 ; i < DEVmaxnum ; i++) - if (DEVices [i] && DEVices [i]->DEVbindCSC && ckt->CKThead [i]) - DEVices [i]->DEVbindCSC (ckt->CKThead [i], ckt) ; - - ckt->CKTmatrix->CKTkluMatrixIsComplex = CKTkluMatrixReal ; - } else { - fprintf (stderr, "Using SPARSE 1.3 as Direct Linear Solver\n") ; - } -#endif - return(OK); } diff --git a/src/spicelib/devices/adms/admst/ngspiceMODULEbindCSC.c.xml b/src/spicelib/devices/adms/admst/ngspiceMODULEbindCSC.c.xml index 7f42ba556..395060b50 100644 --- a/src/spicelib/devices/adms/admst/ngspiceMODULEbindCSC.c.xml +++ b/src/spicelib/devices/adms/admst/ngspiceMODULEbindCSC.c.xml @@ -51,30 +51,16 @@ Author: 2020 Francesco Lannutti #include "ngspice/sperror.h" #include "ngspice/klu-binding.h" -#include <stdlib.h> - -static -int -BindCompare (const void *a, const void *b) -{ - BindElement *A, *B ; - A = (BindElement *)a ; - B = (BindElement *)b ; - - return ((int)(A->Sparse - B->Sparse)) ; -} - int $(module)bindCSC (GENmodel *inModel, CKTcircuit *ckt) { $(module)model *model = ($(module)model *)inModel ; $(module)instance *here ; - double *i ; - BindElement *matched, *BindStruct ; + BindElement i, *matched, *BindStruct ; size_t nz ; - BindStruct = ckt->CKTmatrix->CKTbindStruct ; - nz = (size_t)ckt->CKTmatrix->CKTklunz ; + BindStruct = ckt->CKTmatrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + nz = (size_t)ckt->CKTmatrix->SMPkluMatrix->KLUmatrixLinkedListNZ ; /* loop through all the $(module) models */ for ( ; model != NULL ; model = $(module)nextModel(model)) diff --git a/src/spicelib/devices/asrc/asrcbindCSC.c b/src/spicelib/devices/asrc/asrcbindCSC.c index 5b5165e33..72ddec7a8 100644 --- a/src/spicelib/devices/asrc/asrcbindCSC.c +++ b/src/spicelib/devices/asrc/asrcbindCSC.c @@ -8,31 +8,17 @@ Author: 2015 Francesco Lannutti #include "ngspice/sperror.h" #include "ngspice/klu-binding.h" -#include - -static -int -BindCompare (const void *a, const void *b) -{ - BindElement *A, *B ; - A = (BindElement *)a ; - B = (BindElement *)b ; - - return ((int)(A->Sparse - B->Sparse)) ; -} - int ASRCbindCSC (GENmodel *inModel, CKTcircuit *ckt) { ASRCmodel *model = (ASRCmodel *)inModel ; ASRCinstance *here ; - double *i ; - BindElement *matched, *BindStruct ; + BindElement i, *matched, *BindStruct ; size_t nz ; int j, k ; - BindStruct = ckt->CKTmatrix->CKTbindStruct ; - nz = (size_t)ckt->CKTmatrix->CKTklunz ; + BindStruct = ckt->CKTmatrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + nz = (size_t)ckt->CKTmatrix->SMPkluMatrix->KLUmatrixLinkedListNZ ; /* loop through all the ASRC models */ for ( ; model != NULL ; model = ASRCnextModel(model)) diff --git a/src/spicelib/devices/bjt/bjtbindCSC.c b/src/spicelib/devices/bjt/bjtbindCSC.c index ef0ef3227..b5c58224b 100644 --- a/src/spicelib/devices/bjt/bjtbindCSC.c +++ b/src/spicelib/devices/bjt/bjtbindCSC.c @@ -8,30 +8,16 @@ Author: 2013 Francesco Lannutti #include "ngspice/sperror.h" #include "ngspice/klu-binding.h" -#include - -static -int -BindCompare (const void *a, const void *b) -{ - BindElement *A, *B ; - A = (BindElement *)a ; - B = (BindElement *)b ; - - return ((int)(A->Sparse - B->Sparse)) ; -} - int BJTbindCSC (GENmodel *inModel, CKTcircuit *ckt) { BJTmodel *model = (BJTmodel *)inModel ; BJTinstance *here ; - double *i ; - BindElement *matched, *BindStruct ; + BindElement i, *matched, *BindStruct ; size_t nz ; - BindStruct = ckt->CKTmatrix->CKTbindStruct ; - nz = (size_t)ckt->CKTmatrix->CKTklunz ; + BindStruct = ckt->CKTmatrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + nz = (size_t)ckt->CKTmatrix->SMPkluMatrix->KLUmatrixLinkedListNZ ; /* loop through all the BJT models */ for ( ; model != NULL ; model = BJTnextModel(model)) diff --git a/src/spicelib/devices/bsim1/b1bindCSC.c b/src/spicelib/devices/bsim1/b1bindCSC.c index 666cc032d..23bcc76c2 100644 --- a/src/spicelib/devices/bsim1/b1bindCSC.c +++ b/src/spicelib/devices/bsim1/b1bindCSC.c @@ -8,30 +8,16 @@ Author: 2013 Francesco Lannutti #include "ngspice/sperror.h" #include "ngspice/klu-binding.h" -#include - -static -int -BindCompare (const void *a, const void *b) -{ - BindElement *A, *B ; - A = (BindElement *)a ; - B = (BindElement *)b ; - - return ((int)(A->Sparse - B->Sparse)) ; -} - int B1bindCSC (GENmodel *inModel, CKTcircuit *ckt) { B1model *model = (B1model *)inModel ; B1instance *here ; - double *i ; - BindElement *matched, *BindStruct ; + BindElement i, *matched, *BindStruct ; size_t nz ; - BindStruct = ckt->CKTmatrix->CKTbindStruct ; - nz = (size_t)ckt->CKTmatrix->CKTklunz ; + BindStruct = ckt->CKTmatrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + nz = (size_t)ckt->CKTmatrix->SMPkluMatrix->KLUmatrixLinkedListNZ ; /* loop through all the B1 models */ for ( ; model != NULL ; model = B1nextModel(model)) diff --git a/src/spicelib/devices/bsim2/b2bindCSC.c b/src/spicelib/devices/bsim2/b2bindCSC.c index 7f2da6749..32847a2f9 100644 --- a/src/spicelib/devices/bsim2/b2bindCSC.c +++ b/src/spicelib/devices/bsim2/b2bindCSC.c @@ -8,30 +8,16 @@ Author: 2013 Francesco Lannutti #include "ngspice/sperror.h" #include "ngspice/klu-binding.h" -#include - -static -int -BindCompare (const void *a, const void *b) -{ - BindElement *A, *B ; - A = (BindElement *)a ; - B = (BindElement *)b ; - - return ((int)(A->Sparse - B->Sparse)) ; -} - int B2bindCSC (GENmodel *inModel, CKTcircuit *ckt) { B2model *model = (B2model *)inModel ; B2instance *here ; - double *i ; - BindElement *matched, *BindStruct ; + BindElement i, *matched, *BindStruct ; size_t nz ; - BindStruct = ckt->CKTmatrix->CKTbindStruct ; - nz = (size_t)ckt->CKTmatrix->CKTklunz ; + BindStruct = ckt->CKTmatrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + nz = (size_t)ckt->CKTmatrix->SMPkluMatrix->KLUmatrixLinkedListNZ ; /* loop through all the B2 models */ for ( ; model != NULL ; model = B2nextModel(model)) diff --git a/src/spicelib/devices/bsim3/b3bindCSC.c b/src/spicelib/devices/bsim3/b3bindCSC.c index 8807b6328..ec2c1d5a2 100644 --- a/src/spicelib/devices/bsim3/b3bindCSC.c +++ b/src/spicelib/devices/bsim3/b3bindCSC.c @@ -8,30 +8,16 @@ Author: 2013 Francesco Lannutti #include "ngspice/sperror.h" #include "ngspice/klu-binding.h" -#include - -static -int -BindCompare (const void *a, const void *b) -{ - BindElement *A, *B ; - A = (BindElement *)a ; - B = (BindElement *)b ; - - return ((int)(A->Sparse - B->Sparse)) ; -} - int BSIM3bindCSC (GENmodel *inModel, CKTcircuit *ckt) { BSIM3model *model = (BSIM3model *)inModel ; BSIM3instance *here ; - double *i ; - BindElement *matched, *BindStruct ; + BindElement i, *matched, *BindStruct ; size_t nz ; - BindStruct = ckt->CKTmatrix->CKTbindStruct ; - nz = (size_t)ckt->CKTmatrix->CKTklunz ; + BindStruct = ckt->CKTmatrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + nz = (size_t)ckt->CKTmatrix->SMPkluMatrix->KLUmatrixLinkedListNZ ; /* loop through all the BSIM3 models */ for ( ; model != NULL ; model = BSIM3nextModel(model)) diff --git a/src/spicelib/devices/bsim3soi_dd/b3soiddbindCSC.c b/src/spicelib/devices/bsim3soi_dd/b3soiddbindCSC.c index a8adf8d67..e2acc8f47 100644 --- a/src/spicelib/devices/bsim3soi_dd/b3soiddbindCSC.c +++ b/src/spicelib/devices/bsim3soi_dd/b3soiddbindCSC.c @@ -8,30 +8,16 @@ Author: 2013 Francesco Lannutti #include "ngspice/sperror.h" #include "ngspice/klu-binding.h" -#include - -static -int -BindCompare (const void *a, const void *b) -{ - BindElement *A, *B ; - A = (BindElement *)a ; - B = (BindElement *)b ; - - return ((int)(A->Sparse - B->Sparse)) ; -} - int B3SOIDDbindCSC (GENmodel *inModel, CKTcircuit *ckt) { B3SOIDDmodel *model = (B3SOIDDmodel *)inModel ; B3SOIDDinstance *here ; - double *i ; - BindElement *matched, *BindStruct ; + BindElement i, *matched, *BindStruct ; size_t nz ; - BindStruct = ckt->CKTmatrix->CKTbindStruct ; - nz = (size_t)ckt->CKTmatrix->CKTklunz ; + BindStruct = ckt->CKTmatrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + nz = (size_t)ckt->CKTmatrix->SMPkluMatrix->KLUmatrixLinkedListNZ ; /* loop through all the B3SOIDD models */ for ( ; model != NULL ; model = B3SOIDDnextModel(model)) diff --git a/src/spicelib/devices/bsim3soi_fd/b3soifdbindCSC.c b/src/spicelib/devices/bsim3soi_fd/b3soifdbindCSC.c index 28924c8cb..b4bd0c925 100644 --- a/src/spicelib/devices/bsim3soi_fd/b3soifdbindCSC.c +++ b/src/spicelib/devices/bsim3soi_fd/b3soifdbindCSC.c @@ -8,30 +8,16 @@ Author: 2013 Francesco Lannutti #include "ngspice/sperror.h" #include "ngspice/klu-binding.h" -#include - -static -int -BindCompare (const void *a, const void *b) -{ - BindElement *A, *B ; - A = (BindElement *)a ; - B = (BindElement *)b ; - - return ((int)(A->Sparse - B->Sparse)) ; -} - int B3SOIFDbindCSC (GENmodel *inModel, CKTcircuit *ckt) { B3SOIFDmodel *model = (B3SOIFDmodel *)inModel ; B3SOIFDinstance *here ; - double *i ; - BindElement *matched, *BindStruct ; + BindElement i, *matched, *BindStruct ; size_t nz ; - BindStruct = ckt->CKTmatrix->CKTbindStruct ; - nz = (size_t)ckt->CKTmatrix->CKTklunz ; + BindStruct = ckt->CKTmatrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + nz = (size_t)ckt->CKTmatrix->SMPkluMatrix->KLUmatrixLinkedListNZ ; /* loop through all the B3SOIFD models */ for ( ; model != NULL ; model = B3SOIFDnextModel(model)) diff --git a/src/spicelib/devices/bsim3soi_pd/b3soipdbindCSC.c b/src/spicelib/devices/bsim3soi_pd/b3soipdbindCSC.c index d70337918..3b288ac96 100644 --- a/src/spicelib/devices/bsim3soi_pd/b3soipdbindCSC.c +++ b/src/spicelib/devices/bsim3soi_pd/b3soipdbindCSC.c @@ -8,30 +8,16 @@ Author: 2013 Francesco Lannutti #include "ngspice/sperror.h" #include "ngspice/klu-binding.h" -#include - -static -int -BindCompare (const void *a, const void *b) -{ - BindElement *A, *B ; - A = (BindElement *)a ; - B = (BindElement *)b ; - - return ((int)(A->Sparse - B->Sparse)) ; -} - int B3SOIPDbindCSC (GENmodel *inModel, CKTcircuit *ckt) { B3SOIPDmodel *model = (B3SOIPDmodel *)inModel ; B3SOIPDinstance *here ; - double *i ; - BindElement *matched, *BindStruct ; + BindElement i, *matched, *BindStruct ; size_t nz ; - BindStruct = ckt->CKTmatrix->CKTbindStruct ; - nz = (size_t)ckt->CKTmatrix->CKTklunz ; + BindStruct = ckt->CKTmatrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + nz = (size_t)ckt->CKTmatrix->SMPkluMatrix->KLUmatrixLinkedListNZ ; /* loop through all the B3SOIPD models */ for ( ; model != NULL ; model = B3SOIPDnextModel(model)) diff --git a/src/spicelib/devices/bsim3v0/b3v0bindCSC.c b/src/spicelib/devices/bsim3v0/b3v0bindCSC.c index 179aa4025..1c3016bcf 100644 --- a/src/spicelib/devices/bsim3v0/b3v0bindCSC.c +++ b/src/spicelib/devices/bsim3v0/b3v0bindCSC.c @@ -8,30 +8,16 @@ Author: 2013 Francesco Lannutti #include "ngspice/sperror.h" #include "ngspice/klu-binding.h" -#include - -static -int -BindCompare (const void *a, const void *b) -{ - BindElement *A, *B ; - A = (BindElement *)a ; - B = (BindElement *)b ; - - return ((int)(A->Sparse - B->Sparse)) ; -} - int BSIM3v0bindCSC (GENmodel *inModel, CKTcircuit *ckt) { BSIM3v0model *model = (BSIM3v0model *)inModel ; BSIM3v0instance *here ; - double *i ; - BindElement *matched, *BindStruct ; + BindElement i, *matched, *BindStruct ; size_t nz ; - BindStruct = ckt->CKTmatrix->CKTbindStruct ; - nz = (size_t)ckt->CKTmatrix->CKTklunz ; + BindStruct = ckt->CKTmatrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + nz = (size_t)ckt->CKTmatrix->SMPkluMatrix->KLUmatrixLinkedListNZ ; /* loop through all the BSIM3v0 models */ for ( ; model != NULL ; model = BSIM3v0nextModel(model)) diff --git a/src/spicelib/devices/bsim3v1/b3v1bindCSC.c b/src/spicelib/devices/bsim3v1/b3v1bindCSC.c index 5e72f2bfa..ff7ffc00c 100644 --- a/src/spicelib/devices/bsim3v1/b3v1bindCSC.c +++ b/src/spicelib/devices/bsim3v1/b3v1bindCSC.c @@ -8,30 +8,16 @@ Author: 2013 Francesco Lannutti #include "ngspice/sperror.h" #include "ngspice/klu-binding.h" -#include - -static -int -BindCompare (const void *a, const void *b) -{ - BindElement *A, *B ; - A = (BindElement *)a ; - B = (BindElement *)b ; - - return ((int)(A->Sparse - B->Sparse)) ; -} - int BSIM3v1bindCSC (GENmodel *inModel, CKTcircuit *ckt) { BSIM3v1model *model = (BSIM3v1model *)inModel ; BSIM3v1instance *here ; - double *i ; - BindElement *matched, *BindStruct ; + BindElement i, *matched, *BindStruct ; size_t nz ; - BindStruct = ckt->CKTmatrix->CKTbindStruct ; - nz = (size_t)ckt->CKTmatrix->CKTklunz ; + BindStruct = ckt->CKTmatrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + nz = (size_t)ckt->CKTmatrix->SMPkluMatrix->KLUmatrixLinkedListNZ ; /* loop through all the BSIM3v1 models */ for ( ; model != NULL ; model = BSIM3v1nextModel(model)) diff --git a/src/spicelib/devices/bsim3v32/b3v32bindCSC.c b/src/spicelib/devices/bsim3v32/b3v32bindCSC.c index b958d0e68..ef368e6e5 100644 --- a/src/spicelib/devices/bsim3v32/b3v32bindCSC.c +++ b/src/spicelib/devices/bsim3v32/b3v32bindCSC.c @@ -8,30 +8,16 @@ Author: 2013 Francesco Lannutti #include "ngspice/sperror.h" #include "ngspice/klu-binding.h" -#include - -static -int -BindCompare (const void *a, const void *b) -{ - BindElement *A, *B ; - A = (BindElement *)a ; - B = (BindElement *)b ; - - return ((int)(A->Sparse - B->Sparse)) ; -} - int BSIM3v32bindCSC (GENmodel *inModel, CKTcircuit *ckt) { BSIM3v32model *model = (BSIM3v32model *)inModel ; BSIM3v32instance *here ; - double *i ; - BindElement *matched, *BindStruct ; + BindElement i, *matched, *BindStruct ; size_t nz ; - BindStruct = ckt->CKTmatrix->CKTbindStruct ; - nz = (size_t)ckt->CKTmatrix->CKTklunz ; + BindStruct = ckt->CKTmatrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + nz = (size_t)ckt->CKTmatrix->SMPkluMatrix->KLUmatrixLinkedListNZ ; /* loop through all the BSIM3v32 models */ for ( ; model != NULL ; model = BSIM3v32nextModel(model)) diff --git a/src/spicelib/devices/bsim4/b4bindCSC.c b/src/spicelib/devices/bsim4/b4bindCSC.c index 16c1f21e3..74a18d18c 100644 --- a/src/spicelib/devices/bsim4/b4bindCSC.c +++ b/src/spicelib/devices/bsim4/b4bindCSC.c @@ -8,30 +8,16 @@ Author: 2013 Francesco Lannutti #include "ngspice/sperror.h" #include "ngspice/klu-binding.h" -#include - -static -int -BindCompare (const void *a, const void *b) -{ - BindElement *A, *B ; - A = (BindElement *)a ; - B = (BindElement *)b ; - - return ((int)(A->Sparse - B->Sparse)) ; -} - int BSIM4bindCSC (GENmodel *inModel, CKTcircuit *ckt) { BSIM4model *model = (BSIM4model *)inModel ; BSIM4instance *here ; - double *i ; - BindElement *matched, *BindStruct ; + BindElement i, *matched, *BindStruct ; size_t nz ; - BindStruct = ckt->CKTmatrix->CKTbindStruct ; - nz = (size_t)ckt->CKTmatrix->CKTklunz ; + BindStruct = ckt->CKTmatrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + nz = (size_t)ckt->CKTmatrix->SMPkluMatrix->KLUmatrixLinkedListNZ ; /* loop through all the BSIM4 models */ for ( ; model != NULL ; model = BSIM4nextModel(model)) diff --git a/src/spicelib/devices/bsim4v5/b4v5bindCSC.c b/src/spicelib/devices/bsim4v5/b4v5bindCSC.c index 806e9bf7a..4fd009700 100644 --- a/src/spicelib/devices/bsim4v5/b4v5bindCSC.c +++ b/src/spicelib/devices/bsim4v5/b4v5bindCSC.c @@ -8,30 +8,16 @@ Author: 2013 Francesco Lannutti #include "ngspice/sperror.h" #include "ngspice/klu-binding.h" -#include - -static -int -BindCompare (const void *a, const void *b) -{ - BindElement *A, *B ; - A = (BindElement *)a ; - B = (BindElement *)b ; - - return ((int)(A->Sparse - B->Sparse)) ; -} - int BSIM4v5bindCSC (GENmodel *inModel, CKTcircuit *ckt) { BSIM4v5model *model = (BSIM4v5model *)inModel ; BSIM4v5instance *here ; - double *i ; - BindElement *matched, *BindStruct ; + BindElement i, *matched, *BindStruct ; size_t nz ; - BindStruct = ckt->CKTmatrix->CKTbindStruct ; - nz = (size_t)ckt->CKTmatrix->CKTklunz ; + BindStruct = ckt->CKTmatrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + nz = (size_t)ckt->CKTmatrix->SMPkluMatrix->KLUmatrixLinkedListNZ ; /* loop through all the BSIM4v5 models */ for ( ; model != NULL ; model = BSIM4v5nextModel(model)) diff --git a/src/spicelib/devices/bsim4v6/b4v6bindCSC.c b/src/spicelib/devices/bsim4v6/b4v6bindCSC.c index b4ab1535e..04b5380d5 100644 --- a/src/spicelib/devices/bsim4v6/b4v6bindCSC.c +++ b/src/spicelib/devices/bsim4v6/b4v6bindCSC.c @@ -8,30 +8,16 @@ Author: 2013 Francesco Lannutti #include "ngspice/sperror.h" #include "ngspice/klu-binding.h" -#include - -static -int -BindCompare (const void *a, const void *b) -{ - BindElement *A, *B ; - A = (BindElement *)a ; - B = (BindElement *)b ; - - return ((int)(A->Sparse - B->Sparse)) ; -} - int BSIM4v6bindCSC (GENmodel *inModel, CKTcircuit *ckt) { BSIM4v6model *model = (BSIM4v6model *)inModel ; BSIM4v6instance *here ; - double *i ; - BindElement *matched, *BindStruct ; + BindElement i, *matched, *BindStruct ; size_t nz ; - BindStruct = ckt->CKTmatrix->CKTbindStruct ; - nz = (size_t)ckt->CKTmatrix->CKTklunz ; + BindStruct = ckt->CKTmatrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + nz = (size_t)ckt->CKTmatrix->SMPkluMatrix->KLUmatrixLinkedListNZ ; /* loop through all the BSIM4v6 models */ for ( ; model != NULL ; model = BSIM4v6nextModel(model)) diff --git a/src/spicelib/devices/bsim4v7/b4v7bindCSC.c b/src/spicelib/devices/bsim4v7/b4v7bindCSC.c index ccf935d5c..d23daecd1 100644 --- a/src/spicelib/devices/bsim4v7/b4v7bindCSC.c +++ b/src/spicelib/devices/bsim4v7/b4v7bindCSC.c @@ -8,30 +8,16 @@ Author: 2013 Francesco Lannutti #include "ngspice/sperror.h" #include "ngspice/klu-binding.h" -#include - -static -int -BindCompare (const void *a, const void *b) -{ - BindElement *A, *B ; - A = (BindElement *)a ; - B = (BindElement *)b ; - - return ((int)(A->Sparse - B->Sparse)) ; -} - int BSIM4v7bindCSC (GENmodel *inModel, CKTcircuit *ckt) { BSIM4v7model *model = (BSIM4v7model *)inModel ; BSIM4v7instance *here ; - double *i ; - BindElement *matched, *BindStruct ; + BindElement i, *matched, *BindStruct ; size_t nz ; - BindStruct = ckt->CKTmatrix->CKTbindStruct ; - nz = (size_t)ckt->CKTmatrix->CKTklunz ; + BindStruct = ckt->CKTmatrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + nz = (size_t)ckt->CKTmatrix->SMPkluMatrix->KLUmatrixLinkedListNZ ; /* loop through all the BSIM4v7 models */ for ( ; model != NULL ; model = BSIM4v7nextModel(model)) diff --git a/src/spicelib/devices/bsimsoi/b4soibindCSC.c b/src/spicelib/devices/bsimsoi/b4soibindCSC.c index cf4854bb6..4369bad7f 100644 --- a/src/spicelib/devices/bsimsoi/b4soibindCSC.c +++ b/src/spicelib/devices/bsimsoi/b4soibindCSC.c @@ -8,30 +8,16 @@ Author: 2013 Francesco Lannutti #include "ngspice/sperror.h" #include "ngspice/klu-binding.h" -#include - -static -int -BindCompare (const void *a, const void *b) -{ - BindElement *A, *B ; - A = (BindElement *)a ; - B = (BindElement *)b ; - - return ((int)(A->Sparse - B->Sparse)) ; -} - int B4SOIbindCSC (GENmodel *inModel, CKTcircuit *ckt) { B4SOImodel *model = (B4SOImodel *)inModel ; B4SOIinstance *here ; - double *i ; - BindElement *matched, *BindStruct ; + BindElement i, *matched, *BindStruct ; size_t nz ; - BindStruct = ckt->CKTmatrix->CKTbindStruct ; - nz = (size_t)ckt->CKTmatrix->CKTklunz ; + BindStruct = ckt->CKTmatrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + nz = (size_t)ckt->CKTmatrix->SMPkluMatrix->KLUmatrixLinkedListNZ ; /* loop through all the B4SOI models */ for ( ; model != NULL ; model = B4SOInextModel(model)) diff --git a/src/spicelib/devices/cap/capbindCSC.c b/src/spicelib/devices/cap/capbindCSC.c index 77a37f7fc..095add9fe 100644 --- a/src/spicelib/devices/cap/capbindCSC.c +++ b/src/spicelib/devices/cap/capbindCSC.c @@ -8,30 +8,16 @@ Author: 2013 Francesco Lannutti #include "ngspice/sperror.h" #include "ngspice/klu-binding.h" -#include - -static -int -BindCompare (const void *a, const void *b) -{ - BindElement *A, *B ; - A = (BindElement *)a ; - B = (BindElement *)b ; - - return ((int)(A->Sparse - B->Sparse)) ; -} - int CAPbindCSC (GENmodel *inModel, CKTcircuit *ckt) { CAPmodel *model = (CAPmodel *)inModel ; CAPinstance *here ; - double *i ; - BindElement *matched, *BindStruct ; + BindElement i, *matched, *BindStruct ; size_t nz ; - BindStruct = ckt->CKTmatrix->CKTbindStruct ; - nz = (size_t)ckt->CKTmatrix->CKTklunz ; + BindStruct = ckt->CKTmatrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + nz = (size_t)ckt->CKTmatrix->SMPkluMatrix->KLUmatrixLinkedListNZ ; /* loop through all the CAP models */ for ( ; model != NULL ; model = CAPnextModel(model)) diff --git a/src/spicelib/devices/cccs/cccsbindCSC.c b/src/spicelib/devices/cccs/cccsbindCSC.c index e706a4d73..af887bb1e 100644 --- a/src/spicelib/devices/cccs/cccsbindCSC.c +++ b/src/spicelib/devices/cccs/cccsbindCSC.c @@ -8,30 +8,16 @@ Author: 2013 Francesco Lannutti #include "ngspice/sperror.h" #include "ngspice/klu-binding.h" -#include - -static -int -BindCompare (const void *a, const void *b) -{ - BindElement *A, *B ; - A = (BindElement *)a ; - B = (BindElement *)b ; - - return ((int)(A->Sparse - B->Sparse)) ; -} - int CCCSbindCSC (GENmodel *inModel, CKTcircuit *ckt) { CCCSmodel *model = (CCCSmodel *)inModel ; CCCSinstance *here ; - double *i ; - BindElement *matched, *BindStruct ; + BindElement i, *matched, *BindStruct ; size_t nz ; - BindStruct = ckt->CKTmatrix->CKTbindStruct ; - nz = (size_t)ckt->CKTmatrix->CKTklunz ; + BindStruct = ckt->CKTmatrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + nz = (size_t)ckt->CKTmatrix->SMPkluMatrix->KLUmatrixLinkedListNZ ; /* loop through all the CCCS models */ for ( ; model != NULL ; model = CCCSnextModel(model)) diff --git a/src/spicelib/devices/ccvs/ccvsbindCSC.c b/src/spicelib/devices/ccvs/ccvsbindCSC.c index 2e737c1ba..63986f336 100644 --- a/src/spicelib/devices/ccvs/ccvsbindCSC.c +++ b/src/spicelib/devices/ccvs/ccvsbindCSC.c @@ -8,30 +8,16 @@ Author: 2013 Francesco Lannutti #include "ngspice/sperror.h" #include "ngspice/klu-binding.h" -#include - -static -int -BindCompare (const void *a, const void *b) -{ - BindElement *A, *B ; - A = (BindElement *)a ; - B = (BindElement *)b ; - - return ((int)(A->Sparse - B->Sparse)) ; -} - int CCVSbindCSC (GENmodel *inModel, CKTcircuit *ckt) { CCVSmodel *model = (CCVSmodel *)inModel ; CCVSinstance *here ; - double *i ; - BindElement *matched, *BindStruct ; + BindElement i, *matched, *BindStruct ; size_t nz ; - BindStruct = ckt->CKTmatrix->CKTbindStruct ; - nz = (size_t)ckt->CKTmatrix->CKTklunz ; + BindStruct = ckt->CKTmatrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + nz = (size_t)ckt->CKTmatrix->SMPkluMatrix->KLUmatrixLinkedListNZ ; /* loop through all the CCVS models */ for ( ; model != NULL ; model = CCVSnextModel(model)) diff --git a/src/spicelib/devices/cpl/cplbindCSC.c b/src/spicelib/devices/cpl/cplbindCSC.c index 87896bef2..4aeb205b7 100644 --- a/src/spicelib/devices/cpl/cplbindCSC.c +++ b/src/spicelib/devices/cpl/cplbindCSC.c @@ -8,32 +8,17 @@ Author: 2013 Francesco Lannutti #include "ngspice/sperror.h" #include "ngspice/klu-binding.h" -#include - - -static -int -BindCompare (const void *a, const void *b) -{ - BindElement *A, *B ; - A = (BindElement *)a ; - B = (BindElement *)b ; - - return ((int)(A->Sparse - B->Sparse)) ; -} - int CPLbindCSC (GENmodel *inModel, CKTcircuit *ckt) { CPLmodel *model = (CPLmodel *)inModel ; CPLinstance *here ; - double *i ; - BindElement *matched, *BindStruct ; + BindElement i, *matched, *BindStruct ; size_t nz ; int m, p ; - BindStruct = ckt->CKTmatrix->CKTbindStruct ; - nz = (size_t)ckt->CKTmatrix->CKTklunz ; + BindStruct = ckt->CKTmatrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + nz = (size_t)ckt->CKTmatrix->SMPkluMatrix->KLUmatrixLinkedListNZ ; /* loop through all the CPL models */ for ( ; model != NULL ; model = CPLnextModel(model)) diff --git a/src/spicelib/devices/csw/cswbindCSC.c b/src/spicelib/devices/csw/cswbindCSC.c index 7df35ae53..2f63f3baa 100644 --- a/src/spicelib/devices/csw/cswbindCSC.c +++ b/src/spicelib/devices/csw/cswbindCSC.c @@ -8,30 +8,16 @@ Author: 2013 Francesco Lannutti #include "ngspice/sperror.h" #include "ngspice/klu-binding.h" -#include - -static -int -BindCompare (const void *a, const void *b) -{ - BindElement *A, *B ; - A = (BindElement *)a ; - B = (BindElement *)b ; - - return ((int)(A->Sparse - B->Sparse)) ; -} - int CSWbindCSC (GENmodel *inModel, CKTcircuit *ckt) { CSWmodel *model = (CSWmodel *)inModel ; CSWinstance *here ; - double *i ; - BindElement *matched, *BindStruct ; + BindElement i, *matched, *BindStruct ; size_t nz ; - BindStruct = ckt->CKTmatrix->CKTbindStruct ; - nz = (size_t)ckt->CKTmatrix->CKTklunz ; + BindStruct = ckt->CKTmatrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + nz = (size_t)ckt->CKTmatrix->SMPkluMatrix->KLUmatrixLinkedListNZ ; /* loop through all the CSW models */ for ( ; model != NULL ; model = CSWnextModel(model)) diff --git a/src/spicelib/devices/dio/diobindCSC.c b/src/spicelib/devices/dio/diobindCSC.c index 28aba6450..1a476fd90 100644 --- a/src/spicelib/devices/dio/diobindCSC.c +++ b/src/spicelib/devices/dio/diobindCSC.c @@ -8,30 +8,16 @@ Author: 2013 Francesco Lannutti #include "ngspice/sperror.h" #include "ngspice/klu-binding.h" -#include - -static -int -BindCompare (const void *a, const void *b) -{ - BindElement *A, *B ; - A = (BindElement *)a ; - B = (BindElement *)b ; - - return ((int)(A->Sparse - B->Sparse)) ; -} - int DIObindCSC (GENmodel *inModel, CKTcircuit *ckt) { DIOmodel *model = (DIOmodel *)inModel ; DIOinstance *here ; - double *i ; - BindElement *matched, *BindStruct ; + BindElement i, *matched, *BindStruct ; size_t nz ; - BindStruct = ckt->CKTmatrix->CKTbindStruct ; - nz = (size_t)ckt->CKTmatrix->CKTklunz ; + BindStruct = ckt->CKTmatrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + nz = (size_t)ckt->CKTmatrix->SMPkluMatrix->KLUmatrixLinkedListNZ ; /* loop through all the DIO models */ for ( ; model != NULL ; model = DIOnextModel(model)) diff --git a/src/spicelib/devices/hfet1/hfetbindCSC.c b/src/spicelib/devices/hfet1/hfetbindCSC.c index 06f7df87d..5a4b9b69a 100644 --- a/src/spicelib/devices/hfet1/hfetbindCSC.c +++ b/src/spicelib/devices/hfet1/hfetbindCSC.c @@ -8,30 +8,16 @@ Author: 2013 Francesco Lannutti #include "ngspice/sperror.h" #include "ngspice/klu-binding.h" -#include - -static -int -BindCompare (const void *a, const void *b) -{ - BindElement *A, *B ; - A = (BindElement *)a ; - B = (BindElement *)b ; - - return ((int)(A->Sparse - B->Sparse)) ; -} - int HFETAbindCSC (GENmodel *inModel, CKTcircuit *ckt) { HFETAmodel *model = (HFETAmodel *)inModel ; HFETAinstance *here ; - double *i ; - BindElement *matched, *BindStruct ; + BindElement i, *matched, *BindStruct ; size_t nz ; - BindStruct = ckt->CKTmatrix->CKTbindStruct ; - nz = (size_t)ckt->CKTmatrix->CKTklunz ; + BindStruct = ckt->CKTmatrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + nz = (size_t)ckt->CKTmatrix->SMPkluMatrix->KLUmatrixLinkedListNZ ; /* loop through all the HFETA models */ for ( ; model != NULL ; model = HFETAnextModel(model)) diff --git a/src/spicelib/devices/hfet2/hfet2bindCSC.c b/src/spicelib/devices/hfet2/hfet2bindCSC.c index 37ab4836d..0969b9508 100644 --- a/src/spicelib/devices/hfet2/hfet2bindCSC.c +++ b/src/spicelib/devices/hfet2/hfet2bindCSC.c @@ -8,30 +8,16 @@ Author: 2013 Francesco Lannutti #include "ngspice/sperror.h" #include "ngspice/klu-binding.h" -#include - -static -int -BindCompare (const void *a, const void *b) -{ - BindElement *A, *B ; - A = (BindElement *)a ; - B = (BindElement *)b ; - - return ((int)(A->Sparse - B->Sparse)) ; -} - int HFET2bindCSC (GENmodel *inModel, CKTcircuit *ckt) { HFET2model *model = (HFET2model *)inModel ; HFET2instance *here ; - double *i ; - BindElement *matched, *BindStruct ; + BindElement i, *matched, *BindStruct ; size_t nz ; - BindStruct = ckt->CKTmatrix->CKTbindStruct ; - nz = (size_t)ckt->CKTmatrix->CKTklunz ; + BindStruct = ckt->CKTmatrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + nz = (size_t)ckt->CKTmatrix->SMPkluMatrix->KLUmatrixLinkedListNZ ; /* loop through all the HFET2 models */ for ( ; model != NULL ; model = HFET2nextModel(model)) diff --git a/src/spicelib/devices/hisim2/hsm2bindCSC.c b/src/spicelib/devices/hisim2/hsm2bindCSC.c index 28dcc10f7..20e658931 100644 --- a/src/spicelib/devices/hisim2/hsm2bindCSC.c +++ b/src/spicelib/devices/hisim2/hsm2bindCSC.c @@ -8,30 +8,16 @@ Author: 2013 Francesco Lannutti #include "ngspice/sperror.h" #include "ngspice/klu-binding.h" -#include - -static -int -BindCompare (const void *a, const void *b) -{ - BindElement *A, *B ; - A = (BindElement *)a ; - B = (BindElement *)b ; - - return ((int)(A->Sparse - B->Sparse)) ; -} - int HSM2bindCSC (GENmodel *inModel, CKTcircuit *ckt) { HSM2model *model = (HSM2model *)inModel ; HSM2instance *here ; - double *i ; - BindElement *matched, *BindStruct ; + BindElement i, *matched, *BindStruct ; size_t nz ; - BindStruct = ckt->CKTmatrix->CKTbindStruct ; - nz = (size_t)ckt->CKTmatrix->CKTklunz ; + BindStruct = ckt->CKTmatrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + nz = (size_t)ckt->CKTmatrix->SMPkluMatrix->KLUmatrixLinkedListNZ ; /* loop through all the HSM2 models */ for ( ; model != NULL ; model = HSM2nextModel(model)) diff --git a/src/spicelib/devices/hisimhv1/hsmhvbindCSC.c b/src/spicelib/devices/hisimhv1/hsmhvbindCSC.c index cc39dc1da..25528c33e 100644 --- a/src/spicelib/devices/hisimhv1/hsmhvbindCSC.c +++ b/src/spicelib/devices/hisimhv1/hsmhvbindCSC.c @@ -8,30 +8,16 @@ Author: 2013 Francesco Lannutti #include "ngspice/sperror.h" #include "ngspice/klu-binding.h" -#include - -static -int -BindCompare (const void *a, const void *b) -{ - BindElement *A, *B ; - A = (BindElement *)a ; - B = (BindElement *)b ; - - return ((int)(A->Sparse - B->Sparse)) ; -} - int HSMHVbindCSC (GENmodel *inModel, CKTcircuit *ckt) { HSMHVmodel *model = (HSMHVmodel *)inModel ; HSMHVinstance *here ; - double *i ; - BindElement *matched, *BindStruct ; + BindElement i, *matched, *BindStruct ; size_t nz ; - BindStruct = ckt->CKTmatrix->CKTbindStruct ; - nz = (size_t)ckt->CKTmatrix->CKTklunz ; + BindStruct = ckt->CKTmatrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + nz = (size_t)ckt->CKTmatrix->SMPkluMatrix->KLUmatrixLinkedListNZ ; /* loop through all the HSMHV models */ for ( ; model != NULL ; model = HSMHVnextModel(model)) diff --git a/src/spicelib/devices/hisimhv2/hsmhv2bindCSC.c b/src/spicelib/devices/hisimhv2/hsmhv2bindCSC.c index a7577cb88..e89d9e8aa 100644 --- a/src/spicelib/devices/hisimhv2/hsmhv2bindCSC.c +++ b/src/spicelib/devices/hisimhv2/hsmhv2bindCSC.c @@ -8,30 +8,16 @@ Author: 2016 Francesco Lannutti #include "ngspice/sperror.h" #include "ngspice/klu-binding.h" -#include - -static -int -BindCompare (const void *a, const void *b) -{ - BindElement *A, *B ; - A = (BindElement *)a ; - B = (BindElement *)b ; - - return ((int)(A->Sparse - B->Sparse)) ; -} - int HSMHV2bindCSC (GENmodel *inModel, CKTcircuit *ckt) { HSMHV2model *model = (HSMHV2model *)inModel ; HSMHV2instance *here ; - double *i ; - BindElement *matched, *BindStruct ; + BindElement i, *matched, *BindStruct ; size_t nz ; - BindStruct = ckt->CKTmatrix->CKTbindStruct ; - nz = (size_t)ckt->CKTmatrix->CKTklunz ; + BindStruct = ckt->CKTmatrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + nz = (size_t)ckt->CKTmatrix->SMPkluMatrix->KLUmatrixLinkedListNZ ; /* loop through all the HSMHV2 models */ for ( ; model != NULL ; model = HSMHV2nextModel(model)) diff --git a/src/spicelib/devices/ind/indbindCSC.c b/src/spicelib/devices/ind/indbindCSC.c index 609c0ed2c..114ca8c64 100644 --- a/src/spicelib/devices/ind/indbindCSC.c +++ b/src/spicelib/devices/ind/indbindCSC.c @@ -8,30 +8,16 @@ Author: 2013 Francesco Lannutti #include "ngspice/sperror.h" #include "ngspice/klu-binding.h" -#include - -static -int -BindCompare (const void *a, const void *b) -{ - BindElement *A, *B ; - A = (BindElement *)a ; - B = (BindElement *)b ; - - return ((int)(A->Sparse - B->Sparse)) ; -} - int INDbindCSC (GENmodel *inModel, CKTcircuit *ckt) { INDmodel *model = (INDmodel *)inModel ; INDinstance *here ; - double *i ; - BindElement *matched, *BindStruct ; + BindElement i, *matched, *BindStruct ; size_t nz ; - BindStruct = ckt->CKTmatrix->CKTbindStruct ; - nz = (size_t)ckt->CKTmatrix->CKTklunz ; + BindStruct = ckt->CKTmatrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + nz = (size_t)ckt->CKTmatrix->SMPkluMatrix->KLUmatrixLinkedListNZ ; /* loop through all the IND models */ for ( ; model != NULL ; model = INDnextModel(model)) diff --git a/src/spicelib/devices/ind/mutbindCSC.c b/src/spicelib/devices/ind/mutbindCSC.c index d17ebf640..75ada47e9 100644 --- a/src/spicelib/devices/ind/mutbindCSC.c +++ b/src/spicelib/devices/ind/mutbindCSC.c @@ -8,30 +8,16 @@ Author: 2013 Francesco Lannutti #include "ngspice/sperror.h" #include "ngspice/klu-binding.h" -#include - -static -int -BindCompare (const void *a, const void *b) -{ - BindElement *A, *B ; - A = (BindElement *)a ; - B = (BindElement *)b ; - - return ((int)(A->Sparse - B->Sparse)) ; -} - int MUTbindCSC (GENmodel *inModel, CKTcircuit *ckt) { MUTmodel *model = (MUTmodel *)inModel ; MUTinstance *here ; - double *i ; - BindElement *matched, *BindStruct ; + BindElement i, *matched, *BindStruct ; size_t nz ; - BindStruct = ckt->CKTmatrix->CKTbindStruct ; - nz = (size_t)ckt->CKTmatrix->CKTklunz ; + BindStruct = ckt->CKTmatrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + nz = (size_t)ckt->CKTmatrix->SMPkluMatrix->KLUmatrixLinkedListNZ ; /* loop through all the MUT models */ for ( ; model != NULL ; model = MUTnextModel(model)) diff --git a/src/spicelib/devices/jfet/jfetbindCSC.c b/src/spicelib/devices/jfet/jfetbindCSC.c index c1b79e182..3e4cc95e7 100644 --- a/src/spicelib/devices/jfet/jfetbindCSC.c +++ b/src/spicelib/devices/jfet/jfetbindCSC.c @@ -8,30 +8,16 @@ Author: 2013 Francesco Lannutti #include "ngspice/sperror.h" #include "ngspice/klu-binding.h" -#include - -static -int -BindCompare (const void *a, const void *b) -{ - BindElement *A, *B ; - A = (BindElement *)a ; - B = (BindElement *)b ; - - return ((int)(A->Sparse - B->Sparse)) ; -} - int JFETbindCSC (GENmodel *inModel, CKTcircuit *ckt) { JFETmodel *model = (JFETmodel *)inModel ; JFETinstance *here ; - double *i ; - BindElement *matched, *BindStruct ; + BindElement i, *matched, *BindStruct ; size_t nz ; - BindStruct = ckt->CKTmatrix->CKTbindStruct ; - nz = (size_t)ckt->CKTmatrix->CKTklunz ; + BindStruct = ckt->CKTmatrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + nz = (size_t)ckt->CKTmatrix->SMPkluMatrix->KLUmatrixLinkedListNZ ; /* loop through all the JFET models */ for ( ; model != NULL ; model = JFETnextModel(model)) diff --git a/src/spicelib/devices/jfet2/jfet2bindCSC.c b/src/spicelib/devices/jfet2/jfet2bindCSC.c index 2213b3be1..7c4aeb31e 100644 --- a/src/spicelib/devices/jfet2/jfet2bindCSC.c +++ b/src/spicelib/devices/jfet2/jfet2bindCSC.c @@ -8,30 +8,16 @@ Author: 2013 Francesco Lannutti #include "ngspice/sperror.h" #include "ngspice/klu-binding.h" -#include - -static -int -BindCompare (const void *a, const void *b) -{ - BindElement *A, *B ; - A = (BindElement *)a ; - B = (BindElement *)b ; - - return ((int)(A->Sparse - B->Sparse)) ; -} - int JFET2bindCSC (GENmodel *inModel, CKTcircuit *ckt) { JFET2model *model = (JFET2model *)inModel ; JFET2instance *here ; - double *i ; - BindElement *matched, *BindStruct ; + BindElement i, *matched, *BindStruct ; size_t nz ; - BindStruct = ckt->CKTmatrix->CKTbindStruct ; - nz = (size_t)ckt->CKTmatrix->CKTklunz ; + BindStruct = ckt->CKTmatrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + nz = (size_t)ckt->CKTmatrix->SMPkluMatrix->KLUmatrixLinkedListNZ ; /* loop through all the JFET2 models */ for ( ; model != NULL ; model = JFET2nextModel(model)) diff --git a/src/spicelib/devices/ltra/ltrabindCSC.c b/src/spicelib/devices/ltra/ltrabindCSC.c index 676e80d31..7db85a6f2 100644 --- a/src/spicelib/devices/ltra/ltrabindCSC.c +++ b/src/spicelib/devices/ltra/ltrabindCSC.c @@ -8,30 +8,16 @@ Author: 2013 Francesco Lannutti #include "ngspice/sperror.h" #include "ngspice/klu-binding.h" -#include - -static -int -BindCompare (const void *a, const void *b) -{ - BindElement *A, *B ; - A = (BindElement *)a ; - B = (BindElement *)b ; - - return ((int)(A->Sparse - B->Sparse)) ; -} - int LTRAbindCSC (GENmodel *inModel, CKTcircuit *ckt) { LTRAmodel *model = (LTRAmodel *)inModel ; LTRAinstance *here ; - double *i ; - BindElement *matched, *BindStruct ; + BindElement i, *matched, *BindStruct ; size_t nz ; - BindStruct = ckt->CKTmatrix->CKTbindStruct ; - nz = (size_t)ckt->CKTmatrix->CKTklunz ; + BindStruct = ckt->CKTmatrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + nz = (size_t)ckt->CKTmatrix->SMPkluMatrix->KLUmatrixLinkedListNZ ; /* loop through all the LTRA models */ for ( ; model != NULL ; model = LTRAnextModel(model)) diff --git a/src/spicelib/devices/mes/mesbindCSC.c b/src/spicelib/devices/mes/mesbindCSC.c index 0f0bad066..2fe6e37ce 100644 --- a/src/spicelib/devices/mes/mesbindCSC.c +++ b/src/spicelib/devices/mes/mesbindCSC.c @@ -8,30 +8,16 @@ Author: 2013 Francesco Lannutti #include "ngspice/sperror.h" #include "ngspice/klu-binding.h" -#include - -static -int -BindCompare (const void *a, const void *b) -{ - BindElement *A, *B ; - A = (BindElement *)a ; - B = (BindElement *)b ; - - return ((int)(A->Sparse - B->Sparse)) ; -} - int MESbindCSC (GENmodel *inModel, CKTcircuit *ckt) { MESmodel *model = (MESmodel *)inModel ; MESinstance *here ; - double *i ; - BindElement *matched, *BindStruct ; + BindElement i, *matched, *BindStruct ; size_t nz ; - BindStruct = ckt->CKTmatrix->CKTbindStruct ; - nz = (size_t)ckt->CKTmatrix->CKTklunz ; + BindStruct = ckt->CKTmatrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + nz = (size_t)ckt->CKTmatrix->SMPkluMatrix->KLUmatrixLinkedListNZ ; /* loop through all the MES models */ for ( ; model != NULL ; model = MESnextModel(model)) diff --git a/src/spicelib/devices/mesa/mesabindCSC.c b/src/spicelib/devices/mesa/mesabindCSC.c index 39dce6c1f..43f86a648 100644 --- a/src/spicelib/devices/mesa/mesabindCSC.c +++ b/src/spicelib/devices/mesa/mesabindCSC.c @@ -8,30 +8,16 @@ Author: 2013 Francesco Lannutti #include "ngspice/sperror.h" #include "ngspice/klu-binding.h" -#include - -static -int -BindCompare (const void *a, const void *b) -{ - BindElement *A, *B ; - A = (BindElement *)a ; - B = (BindElement *)b ; - - return ((int)(A->Sparse - B->Sparse)) ; -} - int MESAbindCSC (GENmodel *inModel, CKTcircuit *ckt) { MESAmodel *model = (MESAmodel *)inModel ; MESAinstance *here ; - double *i ; - BindElement *matched, *BindStruct ; + BindElement i, *matched, *BindStruct ; size_t nz ; - BindStruct = ckt->CKTmatrix->CKTbindStruct ; - nz = (size_t)ckt->CKTmatrix->CKTklunz ; + BindStruct = ckt->CKTmatrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + nz = (size_t)ckt->CKTmatrix->SMPkluMatrix->KLUmatrixLinkedListNZ ; /* loop through all the MESA models */ for ( ; model != NULL ; model = MESAnextModel(model)) diff --git a/src/spicelib/devices/mos1/mos1bindCSC.c b/src/spicelib/devices/mos1/mos1bindCSC.c index 48542af39..35e229670 100644 --- a/src/spicelib/devices/mos1/mos1bindCSC.c +++ b/src/spicelib/devices/mos1/mos1bindCSC.c @@ -8,30 +8,16 @@ Author: 2013 Francesco Lannutti #include "ngspice/sperror.h" #include "ngspice/klu-binding.h" -#include - -static -int -BindCompare (const void *a, const void *b) -{ - BindElement *A, *B ; - A = (BindElement *)a ; - B = (BindElement *)b ; - - return ((int)(A->Sparse - B->Sparse)) ; -} - int MOS1bindCSC (GENmodel *inModel, CKTcircuit *ckt) { MOS1model *model = (MOS1model *)inModel ; MOS1instance *here ; - double *i ; - BindElement *matched, *BindStruct ; + BindElement i, *matched, *BindStruct ; size_t nz ; - BindStruct = ckt->CKTmatrix->CKTbindStruct ; - nz = (size_t)ckt->CKTmatrix->CKTklunz ; + BindStruct = ckt->CKTmatrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + nz = (size_t)ckt->CKTmatrix->SMPkluMatrix->KLUmatrixLinkedListNZ ; /* loop through all the MOS1 models */ for ( ; model != NULL ; model = MOS1nextModel(model)) diff --git a/src/spicelib/devices/mos2/mos2bindCSC.c b/src/spicelib/devices/mos2/mos2bindCSC.c index b3eb6334c..775af6e98 100644 --- a/src/spicelib/devices/mos2/mos2bindCSC.c +++ b/src/spicelib/devices/mos2/mos2bindCSC.c @@ -8,30 +8,16 @@ Author: 2013 Francesco Lannutti #include "ngspice/sperror.h" #include "ngspice/klu-binding.h" -#include - -static -int -BindCompare (const void *a, const void *b) -{ - BindElement *A, *B ; - A = (BindElement *)a ; - B = (BindElement *)b ; - - return ((int)(A->Sparse - B->Sparse)) ; -} - int MOS2bindCSC (GENmodel *inModel, CKTcircuit *ckt) { MOS2model *model = (MOS2model *)inModel ; MOS2instance *here ; - double *i ; - BindElement *matched, *BindStruct ; + BindElement i, *matched, *BindStruct ; size_t nz ; - BindStruct = ckt->CKTmatrix->CKTbindStruct ; - nz = (size_t)ckt->CKTmatrix->CKTklunz ; + BindStruct = ckt->CKTmatrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + nz = (size_t)ckt->CKTmatrix->SMPkluMatrix->KLUmatrixLinkedListNZ ; /* loop through all the MOS2 models */ for ( ; model != NULL ; model = MOS2nextModel(model)) diff --git a/src/spicelib/devices/mos3/mos3bindCSC.c b/src/spicelib/devices/mos3/mos3bindCSC.c index 7cc7df5fe..d4792c130 100644 --- a/src/spicelib/devices/mos3/mos3bindCSC.c +++ b/src/spicelib/devices/mos3/mos3bindCSC.c @@ -8,30 +8,16 @@ Author: 2013 Francesco Lannutti #include "ngspice/sperror.h" #include "ngspice/klu-binding.h" -#include - -static -int -BindCompare (const void *a, const void *b) -{ - BindElement *A, *B ; - A = (BindElement *)a ; - B = (BindElement *)b ; - - return ((int)(A->Sparse - B->Sparse)) ; -} - int MOS3bindCSC (GENmodel *inModel, CKTcircuit *ckt) { MOS3model *model = (MOS3model *)inModel ; MOS3instance *here ; - double *i ; - BindElement *matched, *BindStruct ; + BindElement i, *matched, *BindStruct ; size_t nz ; - BindStruct = ckt->CKTmatrix->CKTbindStruct ; - nz = (size_t)ckt->CKTmatrix->CKTklunz ; + BindStruct = ckt->CKTmatrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + nz = (size_t)ckt->CKTmatrix->SMPkluMatrix->KLUmatrixLinkedListNZ ; /* loop through all the MOS3 models */ for ( ; model != NULL ; model = MOS3nextModel(model)) diff --git a/src/spicelib/devices/mos6/mos6bindCSC.c b/src/spicelib/devices/mos6/mos6bindCSC.c index 50138968d..d248bd6af 100644 --- a/src/spicelib/devices/mos6/mos6bindCSC.c +++ b/src/spicelib/devices/mos6/mos6bindCSC.c @@ -8,30 +8,16 @@ Author: 2012 Francesco Lannutti #include "ngspice/sperror.h" #include "ngspice/klu-binding.h" -#include - -static -int -BindCompare (const void *a, const void *b) -{ - BindElement *A, *B ; - A = (BindElement *)a ; - B = (BindElement *)b ; - - return ((int)(A->Sparse - B->Sparse)) ; -} - int MOS6bindCSC (GENmodel *inModel, CKTcircuit *ckt) { MOS6model *model = (MOS6model *)inModel ; MOS6instance *here ; - double *i ; - BindElement *matched, *BindStruct ; + BindElement i, *matched, *BindStruct ; size_t nz ; - BindStruct = ckt->CKTmatrix->CKTbindStruct ; - nz = (size_t)ckt->CKTmatrix->CKTklunz ; + BindStruct = ckt->CKTmatrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + nz = (size_t)ckt->CKTmatrix->SMPkluMatrix->KLUmatrixLinkedListNZ ; /* loop through all the MOS6 models */ for ( ; model != NULL ; model = MOS6nextModel(model)) diff --git a/src/spicelib/devices/mos9/mos9bindCSC.c b/src/spicelib/devices/mos9/mos9bindCSC.c index 23eecc5d1..e6545fb50 100644 --- a/src/spicelib/devices/mos9/mos9bindCSC.c +++ b/src/spicelib/devices/mos9/mos9bindCSC.c @@ -8,30 +8,16 @@ Author: 2013 Francesco Lannutti #include "ngspice/sperror.h" #include "ngspice/klu-binding.h" -#include - -static -int -BindCompare (const void *a, const void *b) -{ - BindElement *A, *B ; - A = (BindElement *)a ; - B = (BindElement *)b ; - - return ((int)(A->Sparse - B->Sparse)) ; -} - int MOS9bindCSC (GENmodel *inModel, CKTcircuit *ckt) { MOS9model *model = (MOS9model *)inModel ; MOS9instance *here ; - double *i ; - BindElement *matched, *BindStruct ; + BindElement i, *matched, *BindStruct ; size_t nz ; - BindStruct = ckt->CKTmatrix->CKTbindStruct ; - nz = (size_t)ckt->CKTmatrix->CKTklunz ; + BindStruct = ckt->CKTmatrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + nz = (size_t)ckt->CKTmatrix->SMPkluMatrix->KLUmatrixLinkedListNZ ; /* loop through all the MOS9 models */ for ( ; model != NULL ; model = MOS9nextModel(model)) diff --git a/src/spicelib/devices/nbjt/nbjtbindCSC.c b/src/spicelib/devices/nbjt/nbjtbindCSC.c index a6e150f52..d7d5e9a27 100644 --- a/src/spicelib/devices/nbjt/nbjtbindCSC.c +++ b/src/spicelib/devices/nbjt/nbjtbindCSC.c @@ -8,30 +8,16 @@ Author: 2013 Francesco Lannutti #include "ngspice/sperror.h" #include "ngspice/klu-binding.h" -#include - -static -int -BindCompare (const void *a, const void *b) -{ - BindElement *A, *B ; - A = (BindElement *)a ; - B = (BindElement *)b ; - - return ((int)(A->Sparse - B->Sparse)) ; -} - int NBJTbindCSC (GENmodel *inModel, CKTcircuit *ckt) { NBJTmodel *model = (NBJTmodel *)inModel ; NBJTinstance *here ; - double *i ; - BindElement *matched, *BindStruct ; + BindElement i, *matched, *BindStruct ; size_t nz ; - BindStruct = ckt->CKTmatrix->CKTbindStruct ; - nz = (size_t)ckt->CKTmatrix->CKTklunz ; + BindStruct = ckt->CKTmatrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + nz = (size_t)ckt->CKTmatrix->SMPkluMatrix->KLUmatrixLinkedListNZ ; /* loop through all the NBJT models */ for ( ; model != NULL ; model = NBJTnextModel(model)) diff --git a/src/spicelib/devices/nbjt2/nbjt2bindCSC.c b/src/spicelib/devices/nbjt2/nbjt2bindCSC.c index c77cef583..fa62ced3c 100644 --- a/src/spicelib/devices/nbjt2/nbjt2bindCSC.c +++ b/src/spicelib/devices/nbjt2/nbjt2bindCSC.c @@ -8,30 +8,16 @@ Author: 2013 Francesco Lannutti #include "ngspice/sperror.h" #include "ngspice/klu-binding.h" -#include - -static -int -BindCompare (const void *a, const void *b) -{ - BindElement *A, *B ; - A = (BindElement *)a ; - B = (BindElement *)b ; - - return ((int)(A->Sparse - B->Sparse)) ; -} - int NBJT2bindCSC (GENmodel *inModel, CKTcircuit *ckt) { NBJT2model *model = (NBJT2model *)inModel ; NBJT2instance *here ; - double *i ; - BindElement *matched, *BindStruct ; + BindElement i, *matched, *BindStruct ; size_t nz ; - BindStruct = ckt->CKTmatrix->CKTbindStruct ; - nz = (size_t)ckt->CKTmatrix->CKTklunz ; + BindStruct = ckt->CKTmatrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + nz = (size_t)ckt->CKTmatrix->SMPkluMatrix->KLUmatrixLinkedListNZ ; /* loop through all the NBJT2 models */ for ( ; model != NULL ; model = NBJT2nextModel(model)) diff --git a/src/spicelib/devices/numd/numdbindCSC.c b/src/spicelib/devices/numd/numdbindCSC.c index d19ef5feb..15bcdf225 100644 --- a/src/spicelib/devices/numd/numdbindCSC.c +++ b/src/spicelib/devices/numd/numdbindCSC.c @@ -8,30 +8,16 @@ Author: 2013 Francesco Lannutti #include "ngspice/sperror.h" #include "ngspice/klu-binding.h" -#include - -static -int -BindCompare (const void *a, const void *b) -{ - BindElement *A, *B ; - A = (BindElement *)a ; - B = (BindElement *)b ; - - return ((int)(A->Sparse - B->Sparse)) ; -} - int NUMDbindCSC (GENmodel *inModel, CKTcircuit *ckt) { NUMDmodel *model = (NUMDmodel *)inModel ; NUMDinstance *here ; - double *i ; - BindElement *matched, *BindStruct ; + BindElement i, *matched, *BindStruct ; size_t nz ; - BindStruct = ckt->CKTmatrix->CKTbindStruct ; - nz = (size_t)ckt->CKTmatrix->CKTklunz ; + BindStruct = ckt->CKTmatrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + nz = (size_t)ckt->CKTmatrix->SMPkluMatrix->KLUmatrixLinkedListNZ ; /* loop through all the NUMD models */ for ( ; model != NULL ; model = NUMDnextModel(model)) diff --git a/src/spicelib/devices/numd2/numd2bindCSC.c b/src/spicelib/devices/numd2/numd2bindCSC.c index 010a2fa6a..a050414c4 100644 --- a/src/spicelib/devices/numd2/numd2bindCSC.c +++ b/src/spicelib/devices/numd2/numd2bindCSC.c @@ -8,30 +8,16 @@ Author: 2013 Francesco Lannutti #include "ngspice/sperror.h" #include "ngspice/klu-binding.h" -#include - -static -int -BindCompare (const void *a, const void *b) -{ - BindElement *A, *B ; - A = (BindElement *)a ; - B = (BindElement *)b ; - - return ((int)(A->Sparse - B->Sparse)) ; -} - int NUMD2bindCSC (GENmodel *inModel, CKTcircuit *ckt) { NUMD2model *model = (NUMD2model *)inModel ; NUMD2instance *here ; - double *i ; - BindElement *matched, *BindStruct ; + BindElement i, *matched, *BindStruct ; size_t nz ; - BindStruct = ckt->CKTmatrix->CKTbindStruct ; - nz = (size_t)ckt->CKTmatrix->CKTklunz ; + BindStruct = ckt->CKTmatrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + nz = (size_t)ckt->CKTmatrix->SMPkluMatrix->KLUmatrixLinkedListNZ ; /* loop through all the NUMD2 models */ for ( ; model != NULL ; model = NUMD2nextModel(model)) diff --git a/src/spicelib/devices/numos/numosbindCSC.c b/src/spicelib/devices/numos/numosbindCSC.c index 9ebb76931..da9bb5658 100644 --- a/src/spicelib/devices/numos/numosbindCSC.c +++ b/src/spicelib/devices/numos/numosbindCSC.c @@ -8,30 +8,16 @@ Author: 2013 Francesco Lannutti #include "ngspice/sperror.h" #include "ngspice/klu-binding.h" -#include - -static -int -BindCompare (const void *a, const void *b) -{ - BindElement *A, *B ; - A = (BindElement *)a ; - B = (BindElement *)b ; - - return ((int)(A->Sparse - B->Sparse)) ; -} - int NUMOSbindCSC (GENmodel *inModel, CKTcircuit *ckt) { NUMOSmodel *model = (NUMOSmodel *)inModel ; NUMOSinstance *here ; - double *i ; - BindElement *matched, *BindStruct ; + BindElement i, *matched, *BindStruct ; size_t nz ; - BindStruct = ckt->CKTmatrix->CKTbindStruct ; - nz = (size_t)ckt->CKTmatrix->CKTklunz ; + BindStruct = ckt->CKTmatrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + nz = (size_t)ckt->CKTmatrix->SMPkluMatrix->KLUmatrixLinkedListNZ ; /* loop through all the NUMOS models */ for ( ; model != NULL ; model = NUMOSnextModel(model)) diff --git a/src/spicelib/devices/res/resbindCSC.c b/src/spicelib/devices/res/resbindCSC.c index 99a2b4c27..514082319 100644 --- a/src/spicelib/devices/res/resbindCSC.c +++ b/src/spicelib/devices/res/resbindCSC.c @@ -8,30 +8,16 @@ Author: 2013 Francesco Lannutti #include "ngspice/sperror.h" #include "ngspice/klu-binding.h" -#include - -static -int -BindCompare (const void *a, const void *b) -{ - BindElement *A, *B ; - A = (BindElement *)a ; - B = (BindElement *)b ; - - return ((int)(A->Sparse - B->Sparse)) ; -} - int RESbindCSC (GENmodel *inModel, CKTcircuit *ckt) { RESmodel *model = (RESmodel *)inModel ; RESinstance *here ; - double *i ; - BindElement *matched, *BindStruct ; + BindElement i, *matched, *BindStruct ; size_t nz ; - BindStruct = ckt->CKTmatrix->CKTbindStruct ; - nz = (size_t)ckt->CKTmatrix->CKTklunz ; + BindStruct = ckt->CKTmatrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + nz = (size_t)ckt->CKTmatrix->SMPkluMatrix->KLUmatrixLinkedListNZ ; /* loop through all the RES models */ for ( ; model != NULL ; model = RESnextModel(model)) diff --git a/src/spicelib/devices/soi3/soi3bindCSC.c b/src/spicelib/devices/soi3/soi3bindCSC.c index 78eca5d70..2207fa81e 100644 --- a/src/spicelib/devices/soi3/soi3bindCSC.c +++ b/src/spicelib/devices/soi3/soi3bindCSC.c @@ -8,30 +8,16 @@ Author: 2013 Francesco Lannutti #include "ngspice/sperror.h" #include "ngspice/klu-binding.h" -#include - -static -int -BindCompare (const void *a, const void *b) -{ - BindElement *A, *B ; - A = (BindElement *)a ; - B = (BindElement *)b ; - - return ((int)(A->Sparse - B->Sparse)) ; -} - int SOI3bindCSC (GENmodel *inModel, CKTcircuit *ckt) { SOI3model *model = (SOI3model *)inModel ; SOI3instance *here ; - double *i ; - BindElement *matched, *BindStruct ; + BindElement i, *matched, *BindStruct ; size_t nz ; - BindStruct = ckt->CKTmatrix->CKTbindStruct ; - nz = (size_t)ckt->CKTmatrix->CKTklunz ; + BindStruct = ckt->CKTmatrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + nz = (size_t)ckt->CKTmatrix->SMPkluMatrix->KLUmatrixLinkedListNZ ; /* loop through all the SOI3 models */ for ( ; model != NULL ; model = SOI3nextModel(model)) diff --git a/src/spicelib/devices/sw/swbindCSC.c b/src/spicelib/devices/sw/swbindCSC.c index 767630fed..c2ebe57cd 100644 --- a/src/spicelib/devices/sw/swbindCSC.c +++ b/src/spicelib/devices/sw/swbindCSC.c @@ -8,30 +8,16 @@ Author: 2013 Francesco Lannutti #include "ngspice/sperror.h" #include "ngspice/klu-binding.h" -#include - -static -int -BindCompare (const void *a, const void *b) -{ - BindElement *A, *B ; - A = (BindElement *)a ; - B = (BindElement *)b ; - - return ((int)(A->Sparse - B->Sparse)) ; -} - int SWbindCSC (GENmodel *inModel, CKTcircuit *ckt) { SWmodel *model = (SWmodel *)inModel ; SWinstance *here ; - double *i ; - BindElement *matched, *BindStruct ; + BindElement i, *matched, *BindStruct ; size_t nz ; - BindStruct = ckt->CKTmatrix->CKTbindStruct ; - nz = (size_t)ckt->CKTmatrix->CKTklunz ; + BindStruct = ckt->CKTmatrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + nz = (size_t)ckt->CKTmatrix->SMPkluMatrix->KLUmatrixLinkedListNZ ; /* loop through all the SW models */ for ( ; model != NULL ; model = SWnextModel(model)) diff --git a/src/spicelib/devices/tra/trabindCSC.c b/src/spicelib/devices/tra/trabindCSC.c index b15459d6d..6bef569fa 100644 --- a/src/spicelib/devices/tra/trabindCSC.c +++ b/src/spicelib/devices/tra/trabindCSC.c @@ -8,30 +8,16 @@ Author: 2013 Francesco Lannutti #include "ngspice/sperror.h" #include "ngspice/klu-binding.h" -#include - -static -int -BindCompare (const void *a, const void *b) -{ - BindElement *A, *B ; - A = (BindElement *)a ; - B = (BindElement *)b ; - - return ((int)(A->Sparse - B->Sparse)) ; -} - int TRAbindCSC (GENmodel *inModel, CKTcircuit *ckt) { TRAmodel *model = (TRAmodel *)inModel ; TRAinstance *here ; - double *i ; - BindElement *matched, *BindStruct ; + BindElement i, *matched, *BindStruct ; size_t nz ; - BindStruct = ckt->CKTmatrix->CKTbindStruct ; - nz = (size_t)ckt->CKTmatrix->CKTklunz ; + BindStruct = ckt->CKTmatrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + nz = (size_t)ckt->CKTmatrix->SMPkluMatrix->KLUmatrixLinkedListNZ ; /* loop through all the TRA models */ for ( ; model != NULL ; model = TRAnextModel(model)) diff --git a/src/spicelib/devices/txl/txlbindCSC.c b/src/spicelib/devices/txl/txlbindCSC.c index f8f3dd001..440fdd310 100644 --- a/src/spicelib/devices/txl/txlbindCSC.c +++ b/src/spicelib/devices/txl/txlbindCSC.c @@ -8,30 +8,16 @@ Author: 2013 Francesco Lannutti #include "ngspice/sperror.h" #include "ngspice/klu-binding.h" -#include - -static -int -BindCompare (const void *a, const void *b) -{ - BindElement *A, *B ; - A = (BindElement *)a ; - B = (BindElement *)b ; - - return ((int)(A->Sparse - B->Sparse)) ; -} - int TXLbindCSC (GENmodel *inModel, CKTcircuit *ckt) { TXLmodel *model = (TXLmodel *)inModel ; TXLinstance *here ; - double *i ; - BindElement *matched, *BindStruct ; + BindElement i, *matched, *BindStruct ; size_t nz ; - BindStruct = ckt->CKTmatrix->CKTbindStruct ; - nz = (size_t)ckt->CKTmatrix->CKTklunz ; + BindStruct = ckt->CKTmatrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + nz = (size_t)ckt->CKTmatrix->SMPkluMatrix->KLUmatrixLinkedListNZ ; /* loop through all the TXL models */ for ( ; model != NULL ; model = TXLnextModel(model)) diff --git a/src/spicelib/devices/vbic/vbicbindCSC.c b/src/spicelib/devices/vbic/vbicbindCSC.c index d9aa51ce0..a2b2190dc 100644 --- a/src/spicelib/devices/vbic/vbicbindCSC.c +++ b/src/spicelib/devices/vbic/vbicbindCSC.c @@ -8,30 +8,16 @@ Author: 2013 Francesco Lannutti #include "ngspice/sperror.h" #include "ngspice/klu-binding.h" -#include - -static -int -BindCompare (const void *a, const void *b) -{ - BindElement *A, *B ; - A = (BindElement *)a ; - B = (BindElement *)b ; - - return ((int)(A->Sparse - B->Sparse)) ; -} - int VBICbindCSC (GENmodel *inModel, CKTcircuit *ckt) { VBICmodel *model = (VBICmodel *)inModel ; VBICinstance *here ; - double *i ; - BindElement *matched, *BindStruct ; + BindElement i, *matched, *BindStruct ; size_t nz ; - BindStruct = ckt->CKTmatrix->CKTbindStruct ; - nz = (size_t)ckt->CKTmatrix->CKTklunz ; + BindStruct = ckt->CKTmatrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + nz = (size_t)ckt->CKTmatrix->SMPkluMatrix->KLUmatrixLinkedListNZ ; /* loop through all the VBIC models */ for ( ; model != NULL ; model = VBICnextModel(model)) diff --git a/src/spicelib/devices/vccs/vccsbindCSC.c b/src/spicelib/devices/vccs/vccsbindCSC.c index 44b3b60d1..aad217bb6 100644 --- a/src/spicelib/devices/vccs/vccsbindCSC.c +++ b/src/spicelib/devices/vccs/vccsbindCSC.c @@ -8,30 +8,16 @@ Author: 2013 Francesco Lannutti #include "ngspice/sperror.h" #include "ngspice/klu-binding.h" -#include - -static -int -BindCompare (const void *a, const void *b) -{ - BindElement *A, *B ; - A = (BindElement *)a ; - B = (BindElement *)b ; - - return ((int)(A->Sparse - B->Sparse)) ; -} - int VCCSbindCSC (GENmodel *inModel, CKTcircuit *ckt) { VCCSmodel *model = (VCCSmodel *)inModel ; VCCSinstance *here ; - double *i ; - BindElement *matched, *BindStruct ; + BindElement i, *matched, *BindStruct ; size_t nz ; - BindStruct = ckt->CKTmatrix->CKTbindStruct ; - nz = (size_t)ckt->CKTmatrix->CKTklunz ; + BindStruct = ckt->CKTmatrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + nz = (size_t)ckt->CKTmatrix->SMPkluMatrix->KLUmatrixLinkedListNZ ; /* loop through all the VCCS models */ for ( ; model != NULL ; model = VCCSnextModel(model)) diff --git a/src/spicelib/devices/vcvs/vcvsbindCSC.c b/src/spicelib/devices/vcvs/vcvsbindCSC.c index 769ebab02..085594670 100644 --- a/src/spicelib/devices/vcvs/vcvsbindCSC.c +++ b/src/spicelib/devices/vcvs/vcvsbindCSC.c @@ -8,30 +8,16 @@ Author: 2013 Francesco Lannutti #include "ngspice/sperror.h" #include "ngspice/klu-binding.h" -#include - -static -int -BindCompare (const void *a, const void *b) -{ - BindElement *A, *B ; - A = (BindElement *)a ; - B = (BindElement *)b ; - - return ((int)(A->Sparse - B->Sparse)) ; -} - int VCVSbindCSC (GENmodel *inModel, CKTcircuit *ckt) { VCVSmodel *model = (VCVSmodel *)inModel ; VCVSinstance *here ; - double *i ; - BindElement *matched, *BindStruct ; + BindElement i, *matched, *BindStruct ; size_t nz ; - BindStruct = ckt->CKTmatrix->CKTbindStruct ; - nz = (size_t)ckt->CKTmatrix->CKTklunz ; + BindStruct = ckt->CKTmatrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + nz = (size_t)ckt->CKTmatrix->SMPkluMatrix->KLUmatrixLinkedListNZ ; /* loop through all the VCVS models */ for ( ; model != NULL ; model = VCVSnextModel(model)) diff --git a/src/spicelib/devices/vsrc/vsrcbindCSC.c b/src/spicelib/devices/vsrc/vsrcbindCSC.c index 81706ce13..38c122f8a 100644 --- a/src/spicelib/devices/vsrc/vsrcbindCSC.c +++ b/src/spicelib/devices/vsrc/vsrcbindCSC.c @@ -8,30 +8,16 @@ Author: 2013 Francesco Lannutti #include "ngspice/sperror.h" #include "ngspice/klu-binding.h" -#include - -static -int -BindCompare (const void *a, const void *b) -{ - BindElement *A, *B ; - A = (BindElement *)a ; - B = (BindElement *)b ; - - return ((int)(A->Sparse - B->Sparse)) ; -} - int VSRCbindCSC (GENmodel *inModel, CKTcircuit *ckt) { VSRCmodel *model = (VSRCmodel *)inModel ; VSRCinstance *here ; - double *i ; - BindElement *matched, *BindStruct ; + BindElement i, *matched, *BindStruct ; size_t nz ; - BindStruct = ckt->CKTmatrix->CKTbindStruct ; - nz = (size_t)ckt->CKTmatrix->CKTklunz ; + BindStruct = ckt->CKTmatrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + nz = (size_t)ckt->CKTmatrix->SMPkluMatrix->KLUmatrixLinkedListNZ ; /* loop through all the VSRC models */ for ( ; model != NULL ; model = VSRCnextModel(model)) @@ -47,7 +33,9 @@ VSRCbindCSC (GENmodel *inModel, CKTcircuit *ckt) /* Pole-Zero Analysis */ if (here->VSRCibrIbrPtr) { - i = here->VSRCibrIbrPtr ; + i.COO = here->VSRCibrIbrPtr ; + i.CSC = NULL ; + i.CSC_Complex = NULL ; matched = (BindElement *) bsearch (&i, BindStruct, nz, sizeof(BindElement), BindCompare) ; here->VSRCibrIbrBinding = matched ; if (matched != NULL) diff --git a/src/xspice/mif/mifbindCSC.c b/src/xspice/mif/mifbindCSC.c index 8d5eca5bd..47ad7b02b 100644 --- a/src/xspice/mif/mifbindCSC.c +++ b/src/xspice/mif/mifbindCSC.c @@ -12,26 +12,12 @@ #include "ngspice/mifproto.h" #include "ngspice/mifdefs.h" -#include - -static -int -BindCompare (const void *a, const void *b) -{ - BindElement *A, *B ; - A = (BindElement *)a ; - B = (BindElement *)b ; - - return ((int)(A->Sparse - B->Sparse)) ; -} - int MIFbindCSC (GENmodel *inModel, CKTcircuit *ckt) { MIFmodel *model = (MIFmodel *)inModel ; MIFinstance *here ; - double *i ; - BindElement *matched, *BindStruct ; + BindElement i, *matched, *BindStruct ; int ii, j, k, l, num_conn, num_port, num_port_k ; Mif_Boolean_t is_input, is_output ; Mif_Cntl_Src_Type_t cntl_src_type ; @@ -39,8 +25,8 @@ MIFbindCSC (GENmodel *inModel, CKTcircuit *ckt) Mif_Smp_Ptr_t *smp_data_cntl, *smp_data_out ; size_t nz ; - BindStruct = ckt->CKTmatrix->CKTbindStruct ; - nz = (size_t)ckt->CKTmatrix->CKTklunz ; + BindStruct = ckt->CKTmatrix->SMPkluMatrix->KLUmatrixBindStructCOO ; + nz = (size_t)ckt->CKTmatrix->SMPkluMatrix->KLUmatrixLinkedListNZ ; /* loop through all the MIF models */ for ( ; model != NULL ; model = MIFnextModel(model))