00001
00002
00003 #include "SkyLineMtx.h"
00004
00005 DSS_NAMESPASE_BEGIN
00006
00007
00008
00009 SkyLineMtx::SkyLineMtx(SparseMatrixF& sm,Ordering* order,MathTracer* eMT)
00010 {
00011 this->n = sm.neq;
00012 this->nonzeros = 0;
00013 this->eMT = eMT;
00014 this->order = order;
00015 this->column_starts = NULL;
00016 this->columndata = NULL;
00017 this->D = NULL;
00018 }
00019
00020 SkyLineMtx::~SkyLineMtx()
00021 {
00022 }
00023
00024 void SkyLineMtx::GrowSkyline(int i, int j,long* column_ns)
00025 {
00026 if (i>j)
00027 {
00028 int l = i-j;
00029 if (column_ns[i]<l)
00030 column_ns[i] = l;
00031 }
00032 else
00033 {
00034 int l = j-i;
00035 if (column_ns[j]<l)
00036 column_ns[j] = l;
00037 }
00038 }
00039
00040
00041 void SkyLineMtx::AllocateMemory(IConectMatrix* spm,int neq)
00042 {
00043 long* perm = order->perm->Items;
00044 column_starts = new int[n+1];
00045 long* column_ns = new long[n];
00046 D = new double[n];
00047
00048 for (int j=0; j<n; j++)
00049 {
00050 IntArrayList* ColumnIndexes = spm->GetIndexesAboveDiagonalInColumn(j);
00051 int nj = perm!=NULL?perm[j]:j;
00052 if (nj>=neq) continue;
00053
00054 int cnt = ColumnIndexes->Count;
00055 for (int idx = 0; idx<cnt; idx++)
00056 {
00057 int ni = perm!=NULL?perm[ColumnIndexes->Items[idx]]:ColumnIndexes->Items[idx];
00058 if (ni>=neq) continue;
00059 GrowSkyline(ni,nj,column_ns);
00060 }
00061 }
00062
00063 long column_field_lenght = 0;
00064 for (int j=0; j<n; j++)
00065 {
00066 column_starts[j] = column_field_lenght;
00067 column_field_lenght += column_ns[j];
00068 }
00069 columns_data_length = column_starts[n] = column_field_lenght;
00070
00071 if (column_field_lenght==0)
00072 column_field_lenght = 1;
00073 columndata = new double[column_field_lenght];
00074
00075 delete column_ns;
00076 }
00077
00078 void SkyLineMtx::WriteStatistics(long no_init_blocks,long no_nonzeros)
00079 {
00080 char str[512];
00081
00082 sprintf(str," number of nonzeros : %ld",Nonzeros());
00083 eMT->Writeln(str);
00084 }
00085
00086 DSS_NAMESPASE_END