first example

This commit is contained in:
philippun 2023-05-11 17:01:33 +02:00
parent ebca11f4fd
commit 06d5d737b0
4 changed files with 73 additions and 0 deletions

1
.gitignore vendored
View File

@ -9,3 +9,4 @@ compile_commands.json
.ccls-cache/
/iwyu/
.Rhistory
.vscode/

View File

@ -38,3 +38,5 @@ add_subdirectory(src)
if(TUG_ENABLE_TESTING)
add_subdirectory(test)
endif()
add_subdirectory(examples)

3
examples/CMakeLists.txt Normal file
View File

@ -0,0 +1,3 @@
add_executable(first_example first_example.cpp)
target_link_libraries(first_example tug)

View File

@ -0,0 +1,67 @@
#include "tug/BoundaryCondition.hpp"
#include <tug/Diffusion.hpp>
#include <iostream>
#include <fstream>
#include <string>
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<double> alpha(n, 1e-1);
// double alpha = 1e-1;
vector<double> 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();
}