FEM: Prevent invalid index for data extraction
This commit is contained in:
@@ -168,6 +168,10 @@ class PostIndexOverFrames1D(base_fempostextractors.Extractor1D):
|
||||
dataset = algo.GetOutputDataObject(0)
|
||||
array = self._x_array_from_dataset(obj, dataset, copy=False)
|
||||
|
||||
# safeguard for invalid access
|
||||
if idx < 0 or array.GetNumberOfTuples()-1 < idx:
|
||||
raise Exception(f"Invalid index: {idx} is not in range 0 - {array.GetNumberOfTuples()-1}")
|
||||
|
||||
if not setup:
|
||||
frame_array.SetNumberOfComponents(array.GetNumberOfComponents())
|
||||
frame_array.SetNumberOfTuples(len(timesteps))
|
||||
@@ -179,6 +183,10 @@ class PostIndexOverFrames1D(base_fempostextractors.Extractor1D):
|
||||
dataset = algo.GetOutputDataObject(0)
|
||||
array = self._x_array_from_dataset(obj, dataset, copy=False)
|
||||
|
||||
# safeguard for invalid access
|
||||
if idx < 0 or array.GetNumberOfTuples()-1 < idx:
|
||||
raise Exception(f"Invalid index: {idx} is not in range 0 - {array.GetNumberOfTuples()-1}")
|
||||
|
||||
frame_array.SetNumberOfComponents(array.GetNumberOfComponents())
|
||||
frame_array.SetNumberOfTuples(1)
|
||||
frame_array.SetTuple(0, idx, array)
|
||||
|
||||
@@ -197,6 +197,11 @@ class PostIndexOverFrames2D(base_fempostextractors.Extractor2D):
|
||||
algo.UpdateTimeStep(timestep)
|
||||
dataset = algo.GetOutputDataObject(0)
|
||||
array = self._y_array_from_dataset(obj, dataset, copy=False)
|
||||
|
||||
# safeguard for invalid access
|
||||
if idx < 0 or array.GetNumberOfTuples()-1 < idx:
|
||||
raise Exception(f"Invalid index: {idx} is not in range 0 - {array.GetNumberOfTuples()-1}")
|
||||
|
||||
if not setup:
|
||||
frame_y_array.SetNumberOfComponents(array.GetNumberOfComponents())
|
||||
frame_y_array.SetNumberOfTuples(len(timesteps))
|
||||
@@ -213,6 +218,10 @@ class PostIndexOverFrames2D(base_fempostextractors.Extractor2D):
|
||||
dataset = algo.GetOutputDataObject(0)
|
||||
array = self._y_array_from_dataset(obj, dataset, copy=False)
|
||||
|
||||
# safeguard for invalid access
|
||||
if idx < 0 or array.GetNumberOfTuples()-1 < idx:
|
||||
raise Exception(f"Invalid index: {idx} is not in range 0 - {array.GetNumberOfTuples()-1}")
|
||||
|
||||
frame_y_array.SetNumberOfComponents(array.GetNumberOfComponents())
|
||||
frame_y_array.SetNumberOfTuples(1)
|
||||
frame_y_array.SetTuple(0, idx, array)
|
||||
|
||||
Reference in New Issue
Block a user