Exemplo n.º 1
0
def genX3d(file=None, set=vsp.SET_ALL, dims=[1000, 400], **kwargs):

    if file is not None:
        vsp.ClearVSPModel()
        vsp.ReadVSPFile(file)
        vsp.Update()

    with RunManager(**kwargs):
        vsp.ExportFile("prop.x3d", set, vsp.EXPORT_X3D)
        with open("prop.x3d", "r") as f:
            x3d_str = f.read()

        x3d_str = x3d_str[0:26] + " width=\"{}px\" height=\"{}px\"".format(
            dims[0], dims[1]) + x3d_str[26:-1]

    return x3d_str
Exemplo n.º 2
0
def runAvl(avlInput,
           alpha=None,
           beta=None,
           savePlots=False,
           binPath=DEFAULT_AVL_BINARY,
           constraints=None,
           **kwargs):
    """

    :param avlInput: AvlInput object to run or
    :param alpha: array of angles of attack to run
    :param savePlots: boolean to save plots or not (default=False)
    :param binPath: path to binary file (optional)
    :param constraints: constraints structure to be used for trimming (default=None)
    :param kwargs: can pass cleanup_flag and change_dir to the RunManager class, if desired
    :return:
    """

    if alpha is None:
        alpha = list(range(-10, 21, 2))
    if beta is None:
        beta = [0]

    with RunManager(**kwargs) as r:
        # save avlInput to that directory
        inputFile = "avlinput.txt"
        avlInput.toFile(inputFile)
        plotFile = "plot.ps"
        outputFiles = []
        fsFiles = []
        cmd = 'plop\nG\n\n'  # turn off plotting
        cmd = cmd + 'load {}\n'.format(inputFile)
        cmd = cmd + 'oper\n'
        cmd = cmd + "g\n"  # go to geometry menu
        cmd = cmd + "h\n"  # print current geometry
        cmd = cmd + "no\n"  # turn normals on
        cmd = cmd + "h\n"  # print
        cmd = cmd + "no\n\n"  # turn normal off

        if constraints is not None:
            for constraint in constraints:
                cmd = cmd + "%s %s %f\n" % tuple(constraint)

        for a in alpha:
            for b in beta:
                cmd = cmd + "+\n"  # add new run case
                cmd = cmd + "a a {}\n".format(
                    a)  # add this alpha to the run case
                cmd = cmd + "b b {}\n".format(
                    b)  # add this beta to the run case
                cmd = cmd + "x\n"  # execute run case
                cmd = cmd + "st\n"
                f = "results_alpha_{}_beta_{}.txt".format(a, b)
                outputFiles.append(f)
                cmd = cmd + f + "\n"

                cmd = cmd + "g\n"  # go to geometry menu
                cmd = cmd + "lo\n"  # turn loading on
                cmd = cmd + "h\n"  # print
                cmd = cmd + "lo\n"  # turn loading off
                cmd = cmd + "\n"  #go back to oper menu

                # save out strip forces
                cmd = cmd + "FS\n"
                fsFiles.append("strip_forces_{}_{}.txt".format(a, b))
                cmd = cmd + "{}\n".format(fsFiles[-1])

                cmd = cmd + "T\n"  # go to trefftz plane menu
                cmd = cmd + "h\n\n"  # print

        cmd = cmd + "\nquit\n"
        p = Popen([binPath],
                  stdout=PIPE,
                  stdin=PIPE,
                  stderr=STDOUT,
                  universal_newlines=True,
                  cwd=r.wd)
        stdOut = p.communicate(input=cmd)[0]

        results = AvlOutput()
        results.parseFiles(outputFiles)

        try:
            stripForces = []
            for f in fsFiles:
                s = StripForcesOutput(f)
                s.cref = avlInput.header.Cref
                stripForces.append(s)

            results.stripForces = stripForces

        except ValueError:
            warnings.warn("AVL strip force parsing failed.")

        if savePlots:
            results.loadPlots(plotFile)

    return results, stdOut
Exemplo n.º 3
0
def export_airfoils(set=vsp.SET_ALL, **kwargs):
    import airfoils
    af_dict = dict()
    with RunManager(**kwargs) as r:
        output_file = r.cwd + "/airfoils.csv"
        vsp.ExportFile(output_file, set, vsp.EXPORT_SELIG_AIRFOIL)

        #parse airfoils.csv
        with open(output_file, "r") as f:
            lines = f.readlines()

        i = 2
        strs = lines[i].split(",")
        rootDir = strs[1].strip()
        i = i + 1
        while i < len(lines):
            if "Airfoil File Name" in lines[i]:
                file = rootDir + lines[i].split(",")[1].strip()
                af = airfoils.VspSeligExport(file)

                i = i + 1

                af.geom_name = lines[i].split(",")[1].strip()
                i = i + 1

                af.geom_id = lines[i].split(",")[1].strip()
                i = i + 1

                af.airfoil_index = int(lines[i].split(",")[1])
                i = i + 1

                af.xsec_flag = lines[i].split(",")[1].strip() == "1"

                i = i + 1

                if af.xsec_flag:
                    af.xsec_index = int(lines[i].split(",")[1])
                    i = i + 1

                    af.xsec_surf_id = lines[i].split(",")[1].strip()
                    i = i + 1

                af.foil_surf_u_value = float(lines[i].split(",")[1])

                i = i + 1
                af.global_u_value = float(lines[i].split(",")[1])

                i = i + 1
                af.le_point = np.array(lines[i].split(",")[1:]).astype(float)

                i = i + 1
                af.te_point = np.array(lines[i].split(",")[1:]).astype(float)

                i = i + 1
                af.chord = float(lines[i].split(",")[1])

                i = i + 1

                #af.findSegments()
                try:
                    af_dict[af.geom_id].append(af)
                except KeyError:
                    af_dict[af.geom_id] = []
                    af_dict[af.geom_id].append(af)

            else:
                i = i + 1

    return af_dict
Exemplo n.º 4
0
def runAvl(avlInput, alpha=None, beta=None, savePlots=False,
           binPath=DEFAULT_AVL_BINARY, constraints=None, collect_surface_forces=False, **kwargs):
    """

    :param avlInput: AvlInput object to run or
    :param alpha: array of angles of attack to run
    :param savePlots: boolean to save plots or not (default=False)
    :param binPath: path to binary file (optional)
    :param constraints: constraints structure to be used for trimming (default=None)
    :param collect_surface_forces: True to have avl output surface forces
    :param kwargs: can pass cleanup_flag and change_dir to the RunManager class, if desired
    :return:
    """

    if alpha is None:
        alpha = list(range(-10,21,2))
    if beta is None:
        beta = [0]

    with RunManager(**kwargs) as r:
        cmd = io.StringIO()

        # save avlInput to that directory
        inputFile = "avlinput.txt"
        avlInput.toFile( inputFile)
        plotFile = "plot.ps"
        outputFiles = []
        fsFiles = []
        fnFiles = []
        cmd.write('plop\nG\n\n') # turn off plotting
        cmd.write('load {}\n'.format(inputFile))
        cmd.write('oper\n')
        cmd.write("g\n")  # go to geometry menu
        cmd.write("h\n")  # print current geometry
        cmd.write("no\n")  # turn normals on
        cmd.write("h\n")  # print
        cmd.write("no\n")  # turn normal off
        # Get front view
        cmd.write("v\n")
        cmd.write("0 0\n")
        cmd.write("h\n\n")

        if constraints is not None:
            for constraint in constraints:
                cmd.write("%s %s %f\n" % tuple(constraint))

        for a in alpha:
            for b in beta:
                cmd.write("+\n")  # add new run case
                cmd.write("a a {}\n".format(a))  # add this alpha to the run case
                cmd.write("b b {}\n".format(b))  # add this beta to the run case
                cmd.write("x\n")  # execute run case
                cmd.write("st\n")
                f = "results_alpha_{}_beta_{}.txt".format(a, b)
                outputFiles.append( f )
                cmd.write(f + "\n")

                cmd.write("g\n") # go to geometry menu
                cmd.write("lo\n")  # turn loading on
                cmd.write("v\n-45.0 20.0\n") # set viewpoint to iso
                cmd.write("h\n")  # print
                # Set viewpoint to front
                cmd.write("v\n")
                cmd.write("0 0\n")
                cmd.write("h\n")
                cmd.write("lo\n") # turn loading off
                cmd.write("\n")  #go back to oper menu

                # save out strip forces
                cmd.write("FS\n")
                fsFiles.append("strip_forces_{}_{}.txt".format(a, b))
                cmd.write("{}\n".format(fsFiles[-1]))

                cmd.write("T\n")  # go to trefftz plane menu
                cmd.write("h\n\n")  # print

                # save out surface forces
                if collect_surface_forces:
                    fn_file = "surface_forces_{}_{}.txt".format(a, b)
                    fnFiles.append(fn_file)
                    cmd.write("FN\n")
                    cmd.write(fn_file + "\n")


        cmd.write("\nquit\n")

        p = Popen([binPath], stdout=PIPE, stdin=PIPE, stderr=STDOUT, universal_newlines=True, cwd=r.wd)
        stdOut = p.communicate(input=cmd.getvalue())[0]

        cmd.close()

        results = AvlOutput()
        results.parseFiles(outputFiles)

        try:
            stripForces = []
            for f in fsFiles:
                s = StripForcesOutput(f)
                s.cref = avlInput.header.Cref
                stripForces.append(s)

            results.stripForces = stripForces
            
        except ValueError:
            warnings.warn("AVL strip force parsing failed.")


        try:
            surfaceForces = []
            for f in fnFiles:
                s = SurfaceForcesOutput(f)
                surfaceForces.append(s)
            results.surfaceForces = surfaceForces
        except ValueError:
            warnings.warn("AVL surface force parsing failed.")


        if savePlots:
            results.loadPlots(plotFile)

    return results, stdOut