Skip to content

Commit f07cd08

Browse files
committed
--ifile uses save_file_structure and will give you duplicate id tags
added bdf set checker
1 parent 2ebbc1d commit f07cd08

File tree

11 files changed

+302
-193
lines changed

11 files changed

+302
-193
lines changed

pyNastran/bdf/bdf.py

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1929,8 +1929,9 @@ def get_bdf_cards(self, bulk_data_lines: list[str],
19291929

19301930
for iline_bulk, line in enumerate(bulk_data_lines):
19311931
ifile_iline = bulk_data_ilines[iline_bulk, :]
1932-
#print(iline_bulk, ifile_iline, line)
1933-
#print(' backup=%r' % backup_comment)
1932+
# print(iline_bulk, ifile_iline)
1933+
# print(iline_bulk, ifile_iline, line)
1934+
# print(' backup={backup_comment!r}')
19341935
comment = ''
19351936
if '$' in line:
19361937
line, comment = line.split('$', 1)
@@ -5266,33 +5267,33 @@ def read_bdf(bdf_filename: Optional[PathLike]=None, validate: bool=True,
52665267
save_file_structure=save_file_structure,
52675268
encoding=encoding)
52685269

5269-
#if 0:
5270-
### TODO: remove all the extra methods
5271-
5272-
#keys_to_suppress = []
5273-
#method_names = model.object_methods(keys_to_skip=keys_to_suppress)
5274-
5275-
#methods_to_remove = [
5276-
#'_process_card', 'read_bdf', 'disable_cards', 'set_dynamic_syntax',
5277-
#'create_card_object', 'create_card_object_fields', 'create_card_object_list',
5278-
5279-
#'set_as_msc',
5280-
#'set_as_nx',
5281-
5282-
#'pop_parse_errors',
5283-
##'pop_xref_errors',
5284-
#'set_error_storage',
5285-
#'is_reject',
5286-
#]
5287-
#for method_name in method_names:
5288-
#if method_name not in methods_to_remove + keys_to_suppress:
5289-
##print(method_name)
5290-
#pass
5291-
#else:
5292-
### TODO: doesn't work...
5293-
##delattr(model, method_name)
5294-
#pass
5295-
#model.get_bdf_stats()
5270+
# if 0:
5271+
# ## TODO: remove all the extra methods
5272+
#
5273+
# keys_to_suppress = []
5274+
# method_names = model.object_methods(keys_to_skip=keys_to_suppress)
5275+
#
5276+
# methods_to_remove = [
5277+
# '_process_card', 'read_bdf', 'disable_cards', 'set_dynamic_syntax',
5278+
# 'create_card_object', 'create_card_object_fields', 'create_card_object_list',
5279+
#
5280+
# 'set_as_msc',
5281+
# 'set_as_nx',
5282+
#
5283+
# 'pop_parse_errors',
5284+
# #'pop_xref_errors',
5285+
# 'set_error_storage',
5286+
# 'is_reject',
5287+
# ]
5288+
# for method_name in method_names:
5289+
# if method_name not in methods_to_remove + keys_to_suppress:
5290+
# #print(method_name)
5291+
# pass
5292+
# else:
5293+
# ## TODO: doesn't work...
5294+
# #delattr(model, method_name)
5295+
# pass
5296+
# model.get_bdf_stats()
52965297
return model
52975298

52985299

pyNastran/bdf/bdf_interface/add_methods.py

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -906,10 +906,13 @@ def add_coord_object(self, coord: Coord, # CORD3G
906906
if key not in model.coords:
907907
model.coords[key] = coord
908908
model._type_to_id_map[coord.type].append(key)
909-
elif coord == model.coords[key]:
910-
model.log.warning(f'replacing equivalent coord:\n{coord}')
909+
return
910+
911+
tag = _get_tag(model, coord, model.coords[key])
912+
if coord == model.coords[key]:
913+
model.log.warning(f'replacing equivalent coord {key}:{tag}\n{coord}')
911914
elif allow_overwrites:
912-
model.log.warning(f'replacing coord:\n{model.coords[key]}with:\n{coord}')
915+
model.log.warning(f'replacing coord{key}:{tag}\n{model.coords[key]}with:\n{coord}')
913916
model.coords[key] = coord
914917
# already handled
915918
#model._type_to_id_map[prop.type].append(key)
@@ -1870,18 +1873,19 @@ def add_object_to_dict(model: BDF, key: int,
18701873
# model.properties_mass[key] = prop
18711874
# model._type_to_id_map[prop.type].append(key)
18721875

1876+
tag = _get_tag(model, obj, obj_dict[key])
18731877
if key not in obj_dict:
18741878
obj_dict[key] = obj
18751879
model._type_to_id_map[obj.type].append(key)
18761880
elif obj == obj_dict[key]:
1877-
model.log.warning(f'replacing equivalent {obj_name}:\n{obj}')
1881+
model.log.warning(f'replacing equivalent {obj_name} {key}:{tag}\n{obj}')
18781882
elif allow_overwrites:
1879-
model.log.warning(f'replacing {obj_name}:\n{obj_dict[key]}with:\n{obj}')
1883+
model.log.warning(f'replacing {obj_name} {key}:{tag}\n{obj_dict[key]}with:\n{obj}')
18801884
obj_dict[key] = obj
18811885
# already handled
18821886
#model._type_to_id_map[prop.type].append(key)
18831887
else:
1884-
model.log.error(f'duplicate {obj_name} {key}:\n{obj_dict[key]}with:\n{obj}')
1888+
model.log.error(f'duplicate {obj_name} {key}:{tag}\n{obj_dict[key]}with:\n{obj}')
18851889
# duplicate_list.append(obj)
18861890
# if model._stop_on_duplicate_error:
18871891
# model.pop_parse_errors()
@@ -1929,16 +1933,35 @@ def add_object_to_dict_no_dupes(model: BDF, key: int, obj_name: str,
19291933
if key not in obj_dict:
19301934
obj_dict[key] = obj
19311935
model._type_to_id_map[obj.type].append(key)
1932-
elif obj == obj_dict[key]:
1933-
model.log.warning(f'replacing equivalent {obj_name}:\n{obj}')
1936+
return
1937+
1938+
tag = _get_tag(model, obj, obj_dict[key])
1939+
if obj == obj_dict[key]:
1940+
model.log.warning(f'replacing equivalent {obj_name} {key}:{tag}\n{obj}')
19341941
elif allow_overwrites:
1935-
model.log.warning(f'replacing {obj_name}:\n{obj_dict[key]}with:\n{obj}')
1942+
model.log.warning(f'replacing {obj_name} {key}:{tag}\n{obj_dict[key]}\nwith:\n{obj}')
19361943
obj_dict[key] = obj
19371944
# already handled
19381945
#model._type_to_id_map[prop.type].append(key)
19391946
else:
1940-
model.log.error(f'duplicate {obj_name} {key}:\n{obj_dict[key]}with:\n{obj}')
1947+
model.log.error(f'duplicate {obj_name} {key}:{tag}\n{obj_dict[key]}\n{obj}')
19411948
duplicate_list.append(obj)
19421949
if model._stop_on_duplicate_error:
19431950
model.pop_parse_errors()
19441951
#raise RuntimeError('pid=%s\nold_prop=\n%snew_prop=\n%s' % (prop.pid, model.properties[key], prop))
1952+
1953+
1954+
def _get_tag(model: BDF, obj1: BaseCard, obj2: BaseCard) -> str:
1955+
"""get a list of files where things are duplicated"""
1956+
if not model.save_file_structure:
1957+
return ''
1958+
ifile1 = obj1.ifile
1959+
ifile2 = obj2.ifile
1960+
filename1 = model.active_filenames[ifile1]
1961+
filename2 = model.active_filenames[ifile2]
1962+
tag = (
1963+
f'\n'
1964+
f'file1: {filename1}\n'
1965+
f'file2: {filename2}'
1966+
)
1967+
return tag

pyNastran/bdf/bdf_interface/attributes.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,12 +1211,12 @@ def type_slot_str(self) -> str:
12111211

12121212
html_msg.append(dash_plus)
12131213

1214-
#for card_group, card_types in sorted(self._slot_to_type_map.items()):
1215-
#html_msg.append('| %s | %s |' % (card_group, ', '.join(card_types)))
1216-
1217-
#html_msg.append(
1218-
#fmt_plus % ('-'*(nchars + 2), '-'*(nline + 2))
1219-
#)
1214+
# for card_group, card_types in sorted(self._slot_to_type_map.items()):
1215+
# html_msg.append('| %s | %s |' % (card_group, ', '.join(card_types)))
1216+
#
1217+
# html_msg.append(
1218+
# fmt_plus % ('-'*(nchars + 2), '-'*(nline + 2))
1219+
# )
12201220
msg = ''.join(html_msg)
12211221
return msg
12221222

pyNastran/bdf/cards/aero/static_loads.py

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
string_or_blank,
2424
)
2525
if TYPE_CHECKING: # pragma: no cover
26-
from pyNastran.bdf.bdf import BDF
26+
from pyNastran.bdf.bdf import BDF, SUPORT, SUPORT1, AESURF, AEPARM, AELINK
2727
from pyNastran.bdf.bdf_interface.bdf_card import BDFCard
2828

2929

@@ -656,7 +656,7 @@ class TRIM(BaseCard):
656656
1: 'sid', 2: 'mach', 3: 'q', 8: 'aeqr',
657657
}
658658

659-
def _get_field_helper(self, n):
659+
def _get_field_helper(self, n: int):
660660
"""
661661
Gets complicated parameters on the TRIM card
662662
@@ -781,9 +781,13 @@ def validate(self):
781781
len(self.labels), len(self.uxs), str(self.labels), str(self.uxs))
782782
raise RuntimeError(msg)
783783

784-
def verify_trim(self, suport, suport1,
785-
aestats, aeparms, aelinks,
786-
aesurf, xref=True):
784+
def verify_trim(self,
785+
suport: list[SUPORT],
786+
suport1: SUPORT1,
787+
aestats: dict[int, AESTAT],
788+
aeparms: dict[str, AEPARM],
789+
aelinks: dict[int, AELINK],
790+
aesurf: dict[str, AESURF], xref=True):
787791
"""
788792
Magic function that makes TRIM cards not frustrating.
789793
@@ -938,39 +942,39 @@ def verify_trim(self, suport, suport1,
938942
raise RuntimeError(msg)
939943

940944
# TODO: this doesn't work for multiple subcases
941-
#ntotal_suport_dofs = nsuport_dofs, nsuport1_dofs
942-
#ndelta = ntrim - nsuport_dofs - nsuport1_dofs - naesurf
943-
#if ndelta != 0:
944-
#msg = 'ntrim - nsuport_dofs - nsuport1_dofs - naesurf = ndelta = %s; ndelta != 0\n' % ndelta
945-
#msg += 'ntrim=%s nsuport_dofs=%s nsuport1_dofs=%s naesurfs=%s' % (
946-
#ntrim, nsuport_dofs, nsuport1_dofs, naesurf)
947-
#raise RuntimeError(msg)
948-
949-
#ndelta = (naestat + naesurf + naeparm + ntrim_aesurf) - (ntrim + naelink + nsuport_dofs + nsuport1_dofs)
950-
#if ndelta != 0:
951-
#msg = (
952-
#'(naestat + naesurf + naeparm + ntrim_aesurf) - '
953-
#'(ntrim + naelink + nsuport_dofs + nsuport1_dofs) = ndelta = %s; ndelta != 0\n'
954-
#'naestat=%s naesurf=%s naeparm=%s ntrim_aesurfs=%s\n'
955-
#'ntrim=%s naelink=%s nsuport_dofs=%s nsuport1_dofs=%s' % (
956-
#ndelta,
957-
#naestat, naesurf, naeparms, ntrim_aesurf,
958-
#ntrim, naelink, nsuport_dofs, nsuport1_dofs))
945+
# ntotal_suport_dofs = nsuport_dofs, nsuport1_dofs
946+
# ndelta = ntrim - nsuport_dofs - nsuport1_dofs - naesurf
947+
# if ndelta != 0:
948+
# msg = 'ntrim - nsuport_dofs - nsuport1_dofs - naesurf = ndelta = %s; ndelta != 0\n' % ndelta
949+
# msg += 'ntrim=%s nsuport_dofs=%s nsuport1_dofs=%s naesurfs=%s' % (
950+
# ntrim, nsuport_dofs, nsuport1_dofs, naesurf)
951+
# raise RuntimeError(msg)
952+
#
953+
# ndelta = (naestat + naesurf + naeparm + ntrim_aesurf) - (ntrim + naelink + nsuport_dofs + nsuport1_dofs)
954+
# if ndelta != 0:
955+
# msg = (
956+
# '(naestat + naesurf + naeparm + ntrim_aesurf) - '
957+
# '(ntrim + naelink + nsuport_dofs + nsuport1_dofs) = ndelta = %s; ndelta != 0\n'
958+
# 'naestat=%s naesurf=%s naeparm=%s ntrim_aesurfs=%s\n'
959+
# 'ntrim=%s naelink=%s nsuport_dofs=%s nsuport1_dofs=%s' % (
960+
# ndelta,
961+
# naestat, naesurf, naeparms, ntrim_aesurf,
962+
# ntrim, naelink, nsuport_dofs, nsuport1_dofs))
959963

960964
nplus = (naestat + naesurf + naeparm)
961965
nminus = ntrim + naelink + nsuport_dofs + nsuport1_dofs
962966

963967
ndelta = nplus - nminus + 0*2*ntrim_aesurfs
964968
if ndelta != 0:
965-
#msg = (
966-
#'(naestat + naesurf + naeparm) - (ntrim + ntrim_aesurf? + naelink + '
967-
#'nsuport_dofs + nsuport1_dofs) = ndelta = %s; ndelta != 0\n'
968-
#'naestat=%s naesurf=%s naeparm=%s ntrim=%s ntrim_aesurf=%s '
969-
#'naelink=%s nsuport_dofs=%s nsuport1_dofs=%s\n' % (
970-
#ndelta,
971-
#naestat, naesurf, naeparm, ntrim, ntrim_aesurf,
972-
#naelink, nsuport_dofs, nsuport1_dofs)
973-
#)
969+
# msg = (
970+
# '(naestat + naesurf + naeparm) - (ntrim + ntrim_aesurf? + naelink + '
971+
# 'nsuport_dofs + nsuport1_dofs) = ndelta = %s; ndelta != 0\n'
972+
# 'naestat=%s naesurf=%s naeparm=%s ntrim=%s ntrim_aesurf=%s '
973+
# 'naelink=%s nsuport_dofs=%s nsuport1_dofs=%s\n' % (
974+
# ndelta,
975+
# naestat, naesurf, naeparm, ntrim, ntrim_aesurf,
976+
# naelink, nsuport_dofs, nsuport1_dofs)
977+
# )
974978
msg = (
975979
'Invalid trim state (ndelta != 0):\n'
976980
f' (naestat + naesurf + naeparm + 0*2*ntrim_aesurf?) = ({naestat} + {naesurf} + {naeparm} + 0*2*{ntrim_aesurf}) = {nplus}\n'
@@ -1193,6 +1197,7 @@ class UXVEC(BaseCard):
11931197
"""
11941198
type = 'UXVEC'
11951199
_field_map = {1: 'sid', }
1200+
11961201
def __init__(self, sid: int, labels: list[str], uxs: list[float],
11971202
comment: str=''):
11981203
BaseCard.__init__(self)

pyNastran/bdf/cards/properties/bush.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ def add_card(cls, card: BDFCard, comment: str=''):
323323
t_fields = cls._read_var(card, 'Ti', istart + 1, istart + 4)
324324
assert len(t_fields) == 3, t_fields
325325
else:
326-
raise RuntimeError('unsupported PBUSH type; pname=%r' % pname)
326+
raise RuntimeError(f'unsupported PBUSH type; pname={pname!r}\n{card}')
327327
#break # old version...
328328
istart += 8
329329
return PBUSH(pid, k_fields, b_fields, ge_fields, rcv_fields, mass,
@@ -1365,7 +1365,7 @@ def add_card(cls, card: BDFCard, comment: str=''):
13651365
# Lumped mass of the cbush; default=0.0
13661366
mass_fields = cls._read_var(card, 'MASSi', istart + 1, istart + 7)
13671367
else:
1368-
raise RuntimeError('unsupported PBUSH type; pname=%r' % pname)
1368+
raise RuntimeError(f'unsupported PBUSH type; pname={pname!r}\n{card}')
13691369
#break # old version...
13701370
istart += 8
13711371
return PBUSH_OPTISTRUCT(pid, k_fields, b_fields, ge_fields, mass_fields,

pyNastran/bdf/field_writer_8.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -211,28 +211,28 @@ def print_float_8(value: float) -> str:
211211
return field
212212

213213

214-
#def print_float_or_int_8(value: int | float) - str:
215-
#"""
216-
#Prints an 8-character width field
217-
218-
#Parameters
219-
#----------
220-
#value : int/float
221-
#the value to print
222-
223-
#Returns
224-
#-------
225-
#field : str
226-
#an 8-character string
227-
#"""
228-
#if isinstance(value, (float, float32, float64)):
229-
#field = print_float_8(value)
230-
#elif isinstance(value, int):
231-
#field = "%8i" % value
232-
#else:
233-
#msg = 'Invalid Type: value=%r type=%s' % (value, type(value))
234-
#raise TypeError(msg)
235-
#return field
214+
# def print_float_or_int_8(value: int | float) - str:
215+
# """
216+
# Prints an 8-character width field
217+
#
218+
# Parameters
219+
# ----------
220+
# value : int/float
221+
# the value to print
222+
#
223+
# Returns
224+
# -------
225+
# field : str
226+
# an 8-character string
227+
# """
228+
# if isinstance(value, (float, float32, float64)):
229+
# field = print_float_8(value)
230+
# elif isinstance(value, int):
231+
# field = "%8i" % value
232+
# else:
233+
# msg = 'Invalid Type: value=%r type=%s' % (value, type(value))
234+
# raise TypeError(msg)
235+
# return field
236236

237237

238238
def print_field_8(value: Optional[int | float | str]) -> str:
@@ -404,7 +404,7 @@ def print_int_card_blocks(fields_blocks: list[Any]) -> str:
404404
]
405405
msg = print_int_card_blocks(fields_blocks)
406406
print(msg)
407-
>>> 'SET1 a 1. 3 1 2 3\n'
407+
>>> "SET1 a 1. 3 1 2 3"
408408
409409
"""
410410
card_name = fields_blocks[0]

pyNastran/bdf/mesh_utils/mpc_dependency.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ def get_rigid_elements_with_node_ids(model: BDF, node_ids):
177177
return rbes
178178

179179

180-
def get_dependent_nid_to_components(model: BDF, mpc_id=None, stop_on_failure=True):
180+
def get_dependent_nid_to_components(model: BDF, mpc_id=None,
181+
stop_on_failure=True):
181182
"""
182183
Gets a dictionary of the dependent node/components.
183184
@@ -283,6 +284,7 @@ def get_dependent_nid_to_components(model: BDF, mpc_id=None, stop_on_failure=Tru
283284
model.log.warning(msg)
284285
else:
285286
raise RuntimeError(rigid_element.type)
287+
286288
return dependent_nid_to_components
287289

288290

@@ -311,13 +313,13 @@ def get_lines_rigid(model: BDF) -> Any:
311313
assert isinstance(n2, integer_types), 'RBE3 eid=%s Giji=%s' % (elem.eid, Giji)
312314
lines_rigid.append([n1, n2])
313315
elif elem.type == 'RBE2':
314-
#list_fields = ['RBE2', elem.eid, elem.Gn(), elem.cm
315-
#] + elem.Gmi_node_ids + [elem.alpha]
316+
# list_fields = ['RBE2', elem.eid, elem.Gn(), elem.cm
317+
# ] + elem.Gmi_node_ids + [elem.alpha]
316318
n2 = elem.Gn() # independent
317319
nids1 = elem.Gmi_node_ids # dependent
318320
for n1 in nids1:
319321
lines_rigid.append([n1, n2])
320-
elif elem.type in ['RBAR', 'RBAR1', 'RROD']: ## TODO: these aren't quite right
322+
elif elem.type in ['RBAR', 'RBAR1', 'RROD']: # TODO: these aren't quite right
321323
dependent = elem.Ga()
322324
independent = elem.Gb()
323325
lines_rigid.append([dependent, independent])

0 commit comments

Comments
 (0)