Масштабное переобозначение

Улучшение читаемости и понимания кода
This commit is contained in:
ParkSuMin
2025-05-14 18:00:22 +03:00
parent 8100f0d4e1
commit d55f8fa5d3
7 changed files with 57 additions and 50 deletions

View File

@@ -10,18 +10,18 @@ protected:
static size_t counter_; static size_t counter_;
size_t id_; size_t id_;
bool excluded_; bool excluded_;
int _boundtype; int bound_type;
public: public:
Form(); Form();
virtual double Function(double, double); virtual double Function(double, double);
virtual std::pair<double, double> Deriative(double, double); virtual std::pair<double, double> Second_Deriative(double, double);
virtual bool Inhere(double, double); virtual bool Inhere(double, double);
virtual std::pair<double, double> missX(double); virtual std::pair<double, double> missX(double);
virtual std::pair<double, double> missY(double); virtual std::pair<double, double> missY(double);
virtual std::pair<double, double> size(); virtual std::pair<double, double> size();
virtual int GetB(); virtual int GetB();
bool Excluded() const; bool Excluded() const;
bool operator==(size_t) const; //bool operator==(size_t) const;
}; };
#endif #endif

View File

@@ -3,6 +3,9 @@
#include "Form.hpp" #include "Form.hpp"
#define EPS_RECTANGLE 0.5
#define EPS_CIRCLE 1
class Rectangle : public Form { class Rectangle : public Form {
private: private:
double a_; double a_;
@@ -12,7 +15,7 @@ private:
public: public:
Rectangle(double, double, double, double, bool, int); Rectangle(double, double, double, double, bool, int);
double Function(double, double) override; double Function(double, double) override;
std::pair<double, double> Deriative(double, double) override; std::pair<double, double> Second_Deriative(double, double) override;
bool Inhere(double, double) override; bool Inhere(double, double) override;
std::pair<double, double> missX(double) override; std::pair<double, double> missX(double) override;
std::pair<double, double> missY(double) override; std::pair<double, double> missY(double) override;
@@ -27,7 +30,7 @@ private:
public: public:
Circle(double, double, double, double, bool, int); Circle(double, double, double, double, bool, int);
double Function(double, double) override; double Function(double, double) override;
std::pair<double, double> Deriative(double, double) override; std::pair<double, double> Second_Deriative(double, double) override;
bool Inhere(double, double) override; bool Inhere(double, double) override;
std::pair<double, double> missX(double) override; std::pair<double, double> missX(double) override;
std::pair<double, double> missY(double) override; std::pair<double, double> missY(double) override;
@@ -43,7 +46,7 @@ private:
public: public:
Arc(double, double, double, double, bool, int); Arc(double, double, double, double, bool, int);
double Function(double, double) override; double Function(double, double) override;
std::pair<double, double> Deriative(double, double) override; std::pair<double, double> Second_Deriative(double, double) override;
std::pair<double, double> missX(double) override; std::pair<double, double> missX(double) override;
std::pair<double, double> missY(double) override; std::pair<double, double> missY(double) override;
std::pair<double, double> size() override; std::pair<double, double> size() override;

View File

@@ -9,10 +9,10 @@ class Solver{
double delta; double delta;
std::vector<double> ThomasMethod(std::vector<std::vector<double>>&, std::vector<double>&) const; std::vector<double> ThomasMethod(std::vector<std::vector<double>>&, std::vector<double>&) const;
void SolveLine(System&, std::vector<Node*>&) const; void SolveLine(System&, std::vector<Node*>&) const;
std::string _name_1; std::string filename_expl;
std::string _name_2; std::string filename_impl;
public: 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 SolveExplicit(System&, double) const;
void SolveImplicit(System&, double) const; void SolveImplicit(System&, double) const;
}; };

View File

@@ -6,7 +6,7 @@ double Form::Function(double, double) {
return 0; return 0;
} }
std::pair<double, double> Form::Deriative(double, double) { std::pair<double, double> Form::Second_Deriative(double, double) {
return { 0, 0 }; return { 0, 0 };
} }
@@ -29,15 +29,15 @@ std::pair<double, double> Form::missY(double) {
Form::Form() { Form::Form() {
id_ = counter_++; id_ = counter_++;
excluded_ = false; excluded_ = false;
_boundtype = -1; bound_type = -1;
} }
bool Form::Excluded() const { bool Form::Excluded() const {
return excluded_; return excluded_;
} }
int Form::GetB() { return _boundtype; } int Form::GetB() { return bound_type; }
bool Form::operator==(size_t id) const { //bool Form::operator==(size_t id) const {
return id_ == id; // return id_ == id;
} //}

View File

@@ -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) { 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; excluded_ = excluded;
_boundtype = btype; bound_type = btype;
} }
std::pair<double, double> Rectangle::missX(double y) { std::pair<double, double> 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_)); return std::max(h_x_ * std::abs(x - a_), h_y_ * std::abs(y - b_));
} }
std::pair<double, double> Rectangle::Deriative(double x, double y) { std::pair<double, double> 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_)) }; 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) { 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) { 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; excluded_ = excluded;
_boundtype = btype; bound_type = btype;
} }
std::pair<double, double> Circle::missY(double x) { std::pair<double, double> 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); return pow(h_x_ * (x - a_), 2) + pow(h_y_ * (y - b_), 2);
} }
std::pair<double, double> Circle::Deriative(double x, double y) { std::pair<double, double> Circle::Second_Deriative(double x, double y) {
return { 2 * h_x_ * (x - a_), 2 * h_y_ * (y - b_) }; return { 2 * h_x_ * (x - a_), 2 * h_y_ * (y - b_) };
} }
@@ -53,12 +53,12 @@ std::pair<double, double> Circle::size() {
} }
bool Circle::Inhere(double x, double y) { 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) { 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; excluded_ = excluded;
_boundtype = btype; bound_type = btype;
} }
std::pair<double, double> Arc::missY(double x) { std::pair<double, double> Arc::missY(double x) {
@@ -75,15 +75,15 @@ double Arc::Function(double x, double y) {
return -1.0; return -1.0;
} }
std::pair<double, double> Arc::Deriative(double x, double y) { std::pair<double, double> Arc::Second_Deriative(double x, double y) {
if (x >= a_ && y >= b_) { if (x >= a_ && y >= b_) {
return { 2 * h_x_ * (x - a_), 2 * h_y_ * (y - b_) }; return { 2 * h_x_ * (x - a_), 2 * h_y_ * (y - b_) };
} }
if (x < a_) { if (x < a_) {
std::cout << "x < a\n"; //std::cout << "x < a\n";
} }
if (y < b_) { if (y < b_) {
std::cout << "y < b\n"; //std::cout << "y < b\n";
} }
return { -1.0, -1.0 }; return { -1.0, -1.0 };
} }

View File

@@ -1,7 +1,7 @@
#include "Solver.hpp" #include "Solver.hpp"
void Solver::SolveExplicit(System& program, double tstop) const { void Solver::SolveExplicit(System& program, double tstop) const {
std::ofstream ExplicitOut(_name_1); std::ofstream output(filename_expl);
//ExplicitOut << "t x y T" << std::endl; //output << "t x y T" << std::endl;
for (double t = 0.0; t < tstop; t += delta) { for (double t = 0.0; t < tstop; t += delta) {
/* Обработка узлов по оси X */ /* Обработка узлов по оси X */
@@ -44,15 +44,15 @@ void Solver::SolveExplicit(System& program, double tstop) const {
} }
for (auto line : program.Nodes()) { for (auto line : program.Nodes()) {
for (auto node : line) 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 { void Solver::SolveImplicit(System& sys, double tstop) const {
std::ofstream EmplicitOut(_name_2); std::ofstream output(filename_impl);
//EmplicitOut << "t x y T" << std::endl; //output << "t x y T" << std::endl;
for (double t = 0.; t < tstop; t += delta) { for (double t = 0.; t < tstop; t += delta) {
for (auto line : sys.Nodes()) for (auto line : sys.Nodes())
@@ -72,9 +72,9 @@ void Solver::SolveImplicit(System& sys, double tstop) const {
} }
for (auto line : sys.Nodes()) { for (auto line : sys.Nodes()) {
for (auto node : line) 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";
} }
} }

View File

@@ -29,16 +29,20 @@ void visualize(std::ofstream& file, std::string filename, int time_end) {
int main() int main()
{ {
/* Граничные условия: /* Граничные условия:
1 - нагрев*/ 1 - нагрев
int l = 3; 2 - теплоизоляция
int t = 1; 3 - конвекция
int r = 1; 4 - отсутствует
int b = 4; */
int r2 = 4; int left = 3;
int s = 4; int top = 1;
int right = 3;
int bottom = 1;
int r2 = 3;
int s = 3;
double step = 10; double step_5 = 5;
double step2 = 5; double step_10 = 10;
double time_step = 1; double time_step = 1;
double time_end = 100; double time_end = 100;
@@ -58,17 +62,17 @@ int main()
obj.Add_Form("Arc", arc, true, r2); obj.Add_Form("Arc", arc, true, r2);
obj.Add_Form("Rectangle", plate, false, 1); obj.Add_Form("Rectangle", plate, false, 1);
System explicit5(obj, step2, CONDUCTIVITY); System explicit5(obj, step_5, CONDUCTIVITY);
System explicit10(obj, step, CONDUCTIVITY); System explicit10(obj, step_10, CONDUCTIVITY);
System implicit5(obj, step2, CONDUCTIVITY); System implicit5(obj, step_5, CONDUCTIVITY);
System implicit10(obj, step, CONDUCTIVITY); System implicit10(obj, step_10, CONDUCTIVITY);
explicit5.DefineBounds(l, t, r, b); explicit5.DefineBounds(left, top, right, bottom);
explicit10.DefineBounds(l, t, r, b); explicit10.DefineBounds(left, top, right, bottom);
implicit5.DefineBounds(l, t, r, b); implicit5.DefineBounds(left, top, right, bottom);
implicit10.DefineBounds(l, t, r, b); implicit10.DefineBounds(left, top, right, bottom);
Solver slv5("explicit5.txt", "implicit5.txt", time_step); Solver slv5("explicit5.txt", "implicit5.txt", time_step);
Solver slv10("explicit10.txt", "implicit10.txt", time_step); Solver slv10("explicit10.txt", "implicit10.txt", time_step);