From 2f34e82bab9c5cdb9bee350a273340dc5b959d49 Mon Sep 17 00:00:00 2001 From: ParkSuMin Date: Wed, 14 May 2025 19:03:22 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B0=D1=81=D1=81=D1=82=D0=BE=D1=8F?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BC=D0=B5=D0=B6=D0=B4=D1=83=20=D1=83?= =?UTF-8?q?=D0=B7=D0=BB=D0=B0=D0=BC=D0=B8=20=D0=BA=D0=B0=D0=BA=20=D0=BF?= =?UTF-8?q?=D0=B5=D1=80=D0=B5=D0=B3=D1=80=D1=83=D0=B7=D0=BA=D0=B0=20=D0=BE?= =?UTF-8?q?=D0=BF=D0=B5=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=B0=20=D0=BC=D0=B8?= =?UTF-8?q?=D0=BD=D1=83=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/Node.hpp | 6 +++++- src/Node.cpp | 22 +++++++++++++--------- src/Solver.cpp | 28 +++++++++++++++------------- 3 files changed, 33 insertions(+), 23 deletions(-) diff --git a/include/Node.hpp b/include/Node.hpp index 815f8df..4e3c3a1 100644 --- a/include/Node.hpp +++ b/include/Node.hpp @@ -15,10 +15,12 @@ class Node{ Node* _below; public: Node(double x = 0., double y = 0., int type = 0., double t = 0.): _x(x), _y(y), _t(t), _left(nullptr), _right(nullptr), _above(nullptr), _below(nullptr), _btype(type) {} + double T() const; double X() const; double Y() const; - double Dist(const Node*) const; + + //double Dist(const Node*) const; void LinkX(Node*, Node*); void LinkY(Node*, Node*); Node*& l(); @@ -28,6 +30,8 @@ public: void SetT(double); bool IsBound(); void SetB(int); + + double operator-(const Node*) const; }; #endif diff --git a/src/Node.cpp b/src/Node.cpp index f248f61..b6e7497 100644 --- a/src/Node.cpp +++ b/src/Node.cpp @@ -34,35 +34,39 @@ double Node::T() const { if (_btype == 3) { if (!_left) if (_right) - return _right->T() / (1 + Dist(_right)); + return _right->T() / (1 + this - _right); if (!_right) if (_left) - return _left->T() / (1 + Dist(_left)); + return _left->T() / (1 + this - _left); if (!_above) if (_below) - return _below->T() / (1 + Dist(_below)); + return _below->T() / (1 + this - _below); if (!_below) if (_above) - return _above->T() / (1 + Dist(_above)); + return _above->T() / (1 + this - _above); if (_right && _left) { if (_right->IsBound()) - return _left->T() / (1 + Dist(_left)); - return _right->T() / (1 + Dist(_right)); + return _left->T() / (1 + this - _left); + return _right->T() / (1 + this - _right); } if (_above && _below) { if (_above->IsBound()) - return _below->T() / (1 + Dist(_below)); - return _above->T() / (1 + Dist(_above)); + return _below->T() / (1 + this - _below); + return _above->T() / (1 + this - _above); } } return _t; } -double Node::Dist(const Node* to) const { +double Node::operator-(const Node* to) const { return std::sqrt(pow(X() - to->X(), 2) + pow(Y() - to->Y(), 2)); } +//double Node::Dist(const Node* to) const { +// return std::sqrt(pow(X() - to->X(), 2) + pow(Y() - to->Y(), 2)); +//} + Node*& Node::l() { return _left; } Node*& Node::r() { return _right; } Node*& Node::u() { return _above; } diff --git a/src/Solver.cpp b/src/Solver.cpp index 4664443..e6f42ee 100644 --- a/src/Solver.cpp +++ b/src/Solver.cpp @@ -80,32 +80,34 @@ void Solver::SolveImplicit(System& sys, double tstop) const { void Solver::SolveLine(System& sys, std::vector& n) const { int size = n.size() - 2; - double mu1 = n.front()->Dist(n[1]) / sys.step(); - double mu2 = n.back()->Dist(n[n.size() - 2]) / sys.step(); + double mu1 = (n.front() - n[1]) / sys.step(); + double mu2 = (n.back() - n[n.size() - 2]) / sys.step(); /* Защита от нуля */ if (mu2 == 0.) mu2 = .1; double val2 = -(2 * sys.a1()) / (pow(sys.step(), 2)) - 1 / delta; double val1 = sys.a1() / (pow(sys.step(), 2)); - std::vector> next(size); + std::vector> _Temperature(size); std::vector right(size); - for (int i = 0; i < next.size(); i++) - next[i].resize(3, 0.0); - next[0][0] = -(2 * sys.a1()) / (mu1 * pow(sys.step(), 2)) - 1 / delta;//val2; - next[0][1] = (2 * sys.a1()) / ((mu1 + 1) * pow(sys.step(), 2));// val1; - next.back()[1] = (2 * sys.a1()) / ((mu2 + 1) * pow(sys.step(), 2));// val1; - next.back()[2] = -(2 * sys.a1()) / (mu2 * pow(sys.step(), 2)) - 1 / delta;//val2; + for (int i = 0; i < _Temperature.size(); i++) + _Temperature[i].resize(3, 0.0); + + _Temperature[0][0] = -(2 * sys.a1()) / (mu1 * pow(sys.step(), 2)) - 1 / delta; /* Первый узел по X */ + _Temperature[0][1] = (2 * sys.a1()) / ((mu1 + 1) * pow(sys.step(), 2)); /* Первый узел по Y */ + _Temperature.back()[1] = (2 * sys.a1()) / ((mu2 + 1) * pow(sys.step(), 2)); + _Temperature.back()[2] = -(2 * sys.a1()) / (mu2 * pow(sys.step(), 2)) - 1 / delta; + for (int i = 1; i < size - 1; i++) { - next[i][0] = val1; - next[i][1] = val2; - next[i][2] = val1; + _Temperature[i][0] = val1; + _Temperature[i][1] = val2; + _Temperature[i][2] = val1; } for (int i = 0; i < right.size(); i++) right[i] = -n[i + 1]->T() / delta; right.front() += -(2 * sys.a1() * n.front()->T()) / (mu1 * (mu1 + 1) * pow(sys.step(), 2)); right.back() += -(2 * sys.a1() * n.back()->T()) / (mu2 * (mu2 + 1) * pow(sys.step(), 2)); - std::vector tmps = ThomasMethod(next, right); + std::vector tmps = ThomasMethod(_Temperature, right); for (int i = 0; i < tmps.size(); i++) n[i + 1]->SetT(tmps[i]); }