Commit 17acd732 authored by John Tourtellott's avatar John Tourtellott

Fix writer issues and add "description" definition

Addresses known issues in LANL prob1
parent 78c28c33
......@@ -115,7 +115,7 @@ format_table = {
],
'BODY': [
card('surface_name', literal_value='from mesh file'),
card('mesh_material_number', use_model_entities_for_value=True),
card('mesh_material_number'),
card('material_number', is_custom=True),
card('temperature', att_type='TemperatureInitialCondition', item_path='temperature',
expression_keyword='temperature_function'),
......@@ -235,7 +235,7 @@ format_table = {
card('output_mode', item_path='output-mode')
],
'MATERIAL': [
card('density', item_path='material-type/density'),
# card('density', item_path='material-type/density'),
card('void_temperature', item_path='material-type/void-temperature',
if_condition=VOID_MATERIAL),
card('sound_speed', item_path='material-type/sound-speed',
......@@ -312,11 +312,11 @@ format_table = {
],
'PHYSICS': [
card('fluid_flow', use_condition_for_boolean=FLOW_ANALYSIS),
card('heat_transfer', use_condition_for_boolean=THERMAL_ANALYSIS),
card('heat_transport', use_condition_for_boolean=THERMAL_ANALYSIS),
card('body_force', att_type='physics', item_path='fluid-body-force',
if_condition=FLOW_ANALYSIS),
card('inviscid', if_condition=FLOW_ANALYSIS,
use_condition_for_boolean=INVISCID_FLOW)
if_condition=FLOW_ANALYSIS)
# card('inviscid', if_condition=FLOW_ANALYSIS,
# use_condition_for_boolean=INVISCID_FLOW)
],
'PROBE': [
card('probe_name', use_name_for_value=True),
......@@ -348,7 +348,7 @@ namelist_sequence = [
base_item_path='type',
if_condition=ENCLOSURE_RADIATION,
custom_method='_write_thermal_condition'),
namelist('PHYSICS', att_type='solver'),
namelist('PHYSICS', custom_method='_write_physics'),
# Note: internally, the materials writer includes PHASE and MATERIAL_SYSTEM
namelist('MATERIAL', custom_method='_write_materials'),
namelist('DIFFUSION_SOLVER',
......
......@@ -47,6 +47,21 @@
</Includes>
<Definitions>
<AttDef Type="description" Label="Description" BaseType="" Version="0">
<ItemDefinitions>
<String Name="description" Label="text:" MultipleLines="true">
<BriefDescription>Text added to top of input file</BriefDescription>
<Categories>
<Cat>Enclosure Radiation</Cat>
<Cat>Fluid Flow</Cat>
<Cat>Heat Transfer</Cat>
<Cat>Induction Heating</Cat>
<Cat>Solid Mechanics</Cat>
</Categories>
<DefaultValue># Truchas simulation</DefaultValue>
</String>
</ItemDefinitions>
</AttDef>
</Definitions>
<!-- Attribute exclusion specifications -->
......@@ -64,7 +79,7 @@
</Rule>
<Rule>
<Def>ht/boundary/dirichlet</Def>
<Def>ht/boundary/htc</Def>
<Def>ht/boundary/HTC</Def>
</Rule>
<Rule>
<Def>ht/boundary/dirichlet</Def>
......@@ -86,10 +101,17 @@
</Views>
</View>
<!-- Placeholder for "analysis view" Todo -->
<View Type="Instanced" Name="Description">
<InstancedAttributes>
<Att Name="description" Type="description" />
</InstancedAttributes>
</View>
<View Type="Group" Title="Analysis" Style="Tiled">
<Views>
<View Title="SelectModules" />
<View Title="Description" />
<View Title="General" />
</Views>
</View>
......
......@@ -32,7 +32,6 @@
<BriefDescription>Initial velocity of the material body</BriefDescription>
<Categories>
<Cat>Fluid Flow</Cat>
<Cat>Heat Transfer</Cat>
</Categories>
<DefaultValue>0.0</DefaultValue>
</Double>
......
......@@ -26,7 +26,7 @@ SMTK_AttributeResource(Version="3")
DefaultValue 0.0
ExpressionType tabular-function
AttDef(Type="ht/boundary/htc" Label="HTC" BaseType="ht/boundary" Unique="true" Version="0")
AttDef(Type="ht/boundary/HTC" Label="HTC" BaseType="ht/boundary" Unique="true" Version="0")
ItemDefinitions
Double(Name="heat-transfer-coefficient" Label="Heat Transfer Coefficient (h)")
Categories #[Cat Heat Transfer]
......@@ -59,7 +59,7 @@ SMTK_AttributeResource(Version="3")
NumberOfRequiredValues="0" Extensible="true")
MembershipMask face
AttDef(Type="ht/interface/htc" Label="HTC" BaseType="ht/interface" Unique="true" Version="0")
AttDef(Type="ht/interface/HTC" Label="HTC" BaseType="ht/interface" Unique="true" Version="0")
ItemDefinitions
Double(Name="heat-transfer-coefficient" Label="Heat Transfer Coefficient (alpha)")
Categories #[Cat Heat Transfer]
......
......@@ -33,7 +33,7 @@
</Double>
</ItemDefinitions>
</AttDef>
<AttDef Type="ht/boundary/htc" Label="HTC" BaseType="ht/boundary" Unique="true" Version="0">
<AttDef Type="ht/boundary/HTC" Label="HTC" BaseType="ht/boundary" Unique="true" Version="0">
<ItemDefinitions>
<Double Name="heat-transfer-coefficient" Label="Heat Transfer Coefficient (h)">
<Categories>
......@@ -79,7 +79,7 @@
<MembershipMask>face</MembershipMask>
</AssociationsDef>
</AttDef>
<AttDef Type="ht/interface/htc" Label="HTC" BaseType="ht/interface" Unique="true" Version="0">
<AttDef Type="ht/interface/HTC" Label="HTC" BaseType="ht/interface" Unique="true" Version="0">
<ItemDefinitions>
<Double Name="heat-transfer-coefficient" Label="Heat Transfer Coefficient (alpha)">
<Categories>
......
......@@ -83,14 +83,23 @@ class Writer:
completed = False
with open(path, 'w') as out:
out.write('* Truchas input file\n')
# Write any user-provided description
desc_att = self.sim_atts.findAttribute('description')
if desc_att:
desc = desc_att.findString('description').value(0)
if desc:
out.write('{}\n'.format(desc))
else:
out.write('* Truchas input file\n')
# Add cmb output strings
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:
......@@ -146,6 +155,8 @@ class Writer:
else:
self.out.write('\n&%s\n' % namelist.title)
for card in format_list:
if card.att_type is None:
raise RuntimeError('card {} missing att_type'.format(card.keyword))
att_list = self.sim_atts.findAttributes(card.att_type)
for att in att_list:
if att.isMemberOf(self.categories):
......@@ -195,6 +206,18 @@ class Writer:
self.out.write('* Mesh file on local file system at:\n')
self.out.write('* {}\n'.format(self.mesh_file))
# ---------------------------------------------------------------------
def _write_physics(self, namelist, format_list):
"""Need custom logic because analysis attribute has no categories
"""
print('Writing', namelist.title)
self.out.write('\n&%s\n' % namelist.title)
for card in format_list:
card.write(self.out, None)
self.out.write('/\n')
# ---------------------------------------------------------------------
def _write_enclosure(self, namelist, format_list):
'''
......@@ -328,13 +351,20 @@ class Writer:
split = att.type().split('/')
CardFormat.write_value(self.out, 'condition', split[-1])
# Write data
data_constant_list = list()
for i in range(att.numberOfItems()):
item = att.item(i)
if item.isExpression():
expression_att = item.expression(0)
CardFormat.write_value(self.out, 'data_function', expression_att.name())
else:
CardFormat.write_value(self.out, 'data_constant', item.value())
data_constant_list.append(item.value(0))
if data_constant_list:
string_list = ['{:}'.format(val) for val in data_constant_list]
data_string = ', '.join(string_list)
CardFormat.write_value(
self.out, 'data_constant', data_string, quote_string=False)
face_set_string = CardFormat.get_model_entity_ids(reference_item, as_string=True)
CardFormat.write_value(
......@@ -527,6 +557,9 @@ class Writer:
material_number += 1
CardFormat.write_value(self.out, card.keyword, material_number)
elif card.keyword == 'mesh_material_number':
model_ent_id = CardFormat.get_model_entity_id(model_ent)
CardFormat.write_value(self.out, card.keyword, model_ent_id)
elif card.keyword in ['temperature', 'velocity']:
# Initial conditions are separate attributes on the same model entity
ic_att = _get_attribute(self.sim_atts, model_ent, card.att_type)
......@@ -728,13 +761,13 @@ class Writer:
immobile = ("solid" == material_type)
CardFormat.write_value(self.out, 'immobile', immobile, as_boolean=True)
# ?Write density
for card in format_list:
card.write(self.out, att)
# Check if this material is the background material
if persistent_id == self.background_material_id:
CardFormat.write_value(self.out, 'material_feature','background')
CardFormat.write_value(self.out, 'density', 1.0)
# End namelist
self.out.write('/\n')
......@@ -811,8 +844,9 @@ class Writer:
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)
CardFormat.Conditions.add(THERMAL_ANALYSIS)
if not ff_item.isEnabled():
CardFormat.Conditions.add(ONLY_THERMAL_ANALYSIS)
self.analyses.append(HT)
category_set |= self.sim_atts.analysisCategories(HT)
......@@ -866,7 +900,7 @@ class Writer:
att_list = self.sim_atts.findAttributes('background-material')
if att_list:
att = att_list[0]
item = att.findRef('background-material')
item = att.findComponent('background-material')
if item.isSet(0):
self.background_material_id = item.value(0).id()
......@@ -900,21 +934,22 @@ class Writer:
self.interface_set_ids = list()
self.enclosure_surface_set_ids = list()
self.moving_enclosure_surface_set_ids = list()
att_list = self.sim_atts.findAttributes('thermal-surface-condition')
att_list = self.sim_atts.findAttributes('ht/interface')
for att in att_list:
reference_item = att.associations()
if reference_item is None:
continue
type_item = att.findString('type')
if type_item.value(0) == 'ds-interface-condition':
if reference_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(reference_item)
self.enclosure_surface_set_ids += surface_ids
moving_item = att.itemAtPath('type/moving', '/')
if moving_item and moving_item.isEnabled():
self.moving_enclosure_surface_set_ids += surface_ids
# type_item = att.findString('type')
# if type_item.value(0) == 'ds-interface-condition':
# 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(reference_item)
# self.enclosure_surface_set_ids += surface_ids
# moving_item = att.itemAtPath('type/moving', '/')
# if moving_item and moving_item.isEnabled():
# self.moving_enclosure_surface_set_ids += surface_ids
self.interface_set_ids.sort()
self.enclosure_surface_set_ids.sort()
......
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