From d55f8fa5d3da5fe594bc14bdd25e1d6168cd65d7 Mon Sep 17 00:00:00 2001 From: ParkSuMin Date: Wed, 14 May 2025 18:00:22 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9C=D0=B0=D1=81=D1=88=D1=82=D0=B0=D0=B1?= =?UTF-8?q?=D0=BD=D0=BE=D0=B5=20=D0=BF=D0=B5=D1=80=D0=B5=D0=BE=D0=B1=D0=BE?= =?UTF-8?q?=D0=B7=D0=BD=D0=B0=D1=87=D0=B5=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Улучшение читаемости и понимания кода --- include/Form.hpp | 6 +++--- include/Primitives.hpp | 9 ++++++--- include/Solver.hpp | 6 +++--- src/Form.cpp | 12 ++++++------ src/Primitives.cpp | 20 ++++++++++---------- src/Solver.cpp | 16 ++++++++-------- src/main.cpp | 38 +++++++++++++++++++++----------------- 7 files changed, 57 insertions(+), 50 deletions(-) diff --git a/include/Form.hpp b/include/Form.hpp index 94f54a6..d40d154 100644 --- a/include/Form.hpp +++ b/include/Form.hpp @@ -10,18 +10,18 @@ protected: static size_t counter_; size_t id_; bool excluded_; - int _boundtype; + int bound_type; public: Form(); virtual double Function(double, double); - virtual std::pair Deriative(double, double); + virtual std::pair Second_Deriative(double, double); virtual bool Inhere(double, double); virtual std::pair missX(double); virtual std::pair missY(double); virtual std::pair size(); virtual int GetB(); bool Excluded() const; - bool operator==(size_t) const; + //bool operator==(size_t) const; }; #endif diff --git a/include/Primitives.hpp b/include/Primitives.hpp index 5e5c663..724abe6 100644 --- a/include/Primitives.hpp +++ b/include/Primitives.hpp @@ -3,6 +3,9 @@ #include "Form.hpp" +#define EPS_RECTANGLE 0.5 +#define EPS_CIRCLE 1 + class Rectangle : public Form { private: double a_; @@ -12,7 +15,7 @@ private: public: Rectangle(double, double, double, double, bool, int); double Function(double, double) override; - std::pair Deriative(double, double) override; + std::pair Second_Deriative(double, double) override; bool Inhere(double, double) override; std::pair missX(double) override; std::pair missY(double) override; @@ -27,7 +30,7 @@ private: public: Circle(double, double, double, double, bool, int); double Function(double, double) override; - std::pair Deriative(double, double) override; + std::pair Second_Deriative(double, double) override; bool Inhere(double, double) override; std::pair missX(double) override; std::pair missY(double) override; @@ -43,7 +46,7 @@ private: public: Arc(double, double, double, double, bool, int); double Function(double, double) override; - std::pair Deriative(double, double) override; + std::pair Second_Deriative(double, double) override; std::pair missX(double) override; std::pair missY(double) override; std::pair size() override; diff --git a/include/Solver.hpp b/include/Solver.hpp index a35ff78..14b0d99 100644 --- a/include/Solver.hpp +++ b/include/Solver.hpp @@ -9,10 +9,10 @@ class Solver{ double delta; std::vector ThomasMethod(std::vector>&, std::vector&) const; void SolveLine(System&, std::vector&) const; - std::string _name_1; - std::string _name_2; + std::string filename_expl; + std::string filename_impl; public: - Solver(std::string name_1, std::string name_2, double dt = 1.): delta(dt), _name_1(name_1), _name_2(name_2) {} + Solver(std::string name_1, std::string name_2, double dt = 1.): delta(dt), filename_expl(name_1), filename_impl(name_2) {} void SolveExplicit(System&, double) const; void SolveImplicit(System&, double) const; }; diff --git a/src/Form.cpp b/src/Form.cpp index b3b6c9b..d7527f6 100644 --- a/src/Form.cpp +++ b/src/Form.cpp @@ -6,7 +6,7 @@ double Form::Function(double, double) { return 0; } -std::pair Form::Deriative(double, double) { +std::pair Form::Second_Deriative(double, double) { return { 0, 0 }; } @@ -29,15 +29,15 @@ std::pair Form::missY(double) { Form::Form() { id_ = counter_++; excluded_ = false; - _boundtype = -1; + bound_type = -1; } bool Form::Excluded() const { return excluded_; } -int Form::GetB() { return _boundtype; } +int Form::GetB() { return bound_type; } -bool Form::operator==(size_t id) const { - return id_ == id; -} \ No newline at end of file +//bool Form::operator==(size_t id) const { +// return id_ == id; +//} \ No newline at end of file diff --git a/src/Primitives.cpp b/src/Primitives.cpp index 94a5380..4847928 100644 --- a/src/Primitives.cpp +++ b/src/Primitives.cpp @@ -2,7 +2,7 @@ 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; - _boundtype = btype; + bound_type = btype; } std::pair Rectangle::missX(double y) { @@ -20,17 +20,17 @@ double Rectangle::Function(double x, double y) { return std::max(h_x_ * std::abs(x - a_), h_y_ * std::abs(y - b_)); } -std::pair Rectangle::Deriative(double x, double 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_)) }; } bool Rectangle::Inhere(double x, double y) { - return Function(x, y) <= 0.5; + 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; - _boundtype = btype; + bound_type = btype; } std::pair Circle::missY(double x) { @@ -44,7 +44,7 @@ double Circle::Function(double x, double y) { return pow(h_x_ * (x - a_), 2) + pow(h_y_ * (y - b_), 2); } -std::pair Circle::Deriative(double x, double y) { +std::pair Circle::Second_Deriative(double x, double y) { return { 2 * h_x_ * (x - a_), 2 * h_y_ * (y - b_) }; } @@ -53,12 +53,12 @@ std::pair Circle::size() { } bool Circle::Inhere(double x, double y) { - return Function(x, y) <= 1; + 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; - _boundtype = btype; + bound_type = btype; } std::pair Arc::missY(double x) { @@ -75,15 +75,15 @@ double Arc::Function(double x, double y) { return -1.0; } -std::pair Arc::Deriative(double x, double y) { +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_) }; } if (x < a_) { - std::cout << "x < a\n"; + //std::cout << "x < a\n"; } if (y < b_) { - std::cout << "y < b\n"; + //std::cout << "y < b\n"; } return { -1.0, -1.0 }; } diff --git a/src/Solver.cpp b/src/Solver.cpp index 3d9bdc4..4664443 100644 --- a/src/Solver.cpp +++ b/src/Solver.cpp @@ -1,7 +1,7 @@ #include "Solver.hpp" void Solver::SolveExplicit(System& program, double tstop) const { - std::ofstream ExplicitOut(_name_1); - //ExplicitOut << "t x y T" << std::endl; + std::ofstream output(filename_expl); + //output << "t x y T" << std::endl; for (double t = 0.0; t < tstop; t += delta) { /* Обработка узлов по оси X */ @@ -44,15 +44,15 @@ void Solver::SolveExplicit(System& program, double tstop) const { } for (auto line : program.Nodes()) { for (auto node : line) - ExplicitOut << t+1 << ' ' << node->X() << ' ' << node->Y() << ' ' << node->T() << '\n'; + output << t+1 << ' ' << node->X() << ' ' << node->Y() << ' ' << node->T() << '\n'; } - ExplicitOut << "\n\n"; + output << "\n\n"; } } void Solver::SolveImplicit(System& sys, double tstop) const { - std::ofstream EmplicitOut(_name_2); - //EmplicitOut << "t x y T" << std::endl; + std::ofstream output(filename_impl); + //output << "t x y T" << std::endl; for (double t = 0.; t < tstop; t += delta) { for (auto line : sys.Nodes()) @@ -72,9 +72,9 @@ void Solver::SolveImplicit(System& sys, double tstop) const { } for (auto line : sys.Nodes()) { for (auto node : line) - EmplicitOut << t + 1 << ' ' << node->X() << ' ' << node->Y() << ' ' << node->T() << '\n'; + output << t + 1 << ' ' << node->X() << ' ' << node->Y() << ' ' << node->T() << '\n'; } - EmplicitOut << "\n\n"; + output << "\n\n"; } } diff --git a/src/main.cpp b/src/main.cpp index 2a23827..a3af872 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -29,16 +29,20 @@ void visualize(std::ofstream& file, std::string filename, int time_end) { int main() { /* Граничные условия: - 1 - нагрев*/ - int l = 3; - int t = 1; - int r = 1; - int b = 4; - int r2 = 4; - int s = 4; + 1 - нагрев + 2 - теплоизоляция + 3 - конвекция + 4 - отсутствует + */ + int left = 3; + int top = 1; + int right = 3; + int bottom = 1; + int r2 = 3; + int s = 3; - double step = 10; - double step2 = 5; + double step_5 = 5; + double step_10 = 10; double time_step = 1; double time_end = 100; @@ -58,17 +62,17 @@ int main() obj.Add_Form("Arc", arc, true, r2); obj.Add_Form("Rectangle", plate, false, 1); - System explicit5(obj, step2, CONDUCTIVITY); - System explicit10(obj, step, CONDUCTIVITY); + System explicit5(obj, step_5, CONDUCTIVITY); + System explicit10(obj, step_10, CONDUCTIVITY); - System implicit5(obj, step2, CONDUCTIVITY); - System implicit10(obj, step, CONDUCTIVITY); + System implicit5(obj, step_5, CONDUCTIVITY); + System implicit10(obj, step_10, CONDUCTIVITY); - explicit5.DefineBounds(l, t, r, b); - explicit10.DefineBounds(l, t, r, b); + explicit5.DefineBounds(left, top, right, bottom); + explicit10.DefineBounds(left, top, right, bottom); - implicit5.DefineBounds(l, t, r, b); - implicit10.DefineBounds(l, t, r, b); + 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);