'Custom Machines - Stress Difference' simulation project by BenLewis


I created a new simulation project called 'Custom Machines - Stress Difference':

This project demonstrates the use of a Paraview programmable filter to calculate the difference in stress between two time steps.

More of my public projects can be found here.



This project demonstrates the use of a Paraview programmable filter to calculate the difference in stress between two time steps. This is useful when investigating fatigue and the simulation requires both static and cyclic loading. While the static loading is required, one is generally interested in the stress due to cyclic loading only. Using this filter, the cyclic stress can be extracted from the results.


The geometry for this simulation was obtained from GrabCAD user Stasia Kulsa.


The stress difference script is shown below:

# Author: Ben Lewis, Custom Machines
# Date: 2017/04/22

import numpy as np
import vtk
from vtk.numpy_interface import dataset_adapter as dsa

ipd0 = self.GetInputDataObject(0, 0)
ipd1 = self.GetInputDataObject(0, 1)
opd = self.GetOutputDataObject(0)

iter0 = ipd0.NewIterator()

iter1 = ipd1.NewIterator()

while not iter0.IsDoneWithTraversal():
    curInput0 = iter0.GetCurrentDataObject()
    curInput1 = iter1.GetCurrentDataObject()
    curOutput = curInput0.NewInstance()
    opd.SetDataSet(iter0, curOutput)

    cauchy0 = curInput0.GetPointData().GetArray('cauchy stress')
    cauchy1 = curInput1.GetPointData().GetArray('cauchy stress')
    cauchyDiff = np.subtract(cauchy1,cauchy0)
    vtkCauchyDiff = dsa.numpyTovtkDataArray(cauchyDiff)
    vtkCauchyDiff.SetName('cauchy stress diff')

    displ0 = curInput0.GetPointData().GetArray('displacement')
    displ1 = curInput1.GetPointData().GetArray('displacement')
    displDiff = np.subtract(displ1,displ0)
    vtkdisplDiff = dsa.numpyTovtkDataArray(displDiff)
    vtkdisplDiff.SetName('displacement diff')

    vmsDiff = vtk.vtkDoubleArray()
    vmsDiff.SetName("von Mises stress diff")
    vmsSignedDiff = vtk.vtkDoubleArray()
    vmsSignedDiff.SetName("von Mises stress (signed) diff")
    numPoints = curInput0.GetNumberOfPoints()
    for i in range(0, numPoints):
        sixx = cauchyDiff[i][0]
        siyy = cauchyDiff[i][1]
        sizz = cauchyDiff[i][2]
        sixy = cauchyDiff[i][3]
        sixz = cauchyDiff[i][4]
        siyz = cauchyDiff[i][5]
        si_trace = sixx + siyy + sizz
        vms = math.sqrt((math.pow(sixx-siyy,2) + math.pow(siyy-sizz,2) + math.pow(sizz-sixx,2) + 6*(math.pow(sixy,2)+math.pow(sixz,2)+math.pow(siyz,2))) / 2)
        vms_signed = si_trace / abs(si_trace) * vms
        vmsSignedDiff.InsertNextValue( vms_signed )


  1. Create a simulation with multiple time steps. Typically, one time step will be used for static loading and another for cyclic loading. In this example project, time step 1 is used for bolt pre-load and time step 2 is used for combustion pressure.
  2. Add a Results Control Solution Field of type cauchy stress tensor.
  3. Run the simulation and download the results.
  4. In Paraview open the two time step files you wish to compare (e.g. sim_1.vtm and sim_2.vtm). Note, use control+click to open multiple files at once. In the Properties panel click apply.
  5. Control-select the two time step files (sim_1.vtm and sim_2.vtm) and select Filters > Alphabetical > Programmable Filter.
  6. Paste the above script into the Script text box and click apply.
  7. Under Coloring, four new fields will be available:
  • cauchy stress diff
  • displacement diff
  • von Mises stress diff
  • von Mises stress (signed) diff
  1. Apply a WarpByVector Filter (Filters > Alphabetical > WarpByVector).
  2. Under Vectors select the newly created displacement diff vector. For Scale Factor enter a value of 100 and click apply.
  3. Under Colors select von Mises stress (signed) diff. Click Choose Preset and select erdc_iceFire_H.

The result is a plot of the displacement and stress due only to combustion (cyclic stress), the stress due to bolt pre-load (static stress) is removed.


The image below shows all three stress states with a high bolt pre-load. Note the cyclic stress (RHS) is relatively low.

The image below shows all three stress states with a low bolt pre-load. Note the cyclic stress (RHS) is relatively high.

The image below shows the cyclic stress in the bolt for a range of bolt pre-lods. It can be seen that it is important to ensure that bolt pre-load is above a minimum threshold to minimize cyclic stress in the bolt.

For more information on bolted joint theory see this link:

If you need help with fatigue simulations please feel free to contact me:


Thanks for this @BenLewis, maybe this can help me do similar in CFD.

Many thanks,


Hi Darren, please keep me updated. Iā€™d love to see how you can make use of this for CFD.