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
import sys
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
module_name = 'adhcommon'
abs_path = os.path.abspath(__file__)
......
......@@ -19,6 +19,7 @@ Common functions for all ADH exporters
import os
import smtk
# Mapping from VTK's tet face ordering to ADH's tet face
# ordering. Note that it also includes the c to fortran indexing.
vtkToAdhFaceMapping = [3, 1, 2, 4]
......@@ -143,29 +144,34 @@ def init_scope(spec):
mesh_item = att.find('mesh')
if mesh_item:
mesh_item = smtk.attribute.to_concrete(mesh_item)
if mesh_item and mesh_item.isEnabled() and mesh_item.numberOfValues() > 0:
meshset = mesh_item.value(0)
scope.mesh_collection = meshset.collection()
print 'mesh', scope.mesh_collection
# Get model that mesh is classified on
model_manager = scope.sim_atts.refModelManager()
model_uuid = scope.mesh_collection.associatedModel()
scope.model = smtk.model.Model(model_manager, model_uuid)
print 'model', scope.model
elif 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
else:
raise Exception('WARNING: No model or mesh specified')
if mesh_item.isEnabled() and mesh_item.numberOfValues() > 0:
meshset = mesh_item.value(0)
#print 'meshset', meshset
scope.mesh_collection = meshset.collection()
if scope.mesh_collection:
print 'mesh collection', scope.mesh_collection
# Get model that mesh is classified on
model_manager = scope.sim_atts.refModelManager()
model_uuid = scope.mesh_collection.associatedModel()
scope.model = smtk.model.Model(model_manager, model_uuid)
print 'model', scope.model
# If no mesh selected, use model's geometry
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')
# Get mesh points - only from 2D entities since that is what gets
......@@ -213,7 +219,7 @@ def init_scope(spec):
material_index = 0
material_att_list = scope.sim_atts.findAttributes('Material')
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:
# print 'material_att', material_att.name()
......@@ -236,7 +242,7 @@ def init_scope(spec):
scope.bc_dict = dict()
bc_index = 0
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:
model_ent_item = bc_att.associations()
# Skip BCs not associated with any model entities
......@@ -252,7 +258,7 @@ def init_scope(spec):
# i.e., key == smtk attribute id, value == output index
scope.constituent_dict = dict()
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:
con_index = len(scope.constituent_dict) + 1
scope.constituent_dict[constituent_att.id()] = con_index
......@@ -288,8 +294,8 @@ def write_section(scope, att_type):
scope.logger.addWarning(msg)
return False
# Sort list by id
att_list.sort(key=lambda x: x.id())
# Sort list
att_list.sort(key=lambda x: x.name())
for att in att_list:
#print 'att', att.name()
format_list = scope.format_table.get(att.type())
......@@ -588,7 +594,7 @@ def write_functions(scope):
timestep_expression = ts_item.expression(0)
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:
# Skip special case of TimeSeriesData
if f.type() == 'TimeSeriesData':
......@@ -686,8 +692,8 @@ def write_bc_sets(scope):
Writes node/element set for each boundary condition attribute
'''
#print 'items', BC_ID_dict.items()
bc_list = sorted(scope.bc_dict.items())
#print 'sorted', bc_list
bc_list = sorted(scope.bc_dict.items(), key=lambda x: x[1])
print 'sorted', bc_list
# Determine mesh dimension
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