# Elemtary matrix to CSR global matrix

 Register Blogs Members List Search Today's Posts Mark Forums Read

 September 19, 2002, 12:42 Elemtary matrix to CSR global matrix #1 xueying Guest   Posts: n/a How can I assemble elemtary matrix to global matrix in CSR format? If anybody has this subroutine, can you share it with me?

 September 22, 2002, 14:50 Re: Elemtary matrix to CSR global matrix #2 Wen Long Guest   Posts: n/a Here is my C progam, can you try it? //-------------- /*Using Compressed Row Storage method to represente a sparce matrix to do A*Vin=Vout (matrix vector multiplying) */ #include #include /*#define N 100; */ /*The maximum size of the matrix is N*N */ void main(void) { float E[10000]; long int C[10000],R[101]; /* E[]----Element value vector C[]----Column index vector R[]----Row position vector */ float Vin[100], Vout[100]; /* Vin[N]---Input vector */ /* Vout[N]---Output vector, Vout[]=A*Vin[] */ long int n; /*actual matrix size */ long int num; long int i; void multiply(float*,long int *, long int *, long int ,float *,float * ); Again: printf("Input size of matrix A, n=:\n"); scanf("%d",&n); if(n>100) {printf("n must < 100!, try again\n"); goto Again; } printf("Input total number of non-zero elements in A\n"); scanf("%d",&num); for(i=0;i

 September 24, 2002, 09:44 Re: Elemtary matrix to CSR global matrix #3 Wen Long Guest   Posts: n/a Sorry, some chars missing when I was copying it (seems funny). Here is the right one: /*Using Compressed Row Storage method to represente a sparce matrix to do A*Vin (matrix vector multiplying) */ #include #include /*#define N 100; */ /*The maximum size of the matrix is N*N */ void main(void) { float E[10000]; long int C[10000],R[101]; /* E[]----Element value vector C[]----Column index vector R[]----Row position vector */ float Vin[100], Vout[100]; /* Vin[N]---Input vector */ /* Vout[N]---Output vector, Vout[]=A*Vin[] */ long int n; /*actual matrix size */ long int num; long int i; void multiply(float*,long int *, long int *, long int ,float *,float * ); Again: printf("Input size of matrix A, n=:\n"); scanf("%d",&n); if(n>100) {printf("n must < 100!, try again\n"); goto Again; } printf("Input total number of non-zero elements in A\n"); scanf("%d",&num); for(i=0; i < num ; i++) /* input E[] and C[] */ { printf("E[%d]=\n",i); scanf("%f",&E[i]); printf("C[%d]=\n",i); scanf("%d",&C[i]); } for(i=0; i < = n; i++) /*input R[] */ { printf("R[%d]=\n",i); scanf("%d",&R[i]); } for(i=0; i < n; i++) /*input Vin[] */ { printf("Vin[%d]=\n",i); scanf("%f",&Vin[i]); } multiply(E,C,R,n,Vin,Vout); /*do the calculation */ printf("Vout[%d=",n); /* print Vout[n] */ for(i=0 ; i < n ; i++) { printf("%10f\n",Vout[i]); } } void multiply(float *pE, long int *pC, long int *pR, long int n, float *pVin, float *pVout) { /* pE----pointer to array E */ /* pC----pointer to array C */ /* pR----pointer to array R */ /* pVin---pointer to array Vin */ /* pVout---pointer to array Vout */ int i,j; for(i=0; i < n; i++) /* row i of A */ { pVout[i]=0; for(j=pR[i];j

 Thread Tools Display Modes Linear Mode

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is OffTrackbacks are On Pingbacks are On Refbacks are On Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post xiuying OpenFOAM Running, Solving & CFD 8 August 27, 2013 15:33 bookie56 OpenFOAM Installation 8 August 13, 2011 04:03 lr103476 OpenFOAM Running, Solving & CFD 30 November 19, 2007 15:09 msrinath80 OpenFOAM Running, Solving & CFD 9 July 22, 2007 02:58 liugx212 OpenFOAM Running, Solving & CFD 3 January 4, 2006 19:07

All times are GMT -4. The time now is 09:37.