2 #include <../../nrnconf.h> 42 "Sparse1.3: Copyright (c) 1985,86,87,88 by Kenneth S. Kundert";
62 #define spINSIDE_SPARSE 144 spPrint( eMatrix, PrintReordered, Data, Header )
147 int PrintReordered, Data, Header;
151 int I, Row, Col,
Size, Top, StartCol = 1, StopCol, Columns, ElementCount = 0;
152 double Magnitude, SmallestDiag, SmallestElement;
153 double LargestElement = 0.0, LargestDiag = 0.0;
155 int *PrintOrdToIntRowMap, *PrintOrdToIntColMap;
167 CALLOC( PrintOrdToIntRowMap,
int, Top + 1 );
168 CALLOC( PrintOrdToIntColMap,
int, Top + 1 );
169 if ( PrintOrdToIntRowMap ==
NULL OR PrintOrdToIntColMap ==
NULL)
173 for (I = 1; I <=
Size; I++)
179 for (J = 1, I = 1; I <= Top; I++)
180 {
if (PrintOrdToIntRowMap[I] != 0)
181 PrintOrdToIntRowMap[ J++ ] = PrintOrdToIntRowMap[
I ];
183 for (J = 1, I = 1; I <= Top; I++)
184 {
if (PrintOrdToIntColMap[I] != 0)
185 PrintOrdToIntColMap[ J++ ] = PrintOrdToIntColMap[
I ];
190 {
printf(
"MATRIX SUMMARY\n\n");
191 printf(
"Size of matrix = %1u x %1u.\n", Size, Size);
193 printf(
"Matrix has been reordered.\n");
197 printf(
"Matrix after factorization:\n");
199 printf(
"Matrix before factorization:\n");
201 SmallestElement = LARGEST_REAL;
202 SmallestDiag = SmallestElement;
206 Columns = PRINTER_WIDTH;
207 if (Header) Columns -= 5;
208 if (Data) Columns = (Columns+1) / 10;
218 { StopCol = StartCol + Columns - 1;
226 for (I = StartCol; I <= StopCol; I++)
227 {
if (PrintReordered)
230 Col = PrintOrdToIntColMap[
I];
236 {
if (PrintReordered)
237 printf(
"Columns %1d to %1d.\n",StartCol,StopCol);
239 {
printf(
"Columns %1d to %1d.\n",
247 for (I = 1; I <=
Size; I++)
248 {
if (PrintReordered)
251 Row = PrintOrdToIntRowMap[
I];
254 {
if (PrintReordered
AND NOT Data)
262 for (J = StartCol; J <= StopCol; J++)
263 {
if (PrintReordered)
266 Col = PrintOrdToIntColMap[J];
269 while(pElement !=
NULL AND pElement->
Row != Row)
273 pImagElements[J - StartCol] =
pElement;
275 if (pElement !=
NULL)
284 if ( (Magnitude =
ELEMENT_MAG(pElement)) > LargestElement )
285 LargestElement = Magnitude;
286 if ((Magnitude < SmallestElement)
AND (Magnitude != 0.0))
287 SmallestElement = Magnitude;
304 for (J = StartCol; J <= StopCol; J++)
305 {
if (pImagElements[J - StartCol] !=
NULL)
307 (
double)pImagElements[J-StartCol]->Imag);
322 {
printf(
"\nLargest element in matrix = %-1.4lg.\n", LargestElement);
323 printf(
"Smallest element in matrix = %-1.4lg.\n", SmallestElement);
326 for (I = 1; I <=
Size; I++)
329 if ( Magnitude > LargestDiag ) LargestDiag = Magnitude;
330 if ( Magnitude < SmallestDiag ) SmallestDiag = Magnitude;
336 {
printf(
"\nLargest diagonal element = %-1.4lg.\n", LargestDiag);
337 printf(
"Smallest diagonal element = %-1.4lg.\n", SmallestDiag);
340 {
printf(
"\nLargest pivot element = %-1.4lg.\n", LargestDiag);
341 printf(
"Smallest pivot element = %-1.4lg.\n", SmallestDiag);
345 printf(
"\nDensity = %2.2lf%%.\n", ((
double)(ElementCount * 100)) /
346 ((
double)(Size * Size)));
351 (
void)fflush(stdout);
353 FREE(PrintOrdToIntColMap);
354 FREE(PrintOrdToIntRowMap);
414 int Reordered, Data, Header;
417 register int I,
Size;
435 "Warning : The following matrix is factored in to LU form.\n" 438 if (Err < 0)
return 0;
440 Err =
fprintf( pMatrixFile,
"%d\t%s\n", Size,
441 (Matrix->
Complex ?
"complex" :
"real"));
442 if (Err < 0)
return 0;
447 {
for (I = 1; I <=
Size; I++)
449 while (pElement !=
NULL)
451 { Row = pElement->
Row;
459 if (
fprintf(pMatrixFile,
"%d\t%d\n", Row, Col) < 0)
return 0;
464 if (
fprintf(pMatrixFile,
"0\t0\n") < 0)
return 0;
469 {
for (I = 1; I <=
Size; I++)
471 while (pElement !=
NULL)
473 { Row = pElement->
Row;
481 ( pMatrixFile,
"%d\t%d\t%-.15lg\t%-.15lg\n",
482 Row, Col, (
double)pElement->
Real, (
double)pElement->Imag
484 if (Err < 0)
return 0;
490 if (
fprintf(pMatrixFile,
"0\t0\t0.0\t0.0\n") < 0)
return 0;
497 {
for (I = 1; I <=
Size; I++)
499 while (pElement !=
NULL)
503 ( pMatrixFile,
"%d\t%d\t%-.15lg\n",
504 Row, Col, (
double)pElement->
Real 506 if (Err < 0)
return 0;
512 if (
fprintf(pMatrixFile,
"0\t0\t0.0\n") < 0)
return 0;
518 if (fclose(pMatrixFile) < 0)
return 0;
588 #if spSEPARATED_COMPLEX_VECTORS 607 #if spSEPARATED_COMPLEX_VECTORS 611 (
double)
RHS[
I], (
double)iRHS[I]
613 if (
Err < 0)
return 0;
619 (
double)
RHS[2*
I], (
double)
RHS[2*I+1]
621 if (
Err < 0)
return 0;
626 #if REAL AND spCOMPLEX 692 register int Size,
I;
694 int NumberOfElements;
695 RealNumber Data, LargestElement, SmallestElement;
696 FILE *pStatsFile, *
fopen();
702 if ((pStatsFile =
fopen(File,
"a")) ==
NULL)
708 fprintf(pStatsFile,
"Matrix has not been factored.\n");
709 fprintf(pStatsFile,
"||| Starting new matrix |||\n");
710 fprintf(pStatsFile,
"%s\n", Label);
712 fprintf(pStatsFile,
"Matrix is complex.\n");
714 fprintf(pStatsFile,
"Matrix is real.\n");
715 fprintf(pStatsFile,
" Size = %d\n",Size);
718 NumberOfElements = 0;
719 LargestElement = 0.0;
720 SmallestElement = LARGEST_REAL;
722 for (I = 1; I <=
Size; I++)
724 while (pElement !=
NULL)
725 { NumberOfElements++;
727 if (Data > LargestElement)
728 LargestElement = Data;
729 if (Data < SmallestElement
AND Data != 0.0)
730 SmallestElement = Data;
735 SmallestElement =
MIN( SmallestElement, LargestElement );
738 fprintf(pStatsFile,
" Initial number of elements = %d\n",
739 NumberOfElements - Matrix->
Fillins);
741 " Initial average number of elements per row = %lf\n",
742 (
double)(NumberOfElements - Matrix->
Fillins) / (
double)Size);
744 fprintf(pStatsFile,
" Average number of fill-ins per row = %lf%%\n",
745 (
double)Matrix->
Fillins / (
double)Size);
746 fprintf(pStatsFile,
" Total number of elements = %d\n",
748 fprintf(pStatsFile,
" Average number of elements per row = %lf\n",
749 (
double)NumberOfElements / (
double)Size);
750 fprintf(pStatsFile,
" Density = %lf%%\n",
751 (
double)(100.0*NumberOfElements)/(
double)(Size*Size));
754 fprintf(pStatsFile,
" Largest Element = %e\n", LargestElement);
755 fprintf(pStatsFile,
" Smallest Element = %e\n\n\n", SmallestElement);
758 (
void)fclose(pStatsFile);
int spFileVector(eMatrix, File, RHS IMAG_RHS) char *eMatrix
ArrayOfElementPtrs FirstInCol
if((pMatrixFile=fopen(File,"a"))==NULL)
#define IS_SPARSE(matrix)
void spPrint(char *eMatrix, int PrintReordered, int Data, int Header)
#define CALLOC(ptr, type, number)
register ElementPtr pElement
#define ASSERT(condition)
fprintf(stderr, "Don't know the location of params at %p\, pp)
int spFileMatrix(char *eMatrix, char *File, char *Label, int Reordered, int Data, int Header)
struct MatrixFrame * MatrixPtr
struct MatrixElement * NextInCol