From 6e388f3d990e2dc9848e94b0942cea5700faae8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20L=C3=BCbke?= Date: Tue, 5 Sep 2023 16:38:54 +0200 Subject: [PATCH] write input of thomas algortithm to file --- src/BTCSv2.cpp | 27 +++++++++++++++++++++++++++ src/CMakeLists.txt | 6 ++++++ 2 files changed, 33 insertions(+) diff --git a/src/BTCSv2.cpp b/src/BTCSv2.cpp index 49e4d1c..705b152 100644 --- a/src/BTCSv2.cpp +++ b/src/BTCSv2.cpp @@ -11,6 +11,11 @@ #include #include +#ifdef WRITE_THOMAS_CSV +#include +#include +#endif + #define NUM_THREADS_BTCS 10 using namespace Eigen; @@ -295,6 +300,28 @@ static VectorXd ThomasAlgorithm(SparseMatrix &A, VectorXd &b) { a_diag[n - 1] = A.coeff(n - 1, n - 2); b_diag[n - 1] = A.coeff(n - 1, n - 1); + // HACK: write CSV to file +#ifdef WRITE_THOMAS_CSV + #include + #include + static std::uint32_t file_index = 0; + std::string file_name = "Thomas_" + std::to_string(file_index++) + ".csv"; + + std::ofstream out_file; + + out_file.open(file_name, std::ofstream::trunc | std::ofstream::out); + + // print header + out_file << "Aa, Ab, Ac, b\n"; + + // iterate through all elements + for (std::size_t i = 0; i < n; i++) { + out_file << a_diag[i] << ", " << b_diag[i] << ", " << c_diag[i] << ", " << b[i] << "\n"; + } + + out_file.close(); +#endif + // start solving - c_diag and x_vec are overwritten n--; c_diag[0] /= b_diag[0]; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b7aceb2..3cc79d4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,5 +1,11 @@ add_library(tug Boundary.cpp Grid.cpp Simulation.cpp FTCS.cpp BTCSv2.cpp) +option(TUG_WRITE_CSV "Write CSV during Thomas algorithm with consecutive numbers for each call" OFF) + +IF(TUG_WRITE_CSV) + target_compile_definitions(tug PRIVATE WRITE_THOMAS_CSV) +endif() + target_link_libraries(tug Eigen3::Eigen) if(TUG_USE_OPENMP AND OpenMP_CXX_FOUND)