@@ -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