New Adams-Bashforth libraries

I’ve got two new refactored Adams-Bashforth type numerical methods available:

  • DIVALIB This is a modernization of DIVA, a variable order Adams method ODE solver by Fred T. Krogh (JPL), extracted from the MATH77 library. This one has a lot of legacy for astrodynamics applications. The original code was insane F77 spaghetti, and AI was able to clean it up a good bit. [note: i started this port years ago so really the modernization is about half-AI and half not].
  • FVODE This is an AI-assisted conversion from C to Fortran of the CVODE ODE integrator from SUNDIALS. There is a lot of history there too, it started in Fortran (see DVODE for another modernization of the original Fortran), was converted to C where it has been developed for decades, and now it’s back to Fortran where it belongs.

Both are now modernized, object-oriented, thread-safe, FPM-ready, etc. Let me know if anyone uses them for anything.

3 Likes

Hi Jacob, great work.

I am strongly interested in ODE integrators, multistep methods included.

Recently, I published FOSS a library I am using in my CFD solvers (for now only some RK-like methods), and I have planned to port some of the methods already implemented into FOODIE, including explicit multistep (like AB) and implicit ones.

The library is

Because the extraction from my solvers is still WIP, I have not announced it, but maybe you are interested in reading it.

My best regards,
Stefano

1 Like

Nice work!

Is there a good reason to require every end consumer to specialize on the integrator type? I’m talking about this:

    function rhs(me, t, y, ydot) result(retval)
        !! Robertson chemical kinetics: ydot = f(t, y)
        class(cvode_solver), intent(inout) :: me
        real(wp), intent(in)  :: t, y(:)
        real(wp), intent(out) :: ydot(:)
    subroutine oscillator(me, t, y, f)
        class(diva_solver), intent(inout) :: me
        real(wp), intent(in) :: t, y(:)   ! y = [x, x']
        real(wp), intent(out) :: f(:)     ! f = [x'']

This means the ODE libraries aren’t interchangeable, requiring multiple RHS “instantiations” to switch between integrators.

An “object-oriented” solution IMO would be to inherit solvers from an (abstract) parent solver; this would set the interface of the right-hand side function, and potentially also the solver usage. The other option would be to have the solver take the functor as a right-hand side. For users that don’t like to use inheritance, a little wrapper would do the job to take a regular (non-type bound) procedure. I’ve looked at the different options here: GitHub - ivan-pi/rk_benchmark: An ODE solver callback benchmark · GitHub

I can see the need for function/subroutine interface, since the integrator can have an extra protocal for return values (i.e. failure to evaluate at a given t-value, solution went negative…).

2 Likes

Brilliant

@jacobwilliams , is there a detailed performance comparison followed by a summary of this new Fortran library versus the C version as part of SUNDIALS? Apologies if I overlooked that at your site. Comparison data will be very useful for me to feed back to a management team I am interacting with certain decisions on their tech stack.

As you will know better than most, ai assistants are really good at test generations at massive scale, extensive comparison runs and analyses and can be let loose to complete a majority of such tasks with relative ease on the part of human developers.

I am hoping the Fortran version will be within 1.5x of C, but it’ll be good to confirm.

1 Like

I like the OO approach in some ways, but you are absolutely right that it does make having the option for your code to choose between different integrators not as easy as it should be. I think there are tradeoffs any way and I’m not sure there is a clear “right way” to do this? I need to study your repo and think about it some more!

Awesome! Also check out rklib if you haven’t seen that yet, you might get some inspiration from that.

1 Like

Added some performance metrics here.

Looks pretty good! For these test problems, FVODE is a good bit faster for small systems, and a little faster or slower for larger problems, but pretty close.

Remind me again why people thought all these old Fortran codes should be converted to C? :man_shrugging:

1 Like

Thank you for the performance metrics. With certain language enhancements (intrinsically being allowed to overcome dynamic dispatch, etc.) and further compiler advances such as by LFortran, Fortran can do substantially better while facilitating top-notch readability of programs that have the least amount of “Morse code” i.e., if humans continue to value this aspect post-ai!!

On being “reminded again” (!!), you would have meant it rhetorically / sarcastically :grinning_face:, but LLNL site includes for CVODE:

“There are several motivations for choosing the C language for cvode. First, a general movement
away from Fortran and toward C in scientific computing was apparent. Second, the pointer, structure, and dynamic memory allocation features in C are extremely useful in software of this complexity,
with the great variety of method options offered. Finally, we prefer C over C++ for cvode because of
the wider availability of C compilers, the potentially greater efficiency of C, and the greater ease of
interfacing the solver to applications written in extended Fortran”

1 Like

It’s funny that all of those reasons are complete nonsense now! Probably they were only partially nonsense at the time (if they did this when Fortran 90 was available, which of course had pointers, structures, and dynamic memory). Likely the availability of compilers (certainly free ones) was a real concern, but luckily that doesn’t seem to be a problem anymore. And standard C-interoperability didn’t come until F2003. But it’s never too late to correct the mistakes of the past. :slight_smile:

2 Likes