Esempio n. 1
0
def get_single_propeller_info(prop_dg):
    """
    Gets propeller info for a single propeller degen geom object
    :param prop_dg: propeller degen geom object
    :return: propeller info named tuple
    """

    # Define named tuple
    #PropInfo = namedtuple("PropInfo", "geom_id thrust_vector rotation_direction hub_center transmat diameter")

    reverse_flag = vsp.GetParmVal(prop_dg.geom_id, "ReverseFlag", "Design")
    rotation_dir_geom = 1 if reverse_flag < 0.5 else -1

    diameter = vsp.GetParmVal(prop_dg.geom_id, "Diameter", "Design")

    # Use transformation matrix to get hub center and rotate default thrust vector into position
    transmat = prop_dg.transmat
    hub_center = transmat.get_translations()
    thrust_vector = transmat.apply_rotations(
        np.array([-1.0, 0.0, 0.0]).reshape((3, 1)))

    # Check the flip normal flag to determine if rotation direction should be reversed
    rotation_dir_blade = rotation_dir_geom
    if (prop_dg.flip_normal == 0
            and not reverse_flag) or (prop_dg.flip_normal == 1
                                      and reverse_flag):
        rotation_dir_blade *= -1

    return PropInfo(prop_dg.geom_id, thrust_vector, rotation_dir_blade,
                    hub_center, transmat, diameter)
Esempio n. 2
0
def get_wing_reference_quantities(wing_name=None, wing_id=None):
    """
    Gets wing reference area, reference span, and reference chord (sref, bref, cref) from the TotalArea, TotalSpan, and
    TotalChord properties of Wing component

    :param wing_name: Name of the wing (will find the first wing with this name)
    :param wing_id: ID of the wing object, if None wing name will be used to find the wing id. Wing ID takes precedence
    over wing_name
    :return: sref, bref, and cref
    """

    # Check that the wing_name and wing_id are not both none
    if wing_name is None and wing_id is None:
        raise ValueError("wing_name and wing_id cannot both be None")

    # If wing_id is None, then use wing name to find the wing id
    if wing_id is None:
        found_wing_id = vsp.FindGeom(wing_name, 0)
        if not found_wing_id:
            raise ValueError(
                "could not find wing with name \"{}\"".format(wing_name))
        wing_id = found_wing_id

    # Get reference parameters
    # TODO: Error check that the wing_id is actually the id to a wing component
    bref = vsp.GetParmVal(wing_id, "TotalSpan", "WingGeom")
    sref = vsp.GetParmVal(wing_id, "TotalArea", "WingGeom")
    cref = vsp.GetParmVal(wing_id, "TotalChord", "WingGeom")

    return sref, bref, cref
Esempio n. 3
0
    def test_parasite_drag(self):
        import numpy as np
        vsp.VSPRenew()
        vsp.ClearVSPModel()
        wing_id = vsp.AddGeom("WING")
        pod_id = vsp.AddGeom("POD")
        sref = vsp.GetParmVal(wing_id, "TotalArea", "WingGeom")

        res = vsp.parasitedrag_sweep(speeds=np.linspace(10, 250, 10),
                                     alts_ft=[0, 10000, 20000, 50000],
                                     sref=sref,
                                     length_unit=vsp.LEN_FT,
                                     speed_unit=vsp.V_UNIT_MPH)

        res.plot()
Esempio n. 4
0
    def test_parasite_drag(self):
        import numpy as np
        vsp.VSPRenew()
        vsp.ClearVSPModel()
        wing_id = vsp.AddGeom("WING")
        pod_id = vsp.AddGeom("POD")
        sref = vsp.GetParmVal(wing_id, "TotalArea", "WingGeom")

        res = vsp.parasitedrag_sweep(speeds=np.linspace(10, 250, 10),
                                     alts_ft=[0, 10000, 20000, 50000],
                                     sref=sref,
                                     length_unit=vsp.LEN_FT,
                                     speed_unit=vsp.V_UNIT_MPH)
        ax = res.plot()
        plt.legend()
        plt.savefig(os.path.join(self.OUTPUT_FOLDER, "parasite.png"), dpi=300)
        self.assertTrue(True)
Esempio n. 5
0
    def addVariable(self,
                    component,
                    group,
                    parm,
                    value=None,
                    lower=None,
                    upper=None,
                    scale=1.0,
                    scaledStep=True,
                    dh=1e-6):
        """
        Add a design variable definition.

        Parameters
        ----------
        component : str
            Name of the VSP component
        group : str
            Name of the VSP group
        parm : str
            Name of the VSP parameter
        value : float or None
            The design variable. If this value is not supplied (None), then
            the current value in the VSP model will be queried and used
        lower : float or None
            Lower bound for the design variable. Use None for no lower bound
        upper : float or None
            Upper bound for the design variable. Use None for no upper bound
        scale : float
            Scale factor
        scaledStep : bool
            Flag to use a scaled step sized based on the initial value of the
            variable. It will remain constant thereafter.
        dh : float
            Step size. When scaledStep is True, the actual step is dh*value. Otherwise
            this actual step is used.
        """

        container_id = openvsp.FindContainer(component, 0)
        if container_id == "":
            raise Error("Bad component for DV: %s" % component)

        parm_id = openvsp.FindParm(container_id, parm, group)
        if parm_id == "":
            raise Error(f"Bad group or parm: {component} {group} {parm}")

        # Now we know the parmID is ok. So we just get the value
        val = openvsp.GetParmVal(parm_id)

        dvName = f"{component}:{group}:{parm}"

        if value is None:
            value = val

        if scaledStep:
            dh = dh * value

            if value == 0:
                raise Error(
                    "Initial value is exactly 0. scaledStep option cannot be used"
                    "Specify an explicit dh with scaledStep=False")

        self.DVs[dvName] = vspDV(parm_id, component, group, parm, value, lower,
                                 upper, scale, dh)