def readPBARL(self, data): """ PBARL(9102,91,52) - the marker for Record 12 """ validTypes = { "ROD": 1, "TUBE": 2, "I": 6, "CHAN": 4, "T": 4, "BOX": 4, "BAR": 2, "CROSS": 4, "H": 4, "T1": 4, "I1": 4, "CHAN1": 4, "Z": 4, "CHAN2": 4, "T2": 4, "BOX1": 6, "HEXA": 3, "HAT": 4, "HAT1": 5, "DBOX": 10, # was 12 } # for GROUP="MSCBML0" #print "reading PBARL" while len( data ) >= 28: # 7*4 - ROD - shortest entry...could be buggy... # TODO fix this eData = data[:28] data = data[28:] out = unpack('2i8s8sf', eData) (pid, mid, group, Type, value) = out Type = Type.strip() dataIn = [pid, mid, group, Type, value] #print "pid=%s mid=%s group=|%s| Type=|%s| value=%s" %(pid,mid,group,Type,value) expectedLength = validTypes[Type] iFormat = 'f' * expectedLength dataIn += list(unpack(iFormat, data[:expectedLength * 4])) data = data[expectedLength * 4 + 4:] # TODO why do i need the +4??? #print "len(out) = ",len(out) #print "PBARL = ",dataIn prop = PBARL(None, dataIn) self.addOp2Property(prop)
def test_pbarl_1(self): """tests the PBARL""" model = BDF(log=None, debug=False) pid = 4 mid = 40 group = 'group' Type = 'bad_type' dim = 42 nsm = 0.5 pbarl = PBARL(pid, mid, Type, dim, group=group, nsm=nsm, comment='comment') with self.assertRaises(ValueError): # Type pbarl.validate() pbarl.Type = 'TUBE' with self.assertRaises(TypeError): # dim pbarl.validate() pbarl.dim = [20.] with self.assertRaises(RuntimeError): pbarl.validate() pbarl.dim = [2., 1.] #with self.assertRaises(ValueError): #pbarl.validate() #pbarl.group = 'MSCBMLO' pbarl.validate() str(pbarl) pbarl.write_card(size=8, is_double=False) pbarl.write_card(size=16, is_double=False) pbarl.write_card(size=16, is_double=True) model.properties[pid] = pbarl nid1 = 52 xyz1 = [0., 0., 0.] model.nodes[nid1] = GRID(nid1, cp=0, xyz=xyz1) nid2 = 53 xyz2 = [1., 0., 0.] model.nodes[nid2] = GRID(nid2, cp=0, xyz=xyz2) E = 30.0e7 G = None nu = 0.3 mat = MAT1(mid, E, G, nu, rho=1.0) model.materials[mid] = mat eid = 42 x = None g0 = None cbar = CBAR(eid, pid, [nid1, nid2], x, g0, offt='GGG', pa=0, pb=0, wa=None, wb=None, comment='') cbar.validate() model.elements[eid] = cbar pbarl._verify(xref=False) model.validate() model.cross_reference() pbarl._verify(xref=True) assert allclose(cbar.Mass(), 9.9247779608), cbar.Mass() mat.rho = 0. assert allclose(cbar.Mass(), 0.5), cbar.Mass()
def _read_pbarl(self, data, n): """ PBARL(9102,91,52) - the marker for Record 12 TODO: buggy """ valid_types = { "ROD": 1, "TUBE": 2, "I": 6, "CHAN": 4, "T": 4, "BOX": 4, "BAR": 2, "CROSS": 4, "H": 4, "T1": 4, "I1": 4, "CHAN1": 4, "Z": 4, "CHAN2": 4, "T2": 4, "BOX1": 6, "HEXA": 3, "HAT": 4, "HAT1": 5, "DBOX": 10, # was 12 #'MLO TUBE' : 2, } # for GROUP="MSCBML0" ntotal = 28 # 7*4 - ROD - shortest entry...could be buggy... # TODO fix this s = Struct(b(self._endian + '2i8s8sf')) #nentries = (len(data) - n) // ntotal #print(self.show_ndata(80)) ndata = len(data) while ndata - n > ntotal: edata = data[n:n+28] n += 28 out = s.unpack(edata) (pid, mid, group, Type, value) = out Type = Type.strip().decode('latin1') group = group.strip().decode('latin1') data_in = [pid, mid, group, Type, value] #print("pid=%s mid=%s group=%r Type=%r value=%s" %(pid, mid, group, Type, value)) if pid > 100000000: raise RuntimeError('bad parsing...') expected_length = valid_types[Type] iformat = b'%if' % expected_length ndelta = expected_length * 4 data_in += list(unpack(iformat, data[n:n+ndelta])) # TODO why do i need the +4??? #min_len = expected_length * 4 + 4 #if len(data) #data = data[n + expected_length * 4 + 4:] n += ndelta #prin( "len(out) = ",len(out))) #print("PBARL = %s" % data_in) prop = PBARL.add_op2_data(data_in) # last value is nsm self._add_op2_property(prop) #print(self.show_data(data[n-8:-100])) break self._increase_card_count('PBARL') #assert len(data) == n return n
def test_bar_area(self): """tests the PBARL""" model = BDF(log=None, debug=False) mid = 40 group = 'group' nsm = 0.0 shape_dims_area = [ # name, dims, area, i1 ('ROD', [2.], 4. * np.pi, 0.), ('TUBE', [5., 1.], 24. * np.pi, 0.), ('BAR', [2., 3.], 6., 0.), ('BOX', [2., 3., 0.5, 0.5], 4., 0.), ('L', [2., 3., 1., 1.], 4., 0.), ('CHAN', [10., 10., 1., 1.], 28., None), ('CHAN1', [9., 0.1, 8., 10.], 19., None), ('CHAN2', [1, 1., 9., 10.], 26., None), # new ('I', [1., 1., 1., 0.1, 0.1, 0.1], 0.28, None), ('I1', [0.1, 1., 0.5, 1.], 1.05, None), ('H', [1.0, 0.1, 1.0, 0.1], 0.2, None), ('Z', [0.5, 0.5, 0.5, 1.], 0.75, None), ('Z', [0.8, 0.5, 0.5, 1.], 0.90, None), ('Z', [0.5, 0.8, 0.5, 1.], 1.05, None), ('Z', [0.5, 0.5, 0.8, 1.], 0.60, None), ('Z', [0.5, 0.5, 0.5, 2.], 1.75, None), ('CHAN', [1., 1., 0.1, 0.1], 0.28, None), ('CHAN1', [0.5, 0.5, 0.5, 1.], 0.75, None), ('CHAN2', [0.1, 0.1, 1., 1.], 0.28, None), ('CROSS', [0.1, 0.1, 1., 0.1], 0.11, None), ('HEXA', [0.1, 1., 1.], 0.90, None), ('HEXA', [0.2, 1., 1.], 0.80, None), ('HEXA', [0.1, 2., 1.], 1.90, None), ('HEXA', [0.1, 1., 2.], 1.80, None), ('HAT', [1., 0.1, 1., 0.1], 0.30, None), ('HAT', [2., 0.1, 1., 0.1], 0.50, None), ('HAT', [1., 0.2, 1., 0.1], 0.56, None), ('HAT', [1., 0.1, 2., 0.1], 0.40, None), ('HAT', [1., 0.1, 1., 0.2], 0.32, None), ('HAT1', [3., 1., 1., 0.1, 0.1], 0.76, None), ('HAT1', [3., 2., 1., 0.1, 0.1], 0.96, None), ('HAT1', [3., 1., 2., 0.1, 0.1], 0.76, None), ('HAT1', [3., 1., 1., 0.2, 0.1], 1.18, None), ('HAT1', [3., 1., 1., 0.1, 0.2], 1.04, None), ('T', [10., 10., 3., 0.5], 33.5, None), ('T2', [10., 5., 0.5, 2.0], 14., None), # ball,hall,tflange,tweb ('T', [1., 1., 0.1, 0.1], 0.19, None), ('T1', [1., 1., 0.1, 0.1], 0.20, None), ('T2', [1., 1., 0.1, 0.1], 0.19, None), ('DBOX', [2., 1., 1., 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, ], 0.64, None), ('DBOX', [2., 2., 1., 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, ], 0.94, None), ('DBOX', [2., 1., 2., 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, ], 0.64, None), ('DBOX', [2., 1., 1., 0.2, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, ], 0.72, None), ('DBOX', [2., 1., 1., 0.1, 0.2, 0.1, 0.1, 0.1, 0.1, 0.1, ], 0.72, None), ('DBOX', [2., 1., 1., 0.1, 0.1, 0.2, 0.1, 0.1, 0.1, 0.1, ], 0.72, None), ('DBOX', [2., 1., 1., 0.1, 0.1, 0.1, 0.2, 0.1, 0.1, 0.1, ], 0.725, None), ('DBOX', [2., 1., 1., 0.1, 0.1, 0.1, 0.1, 0.2, 0.1, 0.1, ], 0.725, None), ('DBOX', [2., 1., 1., 0.1, 0.1, 0.1, 0.1, 0.1, 0.2, 0.1, ], 0.725, None), ('DBOX', [2., 1., 1., 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.2, ], 0.725, None), ] pid = 1 for bar_type, dims, areai, i1 in shape_dims_area: pbarl = PBARL(pid, mid, bar_type, dims, group=group, nsm=nsm, comment='comment') pbarl.validate() area2 = pbarl.Area() if i1 is not None: pbarl.I1() pbarl.I2() pbarl.I12() assert np.allclose(areai, area2), 'bar_type=%r dims=%s area=%s area_expected=%s' % (bar_type, dims, area2, areai) pid += 1
def _readPBARL(self, data, n): """ PBARL(9102,91,52) - the marker for Record 12 TODO: buggy """ validTypes = { "ROD": 1, "TUBE": 2, "I": 6, "CHAN": 4, "T": 4, "BOX": 4, "BAR": 2, "CROSS": 4, "H": 4, "T1": 4, "I1": 4, "CHAN1": 4, "Z": 4, "CHAN2": 4, "T2": 4, "BOX1": 6, "HEXA": 3, "HAT": 4, "HAT1": 5, "DBOX": 10, # was 12 #'MLO TUBE' : 2, } # for GROUP="MSCBML0" ntotal = 28 # 7*4 - ROD - shortest entry...could be buggy... # TODO fix this s = Struct(b'2i8s8sf') #nentries = (len(data) - n) // ntotal #print(self.show_ndata(80)) ndata = len(data) while ndata - n > ntotal: eData = data[n:n + 28] n += 28 out = s.unpack(eData) (pid, mid, group, Type, value) = out Type = Type.strip() dataIn = [pid, mid, group, Type, value] print("pid=%s mid=%s group=%r Type=%r value=%s" % (pid, mid, group, Type, value)) if pid > 100000000: raise RuntimeError('bad parsing...') expectedLength = validTypes[Type] iFormat = b'%if' % expectedLength ndelta = expectedLength * 4 dataIn += list(unpack(iFormat, data[n:n + ndelta])) # TODO why do i need the +4??? #min_len = expectedLength * 4 + 4 #if len(data) #data = data[n + expectedLength * 4 + 4:] n += ndelta #prin( "len(out) = ",len(out))) #print("PBARL = %s" % dataIn) prop = PBARL(None, dataIn) # last value is nsm self.addOp2Property(prop) #print(self.show_data(data[n-8:-100])) break self._increase_card_count('PBARL') #assert len(data) == n return len(data)