Creating a Custom Result on a Contact

On a contact in the Mechanical tree, you can create an ACT result object to access any of the following results: Pressure, Penetration, Gap, Frictional Stress, Sliding Distance, Status, and Fluid Pressure. In the figure, the result Pressure is displayed as a custom result.

 

Creating an Extension for a Custom Result on a Contact

The following XML file adds a toolbar with a single button for creating a custom pressure result for a contact.

<extension version="1" minorversion="" name="ACTResults">
 
   <author>Ansys Inc.</author>
   <description>ACT results</description>
   <guid shortid="ACTResults">23EBAB2B-732D-49E3-91B6-818F8BECF010</guid>
   <script src="main.py" />
   
   <interface context="Mechanical">
     <images>images</images>
     <toolbar name="ACTResults" caption="ACTResults">
       <entry name="ContactResult" icon="contactActRes">
         <callbacks>
           <onclick>CreateContactResult</onclick>
         </callbacks>
       </entry>
     </toolbar>
   </interface>
 
   <simdata context="Mechanical">
     <result name="ContactResult" version="1" caption="ContactResult" icon="result"
             type="scalar" location="elemnode" IsContactResult="true" class="ActResController">
       <property name="Geometry" caption="Geometry" control="scoping"></property>
       <property name="Type" caption="Type" control="select" default="Pressure">
         <attributes options="Pressure,Penetration,Gap,Frictional Stress,Sliding Distance,Status,Fluid Pressure"></attributes>
       </property>
       <callbacks>
         <evaluate>EvaluateContact</evaluate>
       </callbacks>
     </result>
   </simdata>
 
 </extension>

In this file, the element <script> references the IronPython script main.py. The element <interface> defines the toolbar and a button. In the child element <callbacks>, the single callback <onclick> invokes the function EvaluateContact, which creates and adds the result to the simulation environment.

The element <simdata> defines the result.

  • The attributes in the child element <result> provide the name, version, caption, unit, and icon that apply to the result. These properties display in the Details view of Mechanical when the result is selected in the Outline view. The Details view shows each property with the corresponding names and result values.

  • In the child element <callbacks>, the single callback <evaluate> invokes the function EvaluateContact when Mechanical requests an evaluation. The output of this function is sent directly to Mechanical, which displays the result.

Defining Functions for a Custom Result on a Contact

The IronPython script main.py follows. This sample code shows how to create the result object, calculate the result, and set up the result reader. For more information on the result reader, see Retrieving Mechanical Results More Efficiently.

def CreateContactResult(analysis):
    analysis.CreateResultObject("ContactResult")

def EvaluateContact(result, stepInfo, collector):
    result.Controller.EvaluateContact(result, stepInfo, collector)

class ActResController:

    def __init__(self, api, result):
        pass
    
    def EvaluateContact(self, result, stepInfo, collector):
        #get the contact result type
        type_value = result.Properties["Type"].Value
        [contact_type,contact_comp] = self.contactType(type_value)
        
        reader = result.Analysis.GetResultsData()
        
        #set the result collector with the contact elements
        contElemIds = reader.ContactElementIds
        lengths = reader.NumberValuesByElement(contElemIds)
        collector.SetAllIds(contElemIds, lengths)
        
        reader.CurrentResultSet = stepInfo.Set
        contact_result = reader.GetResult(contact_type)
        contact_result.SelectComponents([contact_comp])
        
        values = contact_result.GetElementValues(contElemIds,False)
        collector.SetAllValues(values,lengths)
    
    def contactType(self,argument):
        switcher = {
            "Pressure":["CONT","PRES"],
            "Penetration":["CONT","PENE"],
            "Gap":["CONT","GAP"],
            "Frictional Stress":["CONT","SFRI"],
            "Sliding Distance":["CONT","SLID"],
            "Status":["CONT","STAT"],
            "Fluid Pressure":["CONT","FPRS"],
            }
        return switcher.get(argument, ["CONT","PRES"])