Esempio n. 1
0
def main(case):

    if (case == 'NASTRAN_PRE'):

        dvs_file = 'x_final.dat'
        dvs = open(dvs_file)
        x_dvs = np.loadtxt(dvs);
        dvs.close()

        config = spaceio.Config('../config_DSN.cfg')
        konfig = copy.deepcopy(config)

        computeNastran(konfig, x_dvs)

    elif (case == 'NASTRAN_POST'):

        postproNastran('struct_nastran.f06','struct_nastran.sol')

    elif (case == 'TACS'):

        dvs_file = 'x_final.dat'
        dvs = open(dvs_file)
        x_dvs = np.loadtxt(dvs);
        dvs.close()

        config = spaceio.Config('../config_DSN.cfg')
        konfig = copy.deepcopy(config)

        computeTacs(konfig, x_dvs)
Esempio n. 2
0
def main():

    config = spaceio.Config('config.cfg')

    data = spaceutil.ordered_bunch()
    data.lift_sub = spaceutil.ordered_bunch()
    data.lift_sub.sps = config.DATABASE_LIFT_SUB
    data.lift_sub.ranges = np.array([[0.5, 0.95], [-5.0, 20.0], [-0.5, 0.5],
                                     [-0.5, 0.5], [-0.5, 0.5]])
    data.lift_sup = spaceutil.ordered_bunch()
    data.lift_sup.sps = config.DATABASE_LIFT_SUP
    data.lift_sup.ranges = np.array([[1.1, 9.0], [-5.0, 20.0], [-0.5, 0.5],
                                     [-0.5, 0.5], [-0.5, 0.5]])
    lift_model = spacemodel.RangedModel(data)

    data = spaceutil.ordered_bunch()
    data.drag_sub = spaceutil.ordered_bunch()
    data.drag_sub.sps = config.DATABASE_DRAG_SUB
    data.drag_sub.ranges = np.array([[0.5, 0.95], [-5.0, 20.0], [-0.5, 0.5],
                                     [-0.5, 0.5], [-0.5, 0.5]])
    data.drag_sup = spaceutil.ordered_bunch()
    data.drag_sup.sps = config.DATABASE_DRAG_SUP
    data.drag_sup.ranges = np.array([[1.1, 9.0], [-5.0, 20.0], [-0.5, 0.5],
                                     [-0.5, 0.5], [-0.5, 0.5]])
    drag_model = spacemodel.RangedModel(data)

    mach = 0.5
    aoa = 10.0

    # XB = np.array([[-0.5, 0.5],[-0.5, 0.5]])
    # dvs = LHC_unif(XB,600)

    x = np.arange(-0.5, 0.5, 0.01)
    y = np.arange(-0.5, 0.5, 0.01)
    X, Y = np.meshgrid(x, y)
    Z = np.zeros(X.shape)

    for i in range(X.shape[0]):
        for j in range(X.shape[1]):

            model_l = lift_model.find_model([mach, aoa, 0.0, X[i][j], Y[i][j]])
            model_d = drag_model.find_model([mach, aoa, 0.0, X[i][j], Y[i][j]])
            Z[i][j] = model_l.eval([
                mach, aoa, 0.0, X[i][j], Y[i][j]
            ]) / model_d.eval([mach, aoa, 0.0, X[i][j], Y[i][j]])

    fig = plt.figure()
    plt.contour(X, Y, Z)
    fig.savefig('image.png', dpi=fig.dpi)
Esempio n. 3
0
    # start new design
    design = spacedesign.Design(konfig)
    
    # update local state filenames ( ??? why not in Design() )
    for key in design.files:
        name = design.files[key]
        name = os.path.split(name)[-1]
        design.files[key] = name
       
    return design

# -------------------------------------------------------------------
#  Run Main Program
# -------------------------------------------------------------------

# this is only accessed if running from command prompt
if __name__ == '__main__':
    
    # Command Line Options
    # parser=OptionParser()
    # parser.add_option("-f", "--func",       dest="func_name",
    #                   help="read function", metavar="FUNCTION_NAME")
                      
    # (options, args)=parser.parse_args()

    config = spaceio.Config('config_DSN.cfg')
    eval_design(sys.argv[1], config)



Esempio n. 4
0
def process_design(regime='BOTH'):

    original = False

    number_ini = 0
    range_number = 840

    if original:
        build_points_folder = 'BUILD_POINTS_ORIGINAL'
        designs_folder = 'DESIGNS_BATCH_1'
    else:
        build_points_folder = 'BUILD_POINTS'
        designs_folder = 'DESIGNS'

    desvar = DesignVariables()

    if regime == 'ON':

        ndim_struct = desvar.ndim_struct_on
        pack_structure = desvar.pack_structure_on

    elif regime == 'OFF':

        ndim_struct = desvar.ndim_struct_off
        pack_structure = desvar.pack_structure_off

    elif regime == 'BOTH':

        ndim_struct = desvar.ndim_struct
        pack_structure = desvar.pack_structure

    threshold = 1.0001

    mass_models = []
    for index in range(132):
        mass_model = Surfpack('MASS_%05d' % (index + 1), ndim_struct)
        # if original:
        #     mass_model.load_data(os.path.join(build_points_folder,'build_points_mass_%05d.dat' % (index+1)))
        # else:
        #     mass_model.load_data(os.path.join('BUILD_POINTS_ORIGINAL','enriched_points_mass_%05d.dat' % (index+1)))
        mass_models.append(mass_model)

    thickness_models = []
    for index in range(132):
        thickness_model = Surfpack('THICKNESS_%05d' % (index + 1), ndim_struct)
        # if original:
        #     thickness_model.load_data(os.path.join(build_points_folder,'build_points_thickness_%05d.dat' % (index+1)))
        # else:
        #     thickness_model.load_data(os.path.join('BUILD_POINTS_ORIGINAL','enriched_points_thickness_%05d.dat' % (index+1)))
        thickness_models.append(thickness_model)

    area_models = []
    for index in range(132):
        area_model = Surfpack('AREA_%05d' % (index + 1), ndim_struct)
        # if original:
        #     area_model.load_data(os.path.join(build_points_folder,'build_points_area_%05d.dat' % (index+1)))
        # else:
        #     area_model.load_data(os.path.join('BUILD_POINTS_ORIGINAL','enriched_points_area_%05d.dat' % (index+1)))
        area_models.append(area_model)

    structure_mass_model = Surfpack('STRUCTURE_MASS', ndim_struct)
    structure_area_model = Surfpack('STRUCTURE_AREA', ndim_struct)
    # if original:
    #     structure_mass_model.load_data(os.path.join(build_points_folder,'build_points_STRUCTURE_MASS.dat'))
    #     structure_area_model.load_data(os.path.join(build_points_folder,'build_points_STRUCTURE_AREA.dat'))
    # else:
    #     structure_mass_model.load_data(os.path.join('BUILD_POINTS_ORIGINAL','enriched_points_STRUCTURE_MASS.dat'))
    #     structure_area_model.load_data(os.path.join('BUILD_POINTS_ORIGINAL','enriched_points_STRUCTURE_AREA.dat'))

    for dsn_index in range(number_ini, range_number):

        design_folder = os.path.join(designs_folder,
                                     'DSN_%03d' % (dsn_index + 1))
        history_file_name = os.path.join(design_folder,
                                         'STRUCTURE/history_structure.dat')
        mass_file_name = os.path.join(design_folder,
                                      'STRUCTURE/lc0_mass_member.dat')
        thickness_file_name = os.path.join(design_folder,
                                           'STRUCTURE/lc0_x_final.dat')
        postpro_file_name = os.path.join(design_folder,
                                         'STRUCTURE/postpro_load_1.dat')

        if os.path.exists(history_file_name) and os.path.exists(
                mass_file_name) and os.path.exists(
                    postpro_file_name) and os.path.exists(thickness_file_name):
            history = numpy.loadtxt(history_file_name,
                                    delimiter=',',
                                    skiprows=1)
            structure_mass = history[-1, 1]
            check = history[-1, 2:5]
            if (check[0] < threshold) and (check[1] < threshold) and (
                    check[2] < threshold):

                if structure_mass > 0.0 and structure_mass < 8000.0:

                    print dsn_index + 1, ': Success'
                    config = spaceio.Config(
                        os.path.join(design_folder, 'config_DSN.cfg'))
                    dvs = pack_structure(config)
                    structure_mass_model.add(dvs, structure_mass)

                    mass_data = numpy.loadtxt(mass_file_name)
                    for index, mass_model in enumerate(mass_models):
                        mass_model.add(dvs, mass_data[index])

                    thickness_data = numpy.loadtxt(thickness_file_name)
                    for index, thickness_model in enumerate(thickness_models):
                        thickness_model.add(dvs, thickness_data[index])

                    structure_area = 0
                    for index, area_model in enumerate(area_models):
                        area = mass_data[index] / thickness_data[
                            index] / float(config.MATERIAL_DENSITY)
                        area_model.add(dvs, area)
                        structure_area += area

                    structure_area_model.add(dvs, structure_area)

                else:
                    print dsn_index + 1, ': Too Big or Too Small'
            else:
                print dsn_index + 1, ': Warning: ', check[0], check[1], check[
                    2]
        else:
            print 'Missing:', dsn_index + 1

    structure_mass_model.save_data(
        os.path.join(build_points_folder,
                     'enriched_points_STRUCTURE_MASS.dat'))
    structure_area_model.save_data(
        os.path.join(build_points_folder,
                     'enriched_points_STRUCTURE_AREA.dat'))

    for index, mass_model in enumerate(mass_models):
        print 'Save MASS: ', index
        mass_model.save_data(
            os.path.join(build_points_folder,
                         'enriched_points_mass_%05d.dat' % (index + 1)))

    for index, thickness_model in enumerate(thickness_models):
        print 'Save THICKNESS: ', index
        thickness_model.save_data(
            os.path.join(build_points_folder,
                         'enriched_points_thickness_%05d.dat' % (index + 1)))

    for index, area_model in enumerate(area_models):
        print 'Save AREA: ', index
        area_model.save_data(
            os.path.join(build_points_folder,
                         'enriched_points_area_%05d.dat' % (index + 1)))
Esempio n. 5
0
def process_design():

    range_number = 300

    desvar = DesignVariables()

    build_points_folder = 'BUILD_POINTS'

    lift_model = Surfpack('LIFT', desvar.ndim - 2)
    lift_model.load_data(
        os.path.join(build_points_folder,
                     'build_points_struct_lift_model.dat'))
    drag_model = Surfpack('DRAG', desvar.ndim - 2)
    drag_model.load_data(
        os.path.join(build_points_folder,
                     'build_points_struct_drag_model.dat'))

    threshold = 1.0001

    for dsn_index in range(range_number):

        design_folder = 'DESIGNS/DSN_%03d' % (dsn_index + 1)

        print design_folder

        postpro_file_name = os.path.join(design_folder,
                                         'STRUCTURE/postpro_load_1.dat')

        history_file_name = os.path.join(design_folder,
                                         'STRUCTURE/history_structure.dat')
        mass_file_name = os.path.join(design_folder,
                                      'STRUCTURE/lc0_mass_member.dat')
        postpro_file_name = os.path.join(design_folder,
                                         'STRUCTURE/postpro_load_1.dat')

        if os.path.exists(history_file_name) and os.path.exists(
                mass_file_name) and os.path.exists(postpro_file_name):

            history = numpy.loadtxt(history_file_name,
                                    delimiter=',',
                                    skiprows=1)
            structure_mass = history[-1, 1]
            check = history[-1, 2:5]
            if (check[0] < threshold) and (check[1] < threshold) and (
                    check[2] < threshold):

                config = spaceio.Config(
                    os.path.join(design_folder, 'config_DSN.cfg'))
                dvs = desvar.pack(config)
                dvs_filtered = dvs[0:3] + dvs[5:11]

                print dvs_filtered

                with open(postpro_file_name) as fp:
                    for i, line in enumerate(fp):
                        if i == 13:
                            data = line.split(':')[-1].split(',')
                            lift = float(data[0])
                            drag = float(data[1])
                            print lift, drag
                        elif i > 13:
                            break

                lift_model.add(dvs_filtered, lift)
                drag_model.add(dvs_filtered, drag)

    lift_model.save_data(
        os.path.join(build_points_folder,
                     'enriched_points_struct_lift_model.dat'))
    drag_model.save_data(
        os.path.join(build_points_folder,
                     'enriched_points_struct_drag_model.dat'))

    lift_model.build('kriging')
    drag_model.build('kriging')

    lift_model.save_model('struct_lift.sps')
    drag_model.save_model('struct_drag.sps')