SaveToVtu Namespace Reference

Functions

def SavePebblesToVtu (filename, positions, velocities, rad)
 
def SavePDToVtu (filename, v1, v2, v3)
 

Function Documentation

◆ SavePDToVtu()

def SaveToVtu.SavePDToVtu (   filename,
  v1,
  v2,
  v3 
)
76 def SavePDToVtu(filename, v1, v2, v3):
77  # This function saves clump principal directions in XML/vtu (unstructured grid) format
78  num_part = 1
79  num_timesteps = len(v1)
80 
81  for timestep in range(num_timesteps):
82  pos_string = ""
83  v1_string = ""
84  v2_string = ""
85  v3_string = ""
86 
87  rad_string = ""
88  pos_string = pos_string + "%.4f " % 0
89  pos_string = pos_string + "%.4f " % 0
90  pos_string = pos_string + "%.4f " % 0
91  v1_string = v1_string + "%.4f " % v1[timestep, 0]
92  v1_string = v1_string + "%.4f " % v1[timestep, 1]
93  v1_string = v1_string + "%.4f " % v1[timestep, 2]
94  v2_string = v2_string + "%.4f " % v2[timestep, 0]
95  v2_string = v2_string + "%.4f " % v2[timestep, 1]
96  v2_string = v2_string + "%.4f " % v2[timestep, 2]
97  v3_string = v3_string + "%.4f " % v3[timestep, 0]
98  v3_string = v3_string + "%.4f " % v3[timestep, 1]
99  v3_string = v3_string + "%.4f " % v3[timestep, 2]
100 
101  rad_string = rad_string + "%.4f " % 1.0
102 
103  pos_string = pos_string + "\n"
104  v1_string = v1_string + "\n"
105  v2_string = v2_string + "\n"
106  v3_string = v3_string + "\n"
107 
108  rad_string = rad_string + "\n"
109 
110  textfile = open(filename + '_pd_' + str(timestep) + '.vtu', "w")
111  textfile.write('<?xml version="1.0"?>\n')
112  textfile.write('<VTKFile type="UnstructuredGrid" version="0.1" byte_order="LittleEndian">\n')
113  textfile.write(' <UnstructuredGrid>\n')
114  textfile.write(' <Piece NumberOfPoints="' + str(num_part) + '" NumberOfCells="0">\n')
115  textfile.write(' <Cells>\n')
116  textfile.write(' <DataArray type="Int32" name="connectivity" format="ascii">\n')
117  textfile.write(' 0\n')
118  textfile.write(' </DataArray>\n')
119  textfile.write(' <DataArray type="Float32" name="offset" format="ascii">\n')
120  textfile.write(' 0\n')
121  textfile.write(' </DataArray>\n')
122  textfile.write(' <DataArray type="UInt8" name="types" format="ascii">\n')
123  textfile.write(' 1\n')
124  textfile.write(' </DataArray>\n')
125  textfile.write(' </Cells>\n')
126  textfile.write(' <Points>\n')
127  textfile.write('<DataArray type="Float32" NumberOfComponents="3" format="ascii">\n')
128  textfile.write(pos_string)
129  textfile.write('</DataArray>\n')
130  textfile.write(' </Points>\n')
131  textfile.write(' <PointData>\n')
132  textfile.write('<DataArray type="Float32" Name="Position" NumberOfComponents="3" format="ascii">\n')
133  textfile.write(pos_string)
134  textfile.write('</DataArray>\n')
135  textfile.write('<DataArray type="Float32" Name="v1" NumberOfComponents="3" format="ascii">\n')
136  textfile.write(v1_string)
137  textfile.write('</DataArray>\n')
138  textfile.write('<DataArray type="Float32" Name="v2" NumberOfComponents="3" format="ascii">\n')
139  textfile.write(v2_string)
140  textfile.write('</DataArray>\n')
141  textfile.write('<DataArray type="Float32" Name="v3" NumberOfComponents="3" format="ascii">\n')
142  textfile.write(v3_string)
143  textfile.write('</DataArray>\n')
144  textfile.write('<DataArray type="Float32" Name="Radius" NumberOfComponents="1" format="ascii">\n')
145  textfile.write(rad_string)
146  textfile.write('</DataArray>\n')
147  textfile.write('</PointData>\n')
148  textfile.write('<CellData/>\n')
149  textfile.write('</Piece>\n')
150  textfile.write('</UnstructuredGrid>\n')
151  textfile.write('</VTKFile>\n')
152  textfile.close()
153 
154  return
def SavePDToVtu(filename, v1, v2, v3)
Definition: SaveToVtu.py:76
str
Definition: compute_granudrum_aor.py:141

References compute_granudrum_aor.str.

Referenced by OutputData.ParaviewOutputPebblesAnimated().

◆ SavePebblesToVtu()

def SaveToVtu.SavePebblesToVtu (   filename,
  positions,
  velocities,
  rad 
)
11 def SavePebblesToVtu(filename, positions, velocities, rad):
12  # This function saves pebble information in XML/vtu (unstructured grid) format
13  num_part = np.shape(positions)[0]
14  num_timesteps = np.shape(positions)[1]
15 
16  for timestep in range(num_timesteps):
17  pos_string = ""
18  vel_string = ""
19  rad_string = ""
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]
28 
29  pos_string = pos_string + "\n"
30  vel_string = vel_string + "\n"
31  rad_string = rad_string + "\n"
32 
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')
69  textfile.close()
70 
71  return
72 
73 
74 
75 
def SavePebblesToVtu(filename, positions, velocities, rad)
Definition: SaveToVtu.py:11

References compute_granudrum_aor.str.

Referenced by OutputData.ParaviewOutputPebblesAnimated(), and OutputData.ParaviewOutputPebblesStatic().