using python library ansys.mapdl adn ansys.mapdl.reader extract equivalent stress
I used the following code to extract the equivalent stress and displacement. Currently, the displacement can correspond to the workbench data, but the equivalent stress is not. May I ask if there is a problem with my extraction code? The stress code is as follows:
from ansys.mapdl import reader as pymapdl_reader from ansys.mapdl.reader import rst import numpy as np import json import argparse def extract_stress(self: rst.Result, rsets=None): if rsets is None: rsets = range(self.nsets) elif isinstance(rsets, int): rsets = [rsets] elif not isinstance(rsets, rst.Iterable): raise TypeError("rsets must be an iterable like [0, 1, 2] or range(3)") stress_data = {} for i in rsets: max_sigma1 = max_sigma2 = max_sigma3 = max_sint = max_seqv = float('-inf') enum, element_stresses, enode = self.element_stress(i, principal=True) if element_stresses is None or not any(np.isfinite(stress).any() for stress in element_stresses): print(f"No valid stress data available for result set {i}.") continue for stress_array in element_stresses: if np.isnan(stress_array).all(): continue max_sigma1 = max(max_sigma1, np.max(stress_array[:, 0])) max_sigma2 = max(max_sigma2, np.max(stress_array[:, 1])) max_sigma3 = max(max_sigma3, np.max(stress_array[:, 2])) max_sint = max(max_sint, np.max(stress_array[:, 3])) max_seqv = max(max_seqv, np.max(stress_array[:, 4])) # 存储到字典 stress_data[i] = { "max_sigma1": max_sigma1, "max_sigma2": max_sigma2, "max_sigma3": max_sigma3, "max_sint": max_sint, "max_seqv": max_seqv } # export stress picture for comp in ["X", "Y", "Z", "XY", "XZ", "YZ"]: self.plot_nodal_stress( i, comp=comp, screenshot='stress_{}_{}.png'.format(i, comp), show_displacement=True, window_size=[800, 600], interactive=False ) # export json with open('stress.json', 'w') as json_file: json.dump(stress_data, json_file, indent=4) return if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument("--input", required=True, help="Ansys result file path.") args = parser.parse_args() result = pymapdl_reader.read_binary(args.input) extract_stress(result)
According to the element_stress interface description, to extract VON: von Mises requires principal=True, and then SIGMA1, SIGMA2, SIGMA3, SINT, SEQV will be returned. I now use the above code to get the maximum stress, but the value obtained is inconsistent with the maximum stress obtained by Ansys Workbench. , where is the problem? Looking forward to reply.
Comments
-
This is the same reason I mentioned earlier. I would recommend using https://dpf.docs.pyansys.com/version/0.12/api/ansys.dpf.core.operators.result.stress_eqv_as_mechanical.html#stress-eqv-as-mechanical in dpf. If you want to use mapdl reader, them let me know, I will find a way to average and get similar stress as mechanical
0