3232
3333from pyNastran .utils import object_attributes , check_path , PathLike
3434from pyNastran .utils .numpy_utils import (
35- integer_types , float_types )
35+ integer_types )
3636from pyNastran .bdf .utils import parse_patran_syntax
3737from pyNastran .bdf .bdf_interface .utils import (
3838 _parse_pynastran_header , to_fields , parse_executive_control_deck ,
3939 fill_dmigs , _get_card_name , _parse_dynamic_syntax ,
40+ _prep_comment ,
4041)
4142from pyNastran .bdf .bdf_interface .add_card import CARD_MAP
4243from pyNastran .bdf .bdf_interface .replication import (
486487def load_bdf_object (obj_filename :str , xref : bool = True , log = None , debug : bool = True ):
487488 model = BDF (log = log , debug = debug )
488489 model .load (obj_filename = obj_filename )
489- model .cross_reference (xref = xref , xref_nodes = True , xref_elements = True ,
490- xref_nodes_with_elements = True ,
491- xref_properties = True ,
492- xref_masses = True ,
493- xref_materials = True ,
494- xref_loads = True ,
495- xref_constraints = True ,
496- xref_aero = True ,
497- xref_sets = True ,
498- xref_optimization = True )
490+ model .cross_reference (
491+ run_setup = True ,
492+ run_geom_check = False )
499493 return model
500494
501495
@@ -1367,7 +1361,8 @@ def read_bdf(self, bdf_filename: Optional[PathLike]=None,
13671361 >>> g1 = bdf.Node(1)
13681362 >>> print(g1.get_position())
13691363 [10.0, 12.0, 42.0]
1370- >>> bdf.write_card(bdf_filename2)
1364+ >>> bdf_filename_out = 'fem_out.bdf'
1365+ >>> bdf.write_card(bdf_filename_out)
13711366 >>> print(bdf.card_stats())
13721367
13731368 ---BDF Statistics---
@@ -1954,6 +1949,7 @@ def set_dynamic_syntax(self, dict_of_vars: dict[str, int | float | str]) -> None
19541949 >>> dict_of_vars = {'xVar': 1.0, 'yVar', 2.0, 'zVar':3.0}
19551950 >>> bdf = BDF()
19561951 >>> bdf.set_dynamic_syntax(dict_of_vars)
1952+ >>> bdf_filename = 'fem.bdf'
19571953 >>> bdf.read_bdf(bdf_filename, xref=True)
19581954
19591955 Notes
@@ -3071,18 +3067,18 @@ def _prepare_dmiji(self, unused_card: list[str], card_obj: BDFCard,
30713067 assert isinstance (ifile , integer_types ), ifile
30723068 return self ._prepare_dmix (DMIJI , self ._add_methods .add_dmiji_object , card_obj , ifile , comment = comment )
30733069
3074- def _prepare_ringfl (self , unused_card : list [str ], card_obj : BDFCard ,
3075- ifile : int , comment : str = '' ) -> None :
3076- """adds a RINGFL"""
3077- assert isinstance (ifile , integer_types ), ifile
3078- rings = [RINGFL .add_card (card_obj , icard = 0 , comment = comment )]
3079- if card_obj .field (3 ):
3080- rings .append (RINGFL .add_card (card_obj , icard = 1 , comment = comment ))
3081- if card_obj .field (5 ):
3082- rings .append (RINGFL .add_card (card_obj , icard = 2 , comment = comment ))
3083- for ring in rings :
3084- self ._add_methods .add_ringfl_object (ring )
3085- return rings
3070+ # def _prepare_ringfl(self, unused_card: list[str], card_obj: BDFCard,
3071+ # ifile: int, comment: str='') -> None:
3072+ # """adds a RINGFL"""
3073+ # assert isinstance(ifile, integer_types), ifile
3074+ # rings = [RINGFL.add_card(card_obj, icard=0, comment=comment)]
3075+ # if card_obj.field(3):
3076+ # rings.append(RINGFL.add_card(card_obj, icard=1, comment=comment))
3077+ # if card_obj.field(5):
3078+ # rings.append(RINGFL.add_card(card_obj, icard=2, comment=comment))
3079+ # for ring in rings:
3080+ # self._add_methods.add_ringfl_object(ring)
3081+ # return rings
30863082
30873083 def _prepare_acmodl (self , unused_card : list [str ], card_obj : BDFCard ,
30883084 ifile : int , comment : str = '' ) -> None :
@@ -3400,13 +3396,13 @@ def _add_card_helper_lax(self, card_obj: BDFCard, card: list[str],
34003396 raise DisabledCardError (f'stopping on card={ card_name } ' )
34013397
34023398 if card_name in self ._card_parser :
3403-
34043399 card_class , add_card_function = self ._card_parser [card_name ]
3405- if hasattr (card_class , 'add_card_lax' ):
3406- class_instance = card_class .add_card_lax (card_obj , comment = comment )
3407- else :
3408-
3409- class_instance = card_class .add_card (card_obj , comment = comment )
3400+ add_card = getattr (card_class , 'add_card_lax' ) if hasattr (card_class , 'add_card_lax' ) else getattr (card_class , 'add_card' )
3401+ class_instance = add_card (card_obj , comment = comment )
3402+ # if hasattr(card_class, 'add_card_lax'):
3403+ # class_instance = card_class.add_card_lax(card_obj, comment=comment)
3404+ # else:
3405+ # class_instance = card_class.add_card(card_obj, comment=comment)
34103406 add_card_function (class_instance )
34113407
34123408 elif card_name in self ._card_parser_prepare :
@@ -3449,11 +3445,16 @@ def _add_card_helper(self, card_obj: BDFCard, card: list[str],
34493445
34503446 if card_name in self ._card_parser :
34513447 card_class , add_card_function = self ._card_parser [card_name ]
3448+ add_card = (
3449+ getattr (card_class , 'add_card_lax' )
3450+ if not self .is_strict_card_parser and hasattr (card_class , 'add_card_lax' )
3451+ else getattr (card_class , 'add_card' ))
34523452 try :
3453- if not self .is_strict_card_parser and hasattr (card_class , 'add_card_lax' ):
3454- class_instance = card_class .add_card_lax (card_obj , comment = comment )
3455- else :
3456- class_instance = card_class .add_card (card_obj , comment = comment )
3453+ class_instance = add_card (card_obj , comment = comment )
3454+ # if not self.is_strict_card_parser and hasattr(card_class, 'add_card_lax'):
3455+ # class_instance = card_class.add_card_lax(card_obj, comment=comment)
3456+ # else:
3457+ # class_instance = card_class.add_card(card_obj, comment=comment)
34573458 card_idi = add_card_function (class_instance )
34583459 if card_name not in OBJ_CARDS : # pragma: no cover
34593460 if not isinstance (card_idi , int ):
@@ -3578,6 +3579,7 @@ def get_displacement_index_xyz_cp_cd(self, fdtype: str='float64',
35783579 # assume GRID 1 has a CD=10, CP=0
35793580 # assume GRID 2 has a CD=10, CP=0
35803581 # assume GRID 5 has a CD=50, CP=0
3582+ >>> model = BDF()
35813583 >>> model.point_ids
35823584 [1, 2, 5]
35833585 >>> out = model.get_displacement_index_xyz_cp_cd()
@@ -3690,6 +3692,7 @@ def get_xyz_in_coord_array(self, cid: int=0,
36903692
36913693 Examples
36923694 --------
3695+ >>> model = BDF()
36933696 >>> out = model.get_xyz_in_coord_array(cid=0, fdtype='float64', idtype='int32')
36943697 >>> nid_cp_cd, xyz_cid, xyz_cp, icd_transform, icp_transform = out
36953698 """
@@ -3740,6 +3743,8 @@ def transform_xyzcp_to_xyz_cid(self, xyz_cp: np.ndarray,
37403743 # assume GRID 1 has a CD=10, CP=0
37413744 # assume GRID 2 has a CD=10, CP=0
37423745 # assume GRID 5 has a CD=50, CP=1
3746+
3747+ >>> model = BDF()
37433748 >>> model.point_ids
37443749 [1, 2, 5]
37453750 >>> out = model.get_displacement_index_xyz_cp_cd()
@@ -3910,6 +3915,8 @@ def get_displacement_index(self) -> tuple[Any, Any, dict[int, Any]]:
39103915 # assume GRID 1 has a CD=10
39113916 # assume GRID 2 has a CD=10
39123917 # assume GRID 5 has a CD=50
3918+
3919+ >>> model = BDF()
39133920 >>> model.point_ids
39143921 [1, 2, 5]
39153922 >>> icd_transform = model.get_displacement_index()
@@ -3948,8 +3955,10 @@ def increase_card_count(self, card_name: str, count_num: int=1) -> None:
39483955 count_num : int, optional
39493956 the amount to increment by (default=1)
39503957
3951- >>> bdf.read_bdf(bdf_filename)
3952- >>> bdf.card_count['GRID']
3958+ >>> model = BDF()
3959+ >>> bdf_filename = 'fem.bdf'
3960+ >>> model.read_bdf(bdf_filename)
3961+ >>> model.card_count['GRID']
39533962 50
39543963
39553964 """
@@ -4437,7 +4446,8 @@ def _read_bdf_cards(self, bdf_filename: Optional[str]=None,
44374446 >>> g1 = bdf.Node(1)
44384447 >>> print(g1.get_position())
44394448 [10.0, 12.0, 42.0]
4440- >>> bdf.write_card(bdf_filename2)
4449+ >>> bdf_filename_out = 'fem_out.bdf'
4450+ >>> bdf.write_card(bdf_filename_out)
44414451 >>> print(bdf.card_stats())
44424452
44434453 ---BDF Statistics---
@@ -4801,7 +4811,8 @@ def read_bdf(bdf_filename: Optional[PathLike]=None, validate: bool=True, xref: b
48014811 >>> g1 = bdf.Node(1)
48024812 >>> print(g1.get_position())
48034813 [10.0, 12.0, 42.0]
4804- >>> bdf.write_card(bdf_filename2)
4814+ >>> bdf_filename_out = 'fem_out.bdf'
4815+ >>> bdf.write_card(bdf_filename_out)
48054816 >>> print(bdf.card_stats())
48064817
48074818 ---BDF Statistics---
@@ -4817,7 +4828,7 @@ def read_bdf(bdf_filename: Optional[PathLike]=None, validate: bool=True, xref: b
48174828 """
48184829 model = BDF (log = log , debug = debug , mode = mode )
48194830 if read_cards and skip_cards :
4820- msg = 'read_cards=%s skip_cards=%s cannot be used at the same time'
4831+ msg = f 'read_cards={ read_cards } skip_cards={ skip_cards } cannot be used at the same time'
48214832 raise NotImplementedError (msg )
48224833 if skip_cards :
48234834 model .disable_cards (skip_cards )
@@ -4831,53 +4842,9 @@ def read_bdf(bdf_filename: Optional[PathLike]=None, validate: bool=True, xref: b
48314842 xref = xref , punch = punch , read_includes = True ,
48324843 save_file_structure = save_file_structure ,
48334844 encoding = encoding )
4834-
4835- #if 0:
4836- ### TODO: remove all the extra methods
4837-
4838- #keys_to_suppress = []
4839- #method_names = model.object_methods(keys_to_skip=keys_to_suppress)
4840-
4841- #methods_to_remove = [
4842- #'_process_card', 'read_bdf', 'disable_cards', 'set_dynamic_syntax',
4843- #'create_card_object', 'create_card_object_fields', 'create_card_object_list',
4844-
4845- #'add_NLPARM', 'add_NLPCI',
4846- #'add_PARAM',',
4847-
4848- #'add_card', 'add_card_fields', 'add_card_lines', 'add_cmethod', 'add_constraint',
4849- #'add_convection_property', 'add_creep_material',
4850- #'add_material_dependence', 'add_method',
4851- #'add_random_table',
4852- #'add_table', 'add_table_sdamping', 'add_thermal_BC', 'add_thermal_element',
4853-
4854- #'set_as_msc',
4855- #'set_as_nx',
4856-
4857- #'pop_parse_errors',
4858- #'set_error_storage',
4859- #'is_reject',
4860- #]
4861- #for method_name in method_names:
4862- #if method_name not in methods_to_remove + keys_to_suppress:
4863- ##print(method_name)
4864- #pass
4865- #else:
4866- ### TODO: doesn't work...
4867- ##delattr(model, method_name)
4868- #pass
4869- #model.get_bdf_stats()
48704845 return model
48714846
4872- def _prep_comment (comment ):
4873- return comment .rstrip ()
4874- #print('comment = %r' % comment)
4875- #comment = ' this\n is\n a comment\n'
4876- #print(comment.rstrip('\n').split('\n'))
4877- #sline = [comment[1:] if len(comment) and comment[0] == ' ' else comment
4878- #for comment in comment.rstrip().split('\n')]
4879- #print('sline = ', sline)
4880- def _check_replicated_cards (replicated_cards ):
4847+ def _check_replicated_cards (replicated_cards ) -> None :
48814848 """helper method for ``parse_cards_list``"""
48824849 replicated_card_old = []
48834850 try :
0 commit comments