Расстояние между узлами как перегрузка оператора минус

This commit is contained in:
2025-05-14 19:03:22 +03:00
parent d55f8fa5d3
commit 2f34e82bab
3 changed files with 33 additions and 23 deletions

View File

@@ -15,10 +15,12 @@ class Node{
Node* _below; Node* _below;
public: 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) {} 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 T() const;
double X() const; double X() const;
double Y() const; double Y() const;
double Dist(const Node*) const;
//double Dist(const Node*) const;
void LinkX(Node*, Node*); void LinkX(Node*, Node*);
void LinkY(Node*, Node*); void LinkY(Node*, Node*);
Node*& l(); Node*& l();
@@ -28,6 +30,8 @@ public:
void SetT(double); void SetT(double);
bool IsBound(); bool IsBound();
void SetB(int); void SetB(int);
double operator-(const Node*) const;
}; };
#endif #endif

View File

@@ -34,35 +34,39 @@ double Node::T() const {
if (_btype == 3) { if (_btype == 3) {
if (!_left) if (!_left)
if (_right) if (_right)
return _right->T() / (1 + Dist(_right)); return _right->T() / (1 + this - _right);
if (!_right) if (!_right)
if (_left) if (_left)
return _left->T() / (1 + Dist(_left)); return _left->T() / (1 + this - _left);
if (!_above) if (!_above)
if (_below) if (_below)
return _below->T() / (1 + Dist(_below)); return _below->T() / (1 + this - _below);
if (!_below) if (!_below)
if (_above) if (_above)
return _above->T() / (1 + Dist(_above)); return _above->T() / (1 + this - _above);
if (_right && _left) { if (_right && _left) {
if (_right->IsBound()) if (_right->IsBound())
return _left->T() / (1 + Dist(_left)); return _left->T() / (1 + this - _left);
return _right->T() / (1 + Dist(_right)); return _right->T() / (1 + this - _right);
} }
if (_above && _below) { if (_above && _below) {
if (_above->IsBound()) if (_above->IsBound())
return _below->T() / (1 + Dist(_below)); return _below->T() / (1 + this - _below);
return _above->T() / (1 + Dist(_above)); return _above->T() / (1 + this - _above);
} }
} }
return _t; 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)); 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::l() { return _left; }
Node*& Node::r() { return _right; } Node*& Node::r() { return _right; }
Node*& Node::u() { return _above; } Node*& Node::u() { return _above; }

View File

@@ -80,32 +80,34 @@ void Solver::SolveImplicit(System& sys, double tstop) const {
void Solver::SolveLine(System& sys, std::vector<Node*>& n) const { void Solver::SolveLine(System& sys, std::vector<Node*>& n) const {
int size = n.size() - 2; int size = n.size() - 2;
double mu1 = n.front()->Dist(n[1]) / sys.step(); double mu1 = (n.front() - n[1]) / sys.step();
double mu2 = n.back()->Dist(n[n.size() - 2]) / sys.step(); double mu2 = (n.back() - n[n.size() - 2]) / sys.step();
/* Защита от нуля */ /* Защита от нуля */
if (mu2 == 0.) if (mu2 == 0.)
mu2 = .1; mu2 = .1;
double val2 = -(2 * sys.a1()) / (pow(sys.step(), 2)) - 1 / delta; double val2 = -(2 * sys.a1()) / (pow(sys.step(), 2)) - 1 / delta;
double val1 = sys.a1() / (pow(sys.step(), 2)); double val1 = sys.a1() / (pow(sys.step(), 2));
std::vector<std::vector<double>> next(size); std::vector<std::vector<double>> _Temperature(size);
std::vector<double> right(size); std::vector<double> right(size);
for (int i = 0; i < next.size(); i++) for (int i = 0; i < _Temperature.size(); i++)
next[i].resize(3, 0.0); _Temperature[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; _Temperature[0][0] = -(2 * sys.a1()) / (mu1 * pow(sys.step(), 2)) - 1 / delta; /* Первый узел по X */
next.back()[1] = (2 * sys.a1()) / ((mu2 + 1) * pow(sys.step(), 2));// val1; _Temperature[0][1] = (2 * sys.a1()) / ((mu1 + 1) * pow(sys.step(), 2)); /* Первый узел по Y */
next.back()[2] = -(2 * sys.a1()) / (mu2 * pow(sys.step(), 2)) - 1 / delta;//val2; _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++) { for (int i = 1; i < size - 1; i++) {
next[i][0] = val1; _Temperature[i][0] = val1;
next[i][1] = val2; _Temperature[i][1] = val2;
next[i][2] = val1; _Temperature[i][2] = val1;
} }
for (int i = 0; i < right.size(); i++) for (int i = 0; i < right.size(); i++)
right[i] = -n[i + 1]->T() / delta; right[i] = -n[i + 1]->T() / delta;
right.front() += -(2 * sys.a1() * n.front()->T()) / (mu1 * (mu1 + 1) * pow(sys.step(), 2)); 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)); right.back() += -(2 * sys.a1() * n.back()->T()) / (mu2 * (mu2 + 1) * pow(sys.step(), 2));
std::vector<double> tmps = ThomasMethod(next, right); std::vector<double> tmps = ThomasMethod(_Temperature, right);
for (int i = 0; i < tmps.size(); i++) for (int i = 0; i < tmps.size(); i++)
n[i + 1]->SetT(tmps[i]); n[i + 1]->SetT(tmps[i]);
} }