Compare commits
6 Commits
1fc2925f8f
...
fix
| Author | SHA1 | Date | |
|---|---|---|---|
| 9b80340998 | |||
| 5b2331445c | |||
| e3c7b88dfb | |||
| 64cb04388a | |||
| b07c9e6cea | |||
| 1585c76980 |
@@ -1,12 +0,0 @@
|
|||||||
#include "Header.h"
|
|
||||||
#include "Solver.h"
|
|
||||||
#include <Eigen/Dense>
|
|
||||||
using namespace Eigen;
|
|
||||||
int main() {
|
|
||||||
Solver slv(5., 4., 0., 1., 30, 0, 10);
|
|
||||||
std::cout << "Linear element:";
|
|
||||||
slv.Execute_Linear(0, 5);
|
|
||||||
std::cout << "\nCubic element:";
|
|
||||||
slv.Execute_Cubic(0, 5);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
@@ -142,6 +142,7 @@
|
|||||||
<ConformanceMode>true</ConformanceMode>
|
<ConformanceMode>true</ConformanceMode>
|
||||||
<LanguageStandard>Default</LanguageStandard>
|
<LanguageStandard>Default</LanguageStandard>
|
||||||
<LanguageStandard_C>Default</LanguageStandard_C>
|
<LanguageStandard_C>Default</LanguageStandard_C>
|
||||||
|
<AdditionalIncludeDirectories>include/</AdditionalIncludeDirectories>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
@@ -156,6 +157,7 @@
|
|||||||
<ConformanceMode>true</ConformanceMode>
|
<ConformanceMode>true</ConformanceMode>
|
||||||
<LanguageStandard>Default</LanguageStandard>
|
<LanguageStandard>Default</LanguageStandard>
|
||||||
<LanguageStandard_C>Default</LanguageStandard_C>
|
<LanguageStandard_C>Default</LanguageStandard_C>
|
||||||
|
<AdditionalIncludeDirectories>include/</AdditionalIncludeDirectories>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
@@ -172,6 +174,7 @@
|
|||||||
<ConformanceMode>true</ConformanceMode>
|
<ConformanceMode>true</ConformanceMode>
|
||||||
<LanguageStandard>Default</LanguageStandard>
|
<LanguageStandard>Default</LanguageStandard>
|
||||||
<LanguageStandard_C>Default</LanguageStandard_C>
|
<LanguageStandard_C>Default</LanguageStandard_C>
|
||||||
|
<AdditionalIncludeDirectories>include/</AdditionalIncludeDirectories>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
@@ -179,15 +182,15 @@
|
|||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="MemMAPR-MKE.cpp" />
|
<ClCompile Include="src\MemMAPR-MKE.cpp" />
|
||||||
<ClCompile Include="Solver.cpp" />
|
<ClCompile Include="src\Solver.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="packages.config" />
|
<None Include="packages.config" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="Header.h" />
|
<ClInclude Include="include\Header.h" />
|
||||||
<ClInclude Include="Solver.h" />
|
<ClInclude Include="include\Solver.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
<ImportGroup Label="ExtensionTargets">
|
<ImportGroup Label="ExtensionTargets">
|
||||||
|
|||||||
@@ -18,22 +18,22 @@
|
|||||||
</Filter>
|
</Filter>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="MemMAPR-MKE.cpp">
|
<ClCompile Include="src\Solver.cpp">
|
||||||
<Filter>Исходные файлы</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Solver.cpp">
|
|
||||||
<Filter>Solver</Filter>
|
<Filter>Solver</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="src\MemMAPR-MKE.cpp">
|
||||||
|
<Filter>Исходные файлы</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="packages.config" />
|
<None Include="packages.config" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="Header.h">
|
<ClInclude Include="include\Solver.h">
|
||||||
<Filter>Исходные файлы</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="Solver.h">
|
|
||||||
<Filter>Solver</Filter>
|
<Filter>Solver</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="include\Header.h">
|
||||||
|
<Filter>Исходные файлы</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
@@ -102,7 +102,7 @@
|
|||||||
" y = np.fromstring(data_str, sep=' ')\n",
|
" y = np.fromstring(data_str, sep=' ')\n",
|
||||||
" y_real = u(x)\n",
|
" y_real = u(x)\n",
|
||||||
"\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.plot(x, y_real, label=\"Numeral solution\", color='black')\n",
|
||||||
" plt.title(f\"Linear element, elements = {elements}\")\n",
|
" plt.title(f\"Linear element, elements = {elements}\")\n",
|
||||||
" plt.grid(True)\n",
|
" plt.grid(True)\n",
|
||||||
@@ -138,7 +138,7 @@
|
|||||||
" y = np.fromstring(data_str, sep=' ')\n",
|
" y = np.fromstring(data_str, sep=' ')\n",
|
||||||
" y_real = u(x)\n",
|
" y_real = u(x)\n",
|
||||||
"\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.plot(x, y_real, label=\"Numeral solution\", color='black')\n",
|
||||||
" plt.title(f\"Cubic element, elements = {elements} \")\n",
|
" plt.title(f\"Cubic element, elements = {elements} \")\n",
|
||||||
" plt.xlabel(\"x\")\n",
|
" plt.xlabel(\"x\")\n",
|
||||||
|
|||||||
@@ -1,4 +1,10 @@
|
|||||||
|
// Особенности MSVC
|
||||||
|
#define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include <experimental/filesystem>
|
||||||
|
using namespace std;
|
||||||
|
using namespace std::experimental::filesystem;
|
||||||
|
|
||||||
class Solver {
|
class Solver {
|
||||||
private:
|
private:
|
||||||
@@ -14,4 +20,12 @@ public:
|
|||||||
Solver(double _A, double _B, double _C, double _D, int _N, int _l, int _u);
|
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_Linear(double value_1, double value_2);
|
||||||
void Execute_Cubic(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);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
18
src/MemMAPR-MKE.cpp
Normal file
18
src/MemMAPR-MKE.cpp
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
#include "Solver.h"
|
||||||
|
#include "Header.h"
|
||||||
|
#include <Eigen/Dense>
|
||||||
|
#define A 5.
|
||||||
|
#define B 4.
|
||||||
|
#define C 0.
|
||||||
|
#define D 1.
|
||||||
|
|
||||||
|
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);
|
||||||
|
std::cout << "Linear element:";
|
||||||
|
slv.Execute_Linear(0, 5);
|
||||||
|
std::cout << "\nCubic element:";
|
||||||
|
slv.Execute_Cubic(0, 5);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -3,6 +3,9 @@
|
|||||||
using namespace Eigen;
|
using namespace Eigen;
|
||||||
|
|
||||||
Solver::Solver(double _A, double _B, double _C, double _D, int _N, int _l, int _u) {
|
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;
|
A = _A, B = _B, C = _C, D = _D, N = _N;
|
||||||
upper = _u, lower = _l;
|
upper = _u, lower = _l;
|
||||||
L = (double)(upper - lower) / N;
|
L = (double)(upper - lower) / N;
|
||||||
@@ -16,24 +19,24 @@ void Solver::Execute_Linear(double val1, double val2) {
|
|||||||
// Локальный вектор нагрузки
|
// Локальный вектор нагрузки
|
||||||
VectorXd local_load(2);
|
VectorXd local_load(2);
|
||||||
|
|
||||||
local(0, 0) = -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 / 6.;
|
local(0, 1) = A / L + B / 2. + C * L / 2.;
|
||||||
local(1, 0) = A / L - B / 2. + C * L / 6.;
|
local(1, 0) = A / L - B / 2. + C * L / 2.;
|
||||||
local(1, 1) = -A / L + B / 2. + C * L / 3.;
|
local(1, 1) = -A / L + B / 2. + C * L / 2.;
|
||||||
|
|
||||||
local_load(0) = -D * L / 2.;
|
local_load(0) = -D * L / 2.;
|
||||||
local_load(1) = -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) {
|
for (int elem = 0; elem < N; ++elem) {
|
||||||
int node_i = elem;
|
int node_i = elem + 1;
|
||||||
int node_j = elem + 1;
|
int node_j = elem + 2;
|
||||||
|
|
||||||
ansamb(node_i, node_i) += local(0, 0);
|
ansamb(node_i, node_i) += local(0, 0);
|
||||||
ansamb(node_i, node_j) += local(0, 1);
|
ansamb(node_i, node_j) += local(0, 1);
|
||||||
@@ -50,17 +53,24 @@ void Solver::Execute_Linear(double val1, double val2) {
|
|||||||
std::cout << "Ansamb load vector:\n" << global_load << std::endl;
|
std::cout << "Ansamb load vector:\n" << global_load << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Граничные условия
|
// Boundary conditions
|
||||||
double u_right = val2;
|
double u_right = val2;
|
||||||
ansamb.row(0).setZero();
|
|
||||||
ansamb.row(N).setZero();
|
|
||||||
|
|
||||||
ansamb(0, 0) = L + 1;
|
// 3rd type of boundary condition
|
||||||
|
ansamb.row(0).setZero();
|
||||||
|
ansamb(0, 0) = 1;
|
||||||
ansamb(0, 1) = -1;
|
ansamb(0, 1) = -1;
|
||||||
global_load(0) = 0;
|
global_load(0) = 0;
|
||||||
|
ansamb(1, 1) -= A;
|
||||||
|
|
||||||
ansamb(N, N) = 1;
|
// 1st type of boundary condition
|
||||||
global_load(N) = u_right;
|
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;
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
std::cout << "\nAfter:" << std::endl;
|
std::cout << "\nAfter:" << std::endl;
|
||||||
@@ -74,7 +84,7 @@ void Solver::Execute_Linear(double val1, double val2) {
|
|||||||
std::cout << solution << std::endl;
|
std::cout << solution << std::endl;
|
||||||
|
|
||||||
std::ofstream file("matrix_linear_" + std::to_string(N) + ".txt");
|
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 << solution(i) << ' ';
|
||||||
}
|
}
|
||||||
file << std::endl;
|
file << std::endl;
|
||||||
@@ -82,7 +92,7 @@ void Solver::Execute_Linear(double val1, double val2) {
|
|||||||
|
|
||||||
void Solver::Execute_Cubic(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);
|
MatrixXd local = MatrixXd::Zero(4, 4);
|
||||||
@@ -111,24 +121,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, 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(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(0) = -D * L / 8.0;
|
||||||
local_load(1) = -D * 3.0 * L / 8.0;
|
local_load(1) = -D * 3.0 * L / 8.0;
|
||||||
local_load(2) = -D * 3.0 * L / 8.0;
|
local_load(2) = -D * 3.0 * L / 8.0;
|
||||||
local_load(3) = -D * L / 8.0;
|
local_load(3) = -D * L / 8.0;
|
||||||
|
|
||||||
// Глобальная матрица жёсткости
|
// Глобальные матрицы
|
||||||
MatrixXd ansamb = MatrixXd::Zero(mat_dim, mat_dim);
|
MatrixXd ansamb = MatrixXd::Zero(mat_dim, mat_dim);
|
||||||
|
|
||||||
// Глобальный вектор нагрузок
|
|
||||||
VectorXd global_load = VectorXd::Zero(mat_dim);
|
VectorXd global_load = VectorXd::Zero(mat_dim);
|
||||||
|
|
||||||
// Ансамблирование
|
// Ансамблирование (со смещением на 1, как в линейной версии)
|
||||||
for (int elem = 0; elem < N; ++elem) {
|
for (int elem = 0; elem < N; ++elem) {
|
||||||
int node_i = elem * 3;
|
int node_i = 1 + elem * 3; // смещение на 1
|
||||||
|
for (int i = 0; i < 4; ++i) {
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int j = 0; j < 4; ++j) {
|
||||||
for (int j = 0; j < 4; j++) {
|
|
||||||
ansamb(node_i + i, node_i + j) += local(i, j);
|
ansamb(node_i + i, node_i + j) += local(i, j);
|
||||||
}
|
}
|
||||||
global_load(node_i + i) += local_load(i);
|
global_load(node_i + i) += local_load(i);
|
||||||
@@ -144,12 +151,19 @@ void Solver::Execute_Cubic(double val1, double val2) {
|
|||||||
// Граничные условия
|
// Граничные условия
|
||||||
double u_right = val2;
|
double u_right = val2;
|
||||||
|
|
||||||
|
// 3rd type of boundary condition
|
||||||
ansamb.row(0).setZero();
|
ansamb.row(0).setZero();
|
||||||
ansamb(0, 0) = L / 3.0 + 1;
|
ansamb(0, 0) = 1;
|
||||||
ansamb(0, 1) = -1;
|
ansamb(0, 1) = -1;
|
||||||
global_load(0) = 0;
|
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.row(mat_dim - 1).setZero();
|
||||||
|
ansamb.col(mat_dim - 1).setZero();
|
||||||
ansamb(mat_dim - 1, mat_dim - 1) = 1;
|
ansamb(mat_dim - 1, mat_dim - 1) = 1;
|
||||||
global_load(mat_dim - 1) = u_right;
|
global_load(mat_dim - 1) = u_right;
|
||||||
|
|
||||||
@@ -165,7 +179,7 @@ void Solver::Execute_Cubic(double val1, double val2) {
|
|||||||
std::cout << solution << std::endl;
|
std::cout << solution << std::endl;
|
||||||
|
|
||||||
std::ofstream file("matrix_cubic_" + std::to_string(N) + ".txt");
|
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 << solution(i) << ' ';
|
||||||
}
|
}
|
||||||
file << std::endl;
|
file << std::endl;
|
||||||
Reference in New Issue
Block a user