Skip to content

Commit

Permalink
Cleaned up code in line with PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-l-p committed Nov 13, 2024
1 parent 5b9765e commit 55f20eb
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 96 deletions.
133 changes: 60 additions & 73 deletions sharpy/aero/models/aerogrid.py

Large diffs are not rendered by default.

8 changes: 3 additions & 5 deletions sharpy/controllers/multibodycontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class MultibodyController(controller_interface.BaseController):
)

def __init__(self):
self.in_dict = None
self.in_dict = None # this also holds the settings dict, kept to be consistent with other controllers
self.data = None
self.settings = None

Expand Down Expand Up @@ -157,13 +157,11 @@ def control(self, data, controlled_state):

if controlled_state["structural"].mb_prescribed_dict is None:
controlled_state["structural"].mb_prescribed_dict = dict()

controlled_state["structural"].mb_prescribed_dict[self.controller_id] = {
"psi": control_command,
"psi_dot": psi_dot,
}
controlled_state["structural"].mb_prescribed_dict[self.controller_id].update(
{"delta_psi": control_command - self.prescribed_ang_time_history[0, :]}
)
"delta_psi": control_command - self.prescribed_ang_time_history[0, :]}

return controlled_state, control_command

Expand Down
6 changes: 3 additions & 3 deletions sharpy/solvers/statictrim.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,11 @@ def trim_algorithm(self):

def evaluate(self, alpha, deflection_gamma, thrust):
if not np.isfinite(alpha):
raise ValueError
raise ValueError("Alpha trim gradient is zero, resulting in division by zero.")
if not np.isfinite(deflection_gamma):
raise ValueError
raise ValueError("Delta trim gradient is zero, resulting in division by zero.")
if not np.isfinite(thrust):
raise ValueError
raise ValueError("Thrust trim gradient is zero, resulting in division by zero.")

# modify the trim in the static_coupled solver
self.solver.change_trim(alpha,
Expand Down
21 changes: 7 additions & 14 deletions sharpy/utils/generate_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -2029,27 +2029,20 @@ def generate_multibody_file(list_LagrangeConstraints, list_Bodies, route, case_n
for param in required_parameters:
constraint_id.create_dataset(param, data=getattr(constraint, param))
try:
constraint_id.create_dataset("scalingFactor",
data=getattr(constraint, "scalingFactor"))
except:
constraint_id.create_dataset("scalingFactor", data=constraint.scalingFactor)
except AttributeError:
pass
try:
constraint_id.create_dataset("penaltyFactor",
data=getattr(constraint, "penaltyFactor"))
except:
constraint_id.create_dataset("penaltyFactor", data=constraint.penaltyFactor)
except AttributeError:
pass


try:
constraint_id.create_dataset("aerogrid_warp_factor",
data=getattr(constraint, "aerogrid_warp_factor"))
constraint_id.create_dataset("aerogrid_warp_factor", data=constraint.aerogrid_warp_factor)
except AttributeError:
pass

try:
constraint_id.create_dataset("rot_axisA2",
data=getattr(constraint, "rot_axisA2"))
except:
constraint_id.create_dataset("rot_axisA2", data=constraint.rot_axisA2)
except AttributeError:
pass

iconstraint += 1
Expand Down
3 changes: 2 additions & 1 deletion tests/coupled/static/smith_g_2deg/generate_smith_g_2deg.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ def generate_aero_file():
working_elem = 0
working_node = 0

# right wing (surface 0, beam 0)
i_surf = 0
airfoil_distribution[working_elem:working_elem + num_elem_main, :] = 0
surface_distribution[working_elem:working_elem + num_elem_main] = i_surf
Expand All @@ -207,8 +208,8 @@ def generate_aero_file():
working_elem += num_elem_main
working_node += num_node_main

# right wing (surface 1, beam 1)
i_surf = 1

airfoil_distribution[working_elem:working_elem + num_elem_main, :] = 0
surface_distribution[working_elem:working_elem + num_elem_main] = i_surf
surface_m[i_surf] = m_main
Expand Down
1 change: 1 addition & 0 deletions tests/coupled/static/smith_g_4deg/generate_smith_g_4deg.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ def generate_aero_file():
working_elem = 0
working_node = 0

# right wing (surface 0, beam 0)
i_surf = 0
airfoil_distribution[working_elem:working_elem + num_elem_main, :] = 0
surface_distribution[working_elem:working_elem + num_elem_main] = i_surf
Expand Down

0 comments on commit 55f20eb

Please sign in to comment.