473,386 Members | 1,796 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Assembly Process for FE (Finite Element) code in C

Hello everyone,

I'm working on some Finite Elements(FE) codes in C and now I
encountered some problems in assembly stage. The main idea is that a
large number of 3 by 3 elemental stiffness matrices are calculated and
then they should mapped to specific elements in a very big and sparse
global stiffness matrix. I think the preferred storage format for the
sparse matrix is Compresses Row Storage (CRS) format because it is
compatible with many different sparse solver packages. Now the problem
is that I have no idea how to update and assemble "ia" (pointers to the
begining of each row), "ja" (column indices) and "a" (nonzero values)
arrays as each local stiffness matrix is calculated in the loop. Is it
a better idea to first calculate all the elemental stiffness matrices
and then assemble them in the global system once at the end or I should
update these three arrays each time a local matrix is calculated? I
think SPARSE function in MATLAB can do much of these works for me but I
can't find any similar fuction in C. Since this is my first Finite
Element program, any comments, algorithms or references on this issue
will be a great help.

Mar 23 '06 #1
3 6042
Babak schrieb:
I'm working on some Finite Elements(FE) codes in C and now I
encountered some problems in assembly stage. The main idea is that a
large number of 3 by 3 elemental stiffness matrices are calculated and
then they should mapped to specific elements in a very big and sparse
global stiffness matrix. I think the preferred storage format for the
sparse matrix is Compresses Row Storage (CRS) format because it is
compatible with many different sparse solver packages. Now the problem
is that I have no idea how to update and assemble "ia" (pointers to the
begining of each row), "ja" (column indices) and "a" (nonzero values)
arrays as each local stiffness matrix is calculated in the loop. Is it
a better idea to first calculate all the elemental stiffness matrices
and then assemble them in the global system once at the end or I should
update these three arrays each time a local matrix is calculated? I
think SPARSE function in MATLAB can do much of these works for me but I
can't find any similar fuction in C. Since this is my first Finite
Element program, any comments, algorithms or references on this issue
will be a great help.


This is not exactly a C question; there are several questions.
1) It depends on the finite element formulation (which itself
depends on the application). Let us assume that you have only
local stiffness matrices; the usual way to progress is to
calculate the local stiffness matrices elementwise and add
them to the global stiffness matrix. This part can be easily
parallelized and most formulations offer themselves.
Decide whether you want to manipulate matrix rows and columns
and the right hand side for natural and essential (Neumann or
Dirichlet, or maybe even Robin) boundary conditions or whether
you want to eliminate these rows and columns as far as possible.
Depending on the boundary direction, parametrisation, and the
boundary conditions, assembly of the boundary conditions can
become quite nontrivial.
2) The way to store the matrix depends on the intended solver
for the linear system.
If you use a multigrid method or another iterative solver,
you should not go for a too dumb compressed row or column
format.
If you intend to use a standard direct solver (say LU), then
there are enough variants for the CRS.
3) Your question about the matrix format and the "update and
assembly" may be a C question if presented correctly.
4) There is at least one finite element toolbox written in C:
ug. I do not recommend it for someone who is not deeply
immersed in Numerical Mathematics and a very good C
programmer.

There probably are newsgroups and mailing lists which can
answer questions 1)-4) better than comp.lang.c.

Back to the C part of your question: Give us C code showing
how your variety of CRS is defined; then explain your problem
in terms of C.
However, people in another newsgroup or mailing list may be
able to point you to tested and working C code for your
purposes.
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Mar 23 '06 #2
In article <11********************@e56g2000cwe.googlegroups.c om>,
Babak <b.*******@gmail.com> wrote:

I'm working on some Finite Elements(FE) codes in C and now I
encountered some problems in assembly stage. The main idea is that a
large number of 3 by 3 elemental stiffness matrices are calculated and
then they should mapped to specific elements in a very big and sparse
global stiffness matrix. I think the preferred storage format for the
sparse matrix is Compresses Row Storage (CRS) format because it is
compatible with many different sparse solver packages. Now the problem
is that I have no idea how to update and assemble "ia" (pointers to the
begining of each row), "ja" (column indices) and "a" (nonzero values)
arrays as each local stiffness matrix is calculated in the loop. Is it
a better idea to first calculate all the elemental stiffness matrices
and then assemble them in the global system once at the end or I should
update these three arrays each time a local matrix is calculated? I
think SPARSE function in MATLAB can do much of these works for me but I
can't find any similar fuction in C. Since this is my first Finite
Element program, any comments, algorithms or references on this issue
will be a great help.


Search the web for UMFPACK. This is an open source library,
written in standard C, for storing sparse matrices and solving
sparse linear systems. It is especially well-suited for finite
element computations. Matlab's sparse matrix functions are
based on UMFPACK.

Here is how you would assemble the global stiffness matrix.
Let nelems be the number of elements. You say each element
stiffness matrix is 3x3. Here is a sketch of what you will do:

int *Ti, *Tj;
double *Tx;
int i, j, k, elemno;

Ti = malloc(3 * 3 * nelems * sizeof *Ti);
Tj = malloc(3 * 3 * nelems * sizeof *Tj);
Tx = malloc(3 * 3 * nelems * sizeof *Tx);

k = 0;
for (elemno=0; elemno<nelems; elemno++)
for (i=0; i<3; i++)
for (j=0; j<3; j++) {
Ti[k] = I;
Tj[k] = J;
Tx[k] = m[i][j];
k++;
}

Here m[][] is the stiffness matrix of the element under
consideration and I and J are the row and column numbers in
the global stiffness matrix where m[i][j] is to be stored.

After computing Ti, Tj, Tx, you would call UMFPACK's
umfpack_di_triplet_to_col() function to convert the temporary
representation Ti, Tj, Tx of the global stiffness matrix to
UMFPACK's standard representation, denoted by Ap, Ai, Ax in the
manual. Then you can free the storage allocated to Ti, Tj, Tx.

Read UMFPACK's documentation for further details.

--
Rouben Rostamian

Mar 24 '06 #3
"Babak" <b.*******@gmail.com> skrev i en meddelelse
news:11********************@e56g2000cwe.googlegrou ps.com...
Hello everyone,

I'm working on some Finite Elements(FE) codes in C and now I
encountered some problems in assembly stage. The main idea is
that a
large number of 3 by 3 elemental stiffness matrices are
calculated and
then they should mapped to specific elements in a very big and
sparse
global stiffness matrix. I think the preferred storage format
for the
sparse matrix is Compresses Row Storage (CRS) format because it
is
compatible with many different sparse solver packages. Now the
problem
is that I have no idea how to update and assemble "ia"
(pointers to the
begining of each row), "ja" (column indices) and "a" (nonzero
values)
arrays as each local stiffness matrix is calculated in the
loop. Is it


I don't know about finite element, but I am trying to make a
finite difference program work using something like:

for(i=2, count = 0, no = 0 ; i< nx; i++) {
for(j=2; j< ny; j++) {
if(unknowns[i][j] == 1) {
no++;
pfvector_a[++count] = koeffB[no];
pivector_j[count] = (i-2)*(nx-2) + (j-1);
/* middle cell */
pivector_i[count] = no;
}
if(unknowns[i][j-1] == 1) {
pfvector_a[++count] = koeffA[no];
pivector_j[count] = (i-2)*(nx-2) + (j-2);
/* left */
}
if(unknowns[i][j+1] == 1) {
pfvector_a[++count] = koeffC[no];
pivector_j[count] = (i-2)*(nx-2) + (j);
/* right */
}
if(unknowns[i-1][j] == 1) {
pfvector_a[++count] = koeffE[no];
pivector_j[count] = (i-3)*(nx-2) + (j-1);
/* row up */
}
if(unknowns[i+1][j] == 1) {
pfvector_a[++count] = koeffD[no];
pivector_j[count] = (i-1)*(nx-2) + (j-1);
/* row down */
}
}
}

That is a 2D problem so for each unknown equation in the matrix I
have to look left, right, up and down in order to take boundary
effects in consideration (my first and last cell doesn't have as
many coefficients as the interior cells - actually that applies
to all cells on the domain boundaries). In my code my mesh is
defined from (1,1) to (nx, ny) - or is it (ny, nx)? It's not
completely finished yet.....

Using this method, I have a 2D array called unknowns which allows
me to do calculation on arbitrarily shapes (circle, triangle, L
or T-shaped or even more random if I like) - the routine takes
care of inserting the correct coefficients so if we're standing
on the left top boundary ofcourse there's no coefficient above
and to the left for that equation...

However, I must also say that my code doesn't work at the
moment.... Don't know if there's anything I forgot to include,
since this is also my first time working with such a solver that
requires this format (am trying to make a conjugated gradient
solver work)....

You're saying that this format with "ia" (pointers to the
begining of each row), "ja" (column indices) and "a" is called
Compressed Row Storage (CRS) format ? I didn't knew that, so if
you make any progress I would be interested in seeing how you
solve the problem - (you can also mail me, just remove the .spam
and spam. before and after the @).
Best regards / Med venlig hilsen
Martin Jørgensen

--
---------------------------------------------------------------------------
Home of Martin Jørgensen - http://www.martinjoergensen.dk

Mar 24 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Hsuan-Yeh Chang | last post by:
Dear All, Anyone knows a good Finite Element Solver for python programer? Thanks! HYC
2
by: Terence Shek | last post by:
Is there a way to set the application binding policy so that it always binds to the latest version of an assembly? I'm hoping there is a way to avoid updating the application's binding...
11
by: Nicholas R. Markham | last post by:
When I compile with the -ansi option (using gcc 3.2.3) I'm warned of an implicit declaration of function 'finite'. Does this mean that finite() is not part of ANSI C, or that I didn't include a...
1
by: Luis Esteban Valencia | last post by:
Hello. I got an error on my program. the code is very simple private void btnsubmit_Click(object sender, System.EventArgs e) { string requestLocation =...
4
by: Michael Neumann | last post by:
I'm trying to set up a test environment for an ASP.NET site on a Windows XP Pro box. I installed IIS5.1 and then .Net V2. I put up a web site that contains just a simple Default.aspx "hello...
3
by: Richard Lewis Haggard | last post by:
We are having a lot of trouble with problems relating to failures relating to 'The located assembly's manifest definition with name 'xxx' does not match the assembly reference" but none of us here...
2
by: rrossney | last post by:
Please look at the "what I've already done" section of this message before responding to it: I believe that I've done everything that the people who experience this error are typically told to do....
2
by: ras26 | last post by:
I have a WebSite "App1" which has an external assembly "Lib1". Inside this external assembly we have developed some classes that derive from "System.Web.UI.Page". One of these pages is called...
2
by: ajikoe | last post by:
Hello, Is there any add on python modules suitable for finite element 3D mesh such as to create (beam, plate, etc) ? Best Regards, ajikoe
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.