import numpy as np
[docs]
def lift_drag_coeff(
alpha,
normals,
Sref = 80,
CoefPressure=None,
CoefSkinFriction=None,
):
r"""
Calculate lift and drag coefficients from pressure and skin friction coefficients.
Args:
alpha (float): Angle of attack in degrees.
normals (np.ndarray): Array of shape (n,3) with the normal vectors of the surface.
Sref (float, optional): Reference area to calculate the lift and drag coefficients (default: ``80``).
CoefPressure (np.ndarray, optional): Array of shape (n,1) with the pressure coefficients of the surface. If ``None``, the pressure contribution is ignored (default: ``None``).
CoefSkinFriction (np.ndarray, optional): Array of shape (n,3) with the skin friction coefficients of the surface. If ``None``, the skin friction contribution is ignored (default: ``None``).
Returns:
Tuple[float, float]: Lift and drag coefficients.
"""
CoefLiftPressure, CoefDragPressure, CoefLiftFriction, CoefDragFriction = 0, 0, 0, 0
alpha_ = alpha*np.pi/180
Si = np.sqrt(normals[:,0]**2 + normals[:,1]**2 + normals[:,2]**2).reshape(-1,1)
if CoefPressure is not None:
if len(CoefPressure.shape) == 1:
CoefPressure = CoefPressure.reshape(-1,1)
elif CoefPressure.shape[1] > 1:
raise ValueError("CoefPressure must have shape (n,1).")
ForcePressure = -CoefPressure*normals
CoefLiftPressure = np.sum(ForcePressure[:,2]*np.cos(alpha_)) - np.sum(ForcePressure[:,0]*np.sin(alpha_))
CoefDragPressure = np.sum(ForcePressure[:,2]*np.sin(alpha_)) + np.sum(ForcePressure[:,0]*np.cos(alpha_))
if CoefSkinFriction is not None:
if len(CoefSkinFriction.shape) == 1:
CoefSkinFriction = CoefSkinFriction.reshape(-1,3)
elif CoefSkinFriction.shape[1] != 3:
raise ValueError("CoefSkinFriction must have shape (n,3).")
ForceFriction = CoefSkinFriction*Si
CoefLiftFriction = np.sum(ForceFriction[:,2]*np.cos(alpha_)) - np.sum(ForceFriction[:,0]*np.sin(alpha_))
CoefDragFriction = np.sum(ForceFriction[:,2]*np.sin(alpha_)) + np.sum(ForceFriction[:,0]*np.cos(alpha_))
if CoefPressure is None and CoefSkinFriction is None:
raise ValueError("At least one of CoefPressure or CoefSkinFriction must be provided.")
CL = (CoefLiftPressure + CoefLiftFriction)/Sref
CD = (CoefDragPressure + CoefDragFriction)/Sref
return CL, CD