-
|
pymapdl is used to handle data at postprocess stage. the purpose of my script is to get the max stress at different element sets in all the loadsteps. the code is below. the problem is , i have many loadsteps and many element sets. with the script going, the memory used by ANSYS increase rapidly, the memory used by python script increase slightly. when the memory used by ANSYS reach to 15000MB, ansys died and python become unresponsive. stress_out_dic = {}
for timei in range(1, numstep + 1): # take loadstep as iterator. here,numstep is 17. if set it to 12, this script will run normally.
print(f'工况{timei}/{numstep}')
mapdl.allsel()
mapdl.set(time=timei)
for u in tqdm.tqdm(fdm): # take element set(ansys compnent) as iterator.
jdnm = u['节点']
mapdl.cmsel('s','el_jd_' + jdnm)
mapdl.nsle()
jdstress = stress_out_dic.get(jdnm)
if jdstress is None:
numnd = mc.selednum('node')
stress_out_dic[jdnm] = {
's1max': np.zeros(numnd),
's3min': np.zeros(numnd),
'seqvmax': np.zeros(numnd),
'max_step': 0,
}
jdstress = stress_out_dic[jdnm]
# ANSYS died at the these 3 lines below.
s1 = mapdl.post_processing.nodal_principal_stress('1')
s3 = mapdl.post_processing.nodal_principal_stress('3')
seqv = mapdl.post_processing.nodal_eqv_stress()
# 比较取不利
if np.max(seqv)> np.max(jdstress['seqvmax']):
jdstress['max_step']=timei
jdstress['s1max'] = np.maximum(jdstress['s1max'], s1)
jdstress['s3min'] = np.minimum(jdstress['s3min'], s3)
jdstress['seqvmax'] = np.maximum(jdstress['seqvmax'], seqv) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
I think that's not a Python leak, the growth is in the ANSYS process. nodal_principal_stress() / nodal_eqv_stress() both pull a full-model array every call and only mask down to your selection afterward in Python, so cmsel/nsle don't reduce what ANSYS computes. You're re-fetching the whole model once per element set instead of once per load step. I suggest pulling the three arrays once per load step, then slicing per element set locally (also swapped mc.selednum('node') for len(sel_nodes) since I couldn't find that as a pymapdl API): node_numbers_all = mapdl.mesh.nnum_all
node_to_idx = {n: i for i, n in enumerate(node_numbers_all)}
stress_out_dic = {}
for timei in range(1, numstep + 1):
print(f'工况{timei}/{numstep}')
mapdl.allsel()
mapdl.set(time=timei)
s1_all = mapdl.post_processing.nodal_principal_stress('1')
s3_all = mapdl.post_processing.nodal_principal_stress('3')
seqv_all = mapdl.post_processing.nodal_eqv_stress()
for u in tqdm.tqdm(fdm):
jdnm = u['节点']
mapdl.cmsel('s', 'el_jd_' + jdnm)
mapdl.nsle()
sel_nodes = mapdl.mesh.nnum
idx = np.array([node_to_idx[n] for n in sel_nodes])
s1, s3, seqv = s1_all[idx], s3_all[idx], seqv_all[idx]
jdstress = stress_out_dic.get(jdnm)
if jdstress is None:
numnd = len(sel_nodes)
stress_out_dic[jdnm] = {
's1max': np.zeros(numnd), 's3min': np.zeros(numnd),
'seqvmax': np.zeros(numnd), 'max_step': 0,
}
jdstress = stress_out_dic[jdnm]
if np.max(seqv) > np.max(jdstress['seqvmax']):
jdstress['max_step'] = timei
jdstress['s1max'] = np.maximum(jdstress['s1max'], s1)
jdstress['s3min'] = np.minimum(jdstress['s3min'], s3)
jdstress['seqvmax'] = np.maximum(jdstress['seqvmax'], seqv)If it still grows, mapdl.result (reads the .rst file directly, DPF/reader-based) avoids touching the live session at all. Hope it helps! |
Beta Was this translation helpful? Give feedback.
I think that's not a Python leak, the growth is in the ANSYS process. nodal_principal_stress() / nodal_eqv_stress() both pull a full-model array every call and only mask down to your selection afterward in Python, so cmsel/nsle don't reduce what ANSYS computes. You're re-fetching the whole model once per element set instead of once per load step.
I suggest pulling the three arrays once per load step, then slicing per element set locally (also swapped mc.selednum('node') for len(sel_nodes) since I couldn't find that as a pymapdl API):