Skip to content

Commit

Permalink
refactor: increase post module coverage (#3556)
Browse files Browse the repository at this point in the history
* refactor: removing unused code and typos

* feat: increasing coverage

* chore: adding changelog file 3556.added.md [dependabot-skip]

* feat: fixing coverage

* refactor: removing unused code

* tests: increasing coverage

* fix: tests

* fix: all test

---------

Co-authored-by: pyansys-ci-bot <[email protected]>
  • Loading branch information
germa89 and pyansys-ci-bot authored Nov 22, 2024
1 parent 83a5083 commit c78347c
Show file tree
Hide file tree
Showing 3 changed files with 231 additions and 110 deletions.
1 change: 1 addition & 0 deletions doc/changelog.d/3556.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
refactor: increase post module coverage
55 changes: 11 additions & 44 deletions src/ansys/mapdl/core/post.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,22 +130,12 @@ def __init__(self, mapdl):
if not isinstance(mapdl, MapdlBase): # pragma: no cover
raise TypeError("Must be initialized using Mapdl instance")
self._mapdl_weakref = weakref.ref(mapdl)
self._set_loaded = False

@property
def _mapdl(self):
"""Return the weakly referenced instance of MAPDL"""
return self._mapdl_weakref()

@property
def _log(self):
"""Alias for mapdl log"""
return self._mapdl._log

def _set_log_level(self, level):
"""Alias for mapdl._set_log_level"""
return self._mapdl._set_log_level(level)

@supress_logging
def __repr__(self):
info = "PyMAPDL PostProcessing Instance\n"
Expand All @@ -157,7 +147,7 @@ def __repr__(self):
if self._mapdl.parameters.routine == "POST1":
info += "\n\n" + self._mapdl.set("LIST")
else:
info += "\n\n Enable routine POST1 to see a table of available results"
info += "\n\nEnable routine POST1 to see a table of available results"

return info

Expand Down Expand Up @@ -208,10 +198,6 @@ def frequency_values(self) -> np.ndarray:
# Because in MAPDL is the same.
return self.time_values

def _reset_cache(self):
"""Reset local cache"""
self._set_loaded = False

@property
def filename(self) -> str:
"""Return the current result file name without extension.
Expand Down Expand Up @@ -732,19 +718,6 @@ def _plot_cell_scalars(self, scalars, show_elem_numbering=False, **kwargs):
pl.plot(meshes, [], labels, mapdl=self, **kwargs)
return pl.show(**kwargs)

@property
@supress_logging
def _all_nnum(self):
with self._mapdl.save_selection:
self._mapdl.allsel()
nnum = self._mapdl.get_array("NODE", item1="NLIST")

# rerun if encountered weird edge case of negative first index.
if nnum[0] == -1:
nnum = self._mapdl.get_array("NODE", item1="NLIST")

return nnum.astype(np.int32, copy=False)

@property
@supress_logging
def _all_enum(self):
Expand Down Expand Up @@ -1046,7 +1019,7 @@ def plot_nodal_displacement(
if isinstance(component, str):
if component.upper() == "ALL":
raise ValueError(
'"ALL" not allowed in this context. Select a '
'"ALL" not allowed in this context. Select a '
'single displacement component (e.g. "X")'
)

Expand Down Expand Up @@ -1156,7 +1129,7 @@ def plot_nodal_rotation(self, component, show_node_numbering=False, **kwargs):
if isinstance(component, str):
if component.upper() == "ALL":
raise ValueError(
'"ALL" not allowed in this context. Select a '
'"ALL" not allowed in this context. Select a '
'single component (e.g. "X")'
)

Expand Down Expand Up @@ -1293,7 +1266,7 @@ def plot_element_displacement(
"""
if component.upper() == "ALL":
raise ValueError(
'"ALL" not allowed in this context. Select a '
'"ALL" not allowed in this context. Select a '
'single displacement component (e.g. "X" or "NORM")'
)

Expand Down Expand Up @@ -1364,6 +1337,8 @@ def element_stress(self, component, option="AVG") -> np.ndarray:
0. , 0. ])
"""
if not isinstance(component, str):
component = str(component)
component = elem_check_inputs(component, option, STRESS_TYPES)
return self.element_values("S", component, option)

Expand Down Expand Up @@ -2119,8 +2094,6 @@ def nodal_total_component_strain(self, component) -> np.ndarray:
array([ 1, 2, 3, ..., 7215, 7216, 7217], dtype=int32)
"""
if isinstance(component, int):
component = str(component)
component = check_comp(component, COMPONENT_STRESS_TYPE)
return self.nodal_values("EPTO", component)

Expand Down Expand Up @@ -2497,8 +2470,6 @@ def nodal_elastic_component_strain(self, component) -> np.ndarray:
array([ 1, 2, 3, ..., 7215, 7216, 7217], dtype=int32)
"""
if isinstance(component, int):
component = str(component)
component = check_comp(component, COMPONENT_STRESS_TYPE)
return self.nodal_values("EPEL", component)

Expand Down Expand Up @@ -2838,7 +2809,7 @@ def plot_nodal_elastic_eqv_strain(self, show_node_numbering=False, **kwargs):
"""
scalars = self.nodal_elastic_eqv_strain()
kwargs.setdefault(
"scalar_bar_args", {"title": "Elastic Nodal\n Equivalent Strain"}
"scalar_bar_args", {"title": "Elastic Nodal\nEquivalent Strain"}
)
return self._plot_point_scalars(
scalars, show_node_numbering=show_node_numbering, **kwargs
Expand Down Expand Up @@ -2878,8 +2849,6 @@ def nodal_plastic_component_strain(self, component) -> np.ndarray:
array([ 1, 2, 3, ..., 7215, 7216, 7217], dtype=int32)
"""
if isinstance(component, int):
component = str(component)
component = check_comp(component, COMPONENT_STRESS_TYPE)
return self.nodal_values("EPPL", component)

Expand Down Expand Up @@ -3221,7 +3190,7 @@ def plot_nodal_plastic_eqv_strain(self, show_node_numbering=False, **kwargs):
"""
scalars = self.nodal_plastic_eqv_strain()
kwargs.setdefault(
"scalar_bar_args", {"title": "Plastic Nodal\n Equivalent Strain"}
"scalar_bar_args", {"title": "Plastic Nodal\nEquivalent Strain"}
)
return self._plot_point_scalars(
scalars, show_node_numbering=show_node_numbering, **kwargs
Expand Down Expand Up @@ -3262,8 +3231,6 @@ def nodal_thermal_component_strain(self, component) -> np.ndarray:
array([ 1, 2, 3, ..., 7215, 7216, 7217], dtype=int32)
"""
if isinstance(component, int):
component = str(component)
component = check_comp(component, COMPONENT_STRESS_TYPE)
return self.nodal_values("EPTH", component)

Expand Down Expand Up @@ -3424,7 +3391,7 @@ def nodal_thermal_strain_intensity(self) -> np.ndarray:
Equivalent MAPDL command:
* ``PRNSOL, EPTH, PRIN``
* ``PRNSOL, EPTH, INT``
Returns
-------
Expand Down Expand Up @@ -3611,7 +3578,7 @@ def plot_nodal_thermal_eqv_strain(self, show_node_numbering=False, **kwargs):
"""
scalars = self.nodal_thermal_eqv_strain()
kwargs.setdefault(
"scalar_bar_args", {"title": "Thermal Nodal\n Equivalent Strain"}
"scalar_bar_args", {"title": "Thermal Nodal\nEquivalent Strain"}
)
return self._plot_point_scalars(
scalars, show_node_numbering=show_node_numbering, **kwargs
Expand Down Expand Up @@ -3702,7 +3669,7 @@ def plot_nodal_contact_friction_stress(self, show_node_numbering=False, **kwargs
"""
kwargs.setdefault(
"scalar_bar_args", {"title": "Nodal Contact\n Friction Stress"}
"scalar_bar_args", {"title": "Nodal Contact\nFriction Stress"}
)
return self._plot_point_scalars(
self.nodal_contact_friction_stress(),
Expand Down
Loading

0 comments on commit c78347c

Please sign in to comment.