Commit a33a9fc2 authored by John Tourtellott's avatar John Tourtellott

Add hotstart file output to AdH writers

* Remove as option to shallow water (always write it)
* Writes mesh datasets with names in {icon, ioh, iov}
* Also hide extrusion executable since it is currently obsolete
parent 88a2a213
......@@ -18,10 +18,6 @@
<BriefDescription>Common base name for output files (.2dm, .bc)</BriefDescription>
<DefaultValue>shallowwater</DefaultValue>
</String>
<File Name="HotStartFile" Label="Hot Start File" Version="0"
NumberOfRequiredValues="1" ShouldExist="true"
FileFilters="hot files (*.hot);;All files (*.*)">
</File>
<!-- Advanced attributes -->
<String Name="AnalysisTypes" Label="Analysis Types" AdvanceLevel="99" Version="0"
......@@ -31,8 +27,10 @@
ShouldExist="true" FileFilters="Python files (*.py);;All files (*.*)">
<DefaultValue>AdHShallowWater.py</DefaultValue>
</File>
<!-- Hide Extrusion executable option until new ERDC code in place -->
<File Name="ExtrusionExecutable" Label="adh_2d_3d Executable" Version="0" NumberOfRequiredValues="1"
AdvanceLevel="1" ShouldExist="true"
AdvanceLevel="99" ShouldExist="true"
Optional="true" IsEnabledByDefault="false"
FileFilters="All files (*.*)">
<DefaultValue>adh_2d_3d</DefaultValue>
......
......@@ -95,34 +95,21 @@ def ExportCMB(spec):
f.write('%s %s\n' % t)
write_complete = True
# Write hotstart file
write_complete &= adh.write_hotstart(scope)
if not write_complete:
print 'ERROR writing %s -- exiting' % mt_path
return False
# Get ExportSpec attribute
att_list = scope.export_atts.findAttributes('ExportSpec')
if len(att_list) > 1:
msg = 'More than one ExportSpec instance -- using first one'
print 'WARNING:', msg
scope.logger.addWarning(msg)
else:
export_spec_att = att_list[0]
# Copy host start file to output directory if specified
hotstart_file = '%s.hot' % scope.output_filebase
hotstart_path = os.path.join(scope.output_directory, hotstart_file)
if not os.path.isfile(hotstart_path):
# Look up .hot file in export attributes
item = export_spec_att.find('HotStartFile')
file_item = smtk.attribute.to_concrete(item)
source = file_item.value(0)
if not source:
print 'WARNING: hot start file not specified'
elif not os.path.isfile(source):
print 'WARNING: Unable to find hotstart file at "%s"' % source
else:
print 'Copying %s to %s' % (source, hotstart_path)
shutil.copyfile(source, hotstart_path)
# att_list = scope.export_atts.findAttributes('ExportSpec')
# if len(att_list) > 1:
# msg = 'More than one ExportSpec instance -- using first one'
# print 'WARNING:', msg
# scope.logger.addWarning(msg)
# else:
# export_spec_att = att_list[0]
# Find the adh_2d_3d executable
# THIS BLOCK IS COMMENTED OUT UNTIL THE NEW EXTRUSION
......
......@@ -201,6 +201,9 @@ def ExportCMB(spec):
print 'Wrote', bc_path
completed = True
# Write hotstart file if enabled
completed &= adh.write_hotstart(scope)
if not completed:
print 'WARNING: Export terminated unexpectedly -- output might be invalid.'
......
......@@ -18,6 +18,7 @@ Common functions for all ADH exporters
"""
import os
import smtk
reload(smtk)
# Mapping from VTK's tet face ordering to ADH's tet face
......@@ -203,6 +204,12 @@ def init_scope(spec):
for i in range(types_item.numberOfValues()):
scope.analysis_types.append(types_item.value(i))
# Write hotstart file?
scope.write_hotstart = False
hotstart_item = att.findVoid('WriteHotstart')
if hotstart_item and hotstart_item.isEnabled:
scope.write_hotstart = True
# Make categories set
categories = set()
for analysis in scope.analysis_types:
......@@ -928,3 +935,92 @@ def assign_model_entity_ids(model, dimension, property_name='id', first=1):
entity_id += 1
return entity_id
# ---------------------------------------------------------------------
def write_hotstart(scope):
'''Writes hotstart file
Initial implementation limited to ioh, icon mesh field
'''
print 'write_hotstart()'
#print dir(scope)
mesh = scope.mesh_collection.meshes()
if smtk.wrappingProtocol() == 'pybind11':
pointfields = mesh.pointFields()
else:
pointfields = mesh.pointFieldsForShiboken()
# Limited to datasets with name matching hotstart field names
field_dict = {'ioh': None, 'iov': None, 'icon': None}
field_count = 0
for field in pointfields:
name = field.name()
if name in field_dict:
field_dict[name] = field
field_count += 1
#print 'field_count', field_count
if 0 == field_count:
print 'No mesh fields found with hotstart dataset names'
return True
# Get start time and units for use below
time_att = scope.sim_atts.findAttribute('Time')
item = time_att.itemAtPath('StartTime/Value', '/')
start_time_value_item = smtk.to_concrete(item)
start_time_value = start_time_value_item.value(0)
item = time_att.itemAtPath('StartTime/Units', '/')
start_time_units_item = smtk.to_concrete(item)
start_time_units = start_time_units_item.value(0)
time_unit_names = ['seconds', 'minutes', 'hours', 'days', 'weeks']
start_time_units_string = time_unit_names[start_time_units]
out_filename = scope.output_filebase + '.hot'
out_path = os.path.join(scope.output_directory, out_filename)
completed = False
with open(out_path, 'w') as out:
out.write('DATASET\n')
# Get mesh dimension
dimension = 3
meshset3D = scope.mesh_collection.meshes(smtk.mesh.Dims3)
if meshset3D.is_empty():
dimension = 2
#print 'mesh dimension', dimension
out.write('OBJTYPE "mesh%dd"\n' % dimension)
out.write('BEGSCL\n')
point_count = scope.mesh_points.numberOfPoints()
out.write('ND %d\n' % point_count)
out.write('NC %d\n' % scope.mesh_collection.cells(smtk.mesh.Dims2).size())
out.write('TIMEUNITS %s\n' % start_time_units_string)
out.write('TS %f %d\n' % (start_time_value, start_time_units))
for name in sorted(field_dict.keys()):
if field_dict[name] is None:
continue
out.write('NAME \"%s\"\n' % name)
field = mesh.pointField(name)
data = field.get()
#print 'data', data
dim = field.dimension()
if 1 == dim:
for i in xrange(point_count):
out.write('%f\n' % data[i])
else:
# Traverse by array-slice
lo = 0
for i in xrange(point_count):
hi = lo + dim
dlist = data[lo:hi]
slist = ['%f' % d for d in dlist]
s = ' '.join(slist)
out.write('%s\n' % s)
lo += dim
print 'Wrote %s' % out_path
completed = True
return completed
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