write input of thomas algortithm to file

This commit is contained in:
Max Lübke 2023-09-05 16:38:54 +02:00
parent 55509c1934
commit 6e388f3d99
2 changed files with 33 additions and 0 deletions

View File

@ -11,6 +11,11 @@
#include <tug/Boundary.hpp>
#include <omp.h>
#ifdef WRITE_THOMAS_CSV
#include<fstream>
#include<string>
#endif
#define NUM_THREADS_BTCS 10
using namespace Eigen;
@ -295,6 +300,28 @@ static VectorXd ThomasAlgorithm(SparseMatrix<double> &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<fstream>
#include<string>
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];

View File

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