Skip to content

Commit 98813d7

Browse files
authored
Merge pull request #331 from ImperialCollegeLondon/dev_rewrite_vtk
Merge rewrite of VTK libraries into main
2 parents ca07a63 + 1f3dd53 commit 98813d7

File tree

12 files changed

+299
-393
lines changed

12 files changed

+299
-393
lines changed

sharpy/generators/polaraeroforces.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
@generator_interface.generator
1111
class PolarCorrection(generator_interface.BaseGenerator):
12-
"""
12+
r"""
1313
This generator corrects the aerodynamic forces from UVLM based on the airfoil polars provided by the user in the
1414
``aero.h5`` file. Polars are entered for each airfoil, in a table comprising ``AoA (rad), CL, CD, CM``.
1515

sharpy/linear/assembler/linearbeam.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ def remove_symmetric_modes(self):
370370
self.sys.num_modes = len(self.sys.freq_natural)
371371

372372
def unpack_ss_vector(self, x_n, u_n, struct_tstep):
373-
"""
373+
r"""
374374
Warnings:
375375
Under development. Missing:
376376
* Accelerations

sharpy/linear/assembler/lineargustassembler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def assemble_gust_statespace(self, a_i, b_i, c_i, d_i):
205205
return gustss
206206

207207
def discretise_domain(self):
208-
"""
208+
r"""
209209
Generates a "gust-station" domain, aligned with the free-stream velocity equispaced in
210210
:math:`\Delta t U_\infty` increments.
211211

sharpy/postproc/aerogridplot.py

Lines changed: 65 additions & 199 deletions
Large diffs are not rendered by default.

sharpy/postproc/beamplot.py

Lines changed: 105 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
import os
22

33
import numpy as np
4-
from tvtk.api import tvtk, write_data
54

65
import sharpy.utils.cout_utils as cout
76
from sharpy.utils.solver_interface import solver, BaseSolver
87
import sharpy.utils.settings as settings_utils
98
import sharpy.utils.algebra as algebra
109

1110

11+
import vtk
12+
from vtk.numpy_interface import algorithms as algs
13+
from vtk.numpy_interface import dataset_adapter as dsa
14+
15+
1216
@solver
1317
class BeamPlot(BaseSolver):
1418
"""
@@ -118,9 +122,7 @@ def plot(self, online):
118122
self.write_for(it)
119123

120124
def write_beam(self, it):
121-
it_filename = (self.filename +
122-
('%06u' % it) +
123-
'.vtu')
125+
it_filename = f"{self.filename}{it:06d}.vtp"
124126
num_nodes = self.data.structure.num_node
125127
num_elem = self.data.structure.num_elem
126128

@@ -132,7 +134,6 @@ def write_beam(self, it):
132134
local_y = np.zeros((num_nodes, 3))
133135
local_z = np.zeros((num_nodes, 3))
134136
coords_a = np.zeros((num_nodes, 3))
135-
136137
app_forces = np.zeros((num_nodes, 3))
137138
app_moment = np.zeros((num_nodes, 3))
138139

@@ -150,14 +151,9 @@ def write_beam(self, it):
150151
if tstep.mb_dict is None:
151152
pass
152153
else:
153-
#TODO: fix for lack of g frame description in nonlineardynamicmultibody.py
154154
for i_node in range(tstep.num_node):
155-
#TODO: uncomment for dynamic trim
156-
# try:
157-
# c = algebra.euler2rot([0, self.data.trimmed_values[0], 0])
158-
# except AttributeError:
159155
c = self.data.structure.timestep_info[0].cga()
160-
coords[i_node, :] += np.dot(c, tstep.for_pos[0:3])
156+
coords[i_node, :] += c @ tstep.for_pos[:3]
161157

162158
# check if I can output gravity forces
163159
with_gravity = False
@@ -260,115 +256,128 @@ def write_beam(self, it):
260256
conn[i_elem, :] = self.data.structure.elements[i_elem].reordered_global_connectivities
261257
elem_id[i_elem] = i_elem
262258

263-
ug = tvtk.UnstructuredGrid(points=coords)
264-
ug.set_cells(tvtk.Line().cell_type, conn)
265-
ug.cell_data.scalars = elem_id
266-
ug.cell_data.scalars.name = 'elem_id'
267-
counter = 1
259+
ug = vtk.vtkPolyData(points=coords)
260+
cells = vtk.vtkCellArray()
261+
for _conn in conn:
262+
line = vtk.vtkPolyLine()
263+
line.GetPointIds().SetNumberOfIds(3)
264+
line.GetPointIds().SetId(0, _conn[0])
265+
line.GetPointIds().SetId(1, _conn[1])
266+
line.GetPointIds().SetId(2, _conn[2])
267+
cells.InsertNextCell(line)
268+
ug.SetLines(cells)
269+
270+
ug.GetCellData().AddArray(dsa.numpyTovtkDataArray(np.array(elem_id), name='elem_id'))
271+
ug.GetCellData().AddArray(dsa.numpyTovtkDataArray(coords_a_cell, name="coords_a_elem"))
272+
ug.GetPointData().AddArray(
273+
dsa.numpyTovtkDataArray(node_id, name="node_id")
274+
)
275+
ug.GetPointData().AddArray(dsa.numpyTovtkDataArray(local_x, name="local_x"))
276+
ug.GetPointData().AddArray(dsa.numpyTovtkDataArray(local_y, name="local_y"))
277+
ug.GetPointData().AddArray(dsa.numpyTovtkDataArray(local_z, name="local_z"))
278+
ug.GetPointData().AddArray(dsa.numpyTovtkDataArray(coords_a, name="coords_a"))
279+
268280
if with_postproc_cell:
269281
for k in postproc_cell_vector:
270-
ug.cell_data.add_array(tstep.postproc_cell[k])
271-
ug.cell_data.get_array(counter).name = k + '_cell'
272-
counter += 1
282+
ug.GetCellData().AddArray(
283+
dsa.numpyTovtkDataArray(tstep.postproc_cell[k], name=f"{k}_cell")
284+
)
273285
for k in postproc_cell_6vector:
274-
for i in range(0, 2):
275-
ug.cell_data.add_array(tstep.postproc_cell[k][:, 3*i:3*(i+1)])
276-
ug.cell_data.get_array(counter).name = k + '_' + str(i) + '_cell'
277-
counter += 1
278-
ug.cell_data.add_array(coords_a_cell)
279-
ug.cell_data.get_array(counter).name = 'coords_a_elem'
280-
counter += 1
281-
282-
ug.point_data.scalars = node_id
283-
ug.point_data.scalars.name = 'node_id'
284-
point_vector_counter = 1
285-
ug.point_data.add_array(local_x, 'vector')
286-
ug.point_data.get_array(point_vector_counter).name = 'local_x'
287-
point_vector_counter += 1
288-
ug.point_data.add_array(local_y, 'vector')
289-
ug.point_data.get_array(point_vector_counter).name = 'local_y'
290-
point_vector_counter += 1
291-
ug.point_data.add_array(local_z, 'vector')
292-
ug.point_data.get_array(point_vector_counter).name = 'local_z'
293-
point_vector_counter += 1
294-
ug.point_data.add_array(coords_a, 'vector')
295-
ug.point_data.get_array(point_vector_counter).name = 'coords_a'
286+
for i in range(2):
287+
ug.GetCellData().AddArray(
288+
dsa.numpyTovtkDataArray(
289+
tstep.postproc_cell[k][:, 3*i:3*(i+1)], name=f"{k}_{i}_cell"
290+
)
291+
)
292+
296293
if self.settings['include_applied_forces']:
297-
point_vector_counter += 1
298-
ug.point_data.add_array(app_forces, 'vector')
299-
ug.point_data.get_array(point_vector_counter).name = 'app_forces'
300-
point_vector_counter += 1
301-
ug.point_data.add_array(forces_constraints_nodes, 'vector')
302-
ug.point_data.get_array(point_vector_counter).name = 'forces_constraints_nodes'
294+
ug.GetPointData().AddArray(dsa.numpyTovtkDataArray(app_forces, name="app_forces"))
295+
ug.GetPointData().AddArray(
296+
dsa.numpyTovtkDataArray(forces_constraints_nodes, name="forces_constraints_node")
297+
)
303298
if with_gravity:
304-
point_vector_counter += 1
305-
ug.point_data.add_array(gravity_forces_g[:, 0:3], 'vector')
306-
ug.point_data.get_array(point_vector_counter).name = 'gravity_forces'
299+
ug.GetPointData().AddArray(
300+
dsa.numpyTovtkDataArray(
301+
gravity_forces_g[:, :3], name="gravity_forces"
302+
)
303+
)
307304

308305
if self.settings['include_applied_moments']:
309-
point_vector_counter += 1
310-
ug.point_data.add_array(app_moment, 'vector')
311-
ug.point_data.get_array(point_vector_counter).name = 'app_moments'
312-
point_vector_counter += 1
313-
ug.point_data.add_array(moments_constraints_nodes, 'vector')
314-
ug.point_data.get_array(point_vector_counter).name = 'moments_constraints_nodes'
306+
ug.GetPointData().AddArray(
307+
dsa.numpyTovtkDataArray(app_moment, name="app_moments")
308+
)
309+
ug.GetPointData().AddArray(
310+
dsa.numpyTovtkDataArray(moments_constraints_nodes, name="moments_constraints_nodes")
311+
)
315312
if with_gravity:
316-
point_vector_counter += 1
317-
ug.point_data.add_array(gravity_forces_g[:, 3:6], 'vector')
318-
ug.point_data.get_array(point_vector_counter).name = 'gravity_moments'
313+
ug.GetPointData().AddArray(dsa.numpyTovtkDataArray(gravity_forces_g[:, 3:6], name="gravity_moments"))
314+
319315
if with_postproc_node:
320316
for k in postproc_node_vector:
321-
point_vector_counter += 1
322-
ug.point_data.add_array(tstep.postproc_node[k])
323-
ug.point_data.get_array(point_vector_counter).name = k + '_point'
317+
ug.GetPointData().AddArray(
318+
dsa.numpyTovtkDataArray(
319+
tstep.postproc_node[k], name=f"{k}_point"
320+
)
321+
)
324322
for k in postproc_node_6vector:
325-
for i in range(0, 2):
326-
point_vector_counter += 1
327-
ug.point_data.add_array(tstep.postproc_node[k][:, 3*i:3*(i+1)])
328-
ug.point_data.get_array(point_vector_counter).name = k + '_' + str(i) + '_point'
323+
for i in range(2):
324+
ug.GetPointData().AddArray(
325+
dsa.numpyTovtkDataArray(
326+
tstep.postproc_node[k][:, 3*i:3*(i+1)], name=f"{k}_{i}_point"
327+
)
328+
)
329329

330330
for k in postproc_node_scalar:
331-
point_vector_counter += 1
332-
ug.point_data.add_array(tstep.postproc_node[k])
333-
ug.point_data.get_array(point_vector_counter).name = k
334-
335-
write_data(ug, it_filename)
331+
ug.GetPointData().AddArray(
332+
dsa.numpyTovtkDataArray(
333+
tstep.postproc_node[k],
334+
name=str(k),
335+
)
336+
)
337+
338+
writer = vtk.vtkXMLPolyDataWriter()
339+
writer.SetFileName(it_filename)
340+
writer.SetInputData(ug)
341+
writer.Write()
336342

337343
def write_for(self, it):
338-
it_filename = (self.filename_for +
339-
'%06u' % it)
344+
it_filename = f"{self.filename_for}{it:06d}.vtp"
340345

341-
forces_constraints_FoR = np.zeros((self.data.structure.num_bodies, 3))
342-
moments_constraints_FoR = np.zeros((self.data.structure.num_bodies, 3))
343-
# TODO: what should I do with the forces of the quaternion?
346+
forces_constraints_for = np.zeros((self.data.structure.num_bodies, 3))
347+
moments_constraints_for = np.zeros((self.data.structure.num_bodies, 3))
344348

345349
# aero2inertial rotation
346350
aero2inertial = self.data.structure.timestep_info[it].cga()
347351

348352
# coordinates of corners
349-
FoR_coords = np.zeros((self.data.structure.num_bodies, 3))
353+
for_coords = np.zeros((self.data.structure.num_bodies, 3))
350354
if self.settings['include_rbm']:
351355
offset = np.zeros((3,))
352356
else:
353357
offset = self.data.structure.timestep_info[it].mb_FoR_pos[0, 0:3]
354-
for ibody in range(self.data.structure.num_bodies):
355-
FoR_coords[ibody, :] = self.data.structure.timestep_info[it].mb_FoR_pos[ibody, 0:3] - offset
356358

357359
for ibody in range(self.data.structure.num_bodies):
358-
forces_constraints_FoR[ibody, :] = np.dot(aero2inertial,
359-
self.data.structure.timestep_info[it].forces_constraints_FoR[ibody, 0:3])
360-
moments_constraints_FoR[ibody, :] = np.dot(aero2inertial,
361-
self.data.structure.timestep_info[it].forces_constraints_FoR[ibody, 3:6])
362-
363-
FoRmesh = tvtk.PolyData()
364-
FoRmesh.points = FoR_coords
365-
for_vector_counter = -1
366-
for_vector_counter += 1
367-
FoRmesh.point_data.add_array(forces_constraints_FoR , 'vector')
368-
FoRmesh.point_data.get_array(for_vector_counter).name = 'forces_constraints_FoR'
369-
370-
for_vector_counter += 1
371-
FoRmesh.point_data.add_array(moments_constraints_FoR , 'vector')
372-
FoRmesh.point_data.get_array(for_vector_counter).name = 'moments_constraints_FoR'
373-
374-
write_data(FoRmesh, it_filename)
360+
for_coords[ibody, :] = self.data.structure.timestep_info[it].mb_FoR_pos[ibody, 0:3] - offset
361+
forces_constraints_for[ibody, :] = aero2inertial @ self.data.structure.timestep_info[it].forces_constraints_FoR[ibody, :3]
362+
moments_constraints_for[ibody, :] = aero2inertial @ self.data.structure.timestep_info[it].forces_constraints_FoR[ibody, 3:6]
363+
364+
for_mesh = vtk.vtkPolyData(points=for_coords)
365+
366+
for_mesh.GetPointData().AddArray(
367+
dsa.numpyTovtkDataArray(
368+
forces_constraints_for,
369+
'forces_constraints_FoR',
370+
)
371+
)
372+
373+
for_mesh.GetPointData().AddArray(
374+
dsa.numpyTovtkDataArray(
375+
moments_constraints_for,
376+
"moments_constraints_FoR",
377+
)
378+
)
379+
380+
writer = vtk.vtkXMLPolyDataWriter()
381+
writer.SetFileName(it_filename)
382+
writer.SetInputData(for_mesh)
383+
writer.Write()

sharpy/rom/utils/krylovutils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ def construct_krylov(r, lu_A, B, approx_type='Pade', side='b'):
192192

193193

194194
def lu_factor(sigma, A):
195-
"""
195+
r"""
196196
LU Factorisation wrapper of:
197197
198198
.. math:: LU = (\sigma \mathbf{I} - \mathbf{A})
@@ -214,7 +214,7 @@ def lu_factor(sigma, A):
214214

215215

216216
def lu_solve(lu_A, b, trans=0):
217-
"""
217+
r"""
218218
LU solve wrapper.
219219
220220
Computes the solution to

sharpy/sharpy_main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import warnings
55
import sys
66
import dill as pickle
7-
import sharpy.utils.cout_utils as cout
7+
from sharpy.utils import cout_utils as cout
88
from .version import __version__
99

1010

sharpy/solvers/modal.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -209,15 +209,10 @@ def run(self, **kwargs):
209209

210210
# Number of degrees of freedom
211211
num_str_dof = self.data.structure.num_dof.value
212-
if self.rigid_body_motion:
213-
num_rigid_dof = 10
214-
else:
215-
num_rigid_dof = 0
212+
num_rigid_dof = 10 if self.rigid_body_motion else 0
216213

217214
num_dof = num_str_dof + num_rigid_dof
218215

219-
# if NumLambda
220-
221216
# Initialize matrices
222217
FullMglobal = np.zeros((num_dof, num_dof),
223218
dtype=ct.c_double, order='F')

sharpy/solvers/nonlineardynamicmultibody.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def define_rigid_dofs(self, MB_beam):
175175
first_dof = last_dof + 0
176176

177177
def assembly_MB_eq_system(self, MB_beam, MB_tstep, ts, dt, Lambda, Lambda_dot, MBdict):
178-
"""
178+
r"""
179179
This function generates the matrix and vector associated to the linear system to solve a structural iteration
180180
It usses a Newmark-beta scheme for time integration. Being M, C and K the mass, damping
181181
and stiffness matrices of the system:

0 commit comments

Comments
 (0)