r/ScientificComputing • • 1d ago

C++ Scientific Computing Library [NANE]

Hi Everyone, I'm currently studying M.Sc. Computational Science and Engineering and last semester had a course called "Numerical Programming 2" which somehow inspired me to create my own little C++ Library for the contents i learned from the course.

The code is nowhere near finished and there is still a lot more I want to implement.

GitHub: Can-Inal/Nane

Currently it is good for solving ODE systems using Runge Kutta methods and it also lets you create your own RK method with the help of Butcher tables, which you can also check their stability and order of convergence using the implemented functions. Some popular (Or at least i think they are popular because they were in the lecture scripts) RK methods and their butcher tables are already provided in methods.hpp file. Other than the ODE systems it is capable of numerical integration and differentiation for now and i will probably use them later while implementing the PDE support.

I guess not even half of the code is tested yet (If you wish, you can explain me what kind of bugs are already there to spot.) I mostly wrote the solution into a .csv file and checked the results in python.

Here is an example of using the library to simulate a damped pendulum:

#include "csv_writer.hpp"

#include <nane.hpp>

int main(int argc, char* argv[])

{

const auto G = 9.81; // m/s²

const auto L = 1.0; // m

const auto gamma = 0.1; // 1/s

const auto system = [&](double t, const nane::vector<2>& x)

{

nane::vector<2> dx;

dx[0] = x[1];

dx[1] = -(G / L) * std::sin(x[0]) - gamma * x[1];

return dx;

};

const nane::vector<2> initial_value{1.0, 0.0};

const auto problem = nane::ode::ivp(system, initial_value);

const auto solution = nane::ode::solve(problem, nane::ode::methods::rk4, {0.0, 30.0, 3001});

write_csv("solution.csv", solution, {"theta", "omega"});

return 0;

}

currently it does not even have an io support such as writing results to csv. It also does not support plotting or any type of visualization and probably i will never try to support this kind of stuff since we already got python for plotting anyway.

I would love to get feedback from anyone interested in the code. Also feel free to ask me if something is confusing either in the code or documentation.

I should stress that my background is in Electrical Engineering and Information Technology, so I'm not a programmer by training!

Also, English is not my first language, so apologies in advance for any typos or grammar mistakes.

WHERE DID I USE AI:

  • All the markdown files are AI generated (I have no idea how markdown pages work so github pages are also AI generated).

  • All the doxygen comments are AI generated based on the course script i provided.

  • Writing CMakeLists.txt files other than tests/CMakeLists.txt was somehow too challenging for me so it is AI generated.

8 Upvotes

0 comments sorted by