Commit c8b696ea authored by John Tourtellott's avatar John Tourtellott

Update writer to use categories from the enabled analyses

parent acf4902a
......@@ -215,7 +215,7 @@ format_table = {
'ENCLOSURE_SURFACE': [
card('name', use_name_for_value=True),
card('enclosure_name', att_type='enclosure-radiation',
item_path='enable/enclosure/enclosure-name'),
item_path='enclosure/enclosure-name'),
card('face_block_ids', use_model_entities_for_value=True),
card('emissivity', item_path='emissivity')
],
......@@ -335,12 +335,12 @@ namelist_sequence = [
namelist('MESH', att_type='mesh', custom_method='_write_mesh'),
namelist('OUTPUTS', att_type='outputs', custom_method='_write_outputs'),
namelist('ENCLOSURE', att_type='enclosure-radiation',
base_item_path='enable/enclosure',
base_item_path='enclosure',
if_condition=ENCLOSURE_RADIATION,
custom_method='_write_enclosure'),
namelist('ENCLOSURE_RADIATION',
att_type='enclosure-radiation',
base_item_path='enable/enclosure',
base_item_path='enclosure',
if_condition=ENCLOSURE_RADIATION,
custom_method='_write_enclosure_radiation'),
namelist('ENCLOSURE_SURFACE',
......@@ -360,7 +360,7 @@ namelist_sequence = [
att_type='ht/solver',
base_item_path='analysis/thermal-plus-fluid/thermal-solver'),
namelist('CHAPARRAL', att_type='enclosure-radiation',
base_item_path='enable/chaparral',
base_item_path='chaparral',
if_condition=ENCLOSURE_RADIATION),
namelist('NUMERICS', att_type='numerics'),
namelist('LINEAR_SOLVER',
......
......@@ -59,6 +59,8 @@ class Writer:
print(msg)
raise Exception(msg)
self.analyses = list()
self.categories = list()
self.background_material_id = 0
self.format_table = dict()
self.interface_set_ids = list()
......@@ -81,9 +83,14 @@ class Writer:
completed = False
with open(path, 'w') as out:
out.write('* Truchas input file\n')
dt_string = datetime.datetime.now().strftime('%d-%b-%Y %H:%M')
out.write('* Generated by CMB {}\n'.format(dt_string))
analysis_string = ', '.join(self.analyses)
out.write('* Analysis Modules: {}\n'.format(analysis_string))
self.out = out
for namelist in self.namelist_sequence:
......@@ -131,7 +138,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:
self._write_default_att(att, namelist, format_list)
if att.isMemberOf(self.categories):
self._write_default_att(att, namelist, format_list)
return
# Otherwise process each card in format_list
......@@ -140,7 +148,8 @@ class Writer:
for card in format_list:
att_list = self.sim_atts.findAttributes(card.att_type)
for att in att_list:
card.write(self.out, att, base_item_path=namelist.base_item_path)
if att.isMemberOf(self.categories):
card.write(self.out, att, base_item_path=namelist.base_item_path)
self.out.write('/\n')
# ---------------------------------------------------------------------
......@@ -190,6 +199,8 @@ class Writer:
def _write_enclosure(self, namelist, format_list):
'''
'''
if not 'Enclosure Radiation' in self.categories:
return
print('Writing', namelist.title)
self.out.write('\n&%s\n' % namelist.title)
......@@ -260,6 +271,8 @@ class Writer:
def _write_enclosure_radiation(self, namelist, format_list):
'''
'''
if not 'Enclosure Radiation' in self.categories:
return
print('Writing', namelist.title)
self.out.write('\n&%s\n' % namelist.title)
......@@ -293,6 +306,8 @@ class Writer:
def _write_thermal_condition(self, namelist, format_list):
'''Common writer for ds_boundary_condition, ds_interface_condition, enclosure-surface
'''
if not 'Heat Transfer' in self.categories:
return
print('Writing %s namelists' % (namelist.title))
att_list = self.sim_atts.findAttributes(namelist.att_type)
......@@ -389,6 +404,9 @@ class Writer:
att_list = self.sim_atts.findAttributes(namelist.att_type)
att_list.sort(key=lambda att: att.name())
for att in att_list:
if not att.isMemberOf(self.categories):
continue
reference_item = att.associations()
if reference_item is None or (0 == reference_item.numberOfValues()):
print('Skipping attribute type \"%s\", name \"%s\" -- no associations' % \
......@@ -473,6 +491,9 @@ class Writer:
# Traverse material attributes
att_list.sort(key=lambda att: att.name())
for att in att_list:
if not att.isMemberOf(self.categories):
continue
reference_item = att.associations()
if reference_item is None or (0 == reference_item.numberOfValues()):
print('Skipping attribute type \"%s\", name \"%s\" -- no associations' % \
......@@ -772,32 +793,58 @@ class Writer:
if not analysis_att:
raise RuntimeError('Internal Error -- missing analysis att')
# Get categories based on enabled analyses
ER = 'Enclosure Radiation'
FF = 'Fluid Flow'
HT = 'Heat Transfer'
IH = 'Induction Heating'
SM = 'Solid Mechanics'
self.analyses = list()
self.categories = list()
# Only looking at Heat Transfer and Fluid Flow initially
er_item = None # enclosure radition
ff_item = analysis_att.findVoid('Fluid Flow')
ht_item = analysis_att.findGroup('Heat Transfer')
ff_item = analysis_att.findVoid(FF)
ht_item = analysis_att.findGroup(HT)
ih_item = None # induction heating
sm_item = analysis_att.findVoid('Solid Mechanics')
sm_item = analysis_att.findVoid(SM)
category_set = set()
if ht_item.isEnabled():
ht_condition = THERMAL_ANALYSIS if ff_item.isEnabled() else ONLY_THERMAL_ANALYSIS
CardFormat.Conditions.add(ht_condition)
self.analyses.append(HT)
category_set |= self.sim_atts.analysisCategories(HT)
er_item = ht_item.find('Enclosure Radiation')
er_item = ht_item.find(ER)
print('er_item:', er_item)
if er_item.isEnabled():
CardFormat.Conditions.add(ENCLOSURE_RADIATION)
self.analyses.append(ER)
category_set |= self.sim_atts.analysisCategories(ER)
# Todo MOVING_RADIAITON
raise RuntimeError('Enclosure Radiation selected but NOT yet supported')
ih_item = ht_item.find('Induction Heating')
ih_item = ht_item.find(IH)
if ih_item.isEnabled():
self.analyses.append(IH)
category_set |= self.sim_atts.analysisCategories(IH)
raise RuntimeError('Induction Heating selected but NOT yet supported')
if ff_item.isEnabled():
CardFormat.Conditions.add(FLOW_ANALYSIS)
self.analyses.append(FF)
category_set |= self.sim_atts.analysisCategories(FF)
# Todo VISCOUS_FLOW vs INVISCID_FLOW
if sm_item.isEnabled():
self.analyses.append(SM)
category_set |= self.sim_atts.analysisCategories(SM)
raise RuntimeError('Solid Mechanics selected but NOT yet supported')
self.categories = list(category_set)
print('Enabled analyses: {}'.format(self.analyses))
print('Enabled categories: {}'.format(self.categories))
# Iterim logic during development
# att_list = self.sim_atts.findAttributes('ht/solver')
# for att in att_list:
......
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