From 6482df07276d003f3b97c6aaa8f16705cf9b4dda Mon Sep 17 00:00:00 2001 From: ParkSuMin Date: Thu, 15 May 2025 02:00:37 +0300 Subject: [PATCH 1/5] Renaming --- include/Form.hpp | 6 +-- include/Mesh.hpp | 16 +++--- include/Node.hpp | 18 +++---- include/Object.hpp | 6 +-- include/Primitives.hpp | 24 ++++----- include/System.hpp | 4 +- src/Form.cpp | 8 +-- src/Mesh.cpp | 70 ++++++++++++------------- src/Node.cpp | 116 ++++++++++++++++++++--------------------- src/Object.cpp | 34 ++++++------ src/Primitives.cpp | 84 ++++++++++++++--------------- src/Solver.cpp | 11 ++-- src/System.cpp | 14 ++--- 13 files changed, 205 insertions(+), 206 deletions(-) diff --git a/include/Form.hpp b/include/Form.hpp index d40d154..4baf7fc 100644 --- a/include/Form.hpp +++ b/include/Form.hpp @@ -7,9 +7,9 @@ class Form { protected: - static size_t counter_; - size_t id_; - bool excluded_; + static size_t counter; + size_t id; + bool excluded; int bound_type; public: Form(); diff --git a/include/Mesh.hpp b/include/Mesh.hpp index 0a8bed2..b333d65 100644 --- a/include/Mesh.hpp +++ b/include/Mesh.hpp @@ -6,11 +6,11 @@ #include "Node.hpp" class Mesh{ - std::vector> _mesh; - std::vector _hlines; - std::vector _vlines; - Object& _obj; - double _step; + std::vector> mesh; + std::vector hlines; + std::vector vlines; + Object& obj; + double step; void LinkX(); void LinkY(); void Delnode(int, int); @@ -21,9 +21,9 @@ public: ~Mesh(); //void ShowLinks(); - std::vector>& Nodes() { return _mesh; } - std::vector& LineX() { return _hlines; } - std::vector& LineY() { return _vlines; } + std::vector>& Nodes() { return mesh; } + std::vector& LineX() { return hlines; } + std::vector& LineY() { return vlines; } }; #endif diff --git a/include/Node.hpp b/include/Node.hpp index a868339..232deea 100644 --- a/include/Node.hpp +++ b/include/Node.hpp @@ -4,17 +4,17 @@ #include class Node{ - double _x; - double _y; - double _t; - int _btype; + double x; + double y; + double t; + int btype; - Node* _left; - Node* _right; - Node* _above; - Node* _below; + Node* left; + Node* right; + Node* above; + Node* bellow; 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), bellow(nullptr), btype(_type) {} double T() const; double X() const; diff --git a/include/Object.hpp b/include/Object.hpp index 9381987..67d30fe 100644 --- a/include/Object.hpp +++ b/include/Object.hpp @@ -6,9 +6,9 @@ class Object { private: - std::vector forms_; - double _w; - double _h; + std::vector forms; + double w; + double h; void Updsize(); public: Object(); diff --git a/include/Primitives.hpp b/include/Primitives.hpp index 724abe6..09ea162 100644 --- a/include/Primitives.hpp +++ b/include/Primitives.hpp @@ -8,10 +8,10 @@ class Rectangle : public Form { private: - double a_; - double b_; - double h_x_; - double h_y_; + double x; + double y; + double h_x; + double h_y; public: Rectangle(double, double, double, double, bool, int); double Function(double, double) override; @@ -23,10 +23,10 @@ public: }; class Circle : public Form { private: - double a_; - double b_; - double h_x_; - double h_y_; + double x; + double y; + double h_x; + double h_y; public: Circle(double, double, double, double, bool, int); double Function(double, double) override; @@ -39,10 +39,10 @@ public: class Arc : public Form { private: - double a_; - double b_; - double h_x_; - double h_y_; + double x; + double y; + double h_x; + double h_y; public: Arc(double, double, double, double, bool, int); double Function(double, double) override; diff --git a/include/System.hpp b/include/System.hpp index 8d513bd..61d4ef9 100644 --- a/include/System.hpp +++ b/include/System.hpp @@ -5,11 +5,11 @@ class System{ Object& _obj; - Mesh _mesh; + Mesh mesh; double _a; double _step; public: -System(Object& obj, double step = 10., double a1 = 1.): _obj(obj), _mesh(obj, step), _a(a1), _step(step) {} +System(Object& obj, double step = 10., double a1 = 1.): _obj(obj), mesh(obj, step), _a(a1), _step(step) {} void DefineBounds(int, int, int, int); std::vector>& Nodes(); std::vector& LineX(); diff --git a/src/Form.cpp b/src/Form.cpp index d7527f6..e8f8c8e 100644 --- a/src/Form.cpp +++ b/src/Form.cpp @@ -1,6 +1,6 @@ #include "Form.hpp" -size_t Form::counter_ = 0; +size_t Form::counter = 0; double Form::Function(double, double) { return 0; @@ -27,13 +27,13 @@ std::pair Form::missY(double) { } Form::Form() { - id_ = counter_++; - excluded_ = false; + id = counter++; + excluded = false; bound_type = -1; } bool Form::Excluded() const { - return excluded_; + return excluded; } int Form::GetB() { return bound_type; } diff --git a/src/Mesh.cpp b/src/Mesh.cpp index 884364f..79bbf4a 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -2,12 +2,12 @@ #include #include -Mesh::Mesh(Object& obj, double step) : _obj(obj), _step(step) { +Mesh::Mesh(Object& _obj, double _step) : obj(_obj), step(_step) { for (double y = 0.0; y <= _obj.Height(); y += _step) { - _mesh.push_back(std::vector()); + mesh.push_back(std::vector()); for (double x = 0.0; x <= _obj.Width(); x += _step) { - _mesh.back().push_back(new Node(x, y)); + mesh.back().push_back(new Node(x, y)); } } LinkX(); @@ -17,34 +17,34 @@ Mesh::Mesh(Object& obj, double step) : _obj(obj), _step(step) { void Mesh::LinkX() { - for (int i = 0; i < _mesh.size(); i++) { - _mesh[i][0]->LinkX(nullptr, _mesh[i][1]); - for (int j = 1; j < _mesh[i].size() - 1; j++) - _mesh[i][j]->LinkX(_mesh[i][j - 1], _mesh[i][j + 1]); - _mesh[i].back()->LinkX(_mesh[i][_mesh[i].size() - 2], nullptr); + for (int i = 0; i < mesh.size(); i++) { + mesh[i][0]->LinkX(nullptr, mesh[i][1]); + for (int j = 1; j < mesh[i].size() - 1; j++) + mesh[i][j]->LinkX(mesh[i][j - 1], mesh[i][j + 1]); + mesh[i].back()->LinkX(mesh[i][mesh[i].size() - 2], nullptr); } - for (int i = 0; i < _mesh.size(); i++) - _hlines.push_back(_mesh[i][0]); + for (int i = 0; i < mesh.size(); i++) + hlines.push_back(mesh[i][0]); } void Mesh::LinkY() { - for (int j = 0; j < _mesh[0].size(); j++) { - _mesh[0][j]->LinkY(nullptr, _mesh[1][j]); - for (int i = 1; i < _mesh.size() - 1; i++) - _mesh[i][j]->LinkY(_mesh[i - 1][j], _mesh[i + 1][j]); - _mesh[_mesh.size() - 1][j]->LinkY(_mesh[_mesh.size() - 2][j], nullptr); + for (int j = 0; j < mesh[0].size(); j++) { + mesh[0][j]->LinkY(nullptr, mesh[1][j]); + for (int i = 1; i < mesh.size() - 1; i++) + mesh[i][j]->LinkY(mesh[i - 1][j], mesh[i + 1][j]); + mesh[mesh.size() - 1][j]->LinkY(mesh[mesh.size() - 2][j], nullptr); } - for (int i = 0; i < _mesh[0].size(); i++) - _vlines.push_back(_mesh[0][i]); + for (int i = 0; i < mesh[0].size(); i++) + vlines.push_back(mesh[0][i]); } void Mesh::Adapt() { - for (int i = 0; i < _mesh.size(); i++) { - int s = _mesh[i].size(); + for (int i = 0; i < mesh.size(); i++) { + int s = mesh[i].size(); for (int j = 0; j < s; j++) { - if (!_obj.Inhere(_mesh[i][j]->X(), _mesh[i][j]->Y())) { + if (!obj.Inhere(mesh[i][j]->X(), mesh[i][j]->Y())) { Delnode(i, j); j--; s--; @@ -54,12 +54,12 @@ void Mesh::Adapt() { } void Mesh::Delnode(int i, int j) { - Node* node = _mesh[i][j]; - double bndX1 = _obj.Fillx(node->X(), node->Y()).first; - double bndX2 = _obj.Fillx(node->X(), node->Y()).second; - double bndY1 = _obj.Filly(node->X(), node->Y()).first; - double bndY2 = _obj.Filly(node->X(), node->Y()).second; - int btype = _obj.Who(node->X(), node->Y())->GetB(); + Node* node = mesh[i][j]; + double bndX1 = obj.Fillx(node->X(), node->Y()).first; + double bndX2 = obj.Fillx(node->X(), node->Y()).second; + double bndY1 = obj.Filly(node->X(), node->Y()).first; + double bndY2 = obj.Filly(node->X(), node->Y()).second; + int btype = obj.Who(node->X(), node->Y())->GetB(); if (node->l()) { if (node->l()->X() != bndX2 && node->l()->X() != bndX1) { if (bndX1 != bndX2) { @@ -71,8 +71,8 @@ void Mesh::Delnode(int i, int j) { left->LinkX(node->l(), right); right->LinkX(left, node->r()); node->l() = right; - _mesh[i].push_back(left); - _mesh[i].push_back(right); + mesh[i].push_back(left); + mesh[i].push_back(right); } else { Node* left = new Node(bndX2, node->Y(), btype); @@ -81,7 +81,7 @@ void Mesh::Delnode(int i, int j) { node->r()->l() = left; left->LinkX(node->l(), node->r()); node->l() = left; - _mesh[i].push_back(left); + mesh[i].push_back(left); } } else @@ -101,8 +101,8 @@ void Mesh::Delnode(int i, int j) { down->LinkY(node->d(), up); up->LinkY(down, node->u()); node->d() = up; - _mesh[i].push_back(down); - _mesh[i].push_back(up); + mesh[i].push_back(down); + mesh[i].push_back(up); } else { Node* down = new Node(node->X(), bndY2, btype); @@ -111,7 +111,7 @@ void Mesh::Delnode(int i, int j) { node->u()->d() = down; down->LinkY(node->d(), node->u()); node->d() = down; - _mesh[i].push_back(down); + mesh[i].push_back(down); } } else @@ -120,18 +120,18 @@ void Mesh::Delnode(int i, int j) { if (node->u()) { node->u()->d() = node->d(); } - _mesh[i].erase(_mesh[i].begin() + j); + mesh[i].erase(mesh[i].begin() + j); delete node; } Mesh::~Mesh() { - for (auto line : _mesh) + for (auto line : mesh) for (auto node : line) delete node; } //void Mesh::ShowLinks() { - // for (auto line : _mesh) { + // for (auto line : mesh) { // for (auto node : line) { // if (node->d()) // std::cout << "| "; diff --git a/src/Node.cpp b/src/Node.cpp index 29b0fbd..396f39a 100644 --- a/src/Node.cpp +++ b/src/Node.cpp @@ -1,86 +1,86 @@ #include "Node.hpp" #include -double Node::X() const { return _x; } -double Node::Y() const { return _y; } +double Node::X() const { return x; } +double Node::Y() const { return y; } double Node::T() const { - if (_btype == 1) + if (btype == 1) 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)); + else 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 (bellow) + return bellow->T() / (1 + Dist(bellow)); + if (!bellow) + 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 (above && bellow) { + if (above->IsBound()) + return bellow->T() / (1 + Dist(bellow)); + return above->T() / (1 + Dist(above)); } } - if (_btype == 3) { - if (!_left) - if (_right) - return _right->T(); - if (!_right) - if (_left) - return _left->T(); - if (!_above) - if (_below) - return _below->T(); - if (!_below) - if (_above) - return _above->T(); - if (_right && _left) { - if (_right->IsBound()) - return _left->T(); - return _right->T(); + else if (btype == 3) { + if (!left) + if (right) + return right->T(); + if (!right) + if (left) + return left->T(); + if (!above) + if (bellow) + return bellow->T(); + if (!bellow) + if (above) + return above->T(); + if (right && left) { + if (right->IsBound()) + return left->T(); + return right->T(); } - if (_above && _below) { - if (_above->IsBound()) - return _below->T(); - return _above->T(); + if (above && bellow) { + if (above->IsBound()) + return bellow->T(); + return above->T(); } } - return _t; + return t; } 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; } -Node*& Node::d() { return _below; } +Node*& Node::l() { return left; } +Node*& Node::r() { return right; } +Node*& Node::u() { return above; } +Node*& Node::d() { return bellow; } void Node::LinkX(Node* l, Node* r) { - _left = l; - _right = r; + left = l; + right = r; } void Node::LinkY(Node* d, Node* u) { - _below = d; - _above = u; + bellow = d; + above = u; } -void Node::SetT(double t) { - _t = t; +void Node::SetT(double _t) { + t = _t; } -bool Node::IsBound() { return _btype; } -void Node::SetB(int type) { _btype = type; } \ No newline at end of file +bool Node::IsBound() { return btype; } +void Node::SetB(int _type) { btype = _type; } \ No newline at end of file diff --git a/src/Object.cpp b/src/Object.cpp index b0cede3..a64f954 100644 --- a/src/Object.cpp +++ b/src/Object.cpp @@ -1,9 +1,9 @@ #include "Object.hpp" -Object::Object() : _w(0), _h(0) {} +Object::Object() : w(0), h(0) {} double Object::Inhere(double x, double y) { - for (auto form : forms_) { + for (auto form : forms) { if (form->Excluded()) { if (form->Inhere(x, y)) { return false; @@ -19,25 +19,25 @@ double Object::Inhere(double x, double y) { } void Object::Updsize() { - for (auto form : forms_) { - _w = std::max(_w, form->size().first); - _h = std::max(_h, form->size().second); + for (auto form : forms) { + w = std::max(w, form->size().first); + h = std::max(h, form->size().second); } } bool Object::Add_Form(const std::string& name, std::map& args, bool excluded, int btype) { if (name == "Rectangle") { - forms_.push_back(new Rectangle(args["a"], args["b"], args["h_x"], args["h_y"], excluded, btype)); + forms.push_back(new Rectangle(args["a"], args["b"], args["h_x"], args["h_y"], excluded, btype)); Updsize(); return true; } else if (name == "Circle") { - forms_.push_back(new Circle(args["a"], args["b"], args["h_x"], args["h_y"], excluded, btype)); + forms.push_back(new Circle(args["a"], args["b"], args["h_x"], args["h_y"], excluded, btype)); Updsize(); return true; } else if (name == "Arc") { - forms_.push_back(new Arc(args["a"], args["b"], args["h_x"], args["h_y"], excluded, btype)); + forms.push_back(new Arc(args["a"], args["b"], args["h_x"], args["h_y"], excluded, btype)); Updsize(); return true; } @@ -47,7 +47,7 @@ bool Object::Add_Form(const std::string& name, std::map& ar std::pair Object::Fillx(double x, double y) { - for (auto form : forms_) { + for (auto form : forms) { if (form->Inhere(x, y)) { return form->missX(y); } @@ -56,7 +56,7 @@ std::pair Object::Fillx(double x, double y) { } std::pair Object::Filly(double x, double y) { - for (auto form : forms_) { + for (auto form : forms) { if (form->Inhere(x, y)) { return form->missY(x); } @@ -65,33 +65,33 @@ std::pair Object::Filly(double x, double y) { } double Object::Width() const { - return _w; + return w; } double Object::Height() const { - return _h; + return h; } //std::vector Object::Get_IDs() { // std::vector ids; -// ids.reserve(forms_.size()); -// for (auto form : forms_) { +// ids.reserve(forms.size()); +// for (auto form : forms) { // ids.push_back(form->Get_ID()); // } // return ids; //} Form* Object::Who(double x, double y) { - for (auto form : forms_) { + for (auto form : forms) { if (form->Inhere(x, y)) { return form; } } - return forms_.back(); + return forms.back(); } Object::~Object() { - for (auto form : forms_) + for (auto form : forms) delete form; } diff --git a/src/Primitives.cpp b/src/Primitives.cpp index 4847928..468eed4 100644 --- a/src/Primitives.cpp +++ b/src/Primitives.cpp @@ -1,95 +1,95 @@ #include "Primitives.hpp" -Rectangle::Rectangle(double a, double b, double h_x, double h_y, bool excluded, int btype) : a_(a), b_(b), h_x_(h_x), h_y_(h_y) { - excluded_ = excluded; - bound_type = btype; +Rectangle::Rectangle(double _x, double _y, double _h_x, double _h_y, bool _excluded, int _btype) : x(_x), y(_y), h_x(_h_x), h_y(_h_y) { + excluded = _excluded; + bound_type = _btype; } -std::pair Rectangle::missX(double y) { - return { 0.5 / h_x_ + a_, -0.5 / h_x_ + a_ }; +std::pair Rectangle::missX(double _y) { + return { 0.5 / h_x + x, -0.5 / h_x + x }; } -std::pair Rectangle::missY(double x) { - return { 0.5 / h_y_ + b_, -0.5 / h_y_ + b_ }; +std::pair Rectangle::missY(double _x) { + return { 0.5 / h_y + y, -0.5 / h_y + y }; } std::pair Rectangle::size() { - return { 1 / h_x_, 1 / h_y_ }; + return { 1 / h_x, 1 / h_y }; } -double Rectangle::Function(double x, double y) { - return std::max(h_x_ * std::abs(x - a_), h_y_ * std::abs(y - b_)); +double Rectangle::Function(double _x, double _y) { + return std::max(h_x * std::abs(_x - x), h_y * std::abs(_y - y)); } -std::pair Rectangle::Second_Deriative(double x, double y) { - return { (h_x_ / 2) * ((x - a_) / std::abs(x - a_)), (h_y_ / 2) * ((y - b_) / std::abs(y - b_)) }; +std::pair Rectangle::Second_Deriative(double _x, double _y) { + return { (h_x / 2) * ((_x - x) / std::abs(_x - x)), (h_y / 2) * ((_y - y) / std::abs(_y - y)) }; } bool Rectangle::Inhere(double x, double y) { return Function(x, y) <= EPS_RECTANGLE; } -Circle::Circle(double a, double b, double h_x, double h_y, bool excluded, int btype) : a_(a), b_(b), h_x_(h_x), h_y_(h_y) { - excluded_ = excluded; - bound_type = btype; +Circle::Circle(double _x, double _y, double _h_x, double _h_y, bool _excluded, int _btype) : x(_x), y(_y), h_x(_h_x), h_y(_h_y) { + excluded = _excluded; + bound_type = _btype; } -std::pair Circle::missY(double x) { - return { std::sqrt(1 - pow((h_x_ * (x - a_)), 2)) / h_y_ + b_, -std::sqrt(1 - pow((h_x_ * (x - a_)), 2)) / h_y_ + b_ }; +std::pair Circle::missY(double _x) { + return { std::sqrt(1 - pow((h_x * (_x - x)), 2)) / h_y + y, -std::sqrt(1 - pow((h_x * (_x - x)), 2)) / h_y + y }; } -std::pair Circle::missX(double y) { - return { std::sqrt(1 - pow((h_y_ * (y - b_)), 2)) / h_x_ + a_, -std::sqrt(1 - pow((h_y_ * (y - b_)), 2)) / h_x_ + a_ }; +std::pair Circle::missX(double _y) { + return { std::sqrt(1 - pow((h_y * (_y - y)), 2)) / h_x + x, -std::sqrt(1 - pow((h_y * (_y - y)), 2)) / h_x + x }; } -double Circle::Function(double x, double y) { - return pow(h_x_ * (x - a_), 2) + pow(h_y_ * (y - b_), 2); +double Circle::Function(double _x, double _y) { + return pow(h_x * (_x - x), 2) + pow(h_y * (_y - y), 2); } -std::pair Circle::Second_Deriative(double x, double y) { - return { 2 * h_x_ * (x - a_), 2 * h_y_ * (y - b_) }; +std::pair Circle::Second_Deriative(double _x, double _y) { + return { 2 * h_x * (_x - x), 2 * h_y * (_y - y) }; } std::pair Circle::size() { - return { 1 / h_x_, 1 / h_y_ }; + return { 1 / h_x, 1 / h_y }; } bool Circle::Inhere(double x, double y) { return Function(x, y) <= EPS_CIRCLE; } -Arc::Arc(double a, double b, double h_x, double h_y, bool excluded, int btype) : a_(a), b_(b), h_x_(h_x), h_y_(h_y) { - excluded_ = excluded; - bound_type = btype; +Arc::Arc(double _x, double _y, double _h_x, double _h_y, bool _excluded, int _btype) : x(_x), y(_y), h_x(_h_x), h_y(_h_y) { + excluded = _excluded; + bound_type = _btype; } -std::pair Arc::missY(double x) { - return { std::sqrt(1 - pow((h_x_ * (x - a_)), 2)) / h_y_ + b_, std::sqrt(1 - pow((h_x_ * (x - a_)), 2)) / h_y_ + b_ }; +std::pair Arc::missY(double _x) { + return { std::sqrt(1 - pow((h_x * (_x - x)), 2)) / h_y + y, std::sqrt(1 - pow((h_x * (_x - x)), 2)) / h_y + y }; } -std::pair Arc::missX(double y) { - return { std::sqrt(1 - pow((h_y_ * (y - b_)), 2)) / h_x_ + a_, std::sqrt(1 - pow((h_y_ * (y - b_)), 2)) / h_x_ + a_ }; +std::pair Arc::missX(double _y) { + return { std::sqrt(1 - pow((h_y * (_y - y)), 2)) / h_x + x, std::sqrt(1 - pow((h_y * (_y - y)), 2)) / h_x + x }; } -double Arc::Function(double x, double y) { - if (x >= a_ && y >= b_) { - return pow(h_x_ * (x - a_), 2) + pow(h_y_ * (y - b_), 2); +double Arc::Function(double _x, double _y) { + if (_x >= x && _y >= y) { + return pow(h_x * (_x - x), 2) + pow(h_y * (_y - y), 2); } return -1.0; } -std::pair Arc::Second_Deriative(double x, double y) { - if (x >= a_ && y >= b_) { - return { 2 * h_x_ * (x - a_), 2 * h_y_ * (y - b_) }; +std::pair Arc::Second_Deriative(double _x, double _y) { + if (_x >= x && _y >= y) { + return { 2 * h_x * (_x - x), 2 * h_y * (_y - y) }; } - if (x < a_) { - //std::cout << "x < a\n"; + if (_x < x) { + //std::cout << "_x < a\n"; } - if (y < b_) { - //std::cout << "y < b\n"; + if (_y < y) { + //std::cout << "_y < b\n"; } return { -1.0, -1.0 }; } std::pair Arc::size() { - return { 1 / h_x_, 1 / h_y_ }; + return { 1 / h_x, 1 / h_y }; } bool Arc::Inhere(double x, double y) { diff --git a/src/Solver.cpp b/src/Solver.cpp index 9f7beb5..3cf973c 100644 --- a/src/Solver.cpp +++ b/src/Solver.cpp @@ -61,8 +61,7 @@ void Solver::SolveExplicit(System& sys, double tstop) const { if (!node->IsBound()) { /* Tx = T_right - 2T_current + T_left / delta_x ^ 2 */ /* Ty = T_upper - 2T_current + T_down / delta_y ^ 2*/ - /* T_new = delta_t * a * (delta_x + delta_y) + T_current - (для удобства коээфициент a = 1) */ + /* T_new = delta_t * a * (delta_x + delta_y) + T_current */ double tx = (node->r()->T() - 2 * node->T() + node->l()->T()) / pow(sys.step(), 2); double ty = (node->u()->T() - 2 * node->T() + node->d()->T()) / pow(sys.step(), 2); @@ -107,12 +106,12 @@ void Solver::SolveLine(System& sys, std::vector& n) const { right[i] = -n[i + 1]->T() / delta; right.front() += -(2 * sys.a() * n.front()->T()) / (mu1 * (mu1 + 1) * pow(sys.step(), 2)); right.back() += -(2 * sys.a() * n.back()->T()) / (mu2 * (mu2 + 1) * pow(sys.step(), 2)); - std::vector tmps = ThomasMethod(_Temperature, right); - for (int i = 0; i < tmps.size(); i++) - n[i + 1]->SetT(tmps[i]); + std::vector tmp = ThomasMethod(_Temperature, right); + for (int i = 0; i < tmp.size(); i++) + n[i + 1]->SetT(tmp[i]); } - +/* Метод прогонки для численного решения СЛАУ */ std::vector Solver::ThomasMethod(std::vector>& A, std::vector& b) const { int row = b.size() - 1; diff --git a/src/System.cpp b/src/System.cpp index 0d1cb02..3f05a02 100644 --- a/src/System.cpp +++ b/src/System.cpp @@ -1,30 +1,30 @@ #include "System.hpp" void System::DefineBounds(int l, int t, int r, int b) { - Node* cur = _mesh.LineX().front(); + Node* cur = mesh.LineX().front(); while (cur) { cur->SetB(b); cur = cur->r(); } - cur = _mesh.LineX().back(); + cur = mesh.LineX().back(); while (cur) { cur->SetB(t); cur = cur->r(); } - cur = _mesh.LineY().front(); + cur = mesh.LineY().front(); while (cur) { cur->SetB(l); cur = cur->u(); } - cur = _mesh.LineY().back(); + cur = mesh.LineY().back(); while (cur->u()) { cur->SetB(r); cur = cur->u(); } } -std::vector>& System::Nodes() { return _mesh.Nodes(); } -std::vector& System::LineX() { return _mesh.LineX(); } -std::vector& System::LineY() { return _mesh.LineY(); } +std::vector>& System::Nodes() { return mesh.Nodes(); } +std::vector& System::LineX() { return mesh.LineX(); } +std::vector& System::LineY() { return mesh.LineY(); } From 9325bbc747913c248b4718c77ef8075c316f64bc Mon Sep 17 00:00:00 2001 From: ParkSuMin Date: Thu, 15 May 2025 15:10:34 +0300 Subject: [PATCH 2/5] Here we go again MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Или я опять всё напутал в начальных условиях --- include/Object.hpp | 4 ++-- src/Mesh.cpp | 21 ++++++++++++--------- src/Object.cpp | 4 ++-- src/main.cpp | 29 +++++++++++++++-------------- 4 files changed, 31 insertions(+), 27 deletions(-) diff --git a/include/Object.hpp b/include/Object.hpp index 67d30fe..164bb0e 100644 --- a/include/Object.hpp +++ b/include/Object.hpp @@ -19,8 +19,8 @@ public: double Height() const; bool Add_Form(const std::string&, std::map&, bool, int); - std::pair Filly(double, double); - std::pair Fillx(double, double); + std::pair FillX(double, double); + std::pair FillY(double, double); Form* Who(double, double); }; diff --git a/src/Mesh.cpp b/src/Mesh.cpp index 79bbf4a..ef400a8 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -3,7 +3,6 @@ #include Mesh::Mesh(Object& _obj, double _step) : obj(_obj), step(_step) { - for (double y = 0.0; y <= _obj.Height(); y += _step) { mesh.push_back(std::vector()); for (double x = 0.0; x <= _obj.Width(); x += _step) { @@ -16,7 +15,6 @@ Mesh::Mesh(Object& _obj, double _step) : obj(_obj), step(_step) { } void Mesh::LinkX() { - for (int i = 0; i < mesh.size(); i++) { mesh[i][0]->LinkX(nullptr, mesh[i][1]); for (int j = 1; j < mesh[i].size() - 1; j++) @@ -27,7 +25,6 @@ void Mesh::LinkX() { hlines.push_back(mesh[i][0]); } - void Mesh::LinkY() { for (int j = 0; j < mesh[0].size(); j++) { mesh[0][j]->LinkY(nullptr, mesh[1][j]); @@ -39,7 +36,6 @@ void Mesh::LinkY() { vlines.push_back(mesh[0][i]); } - void Mesh::Adapt() { for (int i = 0; i < mesh.size(); i++) { int s = mesh[i].size(); @@ -55,25 +51,31 @@ void Mesh::Adapt() { void Mesh::Delnode(int i, int j) { Node* node = mesh[i][j]; - double bndX1 = obj.Fillx(node->X(), node->Y()).first; - double bndX2 = obj.Fillx(node->X(), node->Y()).second; - double bndY1 = obj.Filly(node->X(), node->Y()).first; - double bndY2 = obj.Filly(node->X(), node->Y()).second; + /* X Y */ + double bndX1 = obj.FillX(node->X(), node->Y()).first; + double bndX2 = obj.FillX(node->X(), node->Y()).second; + double bndY1 = obj.FillY(node->X(), node->Y()).first; + double bndY2 = obj.FillY(node->X(), node->Y()).second; + /* */ int btype = obj.Who(node->X(), node->Y())->GetB(); if (node->l()) { + // if (node->l()->X() != bndX2 && node->l()->X() != bndX1) { if (bndX1 != bndX2) { + /* bndX2 bndX1 btype */ Node* left = new Node(bndX2, node->Y(), btype); Node* right = new Node(bndX1, node->Y(), btype); node->l()->r() = left; if (node->r()) node->r()->l() = right; + /* X */ left->LinkX(node->l(), right); right->LinkX(left, node->r()); node->l() = right; mesh[i].push_back(left); mesh[i].push_back(right); } + /* X , */ else { Node* left = new Node(bndX2, node->Y(), btype); node->l()->r() = left; @@ -84,9 +86,10 @@ void Mesh::Delnode(int i, int j) { mesh[i].push_back(left); } } + /* , */ else node->l()->r() = node->r(); - } + } /* */ if (node->r()) { node->r()->l() = node->l(); } diff --git a/src/Object.cpp b/src/Object.cpp index a64f954..1d870b6 100644 --- a/src/Object.cpp +++ b/src/Object.cpp @@ -46,7 +46,7 @@ bool Object::Add_Form(const std::string& name, std::map& ar -std::pair Object::Fillx(double x, double y) { +std::pair Object::FillX(double x, double y) { for (auto form : forms) { if (form->Inhere(x, y)) { return form->missX(y); @@ -55,7 +55,7 @@ std::pair Object::Fillx(double x, double y) { return { 0, 0 }; } -std::pair Object::Filly(double x, double y) { +std::pair Object::FillY(double x, double y) { for (auto form : forms) { if (form->Inhere(x, y)) { return form->missY(x); diff --git a/src/main.cpp b/src/main.cpp index 4bf4d80..93f5c7f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -9,15 +9,15 @@ #define ARC_RADIUS 150. -//#define SQUARE_X 355. -//#define SQUARE_Y 155. -//#define SQUARE_SIDE 100. +#define SQUARE_X 355. +#define SQUARE_Y 155. +#define SQUARE_SIDE 100. -#define HOLE_X 155. -#define HOLE_Y 255. -#define HOLE_RADIUS 50. +//#define HOLE_X 155. +//#define HOLE_Y 255. +//#define HOLE_RADIUS 50. -#define CONDUCTIVITY 90. // Теплопроводность материала +#define CONDUCTIVITY 50. // Теплопроводность материала void visualize(std::ofstream& file, std::string filename, int time_end) { file << "set cbrange [" << 0 << ":" << 100 << "]" << std::endl; @@ -41,7 +41,7 @@ int main() int right = 1; int bottom = 3; int arc_bound = 3; - int hole_bound = 2; + int hole_bound = 1; double step_5 = 5; double step_10 = 10; @@ -54,12 +54,16 @@ int main() std::map arc{ {"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} + //std::map circle{ + // {"a", HOLE_X}, {"b", HOLE_Y}, {"h_x", 1 / HOLE_RADIUS}, {"h_y", 1 / HOLE_RADIUS} + //}; + + std::map square{ + {"a", SQUARE_X}, {"b", SQUARE_Y}, {"h_x", 1 / SQUARE_SIDE}, {"h_y", 1 / SQUARE_SIDE} }; Object obj; - obj.Add_Form("Circle", circle, true, hole_bound); + obj.Add_Form("Rectangle", square, true, hole_bound); obj.Add_Form("Arc", arc, true, arc_bound); obj.Add_Form("Rectangle", plate, false, 1); @@ -101,6 +105,3 @@ int main() return 0; } -//std::map square{ - // {"a", SQUARE_X}, {"b", SQUARE_Y}, {"h_x", 1 / SQUARE_SIDE}, {"h_y", 1 / SQUARE_SIDE} - //}; \ No newline at end of file From 2933868ef9b2064ddc316f98ae3127999f4d2ba1 Mon Sep 17 00:00:00 2001 From: ParkSuMin Date: Thu, 15 May 2025 18:00:18 +0300 Subject: [PATCH 3/5] =?UTF-8?q?Python-=D0=B2=D0=B8=D0=B7=D1=83=D0=B0=D0=BB?= =?UTF-8?q?=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8F=20=D1=81=D0=B5=D1=82=D0=BA?= =?UTF-8?q?=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/Mesh.hpp | 1 + include/System.hpp | 1 + src/Mesh.cpp | 16 ++++++++++++++++ src/System.cpp | 4 ++++ src/main.cpp | 4 ++++ visual_mesh.py | 26 ++++++++++++++++++++++++++ 6 files changed, 52 insertions(+) create mode 100644 visual_mesh.py diff --git a/include/Mesh.hpp b/include/Mesh.hpp index b333d65..318c856 100644 --- a/include/Mesh.hpp +++ b/include/Mesh.hpp @@ -20,6 +20,7 @@ public: Mesh(Object&, double); ~Mesh(); //void ShowLinks(); + void VisualizeMesh(std::string); std::vector>& Nodes() { return mesh; } std::vector& LineX() { return hlines; } diff --git a/include/System.hpp b/include/System.hpp index 61d4ef9..278c546 100644 --- a/include/System.hpp +++ b/include/System.hpp @@ -11,6 +11,7 @@ class System{ public: System(Object& obj, double step = 10., double a1 = 1.): _obj(obj), mesh(obj, step), _a(a1), _step(step) {} void DefineBounds(int, int, int, int); + void export_mesh(std::string); std::vector>& Nodes(); std::vector& LineX(); std::vector& LineY(); diff --git a/src/Mesh.cpp b/src/Mesh.cpp index ef400a8..d7cca27 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -1,5 +1,6 @@ #include "Mesh.hpp" #include +#include #include Mesh::Mesh(Object& _obj, double _step) : obj(_obj), step(_step) { @@ -14,6 +15,21 @@ Mesh::Mesh(Object& _obj, double _step) : obj(_obj), step(_step) { Adapt(); } +void Mesh::VisualizeMesh(std::string name) { + std::ofstream data_file(name); + + data_file << "# Coordinates\n"; + data_file << "# Format: x y\n"; + + for (const auto& row : mesh) { + for (const auto& node : row) { + data_file << node->X() << " " << node->Y() << "\n"; + } + } + + data_file.close(); +} + void Mesh::LinkX() { for (int i = 0; i < mesh.size(); i++) { mesh[i][0]->LinkX(nullptr, mesh[i][1]); diff --git a/src/System.cpp b/src/System.cpp index 3f05a02..a0fa9b6 100644 --- a/src/System.cpp +++ b/src/System.cpp @@ -1,5 +1,9 @@ #include "System.hpp" +void System::export_mesh(std::string name) { + mesh.VisualizeMesh(name); +} + void System::DefineBounds(int l, int t, int r, int b) { Node* cur = mesh.LineX().front(); while (cur) { diff --git a/src/main.cpp b/src/main.cpp index 93f5c7f..3aff39c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -73,6 +73,10 @@ int main() System implicit5(obj, step_5, CONDUCTIVITY); System implicit10(obj, step_10, CONDUCTIVITY); + /* Экспорт сеток */ + explicit5.export_mesh("mesh5.txt"); + explicit10.export_mesh("mesh10.txt"); + explicit5.DefineBounds(left, top, right, bottom); explicit10.DefineBounds(left, top, right, bottom); diff --git a/visual_mesh.py b/visual_mesh.py new file mode 100644 index 0000000..15de1a4 --- /dev/null +++ b/visual_mesh.py @@ -0,0 +1,26 @@ +import matplotlib.pyplot as plt + +x_coords = [] +y_coords = [] + +try: + filename = input("Input name: ") + with open(f'{filename}', 'r') as file: + lines = file.readlines() + + for line in lines[2:]: + if line.strip(): + x, y = map(float, line.strip().split()) + x_coords.append(x) + y_coords.append(y) + + plt.figure(figsize=(10, 6)) + plt.scatter(x_coords, y_coords, s=10, c='blue', alpha=0.5) + plt.xlabel('X') + plt.ylabel('Y') + plt.grid(True) + plt.axis('equal') + plt.savefig(f"{filename[:-4]}.png") + plt.show() +except FileNotFoundError: + print(f"{filename} not found. ABORT!") \ No newline at end of file From 1189fae6e3d7e121181ff852451ae6d60db53c94 Mon Sep 17 00:00:00 2001 From: ParkSuMin Date: Thu, 15 May 2025 18:06:57 +0300 Subject: [PATCH 4/5] Link python script to project --- .gitignore | 1 + MemMAPR_winda.vcxproj | 1 + MemMAPR_winda.vcxproj.filters | 1 + es10.plt | 10 ---------- es5.plt | 10 ---------- is10.plt | 10 ---------- is5.plt | 10 ---------- 7 files changed, 3 insertions(+), 40 deletions(-) delete mode 100644 es10.plt delete mode 100644 es5.plt delete mode 100644 is10.plt delete mode 100644 is5.plt diff --git a/.gitignore b/.gitignore index a77a57d..4979850 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ *.userosscache *.sln.docstates *.txt +*.png # User-specific files (MonoDevelop/Xamarin Studio) *.userprefs diff --git a/MemMAPR_winda.vcxproj b/MemMAPR_winda.vcxproj index c1c60de..2f96dc8 100644 --- a/MemMAPR_winda.vcxproj +++ b/MemMAPR_winda.vcxproj @@ -158,6 +158,7 @@ + diff --git a/MemMAPR_winda.vcxproj.filters b/MemMAPR_winda.vcxproj.filters index 941a215..3a463fc 100644 --- a/MemMAPR_winda.vcxproj.filters +++ b/MemMAPR_winda.vcxproj.filters @@ -68,5 +68,6 @@ + \ No newline at end of file diff --git a/es10.plt b/es10.plt deleted file mode 100644 index 7f06c25..0000000 --- a/es10.plt +++ /dev/null @@ -1,10 +0,0 @@ -set cbrange [0:100] -set size ratio 0.8 -unset key - -set palette defined (0 0 0 1, 0.25 0 1 1, 0.5 0 1 0, 0.75 1 1 0, 1 1 0 0) - -do for [i=0:99]{ -plot 'explicit10.txt' u 1:2:3 index i w points pt 5 palette -pause 1e-09} -pause mouse \ No newline at end of file diff --git a/es5.plt b/es5.plt deleted file mode 100644 index 53ef058..0000000 --- a/es5.plt +++ /dev/null @@ -1,10 +0,0 @@ -set cbrange [0:100] -set size ratio 0.8 -unset key - -set palette defined (0 0 0 1, 0.25 0 1 1, 0.5 0 1 0, 0.75 1 1 0, 1 1 0 0) - -do for [i=0:99]{ -plot 'explicit5.txt' u 1:2:3 index i w points pt 5 palette -pause 1e-09} -pause mouse \ No newline at end of file diff --git a/is10.plt b/is10.plt deleted file mode 100644 index 2709fd0..0000000 --- a/is10.plt +++ /dev/null @@ -1,10 +0,0 @@ -set cbrange [0:100] -set size ratio 0.8 -unset key - -set palette defined (0 0 0 1, 0.25 0 1 1, 0.5 0 1 0, 0.75 1 1 0, 1 1 0 0) - -do for [i=0:99]{ -plot 'implicit10.txt' u 1:2:3 index i w points pt 5 palette -pause 1e-09} -pause mouse \ No newline at end of file diff --git a/is5.plt b/is5.plt deleted file mode 100644 index 7c67833..0000000 --- a/is5.plt +++ /dev/null @@ -1,10 +0,0 @@ -set cbrange [0:100] -set size ratio 0.8 -unset key - -set palette defined (0 0 0 1, 0.25 0 1 1, 0.5 0 1 0, 0.75 1 1 0, 1 1 0 0) - -do for [i=0:99]{ -plot 'implicit5.txt' u 1:2:3 index i w points pt 5 palette -pause 1e-09} -pause mouse \ No newline at end of file From 5d555820cc6a0306a1d62275f361a9232dc7a78d Mon Sep 17 00:00:00 2001 From: ParkSuMin Date: Thu, 15 May 2025 18:07:15 +0300 Subject: [PATCH 5/5] Delete .plt tracking --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 4979850..7b64a44 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ *.sln.docstates *.txt *.png +*.plt # User-specific files (MonoDevelop/Xamarin Studio) *.userprefs