Skip to content

Commit

Permalink
bdf_vectorized3:
Browse files Browse the repository at this point in the history
 - more tests & fixig missed cards (PACBAR)
  • Loading branch information
SteveDoyle2 committed Jan 3, 2024
1 parent c0915ae commit 7ddb396
Show file tree
Hide file tree
Showing 18 changed files with 164 additions and 38 deletions.
3 changes: 0 additions & 3 deletions pyNastran/dev/bdf_vectorized3/bdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2146,9 +2146,6 @@ def add_card(cls, card, comment=''):
#'BCPARA' : (BCPARA, add_methods._add_bcpara_object),
'BCTPARM' : (BCTPARM, add_methods._add_bctparm_object),

# nx bolts
'BOLTLD' : (RuntimeCrash, None),

#'CBEAR', 'PBEAR', 'ROTORB',
#'CBEAR' : (Crash, None),
#'PBEAR' : (Crash, None),
Expand Down
14 changes: 7 additions & 7 deletions pyNastran/dev/bdf_vectorized3/bdf_interface/add_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -5938,15 +5938,15 @@ def add_cplstn8(self, eid: int, pid: int, nids: list[int], theta: float=0.0,
return elem

def add_cplsts3(self, eid: int, pid: int, nids: list[int], theta: float=0.0,
tflag=0, T1=None, T2=None, T3=None, comment: str='') -> int:
tflag: int=0, T1=None, T2=None, T3=None, comment: str='') -> int:
"""Creates a CPLSTS3 card"""
elem = self.cplsts3.add(
eid, pid, nids, theta=theta,
tflag=tflag, T1=T1, T2=T2, T3=T3, comment=comment)
return elem

def add_cplsts4(self, eid: int, pid: int, nids: list[int], theta: float=0.0,
tflag=0, T1=None, T2=None, T3=None, T4=None,
tflag: int=0, T1=None, T2=None, T3=None, T4=None,
comment: str='') -> int:
"""Creates a CPLSTS4 card"""
elem = self.cplsts4.add(
Expand Down Expand Up @@ -8109,9 +8109,9 @@ def add_dphase(self, dphase_id: int, node: int, component: int, phase_lead: floa
dphase = self.dphase.add(dphase_id, node, component, phase_lead, comment=comment)
return dphase

def add_rotorg(self, sid, nids, comment: str='') -> int:
def add_rotorg(self, rotor_id: int, nids: list[int], comment: str='') -> int:
"""Creates a ROTORG card"""
rotor = self.rotorg,add(sid, nids, comment=comment)
rotor = self.rotorg.add(rotor_id, nids, comment=comment)
return rotor

def add_rotord(self, sid, rstart, rstep, numstep,
Expand Down Expand Up @@ -8457,7 +8457,8 @@ def add_paabsf(self, pid: int,
s=s, a=a, b=b, k=k, rhoc=rhoc, comment=comment)
return paabsf

def add_pacbar(self, pid, mback, mseptm, freson, kreson, comment: str='') -> PACBAR:
def add_pacbar(self, pid: int, mback: float, mseptm: float,
freson: float, kreson: float, comment: str='') -> int:
"""
Creates a PACBAR card
Expand All @@ -8475,8 +8476,7 @@ def add_pacbar(self, pid, mback, mseptm, freson, kreson, comment: str='') -> PAC
Resonant stiffness of the sandwich construction.
"""
pacbar = PACBAR(pid, mback, mseptm, freson, kreson, comment=comment)
self._add_methods._add_acoustic_property_object(pacbar)
pacbar = self.pacbar.add(pid, mback, mseptm, freson, kreson, comment=comment)
return pacbar

def add_pacabs(self, pid, cutfr, b, k, m,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,9 @@ def solid_property_cards(self) -> list[Any]:

@property
def property_cards(self) -> list[Any]:
acoustic_property_cards = [self.paabsf]
acoustic_property_cards = [
self.paabsf, self.pacbar,
]
zero_d_properties = [
self.pelas, self.pelast,
self.pdamp, self.pdampt,
Expand Down
2 changes: 1 addition & 1 deletion pyNastran/dev/bdf_vectorized3/bdf_interface/write_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,6 @@ def _write_elements(self, bdf_file: TextIOLike,

# acoustic shells
model.caabsf.write_file(bdf_file, size=size, is_double=is_double)
model.paabsf.write_file(bdf_file, size=size, is_double=is_double)

# acoustic solids
model.chacab.write_file(bdf_file, size=size, is_double=is_double)
Expand Down Expand Up @@ -647,6 +646,7 @@ def _write_properties(self, bdf_file: TextIOLike,

# acoustic
model.pacbar.write_file(bdf_file, size=size, is_double=is_double)
model.paabsf.write_file(bdf_file, size=size, is_double=is_double)

def _write_materials(self, bdf_file: TextIOLike, size: int=8, is_double: bool=False,
is_long_ids: Optional[bool]=None) -> None:
Expand Down
2 changes: 0 additions & 2 deletions pyNastran/dev/bdf_vectorized3/cards/base_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ def searchsorted_filter(all_ids: np.ndarray,
expected2 = lookup_ids[i_lookup2]
actual2 = all_ids[i_all2]
assert np.array_equal(expected2, actual2)
#if debug:
#x = 2
return i_lookup2, i_all2


Expand Down
10 changes: 5 additions & 5 deletions pyNastran/dev/bdf_vectorized3/cards/coord.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ def setup(self):
assert len(np.unique(self.coord_id)) == len(self.coord_id)

debug = False
if debug:
if debug: # pragma: no cover
print(f'nresolved = {nresolved}')
while nresolved < ncoords:
i1 = np.where(self.icoord == 1)[0]
Expand All @@ -719,7 +719,7 @@ def setup(self):
if len(coords_to_resolve) == 0:
raise RuntimeError(f'cannot resolve any coordinate systems...unresolved_cids={unresolved_cids}')

if debug:
if debug: # pragma: no cover
print('-----------------------')
n_to_resolve = len(coord1_cids_to_resolve) + len(coord2_cids_to_resolve)
log.debug(f'n={n_to_resolve} resolve this cycle: coord1={np.array(coord1_cids_to_resolve)}; '
Expand All @@ -728,7 +728,7 @@ def setup(self):
nresolved, cord1s_resolved = self._resolve_cord1(
coord1_cids_to_resolve, nresolved, resolved, grid,
unresolved_cids)
if debug:
if debug: # pragma: no cover
if nresolved > nresolved1:
log.debug(f'n={len(coord1_cids_to_resolve)}; resolved CORD1x={cord1s_resolved} -> {coord1_cids_to_resolve}')
log.debug(f'n={len(unresolved_cids)}; unresolved_cids = {unresolved_cids}')
Expand All @@ -738,7 +738,7 @@ def setup(self):
coord2_cids_to_resolve, resolved, nresolved, unresolved_cids,
rid_to_i_icoord_coordtype)

if debug:
if debug: # pragma: no cover
if nresolved > nresolved2:
log.debug(f'n={len(coord2_cids_to_resolve)}; resolved CORD2x={cord2s_resolved} -> {coord2_cids_to_resolve}')
if unresolved_cids:
Expand All @@ -747,7 +747,7 @@ def setup(self):
if 0 in resolved:
# just limiting log messages
resolved.remove(0)
if debug and resolved:
if debug and resolved: # pragma: no cover
log.info(f'n={len(resolved)}; resolved={np.array(list(resolved))}')
if unresolved_cids:
#print(f'unresolved_cids = {unresolved_cids}\n{self.write()}')
Expand Down
6 changes: 6 additions & 0 deletions pyNastran/dev/bdf_vectorized3/cards/elements/acoustic.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ def midside_nodes(self) -> np.ndarray:
assert midside_nodes.shape[1] == 12, midside_nodes.shape
return midside_nodes

@property
def allowed_properties(self) -> list[Any]:
model = self.model
allowed_properties = [model.pacbar]
return [prop for prop in allowed_properties if prop.n > 0]

@property
def max_id(self) -> int:
return max(self.element_id.max(), self.property_id.max(), self.nodes.max())
Expand Down
8 changes: 4 additions & 4 deletions pyNastran/dev/bdf_vectorized3/cards/elements/bolt.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,15 @@ def add(self, bolt_id: int, scale: float,
"""
return super().add(
sid, scale, scale_factors, bolt_ids, comment=comment)
bolt_id, scale, scale_factors, bolt_ids, comment=comment)

def set_used(self, used_dict: dict[str, np.ndarray]) -> None:
used_dict['load_id'].append(self.load_ids)
used_dict['bolt_id'].append(self.bolt_ids)

def remove_unused(self, used_dict: dict[str, np.ndarray]) -> int:
load_id = used_dict['load_id']
load_id = used_dict['bolt_id']
ncards_removed = remove_unused_primary(
self, load_id, self.load_id, 'load_id')
self, load_id, self.bolt_id, 'bolt_id')
return ncards_removed


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,16 @@ def clear(self) -> None:
self.T = np.zeros((0, 3), dtype='float64')
self.theta = np.array([], dtype='float64')

def add(self, eid: int, pid: int, nids: list[int], theta: float=0.0,
tflag: int=0, T1=None, T2=None, T3=None,
comment: str='') -> int:
"""Creates a CPLSTS3 card"""
self.cards.append((eid, pid, nids, theta,
tflag, [T1, T2, T3],
comment))
self.n += 1
return self.n - 1

def add_card(self, card: BDFCard, comment: str='') -> int:
"""
Adds a CPLSTS3 card from ``BDF.add_card(...)``
Expand Down Expand Up @@ -304,6 +314,16 @@ def clear(self) -> None:
self.T = np.zeros((0, 4), dtype='float64')
self.theta = np.array([], dtype='float64')

def add(self, eid: int, pid: int, nids: list[int], theta: float=0.0,
tflag: int=0, T1=None, T2=None, T3=None, T4=None,
comment: str='') -> int:
"""Creates a CPLSTS4 card"""
self.cards.append((eid, pid, nids, theta,
tflag, [T1, T2, T3, T4],
comment))
self.n += 1
return self.n - 1

def add_card(self, card: BDFCard, comment: str='') -> int:
"""
Adds a CPLSTS4 card from ``BDF.add_card(...)``
Expand Down
7 changes: 5 additions & 2 deletions pyNastran/dev/bdf_vectorized3/cards/elements/shell_quality.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def quad_quality_xyz(p1: np.ndarray, p2: np.ndarray,
assert min_area_min == 0., min_area
area_ratioi1 = np.full(nelement, np.nan, dtype=area.dtype)
iarea = np.where(min_area != 0.)[0]
area_ratioi1[area] = area[area] / min_area[iarea]
area_ratioi1[iarea] = area[iarea] / min_area[iarea]
is_nan_area_ratio = True
warnings.warn(f'invalid area_ratio for a quad/hexa/penta because min_area=0')

Expand All @@ -336,7 +336,10 @@ def quad_quality_xyz(p1: np.ndarray, p2: np.ndarray,
area_ratio = area_ratios.max(axis=0)
if is_nan_area_ratio:
inan = np.isnan(area_ratio)
area_ratio[inan] = area_ratio[~inan].max() * 2
inot_nan = ~inan
not_nan_area = area_ratio[inot_nan]
if inot_nan.sum() > 0:
area_ratio[inan] = not_nan_area.max() * 2
assert area_ratio.shape == (nelement, )
del area_ratios

Expand Down
10 changes: 5 additions & 5 deletions pyNastran/dev/bdf_vectorized3/cards/elements/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,29 @@ def get_density_from_material(material_id: np.ndarray,

material_id_check = np.zeros(nmaterials, dtype='int32')
rho = np.full(nmaterials, np.nan, dtype='float64')
if debug:
if debug: # pragma: no cover
print(f'material_id = {material_id}')
for mat in allowed_materials:
mat_material_ids = mat.material_id
if debug:
if debug: # pragma: no cover
print('mat.material_id = ', mat.material_id)
print('mat.rho = ', mat.rho)
#print('i_lookup = ', i_lookup)

i_lookup, i_all = searchsorted_filter(mat_material_ids, material_id)
if len(i_all) == 0:
continue
if debug:
if debug: # pragma: no cover
print('i_lookup = ', i_lookup)
print('i_all = ', i_all)

material_id_check[i_lookup] = mat_material_ids[i_all]
if debug:
if debug: # pragma: no cover
print('material_id_check = ', material_id_check)
print('mat_material_ids = ', mat_material_ids)

rho[i_lookup] = mat.rho[i_all]
#if debug:
#if debug: # pragma: no cover
#print('material_id_check = ', material_id_check)
#print('mat_material_ids = ', mat_material_ids)
#x = 1
Expand Down
1 change: 1 addition & 0 deletions pyNastran/dev/bdf_vectorized3/cards/rotor.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def clear(self) -> None:
self.node_id = np.array([], dtype='int32')

def add(self, rotor_id: int, nids: list[int], comment: str='') -> int:
"""Creates a ROTORG card"""
nids = expand_thru(nids, set_fields=True, sort_fields=False)
nnodes = len(nids)
self.cards.append((rotor_id, nids, comment))
Expand Down
14 changes: 11 additions & 3 deletions pyNastran/dev/bdf_vectorized3/cards/test/test_vector_bolt.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ def test_bolt_nx_1(self):
model.subcases
boltseq = model.boltseq
boltfor = model.boltfor
boltld = model.boltld
bolt = model.bolt

bolt_id = 1
element_type = 1
eids = [11, 12, 13, 14, 15, 16]
bolt = model.add_bolt_nx(bolt_id, element_type, eids=eids, csid=None, idir=None)
str(bolt)
model.add_bolt_nx(bolt_id, element_type, eids=eids, csid=None, idir=None)
str(bolt.write())
str(boltld.write())

RUN_BOLT = False
nids = [101, 102, 103, 104, 105, 106]
Expand All @@ -48,6 +50,12 @@ def test_bolt_nx_1(self):
bolt = model.add_bolt_nx(bolt_id, element_type, eids=eids, csid=None, idir=None)
str(bolt)

scale = 2.0
scale_factors = [3.]
bolt_id = 10
bolt_ids = [1.]
model.boltld.add(bolt_id, scale, scale_factors, bolt_ids, comment='')

#SID Bolt preload set identification number (Integer; No default)
#S_NOi Sequence order number for the BOLTLD, BOLTFOR, and BOLTFRC IDs to be applied. (Integer; No default)
#B_IDi SID of BOLTLD, BOLTFOR, or BOLTFRC bulk entries defining a boltpreload. (Integer; No default)
Expand Down Expand Up @@ -83,7 +91,7 @@ def test_bolt_nx_1(self):
G = None
nu = 0.3
model.add_mat1(mid, E, G, nu)
model2 = save_load_deck(model, xref='standard', punch=True, run_remove_unused=True, run_convert=True, run_renumber=False,
model2 = save_load_deck(model, xref='standard', punch=True, run_remove_unused=False, run_convert=True, run_renumber=False,
run_mirror=True, run_save_load=True, run_quality=True, write_saves=True, run_save_load_hdf5=True,
run_mass_properties=True, run_loads=True, run_test_bdf=True, run_op2_writer=True, run_op2_reader=True,
remove_disabled_cards=True, nastran_format='nx', op2_log_level='warning')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -572,9 +572,13 @@ def test_rotorg(self):
model = BDF(debug=False)
rotorg = model.rotorg
card_lines = ['ROTORG', '10', '1', '2']
model.add_card(card_lines, 'ROTORG', comment='rotorg')
card_lines = ['ROTORG', '10', '10', ' THRU', '20']
model.add_card(card_lines, 'ROTORG', comment='rotorg')

nids = [10, 'thru', 15]
model.add_rotorg(11, nids, comment='')

model.add_grid(1, [1., 0., 0.])
model.add_grid(2, [2., 0., 0.])
for nid in range(10, 21):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -834,8 +834,8 @@ def test_mat10c(self):
mid = 10
model.add_mat10c(mid, form='REAL', rho_real=0.0, rho_imag=0.0, c_real=0.0, c_imag=0.0, comment='')
model.setup()
print(model.mat10c.write())
save_load_deck(model)
model.mat10c.write()
save_load_deck(model, run_remove_unused=False)

def test_matort(self):
log = get_logger(level='warning')
Expand All @@ -853,10 +853,10 @@ def test_matort(self):
model.add_matort(mid, E1, E2, E3, nu12, nu23, nu31, G12, G23, G31,
rho=0.0, alpha1=0.0, alpha2=0.0, alpha3=0.0, tref=0.0, ge=0.0, comment='')
model.setup()
print(model.mathort.write())
print(model.matort.write())
save_load_deck(model)

def test_matort(self):
def test_mathp(self):
log = get_logger(level='warning')
model = BDF(log=log)
mid = 10
Expand Down
Loading

0 comments on commit 7ddb396

Please sign in to comment.