From 8957f65064b95604a7c3d0c84299e4d600d35ad3 Mon Sep 17 00:00:00 2001 From: ParkSuMin Date: Mon, 29 Sep 2025 18:09:58 +0300 Subject: [PATCH 1/4] Add C-part to local matrix for linear element --- Solver.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Solver.cpp b/Solver.cpp index a646e30..341c0bb 100644 --- a/Solver.cpp +++ b/Solver.cpp @@ -16,10 +16,10 @@ void Solver::Execute_Linear(double val1, double val2) { // Локальный вектор нагрузки VectorXd local_load(2); - local(0, 0) = -A / L - B / 2.;// +C * L / 3.; - local(0, 1) = A / L + B / 2.; // +C * L / 6.; - local(1, 0) = A / L - B / 2.; // +C * L / 6.; - local(1, 1) = -A / L + B / 2.;// +C * L / 3.; + local(0, 0) = -A / L - B / 2. + C * L / 3.; + local(0, 1) = A / L + B / 2. + C * L / 6.; + local(1, 0) = A / L - B / 2. + C * L / 6.; + local(1, 1) = -A / L + B / 2. + C * L / 3.; local_load(0) = -D * L / 2.; local_load(1) = -D * L / 2.; From 1fc2925f8f37b0b6bbd0349221f2a55383df88c2 Mon Sep 17 00:00:00 2001 From: ParkSuMin Date: Mon, 29 Sep 2025 19:21:04 +0300 Subject: [PATCH 2/4] Add C-part to local matrix for cubic element --- Solver.cpp | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/Solver.cpp b/Solver.cpp index 341c0bb..6234ff3 100644 --- a/Solver.cpp +++ b/Solver.cpp @@ -91,25 +91,25 @@ void Solver::Execute_Cubic(double val1, double val2) { VectorXd local_load(4); // Формирование локальной матрицы жёсткости - local(0, 0) = -A * 37.0 / 10.0 / L + B * (-1.0) / 2.0; - local(0, 1) = -A * (-189.0) / 40.0 / L + B * 57.0 / 80.0; - local(0, 2) = -A * 27.0 / 20.0 / L + B * (-3.0) / 10.0; - local(0, 3) = -A * (-13.0) / 40.0 / L + B * 7.0 / 80.0; + local(0, 0) = -A * 37.0 / 10.0 / L + B * (-1.0) / 2.0 + C * 8. * L / 105.; + local(0, 1) = -A * (-189.0) / 40.0 / L + B * 57.0 / 80.0 + C * 33. * L / 560.; + local(0, 2) = -A * 27.0 / 20.0 / L + B * (-3.0) / 10.0 - C * 3. * L / 140.; + local(0, 3) = -A * (-13.0) / 40.0 / L + B * 7.0 / 80.0 + C * 19. * L / 1680.; - local(1, 0) = -A * (-189.0) / 40.0 / L + B * (-57.0) / 80.0; - local(1, 1) = -A * 54.0 / 5.0 / L; - local(1, 2) = -A * (-297.0) / 40.0 / L + B * 81.0 / 80.0; - local(1, 3) = -A * 27.0 / 20.0 / L + B * (-3.0) / 10.0; + local(1, 0) = -A * (-189.0) / 40.0 / L + B * (-57.0) / 80.0 + C * 33. * L / 560.; + local(1, 1) = -A * 54.0 / 5.0 / L + C * 27. * L / 70.; + local(1, 2) = -A * (-297.0) / 40.0 / L + B * 81.0 / 80.0 - C * 27. * L / 560.; + local(1, 3) = -A * 27.0 / 20.0 / L + B * (-3.0) / 10.0 - C * 3. * L / 140.; - local(2, 0) = -A * 27.0 / 20.0 / L + B * 3.0 / 10.0; - local(2, 1) = -A * (-297.0) / 40.0 / L + B * (-81.0) / 80.0; - local(2, 2) = -A * 54.0 / 5.0 / L; - local(2, 3) = -A * (-189.0) / 40.0 / L + B * 57.0 / 80.0; + local(2, 0) = -A * 27.0 / 20.0 / L + B * 3.0 / 10.0 - C * 3. * L / 140.; + local(2, 1) = -A * (-297.0) / 40.0 / L + B * (-81.0) / 80.0 - C * 27. * L / 560.; + local(2, 2) = -A * 54.0 / 5.0 / L + C * 27. * L / 70.; + local(2, 3) = -A * (-189.0) / 40.0 / L + B * 57.0 / 80.0 + C * 33. * L / 560.; - local(3, 0) = -A * (-13.0) / 40.0 / L + B * (-7.0) / 80.0; - local(3, 1) = -A * 27.0 / 20.0 / L + B * 3.0 / 10.0; - local(3, 2) = -A * (-189.0) / 40.0 / L + B * (-57.0) / 80.0; - local(3, 3) = -A * 37.0 / 10.0 / L + B * 1.0 / 2.0; + local(3, 0) = -A * (-13.0) / 40.0 / L + B * (-7.0) / 80.0 + C * 19. * L / 1680.; + local(3, 1) = -A * 27.0 / 20.0 / L + B * 3.0 / 10.0 - C * 3. * L / 140.; + local(3, 2) = -A * (-189.0) / 40.0 / L + B * (-57.0) / 80.0 + C * 33. * L / 560.; + local(3, 3) = -A * 37.0 / 10.0 / L + B * 1.0 / 2.0 + C * 8. * L / 105.; // Формирование локального вектора нагрузки local_load(0) = -D * L / 8.0; From 1585c76980cb6779027a4a307de4e6323d9b0b22 Mon Sep 17 00:00:00 2001 From: ParkSuMin Date: Thu, 2 Oct 2025 15:46:22 +0300 Subject: [PATCH 3/4] I hate GU3 --- MemMAPR-MKE.cpp | 10 ++++++++-- Solver.cpp | 33 ++++++++++++++++++--------------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/MemMAPR-MKE.cpp b/MemMAPR-MKE.cpp index 7c5fb21..baa3a72 100644 --- a/MemMAPR-MKE.cpp +++ b/MemMAPR-MKE.cpp @@ -1,12 +1,18 @@ #include "Header.h" #include "Solver.h" #include +#define A 5. +#define B 4. +#define C 0. +#define D 1. + using namespace Eigen; int main() { - Solver slv(5., 4., 0., 1., 30, 0, 10); + std::cout << A << "u''" << " + " << B << "u'" << "+ " << C << "u + " << D << " = 0" << std::endl; + Solver slv(5., 4., 0., 1., 2, 0, 10); std::cout << "Linear element:"; slv.Execute_Linear(0, 5); std::cout << "\nCubic element:"; - slv.Execute_Cubic(0, 5); + //slv.Execute_Cubic(0, 5); return 0; } \ No newline at end of file diff --git a/Solver.cpp b/Solver.cpp index 6234ff3..1065ec0 100644 --- a/Solver.cpp +++ b/Solver.cpp @@ -16,24 +16,24 @@ void Solver::Execute_Linear(double val1, double val2) { // Локальный вектор нагрузки VectorXd local_load(2); - local(0, 0) = -A / L - B / 2. + C * L / 3.; - local(0, 1) = A / L + B / 2. + C * L / 6.; - local(1, 0) = A / L - B / 2. + C * L / 6.; - local(1, 1) = -A / L + B / 2. + C * L / 3.; + local(0, 0) = -A / L - B / 2. + C * L / 2.; + local(0, 1) = A / L + B / 2. + C * L / 2.; + local(1, 0) = A / L - B / 2. + C * L / 2.; + local(1, 1) = -A / L + B / 2. + C * L / 2.; local_load(0) = -D * L / 2.; local_load(1) = -D * L / 2.; // Глобальная матрица жёсткости - MatrixXd ansamb = MatrixXd::Zero(N + 1, N + 1); + MatrixXd ansamb = MatrixXd::Zero(N + 2, N + 2); // Глобальный вектор нагрузок - VectorXd global_load = VectorXd::Zero(N + 1); + VectorXd global_load = VectorXd::Zero(N + 2); - // Ансамблирование + // Ансамблирование (с учётом смещения на 1) for (int elem = 0; elem < N; ++elem) { - int node_i = elem; - int node_j = elem + 1; + int node_i = elem + 1; + int node_j = elem + 2; ansamb(node_i, node_i) += local(0, 0); ansamb(node_i, node_j) += local(0, 1); @@ -52,15 +52,18 @@ void Solver::Execute_Linear(double val1, double val2) { // Граничные условия double u_right = val2; + + ansamb.row(0).setZero(); - ansamb.row(N).setZero(); - - ansamb(0, 0) = L + 1; - ansamb(0, 1) = -1; + ansamb(0, 0) = 1; + ansamb(0, 1) = -A; global_load(0) = 0; + ansamb(1, 1) += -A; - ansamb(N, N) = 1; - global_load(N) = u_right; + ansamb.row(N + 1).setZero(); + ansamb.col(N + 1).setZero(); + ansamb(N + 1, N + 1) = 1; + global_load(N + 1) = u_right; #if DEBUG std::cout << "\nAfter:" << std::endl; From b07c9e6cea8b7f40db8c9ed996a03a931e0113af Mon Sep 17 00:00:00 2001 From: ParkSuMin Date: Mon, 6 Oct 2025 22:22:02 +0300 Subject: [PATCH 4/4] Edit border boundaries Edit graphics notebook --- MemMAPR-MKE.cpp | 4 ++-- Solver.cpp | 36 ++++++++++++++++-------------------- graphics.ipynb | 2 +- 3 files changed, 19 insertions(+), 23 deletions(-) diff --git a/MemMAPR-MKE.cpp b/MemMAPR-MKE.cpp index baa3a72..0b8bee9 100644 --- a/MemMAPR-MKE.cpp +++ b/MemMAPR-MKE.cpp @@ -9,10 +9,10 @@ using namespace Eigen; int main() { std::cout << A << "u''" << " + " << B << "u'" << "+ " << C << "u + " << D << " = 0" << std::endl; - Solver slv(5., 4., 0., 1., 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:"; - //slv.Execute_Cubic(0, 5); + slv.Execute_Cubic(0, 5); return 0; } \ No newline at end of file diff --git a/Solver.cpp b/Solver.cpp index 1065ec0..a17b817 100644 --- a/Solver.cpp +++ b/Solver.cpp @@ -23,10 +23,10 @@ void Solver::Execute_Linear(double val1, double val2) { local_load(0) = -D * L / 2.; local_load(1) = -D * L / 2.; - + // Глобальная матрица жёсткости MatrixXd ansamb = MatrixXd::Zero(N + 2, N + 2); - + // Глобальный вектор нагрузок VectorXd global_load = VectorXd::Zero(N + 2); @@ -53,15 +53,13 @@ void Solver::Execute_Linear(double val1, double val2) { // Граничные условия double u_right = val2; - ansamb.row(0).setZero(); ansamb(0, 0) = 1; - ansamb(0, 1) = -A; + ansamb(0, 1) = -1; global_load(0) = 0; - ansamb(1, 1) += -A; + ansamb(1, 1) -= A; ansamb.row(N + 1).setZero(); - ansamb.col(N + 1).setZero(); ansamb(N + 1, N + 1) = 1; global_load(N + 1) = u_right; @@ -77,7 +75,7 @@ void Solver::Execute_Linear(double val1, double val2) { std::cout << solution << std::endl; std::ofstream file("matrix_linear_" + std::to_string(N) + ".txt"); - for (int i = 0; i < solution.size(); i++) { + for (int i = 1; i < solution.size(); i++) { file << solution(i) << ' '; } file << std::endl; @@ -85,7 +83,7 @@ void Solver::Execute_Linear(double val1, double val2) { void Solver::Execute_Cubic(double val1, double val2) { - int mat_dim = 1 + N * 3; + int mat_dim = N * 3 + 2; // +2 для граничных узлов, как в линейном случае // Локальная матрица жёсткости MatrixXd local = MatrixXd::Zero(4, 4); @@ -96,7 +94,7 @@ void Solver::Execute_Cubic(double val1, double val2) { // Формирование локальной матрицы жёсткости local(0, 0) = -A * 37.0 / 10.0 / L + B * (-1.0) / 2.0 + C * 8. * L / 105.; local(0, 1) = -A * (-189.0) / 40.0 / L + B * 57.0 / 80.0 + C * 33. * L / 560.; - local(0, 2) = -A * 27.0 / 20.0 / L + B * (-3.0) / 10.0 - C * 3. * L / 140.; + local(0, 2) = -A * 27.0 / 20.0 / L + B * (-3.0) / 10.0 - C * 3. * L / 140.; local(0, 3) = -A * (-13.0) / 40.0 / L + B * 7.0 / 80.0 + C * 19. * L / 1680.; local(1, 0) = -A * (-189.0) / 40.0 / L + B * (-57.0) / 80.0 + C * 33. * L / 560.; @@ -114,24 +112,21 @@ void Solver::Execute_Cubic(double val1, double val2) { local(3, 2) = -A * (-189.0) / 40.0 / L + B * (-57.0) / 80.0 + C * 33. * L / 560.; local(3, 3) = -A * 37.0 / 10.0 / L + B * 1.0 / 2.0 + C * 8. * L / 105.; - // Формирование локального вектора нагрузки + // Локальный вектор нагрузки local_load(0) = -D * L / 8.0; local_load(1) = -D * 3.0 * L / 8.0; local_load(2) = -D * 3.0 * L / 8.0; local_load(3) = -D * L / 8.0; - // Глобальная матрица жёсткости + // Глобальные матрицы MatrixXd ansamb = MatrixXd::Zero(mat_dim, mat_dim); - - // Глобальный вектор нагрузок VectorXd global_load = VectorXd::Zero(mat_dim); - // Ансамблирование + // Ансамблирование (со смещением на 1, как в линейной версии) for (int elem = 0; elem < N; ++elem) { - int node_i = elem * 3; - - for (int i = 0; i < 4; i++) { - for (int j = 0; j < 4; j++) { + int node_i = 1 + elem * 3; // смещение на 1 + for (int i = 0; i < 4; ++i) { + for (int j = 0; j < 4; ++j) { ansamb(node_i + i, node_i + j) += local(i, j); } global_load(node_i + i) += local_load(i); @@ -148,9 +143,10 @@ void Solver::Execute_Cubic(double val1, double val2) { double u_right = val2; ansamb.row(0).setZero(); - ansamb(0, 0) = L / 3.0 + 1; + ansamb(0, 0) = 1; ansamb(0, 1) = -1; global_load(0) = 0; + ansamb(1, 1) -= A; ansamb.row(mat_dim - 1).setZero(); ansamb(mat_dim - 1, mat_dim - 1) = 1; @@ -168,7 +164,7 @@ void Solver::Execute_Cubic(double val1, double val2) { std::cout << solution << std::endl; std::ofstream file("matrix_cubic_" + std::to_string(N) + ".txt"); - for (int i = 0; i < solution.size(); i++) { + for (int i = 1; i < solution.size(); i++) { file << solution(i) << ' '; } file << std::endl; diff --git a/graphics.ipynb b/graphics.ipynb index 1ae90e8..15bedf1 100644 --- a/graphics.ipynb +++ b/graphics.ipynb @@ -138,7 +138,7 @@ " y = np.fromstring(data_str, sep=' ')\n", " y_real = u(x)\n", "\n", - " plt.plot(x, y, label=\"Cubic element solution\", color=\"orange\")\n", + " plt.plot(x, y, label=\"Cubic element solution\", color=\"red\")\n", " plt.plot(x, y_real, label=\"Numeral solution\", color='black')\n", " plt.title(f\"Cubic element, elements = {elements} \")\n", " plt.xlabel(\"x\")\n",