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
*.sln.docstates
*.txt
*.png
*.plt
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs

View File

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

View File

@@ -68,5 +68,6 @@
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<None Include="visual_mesh.py" />
</ItemGroup>
</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 {
protected:
static size_t counter_;
size_t id_;
bool excluded_;
static size_t counter;
size_t id;
bool excluded;
int bound_type;
public:
Form();

View File

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

View File

@@ -4,17 +4,17 @@
#include <cmath>
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;

View File

@@ -6,9 +6,9 @@
class Object {
private:
std::vector<Form*> forms_;
double _w;
double _h;
std::vector<Form*> forms;
double w;
double h;
void Updsize();
public:
Object();
@@ -19,8 +19,8 @@ public:
double Height() const;
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);
};

View File

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

View File

@@ -5,12 +5,13 @@
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);
void export_mesh(std::string);
std::vector<std::vector<Node*>>& Nodes();
std::vector<Node*>& LineX();
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"
size_t Form::counter_ = 0;
size_t Form::counter = 0;
double Form::Function(double, double) {
return 0;
@@ -27,13 +27,13 @@ std::pair<double, double> 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; }

View File

@@ -1,13 +1,13 @@
#include "Mesh.hpp"
#include <iostream>
#include <fstream>
#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) {
_mesh.push_back(std::vector<Node*>());
mesh.push_back(std::vector<Node*>());
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();
@@ -15,36 +15,48 @@ Mesh::Mesh(Object& obj, double step) : _obj(obj), _step(step) {
Adapt();
}
void Mesh::LinkX() {
void Mesh::VisualizeMesh(std::string name) {
std::ofstream data_file(name);
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);
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";
}
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() {
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,26 +66,32 @@ 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];
/* <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 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;
/* <20><> <20><><EFBFBD><EFBFBD><EFBFBD> */
int btype = obj.Who(node->X(), node->Y())->GetB();
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 (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* right = new Node(bndX1, node->Y(), btype);
node->l()->r() = left;
if (node->r())
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);
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);
}
/* <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 {
Node* left = new Node(bndX2, node->Y(), btype);
node->l()->r() = left;
@@ -81,12 +99,13 @@ 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);
}
}
/* <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
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()) {
node->r()->l() = node->l();
}
@@ -101,8 +120,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 +130,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 +139,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 << "| ";

View File

@@ -1,86 +1,86 @@
#include "Node.hpp"
#include <iostream>
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; }
bool Node::IsBound() { return btype; }
void Node::SetB(int _type) { btype = _type; }

View File

@@ -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<std::string, double>& 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;
}
@@ -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) {
for (auto form : forms_) {
std::pair<double, double> Object::FillX(double x, double y) {
for (auto form : forms) {
if (form->Inhere(x, y)) {
return form->missX(y);
}
@@ -55,8 +55,8 @@ std::pair<double, double> Object::Fillx(double x, double y) {
return { 0, 0 };
}
std::pair<double, double> Object::Filly(double x, double y) {
for (auto form : forms_) {
std::pair<double, double> Object::FillY(double x, double y) {
for (auto form : forms) {
if (form->Inhere(x, y)) {
return form->missY(x);
}
@@ -65,33 +65,33 @@ std::pair<double, double> Object::Filly(double x, double y) {
}
double Object::Width() const {
return _w;
return w;
}
double Object::Height() const {
return _h;
return h;
}
//std::vector<size_t> Object::Get_IDs() {
// std::vector<size_t> 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;
}

View File

@@ -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<double, double> Rectangle::missX(double y) {
return { 0.5 / h_x_ + a_, -0.5 / h_x_ + a_ };
std::pair<double, double> Rectangle::missX(double _y) {
return { 0.5 / h_x + x, -0.5 / h_x + x };
}
std::pair<double, double> Rectangle::missY(double x) {
return { 0.5 / h_y_ + b_, -0.5 / h_y_ + b_ };
std::pair<double, double> Rectangle::missY(double _x) {
return { 0.5 / h_y + y, -0.5 / h_y + y };
}
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) {
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<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_)) };
std::pair<double, double> 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<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_ };
std::pair<double, double> 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<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_ };
std::pair<double, double> 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<double, double> Circle::Second_Deriative(double x, double y) {
return { 2 * h_x_ * (x - a_), 2 * h_y_ * (y - b_) };
std::pair<double, double> Circle::Second_Deriative(double _x, double _y) {
return { 2 * h_x * (_x - x), 2 * h_y * (_y - y) };
}
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) {
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<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_ };
std::pair<double, double> 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<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_ };
std::pair<double, double> 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<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_) };
std::pair<double, double> 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<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) {

View File

@@ -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<Node*>& 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<double> tmps = ThomasMethod(_Temperature, right);
for (int i = 0; i < tmps.size(); i++)
n[i + 1]->SetT(tmps[i]);
std::vector<double> tmp = ThomasMethod(_Temperature, right);
for (int i = 0; i < tmp.size(); i++)
n[i + 1]->SetT(tmp[i]);
}
/* Метод прогонки для численного решения СЛАУ */
std::vector<double> Solver::ThomasMethod(std::vector<std::vector<double>>& A, std::vector<double>& b) const {
int row = b.size() - 1;

View File

@@ -1,30 +1,34 @@
#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();
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<std::vector<Node*>>& System::Nodes() { return _mesh.Nodes(); }
std::vector<Node*>& System::LineX() { return _mesh.LineX(); }
std::vector<Node*>& System::LineY() { return _mesh.LineY(); }
std::vector<std::vector<Node*>>& System::Nodes() { return mesh.Nodes(); }
std::vector<Node*>& System::LineX() { return mesh.LineX(); }
std::vector<Node*>& System::LineY() { return mesh.LineY(); }

View File

@@ -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<std::string, double> arc{
{"a", WIDTH - ARC_RADIUS}, {"b", HEIGHT - ARC_RADIUS}, {"h_x", 1 / ARC_RADIUS}, {"h_y", 1 / ARC_RADIUS}
};
std::map<std::string, double> circle{
{"a", HOLE_X}, {"b", HOLE_Y}, {"h_x", 1 / HOLE_RADIUS}, {"h_y", 1 / HOLE_RADIUS}
//std::map<std::string, double> circle{
// {"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;
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);
@@ -69,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);
@@ -101,6 +109,3 @@ int main()
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!")