refactor [utils] function to get aero solver settings
first, the outputs of the function is reduced as the name of the aero solver name is unused where the function is called
second, instead of many ifs and copied code a for loop is implemented to make the code leaner
@@ -130,38 +130,27 @@ def span_chord(i_node_surf, zeta):
return dir_span, span, dir_chord, chord
-def find_aerodynamic_solver(settings):
+def find_aerodynamic_solver_settings(settings):
"""
- Retrieves the name and settings of the first aerodynamic solver used in the solution ``flow``.
+ Retrieves the settings of the first aerodynamic solver used in the solution ``flow``.
+
Args:
settings (dict): SHARPy settings (usually found in ``data.settings`` )
Returns:
- tuple: Aerodynamic solver name and solver settings
+ tuple: Aerodynamic solver settings
"""
flow = settings['SHARPy']['flow']
- # Look for the aerodynamic solver
- if 'StaticUvlm' in flow:
- aero_solver_name = 'StaticUvlm'
- aero_solver_settings = settings['StaticUvlm']
- elif 'StaticCoupled' in flow:
- aero_solver_name = settings['StaticCoupled']['aero_solver']
- aero_solver_settings = settings['StaticCoupled']['aero_solver_settings']
- elif 'StaticCoupledRBM' in flow:
- aero_solver_name = settings['StaticCoupledRBM']['aero_solver']
- aero_solver_settings = settings['StaticCoupledRBM']['aero_solver_settings']
- elif 'DynamicCoupled' in flow:
- aero_solver_name = settings['DynamicCoupled']['aero_solver']
- aero_solver_settings = settings['DynamicCoupled']['aero_solver_settings']
- elif 'StepUvlm' in flow:
- aero_solver_name = 'StepUvlm'
- aero_solver_settings = settings['StepUvlm']
- else:
- raise KeyError("ERROR: aerodynamic solver not found")
+ for solver_name in ['StaticUvlm', 'StaticCoupled', 'DynamicCoupled', 'StepUvlm']:
+ if solver_name in flow:
+ aero_solver_settings = settings[solver_name]
+ if 'aero_solver' in settings[solver_name].keys():
+ aero_solver_settings = aero_solver_settings['aero_solver']
- return aero_solver_name, aero_solver_settings
+ return aero_solver_settings
+ raise KeyError("ERROR: Aerodynamic solver not found.")
def find_velocity_generator(settings):
"""
@@ -174,7 +163,7 @@ def find_velocity_generator(settings):
Returns:
tuple: velocity generator name and velocity generator settings
"""
- aero_solver_name, aero_solver_settings = find_aerodynamic_solver(settings)
+ aero_solver_settings = find_aerodynamic_solver_settings(settings)
vel_gen_name = aero_solver_settings['velocity_field_generator']
vel_gen_settings = aero_solver_settings['velocity_field_input']
