DesignLife embedded Add-On, available in Mechanical, allows to plot the Damage Matrix of a node. Is there any way to get the same plot in nCode GUI?
We can make use of the Scripting glyph for getting the Damage Matrix. Assuming that you have a MultiColumn object with damage, mean and range on the fourth, fifth and sixth column, and defining as input of your Scripting glyph a MultiColumn input and as output a Histrogram output, the script to be used is shown below, defining 64 bins for range and mean. Result:
def glyphscript(engineState): import Glyph import numpy as np es = engineState in_MC = es.GetInputMultiColumn(0) hiout = es.GetOutputHistogram(0) in_table = in_MC.GetTable(0,0) num_rows = in_table.GetRowCount() range_s = [] means = [] damage = [] for i in range(num_rows): range_s.append(in_table.GetValue(5,i)) means.append(in_table.GetValue(4,i)) damage.append(in_table.GetValue(3,i)) numBins = 64 buffer_user = 10 ## Bins creation # Step 1: Define the buffer and calculate min and max for both x and y min_x = np.min(range_s) max_x = np.max(range_s) min_y = np.min(means) max_y = np.max(means) # Create boundaries for bins with buffer min_bound_x = max(min_x - buffer_user,0) max_bound_x = max_x + buffer_user min_bound_y = min_y - buffer_user max_bound_y = max_y + buffer_user # Step 2: Generate 64 evenly spaced bins for x and y bins_x = np.linspace(min_bound_x, max_bound_x, numBins+1) # 65 because you need 64 intervals bins_y = np.linspace(min_bound_y, max_bound_y, numBins+1) # Step 3: Create a 2D array to hold the sum of z values in each bin bin_sums = np.zeros((numBins, numBins)) # For storing the sum of z values in each bin # Step 4: Assign each (x, y) pair to a bin and sum damage (z) for i in range(len(means)): # Find which bin (for both x and y) the current point falls into bin_idx_x = np.digitize(range_s[i], bins_x) - 1 # -1 to adjust to 0-based index bin_idx_y = np.digitize(means[i], bins_y) - 1 # -1 for same reason # Accumulate the z value (total sum) in the appropriate bin bin_sums[bin_idx_x, bin_idx_y] += damage[i] # Step 5: Calculate the center values of x and y for each bin # The center of each bin is the midpoint between the bin edges bin_centers_x = (bins_x[:-1] + bins_x[1:]) / 2 bin_centers_y = (bins_y[:-1] + bins_y[1:]) / 2 mat = Glyph.Matrix() atts = dict(Type=2, SubType=2, xmin=min_bound_x, xmax=max_bound_x, xbincount=numBins, xtitle="Range", xunits="MPa", ymin=min_bound_y, ymax=max_bound_y, ybincount=numBins, ytitle="Mean", yunits="MPa", ztitle="damage", zunits="Count") mat.SetAttributes(atts) for i in range(len(bin_centers_x)): for j in range(len(bin_centers_y)): mat.IncXYBin(i,j,bin_sums[i,j]) hiout.PutMatrix(0,mat) hiout.SetChanNumber(0,1) hiout.SetChanTitle(0,"Damage Matrix") return ''