Exemplo n.º 1
0
    def __init__(self, log=None, debug=False):
        """
        Initializes the SHABP object

        Parameters
        ----------
        debug : bool/None; default=True
            used to set the logger if no logger is passed in
                True:  logs debug/info/error messages
                False: logs info/error messages
                None:  logs error messages
        log : logging module object / None
            if log is set, debug is ignored and uses the
            settings the logging object has
        """
        #self.xyz = {}
        self.X = {}
        self.Y = {}
        self.Z = {}
        self.trailer = None

        self.component_name_to_patch = {}
        self.patch_to_component_num = {}
        self.component_to_params = {}
        self.component_num_to_name = {}
        self.component_name_to_num = {}
        self.log = get_logger2(log, debug=debug)

        self.title = ''
        self.header = ''
        self.shabp_cases = {}
Exemplo n.º 2
0
def export_obj_to_hdf5(hdf5_filename, obj, user_custom_types=None, log=None, debug=False):
    """exports an object to an HDF5 file"""
    log = get_logger2(log=log, debug=debug, encoding='utf-8')
    with h5py.File(hdf5_filename, 'w') as hdf5_file:
        log.info('starting export_op2_to_hdf5_file of %r' % hdf5_filename)
        export_obj_to_hdf5_file(
            hdf5_file, obj, user_custom_types=user_custom_types, log=log)
Exemplo n.º 3
0
    def __init__(self, log=None, debug=None, batch=False):
        self.log = get_logger2(log, debug)
        self.debug = debug
        self.n = 0
        #self.p_inf =
        self.rho_inf = 0.002377
        self.v_inf = 100.
        self.q_inf = 0.5 * self.rho_inf * self.v_inf**2
        self.batch = batch

        self.cg = None
        self.machs = None
        self.alphas = None
        self.betas = None

        self.nodes = None
        self.Cp = None
        self.tris = None
        self.surf_id = None

        self.edges = None
        self.edge_surf_id = None
        self.area = None
        self.wake_xyz = None
        self.wake_elements = None
        self._uendian = '<'
        self.f = None
Exemplo n.º 4
0
    def __init__(self, log=None, debug=None):
        """
        Initializes the Usm3d object

        Parameters
        ----------
        debug : bool/None; default=True
            used to set the logger if no logger is passed in
                True:  logs debug/info/error messages
                False: logs info/error messages
                None:  logs error messages
        log : logging module object / None
            if log is set, debug is ignored and uses the
            settings the logging object has
        """
        self.nodes = None
        self.tris = None
        self.tets = None
        self.bcs = None

        self.header = None
        self.loads = None
        self.mapbc = None
        self.precision = 'double'
        self.log = get_logger2(log, debug=debug)
Exemplo n.º 5
0
 def __init__(self, hdf5_file, user_custom_types=None, log=None, debug=False):
     log = get_logger2(log=log, debug=debug, encoding='utf-8')
     if user_custom_types is None:
         user_custom_types = []
     self.user_custom_types = user_custom_types
     self.hdf5_file = hdf5_file
     self.log = log
Exemplo n.º 6
0
    def __init__(self, log=None, debug=False):
        """
        Initializes the AFLR2 object

        Parameters
        ----------
        debug : bool/None; default=True
            used to set the logger if no logger is passed in
                True:  logs debug/info/error messages
                False: logs info/error messages
                None:  logs error messages
        log : logging module object / None
            if log is set, debug is ignored and uses the
            settings the logging object has
        """
        self.log = get_logger2(log=log, debug=debug)
        self.debug = debug

        self.nodes = None
        self.bars = None
        self.curves = None
        self.subcurves = None
        self.grid_bc = None
        self.grid_bcs = None
        self.turn_angle = None
Exemplo n.º 7
0
def load_obj_from_hdf5(hdf5_filename,
                       custom_types_dict=None,
                       log=None,
                       debug=False):
    """
    loads an hdf5 file into an object

    Parameters
    ----------
    hdf5_filename : str
       the h5 filename to load
    custom_types_dict : dict[key] : function()
        the custom mapper
    """
    check_path(hdf5_filename, 'hdf5_filename')
    log = get_logger2(log=log, debug=debug, encoding='utf-8')
    log.info('hdf5_filename = %r' % hdf5_filename)

    model = {}
    with h5py.File(hdf5_filename, 'r') as h5_file:
        load_obj_from_hdf5_file(model,
                                h5_file,
                                custom_types_dict=custom_types_dict,
                                log=log,
                                debug=debug)
    return model
Exemplo n.º 8
0
    def __init__(self, log=None, debug=False):
        self.x = {}
        self.y = {}
        self.z = {}
        self.block_shapes = {}

        self.log = get_logger2(log=log, debug=debug)
Exemplo n.º 9
0
 def test_plot_flutter(self):
     """tests plot_flutter_f06"""
     f06_filename = os.path.join(MODEL_PATH, 'aero', 'bah_plane',
                                 'bah_plane.f06')
     log = get_logger2(log=None, debug=None, encoding='utf-8')
     plot_flutter_f06(f06_filename, show=False, log=log)
     if IS_MATPLOTLIB:
         plt.close()
Exemplo n.º 10
0
 def __init__(self,
              h5_file,
              custom_types_dict=None,
              log=None,
              debug=False,
              encoding='utf8'):
     self.log = get_logger2(log=log, debug=debug, encoding='utf-8')
     if custom_types_dict is None:
         custom_types_dict = {}
     self.custom_types_dict = custom_types_dict
     self.h5_file = h5_file
Exemplo n.º 11
0
 def __init__(self, log=None, debug=False):
     self.log = get_logger2(log, debug=debug)
     self._endian = b''
     self._encoding = 'latin1'
     self.n = 0
     self.infile = None
     self.infilename = None
     self.points = None
     self.elements = None
     self.regions = None
     self.loads = {}
Exemplo n.º 12
0
 def __init__(self, log=None, debug=True):
     self.debug = debug
     self.parts = {}
     self.boundaries = {}
     self.materials = {}
     self.amplitudes = {}
     self.assembly = None
     self.initial_conditions = {}
     self.steps = {}
     self.heading = None
     self.preprint = None
     self.log = get_logger2(log, debug)
Exemplo n.º 13
0
 def test_cmd_line_plot_flutter(self):
     log = get_logger2(log=None, debug=None, encoding='utf-8')
     f06_filename = os.path.join(MODEL_PATH, 'aero', '2_mode_flutter',
                                 '0012_flutter.f06')
     argv = [
         'f06', 'plot_145', f06_filename, '--eas', '--in_units', 'si',
         '--out_units', 'english_in', '--modes', '1:', '--ylimdamp', '-.3:'
     ]
     cmd_line_plot_flutter(argv=argv,
                           plot=IS_MATPLOTLIB,
                           show=False,
                           log=log)
     cmd_line_f06(argv=argv, plot=IS_MATPLOTLIB, show=False, log=log)
Exemplo n.º 14
0
    def test_log_messages(self):
        """tests using get_logger2"""
        log1 = get_logger2(debug=True)
        log1.info('info')
        log1.warning('warning')
        log1.error('error')
        log1.debug('debug')
        log1.exception('exception')
        log1.critical('critical')
        log1.info('%r' % log1)

        log2 = get_logger2(debug=False)
        log2.info('info')
        log2.warning('warning')
        log2.error('error')
        log2.debug('debug')

        log3 = get_logger2(debug=None)
        log3.info('info')
        log3.warning('warning')
        log3.error('error')
        log3.debug('debug')
        with self.assertRaises(AttributeError):
            log3.bad('bad')
Exemplo n.º 15
0
    def __init__(self, log=None, debug=False):
        self.log = get_logger2(log=log, debug=debug)
        self.infilename = None

        self.zones = None
        self.npoints = None
        self.nfaces = None
        self.ndm = None
        self.npatches = []

        self.nodes = empty(shape=0)
        self.tri_elements = empty(shape=0)
        self.quad_elements = empty(shape=0)
        self.tet_elements = empty(shape=0)
        self.hexa_elements = empty(shape=0)
Exemplo n.º 16
0
def make_symmetric_model(bdf_filename,
                         plane: str = 'xz',
                         zero_tol: float = 1e-12,
                         log=None,
                         debug: bool = True):
    log = get_logger2(log=log, debug=debug, encoding='utf-8')
    deprecated('make_symmetric_model',
               'make_half_model',
               '1.3',
               levels=[0, 1, 2])
    return make_half_model(bdf_filename,
                           plane=plane,
                           zero_tol=zero_tol,
                           log=log,
                           debug=debug)
Exemplo n.º 17
0
 def __init__(self, log=None, debug=False):
     self.log = get_logger2(log=log, debug=debug, encoding='utf-8')
     self.headers = [
         'x', 'y', 'z', 'wx', 'wy', 'wz', 'cp2ndu', 'cpisnu', 'lmachu',
         'source', 'doublet'
     ]
     self.headers_ft13 = [
         'x', 'y', 'z', 'd0', 'dx', 'dy', 'dz', 's0', 'anx', 'any', 'anz',
         'lmachu', 'wxu', 'wyu', 'wzu', 'pheu', 'vxu', 'vyu', 'vzu',
         'cplinu', 'cpslnu', 'cp2ndu', 'cpisnu', 'lmachl', 'wxl', 'wyl',
         'wzl', 'phel', 'vxl', 'vyl', 'vzl', 'cplinl', 'cpslnl', 'cp2ndl',
         'cpisnl', 'wnu', 'wnl', 'pwnu', 'pwnl', 'vtu', 'vtl', 'pvtu',
         'pvtl', 'cplind', 'cpslnd', 'cp2ndd', 'cpisnd'
     ]
     self.networks = {}
     self.networks_ft13 = {}
Exemplo n.º 18
0
def main():
    dirnames = ['ascii', 'binary']
    log = get_logger2(debug=False)
    for dirname in dirnames:
        fnames = [
            os.path.join(dirname, fname) for fname in os.listdir(dirname)
            if not fname.endswith('.png')
        ]
        for fname in fnames:
            try:
                read_tecplot(fname, log=log)
                log.info('read %r' % fname)
            except Exception as error:
                log.warning('failed reading %r' % fname)
                log.error(error)
                print('')
Exemplo n.º 19
0
    def __init__(self, log=None, debug=False):
        """
        Initializes the LaWGS object

        Parameters
        ----------
        debug : bool/None; default=True
            used to set the logger if no logger is passed in
                True:  logs debug/info/error messages
                False: logs info/error messages
                None:  logs error messages
        log : logging module object / None
            if log is set, debug is ignored and uses the
            settings the logging object has
        """
        self.log = get_logger2(log=log, debug=debug)
        self.panels = {}
Exemplo n.º 20
0
    def __init__(self, log=None, debug=False):
        """creates BlockMesh"""
        debug = False
        #log = None
        self.log = get_logger2(log, debug=debug)

        # arrays
        self.nodes = None
        self.quads = None
        self.hexas = None
        self.npoints = None
        self.grading = None

        self.iname_to_quads = None
        self.inames = None
        self.bcs = None
        self.iname_to_name = None
        self.iname_to_type = None
Exemplo n.º 21
0
    def __init__(self, log=None, debug=False):
        self.name = 'model_name'
        self.log = get_logger2(log=log, debug=debug, encoding='utf-8')
        self.avl_filename = ''
        self.mach = 0.

        self.sref = 0.
        self.cref = 0.
        self.bcref = 0.

        self.xref = 0.
        self.yref = 0.

        self.zref = 0.
        self.cd0 = 0.
        self.sections = []
        self.surfaces = None
        self.sym_iy = None
        self.sym_iz = None
        self.symz = None
Exemplo n.º 22
0
    def __init__(self, log=None, debug=False):
        """
        Initializes the STL object

        Parameters
        ----------
        debug : bool/None; default=True
            used to set the logger if no logger is passed in
                True:  logs debug/info/error messages
                False: logs info/error messages
                None:  logs error messages
        log : logging module object / None
            if log is set, debug is ignored and uses the
            settings the logging object has
        """
        self.log = get_logger2(log, debug=debug)

        self.nodes = None
        self.elements = None
        self.header = ''
        self.infilename = None
Exemplo n.º 23
0
def main():
    log = get_logger2(debug=True)

    dirnames = ['ascii', 'binary']
    filenames = [

        #'ascii/3dgeom.dat', #  good; multi-zone, geometry
        #'ascii/block_febrick_3d.dat', # 3d unstructured block; good
        #'ascii/block_fetet_3d.dat', # bad; no decimal values
        #'ascii/channel.dat', # 2d structured point; good
        #'ascii/cylinder_slice.dat', # 3d structured point; good
        #'ascii/cylindrical.dat',  # 3d structured empty lines; good
        #'ascii/ell.dat', # 2d; good
        #'ascii/humanoid_quad.dat', # good
        #'ascii/humanoid_tri.dat', # good

        #'ascii/movie.dat',  # csv -> bad
        'ascii/multzn2d.dat',  #  2d structured; good
        #'ascii/plane_slice.dat',  # 2d structured multi-line; good
        #'ascii/point_febrick_3d_02.dat',  # difficult header and funny write bug; bad
        #'ascii/point_fequad_2d.dat',  # 2d; good
        #'ascii/point_fetet_3d.dat',  # good
        #'ascii/point_fetri_2d_01.dat',  # good
        #'ascii/point_fetri_2d_02.dat',  # good
        #'ascii/point_fetri_2d_03.dat',  # good

        #'ascii/simp3dbk.dat',  # 3d structured block - bad
        #'ascii/simp3dpt.dat', #  good
        #'ascii/simpscat.dat', #  bad -> text
        #'ascii/simpxy.dat',  # no xyz; it's a plot -> bad
        #'ascii/simpxy2.dat',  # no xyz; it's a plot -> bad
        #'ascii/tiny.dat',  # good
    ]
    run_filenames(filenames, log)
    return
    dirnames = ['binary']
    for dirname in dirnames:
        fnames = [os.path.join(dirname, fname) for fname in os.listdir(dirname)
                  if not fname.endswith('.png')]
        run_filenames(fnames, log)
Exemplo n.º 24
0
 def __init__(self, log=None, debug=False):
     self.log = get_logger2(log, debug=debug)
Exemplo n.º 25
0
 def __init__(self, log=None, debug=False):
     """creates a Boundary object"""
     self.debug = False
     #log = None
     self.log = get_logger2(log, debug=debug)
Exemplo n.º 26
0
def merge_stl_files(stl_filenames,
                    stl_out_filename=None,
                    remove_bad_elements=False,
                    is_binary=True,
                    float_fmt='%6.12f',
                    log=None):
    """
    Combines multiple STLs into a single file

    Parameters
    ----------
    stl_filenames : List[str, str, ...]
        list of stl filenames or a string filename
        (useful for removing bad elements)
    remove_bad_elements : bool; default=False
        should elements with invalid normals be removed?
    stl_out_filename : str; default=None -> no writing
        string of stl output filename
    is_binary : bool; default=True
        should the output file be binary
    float_fmt : str; default='%6.12f'
        the ascii float format

    Returns
    -------
    stl : STL()
        the stl object
    """
    if isinstance(stl_filenames, str):
        stl_filenames = [stl_filenames]
    assert isinstance(stl_filenames, (list, tuple)), type(stl_filenames)
    assert len(stl_filenames) > 0, stl_filenames

    log = get_logger2(log=log, debug=False, encoding='utf-8')
    if len(stl_filenames) == 1:
        model = STL(log=log)
        model.read_stl(stl_filenames[0])
        if remove_bad_elements:
            model.remove_elements_with_bad_normals()
        if stl_out_filename is not None:
            model.write_stl(stl_out_filename, is_binary=is_binary)
        return model

    nodes = []
    elements = []

    n0 = 0
    for i, fname in enumerate(stl_filenames):
        log.debug(f'reading file {i}: {fname}')
        model = STL(
            log=log)  # TODO: you shouldn't need to to reinstantiate the STL
        model.read_stl(fname)
        nnodes = model.nodes.shape[0]
        nodes.append(model.nodes)
        elements.append(model.elements + n0)
        n0 += nnodes

    model.nodes = vstack(nodes)
    model.elements = vstack(elements)

    if remove_bad_elements:
        model.remove_elements_with_bad_normals()

    if stl_out_filename is not None:
        model.write_stl(stl_out_filename,
                        is_binary=is_binary,
                        float_fmt=float_fmt)
    return model
Exemplo n.º 27
0
    def __init__(self, log=None, debug=True):
        """
        Initializes the PanairGrid object

        Parameters
        ----------
        debug : bool/None; default=True
            used to set the logger if no logger is passed in
                True:  logs debug/info/error messages
                False: logs info/error messages
                None:  logs error messages
        log : logging module object / None
            if log is set, debug is ignored and uses the
            settings the logging object has
        """
        self.infilename = None
        self.title_lines = []
        self.xz_symmetry = 0
        self.xy_symmetry = 0
        self.nsymmetry_planes = 0
        self.title = ''

        self.nnetworks = 0
        self.patches = {}
        self.lines = []

        self.alphas = [0.]
        self.ncases = 0
        self.betas = [0.]
        self.alpha_compressibility = 0.
        self.beta_compressibility = 0.

        self.sref = 1.
        self.bref = 1.
        self.cref = 1.
        self.dref = 1.

        self.xref = 0.
        self.yref = 0.
        self.zref = 0.

        self.isings = 0.0
        self.isingp = 0.0
        self.igeomp = 0.0
        self.icontp = 0.0
        self.ibconp = 0.0
        self.iedgep = 0.0
        self.ipraic = 0.0
        self.nexdgn = 0.0
        self.ioutpr = 0.0
        self.ifmcpr = 0.0
        self.icostp = 0.0

        self.epsgeo = 0.0
        self.igeoin = -1.0
        self.igeout = 0.
        self.nwxref = 0.
        self.triint = 0.0
        self.iabsum = -0.0
        self.is_end = None
        self.pea_section = ''
        self.mach = 0.0
        self.data_check = 2

        self.noff_body_points = 0
        self.nstreamlines = 0

        self.title_section = ''
        self.xyz_section = ''
        self.streamline_section = ''
        self.flow_section = ''
        self.sectional_prop_section = ''
        self.grid_section = ''
        self.symmetry_section = ''

        self.msg = ''
        self.log = get_logger2(log, debug=debug)
Exemplo n.º 28
0
def make_flutter_response(f06_filename,
                          f06_units=None,
                          out_units=None,
                          make_alt=False,
                          log=None):
    """
    Creates the FlutterResponse object

    Parameters
    ----------
    f06_filename : str
        the filename to plot
    f06_units : Dict[name]=unit; default=None
        f06_units = {'velocity' : 'in/s', 'density' : 'slinch/in^3'}
    out_units : Dict[name]=unit; default=None
        out_units = {'velocity' : 'in/s', 'density' : 'slug/ft^3',
                     'altitude' : 'ft', 'dynamic_pressure' : 'psf'}
    Returns
    -------
    flutters : dict
        key : int
           subcase_id
        value : FlutterResponse()

    """
    f06_units = _get_units(f06_units)
    out_units = _get_units(out_units)

    if log is None:
        log = get_logger2(log=None, debug=True, encoding='utf-8')
    flutters = {}
    iline = 0

    # 1 is the default subcase number
    subcase = 1
    results = []
    modes = []

    configuration = None
    xysym = None
    xzsym = None
    mach = None
    density_ratio = None
    method = None

    log.info('f06_filename = %r' % f06_filename)
    with open(f06_filename, 'r') as f06_file:
        while 1:
            nblank = 0
            line = f06_file.readline()
            iline += 1
            #log.debug('line%ia = %r' % (iline, line))
            while 'SUBCASE ' not in line and 'FLUTTER  SUMMARY' not in line:
                line = f06_file.readline()
                iline += 1
                if not line:
                    nblank += 1
                if nblank == 100:
                    #print(line.strip())
                    break
            if nblank == 100:
                break

            #log.debug('line%ib = %r' % (iline, line))
            if 'SUBCASE' in line[109:]:
                sline = line.strip().split()
                isubcase = sline.index('SUBCASE')
                new_subcase = int(sline[isubcase + 1])
                #print('subcasei=%r iline=%s' % (new_subcase, iline))
                if new_subcase > subcase:
                    log.debug('subcase=%s -> new_subcase=%s' %
                              (subcase, new_subcase))
                    log.debug('modes1 = %s' % modes)
                    flutter = FlutterResponse(subcase,
                                              configuration,
                                              xysym,
                                              xzsym,
                                              mach,
                                              density_ratio,
                                              method,
                                              modes,
                                              results,
                                              f06_units=f06_units,
                                              out_units=out_units,
                                              make_alt=make_alt)
                    flutters[subcase] = flutter
                    modes = []
                    results = []

                    subcase = new_subcase
                    #break
                continue

            #log.debug('line%i_FSa = %r' % (iline, line))
            last_line = None
            while 'FLUTTER  SUMMARY' not in line:
                last_line = line
                line = f06_file.readline()
                #log.debug('i=%s %s' % (iline, line.strip().replace('   ', ' ')))

                if '* * * END OF JOB * * *' in line:
                    last_line = None
                    break
                iline += 1
                if not line:
                    nblank += 1
                if nblank == 100:
                    print(line.strip())
                    log.warning('breaking on nblank=100 a')
                    break

            if '* * * END OF JOB * * *' in line:
                break
            if nblank == 100:
                log.warning('breaking on nblank=100 b')
                break

            # pulls the subcase id for the first subcase
            if last_line is not None:
                #log.debug('line%i_FSb = %r' % (iline, line))
                #log.debug('line%i_FSb = %r' % (iline-1, last_line.replace('     ', ' ')))
                sline = last_line.strip().split()
                try:
                    isubcase = sline.index('SUBCASE')
                    subcase = int(sline[isubcase + 1])
                except ValueError:
                    log.error(f"expected: SUBCASE line -> ['SUBCASE', 1]")
                    log.error(f'found: i={iline} sline={sline}')
                    log.error(f'assuming subcase=1')
                    subcase = 1
                    #raise
                log.debug('subcase = %s' % subcase)

            configuration_sline = f06_file.readline().split()
            #log.error(f'configuration_sline={configuration_sline}')
            iline += 1
            configuration = configuration_sline[2]
            xysym = configuration_sline[5]
            xzsym = configuration_sline[8]
            #print(configuration, xysym, xzsym)

            # ['POINT', '=', '30', 'METHOD', '=', 'PKNL']
            point_sline = f06_file.readline().split()
            iline += 1
            mode = int(point_sline[2])
            method = point_sline[-1]  # 13 for PN, 5 for PK

            #log.debug(point_sline)
            if method == 'PK':
                mach = float(point_sline[6])
                density_ratio = float(point_sline[10])
                #method = point_sline[13]
                #if mode == 1:
                #print('# iline mode mach density_ratio method')
                #print(iline, mode, mach, density_ratio, method)

            elif method == 'PKNL':
                mach = None
                density_ratio = None
                #if mode == 1:
                #print('# iline mode method')
                #print(iline, mode, method)
                f06_file.readline()
                iline += 1
            elif method == 'KE':
                #KFREQ       1./KFREQ       VELOCITY          DAMPING       FREQUENCY          COMPLEX   EIGENVALUE
                #0.5500  1.8181818E+00   2.2589194E+01  -2.4541089E-03   3.3374373E+00  -5.6140173E-01     4.5752050E+02
                mach = None
                density_ratio = None
                #if mode == 1:
                #print('# iline mode method')
                #print(iline, mode, method)
                f06_file.readline()
                iline += 1
            else:
                raise NotImplementedError(
                    f'method={method!r} point_sline={point_sline}')

            found_existing_mode = mode in modes
            #if found_existing_mode:
            #log.warning('found existing mode %s...' % mode)
            #print('nresults = %s' % len(results))
            #continue
            #else:
            #modes.append(mode)

            # blanks
            f06_file.readline()
            f06_file.readline()
            iline += 2

            lines = []

            # KFREQ  1./KFREQ                      VELOCITY  DAMPING  FREQUENCY   COMPLEX EIGENVALUE - PK
            # KFREQ  1./KFREQ  DENSITY   MACH NO.  VELOCITY  DAMPING  FREQUENCY   COMPLEX EIGENVALUE - PKNL
            if method == 'PK':
                nvalues = 7
            elif method == 'PKNL':
                nvalues = 9
            elif method == 'KE':
                #KFREQ       1./KFREQ       VELOCITY          DAMPING       FREQUENCY          COMPLEX   EIGENVALUE
                #0.5500  1.8181818E+00   2.2589194E+01  -2.4541089E-03   3.3374373E+00  -5.6140173E-01     4.5752050E+02
                nvalues = 7
            else:
                raise NotImplementedError(method)

            sline = [None] * nvalues
            while len(sline) == nvalues:
                sline = f06_file.readline().split()
                iline += 1

                is_line = (sline and 'PAGE' not in sline
                           and 'INFORMATION' not in sline
                           and 'EIGENVALUE' not in sline
                           and 'USER' not in sline)
                if is_line:
                    #print('sline = %s' % sline)
                    lines.append(sline)

            if found_existing_mode:
                results[mode - 1].extend(lines)
            else:
                results.append(lines)
                modes.append(mode)
            #print('')

        log.debug('modes = %s' % modes)
        flutter = FlutterResponse(subcase,
                                  configuration,
                                  xysym,
                                  xzsym,
                                  mach,
                                  density_ratio,
                                  method,
                                  modes,
                                  results,
                                  f06_units=f06_units,
                                  out_units=out_units,
                                  make_alt=make_alt)
        flutters[subcase] = flutter
    return flutters
Exemplo n.º 29
0
def equivalence_ugrid3d_and_bdf_to_bdf(ugrid_filename: str,
                                       bdf_filename: str,
                                       pshell_pids_to_remove: List[int],
                                       tol: float = 0.01,
                                       renumber: bool = True,
                                       log: Optional[SimpleLogger] = None):
    """
    Merges a UGRID3D (*.ugrid) with a BDF and exports a BDF that is
    equivalenced and renumbered.

    Parameters
    ----------
    ugrid_filename : str
        the AFLR3/UGrid3d filename
    bdf_filename : str
        the BDF filename
    pshell_pids_to_remove : List[int, ...]
    tol : float; default=0.01
        the equivalence tolerance
    renumber : bool; default=True
        calls ``bdf_renumber`` to renumber the output BDF model

    Returns
    -------
    out_bdf_filename : str
        the output BDF filename
    """
    log = get_logger2(log, debug=True)
    log.info(
        f'equivalence_ugrid3d_and_bdf_to_bdf - bdf_filename={bdf_filename}')
    log.info(
        f'equivalence_ugrid3d_and_bdf_to_bdf - ugrid_filename={ugrid_filename}'
    )
    check_path(ugrid_filename, 'ugrid_filename')

    base = os.path.splitext(bdf_filename)[0]
    #bdf_merged_filename = base + '_merged.bdf'
    bdf_equivalence_filename = base + '_equivalence.bdf'
    bdf_renumber_filename = base + '_renumber.bdf'

    update_merge = True
    if update_merge:
        bdf_model = _update_merge(ugrid_filename,
                                  bdf_filename,
                                  pshell_pids_to_remove,
                                  tol=tol,
                                  log=log)
        bdf_equivalence_nodes(bdf_model,
                              bdf_equivalence_filename,
                              tol,
                              renumber_nodes=False,
                              neq_max=10,
                              xref=False,
                              log=log)

    if renumber:
        starting_ids_dict = {
            'cid': 1,
            'nid': 1,
            'eid': 1,
            'pid': 1,
            'mid': 1,
        }
        bdf_renumber(bdf_equivalence_filename,
                     bdf_renumber_filename,
                     size=16,
                     is_double=False,
                     starting_id_dict=starting_ids_dict,
                     log=log)
        #os.remove(bdf_equivalence_filename)
        out_bdf_filename = bdf_renumber_filename
    else:
        out_bdf_filename = bdf_equivalence_filename

    #os.remove(bdf_merged_filename)
    #os.remove(bdf_renumber_filename)
    os.remove('model_join.bdf')
    return out_bdf_filename
Exemplo n.º 30
0
def merge_ugrid3d_and_bdf_to_ugrid3d_filename(
        ugrid_filename: str,
        bdf_filename: str,
        ugrid_filename_out: str,
        pshell_pids_to_remove: List[int],
        update_equivalence: bool = True,
        tol: float = 0.01,
        log: Optional[SimpleLogger] = None):
    """
    assumes cid=0

        Parameters
    ----------
    ugrid_filename : str
        the AFLR3/UGrid3d filename
    bdf_filename : str
        the BDF filename
    ugrid_filename_out : str
        the output AFLR3/UGrid3d filename
    pshell_pids_to_remove : List[int, ...]
        ???
    tol : float; default=0.01
        the equivalence tolerance
    update_equivalence : bool; default=True
        calls ``equivalence_ugrid3d_and_bdf_to_bdf`` to equivalence nodes

    """
    #base, ext = os.path.splitext(ugrid_filename_out)
    #bdf_filename = base + '.bdf'
    log = get_logger2(log, debug=True)
    log.debug(
        f'merge_ugrid3d_and_bdf_to_ugrid3d_filename - bdf_filename = {bdf_filename}'
    )
    log.debug(
        f'merge_ugrid3d_and_bdf_to_ugrid3d_filename - ugrid_filename = {ugrid_filename}'
    )

    if update_equivalence:
        bdf_filename2 = equivalence_ugrid3d_and_bdf_to_bdf(
            ugrid_filename,
            bdf_filename,
            pshell_pids_to_remove,
            tol,
            renumber=True,
            log=log)
    else:
        base = os.path.splitext(bdf_filename)[0]
        #bdf_merged_filename = base + '_merged.bdf'
        #bdf_equivalence_filename = base + '_equivalence.bdf'
        bdf_renumber_filename = base + '_renumber.bdf'
        bdf_filename2 = bdf_renumber_filename

    log.debug(f'**** bdf_filename2 = {bdf_filename2}')
    model = read_bdf(bdf_filename2, xref=False, log=log)

    outi = determine_dytpe_nfloat_endian_from_ugrid_filename(ugrid_filename)
    ndarray_float, float_fmt, nfloat, endian, ugrid_filename = outi
    #ndarray_float, float_fmt, nfloat, endian, ugrid_filename

    # more for documentation than anything else
    assert ndarray_float in ['float32', 'float64'], ndarray_float
    assert float_fmt in ['f', 'd'], float_fmt
    assert nfloat in [4, 8], nfloat
    assert endian in ['<', '>'], endian

    cards_to_get = [
        'GRID', 'CTRIA3', 'CQUAD4', 'PSHELL', 'CTETRA', 'CPYRAM', 'CPENTA',
        'CHEXA'
    ]
    out = model.get_card_ids_by_card_types(cards_to_get)
    nids = out['GRID']
    nnodes = len(nids)

    ntris = len(out['CTRIA3'])
    nquads = len(out['CQUAD4'])

    ntets = len(out['CTETRA'])
    npyramids = len(out['CPYRAM'])
    npentas = len(out['CPENTA'])
    nhexas = len(out['CHEXA'])
    nshells = ntris + nquads
    nsolids = ntets + npyramids + npentas + nhexas
    if nshells == 0:
        raise RuntimeError(
            'the UGRID model does not have any boundary condition surfaces...')
    assert nsolids > 0, nsolids

    #nodes = zeros((nnodes, 3), dtype=ndarray_float)

    #tris = zeros((ntris, 3), dtype='int32')
    #quads = zeros((nquads, 4), dtype='int32')

    #tets = zeros((ntetras, 4), dtype='int32')
    #pyramids = zeros((npyramids, 5), dtype='int32')
    #pentas = zeros((npyramids, 6), dtype='int32')
    #hexas = zeros((nhexas, 6), dtype='int32')

    xyz = array([model.nodes[nid].xyz for nid in sorted(nids)],
                dtype=ndarray_float)

    # get the pshells
    #pshells = out['PSHELL']
    # TODO: need to think about property IDs
    tris = out['CTRIA3']
    quads = out['CQUAD4']
    eids = tris + quads
    pids = [model.elements[eid].pid for eid in eids]

    #tris_shrink = [eid for eid, pid in zip(eids[:ntris], pids[:ntris])
    #if pid in pshell_pids_to_save]
    #quads_shrink = [eid for eid, pid in zip(eids[ntris:], pids[ntris:])
    #if pid in pshell_pids_to_save]
    #ntris = len(tris_shrink)
    #nquads = len(quads_shrink)
    nshells = nquads + ntris
    npids = len(pids)
    if not nshells == npids:
        raise RuntimeError('nshells=%s npids=%s; must be the same' %
                           (nshells, npids))

    #pids_shrink = [pidi for pidi in pids
    #if pidi in pshell_pids_to_save]
    pids_shrink = pids

    with open(ugrid_filename_out, 'wb') as f_ugrid:
        #element_ids = hstack([
        #out['CTRIA3'], out['CQUAD4'],
        #out['CTETRA'] + out['CPYRAM'], out['CPENTA'], out['CHEXA']
        #])
        #fmt = '%ii' % (nsolids * nnodes)
        structi = Struct(endian + '7i')
        f_ugrid.write(
            structi.pack(nnodes, ntris, nquads, ntets, npyramids, npentas,
                         nhexas))

        # %3f or %3d
        fmt = endian + '%i%s' % (nnodes * 3, float_fmt)  # len(x,y,z) = 3
        structi = Struct(fmt)
        f_ugrid.write(structi.pack(*xyz.ravel()))

        for card_type in cards_to_get[1:]:  # drop the GRIDs & PSHELLs
            if card_type == 'PSHELL':
                assert len(pids) > 0, 'pids=%s' % pids
                #print('writing %s' % card_type)

                # %10i
                fmt = endian + '%ii' % (nshells)
                structi = Struct(fmt)
                pids = pids_shrink
                f_ugrid.write(structi.pack(*pids))
            elif card_type in ['CTRIA3', 'CQUAD4'] and 0:
                if card_type == 'CTRIA3':
                    eids = tris
                elif card_type == 'CQUAD4':
                    eids = quads

                # if there are cards
                if len(eids):
                    #print('writing %s' % card_type)
                    nelements = len(eids)
                    eid0 = eids[0]

                    # get the 0th card so we can size the formatter
                    element0 = model.elements[eid0]
                    nnodes_per_element = len(element0.nodes)

                    node_ids = array(
                        [model.elements[eid].node_ids for eid in sorted(eids)],
                        dtype='int32')

                    # '%8i'
                    fmt = endian + '%ii' % (nelements * nnodes_per_element)
                    structi = Struct(fmt)
                    f_ugrid.write(structi.pack(*node_ids.ravel()))
            else:
                eids = out[card_type]

                # if there are cards
                if len(eids):
                    #print('writing %s' % card_type)
                    nelements = len(eids)
                    eid0 = eids[0]

                    # get the 0th card so we can size the formatter
                    element0 = model.elements[eid0]
                    nnodes_per_element = len(element0.nodes)

                    node_ids = array(
                        [model.elements[eid].node_ids for eid in sorted(eids)],
                        dtype='int32')
                    # '%8i'
                    fmt = endian + '%ii' % (nelements * nnodes_per_element)
                    structi = Struct(fmt)
                    f_ugrid.write(structi.pack(*node_ids.ravel()))