Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stride optional input for beamplot and aerogridplot #278

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 4 additions & 121 deletions sharpy/postproc/aerogridplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,6 @@ class AerogridPlot(BaseSolver):
settings_default['include_incidence_angle'] = False
settings_description['include_incidence_angle'] = 'Include panel incidence angle'

settings_types['plot_nonlifting_surfaces'] = 'bool'
settings_default['plot_nonlifting_surfaces'] = False
settings_description['plot_nonlifting_surfaces'] = 'Plot nonlifting surfaces'

settings_types['plot_lifting_surfaces'] = 'bool'
settings_default['plot_lifting_surfaces'] = False
settings_description['plot_lifting_surfaces'] = 'Plot nonlifting surfaces'

settings_types['num_cores'] = 'int'
settings_default['num_cores'] = 1
settings_description['num_cores'] = 'Number of cores used to compute velocities/angles'
Expand All @@ -99,7 +91,6 @@ def __init__(self):
self.folder = None
self.body_filename = ''
self.wake_filename = ''
self.nonlifting_filename = ''
self.ts_max = 0
self.caller = None

Expand All @@ -123,10 +114,6 @@ def initialise(self, data, custom_settings=None, caller=None, restart=False):
self.settings['name_prefix'] +
'wake_' +
self.data.settings['SHARPy']['case'])
self.nonlifting_filename = (self.folder +
self.settings['name_prefix'] +
'nonlifting_' +
self.data.settings['SHARPy']['case'])
self.caller = caller

def run(self, **kwargs):
Expand All @@ -138,18 +125,16 @@ def run(self, **kwargs):
for self.ts in range(self.ts_max):
if self.data.structure.timestep_info[self.ts] is not None:
self.plot_body()
self.plot_wake()
if self.settings['plot_nonlifting_surfaces']:
self.plot_nonlifting_surfaces()
if self.settings['save_wake']:
self.plot_wake()
cout.cout_wrap('...Finished', 1)
elif (self.data.ts % self.settings['stride'] == 0):
aero_tsteps = len(self.data.aero.timestep_info) - 1
struct_tsteps = len(self.data.structure.timestep_info) - 1
self.ts = np.max((aero_tsteps, struct_tsteps))
self.plot_body()
self.plot_wake()
if self.settings['plot_nonlifting_surfaces']:
self.plot_nonlifting_surfaces()
if self.settings['save_wake']:
self.plot_wake()
return self.data

def plot_body(self):
Expand Down Expand Up @@ -348,105 +333,3 @@ def plot_wake(self):
ug.point_data.scalars = np.arange(0, coords.shape[0])
ug.point_data.scalars.name = 'n_id'
write_data(ug, filename)

def plot_nonlifting_surfaces(self):
nonlifting_tstep = self.data.nonlifting_body.timestep_info[self.ts]
struct_tstep = self.data.structure.timestep_info[self.ts]

for i_surf in range(nonlifting_tstep.n_surf):
filename = (self.nonlifting_filename +
'_' +
'%02u_' % i_surf +
'%06u' % self.ts+
'.vtu')

dims = nonlifting_tstep.dimensions[i_surf, :]
point_data_dim = (dims[0]+1)*(dims[1]+1) # + (dims_star[0]+1)*(dims_star[1]+1)
panel_data_dim = (dims[0])*(dims[1]) # + (dims_star[0])*(dims_star[1])

coords = np.zeros((point_data_dim, 3))
conn = []
panel_id = np.zeros((panel_data_dim,), dtype=int)
panel_surf_id = np.zeros((panel_data_dim,), dtype=int)
panel_sigma = np.zeros((panel_data_dim,))
normal = np.zeros((panel_data_dim, 3))
point_struct_id = np.zeros((point_data_dim,), dtype=int)
point_cf = np.zeros((point_data_dim, 3))
u_inf = np.zeros((point_data_dim, 3))
counter = -1

# coordinates of corners
for i_n in range(dims[1]+1):
for i_m in range(dims[0]+1):
counter += 1
coords[counter, :] = nonlifting_tstep.zeta[i_surf][:, i_m, i_n]
# TODO: include those for nonlifting body (are they different for nonlifting coordinates?)
if self.settings['include_rbm']:
coords[counter, :] += struct_tstep.for_pos[0:3]
if self.settings['include_forward_motion']:
coords[counter, 0] -= self.settings['dt']*self.ts*self.settings['u_inf']
counter = -1
node_counter = -1
for i_n in range(dims[1] + 1):
global_counter = self.data.nonlifting_body.aero2struct_mapping[i_surf][i_n]
for i_m in range(dims[0] + 1):
node_counter += 1
# point data
point_struct_id[node_counter] = global_counter
point_cf[node_counter, :] = nonlifting_tstep.forces[i_surf][0:3, i_m, i_n]
try:
u_inf[node_counter, :] = nonlifting_tstep.u_ext[i_surf][0:3, i_m, i_n]
except AttributeError:
pass
if i_n < dims[1] and i_m < dims[0]:
counter += 1
else:
continue

conn.append([node_counter + 0,
node_counter + 1,
node_counter + dims[0]+2,
node_counter + dims[0]+1])
# cell data
normal[counter, :] = nonlifting_tstep.normals[i_surf][:, i_m, i_n]
panel_id[counter] = counter
panel_surf_id[counter] = i_surf
panel_sigma[counter] = nonlifting_tstep.sigma[i_surf][i_m, i_n]

ug = tvtk.UnstructuredGrid(points=coords)
ug.set_cells(tvtk.Quad().cell_type, conn)
ug.cell_data.scalars = panel_id
ug.cell_data.scalars.name = 'panel_n_id'
ug.cell_data.add_array(panel_surf_id)
ug.cell_data.get_array(1).name = 'panel_surface_id'
ug.cell_data.add_array(panel_sigma)
ug.cell_data.get_array(2).name = 'panel_sigma'
ug.cell_data.vectors = normal
ug.cell_data.vectors.name = 'panel_normal'
ug.point_data.scalars = np.arange(0, coords.shape[0])
ug.point_data.scalars.name = 'n_id'
ug.point_data.add_array(point_struct_id)
ug.point_data.get_array(1).name = 'point_struct_id'
ug.point_data.add_array(point_cf)
ug.point_data.get_array(2).name = 'point_steady_force'
ug.point_data.add_array(u_inf)
ug.point_data.get_array(3).name = 'u_inf'
write_data(ug, filename)

def write_paraview_data(self, coords, conn, panel_id, list_cell_parameters, list_cell_names, list_point_parameters, list_point_names, filename):
ug = tvtk.UnstructuredGrid(points=coords)

ug.set_cells(tvtk.Quad().cell_type, conn)
ug.cell_data.scalars = panel_id
ug.cell_data.scalars.name = 'panel_n_id'
for counter in range(len(list_cell_parameters)):
ug.cell_data.add_array(list_cell_parameters[counter])
ug.cell_data.get_array(counter+1).name = list_cell_names[counter]

ug.point_data.scalars = np.arange(0, coords.shape[0])
ug.point_data.scalars.name = 'n_id'
for counter in range(len(list_point_parameters)):
ug.point_data.add_array(list_point_parameters[counter])
ug.point_data.get_array(counter+1).name = list_point_names[counter]

write_data(ug, filename)
6 changes: 5 additions & 1 deletion sharpy/postproc/beamplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ class BeamPlot(BaseSolver):
settings_default['output_rbm'] = True
settings_description['output_rbm'] = 'Write ``csv`` file with rigid body motion data'

settings_types['stride'] = 'int'
settings_default['stride'] = 1
settings_description['stride'] = 'Number of steps between the execution calls when run online'

settings_table = settings_utils.SettingsTable()
__doc__ += settings_table.generate(settings_types, settings_default, settings_description)

Expand Down Expand Up @@ -107,7 +111,7 @@ def plot(self, online):
self.write_beam(it)
if self.settings['include_FoR']:
self.write_for(it)
else:
elif ((len(self.data.structure.timestep_info) - 1) % self.settings['stride'] == 0):
it = len(self.data.structure.timestep_info) - 1
self.write_beam(it)
if self.settings['include_FoR']:
Expand Down
Loading