Hello Kristoffer, I don't quite understand what you are doing. But by judging from the title of your post, I'd like to share with you my opinion, and I hope it would be helpful.
The (multiple) dispatch used by Julia is a dynamic one, that is, the dispatch is preformed at run time instead of compiling time (or "code write time" as you mentioned). So you shouldn't have any worry about that, as long as your callee function can handle different concrete types. If it is not the case or it can't be achieved in a simple way, it is advised to write separate functions (a.k.a. generic function) for different concrete types. On Saturday, March 14, 2015 at 9:28:48 PM UTC+1, Kristoffer Carlsson wrote: > > 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 >
