From f53c849576cfd0eb9ad76d8a4f8eb27bc5ffe08c Mon Sep 17 00:00:00 2001 From: Su Tian Date: Wed, 13 Jan 2021 15:55:18 -0500 Subject: [PATCH] 0113 --- .vscode/settings.json | 3 ++ dakota_interface.py | 29 ++++++++++++++---- ms/iogebt.py | 12 +++++--- sg.py | 68 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 103 insertions(+), 9 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..6e25d1d --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "restructuredtext.languageServer.disabled": true +} \ No newline at end of file diff --git a/dakota_interface.py b/dakota_interface.py index a9d608a..5751c07 100644 --- a/dakota_interface.py +++ b/dakota_interface.py @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/ms/iogebt.py b/ms/iogebt.py index 5c861df..3847102 100644 --- a/ms/iogebt.py +++ b/ms/iogebt.py @@ -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)) @@ -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') diff --git a/sg.py b/sg.py index 37a5075..03e2a21 100644 --- a/sg.py +++ b/sg.py @@ -1,3 +1,4 @@ +import copy import numpy as np @@ -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 +