CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   Main CFD Forum (http://www.cfd-online.com/Forums/main/)
-   -   how to compute non zero in fem (http://www.cfd-online.com/Forums/main/15796-how-compute-non-zero-fem.html)

 ztdep September 27, 2008 01:19

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

 Jed September 27, 2008 06:21

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 `off-diagonal block'. Distinguishing these is important for preallocation in parallel.

 ztdep September 27, 2008 08:48

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

 Jed September 27, 2008 09:25

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().

 ztdep September 27, 2008 09:36

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.

 ztdep September 27, 2008 09:39

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

 Jed September 27, 2008 10:01

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 row-node and the column-node. In 3D you can have several elements which share an edge, hence the extra step.

 ztdep September 27, 2008 11:27

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 15:13.