diff --git a/include/Mesh.hpp b/include/Mesh.hpp index b333d65..318c856 100644 --- a/include/Mesh.hpp +++ b/include/Mesh.hpp @@ -20,6 +20,7 @@ public: Mesh(Object&, double); ~Mesh(); //void ShowLinks(); + void VisualizeMesh(std::string); std::vector>& Nodes() { return mesh; } std::vector& LineX() { return hlines; } diff --git a/include/System.hpp b/include/System.hpp index 61d4ef9..278c546 100644 --- a/include/System.hpp +++ b/include/System.hpp @@ -11,6 +11,7 @@ class System{ public: 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>& Nodes(); std::vector& LineX(); std::vector& LineY(); diff --git a/src/Mesh.cpp b/src/Mesh.cpp index ef400a8..d7cca27 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -1,5 +1,6 @@ #include "Mesh.hpp" #include +#include #include Mesh::Mesh(Object& _obj, double _step) : obj(_obj), step(_step) { @@ -14,6 +15,21 @@ Mesh::Mesh(Object& _obj, double _step) : obj(_obj), step(_step) { Adapt(); } +void Mesh::VisualizeMesh(std::string name) { + std::ofstream data_file(name); + + 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"; + } + } + + data_file.close(); +} + void Mesh::LinkX() { for (int i = 0; i < mesh.size(); i++) { mesh[i][0]->LinkX(nullptr, mesh[i][1]); diff --git a/src/System.cpp b/src/System.cpp index 3f05a02..a0fa9b6 100644 --- a/src/System.cpp +++ b/src/System.cpp @@ -1,5 +1,9 @@ #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(); while (cur) { diff --git a/src/main.cpp b/src/main.cpp index 93f5c7f..3aff39c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -73,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); diff --git a/visual_mesh.py b/visual_mesh.py new file mode 100644 index 0000000..15de1a4 --- /dev/null +++ b/visual_mesh.py @@ -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!") \ No newline at end of file