Hello,

I am writing some code for Finite Elements in Julia. As usual, I have a 
mesh with elements and nodes. However, I do not want to restrict myself to 
only using one type of element per mesh and therefore I have a hierarchy of 
element types along the lines of:

abstract FElement

type LinTrig <:FElement end

type LinQuad <: FElement end

etc

My mesh then consists of a Vector of FElements.

Since I have a Vector of an abstract type I get a performance hit when I, 
for example, assemble the global stiffness matrix. The compiler does not 
know what type of element it will find and have to check it in each 
iteration. For simple material models the overhead from the type checking 
is 10 times larger than calculating the elements stiffness matrix 
contribution.

Now, when I am writing the code for the assembler I can't know what 
elements that the mesh will contain. However, *at the actual call* to the 
assembly function I know what element types I have in the mesh and that 
these will never change. I should then be able to give the compiler that 
information and have it generate efficient code.

I mean, I can do this manually. Just check for the element types, generate 
one vector of elements for each element type and call the assembly function 
for each separate vector of elements. All of these types will be known.

Is this possible to do somehow?

I hope I made sense.

Best regards,
Kristoffer Carlsson

Reply via email to