Commit 29ffb77d authored by John Tourtellott's avatar John Tourtellott
Browse files

Fix categories bug in export code; refactor and extend test

parent 06e46fdb
......@@ -209,8 +209,10 @@ def ExportCMB(export_op):
raise Exception(msg)
print('Writing %s' % analysis)
# Since category string == analyis string...
scope.categories = [analysis]
# Get categories
smtk_analyses = scope.sim_atts.analyses()
smtk_analysis = smtk_analyses.find(analysis)
scope.categories = list(smtk_analysis.categories())
print('Using categories: %s' % scope.categories)
# Initialize output file
......
......@@ -78,8 +78,59 @@ class Omega3PTest1(smtk.testing.TestCase):
op = self.op_manager.createOperation(op_unique_name)
return op
def set_attributes(self, att_resource, model_resource):
"""Populate simulation attributes"""
# Bounday conditions
bc_lookup = {
1: 'Electric',
2: 'Electric'
}
bc_default = 'Exterior'
uuids = model_resource.entitiesMatchingFlags(smtk.model.FACE, True)
for uuid in uuids:
# print('UUID {}'.format(uuid))
prop_list = model_resource.integerProperty(uuid, 'pedigree id')
face_id = prop_list[0]
# print('Face ID {}'.format(face_id))
bc_type = bc_lookup.get(face_id, bc_default)
bc_att = att_resource.createAttribute(bc_type)
self.assertIsNotNone(bc_att)
self.assertTrue(bc_att.associateEntity(uuid))
# Material
uuids = model_resource.entitiesMatchingFlags(smtk.model.VOLUME, True)
uuid = uuids.pop()
mat_att = att_resource.createAttribute('Material')
epsilon_item = mat_att.findDouble('Epsilon')
self.assertTrue(epsilon_item.setValue(2.2))
mu_item = mat_att.findDouble('Mu')
self.assertTrue(mu_item.setValue(0.5))
self.assertTrue(mat_att.associateEntity(uuid))
# Analysis items
finfo_att = att_resource.findAttributes('FrequencyInfo')[0]
num_item = finfo_att.findInt('NumEigenvalues')
self.assertTrue(num_item.setValue(3))
pp_att = att_resource.findAttributes('PostProcess')[0]
toggle_item = pp_att.findGroup('Toggle')
prefix_item = toggle_item.find('ModeFilePrefix')
prefix_item.setIsEnabled(True)
def check_results(self, path):
validator = ACE3PFileValidator(path)
self.assertGreater(validator.get_number_of_lines(), 12)
sections = [
'ModelInfo', 'BoundaryCondition', 'FiniteElement', 'EigenSolver', 'PostProcess',
'SurfaceMaterial', 'Material'
]
for name in sections:
msg = 'output includes {} section'.format(name)
self.assertTrue(validator.has_section(name), msg)
def test_pillbox4(self):
# Minimal test case
# Load model file
gen_filename = '{}.gen'.format(MODEL_NAME)
gen_path = os.path.join(
smtk.testing.SOURCE_DIR, 'data', 'model', '3d', 'genesis', gen_filename)
......@@ -105,26 +156,13 @@ class Omega3PTest1(smtk.testing.TestCase):
# Create attributes for instanced views
util.create_instanced_atts(att_resource)
# Populate simulation attributes
bc_lookup = {
1: 'Electric',
2: 'Electric'
}
bc_default = 'Exterior'
uuids = model_resource.entitiesMatchingFlags(smtk.model.FACE, True)
for uuid in uuids:
# print('UUID {}'.format(uuid))
prop_list = model_resource.integerProperty(uuid, 'pedigree id')
face_id = prop_list[0]
# print('Face ID {}'.format(face_id))
bc_type = bc_lookup.get(face_id, bc_default)
bc_att = att_resource.createAttribute(bc_type)
self.assertIsNotNone(bc_att)
self.assertTrue(bc_att.associateEntity(uuid))
# writer = smtk.io.AttributeWriter()
# logger = smtk.io.Logger()
# write_path = os.path.join(smtk.testing.TEMP_DIR, 'test.sbi')
# write_err = writer.write(att_resource, write_path, logger)
# print('Write attribute returned iserr?', write_err)
finfo_att = att_resource.findAttributes('FrequencyInfo')[0]
num_item = finfo_att.findInt('NumEigenvalues')
self.assertTrue(num_item.setValue(3))
self.set_attributes(att_resource, model_resource)
# Get export operator
py_path = os.path.join(
......@@ -169,15 +207,10 @@ class Omega3PTest1(smtk.testing.TestCase):
self.assertTrue(os.path.exists(expected_path))
# Validate result
validator = ACE3PFileValidator(expected_path)
self.assertTrue(validator.file_exists())
self.assertGreater(validator.get_number_of_lines(), 12)
for name in ['ModelInfo', 'BoundaryCondition', 'FiniteElement', 'EigenSolver']:
msg = 'output includes {} section'.format(name)
self.assertTrue(validator.has_section(name), msg)
self.check_results(expected_path)
# (On success) remove the export folder
shutil.rmtree(export_path)
# shutil.rmtree(export_path)
if __name__ == '__main__':
smtk.testing.process_arguments()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment