create and provide basic function of BTCS2D

This commit is contained in:
Max Lübke 2021-10-26 10:28:42 +02:00
parent 1ede0dee05
commit 0dea11744f
2 changed files with 41 additions and 0 deletions

30
src/diffusion.cpp Normal file
View File

@ -0,0 +1,30 @@
#include "diffusion.hpp"
#include <Eigen/SparseLU>
#include <Eigen/src/Core/Matrix.h>
void BTCS2D(int x, int y, std::vector<double> &c, std::vector<double> &alpha,
double timestep) {
double dx = 1. / x;
double dy = 1. / y;
int size = x * y;
Eigen::VectorXd d = Eigen::VectorXd::Constant(size, 0);
std::vector<T> tripletList;
tripletList.reserve(((x - 1) * (y - 1) * 5));
for (int i = 1; i < y - 1; i++) {
for (int j = 1; j < x - 1; j++) {
double sx = (alpha[i * y + j] * timestep) / (dx * dx);
double sy = (alpha[i * y + j] * timestep) / (dy * dy);
tripletList.push_back(T((i * x) + j, (i * x) + j, (1 + 2 * sx + 2 * sy)));
tripletList.push_back(T((i * x) + j, ((i * x) + j) + x, sy));
tripletList.push_back(T((i * x) + j, ((i * x) + j) - x, sy));
tripletList.push_back(T((i * x) + j, ((i * x) + j) + 1, sx));
tripletList.push_back(T((i * x) + j, ((i * x) + j) - 1, sx));
}
}
}

11
src/diffusion.hpp Normal file
View File

@ -0,0 +1,11 @@
#ifndef DIFFUSION_H_
#define DIFFUSION_H_
#include <Eigen/SparseCore>
#include <vector>
typedef Eigen::Triplet<double> T;
extern void BTCS2D(int x, int y, std::vector<double> &c, double alpha,
double timestep);
#endif // DIFFUSION_H_