Skip to content

Commit 6afe19e

Browse files
committed
test_bdf
- added no_similar_eid flag more flutter preferences
1 parent d2fa90a commit 6afe19e

File tree

14 files changed

+490
-338
lines changed

14 files changed

+490
-338
lines changed

pyNastran/bdf/bdf_interface/add_methods.py

Lines changed: 65 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,9 @@ def add_param_object(self, param: PARAM, allow_overwrites: bool=False) -> None:
245245
model = self.model
246246
if key in model.params and not allow_overwrites:
247247
if not param == model.params[key]:
248-
#if param.key in self.params:
249-
#msg = 'key=%s param=%s old_param=%s' % (key, param, self.params[key])
250-
#raise KeyError(msg)
248+
# if param.key in self.params:
249+
# msg = 'key=%s param=%s old_param=%s' % (key, param, self.params[key])
250+
# raise KeyError(msg)
251251
model.log.warning('key=%s param=%s old_param=%s' %
252252
(key, param, model.params[key]))
253253
model.params[key] = param
@@ -485,9 +485,9 @@ def add_ao_object(self, elem_flag: CBARAO,
485485
assert key > 0, 'eid=%s must be positive; elem_flag=\n%s' % (key, elem_flag)
486486
if key in model.ao_element_flags and not allow_overwrites:
487487
if not elem_flag == model.ao_element_flags[key]:
488-
#self.model._duplicate_elements.append(elem_flag)
489-
#if self.model._stop_on_duplicate_error:
490-
#self.model.pop_parse_errors()
488+
# self.model._duplicate_elements.append(elem_flag)
489+
# if self.model._stop_on_duplicate_error:
490+
# self.model.pop_parse_errors()
491491
assert elem_flag.eid not in self.model.ao_element_flags, 'eid=%s\nold_ao_element=\n%snew_ao_element=\n%s' % (
492492
elem_flag.eid, model.ao_element_flags[elem_flag.eid], elem_flag)
493493
else:
@@ -894,13 +894,32 @@ def add_coord_object(self, coord: Coord, # CORD3G
894894
# add_object_to_dict_no_dupes(model, key, 'coords', coord, model.coords,
895895
# model._duplicate_coords, allow_overwrites)
896896

897-
if key in self.model.coords:
898-
#if not allow_overwrites:
899-
if not coord == self.model.coords[key]:
900-
self.model._duplicate_coords.append(coord)
897+
# v1.4
898+
# if key in self.model.coords:
899+
# #if not allow_overwrites:
900+
# if not coord == self.model.coords[key]:
901+
# self.model._duplicate_coords.append(coord)
902+
# else:
903+
# self.model.coords[key] = coord
904+
# self.model._type_to_id_map[coord.type].append(key)
905+
906+
if key not in model.coords:
907+
model.coords[key] = coord
908+
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}')
911+
elif allow_overwrites:
912+
model.log.warning(f'replacing coord:\n{model.coords[key]}with:\n{coord}')
913+
model.coords[key] = coord
914+
# already handled
915+
#model._type_to_id_map[prop.type].append(key)
901916
else:
902-
self.model.coords[key] = coord
903-
self.model._type_to_id_map[coord.type].append(key)
917+
# error, but no crash b/c op2
918+
model.log.error(f'duplicate coord {key}:\n{model.coords[key]}with:\n{coord}')
919+
# duplicate_list.append(obj)
920+
# if model._stop_on_duplicate_error:
921+
# model.pop_parse_errors()
922+
#raise RuntimeError('pid=%s\nold_prop=\n%snew_prop=\n%s' % (prop.pid, model.properties[key], prop))
904923

905924
def add_matcid_object(self, matcid: MATCID) -> None:
906925
"""adds a MATCID object"""
@@ -1120,18 +1139,18 @@ def add_aeros_object(self, aeros: AEROS) -> None:
11201139
# only one AEROS card allowed
11211140
assert self.model.aeros is None, '\naeros=\n%s old=\n%s' % (aeros, self.model.aeros)
11221141
self.model.aeros = aeros
1123-
#self.model._type_to_id_map[aeros.type].append(key)
1124-
1125-
#def add_aeroz_object(self, aeroz: AEROZ) -> None:
1126-
#"""adds an AEROZ object"""
1127-
#key = aeroz.sid
1128-
#if key in self.model.aeroz and not allow_overwrites:
1129-
#if not aeroz == self.model.zona.aeroz[key]:
1130-
#assert key not in self.model.aeroz, 'AEROZ.sid=%s\nold=\n%snew=\n%s' % (key, self.model.aeroz[key], aeroz)
1131-
#else:
1132-
#assert key > 0, 'sid=%s method=\n%s' % (key, aefact)
1133-
#self.model.aeroz[key] = aeroz
1134-
#self.model._type_to_id_map[aeroz.type].append(key)
1142+
# self.model._type_to_id_map[aeros.type].append(key)
1143+
1144+
# def add_aeroz_object(self, aeroz: AEROZ) -> None:
1145+
# """adds an AEROZ object"""
1146+
# key = aeroz.sid
1147+
# if key in self.model.aeroz and not allow_overwrites:
1148+
# if not aeroz == self.model.zona.aeroz[key]:
1149+
# assert key not in self.model.aeroz, 'AEROZ.sid=%s\nold=\n%snew=\n%s' % (key, self.model.aeroz[key], aeroz)
1150+
# else:
1151+
# assert key > 0, 'sid=%s method=\n%s' % (key, aefact)
1152+
# self.model.aeroz[key] = aeroz
1153+
# self.model._type_to_id_map[aeroz.type].append(key)
11351154

11361155
def add_baror_object(self, baror: BAROR) -> None:
11371156
"""adds an BAROR object"""
@@ -1147,17 +1166,17 @@ def add_beamor_object(self, beamor: BEAMOR) -> None:
11471166
if self.model.beamor is None:
11481167
self.model.beamor = beamor
11491168

1150-
#def add_axic_object(self, axic: AXIC) -> None:
1151-
#"""adds an AXIC object"""
1152-
## only one AXIC card allowed
1153-
#assert self.model.axic is None, '\naxic=\n%s old=\n%s' % (axic, self.model.axic)
1154-
#self.model.axic = axic
1155-
1156-
#def add_axif_object(self, axif: AXIF) -> None:
1157-
#"""adds an AXIF object"""
1158-
## only one AXIC card allowed
1159-
#assert self.model.axif is None, '\naxif=\n%s old=\n%s' % (axif, self.model.axif)
1160-
#self.model.axif = axif
1169+
# def add_axic_object(self, axic: AXIC) -> None:
1170+
# """adds an AXIC object"""
1171+
# # only one AXIC card allowed
1172+
# assert self.model.axic is None, '\naxic=\n%s old=\n%s' % (axic, self.model.axic)
1173+
# self.model.axic = axic
1174+
#
1175+
# def add_axif_object(self, axif: AXIF) -> None:
1176+
# """adds an AXIF object"""
1177+
# # only one AXIC card allowed
1178+
# assert self.model.axif is None, '\naxif=\n%s old=\n%s' % (axif, self.model.axif)
1179+
# self.model.axif = axif
11611180

11621181
def add_acmodl_object(self, acmodl: ACMODL) -> None:
11631182
"""adds a ACMODL object"""
@@ -1335,7 +1354,6 @@ def add_diverg_object(self, diverg: DIVERG, allow_overwrites: bool=False) -> Non
13351354
self.model.divergs[key] = diverg
13361355
self.model._type_to_id_map[diverg.type].append(key)
13371356

1338-
13391357
def add_uxvec_object(self, uxvec: UXVEC,
13401358
allow_overwrites: bool=False) -> None:
13411359
"""adds an UXVEC object"""
@@ -1376,16 +1394,16 @@ def add_dconstr_object(self, dconstr: DCONSTR | DCONADD) -> None:
13761394
self.model.dconstrs[key] = [dconstr]
13771395
self.model._type_to_id_map[dconstr.type].append(key)
13781396

1379-
#def add_DCONADD(self, dconadd, allow_overwrites: bool=False) -> None:
1380-
#key = dconadd.oid
1381-
#if key in self.model.dconstrs and not allow_overwrites:
1382-
#if not dconadd == self.model.dconstrs[key]:
1383-
#assert key not in self.model.dconstrs, 'DCONADD=%s old=\n%snew=\n%s' % (
1384-
#key, self.model.dconstrs[key], dconadd)
1385-
#else:
1386-
#assert key > 0, 'dcid=%s dconadd=%s' % (key, dconadd)
1387-
#self.model.dconstrs[key] = dconadd
1388-
#self.model._type_to_id_map[dconadd.type].append(key)
1397+
# def add_dconadd(self, dconadd, allow_overwrites: bool=False) -> None:
1398+
# key = dconadd.oid
1399+
# if key in self.model.dconstrs and not allow_overwrites:
1400+
# if not dconadd == self.model.dconstrs[key]:
1401+
# assert key not in self.model.dconstrs, 'DCONADD=%s old=\n%snew=\n%s' % (
1402+
# key, self.model.dconstrs[key], dconadd)
1403+
# else:
1404+
# assert key > 0, 'dcid=%s dconadd=%s' % (key, dconadd)
1405+
# self.model.dconstrs[key] = dconadd
1406+
# self.model._type_to_id_map[dconadd.type].append(key)
13891407

13901408
def add_desvar_object(self, desvar: DESVAR) -> None:
13911409
"""adds a DESVAR object"""
@@ -1822,7 +1840,7 @@ def _add_value_to_dict(result: dict[int, Any], key: int, card: Any,
18221840

18231841

18241842
def add_object_to_dict(model: BDF, key: int,
1825-
obj_name : str,
1843+
obj_name: str,
18261844
obj: BaseCard,
18271845
obj_dict: dict[int, BaseCard],
18281846
allow_overwrites: bool) -> None:

pyNastran/bdf/bdf_interface/write_mesh.py

Lines changed: 93 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -595,11 +595,11 @@ def _write_constraints(self, bdf_file: TextFile, size: int=8, is_double: bool=Fa
595595
bdf_file.write(suport.write_card(size, is_double))
596596

597597
if self.spcs or self.spcadds or self.spcoffs:
598-
#bdf_file.write('$SPCs\n')
599-
#str_spc = str(self.spcObject) # old
600-
#if str_spc:
601-
#bdf_file.write(str_spc)
602-
#else:
598+
# bdf_file.write('$SPCs\n')
599+
# str_spc = str(self.spcObject) # old
600+
# if str_spc:
601+
# bdf_file.write(str_spc)
602+
# else:
603603
bdf_file.write('$SPCs\n')
604604
for (unused_id, spcadds) in sorted(self.spcadds.items()):
605605
for spcadd in spcadds:
@@ -661,18 +661,35 @@ def _write_contact(self, bdf_file: TextFile, size: int=8, is_double: bool=False,
661661
bdf_file.write(bgset.write_card(size, is_double))
662662

663663
def _write_coords(self, bdf_file: TextFile, size: int=8, is_double: bool=False,
664-
is_long_ids: Optional[bool]=None) -> None:
664+
is_long_ids: Optional[bool]=None,
665+
breakout_coords: bool=False) -> None:
665666
"""Writes the coordinate cards in a sorted order"""
666667
size, is_long_ids = self._write_mesh_long_ids_size(size, is_long_ids)
667668
if len(self.coords) > 1:
668669
bdf_file.write('$COORDS\n')
669-
for (coord_id, coord) in sorted(self.coords.items()):
670-
if coord_id == 0:
671-
continue
672-
try:
673-
bdf_file.write(coord.write_card(size, is_double))
674-
except RuntimeError:
675-
bdf_file.write(coord.write_card_16(is_double))
670+
671+
if breakout_coords:
672+
for (coord_id, coord) in sorted(self.coords.items()):
673+
if coord_id == 0:
674+
continue
675+
if coord.origin is not None:
676+
bdf_file.write(f'$ cid={coord_id}\n')
677+
bdf_file.write(f'$ origin={coord.origin}\n')
678+
bdf_file.write(f'$ i={coord.i}\n')
679+
bdf_file.write(f'$ j={coord.j}\n')
680+
bdf_file.write(f'$ k={coord.k}\n')
681+
try:
682+
bdf_file.write(coord.write_card(size, is_double))
683+
except RuntimeError:
684+
bdf_file.write(coord.write_card_16(is_double))
685+
else:
686+
for (coord_id, coord) in sorted(self.coords.items()):
687+
if coord_id == 0:
688+
continue
689+
try:
690+
bdf_file.write(coord.write_card(size, is_double))
691+
except RuntimeError:
692+
bdf_file.write(coord.write_card_16(is_double))
676693

677694
def _write_matcids(self, bdf_file: TextFile, size: int=8, is_double: bool=False,
678695
is_long_ids: Optional[bool]=None) -> None:
@@ -797,12 +814,12 @@ def _write_loads(self, bdf_file: TextFile, size: int=8, is_double: bool=False,
797814
else:
798815
for (key, loadcase) in sorted(self.loads.items()):
799816
for load in loadcase:
800-
# if load.type == 'PLOAD2':
801-
# try:
802-
# load.raw_fields()
803-
# except Exception:
804-
# bdf_file.write(load.write_card_separate(self, size, is_double))
805-
# continue
817+
# if load.type == 'PLOAD2':
818+
# try:
819+
# load.raw_fields()
820+
# except Exception:
821+
# bdf_file.write(load.write_card_separate(self, size, is_double))
822+
# continue
806823
try:
807824
bdf_file.write(load.write_card(size, is_double))
808825
except Exception:
@@ -940,49 +957,63 @@ def _write_nodes(self, bdf_file: TextFile, size: int=8, is_double: bool=False,
940957
#self._write_nodes_associated(bdf_file, size, is_double)
941958

942959
def _write_grids(self, bdf_file: TextFile, size: int=8, is_double: bool=False,
943-
is_long_ids: Optional[bool]=None) -> None:
960+
is_long_ids: Optional[bool]=None,
961+
write_as_cid0: bool=False,
962+
) -> None:
944963
"""Writes the GRID-type cards"""
945964
size, is_long_ids = self._write_mesh_long_ids_size(size, is_long_ids)
946-
if self.nodes:
965+
if self.nodes or self.grdset:
947966
bdf_file.write('$NODES\n')
948967
if self.grdset:
949968
bdf_file.write(self.grdset.write_card(size))
950-
write_dict(bdf_file, self.nodes, size, is_double, is_long_ids)
951-
952-
#def _write_nodes_associated(self, bdf_file, size=8, is_double=False):
953-
#"""
954-
#Writes the NODE-type in associated and unassociated groups.
955-
956-
#.. warning:: Sometimes crashes, probably on invalid BDFs.
957-
#"""
958-
#associated_nodes = set()
959-
#for (eid, element) in self.elements.items():
960-
#associated_nodes = associated_nodes.union(set(element.node_ids))
961-
962-
#all_nodes = set(self.nodes.keys())
963-
#unassociated_nodes = list(all_nodes.difference(associated_nodes))
964-
##missing_nodes = all_nodes.difference(
965-
966-
## TODO: this really shouldn't be a list...???
967-
#associated_nodes = list(associated_nodes)
968-
969-
#if associated_nodes:
970-
#bdf_file.write('$ASSOCIATED NODES\n')
971-
#if self.grdset:
972-
#bdf_file.write(self.grdset.write_card(size, is_double))
973-
## TODO: this really shouldn't be a dictionary...???
974-
#for key, node in sorted(associated_nodes.items()):
975-
#bdf_file.write(node.write_card(size, is_double))
976-
977-
#if unassociated_nodes:
978-
#bdf_file.write('$UNASSOCIATED NODES\n')
979-
#if self.grdset and not associated_nodes:
980-
#v(self.grdset.write_card(size, is_double))
981-
#for key, node in sorted(unassociated_nodes.items()):
982-
#if key in self.nodes:
983-
#bdf_file.write(node.write_card(size, is_double))
984-
#else:
985-
#bdf_file.write('$ Missing NodeID=%s' % key)
969+
970+
if write_as_cid0:
971+
for (unused_nid, node) in sorted(self.nodes.items()):
972+
if node.cp != 0:
973+
xyz = node.get_position()
974+
node.uncross_reference()
975+
node.cp = 0
976+
node.xyz = xyz
977+
bdf_file.write(node.write_card(size, is_double))
978+
else:
979+
bdf_file.write(node.write_card(size, is_double))
980+
else:
981+
write_dict(bdf_file, self.nodes, size, is_double, is_long_ids)
982+
983+
# def _write_nodes_associated(self, bdf_file, size=8, is_double=False):
984+
# """
985+
# Writes the NODE-type in associated and unassociated groups.
986+
#
987+
# .. warning:: Sometimes crashes, probably on invalid BDFs.
988+
# """
989+
# associated_nodes = set()
990+
# for (eid, element) in self.elements.items():
991+
# associated_nodes = associated_nodes.union(set(element.node_ids))
992+
#
993+
# all_nodes = set(self.nodes.keys())
994+
# unassociated_nodes = list(all_nodes.difference(associated_nodes))
995+
# #missing_nodes = all_nodes.difference(
996+
#
997+
# # TODO: this really shouldn't be a list...???
998+
# associated_nodes = list(associated_nodes)
999+
#
1000+
# if associated_nodes:
1001+
# bdf_file.write('$ASSOCIATED NODES\n')
1002+
# if self.grdset:
1003+
# bdf_file.write(self.grdset.write_card(size, is_double))
1004+
# # TODO: this really shouldn't be a dictionary...???
1005+
# for key, node in sorted(associated_nodes.items()):
1006+
# bdf_file.write(node.write_card(size, is_double))
1007+
#
1008+
# if unassociated_nodes:
1009+
# bdf_file.write('$UNASSOCIATED NODES\n')
1010+
# if self.grdset and not associated_nodes:
1011+
# v(self.grdset.write_card(size, is_double))
1012+
# for key, node in sorted(unassociated_nodes.items()):
1013+
# if key in self.nodes:
1014+
# bdf_file.write(node.write_card(size, is_double))
1015+
# else:
1016+
# bdf_file.write('$ Missing NodeID=%s' % key)
9861017

9871018
def _write_optimization(self, bdf_file: TextFile, size: int=8, is_double: bool=False,
9881019
is_long_ids: Optional[bool]=None) -> None:
@@ -1049,20 +1080,15 @@ def _write_parametric(self, bdf_file: TextFile, size: int=8, is_double: bool=Fal
10491080
if is_parametric:
10501081
for (unused_id, pset) in sorted(self.pset.items()):
10511082
bdf_file.write(pset.write_card(size, is_double))
1052-
10531083
for (unused_adapt_id, pvals) in sorted(self.pval.items()):
10541084
for pval in pvals:
10551085
bdf_file.write(pval.write_card(size, is_double))
1056-
10571086
for (unused_id, gmcurv) in sorted(self.gmcurv.items()):
10581087
bdf_file.write(gmcurv.write_card(size, is_double))
1059-
10601088
for (unused_id, gmsurf) in sorted(self.gmsurf.items()):
10611089
bdf_file.write(gmsurf.write_card(size, is_double))
1062-
10631090
for (unused_id, feedge) in sorted(self.feedge.items()):
10641091
bdf_file.write(feedge.write_card(size, is_double))
1065-
10661092
for (unused_id, feface) in sorted(self.feface.items()):
10671093
bdf_file.write(feface.write_card(size, is_double))
10681094

@@ -1124,11 +1150,11 @@ def _write_properties_by_element_type(self, bdf_file: TextFile, size: int=8,
11241150

11251151
bdf_file.write('$PROPERTIES\n')
11261152
for prop_class, prop_types in propertys_class_to_property_types.items():
1127-
#print(prop_class, prop_types)
1128-
#for prop_type in prop_types:
1129-
#if prop_type not in properties_by_class:
1130-
#continue
1131-
#print(' ', prop_type)
1153+
# print(prop_class, prop_types)
1154+
# for prop_type in prop_types:
1155+
# if prop_type not in properties_by_class:
1156+
# continue
1157+
# print(' ', prop_type)
11321158
props = properties_by_class[prop_class]
11331159
if not props:
11341160
continue

0 commit comments

Comments
 (0)