Commit 90bdf4c8 authored by John Tourtellott's avatar John Tourtellott

Update AdHSurfaceWater output scripts

* Use updated export spec (definitions)
* Sort attributes by name instead of id for more persistence
* Fix check for missing mesh object in adhcommon.py
parent b6a1fb75
...@@ -17,6 +17,9 @@ import os ...@@ -17,6 +17,9 @@ import os
import sys import sys
import smtk import smtk
# so devs don't complain about pyc files in source
sys.dont_write_bytecode = True
# Explicitly load adhcommon.py, so that it reloads each time # Explicitly load adhcommon.py, so that it reloads each time
module_name = 'adhcommon' module_name = 'adhcommon'
abs_path = os.path.abspath(__file__) abs_path = os.path.abspath(__file__)
......
...@@ -19,6 +19,7 @@ Common functions for all ADH exporters ...@@ -19,6 +19,7 @@ Common functions for all ADH exporters
import os import os
import smtk import smtk
# Mapping from VTK's tet face ordering to ADH's tet face # Mapping from VTK's tet face ordering to ADH's tet face
# ordering. Note that it also includes the c to fortran indexing. # ordering. Note that it also includes the c to fortran indexing.
vtkToAdhFaceMapping = [3, 1, 2, 4] vtkToAdhFaceMapping = [3, 1, 2, 4]
...@@ -143,29 +144,34 @@ def init_scope(spec): ...@@ -143,29 +144,34 @@ def init_scope(spec):
mesh_item = att.find('mesh') mesh_item = att.find('mesh')
if mesh_item: if mesh_item:
mesh_item = smtk.attribute.to_concrete(mesh_item) mesh_item = smtk.attribute.to_concrete(mesh_item)
if mesh_item and mesh_item.isEnabled() and mesh_item.numberOfValues() > 0: if mesh_item.isEnabled() and mesh_item.numberOfValues() > 0:
meshset = mesh_item.value(0) meshset = mesh_item.value(0)
scope.mesh_collection = meshset.collection() #print 'meshset', meshset
print 'mesh', scope.mesh_collection scope.mesh_collection = meshset.collection()
if scope.mesh_collection:
# Get model that mesh is classified on print 'mesh collection', scope.mesh_collection
model_manager = scope.sim_atts.refModelManager()
model_uuid = scope.mesh_collection.associatedModel() # Get model that mesh is classified on
scope.model = smtk.model.Model(model_manager, model_uuid) model_manager = scope.sim_atts.refModelManager()
print 'model', scope.model model_uuid = scope.mesh_collection.associatedModel()
elif model_ent_item and model_ent_item.numberOfValues() > 0: scope.model = smtk.model.Model(model_manager, model_uuid)
model_ent = model_ent_item.value(0) print 'model', scope.model
scope.model = smtk.model.Model(model_ent)
print 'model', scope.model # If no mesh selected, use model's geometry
print 'Using model\'s internal geometry for the mesh'
converter = smtk.io.ModelToMesh()
#print 'converter', converter
scope.mesh_collection = converter(scope.model)
print 'mesh', scope.mesh_collection
else:
raise Exception('WARNING: No model or mesh specified')
if scope.mesh_collection is None: if scope.mesh_collection is None:
if model_ent_item and model_ent_item.numberOfValues() > 0:
model_ent = model_ent_item.value(0)
scope.model = smtk.model.Model(model_ent)
print 'model', scope.model
print 'Using model\'s internal geometry for the mesh'
converter = smtk.io.ModelToMesh()
#print 'converter', converter
scope.mesh_collection = converter(scope.model)
print 'mesh', scope.mesh_collection
if not scope.model:
raise Exception('ERROR: Missing model')
elif not scope.mesh_collection:
raise Exception('ERROR: unable to obtain mesh object') raise Exception('ERROR: unable to obtain mesh object')
# Get mesh points - only from 2D entities since that is what gets # Get mesh points - only from 2D entities since that is what gets
...@@ -213,7 +219,7 @@ def init_scope(spec): ...@@ -213,7 +219,7 @@ def init_scope(spec):
material_index = 0 material_index = 0
material_att_list = scope.sim_atts.findAttributes('Material') material_att_list = scope.sim_atts.findAttributes('Material')
material_att_list += scope.sim_atts.findAttributes('SolidMaterial') material_att_list += scope.sim_atts.findAttributes('SolidMaterial')
material_att_list.sort(key=lambda att:att.id()) material_att_list.sort(key=lambda att:att.name())
for material_att in material_att_list: for material_att in material_att_list:
# print 'material_att', material_att.name() # print 'material_att', material_att.name()
...@@ -236,7 +242,7 @@ def init_scope(spec): ...@@ -236,7 +242,7 @@ def init_scope(spec):
scope.bc_dict = dict() scope.bc_dict = dict()
bc_index = 0 bc_index = 0
bc_att_list = scope.sim_atts.findAttributes('BoundaryCondition') bc_att_list = scope.sim_atts.findAttributes('BoundaryCondition')
bc_att_list.sort(key=lambda bc: bc.id()) bc_att_list.sort(key=lambda bc: bc.name())
for bc_att in bc_att_list: for bc_att in bc_att_list:
model_ent_item = bc_att.associations() model_ent_item = bc_att.associations()
# Skip BCs not associated with any model entities # Skip BCs not associated with any model entities
...@@ -252,7 +258,7 @@ def init_scope(spec): ...@@ -252,7 +258,7 @@ def init_scope(spec):
# i.e., key == smtk attribute id, value == output index # i.e., key == smtk attribute id, value == output index
scope.constituent_dict = dict() scope.constituent_dict = dict()
constituent_att_list = scope.sim_atts.findAttributes('Constituent') constituent_att_list = scope.sim_atts.findAttributes('Constituent')
constituent_att_list.sort(key=lambda att: att.id()) constituent_att_list.sort(key=lambda att: att.name())
for constituent_att in constituent_att_list: for constituent_att in constituent_att_list:
con_index = len(scope.constituent_dict) + 1 con_index = len(scope.constituent_dict) + 1
scope.constituent_dict[constituent_att.id()] = con_index scope.constituent_dict[constituent_att.id()] = con_index
...@@ -288,8 +294,8 @@ def write_section(scope, att_type): ...@@ -288,8 +294,8 @@ def write_section(scope, att_type):
scope.logger.addWarning(msg) scope.logger.addWarning(msg)
return False return False
# Sort list by id # Sort list
att_list.sort(key=lambda x: x.id()) att_list.sort(key=lambda x: x.name())
for att in att_list: for att in att_list:
#print 'att', att.name() #print 'att', att.name()
format_list = scope.format_table.get(att.type()) format_list = scope.format_table.get(att.type())
...@@ -588,7 +594,7 @@ def write_functions(scope): ...@@ -588,7 +594,7 @@ def write_functions(scope):
timestep_expression = ts_item.expression(0) timestep_expression = ts_item.expression(0)
fcn_list = scope.sim_atts.findAttributes('SimExpression') fcn_list = scope.sim_atts.findAttributes('SimExpression')
fcn_list.sort(key=lambda f: f.id()) fcn_list.sort(key=lambda f: f.name())
for f in fcn_list: for f in fcn_list:
# Skip special case of TimeSeriesData # Skip special case of TimeSeriesData
if f.type() == 'TimeSeriesData': if f.type() == 'TimeSeriesData':
...@@ -686,8 +692,8 @@ def write_bc_sets(scope): ...@@ -686,8 +692,8 @@ def write_bc_sets(scope):
Writes node/element set for each boundary condition attribute Writes node/element set for each boundary condition attribute
''' '''
#print 'items', BC_ID_dict.items() #print 'items', BC_ID_dict.items()
bc_list = sorted(scope.bc_dict.items()) bc_list = sorted(scope.bc_dict.items(), key=lambda x: x[1])
#print 'sorted', bc_list print 'sorted', bc_list
# Determine mesh dimension # Determine mesh dimension
dimension = 3 dimension = 3
......
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