Skip to content

Commit

Permalink
cleanup; more lax readers
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveDoyle2 committed Nov 15, 2024
1 parent d935586 commit e838e76
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 38 deletions.
6 changes: 3 additions & 3 deletions pyNastran/bdf/bdf_interface/assign_type_force.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ def _force_integer(svalue: str) -> int:
return avalue


def force_double(card: BDFCard, ifield: int, fieldname: str, end: str='') -> float:
def force_double(card: BDFCard, ifield: int, fieldname: str,
end: str='') -> float:
"""see ``double``"""
svalue = card.field(ifield)

Expand Down Expand Up @@ -146,8 +147,7 @@ def force_double_or_blank(card: BDFCard, ifield: int, fieldname: str,
return fvalue
elif isinstance(svalue, str):
try:
ivalue = int(svalue)
fvalue = float(ivalue)
fvalue = float(svalue)
warnings.warn('%s = %r (field #%s) on card must be a float or blank (not an integer) -> %s.\n'
'card=%s' % (fieldname, svalue, ifield, fvalue, card))
return fvalue
Expand Down
63 changes: 49 additions & 14 deletions pyNastran/bdf/cards/coordinate_systems.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@
from pyNastran.bdf.field_writer_8 import set_blank_if_default
from pyNastran.bdf.cards.base_card import BaseCard
from pyNastran.bdf.bdf_interface.assign_type import (
integer, integer_or_blank, double_or_blank, string_or_blank, integer_or_string)
integer, integer_or_blank, double_or_blank,
string_or_blank, integer_or_string)
from pyNastran.bdf.bdf_interface.assign_type_force import (
force_double_or_blank)
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
Expand Down Expand Up @@ -1827,7 +1830,10 @@ class Cord2x(CoordBase):
- CORD2C
- CORD2S
"""
def __init__(self, cid: int, origin, zaxis, xzplane, rid: int=0, setup: bool=True, comment: str=''):
def __init__(self, cid: int, origin: np.ndarray,
zaxis: np.ndarray,
xzplane: np.ndarray,
rid: int=0, setup: bool=True, comment: str=''):
"""
This method emulates the CORD2x card.
Expand Down Expand Up @@ -1892,7 +1898,7 @@ def __deepcopy__(self, memo_dict):
return new_coood

@classmethod
def export_to_hdf5(cls, h5_file, model, cids):
def export_to_hdf5(cls, h5_file, model: BDF, cids: np.ndarray):
"""exports the coords in a vectorized way"""
comments = []
rid = []
Expand Down Expand Up @@ -2096,31 +2102,60 @@ def add_op2_data(cls, data, comment=''):
return cls(cid, e1, e2, e3, rid=rid, setup=False, comment=comment)

@classmethod
def add_card(cls, card, comment=''):
def add_card(cls, card: BDFCard, comment: str=''):
"""Defines the CORD2x class"""
#: coordinate system ID
cid = integer(card, 1, 'cid')
#: reference coordinate system ID
rid = integer_or_blank(card, 2, 'rid', 0)
rid = integer_or_blank(card, 2, 'rid', default=0)

#: origin in a point relative to the rid coordinate system
origin = np.array([double_or_blank(card, 3, 'e1x', 0.0),
double_or_blank(card, 4, 'e1y', 0.0),
double_or_blank(card, 5, 'e1z', 0.0)],
origin = np.array([double_or_blank(card, 3, 'e1x', default=0.0),
double_or_blank(card, 4, 'e1y', default=0.0),
double_or_blank(card, 5, 'e1z', default=0.0)],
dtype='float64')
#: z-axis in a point relative to the rid coordinate system
zaxis = np.array([double_or_blank(card, 6, 'e2x', 0.0),
double_or_blank(card, 7, 'e2y', 0.0),
double_or_blank(card, 8, 'e2z', 0.0)],
zaxis = np.array([double_or_blank(card, 6, 'e2x', default=0.0),
double_or_blank(card, 7, 'e2y', default=0.0),
double_or_blank(card, 8, 'e2z', default=0.0)],
dtype='float64')
#: a point on the xz-plane relative to the rid coordinate system
xzplane = np.array([double_or_blank(card, 9, 'e3x', 0.0),
double_or_blank(card, 10, 'e3y', 0.0),
double_or_blank(card, 11, 'e3z', 0.0)],
xzplane = np.array([double_or_blank(card, 9, 'e3x', default=0.0),
double_or_blank(card, 10, 'e3y', default=0.0),
double_or_blank(card, 11, 'e3z', default=0.0)],
dtype='float64')
return cls(cid, origin, zaxis, xzplane, rid=rid, comment=comment)
#self._finish_setup()

@classmethod
def add_card_lax(cls, card: BDFCard, comment: str=''):
"""Defines the CORD2x class"""
#: coordinate system ID
cid = integer(card, 1, 'cid')
#: reference coordinate system ID
rid = integer_or_blank(card, 2, 'rid', default=0)

#: origin in a point relative to the rid coordinate system
origin = np.array([
force_double_or_blank(card, 3, 'e1x', default=0.0),
force_double_or_blank(card, 4, 'e1y', default=0.0),
force_double_or_blank(card, 5, 'e1z', default=0.0)],
dtype='float64')
#: z-axis in a point relative to the rid coordinate system
zaxis = np.array([
force_double_or_blank(card, 6, 'e2x', default=0.0),
force_double_or_blank(card, 7, 'e2y', default=0.0),
force_double_or_blank(card, 8, 'e2z', default=0.0)],
dtype='float64')
#: a point on the xz-plane relative to the rid coordinate system
xzplane = np.array([
force_double_or_blank(card, 9, 'e3x', default=0.0),
force_double_or_blank(card, 10, 'e3y', default=0.0),
force_double_or_blank(card, 11, 'e3z', default=0.0)],
dtype='float64')
return cls(cid, origin, zaxis, xzplane, rid=rid, comment=comment)
#self._finish_setup()

def _finish_setup(self):
assert len(self.e1) == 3, self.e1
assert len(self.e2) == 3, self.e2
Expand Down
42 changes: 35 additions & 7 deletions pyNastran/bdf/cards/loads/static_loads.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@
from pyNastran.bdf.cards.base_card import BaseCard, expand_thru, expand_thru_by # _node_ids,
from pyNastran.bdf.cards.collpase_card import collapse_thru_by

from pyNastran.bdf.bdf_interface.bdf_card import BDFCard
from pyNastran.bdf.bdf_interface.assign_type import (
integer, integer_or_blank, double, double_or_blank, string, string_or_blank,
integer_or_string, fields, integer_string_or_blank, integer_or_double)
from pyNastran.bdf.bdf_interface.assign_type_force import (
force_double, force_double_or_blank)
from pyNastran.bdf.field_writer_8 import print_card_8, print_float_8, set_string8_blank_if_default
from pyNastran.bdf.field_writer_16 import (
print_card_16, print_float_16, set_string16_blank_if_default)
Expand Down Expand Up @@ -329,6 +332,7 @@ def write_card(self, size: int=8, is_double: bool=False) -> str:
return self.comment + print_card_8(card)
return self.comment + print_card_16(card)


class GRAV(BaseCard):
"""
Defines acceleration vectors for gravity or other acceleration loading.
Expand All @@ -351,7 +355,8 @@ def _init_from_empty(cls):
N = [1., 1., 1.]
return GRAV(sid, scale, N, cid=0, mb=0, comment='')

def __init__(self, sid, scale, N, cid=0, mb=0, comment=''):
def __init__(self, sid: int, scale: float, N: np.ndarray,
cid: int=0, mb: int=0, comment: str=''):
"""
Creates an GRAV card
Expand Down Expand Up @@ -404,7 +409,7 @@ def validate(self):
raise TypeError(msg)

@classmethod
def add_card(cls, card, comment=''):
def add_card(cls, card: BDF, comment: str=''):
"""
Adds a GRAV card from ``BDF.add_card(...)``
Expand All @@ -417,12 +422,35 @@ def add_card(cls, card, comment=''):
"""
sid = integer(card, 1, 'sid')
cid = integer_or_blank(card, 2, 'cid', 0)
cid = integer_or_blank(card, 2, 'cid', default=0)
scale = double(card, 3, 'scale')
N = array([double_or_blank(card, 4, 'N1', 0.0),
double_or_blank(card, 5, 'N2', 0.0),
double_or_blank(card, 6, 'N3', 0.0)])
mb = integer_or_blank(card, 7, 'mb', 0)
N = array([double_or_blank(card, 4, 'N1', default=0.0),
double_or_blank(card, 5, 'N2', default=0.0),
double_or_blank(card, 6, 'N3', default=0.0)])
mb = integer_or_blank(card, 7, 'mb', default=0)
assert len(card) <= 8, f'len(GRAV card) = {len(card):d}\ncard={card}'
return GRAV(sid, scale, N, cid=cid, mb=mb, comment=comment)

@classmethod
def add_card_lax(cls, card: BDF, comment: str=''):
"""
Adds a GRAV card from ``BDF.add_card(...)``
Parameters
----------
card : BDFCard()
a BDFCard object
comment : str; default=''
a comment for the card
"""
sid = integer(card, 1, 'sid')
cid = integer_or_blank(card, 2, 'cid', default=0)
scale = force_double(card, 3, 'scale')
N = array([force_double_or_blank(card, 4, 'N1', default=0.0),
force_double_or_blank(card, 5, 'N2', default=0.0),
force_double_or_blank(card, 6, 'N3', default=0.0)])
mb = integer_or_blank(card, 7, 'mb', default=0)
assert len(card) <= 8, f'len(GRAV card) = {len(card):d}\ncard={card}'
return GRAV(sid, scale, N, cid=cid, mb=mb, comment=comment)

Expand Down
32 changes: 28 additions & 4 deletions pyNastran/bdf/cards/thermal/loads.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@
from __future__ import annotations
from typing import TYPE_CHECKING
from pyNastran.utils.numpy_utils import integer_types
from pyNastran.bdf.field_writer_8 import print_card_8
from pyNastran.bdf.field_writer_8 import print_card_8, set_blank_if_default
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.base_card import expand_thru, expand_thru_by, BaseCard
from pyNastran.bdf.cards.collpase_card import collapse_thru_by
from pyNastran.bdf.bdf_interface.assign_type import (
integer, integer_or_blank, double, double_or_blank, integer_or_string,
integer_double_or_blank, string, fields)
from pyNastran.bdf.bdf_interface.assign_type_force import (
force_double)
if TYPE_CHECKING: # pragma: no cover
from pyNastran.bdf.bdf import BDF
from pyNastran.bdf.bdf_interface.bdf_card import BDFCard


#class ThermalLoadDefault(ThermalCard):
Expand Down Expand Up @@ -1563,7 +1565,7 @@ def _init_from_empty(cls):
temperatures = {1 : 1.0}
return TEMPD(sid, temperatures, comment='')

def __init__(self, sid, temperature, comment=''):
def __init__(self, sid: int, temperature: float, comment: str=''):
"""
Creates a TEMPD card
Expand All @@ -1584,7 +1586,7 @@ def __init__(self, sid, temperature, comment=''):
self.temperature = temperature

@classmethod
def add_card(cls, card, icard=0, comment=''):
def add_card(cls, card: BDFCard, icard: int=0, comment: str=''):
"""
Adds a TEMPD card from ``BDF.add_card(...)``
Expand All @@ -1605,6 +1607,28 @@ def add_card(cls, card, icard=0, comment=''):
temperature = double(card, i + 2, 'temp')
return TEMPD(sid, temperature, comment=comment)

@classmethod
def add_card_lax(cls, card: BDFCard, icard: int=0, comment: str=''):
"""
Adds a TEMPD card from ``BDF.add_card(...)``
Parameters
----------
card : BDFCard()
a BDFCard object
icard : int; default=0
sid to be parsed
comment : str; default=''
a comment for the card
"""
nfields = len(card) - 1
assert nfields % 2 == 0, 'card=%s' % card
i = 2 * icard
sid = integer(card, i + 1, 'sid')
temperature = force_double(card, i + 2, 'temp')
return TEMPD(sid, temperature, comment=comment)

@classmethod
def add_op2_data(cls, data, comment=''):
"""
Expand Down
20 changes: 11 additions & 9 deletions pyNastran/dev/bdf_vectorized2/test/test_bdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,16 +620,18 @@ def remake_model(bdf_model, fem1, run_pickle):
#out_model_8 = '%s.test_bdfv.bdf' % (model_name)
#out_model_16 = '%s.test_bdfv.bdf' % (model_name)

fem1.save(obj_model)
fem1.save(obj_model, unxref=False)
#fem1.write_bdf(out_model_8)
fem1.get_bdf_stats()
if run_pickle and 0:
if 1:
fem1.save(obj_model)
fem1.save(obj_model, unxref=False)
#fem1.write_bdf(out_model_8)
fem1.get_bdf_stats()

fem1 = BDF(debug=fem1.debug, log=fem1.log)
fem1.load(obj_model)
#fem1.write_bdf(out_model_8)
#fem1.log = log
os.remove(obj_model)
fem1 = BDF(debug=fem1.debug, log=fem1.log)
fem1.load(obj_model)
#fem1.write_bdf(out_model_8)
#fem1.log = log
os.remove(obj_model)
fem1.get_bdf_stats()
return fem1

Expand Down
2 changes: 1 addition & 1 deletion pyNastran/dev/bdf_vectorized3/test/test_bdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -1420,7 +1420,7 @@ def _fem_xref_methods_check(fem1: BDFv) -> None:

def remake_model(bdf_model: BDFs, fem1: BDFs, run_pickle: bool) -> None:
"""reloads the model if we're testing pickling"""
if not run_pickle:
if not run_pickle or 1:
return fem1

#log = fem1.log
Expand Down

0 comments on commit e838e76

Please sign in to comment.