Skip to content

Commit

Permalink
Merge pull request #164 from Eriklyy/dev_io_thrust
Browse files Browse the repository at this point in the history
Change in the io-Settings to add thrust.
  • Loading branch information
ngoiz authored May 5, 2022
2 parents 7956fc5 + 4a23ba9 commit 961a7f6
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 11 deletions.
39 changes: 28 additions & 11 deletions sharpy/io/inout_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def get_variable_value(self, data, timestep_index=-1):
logger.error(msg)
raise IndexError(msg)

#Had to add this part for for_pos and for_vel since they are arrays.
#Needed for for_pos and for_vel since they are arrays.
if len(variable.shape) == 1:
try:
value = variable[self.node, self.index]
Expand Down Expand Up @@ -158,23 +158,40 @@ def set_in_timestep(self, data):
data (sharpy.presharpy.PreSharpy): Simulation data object
"""
if self.node is not None: # structural variable then
variable = getattr(data.structure.timestep_info[-1], self.name)
try:
variable[self.node, self.index] = self.value
except IndexError:
logger.warning('Unable to set node {}, index {} of variable {}'.format(
self.node, self.index, self.dref_name
))
if self.node is not None:
# Check if the node is an app_forces (f.e. Thrust)
if self.name == 'app_forces':
logger.debug('Setting thrust variable')
variable = data.structure.ini_info.steady_applied_forces
try:
variable[self.node, self.index] = self.value
except IndexError:
logger.warning('Unable to set node {}, index {} of variable {}'.format(
self.node, self.index, self.dref_name
))

data.structure.ini_info.steady_applied_forces = variable
logger.debug('Updated timestep')

# else it is a structural variable
else:
variable = getattr(data.structure.timestep_info[-1], self.name)
try:
variable[self.node, self.index] = self.value
except IndexError:
logger.warning('Unable to set node {}, index {} of variable {}'.format(
self.node, self.index, self.dref_name
))

setattr(data.structure.timestep_info[-1], self.name, variable)
logger.debug('Updated timestep')

if self.cs_index is not None:
variable = getattr(data.aero.timestep_info[-1], self.name)

##Creates an array as long as needed. Not required Cs_deflections will be set to zero. If the CS_type in the
## aero.h5 file is 0 this shouldnt have a influence on them.
# Creates an array as long as needed. Not required Cs_deflections will be set to zero. If the CS_type in the
# aero.h5 file is 0 this shouldnt have a influence on them.

while len(variable) <= self.cs_index:
# Adds an element in the array for the new control surface.
variable = np.hstack((variable, np.array(0)))
Expand Down
2 changes: 2 additions & 0 deletions tests/io/Example_simple_hale/Client_HALE.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

#initial values
cs_deflection = [-2.08 * np.pi / 180, 0]
thrust = 6.16
dt = 0.025
n_tstep = 0 #Counter for time

Expand All @@ -64,6 +65,7 @@
# send control input to sharpy
ctrl_value = struct.pack('<5sif', b'RREF0', 0, cs_deflection[0])
ctrl_value += struct.pack('if', 1, cs_deflection[1])
ctrl_value += struct.pack('if', 2, thrust)
logger.info('Sending control input of size {} bytes'.format(len(ctrl_value)))
in_sock.sendto(ctrl_value, sharpy_incoming)
logger.info('Sent control input to {}'.format(sharpy_incoming))
Expand Down
5 changes: 5 additions & 0 deletions tests/io/Example_simple_hale/generate_hale_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
'AerogridPlot',
'BeamPlot',
'DynamicCoupled',
'SaveData'
# 'Modal',
# 'LinearAssember',
# 'AsymptoticStability',
Expand Down Expand Up @@ -737,6 +738,10 @@ def generate_solver_file():
'num_steps': n_tstep,
'dt': dt,
'initial_velocity': u_inf * int(free_flight)}
settings['SaveData'] = { 'save_aero': 'on',
'save_struct': 'on',
'save_linear': 'off',
'save_linear_uvlm': 'off'}

relative_motion = 'off'
if not free_flight:
Expand Down
5 changes: 5 additions & 0 deletions tests/io/Example_simple_hale/variables_hale.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
var_type: 'control_surface'
inout: 'in'
position: 1
- name: 'app_forces'
var_type: 'node'
inout: 'in'
position: 0
index: 1
- name: 'for_pos'
inout: 'out'
position: 0
Expand Down

0 comments on commit 961a7f6

Please sign in to comment.