pythonpyansys

Obtain elastic_strain_principal_1 from PyAnsys


Trying to obtain some data from a simulation saved in a rst file.

Initially we have:

from ansys.dpf import core as dpf
model = dpf.Model(r'.\file.rst')

We want to get elastic_strain_principal_1. We create an operator instance to perform it:

op = dpf.operators.result.elastic_strain_principal_1()

To fill the parameters of this instance we connect it to the model:

op.inputs.data_sources.connect(model.metadata.data_sources)

Despite this is made by default, we are going to ensure that we get principal strain first component in the last time step:

time_scoping = model.metadata.time_freq_support.time_frequencies.data[-1]
op.inputs.time_scoping.connect(float(time_scoping))

Then we create a filds container with the output and get the data:

result_fields_container = op.outputs.fields_container()
field = result_fields_container[0] #only time considered so [0]
field_data = field.data

As far as I know, we obtain the elastic strain principal on all the available nodes for the last time step, but this is not matching the results from Ansys Desktop App by far, if I take the maximum in field.data and the maximum principal strain 1 (that in this particular case always happens at the end of the simulation) in Ansys Deskot App there is a diference of 1.5 units.

I am having trouble understanding how PyAnsys works and why values are not matching.

Also I am doing the same operation for stress_principal_1 with the analogous code structure, in this case the values are correct, both PyAnsys and Ansys Desktop App return identical values, this leads to more confusion.


Solution

  • (@Tzane) Despite I can't post the full code, I can sketch it. Just use the same approach as before but with from ansys.dpf import post. Assume we have the .rst file from ansys in the following local path: file = folder + 'file.rst', then just instantiate our simulation:

    simulation = post.StaticMechanicalSimulation(file)
    times = simulation.time_freq_support.time_frequencies.data
    

    Once we have both, we can iterate over each time-step if needed or retrieve just from a specific time-step: for step in times:

     for step in times:
        displacement = simulation.displacement(times=step)
        strain = imulation.elastic_strain_principal_nodal(times=step)
        stress = simulation.stress_principal_nodal(times=step)
    

    This functions have other arguments such as components= where you can select axis, or named_selections= where you can choose the "body/selection".