Get Results from Beam contact elements with PyMAPDL

perepalacin
perepalacin Member Posts: 5
Name Dropper First Comment
**

Greetings!

I am trying to get the stresses for Beam contact elements I have included in my simulation using PyMAPDL but I can't find out how to do so in the docs.

I basically have a set of beams in my model that work as a connection (bolts) between bodies.

I then apply a preload on these beams to simulate the bolt preload:

Finally, using the worksheet I am able to plot the stresses on these "bolts" on Ansys using the following settings:

Nevertheless, I would like to be able to get these same values inside Python through PyMAPDL so that I can iterate through them and perform different post process operations. The problem is that these beams do not seem to have any visible nodes in ansys asigned to them and I don't know how to select them in with PyMAPDL in order to extract the values from them. Does anyone have an idea of how to approach it?

Thanks alot,

Best regards

Tagged:

Answers

  • Mike Rife
    Mike Rife Member, Employee Posts: 51
    Second Anniversary 10 Comments First Answer 5 Likes
    ✭✭✭✭

    Hi @perepalacin
    Each Beam Connection will result in a unique beam element type being defined for the connection. The Material, Type, Real, Section numbers will be the same so you could select by any of these. There is a 'Element APDL Name' in the Definition section of the Beam Connection - this is a name you can use and it is used to create a MAPDL parameter (with the name) that has the value of the beam element ID number. You could set the first and last beam connection of the list and use the two parameters to figure out the bounds of the material/section/etc IDs.
    One thing to watch out for is that the Bolt Pretension results in the FEM, of what the pretension is scoped to, being split in order to model the pretension. So each beam connection in the input file is one element, but during the solution they get split into two elements. The original element number is kept though. But if you select by say material ID then *GET the element count, don't be surprised when it returns 2 instead of 1!.
    Mike

  • perepalacin
    perepalacin Member Posts: 5
    Name Dropper First Comment
    **

    @Mike Rife said:
    Hi @perepalacin
    Each Beam Connection will result in a unique beam element type being defined for the connection. The Material, Type, Real, Section numbers will be the same so you could select by any of these. There is a 'Element APDL Name' in the Definition section of the Beam Connection - this is a name you can use and it is used to create a MAPDL parameter (with the name) that has the value of the beam element ID number. You could set the first and last beam connection of the list and use the two parameters to figure out the bounds of the material/section/etc IDs.
    One thing to watch out for is that the Bolt Pretension results in the FEM, of what the pretension is scoped to, being split in order to model the pretension. So each beam connection in the input file is one element, but during the solution they get split into two elements. The original element number is kept though. But if you select by say material ID then *GET the element count, don't be surprised when it returns 2 instead of 1!.
    Mike

    Greetings @Mike Rife Thanks a lot for your answer!

    Unfortunately I coulnd't manage to fix my issue. I've found the Element ADPL Name property you mentioned but I do not know how I can retrieve this value using PyMAPDL at the moment. Could you please elaborate a bit more?

    By the way, another aproach I considered is giving the bolts a material only used by them (Structural Steel but with another name) in order to select the elements that belong to this material, but again, I can't seem to find the instruction in the docs that will allow me to select nodes or elements based on their material. Any idea about this too?

    Thanks

  • Mike Rife
    Mike Rife Member, Employee Posts: 51
    Second Anniversary 10 Comments First Answer 5 Likes
    ✭✭✭✭

    @perepalacin The "Element APDL Name" will create a MAPDL Parameter, with the name you give it in WB Mechanical, whose value is the element type ID number. So just use the parameter value in PyMAPDL as we would in MAPDL. Here is the PyMAPDL documentation page on parameters.

  • perepalacin
    perepalacin Member Posts: 5
    Name Dropper First Comment
    **

    @Mike Rife Thanks a lot for your answer. Unfortunately, the mapdl.parameters instruction does not return anything regarding the bolts I added to my model. Please find attached the code block and the definition of my bolts. Am I doing something wrong?

    import numpy as np
    import pandas as pd
    import traceback
    from ansys.mapdl.core import launch_mapdl
    
    # Input parameters
    #directory_path = r'C:\Python\Mapdl\ansys_files\resultstest_files\dp0\SYS\MECH'
    directory_path = r'C:\Users\pere.palacin\Desktop\TestAnsys\test_files\dp0\SYS\MECH'
    rst_file_path = directory_path + r'\file.rst'
    ansys_version = 23.1
    number_of_cpu = 2
    mapdl = launch_mapdl(run_location=directory_path, nproc=number_of_cpu, version=ansys_version, override=True)
    print(mapdl)
    
    # Launch MAPDL instance
    # SHOULD BE ABLE TO SEE SOMETHING LIKE THIS:
    # Product:             Ansys Mechanical Enterprise
    # MAPDL Version:       23.1
    # ansys.mapdl Version: 0.68.1
    
    try:
        mapdl.post1()
        mapdl.file(fname=rst_file_path)
        #Select all geometry
        mapdl.allsel()
        principal_stresses = []
        mapdl.set(1, 1)
    
        print(mapdl.parameters)
        print(mapdl.parameters.copy())
        print(mapdl.parameters.keys())
        print(mapdl.parameters.values())
    
        mapdl.clear()
        mapdl.exit()
    
    except Exception:
        mapdl.clear()
        mapdl.exit()
        print(steps)
        traceback.print_exc()
    
    

    And this is the console output:
    Product: Ansys Mechanical Premium
    MAPDL Version: 23.1
    ansys.mapdl Version: 0.68.1

    MAPDL Parameters

    PORT : 50052.0
    {'PORT': {'type': 'SCALAR', 'value': 50052.0}}
    dict_keys(['PORT'])
    dict_values([{'type': 'SCALAR', 'value': 50052.0}])

  • Mike Rife
    Mike Rife Member, Employee Posts: 51
    Second Anniversary 10 Comments First Answer 5 Likes
    ✭✭✭✭

    Hi @perepalacin
    Ah! Sorry, I was mistaken in the work-flow. I thought you were writing a input file from WB Mechanical and reading that in the PyMAPDL script. Parameters are not saved to the MAPDL result file. But they are to the database. In WB Mechanical -> Analysis Settings; Advanced set the 'Save MAPDL db' to Yes. Solve the analysis. Then in the PyMAPDL script you can add something like:

    db_file_path = directory_path + r'\file.db'
    ...
    mapdl.resume(db_file_path)
    

    And the parameters should then be available. Alternatively there is a MAPDL command to save parameters, and their values, to a file; PARSAV. Then PARRES can be used to read in the file. You could add the PARSAV to a WB Mechanical commands object. Then use parres in the PyMAPDL script.

    Mike