Exemplo n.º 1
0
def run_nastran(bdf_model, nastran, post=-1, size=8, is_double=False):
    """
    Verifies that a valid bdf was written by running nastran and parsing
    the OP2.  Many cards do not support double precision and since there
    is no list, a test is necessary.
    """
    if nastran:
        from pyNastran.op2.op2 import read_op2
        dirname = os.path.dirname(bdf_model)
        basename = os.path.basename(bdf_model).split('.')[0]

        f04_model = os.path.join(dirname, 'out_%s.f04' % basename)
        f06_model = os.path.join(dirname, 'out_%s.f06' % basename)
        op2_model = os.path.join(dirname, 'out_%s.f06' % basename)
        log_model = os.path.join(dirname, 'out_%s.log' % basename)
        xdb_model = os.path.join(dirname, 'out_%s.xdb' % basename)
        pch_model = os.path.join(dirname, 'out_%s.pch' % basename)
        asm_model = os.path.join(dirname, 'out_%s.asm' % basename)
        master_model = os.path.join(dirname, 'out_%s.master' % basename)
        #op2_model = os.path.join(dirname, 'out_%s.op2' % basename)

        #cwd = os.getcwd()
        cwd = dirname
        bdf_model2 = os.path.join(cwd, 'out_%s.bdf' % basename)
        op2_model2 = os.path.join(cwd, 'out_%s.op2' % basename)
        #f06_model2 = os.path.join(cwd, 'out_%s.f06' % basename)
        print(bdf_model2)
        #if os.path.exists(bdf_model2):
        #os.remove(bdf_model2)

        # make sure we're writing an OP2
        bdf = read_bdf(bdf_model, debug=False)
        if 'POST' in bdf.params:
            param_post = bdf.params['POST']
            #print('post = %s' % post)
            param_post.update_values(value1=post)
            #print('post = %s' % post)
        else:
            card = ['PARAM', 'POST', post]
            bdf.add_card(card, 'PARAM', is_list=True)
        bdf.write_bdf(bdf_model2, size=size, is_double=is_double)

        #os.rename(outModel, outModel2)
        if not os.path.exists(f06_model):
            os.system(nastran + bdf_model2)
        for fnamei in [
                f04_model, log_model, xdb_model, pch_model, asm_model,
                master_model
        ]:
            if os.path.exists(fnamei):
                os.remove(fnamei)
        if not os.path.exists(op2_model):
            raise RuntimeError('%s failed' % op2_model)
        op2 = read_op2(op2_model2)
        print(op2.get_op2_stats())
Exemplo n.º 2
0
def run_fem1(fem1,
             bdf_model,
             out_model,
             mesh_form,
             xref,
             punch,
             sum_load,
             size,
             is_double,
             cid,
             run_extract_bodies=False,
             encoding=None,
             crash_cards=None,
             safe_xref=True,
             pickle_obj=False,
             stop=False):
    """
    Reads/writes the BDF

    Parameters
    ----------
    fem1 : BDF()
        The BDF object
    bdf_model : str
        The root path of the bdf filename
    out_model : str
        The path to the output bdf
    mesh_form : str {combined, separate}
        'combined' : interspersed=True
        'separate' : interspersed=False
    xref : bool
        The xref mode
    punch : bool
        punch flag
    sum_load : bool
        static load sum flag
    size : int, {8, 16}
        size flag
    is_double : bool
        double flag
    cid : int / None
        cid flag
    safe_xref : bool; default=False
        ???
    run_extract_bodies : bool; default=False
        isolate the fem bodies; typically 1 body; code is still buggy
    encoding : str; default=None
        the file encoding
    crash_cards : ???
        ???
    """
    if crash_cards is None:
        crash_cards = []
    assert os.path.exists(bdf_model), print_bad_path(bdf_model)
    try:
        if '.pch' in bdf_model:
            fem1.read_bdf(bdf_model, xref=False, punch=True, encoding=encoding)
        else:
            fem1.read_bdf(bdf_model,
                          xref=False,
                          punch=punch,
                          encoding=encoding)
            for card in crash_cards:
                if card in fem1.card_count:
                    raise DisabledCardError('card=%r has been disabled' % card)
            #fem1.geom_check(geom_check=True, xref=False)
            if not stop and not xref:
                skin_filename = 'skin_file.bdf'
                fem1.write_skin_solid_faces(skin_filename,
                                            size=16,
                                            is_double=False)
                if os.path.exists(skin_filename):
                    read_bdf(skin_filename, log=fem1.log)
                    os.remove(skin_filename)
            if xref:
                if run_extract_bodies:
                    extract_bodies(fem1)

                # 1. testing that these methods word without xref
                #fem1._get_rigid()
                #fem1.get_dependent_nid_to_components()
                #fem1._get_maps(eids=None, map_names=None,
                #consider_0d=True, consider_0d_rigid=True,
                #consider_1d=True, consider_2d=True, consider_3d=True)
                #fem1.get_dependent_nid_to_components()

                # 1. testing that these methods work with xref
                fem1._get_rigid()
                #common_node_ids = list(fem1.nodes.keys())
                #fem1.get_rigid_elements_with_node_ids(common_node_ids)

                #for spc_id in set(list(fem1.spcadds.keys()) + list(fem1.spcs.keys())):
                #fem1.get_reduced_spcs(spc_id)
                #for mpc_id in set(list(fem1.mpcadds.keys()) + list(fem1.mpcs.keys())):
                #fem1.get_reduced_mpcs(mpc_id)

                #fem1.get_dependent_nid_to_components()
                #fem1._get_maps(eids=None, map_names=None,
                #consider_0d=True, consider_0d_rigid=True,
                #consider_1d=True, consider_2d=True, consider_3d=True)
                #fem1.get_dependent_nid_to_components()
                #fem1.get_pid_to_node_ids_and_elements_array(pids=None, etypes=None, idtype='int32',
                #msg=' which is required by test_bdf')
                #fem1.get_property_id_to_element_ids_map(msg=' which is required by test_bdf')
                #fem1.get_material_id_to_property_ids_map(msg=' which is required by test_bdf')
                #fem1.get_element_ids_list_with_pids(pids=None)
                #fem1.get_element_ids_dict_with_pids(pids=None, stop_if_no_eids=False,
                #msg=' which is required by test_bdf')
                #fem1.get_node_id_to_element_ids_map()
                #fem1.get_node_id_to_elements_map()

                read_bdf(fem1.bdf_filename,
                         encoding=encoding,
                         debug=fem1.debug,
                         log=fem1.log)

                fem1 = remake_model(bdf_model, fem1, pickle_obj)
                #fem1.geom_check(geom_check=True, xref=True)
    except:
        print("failed reading %r" % bdf_model)
        raise

    #out_model = bdf_model + '_out'
    #if cid is not None and xref:
    #fem1.resolve_grids(cid=cid)

    if mesh_form is None:
        pass
    elif mesh_form == 'combined':
        fem1.write_bdf(out_model,
                       interspersed=True,
                       size=size,
                       is_double=is_double)
    elif mesh_form == 'separate':
        fem1.write_bdf(out_model,
                       interspersed=False,
                       size=size,
                       is_double=is_double)
    else:
        msg = "mesh_form=%r; allowed_mesh_forms=['combined','separate']" % mesh_form
        raise NotImplementedError(msg)
    #fem1.write_as_ctria3(out_model)

    fem1._get_maps()
    #remove_unused_materials(fem1)
    #remove_unused(fem1)
    #units_to = ['m', 'kg', 's']
    #units_from = ['m', 'kg', 's']
    #convert(fem1, units_to, units=units_from)
    if xref:
        check_for_cd_frame(fem1)

        #try:
        #fem1.get_area_breakdown()
        #fem1.get_volume_breakdown()
        #except:
        #if len(fem1.masses) > 0:
        #fem1.log.warning('no elements with area/volume found, but elements with mass were')
        #else:
        #fem1.log.warning('no elements found')

        #if len(fem1.elements) + len(fem1.masses) > 0:
        #try:
        #fem1.get_mass_breakdown()
        #except RuntimeError:
        #fem1.log.warning('no elements with mass found')
    return fem1