Skip to content

Commit

Permalink
0516
Browse files Browse the repository at this point in the history
  • Loading branch information
tian50 committed May 17, 2021
1 parent 60eb6f2 commit aeb04e9
Show file tree
Hide file tree
Showing 21 changed files with 15,429 additions and 346 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
1.3.0

- Added logging and timing functions
- Updated the BeamProperty class
- Updated the readVABSOutHomo function for the latest VABS output format



1.2.0

- Moved all scripts under an extra layer of directory 'msgpi'
Expand Down
5 changes: 3 additions & 2 deletions msgpi/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,15 @@ def solve(sg_xml, analysis, ppcmd, solver, timeout=30, scrnout=True, logger=None
timer.start()
if analysis == 'h':
if solver == 'vabs':
sm = miovabs.readVABSOutHomo(sg_in + '.K')
bp = miovabs.readVABSOutHomo(sg_in + '.K')
if timer:
timer.stop()
return bp
elif solver == 'swiftcomp':
sm = miosc.readSCOutHomo(sg_in + '.k', smdim)
if timer:
timer.stop()
return sm
return sm
elif analysis == 'd':
if timer:
timer.stop()
Expand Down
132 changes: 43 additions & 89 deletions msgpi/dakota_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,16 @@
import dakota.interfacing as di


log_level = 20

# 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 process(fn_json_args, logger=None, timer=None):
def process(fn_json_args, logger=None):
if logger is None:
logger = mlog.initLogger(__name__)
if timer is None:
timer = mtime.Timer(logger=logger.info)
# if timer is None:
# timer = mtime.Timer(logger=logger.info)

print()

timer.start()
# timer.start()
# Load JSON arguments
with open(fn_json_args, 'r') as fo:
interface_args = json.load(fo)
Expand Down Expand Up @@ -73,13 +68,14 @@ def process(fn_json_args, logger=None, timer=None):
# ts=dt.datetime.now(),
# msg=' '.join(('eval', str(evid), 'start'))
# ))
logger.info(' '.join(('eval', str(evid), 'start')))
evtag = ' '.join(('eval', str(evid)))
logger.info(' '.join((evtag, 'start')))


try:
# preVABS/VABS
# print(' - running cross-sectional analysis...')
logger.info('running cross-sectional analysis...')
logger.info(evtag + ' running cross-sectional analysis...')
fn_main = interface_args['fn_main']
analysis = interface_args['analysis']

Expand All @@ -96,109 +92,67 @@ def process(fn_json_args, logger=None, timer=None):
if 'scrnout' in interface_args.keys():
scrnout = interface_args['scrnout']

timer.stop()
# timer.stop()


timer.start()
ms = sga.solve(
# timer.start()
bp = sga.solve(
fn_main, analysis, ppcmd, solver,
timeout=timeout, scrnout=scrnout
timeout=timeout, scrnout=scrnout, logger=logger
)
timer.stop()
# timer.stop()


timer.start()
# timer.start()
# Location of the origin relative to a ref point
# e.g., leading edge of the airfoil
# origin_ref_2 = interface_args['origin_ref_2']
# sc_ref_2 = ms.shear_center[1] + origin_ref_2
xo2 = 0
xo3 = 0

if 'ref_center' in interface_args.keys():
if interface_args['ref_center'] == 'sc':
# Calculate the location of the new origin (e.g. sc)
# relative to the ref point (e.g. leading edge)
# origin_ref_2 = ms.shear_center[1] + origin_ref_2
xo2 -= ms.shear_center[1]
xo3 -= ms.shear_center[2]
ms.offsetBeamRefCenter(ms.shear_center[1], ms.shear_center[2])
# ms_off = sg.calcOffsetBeamProperty(ms.shear_center[1], ms.shear_center[2])
# xo2 = 0
# xo3 = 0


# Extract beam properties
bps = {'xo2': xo2, 'xo3': xo3}
# bps = {'xo2': xo2, 'xo3': xo3}
bps = {}
for n in interface_args['beam_properties']:
bps[n] = ms.getBeamProperty(n)
bps[n] = bp.get(n)

# Calculate actual responses
rc = None
# rc = None
inter = {} # Intermediate values

if type(interface_args['post_process']).__name__ == 'list':
for pp in interface_args['post_process']:
fn = pp[0] # function name
rn = pp[1] # response name
# print(rn)
args = pp[1:]
if fn == 'self':
r = bps[args[1]]
inter[rn] = bps[args[1]]
else:
r = eval(f'dpf.{fn}')(interface_args, params, bps, inter, *args)
# results[rn].function = r
# print(results.descriptors)
# print(inter)
for rn in results.descriptors:
if rn in inter.keys():
results[rn].function = inter[rn]

elif type(interface_args['post_process']).__name__ == 'dict':
# Location of the origin relative to a ref point
# e.g., leading edge of the airfoil
origin_ref_2 = interface_args['origin_ref_2']
sc_ref_2 = ms.shear_center[1] + origin_ref_2

for k, v in interface_args['post_process'].items():
# print('')
# print('v[0]:', v[0])
# print(type(v[0]).__name__)
if type(v[0]).__name__ == 'str' or type(v[0]).__name__ == 'unicode':
if v[0] == 'sc2_ref' or v[0] == 'scy_ref':
bp = sc_ref_2
else:
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:
r = eval('dpf.{0}'.format(v[1]))(bp, v[2])
elif type(v[0]).__name__ == 'list':
# bps = [ms.getBeamProperty(s) for s in v[0]]
bps = []
for s in v[0]:
if s == 'sc2_ref' or s == 'scy_ref':
bps.append(sc_ref_2)
else:
bps.append(ms.getBeamProperty(s))
r = eval('dpf.{0}'.format(v[1]))(bps, v[2])

results[k].function = r

for pp in interface_args['post_process']:
fn = pp[0] # function name
rn = pp[1] # response name
# print(rn)
args = pp[1:]
if fn == 'self':
# r = bps[args[1]]
inter[rn] = bps[args[1]]
else:
r = eval(f'dpf.{fn}')(interface_args, params, bps, inter, *args)
# results[rn].function = r
# print(results.descriptors)
# print(inter)
for rn in results.descriptors:
if rn in inter.keys():
results[rn].function = inter[rn]


# Write output
results.write()

# print(' - done.')
logger.info('done')
timer.stop()
logger.info(evtag + ' done')
# timer.stop()

return

except:
# print(fse.format(dt.datetime.now(), evid, 'FAIL'))
logger.critical(' '.join(('eval', str(evid), 'failed')))
logger.critical(' '.join((evtag, 'failed')))
if 'fail_replace' in interface_args.keys():
for k, v in interface_args['fail_replace'].items():
# if v == 'inf' or v == '-inf':
Expand All @@ -211,7 +165,7 @@ def process(fn_json_args, logger=None, timer=None):
e = tb.format_exc()
print(e)

timer.stop()
# timer.stop()

return

Expand Down
Loading

0 comments on commit aeb04e9

Please sign in to comment.