Read Results at the Specific Locations

Gordon1998
Gordon1998 Member Posts: 12
Name Dropper First Comment
**

Hi, there.

I am currently developing an ANSYS ACT automation tool to output deformations at specific locations. Note that these locations are different from the mesh nodes. The desired locations are described in XYZ coordinates via either a txt file or in-memory arrays (whichever is available in ANSYS).

Some say that I can load these coordinates as a name selection and set the scoping method to the name selection so that the solver can solve for the deformation of these specific locations. Or I can use the dpf module to map the deformation onto the given locations. I would appreciate it if anyone could shed light on the problem. Thanks ahead!

Answers

  • Rajesh Meena
    Rajesh Meena Moderator, Employee Posts: 125
    100 Comments Second Anniversary 5 Answers Solution Developer Community of Practice Member
    ✭✭✭✭

    @Gordon1998

    The DPF way is easier here:

    Refer to this example:

    https://dpf.docs.pyansys.com/version/stable/examples/06-plotting/04-plot_on_path.html#sphx-glr-examples-06-plotting-04-plot-on-path-py

    You can use the above example as reference and write a script either in PyDPF or mechanical DPF ( Since you are working on ACT).

  • Gordon1998
    Gordon1998 Member Posts: 12
    Name Dropper First Comment
    **

    Rajesh, thanks for your reply.

    I followed the steps in the example and applied them to my test project. My test project only has one object (sleeve) and I would like to get the Z_displacement at the target coordinates. The target coordinates are given from the txt file. However, I have problems retrieving the Z_displacement at the target coordinates: the mapped displacements have 0 fields. Would you please point out the mistakes I have in my codes? (Please change the path of the text file and solve for the model again). The text file, geometry, and model are provided in the attachment. Note that I test my codes in the 'Scripting' and use ANSYS 2024R2. The codes are shown below:

    import os
    import mech_dpf 
    import Ans.DataProcessing as dpf
    
    # Load the Model===========================================================
    analysis=ExtAPI.DataModel.Project.Model.Analyses[0]
    Data_source = dpf.DataSources(analysis.ResultFileName)
    
    # Read the Target Coordinates==============================================
    # Specify the Path of the Result File--------------------------------------
    Path_script = os.path.join(os.getenv('TEMP'), "Target_Coordinates.txt")
    
    # Initialize the Data List-------------------------------------------------
    Target_Coordinates = []
    
    # Read the File------------------------------------------------------------
    with open(Path_script, 'r') as file:
        # Read Each Line in the File===========================================
        for line in file:
            # Split the Line into Two Parts based on the Comma Delimiter=======
            parts = line.split(',')
    
            # Convert the parts to float and append as a list to the data list=
            Target_Coordinates.append([float(parts[0]), 
                                       float(parts[1]),
                                       float(parts[2])])
    
    Length = len(Target_Coordinates)
    Target_field = dpf.FieldsFactory.Create3DVectorField(Length)
    [Target_field.Add(i, Target_Coordinates[i - 1]) for i in range(1, Length + 1)]
    # Result_field = Target_field.Data
    
    # Load the Displacement in the Axial Direction============================
    Axial_displacement = dpf.operators.result.displacement_Z(
                                                   data_sources = Data_source)
    Axial_displacement_fc = Axial_displacement.outputs.fields_container. \
                                                                     GetData()
    
    # Map the Displacement to the Target Coordinates==========================
    Mapped_displacement_fc = dpf.operators.mapping.on_coordinates(
                                      fields_container = Axial_displacement_fc, 
                                      coordinates = Target_field)
    Mapped_displacement = Mapped_displacement_fc.outputs.fields_container. \
                                                              GetData()[0].Data
    
  • Rajesh Meena
    Rajesh Meena Moderator, Employee Posts: 125
    100 Comments Second Anniversary 5 Answers Solution Developer Community of Practice Member
    ✭✭✭✭

    @Gordon1998 Sorry. wbpj file does not have all the information. Please archive the project and share wbpz.

  • Gordon1998
    Gordon1998 Member Posts: 12
    Name Dropper First Comment
    **

    @Rajesh Meena, thanks for your reminder. Please find the wbpz file attached.

  • Gordon1998
    Gordon1998 Member Posts: 12
    Name Dropper First Comment
    **

    Hi, @Rajesh Meena.

    My latest finding is that this problem only occurs in mapping the displacement results (displacement_X, displacement_Y, displacement_Z, displacement). However, the mapping operation can be performed properly in interpolating strain and stress results by simply replacing codes of

    dpf.operators.result.displacement_Z(data_sources = Data_source)

    to

    dpf.operators.result.stress_von_mises(data_sources = Data_source)

    or

    dpf.operators.result.strain_eqv_as_mechanical(data_sources = Data_source).

    I would appreciate it if you could provide some insights.

  • Rajesh Meena
    Rajesh Meena Moderator, Employee Posts: 125
    100 Comments Second Anniversary 5 Answers Solution Developer Community of Practice Member
    ✭✭✭✭
    edited January 3

    @Gordon1998

    The source field container should have MeshedRegionSupport.

    You can connect mesh in the displacement_Z operator and it should work. Here is a bit of updated code.

    import os
    import mech_dpf 
    import Ans.DataProcessing as dpf
    
    # Load the Model===========================================================
    analysis=ExtAPI.DataModel.Project.Model.Analyses[0]
    Data_source = dpf.DataSources(analysis.ResultFileName)
    model = dpf.Model(Data_source)
    # Read the Target Coordinates==============================================
    # Specify the Path of the Result File--------------------------------------
    Path_script = r"D:\down\Target_Coordinates.txt"
    
    # Initialize the Data List-------------------------------------------------
    Target_Coordinates = []
    
    # Read the File------------------------------------------------------------
    with open(Path_script, 'r') as file:
        # Read Each Line in the File===========================================
        for line in file:
            # Split the Line into Two Parts based on the Comma Delimiter=======
            parts = line.split(',')
    
            # Convert the parts to float and append as a list to the data list=
            Target_Coordinates.append([float(parts[0]), 
                                       float(parts[1]),
                                       float(parts[2])])
    
    Length = len(Target_Coordinates)
    Target_field = dpf.FieldsFactory.Create3DVectorField(Length)
    for i in range(1, Length + 1):
        Target_field.Add(i, Target_Coordinates[i - 1])
    # Result_field = Target_field.Data
    
    # Load the Displacement in the Axial Direction============================
    Axial_displacement = dpf.operators.result.displacement_Z(
                                                   data_sources = Data_source)
    Axial_displacement.inputs.mesh.Connect(model.Mesh)
    Axial_displacement_fc = Axial_displacement.outputs.fields_container. \
                                                                     GetData()
    
    #Axial_displacement_fc[0].MeshedRegionSupport = model.Mesh
    # Map the Displacement to the Target Coordinates==========================
    Mapped_displacement_fc = dpf.operators.mapping.on_coordinates(fields_container = Axial_displacement_fc, 
                                      coordinates = Target_field)
    Mapped_displacement = Mapped_displacement_fc.outputs.fields_container.GetData()[0].Data
    
  • Rajesh Meena
    Rajesh Meena Moderator, Employee Posts: 125
    100 Comments Second Anniversary 5 Answers Solution Developer Community of Practice Member
    ✭✭✭✭

    Also, make sure that you are coordinates are in the same unit as solver.

  • Gordon1998
    Gordon1998 Member Posts: 12
    Name Dropper First Comment
    **

    Hi, Rajesh. Thank you so much. Your codes give the correct results.

    I have also found that the format of codes matters. For example, if I build up the result field container as:

    Axial_displacement = dpf.operators.result.displacement_Z()
    Axial_displacement.inputs.mesh.connect(model.Mesh)
    Axial_displacement.inputs.data_sources.connect(Data_source)
    

    the code works fine. However, if I build up the field container in one line as:

    Axial_displacement = dpf.operators.result.displacement_Z(mesh = model.Mesh, data_sources = Data_source)
    

    an error will pop out and say the displacement_Z does not have the keyword 'mesh':

  • Rajesh Meena
    Rajesh Meena Moderator, Employee Posts: 125
    100 Comments Second Anniversary 5 Answers Solution Developer Community of Practice Member
    ✭✭✭✭

    @Gordon1998 , yes, I got the same issue and then ended up using additional line for connecting mesh pin.