20 is_data_associated_to_cell,
24 Prepare 2D patches in a unstructured grid for rendering
28 cell_data: list of patches
29 List of Patches with file data
32 Number of degrees of freedom per axis
35 Number of unknowns per patch volume
39 grid: vtk.vtkUnstructuredGrid
43 points = vtk.vtkPoints()
44 cells = vtk.vtkCellArray()
45 grid = vtk.vtkUnstructuredGrid()
47 data = vtk.vtkDoubleArray()
48 data.SetNumberOfComponents(unknowns + 1)
50 data.SetName(
"Unknowns (" + description +
", subdomain)")
52 data.SetName(
"Unknowns (..., subdomain)")
55 dofs_in_patch_per_axis = dof - 1
if not is_data_associated_to_cell
else dof
57 points.SetNumberOfPoints(len(cell_data) * (dofs_in_patch_per_axis + 1) ** 2)
58 cells.SetNumberOfCells(len(cell_data) * dofs_in_patch_per_axis**2)
61 for p
in range(len(cell_data)):
62 patch_x_0, patch_y_0 = cell_data[p].offset
63 patch_width, patch_height = cell_data[p].size
64 z = patch_width * depth_scaling
67 for k
in range(dofs_in_patch_per_axis + 1):
68 for l
in range(dofs_in_patch_per_axis + 1):
69 x = patch_x_0 + mapping[mapping_count] * patch_width
71 y = patch_y_0 + mapping[mapping_count] * patch_height
73 points.SetPoint(point_counter, x, y, z)
76 for k
in range(dofs_in_patch_per_axis):
77 for l
in range(dofs_in_patch_per_axis):
78 cells.InsertNextCell(4)
79 cells.InsertCellPoint(
80 p * (dofs_in_patch_per_axis + 1) * (dofs_in_patch_per_axis + 1)
81 + (k + 0) * (dofs_in_patch_per_axis + 1)
85 cells.InsertCellPoint(
86 p * (dofs_in_patch_per_axis + 1) * (dofs_in_patch_per_axis + 1)
87 + (k + 0) * (dofs_in_patch_per_axis + 1)
91 cells.InsertCellPoint(
92 p * (dofs_in_patch_per_axis + 1) * (dofs_in_patch_per_axis + 1)
93 + (k + 1) * (dofs_in_patch_per_axis + 1)
97 cells.InsertCellPoint(
98 p * (dofs_in_patch_per_axis + 1) * (dofs_in_patch_per_axis + 1)
99 + (k + 1) * (dofs_in_patch_per_axis + 1)
104 if is_data_associated_to_cell:
105 for k
in range(dofs_in_patch_per_axis):
106 for l
in range(dofs_in_patch_per_axis):
107 cell_number = k * dof + l
110 for x
in cell_data[p].values[
111 cell_number * unknowns : cell_number * unknowns + unknowns
114 new_data.append(cell_data[p].subdomain_number)
115 data.InsertNextTuple(new_data)
117 for k
in range(dofs_in_patch_per_axis + 1):
118 for l
in range(dofs_in_patch_per_axis + 1):
119 vertex_number = k * (dofs_in_patch_per_axis + 1) + l
122 for x
in cell_data[p].values[
123 vertex_number * unknowns : vertex_number * unknowns
127 new_data.append(cell_data[p].subdomain_number)
128 data.InsertNextTuple(new_data)
130 grid.SetPoints(points)
131 grid.SetCells(vtk.VTK_PIXEL, cells)
133 if is_data_associated_to_cell:
134 grid.GetCellData().SetScalars(data)
136 grid.GetPointData().SetScalars(data)
142 cell_data, dof, unknowns, description, is_data_associated_to_cell, mapping
145 Prepare 3D patches in a unstructured grid for rendering
149 cell_data: list of patches
150 List of Patches with file data
153 Number of degrees of freedom per axis
156 Number of unknowns per patch volume
160 grid: vtk.vtkUnstructuredGrid
163 dofs_in_patch_per_axis = dof
164 if not is_data_associated_to_cell:
165 dofs_in_patch_per_axis -= 1
167 points = vtk.vtkPoints()
168 cells = vtk.vtkCellArray()
169 grid = vtk.vtkUnstructuredGrid()
171 data = vtk.vtkDoubleArray()
172 data.SetNumberOfComponents(unknowns + 1)
173 if description !=
"":
174 data.SetName(
"Unknowns (" + description +
", subdomain)")
176 data.SetName(
"Unknowns (..., subdomain)")
179 points.SetNumberOfPoints(len(cell_data) * (dofs_in_patch_per_axis + 1) ** 3)
181 for p
in range(len(cell_data)):
182 patch_x_0 = cell_data[p].offset[0]
183 patch_y_0 = cell_data[p].offset[1]
184 patch_z_0 = cell_data[p].offset[2]
187 for k
in range(dofs_in_patch_per_axis + 1):
188 for l
in range(dofs_in_patch_per_axis + 1):
189 for m
in range(dofs_in_patch_per_axis + 1):
190 x = patch_x_0 + mapping[mapping_count] * cell_data[p].size[0]
192 y = patch_y_0 + mapping[mapping_count] * cell_data[p].size[1]
194 z = patch_z_0 + mapping[mapping_count] * cell_data[p].size[2]
196 points.SetPoint(point_counter, x, y, z)
199 for k
in range(dofs_in_patch_per_axis):
200 for l
in range(dofs_in_patch_per_axis):
201 for m
in range(dofs_in_patch_per_axis):
202 cells.InsertNextCell(8)
203 cells.InsertCellPoint(
205 * (dofs_in_patch_per_axis + 1)
206 * (dofs_in_patch_per_axis + 1)
207 * (dofs_in_patch_per_axis + 1)
209 * (dofs_in_patch_per_axis + 1)
210 * (dofs_in_patch_per_axis + 1)
211 + (l + 0) * (dofs_in_patch_per_axis + 1)
215 cells.InsertCellPoint(
217 * (dofs_in_patch_per_axis + 1)
218 * (dofs_in_patch_per_axis + 1)
219 * (dofs_in_patch_per_axis + 1)
221 * (dofs_in_patch_per_axis + 1)
222 * (dofs_in_patch_per_axis + 1)
223 + (l + 0) * (dofs_in_patch_per_axis + 1)
227 cells.InsertCellPoint(
229 * (dofs_in_patch_per_axis + 1)
230 * (dofs_in_patch_per_axis + 1)
231 * (dofs_in_patch_per_axis + 1)
233 * (dofs_in_patch_per_axis + 1)
234 * (dofs_in_patch_per_axis + 1)
235 + (l + 1) * (dofs_in_patch_per_axis + 1)
239 cells.InsertCellPoint(
241 * (dofs_in_patch_per_axis + 1)
242 * (dofs_in_patch_per_axis + 1)
243 * (dofs_in_patch_per_axis + 1)
245 * (dofs_in_patch_per_axis + 1)
246 * (dofs_in_patch_per_axis + 1)
247 + (l + 1) * (dofs_in_patch_per_axis + 1)
251 cells.InsertCellPoint(
253 * (dofs_in_patch_per_axis + 1)
254 * (dofs_in_patch_per_axis + 1)
255 * (dofs_in_patch_per_axis + 1)
257 * (dofs_in_patch_per_axis + 1)
258 * (dofs_in_patch_per_axis + 1)
259 + (l + 0) * (dofs_in_patch_per_axis + 1)
263 cells.InsertCellPoint(
265 * (dofs_in_patch_per_axis + 1)
266 * (dofs_in_patch_per_axis + 1)
267 * (dofs_in_patch_per_axis + 1)
269 * (dofs_in_patch_per_axis + 1)
270 * (dofs_in_patch_per_axis + 1)
271 + (l + 0) * (dofs_in_patch_per_axis + 1)
275 cells.InsertCellPoint(
277 * (dofs_in_patch_per_axis + 1)
278 * (dofs_in_patch_per_axis + 1)
279 * (dofs_in_patch_per_axis + 1)
281 * (dofs_in_patch_per_axis + 1)
282 * (dofs_in_patch_per_axis + 1)
283 + (l + 1) * (dofs_in_patch_per_axis + 1)
287 cells.InsertCellPoint(
289 * (dofs_in_patch_per_axis + 1)
290 * (dofs_in_patch_per_axis + 1)
291 * (dofs_in_patch_per_axis + 1)
293 * (dofs_in_patch_per_axis + 1)
294 * (dofs_in_patch_per_axis + 1)
295 + (l + 1) * (dofs_in_patch_per_axis + 1)
300 if is_data_associated_to_cell:
301 for k
in range(dofs_in_patch_per_axis):
302 for l
in range(dofs_in_patch_per_axis):
303 for m
in range(dofs_in_patch_per_axis):
304 cell_number = k * dof * dof + l * dof + m
307 for x
in cell_data[p].values[
308 cell_number * unknowns : cell_number * unknowns
312 new_data.append(cell_data[p].subdomain_number)
313 data.InsertNextTuple(new_data)
315 for k
in range(dofs_in_patch_per_axis + 1):
316 for l
in range(dofs_in_patch_per_axis + 1):
317 for m
in range(dofs_in_patch_per_axis + 1):
320 * (dofs_in_patch_per_axis + 1)
321 * (dofs_in_patch_per_axis + 1)
322 + l * (dofs_in_patch_per_axis + 1)
327 for x
in cell_data[p].values[
328 vertex_number * unknowns : vertex_number * unknowns
332 new_data.append(cell_data[p].subdomain_number)
333 data.InsertNextTuple(new_data)
335 grid.SetPoints(points)
336 grid.SetCells(vtk.VTK_VOXEL, cells)
338 if is_data_associated_to_cell:
339 grid.GetCellData().SetScalars(data)
341 grid.GetPointData().SetScalars(data)
365 grid, description, unknowns, is_data_associated_to_cell, split_unknowns
369 Label the unknowns of a grid with their symbolic names
371 If the description of the unknowns holds one name per unknown (@see
372 unknown_names_from_description()), we name the components of the data
373 array accordingly, plus the trailing subdomain component. Paraview then
374 offers the names when you colour by the array. Otherwise, we leave the
377 split_unknowns: Boolean
378 If set, we additionally add one array per variable, so filters such as
379 Paraview's Calculator or Contour can address it by name. A scalar
380 becomes an array with one component. The entries v[0], v[1], ... of a
381 variable with multiplicity become one vector array v. As Paraview only
382 treats arrays with three components as vectors, e.g. for glyphs, we
383 pad a vector with two entries with a zero.
386 names = unknown_names_from_description(description, unknowns)
391 grid.GetCellData()
if is_data_associated_to_cell
else grid.GetPointData()
393 data = field_data.GetScalars()
394 for index, name
in enumerate(names):
395 data.SetComponentName(index, name)
396 data.SetComponentName(unknowns,
"subdomain")
399 for array_name, indices
in group_unknown_names(names):
400 array = vtk.vtkDoubleArray()
401 array.SetName(array_name)
402 array.SetNumberOfComponents(3
if len(indices) == 2
else len(indices))
403 array.SetNumberOfTuples(data.GetNumberOfTuples())
404 if len(indices) == 2:
405 array.FillComponent(2, 0.0)
406 for component, index
in enumerate(indices):
407 array.CopyComponent(component, data, index)
408 field_data.AddArray(array)