mirror of
https://git.gfz-potsdam.de/naaice/tug.git
synced 2025-12-13 09:28:23 +01:00
first example
This commit is contained in:
parent
ebca11f4fd
commit
06d5d737b0
1
.gitignore
vendored
1
.gitignore
vendored
@ -9,3 +9,4 @@ compile_commands.json
|
|||||||
.ccls-cache/
|
.ccls-cache/
|
||||||
/iwyu/
|
/iwyu/
|
||||||
.Rhistory
|
.Rhistory
|
||||||
|
.vscode/
|
||||||
|
|||||||
@ -38,3 +38,5 @@ add_subdirectory(src)
|
|||||||
if(TUG_ENABLE_TESTING)
|
if(TUG_ENABLE_TESTING)
|
||||||
add_subdirectory(test)
|
add_subdirectory(test)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
add_subdirectory(examples)
|
||||||
|
|||||||
3
examples/CMakeLists.txt
Normal file
3
examples/CMakeLists.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
add_executable(first_example first_example.cpp)
|
||||||
|
|
||||||
|
target_link_libraries(first_example tug)
|
||||||
67
examples/first_example.cpp
Normal file
67
examples/first_example.cpp
Normal 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();
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user