2 #include <../../nrnconf.h>
54 "Sparse1.3: Copyright (c) 1985,86,87,88 by Kenneth S. Kundert";
73 #define spINSIDE_SPARSE
189 register int J,
Size;
191 int Twins, StartAt = 1;
192 BOOLEAN Swapped, AnotherPassNeeded;
202 { AnotherPassNeeded = Swapped =
NO;
205 for (J = StartAt; J <=
Size; J++)
213 else if ((Twins > 1)
AND NOT AnotherPassNeeded)
214 { AnotherPassNeeded =
YES;
221 if (AnotherPassNeeded)
222 {
for (J = StartAt;
NOT Swapped
AND (J <=
Size); J++)
230 }
while (AnotherPassNeeded);
258 while (pTwin1 !=
NULL)
259 {
if (
ABS(pTwin1->
Real) == 1.0)
262 while ((pTwin2 !=
NULL)
AND (pTwin2->
Row != Col))
266 if (++Twins >= 2)
return Twins;
267 (*ppTwin1 = pTwin1)->Col = Col;
268 (*ppTwin2 = pTwin2)->Col = Row;
292 int Col1 = pTwin1->
Col, Col2 = pTwin2->
Col;
376 spScale( eMatrix, RHS_ScaleFactors, SolutionScaleFactors )
379 register RealVector RHS_ScaleFactors, SolutionScaleFactors;
403 --SolutionScaleFactors;
408 for (
I = 1;
I <= lSize;
I++)
409 {
if ((ScaleFactor = RHS_ScaleFactors[*(
pExtOrder++)]) != 1.0)
421 for (
I = 1;
I <= lSize;
I++)
422 {
if ((ScaleFactor = SolutionScaleFactors[*(
pExtOrder++)]) != 1.0)
445 #if spCOMPLEX AND SCALING
506 register RealVector RHS_ScaleFactors, SolutionScaleFactors;
518 --SolutionScaleFactors;
523 for (
I = 1;
I <= lSize;
I++)
524 {
if ((ScaleFactor = RHS_ScaleFactors[*(
pExtOrder++)]) != 1.0)
537 for (
I = 1;
I <= lSize;
I++)
538 {
if ((ScaleFactor = SolutionScaleFactors[*(
pExtOrder++)]) != 1.0)
649 #if spCOMPLEX AND MULTIPLICATION
699 #if spSEPARATED_COMPLEX_VECTORS
701 --Solution; --iSolution;
703 RHS -= 2; Solution -= 2;
724 Sum.Real =
Sum.Imag = 0.0;
732 #if spSEPARATED_COMPLEX_VECTORS
750 #if MULTIPLICATION AND TRANSPOSE
839 #if spCOMPLEX AND MULTIPLICATION AND TRANSPOSE
889 #if spSEPARATED_COMPLEX_VECTORS
891 --Solution; --iSolution;
893 RHS -= 2; Solution -= 2;
914 Sum.Real =
Sum.Imag = 0.0;
922 #if spSEPARATED_COMPLEX_VECTORS
995 register int I,
Size;
999 #define NORM(a) (nr = ABS((a).Real), ni = ABS((a).Imag), MAX (nr,ni))
1006 { *pDeterminant = 0.0;
1018 { cDeterminant.
Real = 1.0;
1019 cDeterminant.
Imag = 0.0;
1026 Norm =
NORM( cDeterminant );
1028 {
while (Norm >= 1.0e12)
1029 { cDeterminant.
Real *= 1.0e-12;
1030 cDeterminant.
Imag *= 1.0e-12;
1032 Norm =
NORM( cDeterminant );
1034 while (Norm < 1.0e-12)
1035 { cDeterminant.
Real *= 1.0e12;
1036 cDeterminant.
Imag *= 1.0e12;
1038 Norm =
NORM( cDeterminant );
1044 Norm =
NORM( cDeterminant );
1046 {
while (Norm >= 10.0)
1047 { cDeterminant.
Real *= 0.1;
1048 cDeterminant.
Imag *= 0.1;
1050 Norm =
NORM( cDeterminant );
1053 { cDeterminant.
Real *= 10.0;
1054 cDeterminant.
Imag *= 10.0;
1056 Norm =
NORM( cDeterminant );
1062 *pDeterminant = cDeterminant.
Real;
1063 *piDeterminant = cDeterminant.
Imag;
1066 #if REAL AND spCOMPLEX
1071 *pDeterminant = 1.0;
1077 if (*pDeterminant != 0.0)
1078 {
while (
ABS(*pDeterminant) >= 1.0e12)
1079 { *pDeterminant *= 1.0e-12;
1082 while (
ABS(*pDeterminant) < 1.0e-12)
1083 { *pDeterminant *= 1.0e12;
1090 if (*pDeterminant != 0.0)
1091 {
while (
ABS(*pDeterminant) >= 10.0)
1092 { *pDeterminant *= 0.1;
1095 while (
ABS(*pDeterminant) < 1.0)
1096 { *pDeterminant *= 10.0;
1101 *pDeterminant = -*pDeterminant;
1161 while (pListNode !=
NULL)
1164 while (pFillin <= pLastFillin)
1165 (pFillin++)->Row = 0;
1166 pListNode = pListNode->
Next;
1209 #if TRANSLATE AND DELETE
1252 int Size, ExtRow, ExtCol;
1258 ASSERT( Row <= Matrix->ExtSize
AND Col <= Matrix->ExtSize );
1290 while (pLastElement !=
NULL)
1303 while (pLastElement !=
NULL)
1382 else if (Mag < MinPivot)
1386 return MaxPivot / MinPivot;
1461 register int I,
K, Row;
1464 RealNumber E, Em, Wp, Wm, ASp, ASm, ASw, ASy, ASv, ASz, MaxY, ScaleFactor;
1465 RealNumber Linpack, OLeary, InvNormOfInverse;
1473 if (NormOfMatrix == 0.0)
1508 if (
T[
I] < 0.0) Em = -E;
else Em = E;
1512 for (
K =
Size;
K > 0;
K--)
T[
K] *= ScaleFactor;
1518 ASp =
ABS(
T[
I] - Em);
1519 ASm =
ABS(Em +
T[
I]);
1528 ASm +=
ABS(Tm[Row]);
1545 for (ASw = 0.0,
I =
Size;
I > 0;
I--) ASw +=
ABS(
T[
I]);
1546 ScaleFactor = 1.0 / (
SLACK * ASw);
1547 if (ScaleFactor < 0.5)
1548 {
for (
I =
Size;
I > 0;
I--)
T[
I] *= ScaleFactor;
1561 for (
K =
Size;
K > 0;
K--)
T[
K] *= ScaleFactor;
1567 for (ASy = 0.0,
I =
Size;
I > 0;
I--) ASy +=
ABS(
T[
I]);
1568 ScaleFactor = 1.0 / (
SLACK * ASy);
1569 if (ScaleFactor < 0.5)
1570 {
for (
I =
Size;
I > 0;
I--)
T[
I] *= ScaleFactor;
1576 for (MaxY = 0.0,
I =
Size;
I > 0;
I--)
1593 for (
K =
Size;
K > 0;
K--)
T[
K] *= ScaleFactor;
1599 for (ASv = 0.0,
I =
Size;
I > 0;
I--) ASv +=
ABS(
T[
I]);
1600 ScaleFactor = 1.0 / (
SLACK * ASv);
1601 if (ScaleFactor < 0.5)
1602 {
for (
I =
Size;
I > 0;
I--)
T[
I] *= ScaleFactor;
1617 for (
K =
Size;
K > 0;
K--)
T[
K] *= ScaleFactor;
1623 for (ASz = 0.0,
I =
Size;
I > 0;
I--) ASz +=
ABS(
T[
I]);
1629 Linpack = ASy / ASz;
1631 InvNormOfInverse =
MIN( Linpack, OLeary );
1632 return InvNormOfInverse / NormOfMatrix;
1671 register int I,
K, Row;
1674 RealNumber E, Em, ASp, ASm, ASw, ASy, ASv, ASz, MaxY, ScaleFactor;
1675 RealNumber Linpack, OLeary, InvNormOfInverse;
1700 if (
T[
I].
Real < 0.0) Em = -E;
else Em = E;
1745 ScaleFactor = 1.0 / (
SLACK * ASw);
1746 if (ScaleFactor < 0.5)
1768 ScaleFactor = 1.0 / (
SLACK * ASy);
1769 if (ScaleFactor < 0.5)
1776 for (MaxY = 0.0,
I =
Size;
I > 0;
I--)
1801 ScaleFactor = 1.0 / (
SLACK * ASv);
1802 if (ScaleFactor < 0.5)
1829 Linpack = ASy / ASz;
1831 InvNormOfInverse =
MIN( Linpack, OLeary );
1832 return InvNormOfInverse / NormOfMatrix;
1880 if (Max < AbsRowSum) Max = AbsRowSum;
1893 if (Max < AbsRowSum) Max = AbsRowSum;
1980 RealNumber Mag, AbsColSum, Max = 0.0, MaxRow = 0.0, MaxCol = 0.0;
1997 Pivot = 1.0 / pDiag->
Real;
1999 if (Mag > MaxRow) MaxRow = Mag;
2003 if (Mag > MaxRow) MaxRow = Mag;
2014 if (AbsColSum > MaxCol) MaxCol = AbsColSum;
2022 if (Mag > Max) Max = Mag;
2040 if (Mag > MaxRow) MaxRow = Mag;
2044 if (Mag > MaxRow) MaxRow = Mag;
2055 if (AbsColSum > MaxCol) MaxCol = AbsColSum;
2063 if (Mag > Max) Max = Mag;
2070 return MaxRow * MaxCol;
2100 register int Count,
I, MaxCount = 0;
2118 if (Count > MaxCount) MaxCount = Count;
2129 return (MACHINE_RESOLUTION * Rho * Gear);
2131 return (MACHINE_RESOLUTION * Rho * Reid);
ElementPtr spcFindElementInCol(MatrixPtr Matrix, ElementPtr *LastAddr, int Row, int Col, BOOLEAN CreateIfMissing)
#define spSEPARATED_COMPLEX_VECTORS
#define CMPLX_MULT_ADD_ASSIGN(to, from_a, from_b)
#define CMPLX_MULT_ASSIGN(to, from)
#define ALLOC(type, number)
struct MatrixFrame * MatrixPtr
#define CMPLX_MULT_SUBT(to, mult_a, mult_b, subt)
#define IS_FACTORED(matrix)
#define CMPLX_RECIPROCAL(to, den)
#define CMPLX_MULT_SUBT_ASSIGN(to, from_a, from_b)
struct ComplexNumber * ComplexVector
#define IS_SPARSE(matrix)
#define SCLR_MULT_ASSIGN(to, sclr)
register ElementPtr pElement
void spDeleteRowAndCol(char *eMatrix, int Row, int Col)
void spcRowExchange(MatrixPtr, int row1, int row2)
static void ScaleComplexMatrix()
RealNumber spCondition(char *eMatrix, RealNumber NormOfMatrix, int *pError)
if(NOT Matrix->RowsLinked) spcLinkRows(Matrix)
static void ComplexTransposedMatrixMultiply()
static RealNumber ComplexCondition()
void spcColExchange(MatrixPtr, int col1, int col2)
void spScale(char *eMatrix, RealVector RHS_ScaleFactors, RealVector SolutionScaleFactors)
RealNumber spLargestElement(char *eMatrix)
void spStripFills(char *eMatrix)
void spcLinkRows(MatrixPtr)
void spMNA_Preorder(char *eMatrix)
register RealVector Vector
void spMultTransposed(eMatrix, RHS, Solution IMAG_VECTORS) char *eMatrix
RealVector Solution IMAG_VECTORS
RealNumber spRoundoff(char *eMatrix, RealNumber Rho)
void spDeterminant(char *eMatrix, int *pExponent, RealNumber *pDeterminant, RealNumber *piDeterminant)
RealNumber spNorm(char *eMatrix)
void spMultiply(eMatrix, RHS, Solution IMAG_VECTORS) char *eMatrix
ASSERT(IS_SPARSE(Matrix) AND NOT Matrix->Factored)
static void ComplexMatrixMultiply()
RealNumber spPseudoCondition(char *eMatrix)
for(I=Matrix->Size;I, 0;I--)
int NumberOfFillinsInList
struct FillinListNodeStruct * Next
struct MatrixElement * NextInCol
struct MatrixElement * NextInRow
int MaxRowCountInLowerTri
ElementPtr NextAvailFillin
struct FillinListNodeStruct * FirstFillinListNode
BOOLEAN NumberOfInterchangesIsOdd
struct FillinListNodeStruct * LastFillinListNode
ArrayOfElementPtrs FirstInCol
ArrayOfElementPtrs FirstInRow