cross testing FTCS prototype with existing ADI solution

This commit is contained in:
philippun 2023-06-28 14:39:54 +02:00
parent 214cb717d3
commit 5688c82da2
2 changed files with 61 additions and 29 deletions

View File

@ -2,6 +2,8 @@
#include <tug/Diffusion.hpp>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
using namespace tug::diffusion;
@ -10,12 +12,12 @@ using namespace tug::bc;
int main(int argc, char *argv[]) {
int dim = 2;
int n = 5;
int m = 5;
int n = 20;
int m = 20;
vector<double> alpha(n * m, 1e-1);
vector<double> alpha(n * m, 1);
vector<double> field(n * m, 0);
field[0] = 1e-6;
field[0] = 2000;
// for (int i = 1; i<20; i++) {
// for (int j = 0; j<20; j++ ) {
// field[i] = 0;
@ -33,25 +35,55 @@ int main(int argc, char *argv[]) {
cout << endl;
TugInput input_param;
input_param.setTimestep(1.);
input_param.setTimestep(0.1);
input_param.setGridCellN(n, m);
input_param.setDomainSize(n, m);
BoundaryCondition bc(n, m);
boundary_condition bc_constant;
bc_constant.type = BC_TYPE_CONSTANT;
bc_constant.value = 0;
bc.setSide(BC_SIDE_LEFT, bc_constant);
bc.setSide(BC_SIDE_TOP, bc_constant);
bc.setSide(BC_SIDE_RIGHT, bc_constant);
bc.setSide(BC_SIDE_BOTTOM, bc_constant);
input_param.setBoundaryCondition(bc);
// int iterations = 1000;
// for (int t = 0; t < iterations; t++) {
// double result = ADI_2D(input_param, &field[0], &alpha[0]);
// if (t % 100 == 0) {
// cout << "Iteration " << t << ":" << endl;
// for (int i = 0; i<n; i++) {
// for (int j = 0; j<m; j++) {
// cout << field[n * i + j] << " ";
// }
// cout << endl;
// }
// cout << endl;
// }
// }
ofstream myfile;
myfile.open("output.csv");
if (!myfile) {
exit(1);
}
int iterations = 1000;
for (int t = 0; t < iterations; t++) {
double result = ADI_2D(input_param, &field[0], &alpha[0]);
if (t % 100 == 0) {
cout << "Iteration " << t << ":" << endl;
for (int i = 0; i<n; i++) {
for (int j = 0; j<m; j++) {
cout << field[n * i + j] << " ";
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
myfile << field[i * m + j];
if (j < m-1) {
myfile << ", ";
}
cout << endl;
}
cout << endl;
myfile << "\n";
}
myfile << std::endl << std::endl;
}
myfile.close();
}

File diff suppressed because one or more lines are too long