feat: Implement FTCS and BTCS diffusion solvers
This commit is contained in:
parent
42b6ed40fe
commit
5141d0901a
@ -14,6 +14,11 @@ add_subdirectory(tug EXCLUDE_FROM_ALL)
|
||||
|
||||
add_subdirectory(eval)
|
||||
|
||||
add_executable(bench ${GEN_SRC})
|
||||
target_link_libraries(bench PRIVATE Eigen3::Eigen tug)
|
||||
target_include_directories(bench PRIVATE ${CMAKE_BINARY_DIR}/eval)
|
||||
add_executable(bench_FTCS ${GEN_SRC})
|
||||
target_link_libraries(bench_FTCS PRIVATE Eigen3::Eigen tug)
|
||||
target_include_directories(bench_FTCS PRIVATE ${CMAKE_BINARY_DIR}/eval)
|
||||
target_compile_definitions(bench_FTCS PRIVATE BENCH_FTCS)
|
||||
|
||||
add_executable(bench_BTCS ${GEN_SRC})
|
||||
target_link_libraries(bench_BTCS PRIVATE Eigen3::Eigen tug)
|
||||
target_include_directories(bench_BTCS PRIVATE ${CMAKE_BINARY_DIR}/eval)
|
||||
|
||||
@ -4,8 +4,6 @@
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <tug/Simulation.hpp>
|
||||
#include <vector>
|
||||
|
||||
using TugType = double;
|
||||
|
||||
|
||||
37
src/run.cpp
37
src/run.cpp
@ -1,8 +1,8 @@
|
||||
#include "run.hpp"
|
||||
|
||||
#include "io.hpp"
|
||||
#include "tug/Boundary.hpp"
|
||||
#include "tug/Grid.hpp"
|
||||
#include "tug/Core/Numeric/FTCS.hpp"
|
||||
#include "tug/Diffusion.hpp"
|
||||
|
||||
#include <Eigen/src/Core/Map.h>
|
||||
#include <Eigen/src/Core/Matrix.h>
|
||||
@ -11,7 +11,7 @@
|
||||
#include <ratio>
|
||||
#include <vector>
|
||||
|
||||
#include <tug/Simulation.hpp>
|
||||
#include <tug/Core/Matrix.hpp>
|
||||
|
||||
#include <Eigen/Eigen>
|
||||
|
||||
@ -30,14 +30,19 @@ double run_bench(const bench_input &input, const std::string &output_file) {
|
||||
// create tug grids and boundary conditions
|
||||
for (int i = 0; i < raw_data.size(); i++) {
|
||||
|
||||
Eigen::Map<RowMajorMat> mat(raw_data[i].data(), input.nrows, input.ncols);
|
||||
tug::Grid<TugType> grid(input.nrows, input.ncols);
|
||||
#ifdef BENCH_FTCS
|
||||
tug::Diffusion<TugType, tug::FTCS_APPROACH> diffu(raw_data[i].data(),
|
||||
input.nrows, input.ncols);
|
||||
#else
|
||||
tug::Diffusion<TugType, tug::BTCS_APPROACH> diffu(raw_data[i].data(),
|
||||
input.nrows, input.ncols);
|
||||
#endif
|
||||
|
||||
grid.setConcentrations(mat);
|
||||
grid.setDomain(input.s_x, input.s_y);
|
||||
grid.setAlpha(alpha_x, alpha_y);
|
||||
diffu.setDomain(input.s_x, input.s_y);
|
||||
diffu.setAlphaX(alpha_x);
|
||||
diffu.setAlphaY(alpha_y);
|
||||
|
||||
tug::Boundary<TugType> boundary(grid);
|
||||
tug::Boundary<TugType> &boundary = diffu.getBoundaryConditions();
|
||||
|
||||
// set north boundary
|
||||
for (const auto &index : input.boundary.north_const) {
|
||||
@ -63,21 +68,15 @@ double run_bench(const bench_input &input, const std::string &output_file) {
|
||||
input.boundary.values[i]);
|
||||
}
|
||||
|
||||
tug::Simulation<TugType> sim(grid, boundary);
|
||||
|
||||
if (const char *out = std::getenv("OMP_NUM_THREADS")) {
|
||||
int ompNumThreads = std::stoi(out, NULL);
|
||||
sim.setNumberThreads(ompNumThreads);
|
||||
diffu.setNumberThreads(ompNumThreads);
|
||||
}
|
||||
|
||||
sim.setTimestep(input.timestep);
|
||||
sim.setIterations(input.iterations);
|
||||
diffu.setTimestep(input.timestep);
|
||||
diffu.setIterations(input.iterations);
|
||||
|
||||
sim.run();
|
||||
|
||||
const auto &result = grid.getConcentrations();
|
||||
|
||||
raw_data[i] = eigenMatrix_to_vector(result);
|
||||
diffu.run();
|
||||
}
|
||||
|
||||
const auto end_t = std::chrono::high_resolution_clock::now();
|
||||
|
||||
2
tug
2
tug
@ -1 +1 @@
|
||||
Subproject commit 4867261f9d902ea2be161889a968d3bff519f15c
|
||||
Subproject commit 9ca0735654d0ca808fa4704b2b2e13cf417ab865
|
||||
Loading…
x
Reference in New Issue
Block a user