本文整理汇总了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 )
示例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)
示例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)
示例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)