48 static char copyright[] =
49 "Sparse1.3: Copyright (c) 1985,86,87,88,89,90 by Kenneth S. Kundert";
51 "@(#)$Header: spFactor.c,v 1.3 88/06/24 05:01:12 kundert Exp $";
68 #define spINSIDE_SPARSE 230 int Step,
Size, ReorderingRequired;
239 if (RelThreshold <= 0.0) RelThreshold = Matrix->
RelThreshold;
240 if (RelThreshold > 1.0) RelThreshold = Matrix->
RelThreshold;
242 if (AbsThreshold < 0.0) AbsThreshold = Matrix->
AbsThreshold;
244 ReorderingRequired =
NO;
249 for (Step = 1; Step <=
Size; Step++)
250 { pPivot = Matrix->
Diag[Step];
252 if ((LargestInCol * RelThreshold <
ELEMENT_MAG(pPivot)))
259 { ReorderingRequired =
YES;
263 if (NOT ReorderingRequired)
272 #if (ANNOTATE >= ON_STRANGE_BEHAVIOR) 273 printf(
"Reordering, Step = %1d\n", Step);
291 return Matrix->
Error;
300 for (; Step <=
Size; Step++)
313 #if (ANNOTATE == FULL) 323 return Matrix->
Error;
371 register int Step,
Size;
379 0.0, 0.0, DIAG_PIVOTING_AS_DEFAULT );
393 for (Step = 2; Step <=
Size; Step++)
401 { Dest[pElement->
Row] = pElement->
Real;
407 while (pColumn->
Row < Step)
408 { pElement = Matrix->
Diag[pColumn->
Row];
409 pColumn->
Real = Dest[pColumn->
Row] * pElement->
Real;
411 Dest[pElement->
Row] -= pColumn->
Real * pElement->
Real;
417 while (pElement !=
NULL)
418 { pElement->
Real = Dest[pElement->
Row];
423 if (Dest[Step] == 0.0)
return ZeroPivot( Matrix, Step );
424 Matrix->
Diag[Step]->
Real = 1.0 / Dest[Step];
433 { pDest[pElement->
Row] = &pElement->
Real;
439 while (pColumn->
Row < Step)
440 { pElement = Matrix->
Diag[pColumn->
Row];
441 Mult = (*pDest[pColumn->
Row] *= pElement->
Real);
443 *pDest[pElement->
Row] -= Mult * pElement->
Real;
448 if (Matrix->
Diag[Step]->
Real == 0.0)
490 register int Step,
Size;
497 pElement = Matrix->Diag[1];
503 for (Step = 2; Step <=
Size; Step++)
504 {
if (Matrix->DoCmplxDirect[Step])
510 pElement = Matrix->FirstInCol[Step];
517 pColumn = Matrix->FirstInCol[Step];
518 while (pColumn->
Row < Step)
519 { pElement = Matrix->Diag[pColumn->
Row];
531 pElement = Matrix->Diag[Step]->
NextInCol;
532 while (pElement !=
NULL)
548 pElement = Matrix->FirstInCol[Step];
555 pColumn = Matrix->FirstInCol[Step];
556 while (pColumn->
Row < Step)
557 { pElement = Matrix->Diag[pColumn->
Row];
569 pElement = Matrix->Diag[Step];
575 Matrix->Factored =
YES;
576 return (Matrix->Error =
spOKAY);
630 register int Step,
Size;
631 register int *Nc, *No, *Nm;
632 BOOLEAN *DoRealDirect, *DoCmplxDirect;
645 {
for (Step = 1; Step <=
Size; Step++)
647 DoRealDirect[Step] =
YES;
650 DoCmplxDirect[Step] =
YES;
655 {
for (Step = 1; Step <=
Size; Step++)
657 DoRealDirect[Step] =
NO;
660 DoCmplxDirect[Step] =
NO;
672 for (Step = 1; Step <=
Size; Step++)
673 { Nc[Step] = No[Step] = Nm[Step] = 0;
676 while (pElement !=
NULL)
682 while (pColumn->
Row < Step)
683 { pElement = Matrix->
Diag[pColumn->
Row];
691 for (Step = 1; Step <=
Size; Step++)
708 DoRealDirect[Step] = (Nm[Step] + No[Step] > 3*Nc[Step] - 2*Nm[Step]);
712 DoCmplxDirect[Step] =
NO;
719 DoRealDirect[Step] = (Nm[Step] + No[Step] > 3*Nc[Step] - 2*Nm[Step]);
722 DoCmplxDirect[Step] = (Nm[Step] + No[Step] > 7*Nc[Step] - 4*Nm[Step]);
729 DoRealDirect[Step] = (Nm[Step] + No[Step] > 3*Nc[Step] - 2*Nm[Step]);
732 DoCmplxDirect[Step] = (Nm[Step] + No[Step] > 7*Nc[Step] - 4*Nm[Step]);
738 #if (ANNOTATE == FULL) 740 for (Step = 1; Step <=
Size; Step++)
742 printf(
"Operation count for inner loop of factorization = %d.\n", Ops);
782 if (Matrix->MarkowitzRow ==
NULL)
783 {
if (( Matrix->MarkowitzRow =
ALLOC(
int, Size+1)) ==
NULL)
786 if (Matrix->MarkowitzCol ==
NULL)
787 {
if (( Matrix->MarkowitzCol =
ALLOC(
int, Size+1)) ==
NULL)
790 if (Matrix->MarkowitzProd ==
NULL)
791 {
if (( Matrix->MarkowitzProd =
ALLOC(
long, Size+2)) ==
NULL)
797 if (Matrix->DoRealDirect ==
NULL)
803 if (Matrix->DoCmplxDirect ==
NULL)
811 if (Matrix->Intermediate ==
NULL)
816 if (Matrix->Intermediate ==
NULL)
823 Matrix->InternalVectorsAllocated =
YES;
867 register int Count,
I,
Size = Matrix->Size;
875 #if spSEPARATED_COMPLEX_VECTORS OR NOT spCOMPLEX 879 {
if (Matrix->Complex) RHS -= 2;
886 for (I = Step; I <=
Size; I++)
890 pElement = Matrix->FirstInRow[
I];
891 while (pElement !=
NULL AND pElement->
Col < Step)
893 while (pElement !=
NULL)
899 ExtRow = Matrix->IntToExtRowMap[
I];
901 #if spSEPARATED_COMPLEX_VECTORS OR NOT spCOMPLEX 903 if (RHS[ExtRow] != 0.0) Count++;
906 {
if (Matrix->Complex)
907 {
if ((RHS[2*ExtRow] != 0.0)
OR (RHS[2*ExtRow+1] != 0.0))
910 else if (RHS[I] != 0.0) Count++;
913 Matrix->MarkowitzRow[
I] = Count;
917 for (I = Step; I <=
Size; I++)
921 pElement = Matrix->FirstInCol[
I];
922 while (pElement !=
NULL AND pElement->
Row < Step)
924 while (pElement !=
NULL)
928 Matrix->MarkowitzCol[
I] = Count;
976 register int I, *pMarkowitzRow, *pMarkowitzCol;
977 register long Product, *pMarkowitzProduct;
978 register int Size = Matrix->Size;
982 Matrix->Singletons = 0;
984 pMarkowitzProduct = &(Matrix->MarkowitzProd[Step]);
985 pMarkowitzRow = &(Matrix->MarkowitzRow[Step]);
986 pMarkowitzCol = &(Matrix->MarkowitzCol[Step]);
988 for (I = Step; I <=
Size; I++)
991 if ((*pMarkowitzRow > LARGEST_SHORT_INTEGER
AND *pMarkowitzCol != 0)
OR 992 (*pMarkowitzCol > LARGEST_SHORT_INTEGER
AND *pMarkowitzRow != 0))
993 { fProduct = (double)(*pMarkowitzRow++) * (double)(*pMarkowitzCol++);
994 if (fProduct >= LARGEST_LONG_INTEGER)
995 *pMarkowitzProduct++ = LARGEST_LONG_INTEGER;
997 *pMarkowitzProduct++ = fProduct;
1000 { Product = *pMarkowitzRow++ * *pMarkowitzCol++;
1001 if ((*pMarkowitzProduct++ = Product) == 0)
1002 Matrix->Singletons++;
1061 int Step, DiagPivoting;
1072 if (Matrix->Singletons)
1074 if (ChosenPivot !=
NULL)
1075 { Matrix->PivotSelectionMethod =
's';
1080 #if DIAGONAL_PIVOTING 1090 if (ChosenPivot !=
NULL)
1091 { Matrix->PivotSelectionMethod =
'q';
1100 if (ChosenPivot !=
NULL)
1101 { Matrix->PivotSelectionMethod =
'd';
1109 Matrix->PivotSelectionMethod =
'e';
1166 register long *pMarkowitzProduct;
1172 pMarkowitzProduct = &(Matrix->MarkowitzProd[Matrix->Size+1]);
1173 Matrix->MarkowitzProd[Matrix->Size+1] = Matrix->MarkowitzProd[Step];
1177 Singletons = Matrix->Singletons--;
1184 Matrix->MarkowitzProd[Step-1] = 0;
1186 while (Singletons-- > 0)
1209 while ( *pMarkowitzProduct-- )
1217 I = pMarkowitzProduct - Matrix->MarkowitzProd + 1;
1220 if (I < Step)
break;
1221 if (I > Matrix->Size) I = Step;
1224 if ((ChosenPivot = Matrix->Diag[I]) !=
NULL)
1229 ( PivotMag > Matrix->AbsThreshold
AND 1230 PivotMag > Matrix->RelThreshold *
1231 FindBiggestInColExclude( Matrix, ChosenPivot, Step )
1232 )
return ChosenPivot;
1237 if (Matrix->MarkowitzCol[I] == 0)
1238 { ChosenPivot = Matrix->FirstInCol[
I];
1239 while ((ChosenPivot !=
NULL)
AND (ChosenPivot->
Row < Step))
1241 if (ChosenPivot !=
NULL)
1247 ( PivotMag > Matrix->AbsThreshold
AND 1248 PivotMag > Matrix->RelThreshold *
1249 FindBiggestInColExclude( Matrix, ChosenPivot,
1251 )
return ChosenPivot;
1253 {
if (Matrix->MarkowitzRow[I] == 0)
1254 { ChosenPivot = Matrix->FirstInRow[
I];
1255 while((ChosenPivot !=
NULL)
AND (ChosenPivot->
Col<Step))
1257 if (ChosenPivot !=
NULL)
1263 ( PivotMag > Matrix->AbsThreshold
AND 1264 PivotMag > Matrix->RelThreshold *
1265 FindBiggestInColExclude( Matrix,
1268 )
return ChosenPivot;
1273 { ChosenPivot = Matrix->FirstInRow[
I];
1274 while ((ChosenPivot !=
NULL)
AND (ChosenPivot->
Col < Step))
1276 if (ChosenPivot !=
NULL)
1282 ( PivotMag > Matrix->AbsThreshold
AND 1283 PivotMag > Matrix->RelThreshold *
1284 FindBiggestInColExclude( Matrix, ChosenPivot,
1286 )
return ChosenPivot;
1296 Matrix->Singletons++;
1311 #if DIAGONAL_PIVOTING 1312 #if MODIFIED_MARKOWITZ 1386 register long MinMarkowitzProduct, *pMarkowitzProduct;
1387 register ElementPtr pDiag, pOtherInRow, pOtherInCol;
1388 int I, NumberOfTies;
1389 ElementPtr ChosenPivot, TiedElements[MAX_MARKOWITZ_TIES + 1];
1390 RealNumber Magnitude, LargestInCol, Ratio, MaxRatio;
1396 MinMarkowitzProduct = LARGEST_LONG_INTEGER;
1397 pMarkowitzProduct = &(Matrix->MarkowitzProd[Matrix->Size+2]);
1398 Matrix->MarkowitzProd[Matrix->Size+1] = Matrix->MarkowitzProd[Step];
1401 Matrix->MarkowitzProd[Step-1] = -1;
1423 {
while (MinMarkowitzProduct < *(--pMarkowitzProduct))
1432 I = pMarkowitzProduct - Matrix->MarkowitzProd;
1435 if (I < Step)
break;
1436 if (I > Matrix->Size) I = Step;
1438 if ((pDiag = Matrix->Diag[I]) ==
NULL)
1440 if ((Magnitude =
ELEMENT_MAG(pDiag)) <= Matrix->AbsThreshold)
1443 if (*pMarkowitzProduct == 1)
1451 { pOtherInRow = Matrix->FirstInRow[
I];
1452 while(pOtherInRow !=
NULL)
1453 {
if (pOtherInRow->
Col >= Step
AND pOtherInRow->
Col != I)
1457 pOtherInCol = Matrix->FirstInCol[
I];
1458 while(pOtherInCol !=
NULL)
1459 {
if (pOtherInCol->
Row >= Step
AND pOtherInCol->
Row != I)
1468 {
if (pOtherInRow->
Col == pOtherInCol->
Row)
1471 if (Magnitude >= LargestOffDiagonal)
1480 if (*pMarkowitzProduct < MinMarkowitzProduct)
1483 TiedElements[0] = pDiag;
1484 MinMarkowitzProduct = *pMarkowitzProduct;
1490 if (NumberOfTies < MAX_MARKOWITZ_TIES)
1491 { TiedElements[++NumberOfTies] = pDiag;
1492 if (NumberOfTies >= MinMarkowitzProduct * TIES_MULTIPLIER)
1499 if (NumberOfTies < 0)
1504 MaxRatio = 1.0 / Matrix->RelThreshold;
1506 for (I = 0; I <= NumberOfTies; I++)
1507 { pDiag = TiedElements[
I];
1510 Ratio = LargestInCol / Magnitude;
1511 if (Ratio < MaxRatio)
1512 { ChosenPivot = pDiag;
1585 register long MinMarkowitzProduct, *pMarkowitzProduct;
1588 ElementPtr ChosenPivot, pOtherInRow, pOtherInCol;
1589 RealNumber Magnitude, LargestInCol, LargestOffDiagonal;
1594 MinMarkowitzProduct = LARGEST_LONG_INTEGER;
1595 pMarkowitzProduct = &(Matrix->MarkowitzProd[Matrix->Size+2]);
1596 Matrix->MarkowitzProd[Matrix->Size+1] = Matrix->MarkowitzProd[Step];
1599 Matrix->MarkowitzProd[Step-1] = -1;
1621 {
while (*(--pMarkowitzProduct) >= MinMarkowitzProduct)
1625 I = pMarkowitzProduct - Matrix->MarkowitzProd;
1628 if (I < Step)
break;
1629 if (I > Matrix->Size) I = Step;
1631 if ((pDiag = Matrix->Diag[I]) ==
NULL)
1633 if ((Magnitude =
ELEMENT_MAG(pDiag)) <= Matrix->AbsThreshold)
1636 if (*pMarkowitzProduct == 1)
1644 { pOtherInRow = Matrix->FirstInRow[
I];
1645 while(pOtherInRow !=
NULL)
1646 {
if (pOtherInRow->
Col >= Step
AND pOtherInRow->
Col != I)
1650 pOtherInCol = Matrix->FirstInCol[
I];
1651 while(pOtherInCol !=
NULL)
1652 {
if (pOtherInCol->
Row >= Step
AND pOtherInCol->
Row != I)
1661 {
if (pOtherInRow->
Col == pOtherInCol->
Row)
1664 if (Magnitude >= LargestOffDiagonal)
1673 MinMarkowitzProduct = *pMarkowitzProduct;
1674 ChosenPivot = pDiag;
1677 if (ChosenPivot !=
NULL)
1679 if(
ELEMENT_MAG(ChosenPivot) <= Matrix->RelThreshold * LargestInCol )
1751 register long MinMarkowitzProduct, *pMarkowitzProduct;
1754 int NumberOfTies,
Size = Matrix->Size;
1756 RealNumber Magnitude, Ratio, RatioOfAccepted, LargestInCol;
1761 MinMarkowitzProduct = LARGEST_LONG_INTEGER;
1762 pMarkowitzProduct = &(Matrix->MarkowitzProd[Size+2]);
1763 Matrix->MarkowitzProd[Size+1] = Matrix->MarkowitzProd[Step];
1766 for (J = Size+1; J > Step; J--)
1768 if (*(--pMarkowitzProduct) > MinMarkowitzProduct)
1770 if (J > Matrix->Size)
1774 if ((pDiag = Matrix->Diag[I]) ==
NULL)
1776 if ((Magnitude =
ELEMENT_MAG(pDiag)) <= Matrix->AbsThreshold)
1781 if (Magnitude <= Matrix->RelThreshold * LargestInCol)
1784 if (*pMarkowitzProduct < MinMarkowitzProduct)
1787 ChosenPivot = pDiag;
1788 MinMarkowitzProduct = *pMarkowitzProduct;
1789 RatioOfAccepted = LargestInCol / Magnitude;
1796 Ratio = LargestInCol / Magnitude;
1797 if (Ratio < RatioOfAccepted)
1798 { ChosenPivot = pDiag;
1799 RatioOfAccepted = Ratio;
1801 if (NumberOfTies >= MinMarkowitzProduct * TIES_MULTIPLIER)
1879 register int I,
Size = Matrix->Size;
1882 long Product, MinMarkowitzProduct;
1884 RealNumber Magnitude, LargestElementMag, Ratio, RatioOfAccepted, LargestInCol;
1889 LargestElementMag = 0.0;
1890 MinMarkowitzProduct = LARGEST_LONG_INTEGER;
1893 for (I = Step; I <=
Size; I++)
1894 { pElement = Matrix->FirstInCol[
I];
1896 while (pElement !=
NULL AND pElement->
Row < Step)
1902 while (pElement !=
NULL)
1906 if ((Magnitude =
ELEMENT_MAG(pElement)) > LargestElementMag)
1907 { LargestElementMag = Magnitude;
1911 Product = Matrix->MarkowitzRow[pElement->
Row] *
1912 Matrix->MarkowitzCol[pElement->
Col];
1915 if ((Product <= MinMarkowitzProduct)
AND 1916 (Magnitude > Matrix->RelThreshold * LargestInCol)
AND 1917 (Magnitude > Matrix->AbsThreshold))
1921 if (Product < MinMarkowitzProduct)
1925 MinMarkowitzProduct = Product;
1926 RatioOfAccepted = LargestInCol / Magnitude;
1933 Ratio = LargestInCol / Magnitude;
1934 if (Ratio < RatioOfAccepted)
1936 RatioOfAccepted = Ratio;
1938 if (NumberOfTies >= MinMarkowitzProduct * TIES_MULTIPLIER)
1946 if (ChosenPivot !=
NULL)
return ChosenPivot;
1948 if (LargestElementMag == 0.0)
1954 return pLargestElement;
2006 while (pElement !=
NULL)
2007 {
if ((Magnitude =
ELEMENT_MAG(pElement)) > Largest)
2008 Largest = Magnitude;
2075 Row = pElement->
Row;
2076 Col = pElement->Col;
2077 pElement = Matrix->FirstInCol[Col];
2080 while ((pElement !=
NULL)
AND (pElement->Row < Step))
2081 pElement = pElement->NextInCol;
2084 if (pElement->Row != Row)
2090 while ((pElement = pElement->NextInCol) !=
NULL)
2091 {
if ((Magnitude =
ELEMENT_MAG(pElement)) > Largest)
2092 {
if (pElement->Row != Row)
2093 Largest = Magnitude;
2147 register int Row, Col;
2148 long OldMarkowitzProd_Step, OldMarkowitzProd_Row, OldMarkowitzProd_Col;
2154 Matrix->PivotsOriginalRow = Row;
2155 Matrix->PivotsOriginalCol = Col;
2157 if ((Row == Step)
AND (Col == Step))
return;
2163 SWAP(
long, Matrix->MarkowitzProd[Step], Matrix->MarkowitzProd[Row] );
2170 OldMarkowitzProd_Step = Matrix->MarkowitzProd[Step];
2171 OldMarkowitzProd_Row = Matrix->MarkowitzProd[Row];
2172 OldMarkowitzProd_Col = Matrix->MarkowitzProd[Col];
2177 Matrix->NumberOfInterchangesIsOdd =
2178 NOT Matrix->NumberOfInterchangesIsOdd;
2179 Matrix->MarkowitzProd[Row] = Matrix->MarkowitzRow[Row] *
2180 Matrix->MarkowitzCol[Row];
2183 if ((Matrix->MarkowitzProd[Row]==0) != (OldMarkowitzProd_Row==0))
2184 {
if (OldMarkowitzProd_Row == 0)
2185 Matrix->Singletons--;
2187 Matrix->Singletons++;
2194 Matrix->NumberOfInterchangesIsOdd =
2195 NOT Matrix->NumberOfInterchangesIsOdd;
2196 Matrix->MarkowitzProd[Col] = Matrix->MarkowitzCol[Col] *
2197 Matrix->MarkowitzRow[Col];
2200 if ((Matrix->MarkowitzProd[Col]==0) != (OldMarkowitzProd_Col==0))
2201 {
if (OldMarkowitzProd_Col == 0)
2202 Matrix->Singletons--;
2204 Matrix->Singletons++;
2208 Matrix->FirstInCol+Col,
2213 Matrix->FirstInCol+Row,
2217 Matrix->FirstInCol+Step,
2221 Matrix->MarkowitzProd[Step] = Matrix->MarkowitzCol[Step] *
2222 Matrix->MarkowitzRow[Step];
2223 if ((Matrix->MarkowitzProd[Step]==0) != (OldMarkowitzProd_Step==0))
2224 {
if (OldMarkowitzProd_Step == 0)
2225 Matrix->Singletons--;
2227 Matrix->Singletons++;
2281 if (Row1 > Row2)
SWAP(
int, Row1, Row2);
2283 Row1Ptr = Matrix->FirstInRow[Row1];
2284 Row2Ptr = Matrix->FirstInRow[Row2];
2288 if (Row1Ptr ==
NULL)
2289 { Column = Row2Ptr->
Col;
2294 else if (Row2Ptr ==
NULL)
2295 { Column = Row1Ptr->
Col;
2300 else if (Row1Ptr->
Col < Row2Ptr->
Col)
2301 { Column = Row1Ptr->
Col;
2306 else if (Row1Ptr->
Col > Row2Ptr->
Col)
2307 { Column = Row2Ptr->
Col;
2313 { Column = Row1Ptr->
Col;
2323 if (Matrix->InternalVectorsAllocated)
2324 SWAP(
int, Matrix->MarkowitzRow[Row1], Matrix->MarkowitzRow[Row2]);
2325 SWAP(
ElementPtr, Matrix->FirstInRow[Row1], Matrix->FirstInRow[Row2]);
2326 SWAP(
int, Matrix->IntToExtRowMap[Row1], Matrix->IntToExtRowMap[Row2]);
2328 Matrix->ExtToIntRowMap[ Matrix->IntToExtRowMap[Row1] ] = Row1;
2329 Matrix->ExtToIntRowMap[ Matrix->IntToExtRowMap[Row2] ] = Row2;
2383 if (Col1 > Col2)
SWAP(
int, Col1, Col2);
2385 Col1Ptr = Matrix->FirstInCol[Col1];
2386 Col2Ptr = Matrix->FirstInCol[Col2];
2390 if (Col1Ptr ==
NULL)
2391 { Row = Col2Ptr->
Row;
2396 else if (Col2Ptr ==
NULL)
2397 { Row = Col1Ptr->
Row;
2402 else if (Col1Ptr->
Row < Col2Ptr->
Row)
2403 { Row = Col1Ptr->
Row;
2408 else if (Col1Ptr->
Row > Col2Ptr->
Row)
2409 { Row = Col2Ptr->
Row;
2415 { Row = Col1Ptr->
Row;
2425 if (Matrix->InternalVectorsAllocated)
2426 SWAP(
int, Matrix->MarkowitzCol[Col1], Matrix->MarkowitzCol[Col2]);
2427 SWAP(
ElementPtr, Matrix->FirstInCol[Col1], Matrix->FirstInCol[Col2]);
2428 SWAP(
int, Matrix->IntToExtColMap[Col1], Matrix->IntToExtColMap[Col2]);
2430 Matrix->ExtToIntColMap[ Matrix->IntToExtColMap[Col1] ] = Col1;
2431 Matrix->ExtToIntColMap[ Matrix->IntToExtColMap[Col2] ] = Col2;
2484 int Row1, Row2, Column;
2486 ElementPtr *ElementAboveRow1, *ElementAboveRow2;
2487 ElementPtr ElementBelowRow1, ElementBelowRow2;
2492 ElementAboveRow1 = &(Matrix->FirstInCol[Column]);
2493 pElement = *ElementAboveRow1;
2494 while (pElement->
Row < Row1)
2495 { ElementAboveRow1 = &(pElement->
NextInCol);
2496 pElement = *ElementAboveRow1;
2498 if (Element1 !=
NULL)
2499 { ElementBelowRow1 = Element1->
NextInCol;
2500 if (Element2 ==
NULL)
2503 if ( ElementBelowRow1 !=
NULL AND ElementBelowRow1->
Row < Row2 )
2506 *ElementAboveRow1 = ElementBelowRow1;
2509 pElement = ElementBelowRow1;
2511 { ElementAboveRow2 = &(pElement->
NextInCol);
2512 pElement = *ElementAboveRow2;
2513 }
while (pElement !=
NULL AND pElement->
Row < Row2);
2518 *ElementAboveRow1 =ElementBelowRow1;
2520 Element1->
Row = Row2;
2525 if ( ElementBelowRow1->
Row == Row2)
2528 Element1->NextInCol = Element2->NextInCol;
2535 pElement = ElementBelowRow1;
2537 { ElementAboveRow2 = &(pElement->
NextInCol);
2538 pElement = *ElementAboveRow2;
2539 }
while (pElement->
Row < Row2);
2545 Element2->NextInCol = ElementBelowRow1;
2547 Element1->NextInCol = ElementBelowRow2;
2549 Element1->
Row = Row2;
2550 Element2->Row = Row1;
2559 if (ElementBelowRow1->
Row != Row2)
2561 { ElementAboveRow2 = &(pElement->
NextInCol);
2562 pElement = *ElementAboveRow2;
2563 }
while (pElement->
Row < Row2);
2568 *ElementAboveRow2 = Element2->
NextInCol;
2570 Element2->NextInCol = ElementBelowRow1;
2572 Element2->
Row = Row1;
2625 int Col1, Col2, Row;
2628 ElementPtr *ElementLeftOfCol1, *ElementLeftOfCol2;
2629 ElementPtr ElementRightOfCol1, ElementRightOfCol2;
2634 ElementLeftOfCol1 = &(Matrix->FirstInRow[Row]);
2635 pElement = *ElementLeftOfCol1;
2636 while (pElement->
Col < Col1)
2637 { ElementLeftOfCol1 = &(pElement->
NextInRow);
2638 pElement = *ElementLeftOfCol1;
2640 if (Element1 !=
NULL)
2641 { ElementRightOfCol1 = Element1->
NextInRow;
2642 if (Element2 ==
NULL)
2645 if ( ElementRightOfCol1 !=
NULL AND ElementRightOfCol1->
Col < Col2 )
2648 *ElementLeftOfCol1 = ElementRightOfCol1;
2651 pElement = ElementRightOfCol1;
2653 { ElementLeftOfCol2 = &(pElement->
NextInRow);
2654 pElement = *ElementLeftOfCol2;
2655 }
while (pElement !=
NULL AND pElement->
Col < Col2);
2660 *ElementLeftOfCol1 =ElementRightOfCol1;
2662 Element1->
Col = Col2;
2667 if ( ElementRightOfCol1->
Col == Col2)
2670 Element1->NextInRow = Element2->NextInRow;
2677 pElement = ElementRightOfCol1;
2679 { ElementLeftOfCol2 = &(pElement->
NextInRow);
2680 pElement = *ElementLeftOfCol2;
2681 }
while (pElement->
Col < Col2);
2683 ElementRightOfCol2 = Element2->
NextInRow;
2687 Element2->NextInRow = ElementRightOfCol1;
2689 Element1->NextInRow = ElementRightOfCol2;
2691 Element1->
Col = Col2;
2692 Element2->Col = Col1;
2701 if (ElementRightOfCol1->
Col != Col2)
2703 { ElementLeftOfCol2 = &(pElement->
NextInRow);
2704 pElement = *ElementLeftOfCol2;
2705 }
while (pElement->
Col < Col2);
2707 ElementRightOfCol2 = Element2->
NextInRow;
2710 *ElementLeftOfCol2 = Element2->
NextInRow;
2712 Element2->NextInRow = ElementRightOfCol1;
2714 Element2->
Col = Col1;
2771 if (
ABS(pPivot->Real) == 0.0)
2775 pPivot->Real = 1.0 / pPivot->Real;
2778 while (pUpper !=
NULL)
2781 pUpper->
Real *= pPivot->Real;
2785 while (pLower !=
NULL)
2786 { Row = pLower->
Row;
2867 while (pUpper !=
NULL)
2875 while (pLower !=
NULL)
2876 { Row = pLower->
Row;
2935 register int Row, Col;
2937 register int *MarkoRow = Matrix->MarkowitzRow, *MarkoCol = Matrix->MarkowitzCol;
2944 { Row = ColPtr->
Row;
2948 if ((MarkoRow[Row] > LARGEST_SHORT_INTEGER
AND MarkoCol[Row] != 0)
OR 2949 (MarkoCol[Row] > LARGEST_SHORT_INTEGER
AND MarkoRow[Row] != 0))
2950 { Product = MarkoCol[Row] * MarkoRow[Row];
2951 if (Product >= LARGEST_LONG_INTEGER)
2952 Matrix->MarkowitzProd[Row] = LARGEST_LONG_INTEGER;
2954 Matrix->MarkowitzProd[Row] = Product;
2956 else Matrix->MarkowitzProd[Row] = MarkoRow[Row] * MarkoCol[Row];
2957 if (MarkoRow[Row] == 0)
2958 Matrix->Singletons++;
2962 { Col = RowPtr->
Col;
2966 if ((MarkoRow[Col] > LARGEST_SHORT_INTEGER
AND MarkoCol[Col] != 0)
OR 2967 (MarkoCol[Col] > LARGEST_SHORT_INTEGER
AND MarkoRow[Col] != 0))
2968 { Product = MarkoCol[Col] * MarkoRow[Col];
2969 if (Product >= LARGEST_LONG_INTEGER)
2970 Matrix->MarkowitzProd[Col] = LARGEST_LONG_INTEGER;
2972 Matrix->MarkowitzProd[Col] = Product;
2974 else Matrix->MarkowitzProd[Col] = MarkoRow[Col] * MarkoCol[Col];
2975 if ((MarkoCol[Col] == 0)
AND (MarkoRow[Col] != 0))
2976 Matrix->Singletons++;
3030 ppElementAbove = &Matrix->FirstInCol[Col];
3031 pElement = *ppElementAbove;
3032 while (pElement !=
NULL)
3033 {
if (pElement->
Row < Row)
3034 { ppElementAbove = &pElement->
NextInCol;
3035 pElement = *ppElementAbove;
3044 Matrix->MarkowitzProd[Row] = ++Matrix->MarkowitzRow[Row] *
3045 Matrix->MarkowitzCol[Row];
3046 if ((Matrix->MarkowitzRow[Row] == 1)
AND (Matrix->MarkowitzCol[Row] != 0))
3047 Matrix->Singletons--;
3048 Matrix->MarkowitzProd[Col] = ++Matrix->MarkowitzCol[Col] *
3049 Matrix->MarkowitzRow[Col];
3050 if ((Matrix->MarkowitzRow[Col] != 0)
AND (Matrix->MarkowitzCol[Col] == 1))
3051 Matrix->Singletons--;
3087 Matrix->
SingularRow = Matrix->IntToExtRowMap[ Step ];
3088 Matrix->SingularCol = Matrix->IntToExtColMap[ Step ];
3101 Matrix->
SingularRow = Matrix->IntToExtRowMap[ Step ];
3102 Matrix->SingularCol = Matrix->IntToExtColMap[ Step ];
3111 #if (ANNOTATE == FULL) 3130 printf(
"Step = %1d ", Step);
3131 printf(
"Pivot found at %1d,%1d using ", Matrix->PivotsOriginalRow,
3132 Matrix->PivotsOriginalCol);
3133 switch(Matrix->PivotSelectionMethod)
3134 {
case 's': printf(
"SearchForSingleton\n");
break;
3135 case 'q': printf(
"QuicklySearchDiagonal\n");
break;
3136 case 'd': printf(
"SearchDiagonal\n");
break;
3137 case 'e': printf(
"SearchEntireMatrix\n");
break;
3140 printf(
"MarkowitzRow = ");
3141 for (I = 1; I <= Matrix->Size; I++)
3142 printf(
"%2d ", Matrix->MarkowitzRow[I]);
3145 printf(
"MarkowitzCol = ");
3146 for (I = 1; I <= Matrix->Size; I++)
3147 printf(
"%2d ", Matrix->MarkowitzCol[I]);
3150 printf(
"MarkowitzProduct = ");
3151 for (I = 1; I <= Matrix->Size; I++)
3152 printf(
"%2d ", Matrix->MarkowitzProd[I]);
3155 printf(
"Singletons = %2d\n", Matrix->Singletons);
3157 printf(
"IntToExtRowMap = ");
3158 for (I = 1; I <= Matrix->Size; I++)
3159 printf(
"%2d ", Matrix->IntToExtRowMap[I]);
3162 printf(
"IntToExtColMap = ");
3163 for (I = 1; I <= Matrix->Size; I++)
3164 printf(
"%2d ", Matrix->IntToExtColMap[I]);
3167 printf(
"ExtToIntRowMap = ");
3168 for (I = 1; I <= Matrix->ExtSize; I++)
3169 printf(
"%2d ", Matrix->ExtToIntRowMap[I]);
3172 printf(
"ExtToIntColMap = ");
3173 for (I = 1; I <= Matrix->ExtSize; I++)
3174 printf(
"%2d ", Matrix->ExtToIntColMap[I]);
#define CMPLX_MULT_ASSIGN(to, from)
static RealNumber FindBiggestInColExclude()
void spcRowExchange(MatrixPtr Matrix, int Row1, int Row2)
#define spDEFAULT_PARTITION
#define ALLOC(type, number)
#define CMPLX_ASSIGN(to, from)
#define spINDIRECT_PARTITION
static void CountMarkowitz()
void spcColExchange(MatrixPtr Matrix, int Col1, int Col2)
static RealNumber FindLargestInCol()
#define spDIRECT_PARTITION
This document describes the JSPICE3 Josephson junction model I derivation of the model The expression for the junction current is J
static int MatrixIsSingular()
#define IS_SPARSE(matrix)
static void ExchangeRowsAndCols()
static void ExchangeRowElements()
static int FactorComplexMatrix()
#define CMPLX_MULT_SUBT_ASSIGN(to, from_a, from_b)
struct MatrixElement * NextInCol
static ElementPtr SearchEntireMatrix()
static void RealRowColElimination()
ElementPtr spcCreateElement()
ASSERT(IS_VALID(Matrix) AND IS_FACTORED(Matrix))
static ElementPtr SearchDiagonal()
register ElementPtr pElement
static void ComplexRowColElimination()
static void UpdateMarkowitzNumbers()
static ElementPtr SearchForPivot()
ElementPtr spcFindElementInCol()
void spcCreateInternalVectors(MatrixPtr Matrix)
static void ExchangeColElements()
static ElementPtr SearchForSingleton()
while(TDesc->tSucc!=NULL)
static void WriteStatus()
BOOLEAN InternalVectorsAllocated
int spOrderAndFactor(char *eMatrix, RHS, RelThreshold, AbsThreshold, BOOLEAN DiagPivoting)
struct MatrixElement * NextInRow
struct MatrixFrame * MatrixPtr
#define CMPLX_MULT(to, from_a, from_b)
int MaxRowCountInLowerTri
static ElementPtr CreateFillin()
int spFactor(char *eMatrix)
ArrayOfElementPtrs FirstInCol
void spPartition(char *eMatrix, int Mode)
static ElementPtr QuicklySearchDiagonal()
#define CMPLX_RECIPROCAL(to, den)
static void MarkowitzProducts()