diff --git a/dakota_interface.py b/dakota_interface.py index 63ccc03..134338e 100644 --- a/dakota_interface.py +++ b/dakota_interface.py @@ -25,8 +25,27 @@ def interface(fn_json_args): interface_args = json.load(fo) + # Load data processing module + if 'data_process_functions_file' in interface_args.keys(): + fn_dpf = interface_args['data_process_functions_file'] + if fn_dpf != '': + import_str = 'import {0} as dpf'.format(fn_dpf) + exec(import_str) + + # Read parameters params, results = di.read_parameters_file(sys.argv[-2], sys.argv[-1]) + + + # Pre-processing of parameters + if 'pre_process' in interface_args.keys(): + funcs = interface_args['pre_process'] + if len(funcs) > 0: + for func in funcs: + eval('dpf.{0}'.format(func))(params) + + + # Substitute templates for fn_t, fn_i in interface_args['template_output'].items(): di.dprepro(template=fn_t, parameters=params, output=fn_i) @@ -37,12 +56,6 @@ def interface(fn_json_args): )) - # Processing of parameters - - - # study = interface_args['study'] - - try: # preVABS/VABS print(' - running cross-sectional analysis...') @@ -53,26 +66,21 @@ def interface(fn_json_args): ms = sga.solve(fn_main, analysis, ppcmd, solver, False) - # Collect beam properties - # responses = interface_args['beam_props'] - # for k, v in responses.items(): - # if k == 'stiffness_refined': - # for label, index in v.items(): - # results[label].function = ms.stiffness_refined[index[0]][index[1]] - - # Calculate actual responses - is_post_funcs_imported = False - for k, v in interface_args['post_functions'].items(): + # is_post_funcs_imported = False + for k, v in interface_args['post_process'].items(): + # print('') + # print('label:', v[0]) bp = ms.getBeamProperty(v[0]) + # print('bp:', bp) if v[1] == 'self': r = bp elif v[1] == 'abs_rel_diff': r = np.abs((bp - v[2]) / v[2]) else: - if not is_post_funcs_imported: - import post_funcs - is_post_funcs_imported = True + # if not is_post_funcs_imported: + # import post_funcs + # is_post_funcs_imported = True # eval('from post_funcs import {0}'.format(v[1])) # r = eval(v[1])(bp, v[2]) r = eval('post_funcs.{0}'.format(v[1]))(bp, v[2]) diff --git a/galaxy_interface.py b/galaxy_interface.py deleted file mode 100644 index 0166aa5..0000000 --- a/galaxy_interface.py +++ /dev/null @@ -1,76 +0,0 @@ -import os -import sys -import subprocess as sbp -import datetime as dt -import json -import traceback as tb -import numpy as np -import pandas as pd -import xml.etree.ElementTree as et -import msgpi.presg as psg -import msgpi.analysis as sga -import msgpi.io.iosc as miosc -import msgpi.io.iovabs as miovabs -import dakota.interfacing as di - - -# Format string -msgfmt_w_ts = '- [{ts:%H}:{ts:%M}] {msg}' # string format with time stamp -fse = ' x [{0:%H}:{0:%M}:{0:%S}] EVAL {1:d}: {2:s}' -fsi = ' > [{0:%H}:{0:%M}:{0:%S}] EVAL {1:d}: {2:s}' - - -def interface(fn_json_args): - # Load JSON arguments - with open(fn_json_args, 'r') as fo: - interface_args = json.load(fo) - - - # Processing of parameters - - - study = interface_args['study'] - - - try: - # preVABS/VABS - print(' - running cross-sectional analysis...') - fn_main = interface_args['fn_main'] - analysis = interface_args['analysis'] - ppcmd = interface_args['prevabs_cmd'] - solver = interface_args['solver'] - ms = sga.solve(fn_main, analysis, ppcmd, solver, False) - - - # Collect beam properties - responses = interface_args['beam_props'] - for k, v in responses.items(): - if k == 'stiffness_refined': - for label, index in v.items(): - results[label].function = ms.stiffness_refined[index[0]][index[1]] - - - # Calculate actual responses - - - - # Write output - results.write() - - print(' - done.') - - return - - except: - results.fail() - with open('results.out', 'w') as fout: - results.write(stream=fout) - print(fse.format(dt.datetime.now(), evid, 'FAIL')) - e = tb.format_exc() - print(e) - return - - - -if __name__ == "__main__": - interface(sys.argv[1])