Commit a42bcd70 authored by John Tourtellott's avatar John Tourtellott

Update Truchas export script to smtk operator

* Also rename truchas-simbuilder.sbt to Truchas.sbt
* Adds truchas-export.sbt as well
parent fd481317
......@@ -10,20 +10,78 @@
#
#=============================================================================
"""
Root writer script for Truchas workflows
Export operator for Truchas workflows
"""
import os
print 'loading', os.path.basename(__file__)
import sys
import smtk
if 'pybind11' == smtk.wrappingProtocol():
#print 'Using pybind11 bindings'
import smtk.simulation
import smtk.attribute
import smtk.io
import smtk.operation
# Add the directory containing this file to the python module search list
import inspect
sys.path.insert(0, os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))))
import internal
from internal import writer
reload(writer) # for development
# reload(writer) # for development
class Export(smtk.operation.Operation):
def __init__(self):
smtk.operation.Operation.__init__(self)
def name(self):
return "Export Truchas"
def operateInternal(self):
try:
success = ExportCMB(self.parameters(), self.log())
except:
print 'Error', self.log().convertToString()
#smtk.ErrorMessage(self.log(), sys.exc_info()[0])
raise
return self.createResult(smtk.operation.Operation.Outcome.FAILED)
# Return with success
result = self.createResult(smtk.operation.Operation.Outcome.SUCCEEDED)
result.find('success').setValue(success)
return result
def createSpecification(self):
spec = self.createBaseSpecification()
print 'spec:', spec
# Load export atts
source_dir = os.path.abspath(os.path.dirname(__file__))
print 'source_dir:', source_dir
sbt_path = os.path.join(source_dir, 'internal', 'truchas-export.sbt')
print 'sbt_path:', sbt_path
reader = smtk.io.AttributeReader()
result = reader.read(spec, sbt_path, self.log())
print 'reader result:', result
# opDef = spec.createDefinition('test op', 'operation')
opDef = spec.findDefinition('truchas-export')
simulationDef = smtk.attribute.ResourceItemDefinition.New('attributes')
simulationDef.setAcceptsEntries('smtk::attribute::Resource', '', True)
opDef.addItemDefinition(simulationDef)
modelDef = smtk.attribute.ResourceItemDefinition.New('model')
modelDef.setAcceptsEntries('smtk::model::Resource', '', True)
opDef.addItemDefinition(modelDef)
resultDef = spec.createDefinition('test result', 'result')
successDef = smtk.attribute.IntItemDefinition.New('success')
resultDef.addItemDefinition(successDef)
return spec
# ---------------------------------------------------------------------
#
......@@ -335,28 +393,13 @@ namelist_sequence = [
# ---------------------------------------------------------------------
def ExportCMB(spec):
def ExportCMB(operator_spec, logger):
'''
Entry function, called by CMB to write export file
'''
logger = spec.getLogger()
# Get export attributes
export_spec_att = None
export_atts = spec.getExportAttributes()
if export_atts is not None:
att_list = export_atts.findAttributes('ExportSpec')
if att_list:
export_spec_att = att_list[0]
if export_spec_att is None:
msg = 'No ExportSpec instance -- cannot export'
print 'WARNING:', msg
logger.addError(msg)
return False
# Get project name
project_name_item = export_spec_att.findString('ProjectName')
project_name_item = operator_spec.findString('ProjectName')
project_name = project_name_item.value(0)
if not project_name:
project_name = 'truchas'
......@@ -368,12 +411,9 @@ def ExportCMB(spec):
# Initialize project path (folder)
project_path = None
item = export_spec_att.find('ProjectDir')
item = operator_spec.find('ProjectDir')
if item is not None:
if 'shiboken' == smtk.wrappingProtocol():
dir_item = smtk.attribute.to_concrete(item)
else:
dir_item = item
dir_item = item
project_path = dir_item.value(0)
print 'project_path', project_path
......@@ -391,8 +431,10 @@ def ExportCMB(spec):
# Initialize writer object
output_filename = '%s.inp' % project_name
output_path = os.path.join(project_path, output_filename)
truchas_writer = writer.Writer(spec)
completed = True
truchas_writer = writer.Writer(operator_spec, logger)
completed = truchas_writer.write(output_path, namelist_sequence, format_table)
print 'Writer completion status %s' % completed
sys.stdout.flush()
# print 'Writer completion status %s' % completed
# sys.stdout.flush()
print 'TODO truchas_writer'
return completed
Steps for (re)constructing test case #1
Model: disk_out_ref.smtk
Enclosure
Modules/Enclosure Radiation
* Disable!
Functions
......@@ -43,23 +43,24 @@ Material
Background material
* Set to "Void material"
Surfaces: Thermal Surface Conditions
* Name "Thermal BC"
* Type DS Boundary Condition
* Condition "HTC and/or External Radiation"
Modules/Heat Transfer/Boundary Conditions/Boundary
HTC --> New
* Name "Thermal BC HTC"
* HTC: Heat Transfer Coefficient (h) 0.543
* Associate to Side Set 1
Radiation --> New
* Emissitivity (epsilon) 0.888
* Ambient Temp (T infinity) 32.2
* Associate to Side Set 1
TBD
* HTC: Reference Temperature (T0) 212.5
* External: Emissitivity (epsilon) 0.888
* External: Ambient Temp (T infinity) 32.2
* Associated to set id 1
Surface: Thermal Surface Conditions
Modules/Heat Transfer/Boundary Conditions/Interface
HTC --> New
* Name "Thermal Interface"
* Type DS Interface Condition
* Condition "Internal HTC"
* Heat Transfer coefficient 0.123
* Associated to set id 4
* Associate to Side Set 4
Surface: Fluid Boundary Conditions
* Name "Pressure BC"
......@@ -78,42 +79,52 @@ Surface: Fluid Boundary Conditions
* Velocity Subgroup 0 1.1 2.2 3.3
* Associated to set id 3
Solver: Analysis Type
Modules/Heat Transfer/Solver
* Analysis Type "Fluid Plus Thermal"
* Thermal plus fluid: Thermal solver: Vebose Stepping ON
* Fluid Only: Flow numerics: Viscous Number 5
* Fluid Only: Flow Numerics: Mass limiter ON; cutoff 2.5e-5 (advanced)
* Viscous Flow Model enable
Solver: Simulation Control
Analysis
SHOW ADVANCED LEVEL
General:
* Start Time 0
* End Time 999.9
* Output Delta-Time Multiplier 0.02
* (Advanced) Add Sub Group (2X)
* 1, 0.1
* 5, 0.2
Simulation Control
* Enable
* Phase Start Times Add 2 values 0, 20
* Phase Init Dt Factor 0.01
Body
Initial Conditions
* Temperature --> New
* Name "body-0" (default)
* Temperature 98.6
* Associated to set id 1
* Associated to Element Block 1
Sources
Modules/Heat Transfer/Sources
Volumetric Heat Source --> New
* Name "Heat source"
* Temperature function "Source function"
* Associated to set 1
Other
# Exodus Block Modulus enabled (advanced)
* Start Time 0
* End Time 999.9
* Output Delta-Time Multiplier 0.02
* In advanced - create 2 output sub groups:
* 1, 0.1
* 5, 0.2
* Associated to Element Block 1
Globals/
* Fluid Body Force: 0, 0, -32.2
* Probes
Other
(Advanced) Exodus Block Modulus enabled
* 10000 (default)
Probes
Probe --> New
* Name "Probe 1"
* Description: Descriptive phrase goes here...
* Coordinates 3.14159, -0.111, 2.54
Save Resource As: sbi.test1.smtk
<SMTK_AttributeResource Version="3">
<Definitions>
<AttDef Type="truchas-export" BaseType="operation" Label="Export to Truchas">
<BriefDescription>
Write ACE3P input file for selected program.
</BriefDescription>
<DetailedDescription>
Todo
</DetailedDescription>
<ItemDefinitions>
<Resource Name="model" Label="Model">
<Accepts>
<Resource Name="smtk::model::Resource"/>
</Accepts>
</Resource>
<Resource Name="attributes" Label="Attributes">
<Accepts>
<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>
</ItemDefinitions>
</AttDef>
</Definitions>
<Views>
<View Type="Instanced" Title="Export Settings" TopLevel="true" FilterByCategory="false" FilterByAdvanceLevel="true">
<InstancedAttributes>
<Att Name="Options" Type="ExportSpec" />
</InstancedAttributes>
</View>
</Views>
</SMTK_AttributeResource>
......@@ -3,9 +3,9 @@ import cardformat
import writer
# Reload modules for development
reload(namelist)
reload(cardformat)
reload(writer)
# reload(namelist)
# reload(cardformat)
# reload(writer)
# Import the classes
from namelist import Namelist
......
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