Guest User

core

a guest
Feb 12th, 2021
433
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.80 KB | None | 0 0
  1. import openmdao.api as om
  2. import numpy as np
  3. import matplotlib.pyplot as plt
  4.  
  5. import Inviscid as inviscid
  6.  
  7. if __name__ == "__main__":
  8.  
  9.     def plot_pressure(soln_filename=None):
  10.         plt.plot(p.get_val('aerofoil_ccw_coordinates')[0, :], p.get_val('aerofoil_ccw_coordinates')[1, :])
  11.         plt.plot(p.get_val('InviscidSubsystem.collocation_point_coordinates')[0, :], p.get_val('InviscidSubsystem.collocation_point_coordinates')[1, :], marker=".", linestyle='None')
  12.         plt.plot(p.get_val('InviscidSubsystem.extra_collocation_point_coordinates')[0, :], p.get_val('InviscidSubsystem.extra_collocation_point_coordinates')[1, :], marker=".", linestyle='None')
  13.         plt.plot(p.get_val('InviscidSubsystem.collocation_point_coordinates')[0, :], -p.get_val('pressure_coefficients'), label="TASWiG")
  14.         if soln_filename:
  15.             javafoil = np.loadtxt(soln_filename)
  16.             plt.plot(javafoil[:, 0], -javafoil[:, 2], label="Javafoil")
  17.         plt.xlim(-0.1, 1.1)
  18.         plt.ylim(-1, 1.8)
  19.         plt.xlabel("x/c")
  20.         plt.ylabel("-Cp")
  21.         plt.legend()
  22.         plt.show()
  23.  
  24.     def nice_check_partials():
  25.         with np.printoptions(linewidth=1024, edgeitems=20, formatter={'float_kind': '{:5.5f}'.format}):
  26.             # formatter={'float_kind': '{:5.2f}'.format})
  27.             p.check_partials(show_only_incorrect=True, compact_print=False)
  28.  
  29.     aerofoil_path = r"DOWNLOAD THE AEROFOIL COORDINATES AND PUT THE FILEPATH HERE"
  30.     aerofoil = np.loadtxt(aerofoil_path).T
  31.     num_points = aerofoil.shape[1]
  32.     # num_points = 61
  33.     # num_upper_weights = 3
  34.     # num_lower_weights = 3
  35.  
  36.     p = om.Problem(model=om.Group())
  37.     p.model.add_subsystem('InviscidSubsystem',
  38.                           inviscid.InviscidGroup(num_points=num_points),
  39.                           promotes_inputs=['aerofoil_ccw_coordinates', 'alpha'],
  40.                           promotes_outputs=['external_tangential_velocities',
  41.                                             'pressure_coefficients',
  42.                                             'stagnation_point_position'])
  43.  
  44.     p.model.set_input_defaults('alpha', 0.5, units='deg')
  45.     p.model.set_input_defaults('aerofoil_ccw_coordinates', aerofoil)
  46.  
  47.     p.model.add_subsystem('obj_cmp', om.ExecComp('obj = (stagnation_point_position-1.0)**2'), promotes=['stagnation_point_position', 'obj'])
  48.  
  49.     p.model.add_objective('obj')
  50.     p.model.add_design_var('alpha', lower=0, upper=10, units='deg')
  51.  
  52.     p.driver = om.ScipyOptimizeDriver()
  53.     p.driver.options['optimizer'] = 'SLSQP'
  54.     #p.driver.options['maxiter'] = 100
  55.     p.driver.options['tol'] = 1e-8
  56.     p.driver.options['debug_print'] = ['desvars', 'ln_cons', 'nl_cons', 'objs']
  57.  
  58.     p.setup()
  59.     print("Setup")
  60.     p.run_model()
  61.     print("Ran model")
  62.     p.run_driver()
  63.     print("Finished optimisation")
  64.  
  65.  
  66.  
Advertisement
Add Comment
Please, Sign In to add comment