Skip to main content
Load raw data from a .csv file and run a typical tensile data analysis to extract values for Ultimate Tensile Strength, Young’s Modulus and Elongation at failure. Import the results into Granta MI.

Load data from CSV

The raw Load vs Displacement data is stored in a CSV file. Import the data directly into a DataFrame using the pandas function .read_csv().
Displacement [mm] Load [N]
0 0.000000 0.000
1 0.005282 273.392
2 0.005282 307.173
3 0.006010 331.741
4 0.006738 352.556
The convention in this example is that all properties are in SI units unless otherwise specified. Create a new DataFrame, converting Displacement to SI units and renaming both columns.
Displacement Load
0 0.000000 0.000
1 0.000005 273.392
2 0.000005 307.173
3 0.000006 331.741
4 0.000007 352.556

Process the data

Plot Load-Displacement data

This code snippet is optional, and is included to increase the size of all plots generated in this notebook.
Use matplotlib to plot the Load-Displacement curve. For this plot, we’ve divided df.Load by 1e3 so the y-axis is displayed in kN.
png

Convert Load-Displacement to Stress-Strain

Converting the Load-Displacement curve into Stress-Strain requires the gauge length and area, given here as constants in SI units. In a full workflow, these values can be loaded from a source file. Calculate the Stress and Strain and store as new columns in the DataFrame.
Displacement Load Strain Stress
0 0.000000 0.000 0.000000 0.000000e+00
1 0.000005 273.392 0.000066 1.208322e+07
2 0.000005 307.173 0.000066 1.357626e+07
3 0.000006 331.741 0.000075 1.466210e+07
4 0.000007 352.556 0.000084 1.558207e+07
Now create a plot of Stress-Strain:
png Since the plastic region extends over a large strain range, it is difficult to see detail in the elastic region. Create an inset and plot the elastic and yield region only.
png

Calculate Ultimate tensile strength

Ultimate tensile strength can be calculated by taking the maximum value of the df.Stress column. Calculate and store the tensile strength in SI units and MPa (the latter will be used later).
Previous cell output:
Add a marker and annotation on the stress-strain plot above, showing the location and value of the Ultimate tensile strength.
png

Calculate Young’s modulus

Calculate Young’s modulus by taking the gradient of the Stress-Strain curve between 5% and 25% of the total tensile strength (chordal fit method). There is no interpolation, because the Stress-Strain values closest to the 5% and 25% bounds are used.
Previous cell output:
Add the chordal fit to the inset plot.
png

Calculate 0.2% offset yield stress

The offset yield stress is determined by calculating the intercept between the chordal fit line and the stress response. First add the offset chordal fit line to the plot, to show where the yield stress lies.
png Calculate the difference between the solid blue and dotted black lines, then find the values immediately before and after the intercept. Perform a linear interpolation to find the exact value of the yield stress.
Previous cell output:
Plot the 0.2% offset yield stress on the Stress-Strain plot. This time, plot the marker on both the full and inset axes, and annotate the inset.
png

Calculate Elongation at failure

The data has been pre-processed before import, so the last point in the data series is the failure point.
Previous cell output:
Plot the Elongation at failure on the full-range axes, and add a line between the failure point and the elongation value. The legend updates to include all lines on both sets of axes.
png

Calculate True Stress-Strain

Since there is a 1:1 relationship between engineering and true stress-strain values, True Stress-Strain is added to the DataFrame as additional columns.
Displacement Load Strain Stress find_intercept True_Strain True_Stress
0 0.000000 0.000 0.000000 0.000000e+00 4.093098e+08 0.000000 0.000000e+00
1 0.000005 273.392 0.000066 1.208322e+07 4.078764e+08 0.000066 1.208402e+07
2 0.000005 307.173 0.000066 1.357626e+07 4.093694e+08 0.000066 1.357715e+07
3 0.000006 331.741 0.000075 1.466210e+07 4.085924e+08 0.000075 1.466320e+07
4 0.000007 352.556 0.000084 1.558207e+07 4.076494e+08 0.000084 1.558338e+07
Create a new plot to compare Engineering and True Stress-Strain.
png

Calculate True Stress-True Plastic Strain

Create a new DataFrame to store the True Stress-True Plastic Strain, since the x axis is different to Stress-Strain.
Strain Stress
0 0.000000 3.355557e+08
1 0.000008 3.370594e+08
2 0.000029 3.374152e+08
3 0.000050 3.377409e+08
4 0.000067 3.380495e+08
Plot True Stress-True Plastic Strain. Force the x limit to be 0, but not the y limit (the curve starts at the Yield stress).
png

Import data and results into Granta MI

Finally, import the raw data, processed data and results into a new Granta MI record. Connect to Granta MI and specify a database and table.
Create a new record to import the data into, using datetime.now() to ensure the record name is unique. At this stage, the record has only been created in the MI Scripting Toolkit. The changes will be pushed to Granta MI when session.update() is called at the end of the notebook.

Create and populate point attributes

Define a function to write a dict of attribute name-value pairs to point attributes on the record. Each dict will contain values with a single unit.
Build the dicts of attribute name-value pairs and call the function above on each. (The strain values are dimensionless but will be imported as a percentage, so they are multiplied by 100 before import.)

Create and populate text attributes

Define a similar function for text attributes:
Define the dict of text attributes, and call the function above. We’ve defined the attribute values manually, but they could easily be read from the source file.

Create and populate functional attributes

Finally, define a function to import functional attributes.
Call the function for each curve generated in this script.

Write your changes to Granta MI

Previous cell output: