Defining Flow Stress from Interpolated Data - Using Lambda Functions
In this notebook it is shown, how to define a flow stress function from interpolated data using the interpolation functions from scipy.
The concept can be transferred to any other material data as well.
This notebook is essentially the same as Interpolating_Flow_Stress.ipynb, with one main difference: we will use lambda functions as hook values instead of real hook implementations. This is appropriate for usage in input files and for quick testing purposes, plugins shall and can not use this approach.
First, we need to import some packages.
importpyroll.basicaspr# PyRolL itselfimportpandasaspd# pandas for data importimportnumpyasnp# numpy for numeric calculationsimportscipy.interpolateasinterpolate# scipy.interpolate for interpolations
We import the data to interpolate from a CSV file using pandas. The result is a dataframe containing all data from the file. Note, that the column names are derived from the first row of the file.
Here comes the difference, we do not define hook implementations, but give the interpolation function directly to the in profile.
The flow_stress hook is the main hook for calculation flow stress, it returns the flow stress depending on the current state of the profile.
Another hook regarding flow stress is flow_stress_function. It returns a function of the classic flow stress parameters strain, strain rate and temperature to enable plugins to calculate their own variations of flow stress.
Here it needs a nested lambda function to be defined.
Lets run the solution procedure of the roll pass.
We see no errors claiming that a flow stress value is missing.
pass1.solve(in_profile)
Profile
classifiers
{'generic_elongation', 'diamond'}
cross_section
Polygon
area
0.0018470652317200606
height
0.0447243903911893
perimeter
0.1684260697843319
width
0.06560167360406856
cross_section_error
-0.0360789946906479
cross_section_filling_ratio
0.9639210053093521
density
7500.0
filling_error
-0.143021899359
filling_ratio
0.856978100641
flow_stress
<function <lambda> at 0x7f0a6a25f6d0>
flow_stress_function
<function <lambda> at 0x7f0a6a25d7e0>
length
0.0
specific_heat_capacity
690
strain
0.19349552465258638
t
0.07056039637464354
temperature
1369.19933374975
Lets check, if our new hooks are really used. We check that the flow stress value stored in the out profile of the pass is numerically equal to a manually calculated value using the respective strain.
If everything went fine, we shall se no output of this statement, otherwise an error message.