Esempio n. 1
0
def assert_fields(card1, card2):
    return
    try:
        fields1 = wipe_empty_fields(card1.repr_fields())
        fields2 = wipe_empty_fields(card2.repr_fields())
    except:
        print("card1 = \n%s" % card1)
        print("card2 = \n%s" % card2)
        raise

    if len(fields1) != len(fields2):
        msg = ('len(fields1)=%s len(fields2)=%s\n%r\n%r\n%s\n%s'
               % (len(fields1), len(fields2), fields1, fields2,
                  print_card(fields1), print_card(fields2)))
        raise RuntimeError(msg)

    for (i, field1, field2) in zip(count(), fields1, fields2):
        value1a = print_field_8(field1)
        value2a = print_field_8(field2)
        if value1a != value2a:
            value1 = print_field_8(interpret_value(value1a))
            value2 = print_field_8(interpret_value(value2a))

            if value1 != value2:
                msg = 'value1 != value2\n'
                msg += ('cardName=%s ID=%s i=%s field1=%r field2=%r value1=%r '
                        'value2=%r\n%r\n%r' % (fields1[0], fields1[1], i,
                                               field1, field2, value1, value2,
                                               fields1, fields2))
                raise RuntimeError(msg)
Esempio n. 2
0
    def add_card(self, card_lines, card_name, comment='', is_list=True):
        card_name = card_name.upper()
        self._increase_card_count(card_name)
        if card_name in ['DEQATN']:
            card_obj = card_lines
            card = card_lines
        else:
            if is_list:
                fields = card_lines
            else:
                fields = to_fields(card_lines, card_name)

            # apply OPENMDAO syntax
            if self._is_dynamic_syntax:
                fields = [self._parse_dynamic_syntax(field) if '%' in
                          field[0:1] else field for field in fields]

                card = wipe_empty_fields([interpret_value(field, fields)
                                          if field is not None
                                          else None for field in fields])
            else:  # leave everything as strings
                card = wipe_empty_fields(fields)
            card_obj = BDFCard(card)

        if card_name == 'HYPER':
            hyper = HYPER(card_obj, comment)
            self.hyper[hyper.pid] = hyper
            return
        elif card_name == 'FLOW':
            flow = FLOW(card_obj, comment)
            self.flow[flow.flow_id] = flow
            return
        BDF.add_card(self, card, card_name, comment=comment, is_list=True)
Esempio n. 3
0
def assert_fields(card1, card2):
    return
    try:
        fields1 = wipe_empty_fields(card1.repr_fields())
        fields2 = wipe_empty_fields(card2.repr_fields())
    except:
        print("card1 = \n%s" % card1)
        print("card2 = \n%s" % card2)
        raise

    if len(fields1) != len(fields2):
        msg = ('len(fields1)=%s len(fields2)=%s\n%r\n%r\n%s\n%s' %
               (len(fields1), len(fields2), fields1, fields2,
                print_card(fields1), print_card(fields2)))
        raise RuntimeError(msg)

    for (i, field1, field2) in zip(count(), fields1, fields2):
        value1a = print_field_8(field1)
        value2a = print_field_8(field2)
        if value1a != value2a:
            value1 = print_field_8(interpret_value(value1a))
            value2 = print_field_8(interpret_value(value2a))

            if value1 != value2:
                msg = 'value1 != value2\n'
                msg += ('cardName=%s ID=%s i=%s field1=%r field2=%r value1=%r '
                        'value2=%r\n%r\n%r' %
                        (fields1[0], fields1[1], i, field1, field2, value1,
                         value2, fields1, fields2))
                raise RuntimeError(msg)
 def write_card(self, size=8, is_double=False):
     card = wipe_empty_fields(self.repr_fields())
     if size == 8 or len(card) == 8: # to last node
         msg = self.comment + print_card_8(card)
     else:
         msg = self.comment + print_card_16(card)
     return msg
Esempio n. 5
0
    def __init__(self, card=None, data=None, comment=''):
        ThermalLoad.__init__(self, card, data)
        if comment:
            self._comment = comment
        if card:
            #: Load set identification number. (Integer > 0)
            self.sid = integer(card, 1, 'sid')

            #: Identification number of an CHBDYj element. (Integer > 0)
            self.eid = integer(card, 2, 'eid')

            qFlux = []
            j = 1
            for i in range(3, len(card)):
                q = double_or_blank(card, i, 'qFlux%i' % j)
                qFlux.append(q)
                j += 1

            assert len(qFlux) > 0
            #: Heat flux at the i-th grid point on the referenced CHBDYj
            #: element. (Real or blank)
            self.qFlux = wipe_empty_fields(qFlux)
        else:
            self.sid = data[0]
            self.eid = data[1]
            self.qFlux = data[2]
Esempio n. 6
0
    def __init__(self, card=None, data=None, comment=''):
        ThermalLoad.__init__(self, card, data)
        if comment:
            self._comment = comment
        if card:
            #: Load set identification number. (Integer > 0)
            self.sid = integer(card, 1, 'sid')

            #: Identification number of an CHBDYj element. (Integer > 0)
            self.eid = integer(card, 2, 'eid')

            qFlux  = []
            j = 1
            for i in range(3, len(card)):
                q = double_or_blank(card, i, 'qFlux%i' % j)
                qFlux.append(q)
                j += 1

            assert len(qFlux) > 0
            #: Heat flux at the i-th grid point on the referenced CHBDYj
            #: element. (Real or blank)
            self.qFlux = wipe_empty_fields(qFlux)
        else:
            self.sid = data[0]
            self.eid = data[1]
            self.qFlux = data[2]
Esempio n. 7
0
    def __init__(self, card, has_none=True):
        # type: (List[str], bool) -> None
        """
        Parameters
        ----------
        card : List[str]
           the split values for the card
        has_none : bool; default=True
           helps with a special case to speed up runtime

        # definitely bad
        card = ['GRID', '1', '', '1.0', '2.0', '3.0']
        BDFCard(card, has_none=False)

        # definitely correct
        card = ['GRID', '1', None, '1.0', '2.0', '3.0']
        BDFCard(card, has_none=True)

        # ???
        card = ['GRID', '1', '', 1.0, 2.0, 3.0]
        BDFCard(card, has_none=True)
        """
        if has_none:
            card = wipe_empty_fields(
                [print_field_16(field).strip() for field in card])
        self.card = card
        self.nfields = len(self.card)
Esempio n. 8
0
    def add_card(cls, card, comment=''):
        """
        Adds a QBDY2 card from ``BDF.add_card(...)``

        Parameters
        ----------
        card : BDFCard()
            a BDFCard object
        comment : str; default=''
            a comment for the card

        """
        sid = integer(card, 1, 'sid')
        eid = integer(card, 2, 'eid')

        qfluxs = []
        j = 1
        for i in range(3, len(card)):
            q = double_or_blank(card, i, 'qFlux%i' % j)
            qfluxs.append(q)
            j += 1

        assert len(qfluxs) > 0, qfluxs
        qfluxs = wipe_empty_fields(qfluxs)
        return QBDY2(sid, eid, qfluxs, comment=comment)
Esempio n. 9
0
 def write_card(self, size: int=8, is_double: bool=False) -> str:
     card = wipe_empty_fields(self.repr_fields())
     if size == 8 or len(card) == 8: # to last node
         msg = self.comment + print_card_8(card)
     else:
         msg = self.comment + print_card_16(card)
     return msg
Esempio n. 10
0
    def __init__(self, card, has_none=True):
        """
        Parameters
        ----------
        card : List[str]
           the split values for the card
        has_none : bool; default=True
           helps with a special case to speed up runtime

        # definitely bad
        card = ['GRID', '1', '', '1.0', '2.0', '3.0']
        BDFCard(card, has_none=False)

        # definitely correct
        card = ['GRID', '1', None, '1.0', '2.0', '3.0']
        BDFCard(card, has_none=True)

        # ???
        card = ['GRID', '1', '', 1.0, 2.0, 3.0]
        BDFCard(card, has_none=True)
        """
        if has_none:
            card = wipe_empty_fields([print_field_16(field).strip() for field in card])
        self.card = card
        self.nfields = len(self.card)
Esempio n. 11
0
 def __init__(self, card=None, debug=False):
     self.debug = debug
     if card:
         self.card = wipe_empty_fields(card)
         self.nfields = len(self.card)
     else:
         self.card = None
         self.nfields = None
 def write_card(self, size=8, is_double=False):
     card = wipe_empty_fields(self.repr_fields())
     if size == 8 or len(card) == 8: # to last node
         msg = self.comment + print_card_8(card)
     else:
         msg = self.comment + print_card_16(card)
     #msg2 = self.write_card(size)
     #assert msg == msg2, '\n%s---\n%s\n%r\n%r' % (msg, msg2, msg, msg2)
     return msg
Esempio n. 13
0
 def write_card(self, size: int=8, is_double: bool=False) -> str:
     card = wipe_empty_fields(self.repr_fields())
     if size == 8 or len(card) == 8: # to last node
         msg = self.comment + print_card_8(card)
     else:
         msg = self.comment + print_card_16(card)
     #msg2 = self.write_card(size)
     #assert msg == msg2, '\n%s---\n%s\n%r\n%r' % (msg, msg2, msg, msg2)
     return msg
Esempio n. 14
0
def print_card_16(fields, wipe_fields=True):
    """
    Prints a nastran-style card with 16-character width fields.

    :param fields: all the fields in the BDF card (no trailing Nones)
    :param wipe_fields:  some cards (e.g. PBEAM) have ending fields
                         that need to be there, others cannot have them.
    .. note:: An internal field value of None or '' will be treated as
              a blank field
    .. note:: A large field format follows the  8-16-16-16-16-8 = 80
              format where the first 8 is the card name or
              blank (continuation).  The last 8-character field indicates
              an optional continuation, but because it's a left-justified
              unneccessary field, print_card doesnt use it.

    .. code-block:: python

      >>> fields = ['DUMMY', 1, 2, 3, None, 4, 5, 6, 7, 8.]
      >>> print_card_16(fields)
      DUMMY*                 1               2               3
      *                      4               5               6               7
      *                     8.
      *
    """
    if wipe_fields:
        fields = wipe_empty_fields(fields)
    nfields_main = len(fields) - 1  # chop off the card name
    nbdf_lines = nfields_main // 8
    if nfields_main % 8 != 0:
        nbdf_lines += 1
        nextra_fields = 8 * nbdf_lines -  nfields_main
        fields += [None] * nextra_fields

    try:
        out = '%-8s' % (fields[0] + '*')
    except:
        print("ERROR!  fields=%s" % fields)
        sys.stdout.flush()
        raise

    for i in range(1, len(fields)):
        field = fields[i]
        try:
            out += print_field_16(field)
        except:
            print("bad fields = %s" % fields)
            raise
        if i % 4 == 0:  # allow 1+4 fields per line
            out = out.rstrip(' ')
            if out[-1] == '\n':  # empty line
                out += '*'
            out += '\n*       '
    out = out.rstrip(' *')  # removes one continuation star
    if not out.endswith('\n'):
        out += '\n'
    return out
Esempio n. 15
0
def print_card_double(fields, wipe_fields=True):
    """
    Prints a nastran-style card with 16-character width fields.

    :param fields: all the fields in the BDF card (no trailing Nones)
    :param wipe_fields:  some cards (e.g. PBEAM) have ending fields
                         that need to be there, others cannot have them.
    .. note:: An internal field value of None or '' will be treated as
              a blank field
    .. note:: A large field format follows the  8-16-16-16-16-8 = 80
              format where the first 8 is the card name or
              blank (continuation).  The last 8-character field indicates
              an optional continuation, but because it's a left-justified
              unneccessary field, print_card doesnt use it.

    Example
    =======
    >>> fields = ['DUMMY', 1, 2, 3, None, 4, 5, 6, 7, 8.]
    >>> print_card_double(fields)
    DUMMY*                 1               2               3
    *                      4               5               6               7
    *       8.0000000000D+00
    *
    """
    if wipe_fields:
        fields = wipe_empty_fields(fields)
    nfields_main = len(fields) - 1  # chop off the card name
    nBDF_lines = nfields_main // 8
    if nfields_main % 8 != 0:
        nBDF_lines += 1
        nExtra_fields = 8 * nBDF_lines - nfields_main
        fields += [None] * nExtra_fields

    try:
        out = '%-8s' % (fields[0] + '*')
    except:
        print("ERROR!  fields=%s" % fields)
        sys.stdout.flush()
        raise

    for i in range(1, len(fields)):
        field = fields[i]
        try:
            out += print_field_double(field)
        except:
            print("bad fields = %s" % fields)
            raise
        if i % 4 == 0:  # allow 1+4 fields per line
            out = out.rstrip(' ')
            if out[-1] == '\n':  # empty line
                out += '*'
            out += '\n*       '
    out = out.rstrip(' *')  # removes one continuation star
    if not out.endswith('\n'):
        out += '\n'
    return out
Esempio n. 16
0
 def __init__(self, card=None, oldCardObj=None, debug=False):
     self.debug = debug
     if card:
         self.card = wipe_empty_fields(card)
         #self.card = card
         #self.old_card = oldCardObj
         self.nfields = len(self.card)
     else:
         self.old_card = None
         self.card = None
         self.nfields = None
Esempio n. 17
0
 def __init__(self, card=None, oldCardObj=None, debug=False):
     self.debug = debug
     if card:
         self.card = wipe_empty_fields(card)
         #self.card = card
         #self.old_card = oldCardObj
         self.nfields = len(self.card)
     else:
         self.old_card = None
         self.card = None
         self.nfields = None
Esempio n. 18
0
def assert_fields(card1, card2):
    try:
        fields1 = wipe_empty_fields(card1.repr_fields())
        fields2 = wipe_empty_fields(card2.repr_fields())
    except:
        print("card1 = \n%s" % (card1))
        print("card2 = \n%s" % (card2))
        raise

    if len(fields1) != len(fields2):
        msg = ('len(fields1)=%s len(fields2)=%s\n%r\n%r\n%s\n%s' %
               (len(fields1), len(fields2), fields1, fields2,
                print_card_8(fields1), print_card_8(fields2)))
        raise RuntimeError(msg)

    msg_end = ''
    max_int = 99999999
    for (i, field1, field2) in zip(count(), fields1, fields2):
        if isinstance(field1, int) and field1 > max_int:
            value1a = print_field_16(field1)
            value2a = print_field_16(field2)
        else:
            value1a = print_field_8(field1)
            value2a = print_field_8(field2)
        msg_end += '%-2s: %-8s %-8s\n' % (i, field1, field2)
        if value1a != value2a:
            if isinstance(field1, int) and field1 > max_int:
                value1 = print_field_16(interpret_value(value1a))
                value2 = print_field_16(interpret_value(value2a))
            else:
                value1 = print_field_8(interpret_value(value1a))
                value2 = print_field_8(interpret_value(value2a))

            if value1 != value2:
                msg = 'value1 != value2\n'
                msg += (
                    'card_name=%s ID=%s i=%s field1=%r field2=%r value1=%r '
                    'value2=%r\n%r\n%r\n' %
                    (fields1[0], fields1[1], i, field1, field2, value1, value2,
                     fields1, fields2))
                raise RuntimeError(msg + msg_end)
Esempio n. 19
0
    def add_card(cls, card, comment=''):
        """
        Adds an MKAERO1 card from ``BDF.add_card(...)``

        Parameters
        ----------
        card : BDFCard()
            a BDFCard object
        comment : str; default=''
            a comment for the card
        """
        list_fields = [interpret_value(field) for field in card[1:]]
        nfields = len(list_fields) - 8
        machs = []
        reduced_freqs = []
        for i in range(1, 1 + nfields):
            machs.append(double_or_blank(card, i, 'mach'))
            reduced_freqs.append(double_or_blank(card, i + 8, 'rFreq'))
        machs = wipe_empty_fields(machs)
        reduced_freqs = wipe_empty_fields(reduced_freqs)
        return MKAERO1(machs, reduced_freqs, comment=comment)
Esempio n. 20
0
    def add_card(cls, card, comment=''):
        sid = integer(card, 1, 'sid')
        eid = integer(card, 2, 'eid')

        qfluxs = []
        j = 1
        for i in range(3, len(card)):
            q = double_or_blank(card, i, 'qFlux%i' % j)
            qfluxs.append(q)
            j += 1

        assert len(qfluxs) > 0, qfluxs
        qfluxs = wipe_empty_fields(qfluxs)
        return QBDY2(sid, eid, qfluxs, comment=comment)
Esempio n. 21
0
    def add_card(cls, card, comment=''):
        sid = integer(card, 1, 'sid')
        eid = integer(card, 2, 'eid')

        qfluxs = []
        j = 1
        for i in range(3, len(card)):
            q = double_or_blank(card, i, 'qFlux%i' % j)
            qfluxs.append(q)
            j += 1

        assert len(qfluxs) > 0, qfluxs
        qfluxs = wipe_empty_fields(qfluxs)
        return QBDY2(sid, eid, qfluxs, comment=comment)
Esempio n. 22
0
    def add_card(self, card_lines, card_name, comment='', is_list=True):
        card_name = card_name.upper()
        self._increase_card_count(card_name)
        if card_name in ['DEQATN']:
            card_obj = card_lines
            card = card_lines
        else:
            if is_list:
                fields = card_lines
            else:
                fields = to_fields(card_lines, card_name)

            # apply OPENMDAO syntax
            if self._is_dynamic_syntax:
                fields = [
                    self._parse_dynamic_syntax(field)
                    if '%' in field[0:1] else field for field in fields
                ]

                card = wipe_empty_fields([
                    interpret_value(field, fields)
                    if field is not None else None for field in fields
                ])
            else:  # leave everything as strings
                card = wipe_empty_fields(fields)
            card_obj = BDFCard(card)

        if card_name == 'HYPER':
            hyper = HYPER(card_obj, comment)
            self.hyper[hyper.pid] = hyper
            return
        elif card_name == 'FLOW':
            flow = FLOW(card_obj, comment)
            self.flow[flow.flow_id] = flow
            return
        BDF.add_card(self, card, card_name, comment=comment, is_list=True)
Esempio n. 23
0
    def write_card(self, bdf_file, size=8, is_double=True, element_id=None):
        assert size in [8, 16], size
        assert is_double in [True, False], is_double
        if self.n:
            if element_id is None:
                i = arange(self.n)
            else:
                #assert len(unique(element_id))==len(element_id), unique(element_id)
                i = searchsorted(self.element_id, element_id)

            for (eid, caero, box1, box2, setg, dz, method, usage, nelements, melements,
                    ) in zip(self.element_id[i], self.caero[i], self.box1[i],
                    self.box2[i], self.setg[i], self.dz[i],
                    self.method[i], self.usage[i], self.nelements[i], self.melements[i]):

                sdz = set_blank_if_default(dz, 0.)
                smethod = set_blank_if_default(method, 'IPS')
                susage = set_blank_if_default(usage, 'BOTH')
                snelements = set_blank_if_default(nelements, 10)
                smelements = set_blank_if_default(melements, 10)
                list_fields = ['SPLINE1', eid, caero, box1, box2,
                  setg, sdz, smethod, susage, snelements, smelements]
                list_fields = wipe_empty_fields(list_fields)
                bdf_file.write(print_card_8(list_fields))
Esempio n. 24
0
    def write_card(self, f, size=8, is_double=True, element_id=None):
        assert size in [8, 16], size
        assert is_double in [True, False], is_double
        if self.n:
            if element_id is None:
                i = arange(self.n)
            else:
                #assert len(unique(element_id))==len(element_id), unique(element_id)
                i = searchsorted(self.element_id, element_id)

            for (eid, caero, box1, box2, setg, dz, method, usage, nelements, melements,
                    ) in zip(self.element_id[i], self.caero[i], self.box1[i],
                    self.box2[i], self.setg[i], self.dz[i],
                    self.method[i], self.usage[i], self.nelements[i], self.melements[i]):

                sdz = set_blank_if_default(dz, 0.)
                smethod = set_blank_if_default(method, 'IPS')
                susage = set_blank_if_default(usage, 'BOTH')
                snelements = set_blank_if_default(nelements, 10)
                smelements = set_blank_if_default(melements, 10)
                list_fields = ['SPLINE1', eid, caero, box1, box2,
                  setg, sdz, smethod, susage, snelements, smelements]
                list_fields = wipe_empty_fields(list_fields)
                f.write(print_card_8(list_fields))
Esempio n. 25
0
    def add_card(self, card_lines, card_name, comment='', is_list=True):
        """
        Adds a card object to the BDF object using a streaming approach.

        :param self:       the BDF object
        :param card_lines: the list of the card fields
         >>> ['GRID,1,2',]  # (is_list = False)
         >>> ['GRID',1,2,]  # (is_list = True; default)

        :param card_name: the card_name -> 'GRID'
        :param comment:   an optional the comment for the card
        :param is_list:   changes card_lines from a list of lines to
                          a list of fields
        :returns card_object: the card object representation of card

        .. note:: this is a very useful method for interfacing with the code
        .. note:: the cardObject is not a card-type object...so not a GRID
                  card or CQUAD4 object.  It's a BDFCard Object.  However,
                  you know the type (assuming a GRID), so just call the
                  *mesh.Node(nid)* to get the Node object that was just
                  created.
        .. warning:: cardObject is not returned
        """
        if comment:
            self.bdf_out_file.write(comment)

        if card_name in ['DEQATN']:
            card_obj = card_lines
            card = card_lines
            #print("card =", '\n'.join(card_lines))
            self.bdf_out_file.write('\n'.join(card_lines))
        else:
            if is_list:
                fields = card_lines
            else:
                fields = to_fields(card_lines, card_name)

            # apply OPENMDAO syntax
            if self._is_dynamic_syntax:
                fields = [
                    self._parse_dynamic_syntax(field)
                    if '%' in field[0:1] else field for field in fields
                ]

            card = wipe_empty_fields([
                interpret_value(field, fields) if field is not None else None
                for field in fields
            ])
            #print(card)
            card_obj = BDFCard(card)
            self.bdf_out_file.write(print_card_8(card_obj))

        #for reject_card in self.reject_cards:
        #try:
        #print('comment =', comment)
        #except RuntimeError:
        #for field in reject_card:
        #if field is not None and '=' in field:
        #raise SyntaxError('cannot reject equal signed '
        #              'cards\ncard=%s\n' % reject_card)
        #raise

        #self.reject_cards.append(card)
        #print('rejecting processed auto=rejected %s' % card)
        return card_obj
Esempio n. 26
0
 def __init__(self, card, has_none=True):
     if has_none:
         card = wipe_empty_fields([print_field_16(field).strip() for field in card])
     self.card = card
     self.nfields = len(self.card)
Esempio n. 27
0
def to_fields_replication(card_lines):
    """
    Converts a series of lines in a card into string versions of the field.
    Handles large, small, and CSV formatted cards.  Same as to_fields, but
    uses a different method to determine if it's large or small field format.

    Parameters
    ----------
    lines : List[str]
        the lines of the BDF card object

    Returns
    -------
    fields : List[str]
        the string formatted fields of the card

    .. warning:: this function is used by the reader and isn't intended
                 to be called by a separate process

    .. code-block:: python

      >>> card_lines = ['GRID,1,,1.0,2.0,3.0']
      >>> card_name = 'GRID'
      >>> fields = to_fields_replication(lines)
      >>> fields
      ['GRID', '1', '', '1.0', '2.0', '3.0']

    """
    #print('to_fields_replicationA =', card_lines)
    #line0 = card_lines[0]
    fields = []
    for iline, line in enumerate(card_lines):
        line = line.rstrip()

        if '\t' in line:
            line = expand_tabs(line)
        #print('  line = %r' % line)
        if ',' in line:
            assert '\t' not in line, '%r' % line
            sline = line.split(',')
            #print('sline = ', iline, sline)
            if iline == 0:
                card_name = sline[0]
                #assert card_name != '=', card_lines
                fields.append(card_name)

            if '*' in sline[0]:
                fields.extend(sline[1:5])
                for unused_i in range(5 - len(sline)):
                    fields.append('')
            else:
                fields.extend(sline[1:9])
                for unused_i in range(9 - len(sline)):
                    fields.append('')
        else:
            assert '\t' not in line, line
            if iline == 0:
                card_name = line[0:8]
                assert card_name != '=', card_lines
                fields.append(card_name)

            if '*' in card_name:
                fields.extend(
                    [line[8:24], line[24:40], line[40:56], line[56:72]])
            else:
                fields.extend([
                    line[8:16], line[16:24], line[24:32], line[32:40],
                    line[40:48], line[48:56], line[56:64], line[64:72]
                ])
    assert '*' not in card_name, card_lines
    wiped_fields = wipe_empty_fields(fields)
    for field in fields:
        sfield = field.strip()
        #while '= ' in sfield:
        #sfield = field.replace('= ','=')
        #print('sfield=%r' % sfield)
        if ' ' in sfield:
            raise RuntimeError('field=%r has embedded blanks\nfields=%s' %
                               (sfield, fields))
    return wiped_fields
Esempio n. 28
0
    def add_card(self, card_lines, card_name, comment='', is_list=True):
        """
        Adds a card object to the BDF object using a streaming approach.

        Parameters
        ----------
        card_lines : List[str]
            the list of the card fields

         >>> ['GRID,1,2',]  # (is_list = False)
         >>> ['GRID',1,2,]  # (is_list = True; default)

        card_name : str
            the card_name -> 'GRID'
        comment : str; default=True
            an optional the comment for the card
        is_list : bool; default=True
            changes card_lines from a list of lines to
            a list of fields

        Returns
        -------
        card_object : BDFCard()
            the card object representation of card

        .. note:: this is a very useful method for interfacing with the code
        .. note:: the cardObject is not a card-type object...so not a GRID
                  card or CQUAD4 object.  It's a BDFCard Object.  However,
                  you know the type (assuming a GRID), so just call the
                  *mesh.Node(nid)* to get the Node object that was just
                  created.
        .. warning:: cardObject is not returned
        """
        if comment:
            self.bdf_out_file.write(comment)

        if card_name in ['DEQATN']:
            card_obj = card_lines
            card = card_lines
            #print("card =", '\n'.join(card_lines))
            self.bdf_out_file.write('\n'.join(card_lines))
        else:
            if is_list:
                fields = card_lines
            else:
                fields = to_fields(card_lines, card_name)

            # apply OPENMDAO syntax
            if self._is_dynamic_syntax:
                fields = [self._parse_dynamic_syntax(field) if '%' in
                          field[0:1] else field for field in fields]

            card = wipe_empty_fields([interpret_value(field, fields) if field is not None
                                      else None for field in fields])
            #print(card)
            card_obj = BDFCard(card)
            self.bdf_out_file.write(print_card_8(card_obj))

        #for reject_card in self.reject_cards:
            #try:
            #print('comment =', comment)
            #except RuntimeError:
                #for field in reject_card:
                    #if field is not None and '=' in field:
                        #raise SyntaxError('cannot reject equal signed '
                        #              'cards\ncard=%s\n' % reject_card)
                #raise

        #self.reject_cards.append(card)
        #print('rejecting processed auto=rejected %s' % card)
        return card_obj
Esempio n. 29
0
def print_card_16(fields, wipe_fields=True):
    # type: (List[Optional[Union[int, float, str]]], bool) -> str
    """
    Prints a nastran-style card with 16-character width fields.

    Parameters
    ----------
    fields : List[varies]
        all the fields in the BDF card (no trailing Nones)
    wipe_fields : bool; default=True
        some cards (e.g. PBEAM) have ending fields
        that need to be there, others cannot have them.

    Returns
    -------
    card : str
        string representation of the card in small field format

    .. note:: An internal field value of None or '' will be treated as
              a blank field
    .. note:: A large field format follows the  8-16-16-16-16-8 = 80
              format where the first 8 is the card name or
              blank (continuation).  The last 8-character field indicates
              an optional continuation, but because it's a left-justified
              unneccessary field, print_card doesnt use it.

    .. code-block:: python

      >>> fields = ['DUMMY', 1, 2, 3, None, 4, 5, 6, 7, 8.]
      >>> print_card_16(fields)
      DUMMY*                 1               2               3
      *                      4               5               6               7
      *                     8.
      *
    """
    if wipe_fields:
        fields = wipe_empty_fields(fields)
    nfields_main = len(fields) - 1  # chop off the card name
    nbdf_lines = nfields_main // 8
    if nfields_main % 8 != 0:
        nbdf_lines += 1
        nextra_fields = 8 * nbdf_lines - nfields_main
        fields += [None] * nextra_fields

    try:
        out = '%-8s' % (fields[0] + '*')
    except:
        print("ERROR!  fields=%s" % fields)
        sys.stdout.flush()
        raise

    for i in range(1, len(fields)):
        field = fields[i]
        try:
            out += print_field_16(field)
        except:
            print("bad fields = %s" % fields)
            raise
        if i % 4 == 0:  # allow 1+4 fields per line
            out = out.rstrip(' ')
            if out[-1] == '\n':  # empty line
                out += '*'
            out += '\n*       '
    out = out.rstrip(' *')  # removes one continuation star
    if not out.endswith('\n'):
        out += '\n'
    return out