Commit 0899a08f authored by John Tourtellott's avatar John Tourtellott

Update model association logic to CMB6 policy

* Main change is that CMB6 replaced ModelEntityItem with ReferenceItem
* This commit fixes errors writing material attributes
parent 229ad016
......@@ -30,7 +30,7 @@ sys.path.insert(0, os.path.dirname(os.path.abspath(inspect.getfile(inspect.curre
import internal
from internal import writer
# reload(writer) # for development
reload(writer) # for development
class Export(smtk.operation.Operation):
......
......@@ -52,7 +52,7 @@ class Writer:
raise Exception(msg)
model_entity = smtk.model.Entity.CastTo(operator_spec.find('model').objectValue(0))
self.model_resource = model_entity.resource()
self.model_resource = smtk.model.Resource.CastTo(model_entity.resource())
if self.model_resource is None:
msg = 'ERROR - No model'
......@@ -299,8 +299,8 @@ class Writer:
att_list.sort(key=lambda att: att.name())
for att in att_list:
#print('Writing att ', att.name())
model_ent_item = att.associations()
if model_ent_item is None or (0 == model_ent_item.numberOfValues()):
reference_item = att.associations()
if reference_item is None or (0 == reference_item.numberOfValues()):
print('Skipping attribute type \"%s\", name \"%s\" -- no associations' % \
(att.type(), att.name()))
continue
......@@ -321,7 +321,7 @@ class Writer:
else:
CardFormat.write_value(self.out, 'data_constant', item.value())
face_set_string = CardFormat.get_model_entity_ids(model_ent_item, as_string=True)
face_set_string = CardFormat.get_model_entity_ids(reference_item, as_string=True)
CardFormat.write_value(
self.out, 'face_set_ids', face_set_string, quote_string=False)
......@@ -389,8 +389,8 @@ class Writer:
att_list = self.sim_atts.findAttributes(namelist.att_type)
att_list.sort(key=lambda att: att.name())
for att in att_list:
model_ent_item = att.associations()
if model_ent_item is None or (0 == model_ent_item.numberOfValues()):
reference_item = att.associations()
if reference_item is None or (0 == reference_item.numberOfValues()):
print('Skipping attribute type \"%s\", name \"%s\" -- no associations' % \
(att.type(), att.name()))
continue
......@@ -450,24 +450,27 @@ class Writer:
'''
print('Writing', namelist.title, 'namelists')
# Get 'material' definition, for use below
material_defn = self.sim_atts.findDefinition('material')
att_list = self.sim_atts.findAttributes(namelist.att_type)
att_list.sort(key=lambda att: att.name())
for att in att_list:
model_ent_item = att.associations()
if model_ent_item is None or (0 == model_ent_item.numberOfValues()):
reference_item = att.associations()
if reference_item is None or (0 == reference_item.numberOfValues()):
print('Skipping attribute type \"%s\", name \"%s\" -- no associations' % \
(att.type(), att.name()))
continue
# Write separate BODY namelist for each model item
for i in range(model_ent_item.numberOfValues()):
model_ent_ref = model_ent_item.value(i)
for i in range(reference_item.numberOfValues()):
model_ent = reference_item.objectValue(i)
self.out.write('\n&%s\n' % namelist.title)
for card in format_list:
if 'material_number' == card.keyword:
# In _setup(), info was attached to each model entity
model_ent = model_ent_ref.entity()
idlist = self.model_resource.integerProperty(
model_ent, 'material number')
if not idlist:
......@@ -480,18 +483,15 @@ class Writer:
# per email discussions 23-Jun-2016.
# And for two-phase materials, the fluid number is +1 more
# than the property set on the model entity.
att_uuid_list = model_ent_ref.attributes()
#print('att_uuid_list', att_uuid_list, len(att_uuid_list))
for att_uuid in att_uuid_list:
sibling_att = self.sim_atts.findAttribute(att_uuid)
#print(' sibling type', sibling_att.type())
if sibling_att.type() == 'material':
mat_type_item = sibling_att.findString('material-type')
mat_type = mat_type_item.value(0)
#print('material type:', mat_type)
if 'two-phase' == mat_type:
material_number += 1
break
material_att_list = model_ent.attributes(material_defn)
if material_att_list:
material_att = material_att_list[0]
mat_type_item = material_att.findString('material-type')
mat_type = mat_type_item.value(0)
#print('material type:', mat_type)
if 'two-phase' == mat_type:
material_number += 1
break
CardFormat.write_value(self.out, card.keyword, material_number)
else:
......@@ -854,12 +854,11 @@ class Writer:
self.material_number_dict[persistent_id] = material_count
# Attach material number to each associated model entity (if any)
model_ent_item = att.associations()
for i in range(model_ent_item.numberOfValues()):
ent_ref = model_ent_item.value(i)
ent = ent_ref.entity()
reference_item = att.associations()
for i in range(reference_item.numberOfValues()):
entity = reference_item.objectValue(i)
self.model_resource.setIntegerProperty(
ent, 'material number', material_count)
entity.id(), 'material number', material_count)
# If material is two-phase, reserve TWO numbers, 1 for each phase
material_type_item = att.findString('material-type')
......@@ -877,15 +876,15 @@ class Writer:
self.moving_enclosure_surface_set_ids = list()
att_list = self.sim_atts.findAttributes('thermal-surface-condition')
for att in att_list:
model_ent_item = att.associations()
if model_ent_item is None:
reference_item = att.associations()
if reference_item is None:
continue
type_item = att.findString('type')
if type_item.value(0) == 'ds-interface-condition':
self.interface_set_ids += CardFormat.get_model_entity_ids(model_ent_item)
self.interface_set_ids += CardFormat.get_model_entity_ids(reference_item)
elif type_item.value(0) == 'enclosure-surface':
surface_ids = CardFormat.get_model_entity_ids(model_ent_item)
surface_ids = CardFormat.get_model_entity_ids(reference_item)
self.enclosure_surface_set_ids += surface_ids
moving_item = att.itemAtPath('type/moving', '/')
if moving_item and moving_item.isEnabled():
......
Markdown is supported
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