Exemple #1
0
 def write_card_16(self, is_double=False):
     """
         Writes a GRID card in 16-field format
         """
     xyz = self.xyz
     cp = set_string16_blank_if_default(self.Cp(), 0)
     cd = set_string16_blank_if_default(self.Cd(), 0)
     seid = set_string16_blank_if_default(self.SEid(), 0)
     if is_double:
         msg = ('%-8s%16i%16s%16s%16s\n'
                '%-8s%16s%16s%16s%16s\n' % (
                    'GRID*', self.nid,
                    cp,
                    print_scientific_double(xyz[0]),
                    print_scientific_double(xyz[1]),
                    '*',
                    print_scientific_double(xyz[2]),
                    cd, self.ps, seid))
     else:
         msg = ('%-8s%16i%16s%16s%16s\n'
                '%-8s%16s%16s%16s%16s\n' % (
                    'GRID*', self.nid,
                    cp,
                    print_float_16(xyz[0]),
                    print_float_16(xyz[1]),
                    '*',
                    print_float_16(xyz[2]),
                    cd, self.ps, seid))
     return self.comment + msg.rstrip() + '\n'
Exemple #2
0
 def write_card_16(self, is_double=False):
     # TODO: we're sure MPCs support double precision?
     msg = 'MPC*    %16s' % self.conid
     grids, constraints, coefficients = self.node_ids, self.constraints, self.coefficients
     if is_double:
         for i, grid, component, coefficient in zip(count(), grids,
                                                    constraints,
                                                    coefficients):
             if i == 0:
                 msg += '%16i%16s%16s\n' % (
                     grid, component, print_scientific_double(coefficient))
             elif i % 2 == 1:
                 msg += '%-8s%16i%16s%16s\n' % (
                     '*', grid, component,
                     print_scientific_double(coefficient))
             else:
                 msg += '%-8s%16s%16i%16s%16s\n' % (
                     '*', '', grid, component,
                     print_scientific_double(coefficient))
     else:
         for i, grid, component, coefficient in zip(count(), grids,
                                                    constraints,
                                                    coefficients):
             if i == 0:
                 msg += '%16i%16s%16s\n' % (grid, component,
                                            print_float_16(coefficient))
             elif i % 2 == 1:
                 msg += '%-8s%16i%16s%16s\n' % ('*', grid, component,
                                                print_float_16(coefficient))
             else:
                 msg += '%-8s%16s%16i%16s%16s\n' % (
                     '*', '', grid, component, print_float_16(coefficient))
     if i % 2 == 0:
         msg += '*'
     return self.comment + msg.rstrip() + '\n'
Exemple #3
0
 def write_card_16(self, is_double=False):
     # TODO: we're sure MPCs support double precision?
     msg = 'MPC*    %16s' % self.conid
     grids, constraints, enforceds = self.node_ids, self.constraints, self.enforced
     if is_double:
         for i, grid, component, enforced in zip(count(), grids, constraints, enforceds):
             if i == 0:
                 msg += '%16i%16s%16s\n' % (
                     grid, component, print_scientific_double(enforced))
             elif i % 2 == 1:
                 msg += '%-8s%16i%16s%16s\n' % (
                     '*', grid, component, print_scientific_double(enforced))
             else:
                 msg += '%-8s%16s%16i%16s%16s\n' % (
                     '*', '', grid, component, print_scientific_double(enforced))
     else:
         for i, grid, component, enforced in zip(count(), grids, constraints, enforceds):
             if i == 0:
                 msg += '%16i%16s%16s\n' % (grid, component, print_float_16(enforced))
             elif i % 2 == 1:
                 msg += '%-8s%16i%16s%16s\n' % (
                     '*', grid, component, print_float_16(enforced))
             else:
                 msg += '%-8s%16s%16i%16s%16s\n' % (
                     '*', '', grid, component, print_float_16(enforced))
     if i % 2 == 0:
         msg += '*'
     return self.comment + msg.rstrip() + '\n'
Exemple #4
0
    def write_bdf2(self, size=8, is_double=False):
        """
        The writer method used by BDF.write_bdf

        :param self:
          the GRID object pointer
        :param size:
          the size of the card (8/16)
        :type size:
          int
        :param isdouble:
          should this card be written with double precision (default=False)
        :type is_double:
          bool
        """
        xyz = self.xyz
        if size == 8:
            cp = set_string8_blank_if_default(self.Cp(), 0)
            cd = set_string8_blank_if_default(self.Cd(), 0)
            seid = set_string8_blank_if_default(self.SEid(), 0)
            msg = '%-8s%8i%8s%s%s%s%s%8s%s\n' % ('GRID', self.nid, cp,
                    print_float_8(xyz[0]),
                    print_float_8(xyz[1]),
                    print_float_8(xyz[2]),
                    cd, self.ps, seid)
        else:
            cp = set_string16_blank_if_default(self.Cp(), 0)
            cd = set_string16_blank_if_default(self.Cd(), 0)
            seid = set_string16_blank_if_default(self.SEid(), 0)
            if double:
                msg = ('%-8s%16i%16s%16s%16s\n'
                       '%-8s%16s%16s%16s%16s\n' % ('GRID*', self.nid,
                        cp,
                        print_scientific_double(xyz[0]),
                        print_scientific_double(xyz[1]),
                        '*',
                        print_scientific_double(xyz[2]),
                        cd, self.ps, seid))
            else:
                msg = ('%-8s%16i%16s%16s%16s\n'
                       '%-8s%16s%16s%16s%16s\n' % ('GRID*', self.nid,
                        cp,
                        print_float_16(xyz[0]),
                        print_float_16(xyz[1]),
                        '*',
                        print_float_16(xyz[2]),
                        cd, self.ps, seid))
        return self.comment() + msg.rstrip() + '\n'
Exemple #5
0
 def write_bdf2(self, size=8, double=False):
     if size == 8:
         msg = 'MPC     %8s' % self.conid
         for (i, grid, component, enforced) in zip(count(), self.gids,
                                                   self.constraints,
                                                   self.enforced):
             msg += '%8i%8s%8s' % (grid, component, print_float_8(enforced))
             if i % 2 == 1 and i > 0:
                 msg += '\n%8s%8s' % ('', '')
     elif size == 16:
         # TODO: we're sure MPCs support double precision?
         msg = 'MPC*    %16s' % self.conid
         if double:
             for (i, grid, component,
                  enforced) in zip(count(), self.gids, self.constraints,
                                   self.enforced):
                 msg += '%16i%16s%16s' % (grid, component,
                                          print_scientific_double(enforced))
                 if i % 2 == 1 and i > 0:
                     msg += '\n%8s%16s' % ('*', '')
         else:
             for (i, grid, component,
                  enforced) in zip(count(), self.gids, self.constraints,
                                   self.enforced):
                 msg += '%16i%16s%16s' % (grid, component,
                                          print_float_16(enforced))
                 if i % 2 == 1 and i > 0:
                     msg += '\n%8s%16s' % ('*', '')
     return self.comment() + msg.rstrip() + '\n'
Exemple #6
0
    def write_bdf2(self, size=8, is_double=False):
        """
        The writer method used by BDF.write_bdf

        :param self:
          the GRID object pointer
        :param size:
          the size of the card (8/16)
        :type size:
          int
        :param isdouble:
          should this card be written with double precision (default=False)
        :type is_double:
          bool
        """
        xyz = self.xyz
        if size == 8:
            cp = set_string8_blank_if_default(self.Cp(), 0)
            cd = set_string8_blank_if_default(self.Cd(), 0)
            seid = set_string8_blank_if_default(self.SEid(), 0)
            msg = '%-8s%8i%8s%s%s%s%s%8s%s\n' % (
                'GRID', self.nid, cp, print_float_8(
                    xyz[0]), print_float_8(xyz[1]), print_float_8(
                        xyz[2]), cd, self.ps, seid)
        else:
            cp = set_string16_blank_if_default(self.Cp(), 0)
            cd = set_string16_blank_if_default(self.Cd(), 0)
            seid = set_string16_blank_if_default(self.SEid(), 0)
            if double:
                msg = ('%-8s%16i%16s%16s%16s\n'
                       '%-8s%16s%16s%16s%16s\n' %
                       ('GRID*', self.nid, cp, print_scientific_double(
                           xyz[0]), print_scientific_double(xyz[1]), '*',
                        print_scientific_double(xyz[2]), cd, self.ps, seid))
            else:
                msg = ('%-8s%16i%16s%16s%16s\n'
                       '%-8s%16s%16s%16s%16s\n' %
                       ('GRID*', self.nid, cp, print_float_16(xyz[0]),
                        print_float_16(xyz[1]), '*', print_float_16(
                            xyz[2]), cd, self.ps, seid))
        return self.comment() + msg.rstrip() + '\n'
Exemple #7
0
    def write_card_16(self, is_double=False):
        """
        Writes a GRID card in 16-field format
        """
        xyz = self.xyz
        cp = set_string16_blank_if_default(self.Cp(), 0)
        cd = set_string16_blank_if_default(self.Cd(), 0)
        seid = set_string16_blank_if_default(self.SEid(), 0)

        if is_double:
            if [cd, self.ps, self.seid] == [0, '', 0]:
                msg = ('GRID*   %16i%16s%16s%16s\n'
                       '*       %16s\n' %
                       (self.nid, cp, print_scientific_double(
                           xyz[0]), print_scientific_double(
                               xyz[1]), print_scientific_double(xyz[2])))
            else:
                msg = ('GRID*   %16i%16s%16s%16s\n'
                       '*       %16s%16s%16s%16s\n' %
                       (self.nid, cp, print_scientific_double(
                           xyz[0]), print_scientific_double(xyz[1]),
                        print_scientific_double(xyz[2]), cd, self.ps, seid))
        else:
            if [cd, self.ps, self.seid] == [0, '', 0]:
                msg = ('GRID*   %16i%16s%16s%16s\n'
                       '*       %16s\n' %
                       (self.nid, cp, print_float_16(xyz[0]),
                        print_float_16(xyz[1]), print_float_16(xyz[2])))
            else:
                msg = ('GRID*   %16i%16s%16s%16s\n'
                       '*       %16s%16s%16s%16s\n' %
                       (self.nid, cp, print_float_16(xyz[0]),
                        print_float_16(xyz[1]), print_float_16(
                            xyz[2]), cd, self.ps, seid))
        return self.comment + msg
Exemple #8
0
    def write_card_16(self, is_double=False, bdf_file=None):
        # type: (bool) -> str
        """
        Writes a GRID card in 16-field format
        """
        assert bdf_file is not None
        self.make_current()
        msg = ''
        for nid, xyz, cp, cd, ps, seid in zip(
            self.nid, self.xyz, self.cp, self.cd, self.ps, self.seid):
            cps = set_string8_blank_if_default(cp, 0)
            cp = set_string16_blank_if_default(cp, 0)
            cd = set_string16_blank_if_default(cd, 0)
            seid = set_string16_blank_if_default(seid, 0)

            if is_double:
                if [cd, ps, seid] == [0, '', 0]:
                    msgi = ('GRID*   %16i%16s%16s%16s\n'
                            '*       %16s\n' % (
                                nid,
                                cp,
                                print_scientific_double(xyz[0]),
                                print_scientific_double(xyz[1]),
                                print_scientific_double(xyz[2])))
                else:
                    msgi = ('GRID*   %16i%16s%16s%16s\n'
                            '*       %16s%16s%16s%16s\n' % (
                                nid,
                                cp,
                                print_scientific_double(xyz[0]),
                                print_scientific_double(xyz[1]),
                                print_scientific_double(xyz[2]),
                                cd, ps, seid))
            else:
                if [cd, self.ps, self.seid] == [0, '', 0]:
                    msgi = ('GRID*   %16i%16s%16s%16s\n'
                            '*       %16s\n' % (
                                nid,
                                cp,
                                print_float_16(xyz[0]),
                                print_float_16(xyz[1]),
                                print_float_16(xyz[2])))
                else:
                    msgi = ('GRID*   %16i%16s%16s%16s\n'
                            '*       %16s%16s%16s%16s\n' % (
                                nid,
                                cp,
                                print_float_16(xyz[0]),
                                print_float_16(xyz[1]),
                                print_float_16(xyz[2]),
                                cd, ps, seid))
                msg += self.comment[nid] + msgi
        bdf_file.write(msg)
        return msg
Exemple #9
0
 def write_bdf2(self, size=8, double=False):
     if size == 8:
         msg = 'MPC     %8s' % self.conid
         for (i, grid, component, enforced) in zip(count(), self.gids,
              self.constraints, self.enforced):
             msg += '%8i%8s%8s' % (grid, component, print_float_8(enforced))
             if i % 2 == 1 and i > 0:
                 msg += '\n%8s%8s' % ('', '')
     elif size == 16:
         # TODO: we're sure MPCs support double precision?
         msg = 'MPC*    %16s' % self.conid
         if double:
             for (i, grid, component, enforced) in zip(count(), self.gids,
                  self.constraints, self.enforced):
                 msg += '%16i%16s%16s' % (grid, component, print_scientific_double(enforced))
                 if i % 2 == 1 and i > 0:
                     msg += '\n%8s%16s' % ('*', '')
         else:
             for (i, grid, component, enforced) in zip(count(), self.gids,
                  self.constraints, self.enforced):
                 msg += '%16i%16s%16s' % (grid, component, print_float_16(enforced))
                 if i % 2 == 1 and i > 0:
                     msg += '\n%8s%16s' % ('*', '')
     return self.comment() + msg.rstrip() + '\n'
Exemple #10
0
    def write_bdf_by_index(self, f, i=None, size=8, is_double=False, write_header=True):
        """
        Write the BDF cards

        :param f: a file object
        :param i: the indicies (default=None -> all)
        :param size: the field width (8/16)
        :param is_double: is this double precision (default=False)
        :param write_header: should the card marker be written
        """
        if i is None:
            i = slice(None, None)
        if self.n:
            if write_header:
                f.write('$GRID\n')
            #self.model.log.debug('GRID i = %s' % i)

            # default to the GRDSET defaults
            #cp0 = self.model.grdset.cp
            #cd0 = self.model.grdset.cd
            #ps0 = self.model.grdset.ps
            #seid0 = self.model.grdset.seid

            # default to the GRID defaults
            cp0 = 0
            cd0 = 0
            ps0 = -1
            seid0 = 0
            blank = ' '*8 if size==8 else ' ' * 16
            Cp   = [cpi if cpi != cp0 else blank for cpi in self.cp[i]]
            Cd   = [cdi if cdi != cd0 else blank for cdi in self.cd[i]]
            Ps   = [psi if psi != ps0 else blank for psi in self.ps[i]]
            Seid = [seidi if seidi != seid0 else blank for seidi in self.seid[i]]
            if size == 8:
                for (nid, cp, xyz, cd, ps, seid) in zip(self.node_id, Cp, self.xyz[i, :], Cd, Ps, Seid):
                    msg = ('%-8s%8i%8s%s%s%s%s%8s%s\n' % ('GRID', nid, cp,
                            print_float_8(xyz[0]),
                            print_float_8(xyz[1]),
                            print_float_8(xyz[2]),
                            cd, ps, seid)).rstrip() + '\n'
                    f.write(msg)
            else:
                if is_double:
                    for (nid, cp, xyz, cd, ps, seid) in zip(self.node_id, Cp, self.xyz[i, :], Cd, Ps, Seid):
                        msg = (('%-8s%16i%16s%16s%16s\n'
                               '%-8s%16s%16s%16s%16s\n' % ('GRID*', nid,
                                cp,
                                print_scientific_double(xyz[0]),
                                print_scientific_double(xyz[1]),
                                '*',
                                print_scientific_double(xyz[2]),
                                cd, ps, seid))).rstrip() + '\n'
                        f.write(msg)
                else:
                    for (nid, cp, xyz, cd, ps, seid) in zip(self.node_id, Cp, self.xyz[i, :], Cd, Ps, Seid):
                        msg = (('%-8s%16i%16s%16s%16s\n'
                               '%-8s%16s%16s%16s%16s\n' % ('GRID*', nid,
                                cp,
                                print_float_16(xyz[0]),
                                print_float_16(xyz[1]),
                                '*',
                                print_float_16(xyz[2]),
                                cd, ps, seid))).rstrip() + '\n'
                        f.write(msg)
Exemple #11
0
    def write_card_by_index(self,
                            bdf_file,
                            i=None,
                            size=8,
                            is_double=False,
                            write_header=True):
        """
        Write the BDF cards

        Parameters
        ----------
        bdf_file : file
            a file object
        i : List[int] (default=None -> all)
            the indicies
        size : int; default=8
            the field width (8/16)
        is_double: bool; default=False
            is this double precision
        write_header : bool; default=True
            should the card marker be written
        """
        if i is None:
            i = slice(None, None)
        if self.n:
            if write_header:
                bdf_file.write('$GRID\n')
            if max(self.node_id.max(), self.cd.max(),
                   self.cp.max()) > self.model.max_int:
                size = 16
            #self.model.log.debug('GRID i = %s' % i)

            # default to the GRDSET defaults
            #cp0 = self.model.grdset.cp
            #cd0 = self.model.grdset.cd
            #ps0 = self.model.grdset.ps
            #seid0 = self.model.grdset.seid

            # default to the GRID defaults
            #cp0 = 0
            #cd0 = 0
            ps0 = -1
            seid0 = 0
            blank = ' ' * 8 if size == 8 else ' ' * 16
            Cp = [cpi if cpi != 0 else blank for cpi in self.cp[i]]
            Cd = [cdi if cdi != 0 else blank for cdi in self.cd[i]]
            Ps = [psi if psi != ps0 else blank for psi in self.ps[i]]
            Seid = [
                seidi if seidi != seid0 else blank for seidi in self.seid[i]
            ]
            if size == 8:
                for (nid, cp, xyz, cd, ps,
                     seid) in zip(self.node_id, Cp, self.xyz[i, :], Cd, Ps,
                                  Seid):
                    msg = (
                        'GRID    %8i%8s%s%s%s%8s%8s%s\n' %
                        (nid, cp, print_float_8(xyz[0]), print_float_8(xyz[1]),
                         print_float_8(xyz[2]), cd, ps, seid)).rstrip() + '\n'

                    bdf_file.write(msg)
            else:
                if is_double:
                    for (nid, cp, xyz, cd, ps,
                         seid) in zip(self.node_id, Cp, self.xyz[i, :], Cd, Ps,
                                      Seid):
                        msg = (('GRID*   %16i%16s%16s%16s\n'
                                '*       %16s%16s%16s%16s\n' %
                                (nid, cp, print_scientific_double(
                                    xyz[0]), print_scientific_double(xyz[1]),
                                 print_scientific_double(
                                     xyz[2]), cd, ps, seid))).rstrip() + '\n'
                        bdf_file.write(msg)
                else:
                    for (nid, cp, xyz, cd, ps,
                         seid) in zip(self.node_id, Cp, self.xyz[i, :], Cd, Ps,
                                      Seid):
                        msg = (('GRID*   %16i%16s%16s%16s\n'
                                '*       %-8s%16s%16s%16s\n' %
                                (nid, cp, print_float_16(xyz[0]),
                                 print_float_16(xyz[1]), print_float_16(
                                     xyz[2]), cd, ps, seid))).rstrip() + '\n'
                        bdf_file.write(msg)
Exemple #12
0
    def write_card_by_index(self, bdf_file, i=None, size=8, is_double=False, write_header=True):
        """
        Write the BDF cards

        Parameters
        ----------
        bdf_file : file
            a file object
        i : List[int] (default=None -> all)
            the indicies
        size : int; default=8
            the field width (8/16)
        is_double: bool; default=False
            is this double precision
        write_header : bool; default=True
            should the card marker be written
        """
        if i is None:
            i = slice(None, None)
        if self.n:
            if write_header:
                bdf_file.write('$GRID\n')
            if max(self.node_id.max(), self.cd.max(), self.cp.max()) > self.model.max_int:
                size = 16
            #self.model.log.debug('GRID i = %s' % i)

            # default to the GRDSET defaults
            #cp0 = self.model.grdset.cp
            #cd0 = self.model.grdset.cd
            #ps0 = self.model.grdset.ps
            #seid0 = self.model.grdset.seid

            # default to the GRID defaults
            #cp0 = 0
            #cd0 = 0
            ps0 = -1
            seid0 = 0
            blank = ' ' * 8 if size == 8 else ' ' * 16
            Cp = [cpi if cpi != 0 else blank for cpi in self.cp[i]]
            Cd = [cdi if cdi != 0 else blank for cdi in self.cd[i]]
            Ps = [psi if psi != ps0 else blank for psi in self.ps[i]]
            Seid = [seidi if seidi != seid0 else blank for seidi in self.seid[i]]
            if size == 8:
                for (nid, cp, xyz, cd, ps, seid) in zip(
                        self.node_id, Cp, self.xyz[i, :], Cd, Ps, Seid):
                    msg = ('GRID    %8i%8s%s%s%s%8s%8s%s\n' % (
                        nid, cp,
                        print_float_8(xyz[0]),
                        print_float_8(xyz[1]),
                        print_float_8(xyz[2]),
                        cd, ps, seid)).rstrip() + '\n'

                    bdf_file.write(msg)
            else:
                if is_double:
                    for (nid, cp, xyz, cd, ps, seid) in zip(
                            self.node_id, Cp, self.xyz[i, :], Cd, Ps, Seid):
                        msg = (('GRID*   %16i%16s%16s%16s\n'
                                '*       %16s%16s%16s%16s\n' % (
                                    nid, cp,
                                    print_scientific_double(xyz[0]),
                                    print_scientific_double(xyz[1]),
                                    print_scientific_double(xyz[2]),
                                    cd, ps, seid))).rstrip() + '\n'
                        bdf_file.write(msg)
                else:
                    for (nid, cp, xyz, cd, ps, seid) in zip(
                            self.node_id, Cp, self.xyz[i, :], Cd, Ps, Seid):
                        msg = (('GRID*   %16i%16s%16s%16s\n'
                                '*       %-8s%16s%16s%16s\n' % (
                                    nid, cp,
                                    print_float_16(xyz[0]),
                                    print_float_16(xyz[1]),
                                    print_float_16(xyz[2]),
                                    cd, ps, seid))).rstrip() + '\n'
                        bdf_file.write(msg)