Skip to content

Commit

Permalink
0129
Browse files Browse the repository at this point in the history
  • Loading branch information
tian50 committed Jan 30, 2021
1 parent 7197454 commit 7214bfa
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 26 deletions.
82 changes: 56 additions & 26 deletions dakota_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import datetime as dt
import json
import os
import platform
import subprocess as sbp
import sys
import traceback as tb
Expand Down Expand Up @@ -63,7 +64,12 @@ def process(fn_json_args):
print(' - running cross-sectional analysis...')
fn_main = interface_args['fn_main']
analysis = interface_args['analysis']
ppcmd = interface_args['prevabs_cmd']

if platform.system() == 'Windows':
ppcmd = interface_args['prevabs_cmd_win']
elif platform.system() == 'Linux':
ppcmd = interface_args['prevabs_cmd_linux']

solver = interface_args['solver']
timeout = 30
if 'timeout' in interface_args.keys():
Expand All @@ -80,44 +86,68 @@ def process(fn_json_args):
# 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])

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

# Calculate actual responses
rc = None
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
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]]
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)
r = eval(f'dpf.{fn}')(interface_args, params, bps, inter, *args)
results[rn].function = r

elif type(interface_args['post_process']).__name__ == 'dict':
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:
bps.append(ms.getBeamProperty(s))
r = eval('dpf.{0}'.format(v[1]))(bps, v[2])

results[k].function = r
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


# Write output
Expand Down
45 changes: 45 additions & 0 deletions plotBlade.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import os
import sys
import subprocess as sbp
import numpy as np
import pprint as pp
import msm
import msmio as mio
import msmsg as msg
import msmbeam as msb
import utilities as utl


def plotBlade():
blade = msb.Beam()
blade.readPreGEBTIn(sys.argv[1])
for i, st in enumerate(blade.stations):
cs = st['cross_section']
cs.readPreVABSIn(st['section'] + '.temp.xml', '', '')

if i in [2, 3, 4]:
cs.name_baseline = 'vr7_baselines_' + str(i)
else:
cs.name_baseline = 'vr7_baselines'
cs.name_layup = 'vr7_layups'
cs.pitch = st['pitch']
# Set obliqueness
sw = st['sweep']
cos11 = np.cos(np.deg2rad(sw))
cos21 = np.cos(np.deg2rad(sw + 90.))
cs.cos11 = utl.floorAbsolute(cos11 * 1e6) * 1e-6
cs.cos21 = utl.floorAbsolute(cos21 * 1e6) * 1e-6

cs.updateXMLElementTree('h')

# Write new PreVABS input
cs.writePreVABSIn(cs.name + '.xml')
msm.run('prevabs', cs.name+'.xml', '-h', '-vabs')

# Read nodes and elements
cs.readVABSIn()
blade.writeGmshMsh()


if __name__ == "__main__":
plotBlade()

0 comments on commit 7214bfa

Please sign in to comment.