13 num_part = np.shape(positions)[0]
14 num_timesteps = np.shape(positions)[1]
16 for timestep
in range(num_timesteps):
20 for num
in range(num_part):
21 pos_string = pos_string +
"%.4f " % positions[num, timestep, 0]
22 pos_string = pos_string +
"%.4f " % positions[num, timestep, 1]
23 pos_string = pos_string +
"%.4f " % positions[num, timestep, 2]
24 vel_string = vel_string +
"%.4f " % velocities[num, timestep, 0]
25 vel_string = vel_string +
"%.4f " % velocities[num, timestep, 1]
26 vel_string = vel_string +
"%.4f " % velocities[num, timestep, 2]
27 rad_string = rad_string +
"%.4f " % rad[num, timestep]
29 pos_string = pos_string +
"\n"
30 vel_string = vel_string +
"\n"
31 rad_string = rad_string +
"\n"
33 textfile = open(filename +
'_' +
str(timestep) +
'.vtu',
"w")
34 textfile.write(
'<?xml version="1.0"?>\n')
35 textfile.write(
'<VTKFile type="UnstructuredGrid" version="0.1" byte_order="LittleEndian">\n')
36 textfile.write(
' <UnstructuredGrid>\n')
37 textfile.write(
' <Piece NumberOfPoints="' +
str(num_part) +
'" NumberOfCells="0">\n')
38 textfile.write(
' <Cells>\n')
39 textfile.write(
' <DataArray type="Int32" name="connectivity" format="ascii">\n')
40 textfile.write(
' 0\n')
41 textfile.write(
' </DataArray>\n')
42 textfile.write(
' <DataArray type="Float32" name="offset" format="ascii">\n')
43 textfile.write(
' 0\n')
44 textfile.write(
' </DataArray>\n')
45 textfile.write(
' <DataArray type="UInt8" name="types" format="ascii">\n')
46 textfile.write(
' 1\n')
47 textfile.write(
' </DataArray>\n')
48 textfile.write(
' </Cells>\n')
49 textfile.write(
' <Points>\n')
50 textfile.write(
'<DataArray type="Float32" NumberOfComponents="3" format="ascii">\n')
51 textfile.write(pos_string)
52 textfile.write(
'</DataArray>\n')
53 textfile.write(
' </Points>\n')
54 textfile.write(
' <PointData>\n')
55 textfile.write(
'<DataArray type="Float32" Name="Position" NumberOfComponents="3" format="ascii">\n')
56 textfile.write(pos_string)
57 textfile.write(
'</DataArray>\n')
58 textfile.write(
'<DataArray type="Float32" Name="Velocity" NumberOfComponents="3" format="ascii">\n')
59 textfile.write(vel_string)
60 textfile.write(
'</DataArray>\n')
61 textfile.write(
'<DataArray type="Float32" Name="Radius" NumberOfComponents="1" format="ascii">\n')
62 textfile.write(rad_string)
63 textfile.write(
'</DataArray>\n')
64 textfile.write(
'</PointData>\n')
65 textfile.write(
'<CellData/>\n')
66 textfile.write(
'</Piece>\n')
67 textfile.write(
'</UnstructuredGrid>\n')
68 textfile.write(
'</VTKFile>\n')
def SavePebblesToVtu(filename, positions, velocities, rad)
Definition: SaveToVtu.py:11