From 901ccf2737234ad693ad0fe890a9ce8aebbd0d8a Mon Sep 17 00:00:00 2001 From: Alex Kaszynski Date: Tue, 18 May 2021 16:51:02 -0600 Subject: [PATCH] refactor stitle (#29) --- ansys/mapdl/reader/cyclic_reader.py | 40 ++++++++++---------- ansys/mapdl/reader/rst.py | 57 +++++++++++++++-------------- setup.py | 2 +- 3 files changed, 50 insertions(+), 49 deletions(-) diff --git a/ansys/mapdl/reader/cyclic_reader.py b/ansys/mapdl/reader/cyclic_reader.py index cd8d7186..ff3325d1 100644 --- a/ansys/mapdl/reader/cyclic_reader.py +++ b/ansys/mapdl/reader/cyclic_reader.py @@ -686,7 +686,7 @@ def plot_nodal_thermal_strain(self, rnum, sel_type_all : bool, optional If node_components is specified, plots those elements - containing all nodes of the component. Default True. + containing all nodes of the component. Default ``True``. Returns ------- @@ -707,7 +707,7 @@ def plot_nodal_thermal_strain(self, rnum, _, strain = self.nodal_thermal_strain(rnum, phase, False, True) scalars = strain[:, :, idx] - kwargs.setdefault('stitle', '%s Nodal Thermal Strain' % comp) + kwargs.setdefault('scalar_bar_args', {'title': f'{comp} Nodal Thermal Strain'}) kwargs['node_components'] = node_components kwargs['element_components'] = element_components kwargs['show_displacement'] = show_displacement @@ -825,7 +825,7 @@ def plot_nodal_elastic_strain(self, rnum, sel_type_all : bool, optional If node_components is specified, plots those elements - containing all nodes of the component. Default True. + containing all nodes of the component. Default ``True``. Returns ------- @@ -843,7 +843,7 @@ def plot_nodal_elastic_strain(self, rnum, _, strain = self.nodal_elastic_strain(rnum, phase, False, full_rotor) scalars = strain[:, :, idx] - kwargs.setdefault('stitle', '%s Nodal Elastic Strain' % comp.upper()) + kwargs.setdefault('scalar_bar_args', {'title': f'{comp} Nodal Elastic Strain'}) kwargs['node_components'] = node_components kwargs['element_components'] = element_components kwargs['show_displacement'] = show_displacement @@ -961,7 +961,7 @@ def plot_nodal_plastic_strain(self, rnum, sel_type_all : bool, optional If node_components is specified, plots those elements - containing all nodes of the component. Default True. + containing all nodes of the component. Default ``True``. Returns ------- @@ -979,7 +979,7 @@ def plot_nodal_plastic_strain(self, rnum, _, strain = self.nodal_plastic_strain(rnum, phase, False, full_rotor) scalars = strain[:, :, idx] - kwargs.setdefault('stitle', '%s Nodal Plastic Strain' % comp) + kwargs.setdefault('scalar_bar_args', {'title': f'{comp} Nodal Plastic Strain'}) kwargs['node_components'] = node_components kwargs['element_components'] = element_components kwargs['show_displacement'] = show_displacement @@ -1106,7 +1106,7 @@ def plot_nodal_solution(self, rnum, comp='norm', sel_type_all : bool, optional If node_components is specified, plots those elements - containing all nodes of the component. Default True. + containing all nodes of the component. Default ``True``. Returns ------- @@ -1133,19 +1133,19 @@ def plot_nodal_solution(self, rnum, comp='norm', label = 'Cyclic Rotor\nDisplacement' if comp == 'x': scalars = result[:, :, 0] - stitle = 'X {:s}\n'.format(label) + title = 'X {:s}\n'.format(label) elif comp == 'y': scalars = result[:, :, 1] - stitle = 'Y {:s}\n'.format(label) + title = 'Y {:s}\n'.format(label) elif comp == 'z': scalars = result[:, :, 2] - stitle = 'Z {:s}\n'.format(label) + title = 'Z {:s}\n'.format(label) else: # Normalize displacement scalars = (result*result).sum(2)**0.5 - stitle = 'Normalized\n%s\n' % label - kwargs.setdefault('stitle', stitle) + title = 'Normalized\n%s\n' % label + kwargs.setdefault('scalar_bar_args', {'title': title}) kwargs['node_components'] = node_components kwargs['element_components'] = element_components kwargs['show_displacement'] = show_displacement @@ -1211,7 +1211,7 @@ def plot_nodal_stress(self, rnum, sel_type_all : bool, optional If node_components is specified, plots those elements - containing all nodes of the component. Default True. + containing all nodes of the component. Default ``True``. Returns ------- @@ -1231,7 +1231,8 @@ def plot_nodal_stress(self, rnum, _, stress = self.nodal_stress(rnum, phase, False, full_rotor=True) scalars = stress[:, :, idx] - kwargs.setdefault('stitle', 'Cyclic Rotor\nNodal Stress\n%s\n' % comp) + kwargs.setdefault('scalar_bar_args', + {'title': f'Cyclic Rotor\nNodal Stress\n{comp}\n'}) kwargs['node_components'] = node_components kwargs['element_components'] = element_components kwargs['show_displacement'] = show_displacement @@ -1291,7 +1292,7 @@ def plot_principal_nodal_stress(self, rnum, sel_type_all : bool, optional If node_components is specified, plots those elements - containing all nodes of the component. Default True. + containing all nodes of the component. Default ``True``. kwargs : keyword arguments Additional keyword arguments. See ``help(pyvista.plot)`` @@ -1315,8 +1316,8 @@ def plot_principal_nodal_stress(self, rnum, _, pstress = self.principal_nodal_stress(rnum, phase, full_rotor=True) scalars = pstress[:, :, idx] - kwargs.setdefault('stitle', - 'Cyclic Rotor\nPrincipal Nodal Stress\n%s\n' % comp) + kwargs.setdefault('scalar_bar_args', + {'title': f'Cyclic Rotor\nPrincipal Nodal Stress\n{comp}\n'}) kwargs['node_components'] = node_components kwargs['element_components'] = element_components kwargs['show_displacement'] = show_displacement @@ -1330,8 +1331,7 @@ def plot_principal_nodal_stress(self, rnum, self._plot_cyclic_point_scalars(scalars, rnum, **kwargs) def nodal_temperature(self, rnum, full_rotor=False): - """Retrieves the temperature for each node in the - solution. + """Retrieves the temperature for each node in the solution. The order of the results corresponds to the sorted node numbering. @@ -1409,7 +1409,7 @@ def plot_nodal_temperature(self, rnum, sel_type_all : bool, optional If node_components is specified, plots those elements - containing all nodes of the component. Default True. + containing all nodes of the component. Default ``True``. Returns ------- diff --git a/ansys/mapdl/reader/rst.py b/ansys/mapdl/reader/rst.py index fd61dde7..3eba03c9 100644 --- a/ansys/mapdl/reader/rst.py +++ b/ansys/mapdl/reader/rst.py @@ -626,7 +626,7 @@ def plot_nodal_solution(self, rnum, comp=None, else: grid = self.grid - kwargs.setdefault('stitle', '%s\n%s\n' % (comp, label)) + kwargs.setdefault('scalar_bar_args', {'title': f'{comp}\n{label}\n'}) return self._plot_point_scalars(scalars, rnum=rnum, grid=grid, show_displacement=show_displacement, displacement_factor=displacement_factor, @@ -949,8 +949,10 @@ def animate_nodal_solution_set(self, rnums=None, comp='norm', the top down. >>> rsets = range(0, rst.nsets, 50) - >>> rst.animate_nodal_solution_set(rsets, stitle='Temp', lighting=False, - cpos='zx', movie_filename='example.gif') + >>> rst.animate_nodal_solution_set(rsets, + ... scalar_bar_args={'title': 'My Animation'}, + ... lighting=False, cpos='zx', + ... movie_filename='example.gif') """ if self.nsets == 1: raise RuntimeError('Unable to animate. Solution contains only one ' @@ -2434,8 +2436,7 @@ def plot_principal_nodal_stress(self, rnum, comp=None, 'S3': 'Principal Stress 3', 'SINT': 'Stress Intensity', 'SEQV': 'von Mises Stress'} - kwargs.setdefault('stitle', stype_stitle_map[comp]) - + kwargs.setdefault('scalar_bar_args', {'title': stype_stitle_map[comp]}) return self._plot_point_scalars(stress, grid=grid, rnum=rnum, show_displacement=show_displacement, displacement_factor=displacement_factor, @@ -2564,7 +2565,6 @@ def _plot_point_scalars(self, scalars, rnum=None, grid=None, screenshot = kwargs.pop('screenshot', None) interactive = kwargs.pop('interactive', True) text_color = kwargs.pop('text_color', None) - use_ipyvtk = kwargs.pop('use_ipyvtk', pv.rcParams['use_ipyvtk']) kwargs.setdefault('smooth_shading', pv.rcParams.get('smooth_shading', True)) kwargs.setdefault('color', 'w') @@ -2625,8 +2625,7 @@ def _plot_point_scalars(self, scalars, rnum=None, grid=None, plotter.show(interactive=False, auto_close=False, window_size=window_size, full_screen=full_screen, - interactive_update=not off_screen, - use_ipyvtk=use_ipyvtk) + interactive_update=not off_screen) self._animating = True def q_callback(): @@ -2928,10 +2927,10 @@ def plot_nodal_stress(self, rnum, comp=None, sel_type_all : bool, optional If node_components is specified, plots those elements - containing all nodes of the component. Default True. + containing all nodes of the component. Default ``True``. kwargs : keyword arguments - Additional keyword arguments. See help(pyvista.plot) + Additional keyword arguments. See ``help(pyvista.plot)`` Returns ------- @@ -2944,7 +2943,8 @@ def plot_nodal_stress(self, rnum, comp=None, >>> rst.plot_nodal_stress(0, comp='x', show_displacement=True) """ - kwargs['stitle'] = '%s Component Nodal Stress' % comp + kwargs.setdefault('scalar_bar_args', + {'title': f'{comp} Component Nodal Stress'}) return self._plot_nodal_result(rnum, 'ENS', comp, STRESS_TYPES, show_displacement, displacement_factor, node_components, @@ -3422,7 +3422,7 @@ def plot_element_result(self, rnum, result_type, item_index, in_element_coord_sys) desc = self.available_results.description[result_type].capitalize() - kwargs.setdefault('stitle', desc) + kwargs.setdefault('scalar_bar_args', {'title': desc}) return bsurf.plot(scalars='_scalars', **kwargs) def _extract_surface_element_result(self, rnum, result_type, item_index, @@ -3646,14 +3646,14 @@ def plot_cylindrical_nodal_stress(self, rnum, comp=None, show_displacement=False sel_type_all : bool, optional If node_components is specified, plots those elements - containing all nodes of the component. Default True. + containing all nodes of the component. Default ``True``. **kwargs : keyword arguments - Optional keyword arguments. See help(pyvista.plot) + Optional keyword arguments. See ``help(pyvista.plot)`` Examples -------- - Plot nodal stress in the radial direction + Plot nodal stress in the radial direction. >>> from ansys.mapdl import reader as pymapdl_reader >>> result = pymapdl_reader.read_binary('file.rst') @@ -3672,7 +3672,8 @@ def plot_cylindrical_nodal_stress(self, rnum, comp=None, show_displacement=False grid, ind = self._extract_element_components(element_components) scalars = scalars[ind] - kwargs.setdefault('stitle', '%s Cylindrical\nNodal Stress' % comp) + kwargs.setdefault('scalar_bar_args', + {'title': f'{comp} Cylindrical\nNodal Stress'}) return self._plot_point_scalars(scalars, grid=grid, rnum=rnum, show_displacement=show_displacement, displacement_factor=displacement_factor, @@ -3707,10 +3708,10 @@ def plot_nodal_temperature(self, rnum, show_displacement=False, sel_type_all : bool, optional If node_components is specified, plots those elements - containing all nodes of the component. Default True. + containing all nodes of the component. Default ``True``. **kwargs : keyword arguments - Optional keyword arguments. See help(pyvista.plot) + Optional keyword arguments. See ``help(pyvista.plot)`` Examples -------- @@ -3737,7 +3738,7 @@ def plot_nodal_temperature(self, rnum, show_displacement=False, return self._plot_point_scalars(scalars, grid=grid, rnum=rnum, show_displacement=show_displacement, displacement_factor=displacement_factor, - stitle='Nodal Tempature', + scalar_bar_args={'title': 'Nodal Tempature'}, **kwargs) def nodal_thermal_strain(self, rnum): @@ -3767,7 +3768,7 @@ def nodal_thermal_strain(self, rnum): Examples -------- - Load the nodal thermal strain for the first solution + Load the nodal thermal strain for the first solution. >>> from ansys.mapdl import reader as pymapdl_reader >>> rst = pymapdl_reader.read_binary('file.rst') @@ -3777,7 +3778,7 @@ def nodal_thermal_strain(self, rnum): def plot_nodal_thermal_strain(self, rnum, comp=None, - stitle='Nodal Thermal Strain', + scalar_bar_args={'title': 'Nodal Thermal Strain'}, show_displacement=False, displacement_factor=1, node_components=None, @@ -3841,7 +3842,7 @@ def plot_nodal_thermal_strain(self, rnum, node_components=node_components, element_components=element_components, sel_type_all=sel_type_all, - stitle=stitle, + scalar_bar_args=scalar_bar_args, **kwargs) def nodal_elastic_strain(self, rnum): @@ -3885,7 +3886,7 @@ def nodal_elastic_strain(self, rnum): return self._nodal_result(rnum, 'EEL') def plot_nodal_elastic_strain(self, rnum, comp, - stitle='Nodal Elastic Strain', + scalar_bar_args={'title': 'Nodal Elastic Strain'}, show_displacement=False, displacement_factor=1, node_components=None, @@ -3940,7 +3941,7 @@ def plot_nodal_elastic_strain(self, rnum, comp, >>> result = examples.download_pontoon() >>> result.plot_nodal_elastic_strain(0) """ - stitle = ' '.join([comp.upper(), stitle]) + scalar_bar_args['title'] = ' '.join([comp.upper(), scalar_bar_args['title']]) return self._plot_nodal_result(rnum, 'EEL', comp, STRAIN_TYPES, @@ -3949,7 +3950,7 @@ def plot_nodal_elastic_strain(self, rnum, comp, node_components=node_components, element_components=element_components, sel_type_all=sel_type_all, - stitle=stitle, + scalar_bar_args=scalar_bar_args, **kwargs) def nodal_plastic_strain(self, rnum): @@ -3985,7 +3986,7 @@ def nodal_plastic_strain(self, rnum): return self._nodal_result(rnum, 'EPL') def plot_nodal_plastic_strain(self, rnum, comp, - stitle='Nodal Plastic Strain', + scalar_bar_args={'title': 'Nodal Plastic Strain'}, show_displacement=False, displacement_factor=1, node_components=None, @@ -4041,7 +4042,7 @@ def plot_nodal_plastic_strain(self, rnum, comp, >>> result = examples.download_pontoon() >>> result.plot_nodal_plastic_strain(0) """ - stitle = ' '.join([comp.upper(), stitle]) + scalar_bar_args['title'] = ' '.join([comp.upper(), scalar_bar_args['title']]) return self._plot_nodal_result(rnum, 'EPL', comp, STRAIN_TYPES, @@ -4050,7 +4051,7 @@ def plot_nodal_plastic_strain(self, rnum, comp, node_components=node_components, element_components=element_components, sel_type_all=sel_type_all, - stitle=stitle, + scalar_bar_args=scalar_bar_args, **kwargs) def _plot_nodal_result(self, rnum, result_type, comp, available_comps, diff --git a/setup.py b/setup.py index 31728d0c..61cb13c6 100644 --- a/setup.py +++ b/setup.py @@ -84,7 +84,7 @@ def compilerName(): exec(fd.read()) install_requires = ['numpy>=1.14.0', - 'pyvista>=0.28.0', + 'pyvista>=0.30.1', 'appdirs>=1.4.0', 'tqdm>=4.45.0']