Commit 229ad016 authored by John Tourtellott's avatar John Tourtellott

Truchas revisions based on LANL feedback 29-Jan-2019

* Restore model association to Material attributes
* Write all materials, even when no associated entities
* Add interim logic to set analysis condition(s)
* Don't copy or rename mesh file; just write .inp file
parent 208298da
......@@ -68,7 +68,7 @@ class Export(smtk.operation.Operation):
print('reader result:', result)
# opDef = spec.createDefinition('test op', 'operation')
opDef = spec.findDefinition('truchas-export')
opDef = spec.findDefinition('export')
simulationDef = smtk.attribute.ResourceItemDefinition.New('attributes')
simulationDef.setAcceptsEntries('smtk::attribute::Resource', '', True)
......@@ -353,11 +353,11 @@ namelist_sequence = [
namelist('MATERIAL', custom_method='_write_materials'),
namelist('DIFFUSION_SOLVER',
if_condition=ONLY_THERMAL_ANALYSIS,
att_type='solver',
att_type='ht/solver',
base_item_path='analysis/thermal'),
namelist('DIFFUSION_SOLVER',
if_condition=[THERMAL_ANALYSIS, FLOW_ANALYSIS],
att_type='solver',
att_type='ht/solver',
base_item_path='analysis/thermal-plus-fluid/thermal-solver'),
namelist('CHAPARRAL', att_type='enclosure-radiation',
base_item_path='enable/chaparral',
......@@ -399,64 +399,25 @@ def ExportCMB(export_op):
Entry function, called by CMB to write export file
'''
# Get project name
operator_spec = export_op.parameters()
logger = export_op.log()
project_name_item = operator_spec.findString('ProjectName')
project_name = project_name_item.value(0)
if not project_name:
project_name = 'truchas'
msg = 'No Project Name specified; using \"%s\"' % project_name
print('WARNING:', msg)
logger.addWarning(msg)
print('project_name', project_name)
project_name = project_name
# Initialize project path (folder)
project_path = None
item = operator_spec.find('ProjectDir')
if item is not None:
dir_item = item
project_path = dir_item.value(0)
print('project_path', project_path)
if not project_path:
project_path = os.getcwd()
msg = 'No project_path specified -- using', project_path
print('ERROR:', msg)
logger.addWarning(msg)
return False
# Get output filename
output_file_item = operator_spec.findFile('output-file')
output_file = output_file_item.value(0)
output_dir = os.path.dirname(output_file)
# Create output folder if needed
if not os.path.exists(project_path):
os.makedirs(project_path)
# Write mesh file
model_entity = smtk.model.Entity.CastTo(operator_spec.find('model').objectValue(0))
write_mesh_op = smtk.session.mesh.Export.create()
if write_mesh_op is None:
print('MESH OPERATOR IS NONE')
mesh_filename = 'NOT-FOUND'
else:
mesh_filename = project_name + ".exo"
mesh_path = os.path.join(project_path, mesh_filename)
write_mesh_op.parameters().associate(model_entity)
if not os.path.exists(output_dir):
os.makedirs(output_dir)
file_item = write_mesh_op.parameters().findFile('filename')
file_item.setIsEnabled(True)
file_item.setValue(mesh_path)
result = write_mesh_op.operate()
outcome = result.findInt("outcome").value(0);
if (outcome != int(smtk.operation.Operation.Outcome.SUCCEEDED)):
logger.addError('Error writing model file %s, outcome %s' % (mesh_path, outcome))
return False
# Get mesh filename
mesh_file_item = operator_spec.findFile('mesh-file')
mesh_file = mesh_file_item.value(0)
# Write input file
output_filename = '%s.inp' % project_name
output_path = os.path.join(project_path, output_filename)
truchas_writer = writer.Writer(operator_spec, logger, mesh_filename)
completed = truchas_writer.write(output_path, namelist_sequence, format_table)
# Initialize writer
truchas_writer = writer.Writer(operator_spec, logger, mesh_file)
completed = truchas_writer.write(output_file, namelist_sequence, format_table)
print('Writer completion status %s' % completed)
sys.stdout.flush()
return completed
......@@ -20,6 +20,9 @@
</ItemDefinitions>
</AttDef>
<AttDef Type="material" Label="Material" BaseType="" Version="0" Unique="true">
<AssociationsDef Name="MaterialAssociations" Version="0" NumberOfRequiredValues="0" Extensible="true">
<MembershipMask>volume</MembershipMask>
</AssociationsDef>
<ItemDefinitions>
<String Name="material-type" Label="Material Type">
<Categories>
......
......@@ -22,9 +22,9 @@ SMTK_AttributeSystem(Version="2")
Cat Heat Transfer
AttDef(Type="material" Label="Material" BaseType="" Version="0" Unique="true")
//- AssociationsDef(Name="MaterialAssociations" Version="0"
//- NumberOfRequiredValues="0" Extensible="true")
//- MembershipMask volume
AssociationsDef(Name="MaterialAssociations" Version="0"
NumberOfRequiredValues="0" Extensible="true")
MembershipMask volume
ItemDefinitions
String(Name="material-type" Label="Material Type")
+categories-all
......
<SMTK_AttributeResource Version="3">
<Definitions>
<AttDef Type="truchas-export" BaseType="operation" Label="Export to Truchas">
<AttDef Type="export" BaseType="operation" Label="Export to Truchas" Version="1">
<BriefDescription>
Write ACE3P input file for selected program.
Write Truchas input file.
</BriefDescription>
<DetailedDescription>
Todo
Using the specified model and simulation attribute resources, this
operation will write a Truchas input file to the specified location.
</DetailedDescription>
<ItemDefinitions>
<Component Name="model" Label="Model" LockType="DoNotLock">
......@@ -18,20 +19,22 @@
<Resource Name="smtk::attribute::Resource"/>
</Accepts>
</Resource>
<String Name="ProjectName" Label="Project Name" Version="0">
<BriefDescription>Name (prefix) to use for generated files</BriefDescription>
</String>
<Directory Name="ProjectDir" Label="Project Directory"
Version="0" NumberOfRequiredValues="1" ShouldExist="false">
<BriefDescription>Filesystem folder for all generated files</BriefDescription>
</Directory>
<File Name="output-file" Label="Output File"
FileFilters="Input files (*.inp);;All files (*.*)" Version="0">
<BriefDescription>Truchas file to be generated</BriefDescription>
</File>
<File Name="mesh-file" Label="Mesh File" ShouildExist="true"
FileFilters="Exodus files (*.exo *.ex2 *.gen);;All files (*.*)" Version="0">
<BriefDescription>(for reference) Exodus file to use with the output file</BriefDescription>
</File>
</ItemDefinitions>
</AttDef>
</Definitions>
<Views>
<View Type="Instanced" Title="Export Settings" TopLevel="true" FilterByCategory="false" FilterByAdvanceLevel="true">
<View Type="Instanced" Title="Export Settings" TopLevel="true"
FilterByCategory="false" FilterByAdvanceLevel="true">
<InstancedAttributes>
<Att Name="Options" Type="ExportSpec" />
<Att Name="Options" Type="export" />
</InstancedAttributes>
</View>
</Views>
......
......@@ -10,6 +10,7 @@
#
#=============================================================================
from __future__ import print_function
import datetime
import os
print('loading', os.path.basename(__file__))
......@@ -80,7 +81,9 @@ class Writer:
completed = False
with open(path, 'w') as out:
out.write('Generated by CMB\n')
dt_string = datetime.datetime.now().strftime('%d-%b-%Y %H:%M')
out.write('* Generated by CMB {}\n'.format(dt_string))
self.out = out
for namelist in self.namelist_sequence:
......@@ -161,7 +164,7 @@ class Writer:
'''
'''
print('Writing', namelist.title)
self.out.write('\n&%s\n' % namelist.title)
self._start_namelist(namelist)
att_list = self.sim_atts.findAttributes(namelist.att_type)
mesh_att = att_list[0]
......@@ -169,14 +172,19 @@ class Writer:
if not card.is_custom:
card.write(self.out, mesh_att)
elif 'mesh_file' == card.keyword:
CardFormat.write_value(self.out, card.keyword, self.mesh_file)
mesh_filename = os.path.basename(self.mesh_file)
CardFormat.write_value(self.out, card.keyword, mesh_filename)
elif 'interface_side_sets' == card.keyword:
if self.interface_set_ids:
side_set_string = ','.join([str(x) for x in self.interface_set_ids])
CardFormat.write_value(
self.out, 'interface_side_sets', side_set_string, quote_string=False)
self.out.write('/\n')
self._finish_namelist()
if self.mesh_file:
self.out.write('* Mesh file on local file system at:\n')
self.out.write('* {}\n'.format(self.mesh_file))
# ---------------------------------------------------------------------
def _write_enclosure(self, namelist, format_list):
......@@ -782,33 +790,51 @@ class Writer:
# self.mesh_file = model_path
# Get analysis type and set CardFormat conditions
att_list = self.sim_atts.findAttributes('solver')
att_list.sort(key=lambda att: att.name())
if att_list:
solver_att = att_list[0]
analysis_item = solver_att.findString('analysis')
analysis = analysis_item.value(0)
print('analysis', analysis)
viscous_item = None
if 'fluid' == analysis:
CardFormat.Conditions.add(FLOW_ANALYSIS)
viscous_item = solver_att.itemAtPath(
'analysis/fluid/viscous-flow-model', '/')
elif 'thermal' == analysis:
CardFormat.Conditions.add(THERMAL_ANALYSIS)
CardFormat.Conditions.add(ONLY_THERMAL_ANALYSIS)
else:
CardFormat.Conditions.add(FLOW_ANALYSIS)
CardFormat.Conditions.add(THERMAL_ANALYSIS)
viscous_item = solver_att.itemAtPath(
'analysis/fluid/viscous-flow-model', '/')
if viscous_item is not None:
if viscous_item.isEnabled:
CardFormat.Conditions.add(VISCOUS_FLOW)
else:
CardFormat.Conditions.add(INVISCID_FLOW)
#print('Initial Conditions', CardFormat.Conditions)
# Todo rewrite this code once analysis view is in place
# att_list = self.sim_atts.findAttributes('solver')
# att_list.sort(key=lambda att: att.name())
# if att_list:
# solver_att = att_list[0]
# analysis_item = solver_att.findString('analysis')
# analysis = analysis_item.value(0)
# print('analysis', analysis)
# viscous_item = None
# if 'fluid' == analysis:
# CardFormat.Conditions.add(FLOW_ANALYSIS)
# viscous_item = solver_att.itemAtPath(
# 'analysis/fluid/viscous-flow-model', '/')
# elif 'thermal' == analysis:
# CardFormat.Conditions.add(THERMAL_ANALYSIS)
# CardFormat.Conditions.add(ONLY_THERMAL_ANALYSIS)
# else:
# CardFormat.Conditions.add(FLOW_ANALYSIS)
# CardFormat.Conditions.add(THERMAL_ANALYSIS)
# viscous_item = solver_att.itemAtPath(
# 'analysis/fluid/viscous-flow-model', '/')
# if viscous_item is not None:
# if viscous_item.isEnabled:
# CardFormat.Conditions.add(VISCOUS_FLOW)
# else:
# CardFormat.Conditions.add(INVISCID_FLOW)
# #print('Initial Conditions', CardFormat.Conditions)
# Iterim logic during development
att_list = self.sim_atts.findAttributes('ht/solver')
for att in att_list:
analysis_item = att.findString('analysis')
if analysis_item is not None:
analysis = analysis_item.value(0)
if analysis == 'thermal':
print('Adding analysis conditions "{}" "{}"'.format(
THERMAL_ANALYSIS, ONLY_THERMAL_ANALYSIS))
CardFormat.Conditions.add(THERMAL_ANALYSIS)
CardFormat.Conditions.add(ONLY_THERMAL_ANALYSIS)
elif analysis == 'thermal-plus-fluid':
print('Adding analysis conditions "{}", "{}"'.format(
THERMAL_ANALYSIS, FLOW_ANALYSIS))
CardFormat.Conditions.add(THERMAL_ANALYSIS)
CardFormat.Conditions.add(FLOW_ANALYSIS)
# Get the background material attribute's id
att_list = self.sim_atts.findAttributes('background-material')
......@@ -823,20 +849,12 @@ class Writer:
att_list = self.sim_atts.findAttributes('material')
att_list.sort(key=lambda att: att.name())
for att in att_list:
model_ent_item = att.associations()
# Skip materials with no model associations
# except for the background material
if model_ent_item is None and att.id() != self.background_material_id:
continue
material_count += 1
persistent_id = att.id()
self.material_number_dict[persistent_id] = material_count
# Attach material number to each model entity
if model_ent_item is None:
continue
# 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()
......
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