Commit f4bc270a authored by John Tourtellott's avatar John Tourtellott

Add logic to write exodus file and debug export

* Fix export atts & logic to use model component instead of resource
* Using smtk::session::mesh::Export to write mesh,
  future versions should consider copying the input file
* Set Unique on each thermal bc
* Set enclosure radiation off by default
parent 57d79fec
......@@ -15,11 +15,13 @@ Export operator for Truchas workflows
import os
print 'loading', os.path.basename(__file__)
import sys
sys.dont_write_bytecode
import smtk
import smtk.attribute
import smtk.io
import smtk.operation
import smtk.session.mesh
# Add the directory containing this file to the python module search list
import inspect
......@@ -39,7 +41,7 @@ class Export(smtk.operation.Operation):
def operateInternal(self):
try:
success = ExportCMB(self.parameters(), self.log())
success = ExportCMB(self)
except:
print 'Error', self.log().convertToString()
#smtk.ErrorMessage(self.log(), sys.exc_info()[0])
......@@ -391,12 +393,15 @@ namelist_sequence = [
# ---------------------------------------------------------------------
def ExportCMB(operator_spec, logger):
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:
......@@ -426,13 +431,31 @@ def ExportCMB(operator_spec, logger):
if not os.path.exists(project_path):
os.makedirs(project_path)
# Initialize writer object
# 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)
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
# Write input file
output_filename = '%s.inp' % project_name
output_path = os.path.join(project_path, output_filename)
completed = True
truchas_writer = writer.Writer(operator_spec, logger)
truchas_writer = writer.Writer(operator_spec, logger, mesh_filename)
completed = truchas_writer.write(output_path, namelist_sequence, format_table)
# print 'Writer completion status %s' % completed
# sys.stdout.flush()
print 'TODO truchas_writer'
print 'Writer completion status %s' % completed
sys.stdout.flush()
return completed
......@@ -7,7 +7,7 @@
<Definitions>
<AttDef Type="enclosure-radiation" Label="Enclosure Radiation" BaseType="" Version="0" Unique="true">
<ItemDefinitions>
<Group Name="enable" Label="Enable" Version="0" Optional="true" IsEnabledByDefault="true">
<Group Name="enable" Label="Enable" Version="0" Optional="true" IsEnabledByDefault="false">
<ItemDefinitions>
<Group Name="chaparral" Label="Chaparral" Version="0">
<ItemDefinitions>
......
......@@ -9,7 +9,7 @@ SMTK_AttributeSystem(Version="2")
Version="0" Unique="true")
ItemDefinitions
Group(Name="enable", Label="Enable" Version="0"
Optional="true" IsEnabledByDefault="true")
Optional="true" IsEnabledByDefault="false")
ItemDefinitions
Group(Name="chaparral" Label="Chaparral" Version="0")
ItemDefinitions
......
......@@ -12,36 +12,39 @@ SMTK_AttributeSystem(Version="2")
NumberOfRequiredValues="0" Extensible="true")
MembershipMask face
AttDef(Type="ht/boundary/dirichlet" Label="Dirichlet" BaseType="ht/boundary" Version="0")
AttDef(Type="ht/boundary/dirichlet" Label="Dirichlet" BaseType="ht/boundary" Unique="true" Version="0")
ItemDefinitions
Double(Name="temperature" Label="Temperature")
Categories #[Cat Heat Transfer]
DefaultValue 0.0
ExpressionType tabular-function
AttDef(Type="ht/boundary/flux" Label="Flux" BaseType="ht/boundary" Version="0")
AttDef(Type="ht/boundary/flux" Label="Flux" BaseType="ht/boundary" Unique="true" Version="0")
ItemDefinitions
Double(Name="heat-flux" Label="Heat Flux")
Categories #[Cat Heat Transfer]
DefaultValue 0.0
ExpressionType tabular-function
AttDef(Type="ht/boundary/htc" Label="HTC" BaseType="ht/boundary" 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]
DefaultValue 0.0
ExpressionType tabular-function
Double(Name="reference-temperature" Label="Reference Temperature (T0)")
Categories #[Cat Heat Transfer]
DefaultValue 0.0
ExpressionType tabular-function
AttDef(Type="ht/boundary/radiation" Label="Radiation" BaseType="ht/boundary" Version="0")
AttDef(Type="ht/boundary/radiation" Label="Radiation" BaseType="ht/boundary" Unique="true" Version="0")
ItemDefinitions
Double(Name="emissivity" Label="Emissivity (epsilon)")
Categories #[Cat Heat Transfer]
DefaultValue 0.0
ExpressionType tabular-function
RangeInfo
Min(Inclusive="true") 0.0 ExpressionType tabular-function
Min(Inclusive="true") 0.0
Max(Inclusive="true") 1.0
Double(Name="ambient-temperature"
Label="Ambient Temperature (T infinity)")
......@@ -56,14 +59,14 @@ SMTK_AttributeSystem(Version="2")
NumberOfRequiredValues="0" Extensible="true")
MembershipMask face
AttDef(Type="ht/interface/htc" Label="HTC" BaseType="ht/interface" 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]
DefaultValue 0.0
ExpressionType tabular-function
AttDef(Type="ht/interface/radiation" Label="Gap Radiation" BaseType="ht/interface" Version="0")
AttDef(Type="ht/interface/radiation" Label="Gap Radiation" BaseType="ht/interface" Unique="true" Version="0")
ItemDefinitions
Double(Name="emissivity" Label="Emissivity (epsilon)")
Categories #[Cat Heat Transfer]
......
......@@ -11,7 +11,7 @@
<MembershipMask>face</MembershipMask>
</AssociationsDef>
</AttDef>
<AttDef Type="ht/boundary/dirichlet" Label="Dirichlet" BaseType="ht/boundary" Version="0">
<AttDef Type="ht/boundary/dirichlet" Label="Dirichlet" BaseType="ht/boundary" Unique="true" Version="0">
<ItemDefinitions>
<Double Name="temperature" Label="Temperature">
<Categories>
......@@ -22,7 +22,7 @@
</Double>
</ItemDefinitions>
</AttDef>
<AttDef Type="ht/boundary/flux" Label="Flux" BaseType="ht/boundary" Version="0">
<AttDef Type="ht/boundary/flux" Label="Flux" BaseType="ht/boundary" Unique="true" Version="0">
<ItemDefinitions>
<Double Name="heat-flux" Label="Heat Flux">
<Categories>
......@@ -33,7 +33,7 @@
</Double>
</ItemDefinitions>
</AttDef>
<AttDef Type="ht/boundary/htc" Label="HTC" BaseType="ht/boundary" 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>
......@@ -42,9 +42,16 @@
<DefaultValue>0.0</DefaultValue>
<ExpressionType>tabular-function</ExpressionType>
</Double>
<Double Name="reference-temperature" Label="Reference Temperature (T0)">
<Categories>
<Cat>Heat Transfer</Cat>
</Categories>
<DefaultValue>0.0</DefaultValue>
<ExpressionType>tabular-function</ExpressionType>
</Double>
</ItemDefinitions>
</AttDef>
<AttDef Type="ht/boundary/radiation" Label="Radiation" BaseType="ht/boundary" Version="0">
<AttDef Type="ht/boundary/radiation" Label="Radiation" BaseType="ht/boundary" Unique="true" Version="0">
<ItemDefinitions>
<Double Name="emissivity" Label="Emissivity (epsilon)">
<Categories>
......@@ -53,7 +60,7 @@
<DefaultValue>0.0</DefaultValue>
<ExpressionType>tabular-function</ExpressionType>
<RangeInfo>
<Min Inclusive="true">0.0 ExpressionType tabular-function</Min>
<Min Inclusive="true">0.0</Min>
<Max Inclusive="true">1.0</Max>
</RangeInfo>
</Double>
......@@ -72,7 +79,7 @@
<MembershipMask>face</MembershipMask>
</AssociationsDef>
</AttDef>
<AttDef Type="ht/interface/htc" Label="HTC" BaseType="ht/interface" 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,7 +90,7 @@
</Double>
</ItemDefinitions>
</AttDef>
<AttDef Type="ht/interface/radiation" Label="Gap Radiation" BaseType="ht/interface" Version="0">
<AttDef Type="ht/interface/radiation" Label="Gap Radiation" BaseType="ht/interface" Unique="true" Version="0">
<ItemDefinitions>
<Double Name="emissivity" Label="Emissivity (epsilon)">
<Categories>
......
......@@ -4,25 +4,23 @@ Model: disk_out_ref.smtk
Modules/Enclosure Radiation
* Disable!
Functions
* Al viscosity
Globals: Functions
* New
* Rename "Al viscosity"
* (1) 662, 1379
* (2) 669, 1364
* (3) 769, 1339
* (4) 685, 1324
* (5) 689, 1317
* (6) 700, 1268
* (7) 718, 1250
* (8) 768, 1175
* (9) 806, 1102
* (10) 833, 1028
* Source Function
* (3) 833, 1028
* Remove rows 4-10 (NOT Delete!)
* New
* Rename "Source Function"
* 100, 100.001
* 200, 200.002
* 300, 300.003
* Remove rows 4-10 (NOT Delete!)
Material
Materials/Specification
* New
* Name "Aluminum 6061-T6"
* Two Phase
* Density 2700
......@@ -43,24 +41,43 @@ Material
Background material
* Set to "Void material"
Modules/Heat Transfer/Boundary Conditions/Boundary
HTC --> New
* Name "Thermal BC HTC"
* HTC: Heat Transfer Coefficient (h) 0.543
## Modules/Heat Transfer/Boundary Conditions/Boundary
Dirichlet --> New
* Rename: "bc temp"
* Temperature 98.6
* Associate to Side Set 1
Flux --> New
* Rename "bc flux"
* Heat Flux 3.14
* Associate to Side Set 2
HTC --> New
* Rename "bc htc"
* Heat Transfer Coefficient (h) 0.543
* Reference Temperature (T0) 32.2
* Associate to Side Set 3
Radiation --> New
* Rename "bc rad"
* Emissitivity (epsilon) 0.888
* Ambient Temp (T infinity) 32.2
* Associate to Side Set 1
* Associate to Side Set 4
TBD
* HTC: Reference Temperature (T0) 212.5
## Modules/Heat Transfer/Boundary Conditions/Interface
Gap Radiation --> New
* Rename "ic rad"
* Emissivity (epsilon) 0.5
- Associate to Side Set 5
Modules/Heat Transfer/Boundary Conditions/Interface
HTC --> New
* Name "Thermal Interface"
* Rename "ic htc"
* Heat Transfer coefficient 0.123
* Associate to Side Set 4
* Associate to Side Set 6
Surface: Fluid Boundary Conditions
* Name "Pressure BC"
......@@ -79,7 +96,7 @@ Surface: Fluid Boundary Conditions
* Velocity Subgroup 0 1.1 2.2 3.3
* Associated to set id 3
Modules/Heat Transfer/Solver
## Modules/Heat Transfer/Solver
* Analysis Type "Fluid Plus Thermal"
* Thermal plus fluid: Thermal solver: Vebose Stepping ON
* Fluid Only: Flow numerics: Viscous Number 5
......
......@@ -8,12 +8,12 @@
Todo
</DetailedDescription>
<ItemDefinitions>
<Resource Name="model" Label="Model">
<Component Name="model" Label="Model" LockType="DoNotLock">
<Accepts>
<Resource Name="smtk::model::Resource"/>
<Resource Name="smtk::model::Resource" Filter="model" />
</Accepts>
</Resource>
<Resource Name="attributes" Label="Attributes">
</Component>
<Resource Name="attributes" Label="Attributes" LockType="DoNotLock">
<Accepts>
<Resource Name="smtk::attribute::Resource"/>
</Accepts>
......
......@@ -39,7 +39,7 @@ class Writer:
'''
# ---------------------------------------------------------------------
def __init__(self, operator_spec, logger):
def __init__(self, operator_spec, logger, mesh_filename='NOT-FOUND'):
'''
'''
self.sim_atts = smtk.attribute.Resource.CastTo(operator_spec.find('attributes').value())
......@@ -49,7 +49,9 @@ class Writer:
print msg
raise Exception(msg)
self.model_resource = smtk.model.Resource.CastTo(operator_spec.find('model').value())
model_entity = smtk.model.Entity.CastTo(operator_spec.find('model').objectValue(0))
self.model_resource = model_entity.resource()
if self.model_resource is None:
msg = 'ERROR - No model'
print msg
......@@ -62,7 +64,7 @@ class Writer:
self.moving_enclosure_surface_set_ids = list()
# key = material att id; value = output material_number
self.material_number_dict = dict()
self.mesh_file = 'NOT-FOUND'
self.mesh_file = mesh_filename
self.namelist_sequence = list()
self.out = None
......@@ -287,6 +289,7 @@ class Writer:
att_list = self.sim_atts.findAttributes(namelist.att_type)
att_list.sort(key=lambda att: att.name())
for att in att_list:
# print 'Writing att ', att.name()
model_ent_item = att.associations()
if model_ent_item is None or (0 == model_ent_item.numberOfValues()):
print 'Skipping attribute type \"%s\", name \"%s\" -- no associations' % \
......@@ -740,42 +743,42 @@ class Writer:
# Get mesh file from model manager
# mask = int(smtk.model.ModelEntityType)
mask = int(smtk.model.EntityTypeBits.MODEL_ENTITY)
model_ents = self.model_resource.entitiesMatchingFlags(mask, True)
print 'model_ents', model_ents
if not model_ents:
msg = 'No model - export will be incomplete'
print 'WARNING:', msg
elif len(model_ents) > 1:
msg = 'Multiple models - using first one'
print 'WARNING:', msg
model_ent = model_ents.pop()
print 'has smtk_url?', self.model_resource.hasStringProperty(model_ent, 'smtk_url')
urls = self.model_resource.stringProperty(model_ent, 'url')
if urls:
url = urls[0]
print 'url', url
# Get model fileanme
model_file = os.path.basename(url)
print 'model_file', model_file
#self.output.write(' File: %s\n\n' % model_file)
# Get full path to model
model_path = model_file # default case, when testing w/smtk
if os.path.isabs(url):
model_path = url
else:
smtk_urls = self.model_resource.stringProperty(model_ent, 'smtk_url')
print 'smtk_urls', smtk_urls
if smtk_urls:
smtk_url = smtk_urls[0]
model_path = os.path.join(smtk_url, url)
model_path = os.path.abspath(model_path)
print 'model_path', model_path
self.mesh_file = model_path
# mask = int(smtk.model.EntityTypeBits.MODEL_ENTITY)
# model_ents = self.model_resource.entitiesMatchingFlags(mask, True)
# print 'model_ents', model_ents
# if not model_ents:
# msg = 'No model - export will be incomplete'
# print 'WARNING:', msg
# elif len(model_ents) > 1:
# msg = 'Multiple models - using first one'
# print 'WARNING:', msg
# model_ent = model_ents.pop()
# print 'has smtk_url?', self.model_resource.hasStringProperty(model_ent, 'smtk_url')
# urls = self.model_resource.stringProperty(model_ent, 'url')
# if urls:
# url = urls[0]
# print 'url', url
# # Get model fileanme
# model_file = os.path.basename(url)
# print 'model_file', model_file
# #self.output.write(' File: %s\n\n' % model_file)
# # Get full path to model
# model_path = model_file # default case, when testing w/smtk
# if os.path.isabs(url):
# model_path = url
# else:
# smtk_urls = self.model_resource.stringProperty(model_ent, 'smtk_url')
# print 'smtk_urls', smtk_urls
# if smtk_urls:
# smtk_url = smtk_urls[0]
# model_path = os.path.join(smtk_url, url)
# model_path = os.path.abspath(model_path)
# print 'model_path', model_path
# self.mesh_file = model_path
# Get analysis type and set CardFormat conditions
att_list = self.sim_atts.findAttributes('solver')
......
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