Skip to content

Commit 488306a

Browse files
authored
Merge pull request #17 from MuellerSeb/field_data
Enhancement: Field data export
2 parents fcfc346 + 2dcbedc commit 488306a

File tree

15 files changed

+1197
-652
lines changed

15 files changed

+1197
-652
lines changed

evtk/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
from pyevtk import *
22

33
import warnings
4-
warnings.warn('the "evtk" package is deprecated, use "pyevtk" instead', DeprecationWarning)
4+
5+
warnings.warn(
6+
'the "evtk" package is deprecated, use "pyevtk" instead',
7+
DeprecationWarning,
8+
)

examples/group.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#! /usr/bin/env python
22

33
# ***********************************************************************************
4-
# * Copyright 2010 - 2016 Paulo A. Herrera. All rights reserved. *
4+
# * Copyright 2010 - 2016 Paulo A. Herrera. All rights reserved. *
55
# * *
66
# * Redistribution and use in source and binary forms, with or without *
77
# * modification, are permitted provided that the following conditions are met: *
@@ -33,8 +33,8 @@
3333
from pyevtk.vtk import VtkGroup
3434

3535
g = VtkGroup("./group")
36-
g.addFile(filepath = "sim0000.vtu", sim_time = 0.0)
37-
g.addFile(filepath = "sim0001.vtu", sim_time = 1.0)
38-
g.addFile(filepath = "sim0002.vtu", sim_time = 2.0)
39-
g.addFile(filepath = "sim0003.vtu", sim_time = 3.0)
36+
g.addFile(filepath="sim0000.vtu", sim_time=0.0)
37+
g.addFile(filepath="sim0001.vtu", sim_time=1.0)
38+
g.addFile(filepath="sim0002.vtu", sim_time=2.0)
39+
g.addFile(filepath="sim0003.vtu", sim_time=3.0)
4040
g.save()

examples/image.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#! /usr/bin/env python
22

33
# ***********************************************************************************
4-
# * Copyright 2010 - 2016 Paulo A. Herrera. All rights reserved. *
4+
# * Copyright 2010 - 2016 Paulo A. Herrera. All rights reserved. *
55
# * *
66
# * Redistribution and use in source and binary forms, with or without *
77
# * modification, are permitted provided that the following conditions are met: *
@@ -38,19 +38,21 @@
3838
npoints = (nx + 1) * (ny + 1) * (nz + 1)
3939

4040
# Variables
41-
pressure = np.random.rand(ncells).reshape( (nx, ny, nz), order = 'C')
42-
temp = np.random.rand(npoints).reshape( (nx + 1, ny + 1, nz + 1))
41+
pressure = np.random.rand(ncells).reshape((nx, ny, nz), order="C")
42+
temp = np.random.rand(npoints).reshape((nx + 1, ny + 1, nz + 1))
4343

44-
imageToVTK("./image", cellData = {"pressure" : pressure}, pointData = {"temp" : temp} )
44+
imageToVTK(
45+
"./image", cellData={"pressure": pressure}, pointData={"temp": temp}
46+
)
4547

46-
fluxx = np.random.rand(ncells).reshape( (nx, ny, nz), order='F')
47-
fluxy = np.random.rand(ncells).reshape( (nx, ny, nz), order='F')
48-
fluxz = np.random.rand(ncells).reshape( (nx, ny, nz), order='F')
48+
fluxx = np.random.rand(ncells).reshape((nx, ny, nz), order="F")
49+
fluxy = np.random.rand(ncells).reshape((nx, ny, nz), order="F")
50+
fluxz = np.random.rand(ncells).reshape((nx, ny, nz), order="F")
4951
flux = (fluxx, fluxy, fluxz)
5052

51-
Efieldx = np.random.rand(npoints).reshape( (nx + 1, ny + 1, nz + 1), order='F')
52-
Efieldy = np.random.rand(npoints).reshape( (nx + 1, ny + 1, nz + 1), order='F')
53-
Efieldz = np.random.rand(npoints).reshape( (nx + 1, ny + 1, nz + 1), order='F')
54-
Efield = (Efieldx,Efieldy,Efieldz)
53+
Efieldx = np.random.rand(npoints).reshape((nx + 1, ny + 1, nz + 1), order="F")
54+
Efieldy = np.random.rand(npoints).reshape((nx + 1, ny + 1, nz + 1), order="F")
55+
Efieldz = np.random.rand(npoints).reshape((nx + 1, ny + 1, nz + 1), order="F")
56+
Efield = (Efieldx, Efieldy, Efieldz)
5557

56-
imageToVTK("./image", cellData={"flux" : flux}, pointData = {"Efield" : Efieldx} )
58+
imageToVTK("./image", cellData={"flux": flux}, pointData={"Efield": Efieldx})

examples/lines.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@
4848
x[2], y[2], z[2] = 0.0, 0.0, 0.0
4949
x[3], y[3], z[3] = -1.0, 1.0, 1.0
5050

51-
linesToVTK("./lines", x, y, z, cellData = {"vel" : vel}, pointData = {"temp" : temp, "pressure" : pressure})
52-
53-
51+
linesToVTK(
52+
"./lines",
53+
x,
54+
y,
55+
z,
56+
cellData={"vel": vel},
57+
pointData={"temp": temp, "pressure": pressure},
58+
)

examples/lowlevel.py

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#! /usr/bin/env python
22

33
# ***********************************************************************************
4-
# * Copyright 2010 - 2016 Paulo A. Herrera. All rights reserved *
4+
# * Copyright 2010 - 2016 Paulo A. Herrera. All rights reserved *
55
# * *
66
# * Redistribution and use in source and binary forms, with or without *
77
# * modification, are permitted provided that the following conditions are met: *
@@ -34,45 +34,44 @@
3434

3535
nx, ny, nz = 6, 6, 2
3636
lx, ly, lz = 1.0, 1.0, 1.0
37-
dx, dy, dz = lx/nx, ly/ny, lz/nz
37+
dx, dy, dz = lx / nx, ly / ny, lz / nz
3838
ncells = nx * ny * nz
3939
npoints = (nx + 1) * (ny + 1) * (nz + 1)
40-
x = np.arange(0, lx + 0.1*dx, dx, dtype='float64')
41-
y = np.arange(0, ly + 0.1*dy, dy, dtype='float64')
42-
z = np.arange(0, lz + 0.1*dz, dz, dtype='float64')
43-
start, end = (0,0,0), (nx, ny, nz)
40+
x = np.arange(0, lx + 0.1 * dx, dx, dtype="float64")
41+
y = np.arange(0, ly + 0.1 * dy, dy, dtype="float64")
42+
z = np.arange(0, lz + 0.1 * dz, dz, dtype="float64")
43+
start, end = (0, 0, 0), (nx, ny, nz)
4444

4545
w = VtkFile("./evtk_test", VtkRectilinearGrid)
46-
w.openGrid(start = start, end = end)
47-
w.openPiece( start = start, end = end)
46+
w.openGrid(start=start, end=end)
47+
w.openPiece(start=start, end=end)
4848

4949
# Point data
5050
temp = np.random.rand(npoints)
51-
vx = vy = vz = np.zeros([nx + 1, ny + 1, nz + 1], dtype="float64", order = 'F')
52-
w.openData("Point", scalars = "Temperature", vectors = "Velocity")
51+
vx = vy = vz = np.zeros([nx + 1, ny + 1, nz + 1], dtype="float64", order="F")
52+
w.openData("Point", scalars="Temperature", vectors="Velocity")
5353
w.addData("Temperature", temp)
54-
w.addData("Velocity", (vx,vy,vz))
54+
w.addData("Velocity", (vx, vy, vz))
5555
w.closeData("Point")
5656

5757
# Cell data
58-
pressure = np.zeros([nx, ny, nz], dtype="float64", order='F')
59-
w.openData("Cell", scalars = "Pressure")
58+
pressure = np.zeros([nx, ny, nz], dtype="float64", order="F")
59+
w.openData("Cell", scalars="Pressure")
6060
w.addData("Pressure", pressure)
6161
w.closeData("Cell")
6262

6363
# Coordinates of cell vertices
6464
w.openElement("Coordinates")
65-
w.addData("x_coordinates", x);
66-
w.addData("y_coordinates", y);
67-
w.addData("z_coordinates", z);
68-
w.closeElement("Coordinates");
65+
w.addData("x_coordinates", x)
66+
w.addData("y_coordinates", y)
67+
w.addData("z_coordinates", z)
68+
w.closeElement("Coordinates")
6969

7070
w.closePiece()
7171
w.closeGrid()
7272

73-
w.appendData(data = temp)
74-
w.appendData(data = (vx,vy,vz))
75-
w.appendData(data = pressure)
73+
w.appendData(data=temp)
74+
w.appendData(data=(vx, vy, vz))
75+
w.appendData(data=pressure)
7676
w.appendData(x).appendData(y).appendData(z)
7777
w.save()
78-

examples/points.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#! /usr/bin/env python
22

33
# ***********************************************************************************
4-
# * Copyright 2010 - 2016 Paulo A. Herrera. All rights reserved. *
4+
# * Copyright 2010 - 2016 Paulo A. Herrera. All rights reserved. *
55
# * *
66
# * Redistribution and use in source and binary forms, with or without *
77
# * modification, are permitted provided that the following conditions are met: *
@@ -39,11 +39,10 @@
3939
z = np.random.rand(npoints)
4040
pressure = np.random.rand(npoints)
4141
temp = np.random.rand(npoints)
42-
pointsToVTK("./rnd_points", x, y, z, data = {"temp" : temp, "pressure" : pressure})
42+
pointsToVTK("./rnd_points", x, y, z, data={"temp": temp, "pressure": pressure})
4343

4444
# Example 2
45-
x = np.arange(1.0,10.0,0.1)
46-
y = np.arange(1.0,10.0,0.1)
47-
z = np.arange(1.0,10.0,0.1)
48-
pointsToVTK("./line_points", x, y, z, data = {"elev" : z})
49-
45+
x = np.arange(1.0, 10.0, 0.1)
46+
y = np.arange(1.0, 10.0, 0.1)
47+
z = np.arange(1.0, 10.0, 0.1)
48+
pointsToVTK("./line_points", x, y, z, data={"elev": z})

examples/poly_lines.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@
6161
vel[0:3] = 1.0
6262
vel[4:6] = 5.0
6363

64-
polyLinesToVTK("./poly_lines", x, y, z, pointsPerLine = pointsPerLine, cellData = {"vel" : vel}, pointData = {"temp" : temp, "pressure" : pressure})
65-
66-
64+
polyLinesToVTK(
65+
"./poly_lines",
66+
x,
67+
y,
68+
z,
69+
pointsPerLine=pointsPerLine,
70+
cellData={"vel": vel},
71+
pointData={"temp": temp, "pressure": pressure},
72+
)

examples/rectilinear.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#! /usr/bin/env python
22

33
# ***********************************************************************************
4-
# * Copyright 2010 - 2016 Paulo A. Herrera. All rights reserved. *
4+
# * Copyright 2010 - 2016 Paulo A. Herrera. All rights reserved. *
55
# * *
66
# * Redistribution and use in source and binary forms, with or without *
77
# * modification, are permitted provided that the following conditions are met: *
@@ -36,18 +36,25 @@
3636
# Dimensions
3737
nx, ny, nz = 6, 6, 2
3838
lx, ly, lz = 1.0, 1.0, 1.0
39-
dx, dy, dz = lx/nx, ly/ny, lz/nz
39+
dx, dy, dz = lx / nx, ly / ny, lz / nz
4040

4141
ncells = nx * ny * nz
4242
npoints = (nx + 1) * (ny + 1) * (nz + 1)
4343

4444
# Coordinates
45-
x = np.arange(0, lx + 0.1*dx, dx, dtype='float64')
46-
y = np.arange(0, ly + 0.1*dy, dy, dtype='float64')
47-
z = np.arange(0, lz + 0.1*dz, dz, dtype='float64')
45+
x = np.arange(0, lx + 0.1 * dx, dx, dtype="float64")
46+
y = np.arange(0, ly + 0.1 * dy, dy, dtype="float64")
47+
z = np.arange(0, lz + 0.1 * dz, dz, dtype="float64")
4848

4949
# Variables
50-
pressure = np.random.rand(ncells).reshape( (nx, ny, nz))
51-
temp = np.random.rand(npoints).reshape( (nx + 1, ny + 1, nz + 1))
52-
53-
gridToVTK("./rectilinear", x, y, z, cellData = {"pressure" : pressure}, pointData = {"temp" : temp})
50+
pressure = np.random.rand(ncells).reshape((nx, ny, nz))
51+
temp = np.random.rand(npoints).reshape((nx + 1, ny + 1, nz + 1))
52+
53+
gridToVTK(
54+
"./rectilinear",
55+
x,
56+
y,
57+
z,
58+
cellData={"pressure": pressure},
59+
pointData={"temp": temp},
60+
)

examples/structured.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#! /usr/bin/env python
22

33
# ***********************************************************************************
4-
# * Copyright 2010 - 2016 Paulo A. Herrera. All rights reserved. *
4+
# * Copyright 2010 - 2016 Paulo A. Herrera. All rights reserved. *
55
# * *
66
# * Redistribution and use in source and binary forms, with or without *
77
# * modification, are permitted provided that the following conditions are met: *
@@ -37,15 +37,15 @@
3737
# Dimensions
3838
nx, ny, nz = 6, 6, 2
3939
lx, ly, lz = 1.0, 1.0, 1.0
40-
dx, dy, dz = lx/nx, ly/ny, lz/nz
40+
dx, dy, dz = lx / nx, ly / ny, lz / nz
4141

4242
ncells = nx * ny * nz
4343
npoints = (nx + 1) * (ny + 1) * (nz + 1)
4444

4545
# Coordinates
46-
X = np.arange(0, lx + 0.1*dx, dx, dtype='float64')
47-
Y = np.arange(0, ly + 0.1*dy, dy, dtype='float64')
48-
Z = np.arange(0, lz + 0.1*dz, dz, dtype='float64')
46+
X = np.arange(0, lx + 0.1 * dx, dx, dtype="float64")
47+
Y = np.arange(0, ly + 0.1 * dy, dy, dtype="float64")
48+
Z = np.arange(0, lz + 0.1 * dz, dz, dtype="float64")
4949

5050
x = np.zeros((nx + 1, ny + 1, nz + 1))
5151
y = np.zeros((nx + 1, ny + 1, nz + 1))
@@ -56,12 +56,19 @@
5656
for k in range(nz + 1):
5757
for j in range(ny + 1):
5858
for i in range(nx + 1):
59-
x[i,j,k] = X[i] + (0.5 - rnd.random()) * 0.1 * dx
60-
y[i,j,k] = Y[j] + (0.5 - rnd.random()) * 0.1 * dy
61-
z[i,j,k] = Z[k] + (0.5 - rnd.random()) * 0.1 * dz
59+
x[i, j, k] = X[i] + (0.5 - rnd.random()) * 0.1 * dx
60+
y[i, j, k] = Y[j] + (0.5 - rnd.random()) * 0.1 * dy
61+
z[i, j, k] = Z[k] + (0.5 - rnd.random()) * 0.1 * dz
6262

6363
# Variables
64-
pressure = np.random.rand(ncells).reshape( (nx, ny, nz))
65-
temp = np.random.rand(npoints).reshape( (nx + 1, ny + 1, nz + 1))
64+
pressure = np.random.rand(ncells).reshape((nx, ny, nz))
65+
temp = np.random.rand(npoints).reshape((nx + 1, ny + 1, nz + 1))
6666

67-
gridToVTK("./structured", x, y, z, cellData = {"pressure" : pressure}, pointData = {"temp" : temp})
67+
gridToVTK(
68+
"./structured",
69+
x,
70+
y,
71+
z,
72+
cellData={"pressure": pressure},
73+
pointData={"temp": temp},
74+
)

examples/unstructured.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,14 @@
4848
x[4], y[4], z[4] = 1.0, 1.0, 0.0
4949
x[5], y[5], z[5] = 2.0, 1.0, 0.0
5050

51+
point_data = {"test_pd": np.array([1, 2, 3, 4, 5, 6])}
52+
cell_data = {"test_cd": np.array([1, 2, 3])}
53+
field_data = {"test_fd": np.array([1.0, 2.0])}
5154
# Define connectivity or vertices that belongs to each element
5255
conn = np.zeros(10)
5356

54-
conn[0], conn[1], conn[2] = 0, 1, 3 # first triangle
55-
conn[3], conn[4], conn[5] = 1, 4, 3 # second triangle
57+
conn[0], conn[1], conn[2] = 0, 1, 3 # first triangle
58+
conn[3], conn[4], conn[5] = 1, 4, 3 # second triangle
5659
conn[6], conn[7], conn[8], conn[9] = 1, 2, 5, 4 # rectangle
5760

5861
# Define offset of last vertex of each element
@@ -67,4 +70,15 @@
6770
ctype[0], ctype[1] = VtkTriangle.tid, VtkTriangle.tid
6871
ctype[2] = VtkQuad.tid
6972

70-
unstructuredGridToVTK("unstructured", x, y, z, connectivity = conn, offsets = offset, cell_types = ctype, cellData = None, pointData = None)
73+
unstructuredGridToVTK(
74+
"unstructured",
75+
x,
76+
y,
77+
z,
78+
connectivity=conn,
79+
offsets=offset,
80+
cell_types=ctype,
81+
cellData=cell_data,
82+
pointData=point_data,
83+
fieldData=field_data,
84+
)

0 commit comments

Comments
 (0)