0

I am trying to create a code to produce a failure mode plot for honeycomb beam structures as seen in the image below:

example graph

(from M. Sadighi et al. 2009)

There are distinct formulas to calculate the load at which the failure will occur, and given the material/beam parameters, the lowest value is the most likely failure to occur.

I have a triple nested for loop running ranges of values for t, L, and rho. Mesh grid from numpy and the contour plot from matplotlib seemed logical, but throw an error for the z input requiring a 2D array.

I thought that maybe each failure type could be encoded into a value (i.e. 1 for core crush, 2 for indentation, etc.) and you could scan the x and y values to store where the change in failure type happen, but I still don't know how to get that into a plot.

The closest thing I have found so far can be seen here The moons dataset and decision surface graphics in a Jupyter environment where the plot is split into different colored regions.

How can this be plotted?

P.S. I know that you are suppose to attach code, however in this case, a ton of variables are need to do the calculations and would be difficult to pass around.

xdze2
  • 3,986
  • 2
  • 12
  • 29
paperstsoap
  • 335
  • 4
  • 13

1 Answers1

0

I am trying to rephrase the question. Let's say we have functions of two coordinates: f1(x, y), f2(x, y)... They correspond for instance at the critical stress for each failure mode. Variables x, y are two of the parameters.

For a given (x, y) the failure mode is obtain by using argmin( f1(x, y), f2(x, y), ... ) i.e. the failure mode for which the critical stress is minimal

Here is the simple solution I could think of to obtain a map of the failure modes:

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.colors import ListedColormap

# Mesh the parameters space
x = np.linspace(0, 2, 35)
y = np.linspace(0, 1, 24)

x_grid, y_grid = np.meshgrid(x, y)

# Compute the functions for each point on the mesh
f1 = x_grid + y_grid
f2 = 0.5 + x_grid**2
f3 = 1 + y_grid**2

# Identify which function is minimal for each point
failure_mode = np.argmin([f1, f2, f3], axis=0)

# Graph
discrete_colormap = ListedColormap(['gold', 'darkorange', 'mediumseagreen'])

plt.pcolormesh(x, y, failure_mode, cmap=discrete_colormap);
cbar = plt.colorbar();
cbar.set_label('failure mode');
cbar.set_ticks(np.arange(np.max(failure_mode)+1));
plt.xlabel('x'); plt.ylabel('y');

which gives:

map of the failure mode

See for example this answer for discrete colormap.


Here is a solution to plot the contour of each zone:

The contour of the zone i is defined as the points (x, y) such that f_i(x, y) is equal to the minimum of all the remaining functions i.e. min( f_j(x, y) for i != j ). We could use several contour plots with surfaces equal to f_i(x, y) - min( f_j(x, y) for i!=j ). The level of the zone boundary is zero.

import numpy as np
import matplotlib.pyplot as plt

# Mesh the parameters space
x = np.linspace(0, 2, 35)
y = np.linspace(0, 1, 24)

x_grid, y_grid = np.meshgrid(x, y)

# List of functions evaluated for each point of the mesh
f_grid = [x_grid + y_grid,
          0.5 + x_grid**2,
          1 + y_grid**2]

# Identify which function is minimal for each point
failure_mode = np.argmin(f_grid, axis=0)

# this part is for the background
critical_stress = np.min(f_grid, axis=0)
plt.pcolormesh(x, y, critical_stress, shading='Gouraud')
cbar = plt.colorbar();
cbar.set_label('critical stress');

# Plot the contour of each zone
for i in range(len(f_grid)):
    other_functions = [f_j for j, f_j in enumerate(f_grid) if i != j]
    level_surface = f_grid[i] - np.min(other_functions, axis=0)
    plt.contour(x, y, level_surface,
                levels=[0, ],
                linewidths=2, colors='black');
    # label
    barycentre_x = np.mean(x_grid[failure_mode==i])
    barycentre_y = np.mean(y_grid[failure_mode==i])
    plt.text(barycentre_x, barycentre_y, 'mode %i' % i)

plt.xlabel('x'); plt.ylabel('y');

the graph is:

map with zones

xdze2
  • 3,986
  • 2
  • 12
  • 29
  • I think this will achieve what I am after. Is it possible to make the colors white and the borders black as seen in the image? That is how they are normally presented, but may be difficult to do. – paperstsoap Sep 18 '19 at 18:30
  • @paperstsoap I added a solution to plot the boundaries of each zone. I also added the critical stress (background), but this is not necessary – xdze2 Sep 18 '19 at 21:48
  • I commented out the section that does the color map and changed the mode i piece to be an if statement to assign the names. This should work for my application. I need to make a few tweaks on my side to confirm, but will give it the check. – paperstsoap Sep 20 '19 at 18:10