Compare commits
4 Commits
e53cef771a
...
af1950982b
| Author | SHA1 | Date | |
|---|---|---|---|
| af1950982b | |||
| 5a8c3357ca | |||
| 4ab15cb13b | |||
| dc0df855d7 |
@@ -1,11 +1,12 @@
|
|||||||
#include "Header.h"
|
#include "Header.h"
|
||||||
#include "Solver.h"
|
#include "Solver.h"
|
||||||
|
#include <Eigen/Dense>
|
||||||
|
using namespace Eigen;
|
||||||
int main() {
|
int main() {
|
||||||
Solver slv(3., 2., 5., 20, 1, 6);
|
Solver slv(5., 4., 0., 1., 30, 0, 10);
|
||||||
std::cout << "Linear element:" << std::endl;
|
std::cout << "Linear element:" << std::endl;
|
||||||
slv.Execute_Linear(-5, -10);
|
slv.Execute_Linear(0, 5);
|
||||||
std::cout << "\nCubic element:" << std::endl;
|
//std::cout << "\nCubic element:" << std::endl;
|
||||||
slv.Execute_Cubic(-5, -10);
|
//slv.Execute_Cubic(0, 5);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -1,18 +1,24 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio Version 17
|
# Visual Studio Version 17
|
||||||
VisualStudioVersion = 17.14.36310.24 d17.14
|
VisualStudioVersion = 17.14.36310.24
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MemMAPR-MKE", "MemMAPR-MKE.vcxproj", "{5D2C9737-E669-4AF1-9B8C-4339EF6E4EB0}"
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MemMAPR-MKE", "MemMAPR-MKE.vcxproj", "{5D2C9737-E669-4AF1-9B8C-4339EF6E4EB0}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
DEBUG_THIRD|x64 = DEBUG_THIRD|x64
|
||||||
|
DEBUG_THIRD|x86 = DEBUG_THIRD|x86
|
||||||
Debug|x64 = Debug|x64
|
Debug|x64 = Debug|x64
|
||||||
Debug|x86 = Debug|x86
|
Debug|x86 = Debug|x86
|
||||||
Release|x64 = Release|x64
|
Release|x64 = Release|x64
|
||||||
Release|x86 = Release|x86
|
Release|x86 = Release|x86
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{5D2C9737-E669-4AF1-9B8C-4339EF6E4EB0}.DEBUG_THIRD|x64.ActiveCfg = DEBUG_FIRST|x64
|
||||||
|
{5D2C9737-E669-4AF1-9B8C-4339EF6E4EB0}.DEBUG_THIRD|x64.Build.0 = DEBUG_FIRST|x64
|
||||||
|
{5D2C9737-E669-4AF1-9B8C-4339EF6E4EB0}.DEBUG_THIRD|x86.ActiveCfg = DEBUG_FIRST|Win32
|
||||||
|
{5D2C9737-E669-4AF1-9B8C-4339EF6E4EB0}.DEBUG_THIRD|x86.Build.0 = DEBUG_FIRST|Win32
|
||||||
{5D2C9737-E669-4AF1-9B8C-4339EF6E4EB0}.Debug|x64.ActiveCfg = Debug|x64
|
{5D2C9737-E669-4AF1-9B8C-4339EF6E4EB0}.Debug|x64.ActiveCfg = Debug|x64
|
||||||
{5D2C9737-E669-4AF1-9B8C-4339EF6E4EB0}.Debug|x64.Build.0 = Debug|x64
|
{5D2C9737-E669-4AF1-9B8C-4339EF6E4EB0}.Debug|x64.Build.0 = Debug|x64
|
||||||
{5D2C9737-E669-4AF1-9B8C-4339EF6E4EB0}.Debug|x86.ActiveCfg = Debug|Win32
|
{5D2C9737-E669-4AF1-9B8C-4339EF6E4EB0}.Debug|x86.ActiveCfg = Debug|Win32
|
||||||
|
|||||||
@@ -1,6 +1,14 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
<ItemGroup Label="ProjectConfigurations">
|
<ItemGroup Label="ProjectConfigurations">
|
||||||
|
<ProjectConfiguration Include="DEBUG_FIRST|Win32">
|
||||||
|
<Configuration>DEBUG_FIRST</Configuration>
|
||||||
|
<Platform>Win32</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="DEBUG_FIRST|x64">
|
||||||
|
<Configuration>DEBUG_FIRST</Configuration>
|
||||||
|
<Platform>x64</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
<ProjectConfiguration Include="Debug|Win32">
|
<ProjectConfiguration Include="Debug|Win32">
|
||||||
<Configuration>Debug</Configuration>
|
<Configuration>Debug</Configuration>
|
||||||
<Platform>Win32</Platform>
|
<Platform>Win32</Platform>
|
||||||
@@ -32,6 +40,12 @@
|
|||||||
<PlatformToolset>v143</PlatformToolset>
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
<CharacterSet>Unicode</CharacterSet>
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DEBUG_FIRST|Win32'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>false</UseDebugLibraries>
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
@@ -45,6 +59,12 @@
|
|||||||
<PlatformToolset>v143</PlatformToolset>
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
<CharacterSet>Unicode</CharacterSet>
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DEBUG_FIRST|x64'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>false</UseDebugLibraries>
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
@@ -60,12 +80,18 @@
|
|||||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
</ImportGroup>
|
</ImportGroup>
|
||||||
|
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='DEBUG_FIRST|Win32'" Label="PropertySheets">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
</ImportGroup>
|
</ImportGroup>
|
||||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
</ImportGroup>
|
</ImportGroup>
|
||||||
|
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='DEBUG_FIRST|x64'" Label="PropertySheets">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
</ImportGroup>
|
</ImportGroup>
|
||||||
@@ -82,6 +108,18 @@
|
|||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='DEBUG_FIRST|Win32'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
<ClCompile>
|
<ClCompile>
|
||||||
<WarningLevel>Level3</WarningLevel>
|
<WarningLevel>Level3</WarningLevel>
|
||||||
@@ -100,8 +138,24 @@
|
|||||||
<ClCompile>
|
<ClCompile>
|
||||||
<WarningLevel>Level3</WarningLevel>
|
<WarningLevel>Level3</WarningLevel>
|
||||||
<SDLCheck>true</SDLCheck>
|
<SDLCheck>true</SDLCheck>
|
||||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<ConformanceMode>true</ConformanceMode>
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
<LanguageStandard>Default</LanguageStandard>
|
||||||
|
<LanguageStandard_C>Default</LanguageStandard_C>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Console</SubSystem>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='DEBUG_FIRST|x64'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>DEBUG;_CONSOLE;THIRD;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
<LanguageStandard>Default</LanguageStandard>
|
||||||
|
<LanguageStandard_C>Default</LanguageStandard_C>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
@@ -116,6 +170,8 @@
|
|||||||
<SDLCheck>true</SDLCheck>
|
<SDLCheck>true</SDLCheck>
|
||||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<ConformanceMode>true</ConformanceMode>
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
<LanguageStandard>Default</LanguageStandard>
|
||||||
|
<LanguageStandard_C>Default</LanguageStandard_C>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
|
|||||||
178
Solver.cpp
178
Solver.cpp
@@ -2,165 +2,151 @@
|
|||||||
#include <Eigen/Dense>
|
#include <Eigen/Dense>
|
||||||
using namespace Eigen;
|
using namespace Eigen;
|
||||||
|
|
||||||
Solver::Solver(double _A, double _B, double _C, int _N, int _l, int _u) {
|
Solver::Solver(double _A, double _B, double _C, double _D, int _N, int _l, int _u) {
|
||||||
A = _A, B = _B, C = _C, N = _N;
|
A = _A, B = _B, C = _C, D = _D, N = _N;
|
||||||
upper = _u, lower = _l;
|
upper = _u, lower = _l;
|
||||||
L = upper - lower;
|
L = upper - lower;
|
||||||
dx = L / N;
|
dx = L / N;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Solver::Execute_Linear(double val1, double val2) {
|
void Solver::Execute_Linear(double val1, double val2) {
|
||||||
|
|
||||||
MatrixXd local = MatrixXd::Zero(2, 2);
|
MatrixXd local = MatrixXd::Zero(2, 2);
|
||||||
local(0, 0) = A / dx - B / 2.;
|
|
||||||
local(0, 1) = -A / dx + B / 2.;
|
|
||||||
local(1, 0) = -A / dx - B / 2.;
|
|
||||||
local(1, 1) = A / dx + B / 2.;
|
|
||||||
std::cout << "Local matrix:\n" << local << std::endl;
|
|
||||||
|
|
||||||
VectorXd local_load(2);
|
VectorXd local_load(2);
|
||||||
local_load(0) = C * dx / 2;
|
|
||||||
local_load(1) = C * dx / 2;
|
|
||||||
|
|
||||||
// Ансаблированные матрицы и вектор
|
local(0, 0) = -A / dx - B / 2. + C * dx / 3.;
|
||||||
|
local(0, 1) = A / dx + B / 2. + C * dx / 6.;
|
||||||
|
local(1, 0) = A / dx - B / 2. + C * dx / 6.;
|
||||||
|
local(1, 1) = -A / dx + B / 2. + C * dx / 3.;
|
||||||
|
|
||||||
|
local_load(0) = -D * dx / 2.;
|
||||||
|
local_load(1) = -D * dx / 2.;
|
||||||
|
|
||||||
MatrixXd ansamb = MatrixXd::Zero(N + 1, N + 1);
|
MatrixXd ansamb = MatrixXd::Zero(N + 1, N + 1);
|
||||||
VectorXd global_load = VectorXd::Zero(N + 1);
|
VectorXd global_load = VectorXd::Zero(N + 1);
|
||||||
|
|
||||||
// Ансамблирование для каждого конечного элемента
|
// Ансамблирование
|
||||||
for (int elem = 0; elem < N; ++elem) {
|
for (int elem = 0; elem < N; ++elem) {
|
||||||
int node_i = elem;
|
int node_i = elem;
|
||||||
int node_j = elem + 1;
|
int node_j = elem + 1;
|
||||||
|
|
||||||
// Матрица жесткости
|
|
||||||
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);
|
||||||
ansamb(node_j, node_i) += local(1, 0);
|
ansamb(node_j, node_i) += local(1, 0);
|
||||||
ansamb(node_j, node_j) += local(1, 1);
|
ansamb(node_j, node_j) += local(1, 1);
|
||||||
|
|
||||||
// Вектор нагрузки
|
|
||||||
global_load(node_i) += local_load(0);
|
global_load(node_i) += local_load(0);
|
||||||
global_load(node_j) += local_load(1);
|
global_load(node_j) += local_load(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
std::cout << "Before:" << std::endl;
|
std::cout << "Before:" << std::endl;
|
||||||
std::cout << "Ansamb matrix:\n" << ansamb << std::endl;
|
std::cout << "Ansamb matrix:\n" << ansamb << std::endl;
|
||||||
std::cout << "Ansamb load vector:\n" << global_load << std::endl;
|
std::cout << "Ansamb load vector:\n" << global_load << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
// ГУ 1-го рода
|
double u_right = val2;
|
||||||
double u_left = val1; // u(1) = 5
|
|
||||||
double u_right = val2; // u(6) = 15
|
|
||||||
|
|
||||||
// Обнуляем первую строку и столбец матрицы, устанавливаем диагональ = 1
|
// Clear first and last rows
|
||||||
ansamb.row(0).setZero();
|
ansamb.row(0).setZero();
|
||||||
ansamb.col(0).setZero();
|
|
||||||
ansamb(0, 0) = 1.0;
|
|
||||||
global_load(0) = u_left;
|
|
||||||
|
|
||||||
// Обнуляем последнюю строку и столбец матрицы, устанавливаем диагональ = 1
|
|
||||||
ansamb.row(N).setZero();
|
ansamb.row(N).setZero();
|
||||||
ansamb.col(N).setZero();
|
|
||||||
ansamb(N, N) = 1.0;
|
// u'(0) = u(0)
|
||||||
|
ansamb(0, 0) = dx + 1;
|
||||||
|
ansamb(0, 1) = -1;
|
||||||
|
global_load(0) = 0;
|
||||||
|
|
||||||
|
// u(10) = u_right = 5
|
||||||
|
ansamb(N, N) = 1;
|
||||||
global_load(N) = u_right;
|
global_load(N) = u_right;
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
std::cout << "\nAfter:" << std::endl;
|
std::cout << "\nAfter:" << std::endl;
|
||||||
std::cout << "Modified matrix:\n" << ansamb << std::endl;
|
std::cout << "Modified matrix:\n" << ansamb << std::endl;
|
||||||
std::cout << "Modified load vector:\n" << global_load << std::endl;
|
std::cout << "Modified load vector:\n" << global_load << std::endl;
|
||||||
|
#endif
|
||||||
|
|
||||||
VectorXd solution = ansamb.fullPivLu().solve(global_load);
|
VectorXd solution = ansamb.fullPivLu().solve(global_load);
|
||||||
std::cout << "\nSolution:" << std::endl;
|
std::cout << "\nSolution:" << std::endl;
|
||||||
std::cout << solution << std::endl;
|
std::cout << solution << std::endl;
|
||||||
|
|
||||||
std::ofstream file("matrix_2.txt");
|
std::ofstream file("matrix_linear.txt");
|
||||||
for (int i = 0; i < N + 1; i++) {
|
for (int i = 0; i < N; i++) {
|
||||||
file << solution(i) << ' ';
|
file << solution(i) << ' ';
|
||||||
}
|
}
|
||||||
file << std::endl;
|
file << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Solver::Execute_Cubic(double val1, double val2) {
|
void Solver::Execute_Cubic(double val1, double val2) {
|
||||||
// Локальная матрица жесткости (4x4)
|
|
||||||
MatrixXd local = MatrixXd::Zero(4, 4);
|
|
||||||
local(0, 0) = -37. * A / (10 * dx) - B / 2.;
|
|
||||||
local(0, 1) = 189. * A / (40 * dx) + 57. * B / 80.;
|
|
||||||
local(0, 2) = -27. * A / (20 * dx) - 3. * B / 10.;
|
|
||||||
local(0, 3) = 13. * A / (40. * dx) + 7. * B / 10.;
|
|
||||||
|
|
||||||
local(1, 0) = 189. * A / (40 * dx) - 57. * B / 80.;
|
int mat_dim = 1 + N * 3;
|
||||||
local(1, 1) = -54. * A / (5 * dx);
|
Eigen::MatrixXd Amat(mat_dim, mat_dim);
|
||||||
local(1, 2) = 297. * A / (40. * dx) + 81. * B / 80.;
|
Eigen::VectorXd b(mat_dim);
|
||||||
local(1, 3) = -27 * A / (20. * dx) - 3. * B / 10.;
|
Amat.setZero();
|
||||||
|
b.setZero();
|
||||||
|
|
||||||
local(2, 0) = -27. * A / (20. * dx) + 3. * B / 10.;
|
// Assemble matrix
|
||||||
local(2, 1) = 297. * A / (40. * dx) - 81. * B / 80.;
|
for (int i = 0; i < mat_dim - 3; i += 3) {
|
||||||
local(2, 2) = -54. * A / (5. * dx);
|
Amat(i, i + 0) -= A * 37.0 / 10.0 / dx;
|
||||||
local(2, 3) = 189. * A / (40. * dx) + 57. * B / 80.;
|
Amat(i, i + 1) -= A * (-189.0) / 40.0 / dx;
|
||||||
|
Amat(i, i + 2) -= A * 27.0 / 20.0 / dx;
|
||||||
|
Amat(i, i + 3) -= A * (-13.0) / 40.0 / dx;
|
||||||
|
Amat(i + 1, i + 0) -= A * (-189.0) / 40.0 / dx;
|
||||||
|
Amat(i + 1, i + 1) -= A * 54.0 / 5.0 / dx;
|
||||||
|
Amat(i + 1, i + 2) -= A * (-297.0) / 40.0 / dx;
|
||||||
|
Amat(i + 1, i + 3) -= A * 27.0 / 20.0 / dx;
|
||||||
|
Amat(i + 2, i + 0) -= A * 27.0 / 20.0 / dx;
|
||||||
|
Amat(i + 2, i + 1) -= A * (-297.0) / 40.0 / dx;
|
||||||
|
Amat(i + 2, i + 2) -= A * 54.0 / 5.0 / dx;
|
||||||
|
Amat(i + 2, i + 3) -= A * (-189.0) / 40.0 / dx;
|
||||||
|
Amat(i + 3, i + 0) -= A * (-13.0) / 40.0 / dx;
|
||||||
|
Amat(i + 3, i + 1) -= A * 27.0 / 20.0 / dx;
|
||||||
|
Amat(i + 3, i + 2) -= A * (-189.0) / 40.0 / dx;
|
||||||
|
Amat(i + 3, i + 3) -= A * 37.0 / 10.0 / dx;
|
||||||
|
|
||||||
local(3, 0) = 13. * A / (40. * dx) - 7. * B / 80.;
|
Amat(i + 0, i + 0) += B * (-1.0) / 2.0;
|
||||||
local(3, 1) = -27. * A / (20. * dx) + 3. * B / 10.;
|
Amat(i + 0, i + 1) += B * 57.0 / 80.0;
|
||||||
local(3, 2) = 189. * A / (40. * dx) - 57. * B / 80.;
|
Amat(i + 0, i + 2) += B * (-3.0) / 10.0;
|
||||||
local(3, 3) = -37. * A / (10. * dx) + B / 2.;
|
Amat(i + 0, i + 3) += B * 7.0 / 80.0;
|
||||||
|
Amat(i + 1, i + 0) += B * (-57.0) / 80.0;
|
||||||
|
|
||||||
// Локальный вектор нагрузки (4x1)
|
Amat(i + 1, i + 2) += B * 81.0 / 80.0;
|
||||||
VectorXd local_load(4);
|
Amat(i + 1, i + 3) += B * (-3.0) / 10;
|
||||||
local_load(0) = -C * dx / 8.;
|
Amat(i + 2, i + 0) += B * 3.0 / 10.0;
|
||||||
local_load(1) = -3. * C * dx / 8.;
|
Amat(i + 2, i + 1) += B * (-81.0) / 80.0;
|
||||||
local_load(2) = -3. * C * dx / 8.;
|
|
||||||
local_load(3) = -C * dx / 8.;
|
|
||||||
|
|
||||||
std::cout << "Local matrix:\n" << local << std::endl;
|
Amat(i + 2, i + 3) += B * 57.0 / 80.0;
|
||||||
std::cout << "Local load vector:\n" << local_load << std::endl;
|
Amat(i + 3, i + 0) += B * (-7.0) / 80.0;
|
||||||
|
Amat(i + 3, i + 1) += B * 3.0 / 10.0;
|
||||||
// Размер глобальной системы: для кубических элементов (4 узла на элемент, перекрытие по 2 узла)
|
Amat(i + 3, i + 2) += B * (-57.0) / 80.0;
|
||||||
int ndof = 2 * N + 2;
|
Amat(i + 3, i + 3) += B * 1.0 / 2.0;
|
||||||
MatrixXd ansamb = MatrixXd::Zero(ndof, ndof);
|
|
||||||
VectorXd global_load = VectorXd::Zero(ndof);
|
|
||||||
|
|
||||||
// АНСАМБЛИРОВАНИЕ
|
|
||||||
for (int elem = 0; elem < N; ++elem) {
|
|
||||||
int node_start = 2 * elem; // Начальный индекс для текущего элемента
|
|
||||||
|
|
||||||
// Добавляем локальную матрицу
|
|
||||||
for (int i = 0; i < 4; ++i) {
|
|
||||||
for (int j = 0; j < 4; ++j) {
|
|
||||||
ansamb(node_start + i, node_start + j) += local(i, j);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Добавляем локальный вектор нагрузки
|
|
||||||
for (int i = 0; i < 4; ++i) {
|
|
||||||
global_load(node_start + i) += local_load(i);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "Before boundary conditions:" << std::endl;
|
// Assembdxe vector
|
||||||
std::cout << "Ansamb matrix:\n" << ansamb << std::endl;
|
for (int i = 0; i < mat_dim - 3; i += 3) {
|
||||||
std::cout << "Ansamb load vector:\n" << global_load << std::endl;
|
b(i) -= D * dx / 8.0;
|
||||||
|
b(i + 1) -= D * 3.0 * dx / 8.0;
|
||||||
|
b(i + 2) -= D * 3.0 * dx / 8.0;
|
||||||
|
b(i + 3) -= D * dx / 8.0;
|
||||||
|
}
|
||||||
|
|
||||||
// ГРАНИЧНЫЕ УСЛОВИЯ
|
|
||||||
double u_left = val1; // u(1) = 5
|
|
||||||
double u_right = val2; // u(6) = 15
|
|
||||||
|
|
||||||
ansamb.row(0).setZero();
|
Amat.row(0).setZero();
|
||||||
ansamb.col(0).setZero();
|
Amat(0, 0) = dx / 3.0 + 1;
|
||||||
ansamb(0, 0) = 1.0;
|
Amat(0, 1) = -1;
|
||||||
global_load(0) = u_left;
|
b(0) = 0;
|
||||||
|
|
||||||
ansamb.row(ndof - 1).setZero();
|
Amat.row(mat_dim - 1).setZero();
|
||||||
ansamb.col(ndof - 1).setZero();
|
Amat(mat_dim - 1, mat_dim - 1) = 1;
|
||||||
ansamb(ndof - 1, ndof - 1) = 1.0;
|
b(mat_dim - 1) = val2;
|
||||||
global_load(ndof - 1) = u_right;
|
|
||||||
|
|
||||||
std::cout << "\nAfter boundary conditions:" << std::endl;
|
|
||||||
std::cout << "Modified matrix:\n" << ansamb << std::endl;
|
|
||||||
std::cout << "Modified load vector:\n" << global_load << std::endl;
|
|
||||||
|
|
||||||
// Решение системы
|
// Решение системы
|
||||||
VectorXd solution = ansamb.fullPivLu().solve(global_load);
|
VectorXd solution = Amat.colPivHouseholderQr().solve(b);
|
||||||
std::cout << "\nSolution:" << std::endl;
|
std::cout << "\nSolution:" << std::endl;
|
||||||
std::cout << solution << std::endl;
|
std::cout << solution << std::endl;
|
||||||
|
|
||||||
// Сохранение результатов (берем только значения функции в узлах, шаг 2)
|
|
||||||
std::ofstream file("matrix_cubic.txt");
|
std::ofstream file("matrix_cubic.txt");
|
||||||
for (int i = 0; i < ndof; i += 2) {
|
for (int i = 0; i < solution.size(); i++) {
|
||||||
file << solution(i) << ' ';
|
file << solution(i) << ' ';
|
||||||
}
|
}
|
||||||
file << std::endl;
|
file << std::endl;
|
||||||
|
|||||||
5
Solver.h
5
Solver.h
@@ -1,10 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
class Solver {
|
class Solver {
|
||||||
private:
|
private:
|
||||||
double A, B, C, L, dx;
|
double A, B, C, D, L, dx;
|
||||||
int N, upper, lower;
|
int N, upper, lower;
|
||||||
public:
|
public:
|
||||||
Solver(double _A, double _B, double _C, 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);
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user