How can I make the average transmission loss a parameter?
Erik Kostson
Member, Moderator, Employee Posts: 275
✭✭✭✭
How can I make the average transmission loss a parameter in a harmonic acoustic analysis?
1
Best Answer
-
The average is not available to be made parameter, only min and max is. It is still possible to do this though.
Below is one way of doing that (using python code). It assumes that we have a harmonic acoustic analysis with a results object called Transmission Loss. Due to a limitation in reading in these results, it needs to save the result to file, read the content of the file, and calculate what is needed (average in this case), and make that value a parameter.
Script:
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 """ import csv myfile='D:\mtl.txt' # 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") ExtAPI.Log.WriteMessage('Start') tl = DataModel.GetObjectsByName("Transmission Loss")[0] tl.Activate() tl.ExportToTextFile(myfile) avtl=0 tot=0 nr=0 with open(myfile, 'rb') as f: data = csv.reader(f,delimiter='\t') next(data) for row in data: nr=nr+1 tot=tot+(float(row[1])) avtl=tot/nr #ExtAPI.Log.WriteMessage(str(avtl)) this.GetCustomPropertyByPath("My Results/mytl").Value=avtl
Property provide:
def reload_props(): this.PropertyProvider = None # comment the following return to allow the rest of the function definition to be executed and add properties #return """ Some sample code is provided below that shows how to: 1. Create an instance of the Provider. The Provider class is used to add custom properties to the details. 2. Use the Provider instance to add custom properties. 3. Configure those custom properties. """ # Create the property instance provider = Provider() # Create a group named Group 1. group = provider.AddGroup("My Results") # Create a property with control type Expression and a property with control type Double, and add it to the Group 1 double_prop = group.AddProperty("mytl", Control.Double) #expression_prop = group.AddProperty("Expression Property 1", Control.Expression) # Expression is a string # Configure the double property to be parameterizable. As a default the property will be an input parameter. # However, by updating the ParameterType property, it can be configured to be a output parameter as well. double_prop.CanParameterize = True double_prop.ParameterType = ParameterType.Output this.PropertyProvider = provider # region Property Provider Template from Ansys.ACT.Mechanical.AdditionalProperties import PropertyProviderAdapter from Ansys.ACT.Mechanical.AdditionalProperties import * """ The property_templates module is located in %awp_root212%\aisol\DesignSpace\DSPages\Python\mech_templates """ from mech_templates import property_templates property_templates.set_ext_api(ExtAPI)
1
This discussion has been closed.