Расчёт абсолютных погрешностей вычислений темератур
This commit is contained in:
60
Error_folder/get_average.py
Normal file
60
Error_folder/get_average.py
Normal 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)
|
||||
Reference in New Issue
Block a user