From 06d5d737b09c910783016fdae5f5857818ede92e Mon Sep 17 00:00:00 2001 From: philippun Date: Thu, 11 May 2023 17:01:33 +0200 Subject: [PATCH] first example --- .gitignore | 1 + CMakeLists.txt | 2 ++ examples/CMakeLists.txt | 3 ++ examples/first_example.cpp | 67 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 73 insertions(+) create mode 100644 examples/CMakeLists.txt create mode 100644 examples/first_example.cpp diff --git a/.gitignore b/.gitignore index cf9dc56..bec6f3f 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ compile_commands.json .ccls-cache/ /iwyu/ .Rhistory +.vscode/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 26f716e..0e38161 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,3 +38,5 @@ add_subdirectory(src) if(TUG_ENABLE_TESTING) add_subdirectory(test) endif() + +add_subdirectory(examples) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt new file mode 100644 index 0000000..b33dfec --- /dev/null +++ b/examples/CMakeLists.txt @@ -0,0 +1,3 @@ +add_executable(first_example first_example.cpp) + +target_link_libraries(first_example tug) \ No newline at end of file diff --git a/examples/first_example.cpp b/examples/first_example.cpp new file mode 100644 index 0000000..2d07bda --- /dev/null +++ b/examples/first_example.cpp @@ -0,0 +1,67 @@ +#include "tug/BoundaryCondition.hpp" +#include + +#include +#include +#include + +using namespace std; +using namespace tug::diffusion; +using namespace tug::bc; + +int main(int argc, char *argv[]) { + + // define problem dimensionality + // set grid sizes for each dimension + int dim = 1; + int n = 20; + + vector alpha(n, 1e-1); + // double alpha = 1e-1; + vector field(n, 1e-6); + for (int i = 1; i<20; i++) { + field[i] = 0; + } + // double field = 1e-6; + + + TugGrid grid_param; // why is grid_param defined separately? + // grid_param.grid_cells[0] = 20; + // grid_param.grid_cells[1] = 0; + // grid_param.grid_cells[2] = 0; + + // grid_param.domain_size[0] = 20; + // grid_param.domain_size[1] = 0; + // grid_param.domain_size[2] = 0; + + + + TugInput input_param; + input_param.setTimestep(1.); + //input_param.grid = grid_param; + input_param.setGridCellN(n); + input_param.setDomainSize(n); // what is domain????? + BoundaryCondition bc(n); + input_param.setBoundaryCondition(bc); + + ofstream myfile; + myfile.open("output.csv"); + if (!myfile) { + exit(1); + } + + for (int t = 0; t < 10000; t++) { + double result = BTCS_1D(input_param, &field[0], &alpha[0]); + //myfile << result; + //myfile << '\n'; + //myfile << "Vector contents: "; + for (int i = 0; i < field.size(); i++) { + myfile << field[i]; + if (i < field.size()-1) { + myfile << ", "; + } + } + myfile << std::endl; + } + myfile.close(); +} \ No newline at end of file