diff --git a/include/Node.hpp b/include/Node.hpp index 4e3c3a1..a868339 100644 --- a/include/Node.hpp +++ b/include/Node.hpp @@ -20,7 +20,7 @@ public: 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(); @@ -30,8 +30,6 @@ 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 b6e7497..29b0fbd 100644 --- a/src/Node.cpp +++ b/src/Node.cpp @@ -7,6 +7,31 @@ double Node::T() const { return 100.; if (_btype == 2) { + if (!_left) + if (_right) + return _right->T() / (1 + Dist(_right)); + if (!_right) + if (_left) + return _left->T() / (1 + Dist(_left)); + if (!_above) + if (_below) + return _below->T() / (1 + Dist(_below)); + if (!_below) + if (_above) + return _above->T() / (1 + Dist(_above)); + if (_right && _left) { + if (_right->IsBound()) + return _left->T() / (1 + Dist(_left)); + return _right->T() / (1 + Dist(_right)); + } + if (_above && _below) { + if (_above->IsBound()) + return _below->T() / (1 + Dist(_below)); + return _above->T() / (1 + Dist(_above)); + } + } + + if (_btype == 3) { if (!_left) if (_right) return _right->T(); @@ -31,42 +56,13 @@ double Node::T() const { } } - if (_btype == 3) { - if (!_left) - if (_right) - return _right->T() / (1 + this - _right); - if (!_right) - if (_left) - return _left->T() / (1 + this - _left); - if (!_above) - if (_below) - return _below->T() / (1 + this - _below); - if (!_below) - if (_above) - return _above->T() / (1 + this - _above); - if (_right && _left) { - if (_right->IsBound()) - return _left->T() / (1 + this - _left); - return _right->T() / (1 + this - _right); - } - if (_above && _below) { - if (_above->IsBound()) - return _below->T() / (1 + this - _below); - return _above->T() / (1 + this - _above); - } - } - return _t; } -double Node::operator-(const Node* to) const { +double Node::Dist(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; } @@ -87,5 +83,4 @@ void Node::SetT(double t) { } bool Node::IsBound() { return _btype; } -void Node::SetB(int type) { _btype = type; } - +void Node::SetB(int type) { _btype = type; } \ No newline at end of file diff --git a/src/Solver.cpp b/src/Solver.cpp index e6f42ee..2f3284a 100644 --- a/src/Solver.cpp +++ b/src/Solver.cpp @@ -80,8 +80,8 @@ 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() - n[1]) / sys.step(); - double mu2 = (n.back() - n[n.size() - 2]) / sys.step(); + double mu1 = n.front()->Dist(n[1]) / sys.step(); + double mu2 = n.back()->Dist(n[n.size() - 2]) / sys.step(); /* Защита от нуля */ if (mu2 == 0.) mu2 = .1; diff --git a/src/main.cpp b/src/main.cpp index a3af872..eab61bf 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,6 +2,8 @@ #include #include +#define STEP 1 + #define WIDTH 500. #define HEIGHT 400. @@ -11,8 +13,8 @@ //#define SQUARE_Y 155. //#define SQUARE_SIDE 100. -#define HOLE_X 355. -#define HOLE_Y 155. +#define HOLE_X 155. +#define HOLE_Y 255. #define HOLE_RADIUS 50. #define CONDUCTIVITY 50. // Теплопроводность материала @@ -29,7 +31,7 @@ void visualize(std::ofstream& file, std::string filename, int time_end) { int main() { /* Граничные условия: - 1 - нагрев + 1 - нагрев 2 - теплоизоляция 3 - конвекция 4 - отсутствует @@ -38,33 +40,32 @@ int main() int top = 1; int right = 3; int bottom = 1; - int r2 = 3; - int s = 3; + int arc_bound = 3; + int hole_bound = 1; double step_5 = 5; double step_10 = 10; - double time_step = 1; double time_end = 100; - std::map plate{ - {"a", WIDTH / 2}, {"b", HEIGHT / 2}, {"h_x", 1 / WIDTH}, {"h_y", 1 / HEIGHT} + std::map plate{ + {"a", WIDTH / 2}, {"b", HEIGHT / 2}, {"h_x", 1 / WIDTH}, {"h_y", 1 / HEIGHT} }; std::map arc{ - {"a", WIDTH - ARC_RADIUS}, {"b", HEIGHT - ARC_RADIUS}, {"h_x", 1 / ARC_RADIUS}, {"h_y", 1 / ARC_RADIUS} + {"a", WIDTH - ARC_RADIUS}, {"b", HEIGHT - ARC_RADIUS}, {"h_x", 1 / ARC_RADIUS}, {"h_y", 1 / ARC_RADIUS} }; std::map circle{ {"a", HOLE_X}, {"b", HOLE_Y}, {"h_x", 1 / HOLE_RADIUS}, {"h_y", 1 / HOLE_RADIUS} }; Object obj; - obj.Add_Form("Circle", circle, true, s); - obj.Add_Form("Arc", arc, true, r2); + obj.Add_Form("Circle", circle, true, hole_bound); + obj.Add_Form("Arc", arc, true, arc_bound); obj.Add_Form("Rectangle", plate, false, 1); System explicit5(obj, step_5, CONDUCTIVITY); System explicit10(obj, step_10, CONDUCTIVITY); - + System implicit5(obj, step_5, CONDUCTIVITY); System implicit10(obj, step_10, CONDUCTIVITY); @@ -74,14 +75,14 @@ int main() implicit5.DefineBounds(left, top, right, bottom); implicit10.DefineBounds(left, top, right, bottom); - Solver slv5("explicit5.txt", "implicit5.txt", time_step); - Solver slv10("explicit10.txt", "implicit10.txt", time_step); + Solver slv5("explicit5.txt", "implicit5.txt", STEP); + Solver slv10("explicit10.txt", "implicit10.txt", STEP); slv5.SolveExplicit(explicit5, time_end); slv5.SolveImplicit(implicit5, time_end); slv10.SolveExplicit(explicit10, time_end); slv10.SolveImplicit(implicit10, time_end); - + std::ofstream script("es10.plt"); visualize(script, "explicit10.txt", time_end); script.close();