Skip to content

Commit dba7d66

Browse files
committed
added documentation
1 parent 8d9747f commit dba7d66

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

python/damask/_vtk.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,20 @@ def from_image_data(cells: IntSequence,
232232
-------
233233
new : damask.VTK
234234
VTK-based geometry without nodal or cell data.
235+
236+
Examples
237+
--------
238+
Create image data with larger spacing along z-direction:
239+
240+
>>> import damask
241+
>>> cells = (16,8,4)
242+
>>> size = (1.0,0.5,.4)
243+
>>> print(v := damask.VTK.from_image_data(cells=cells,size=size))
244+
vtkImageData
245+
<BLANKLINE>
246+
# cells: 512
247+
<BLANKLINE>
248+
# points: 765
235249
"""
236250
vtk_data = vtkImageData()
237251
vtk_data.SetDimensions(*(np.array(cells)+1))
@@ -267,6 +281,21 @@ def from_unstructured_grid(nodes: np.ndarray,
267281
-------
268282
new : damask.VTK
269283
VTK-based geometry without nodal or cell data.
284+
285+
Examples
286+
--------
287+
Create a first-order tetrahedron:
288+
289+
>>> import damask
290+
>>> import numpy as np
291+
>>> nodes = np.array([[0,0,0],[1,0,0],[1,1,0],[0,0,1]])
292+
>>> connectivity = np.array([[0,1,2,3]])
293+
>>> print(v := damask.VTK.from_unstructured_grid(nodes,connectivity,'TETRAHEDRON'))
294+
vtkUnstructuredGrid
295+
<BLANKLINE>
296+
# cells: 1
297+
<BLANKLINE>
298+
# points: 4
270299
"""
271300
vtk_nodes = vtkPoints()
272301
vtk_nodes.SetData(numpy_to_vtk(np.ascontiguousarray(nodes)))
@@ -529,6 +558,24 @@ def set(self,
529558
Notes
530559
-----
531560
If the number of cells equals the number of points, the data is added to both.
561+
562+
563+
Examples
564+
--------
565+
Add a constant tensor field called 'F' to image data:
566+
567+
>>> import numpy as np
568+
>>> import damask
569+
>>> cells = (16,8,16)
570+
>>> size = (1.0,0.5,1.0)
571+
>>> v = damask.VTK.from_image_data(cells=cells,size=size)
572+
>>> print(v := v.set(label='F',data=np.broadcast_to(np.eye(3),(np.prod(cells),3,3))))
573+
vtkImageData
574+
<BLANKLINE>
575+
# cells: 2048
576+
- F
577+
<BLANKLINE>
578+
# points: 2601
532579
"""
533580

534581
def _add_array(vtk_data,

0 commit comments

Comments
 (0)