How to export Frequency Response Amplitude and Phase from Mechanical?

I have the Frequency response result from Harmonic Analysis and I want to export the Frequency, Amplitude and Phase information from Mechanical.
Answers
-
We can do it using the below script via Python Code with "After Post" callback. This would work both in GUI mode (mechanical open) and also in Batch mode (Mechanical closed). This would work in Windows as well as Linux. Tested in 23R1 - 24R1.
Please feel free to modify the code as needed.
def after_post(this, solution):# Do not edit this line """ Called after post processing. Keyword Arguments : this -- the datamodel object instance of the python code object you are currently editing in the tree solution -- Solution """ # To access properties created using the Property Provider, please use the following command. # this.GetCustomPropertyByPath("your_property_group_name/your_property_name") # To access scoping properties use the following to access geometry scoping and named selection respectively: # this.GetCustomPropertyByPath("your_property_group_name/your_property_name/Geometry Selection") # this.GetCustomPropertyByPath("your_property_group_name/your_property_name/Named Selection") import csv freqRespObj = DataModel.GetObjectsByType(DataModelObjectCategory.DeformationFrequencyResponse)[0] tabData = freqRespObj.TabularData freqData = list(tabData['Frequency']) AmpData = list(tabData['Amplitude']) phaseData = list(tabData['Phase Angle']) csv_file = r"D:\output.csv" data = zip(freqData, AmpData, phaseData) with open(csv_file, 'wb') as file: writer = csv.writer(file) writer.writerow(['Frequency', 'Amplitude', 'Phase Angle']) writer.writerows(data)
1 -
Hi Rohit, could you please help how we can use this script in batch mode? like while solving using a cluster Linux, when UI is not open?
0 -
-
Hello @SK , as I mentioned in my answer, the workflow can be used for both Windows and Linux via Python Code object. This would work in both GUI mode and also batch mode.
0 -
@Rohith Patchigolla
Thanks, but how to replace line --> csv_file = r"D:\output.csv"
this with an drive independent location when we use your cluster/cloud to solve the analysis not the local machine.0 -
Hello @SK , if you are using RSM to send the solve to a cluster, then, the Python Code gets activated once the results are downloaded again locally. So, one could use a local directory.
One could ofcourse use drive independent location, say Solver Directory. You can use the below commands to replace the "csv_file = r"D:\output.csv"" line.
import os solverDir = this.WorkingDir filename = r"output.csv" csv_file = os.path.join(solverDir,filename)
0 -
@Rohith Patchigolla
Thanks, I' not using a RSM, but I'm doing is creating an input file.dat and solving it using inhouse cluster which has HPC. Problem is that, when I use your script is works fine on my local machine when GUI is open but when I create an input file (say file.dat), python code is not executing.0 -
@SK , thanks for explaining your workflow. This python code is based on after post target callback. This target callback is not writing anything to the input file and is purely designed to run after the post processing is done in Mechanical and uses an existing Frequency response result object.
If you are looking to automate this export via input file running in a cluster, I would suggest using APDL commands to do extract the frequency vs amplitude/phase angle information using /post26 commands. Python approach is not applicable here. Perhaps, if you are reading back your results into Mechanical, then python approach will work.
Hope this clarifies.
0 -
@Rohith Patchigolla
Thanks for the clarification, could you please share a sample script to do that using APDL commands or a reference of this if this has been shared in past.0 -
Hello Expert,
I need to export velocity FRF of predefined named selections in a harmonic analysis. I'm creating an input file from GUI and solving it using an inhouse HPC cluster. RST file size is very large that I cant download it to generate a FRF in GUI mode. So need a method by which it will auto create a CSV/txt file for required frequency response plot then I can download only that csv file and no need to download large rst file.
0