当前位置: 首页>>代码示例>>Python>>正文


Python FileParser.transfer_var方法代码示例

本文整理汇总了Python中openmdao.util.filewrap.FileParser.transfer_var方法的典型用法代码示例。如果您正苦于以下问题:Python FileParser.transfer_var方法的具体用法?Python FileParser.transfer_var怎么用?Python FileParser.transfer_var使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在openmdao.util.filewrap.FileParser的用法示例。


在下文中一共展示了FileParser.transfer_var方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: execute

# 需要导入模块: from openmdao.util.filewrap import FileParser [as 别名]
# 或者: from openmdao.util.filewrap.FileParser import transfer_var [as 别名]
    def execute(self):

        super(Comp_Plate, self).execute()

        parser = FileParser()
        parser.set_file(self.nastran_filename)

        self.comp_elm_dict = {}
        parser.reset_anchor()
        for cquad4 in range(1,26):
            parser.mark_anchor("CQUAD4")
            elmtype = parser.transfer_var(0, 1)
            elmid = parser.transfer_var(0, 2)
            pid = parser.transfer_var(0, 3)

            if pid not in self.comp_elm_dict:
                self.comp_elm_dict[ pid ] = []

            self.comp_elm_dict[pid].append( elmid )

        max_minor_strain_by_pid, max_major_strain_by_pid = self.calculate_max_strains()

        self.property1_max_major_strain = max_major_strain_by_pid[ 801 ]
        self.property2_max_major_strain = max_major_strain_by_pid[ 802 ]
        self.property3_max_major_strain = max_major_strain_by_pid[ 803 ]

        self.property1_max_minor_strain = max_minor_strain_by_pid[ 801 ]
        self.property2_max_minor_strain = max_minor_strain_by_pid[ 802 ]
        self.property3_max_minor_strain = max_minor_strain_by_pid[ 803 ]

        # Calculate the maximum strain (max(major,minor)) for each property 
        self.property1_max_major_minor_strain = max( self.property1_max_major_strain, self.property1_max_minor_strain )
        self.property2_max_major_minor_strain = max( self.property2_max_major_strain, self.property2_max_minor_strain )
        self.property3_max_major_minor_strain = max( self.property3_max_major_strain, self.property3_max_minor_strain )
开发者ID:OpenMDAO-Plugins,项目名称:nastranwrapper,代码行数:36,代码来源:comp_plate_static_nastran.py

示例2: load_model

# 需要导入模块: from openmdao.util.filewrap import FileParser [as 别名]
# 或者: from openmdao.util.filewrap.FileParser import transfer_var [as 别名]
    def load_model(self, filename):
        """Reads in an existing PDCYL input file and populates the variable
        tree with its values."""
        
        infile = FileParser()
        infile.set_file(filename)
        
        # Title is a string
        self.title = infile.transfer_line(2)

        # Print flag becomes a Bool
        if infile.transfer_var(4, 1) == 3:
            self.icalc = True
        else:
            self.icalc = False
        
        # Named variables in dictionary
        for key, val in self._fields.iteritems():
            self.set(val, infile.transfer_var(key, 1))
开发者ID:JustinSGray,项目名称:OpenMDAO-Framework,代码行数:21,代码来源:pdcyl_comp.py

示例3: test_output_parse

# 需要导入模块: from openmdao.util.filewrap import FileParser [as 别名]
# 或者: from openmdao.util.filewrap.FileParser import transfer_var [as 别名]
    def test_output_parse(self):

        data = "Junk\n" + \
                   "Anchor\n" + \
                   " A 1, 2 34, Test 1e65\n" + \
                   " B 4 Stuff\n" + \
                   "Anchor\n" + \
                   " C 77 False NaN 333.444\n" + \
                   " 1,2,3,4,5\n" + \
                   " Inf 1.#QNAN -1.#IND\n"

        outfile = open(self.filename, 'w')
        outfile.write(data)
        outfile.close()

        gen = FileParser()
        gen.set_file(self.filename)
        gen.set_delimiters(' ')

        gen.mark_anchor('Anchor')
        val = gen.transfer_var(1, 1)
        self.assertEqual(val, 'A')
        gen.reset_anchor()
        val = gen.transfer_var(3, 2)
        self.assertEqual(val, 4)
        self.assertEqual(type(val), int)
        gen.mark_anchor('Anchor',2)
        val = gen.transfer_var(1, 4)
        self.assertEqual(isnan(val), True)
        val = gen.transfer_var(3, 1)
        self.assertEqual(isinf(val), True)
        val = gen.transfer_var(3, 2)
        self.assertEqual(isnan(val), True)
        val = gen.transfer_var(3, 3)
        self.assertEqual(isnan(val), True)
        val = gen.transfer_line(-1)
        self.assertEqual(val, ' B 4 Stuff')

        # Now, let's try column delimiters
        gen.set_delimiters('columns')
        gen.mark_anchor('Anchor',-1)
        val = gen.transfer_var(1, 8, 10)
        self.assertEqual(val, 'als')
        val = gen.transfer_var(1, 17)
        self.assertEqual(val, 333.444)

        # Test some errors
        try:
            gen.mark_anchor('C 77', 3.14)
        except ValueError, err:
            msg = "The value for occurrence must be an integer"
            self.assertEqual(str(err), msg)
开发者ID:ChanChiChoi,项目名称:OpenMDAO-Framework,代码行数:54,代码来源:test_filewrap.py

示例4: test_comment_char

# 需要导入模块: from openmdao.util.filewrap import FileParser [as 别名]
# 或者: from openmdao.util.filewrap.FileParser import transfer_var [as 别名]
    def test_comment_char(self):

        # Check to see if the use of the comment
        #   characters works
        data = "Junk\n" + \
                   "CAnchor\n" + \
                   " Z 11, 22 344, Test 1e65\n" + \
                   " B 4 Stuff\n" + \
                   "  $ Anchor\n" + \
                   " Q 1, 2 34, Test 1e65\n" + \
                   " B 4 Stuff\n" + \
                   "Anchor\n" + \
                   " A 1, 2 34, Test 1e65\n" + \
                   " B 4 Stuff\n" + \
                   "Anchor\n" + \
                   " C 77 False NaN 333.444\n" + \
                   " 1,2,3,4,5\n" + \
                   " Inf 1.#QNAN -1.#IND\n"

        outfile = open(self.filename, 'w')
        outfile.write(data)
        outfile.close()

        # Test full line comments
        gen = FileParser(full_line_comment_char="C")
        gen.set_file(self.filename)
        gen.set_delimiters(' ')
        gen.mark_anchor('Anchor')
        val = gen.transfer_var(1, 1)
        self.assertEqual(val, 'A')

        # Test end of line comments also
        gen = FileParser(full_line_comment_char="C", end_of_line_comment_char="$")
        gen.set_file(self.filename)
        gen.set_delimiters(' ')
        gen.mark_anchor('Anchor')
        val = gen.transfer_var(1, 1)
        self.assertEqual(val, 'A')
开发者ID:ChanChiChoi,项目名称:OpenMDAO-Framework,代码行数:40,代码来源:test_filewrap.py

示例5: test_output_parse_same_anchors

# 需要导入模块: from openmdao.util.filewrap import FileParser [as 别名]
# 或者: from openmdao.util.filewrap.FileParser import transfer_var [as 别名]
    def test_output_parse_same_anchors(self):

        data = "CQUAD4 1 3.456\n" + \
               "CQUAD4 2 4.123\n" + \
               "CQUAD4 3 7.222\n" + \
               "CQUAD4 4\n"

        outfile = open(self.filename, 'w')
        outfile.write(data)
        outfile.close()

        gen = FileParser()
        gen.set_file(self.filename)
        gen.set_delimiters(' ')

        gen.mark_anchor('CQUAD4')
        val = gen.transfer_var(0, 3)
        self.assertEqual(val, 3.456)

        gen.mark_anchor('CQUAD4')
        val = gen.transfer_var(0, 3)
        self.assertEqual(val, 4.123)

        gen.mark_anchor('CQUAD4', 2)
        val = gen.transfer_var(0, 2)
        self.assertEqual(val, 4)

        gen.reset_anchor()

        gen.mark_anchor('CQUAD4', -1)
        val = gen.transfer_var(0, 2)
        self.assertEqual(val, 4)

        gen.mark_anchor('CQUAD4', -1)
        val = gen.transfer_var(0, 3)
        self.assertEqual(val, 7.222)

        gen.mark_anchor('CQUAD4', -2)
        val = gen.transfer_var(0, 3)
        self.assertEqual(val, 4.123)
开发者ID:ChanChiChoi,项目名称:OpenMDAO-Framework,代码行数:42,代码来源:test_filewrap.py

示例6: parse_output

# 需要导入模块: from openmdao.util.filewrap import FileParser [as 别名]
# 或者: from openmdao.util.filewrap.FileParser import transfer_var [as 别名]
    def parse_output(self):
        """Parses the HSRNOISE output file and extracts data."""
        
        outfile = FileParser()
        outfile.set_file('test.output')
        
        outfile.mark_anchor("JN8C4 JET NOISE MODULE")
        outfile.mark_anchor("TOTAL")
        self.thetas = outfile.transfer_array(4,2,4,18)
        self.Freq = outfile.transfer_2Darray(7,1,30,1)        
        self.SPL = outfile.transfer_2Darray(7,2,30,18)
        outfile.mark_anchor("DBA")
        self.OASPL = outfile.transfer_array(-1, 2, -1, 18)
        self.OASPL30 = outfile.transfer_var(-1, 4)
        self.OASPL60 = outfile.transfer_var(-1, 7)
        self.OASPL90 = outfile.transfer_var(-1, 10)
        self.OASPL120 = outfile.transfer_var(-1, 13)
        self.OASPL150 = outfile.transfer_var(-1, 16)

        outfile.mark_anchor("EPNL SUMMARY")
        self.TotalEPNL = outfile.transfer_var(9, 2)
        self.TotalMaxPNLT = outfile.transfer_var(9, 5)
        self.JetEPNL = outfile.transfer_var(8, 2)
开发者ID:ChanChiChoi,项目名称:OpenMDAO-Framework,代码行数:25,代码来源:hsrnoise.py

示例7: test_more_delims

# 需要导入模块: from openmdao.util.filewrap import FileParser [as 别名]
# 或者: from openmdao.util.filewrap.FileParser import transfer_var [as 别名]
    def test_more_delims(self):

        data = "anchor,1.0,2.0\n" + \
               "abc=123.456\n" + \
               "c=1,2,Word,6\n" + \
               "d=C:/abc/def,a+b*c^2,(%#%),!true\n" + \
               "a^33 1.#QNAN^#$%^"

        outfile = open(self.filename, 'w')
        outfile.write(data)
        outfile.close()

        op = FileParser()
        op.set_file(self.filename)

        olddelims = op.delimiter
        op.set_delimiters(' \t,=')

        op.mark_anchor('anchor')

        val = op.transfer_var(0, 1)
        self.assertEqual(val, 'anchor')
        val = op.transfer_var(0, 2)
        self.assertEqual(val, 1.0)
        val = op.transfer_var(1, 1)
        self.assertEqual(val, 'abc')
        val = op.transfer_var(1, 2)
        self.assertEqual(val, 123.456)
        val = op.transfer_var(2, 4)
        self.assertEqual(val, 'Word')
        val = op.transfer_var(2, 5)
        self.assertEqual(val, 6)
        val = op.transfer_var(3, 2)
        self.assertEqual(val, 'C:/abc/def')
        val = op.transfer_var(3, 3)
        self.assertEqual(val, 'a+b*c^2')
        val = op.transfer_var(3, 4)
        self.assertEqual(val, '(%#%)')
        val = op.transfer_var(3, 5)
        self.assertEqual(val, '!true')

        op.set_delimiters(' \t^')
        val = op.transfer_var(4, 1)
        self.assertEqual(val, 'a')
        val = op.transfer_var(4, 2)
        self.assertEqual(val, 33)
        val = op.transfer_var(4, 3)
        self.assertEqual(isnan(val), True)
        val = op.transfer_var(4, 4)
        self.assertEqual(val, '#$%')
开发者ID:ChanChiChoi,项目名称:OpenMDAO-Framework,代码行数:52,代码来源:test_filewrap.py

示例8: load_model

# 需要导入模块: from openmdao.util.filewrap import FileParser [as 别名]
# 或者: from openmdao.util.filewrap.FileParser import transfer_var [as 别名]
    def load_model(self, control_input='control.in',
                         flocond_input='flocond.in',
                         expnd_input='expnd.in',
                         zrdmix_input='zrdmix.in',
                         hwall_input='hwall.in'):
        '''Reads in an existing set of input files and populates the model.'''
        
        ignore = ['ist', 'ifab']
        ct = Namelist(self)
        ct.set_filename(control_input)
        ct.parse_file()
        ct.load_model(ignore=ignore)

        ignore = ['p01d', 'p02d', 't01d', 't02d', 'rm1', 'rm2', 'gam', 'pinf',
                  'a1d', 'a2d', 'a3d']
        fc = Namelist(self)
        fc.set_filename(flocond_input)
        fc.parse_file()
        fc.load_model(ignore=ignore)
        self.flow_in.pri.Pt = fc.find_card('floc', 'p01d')
        self.flow_in.sec.Pt = fc.find_card('floc', 'p02d')
        self.flow_in.pri.Tt = fc.find_card('floc', 't01d')
        self.flow_in.sec.Tt = fc.find_card('floc', 't02d')
        self.flow_in.pri.Mach = fc.find_card('floc', 'rm1')
        self.flow_in.sec.Mach = fc.find_card('floc', 'rm2')
        self.flow_in.gamma = fc.find_card('floc', 'gam')
        self.flow_in.Pstatic = fc.find_card('floc', 'pinf')
        a1d = fc.find_card('floc', 'a1d')
        a2d = fc.find_card('floc', 'a2d')
        a3d = fc.find_card('floc', 'a3d')
        
        ep = Namelist(self)
        ep.set_filename(expnd_input)
        ep.parse_file()
        ep.load_model()
        
        ignore = ['RLD', 'H0LM', 'H0HY', 'ALP1', 'ALP2', 'BWID']
        zr = Namelist(self)
        zr.set_filename(zrdmix_input)
        zr.parse_file()
        zr.load_model(ignore=ignore)
        self.geo_in.length = zr.find_card('zrd', 'RLD')
        self.geo_in.LhWave = zr.find_card('zrd', 'H0LM')
        self.geo_in.LhMh = zr.find_card('zrd', 'H0HY')
        self.geo_in.ChuteAngles = zr.find_card('zrd', 'ALP1')
        #self.geo_in.ChuteAngles = zr.find_card('zrd', 'ALP2')
        BWID = zr.find_card('zrd', 'BWID')

        parser = FileParser()
        parser.set_file(hwall_input)
        parser.set_delimiters(", ")
        nrow = parser.transfer_var(0, 1)
        geom = zeros((nrow, 2), 'd')
        for index in range(nrow):
            geom[index, :] = parser.transfer_array(1+index, 1, 1+index, 2)
            
        self.geom = geom
        
        # Reverse area calculations for AsAp, AeAt and AR
        # Note that DREA only uses half the area as it assumes a plane of symmetry
        self.geo_in.Apri = 2.0*a1d
        self.geo_in.AsAp = 2.0*a2d/self.geo_in.Apri
        self.geo_in.Asec = self.geo_in.AsAp*self.geo_in.Apri
        self.geo_in.AeAt = 2.0*a3d/(self.geo_in.Apri+self.geo_in.Asec)
        self.geo_in.AR = BWID*BWID/(self.geo_in.Apri+self.geo_in.Asec)
        
        #self.geo_in.length = self.geom[-1, 0]
        self.geo_in.width = 0.5*(self.geo_in.Apri + self.geo_in.Asec)/self.geom[0,1]
        self.geo_in.Aexit = 2.0*self.geom[-1,1]*self.geo_in.width  
开发者ID:OpenMDAO-Plugins,项目名称:drea_wrapper,代码行数:71,代码来源:DREA.py


注:本文中的openmdao.util.filewrap.FileParser.transfer_var方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。