This commit is contained in:
Max Lübke 2021-11-05 11:05:19 +01:00
parent 00dad33b0f
commit 8dff22c7bf
2 changed files with 14 additions and 10 deletions

View File

@ -13,6 +13,7 @@
#include <Eigen/src/SparseLU/SparseLU.h>
#include <Eigen/src/SparseQR/SparseQR.h>
#include <iostream>
#include <ostream>
void BTCS2D(int x, int y, std::vector<double> &c, std::vector<double> &alpha,
double timestep) {
@ -34,7 +35,10 @@ void BTCS2D(int x, int y, std::vector<double> &c, std::vector<double> &alpha,
double sx = (alpha[i * x + j] * timestep) / (dx * dx);
double sy = (alpha[i * x + j] * timestep) / (dy * dy);
tripletList.push_back(T(A_line, i * x + j, (1 + 2 * sx + 2 * sy)));
tripletList.push_back(T(A_line, i * x + j, (1. + 2. * sx + 2. * sy)));
std::cout << sx << std::endl;
tripletList.push_back(T(A_line, (i - 1) * x + j, sy));
tripletList.push_back(T(A_line, (i + 1) * x + j, sy));
tripletList.push_back(T(A_line, i * x + (j + 1), sx));
@ -47,7 +51,7 @@ void BTCS2D(int x, int y, std::vector<double> &c, std::vector<double> &alpha,
std::cout << b << std::endl;
Eigen::SparseMatrix<double> A(size, (x * y) - 4);
Eigen::SparseMatrix<double> A(size, x*y);
A.setFromTriplets(tripletList.begin(), tripletList.end());
Eigen::SparseQR<Eigen::SparseMatrix<double>, Eigen::COLAMDOrdering<int>>

View File

@ -7,16 +7,16 @@ using namespace std;
int main(int argc, char *argv[]) {
int x = 5;
int y = 5;
int x = 4;
int y = 4;
std::vector<double> alpha(x * y, -1.5 * pow(10, -2));
std::vector<double> input(x * y, 0);
input[x + 1] = 5.55 * std::pow(10, -6);
input[x + 2] = 5.5556554 * std::pow(10, -6);
input[x + 3] = 5.234564213 * std::pow(10, -6);
std::vector<double> alpha(x * y, 1 * pow(10, -9));
std::vector<double> input(x * y, 1 * std::pow(10,-6));
input[x + 1] = 5 * std::pow(10, -6);
// input[x + 2] = 5.5556554 * std::pow(10, -6);
// input[x + 3] = 5.234564213 * std::pow(10, -6);
BTCS2D(x, y, input, alpha, 10.);
BTCS2D(x, y, input, alpha, 1.);
return 0;
}