# Is there an open source set of ODE solvers for C that use the native C99 complex type?

I've been using GSL as the foundation of many of my simulations, but it's a little bit overkill for my purposes and it defines its own complex type for legacy reasons. Rather than code my own Runge-Kutta ODE solver, which would probably not be very efficient, are there any open source ODE solvers that use the native C99 complex type?

• I don't know where do you want to use it, but in general RK is quite hard to be implemented in non-efficient way... Have you made any benchmarks that showed that you have this problem? – mbq Nov 30 '11 at 10:18
• None. I haven't written my own because I don't want to reinvent the wheel. If I have to then I will, but finding time to spend on something that isn't broken isn't on the cards for me right now. If an answer comes up that's what I'm looking for, I won't be able to actually use if for a few months. In addition, RK isn't always what I need, just what I know the algorithm for. – qubyte Nov 30 '11 at 10:47
• Incidentally, I'm doing simulations of small quantum systems most of the time. Not exclusively though. – qubyte Nov 30 '11 at 10:55
• I would advice against implementing variable step-size RK yourself (except for educational purposes). There are a lot of heuristics involved in finding the optimal step size. – Jitse Niesen Dec 7 '11 at 11:32
• As I said, any I'd write quickly would be either wrong, or slow. Is it particularly hard to implement RK with complex input/output? I know you can just split it into two real parts, but this is kind of annoying! – qubyte Dec 7 '11 at 13:32

You might consider it "overkill", but PETSc's time integration package can be used with C99 complex (configure --with-scalar-type=complex). Supported methods include

These implementations are most appropriate for high-dimensional problems such as semi-discretized partial differential equations (method of lines).

• It is a little large, but I didn't know about it so +1. Ideally whatever I use will be no larger than GSL. I'll take a look at the manual and see what I think. – qubyte Nov 30 '11 at 8:51
• Just to be clear, you link against these libraries at compile time. Is that right? – qubyte Dec 1 '11 at 1:19
• Nothing is linked at compile time. Ever. Linking is done after compiling (even if the compiler invokes the linker). You can dynamically load the library, but you will need the headers to compile your code to call into the library. If that doesn't answer your question, please explain what you want to do. – Jed Brown Dec 1 '11 at 2:11
• You're right of course. Silly error, but you knew what I meant. My question would have been better stated as "Do I link to these libraries?" as opposed to compiling the bits I require at the same time as my own code as is the case with Boost. I am aware that calling functions from a library will require headers, I have been doing this for some time. – qubyte Dec 1 '11 at 2:28
• Yes, you compile PETSc independently from your application. It is not header-only like Boost. – Jed Brown Dec 1 '11 at 2:30

Another option you have, unless the system is rather complicated, is to just convert from complex notation to a problem with two unknowns that represent the real and imaginary part. You can then use a standard real-valued ODE solver.

• This is exactly what I'm trying to avoid. In fact GSL integrators are real only if memory serves, so this is what I'm doing at the moment. – qubyte Dec 18 '11 at 4:32