Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Build application

on: [push, pull_request]

jobs:
ubuntu-gcc-build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Build
run: |
sudo apt-get update
sudo apt install libomp-dev
cd Poisson_Equation/src
g++ -mavx2 -mfma -fopenmp -o out.exe test.cpp -I./../headers/ -std=c++17 -O3
- name: Run test
shell: bash
run: |
cd Poisson_Equation/src
./out.exe
10 changes: 10 additions & 0 deletions Poisson_Equation/files/Approximation.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
0.367879 0.527292 0.697676 0.852144 0.960789 1 0.960789 0.852144 0.697676 0.527292 0.367879
0.527292 0.755035 0.999793 1.2224 1.37932 1.43613 1.37967 1.22293 1.00029 0.755327 0.527292
0.697676 0.999622 1.32406 1.61925 1.82745 1.90297 1.82831 1.62053 1.32523 1.00029 0.697676
0.852144 1.22171 1.61832 1.97897 2.23333 2.3258 2.23516 1.98153 1.62053 1.22293 0.852144
0.960789 1.37769 1.82441 2.23022 2.51625 2.6204 2.52012 2.23516 1.82831 1.37967 0.960789
1 1.43333 1.89648 2.31637 2.6117 2.71828 2.6204 2.3258 1.90297 1.43613 1
0 0 0 0 0 2.6117 2.51625 2.23333 1.82745 1.37932 0.960789
0 0 0 0 0 2.31637 2.23022 1.97897 1.61925 1.2224 0.852144
0 0 0 0 0 1.89648 1.82441 1.61832 1.32406 0.999793 0.697676
0 0 0 0 0 1.43333 1.37769 1.22171 0.999622 0.755035 0.527292
10 changes: 10 additions & 0 deletions Poisson_Equation/files/Correct.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
0.367879 0.527292 0.697676 0.852144 0.960789 1 0.960789 0.852144 0.697676 0.527292 0.367879
0.527292 0.755784 1 1.2214 1.37713 1.43333 1.37713 1.2214 1 0.755784 0.527292
0.697676 1 1.32313 1.61607 1.82212 1.89648 1.82212 1.61607 1.32313 1 0.697676
0.852144 1.2214 1.61607 1.97388 2.22554 2.31637 2.22554 1.97388 1.61607 1.2214 0.852144
0.960789 1.37713 1.82212 2.22554 2.50929 2.6117 2.50929 2.22554 1.82212 1.37713 0.960789
1 1.43333 1.89648 2.31637 2.6117 2.71828 2.6117 2.31637 1.89648 1.43333 1
0 0 0 0 0 2.6117 2.50929 2.22554 1.82212 1.37713 0.960789
0 0 0 0 0 2.31637 2.22554 1.97388 1.61607 1.2214 0.852144
0 0 0 0 0 1.89648 1.82212 1.61607 1.32313 1 0.697676
0 0 0 0 0 1.43333 1.37713 1.2214 1 0.755784 0.527292
2 changes: 2 additions & 0 deletions Poisson_Equation/files/Error.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Задача решена с погрешностью 0.0108329
Максимальное отклонение точного и численного решений в точке x = 0.2, y = 0.6
3 changes: 3 additions & 0 deletions Poisson_Equation/files/Solver_results.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
2.8212e-09
2.49716e-08
22
3 changes: 3 additions & 0 deletions Poisson_Equation/files/Solver_results_2N.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
9.71618e-09
5.01926e-06
582
148 changes: 133 additions & 15 deletions Poisson_Equation/headers/Dirichlet_Problem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <memory>
#include <iostream>
#include <functional>
#include <fstream>

using FP = double;

Expand Down Expand Up @@ -53,6 +54,7 @@ namespace numcpp {
using two_dim_function = std::function<FP(FP, FP)>;

size_t m, n;
size_t task_num;
std::unique_ptr<ISolver> solver;
std::array<FP, 4> corners; // {x0, y0, xn, ym}

Expand Down Expand Up @@ -105,6 +107,11 @@ namespace numcpp {
this->mu5 = std::move(new_mu[4]);
this->mu6 = std::move(new_mu[5]);
}

void set_task_num(size_t num)
{
this->task_num = num;
}
};


Expand Down Expand Up @@ -210,23 +217,69 @@ std::vector<std::vector<FP>> const DirichletProblemSolver<GridType::Regular>::so
solver->set_system_matrix(std::move(matrix));
solver->set_b(b);
std::vector<FP> solution = solver->solve();
std::vector<std::vector<FP>> res(n + 1, std::vector<FP>(m + 1, 0));
if(task_num == 0)
{
FP error = 0;
FP x_max = 0;
FP y_max = 0;

std::vector<std::vector<FP>> res;
res.resize(m - 1);
for(size_t i = 0; i < m - 1; i++)
{
for(size_t j = 0; j < n - 1; j++)
{
FP y = corners[1] + (i + 1) * k;
FP x = corners[0] + (j + 1) * h;
FP dot_solution = solution[(n - 1) * i + j];
FP dot_correct = u(x, y);
if(std::abs(dot_correct - dot_solution) > error)
{
error = std::abs(dot_correct - dot_solution);
x_max = x;
y_max = y;
}
}
}
std::ofstream fout_res("../files/Error.txt");
fout_res << "Задача решена с погрешностью " << error << "\nМаксимальное отклонение точного и численного решений в точке x = " << x_max << ", y = " << y_max << '\n';
fout_res.close();
}



FP start_x = corners[0];
FP start_y = corners[1];

FP approximation_error = 0;
for (size_t j = 0; j <= m; ++j)
{
res[0][j] = mu1(start_y + static_cast<FP>(j) * k);
}
for (size_t j = 0; j <= m; ++j)
{
res[n][j] = mu2(start_y + static_cast<FP>(j) * k);
}

for(size_t i = 0; i < m - 1; i++)
for(size_t j = 0; j < n - 1; j++)

for (size_t i = 1; i <= n; ++i)
{
res[i][0] = mu3(start_x + static_cast<FP>(i) * h);
}
for (size_t i = 1; i <= n; ++i)
{
res[i][m] = mu4(start_x + static_cast<FP>(i) * h);
}

size_t index = 0;
for (size_t j = 1; j < m; ++j)
{
for (size_t i = 1; i < n; ++i)
{
FP y = corners[1] + (i + 1) * k;
FP x = corners[0] + (j + 1) * h;
FP dot_solution = solution[(n - 1) * i + j];
approximation_error = std::max(std::abs(u(x, y) - dot_solution), approximation_error);
res[i].push_back(dot_solution);
res[i][j] = solution[index++];
}

std::cout << "General error: " << approximation_error << '\n';
}



return res;
}

Expand Down Expand Up @@ -501,20 +554,85 @@ std::vector<std::vector<FP>> const DirichletProblemSolver<GridType::Regular>::so
solver->set_b(b);
std::vector<FP> solution = solver->solve();

FP x_max_err = 0.0;
FP y_max_err = 0.0;
FP approximation_error = 0.0;
for (size_t i = 0; i < sz; ++i)
{
approximation_error = std::max(std::abs(solution[i] - real_sol[i]), approximation_error);
if (std::abs(solution[i] - real_sol[i]) > approximation_error)
{
approximation_error = std::abs(solution[i] - real_sol[i]);
if (i < (n / 2 - 1) * (m / 2))
{
x_max_err = start_x + static_cast<FP>(n / 2 + 1 + i % (n / 2 - 1)) * h;
y_max_err = start_y + static_cast<FP>(1 + static_cast<int>(i / (n / 2 - 1))) * k;
}
else
{
x_max_err = start_x + static_cast<FP>(1 + (i - (n / 2 - 1) * (m / 2)) % (n - 1)) * h;
y_max_err = start_y + static_cast<FP>(m / 2 + 1 + static_cast<int>((i - (n / 2 - 1) * (m / 2)) / (n - 1))) * k;
}
}
}

std::cout << "Node with maximum error: x = " << x_max_err << ", y = " << y_max_err << std::endl;
std::cout << "General error: " << approximation_error << std::endl;

std::ofstream fout_res("../files/Error.txt");
fout_res << "Задача решена с погрешностью " << approximation_error << "\nМаксимальное отклонение точного и численного решений в точке x = " << x_max_err << ", y = " << y_max_err << '\n';
fout_res.close();

std::vector<std::vector<FP>> res(n + 1, std::vector<FP>(m + 1, 0));

for (size_t j = m / 2; j <= m; ++j)
{
res[0][j] = mu1(start_y + static_cast<FP>(j) * k);
}
for (size_t j = 0; j <= m / 2; ++j)
{
res[n / 2][j] = mu2(start_y + static_cast<FP>(j) * k);
}
for (size_t j = 0; j <= m; ++j)
{
res[n][j] = mu3(start_y + static_cast<FP>(j) * k);
}

for (size_t i = n / 2 + 1; i < n; ++i)
{
res[i][0] = mu4(start_x + static_cast<FP>(i) * h);
}
for (size_t i = 1; i < n / 2; ++i)
{
res[i][m / 2] = mu5(start_x + static_cast<FP>(i) * h);
}
for (size_t i = 1; i < n; ++i)
{
res[i][m] = mu6(start_x + static_cast<FP>(i) * h);
}

size_t index = 0;
for (size_t j = 1; j <= m / 2; ++j)
{
for (size_t i = n / 2 + 1; i < n; ++i)
{
res[i][j] = solution[index++];
}
}
for (size_t j = m / 2 + 1; j < m; ++j)
{
for (size_t i = 1; i < n; ++i)
{
res[i][j] = solution[index++];
}
}

// Placeholder
return std::vector<std::vector<FP>>();
return res;
}


} // namespace numcpp



#endif // __DIRICHLET_PROBLEM_HPP__
#endif // __DIRICHLET_PROBLEM_HPP__
Loading