當前位置: 首頁>>代碼示例>>Python>>正文


Python FileParser.reset_anchor方法代碼示例

本文整理匯總了Python中openmdao.util.filewrap.FileParser.reset_anchor方法的典型用法代碼示例。如果您正苦於以下問題:Python FileParser.reset_anchor方法的具體用法?Python FileParser.reset_anchor怎麽用?Python FileParser.reset_anchor使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在openmdao.util.filewrap.FileParser的用法示例。


在下文中一共展示了FileParser.reset_anchor方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: execute

# 需要導入模塊: from openmdao.util.filewrap import FileParser [as 別名]
# 或者: from openmdao.util.filewrap.FileParser import reset_anchor [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: test_output_parse

# 需要導入模塊: from openmdao.util.filewrap import FileParser [as 別名]
# 或者: from openmdao.util.filewrap.FileParser import reset_anchor [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

示例3: test_output_parse_array

# 需要導入模塊: from openmdao.util.filewrap import FileParser [as 別名]
# 或者: from openmdao.util.filewrap.FileParser import reset_anchor [as 別名]
    def test_output_parse_array(self):

        data = "Anchor\n" + \
               "10 20 30 40 50 60 70 80\n" + \
               "11 21 31 41 51 61 71 81\n" + \
               "Key a b c d e\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_array(1, 1, 1, 8)
        self.assertEqual(val[0], 10)
        self.assertEqual(val[7], 80)
        val = gen.transfer_array(1, 5, 2, 6)
        self.assertEqual(val[0], 50)
        self.assertEqual(val[9], 61)
        gen.mark_anchor('Key')
        val = gen.transfer_array(0, 2, 0, 6)
        self.assertEqual(val[4], 'e')
        val = gen.transfer_array(0, 2, fieldend=6)
        self.assertEqual(val[4], 'e')

        # Now, let's try column delimiters
        gen.reset_anchor()
        gen.mark_anchor('Anchor')
        gen.set_delimiters('columns')
        val = gen.transfer_array(1, 7, 1, 15)
        self.assertEqual(val[0], 30)
        self.assertEqual(val[2], 50)
        val = gen.transfer_array(1, 10, 2, 18)
        self.assertEqual(val[0], 40)
        self.assertEqual(val[5], 61)
        val = gen.transfer_array(3, 5, 3, 10)
        self.assertEqual(val[0], 'a b c')

        try:
            gen.transfer_array(1, 7, 1)
        except ValueError, err:
            msg = "fieldend is missing, currently required"
            self.assertEqual(str(err), msg)
開發者ID:ChanChiChoi,項目名稱:OpenMDAO-Framework,代碼行數:48,代碼來源:test_filewrap.py

示例4: test_output_parse_same_anchors

# 需要導入模塊: from openmdao.util.filewrap import FileParser [as 別名]
# 或者: from openmdao.util.filewrap.FileParser import reset_anchor [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


注:本文中的openmdao.util.filewrap.FileParser.reset_anchor方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。