00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #define spINSIDE_SPARSE
00032 #include "spConfig.h"
00033 #include "spmatrix.h"
00034 #include "spDefs.h"
00035
00036
00037 #include "machine.h"
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 static void
00056 spFixThresold(eMatrix,eps,releps)
00057 char *eMatrix;
00058 double eps,releps;
00059 {
00060 MatrixPtr Matrix = (MatrixPtr)eMatrix;
00061 Matrix->AbsThreshold = eps;
00062 Matrix->RelThreshold = releps;
00063 }
00064
00065
00066 static void
00067 spGetNumRank(eMatrix,n)
00068 char *eMatrix;
00069 int *n;
00070 {
00071 MatrixPtr Matrix = (MatrixPtr)eMatrix;
00072 *n = Matrix->NumRank;
00073 }
00074
00075 extern void cerro();
00076
00077 void
00078 C2F(lufact1)(val,lln,col,n,nel,fmat,eps,releps,nrank,ierr)
00079 double *val,*eps,*releps;
00080 long *fmat;
00081 int *n,*nel,*nrank,*lln,*col,*ierr;
00082 {
00083 int error,i,i0,i1,k,j;
00084 spREAL *pelement;
00085 *ierr = 0;
00086 *fmat = (long)spCreate(*n,0,&error);
00087 if (error != spOKAY) {
00088 *ierr = 1;
00089 return;
00090 }
00091
00092
00093 i0=0;
00094 i1=i0;
00095 i=1;
00096 for (k = 0 ;k < *nel; k++) {
00097 i0=i0+1;
00098 while (i0-i1 > lln[i-1]) {
00099 i1=i0;
00100 i=i+1;
00101 i0=i0+1;
00102 }
00103 j=col[k];
00104 pelement = spGetElement((char*) *fmat,i,j);
00105 if (pelement == 0) {
00106 *ierr=2;
00107 return;
00108 }
00109 spADD_REAL_ELEMENT(pelement,(spREAL)(val[k]));
00110
00111 }
00112
00113 spFixThresold((char*) *fmat,*eps,*releps);
00114
00115 error = spFactor((char*) *fmat);
00116 spGetNumRank((char *) *fmat,nrank);
00117 switch (error) {
00118 case spZERO_DIAG:
00119 cerro("zero_diag: A zero was encountered on the diagonal the matrix ");
00120 break;
00121 case spNO_MEMORY:
00122 *ierr=3;
00123 break;
00124 case spSINGULAR:
00125 *ierr=-1;
00126 break;
00127 case spSMALL_PIVOT:
00128 *ierr=-2;
00129 break;
00130 }
00131 }
00132
00133
00134
00135
00136
00137
00138
00139 extern void Cout(char *str);
00140
00141 void C2F(lusolve1)(fmat,b,x)
00142 double *b, *x;
00143 long *fmat;
00144 {
00145 spSolve((char*) *fmat,(spREAL*)b,(spREAL*)x);
00146 }
00147
00148
00149
00150
00151
00152
00153 void C2F(ludel1)(fmat)
00154 long *fmat;
00155 {
00156 spDestroy((char*) *fmat);
00157 }
00158
00159
00160
00161
00162
00163
00164 static void
00165 spSize(eMatrix,n)
00166 char *eMatrix;
00167 int *n;
00168 {
00169 MatrixPtr Matrix = (MatrixPtr)eMatrix;
00170 *n=Matrix->Size;
00171 }
00172
00173 void C2F(lusize)(fmat,n)
00174 long *fmat;
00175 int *n;
00176 {
00177 spSize((char *) *fmat,n);
00178 }
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190 void GetSigD(MatrixPtr Matrix,int indsigd[],double sigd[])
00191 {
00192 int I,J,mc=0,last=0;
00193 int Size=Matrix->Size;
00194 for (I = 1; I <= Size; I++)
00195 {
00196 indsigd[I-1]=1;
00197 indsigd[Size+I-1]= Matrix->IntToExtColMap[I];
00198 sigd[I-1]=1.0;
00199 }
00200
00201 for (I = 1; I <= Size; I++)
00202 if (Matrix->ExtToIntColMap[I]== -1) mc++;
00203
00204 if (mc != 0)
00205 {
00206 for (I = Size -(mc)+1 ; I <= Size; I++)
00207 {
00208 for ( J=last+1; J <=Size; J++)
00209 {
00210 if (Matrix->ExtToIntColMap[J]==-1)
00211 {
00212 last=J;break;
00213 }
00214 }
00215 indsigd[I-1]=1;
00216 indsigd[Size+I-1]= last;
00217 }
00218 }
00219 }
00220
00221
00222
00223
00224 void GetSigG(MatrixPtr Matrix,int indsigg[],double sigg[])
00225 {
00226 int Size=Matrix->Size;
00227 int I,J,mc=0,last=0;
00228
00229 for (I = 1; I <= Size; I++)
00230 if (Matrix->ExtToIntRowMap[I]== -1) mc++;
00231
00232 for (I = 1; I <= Size-mc ; I++)
00233 {
00234 indsigg[I-1]= 1;
00235 indsigg[Size+Matrix->IntToExtRowMap[I]-1]=I;
00236 sigg[I-1]=1;
00237 }
00238
00239 if (mc != 0)
00240 {
00241 for (I = Size -(mc)+1 ; I <= Size; I++)
00242 {
00243 for ( J=last+1; J <=Size; J++)
00244 {
00245 if (Matrix->ExtToIntRowMap[J]==-1)
00246 {
00247
00248 last=J;break;
00249 }
00250 }
00251 indsigg[I-1]= 1;
00252 indsigg[Size+last-1]=I;
00253 sigg[I-1]=1;
00254 }
00255 }
00256 }
00257
00258
00259 static void
00260 spLuget(eMatrix,indP,P,indl,l,indu,u,indQ,Q)
00261 char *eMatrix;
00262 int *indP,*indl,*indu,*indQ;
00263 double *P,*Q,*l,*u;
00264 {
00265 int I,J;
00266 int lsize,usize;
00267
00268 MatrixPtr Matrix = (MatrixPtr) eMatrix;
00269 ElementPtr pElement;
00270 int Size;
00271 Size = Matrix->Size;
00272 GetSigD(Matrix,indQ,Q);
00273 GetSigG(Matrix,indP,P);
00274 for (J = 1; J <= Size ; J++)
00275 {
00276 indl[J-1] = 0;
00277 indu[J-1] = 0;
00278 }
00279 lsize=0;
00280 usize=0;
00281 for (I = 1; I <= Size ; I++)
00282 {
00283 indu[I-1]=indu[I-1]+1;
00284 indu[Size+usize]=I;
00285 u[usize]=1.0;
00286 usize=usize+1;
00287
00288 pElement = Matrix->FirstInRow[I];
00289 while ( pElement != NULL )
00290 {
00291 J = pElement->Col;
00292 if (I >= J) {
00293 indl[I-1] = indl[I-1]+1;
00294 indl[Size+lsize]=J;
00295 l[lsize]=(double) pElement->Real ;
00296 lsize=lsize+1;
00297
00298 }
00299 else {
00300 indu[I-1] = indu[I-1]+1;
00301 indu[Size+usize]=J;
00302 u[usize]=(double) pElement->Real ;
00303 usize=usize+1;
00304
00305 }
00306 pElement = pElement->NextInRow;
00307 };
00308 };
00309 }
00310
00311
00312
00313
00314
00315 void C2F(luget1)(fmat,indP,P,indl,l,indu,u,indQ,Q)
00316 long *fmat;
00317 double *P,*Q,*l,*u;
00318 int *indP,*indl,*indu,*indQ;
00319 {
00320 spLuget((char *) *fmat,indP,P,indl,l,indu,u,indQ,Q);
00321 }
00322
00323
00324
00325
00326
00327
00328
00329
00330 static void
00331 spLusiz(eMatrix,lsize,usize)
00332 char *eMatrix;
00333 int *lsize,*usize;
00334 {
00335 int J;
00336 MatrixPtr Matrix = (MatrixPtr) eMatrix;
00337 ElementPtr pElement;
00338 int Size;
00339 Size = Matrix->Size;
00340 *lsize=0;
00341 *usize=Size;
00342 for (J = 1; J <= Size ; J++)
00343 {
00344 pElement = Matrix->FirstInCol[J];
00345 while ( pElement != NULL )
00346 {
00347 if (pElement->Row >= J)
00348 *lsize=*lsize+1;
00349 else
00350 *usize=*usize+1;
00351 pElement = pElement->NextInCol;
00352 };
00353 };
00354 }
00355 void C2F(lusiz1)(fmat,lsize,usize)
00356 long *fmat;
00357 int *lsize,*usize;
00358 {
00359 spLusiz((char *) *fmat,lsize,usize);
00360 }