mirror of
https://git.gfz-potsdam.de/naaice/tug.git
synced 2025-12-13 17:38:23 +01:00
56 lines
1.3 KiB
C++
56 lines
1.3 KiB
C++
#include <diffusion/BTCSDiffusion.hpp>
|
|
#include <diffusion/BoundaryCondition.hpp>
|
|
|
|
#include <algorithm> // for copy, max
|
|
#include <cmath>
|
|
#include <iomanip>
|
|
#include <iostream> // for std
|
|
#include <vector> // for vector
|
|
using namespace std;
|
|
|
|
using namespace Diffusion;
|
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
// dimension of grid
|
|
int dim = 1;
|
|
|
|
int n = 20;
|
|
|
|
// create input + diffusion coefficients for each grid cell
|
|
std::vector<double> alpha(n, 1 * pow(10, -1));
|
|
std::vector<double> field(n, 1 * std::pow(10, -6));
|
|
std::vector<boundary_condition> bc(n + 2, {0, 0});
|
|
|
|
// create instance of diffusion module
|
|
BTCSDiffusion diffu(dim);
|
|
|
|
diffu.setXDimensions(1, n);
|
|
|
|
// set the boundary condition for the left ghost cell to dirichlet
|
|
bc[1] = {Diffusion::BC_CONSTANT, 5 * std::pow(10, -6)};
|
|
// diffu.setBoundaryCondition(1, 0, BTCSDiffusion::BC_CONSTANT,
|
|
// 5. * std::pow(10, -6));
|
|
|
|
// set timestep for simulation to 1 second
|
|
diffu.setTimestep(1.);
|
|
|
|
cout << setprecision(12);
|
|
|
|
// loop 100 times
|
|
// output is currently generated by the method itself
|
|
for (int i = 0; i < 100; i++) {
|
|
diffu.simulate(field.data(), alpha.data(), bc.data());
|
|
|
|
cout << "Iteration: " << i << "\n\n";
|
|
|
|
for (auto &cell : field) {
|
|
cout << cell << "\n";
|
|
}
|
|
|
|
cout << "\n" << endl;
|
|
}
|
|
|
|
return 0;
|
|
}
|