Renaming
This commit is contained in:
@@ -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();
|
||||||
|
|||||||
@@ -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);
|
||||||
@@ -21,9 +21,9 @@ public:
|
|||||||
~Mesh();
|
~Mesh();
|
||||||
//void ShowLinks();
|
//void ShowLinks();
|
||||||
|
|
||||||
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
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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();
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -5,11 +5,11 @@
|
|||||||
|
|
||||||
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);
|
||||||
std::vector<std::vector<Node*>>& Nodes();
|
std::vector<std::vector<Node*>>& Nodes();
|
||||||
std::vector<Node*>& LineX();
|
std::vector<Node*>& LineX();
|
||||||
|
|||||||
@@ -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; }
|
||||||
|
|||||||
70
src/Mesh.cpp
70
src/Mesh.cpp
@@ -2,12 +2,12 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#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();
|
||||||
@@ -17,34 +17,34 @@ Mesh::Mesh(Object& obj, double step) : _obj(obj), _step(step) {
|
|||||||
|
|
||||||
void Mesh::LinkX() {
|
void Mesh::LinkX() {
|
||||||
|
|
||||||
for (int i = 0; i < _mesh.size(); i++) {
|
for (int i = 0; i < mesh.size(); i++) {
|
||||||
_mesh[i][0]->LinkX(nullptr, _mesh[i][1]);
|
mesh[i][0]->LinkX(nullptr, mesh[i][1]);
|
||||||
for (int j = 1; j < _mesh[i].size() - 1; j++)
|
for (int j = 1; j < mesh[i].size() - 1; j++)
|
||||||
_mesh[i][j]->LinkX(_mesh[i][j - 1], _mesh[i][j + 1]);
|
mesh[i][j]->LinkX(mesh[i][j - 1], mesh[i][j + 1]);
|
||||||
_mesh[i].back()->LinkX(_mesh[i][_mesh[i].size() - 2], nullptr);
|
mesh[i].back()->LinkX(mesh[i][mesh[i].size() - 2], nullptr);
|
||||||
}
|
}
|
||||||
for (int i = 0; i < _mesh.size(); i++)
|
for (int i = 0; i < mesh.size(); i++)
|
||||||
_hlines.push_back(_mesh[i][0]);
|
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,12 +54,12 @@ 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;
|
double bndX1 = obj.Fillx(node->X(), node->Y()).first;
|
||||||
double bndX2 = _obj.Fillx(node->X(), node->Y()).second;
|
double bndX2 = obj.Fillx(node->X(), node->Y()).second;
|
||||||
double bndY1 = _obj.Filly(node->X(), node->Y()).first;
|
double bndY1 = obj.Filly(node->X(), node->Y()).first;
|
||||||
double bndY2 = _obj.Filly(node->X(), node->Y()).second;
|
double bndY2 = obj.Filly(node->X(), node->Y()).second;
|
||||||
int btype = _obj.Who(node->X(), node->Y())->GetB();
|
int btype = obj.Who(node->X(), node->Y())->GetB();
|
||||||
if (node->l()) {
|
if (node->l()) {
|
||||||
if (node->l()->X() != bndX2 && node->l()->X() != bndX1) {
|
if (node->l()->X() != bndX2 && node->l()->X() != bndX1) {
|
||||||
if (bndX1 != bndX2) {
|
if (bndX1 != bndX2) {
|
||||||
@@ -71,8 +71,8 @@ void Mesh::Delnode(int i, int j) {
|
|||||||
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);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Node* left = new Node(bndX2, node->Y(), btype);
|
Node* left = new Node(bndX2, node->Y(), btype);
|
||||||
@@ -81,7 +81,7 @@ 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -101,8 +101,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 +111,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 +120,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 << "| ";
|
||||||
|
|||||||
116
src/Node.cpp
116
src/Node.cpp
@@ -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; }
|
||||||
@@ -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;
|
||||||
}
|
}
|
||||||
@@ -47,7 +47,7 @@ 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);
|
||||||
}
|
}
|
||||||
@@ -56,7 +56,7 @@ std::pair<double, double> Object::Fillx(double x, double y) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|
||||||
|
|||||||
@@ -1,30 +1,30 @@
|
|||||||
#include "System.hpp"
|
#include "System.hpp"
|
||||||
|
|
||||||
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(); }
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user