Results#

class planestress.post.results.Results(plane_stress: PlaneStress, u: npt.NDArray[np.float64])[source]#

Bases: object

Class for plane-stress results.

Parameters:
  • plane_stress (PlaneStress) – PlaneStress analysis object used to generate these results.

  • u (npt.NDArray[np.float64]) – Displacement vector.

Variables:
  • ux (npt.NDArray[np.float64]) – x component of the displacement vector.

  • uy (npt.NDArray[np.float64]) – y component of the displacement vector.

  • uxy (npt.NDArray[np.float64]) – Resultant component of the displacement vector.

  • f (npt.NDArray[np.float64]) – Calculated nodal forces.

  • f_r (npt.NDArray[np.float64]) – Calculated nodal reactions.

  • element_results (list[ElementResults]) – List of ElementResults objects.

Methods

calculate_node_forces

Calculates and stores the resultant nodal forces.

calculate_reactions

Calculates and stores the nodal reactions.

calculate_stresses

Calculates and stores the element stresses in self.element_results.

get_nodal_stresses

Calculates the nodal stresses.

get_principal_stresses

Calculates the prinicipal stresses at the nodes.

get_tresca_stresses

Calculates the Tresca stress at the nodes.

get_von_mises_stresses

Calculates the von Mises stress at the nodes.

partition_displacements

Partitions the u vector into x and y displacement vectors.

plot_deformed_shape

Plots the deformed shape.

plot_displacement_contour

Plots the displacement contours.

plot_principal_stress_vectors

Generates a vector plot of the principal stresses.

plot_stress

Generates a stress contour plot.

Attributes

plane_stress

u

ux

uy

uxy

f

f_r

element_results

partition_displacements() None[source]#

Partitions the u vector into x and y displacement vectors.

calculate_node_forces(k: csc_array) None[source]#

Calculates and stores the resultant nodal forces.

Parameters:

k (csc_array) – Original stiffness matrix (before modification).

calculate_reactions(f: ndarray[Any, dtype[float64]]) None[source]#

Calculates and stores the nodal reactions.

Parameters:

f (ndarray[Any, dtype[float64]]) – Applied force vector.

calculate_stresses(elements: list[FiniteElement]) None[source]#

Calculates and stores the element stresses in self.element_results.

Parameters:

elements (list[FiniteElement]) – List of FiniteElement objects used during the analysis.

get_nodal_stresses(agg_func: ~typing.Callable[[list[float]], float] = <function average>) ndarray[Any, dtype[float64]][source]#

Calculates the nodal stresses.

Parameters:

agg_func (Callable[[list[float]], float]) – A function that aggregates the stresses if the point is shared by several elements. The function must receive a list of stresses and return a single stress. Defaults to np.average.

Returns:

A numpy.ndarray of the nodal stresses of size [n x 3], where n is the number of nodes in the mesh. The columns consist of the three stress components, (sig_xx, sig_yy, sig_xy).

Return type:

ndarray[Any, dtype[float64]]

get_principal_stresses(agg_func: ~typing.Callable[[list[float]], float] = <function average>) ndarray[Any, dtype[float64]][source]#

Calculates the prinicipal stresses at the nodes.

Parameters:

agg_func (Callable[[list[float]], float]) – A function that aggregates the stresses if the point is shared by several elements. The function must receive a list of stresses and return a single stress. Defaults to np.average.

Returns:

A numpy.ndarray of the principal nodal stresses of size [n x 3], where n is the number of nodes in the mesh. The columns consist of the two principal stress components and the principal stress angle: (\(\sigma_{11}\), \(\sigma_{22}\), \(\theta_p\)).

Return type:

ndarray[Any, dtype[float64]]

get_von_mises_stresses(agg_func: ~typing.Callable[[list[float]], float] = <function average>) ndarray[Any, dtype[float64]][source]#

Calculates the von Mises stress at the nodes.

Parameters:

agg_func (Callable[[list[float]], float]) – A function that aggregates the stresses if the point is shared by several elements. The function must receive a list of stresses and return a single stress. Defaults to np.average.

Returns:

A numpy.ndarray of the von Mises nodal stresses.

Return type:

ndarray[Any, dtype[float64]]

get_tresca_stresses(agg_func: ~typing.Callable[[list[float]], float] = <function average>) ndarray[Any, dtype[float64]][source]#

Calculates the Tresca stress at the nodes.

Parameters:

agg_func (Callable[[list[float]], float]) – A function that aggregates the stresses if the point is shared by several elements. The function must receive a list of stresses and return a single stress. Defaults to np.average.

Returns:

A numpy.ndarray of the Tresca nodal stresses.

Return type:

ndarray[Any, dtype[float64]]

plot_displacement_contour(direction: str, **kwargs: Any) Axes[source]#

Plots the displacement contours.

Parameters:
  • direction (str) – Displacement field to plot. May be either "x", "y" or "xy" (resultant displacement).

  • kwargs (Any) – See below.

Keyword Arguments:
  • title (str) – Plot title. Defaults to "Displacement Contours [{direction}]".

  • contours (bool) – If set to True, plots contour lines. Defaults to False.

  • colormap (str) – Matplotlib color map, see https://matplotlib.org/stable/tutorials/colors/colormaps.html for more detail. Defaults to "coolwarm".

  • normalize (bool) – If set to True, CenteredNorm is used to scale the colormap, if set to False, the default linear scaling is used. CenteredNorm effectively places the center of the colormap at zero displacement. Defaults to True.

  • num_levels (int) – Number of contour levels. Defaults to 11.

  • colorbar_format (str) – Number formatting string for displacements, see https://docs.python.org/3/library/string.html. Defaults to "{x:.4e}", i.e. exponential format with 4 decimal places.

  • colorbar_label (str) – Colorbar label. Defaults to "Displacement".

  • alpha (float) – Transparency of the mesh outlines, \(0 \leq \alpha \leq 1\). Defaults to 0.2.

  • kwargs (dict[str, Any]) – Other keyword arguments are passed to plotting_context().

Raises:

ValueError – If the value for direction is not valid.

Returns:

Matplotlib axes object.

Return type:

Axes

Example

TODO.

plot_deformed_shape(displacement_scale: float, **kwargs: Any) Axes[source]#

Plots the deformed shape.

Parameters:
  • displacement_scale (float) – Displacement scale.

  • kwargs (Any) – See below.

Keyword Arguments:
  • title (str) – Plot title. Defaults to "Deformed Shape [ds = {displacement_scale}]".

  • alpha (float) – Transparency of the mesh outlines, \(0 \leq \alpha \leq 1\). Defaults to 0.8.

  • kwargs (dict[str, Any]) – Other keyword arguments are passed to plotting_context().

Returns:

Matplotlib axes object.

Return type:

Axes

Example

TODO.

plot_stress(stress: str, **kwargs: Any) Axes[source]#

Generates a stress contour plot.

Parameters:
  • stress (str) – Stress value to plot. See below for list of values.

  • kwargs (Any) – See below.

Keyword Arguments:
  • title (str) – Plot title. Defaults to "Stress Contour Plot - {stress}".

  • contours (bool) – If set to True, plots contour lines. Defaults to False.

  • colormap (str) – Matplotlib color map, see https://matplotlib.org/stable/tutorials/colors/colormaps.html for more detail. Defaults to "coolwarm".

  • stress_limits (tuple[float, float] | None) – Custom colorbar stress limits (sig_min, sig_max). Values outside these limits will appear as white. Defaults to None.

  • normalize (bool) – If set to True, CenteredNorm is used to scale the colormap, if set to False, the default linear scaling is used. CenteredNorm effectively places the center of the colormap at zero displacement. Defaults to True.

  • num_levels (int) – Number of contour levels. Defaults to 11.

  • colorbar_format (str) – Number formatting string for stresses, see https://docs.python.org/3/library/string.html. Defaults to "{x:.4e}", i.e. exponential format with 4 decimal places.

  • colorbar_label (str) – Colorbar label. Defaults to "Stress".

  • alpha (float) – Transparency of the mesh outlines, \(0 \leq \alpha \leq 1\). Defaults to 0.2.

  • agg_func (Callable[[list[float]], float]) – A function that aggregates the stresses if the point is shared by several elements. The function must receive a list of stresses and return a single stress. Defaults to np.average.

  • kwargs (dict[str, Any]) – Other keyword arguments are passed to plotting_context().

Raises:

ValueError – If the value for stress is not valid.

Returns:

Matplotlib axes object.

Return type:

Axes

Example

TODO.

Stress plotting options

Below is a list of the acceptable values for stress:

  • "xx" - stress in the x direction.

  • "yy" - stress in the y direction.

  • "xy" - shear stress in the xy direction.

  • 11 - maximum principal stress.

  • 22 - minimum principal stress.

  • vm - von Mises stress.

  • tr - Tresca stress.

  • TODO others.

plot_principal_stress_vectors(stress: str, **kwargs: Any) Axes[source]#

Generates a vector plot of the principal stresses.

Parameters:
  • stress (str) – Stress value to plot. See below for list of values.

  • kwargs (Any) – See below.

Keyword Arguments:
  • title (str) – Plot title. Defaults to "Stress Vector Plot - {stress}".

  • colormap (str) – Matplotlib color map, see https://matplotlib.org/stable/tutorials/colors/colormaps.html for more detail. Defaults to "coolwarm".

  • stress_limits (tuple[float, float] | None) – Custom stress limits (sig_min, sig_max). Values outside these limits will not be plotted. Defaults to None.

  • num_levels (int) – Number of contour levels. Defaults to 11.

  • colorbar_format (str) – Number formatting string for stresses, see https://docs.python.org/3/library/string.html. Defaults to "{x:.4e}", i.e. exponential format with 4 decimal places.

  • colorbar_label (str) – Colorbar label. Defaults to "Stress".

  • alpha (float) – Transparency of the mesh outlines, \(0 \leq \alpha \leq 1\). Defaults to 0.2.

  • agg_func (Callable[[list[float]], float]) – A function that aggregates the stresses if the point is shared by several elements. The function must receive a list of stresses and return a single stress. Defaults to np.average.

  • kwargs (dict[str, Any]) – Other keyword arguments are passed to plotting_context().

Raises:

ValueError – If the value for stress is not valid.

Returns:

Matplotlib axes object.

Return type:

Axes

Example

TODO.

Stress plotting options

Below is a list of the acceptable values for stress:

  • 11 - maximum principal stress.

  • 22 - minimum principal stress.

  • TODO 11 and 22 together.