3 Commits
master ... fix

12 changed files with 123 additions and 87 deletions

View File

@@ -0,0 +1,44 @@
import re
def parse_temp_file(temp_file):
node_temps = {}
with open(temp_file, 'r') as f:
for line in f:
match = re.match(r'^\s*(\d+)\s+([\d.]+)\s*$', line.strip())
if match:
node = int(match.group(1))
temp = float(match.group(2))
node_temps[node] = temp
return node_temps
def parse_node_file(node_file):
node_coords = {}
with open(node_file, 'r') as f:
for line in f:
match = re.match(r'^\s*(\d+)\s+([-\d.Ee]+)\s+([-\d.Ee]+)\s+([-\d.Ee]+)\s+[-\d.]+', line.strip())
if match:
node = int(match.group(1))
x = float(match.group(2))
y = float(match.group(3))
node_coords[node] = (x, y)
return node_coords
def process_files(temp_file, node_file, output_file):
node_temps = parse_temp_file(temp_file)
node_coords = parse_node_file(node_file)
with open(output_file, 'w') as f:
for node in node_temps:
if node in node_coords:
x, y = node_coords[node]
temp = node_temps[node]
f.write(f"100 {int(x)} {int(y)} {temp}\n")
else:
print(f"Warning: Node {node} not found in coordinate file")
temp_file = "temp_data.txt"
node_file = "node_data.txt"
output_file = "ansys.txt"
process_files(temp_file, node_file, output_file)
print(f"Output written to {output_file}")

View File

@@ -0,0 +1,60 @@
import math
def read_points(filename):
points = []
with open(filename, 'r') as f:
for line in f:
parts = line.strip().split()
if len(parts) == 4:
try:
x = float(parts[1])
y = float(parts[2])
temp = float(parts[3])
points.append((x, y, temp))
except ValueError:
print(f"Warning: Skipping invalid line in {filename}: {line.strip()}")
return points
def euclidean_distance(p1, p2):
return math.sqrt((p2[0] - p1[0])**2 + (p2[1] - p1[1])**2)
def find_closest_points(myprog_points, ansys_points):
differences = []
for myprog_point in myprog_points:
myprog_x, myprog_y, myprog_temp = myprog_point
min_distance = float('inf')
temp_diff = None
closest_point = None
# Find closest point in ansys.txt
for ansys_point in ansys_points:
ansys_x, ansys_y, ansys_temp = ansys_point
distance = euclidean_distance((myprog_x, myprog_y), (ansys_x, ansys_y))
if distance < min_distance:
min_distance = distance
temp_diff = abs(myprog_temp - ansys_temp)
closest_point = ansys_point
if temp_diff is not None:
differences.append(temp_diff)
print(f"Myprog point ({myprog_x}, {myprog_y}, {myprog_temp}) -> Closest Ansys point ({closest_point[0]}, {closest_point[1]}, {closest_point[2]}) -> Temp diff: {temp_diff}")
return differences
def process_files(myprog_file, ansys_file):
myprog_points = read_points(myprog_file)
ansys_points = read_points(ansys_file)
if not myprog_points or not ansys_points:
print("Error: One or both files are empty or contain no valid data.")
return
differences = find_closest_points(myprog_points, ansys_points)
if differences:
avg_difference = sum(differences) / len(differences)
print(f"\nAverage temperature difference: {avg_difference}")
else:
print("No valid matches found between the files.")
myprog_file = "myprog.txt"
ansys_file = "ansys.txt"
process_files(myprog_file, ansys_file)

View File

@@ -0,0 +1,4 @@
file = open('../implicit10.txt').readlines()
lines = [line for line in file if line.startswith('100')]
open('myprog.txt', 'w').write(''.join(lines))

View File

@@ -14,7 +14,6 @@ protected:
public:
Form();
virtual double Function(double, double);
virtual std::pair<double, double> Second_Deriative(double, double);
virtual bool Inhere(double, double);
virtual std::pair<double, double> missX(double);
virtual std::pair<double, double> missY(double);

View File

@@ -1,9 +1,11 @@
#ifndef MIMAPR_MESH_H
#define MIMAPR_MESH_H
#include <vector>
#include "Object.hpp"
#include "Node.hpp"
#include <vector>
#include <iostream>
#include <fstream>
class Mesh{
std::vector<std::vector<Node*>> mesh;

View File

@@ -1,6 +1,8 @@
#ifndef MIMAPR_NODE_H
#define MIMAPR_NODE_H
#define T_START 0.
#include <cmath>
class Node{
@@ -14,7 +16,7 @@ class Node{
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), bellow(nullptr), btype(_type) {}
Node(double _x = 0., double _y = 0., int _type = 0., double _t = T_START): x(_x), y(_y), t(_t), left(nullptr), right(nullptr), above(nullptr), bellow(nullptr), btype(_type) {}
double T() const;
double X() const;

View File

@@ -15,7 +15,6 @@ private:
public:
Rectangle(double, double, double, double, bool, int);
double Function(double, double) override;
std::pair<double, double> Second_Deriative(double, double) override;
bool Inhere(double, double) override;
std::pair<double, double> missX(double) override;
std::pair<double, double> missY(double) override;
@@ -30,7 +29,6 @@ private:
public:
Circle(double, double, double, double, bool, int);
double Function(double, double) override;
std::pair<double, double> Second_Deriative(double, double) override;
bool Inhere(double, double) override;
std::pair<double, double> missX(double) override;
std::pair<double, double> missY(double) override;
@@ -46,7 +44,6 @@ private:
public:
Arc(double, double, double, double, bool, int);
double Function(double, double) override;
std::pair<double, double> Second_Deriative(double, double) override;
std::pair<double, double> missX(double) override;
std::pair<double, double> missY(double) override;
std::pair<double, double> size() override;

View File

@@ -6,10 +6,6 @@ double Form::Function(double, double) {
return 0;
}
std::pair<double, double> Form::Second_Deriative(double, double) {
return { 0, 0 };
}
std::pair<double, double> Form::size() {
return { 0, 0 };
}
@@ -37,7 +33,3 @@ bool Form::Excluded() const {
}
int Form::GetB() { return bound_type; }
//bool Form::operator==(size_t id) const {
// return id_ == id;
//}

View File

@@ -1,8 +1,4 @@
#include "Mesh.hpp"
#include <iostream>
#include <fstream>
#include <Object.hpp>
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*>());
@@ -148,33 +144,3 @@ Mesh::~Mesh() {
for (auto node : line)
delete node;
}
//void Mesh::ShowLinks() {
// for (auto line : mesh) {
// for (auto node : line) {
// if (node->d())
// std::cout << "| ";
// }
// std::cout << '\n';
// for (auto node : line) {
// if (node->l()) {
// std::cout << '-';
// }
// std::cout << 'N';
// if (node->r()) {
// std::cout << '-';
// }
// else {
// std::cout << '\n';
// }
// }
// for (auto node : line) {
// if (node->u())
// std::cout << "|";
// std::cout << " ";
//
// }
// std::cout << '\n';
// }
//}

View File

@@ -72,15 +72,6 @@ double Object::Height() const {
return h;
}
//std::vector<size_t> Object::Get_IDs() {
// std::vector<size_t> ids;
// 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) {
if (form->Inhere(x, y)) {

View File

@@ -20,10 +20,6 @@ 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 - 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;
}
@@ -44,10 +40,6 @@ 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 - x), 2 * h_y * (_y - y) };
}
std::pair<double, double> Circle::size() {
return { 1 / h_x, 1 / h_y };
}
@@ -75,19 +67,6 @@ double Arc::Function(double _x, double _y) {
return -1.0;
}
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 < x) {
//std::cout << "_x < a\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 };
}

View File

@@ -17,7 +17,7 @@
//#define HOLE_Y 255.
//#define HOLE_RADIUS 50.
#define CONDUCTIVITY 50. // Теплопроводность материала
#define CONDUCTIVITY 100. // Теплопроводность материала
void visualize(std::ofstream& file, std::string filename, int time_end) {
file << "set cbrange [" << 0 << ":" << 100 << "]" << std::endl;
@@ -32,15 +32,15 @@ int main()
{
/* Граничные условия:
1 - нагрев
2 - теплоизоляция
3 - конвекция
4 - отсутствует
2 - конвекция
3 - теплоизоляция
0 - отсутствует
*/
int left = 1;
int top = 3;
int top = 2;
int right = 1;
int bottom = 3;
int arc_bound = 3;
int bottom = 2;
int arc_bound = 2;
int hole_bound = 1;
double step_5 = 5;