Can you provide an example of using the materials module in Mechanical?

Pernelle Marone-Hitz
Pernelle Marone-Hitz Member, Moderator, Employee Posts: 535
100 Answers 250 Likes 100 Comments Ansys Employee
edited June 21 in Structures

Can you provide an example of using the materials module in Mechanical?

Tagged:

Best Answers

  • Pernelle Marone-Hitz
    Pernelle Marone-Hitz Member, Moderator, Employee Posts: 535
    100 Answers 250 Likes 100 Comments Ansys Employee
    Answer ✓

    Material properties defined in Engineering Data can be accessed in Mechanical thanks to the material module:

        # import materials module
        import materials 
        # get to first material in the Mechanical tree
        mat = ExtAPI.DataModel.Project.Model.Materials.Children[0]
        print(mat.Name)
        # get engineering data material properties for this material
        matED = mat.GetEngineeringDataMaterial()
        # get and print list of material properties
        listMatProp = materials.GetListMaterialProperties(matED)
        print(listMatProp)
        # get and print Elasticity properties (if it exists)
        elasticity = materials.GetMaterialPropertyByName(matED,"Elasticity")
        print(elasticity)
    
  • Pernelle Marone-Hitz
    Pernelle Marone-Hitz Member, Moderator, Employee Posts: 535
    100 Answers 250 Likes 100 Comments Ansys Employee
    Answer ✓

    Hi @BenHett ,
    To edit an existing material, I would recommend using the WB recording to find the commandes.
    You can refer to that post: https://discuss.ansys.com/discussion/2281/how-to-create-a-custom-material-in-ansys-workbench-programmatically-by-using-apis-act

    Here's a script example:

    system1 = GetSystem(Name="SYS")
    engineeringData1 = system1.GetContainer(ComponentName="Engineering Data")
    material1 = engineeringData1.GetMaterial(Name="Structural Steel")
    matlProp1 = material1.GetProperty(Name="Elasticity")
    matlProp1.SetData(
        Variables=["Young's Modulus"],
        Values=[["30 [Pa]"]])
    

    If you need to launch the script from Mechanical, you'll just have to embed this into a string and use ScriptByName('journaling').ExecuteCommand(cmd). This post should help: https://discuss.ansys.com/discussion/357/how-to-create-and-assign-material-from-mechanical-using-act

    For the manual copy/paste, I believe there should be a way. Please contact your local support provider, or use the forum in the Ansys Learning Space.

Answers

  • BenHett
    BenHett Member Posts: 2
    First Comment

    This example is great thanks, I had been doing it this way.
    mat=ExtAPI.DataModel.GetObjectsByType(DataModelObjectCategory.Material)[0]
    mats=ExtAPI.DataModel.GetObjectsByType(DataModelObjectCategory.Material)
    matED=mat.InternalObject.EDAMaterial

    **Could you provide an example to edit existing materials? ** This stems from the inability to easily copy and paste **TEMPERATURE DEPENDENT STRENGTH DATA **from the Engineering Data GUI. It is driving me crazy. Sometimes you get material cards that don't have strength and you want to add them. I thought about making a script to edit the XML but that isn't straight forward either. I figured it would be easier to just send a list or 2 into the material in python, but can't seem to find how to do that anywhere. If there is an easy way to do this it would be greatly appreciated!! If I am missing something through the GUI and there is a way to add **TEMPERATURE DEPENDENT STRENGTH DATA ** it would be good too.

  • BenHett
    BenHett Member Posts: 2
    First Comment

    Ok, this got me most of the way there. However, I still am unable to create Temperature dependent strength Data. For CTE and Elastic Properties it defaults to Temperature Dependent. For Strength it defaults to a single value. I think this needs a change in the setup from the development team. I have clicked and clicked around the GUI. I had 2 other people try to do it through the GUI and no one can figure it out. I spent about half a day trying to do it through python and still couldn't do it. Could you please give me an example of adding specifically Temperature Dependent Strength Data via python? Note: I have also tried reading it in from text file, but it doesn't want to recognize temperature as valid variable and I don't know how to add it.

  • Mike Rife
    Mike Rife Member, Employee Posts: 10
    Ansys Employee Name Dropper First Comment Photogenic

    Hi @BenHett The failure theories, as implemented in WB Mechanical, that utilize those specific material models do not have temperature dependency. So having defining a temperature dependent values is not available.

    I've not done this but this seems like a good idea for a Python Result object. The temperature dependent property could be defined in the Details of the Python Result and used in the safety factor calculation. Then the result plotted onto the mesh.

    Mike