Change encoding

This commit is contained in:
2025-05-14 14:21:16 +03:00
parent 832a2dbeb2
commit 8100f0d4e1
2 changed files with 37 additions and 31 deletions

View File

@@ -1,13 +1,15 @@
#include "Solver.hpp" #include "Solver.hpp"
void Solver::SolveExplicit(System& program, double tstop) const { void Solver::SolveExplicit(System& program, double tstop) const {
std::ofstream ExplicitOut(_name_1); std::ofstream ExplicitOut(_name_1);
//ExplicitOut << "t x y T" << std::endl;
for (double t = 0.0; t < tstop; t += delta) { for (double t = 0.0; t < tstop; t += delta) {
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD> X */ /* Обработка узлов по оси X */
for (int i = 1; i < program.LineX().size() - 1; i++) { for (int i = 1; i < program.LineX().size() - 1; i++) {
std::vector<Node*> temperature; std::vector<Node*> temperature;
Node* cur = program.LineX()[i]; Node* cur = program.LineX()[i];
while (cur) { while (cur) {
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> */ /* Проверка на существование узла */
if (cur->r() && cur->r()->X() - cur->X() > program.step()) { if (cur->r() && cur->r()->X() - cur->X() > program.step()) {
temperature.push_back(cur); temperature.push_back(cur);
SolveLine(program, temperature); SolveLine(program, temperature);
@@ -21,12 +23,12 @@ void Solver::SolveExplicit(System& program, double tstop) const {
} }
SolveLine(program, temperature); SolveLine(program, temperature);
} }
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD> Y */ /* Обработка узлов по оси Y */
for (int i = 1; i < program.LineY().size() - 1; i++) { for (int i = 1; i < program.LineY().size() - 1; i++) {
std::vector<Node*> temperature; std::vector<Node*> temperature;
Node* cur = program.LineY()[i]; Node* cur = program.LineY()[i];
while (cur) { while (cur) {
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> */ /* Проверка на существование узла */
if (cur->u() && cur->u()->Y() - cur->Y() > program.step()) { if (cur->u() && cur->u()->Y() - cur->Y() > program.step()) {
temperature.push_back(cur); temperature.push_back(cur);
SolveLine(program, temperature); SolveLine(program, temperature);
@@ -42,7 +44,7 @@ void Solver::SolveExplicit(System& program, double tstop) const {
} }
for (auto line : program.Nodes()) { for (auto line : program.Nodes()) {
for (auto node : line) for (auto node : line)
ExplicitOut << node->X() << ' ' << node->Y() << ' ' << node->T() << '\n'; ExplicitOut << t+1 << ' ' << node->X() << ' ' << node->Y() << ' ' << node->T() << '\n';
} }
ExplicitOut << "\n\n"; ExplicitOut << "\n\n";
} }
@@ -50,15 +52,17 @@ void Solver::SolveExplicit(System& program, double tstop) const {
void Solver::SolveImplicit(System& sys, double tstop) const { void Solver::SolveImplicit(System& sys, double tstop) const {
std::ofstream EmplicitOut(_name_2); std::ofstream EmplicitOut(_name_2);
//EmplicitOut << "t x y T" << std::endl;
for (double t = 0.; t < tstop; t += delta) { for (double t = 0.; t < tstop; t += delta) {
for (auto line : sys.Nodes()) for (auto line : sys.Nodes())
for (auto node : line) { for (auto node : line) {
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> */ /* Проверка на внутренний узел */
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
(<EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> a = 1) */ (для удобства коээфициент 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);
@@ -68,7 +72,7 @@ void Solver::SolveImplicit(System& sys, double tstop) const {
} }
for (auto line : sys.Nodes()) { for (auto line : sys.Nodes()) {
for (auto node : line) for (auto node : line)
EmplicitOut << node->X() << ' ' << node->Y() << ' ' << node->T() << '\n'; EmplicitOut << t + 1 << ' ' << node->X() << ' ' << node->Y() << ' ' << node->T() << '\n';
} }
EmplicitOut << "\n\n"; EmplicitOut << "\n\n";
} }
@@ -78,7 +82,7 @@ void Solver::SolveLine(System& sys, std::vector<Node*>& n) const {
int size = n.size() - 2; int size = n.size() - 2;
double mu1 = n.front()->Dist(n[1]) / sys.step(); double mu1 = n.front()->Dist(n[1]) / sys.step();
double mu2 = n.back()->Dist(n[n.size() - 2]) / sys.step(); double mu2 = n.back()->Dist(n[n.size() - 2]) / sys.step();
/* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD> */ /* Защита от нуля */
if (mu2 == 0.) if (mu2 == 0.)
mu2 = .1; mu2 = .1;
double val2 = -(2 * sys.a1()) / (pow(sys.step(), 2)) - 1 / delta; double val2 = -(2 * sys.a1()) / (pow(sys.step(), 2)) - 1 / delta;

View File

@@ -15,32 +15,34 @@
#define HOLE_Y 155. #define HOLE_Y 155.
#define HOLE_RADIUS 50. #define HOLE_RADIUS 50.
#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;
file << "set size ratio " << float(400) / 500 << "\nunset key\n" << "\nset 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)\n" << std::endl; file << "set size ratio " << float(400) / 500 << "\nunset key\n" << "\nset 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)\n" << std::endl;
file << "do for [i=0:" << time_end - 1 << "]{" << std::endl; file << "do for [i=0:" << time_end - 1 << "]{" << std::endl;
file << "plot '" << filename << "' u 1:2:3 index i w points pt 5 palette" << std::endl; file << "plot '" << filename << "' u 2:3:4 index i w points pt 5 palette" << std::endl;
file << "pause " << 0.000000001 << "}" << std::endl; file << "pause " << 0.000000001 << "}" << std::endl;
file << "pause mouse"; file << "pause mouse";
} }
int main() int main()
{ {
int l = 3; //Bound conditions /* Граничные условия:
int t = 3; 1 - нагрев*/
int l = 3;
int t = 1;
int r = 1; int r = 1;
int b = 3; int b = 4;
int r2 = 4; int r2 = 4;
int s = 3; int s = 4;
double step = 10; // Mesh step double step = 10;
double step2 = 5; // Mesh step double step2 = 5;
double time_step = 1; double time_step = 1;
double time_end = 100; double time_end = 100;
double C = 50.; // Material props
std::map<std::string, double> plate{ std::map<std::string, double> plate{
{"a", WIDTH / 2}, {"b", HEIGHT / 2}, {"h_x", 1 / WIDTH}, {"h_y", 1 / HEIGHT} {"a", WIDTH / 2}, {"b", HEIGHT / 2}, {"h_x", 1 / WIDTH}, {"h_y", 1 / HEIGHT}
}; };
@@ -56,26 +58,26 @@ int main()
obj.Add_Form("Arc", arc, true, r2); obj.Add_Form("Arc", arc, true, r2);
obj.Add_Form("Rectangle", plate, false, 1); obj.Add_Form("Rectangle", plate, false, 1);
System explicit10(obj, step, C); System explicit5(obj, step2, CONDUCTIVITY);
System explicit10(obj, step, CONDUCTIVITY);
System implicit5(obj, step2, CONDUCTIVITY);
System implicit10(obj, step, CONDUCTIVITY);
explicit5.DefineBounds(l, t, r, b);
explicit10.DefineBounds(l, t, r, b); explicit10.DefineBounds(l, t, r, b);
System explicit5(obj, step2, C); implicit5.DefineBounds(l, t, r, b);
explicit5.DefineBounds(l, t, r, b);
System implicit10(obj, step, C);
implicit10.DefineBounds(l, t, r, b); implicit10.DefineBounds(l, t, r, b);
System implicit5(obj, step2, C);
implicit5.DefineBounds(l, t, r, b);
Solver slv10("explicit10.txt", "implicit10.txt", time_step);
slv10.SolveExplicit(explicit10, time_end);
slv10.SolveImplicit(implicit10, time_end);
Solver slv5("explicit5.txt", "implicit5.txt", time_step); Solver slv5("explicit5.txt", "implicit5.txt", time_step);
Solver slv10("explicit10.txt", "implicit10.txt", time_step);
slv5.SolveExplicit(explicit5, time_end); slv5.SolveExplicit(explicit5, time_end);
slv5.SolveImplicit(implicit5, time_end); slv5.SolveImplicit(implicit5, time_end);
slv10.SolveExplicit(explicit10, time_end);
slv10.SolveImplicit(implicit10, time_end);
std::ofstream script("es10.plt"); std::ofstream script("es10.plt");
visualize(script, "explicit10.txt", time_end); visualize(script, "explicit10.txt", time_end);
script.close(); script.close();