fix #3

Merged
ParkSuMin merged 5 commits from fix into master 2025-05-15 17:09:02 +02:00
22 changed files with 287 additions and 268 deletions

2
.gitignore vendored
View File

@@ -10,6 +10,8 @@
*.userosscache *.userosscache
*.sln.docstates *.sln.docstates
*.txt *.txt
*.png
*.plt
# User-specific files (MonoDevelop/Xamarin Studio) # User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs *.userprefs

View File

@@ -158,6 +158,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="packages.config" /> <None Include="packages.config" />
<None Include="visual_mesh.py" />
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">

View File

@@ -68,5 +68,6 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="packages.config" /> <None Include="packages.config" />
<None Include="visual_mesh.py" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

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

10
es5.plt
View File

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

View File

@@ -7,9 +7,9 @@
class Form { class Form {
protected: protected:
static size_t counter_; static size_t counter;
size_t id_; size_t id;
bool excluded_; bool excluded;
int bound_type; int bound_type;
public: public:
Form(); Form();

View File

@@ -6,11 +6,11 @@
#include "Node.hpp" #include "Node.hpp"
class Mesh{ class Mesh{
std::vector<std::vector<Node*>> _mesh; std::vector<std::vector<Node*>> mesh;
std::vector<Node*> _hlines; std::vector<Node*> hlines;
std::vector<Node*> _vlines; std::vector<Node*> vlines;
Object& _obj; Object& obj;
double _step; double step;
void LinkX(); void LinkX();
void LinkY(); void LinkY();
void Delnode(int, int); void Delnode(int, int);
@@ -20,10 +20,11 @@ public:
Mesh(Object&, double); Mesh(Object&, double);
~Mesh(); ~Mesh();
//void ShowLinks(); //void ShowLinks();
void VisualizeMesh(std::string);
std::vector<std::vector<Node*>>& Nodes() { return _mesh; } std::vector<std::vector<Node*>>& Nodes() { return mesh; }
std::vector<Node*>& LineX() { return _hlines; } std::vector<Node*>& LineX() { return hlines; }
std::vector<Node*>& LineY() { return _vlines; } std::vector<Node*>& LineY() { return vlines; }
}; };
#endif #endif

View File

@@ -4,17 +4,17 @@
#include <cmath> #include <cmath>
class Node{ class Node{
double _x; double x;
double _y; double y;
double _t; double t;
int _btype; int btype;
Node* _left; Node* left;
Node* _right; Node* right;
Node* _above; Node* above;
Node* _below; Node* bellow;
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), bellow(nullptr), btype(_type) {}
double T() const; double T() const;
double X() const; double X() const;

View File

@@ -6,9 +6,9 @@
class Object { class Object {
private: private:
std::vector<Form*> forms_; std::vector<Form*> forms;
double _w; double w;
double _h; double h;
void Updsize(); void Updsize();
public: public:
Object(); Object();
@@ -19,8 +19,8 @@ public:
double Height() const; double Height() const;
bool Add_Form(const std::string&, std::map<std::string, double>&, bool, int); bool Add_Form(const std::string&, std::map<std::string, double>&, bool, int);
std::pair<double, double> Filly(double, double); std::pair<double, double> FillX(double, double);
std::pair<double, double> Fillx(double, double); std::pair<double, double> FillY(double, double);
Form* Who(double, double); Form* Who(double, double);
}; };

View File

@@ -8,10 +8,10 @@
class Rectangle : public Form { class Rectangle : public Form {
private: private:
double a_; double x;
double b_; double y;
double h_x_; double h_x;
double h_y_; double h_y;
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;
@@ -23,10 +23,10 @@ public:
}; };
class Circle : public Form { class Circle : public Form {
private: private:
double a_; double x;
double b_; double y;
double h_x_; double h_x;
double h_y_; double h_y;
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;
@@ -39,10 +39,10 @@ public:
class Arc : public Form { class Arc : public Form {
private: private:
double a_; double x;
double b_; double y;
double h_x_; double h_x;
double h_y_; double h_y;
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;

View File

@@ -5,12 +5,13 @@
class System{ class System{
Object& _obj; Object& _obj;
Mesh _mesh; Mesh mesh;
double _a; double _a;
double _step; double _step;
public: 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); void DefineBounds(int, int, int, int);
void export_mesh(std::string);
std::vector<std::vector<Node*>>& Nodes(); std::vector<std::vector<Node*>>& Nodes();
std::vector<Node*>& LineX(); std::vector<Node*>& LineX();
std::vector<Node*>& LineY(); std::vector<Node*>& LineY();

View File

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

10
is5.plt
View File

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

View File

@@ -1,6 +1,6 @@
#include "Form.hpp" #include "Form.hpp"
size_t Form::counter_ = 0; size_t Form::counter = 0;
double Form::Function(double, double) { double Form::Function(double, double) {
return 0; return 0;
@@ -27,13 +27,13 @@ std::pair<double, double> Form::missY(double) {
} }
Form::Form() { Form::Form() {
id_ = counter_++; id = counter++;
excluded_ = false; excluded = false;
bound_type = -1; bound_type = -1;
} }
bool Form::Excluded() const { bool Form::Excluded() const {
return excluded_; return excluded;
} }
int Form::GetB() { return bound_type; } int Form::GetB() { return bound_type; }

View File

@@ -1,13 +1,13 @@
#include "Mesh.hpp" #include "Mesh.hpp"
#include <iostream> #include <iostream>
#include <fstream>
#include <Object.hpp> #include <Object.hpp>
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) { for (double y = 0.0; y <= _obj.Height(); y += _step) {
_mesh.push_back(std::vector<Node*>()); mesh.push_back(std::vector<Node*>());
for (double x = 0.0; x <= _obj.Width(); x += _step) { 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(); LinkX();
@@ -15,36 +15,48 @@ Mesh::Mesh(Object& obj, double step) : _obj(obj), _step(step) {
Adapt(); Adapt();
} }
void Mesh::LinkX() { void Mesh::VisualizeMesh(std::string name) {
std::ofstream data_file(name);
for (int i = 0; i < _mesh.size(); i++) { data_file << "# Coordinates\n";
_mesh[i][0]->LinkX(nullptr, _mesh[i][1]); data_file << "# Format: x y\n";
for (int j = 1; j < _mesh[i].size() - 1; j++)
_mesh[i][j]->LinkX(_mesh[i][j - 1], _mesh[i][j + 1]); for (const auto& row : mesh) {
_mesh[i].back()->LinkX(_mesh[i][_mesh[i].size() - 2], nullptr); for (const auto& node : row) {
data_file << node->X() << " " << node->Y() << "\n";
}
} }
for (int i = 0; i < _mesh.size(); i++)
_hlines.push_back(_mesh[i][0]); data_file.close();
} }
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++)
hlines.push_back(mesh[i][0]);
}
void Mesh::LinkY() { void Mesh::LinkY() {
for (int j = 0; j < _mesh[0].size(); j++) { for (int j = 0; j < mesh[0].size(); j++) {
_mesh[0][j]->LinkY(nullptr, _mesh[1][j]); mesh[0][j]->LinkY(nullptr, mesh[1][j]);
for (int i = 1; i < _mesh.size() - 1; i++) for (int i = 1; i < mesh.size() - 1; i++)
_mesh[i][j]->LinkY(_mesh[i - 1][j], _mesh[i + 1][j]); mesh[i][j]->LinkY(mesh[i - 1][j], mesh[i + 1][j]);
_mesh[_mesh.size() - 1][j]->LinkY(_mesh[_mesh.size() - 2][j], nullptr); mesh[mesh.size() - 1][j]->LinkY(mesh[mesh.size() - 2][j], nullptr);
} }
for (int i = 0; i < _mesh[0].size(); i++) for (int i = 0; i < mesh[0].size(); i++)
_vlines.push_back(_mesh[0][i]); vlines.push_back(mesh[0][i]);
} }
void Mesh::Adapt() { void Mesh::Adapt() {
for (int i = 0; i < _mesh.size(); i++) { for (int i = 0; i < mesh.size(); i++) {
int s = _mesh[i].size(); int s = mesh[i].size();
for (int j = 0; j < s; j++) { 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); Delnode(i, j);
j--; j--;
s--; s--;
@@ -54,26 +66,32 @@ void Mesh::Adapt() {
} }
void Mesh::Delnode(int i, int j) { void Mesh::Delnode(int i, int j) {
Node* node = _mesh[i][j]; Node* node = mesh[i][j];
double bndX1 = _obj.Fillx(node->X(), node->Y()).first; /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD> X <20> Y */
double bndX2 = _obj.Fillx(node->X(), node->Y()).second; double bndX1 = obj.FillX(node->X(), node->Y()).first;
double bndY1 = _obj.Filly(node->X(), node->Y()).first; double bndX2 = obj.FillX(node->X(), node->Y()).second;
double bndY2 = _obj.Filly(node->X(), node->Y()).second; double bndY1 = obj.FillY(node->X(), node->Y()).first;
int btype = _obj.Who(node->X(), node->Y())->GetB(); double bndY2 = obj.FillY(node->X(), node->Y()).second;
/* <20><> <20><><EFBFBD><EFBFBD><EFBFBD> */
int btype = obj.Who(node->X(), node->Y())->GetB();
if (node->l()) { if (node->l()) {
// <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (node->l()->X() != bndX2 && node->l()->X() != bndX1) { if (node->l()->X() != bndX2 && node->l()->X() != bndX1) {
if (bndX1 != bndX2) { if (bndX1 != bndX2) {
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> bndX2 <20> bndX1 <20> <20><> btype */
Node* left = new Node(bndX2, node->Y(), btype); Node* left = new Node(bndX2, node->Y(), btype);
Node* right = new Node(bndX1, node->Y(), btype); Node* right = new Node(bndX1, node->Y(), btype);
node->l()->r() = left; node->l()->r() = left;
if (node->r()) if (node->r())
node->r()->l() = right; node->r()->l() = right;
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD> X */
left->LinkX(node->l(), right); left->LinkX(node->l(), right);
right->LinkX(left, node->r()); right->LinkX(left, node->r());
node->l() = right; node->l() = right;
_mesh[i].push_back(left); mesh[i].push_back(left);
_mesh[i].push_back(right); mesh[i].push_back(right);
} }
/* <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> X <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> */
else { else {
Node* left = new Node(bndX2, node->Y(), btype); Node* left = new Node(bndX2, node->Y(), btype);
node->l()->r() = left; node->l()->r() = left;
@@ -81,12 +99,13 @@ void Mesh::Delnode(int i, int j) {
node->r()->l() = left; node->r()->l() = left;
left->LinkX(node->l(), node->r()); left->LinkX(node->l(), node->r());
node->l() = left; node->l() = left;
_mesh[i].push_back(left); mesh[i].push_back(left);
} }
} }
/* <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
else else
node->l()->r() = node->r(); node->l()->r() = node->r();
} } /* <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> */
if (node->r()) { if (node->r()) {
node->r()->l() = node->l(); node->r()->l() = node->l();
} }
@@ -101,8 +120,8 @@ void Mesh::Delnode(int i, int j) {
down->LinkY(node->d(), up); down->LinkY(node->d(), up);
up->LinkY(down, node->u()); up->LinkY(down, node->u());
node->d() = up; node->d() = up;
_mesh[i].push_back(down); mesh[i].push_back(down);
_mesh[i].push_back(up); mesh[i].push_back(up);
} }
else { else {
Node* down = new Node(node->X(), bndY2, btype); Node* down = new Node(node->X(), bndY2, btype);
@@ -111,7 +130,7 @@ void Mesh::Delnode(int i, int j) {
node->u()->d() = down; node->u()->d() = down;
down->LinkY(node->d(), node->u()); down->LinkY(node->d(), node->u());
node->d() = down; node->d() = down;
_mesh[i].push_back(down); mesh[i].push_back(down);
} }
} }
else else
@@ -120,18 +139,18 @@ void Mesh::Delnode(int i, int j) {
if (node->u()) { if (node->u()) {
node->u()->d() = node->d(); node->u()->d() = node->d();
} }
_mesh[i].erase(_mesh[i].begin() + j); mesh[i].erase(mesh[i].begin() + j);
delete node; delete node;
} }
Mesh::~Mesh() { Mesh::~Mesh() {
for (auto line : _mesh) for (auto line : mesh)
for (auto node : line) for (auto node : line)
delete node; delete node;
} }
//void Mesh::ShowLinks() { //void Mesh::ShowLinks() {
// for (auto line : _mesh) { // for (auto line : mesh) {
// for (auto node : line) { // for (auto node : line) {
// if (node->d()) // if (node->d())
// std::cout << "| "; // std::cout << "| ";

View File

@@ -1,86 +1,86 @@
#include "Node.hpp" #include "Node.hpp"
#include <iostream> #include <iostream>
double Node::X() const { return _x; } double Node::X() const { return x; }
double Node::Y() const { return _y; } double Node::Y() const { return y; }
double Node::T() const { double Node::T() const {
if (_btype == 1) if (btype == 1)
return 100.; return 100.;
if (_btype == 2) { else if (btype == 2) {
if (!_left) if (!left)
if (_right) if (right)
return _right->T() / (1 + Dist(_right)); return right->T() / (1 + Dist(right));
if (!_right) if (!right)
if (_left) if (left)
return _left->T() / (1 + Dist(_left)); return left->T() / (1 + Dist(left));
if (!_above) if (!above)
if (_below) if (bellow)
return _below->T() / (1 + Dist(_below)); return bellow->T() / (1 + Dist(bellow));
if (!_below) if (!bellow)
if (_above) if (above)
return _above->T() / (1 + Dist(_above)); return above->T() / (1 + Dist(above));
if (_right && _left) { if (right && left) {
if (_right->IsBound()) if (right->IsBound())
return _left->T() / (1 + Dist(_left)); return left->T() / (1 + Dist(left));
return _right->T() / (1 + Dist(_right)); return right->T() / (1 + Dist(right));
} }
if (_above && _below) { if (above && bellow) {
if (_above->IsBound()) if (above->IsBound())
return _below->T() / (1 + Dist(_below)); return bellow->T() / (1 + Dist(bellow));
return _above->T() / (1 + Dist(_above)); return above->T() / (1 + Dist(above));
} }
} }
if (_btype == 3) { else if (btype == 3) {
if (!_left) if (!left)
if (_right) if (right)
return _right->T(); return right->T();
if (!_right) if (!right)
if (_left) if (left)
return _left->T(); return left->T();
if (!_above) if (!above)
if (_below) if (bellow)
return _below->T(); return bellow->T();
if (!_below) if (!bellow)
if (_above) if (above)
return _above->T(); return above->T();
if (_right && _left) { if (right && left) {
if (_right->IsBound()) if (right->IsBound())
return _left->T(); return left->T();
return _right->T(); return right->T();
} }
if (_above && _below) { if (above && bellow) {
if (_above->IsBound()) if (above->IsBound())
return _below->T(); return bellow->T();
return _above->T(); return above->T();
} }
} }
return _t; return t;
} }
double Node::Dist(const Node* to) const { double Node::Dist(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));
} }
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; }
Node*& Node::d() { return _below; } Node*& Node::d() { return bellow; }
void Node::LinkX(Node* l, Node* r) { void Node::LinkX(Node* l, Node* r) {
_left = l; left = l;
_right = r; right = r;
} }
void Node::LinkY(Node* d, Node* u) { void Node::LinkY(Node* d, Node* u) {
_below = d; bellow = d;
_above = u; above = u;
} }
void Node::SetT(double t) { void Node::SetT(double _t) {
_t = t; t = _t;
} }
bool Node::IsBound() { return _btype; } bool Node::IsBound() { return btype; }
void Node::SetB(int type) { _btype = type; } void Node::SetB(int _type) { btype = _type; }

View File

@@ -1,9 +1,9 @@
#include "Object.hpp" #include "Object.hpp"
Object::Object() : _w(0), _h(0) {} Object::Object() : w(0), h(0) {}
double Object::Inhere(double x, double y) { double Object::Inhere(double x, double y) {
for (auto form : forms_) { for (auto form : forms) {
if (form->Excluded()) { if (form->Excluded()) {
if (form->Inhere(x, y)) { if (form->Inhere(x, y)) {
return false; return false;
@@ -19,25 +19,25 @@ double Object::Inhere(double x, double y) {
} }
void Object::Updsize() { void Object::Updsize() {
for (auto form : forms_) { for (auto form : forms) {
_w = std::max(_w, form->size().first); w = std::max(w, form->size().first);
_h = std::max(_h, form->size().second); h = std::max(h, form->size().second);
} }
} }
bool Object::Add_Form(const std::string& name, std::map<std::string, double>& args, bool excluded, int btype) { bool Object::Add_Form(const std::string& name, std::map<std::string, double>& args, bool excluded, int btype) {
if (name == "Rectangle") { 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(); Updsize();
return true; return true;
} }
else if (name == "Circle") { 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(); Updsize();
return true; return true;
} }
else if (name == "Arc") { 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(); Updsize();
return true; return true;
} }
@@ -46,8 +46,8 @@ bool Object::Add_Form(const std::string& name, std::map<std::string, double>& ar
std::pair<double, double> Object::Fillx(double x, double y) { std::pair<double, double> Object::FillX(double x, double y) {
for (auto form : forms_) { for (auto form : forms) {
if (form->Inhere(x, y)) { if (form->Inhere(x, y)) {
return form->missX(y); return form->missX(y);
} }
@@ -55,8 +55,8 @@ std::pair<double, double> Object::Fillx(double x, double y) {
return { 0, 0 }; return { 0, 0 };
} }
std::pair<double, double> Object::Filly(double x, double y) { std::pair<double, double> Object::FillY(double x, double y) {
for (auto form : forms_) { for (auto form : forms) {
if (form->Inhere(x, y)) { if (form->Inhere(x, y)) {
return form->missY(x); return form->missY(x);
} }
@@ -65,33 +65,33 @@ std::pair<double, double> Object::Filly(double x, double y) {
} }
double Object::Width() const { double Object::Width() const {
return _w; return w;
} }
double Object::Height() const { double Object::Height() const {
return _h; return h;
} }
//std::vector<size_t> Object::Get_IDs() { //std::vector<size_t> Object::Get_IDs() {
// std::vector<size_t> ids; // std::vector<size_t> ids;
// ids.reserve(forms_.size()); // ids.reserve(forms.size());
// for (auto form : forms_) { // for (auto form : forms) {
// ids.push_back(form->Get_ID()); // ids.push_back(form->Get_ID());
// } // }
// return ids; // return ids;
//} //}
Form* Object::Who(double x, double y) { Form* Object::Who(double x, double y) {
for (auto form : forms_) { for (auto form : forms) {
if (form->Inhere(x, y)) { if (form->Inhere(x, y)) {
return form; return form;
} }
} }
return forms_.back(); return forms.back();
} }
Object::~Object() { Object::~Object() {
for (auto form : forms_) for (auto form : forms)
delete form; delete form;
} }

View File

@@ -1,95 +1,95 @@
#include "Primitives.hpp" #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) { 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; excluded = _excluded;
bound_type = btype; bound_type = _btype;
} }
std::pair<double, double> Rectangle::missX(double y) { std::pair<double, double> Rectangle::missX(double _y) {
return { 0.5 / h_x_ + a_, -0.5 / h_x_ + a_ }; return { 0.5 / h_x + x, -0.5 / h_x + x };
} }
std::pair<double, double> Rectangle::missY(double x) { std::pair<double, double> Rectangle::missY(double _x) {
return { 0.5 / h_y_ + b_, -0.5 / h_y_ + b_ }; return { 0.5 / h_y + y, -0.5 / h_y + y };
} }
std::pair<double, double> Rectangle::size() { std::pair<double, double> Rectangle::size() {
return { 1 / h_x_, 1 / h_y_ }; return { 1 / h_x, 1 / h_y };
} }
double Rectangle::Function(double x, double y) { 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 - x), h_y * std::abs(_y - y));
} }
std::pair<double, double> Rectangle::Second_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 - x) / std::abs(_x - x)), (h_y / 2) * ((_y - y) / std::abs(_y - y)) };
} }
bool Rectangle::Inhere(double x, double y) { bool Rectangle::Inhere(double x, double y) {
return Function(x, y) <= EPS_RECTANGLE; 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 _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; excluded = _excluded;
bound_type = btype; bound_type = _btype;
} }
std::pair<double, double> Circle::missY(double x) { std::pair<double, double> 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_ }; 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<double, double> Circle::missX(double y) { std::pair<double, double> 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_ }; 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) { 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 - x), 2) + pow(h_y * (_y - y), 2);
} }
std::pair<double, double> Circle::Second_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 - x), 2 * h_y * (_y - y) };
} }
std::pair<double, double> Circle::size() { std::pair<double, double> Circle::size() {
return { 1 / h_x_, 1 / h_y_ }; return { 1 / h_x, 1 / h_y };
} }
bool Circle::Inhere(double x, double y) { bool Circle::Inhere(double x, double y) {
return Function(x, y) <= EPS_CIRCLE; 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 _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; excluded = _excluded;
bound_type = btype; bound_type = _btype;
} }
std::pair<double, double> Arc::missY(double x) { std::pair<double, double> 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_ }; 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<double, double> Arc::missX(double y) { std::pair<double, double> 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_ }; 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) { double Arc::Function(double _x, double _y) {
if (x >= a_ && y >= b_) { if (_x >= x && _y >= y) {
return pow(h_x_ * (x - a_), 2) + pow(h_y_ * (y - b_), 2); return pow(h_x * (_x - x), 2) + pow(h_y * (_y - y), 2);
} }
return -1.0; return -1.0;
} }
std::pair<double, double> Arc::Second_Deriative(double x, double y) { std::pair<double, double> Arc::Second_Deriative(double _x, double _y) {
if (x >= a_ && y >= b_) { if (_x >= x && _y >= y) {
return { 2 * h_x_ * (x - a_), 2 * h_y_ * (y - b_) }; return { 2 * h_x * (_x - x), 2 * h_y * (_y - y) };
} }
if (x < a_) { if (_x < x) {
//std::cout << "x < a\n"; //std::cout << "_x < a\n";
} }
if (y < b_) { if (_y < y) {
//std::cout << "y < b\n"; //std::cout << "_y < b\n";
} }
return { -1.0, -1.0 }; return { -1.0, -1.0 };
} }
std::pair<double, double> Arc::size() { std::pair<double, double> Arc::size() {
return { 1 / h_x_, 1 / h_y_ }; return { 1 / h_x, 1 / h_y };
} }
bool Arc::Inhere(double x, double y) { bool Arc::Inhere(double x, double y) {

View File

@@ -61,8 +61,7 @@ void Solver::SolveExplicit(System& sys, double tstop) const {
if (!node->IsBound()) { if (!node->IsBound()) {
/* Tx = T_right - 2T_current + T_left / delta_x ^ 2 */ /* Tx = T_right - 2T_current + T_left / delta_x ^ 2 */
/* Ty = T_upper - 2T_current + T_down / delta_y ^ 2*/ /* Ty = T_upper - 2T_current + T_down / delta_y ^ 2*/
/* T_new = delta_t * a * (delta_x + delta_y) + T_current /* T_new = delta_t * a * (delta_x + delta_y) + T_current */
(для удобства коээфициент a = 1) */
double tx = (node->r()->T() - 2 * node->T() + node->l()->T()) / pow(sys.step(), 2); 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); 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<Node*>& n) const {
right[i] = -n[i + 1]->T() / delta; right[i] = -n[i + 1]->T() / delta;
right.front() += -(2 * sys.a() * n.front()->T()) / (mu1 * (mu1 + 1) * pow(sys.step(), 2)); 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)); right.back() += -(2 * sys.a() * n.back()->T()) / (mu2 * (mu2 + 1) * pow(sys.step(), 2));
std::vector<double> tmps = ThomasMethod(_Temperature, right); std::vector<double> tmp = ThomasMethod(_Temperature, right);
for (int i = 0; i < tmps.size(); i++) for (int i = 0; i < tmp.size(); i++)
n[i + 1]->SetT(tmps[i]); n[i + 1]->SetT(tmp[i]);
} }
/* Метод прогонки для численного решения СЛАУ */
std::vector<double> Solver::ThomasMethod(std::vector<std::vector<double>>& A, std::vector<double>& b) const { std::vector<double> Solver::ThomasMethod(std::vector<std::vector<double>>& A, std::vector<double>& b) const {
int row = b.size() - 1; int row = b.size() - 1;

View File

@@ -1,30 +1,34 @@
#include "System.hpp" #include "System.hpp"
void System::export_mesh(std::string name) {
mesh.VisualizeMesh(name);
}
void System::DefineBounds(int l, int t, int r, int b) { void System::DefineBounds(int l, int t, int r, int b) {
Node* cur = _mesh.LineX().front(); Node* cur = mesh.LineX().front();
while (cur) { while (cur) {
cur->SetB(b); cur->SetB(b);
cur = cur->r(); cur = cur->r();
} }
cur = _mesh.LineX().back(); cur = mesh.LineX().back();
while (cur) { while (cur) {
cur->SetB(t); cur->SetB(t);
cur = cur->r(); cur = cur->r();
} }
cur = _mesh.LineY().front(); cur = mesh.LineY().front();
while (cur) { while (cur) {
cur->SetB(l); cur->SetB(l);
cur = cur->u(); cur = cur->u();
} }
cur = _mesh.LineY().back(); cur = mesh.LineY().back();
while (cur->u()) { while (cur->u()) {
cur->SetB(r); cur->SetB(r);
cur = cur->u(); cur = cur->u();
} }
} }
std::vector<std::vector<Node*>>& System::Nodes() { return _mesh.Nodes(); } std::vector<std::vector<Node*>>& System::Nodes() { return mesh.Nodes(); }
std::vector<Node*>& System::LineX() { return _mesh.LineX(); } std::vector<Node*>& System::LineX() { return mesh.LineX(); }
std::vector<Node*>& System::LineY() { return _mesh.LineY(); } std::vector<Node*>& System::LineY() { return mesh.LineY(); }

View File

@@ -9,15 +9,15 @@
#define ARC_RADIUS 150. #define ARC_RADIUS 150.
//#define SQUARE_X 355. #define SQUARE_X 355.
//#define SQUARE_Y 155. #define SQUARE_Y 155.
//#define SQUARE_SIDE 100. #define SQUARE_SIDE 100.
#define HOLE_X 155. //#define HOLE_X 155.
#define HOLE_Y 255. //#define HOLE_Y 255.
#define HOLE_RADIUS 50. //#define HOLE_RADIUS 50.
#define CONDUCTIVITY 90. // Теплопроводность материала #define CONDUCTIVITY 50. // Теплопроводность материала
void visualize(std::ofstream& file, std::string filename, int time_end) { void visualize(std::ofstream& file, std::string filename, int time_end) {
file << "set cbrange [" << 0 << ":" << 100 << "]" << std::endl; file << "set cbrange [" << 0 << ":" << 100 << "]" << std::endl;
@@ -41,7 +41,7 @@ int main()
int right = 1; int right = 1;
int bottom = 3; int bottom = 3;
int arc_bound = 3; int arc_bound = 3;
int hole_bound = 2; int hole_bound = 1;
double step_5 = 5; double step_5 = 5;
double step_10 = 10; double step_10 = 10;
@@ -54,12 +54,16 @@ int main()
std::map<std::string, double> arc{ std::map<std::string, double> arc{
{"a", WIDTH - ARC_RADIUS}, {"b", HEIGHT - ARC_RADIUS}, {"h_x", 1 / ARC_RADIUS}, {"h_y", 1 / ARC_RADIUS} {"a", WIDTH - ARC_RADIUS}, {"b", HEIGHT - ARC_RADIUS}, {"h_x", 1 / ARC_RADIUS}, {"h_y", 1 / ARC_RADIUS}
}; };
std::map<std::string, double> circle{ //std::map<std::string, double> circle{
{"a", HOLE_X}, {"b", HOLE_Y}, {"h_x", 1 / HOLE_RADIUS}, {"h_y", 1 / HOLE_RADIUS} // {"a", HOLE_X}, {"b", HOLE_Y}, {"h_x", 1 / HOLE_RADIUS}, {"h_y", 1 / HOLE_RADIUS}
//};
std::map<std::string, double> square{
{"a", SQUARE_X}, {"b", SQUARE_Y}, {"h_x", 1 / SQUARE_SIDE}, {"h_y", 1 / SQUARE_SIDE}
}; };
Object obj; 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("Arc", arc, true, arc_bound);
obj.Add_Form("Rectangle", plate, false, 1); obj.Add_Form("Rectangle", plate, false, 1);
@@ -69,6 +73,10 @@ int main()
System implicit5(obj, step_5, CONDUCTIVITY); System implicit5(obj, step_5, CONDUCTIVITY);
System implicit10(obj, step_10, CONDUCTIVITY); System implicit10(obj, step_10, CONDUCTIVITY);
/* Экспорт сеток */
explicit5.export_mesh("mesh5.txt");
explicit10.export_mesh("mesh10.txt");
explicit5.DefineBounds(left, top, right, bottom); explicit5.DefineBounds(left, top, right, bottom);
explicit10.DefineBounds(left, top, right, bottom); explicit10.DefineBounds(left, top, right, bottom);
@@ -101,6 +109,3 @@ int main()
return 0; return 0;
} }
//std::map<std::string, double> square{
// {"a", SQUARE_X}, {"b", SQUARE_Y}, {"h_x", 1 / SQUARE_SIDE}, {"h_y", 1 / SQUARE_SIDE}
//};

26
visual_mesh.py Normal file
View File

@@ -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!")