Source code for openaerostruct.functionals.total_lift_drag
importopenmdao.apiasom
[docs]classTotalLiftDrag(om.ExplicitComponent):""" Compute the coefficients of lift (CL) and drag (CD) and dimensional lift (L) and drag (D) for the entire aircraft, based on the area-weighted sum of individual surfaces' CLs and CDs. Parameters ---------- CL : float Coefficient of lift (CL) for one lifting surface. CD : float Coefficient of drag (CD) for one lifting surface. S_ref : float Surface area for one lifting surface. rho : float Freestream density. v : float Freestream velocity. Returns ------- CL : float Total coefficient of lift (CL) for the entire aircraft. CD : float Total coefficient of drag (CD) for the entire aircraft. L : float Total lift force (L) for the entire aircraft. D : float Total drag force (D) for the entire aircraft. """definitialize(self):self.options.declare("surfaces",types=list)defsetup(self):forsurfaceinself.options["surfaces"]:name=surface["name"]self.add_input(name+"_CL",val=1.0,tags=["mphys_result"])self.add_input(name+"_CD",val=1.0,tags=["mphys_result"])self.add_input(name+"_S_ref",val=1.0,units="m**2",tags=["mphys_coupling"])self.declare_partials(["CL","L"],name+"_CL")self.declare_partials(["CD","D"],name+"_CD")self.declare_partials(["CL","L"],name+"_S_ref")self.declare_partials(["CD","D"],name+"_S_ref")self.add_input("S_ref_total",val=1.0,units="m**2",tags=["mphys_input"])self.add_input("rho",val=1.0,units="kg/m**3",tags=["mphys_input"])self.add_input("v",val=1.0,units="m/s",tags=["mphys_input"])self.add_output("CL",val=1.0,tags=["mphys_result"])self.add_output("CD",val=1.0,tags=["mphys_result"])self.add_output("L",val=1.0,units="N",tags=["mphys_result"])self.add_output("D",val=1.0,units="N",tags=["mphys_result"])self.declare_partials("CL","S_ref_total")self.declare_partials("CD","S_ref_total")self.declare_partials(["L","D"],["rho","v"])defcompute(self,inputs,outputs):# Compute the weighted CL and CD contributions from each surface,# weighted by the individual surface areasCL=0.0CD=0.0forsurfaceinself.options["surfaces"]:name=surface["name"]S_ref=inputs[name+"_S_ref"]CL+=inputs[name+"_CL"]*S_refCD+=inputs[name+"_CD"]*S_ref# Before normalizing by total area, compute L and Doutputs["L"]=CL*0.5*inputs["rho"]*inputs["v"]**2outputs["D"]=CD*0.5*inputs["rho"]*inputs["v"]**2# Normalize by total area to get coefficientsoutputs["CL"]=CL/inputs["S_ref_total"]outputs["CD"]=CD/inputs["S_ref_total"]defcompute_partials(self,inputs,partials):# Compute the weighted CL and CD contributions from each surface,# weighted by the individual surface areasCL=0.0CD=0.0forsurfaceinself.options["surfaces"]:name=surface["name"]S_ref=inputs[name+"_S_ref"]CL+=inputs[name+"_CL"]*S_refCD+=inputs[name+"_CD"]*S_refS_ref_total=inputs["S_ref_total"]partials["L","rho"]=CL*0.5*inputs["v"]**2partials["D","rho"]=CD*0.5*inputs["v"]**2partials["L","v"]=CL*inputs["rho"]*inputs["v"]partials["D","v"]=CD*inputs["rho"]*inputs["v"]partials["CL","S_ref_total"]=-CL/S_ref_total**2partials["CD","S_ref_total"]=-CD/S_ref_total**2forsurfaceinself.options["surfaces"]:name=surface["name"]S_ref=inputs[name+"_S_ref"]partials["CL",name+"_CL"]=S_ref/S_ref_totalpartials["CD",name+"_CD"]=S_ref/S_ref_totalpartials["CL",name+"_S_ref"]=inputs[name+"_CL"]/S_ref_totalpartials["CD",name+"_S_ref"]=inputs[name+"_CD"]/S_ref_totalpartials["L",name+"_CL"]=0.5*inputs["rho"]*inputs["v"]**2*S_refpartials["D",name+"_CD"]=0.5*inputs["rho"]*inputs["v"]**2*S_refpartials["L",name+"_S_ref"]=0.5*inputs["rho"]*inputs["v"]**2*inputs[name+"_CL"]partials["D",name+"_S_ref"]=0.5*inputs["rho"]*inputs["v"]**2*inputs[name+"_CD"]