Skip to content

Commit

Permalink
bdf_vectorized3
Browse files Browse the repository at this point in the history
 - fixing overflow bug
  • Loading branch information
SteveDoyle2 committed Oct 6, 2023
1 parent 2a549cd commit ef33236
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 66 deletions.
7 changes: 2 additions & 5 deletions pyNastran/dev/bdf_vectorized3/bdf_interface/write_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -1014,12 +1014,9 @@ def _write_constraints(self, bdf_file: TextIOLike,
model.mpc.write_file(bdf_file, size=size, is_double=is_double)
#bdf_file.write(model.mpcax.write(size=size))

return
if len(model.suport) or len(model.suport1):
if len(model.suport):
bdf_file.write('$CONSTRAINTS\n')
bdf_file.write(model.suport.write(size, is_double))
for unused_suport_id, suport in sorted(model.suport1.items()):
bdf_file.write(suport.write_card(size, is_double))
model.suport.write_file(bdf_file, size=size, is_double=is_double)

return
if self.spcoffs:
Expand Down
28 changes: 21 additions & 7 deletions pyNastran/dev/bdf_vectorized3/cards/bdf_sets.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from collections import defaultdict
from typing import Any, TYPE_CHECKING
import numpy as np
from pyNastran.bdf.field_writer_8 import print_card_8
#from pyNastran.bdf.field_writer_8 import print_card_8
from pyNastran.utils.numpy_utils import integer_types
from pyNastran.bdf.cards.base_card import expand_thru, _format_comment
from pyNastran.bdf.bdf_interface.assign_type import (
Expand All @@ -13,8 +13,9 @@

#from pyNastran.dev.bdf_vectorized3.bdf_interface.geom_check import geom_check
from pyNastran.dev.bdf_vectorized3.cards.write_utils import array_str, array_default_int
from pyNastran.dev.bdf_vectorized3.cards.base_card import VectorizedBaseCard, parse_node_check #get_print_card_8_16,
from pyNastran.dev.bdf_vectorized3.cards.write_utils import get_print_card, MAX_8_CHAR_INT
from pyNastran.dev.bdf_vectorized3.cards.base_card import VectorizedBaseCard, parse_node_check, get_print_card_8_16
from pyNastran.dev.bdf_vectorized3.cards.write_utils import get_print_card, update_field_size
from pyNastran.dev.bdf_vectorized3.bdf_interface.geom_check import geom_check


if TYPE_CHECKING: # pragma: no cover
Expand Down Expand Up @@ -208,13 +209,19 @@ def __apply_slice__(self, grid: ASET, i: np.ndarray) -> None:
grid.node_id = self.node_id[i]
grid.component = self.component[i]

def geom_check(self, missing: dict[str, np.ndarray]):
nid = self.model.grid.node_id
geom_check(self,
missing,
node=(nid, self.node_id),)

@parse_node_check
def write_file(self, bdf_file: TextIOLike,
size: int=8, is_double: bool=False,
write_card_header: bool=False) -> None:
max_int = self.node_id.max()
#size = update_field_size(max_int, size)
print_card = print_card_8
size = update_field_size(max_int, size)
print_card = get_print_card(size, max_int)

comp_to_nids = defaultdict(list)
for nid, comp in zip_longest(self.node_id, self.component):
Expand Down Expand Up @@ -466,13 +473,20 @@ def __apply_slice__(self, grid: SUPORT, i: np.ndarray) -> None:
grid.node_id = self.node_id[i]
grid.component = self.component[i]


def geom_check(self, missing: dict[str, np.ndarray]):
nid = self.model.grid.node_id
geom_check(self,
missing,
node=(nid, self.node_id),)

@parse_node_check
def write_file(self, bdf_file: TextIOLike,
size: int=8, is_double: bool=False,
write_card_header: bool=False) -> None:
max_int = self.node_id.max()
#size = update_field_size(max_int, size)
print_card = print_card_8
size = update_field_size(max_int, size)
print_card = get_print_card_8_16(size)

suport_id_to_nid_comp = defaultdict(list)
for suport_idi, nid, comp in zip_longest(self.suport_id, self.node_id, self.component):
Expand Down
2 changes: 0 additions & 2 deletions pyNastran/dev/bdf_vectorized3/cards/elements/beam.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,6 @@ def center_of_mass(self) -> np.ndarray:
mass_per_length[iipid] = mpl
nsm_per_length[iipid] = nsmpl
#nsm_centroid[iipid] = 0.
x = 1

#if nsm != 0.:
#p1_nsm = p1 + prop.ma
Expand Down Expand Up @@ -671,7 +670,6 @@ def center_of_mass(self) -> np.ndarray:
nsm_n1 = (p1[iipid, :] + jhat[iipid, :] * m1 + khat[jpid, :] * m2)
nsm_n2 = (p2[iipid, :] + jhat[iipid, :] * m1 + khat[jpid, :] * m2)
nsm_centroid[iipid, :] = (nsm_n1 + nsm_n2) / 2.
x = 1
#elif prop.type == 'PBMSECT':
#continue
#mass_per_length = prop.MassPerLength()
Expand Down
4 changes: 3 additions & 1 deletion pyNastran/dev/bdf_vectorized3/cards/elements/bush.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from pyNastran.dev.bdf_vectorized3.cards.base_card import (
Element, Property, get_print_card_8_16,
parse_element_check, parse_property_check)
from pyNastran.dev.bdf_vectorized3.cards.write_utils import array_str, array_default_int
from pyNastran.dev.bdf_vectorized3.cards.write_utils import update_field_size, array_str, array_default_int
from .rod import line_length, line_centroid, line_centroid_with_spoints
from .utils import get_mass_from_property
from pyNastran.dev.bdf_vectorized3.bdf_interface.geom_check import geom_check
Expand Down Expand Up @@ -463,6 +463,8 @@ def geom_check(self, missing: dict[str, np.ndarray]):
def write_file(self, bdf_file: TextIOLike, size: int=8,
is_double: bool=False,
write_card_header: bool=False) -> None:
max_int = self.property_id.max()
size = update_field_size(max_int, size)
print_card = get_print_card_8_16(size)

#RCV was added <= MSC 2016
Expand Down
8 changes: 2 additions & 6 deletions pyNastran/dev/bdf_vectorized3/cards/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
#from pyNastran.dev.bdf_vectorized3.bdf_interface.geom_check import geom_check
from pyNastran.dev.bdf_vectorized3.cards.write_utils import array_str, array_float, array_default_int
from pyNastran.dev.bdf_vectorized3.cards.base_card import VectorizedBaseCard, parse_node_check #get_print_card_8_16,
from pyNastran.dev.bdf_vectorized3.cards.write_utils import get_print_card, MAX_8_CHAR_INT
from pyNastran.dev.bdf_vectorized3.cards.write_utils import get_print_card, update_field_size, MAX_8_CHAR_INT
from pyNastran.dev.bdf_vectorized3.bdf_interface.geom_check import geom_check

from pyNastran.femutils.coord_transforms import (
xyz_to_rtz_array,
Expand Down Expand Up @@ -904,11 +905,6 @@ def index(self, node_id: np.ndarray) -> np.ndarray:
return inid


def update_field_size(max_int: int, size: int) -> int:
if max_int > MAX_8_CHAR_INT:
size = 16
return size

def _write_grid_large(grid: GRID, bdf_file: TextIOLike,
print_scientific: Callable[float],
is_double: bool=False,
Expand Down
47 changes: 26 additions & 21 deletions pyNastran/dev/bdf_vectorized3/cards/loads/static_pressure_loads.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from pyNastran.bdf.field_writer_8 import set_blank_if_default
from pyNastran.bdf.cards.base_card import expand_thru
from pyNastran.bdf.field_writer_8 import print_card_8, print_float_8 # , print_field_8
from pyNastran.bdf.field_writer_8 import print_card_8 # , print_float_8 # , print_field_8
from pyNastran.bdf.field_writer_16 import print_card_16 # , print_scientific_16, print_field_16
#from pyNastran.bdf.field_writer_double import print_scientific_double
from pyNastran.bdf.bdf_interface.assign_type import (
Expand Down Expand Up @@ -89,16 +89,12 @@ def add_card(self, card: BDFCard, comment: str='') -> int:
self.n += 1
return self.n

@Load.parse_cards_check
def parse_cards(self) -> None:
if self.n == 0:
return
ncards = len(self.cards)
if ncards == 0:
return
load_id = np.zeros(ncards, dtype='int32')
pressure = np.zeros(ncards, dtype='float64')
node_id = np.zeros((ncards, 4), dtype='int32')
assert ncards > 0, ncards

for icard, card in enumerate(self.cards):
(sid, pressurei, nodesi, comment) = card
Expand Down Expand Up @@ -276,7 +272,6 @@ def parse_cards(self) -> None:
scale = np.zeros(ncards, dtype='|U8')
x = np.zeros((ncards, 2), dtype='float64')
pressure = np.zeros((ncards, 2), dtype='float64')
assert ncards > 0, ncards

for icard, card in enumerate(self.cards):
(sid, eid, load_typei, scalei, x12, pressurei, comment) = card
Expand Down Expand Up @@ -645,7 +640,7 @@ def parse_cards(self) -> None:
load_id = np.zeros(ncards, dtype='int32')
pressure = np.zeros(ncards, dtype='float64')
nelement = np.zeros(ncards, dtype='int32')
assert ncards > 0, ncards

element_ids_ = []
for icard, card in enumerate(self.cards):
(sid, pressurei, eids, comment) = card
Expand Down Expand Up @@ -881,12 +876,9 @@ def add_card(self, card: BDFCard, comment: str='') -> int:
self.n += 1
return self.n

@Load.parse_cards_check
def parse_cards(self) -> None:
if self.n == 0:
return
ncards = len(self.cards)
if ncards == 0:
return
load_id = np.zeros(ncards, dtype='int32')
coord_id = np.full(ncards, -1, dtype='int32')
pressure = np.zeros((ncards, 4), dtype='float64')
Expand All @@ -896,7 +888,6 @@ def parse_cards(self) -> None:
line_load_dir = np.full(ncards, '', dtype='|U8')
nvector = np.zeros((ncards, 3), dtype='float64')
nelement = np.zeros(ncards, dtype='int32')
assert ncards > 0, ncards
element_ids = []
for icard, card in enumerate(self.cards):
(sid, eid, pressures, eids, g1, g34,
Expand All @@ -921,8 +912,24 @@ def parse_cards(self) -> None:

def _save(self, load_id, element_ids, coord_id, pressure, nodes_g1_g34,
surf_or_line, line_load_dir, nvector, nelement):

nloads = len(load_id)
if surf_or_line is None:
surf_or_line = np.full(nloads, 'SURF', dtype='|U8')
if line_load_dir is None:
line_load_dir = np.full(nloads, 'NOMR', dtype='|U8')

if len(self.load_id) != 0:
raise NotImplementedError()
load_id = np.hstack([self.load_id, load_id])
element_ids = np.hstack([self.element_ids, element_ids])
coord_id = np.hstack([self.coord_id, coord_id])
pressure = np.vstack([self.pressure, pressure])
nodes_g1_g34 = np.vstack([self.nodes_g1_g34, nodes_g1_g34])
surf_or_line = np.hstack([self.surf_or_line, surf_or_line])
line_load_dir = np.hstack([self.line_load_dir, line_load_dir])
nvector = np.vstack([self.nvector, nvector])
nelement = np.hstack([self.nelement, nelement])

nloads = len(load_id)
self.load_id = load_id
self.element_ids = element_ids
Expand All @@ -931,11 +938,6 @@ def _save(self, load_id, element_ids, coord_id, pressure, nodes_g1_g34,
assert pressure.shape == (nloads, 4), pressure
self.nodes_g1_g34 = nodes_g1_g34

if surf_or_line is None:
surf_or_line = np.full(nloads, 'SURF', dtype='|U8')
if line_load_dir is None:
line_load_dir = np.full(nloads, 'NOMR', dtype='|U8')

self.surf_or_line = surf_or_line
self.line_load_dir = line_load_dir
assert nvector is not None
Expand Down Expand Up @@ -1290,8 +1292,11 @@ def area_centroid_normal_pressure(self) -> tuple[np.ndarray, np.ndarray, np.ndar
# apply nvector to the normal for places that the normal vector isn't used
normal[~is_normal, :] = nvector[~is_normal, :]

if np.any(np.isnan(mean_pressure)):
raise RuntimeError('there are nan pressures', mean_pressure)
inan = np.isnan(mean_pressure)
if np.any(inan):
assert len(mean_pressure) == len(self.element_ids)
eids_nan = self.element_ids[inan]
raise RuntimeError(f'there are nan PLOAD4 pressures for eids={eids_nan}')
assert len(area) == nelement, f'narea={len(area)}; nelement={nelement}'
assert len(mean_pressure) == nelement, f'npressure={len(mean_pressure)}; nelement={nelement}'

Expand Down
46 changes: 27 additions & 19 deletions pyNastran/dev/bdf_vectorized3/cards/test/test_vector_loads.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,8 @@ def test_grav(self):
def test_pload4_01(self):
"""tests a PLOAD4"""
model = BDF(debug=False)
pload4 = model.pload4

lines = ['PLOAD4 1000 1 -60. -60. 60. 1']
card = model._process_card(lines)
cardi = BDFCard(card)
Expand All @@ -304,28 +306,21 @@ def test_pload4_02(self):
model.pload4.write(size, 'dummy')
#card.raw_fields()

def _test_pload4_line(self):
def test_pload4_line(self):
"""tests a PLOAD4 LINE option"""
#PLOAD4 10 10 0.819.2319
#0 1. 0. 0. LINE NORM
model = BDF(log=log, mode='msc')
pload4 = model.pload4

sid = 1
eids = 1
pressures = 1.
model.add_pload4(sid, eids, pressures,
g1=None, g34=None, cid=0, nvector=None,
surf_or_line='SURFBAD', line_load_dir='NORMBAD', comment='')
model.setup()
pload4 = model.pload4
#with self.assertRaises(RuntimeError):
#pload4.validate()
pload4.surf_or_line[0] = 'SURF'
#with self.assertRaises(RuntimeError):
#pload4.validate()
pload4.line_load_dir[0] = 'NORM'
#pload4.validate()
#model.clear_attributes()
iload0 = model.add_pload4(
sid, eids, pressures,
g1=None, g34=None, cid=0, nvector=None,
surf_or_line='SURFBAD', line_load_dir='NORMBAD', comment='') - 1


eid = 10
pid = 20
Expand Down Expand Up @@ -371,6 +366,18 @@ def _test_pload4_line(self):
# P1 denotes that the line load along edge G1 and G2 has the
# constant value of P1.
#
model.setup()
#with self.assertRaises(RuntimeError):
#pload4.validate()
print(pload4.write())
pload4.element_ids[iload0] = 10
pload4.surf_or_line[iload0] = 'SURF'
#with self.assertRaises(RuntimeError):
#pload4.validate()
pload4.line_load_dir[iload0] = 'NORM'
#pload4.validate()
#model.clear_attributes()

sid = 10
eids = [10, 11]
pressures = [1., 0., 0., 0.]
Expand All @@ -386,9 +393,9 @@ def _test_pload4_line(self):
# direction of the element coordinate system. If both (CID, N1, n2, N3) and LDIR are
# blank, then the default is LDIR=NORM.
nvector = [1., 0., 0.]
pload4 = model.add_pload4(sid, eids, pressures, g1=None, g34=None,
cid=cid, nvector=nvector,
surf_or_line='LINE', line_load_dir='NORM', comment='pload4_line')
pload4i = model.add_pload4(sid, eids, pressures, g1=None, g34=None,
cid=cid, nvector=nvector,
surf_or_line='LINE', line_load_dir='NORM', comment='pload4_line')
pload4 = model.pload4
#assert pload4.raw_fields() == ['PLOAD4', 10, 10, 1.0, 0.0, 0.0, 0.0, 'THRU', 11,
#0, 1.0, 0.0, 0.0, 'LINE', 'NORM']
Expand All @@ -398,7 +405,6 @@ def _test_pload4_line(self):
cid=cid, nvector=nvector,
surf_or_line='SURF', line_load_dir='NORM',
comment='pload4_line')
pload4 = model.pload4
#str(pload4.raw_fields())

sid = 11
Expand All @@ -408,9 +414,11 @@ def _test_pload4_line(self):
cid=cid, nvector=nvector,
surf_or_line='SURF', line_load_dir='NORM',
comment='pload4_line')
pload4 = model.pload4

model.setup()
model.validate()
model.cross_reference()
pload4.sum_forces_moments()

p0 = [0., 0., 0.]
loadcase_id = sid
Expand Down
5 changes: 5 additions & 0 deletions pyNastran/dev/bdf_vectorized3/cards/write_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ def get_print_card(size: int, max_int: int) -> Callable:
print_card = print_card_8
return print_card

def update_field_size(max_int: int, size: int) -> int:
if max_int > MAX_8_CHAR_INT:
size = 16
return size

def get_print_card_size(size: int, max_int: int) -> tuple[Callable, int]:
if size == 16 or max_int > MAX_8_CHAR_INT:
print_card = print_card_16
Expand Down
11 changes: 6 additions & 5 deletions pyNastran/dev/bdf_vectorized3/test/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,12 @@ def test_other_2(self):
args = ['test_bdf', str(bdf_filename)]
test_bdf(args, show_args=False)

def test_overflow(self):
# overflow
bdf_filename = MODEL_PATH / 'other' / 'sdr11se_s2dclg.bdf'
args = ['test_bdf', str(bdf_filename)]
test_bdf(args, show_args=False)

def test_other_3(self):
# missing GRID card
#bdf_filename = MODEL_PATH / 'other' / 'ofprand1.bdf'
Expand Down Expand Up @@ -383,11 +389,6 @@ def test_other_3(self):
#args = ['test_bdf', str(bdf_filename)]
#test_bdf(args, show_args=False)

# overflow
bdf_filename = MODEL_PATH / 'other' / 'sdr11se_s2dclg.bdf'
args = ['test_bdf', str(bdf_filename)]
test_bdf(args, show_args=False)

# EIGC parsing
#bdf_filename = MODEL_PATH / 'other' / 'rot063akd2s_107.bdf'
#args = ['test_bdf', str(bdf_filename)]
Expand Down

0 comments on commit ef33236

Please sign in to comment.