From e3c7b88dfb1df7c4f34aae2e1286834a0547c91e Mon Sep 17 00:00:00 2001 From: ParkSuMin Date: Wed, 8 Oct 2025 21:14:13 +0300 Subject: [PATCH 1/2] New structure --- MemMAPR-MKE.vcxproj | 11 +++++++---- MemMAPR-MKE.vcxproj.filters | 16 ++++++++-------- Header.h => include/Header.h | 0 Solver.h => include/Solver.h | 14 ++++++++++++++ MemMAPR-MKE.cpp => src/MemMAPR-MKE.cpp | 6 +++--- Solver.cpp => src/Solver.cpp | 0 6 files changed, 32 insertions(+), 15 deletions(-) rename Header.h => include/Header.h (100%) rename Solver.h => include/Solver.h (61%) rename MemMAPR-MKE.cpp => src/MemMAPR-MKE.cpp (81%) rename Solver.cpp => src/Solver.cpp (100%) diff --git a/MemMAPR-MKE.vcxproj b/MemMAPR-MKE.vcxproj index 51fce13..ea86f90 100644 --- a/MemMAPR-MKE.vcxproj +++ b/MemMAPR-MKE.vcxproj @@ -142,6 +142,7 @@ true Default Default + include/ Console @@ -156,6 +157,7 @@ true Default Default + include/ Console @@ -172,6 +174,7 @@ true Default Default + include/ Console @@ -179,15 +182,15 @@ - - + + - - + + diff --git a/MemMAPR-MKE.vcxproj.filters b/MemMAPR-MKE.vcxproj.filters index 68b8f0e..6da7bf8 100644 --- a/MemMAPR-MKE.vcxproj.filters +++ b/MemMAPR-MKE.vcxproj.filters @@ -18,22 +18,22 @@ - - Исходные файлы - - + Solver + + Исходные файлы + - - Исходные файлы - - + Solver + + Исходные файлы + \ No newline at end of file diff --git a/Header.h b/include/Header.h similarity index 100% rename from Header.h rename to include/Header.h diff --git a/Solver.h b/include/Solver.h similarity index 61% rename from Solver.h rename to include/Solver.h index 9ea0440..5c33167 100644 --- a/Solver.h +++ b/include/Solver.h @@ -1,4 +1,10 @@ +// Особенности MSVC +#define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING + #pragma once +#include +using namespace std; +using namespace std::experimental::filesystem; class Solver { private: @@ -14,4 +20,12 @@ public: Solver(double _A, double _B, double _C, double _D, int _N, int _l, int _u); void Execute_Linear(double value_1, double value_2); void Execute_Cubic(double value_1, double value_2); + + bool check_path(string path) { + return exists(path); + } + + void make_path(string path) { + create_directory(path); + } }; \ No newline at end of file diff --git a/MemMAPR-MKE.cpp b/src/MemMAPR-MKE.cpp similarity index 81% rename from MemMAPR-MKE.cpp rename to src/MemMAPR-MKE.cpp index 0b8bee9..a69c864 100644 --- a/MemMAPR-MKE.cpp +++ b/src/MemMAPR-MKE.cpp @@ -1,5 +1,5 @@ -#include "Header.h" -#include "Solver.h" +#include "Solver.h" +#include "Header.h" #include #define A 5. #define B 4. @@ -9,7 +9,7 @@ using namespace Eigen; int main() { std::cout << A << "u''" << " + " << B << "u'" << "+ " << C << "u + " << D << " = 0" << std::endl; - Solver slv(A, B, C, D, 20, 0, 10); + Solver slv(A, B, C, D, 2, 0, 10); std::cout << "Linear element:"; slv.Execute_Linear(0, 5); std::cout << "\nCubic element:"; diff --git a/Solver.cpp b/src/Solver.cpp similarity index 100% rename from Solver.cpp rename to src/Solver.cpp From 5b2331445cf8030e70df91d89f86a4437f62e8c4 Mon Sep 17 00:00:00 2001 From: ParkSuMin Date: Wed, 8 Oct 2025 21:36:44 +0300 Subject: [PATCH 2/2] Modify code and notebook --- graphics.ipynb | 2 +- src/MemMAPR-MKE.cpp | 2 +- src/Solver.cpp | 17 ++++++++++++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/graphics.ipynb b/graphics.ipynb index 15bedf1..1872fe4 100644 --- a/graphics.ipynb +++ b/graphics.ipynb @@ -102,7 +102,7 @@ " y = np.fromstring(data_str, sep=' ')\n", " y_real = u(x)\n", "\n", - " plt.plot(x, y, label=\"Linear element solution\", color='red')\n", + " plt.plot(x, y, label=\"Linear element solution\", color='blue')\n", " plt.plot(x, y_real, label=\"Numeral solution\", color='black')\n", " plt.title(f\"Linear element, elements = {elements}\")\n", " plt.grid(True)\n", diff --git a/src/MemMAPR-MKE.cpp b/src/MemMAPR-MKE.cpp index a69c864..1fe9c78 100644 --- a/src/MemMAPR-MKE.cpp +++ b/src/MemMAPR-MKE.cpp @@ -9,7 +9,7 @@ using namespace Eigen; int main() { std::cout << A << "u''" << " + " << B << "u'" << "+ " << C << "u + " << D << " = 0" << std::endl; - Solver slv(A, B, C, D, 2, 0, 10); + Solver slv(A, B, C, D, 20, 0, 10); std::cout << "Linear element:"; slv.Execute_Linear(0, 5); std::cout << "\nCubic element:"; diff --git a/src/Solver.cpp b/src/Solver.cpp index a17b817..c84c387 100644 --- a/src/Solver.cpp +++ b/src/Solver.cpp @@ -3,6 +3,9 @@ using namespace Eigen; Solver::Solver(double _A, double _B, double _C, double _D, int _N, int _l, int _u) { + if (_N < 1) + throw std::runtime_error("N CAN BE OVER THAN 1!"); + A = _A, B = _B, C = _C, D = _D, N = _N; upper = _u, lower = _l; L = (double)(upper - lower) / N; @@ -50,16 +53,22 @@ void Solver::Execute_Linear(double val1, double val2) { std::cout << "Ansamb load vector:\n" << global_load << std::endl; #endif - // Граничные условия + // Boundary conditions double u_right = val2; + // 3rd type of boundary condition ansamb.row(0).setZero(); ansamb(0, 0) = 1; ansamb(0, 1) = -1; global_load(0) = 0; ansamb(1, 1) -= A; + // 1st type of boundary condition + for (int i = 0; i < global_load.size(); ++i) { + global_load(i) = global_load(i) - u_right * ansamb(i, N + 1); + } ansamb.row(N + 1).setZero(); + ansamb.col(N + 1).setZero(); ansamb(N + 1, N + 1) = 1; global_load(N + 1) = u_right; @@ -142,13 +151,19 @@ void Solver::Execute_Cubic(double val1, double val2) { // Граничные условия double u_right = val2; + // 3rd type of boundary condition ansamb.row(0).setZero(); ansamb(0, 0) = 1; ansamb(0, 1) = -1; global_load(0) = 0; ansamb(1, 1) -= A; + // 1st type of boundary condition + for (int i = 0; i < global_load.size(); ++i) { + global_load(i) = global_load(i) - u_right * ansamb(i, mat_dim - 1); + } ansamb.row(mat_dim - 1).setZero(); + ansamb.col(mat_dim - 1).setZero(); ansamb(mat_dim - 1, mat_dim - 1) = 1; global_load(mat_dim - 1) = u_right;