Take the 2-minute tour ×
Computational Science Stack Exchange is a question and answer site for scientists using computers to solve scientific problems. It's 100% free, no registration required.

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?

share|improve this question
    
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
1  
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

2 Answers 2

up vote 8 down vote accepted

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

share|improve this answer
    
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.

share|improve this answer
    
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.