From 5309c7410cbdc6d5813ee612c26125c755afbcaa Mon Sep 17 00:00:00 2001 From: Su Tian Date: Fri, 30 Jul 2021 15:00:39 -0400 Subject: [PATCH] 0730 --- msgpi/io/iosc.py | 172 ++++++++++++++++++++++++++++++++--------------- msgpi/sg.py | 122 ++++++++++++++++++++++++++------- 2 files changed, 215 insertions(+), 79 deletions(-) diff --git a/msgpi/io/iosc.py b/msgpi/io/iosc.py index 7c88f58..6f1e843 100644 --- a/msgpi/io/iosc.py +++ b/msgpi/io/iosc.py @@ -377,6 +377,122 @@ def readSCOutBeamProperty(fn, scrnout=True, logger=None): +def readSCOutShellProperty(fn, scrnout=True, logger=None): + if logger is None: + logger = mlog.initLogger(__name__) + + # sm = sgm.MaterialSection(smdim = 1) + sp = sgm.ShellProperty() + + linesRead = [] + keywordsIndex = {} + + with open(fn, 'r') as fin: + ln = -1 + prop_plane = None + 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: + sp.xm3 = float(line.split()[-1]) + elif 'i11' in line: + sp.i11 = float(line.split()[-1]) + sp.i22 = sp.i11 + + + # Structural properties + # --------------------- + + elif 'Effective Stiffness Matrix' in line: + keywordsIndex['stff'] = ln + elif 'Effective Compliance Matrix' in line: + keywordsIndex['cmpl'] = ln + + elif 'In-Plane' in line: + prop_plane = 'in' + elif 'Flexural' in line: + prop_plane = 'out' + + elif 'E1' in line: + if prop_plane == 'in': + sp.e1_i = float(line.split('=')[-1]) + elif prop_plane == 'out': + sp.e1_o = float(line.split('=')[-1]) + elif 'E2' in line: + if prop_plane == 'in': + sp.e2_i = float(line.split('=')[-1]) + elif prop_plane == 'out': + sp.e2_o = float(line.split('=')[-1]) + elif 'G12' in line: + if prop_plane == 'in': + sp.g12_i = float(line.split('=')[-1]) + elif prop_plane == 'out': + sp.g12_o = float(line.split('=')[-1]) + elif 'nu12' in line: + if prop_plane == 'in': + sp.nu12_i = float(line.split('=')[-1]) + elif prop_plane == 'out': + sp.nu12_o = float(line.split('=')[-1]) + elif 'eta121' in line: + if prop_plane == 'in': + sp.eta121_i = float(line.split('=')[-1]) + elif prop_plane == 'out': + sp.eta121_o = float(line.split('=')[-1]) + elif 'eta122' in line: + if prop_plane == 'in': + sp.eta122_i = float(line.split('=')[-1]) + elif prop_plane == 'out': + sp.eta122_o = float(line.split('=')[-1]) + + + ln = keywordsIndex['mass'] + sp.mass = utl.textToMatrix(linesRead[ln + 2:ln + 8]) + + try: + ln = keywordsIndex['stff'] + sp.stff = utl.textToMatrix(linesRead[ln + 2:ln + 6]) + except KeyError: + if scrnout: + print('No classical stiffness matrix found.') + else: + pass + + try: + ln = keywordsIndex['cmpl'] + sp.cmpl = utl.textToMatrix(linesRead[ln + 2:ln + 6]) + except KeyError: + if scrnout: + print('No classical flexibility matrix found.') + else: + pass + + + + return sp + + + + + + + + + def readSCOutHomo(fn, smdim, scrnout=True, logger=None): """Read SwiftComp homogenization results. @@ -645,13 +761,6 @@ def writeSCNodes(sg, fobj, sfi, sff): return - - - - - - - def writeSCElements(sg, fobj, sfi): for eid in sg.elementids1d: elem = np.zeros(7, dtype=int) @@ -692,13 +801,6 @@ 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)) @@ -706,26 +808,12 @@ def writeSCElementOrientations(sg, fobj, sfi, sff): 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 @@ -753,13 +841,6 @@ 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 @@ -823,13 +904,6 @@ 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]) @@ -838,13 +912,6 @@ 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 @@ -866,13 +933,6 @@ 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 diff --git a/msgpi/sg.py b/msgpi/sg.py index 1be789f..7cf86db 100644 --- a/msgpi/sg.py +++ b/msgpi/sg.py @@ -432,8 +432,74 @@ def offsetBeamRefCenter(self, offset_x2, offset_x3): class ShellProperty(MaterialSection): + """A plate/shell property class (smdim = 2) """ - """ + def __init__(self): + MaterialSection.__init__(self, smdim=1) + + self.mass = [] + + self.xm3 = None + + self.i11 = None + self.i22 = None + + self.stff = [] + self.cmpl = [] + + self.e1_i = None + self.e2_i = None + self.g12_i = None + self.nu12_i = None + self.eta121_i = None + self.eta122_i = None + + self.e1_o = None + self.e2_o = None + self.g12_o = None + self.nu12_o = None + self.eta121_o = None + self.eta122_o = None + + def print(self): + fmt = '20.10E' + print('Summary') + print() + print('Effective Mass Matrix') + print(mutil.matrixToString(self.mass, fmt=fmt)) + print() + print('The Mass Center') + print(f'({self.xm3:{fmt}})') + print() + print(f'Mass moments of inertia i11 = i22 = {self.i11:{fmt}}') + + print() + print('The Effective Stiffness Matrix') + print(mutil.matrixToString(self.stff, fmt=fmt)) + print('The Effective Compliance Matrix') + print(mutil.matrixToString(self.cmpl, fmt=fmt)) + print() + print('In-Plane Properties') + print(f'E1 = {self.e1_i:{fmt}}') + print(f'E2 = {self.e2_i:{fmt}}') + print(f'G12 = {self.g12_i:{fmt}}') + print(f'nu12 = {self.nu12_i:{fmt}}') + print(f'eta121 = {self.eta121_i:{fmt}}') + print(f'eta122 = {self.eta122_i:{fmt}}') + print(f'E1 = {self.e1_i:{fmt}}') + print(f'E2 = {self.e2_i:{fmt}}') + print(f'G12 = {self.g12_i:{fmt}}') + print(f'nu12 = {self.nu12_i:{fmt}}') + print(f'eta121 = {self.eta121_i:{fmt}}') + print(f'eta122 = {self.eta122_i:{fmt}}') + print() + print('Flexural Properties') + print(f'E1 = {self.e1_o:{fmt}}') + print(f'E2 = {self.e2_o:{fmt}}') + print(f'G12 = {self.g12_o:{fmt}}') + print(f'nu12 = {self.nu12_o:{fmt}}') + print(f'eta121 = {self.eta121_o:{fmt}}') + print(f'eta122 = {self.eta122_o:{fmt}}') @@ -449,6 +515,11 @@ class MaterialProperty(MaterialSection): def __init__(self, name=''): MaterialSection.__init__(self, 3) self.name = name + + #: int: (continuum model) Isotropy type. + #: Isotropic (0), orthotropic (1), anisotropic (2). + self.anisotropy = None + self.e1 = None self.e2 = None self.e3 = None @@ -460,7 +531,12 @@ def __init__(self, name=''): self.nu23 = None def assignConstants(self, consts): - if len(consts) == 9: + if len(consts) == 2: + self.anisotropy = 0 + self.e1 = consts[0] + self.nu12 = consts[1] + elif len(consts) == 9: + self.anisotropy = 1 self.e1, self.e2, self.e3 = consts[:3] self.g12, self.g13, self.g23 = consts[3:6] self.nu12, self.nu13, self.nu23 = consts[6:] @@ -487,7 +563,7 @@ class StructureGene(object): Beam (1), plate/shell (2), 3D continuum (3). """ - def __init__(self, name, sgdim, smdim): + def __init__(self, name, sgdim, smdim=None): #: str: Name of the SG. self.name = name #: int: Dimension of the SG. @@ -831,21 +907,21 @@ def __writeSCMaterials(self, fobj, sfi, sff): # itype = 1 # elif m.type == 'anisotropic': # itype = 2 - mp = m.eff_props[3] - ioutil.writeFormatIntegers(fobj, (mid, mp['type'], 1)) - ioutil.writeFormatFloats(fobj, (0, mp['density'])) - if mp['type'] == 0: - mpc = mp['constants'] - ioutil.writeFormatFloats(fobj, [mpc['e'], mpc['nu']]) - elif mp['type'] == 1: - mpc = mp['constants'] - ioutil.writeFormatFloats(fobj, [mpc['e1'], mpc['e2'], mpc['e3']]) - ioutil.writeFormatFloats(fobj, [mpc['g12'], mpc['g13'], mpc['g23']]) - ioutil.writeFormatFloats(fobj, [mpc['nu12'], mpc['nu13'], mpc['nu23']]) - elif mp['type'] == 2: + # mp = m.eff_props[3] + ioutil.writeFormatIntegers(fobj, (mid, m.anisotropy, 1)) + ioutil.writeFormatFloats(fobj, (0, m.density)) + if m.anisotropy == 0: + # mpc = m.constants + ioutil.writeFormatFloats(fobj, [m.e1, m.nu12]) + elif m.anisotropy == 1: + # mpc = m.constants + ioutil.writeFormatFloats(fobj, [m.e1, m.e2, m.e3]) + ioutil.writeFormatFloats(fobj, [m.g12, m.g13, m.g23]) + ioutil.writeFormatFloats(fobj, [m.nu12, m.nu13, m.nu23]) + elif m.anisotropy == 2: for i in range(6): for j in range(i, 6): - fobj.write(sff.format(mp['stiffness'][i][j])) + fobj.write(sff.format(m.stiffness[i][j])) fobj.write('\n') fobj.write('\n') return @@ -894,24 +970,24 @@ def writeSCInH(self, fn, sfi, sff): fobj.write('\n') # Nodal coordinates - self.__writeSCNodes(self, fobj, sfi, sff) + self.__writeSCNodes(fobj, sfi, sff) fobj.write('\n') # Element connectivities - self.__writeSCElements(self, fobj, sfi) + self.__writeSCElements(fobj, sfi) fobj.write('\n') if self.trans_element != 0: - self.__writeSCElementOrientations(self, fobj, sfi, sff) + self.__writeSCElementOrientations(fobj, sfi, sff) fobj.write('\n') # Material-orientation combinations if len(self.mocombos) > 0: - self.__writeSCMOCombos(self, fobj, sfi, sff) + self.__writeSCMOCombos(fobj, sfi, sff) fobj.write('\n') # Material - self.__writeSCMaterials(self, fobj, sfi, sff) + self.__writeSCMaterials(fobj, sfi, sff) fobj.write('\n') # Omega @@ -986,9 +1062,9 @@ def writeSCIn(self, fn, analysis='h'): sff = '{:16.6E}' if 'h' in analysis: - self.writeSCInH(self, fn, sfi, sff) + self.writeSCInH(fn, sfi, sff) elif ('d' in analysis) or ('l' in analysis): - self.writeSCInD(self, fn, sfi, sff) + self.writeSCInD(fn, sfi, sff) return fn