Hi,
I have velocity field data, is there a way to use existing filters to calculate the acceleration field?
Hi,
I have velocity field data, is there a way to use existing filters to calculate the acceleration field?
HI @ebreard
This is possible but way complex than it should be.
If the timesteps progression is linear (eg: 0.1, 0.2, 0.3), you can use TemporalShiftScale to shift your timesteps and then PythonCalculator to compare between timesteps and do the computation.
If not, then it can only be done one timestep at a time, using ForceTime or TemporalArrayOperator.
Hth,
Thanks, is there no plan to add this as a filter? Lots of folks would be using it
Not yet, one would need to invest some time or funding in order to get this going.
You can also open a feature request here:
created this “programmable filter” that calculates the temporal derivative of a Gas_Velocity vector (acceleration). The input data was cell data, then I used the CelltoPoint data, and to that layer applied the programmable filter with the following code:
import numpy as np
from vtk.util.numpy_support import numpy_to_vtk
# Current velocity data (vector)
velocity_current = inputs[0].PointData['Gas_Velocity']
# Current simulation time
current_time = self.GetInputDataObject(0, 0).GetInformation().Get(vtk.vtkDataObject.DATA_TIME_STEP())
# Check if previous velocity data is available (not first timestep)
if hasattr(self, 'prev_velocity'):
dt = current_time - self.prev_time
if dt <= 0:
dt = 0.001 # Fallback timestep (1 ms for 1000 Hz data)
dv_dt = (velocity_current - self.prev_velocity) / dt
else:
dv_dt = np.zeros_like(velocity_current) # Zero initial derivative
# Add derivative to output
vtk_dv_dt = numpy_to_vtk(dv_dt, deep=True)
vtk_dv_dt.SetName('GasAcceleration')
output.PointData.AddArray(vtk_dv_dt)
# Store current timestep for next iteration
self.prev_velocity = velocity_current.copy()
self.prev_time = current_time
works well
here is an example of temporal derivative on Cell data for an array:
import numpy as np
from vtk.util.numpy_support import numpy_to_vtk
import vtk
# Access the current timestep's cell data
P_G_current = inputs[0].CellData['P_G']
# Get current simulation time
current_time = self.GetInputDataObject(0, 0).GetInformation().Get(vtk.vtkDataObject.DATA_TIME_STEP())
if hasattr(self, 'prev_PG'):
dt = current_time - self.prev_time
if dt <= 0:
dt = 0.001 # fallback for 1000Hz data
dPG_dt = (P_G_current - self.prev_PG) / dt
else:
dPG_dt = np.zeros_like(P_G_current)
# Convert numpy array explicitly to VTK format
vtk_dPG_dt = numpy_to_vtk(dPG_dt, deep=True)
vtk_dPG_dt.SetName('P_G_TemporalDerivative')
# Add the array as Cell Data (since original data is cell-based)
output.CellData.AddArray(vtk_dPG_dt)
# Store current values for next timestep
self.prev_PG = P_G_current.copy()
self.prev_time = current_time