Skip to content

Commit

Permalink
codacy work
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveDoyle2 committed Apr 1, 2019
1 parent 9e858b1 commit 843170d
Show file tree
Hide file tree
Showing 15 changed files with 380 additions and 321 deletions.
52 changes: 29 additions & 23 deletions pyNastran/bdf/bdf_interface/dev/dmap.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,4 @@
from __future__ import print_function
lines = [
"ASSIGN OUTPUT2='myMatrix.op2',",
' UNIT=15',
'$',
'SOL 100',
'DIAG 8,44',
'COMPILE USERDMAP',
'ALTER 2',
'DMIIN DMI,DMINDX/A,B,MYDOF,,,,,,,/ $',
'MPYAD A,B,/ATB/1///$',
'MPYAD B,A,/BTA/1///$',
'OUTPUT2 A,B,ATB,BTA,MYDOF//0/15$',
'CEND',
]
#with open('isat.bdf', 'r') as f:
#lines = f.readlines()

def read_dmap(lines):
lines2 = []
Expand Down Expand Up @@ -69,7 +53,7 @@ def read_dmap(lines):
line = line.replace(' =', '=').replace('= ', '=')
sline = line.split()
if len(sline) == 3:
assign, output, unit = sline
unused_assign, output, unit = sline
word, unit_num = unit.split('=')
output, fname = output.split('=')
assert word == 'UNIT', word
Expand Down Expand Up @@ -100,16 +84,16 @@ def read_dmap(lines):
#
# works for
# TYPE PARAM,,CS,Y,ALPAH=1.
base, NDDL, Type, y, word_val = sline
unused_base, unused_NDDL, unused_Type, unused_y, word_val = sline
param_name, default_value = word_val.split('=')
code += 'model.params[%r].set_value(%s)\n' % (param_name, default_value)

elif line.startswith('LAMX '):
sline = line[5:].split('/')
print('sline =', sline)
if len(sline) == 4:
pre, b, c, resflag = sline
resflg = int(resflag)
pre, unused_b, unused_c, resflag = sline
unused_resflg = int(resflag)
if pre.startswith('FREQMASS,'):
raise NotImplementedError('FREQMASS')
elif pre.startswith(',,LAMA'):
Expand All @@ -135,7 +119,7 @@ def read_dmap(lines):
option = int(sline[1])
if option == 6:
sline = sline[2:]
code += space + '%s = \n'
code += spaces + '%s = \n'
else:
raise NotImplementedError(option)

Expand All @@ -153,7 +137,7 @@ def read_dmap(lines):
pass
elif line.startswith('DMIIN DMI,DMINDX/'):
sline = line.split('/')
pre, data, post = sline
pre, data, unused_post = sline
matrices = data.replace(' ', '').rstrip(',')
matrices_to_load = matrices.split(',')
print('matrices_to_load =', matrices_to_load)
Expand Down Expand Up @@ -185,7 +169,7 @@ def read_dmap(lines):
elif line.startswith('OUTPUT2 '):
sline = line[8:].replace(' ', '').split('/')
if len(sline) == 4:
output_matrices, dunno, method, unit_num = sline
output_matrices, unused_dunno, unused_method, unit_num = sline
matrix_names = output_matrices.split(',')
code += '\n'
for name in matrix_names:
Expand All @@ -204,3 +188,25 @@ def read_dmap(lines):

print('-----------')
print(code)

def main():
lines = [
"ASSIGN OUTPUT2='myMatrix.op2',",
' UNIT=15',
'$',
'SOL 100',
'DIAG 8,44',
'COMPILE USERDMAP',
'ALTER 2',
'DMIIN DMI,DMINDX/A,B,MYDOF,,,,,,,/ $',
'MPYAD A,B,/ATB/1///$',
'MPYAD B,A,/BTA/1///$',
'OUTPUT2 A,B,ATB,BTA,MYDOF//0/15$',
'CEND',
]
#with open('isat.bdf', 'r') as f:
#lines = f.readlines()
read_dmap(lines)

if __name__ == '__main__': # pragma: no cover
main()
35 changes: 19 additions & 16 deletions pyNastran/bdf/bdf_interface/dev/matrices.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""
from __future__ import print_function
import numpy as np
import scipy as sp

def _lambda_1d(v1):
"""
Expand Down Expand Up @@ -38,14 +39,21 @@ def triple(A, B):
"""
return np.einsum('ia,aj,ka->ijk', A, B, A)

def get_sub_eids(all_eids, eids):
"""supports limiting the element/mass ids"""
eids = np.array(eids)
ieids = np.searchsorted(all_eids, eids)
eids2 = eids[all_eids[ieids] == eids]
return eids2

def make_mass_matrix(model, reference_point):
"""
Performs an accurate mass calculation
..todo:: not anywhere close to being done
..todo:: doesn't support SPOINTs/EPOINTs
"""
icd_transform, icp_transform, xyz_cp, nid_cp_cd = model.get_displacement_index_xyz_cp_cd(
unused_icd_transform, icp_transform, xyz_cp, nid_cp_cd = model.get_displacement_index_xyz_cp_cd(
fdtype='float64', idtype='int32', sort_ids=True)
xyz_cid0 = model.transform_xyzcp_to_xyz_cid(
xyz_cp, icp_transform, cid=0, in_place=False, atol=1e-6)
Expand All @@ -67,7 +75,6 @@ def make_mass_matrix(model, reference_point):
i += 6
nrows = len(components)

import scipy as sp
mass = sp.sparse.dok_matrix((nrows, nrows), dtype=np.float64)

no_mass = [
Expand All @@ -82,12 +89,7 @@ def make_mass_matrix(model, reference_point):
'CORD3G', 'CONV', 'CONVM', 'CSET', 'CSET1', 'CLOAD',
'CHBDYG', 'CHBDYE', 'CHBDYP',
]
def get_sub_eids(all_eids, eids):
"""supports limiting the element/mass ids"""
eids = np.array(eids)
ieids = np.searchsorted(all_eids, eids)
eids2 = eids[all_eids[ieids] == eids]
return eids2
all_eids = np.array(list(model.elements.keys()), dtype='int32')

#etypes_skipped = set([])
for etype, eids in model._type_to_id_map.items():
Expand Down Expand Up @@ -117,7 +119,7 @@ def get_sub_eids(all_eids, eids):

inid1 = inids[n1]
inid2 = inids[n2]
v1 = xyz[inid2, :] - xyz[inid1, :]
v1 = xyz_cid0[inid2, :] - xyz_cid0[inid1, :]
length = np.linalg.norm(v1)
mpl = elem.MassPerLength()
massi = mpl * length / 2.
Expand All @@ -140,7 +142,7 @@ def get_sub_eids(all_eids, eids):
for eid in eids2:
elem = model.masses[eid]
massi = elem.Mass()
rx, ry, rz = elem.X
unused_rx, unused_ry, unused_rz = elem.X
mass_mat[0, 0] = massi
mass_mat[1, 1] = massi
mass_mat[2, 2] = massi
Expand Down Expand Up @@ -318,7 +320,8 @@ def make_gpwg(Mgg, reference_point, xyz_cid0, grid_cps, coords, log):
I21 = I12 = -Mr[0, 1] - Mz * xz * yz
I13 = I31 = -Mr[0, 2] - My * xy * zy
I22 = Mr[1, 1] - Mz * xz ** 2 - Mx * zx ** 2
I32 = I23 = -Mr[1, 2] - Mx * yx * zx
I23 = -Mr[1, 2] - Mx * yx * zx
I32 = I23
I33 = Mr[2, 2] - Mx * yx ** 2 - My * xy ** 2
II = np.array([
[I11, I12, I13],
Expand All @@ -333,7 +336,7 @@ def make_gpwg(Mgg, reference_point, xyz_cid0, grid_cps, coords, log):
# 6. Reverse the sign of the off diagonal terms
np.fill_diagonal(-II, np.diag(II))
#print('I~=\n%s\n' % II)
if nan in II:
if np.nan in II:
Q = np.zeros((3, 3), dtype='float32')
else:
omegaQ, Q = np.linalg.eig(II)
Expand All @@ -351,11 +354,11 @@ def get_Ajj(model, xyz=None):
xyz = {}
for nid, node in model.nodes.items():
xyz[nid] = node.get_position()
for caero_id, caero in model.caeros.items():
centroids = caero.get_centroids()
for unused_caero_id, caero in model.caeros.items():
unused_centroids = caero.get_centroids()

for spline_id, spline in model.splines.items():
spline_nodes = spline.spline_nodes
for unused_spline_id, spline in model.splines.items():
unused_spline_nodes = spline.spline_nodes

Ajj = None
return Ajj
4 changes: 4 additions & 0 deletions pyNastran/bdf/bdf_interface/dev/set_operations.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
defines:
- array2 = intersect1d_multi(array_set, assume_unique=False)
"""
import numpy as np

def intersect1d_multi(array_set, assume_unique=False):
Expand Down
10 changes: 5 additions & 5 deletions pyNastran/bdf/bdf_interface/hdf5_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ def _export_dconstrs(hdf5_file, model, encoding):
ndconadds = len(dconadds)
if ndconadds:
dconadd_group = dconstrs_group.create_group('DCONADD')
keys = np.arange(ndconadds, dtype='int32')
unused_keys = np.arange(ndconadds, dtype='int32')
dconadds0 = dconadds[0]
dconadds0.export_to_hdf5(dconadd_group, dconadds, encoding)

Expand Down Expand Up @@ -859,10 +859,10 @@ def _hdf5_export_object_dict(group, model, name, obj_dict, keys, encoding):
#if isinstance(value, text_type):
#value = value.encode(encoding)

try:
_h5_export_class(sub_group, model, key, value, skip_attrs, encoding, debug=False)
except: # pragma: no cover
raise
#try:
_h5_export_class(sub_group, model, key, value, skip_attrs, encoding, debug=False)
#except: # pragma: no cover
#raise
# for debugging
#sub_group2 = group.create_group('values2')
#_h5_export_class(sub_group2, model, key, value, skip_attrs, encoding, debug=True)
Expand Down
35 changes: 19 additions & 16 deletions pyNastran/bdf/cards/aero/aero.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,8 @@ def object_attributes(self, mode='public', keys_to_skip=None):
if keys_to_skip is None:
keys_to_skip = []
my_keys_to_skip = ['Cis']
return BaseCard.object_attributes(self, mode=mode, keys_to_skip=keys_to_skip+my_keys_to_skip)
return BaseCard.object_attributes(self, mode=mode,
keys_to_skip=keys_to_skip+my_keys_to_skip)

def object_methods(self, mode='public', keys_to_skip=None):
""".. seealso:: `pyNastran.utils.object_methods(...)`"""
Expand Down Expand Up @@ -1378,20 +1379,21 @@ def _get_field_helper(self, n):
"""
if n == 9:
return self.p1[0]
out = self.p1[0]
elif n == 10:
return self.p1[1]
out = self.p1[1]
elif n == 11:
return self.p1[2]
out = self.p1[2]

elif n == 13:
return self.p4[0]
out = self.p4[0]
elif n == 14:
return self.p4[1]
out = self.p4[1]
elif n == 15:
return self.p4[2]
out = self.p4[2]
else:
raise KeyError('Field %r is an invalid CAERO1 entry.' % n)
return out

def _update_field_helper(self, n, value):
"""
Expand Down Expand Up @@ -1666,7 +1668,8 @@ def _init_ids(self, dtype='int32'):

npanels = nchord * nspan
try:
self.box_ids = np.arange(self.eid, self.eid + npanels, dtype=dtype).reshape(nspan, nchord).T
self.box_ids = np.arange(self.eid, self.eid + npanels,
dtype=dtype).reshape(nspan, nchord).T
except OverflowError:
if dtype == 'int64':
# we already tried int64
Expand Down Expand Up @@ -2092,13 +2095,14 @@ def _get_field_helper(self, n):
"""
if n == 9:
return self.p1[0]
out = self.p1[0]
elif n == 10:
return self.p1[1]
out = self.p1[1]
elif n == 11:
return self.p1[2]
out = self.p1[2]
else:
raise KeyError('Field %r is an invalid CAERO2 entry.' % n)
return out

def _update_field_helper(self, n, value):
"""
Expand Down Expand Up @@ -3152,7 +3156,6 @@ class CAERO5(BaseCard):
def _init_from_empty(cls):
eid = 1
pid = 1
ncontrol_surfaces = 1
p1 = [0., 0., 0.]
p4 = [0., 10., 0.]
x12 = 1.
Expand Down Expand Up @@ -4911,10 +4914,10 @@ def safe_cross_reference(self, model, xref_errors):
#def safe_set(self, setg, set_type, self.eid, xref_errors, msg=''):
try:
self.setg_ref = model.Set(self.setg, msg=msg)
try:
self.setg_ref.safe_cross_reference(model, 'Node', msg=msg)
except:
raise
#try:
self.setg_ref.safe_cross_reference(model, 'Node', msg=msg)
#except:
#raise

nnodes = len(self.setg_ref.ids)
if nnodes < 3:
Expand Down
Loading

0 comments on commit 843170d

Please sign in to comment.