Planet-Factory / legacy-claude

The CLAuDE model
https://planet-factory.github.io/claude-docs/
MIT License
167 stars 28 forks source link

Increase speed 5x through np matrix operations #19

Closed wanLo closed 3 years ago

wanLo commented 3 years ago

These changes drastically improve the speed of the calculations in the main loop by replacing nested for-loops with numpy matrix operations. In general, I replaced many slow for-loops with corresponding matrix operations, always keeping the idea of the original algorithm. This sometimes introduces small numerical differences, which I believe are insignificant. In total, calculations (without plotting) are ~5x faster. Plotting now takes by far the most amount of time in each iteration.

Detailed comparison of performance improvements: Part Improvement
Radiation ~35x
Velocity ~20x
Advection ~120x
Projection* ~4x

* grid_velocities_[north|south] should also be optimized, but I could not wrap my head around the side-effects in the nested for-loops of these functions

drsimonclark commented 3 years ago

This is incredible! Thank you for vectorising this stuff as I had no idea how to do this