Exemplo n.º 1
0
    def write_card(self, bdf_file, size=8, is_double=False):
        #nids = ['%8i' % node_id for node_id in self.node_id]
        nleftover = self.n // 3 * 3
        if size == 8:
            temps = [print_float_8(tempi) % temp for temp in self.temperature]
            for i in range(0, self.n, 3):
                bdf_file.write('TEMP    %8i%8i%s %8i%s%8i%s' % (self.temp_id,
                                                                self.node_id[i], print_float_8(temps[i]),
                                                                self.node_id[i+1], print_float_8(temps[i+1]),
                                                                self.node_id[i+2], print_float_8(temps[i+2])))
            for i in range(nleftover, self.n - nleftover):
                bdf_file.write('TEMP    %8i%s' % (self.temp_id, print_float_8(temps[i])))

            if self.is_default:
                bdf_file.write('TEMPD   %8i%s\n' % (self.temp_id, print_float_8(self.default)))
        else:
            temps = [print_float_16(tempi) % temp for temp in self.temperature]
            for i in range(0, self.n, 3):
                bdf_file.write('TEMP*   %16i%16i%s\n' % (self.temp_id,
                                                         self.node_id[i], print_float_16(temps[i])))
                bdf_file.write('%8s%16i%s%16i%s' % ('*       ',
                                                    self.node_id[i+1], print_float_16(temps[i+1]),
                                                    self.node_id[i+2], print_float_16(temps[i+2])))
            for i in range(nleftover, self.n - nleftover):
                bdf_file.write('TEMP*   %16i%16i%s\n*\n' % (self.temp_id, self.node_id[i], print_float_16(temps[i])))
            if self.is_default:
                bdf_file.write('TEMPD*  %16i%s\n' % (self.temp_id, print_float_16(self.default)))
Exemplo n.º 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'
Exemplo n.º 3
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'
Exemplo n.º 4
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'
Exemplo n.º 5
0
    def write_card(self, bdf_file, size=8, is_double=False, element_id=None):
        assert self.n > 0, self.n
        if self.n:
            if element_id is None:
                i = arange(self.n)
            else:
                i = searchsorted(self.element_id, element_id)

            blank = ' ' * size
            #cid = [cid if cid != 0 else '' for cid in self.coord_id]


            #Mass = [x if x != 0.0 else '' for x in self.mass[i]]
            if size == 8:
                X0 = [print_float_8(x) if x != 0.0 else blank for x in self.x[i, 0]]
                X1 = [print_float_8(x) if x != 0.0 else blank for x in self.x[i, 1]]
                X2 = [print_float_8(x) if x != 0.0 else '' for x in self.x[i, 2]]

                I0 = [print_float_8(x) if x != 0.0 else blank for x in self.I[i, 0]]
                I1 = [print_float_8(x) if x != 0.0 else blank for x in self.I[i, 1]]
                I2 = [print_float_8(x) if x != 0.0 else blank for x in self.I[i, 2]]
                I3 = [print_float_8(x) if x != 0.0 else blank for x in self.I[i, 3]]
                I4 = [print_float_8(x) if x != 0.0 else blank for x in self.I[i, 4]]
                I5 = [print_float_8(x) if x != 0.0 else blank for x in self.I[i, 5]]
                for (eid, nid, cid, mass, x0, x1, x2, i0, i1, i2, i3, i4, i5) in zip(
                    self.element_id[i], self.node_id[i], self.coord_id[i], self.mass[i],
                    X0, X1, X2, I0, I1, I2, I3, I4, I5):
                    if eid in self._comments:
                        bdf_file.write(self._comments[eid])
                    carda = '%-8s%8i%8i%8i%8s%s%s%s\n' % ('CONM2', eid, nid, cid, print_float_8(mass), x0, x1, x2)
                    cardb = '%8s%8s%8s%8s%8s%8s%8s' % ('', i0, i1, i2, i3, i4, i5)
                    cardi = (carda + cardb).rstrip() + '\n'
                    bdf_file.write(cardi)
            else:
                assert size == 16, size
                X0 = [print_float_16(x) if x != 0.0 else blank for x in self.x[i, 0]]
                X1 = [print_float_16(x) if x != 0.0 else blank for x in self.x[i, 1]]
                X2 = [print_float_16(x) if x != 0.0 else '' for x in self.x[i, 2]]

                I0 = [print_float_16(x) if x != 0.0 else blank for x in self.I[i, 0]]
                I1 = [print_float_16(x) if x != 0.0 else blank for x in self.I[i, 1]]
                I2 = [print_float_16(x) if x != 0.0 else blank for x in self.I[i, 2]]
                I3 = [print_float_16(x) if x != 0.0 else blank for x in self.I[i, 3]]
                I4 = [print_float_16(x) if x != 0.0 else blank for x in self.I[i, 4]]
                I5 = [print_float_16(x) if x != 0.0 else blank for x in self.I[i, 5]]
                for (eid, nid, cid, mass, x0, x1, x2, i0, i1, i2, i3, i4, i5) in zip(
                    self.element_id[i], self.node_id[i], self.coord_id[i], self.mass[i],
                    X0, X1, X2, I0, I1, I2, I3, I4, I5):
                    if eid in self._comments:
                        bdf_file.write(self._comments[eid])
                    carda = '%-8s%16i%16i%16i%16s\n' % ('CONM2*', eid, nid, cid, print_float_8(mass), )
                    cardb = '%-8s%16s%16s%16s%16s\n' % ('*', x0, x1, x2, i0)
                    cardc = '%-8s%16s%16s%16s%16s\n' % ('*', i1, i2, i3, i4)
                    cardd = '%-8s%16s' % ('*', i5)
                    cardcd = (cardc + cardd).rstrip('* \n')
                    if cardcd:
                        cardi = carda + cardb + cardc + cardd
                    else:
                        cardi = carda + cardb
                    bdf_file.write(cardi.rstrip() + '\n')
Exemplo n.º 6
0
 def write_card(self, bdf_file, size=8, is_double=False):
     if self.n:
         if size == 8:
             for load_id, element_id, tbar, tprime in zip(
                     self.load_id, self.element_id, self.tbar, self.tprime):
                 bdf_file.write('TEMPP1  %8i%8i%s%s\n' %
                                (load_id, element_id, print_float_8(tbar),
                                 print_float_8(tprime)))
         else:
             for load_id, element_id, tbar, tprime in zip(
                     self.load_id, self.element_id, self.tbar, self.tprime):
                 bdf_file.write('TEMPP1* %16i%16i%s%s\n*\n' %
                                (load_id, element_id, print_float_16(tbar),
                                 print_float_16(tprime)))
Exemplo n.º 7
0
 def write_card(self, f, size=8, is_double=False):
     if self.n:
         if size == 8:
             for load_id, element_id, tbar, tprime in zip(self.load_id, self.element_id, self.tbar, self.tprime):
                 f.write('TEMPP1  %8i%8i%s%s\n' % (load_id, element_id, print_float_8(tbar), print_float_8(tprime)))
         else:
             for load_id, element_id, tbar, tprime in zip(self.load_id, self.element_id, self.tbar, self.tprime):
                 f.write('TEMPP1* %16i%16i%s%s\n*\n' % (load_id, element_id, print_float_16(tbar), print_float_16(tprime)))
Exemplo n.º 8
0
    def test_float_16(self):
        small_exponent = -17
        large_exponent = 17

        nums = (
            [0., 0.000034, -0.000034] +
            [9./11 * 10**x for x in range(small_exponent, large_exponent+1)] +
            [-9./11 * 10**x for x in range(small_exponent, large_exponent+1)])

        expected = [
            '              0.', '         .000034', '        -.000034',

            '8.18181818182-18', '8.18181818182-17', '8.18181818182-16', '8.18181818182-15',
            '8.18181818182-14', '8.18181818182-13', '8.18181818182-12', '8.18181818182-11',
            '8.18181818182-10', '8.181818181818-9', '8.181818181818-8', '8.181818181818-7',
            '8.181818181818-6', '8.181818181818-5', '8.181818181818-4', '.008181818181818',
            '.081818181818182', '.818181818181818', '8.18181818181818', '81.8181818181818',
            '818.181818181818', '8181.81818181818', '81818.1818181818', '818181.818181818',
            '8181818.18181818', '81818181.8181818', '818181818.181818', '8181818181.81818',
            '81818181818.1818', '818181818181.818', '8181818181818.18', '81818181818181.8',
            '818181818181818.', '8.18181818182+15', '8.18181818182+16',

            '-8.1818181818-18', '-8.1818181818-17', '-8.1818181818-16', '-8.1818181818-15',
            '-8.1818181818-14', '-8.1818181818-13', '-8.1818181818-12', '-8.1818181818-11',
            '-8.1818181818-10', '-8.18181818182-9', '-8.18181818182-8', '-8.18181818182-7',
            '-8.18181818182-6', '-8.18181818182-5', '-8.18181818182-4', '-8.18181818182-3',
            '-.08181818181818', '-.81818181818182', '-8.1818181818182', '-81.818181818182',
            '-818.18181818182', '-8181.8181818182', '-81818.181818182', '-818181.81818182',
            '-8181818.1818182', '-81818181.818182', '-818181818.18182', '-8181818181.8182',
            '-81818181818.182', '-818181818181.82', '-8181818181818.2', '-81818181818182.',
            '-8.1818181818+14', '-8.1818181818+15', '-8.1818181818+16',
        ]
        for x, expectedi in zip(nums, expected):
            output = print_float_16(x)
            self.assertEqual(len(output), 16, msg='output=%r len(output)=%i' % (output, len(output)))
            self.assertEqual(output, expectedi, msg='num=%s output=%r expected=%r' % (x, output, expectedi))

        if 0:
            nums = [0.99999999999999 * 10**x for x in range(small_exponent, large_exponent+1)]
            positive_output = [print_float_16(x) for x in nums]
            negative_output = [print_float_16(-x) for x in nums]
Exemplo n.º 9
0
    def test_float_16(self):
        small_exponent = -17
        large_exponent = 17

        nums = (
            [0., 0.000034, -0.000034] +
            [9./11 * 10**x for x in range(small_exponent, large_exponent+1)] +
            [-9./11 * 10**x for x in range(small_exponent, large_exponent+1)])

        expected = [
            '              0.', '         .000034', '        -.000034',

            '8.18181818182-18', '8.18181818182-17', '8.18181818182-16', '8.18181818182-15',
            '8.18181818182-14', '8.18181818182-13', '8.18181818182-12', '8.18181818182-11',
            '8.18181818182-10', '8.181818181818-9', '8.181818181818-8', '8.181818181818-7',
            '8.181818181818-6', '8.181818181818-5', '8.181818181818-4', '.008181818181818',
            '.081818181818182', '.818181818181818', '8.18181818181818', '81.8181818181818',
            '818.181818181818', '8181.81818181818', '81818.1818181818', '818181.818181818',
            '8181818.18181818', '81818181.8181818', '818181818.181818', '8181818181.81818',
            '81818181818.1818', '818181818181.818', '8181818181818.18', '81818181818181.8',
            '818181818181818.', '8.18181818182+15', '8.18181818182+16',

            '-8.1818181818-18', '-8.1818181818-17', '-8.1818181818-16', '-8.1818181818-15',
            '-8.1818181818-14', '-8.1818181818-13', '-8.1818181818-12', '-8.1818181818-11',
            '-8.1818181818-10', '-8.18181818182-9', '-8.18181818182-8', '-8.18181818182-7',
            '-8.18181818182-6', '-8.18181818182-5', '-8.18181818182-4', '-8.18181818182-3',
            '-.08181818181818', '-.81818181818182', '-8.1818181818182', '-81.818181818182',
            '-818.18181818182', '-8181.8181818182', '-81818.181818182', '-818181.81818182',
            '-8181818.1818182', '-81818181.818182', '-818181818.18182', '-8181818181.8182',
            '-81818181818.182', '-818181818181.82', '-8181818181818.2', '-81818181818182.',
            '-8.1818181818+14', '-8.1818181818+15', '-8.1818181818+16',
        ]
        for x, expectedi in zip(nums, expected):
            output = print_float_16(x)
            self.assertEqual(len(output), 16, msg='output=%r len(output)=%i' % (output, len(output)))
            self.assertEqual(output, expectedi, msg='num=%s output=%r expected=%r' % (x, output, expectedi))

        if 0:
            nums = [0.99999999999999 * 10**x for x in range(small_exponent, large_exponent+1)]
            positive_output = [print_float_16(x) for x in nums]
            negative_output = [print_float_16(-x) for x in nums]
Exemplo n.º 10
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
Exemplo n.º 11
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
Exemplo n.º 12
0
    def write_bdf(self,
                  bdf_filename,
                  include_shells=True,
                  include_solids=True,
                  convert_pyram_to_penta=True,
                  write_grids=True,
                  encoding=None,
                  size=16,
                  is_double=False,
                  check=True):
        """
        writes a Nastran BDF

        Parameters
        ----------
        size : int; {8, 16}; default=16
            the bdf write precision
        is_double : bool; default=False
            the field precision to write
        """
        self._check_node_ids()

        if encoding is None:
            encoding = sys.getdefaultencoding()
        #assert encoding.lower() in ['ascii', 'latin1', 'utf8'], encoding

        with open(bdf_filename, 'w', encoding=encoding) as bdf_file:
            #bdf_file.write('CEND\n')
            #bdf_file.write('BEGIN BULK\n')
            bdf_file.write('$ pyNastran: punch=True\n')
            bdf_file.write('$ pyNastran: encoding=utf-8\n')
            mid = 1
            bdf_file.write('MAT1, %i, 1.0e7,, 0.3\n' % mid)

            self.log.debug('writing GRIDs')
            write_grids = True
            if write_grids:
                if not self.read_solids:
                    nids_to_write = np.unique(
                        np.hstack([self.quads.ravel(),
                                   self.tris.ravel()]))
                    nnodes = self.nodes.shape[0]
                    all_nids = np.arange(nnodes, dtype='int32')
                    inid = np.searchsorted(all_nids, nids_to_write)
                    unused_nodes = self.nodes[inid, :]

                    if size == 8:
                        for i, nid in enumerate(nids_to_write):
                            if i % 200000:  # pragma: no cover
                                print('  i = %s' % i)
                            node = self.nodes[i, :]
                            bdf_file.write('GRID    %8i%8s%s%s%s\n' %
                                           (nid, '', print_float_8(node[0]),
                                            print_float_8(node[1]),
                                            print_float_8(node[2])))
                    else:
                        for i, nid in enumerate(nids_to_write):
                            if i % 200000:  # pragma: no cover
                                print('  i = %s' % i)
                            node = self.nodes[i, :]
                            bdf_file.write('GRID*   %16i%16s%16s%16s\n'
                                           '*       %16s\n' %
                                           (nid, '', print_float_16(node[0]),
                                            print_float_16(node[1]),
                                            print_float_16(node[2])))
                else:
                    if check:
                        self.check_hanging_nodes()
                    if size == 8:
                        for i, node in enumerate(self.nodes):
                            node = self.nodes[i, :]
                            bdf_file.write('GRID    %8i%8s%s%s%s\n' %
                                           (i + 1, '', print_float_8(node[0]),
                                            print_float_8(node[1]),
                                            print_float_8(node[2])))
                    else:
                        for i, node in enumerate(self.nodes):
                            node = self.nodes[i, :]
                            bdf_file.write('GRID*   %16i%16s%16s%16s\n'
                                           '*       %16s\n' %
                                           (i + 1, '', print_float_16(node[0]),
                                            print_float_16(node[1]),
                                            print_float_16(node[2])))

                self.log.debug('finished writing GRIDs')

            eid = 1
            pids = self.pids  #+ 1
            if include_shells:
                upids = unique(pids)  # auto-sorts
                for pid in upids:
                    bdf_file.write('PSHELL,%i,%i, 0.1\n' % (pid, mid))
                self.log.debug('writing CTRIA3')
                for element in self.tris:
                    assert len(np.unique(element)) == 3, element
                    bdf_file.write('CTRIA3  %-8i%-8i%-8i%-8i%-8i\n' %
                                   (eid, pids[eid - 1], element[0], element[1],
                                    element[2]))
                    eid += 1

                self.log.debug('writing CQUAD4')
                for element in self.quads:
                    assert len(np.unique(element)) == 4, element
                    bdf_file.write('CQUAD4  %-8i%-8i%-8i%-8i%-8i%-8i\n' %
                                   (eid, pids[eid - 1], element[0], element[1],
                                    element[2], element[3]))
                    eid += 1
            else:
                ntris = self.tris.shape[0]
                nquads = self.quads.shape[0]
                eid += ntris + nquads

            if len(pids) == 0:
                max_pid = 1
            else:
                max_pid = pids.max()
            #==========================================
            # solids
            if include_solids:
                pid = max_pid + 1
                eid, pid = self._write_bdf_solids(
                    bdf_file,
                    eid,
                    pid,
                    convert_pyram_to_penta=convert_pyram_to_penta)
            bdf_file.write('ENDDATA\n')
Exemplo n.º 13
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)
Exemplo n.º 14
0
    def write_card(self, bdf_file, size=8, is_double=False, element_id=None):
        assert self.n > 0, self.n
        if self.n:
            if element_id is None:
                i = arange(self.n)
            else:
                i = searchsorted(self.element_id, element_id)

            blank = ' ' * size
            #cid = [cid if cid != 0 else '' for cid in self.coord_id]

            #Mass = [x if x != 0.0 else '' for x in self.mass[i]]
            if size == 8:
                X0 = [
                    print_float_8(x) if x != 0.0 else blank
                    for x in self.x[i, 0]
                ]
                X1 = [
                    print_float_8(x) if x != 0.0 else blank
                    for x in self.x[i, 1]
                ]
                X2 = [
                    print_float_8(x) if x != 0.0 else '' for x in self.x[i, 2]
                ]

                I0 = [
                    print_float_8(x) if x != 0.0 else blank
                    for x in self.I[i, 0]
                ]
                I1 = [
                    print_float_8(x) if x != 0.0 else blank
                    for x in self.I[i, 1]
                ]
                I2 = [
                    print_float_8(x) if x != 0.0 else blank
                    for x in self.I[i, 2]
                ]
                I3 = [
                    print_float_8(x) if x != 0.0 else blank
                    for x in self.I[i, 3]
                ]
                I4 = [
                    print_float_8(x) if x != 0.0 else blank
                    for x in self.I[i, 4]
                ]
                I5 = [
                    print_float_8(x) if x != 0.0 else blank
                    for x in self.I[i, 5]
                ]
                for (eid, nid, cid, mass, x0, x1, x2, i0, i1, i2, i3, i4,
                     i5) in zip(self.element_id[i], self.node_id[i],
                                self.coord_id[i], self.mass[i], X0, X1, X2, I0,
                                I1, I2, I3, I4, I5):
                    if eid in self._comments:
                        bdf_file.write(self._comments[eid])
                    carda = '%-8s%8i%8i%8i%8s%s%s%s\n' % (
                        'CONM2', eid, nid, cid, print_float_8(mass), x0, x1,
                        x2)
                    cardb = '%8s%8s%8s%8s%8s%8s%8s' % ('', i0, i1, i2, i3, i4,
                                                       i5)
                    cardi = (carda + cardb).rstrip() + '\n'
                    bdf_file.write(cardi)
            else:
                assert size == 16, size
                X0 = [
                    print_float_16(x) if x != 0.0 else blank
                    for x in self.x[i, 0]
                ]
                X1 = [
                    print_float_16(x) if x != 0.0 else blank
                    for x in self.x[i, 1]
                ]
                X2 = [
                    print_float_16(x) if x != 0.0 else '' for x in self.x[i, 2]
                ]

                I0 = [
                    print_float_16(x) if x != 0.0 else blank
                    for x in self.I[i, 0]
                ]
                I1 = [
                    print_float_16(x) if x != 0.0 else blank
                    for x in self.I[i, 1]
                ]
                I2 = [
                    print_float_16(x) if x != 0.0 else blank
                    for x in self.I[i, 2]
                ]
                I3 = [
                    print_float_16(x) if x != 0.0 else blank
                    for x in self.I[i, 3]
                ]
                I4 = [
                    print_float_16(x) if x != 0.0 else blank
                    for x in self.I[i, 4]
                ]
                I5 = [
                    print_float_16(x) if x != 0.0 else blank
                    for x in self.I[i, 5]
                ]
                for (eid, nid, cid, mass, x0, x1, x2, i0, i1, i2, i3, i4,
                     i5) in zip(self.element_id[i], self.node_id[i],
                                self.coord_id[i], self.mass[i], X0, X1, X2, I0,
                                I1, I2, I3, I4, I5):
                    if eid in self._comments:
                        bdf_file.write(self._comments[eid])
                    carda = '%-8s%16i%16i%16i%16s\n' % (
                        'CONM2*',
                        eid,
                        nid,
                        cid,
                        print_float_8(mass),
                    )
                    cardb = '%-8s%16s%16s%16s%16s\n' % ('*', x0, x1, x2, i0)
                    cardc = '%-8s%16s%16s%16s%16s\n' % ('*', i1, i2, i3, i4)
                    cardd = '%-8s%16s' % ('*', i5)
                    cardcd = (cardc + cardd).rstrip('* \n')
                    if cardcd:
                        cardi = carda + cardb + cardc + cardd
                    else:
                        cardi = carda + cardb
                    bdf_file.write(cardi.rstrip() + '\n')
Exemplo n.º 15
0
    def write_card_by_index(self, bdf_file, 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:
                bdf_file.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'
                    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 = (('%-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'
                        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 = (('%-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'
                        bdf_file.write(msg)
Exemplo n.º 16
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)