Beispiel #1
0
 def _read_eigb(self, data, n):
     """EIGB(107,1,86) - Record 7"""
     ntotal = 60
     nentries = (len(data) - n) // ntotal
     self._increase_card_count('EIGB', nentries)
     for i in range(nentries):
         edata = data[n:n + ntotal]
         #self.show_data(edata[44:])
         # int, 8s, 2f, 3i, i, 8s, 4i
         out = unpack('i8s ff 3i i 8s 4i', edata)
         sid, method, L1, L2, nep, ndp, ndn, dunno, norm, g, c, dunno_a, dunno_b = out
         if self.is_debug_file:
             self.binary_debug.write('EIGB=%s\n' % str(out))
         #print('out = %s' % str(out))
         method = method.strip().decode('latin1')
         norm = norm.strip().decode('latin1')
         eigb = EIGB(sid, method, L1, L2, nep, ndp, ndn, norm, g, c)
         self._add_method_object(eigb)
         n += ntotal
     return n
Beispiel #2
0
    def _read_eigc(self, data, n):
        """
        EIGC(207,2,87) - Record 8

        Word Name    Type Description
        1 SID           I Load set identification number
        2 METHOD(2) CHAR4 Method of eigenvalue extraction
        4 NORM(2)   CHAR4 Method for normalizing eigenvectors
        6 G             I Grid or scalar point identification number
        7 C             I Component number
        8 E            RS Convergence criterion
        9 ND1           I Number of desired eigenvectors
        10 CONTFLG      I Continuation flag
        CONTFLG=0 With continuation
        11 AAJ         RS Location of A on real axis
        12 WAJ         RS Location of A on imaginary axis
        13 ABJ         RS Location of B on real axis
        14 WBJ         RS Location of B on imaginary axis
        15 LJ          RS Width of search region
        16 NEJ          I Number of estimated roots
        17 NDJ          I Number of desired eigenvectors
        Words 11 through 17 repeat until (-1,-1,-1,-1,-1,-1,-1) occ
        CONTFLG =-1 Without continuation
        End CONTFLG
        """
        if 0:
            ntotal = 60
            nentries = (len(data) - n) // ntotal
            self.increase_card_count('EIGB', nentries)
            struct1 = Struct(self._endian + b'i 4s 4s 2i f 2i')
            #struct2 = Struct(self._endian + b'5f2i')
            for i in range(nentries):
                edata = data[n:n + ntotal]
                #self.show_data(edata[44:])
                # int, 8s, 2f, 3i, i, 8s, 4i
                out = struct1.unpack(edata)
                sid, method, L1, L2, nep, ndp, ndn, dunno, norm, g, c, dunno_a, dunno_b = out
                if self.is_debug_file:
                    self.binary_debug.write('EIGC=%s\n' % str(out))
                #print('out = %s' % str(out))
                method = method.strip().decode('latin1')
                norm = norm.strip().decode('latin1')
                eigb = EIGB(sid, method, L1, L2, nep, ndp, ndn, norm, g, c)
                self._add_method_object(eigb)
                n += ntotal
            #return n

        #-------------------------------------------------
        ndata = len(data)
        nfields = (ndata - n) // 4
        datan = data[n:]
        ints = unpack(b(self._uendian + '%ii' % nfields), datan)
        floats = unpack(b(self._uendian + '%if' % nfields), datan)
        strings = unpack(b(self._uendian + '4s' * nfields), datan)
        #print('ints = ', ints)
        #print('floats = ', floats)
        #print('strings = ', strings)

        i = 0
        nentries = 0
        while i < nfields:
            sid = ints[i + 0]
            method = (strings[i + 1] + strings[i + 2]).strip().decode('latin1')
            norm = (strings[i + 3] + strings[i + 4]).strip().decode('latin1')
            grid = ints[i + 5]
            component = ints[i + 6]
            epsilon = floats[i + 7]
            neigenvalues = ints[i + 8]
            control_flag = ints[i + 9]

            #print('sid=%s method=%r norm=%r grid=%s component=%s epsilon=%s, '
            #      'neigenvalues=%s ctlflag=%s' % (
            #          sid, method, norm, grid, component, epsilon, neigenvalues, control_flag))

            alphaAjs = []
            omegaAjs = []
            alphaBjs = []
            omegaBjs = []
            LJs = []
            NEJs = []
            NDJs = []

            # dummy
            mblkszs = []
            iblkszs = []
            ksteps = []
            NJIs = []
            if control_flag == -1:
                datai = [
                    sid, method, norm, grid, component, epsilon, neigenvalues,
                    -1
                ]
            elif control_flag == 0:
                intsi = ints[i + 10:i + 17]
                assert len(intsi) == 7, 'len=%s intsi=%s' % (len(intsi), intsi)
                datai = [
                    sid, method, norm, grid, component, epsilon, neigenvalues,
                    0
                ]
                while intsi != (-1, -1, -1, -1, -1, -1, -1):
                    aaj, waj, abj, wbj, lj = floats[i + 10:i + 15]
                    #print('aaj=%s waj=%s abj=%s wbj=%s lj=%s'  % (
                    #aaj, waj, abj, wbj, lj))
                    nej, ndj = ints[i + 15:i + 17]
                    datai.extend([(aaj, waj, abj, wbj, lj, nej)])

                    alphaAjs.append(aaj)
                    omegaAjs.append(waj)
                    alphaBjs.append(abj)
                    omegaBjs.append(wbj)
                    if norm == 'MAX':
                        # faked
                        mblkszs.append(0.)
                        iblkszs.append(0)
                        ksteps.append(0)
                        NJIs.append(0)

                    LJs.append(lj)
                    NEJs.append(nej)
                    NDJs.append(ndj)
                    #print('aaj=%s waj=%s abj=%s wbj=%s lj=%s nej=%s ndj=%s'  % (
                    #aaj, waj, abj, wbj, lj, nej, ndj
                    #))
                    i += 7
                    intsi = ints[i + 10:i + 17]
                    #print('intsi = ', intsi)
                    assert len(intsi) == 7, 'len=%s intsi=%s' % (len(intsi),
                                                                 intsi)
                    #print("intsi = ", intsi)
                    #print()
                    #11 AAJ RS Location of A on real axis
                    #12 WAJ RS Location of A on imaginary axis
                    #13 ABJ RS Location of B on real axis
                    #14 WBJ RS Location of B on imaginary axis
                    #15 LJ RS Width of search region
                    #16 NEJ I Number of estimated roots
                    #17 NDJ I Number of desired eigenvectors
                assert len(intsi) == 7, intsi
                #print('intsi = ', intsi)
                #raise NotImplementedError('EIGC control_flag=%s' % control_flag)
            else:
                raise NotImplementedError('EIGC control_flag=%s' %
                                          control_flag)
            datai.extend([-1, -1, -1, -1, -1, -1, -1])  # creates a +7

            if self.is_debug_file:
                self.binary_debug.write('  EIGC=%s\n' % str(datai))

            if grid == 0:
                grid = None
                assert component == 0, component
                component = None

            eigc = self.add_eigc(sid,
                                 method,
                                 grid,
                                 component,
                                 epsilon,
                                 neigenvalues,
                                 norm=norm,
                                 mblkszs=mblkszs,
                                 iblkszs=iblkszs,
                                 ksteps=ksteps,
                                 NJIs=NJIs,
                                 alphaAjs=alphaAjs,
                                 omegaAjs=omegaAjs,
                                 alphaBjs=alphaBjs,
                                 omegaBjs=omegaBjs,
                                 LJs=LJs,
                                 NEJs=NEJs,
                                 NDJs=NDJs,
                                 shift_r1=None,
                                 shift_i1=None,
                                 isrr_flag=None,
                                 nd1=None,
                                 comment='')
            eigc.validate()

            #while intsi != (-1, -1, -1):
            #gridi, compi, coeffi = ints[i+4], ints[i+5], floats[i+6]
            #mpc_data.extend([gridi, compi, coeffi])
            #nodes.append(gridi)
            #components.append(compi)
            #coefficients.append(coeffi)
            #i += 3

            # +10 is for the prefix; +7 is for the -1s
            i += 10 + 7  # 3 + 4 from (-1,-1,-1) and (sid,grid,comp,coeff)
            nentries += 1
            #print('--------------')
        self.increase_card_count('EIGC', nentries)
        return len(data)