pymapdl icon indicating copy to clipboard operation
pymapdl copied to clipboard

animate_nodal_solution_set for Stresses, Strains

Open jeremymoran opened this issue 5 years ago • 6 comments

Hi,

I currently have a sim with one load step and several substeps. Just curious as to whether I can animate the nodal stresses, strains using the animate_nodal_solution_set function?

jeremymoran avatar Nov 17 '20 09:11 jeremymoran

At the moment, no, but I can add these features in the near future.

akaszynski avatar Nov 18 '20 15:11 akaszynski

No problem. Perhaps a simpler alternative in the interim would be to write a sequence of .vtu files, i.e. results001.vtu, results.002.vtu. This can get read by Paraview as an animated sequence. I modified the save_to_vtk() function to remove the "Nodal Solution X" label. This way every .vtu file simply has "Nodal Solution" without numbering, allowing for proper playback.

I have attached my modified function here if it is of any help. I simply use this in a loop.

def save_as_vtk2(resultf, filename, rsets=None, result_types=['ENS','EEL','EPL']):

    # Copy grid as to not write results to original object
    grid = resultf.grid.copy()

    if rsets is None:
        rsets = range(resultf.nsets)
    elif isinstance(rsets, int):
        rsets = [rsets]
    elif not isinstance(rsets, Iterable):
        raise TypeError('rsets must be an iterable like [0, 1, 2] or range(3)')

    if result_types is None:
        result_types = ELEMENT_INDEX_TABLE_KEYS
    elif not isinstance(result_types, list):
        raise TypeError('result_types must be a list of solution types')
    else:
        for item in result_types:
            if item not in ELEMENT_INDEX_TABLE_KEYS:
                raise ValueError('Invalid result type "%s" % item')

    try:
        from tqdm import tqdm
        pbar = tqdm(total=len(rsets), desc='Saving to file')
    except ImportError:
        pbar = None

    for i in rsets:
        # Nodal results
        _, val = resultf.nodal_solution(i)
        grid.point_arrays['Nodal Solution'] = val   #Removed Nodal Solution XX label

        # Nodal results
        for rtype in resultf.available_results:
            if rtype in result_types:
                _, values = resultf._nodal_result(i, rtype)
                desc = element_index_table_info[rtype]
                grid.point_arrays['{:s}'.format(desc)] = values #Removed Nodal Solution XX label

        if pbar is not None:
            pbar.update(1)

    grid.save(filename)
    if pbar is not None:
        pbar.close()

def APDL_VTK():
    rst = pyansys.read_binary('apdl/file.rst')
    rsets = range(0, rst.nsets, 5)

    for i in rsets:
        save_as_vtk2(rst,'output/vtk/ansys_vtk_%d.vtk'%i, i)

jeremymoran avatar Nov 18 '20 23:11 jeremymoran

Linking #362

Clearly there is a need for improving plotting capabilities. We probably need to think about the long term plan and the big picture.

germa89 avatar Jul 07 '22 10:07 germa89

We might want to consider pulling off the plotting components of pymapdl into a separate library as pyfluent did within pyfluent-visualization.

akaszynski avatar Jul 07 '22 19:07 akaszynski

I think that is way to go forward. If we share the data model with pyfluent we might be able to reuse many of their functions. But I guess it is not possible.

germa89 avatar Jul 08 '22 10:07 germa89