Frequency Response results from an analysis using On-Demand Expansion?
Andreas Rydin
Member, Employee Posts: 2
✭✭✭
Answers
-
Here is a pyDPF script that will generate output files, for each node, the frequence response for each load step. The script assumes that the *rfrq, *mode and *rst files are located in the same folder (which would be the case if you're solving the modal+harmonic in the same system)
from ansys.dpf import core as dpf import os,re import glob # Result Data dpf.start_local_server(ansys_path=r'C:\Program Files\ANSYS Inc\v231') res_path = r'D:\Temp\pyDPF\frf\expansion' res_file = "file.rfrq" resFile_exp = os.path.join(res_path, res_file) ds = dpf.DataSources(resFile_exp) mode_files = glob.glob(res_path + '/*.mode') rst_files = glob.glob(res_path + '/*.rst') data_source_up = dpf.DataSources() for f in mode_files: numbers = re.findall(r'\d+', os.path.basename(f)) data_source_up.set_domain_result_file_path(f, int(numbers[0])) print(int(numbers[0]), f) if len(rst_files) > 0: for f in rst_files: numbers = re.findall(r'\d+', os.path.basename(f)) data_source_up.add_file_path(f, 'rst', True, int(numbers[0])) print(int(numbers[0]), f) ds.add_upstream(data_source_up) my_model = dpf.Model(ds) # Node Scopings n_scoping = dpf.Scoping() n_scoping.ids = [11091,11061] #Time Scoping ls = my_model.metadata.time_freq_support.time_frequencies ls_scoping = ls.scoping.ids timeList = dpf.operators.metadata.time_freq_provider(data_sources=ds).outputs.time_freq_support().time_frequencies.data time_ids = list(range(1, len(timeList) + 1)) #Acceleration outputs acc = dpf.operators.result.acceleration(data_sources=ds,time_scoping=time_ids,mesh_scoping=n_scoping) my_model.metadata.release_streams() for ns in n_scoping.ids: nScoping = dpf.Scoping() nScoping.ids = [ns] acc_rs = dpf.operators.scoping.rescope_fc(fields_container=acc,mesh_scoping=nScoping) acc_amp = dpf.operators.math.amplitude_fc(fields_container=acc_rs) #Get max/min from the acclacement scoping acc_max = dpf.operators.min_max.min_max_fc(fields_container=acc_amp) acc_max_output = acc_amp.outputs.fields_container() acc_Z = acc_max.outputs.field_max().data[:, 0] #Loop through the different load steps cnt = 0 for ls in range(1,len(dpf.operators.metadata.time_freq_provider(data_sources=ds).outputs.time_freq_support().time_frequencies.scoping.ids)+1): freq_ls = dpf.operators.metadata.time_freq_provider(data_sources=ds).outputs.time_freq_support().time_frequencies.get_entity_data_by_id(ls) freq_ls_num = len(freq_ls) lcstring = 'Load Case #'+str(ls) y_value = acc_Z[cnt:cnt+freq_ls_num] freq_value = timeList[cnt:cnt+freq_ls_num] #Print to file fName = 'Acceleration_'+str(ns)+'_step_'+str(ls)+'.txt' with open(fName,'w+') as g: j = 0 while j < len(freq_value): val = str(freq_value[j])+","+str(y_value[j])+"\n" g.write(val) j+=1 cnt = cnt+freq_ls_num
1