Material Properties and Tabular Data

This example demonstrates scripting interaction with Engineering Data to access, create, and modify material property data. In this example, you have experimental total strain/stress data in a text file that you wish to use to define Multilinear Isotropic Hardening property data for a material. After you extract the ScriptingGuideExamples.zip file, you will find the files for this example in the Material_Tabular_Data directory.

As an additional consideration, the Multilinear Isotropic Hardening property data in Engineering Data is defined in terms of plastic strain. The script must first convert the total strain data to plastic strain, using the relationship:

Plastic Strain = Total Strain – Stress/Young’s Modulus

The above consideration will be used to demonstrate calculations based on physical quantities and units.

To automate property creation, you will write a script that performs the following operations:

  1. Create a system for a Static Structural analysis and access the data container for Engineering Data.

  2. Load material data for Polyethylene. By default, this material does not include property data for Multilinear Isotropic Hardening.

  3. Read experimental data from a text file and generate lists of data for the necessary variables (converting Total Strain to Plastic Strain)

  4. Create the Multilinear Isotropic Hardening property within Polyethylene and set its data table.

Sample Data File

The sample data file to be used in this example follows:

#
# Stress Stain Data for the Material Properties scripting example.
#
# The data is Total Strain (in m m^-1), Stress (in MPa)
#
7.33E-02, 80.6
1.80E-01, 88.0
6.30E-01, 142.5
7.53E-01, 168.0
8.70E-01, 187.0

Workbench Script

The script for this example follows. Each line is numbered for reference in the discussion that follows.

1 	workDir = "ScriptingGuideExamples\Material_Tabular_Data/"
2 
3 	# Create an Engineering Data system and access its data container
4 	template1 = GetTemplate(
5 	    TemplateName="Static Structural",
6 	    Solver="ANSYS")
7 	system1 = template1.CreateSystem()
8 	engineeringData1 = system1.GetContainer(ComponentName="Engineering Data")
9 
10	# Import Polyethylene
11	poly = engineeringData1.ImportMaterial(
12	    Name="Polyethylene",
13	    Source="General_Materials.xml")    
14
15	# Initialize lists for variable values
16	temperature = []
17	strain = []
18	stress = []
19
20	# Get the value of Young's Modulus for use in the Total/Plastic strain calculation.
21	# Material Property data is always returned as a Quantity.
22	elasticity = poly.GetProperty(Name="Elasticity")
23	E = elasticity.GetData(Variables="Young's Modulus")
24
25	# Read the data file and create lists for Temperature, Strain and Stress values
26	# We must convert Total Strain in the data file into Plastic Strain
27	fileName = AbsUserPathName(workDir + "StressStrainData.txt")
28	dataFile = open(fileName,"r")
29	for line in dataFile:
30	    # Skip comment lines
31	    if line.startswith("#"):
32	       continue
33	       
34	    # Split at the comma to get strain, stress
35	    (thisStrain, thisStress) = line.split(",")
36	    
37	    # Convert the data into Quantities with Units.
38	    thisStrain = Quantity(float(thisStrain),"m m^-1")
39	    thisStress = Quantity(float(thisStress),"MPa")
40	    
41	    # Append data to the variable lists (converting total strain to plastic strain)
42	    temperature.append(0)
43	    calcStrain = thisStrain - thisStress/E
44	    if calcStrain.Value < 1e-4:
45	        calcStrain = Quantity(0.0,"m m^-1")
46	    strain.append(calcStrain)
47	    stress.append(thisStress)
48
49	# Create the Multilinear Isotropic Hardening property and set the data for it
50	miso = poly.CreateProperty(
51	    Name="Isotropic Hardening",
52	    Definition="Multilinear")
53	miso.SetData(    
54	    SheetName="Isotropic Hardening",
55	    SheetQualifiers={"Definition Method": "Multilinear"},
56	    Variables = ["Temperature","Plastic Strain","Stress"],
57	    Values = [temperature, strain, stress])
58	    
59	# Save the project
60	Save(
61	    FilePath=AbsUserPathName(workDir + "TabularData.wbpj"),
62	    Overwrite=True)

Discussion

This example demonstrates interaction with Engineering Data to get, create, and set material properties. It also demonstrates calculations involving quantities and units. The following discussion refers to the specified line numbers of the example script to illustrate some of these concepts and constructs. Discussion points from earlier examples will not be repeated here.

Lines 1-13

To set the project up to work with Polyethylene, the script creates a new Static Structural system, access its Engineering Data container, and load material data from the General Materials library.

Lines 15-18

Interaction with tabular data is done in terms of the variables that make up the data table. Each variable represents a column in the table, with a list of data for the variable. Here the script initializes three lists for temperature, strain and stress data. Multilinear Isotropic Hardening property data can be temperature-dependent, and temperature is a required variable in the data table. Because the data is not temperature-dependent, you will use the same value of temperature (0 [C]) at each strain/stress point.

Lines 20-23

Because the calculation for plastic strain depends on Young's Modulus, you use the GetData() method to get the Young’s Modulus value from the elasticity property. Within Engineering Data, all property values are stored and returned as quantities, which include both a numeric value and a unit. See Lines 35-41 for further discussion on quantities and units.

Lines 25-32

Here the script opens the text data file and reads each line one at a time. If the line begins with a comment character '#', the script continues to the next line in the file.

Lines 34-35

The Python split() function is used to break the comma delimited line and return the separate values into variables for strain and stress.

Lines 37-39

In this example, you are creating explicit unit-based quantities for stress and strain values to ensure dimensional and unit consistency in later calculations.

Material property data (or any other quantity data) can be set either as a quantity (with value and units) or as a simple numeric value. For more information, see Specifying Quantities Without Units. If a numeric value is supplied, the units are assumed to be the same as the current project units for the variable. It is the script writer’s responsibility to ensure the numeric data and project units are consistent.

Line 43-45

Because temperature is a simple constant value, temperature is specirfied as a numeric value (without units), and the units are taken from the current project unit system. The script appends 0 into the list of temperature data for this strain/stress pair.

Line 46

Here the script calculates plastic strain based on the available quantities and appends it to the variable list. Mathematical operations involving quantities enforce dimensional consistency and automatically perform unit conversion as necessary to generate a consistent result.

Line 47

Stress data is also appended to the appropriate list.

Lines 50-52

A new property for Multilinear Isotropic Hardening is created within Polyethylene.

Lines 53-57

The SetData() method is used to set single value or tabular data for material properties. Some properties can contain more than one data table, so the SheetName and SheetQualifiers arguments are used to specify the exact data table to be accessed. The Variables argument specifies one or more variables in the table to be set. The Values argument specifies the values that correspond to each variable.

Lines 59-62

Finally the script saves the project, overwriting if one already exists.