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

Улучшение читаемости и понимания кода
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

@@ -6,7 +6,7 @@ double Form::Function(double, double) {
return 0;
}
std::pair<double, double> Form::Deriative(double, double) {
std::pair<double, double> Form::Second_Deriative(double, double) {
return { 0, 0 };
}
@@ -29,15 +29,15 @@ std::pair<double, double> 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;
}
//bool Form::operator==(size_t id) const {
// 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) {
excluded_ = excluded;
_boundtype = btype;
bound_type = btype;
}
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_));
}
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_)) };
}
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<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);
}
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_) };
}
@@ -53,12 +53,12 @@ std::pair<double, double> 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<double, double> Arc::missY(double x) {
@@ -75,15 +75,15 @@ double Arc::Function(double x, double y) {
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_) {
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 };
}

View File

@@ -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";
}
}

View File

@@ -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);