Beispiel #1
0
def _ArrayToSwigVec3(a):
    """Converts a numpy array to a Swig Vec3."""
    v = physics.Vec3()
    a_linear = np.reshape(a, (3, ))
    v.x = a_linear[0]
    v.y = a_linear[1]
    v.z = a_linear[2]
    return v
Beispiel #2
0
    def CalcLiftAndDragCoeffs(self, state, inputs):
        """Calculate the lift and drag coefficients."""

        wing_inputs = self.InputsToWingInputs(inputs)
        wing_state = self.StateToWingState(state)

        v_rel, alpha, beta = wing_state.CalcAerodynamicAngles(
            wing_inputs.wind_g)
        # Fixing total thrust coefficient to 0.0 for this application.
        thrust_coeff = 0.0
        _, cf_b, _ = self._wing.CalcAeroForceMomentPos(v_rel, alpha, beta,
                                                       wing_state.omega_b,
                                                       wing_inputs.flaps,
                                                       thrust_coeff)

        c_cf_b = physics.Vec3()
        c_cf_b.x = cf_b[0, 0]
        c_cf_b.y = cf_b[1, 0]
        c_cf_b.z = cf_b[2, 0]
        c_cf_w = physics.Vec3()
        physics.RotBToW(c_cf_b.this, alpha, beta, c_cf_w.this)

        return -c_cf_w.z, -c_cf_w.x
Beispiel #3
0
def _GetStabilityCoefficients(lookup_function,
                              alphas,
                              betas,
                              dflaps=None,
                              domega=None):
    """Generates array of force and moment coefficients in stability axes."""
    cf_s = np.zeros((3, len(alphas), len(betas)))
    cm_s = np.zeros((3, len(alphas), len(betas)))
    for i, alpha in enumerate(alphas):
        for j, beta in enumerate(betas):
            cf_b, cm_b = lookup_function(alpha,
                                         beta,
                                         dflaps=dflaps,
                                         domega=domega)
            cf_b_vec3 = _ArrayToSwigVec3(cf_b)
            cf_s_vec3 = physics.Vec3()
            physics.RotBToS(cf_b_vec3.this, alpha, cf_s_vec3.this)
            cm_b_vec3 = _ArrayToSwigVec3(cm_b)
            cm_s_vec3 = physics.Vec3()
            physics.RotBToS(cm_b_vec3.this, alpha, cm_s_vec3.this)
            cf_s[:, i, j] = _SwigVec3ToArray(cf_s_vec3)
            cm_s[:, i, j] = _SwigVec3ToArray(cm_s_vec3)
    return cf_s, cm_s
Beispiel #4
0
  def testStateToVector(self):
    """Simple test of calling the Aero class."""
    aero = physics.Aero(physics.GetAeroSimParams())

    omega_hat = physics.Vec3()
    omega_hat.x = 0.0
    omega_hat.y = 0.0
    omega_hat.z = 0.0
    flaps = physics.VecWrapper(system_types.kNumFlaps)
    for i in range(system_types.kNumFlaps):
      flaps.SetValue(i, 0.0)
    force_moment = physics.ForceMoment()
    thrust_coeff = 0.0
    aero.CalcForceMomentCoeff(0.0, 0.0, omega_hat, flaps.GetVec(), 0.0,
                              force_moment, thrust_coeff)
Beispiel #5
0
  def CalcFMCoeff(self, alpha, beta, flaps, c_omega, thrust_coeff):
    """Calculates the body force and moment coefficients from an DVL database.

    This function should mirror the functionality of Aero::CalcDvlAeroCFM in the
    sim.

    Args:
      alpha: Angle of attack [rad].
      beta: Side-slip angle [rad].
      flaps: Array of kNumFlaps-by-1 control surface deflections [rad].
      c_omega: Array of 3-by-1 dimensionless body rates [#].
      thrust_coeff: Double of thrust coefficient [#], wind turbine notation.

    Returns:
      A tuple (cf, cm) containing the force and moment coefficients.

    Raises:
      DimensionException: The argument flaps has an incorrect shape.
    """
    if flaps.shape not in ((system_types.kNumFlaps,),
                           (system_types.kNumFlaps, 1)):
      raise DimensionException('Only %d flaps supported.' % self._num_flaps)
    if c_omega.shape not in ((3,), (3, 1)):
      raise DimensionException('c_omega must be a 3 vector.')

    flaps_vec = physics.VecWrapper(system_types.kNumFlaps)
    for i in range(system_types.kNumFlaps):
      flaps_vec.SetValue(i, flaps[i])

    c_omega_vec3 = physics.Vec3()
    c_omega_vec3.x = c_omega[0]
    c_omega_vec3.y = c_omega[1]
    c_omega_vec3.z = c_omega[2]

    force_moment = physics.ForceMoment()
    self._swig_dvl.CalcForceMomentCoeff(alpha, beta, c_omega_vec3.this,
                                        flaps_vec.GetVec(), force_moment.this,
                                        thrust_coeff)
    cf = numpy.array([[force_moment.force.x,
                       force_moment.force.y,
                       force_moment.force.z]]).T
    cm = numpy.array([[force_moment.moment.x,
                       force_moment.moment.y,
                       force_moment.moment.z]]).T

    return (cf, cm)
Beispiel #6
0
def CalcBlendForceMomentCoeffs(aero_model,
                               alpha,
                               beta=0.0,
                               omega_hat=(0.0, 0.0, 0.0),
                               flaps=((0.0, ) * labels.kNumFlaps),
                               reynolds_number=None):
    """Calculates a BlendDatum of force-moment coefficients.

  Args:
    aero_model: A physics.Aero instance.
    alpha: Angle-of-attack [rad].
    beta: Sideslip angle [rad].
    omega_hat: Length-3 object of body rates [rad/s].
    flaps: Length-8 object of flap deflections [rad].
    reynolds_number: Reynolds number [#].

  Returns:
    BlendDatum of force-moment coefficients.
  """

    omega_hat_vec3 = physics.Vec3()
    omega_hat_vec3.x, omega_hat_vec3.y, omega_hat_vec3.z = omega_hat

    flaps_vec = physics.VecWrapper(labels.kNumFlaps)
    for i, flap in enumerate(flaps):
        flaps_vec.SetValue(i, flap)

    if reynolds_number is None:
        reynolds_number = FLAGS.re

    cfms = BlendDatum(lambda key: physics.ForceMoment())
    thrust_coeff = FLAGS.thrust_coeff

    aero_model.CalcLowIncidenceCoeffs(alpha, beta, omega_hat_vec3,
                                      flaps_vec.GetVec(), reynolds_number,
                                      cfms['low'].this, thrust_coeff)
    aero_model.CalcHighIncidenceCoeffs(alpha, beta, omega_hat_vec3,
                                       flaps_vec.GetVec(), reynolds_number,
                                       cfms['high'].this, thrust_coeff)
    aero_model.CalcForceMomentCoeff(alpha, beta, omega_hat_vec3,
                                    flaps_vec.GetVec(), reynolds_number,
                                    cfms['blended'].this, thrust_coeff)
    return cfms
Beispiel #7
0
 def CalcFMCoeff(self, alpha, beta, reynolds_number, flaps, omega_hat,
                 thrust_coeff):
     """Calculates force and moment coefficients from the Swig database."""
     omega_hat_vec3 = physics.Vec3()
     omega_hat_vec3.x = omega_hat[0, 0]
     omega_hat_vec3.y = omega_hat[1, 0]
     omega_hat_vec3.z = omega_hat[2, 0]
     flaps_vec = physics.VecWrapper(system_types.kNumFlaps)
     for i in range(system_types.kNumFlaps):
         flaps_vec.SetValue(i, flaps[i, 0])
     force_moment = physics.ForceMoment()
     self._aero.CalcForceMomentCoeff(alpha, beta, omega_hat_vec3.this,
                                     flaps_vec.GetVec(), reynolds_number,
                                     force_moment.this, thrust_coeff)
     force_moment_coeff = (np.matrix([[force_moment.force.x],
                                      [force_moment.force.y],
                                      [force_moment.force.z]]),
                           np.matrix([[force_moment.moment.x],
                                      [force_moment.moment.y],
                                      [force_moment.moment.z]]))
     return force_moment_coeff
Beispiel #8
0
def RotBToW(cf_b, alpha, beta):
    cf_w = physics.Vec3()
    physics.RotBToW(cf_b.this, alpha, beta, cf_w.this)
    return cf_w