Skip to content

Commit

Permalink
0519
Browse files Browse the repository at this point in the history
  • Loading branch information
tian50 committed May 19, 2021
1 parent c7f582b commit bf0338e
Show file tree
Hide file tree
Showing 30 changed files with 51,210 additions and 10,829 deletions.
294 changes: 250 additions & 44 deletions msgpi/io/iosc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import numpy as np
import msgpi.io.utils as utl
import msgpi.sg as sgm
import msgpi.logger as mlog


# ====================================================================
Expand Down Expand Up @@ -200,7 +201,183 @@ def readSCIn(fn_sg, smdim):
return sg


def readSCOutHomo(fn, smdim):







def readSCOutBeamProperty(fn, scrnout=True, logger=None):
"""Read SwiftComp homogenization results
Parameters
----------
fn : str
SwiftComp output file name (e.g. example.sg.k).
scrnout : bool, default True
Switch of printing cmd output.
Returns
-------
msgpi.sg.BeamProperty
Material/sectional properties.
"""
if logger is None:
logger = mlog.initLogger(__name__)

# sm = sgm.MaterialSection(smdim = 1)
bp = sgm.BeamProperty()

linesRead = []
keywordsIndex = {}


with open(fn, 'r') as fin:
ln = -1
for line in fin:

line = line.strip()

if len(line) > 0:
linesRead.append(line)
ln += 1
else:
continue

if '-----' in line:
continue


# Inertial properties
# -------------------

elif 'Effective Mass Matrix' in line:
keywordsIndex['mass'] = ln
elif 'Mass Center Location' in line:
keywordsIndex['mc'] = ln
elif 'Mass per unit span' in line:
bp.mu = float(line.split()[-1])
elif 'i11' in line:
bp.i11 = float(line.split()[-1])
elif 'i22' in line:
bp.i22 = float(line.split()[-1])
elif 'i33' in line:
bp.i33 = float(line.split()[-1])
elif 'principal inertial axes rotated' in line:
line = line.split()
tmp_id = line.index('degrees')
bp.phi_pia = float(line[tmp_id - 1])
elif 'Mass-Weighted Radius of Gyration' in line:
bp.rg = float(line.split()[-1])


# Structural properties
# ---------------------

elif 'Effective Stiffness Matrix' in line:
keywordsIndex['csm'] = ln
elif 'Effective Compliance Matrix' in line:
keywordsIndex['cfm'] = ln

elif 'Tension Center Location' in line:
keywordsIndex['tc'] = ln
elif 'extension stiffness EA' in line:
bp.ea = float(line.split()[-1])
elif 'torsional stiffness GJ' in line:
bp.gj = float(line.split()[-1])
elif 'Principal bending stiffness EI22' in line:
bp.ei22 = float(line.split()[-1])
elif 'Principal bending stiffness EI33' in line:
bp.ei33 = float(line.split()[-1])
elif 'principal bending axes rotated' in line:
line = line.split()
tmp_id = line.index('degrees')
bp.phi_pba = float(line[tmp_id - 1])

elif 'Timoshenko Stiffness Matrix' in line:
keywordsIndex['tsm'] = ln
elif 'Timoshenko Compliance Matrix' in line:
keywordsIndex['tfm'] = ln

elif 'Shear Center Location' in line:
keywordsIndex['sc'] = ln
elif 'Principal shear stiffness GA22' in line:
bp.ga22 = float(line.split()[-1])
elif 'Principal shear stiffness GA33' in line:
bp.ga33 = float(line.split()[-1])
elif 'principal shear axes rotated' in line:
line = line.split()
tmp_id = line.index('degrees')
bp.phi_psa = float(line[tmp_id - 1])


ln = keywordsIndex['mass']
bp.mass = utl.textToMatrix(linesRead[ln + 2:ln + 8])

#check whether the analysis is Vlasov or timoshenko
#Read stiffness matrix and compliance matrix
if 'vsm' in keywordsIndex.keys():
pass

else:
try:
ln = keywordsIndex['csm']
bp.stff = utl.textToMatrix(linesRead[ln + 2:ln + 6])
except KeyError:
if scrnout:
print('No classical stiffness matrix found.')
else:
pass

try:
ln = keywordsIndex['cfm']
bp.cmpl = utl.textToMatrix(linesRead[ln + 2:ln + 6])
except KeyError:
if scrnout:
print('No classical flexibility matrix found.')
else:
pass

try:
ln = keywordsIndex['tsm']
bp.stff_t = utl.textToMatrix(linesRead[ln + 2:ln + 8])
except KeyError:
if scrnout:
print('No Timoshenko stiffness matrix found.')
else:
pass
try:
ln = keywordsIndex['tfm']
bp.cmpl_t = utl.textToMatrix(linesRead[ln + 2:ln + 8])
except KeyError:
if scrnout:
print('No Timoshenko flexibility matrix found.')
else:
pass

if 'tc' in keywordsIndex.keys():
ln = keywordsIndex['tc']
bp.xt2, bp.xt3 = list(map(float, linesRead[ln + 2].split()))
if 'sc' in keywordsIndex.keys():
ln = keywordsIndex['sc']
bp.xs2, bp.xs3 = list(map(float, linesRead[ln + 2].split()))
if 'mc' in keywordsIndex.keys():
ln = keywordsIndex['mc']
bp.xm2, bp.xm3 = list(map(float, linesRead[ln + 2].split()))


return bp









def readSCOutHomo(fn, smdim, scrnout=True, logger=None):
"""Read SwiftComp homogenization results.
:param fn: SwiftComp output file (e.g. example.sg.k)
Expand All @@ -209,6 +386,14 @@ def readSCOutHomo(fn, smdim):
:param smdim: Dimension of the structural model
:type smdim: int
"""
if logger is None:
logger = mlog.initLogger(__name__)

if smdim == 1:
bp = readSCOutBeamProperty(fn, scrnout, logger=logger)
return bp


linesRead = []
keywordsIndex = {}

Expand Down Expand Up @@ -241,49 +426,7 @@ def readSCOutHomo(fn, smdim):

# ems = 6 # effective matrix size

if smdim == 1:
ems = 4
if 'The Effective Stiffness Matrix' in keywordsIndex.keys():
indexStiffness = keywordsIndex['The Effective Stiffness Matrix']
sm.eff_props[1]['stiffness']['classical'] = utl.textToMatrix(
linesRead[indexStiffness + 2:indexStiffness + 2 + ems])
# else:
# print('No effective stiffness matrix found.')

if 'The Effective Compliance Matrix' in keywordsIndex.keys():
indexCompliance = keywordsIndex['The Effective Compliance Matrix']
sm.eff_props[1]['compliance']['classical'] = utl.textToMatrix(
linesRead[indexCompliance + 2:indexCompliance + 2 + ems])
# else:
# print('No effective compliance matrix found.')

if 'Timoshenko Stiffness' in keywordsIndex.keys():
indexStiffness = keywordsIndex['Timoshenko Stiffness']
sm.eff_props[1]['stiffness']['refined'] = utl.textToMatrix(
linesRead[indexStiffness + 2:indexStiffness + 8])
# else:
# print('No effective timoshenko stiffness matrix found.')

if 'Timoshenko Compliance' in keywordsIndex.keys():
indexCompliance = keywordsIndex['Timoshenko Compliance']
sm.eff_props[1]['compliance']['refined'] = utl.textToMatrix(
linesRead[indexCompliance + 2:indexCompliance + 8])
# else:
# print('No effective timoshenko compliance matrix found.')

if 'Shear Center Location' in keywordsIndex.keys():
index_sc = keywordsIndex['Shear Center Location']
sm.eff_props[1]['shearcenter'] = list(map(
float, linesRead[index_sc+2].strip().split()
))
# else:
# print('No shear center location found.')

line = linesRead[keywordsIndex['Effective Density']]
line = line.strip().split('=')
sm.eff_props[1]['density'] = float(line[-1].strip())

elif smdim == 2:
if smdim == 2:
ems = 6

try:
Expand Down Expand Up @@ -361,6 +504,13 @@ def readSCOutHomo(fn, smdim):
return sm









def readSCOutFailure(fn_swiftcomp_in, failure_analysis):
fn_swiftcomp_in += '.fi'
lines = []
Expand Down Expand Up @@ -443,6 +593,13 @@ def writeSCNodes(sg, fobj, sfi, sff):
return









def writeSCElements(sg, fobj, sfi):
for eid in sg.elementids1d:
elem = np.zeros(7, dtype=int)
Expand Down Expand Up @@ -483,19 +640,40 @@ def writeSCElements(sg, fobj, sfi):
return









def writeSCElementOrientations(sg, fobj, sfi, sff):
for eid, orient in sg.elem_orient.items():
fobj.write(sfi.format(eid))
utl.writeFormatFloats(fobj, np.hstack(orient))
return









def writeSCMOCombos(sg, fobj, sfi, sff):
for cid, combo in sg.mocombos.items():
fobj.write((sfi + sfi + sff + '\n').format(cid, combo[0], combo[1]))
return









def writeSCMaterials(sg, fobj, sfi, sff):
for mid, m in sg.materials.items():
# itype = 0
Expand Down Expand Up @@ -523,6 +701,13 @@ def writeSCMaterials(sg, fobj, sfi, sff):
return









def writeSCInH(sg, fn, sfi, sff):
with open(fn, 'w') as fobj:
# Extra inputs for dimensionally reducible structures
Expand Down Expand Up @@ -586,6 +771,13 @@ def writeSCInH(sg, fn, sfi, sff):
fobj.write('\n')









def writeSCInD(sg, fn, sfi, sff):
with open(fn, 'w') as fobj:
utl.writeFormatFloats(fobj, sg.global_displacements, sff[2:-1])
Expand All @@ -594,6 +786,13 @@ def writeSCInD(sg, fn, sfi, sff):
utl.writeFormatFloats(fobj, sg.global_loads, sff[2:-1])









def writeSCInF(sg, fn, sfi, sff):
with open(fn, 'w') as fobj:
# Addtional material properties
Expand All @@ -615,6 +814,13 @@ def writeSCInF(sg, fn, sfi, sff):
utl.writeFormatFloats(fobj, sg.global_loads, sff[2:-1])









def writeSCIn(sg, fn, analysis='h'):
""" Write SG input files for SwiftComp
Expand Down
Loading

0 comments on commit bf0338e

Please sign in to comment.