コード例 #1
0
def read_q(grid_file, q_file, multiblock=True, blanking=False, logger=None):
    """
    Read grid and solution files.
    Returns a :class:`DomainObj` initialized from `grid_file` and `q_file`.

    grid_file: string
        Grid filename.

    q_file: string
        Q data filename.
    """
    logger = logger or NullLogger()

    domain = read_plot3d_grid(grid_file,
                              multiblock,
                              dim=3,
                              blanking=blanking,
                              planes=False,
                              binary=True,
                              big_endian=False,
                              single_precision=False,
                              unformatted=True,
                              logger=logger)

    with open(q_file, 'rb') as inp:
        logger.info("reading Q file '%s'", q_file)
        stream = Stream(inp,
                        binary=True,
                        big_endian=False,
                        single_precision=False,
                        integer_8=False,
                        unformatted=True,
                        recordmark_8=False)
        if multiblock:
            # Read number of zones.
            nblocks = stream.read_int(full_record=True)
        else:
            nblocks = 1
        if nblocks != len(domain.zones):
            raise RuntimeError('Q zones %d != Grid zones %d' \
                               % (nblocks, len(domain.zones)))

        # Read zone dimensions, nq, nqc.
        reclen = stream.read_recordmark()
        expected = stream.reclen_ints(3 * nblocks + 2)
        if reclen != expected:
            logger.warning('unexpected dimensions recordlength'
                           ' %d vs. %d', reclen, expected)

        for zone in domain.zones:
            name = domain.zone_name(zone)
            imax, jmax, kmax = stream.read_ints(3)
            if imax < 1 or jmax < 1 or kmax < 1:
                raise ValueError("invalid dimensions: %dx%dx%d" \
                                 % (imax, jmax, kmax))
            logger.debug('    %s: %dx%dx%d', name, imax, jmax, kmax)
            zone_i, zone_j, zone_k = zone.shape
            if imax != zone_i or jmax != zone_j or kmax != zone_k:
                raise RuntimeError('%s: Q %dx%dx%d != Grid %dx%dx%d' \
                                   % (name, imax, jmax, kmax,
                                      zone_i, zone_j, zone_k))

        nq, nqc = stream.read_ints(2)
        logger.debug('    nq %d, nqc %d', nq, nqc)

        reclen2 = stream.read_recordmark()
        if reclen2 != reclen:
            logger.warning('mismatched dimensions recordlength'
                           ' %d vs. %d', reclen2, reclen)

        # Read zone scalars and variables.
        for zone in domain.zones:
            name = domain.zone_name(zone)
            logger.debug('reading data for %s', name)
            _read_scalars(zone, nqc, stream, logger)
            _read_vars(zone, nq, nqc, stream, logger)

    return domain
コード例 #2
0
def read_plot3d_q(grid_file, q_file, multiblock=True, dim=3, blanking=False,
                  planes=False, binary=True, big_endian=False,
                  single_precision=True, unformatted=True, logger=None):
    """
    Returns a :class:`DomainObj` initialized from Plot3D `grid_file` and
    `q_file`.  Q variables are assigned to 'density', 'momentum', and
    'energy_stagnation_density'.  Scalars are assigned to 'mach', 'alpha',
    'reynolds', and 'time'.

    grid_file: string
        Grid filename.

    q_file: string
        Q data filename.
    """
    logger = logger or NullLogger()

    domain = read_plot3d_grid(grid_file, multiblock, dim, blanking, planes,
                              binary, big_endian, single_precision,
                              unformatted, logger)

    mode = 'rb' if binary else 'r'
    with open(q_file, mode) as inp:
        logger.info('reading Q file %r', q_file)
        stream = Stream(inp, binary, big_endian, single_precision, False,
                        unformatted, False)
        if multiblock:
            # Read number of zones.
            nblocks = stream.read_int(full_record=True)
        else:
            nblocks = 1
        if nblocks != len(domain.zones):
            raise RuntimeError('Q zones %d != Grid zones %d'
                               % (nblocks, len(domain.zones)))

        # Read zone dimensions.
        if unformatted:
            reclen = stream.read_recordmark()
            expected = stream.reclen_ints(dim * nblocks)
            if reclen != expected:
                logger.warning('unexpected dimensions recordlength'
                               ' %d vs. %d', reclen, expected)
        for zone in domain.zones:
            name = domain.zone_name(zone)
            imax, jmax, kmax = _read_plot3d_dims(stream, dim)
            if dim > 2:
                logger.debug('    %s: %dx%dx%d', name, imax, jmax, kmax)
                zone_i, zone_j, zone_k = zone.shape
                if imax != zone_i or jmax != zone_j or kmax != zone_k:
                    raise RuntimeError('%s: Q %dx%dx%d != Grid %dx%dx%d'
                                       % (name, imax, jmax, kmax,
                                          zone_i, zone_j, zone_k))
            else:
                logger.debug('    %s: %dx%d', name, imax, jmax)
                zone_i, zone_j = zone.shape
                if imax != zone_i or jmax != zone_j:
                    raise RuntimeError('%s: Q %dx%d != Grid %dx%d'
                                       % (name, imax, jmax, zone_i, zone_j))
        if unformatted:
            reclen2 = stream.read_recordmark()
            if reclen2 != reclen:
                logger.warning('mismatched dimensions recordlength'
                               ' %d vs. %d', reclen2, reclen)

        # Read zone scalars and variables.
        for zone in domain.zones:
            name = domain.zone_name(zone)
            logger.debug('reading data for %s', name)
            _read_plot3d_qscalars(zone, stream, logger)
            _read_plot3d_qvars(zone, stream, planes, logger)

    return domain
コード例 #3
0
def read_q(grid_file, q_file, multiblock=True, blanking=False, logger=None):
    """
    Read grid and solution files.
    Returns a :class:`DomainObj` initialized from `grid_file` and `q_file`.

    grid_file: string
        Grid filename.

    q_file: string
        Q data filename.
    """
    logger = logger or NullLogger()

    domain = read_plot3d_grid(grid_file, multiblock, dim=3, blanking=blanking,
                              planes=False, binary=True, big_endian=False,
                              single_precision=False, unformatted=True,
                              logger=logger)

    with open(q_file, 'rb') as inp:
        logger.info("reading Q file '%s'", q_file)
        stream = Stream(inp, binary=True, big_endian=False,
                        single_precision=False, integer_8=False,
                        unformatted=True, recordmark_8=False)
        if multiblock:
            # Read number of zones.
            nblocks = stream.read_int(full_record=True)
        else:
            nblocks = 1
        if nblocks != len(domain.zones):
            raise RuntimeError('Q zones %d != Grid zones %d' \
                               % (nblocks, len(domain.zones)))

        # Read zone dimensions, nq, nqc.
        reclen = stream.read_recordmark()
        expected = stream.reclen_ints(3*nblocks + 2)
        if reclen != expected:
            logger.warning('unexpected dimensions recordlength'
                           ' %d vs. %d', reclen, expected)

        for zone in domain.zones:
            name = domain.zone_name(zone)
            imax, jmax, kmax = stream.read_ints(3)
            if imax < 1 or jmax < 1 or kmax < 1:
                raise ValueError("invalid dimensions: %dx%dx%d" \
                                 % (imax, jmax, kmax))
            logger.debug('    %s: %dx%dx%d', name, imax, jmax, kmax)
            zone_i, zone_j, zone_k = zone.shape
            if imax != zone_i or jmax != zone_j or kmax != zone_k:
                raise RuntimeError('%s: Q %dx%dx%d != Grid %dx%dx%d' \
                                   % (name, imax, jmax, kmax,
                                      zone_i, zone_j, zone_k))

        nq, nqc = stream.read_ints(2)
        logger.debug('    nq %d, nqc %d', nq, nqc)

        reclen2 = stream.read_recordmark()
        if reclen2 != reclen:
            logger.warning('mismatched dimensions recordlength'
                           ' %d vs. %d', reclen2, reclen)

        # Read zone scalars and variables.
        for zone in domain.zones:
            name = domain.zone_name(zone)
            logger.debug('reading data for %s', name)
            _read_scalars(zone, nqc, stream, logger)
            _read_vars(zone, nq, nqc, stream, logger)

    return domain
コード例 #4
0
def read_plot3d_f(grid_file, f_file, varnames=None, multiblock=True, dim=3,
                  blanking=False, planes=False, binary=True, big_endian=False,
                  single_precision=True, unformatted=True, logger=None):
    """
    Returns a :class:`DomainObj` initialized from Plot3D `grid_file` and
    `f_file`.  Variables are assigned to names of the form `f_N`.

    grid_file: string
        Grid filename.

    f_file: string
        Function data filename.
    """
    logger = logger or NullLogger()

    domain = read_plot3d_grid(grid_file, multiblock, dim, blanking, planes,
                              binary, big_endian, single_precision,
                              unformatted, logger)

    mode = 'rb' if binary else 'r'
    with open(f_file, mode) as inp:
        logger.info('reading F file %r', f_file)
        stream = Stream(inp, binary, big_endian, single_precision, False,
                        unformatted, False)
        if multiblock:
            # Read number of zones.
            nblocks = stream.read_int(full_record=True)
        else:
            nblocks = 1
        if nblocks != len(domain.zones):
            raise RuntimeError('F zones %d != Grid zones %d'
                               % (nblocks, len(domain.zones)))

        # Read zone dimensions.
        if unformatted:
            reclen = stream.read_recordmark()
            expected = stream.reclen_ints((dim+1) * nblocks)
            if reclen != expected:
                logger.warning('unexpected dimensions recordlength'
                               ' %d vs. %d', reclen, expected)
        for zone in domain.zones:
            name = domain.zone_name(zone)
            imax, jmax, kmax, nvars = _read_plot3d_dims(stream, dim, True)
            if dim > 2:
                logger.debug('    %s: %dx%dx%d %d',
                             name, imax, jmax, kmax, nvars)
                zone_i, zone_j, zone_k = zone.shape
                if imax != zone_i or jmax != zone_j or kmax != zone_k:
                    raise RuntimeError('%s: F %dx%dx%d != Grid %dx%dx%d'
                                       % (name, imax, jmax, kmax,
                                          zone_i, zone_j, zone_k))
            else:
                logger.debug('    %s: %dx%d %d', name, imax, jmax, nvars)
                zone_i, zone_j = zone.shape
                if imax != zone_i or jmax != zone_j:
                    raise RuntimeError('%s: F %dx%d != Grid %dx%d'
                                       % (name, imax, jmax, zone_i, zone_j))
        if unformatted:
            reclen2 = stream.read_recordmark()
            if reclen2 != reclen:
                logger.warning('mismatched dimensions recordlength'
                               ' %d vs. %d', reclen2, reclen)

        # Read zone variables.
        for zone in domain.zones:
            name = domain.zone_name(zone)
            logger.debug('reading data for %s', name)
            _read_plot3d_fvars(zone, stream, dim, nvars, varnames, planes,
                               logger)
    return domain