Modify code and notebook
This commit is contained in:
@@ -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",
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
using namespace Eigen;
|
using namespace Eigen;
|
||||||
int main() {
|
int main() {
|
||||||
std::cout << A << "u''" << " + " << B << "u'" << "+ " << C << "u + " << D << " = 0" << std::endl;
|
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:";
|
std::cout << "Linear element:";
|
||||||
slv.Execute_Linear(0, 5);
|
slv.Execute_Linear(0, 5);
|
||||||
std::cout << "\nCubic element:";
|
std::cout << "\nCubic element:";
|
||||||
|
|||||||
@@ -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;
|
||||||
@@ -50,16 +53,22 @@ 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;
|
||||||
|
|
||||||
|
// 3rd type of boundary condition
|
||||||
ansamb.row(0).setZero();
|
ansamb.row(0).setZero();
|
||||||
ansamb(0, 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;
|
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.row(N + 1).setZero();
|
||||||
|
ansamb.col(N + 1).setZero();
|
||||||
ansamb(N + 1, N + 1) = 1;
|
ansamb(N + 1, N + 1) = 1;
|
||||||
global_load(N + 1) = u_right;
|
global_load(N + 1) = u_right;
|
||||||
|
|
||||||
@@ -142,13 +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) = 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;
|
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;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user