Skip to content

Commit

Permalink
0113
Browse files Browse the repository at this point in the history
  • Loading branch information
tian50 committed Jan 13, 2021
1 parent 45f78e6 commit f53c849
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"restructuredtext.languageServer.disabled": true
}
29 changes: 24 additions & 5 deletions dakota_interface.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import os
import sys
import copy
import csv
import subprocess as sbp
import datetime as dt
import json
import os
import subprocess as sbp
import sys
import traceback as tb
import numpy as np
import xml.etree.ElementTree as et
Expand Down Expand Up @@ -75,9 +76,18 @@ def process(fn_json_args):
timeout=timeout, scrnout=scrnout
)

# 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

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
ms.offsetBeamRefCenter(ms.shear_center[1], ms.shear_center[2])
# ms_off = sg.calcOffsetBeamProperty(ms.shear_center[1], ms.shear_center[2])

# Calculate actual responses
rc = None
Expand All @@ -86,7 +96,10 @@ def process(fn_json_args):
# print('v[0]:', v[0])
# print(type(v[0]).__name__)
if type(v[0]).__name__ == 'str' or type(v[0]).__name__ == 'unicode':
bp = ms.getBeamProperty(v[0])
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
Expand All @@ -95,7 +108,13 @@ def process(fn_json_args):
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 = [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
Expand Down
12 changes: 8 additions & 4 deletions ms/iogebt.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,11 +482,14 @@ def writeGEBTIn(beam, fn_gebt_in=''):
# tcm = st['tcm']
# for row in tcm:
# utl.writeFormatFloats(fout, row)
if len(ms.eff_props[1]['compliance']['refined']) > 0:
for row in ms.eff_props[1]['compliance']['refined']:
# if len(ms.eff_props[1]['compliance']['refined']) > 0:
if not ms.compliance_refined is None:
# for row in ms.eff_props[1]['compliance']['refined']:
for row in ms.compliance_refined:
utl.writeFormatFloats(fout, row)
else:
for i, row in enumerate(ms.eff_props[1]['compliance']['classical']):
# for i, row in enumerate(ms.eff_props[1]['compliance']['classical']):
for i, row in enumerate(ms.compliance):
utl.writeFormatFloats(fout, (row[0], 0, 0, row[1], row[2], row[3]))
if i == 0:
utl.writeFormatFloats(fout, np.zeros(6))
Expand All @@ -496,7 +499,8 @@ def writeGEBTIn(beam, fn_gebt_in=''):
# mass = st['mass']
# for row in mass:
# utl.writeFormatFloats(fout, row)
for row in ms.eff_props[1]['mass']['origin']:
# for row in ms.eff_props[1]['mass']['origin']:
for row in ms.mass_origin:
utl.writeFormatFloats(fout, row)
fout.write('\n')

Expand Down
68 changes: 68 additions & 0 deletions sg.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import copy
import numpy as np


Expand Down Expand Up @@ -539,3 +540,70 @@ def findComboByMaterialOrientation(self, name, angle):
if (self.materials[mo[0]].name == name) and (mo[1] == angle):
return i
return 0









def calcOffsetBeamProperty(sg, offset_x2, offset_x3):
sg_off = copy.deepcopy(sg)

# Offset mass matrix
mm_o = np.asarray(sg_off.mass_mc)
if (offset_x2 != sg_off.mass_center[1]) or (offset_x3 != sg_off.mass_center[2]):
# mm_c = np.asarray(self.mass_mc)
mu = mm_o[0, 0]
mi_c = mm_o[3:, 3:]

x2 = sg_off.mass_center[1] - offset_x2
x3 = sg_off.mass_center[2] - offset_x3
r_tilde = np.array([
[0, -x3, x2],
[x3, 0, 0],
[-x2, 0, 0]
])

mm_o[:3, 3:] = mu * r_tilde.T
mm_o[3:, :3] = mu * r_tilde

# I_o = I_c + m * r_tilde.r_tilde^T
mm_o[3:, 3:] = mm_o[3:, 3:] + mu * np.dot(r_tilde, r_tilde.T)
sg_off.mass_origin = mm_o
sg_off.mass_center[1] -= offset_x2
sg_off.mass_center[2] -= offset_x3


# Offset stiffness and compliance
trfm_4 = np.eye(4)
trfm_6 = np.eye(6)

trfm_4[2, 0] = offset_x3
trfm_4[3, 0] = -offset_x2

trfm_6[4, 0] = offset_x3
trfm_6[5, 0] = -offset_x2
trfm_6[3, 1] = -offset_x3
trfm_6[3, 2] = offset_x2

cmp_4 = np.asarray(sg_off.compliance)
cmp_6 = np.asarray(sg_off.compliance_refined)

sg_off.compliance = np.dot(trfm_4.T, np.dot(cmp_4, trfm_4))
sg_off.compliance_refined = np.dot(trfm_6.T, np.dot(cmp_6, trfm_6))

sg_off.stiffness = np.linalg.inv(sg_off.compliance)
sg_off.stiffness_refined = np.linalg.inv(sg_off.compliance_refined)

sg_off.tension_center[1] -= offset_x2
sg_off.tension_center[2] -= offset_x3

sg_off.shear_center[1] -= offset_x2
sg_off.shear_center[2] -= offset_x3


return sg_off

0 comments on commit f53c849

Please sign in to comment.