# pylint: disable=C0103,R0902,R0904,R0914,C0111
from __future__ import (nested_scopes, generators, division, absolute_import,
print_function, unicode_literals)
from six import iteritems
from six.moves import range
from pyNastran.bdf.field_writer_8 import print_card_8
from pyNastran.bdf.field_writer_16 import print_card_16
from pyNastran.bdf.field_writer_double import print_card_double
from pyNastran.bdf.cards.utils import wipe_empty_fields
from pyNastran.bdf.cards.thermal.thermal import ThermalCard
from pyNastran.bdf.field_writer_8 import set_blank_if_default
from pyNastran.bdf.cards.baseCard import expand_thru, expand_thru_by, collapse_thru_by
from pyNastran.bdf.bdfInterface.assign_type import (integer, integer_or_blank,
double, double_or_blank, integer_or_string, string, fields)
[docs]class ThermalLoadDefault(ThermalCard):
def __init__(self, card, data):
pass
[docs]class ThermalLoad(ThermalCard):
def __init__(self, card, data):
pass
[docs]class QBDY1(ThermalLoad):
"""
Defines a uniform heat flux into CHBDYj elements.
"""
type = 'QBDY1'
def __init__(self, card=None, data=None, comment=''):
ThermalLoad.__init__(self, card, data)
if comment:
self._comment = comment
if card:
#: Load set identification number. (Integer > 0)
self.sid = integer(card, 1, 'sid')
#: Heat flux into element (FLOAT)
self.qFlux = double(card, 2, 'qFlux')
eids = []
j = 1
for i in range(3, len(card)):
eid = integer_or_string(card, i, 'eid%i' % j)
eids.append(eid)
j += 1
#: CHBDYj element identification numbers (Integer)
assert len(eids) > 0
#: .. todo:: use expand_thru_by ???
self.eids = expand_thru(eids)
else:
self.sid = data[0]
self.qFlux = data[1]
self.eids = data[2:]
[docs] def getLoads(self):
return [self]
[docs] def cross_reference(self, model):
msg = ' which is required by QBDY1 sid=%s' % self.sid
self.eids = model.Elements(self.eids, msg=msg)
[docs] def Eid(self, eid):
if isinstance(eid, int):
return eid
return eid.eid
[docs] def nQFluxTerms(self):
return len(self.qFlux)
[docs] def Eids(self):
eids = []
for eid in self.eids:
eids.append(self.Eid(eid))
return eids
[docs] def raw_fields(self):
list_fields = ['QBDY1', self.sid, self.qFlux] + self.Eids()
return list_fields
[docs] def repr_fields(self):
eids = collapse_thru_by(self.Eids())
list_fields = ['QBDY1', self.sid, self.qFlux] + eids
return list_fields
[docs] def write_card(self, size=8, is_double=False):
card = self.repr_fields()
if size == 8:
return self.comment() + print_card_8(card)
if is_double:
return self.comment() + print_card_double(card)
return self.comment() + print_card_16(card)
[docs]class QBDY2(ThermalLoad): # not tested
"""
Defines a uniform heat flux load for a boundary surface.
"""
type = 'QBDY2'
def __init__(self, card=None, data=None, comment=''):
ThermalLoad.__init__(self, card, data)
if comment:
self._comment = comment
if card:
#: Load set identification number. (Integer > 0)
self.sid = integer(card, 1, 'sid')
#: Identification number of an CHBDYj element. (Integer > 0)
self.eid = integer(card, 2, 'eid')
qFlux = []
j = 1
for i in range(3, len(card)):
q = double_or_blank(card, i, 'qFlux%i' % j)
qFlux.append(q)
j += 1
assert len(qFlux) > 0
#: Heat flux at the i-th grid point on the referenced CHBDYj
#: element. (Real or blank)
self.qFlux = wipe_empty_fields(qFlux)
else:
self.sid = data[0]
self.eid = data[1]
self.qFlux = data[2]
[docs] def getLoads(self):
return [self]
[docs] def cross_reference(self, model):
msg = ' which is required by QBDY2 sid=%s' % self.sid
self.eid = model.Element(self.eid, msg=msg)
[docs] def Eid(self):
if isinstance(self.eid, int):
return self.eid
return self.eid.eid
[docs] def nQFluxTerms(self):
return len(self.qFlux)
[docs] def raw_fields(self):
list_fields = ['QBDY2', self.sid, self.Eid()] + self.qFlux
return list_fields
[docs] def repr_fields(self):
return self.raw_fields()
[docs] def write_card(self, size=8, is_double=False):
card = self.repr_fields()
if size == 8:
return self.comment() + print_card_8(card)
if is_double:
return self.comment() + print_card_double(card)
return self.comment() + print_card_16(card)
[docs]class QBDY3(ThermalLoad):
"""
Defines a uniform heat flux load for a boundary surface.
"""
type = 'QBDY3'
def __init__(self, card=None, data=None, comment=''):
ThermalLoad.__init__(self, card, data)
if comment:
self._comment = comment
if card:
#: Load set identification number. (Integer > 0)
self.sid = integer(card, 1, 'sid')
#: Heat flux into element
self.Q0 = double(card, 2, 'Q0')
#: Control point for thermal flux load. (Integer > 0; Default = 0)
self.cntrlnd = integer_or_blank(card, 3, 'cntrlnd', 0)
nfields = card.nfields
eids = fields(integer_or_string, card, 'eid', i=4, j=nfields)
#: CHBDYj element identification numbers
self.eids = expand_thru_by(eids)
else:
self.sid = data[0]
self.Q0 = data[1]
self.cntrlnd = data[2]
self.eids = list(data[3:])
[docs] def cross_reference(self, model):
msg = ' which is required by QBDY3 sid=%s' % self.sid
for i, eid in enumerate(self.eids):
self.eids[i] = model.Element(eid, msg=msg)
[docs] def Eids(self):
eids = []
for eid in self.eids:
eids.append(self.Eid(eid))
return eids
[docs] def Eid(self, eid):
if isinstance(eid, int):
return eid
return eid.eid
[docs] def raw_fields(self):
eids = self.Eids()
eids.sort()
list_fields = (['QBDY3', self.sid, self.Q0, self.cntrlnd] +
collapse_thru_by(eids))
return list_fields
[docs] def repr_fields(self):
cntrlnd = set_blank_if_default(self.cntrlnd, 0)
eids = self.Eids()
eids.sort()
list_fields = ['QBDY3', self.sid, self.Q0, cntrlnd] + collapse_thru_by(eids)
return list_fields
[docs] def getLoads(self):
"""
.. todo:: return loads
"""
return []
[docs] def write_card(self, size=8, is_double=False):
card = self.repr_fields()
if size == 8:
return self.comment() + print_card_8(card)
if is_double:
return self.comment() + print_card_double(card)
return self.comment() + print_card_16(card)
[docs]class QHBDY(ThermalLoad):
"""
Defines a uniform heat flux into a set of grid points.
"""
type = 'QHBDY'
def __init__(self, card=None, data=None, comment=''):
ThermalLoad.__init__(self, card, data)
if comment:
self._comment = comment
if card:
#: Load set identification number. (Integer > 0)
self.sid = integer(card, 1, 'eid')
self.flag = string(card, 2, 'flag')
assert self.flag in ['POINT', 'LINE', 'REV', 'AREA3', 'AREA4',
'AREA6', 'AREA8']
#: Magnitude of thermal flux into face. Q0 is positive for heat
#: into the surface. (Real)
self.Q0 = double(card, 3, 'Q0')
#: Area factor depends on type. (Real > 0.0 or blank)
self.af = double_or_blank(card, 4, 'af')
nfields = card.nfields
#: grids
self.grids = fields(integer, card, 'grid', i=5, j=nfields)
#: Grid point identification of connected grid points.
#: (Integer > 0 or blank)
self.grids = expand_thru_by(self.grids)
else:
self.sid = data[0]
self.flag = data[1]
self.Q0 = data[2]
self.af = data[3]
self.grids = data[4:]
[docs] def getLoads(self):
return [self]
[docs] def cross_reference(self, model):
pass
[docs] def raw_fields(self):
list_fields = ['QHBDY', self.sid, self.flag, self.Q0, self.af] + self.grids
return list_fields
[docs] def repr_fields(self):
return self.raw_fields()
[docs] def write_card(self, size=8, is_double=False):
card = self.repr_fields()
if size == 8:
return self.comment() + print_card_8(card)
if is_double:
return self.comment() + print_card_double(card)
return self.comment() + print_card_16(card)
[docs]class TEMP(ThermalLoad):
"""
Defines temperature at grid points for determination of thermal loading,
temperature-dependent material properties, or stress recovery.
+------+-----+----+-------+----+-------+----+----+
| TEMP | SID | G1 | T1 | G2 | T2 | G3 | T3 |
+------+-----+----+-------+----+-------+----+----+
| TEMP | 3 | 94 | 316.2 | 49 | 219.8 | | |
+------+-----+----+-------+----+-------+----+----+
"""
type = 'TEMP'
def __init__(self, card=None, data=None, comment=''):
ThermalLoad.__init__(self, card, data)
if comment:
self._comment = comment
if card:
#: Load set identification number. (Integer > 0)
self.sid = integer(card, 1, 'sid')
nfields = len(card) - 2
assert nfields % 2 == 0
#: dictionary of temperatures where the key is the grid ID (Gi)
#: and the value is the temperature (Ti)
self.temperatures = {}
for i in range(nfields // 2):
n = i * 2 + 2
gi = integer(card, n, 'g' + str(i))
Ti = double(card, n + 1, 'T' + str(i))
self.temperatures[gi] = Ti
else:
#print "TEMP data = ",data
self.sid = data[0]
self.temperatures = {data[1]: data[2]}
[docs] def add(self, temp_obj):
assert self.sid == temp_obj.sid
for (gid, temp) in iteritems(self.tempObj.temperatures):
self.temperatures[gid] = temp
[docs] def cross_reference(self, model):
pass
[docs] def raw_fields(self):
"""Writes the TEMP card"""
list_fields = ['TEMP', self.sid]
ntemps = len(self.temperatures) - 1
for i, (gid, temp) in enumerate(sorted(iteritems(self.temperatures))):
list_fields += [gid, temp]
if i % 3 == 2 and ntemps > i: # start a new TEMP card
list_fields += [None, 'TEMP', self.lid]
return list_fields
[docs] def repr_fields(self):
"""Writes the TEMP card"""
return self.raw_fields()
[docs] def getLoads(self):
"""
.. todo:: return loads
"""
return []
[docs] def write_card(self, size=8, is_double=False):
card = self.repr_fields()
if size == 8:
return self.comment() + print_card_8(card)
if is_double:
return self.comment() + print_card_double(card)
return self.comment() + print_card_16(card)
# Loads
#-------------------------------------------------------
# Default Loads
[docs]class TEMPD(ThermalLoadDefault):
"""
Defines a temperature value for all grid points of the structural model
that have not been given a temperature on a TEMP entry
"""
type = 'TEMPD'
def __init__(self, card=None, data=None, comment=''):
ThermalLoadDefault.__init__(self, card, data)
if comment:
self._comment = comment
if card:
nfields = len(card) - 1
assert nfields % 2 == 0
#: dictionary of temperatures where the key is the set ID (SIDi)
#: and the value is the temperature (Ti)
self.temperatures = {}
for i in range(0, nfields, 2):
n = i // 2
sid = integer(card, i + 1, 'sid' + str(n))
temp = double(card, i + 2, 'temp' + str(n))
self.temperatures[sid] = temp
else:
self.temperatures = {data[0]: data[1]}
[docs] def add(self, tempd_obj):
for (lid, tempd) in iteritems(tempd_obj.temperatures):
self.temperatures[lid] = tempd
[docs] def cross_reference(self, model):
pass
[docs] def repr_fields(self):
"""Writes the TEMPD card"""
list_fields = ['TEMPD']
nTemps = len(self.temperatures) - 1
for i, (gid, temp) in enumerate(sorted(iteritems(self.temperatures))):
list_fields += [gid, temp]
if i % 4 == 3 and nTemps > i: # start a new TEMP card
list_fields += ['TEMPD']
return list_fields
[docs] def write_card(self, size=8, is_double=False):
card = self.repr_fields()
if size == 8:
return self.comment() + print_card_8(card)
if is_double:
return self.comment() + print_card_double(card)
return self.comment() + print_card_16(card)