## Introduction

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.

## Geometry

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

https://grabcad.com/library/engine-195

## Script

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)
opd.CopyStructure(ipd0)
iter0 = ipd0.NewIterator()
iter0.UnRegister(None)
iter0.InitTraversal()
iter1 = ipd1.NewIterator()
iter1.UnRegister(None)
iter1.InitTraversal()
while not iter0.IsDoneWithTraversal():
curInput0 = iter0.GetCurrentDataObject()
curInput1 = iter1.GetCurrentDataObject()
curOutput = curInput0.NewInstance()
curOutput.UnRegister(None)
opd.SetDataSet(iter0, curOutput)
curOutput.ShallowCopy(curInput1)
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)
vmsDiff.InsertNextValue(vms)
vms_signed = si_trace / abs(si_trace) * vms
vmsSignedDiff.InsertNextValue( vms_signed )
curOutput.GetPointData().AddArray(vtkCauchyDiff)
curOutput.GetPointData().AddArray(vtkdisplDiff)
curOutput.GetPointData().AddArray(vmsDiff)
curOutput.GetPointData().AddArray(vmsSignedDiff)
iter0.GoToNextItem()
iter1.GoToNextItem()
```

## Instructions

- 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.
- Add a Results Control Solution Field of type
**cauchy stress tensor**.

- Run the simulation and download the results.
- 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.

- Control-select the two time step files (
**sim_1.vtm** and **sim_2.vtm**) and select Filters > Alphabetical > Programmable Filter.
- Paste the above script into the Script text box and click
**apply**.

- Under
**Coloring**, four new fields will be available:

- cauchy stress diff
- displacement diff
- von Mises stress diff
- von Mises stress (signed) diff

- Apply a WarpByVector Filter (Filters > Alphabetical > WarpByVector).
- Under
**Vectors** select the newly created **displacement diff** vector. For Scale Factor enter a value of 100 and click **apply**.
- 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.

## Results

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:

https://en.wikipedia.org/wiki/Bolted_joint

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

https://www.simscale.com/custom-machines/