General Mechanical

General Mechanical

ACT – Getting result time history

Tagged: ,

    • mjmiddle
      Ansys Employee

      An often question with ACT scripting is how to read the result history for result objects in Mechanical.

      A time-intensive method would be to set the Display time on a result object in a loop and evaluate for each substep time point. Since evaluating each result for many results, each at a substep time point, can take a long time, a quicker way to do this would be to duplicate the result for each time point, and set the different Display time in the details. Then evaluation is done once but you get many result objects to loop through to extract the data (min, max, average). Creating many result objects can take time itself, although Outline display update can be turned off under "with Transaction():" block of python code, and this will speed up the object creation.

      In the future, it is intended to have full ACT coverage for result histories, but as of now their are a few result types you can get the history without resorting to the above methods. This can be done for probe objects. Use the "Sequence" found in the "internalObject".

      The InternalObject is only found on Windows systems, not Linux. The ACT object names will be a little different depending on the probe type, but always look for "Sequence" in the name using the python dir(result) command under a result object.

      For example, a joint probe with the "Result Type" set to "Total Force" or "Total Moment":

      probe.InternalObject.SequenceXVector(0)
      probe.InternalObject.SequenceYVector(0)
      probe.InternalObject.SequenceZVector(0)
      probe.InternalObject.SequenceTotalVector(0)
      

      The argument here is an integer and represents the row in the table, beginning at zero for row 1.

      Other than probes, it can be done for a frequency response for harmonic analysis. Example for deformation response:

      a = ExtAPI.DataModel.Project.Model.Analyses[0]
      f = a.Solution.AddDeformationFrequencyResponse()
      selection = ExtAPI.SelectionManager.CreateSelectionInfo(SelectionTypeEnum.GeometryEntities)
      selection.Ids = [27]
      f.Location = selection
      aset = a.Children[1] # Analysis Settings
      if aset.FrequencySpacing == Ansys.ACT.Automation.Mechanical.Enums.FrequencySpacingType.Linear:
         # Other options are Logarithmic, OctaveBand1, OctaveBand2, OctaveBand3, OctaveBand6, OctaveBand12, OctaveBand24
         # Doesn't account for user defined frequencies
         step = (aset.RangeMaximum.Value - aset.RangeMinimum.Value) / float(aset.SolutionIntervals)
         freq = step
         freqs = []
         amp_dict = {}
         phase_dict = {}
         if not f.MinimumFrequency.Value == 0.0:
             freqs.append(f.MinimumFrequency.Value)
             amp_dict[f.MinimumFrequency.Value] = f.InternalObject.GetAmpAtFrequency(f.MinimumFrequency.Value, 0)
             phase_dict[f.MinimumFrequency.Value] = f.InternalObject.GetPhaseAtFrequency(f.MinimumFrequency.Value)
         while (freq < f.MaximumFrequency.Value):
             if freq <= f.MinimumFrequency.Value: continue
             freqs.append(freq)
             amp_dict[freq] = f.InternalObject.GetAmpAtFrequency(freq, 0)
             phase_dict[freq] = f.InternalObject.GetPhaseAtFrequency(freq)
             freq += step
         freqs.append(f.MaximumFrequency.Value)
         amp_dict[f.MaximumFrequency.Value] = f.InternalObject.GetAmpAtFrequency(f.MaximumFrequency.Value, 0)
         phase_dict[f.MaximumFrequency.Value] = f.InternalObject.GetPhaseAtFrequency(f.MaximumFrequency.Value)
      

      ____________________________________________________________

      Beyond probe types and harmonic analysis frequency response, you can always extract values directly from the GUI panel. This means it will not work if the script is meant to be run in batch (no GUI display):

      result.Activate()
      Pane=ExtAPI.UserInterface.GetPane(MechanicalPanelEnum.TabularData)   #This is the "Tabular Data" table at the right
      Con = Pane.ControlUnknown
      # same as Con = ExtAPI.DataModel.InternalObject["ds"].Graphics.CompositeGrid
      # (1,1) is empty grey box at upper left
      for C in range(1,Con.ColumnsCount+1):
         for R in range(1,Con.RowsCount+1):
             Text = Con.cell(R,C).Text 
             if Text!=None:
                 print Text
      # to set a value directly to GUI table:
      cell = Con.cell(R,C)
      Con.TriggerBeforeEdit(cell)
      cell.Text=str("1")   # must convert all values to string
      Con.TriggerAfterEdit(cell)
      

      Setting tabular data values does not normally need to be done through the GUI panel. This is something done for loads, not results. Results should be read-only. In the Ansys help see section:

      https://ansyshelp.ansys.com/account/Secured?returnurl=/Views/Secured/corp/v201/en/act_script/MechAPIsSetDiscreteValues.html

    • Aniket
      Ansys Employee
Viewing 1 reply thread
  • You must be logged in to reply to this topic.