how to compute non zero in fem
Dear friends: How to computet the nuber of nonzeros in the fem method for liner triagnualr lelement in 2 d problem regardds

Re: how to compute non zero in fem
Initialize a vector v to all ones. Iterate over the elements and for each node n, and different node p, add 1/2 to v[n] if p is not on a boundary and add 1 to v[n] if p is on a boundary. The vector now has the number of nonzeros in the each row. (The 1/2 is because every interior neighbor will be counted twice in 2D. In 3D there is an extra step to fix the duplicate counts.)
A similar algorithm can be used in parallel to determine the number of nonzeros for the `diagonal block' and the `offdiagonal block'. Distinguishing these is important for preallocation in parallel. 
Re: how to compute non zero in fem
thank you very much for your feedback. it is a great idea. I now working on my FEM code now, and i want to write the global matrix into the CSR (compressed sparse row) format, so as to use the BCGSTAb method. Could you please give me some idea. Regards

Re: how to compute non zero in fem
Once you know the number of nonzeros per row, a `scan' operation gets you the starting offset for each row. Then you iterate over the elements and actually assemble values. I recommend using a library like PETSc, but it's not difficult to implement yourself if (a) you are sure you only want to use BCGStab and (b) you are sure you know exactly what preconditioner you want to use. If this isn't a purely academic exercise, then you should not sure of either. If you use PETSc (http://mcs.anl.gov/petsc) see MatSeqAIJSetPreallocation() and MatSetValues().

Re: how to compute non zero in fem
thank you very much dear friends. i am working under windows now, and i now have the solver with BCGSTAB and ilu preconditioner. so the only thing is the matrix in the CSR format. regards.

Re: how to compute non zero in fem
why did you say "The 1/2 is because every interior neighbor will be counted twice in 2D" , i am sorry that i can not fully agree with you. if a node have 5 elemetn aroud it. then it will be count 5 times, then we will have a value of 5/2.am i right let me know please if i am wrong

Re: how to compute non zero in fem
It will be counted exactly twice in each row. There are exactly two elements which have both the rownode and the columnnode. In 3D you can have several elements which share an edge, hence the extra step.

Re: how to compute non zero in fem
could you please detail it further. i can not fully understand you .

All times are GMT 4. The time now is 21:10. 