Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveDoyle2 committed Apr 3, 2019
1 parent 843170d commit 38a9fa8
Show file tree
Hide file tree
Showing 14 changed files with 160 additions and 58 deletions.
18 changes: 16 additions & 2 deletions pyNastran/bdf/bdf_interface/get_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -1890,7 +1890,8 @@ def get_element_nodes_by_element_type(self, dtype='int32', solids=None):
return self.get_elements_properties_nodes_by_element_type(
dtype=dtype, solids=solids)

def get_elements_properties_nodes_by_element_type(self, dtype='int32', solids=None):
def get_elements_properties_nodes_by_element_type(self, dtype='int32', solids=None,
stop_if_no_eids=True):
# type: (str, Optional[Dict[str, Any]]) -> Any
"""
Gets a dictionary of element type to [eids, pids, node_ids]
Expand Down Expand Up @@ -1943,6 +1944,9 @@ def get_elements_properties_nodes_by_element_type(self, dtype='int32', solids=No
'CQUADX', 'CQUADX4', 'CQUADX8',
'CTETRA', 'CPENTA', 'CHEXA', 'CPYRAM',
'CBUSH', 'CBUSH1D', 'CBUSH2D', 'CFAST', 'CGAP',

# not supported
'GENEL', 'CHBDYG',
]
output = {}

Expand All @@ -1954,12 +1958,15 @@ def get_elements_properties_nodes_by_element_type(self, dtype='int32', solids=No
'CPENTA' : (6, 15),
'CPYRAM' : (5, 13),
}

etypes_found = []
for etype in etypes:
if etype not in self._type_to_id_map:
continue
eids_list = self._type_to_id_map[etype]
if not eids_list:
continue
etypes_found.append(etype)
eids = np.array(eids_list, dtype=dtype)
neids = len(eids)
eid0 = eids[0]
Expand Down Expand Up @@ -2033,7 +2040,14 @@ def get_elements_properties_nodes_by_element_type(self, dtype='int32', solids=No
etype_min = elem.type + str(nnodes_min)
ieids_min = np.array(ieids_min, dtype=dtype)
output[etype_min] = [eids[ieids_min], pids[ieids_min], nids[ieids_min, :nnodes_min]]
assert len(output), 'output is empty...'
if stop_if_no_eids:
msg = (
'get_elements_properties_nodes_by_element_type output is empty; '
'nelements=%s; etypes_found=%s' % (
len(self.elements), etypes_found)) # etypes_found
self.log.warning(msg)
else:
assert len(output), 'get_elements_properties_nodes_by_element_type output is empty...'
return output

#--------------------
Expand Down
41 changes: 32 additions & 9 deletions pyNastran/bdf/bdf_interface/hdf5_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -2111,23 +2111,46 @@ def _put_keys_values_into_dict(model, name, keys, values, cast_int_keys=True):
card_count = model.card_count

# 'dmigs', 'dmiks', 'dmijs', 'dmijis', 'dmis'
if cast_int_keys and name not in ['dscreen', 'dti', 'aecomps']:
if cast_int_keys and name not in ['dscreen', 'dti', 'aecomps', 'seconct', 'sebndry']:
#print('keys =', keys, cast_int_keys, name)
try:
keys = [int(key) for key in keys]
except ValueError: # pragma: no cover
# If this hits, you need probably have a non-integer key
# (e.g., a tuple of 2 ints) and need to skip the above
# caster and figure out the right way to cast it.
#
# This could be a string (in which case you just pass the
# initial check above and then use the normal adder below)
# similar to 'dscreen'.
#
# Another possibility is you have a (int_a, int_b) tuple key.
# Follow the pattern for 'seconct'.
print('name =', name)
print('keys = ', keys)
print('values = ', values)
raise

for key, value in zip(keys, values):
slot[key] = value
#print(' *%s %s' % (value.type, key))
Type = value.type
if Type not in card_count:
card_count[Type] = 0
card_count[Type] += 1
model._type_to_id_map[Type].append(key)
tuple_integer_casts = ('seconct', 'sebndry')
if name in tuple_integer_casts:
for key, value in zip(keys, values):
key = tuple(key)
slot[key] = value
#print(' *%s %s' % (value.type, key))
card_type = value.type
if card_type not in card_count:
card_count[card_type] = 0
card_count[card_type] += 1
model._type_to_id_map[card_type].append(key)
else:
for key, value in zip(keys, values):
slot[key] = value
#print(' *%s %s' % (value.type, key))
card_type = value.type
if card_type not in card_count:
card_count[card_type] = 0
card_count[card_type] += 1
model._type_to_id_map[card_type].append(key)

def _put_keys_values_into_list(model, name, keys, values):
"""add something like an MKAERO1 to a list"""
Expand Down
42 changes: 41 additions & 1 deletion pyNastran/bdf/cards/dmig.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,8 @@ def matrix_type(self):
else:
# technically right, but nulling this will fix bad decks
#self.ncols = blank(card, 8, 'matrix_form=%s; ncol' % self.matrix_form)
raise NotImplementedError('self.matrix_form=%r is not supported' % self.matrix_form)
raise NotImplementedError('%s matrix_form=%r is not supported' % (
self.type, self.matrix_form))
return matrix_type

def finalize(self):
Expand Down Expand Up @@ -1788,6 +1789,45 @@ def finalize(self):
if self.is_complex:
self.Complex = np.asarray(self.Complex)

@property
def matrix_type(self):
"""
gets the matrix type
1 Square matrix (not symmetric)
2 General rectangular matrix
3 Diagonal matrix (M=number of rows, N = 1)
#4 Lower triangular factor
#5 Upper triangular factor
6 Symmetric matrix
8 Identity matrix (M=number of rows, N = M)
"""
if not isinstance(self.matrix_form, integer_types):
msg = 'ifo must be an integer; matrix_form=%r type=%s name=%s' % (
self.matrix_form, type(self.matrix_form), self.name)
raise TypeError(msg)
if isinstance(self.matrix_form, bool):
msg = 'matrix_form must not be a boolean; matrix_form=%r type=%s name=%s' % (
self.matrix_form, type(self.matrix_form), self.name)
raise TypeError(msg)

if self.matrix_form == 1:
matrix_type = 'square'
elif self.matrix_form == 2: # 9 ???
matrix_type = 'rectangular'
elif self.matrix_form == 3:
matrix_type = 'diagonal'
elif self.matrix_form == 6:
matrix_type = 'symmetric'
elif self.matrix_form == 9:
matrix_type = 'identity'
else:
# technically right, but nulling this will fix bad decks
#self.ncols = blank(card, 8, 'matrix_form=%s; ncol' % self.matrix_form)
raise NotImplementedError('%s matrix_form=%r is not supported' % (
self.type, self.matrix_form))
return matrix_type

@property
def is_polar(self):
if self.tin in [1, 2]:
Expand Down
2 changes: 1 addition & 1 deletion pyNastran/bdf/cards/elements/beam.py
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ def _verify(self, xref):
unused_edges = self.get_edge_ids()
if xref: # True
prop = self.pid_ref
assert prop.type in ['PBEAM', 'PBEAML', 'PBCOMP'], prop
assert prop.type in ['PBEAM', 'PBEAML', 'PBCOMP', 'PBMSECT'], prop
mid = self.Mid()
nsm = self.Nsm()
assert isinstance(mid, int), 'mid=%r' % mid
Expand Down
10 changes: 5 additions & 5 deletions pyNastran/bdf/cards/elements/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -1114,10 +1114,10 @@ def add_card(cls, card, comment=''):
assert k is None, k
iz = card_fields.index('Z')
assert card_fields[iz] == 'Z', card_fields
_k_fields, unused_istop = _read_genel_fields_until_char_blank(ucard_fields, iz+1)
for i, _k in enumerate(_k_fields):
ki = double(card, i + iz+1, 'K_%i' % (i + 1))
k.append(ki)
_z_fields, unused_istop = _read_genel_fields_until_char_blank(ucard_fields, iz+1)
for i, _z in enumerate(_z_fields):
zi = double(card, i + iz+1, 'Z_%i' % (i + 1))
z.append(zi)
unused_nblanks = _get_genel_offset(nz)
#kz = z

Expand All @@ -1126,7 +1126,7 @@ def add_card(cls, card, comment=''):
i_s = ucard_fields.index('S')
assert ucard_fields[i_s] == 'S', card_fields
_s_fields, unused_istop = _read_genel_fields_until_char_blank(ucard_fields, i_s+1)
for i, _s in enumerate(_k_fields):
for i, _s in enumerate(_s_fields):
si = double(card, i + i_s+1, 'S_%i' % (i + 1))
s.append(si)
unused_nblanks = _get_genel_offset(ns)
Expand Down
1 change: 1 addition & 0 deletions pyNastran/bdf/cards/properties/bars.py
Original file line number Diff line number Diff line change
Expand Up @@ -1868,6 +1868,7 @@ def __init__(self, pid, mid, form, options, comment=''):

self.mid_ref = None
self.brps_ref = {}
self.outp_ref = None

def validate(self):
assert self.form in ['GS', 'OP', 'CP'], 'pid=%s form=%r' % (self.pid, self.form)
Expand Down
7 changes: 7 additions & 0 deletions pyNastran/bdf/cards/superelements.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ class SEBNDRY(BaseCard):
+---------+-------+-------+-------+-------+-------+-------+-------+-------+
"""
type = 'SEBNDRY'
@classmethod
def _init_from_empty(cls):
seid_a = 1
seid_b = 2
ids = [10, 20, 30]
return SEBNDRY(seid_a, seid_b, ids, comment='')

def __init__(self, seid_a, seid_b, ids, comment=''):
BaseCard.__init__(self)
if comment:
Expand Down
13 changes: 10 additions & 3 deletions pyNastran/bdf/cards/thermal/radiation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"""
from __future__ import (nested_scopes, generators, division, absolute_import,
print_function, unicode_literals)
import warnings

from pyNastran.utils.numpy_utils import integer_types, float_types
from pyNastran.bdf.field_writer_8 import set_blank_if_default, print_card_8
Expand Down Expand Up @@ -45,17 +46,23 @@ def __init__(self, radmid, absorb, emissivity, comment=''):
self.radmid = radmid

self.absorb = absorb
if isinstance(emissivity, float):
if isinstance(emissivity, float_types):
self.emissivity = [emissivity]
else:
self.emissivity = emissivity

def validate(self):
assert self.radmid > 0, str(self)
msg = ''
if self.absorb is not None:
assert 0. <= self.absorb <= 1.0, 'absorb=%s\n%s' % (self.absorb, str(self))
if not 0. <= self.absorb <= 1.0:
msg += 'absorb=%s not in range 0.0 <= absorb <= 1..0\n' % (self.absorb)
for i, emissivityi in enumerate(self.emissivity):
assert 0. <= emissivityi <= 1.0, 'emissivity[%i]=%s\n%s' % (i, emissivityi, str(self))
if not 0. <= emissivityi <= 1.0:
msg += 'emissivity[%i]=%s\n' % (i, emissivityi)
if msg:
warnings.warn(msg + str(self))
raise RuntimeError(msg + str(self))

@classmethod
def add_card(cls, card, comment=''):
Expand Down
35 changes: 17 additions & 18 deletions pyNastran/bdf/mesh_utils/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,21 @@ def create_structured_cquad4s(model, pid,
eid += 1
return nid, eid

def cone3d(model, pid,
xs, radius, nx=5, ntheta=10, endpoint=True):
"""
create a cone by segments in 3d
xs = [0., 1., 2.]
radius = [1., 2., 4.]
>>> cone(model, pid, xs, radius1, radius2)
"""
xstation = np.asarray(xstation)
ystation = np.zeros(xstation.shape)
zstation = np.zeros(xstation.shape)
aspect_ratio = 1.0
xyz_elems = create_axisymmetric_body(
nx, aspect_ratio,
xstation, ystation, zstation, radii,
p1, dy, dz)
return
#def cone3d(model, pid,
#xs, radius, nx=5, ntheta=10, endpoint=True):
#"""
#create a cone by segments in 3d

#xs = [0., 1., 2.]
#radius = [1., 2., 4.]
#>>> cone(model, pid, xs, radius1, radius2)
#"""
#xstation = np.asarray(xstation)
#ystation = np.zeros(xstation.shape)
#zstation = np.zeros(xstation.shape)
#aspect_ratio = 1.0
#xyz_elems = create_axisymmetric_body(
#nx, aspect_ratio,
#xstation, ystation, zstation, radii,
#p1, dy, dz)
#return
4 changes: 4 additions & 0 deletions pyNastran/converters/avl/avl.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ def __init__(self, log=None, debug=False):
self.zref = 0.
self.cd0 = 0.
self.sections = []
self.surfaces = None
self.sym_iy = None
self.sym_iz = None
self.symz = None

def read_avl(self, avl_filename):
"""only the first 4 chancters are read...not in this reader"""
Expand Down
4 changes: 1 addition & 3 deletions pyNastran/converters/nastran/nastran_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,7 @@

IS_TESTING = 'test' in sys.argv[0]
class NastranIO(NastranGuiResults, NastranGeometryHelper):
"""
Defines the GUI class for Nastran.
"""
"""Defines the GUI class for Nastran."""
def __init__(self):
super(NastranIO, self).__init__()
self.nid_release_map = {}
Expand Down
20 changes: 12 additions & 8 deletions pyNastran/converters/panair/panair_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@


class PanairIO(object):
"""Defines the GUI class for Panair."""
def __init__(self, gui):
self.gui = gui
self.colormap = 'viridis'
self.elements = None

def get_panair_wildcard_geometry_results_functions(self):
data = ('Panair',
Expand Down Expand Up @@ -103,7 +105,7 @@ def clear_panair(self):
del self.elements

def _fill_panair_geometry_case(self, cases, ID, nodes, elements, regions,
kt, cp_norm, loads):
kt, cp_norm, unused_loads):
self.elements = elements
colormap = 'jet' # self.colormap
nnids = nodes.shape[0]
Expand Down Expand Up @@ -292,17 +294,19 @@ def load_panair_results(self, panair_filename):

if os.path.exists(panair_out_filename):
out = read_panair_out(panair_out_filename, log=self.gui.log)
alphas = geom_model.alphas
betas = geom_model.betas
unused_alphas = geom_model.alphas
unused_betas = geom_model.betas
icase, out_form = add_networks(out.networks, out.headers, is_beta0,
ID, icase, cases, geom_model, nelements, colormap=colormap)
ID, icase, cases, geom_model, nelements,
self.gui.log, colormap=colormap)
assert len(out_form) > 0, out_form
form.append(('Out: Mach=%s' % mach, None, out_form))

if os.path.exists(ft13_filename):
out.read_ft13(ft13_filename)
icase, ft13_form = add_networks(out.networks_ft13, out.headers_ft13, is_beta0,
ID, icase, cases, geom_model, nelements, colormap=colormap)
ID, icase, cases, geom_model, nelements,
self.gui.log, colormap=colormap)
assert len(ft13_form) > 0, ft13_form
form.append(('Ft13: Mach=%s' % mach, None, ft13_form))

Expand All @@ -311,12 +315,12 @@ def load_panair_results(self, panair_filename):
self.gui._finish_results_io2(model_name, form, cases)

def add_networks(out_networks, out_headers, is_beta0,
ID, icase, cases, geom_model, nelements, colormap='jet'):
ID, icase, cases, geom_model, nelements, log, colormap='jet'):
out_form = []
nsolutions = len(out_networks)
unused_nsolutions = len(out_networks)
for isolution, networks in sorted(out_networks.items()):
if networks == {}:
self.log.info('skipping isolution=%s' % (isolution))
log.info('skipping isolution=%s' % (isolution))
continue
print('isolution = ', isolution, geom_model.alphas)
alpha = geom_model.alphas[isolution-1]
Expand Down
Loading

0 comments on commit 38a9fa8

Please sign in to comment.