How can we using act mech. scripting print the average pressure on a fsi surface?
Erik Kostson
Member, Moderator, Employee Posts: 287
✭✭✭✭
Say we have a vibro-acoustic models and a FSI surface - named selection called watersteelinter_so_fsi. How can we print the average pressure there for each frequency ?
0
Best Answer
-
Below is one possible way of doing this :
analysis = Model.Analyses[0] solution=analysis.Solution ns = DataModel.GetObjectsByName('watersteelinter_so_fsi')[0] mypresres=ExtAPI.DataModel.Project.Model.Analyses[0].Solution.AddAcousticPressureResult() # insert Pressure result mypresres.Location=ns mypresresname=mypresres.Name resallset=solution.CreateResultsAtAllSets(mypresres.ObjectId) fpath = "D:/" fname = "myaverpres.txt" f = open(fpath+fname,"w") for set in resallset: #print(set.Name + 'mean pres. : ' + str(set.Average) + ', at freq. : ' + str(set.ReportedFrequency)) #write to file as needed f.write(str(set.Name) + 'mean pres. : ' + str(set.Average) + ', at freq. : ' + str(set.ReportedFrequency) +"\n") f.close() #mypresres.Delete() #pd= DataModel.GetObjectsByName(mypresresname)[0] #pd.DeleteTreeGroupAndChildren()
and as a Python code (under solution) with an after solve callback:
def after_solve(this, analysis):# Do not edit this line """ Called after solving the parent analysis. Keyword Arguments : this -- the datamodel object instance of the python code object you are currently editing in the tree analysis -- Coupled Field Harmonic """ # 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") solution=analysis.Solution ns = DataModel.GetObjectsByName('watersteelinter_so_fsi')[0] mypresres=ExtAPI.DataModel.Project.Model.Analyses[0].Solution.AddAcousticPressureResult() # insert Pressure result mypresres.Location=ns mypresresname=mypresres.Name mypresres.EvaluateAllResults() resallset=solution.CreateResultsAtAllSets(mypresres.ObjectId) mypresres.Delete() fpath = "D:/" fname = "myaverpres.txt" f = open(fpath+fname,"w") for set in resallset: #print(set.Name + 'mean pres. : ' + str(set.Average) + ', at freq. : ' + str(set.ReportedFrequency)) #write to file as needed set.EvaluateAllResults() f.write(str(set.Name) + ', mean pres. : ' + str(set.Average) + ', at freq. : ' + str(set.ReportedFrequency) +"\n") set.Delete() f.close() pd= DataModel.GetObjectsByName(mypresresname)[0] pd.DeleteTreeGroupAndChildren() pass
0