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

A few minor bug fixes #273

Merged
merged 9 commits into from
Dec 27, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -2368,9 +2368,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Run SHARPy Simulation"
"execution_count": 22,
]
"### Run SHARPy Simulation"]
},
{
"cell_type": "code",
Expand Down
13 changes: 4 additions & 9 deletions sharpy/postproc/aeroforcescalculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,8 @@ def calculate_forces(self, ts):
self.data.aero.timestep_info[ts].body_unsteady_forces[i_surf, 0:3]
) = self.calculate_forces_for_isurf_in_g_frame(force[i_surf], unsteady_force=unsteady_force[i_surf])

print(self.settings["nonlifting_body"])
if self.settings["nonlifting_body"]:
print(self.data.nonlifting_body.n_surf)
for i_surf in range(self.data.nonlifting_body.n_surf):
print(i_surf)
(
self.data.nonlifting_body.timestep_info[ts].inertial_steady_forces[i_surf, 0:3],
self.data.nonlifting_body.timestep_info[ts].body_steady_forces[i_surf, 0:3],
Expand Down Expand Up @@ -236,8 +233,8 @@ def screen_output(self, ts):
def file_output(self, filename):
# assemble forces/moments matrix
# (1 timestep) + (3+3 inertial steady+unsteady) + (3+3 body steady+unsteady)
force_matrix = np.zeros((self.ts_max, 1 + 3 + 3 + 3 + 3 + 3 + 3))
moment_matrix = np.zeros((self.ts_max, 1 + 3 + 3 + 3 + 3 + 3 + 3))
force_matrix = np.zeros((self.ts_max, 1 + 3 + 3 + 3 + 3 ))
moment_matrix = np.zeros((self.ts_max, 1 + 3 + 3 + 3 + 3))
for ts in range(self.ts_max):
aero_tstep = self.data.aero.timestep_info[ts]
i = 0
Expand Down Expand Up @@ -271,12 +268,10 @@ def file_output(self, filename):
header += 'fx_unsteady_G, fy_unsteady_G, fz_unsteady_G, '
header += 'fx_steady_a, fy_steady_a, fz_steady_a, '
header += 'fx_unsteady_a, fy_unsteady_a, fz_unsteady_a'
header += 'mx_total_G, my_total_G, mz_total_G'
header += 'mx_total_a, my_total_a, mz_total_a'

np.savetxt(self.folder + 'forces_' + filename,
force_matrix,
fmt='%i' + ', %10e'*18,
fmt='%i' + ', %10e' * (np.shape(force_matrix)[1] - 1),
delimiter=',',
header=header,
comments='#')
Expand All @@ -290,7 +285,7 @@ def file_output(self, filename):

np.savetxt(self.folder + 'moments_' + filename,
moment_matrix,
fmt='%i' + ', %10e'*18,
fmt='%i' + ', %10e' * (np.shape(moment_matrix)[1] - 1),
delimiter=',',
header=header,
comments='#')
58 changes: 32 additions & 26 deletions sharpy/postproc/savedata.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,7 @@ def initialise(self, data, custom_settings=None, caller=None, restart=False):
self.filename_linear = self.folder + self.data.settings['SHARPy']['case'] + '.linss.h5'

# remove old file if it exists
for file_path in [self.filename, self.filename_linear]:
if os.path.isfile(file_path):
os.remove(file_path)
self.remove_file_if_exist(self.filename)

# check that there is a linear system - else return setting to false
if self.settings['save_linear'] or self.settings['save_linear_uvlm']:
Expand Down Expand Up @@ -204,6 +202,10 @@ def initialise(self, data, custom_settings=None, caller=None, restart=False):
self.ClassesToSave += (sharpy.solvers.linearassembler.Linear, sharpy.linear.src.libss.ss_block)
self.caller = caller

def remove_file_if_exist(self, filepath):
if os.path.isfile(filepath):
os.remove(filepath)

def run(self, **kwargs):

online = settings_utils.set_value_or_default(kwargs, 'online', False)
Expand Down Expand Up @@ -247,33 +249,37 @@ def run(self, **kwargs):

hdfile.close()

if self.settings['save_linear_uvlm']:
linhdffile = h5py.File(self.filename.replace('.data.h5', '.uvlmss.h5'), 'a')
h5utils.add_as_grp(self.data.linear.linear_system.uvlm.ss, linhdffile, grpname='ss',
if self.settings['save_linear_uvlm']:
linhdffile = h5py.File(self.filename.replace('.data.h5', '.uvlmss.h5'), 'a')
self.remove_file_if_exist(linhdffile)
h5utils.add_as_grp(self.data.linear.linear_system.uvlm.ss, linhdffile, grpname='ss',
ClassesToSave=self.ClassesToSave, SkipAttr=self.settings['skip_attr'],
compress_float=self.settings['compress_float'])
h5utils.add_as_grp(self.data.linear.linear_system.linearisation_vectors, linhdffile,
grpname='linearisation_vectors',
ClassesToSave=self.ClassesToSave, SkipAttr=self.settings['skip_attr'],
compress_float=self.settings['compress_float'])
linhdffile.close()

if self.settings['save_linear']:
self.remove_file_if_exist(self.filename_linear)
with h5py.File(self.filename_linear, 'a') as linfile:
h5utils.add_as_grp(self.data.linear.linear_system.linearisation_vectors, linfile,
grpname='linearisation_vectors',
ClassesToSave=self.ClassesToSave, SkipAttr=self.settings['skip_attr'],
compress_float=self.settings['compress_float'])
h5utils.add_as_grp(self.data.linear.linear_system.linearisation_vectors, linhdffile,
grpname='linearisation_vectors',
h5utils.add_as_grp(self.data.linear.ss, linfile, grpname='ss',
ClassesToSave=self.ClassesToSave, SkipAttr=self.settings['skip_attr'],
compress_float=self.settings['compress_float'])
linhdffile.close()

if self.settings['save_linear']:
with h5py.File(self.filename_linear, 'a') as linfile:
h5utils.add_as_grp(self.data.linear.linear_system.linearisation_vectors, linfile,
grpname='linearisation_vectors',
ClassesToSave=self.ClassesToSave, SkipAttr=self.settings['skip_attr'],
compress_float=self.settings['compress_float'])
h5utils.add_as_grp(self.data.linear.ss, linfile, grpname='ss',
ClassesToSave=self.ClassesToSave, SkipAttr=self.settings['skip_attr'],
compress_float=self.settings['compress_float'])

if self.settings['save_rom']:
try:
for k, rom in self.data.linear.linear_system.uvlm.rom.items():
rom.save(self.filename.replace('.data.h5', '_{:s}.rom.h5'.format(k.lower())))
except AttributeError:
cout.cout_wrap('Could not locate a reduced order model to save')

if self.settings['save_rom']:
try:
for k, rom in self.data.linear.linear_system.uvlm.rom.items():
romhdffile = self.filename.replace('.data.h5', '_{:s}.rom.h5'.format(k.lower()))
self.remove_file_if_exist(romhdffile)
rom.save(romhdffile)
except AttributeError:
cout.cout_wrap('Could not locate a reduced order model to save')

elif self.settings['format'] == 'mat':
from scipy.io import savemat
Expand Down
2 changes: 1 addition & 1 deletion sharpy/structure/utils/modalutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def write_modes_vtk(data, eigenvectors, NumLambda, filename_root,
else:
num_rigid_body = 0

for mode in range(num_rigid_body, NumLambda - num_rigid_body):
for mode in range(num_rigid_body, NumLambda):
# scale eigenvector
eigvec = eigenvectors[:num_dof, mode]
fact = scale_mode(data, eigvec, rot_max_deg, perc_max)
Expand Down