-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstructural_analysis_extraction.py
31 lines (23 loc) · 1.41 KB
/
structural_analysis_extraction.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from ansys.mapdl import reader as pymapdl_reader
class StructuralAnalysisExtractor:
def __init__(self, file_path, node_number, load_step, sub_step):
self.file_path = file_path
self.node_number = node_number
self.load_step = load_step
self.sub_step = sub_step
def extract_data(self):
result = pymapdl_reader.read_binary(self.file_path)
# Get the nodal stress data (which is a tuple)
stress_data_tuple = result.nodal_stress(self.load_step - 1, self.sub_step - 1)
# The first element contains the node numbers associated with the stress data
stress_node_numbers = stress_data_tuple[0]
# The second element contains the actual stress values
stress_data = stress_data_tuple[1]
print(f"Available node numbers: {stress_node_numbers}") # Debug print
# Check if the specified node number is in the stress data
if self.node_number not in stress_node_numbers:
raise RuntimeError(f"Node number {self.node_number} not found in the stress data.")
# Find the index of the node number in the stress data
stress_node_index = list(stress_node_numbers).index(self.node_number)
# Return the stress value for the specified node
return stress_data[stress_node_index, 0] # Assuming you want the first stress component