Commit d448267a authored by T.J. Corona's avatar T.J. Corona

Update ACE3P exporter for CMB 6.

parent 83cbdd6b
......@@ -25,9 +25,68 @@ if 'pybind11' == smtk.wrappingProtocol():
import smtk.model
import smtk.simulation
# 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()))))
from internal.writers import utils, loading
from internal.writers import tem3pwriter # for testing only
class Export(smtk.operation.Operation):
def __init__(self):
smtk.operation.Operation.__init__(self)
def name(self):
return "export ACE3P"
def operateInternal(self):
sim_attrs = smtk.attribute.Resource.CastTo(self.parameters().find('simulation').value())
exp_attrs = smtk.attribute.Resource.CastTo(self.parameters().find('export').value())
model_resource = smtk.model.Resource.CastTo(self.parameters().find('model resource').value())
sim_attrs.setRefModelResource(model_resource)
# create export spec object
spec = smtk.simulation.ExportSpec()
spec.setSimulationAttributes(sim_attrs)
spec.setExportAttributes(exp_attrs)
try:
success = ExportCMB(spec)
except:
smtk.ErrorMessage(self.log(), sys.exc_info()[0])
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()
opDef = spec.createDefinition('test op', 'operation')
simulationDef = smtk.attribute.ResourceItemDefinition.New('simulation')
simulationDef.setAcceptsEntries('smtk::attribute::Resource', '', True)
opDef.addItemDefinition(simulationDef)
exportDef = smtk.attribute.ResourceItemDefinition.New('export')
exportDef.setAcceptsEntries('smtk::attribute::Resource', '', True)
opDef.addItemDefinition(exportDef)
modelDef = smtk.attribute.ResourceItemDefinition.New('model resource')
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
ExportScope = type('ExportScope', (object,), dict())
# ---------------------------------------------------------------------
def ExportCMB(spec):
......@@ -38,7 +97,7 @@ def ExportCMB(spec):
----------
spec: Top-level object passed in from CMB
'''
#print 'Enter ExportCMB()'
# print 'Enter ExportCMB()'
# Initialize scope instance to store spec values and other info
scope = ExportScope()
......@@ -80,22 +139,34 @@ def ExportCMB(spec):
print 'solver_string:', solver_string
scope.solver_list = solver_string.split('.')
scope.domain_source = None
# if scope.solver_list[0] == 'track3p':
# # Special case - check Domain for prerequisite simulation
# att_list = scope.sim_atts.findAttributes('Domain')
# if not att_list:
# msg = 'Track3P simulation missing Domain attribute'
# domain_att = att_list[0]
# input_data_item = domain_att.findGroup('InputData')
# source_item = input_data_item.find('Source')
# if source_item.value(0) == 'Omega3P':
# scope.solver_list = ['omega3p'] + scope.solver_list
# elif source_item.value(0) == 'S3P':
# scope.solver_list = ['s3p'] + scope.solver_list
# # And save for later
# scope.domain_source = source_item.value(0)
folder_item = export_spec_att.findDirectory('OutputFolder')
if folder_item is None or not folder_item.isSet(0):
msg = 'Output folder not set -- cannot export'
scope.logger.addError(msg)
raise Exception(msg)
scope.output_folder = folder_item.value(0)
# For all cases except acdtool, user must specify folder and filename prefix
if solver_string != 'acdtool':
folder_item = export_spec_att.findDirectory('OutputFolder')
if folder_item is None or not folder_item.isSet(0):
msg = 'Output folder not set -- cannot export '
scope.logger.addError(msg)
raise Exception(msg)
scope.output_folder = folder_item.value(0)
file_prefix_item = export_spec_att.findString('OutputFilePrefix')
if file_prefix_item is None or not file_prefix_item.isSet(0):
msg = 'Output file prefix not set -- cannot export'
scope.logger.addError(msg)
raise Exception(msg)
scope.output_file_prefix = file_prefix_item.value(0)
file_prefix_item = export_spec_att.findString('OutputFilePrefix')
if file_prefix_item is None or not file_prefix_item.isSet(0):
msg = 'Output file prefix not set -- cannot export'
scope.logger.addError(msg)
raise Exception(msg)
scope.output_file_prefix = file_prefix_item.value(0)
# Keep track of files & folders that need to get uploaded
# Use a set to prevent inserting that same thing twice
......@@ -111,24 +182,23 @@ def ExportCMB(spec):
's3p': 'S3P Analysis',
't3p': 'T3P Analysis',
'track3p': 'Track3P Analysis',
'tem3p-eigen': 'TEM3P Eigenmode',
'tem3p-elastic': 'TEM3P Elastic',
'tem3p-eigen': 'TEM3P Structural Eigenmode',
'tem3p-structure': 'TEM3P Structural Static',
'tem3p-harmonic': 'TEM3P Harmonic Response',
'tem3p-thermal-linear': 'TEM3P Thermal Linear',
'tem3p-thermal-nonlinear': 'TEM3P Thermal Nonlinear',
'tem3p-thermo-elastic': 'TEMP3P ThermoElastic'
'tem3p-thermal-nonlinear': 'TEM3P Thermal Nonlinear'
}
# Loop over all solvers and write corresponding files
for solver in scope.solver_list:
if 'acdtool' == solver:
completed = True
continue
# Hack/workaround for typo in export template
if solver == 'temp3p-thermal-nonlinear':
solver = 'tem3p-thermal-nonlinear'
# Get full analysis name
analysis = analysis_lookup.get(solver)
if not analysis:
msg = 'The ACE3P analysis is not specified, solver %s ' % solver
msg = 'The ACE3P analysis is not specified, solver %s' % solver
scope.logger.addError(msg)
raise Exception(msg)
print 'Writing %s' % analysis
......@@ -139,7 +209,14 @@ def ExportCMB(spec):
print 'Using categories: %s' % scope.categories
# Initialize output file
file_ext = 'tem3p' if solver.startswith('tem3p') else solver
extension_lookup = {
'tem3p-eigen': 'tem3p',
'tem3p-structure': 'tem3p',
'tem3p-harmonic': 'tem3p',
'tem3p-thermal-linear': 'tem3p',
'tem3p-thermal-nonlinear': 'tem3p'
}
file_ext = extension_lookup.get(solver, solver)
filename = '%s.%s' % (scope.output_file_prefix, file_ext)
output_path = os.path.join(scope.output_folder, filename)
print 'Output file %s' % output_path
......@@ -198,8 +275,6 @@ def ExportCMB(spec):
completed = nersc.submit_ace3p(scope, sim_item)
print 'Submit to NERSC status: %s' % completed
elif scope.solver_list[0] == 'acdtool':
raise Exception('ACDTool selected but Submit to NERSC not enabled -- no work to do ')
else:
# For test/debug, list any files to upload
print 'Files for upload:'
......@@ -276,7 +351,7 @@ def write_boundarycondition(scope):
ent_ref = slave_item.value(0)
if ent_ref:
ent = ent_ref.entity()
prop_idlist = scope.model_manager.integerProperty(ent, 'pedigree id')
prop_idlist = scope.model_manager.integerProperty(ent.id(), 'pedigree id')
if prop_idlist:
scope.output.write(' Periodic_M: %s\n' % prop_idlist[0])
else:
......@@ -568,7 +643,7 @@ def write_loading_info(scope):
boundary_item = att.findModelEntity('SourceBoundary')
boundary_ids = utils.get_entity_ids(scope, boundary_item)
if len(boundary_ids) == 0:
raise Exception('No SourceBoundary specified for LoadingInfo %s ' % att.name())
raise Exception('No SourceBoundary specified for LoadingInfo %s' % att.name())
scope.output.write(' BoundaryID: %d\n' % boundary_ids[0])
# Finish LoadingInfo
......@@ -591,20 +666,10 @@ def write_time_stepping(scope):
scope.output.write('TimeStepping:\n')
scope.output.write('{\n')
# Max time
max_time_item = feinfo_att.findDouble('MaxTime')
if not max_time_item.isSet(0):
msg = 'Cannot export because "Maximum Time" is not set in the Analysis tab '
raise Exception(msg)
max_time = max_time_item.value(0)
max_time = feinfo_att.findDouble('MaxTime').value(0)
scope.output.write(' MaximumTime: %g\n' % max_time)
# Time step
dt_item = feinfo_att.findDouble('DT')
if not dt_item.isSet(0):
msg = 'Cannot export because "Time Step" is not set in the Analysis tab '
raise Exception(msg)
dt = dt_item.value(0)
dt = feinfo_att.findDouble('DT').value(0)
scope.output.write(' DT: %g\n' % dt)
scope.output.write('}\n')
......@@ -654,12 +719,7 @@ def write_monitor(scope):
scope.output.write(' Type: %s\n' % type_string)
# Name current found as name item instead of att.name()
name_item = att.findString('Name')
name = name_item.value(0)
if not name:
msg = 'Cannot export because there is a %s monitor with an empty name field ' % type_string
raise Exception(msg)
scope.output.write(' Name: %s\n' % name)
scope.output.write(' Name: %s\n' % name_item.value(0))
# Voltage Monitor a special case
if type_string == 'ModeVoltage':
......@@ -677,21 +737,6 @@ def write_monitor(scope):
else:
scope.output.write(' %s: %s\n' % (keyword, item.value(0)))
# PowerMonitor can use analysis end time and interval if not set here
if type_string == 'Power':
# Get FEInfo, which provides the default values if needed
feinfo_att = scope.sim_atts.findAttributes('FEInfo')[0]
time_end_item = att.findDouble('TimeEnd')
if not time_end_item.isEnabled():
max_time = feinfo_att.findDouble('MaxTime').value(0)
scope.output.write(' %s: %g\n' % ('TimeEnd', max_time))
time_step_item = att.findDouble('TimeStep')
if not time_step_item.isEnabled():
dt = feinfo_att.findDouble('DT').value(0)
scope.output.write(' %s: %g\n' % ('TimeStep', dt))
# Handle MonitorBoundary as special case
boundary_item = att.findModelEntity('MonitorBoundary')
if boundary_item is not None:
......
......@@ -67,9 +67,7 @@ class CumulusClient():
#print 'user', user
user_id = user['_id']
r = self._client.listFolder(user_id, 'user', name='Private')
if len(r) != 1:
raise Exception('Wrong number of users; should be 1 got %s' % len(r))
self._private_folder_id = r[0]['_id']
self._private_folder_id = r.next()['_id']
print 'private_folder_id', self._private_folder_id
# ---------------------------------------------------------------------
......@@ -346,10 +344,9 @@ class CumulusClient():
'''Returns folder_id, creating one if needed
'''
# Check if folder already exists
folder_list = self._client.listFolder(parent_id, name=name)
folder_list = list(self._client.listFolder(parent_id, name=name))
if folder_list:
folder = folder_list[0]
#print 'found folder %s: %s' % (name, str(folder))
return folder['_id']
# (else)
......
......@@ -16,7 +16,7 @@ def get_model_info(scope):
* scope.model_file
* scope.model_path
'''
scope.model_manager = scope.sim_atts.refModelManager()
scope.model_manager = scope.sim_atts.refModelResource()
mask = int(smtk.model.MODEL_ENTITY)
model_ents = scope.model_manager.entitiesMatchingFlags(mask, True)
#print 'model_ents', model_ents
......@@ -104,12 +104,9 @@ def get_entity_ids(scope, model_entity_item):
if not model_entity_item.isSet(i):
continue
ent_ref = model_entity_item.value(i)
ent = ent_ref.entity()
prop_idlist = scope.model_manager.integerProperty(ent, 'pedigree id')
#print 'idlist', idlist
ent = model_entity_item.objectValue(i)
prop_idlist = scope.model_manager.integerProperty(ent.id(), 'pedigree id')
if prop_idlist:
#scope.output.write(' %d' % idlist[0])
ent_idlist.append(prop_idlist[0])
return sorted(ent_idlist)
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