1818 AEFACT , AELINK ,
1919 AELIST ,
2020 AEPARM , AESURF , # AESURFS,
21- CAERO1 , CAERO2 , CAERO3 , CAERO4 , CAERO5 ,
22- PAERO1 , PAERO2 , PAERO3 , PAERO4 , PAERO5 ,
21+ # CAERO1, CAERO2, CAERO3, CAERO4, CAERO5,
22+ # PAERO1, PAERO2, PAERO3, PAERO4, PAERO5,
2323 #MONPNT1, MONPNT2, MONPNT3,
24- SPLINE1 , SPLINE2 , SPLINE3 , SPLINE4 , SPLINE5 ,
24+ # SPLINE1, SPLINE2, SPLINE3, SPLINE4, SPLINE5,
2525 )
2626 from pyNastran .bdf .cards .aero .static_loads import AESTAT , AEROS , TRIM # CSSCHD, TRIM2, DIVERG
2727 from pyNastran .bdf .cards .aero .dynamic_loads import AERO , FLFACT , FLUTTER , GUST
3737 from pyNastran .bdf .cards .dynamic import (
3838 #DELAY, DPHASE,
3939 NLPARM )
40- from pyNastran .bdf .cards .elements .rigid import (
41- RBAR , RBAR1 , RBE1 , RBE2 , RBE3 , RROD , RSPLINE , RSSCON )
40+ # from pyNastran.bdf.cards.elements.rigid import (
41+ # RBAR, RBAR1, RBE1, RBE2, RBE3, RROD, RSPLINE, RSSCON)
4242 from pyNastran .bdf .cards .loads .loads import SLOAD , DAREA
4343 from pyNastran .bdf .cards .loads .dloads import DLOAD , TLOAD1 , TLOAD2 , RLOAD1 , RLOAD2
4444 from pyNastran .bdf .cards .loads .static_loads import (LOAD , GRAV , ACCEL , ACCEL1 , FORCE ,
6565 DVPREL1 , DVPREL2 )
6666 from pyNastran .bdf .cards .bdf_sets import SET1 , SET3
6767 from pyNastran .bdf .cards .thermal .thermal import PHBDY
68- #from pyNastran.bdf.cards.thermal.loads import (QBDY1, QBDY2, QBDY3, QHBDY, TEMP, TEMPD, TEMPB3,
69- # TEMPRB, QVOL, QVECT)
68+ # from pyNastran.bdf.cards.thermal.loads import (QBDY1, QBDY2, QBDY3, QHBDY, TEMP, TEMPD, TEMPB3,
69+ # TEMPRB, QVOL, QVECT)
7070 from pyNastran .bdf .cards .bdf_tables import (TABLED1 , TABLED2 , TABLED3 , TABLED4 ,
7171 TABLEM1 , TABLEM2 , TABLEM3 , TABLEM4 ,
7272 TABLES1 , TABLEST , TABLEHT , TABLEH1 ,
@@ -173,13 +173,32 @@ def Nodes(self, nids: list[int], msg: str='') -> list[GRID | SPOINT | EPOINT]:
173173
174174 """
175175 nodes = []
176- try :
177- for nid in nids :
178- nodes .append (self .Node (nid , msg = msg ))
179- except AssertionError :
180- print (msg )
181- print (nids )
182- raise
176+ nids_failed = []
177+ for nid in nids :
178+ assert isinstance (nid , integer_types ), 'nid should be an integer; not %s' % type (nid )
179+
180+ for nid in nids :
181+ if nid in self .nodes :
182+ node = self .nodes [nid ]
183+ elif nid in self .spoints :
184+ node = self .spoints [nid ]
185+ elif nid in self .epoints :
186+ node = self .epoints [nid ]
187+ else :
188+ nids_failed .append (nid )
189+ continue
190+ nodes .append (node )
191+
192+ if len (nids_failed ):
193+ nid_list = _unique_keys (self .nodes )
194+ msg = f'nids={ nids_failed } are not a GRID, SPOINT, or EPOINT{ msg } \n '
195+ msg += 'nids=%s\n ' % nid_list
196+ if self .spoints :
197+ msg += 'spoints=%s\n ' % _unique_keys (self .spoints )
198+ if self .epoints :
199+ msg += 'epoints=%s\n ' % _unique_keys (self .epoints )
200+ raise KeyError (msg )
201+
183202 return nodes
184203
185204 def Point (self , nid : int , msg : str = '' ) -> POINT :
@@ -222,15 +241,15 @@ def Elements(self, eids: list[int], msg: str='') -> list[Any]:
222241
223242 """
224243 elements = []
225- bad_eids = []
244+ failed_eids = []
226245 for eid in eids :
227246 try :
228247 elements .append (self .Element (eid , msg ))
229248 except KeyError :
230- bad_eids .append (eid )
231- if bad_eids :
249+ failed_eids .append (eid )
250+ if failed_eids :
232251 msg = 'eids=%s not found%s. Allowed elements=%s' % (
233- bad_eids , msg , _unique_keys (self .elements ))
252+ failed_eids , msg , _unique_keys (self .elements ))
234253 raise KeyError (msg )
235254 return elements
236255
@@ -271,8 +290,17 @@ def Properties(self, pids: list[int], msg: str='') -> list[Any]:
271290
272291 """
273292 properties = []
293+ failed_pids = []
274294 for pid in pids :
275- properties .append (self .Property (pid , msg ))
295+ try :
296+ properties .append (self .Property (pid ))
297+ except KeyError :
298+ failed_pids .append (pid )
299+ continue
300+ if failed_pids :
301+ msg = 'pids=%s not found%s. Allowed properties=%s' % (
302+ failed_pids , msg , _unique_keys (self .properties ))
303+ raise KeyError (msg )
276304 return properties
277305
278306 def PropertyMass (self , pid : int , msg : str = '' ) -> PMASS :
@@ -402,7 +430,9 @@ def Load(self, sid: int, consider_load_combinations: bool=True,
402430 sid , msg , np .unique (loads_ids ), np .unique (load_combination_ids )))
403431 return load
404432
405- def DLoad (self , sid : int , consider_dload_combinations : bool = True , msg : str = '' ) -> DLOAD :
433+ def DLoad (self , sid : int ,
434+ consider_dload_combinations : bool = True ,
435+ msg : str = '' ) -> DLOAD :
406436 """
407437 Gets a DLOAD, TLOAD1, TLOAD2, etc. associated with the
408438 Case Control DLOAD entry
@@ -459,7 +489,9 @@ def DPHASE(self, dphase_id: int, msg: str='') -> DPHASE:
459489 % (dphase_id , msg , list (self .dphases .keys ())))
460490
461491 #--------------------
462- def MPC (self , mpc_id : int , consider_mpcadd : bool = True , msg : str = '' ) -> MPC | MPCADD :
492+ def MPC (self , mpc_id : int ,
493+ consider_mpcadd : bool = True ,
494+ msg : str = '' ) -> MPC | MPCADD :
463495 """
464496 Gets an MPCADD or MPC
465497
@@ -486,7 +518,9 @@ def MPC(self, mpc_id: int, consider_mpcadd: bool=True, msg: str='') -> MPC | MPC
486518 mpc_id , msg , np .unique (mpc_ids ), np .unique (mpcadd_ids )))
487519 return constraint
488520
489- def SPC (self , spc_id : int , consider_spcadd : bool = True , msg : str = '' ) -> SPC | SPC1 | SPCADD :
521+ def SPC (self , spc_id : int ,
522+ consider_spcadd : bool = True ,
523+ msg : str = '' ) -> SPC | SPC1 | SPCADD :
490524 """
491525 Gets an SPCADD or SPC
492526
@@ -607,14 +641,14 @@ def safe_aesurf(self, aesurf_name: str, msg: str='') -> Optional[AESURF]:
607641
608642 def AESurf (self , aesurf_name : str , msg : str = '' ) -> AESURF :
609643 """gets an AESURF"""
610- #if isinstance(aesurf_name, integer_types):
611- # aesurf_id = aesurf_name
612- # try:
613- # return self.aesurf[aesurf_id]
614- # except KeyError:
615- # raise KeyError('aesurf=%s not found%s. Allowed AESURF=%s'
616- # % (aesurf_id, msg, _unique_keys(self.aesurf)))
617- #else:
644+ # if isinstance(aesurf_name, integer_types):
645+ # aesurf_id = aesurf_name
646+ # try:
647+ # return self.aesurf[aesurf_id]
648+ # except KeyError:
649+ # raise KeyError('aesurf=%s not found%s. Allowed AESURF=%s'
650+ # % (aesurf_id, msg, _unique_keys(self.aesurf)))
651+ # else:
618652 assert isinstance (aesurf_name , str ), f'aesurf_name={ aesurf_name !r} '
619653
620654 for aesurf_int , aesurf in self .aesurf .items ():
@@ -636,6 +670,8 @@ def AESurf_int(self, aesurf_id: int, msg: str='') -> AESURF:
636670
637671 def Acsid (self , msg : str = '' ) -> Coord :
638672 """gets the aerodynamic coordinate system"""
673+ acsid_aero = - 1
674+ acsid_aeros = - 1
639675 if self .aero is not None :
640676 acsid_aero = self .aero .Acsid ()
641677 if self .aeros is not None :
@@ -666,7 +702,7 @@ def safe_acsid(self, msg: str='') -> Optional[Coord]:
666702 elif self .aeros is not None :
667703 coord = self .Coord (acsid_aeros , msg = msg )
668704 else :
669- ## TODO: consider changing this...
705+ # TODO: consider changing this...
670706 self .log .error (f'neither AERO nor AEROS cards exist; assuming global (cid=0){ msg } .' )
671707 return self .Coord (0 , msg = msg )
672708 return coord
@@ -719,14 +755,14 @@ def Gust(self, sid: int, msg: str='') -> GUST:
719755 # AERO CONTROL SURFACE CARDS
720756 def AEStat (self , aestat_name : str , msg : str = '' ) -> AESTAT :
721757 """gets an AESTAT"""
722- #if isinstance(aesurf_name, integer_types):
723- # aesurf_id = aesurf_name
724- # try:
725- # return self.aesurf[aesurf_id]
726- # except KeyError:
727- # raise KeyError('aesurf=%s not found%s. Allowed AESURF=%s'
728- # % (aesurf_id, msg, _unique_keys(self.aesurf)))
729- #else:
758+ # if isinstance(aesurf_name, integer_types):
759+ # aesurf_id = aesurf_name
760+ # try:
761+ # return self.aesurf[aesurf_id]
762+ # except KeyError:
763+ # raise KeyError('aesurf=%s not found%s. Allowed AESURF=%s'
764+ # % (aesurf_id, msg, _unique_keys(self.aesurf)))
765+ # else:
730766 assert isinstance (aestat_name , str ), f'aestat_name={ aestat_name !r} '
731767
732768 for aestat_int , aestat in self .aestats .items ():
@@ -755,24 +791,24 @@ def AELIST(self, aid: int, msg: str='') -> AELIST:
755791 raise KeyError ('id=%s not found%s. Allowed AELISTs=%s'
756792 % (aid , msg , _unique_keys (self .aelists )))
757793
758- def AELink (self , link_id : int , msg : str = '' ) -> AELINK :
794+ def AELink (self , aelink_id : int , msg : str = '' ) -> AELINK :
759795 """gets an AELINK"""
760796 try :
761- return self .aelinks [link_id ]
797+ return self .aelinks [aelink_id ]
762798 except KeyError :
763- raise KeyError ('link_id =%s not found%s. Allowed AELINKs=%s'
764- % (link_id , msg , _unique_keys (self .aelinks )))
799+ raise KeyError ('aelink_id =%s not found%s. Allowed AELINKs=%s'
800+ % (aelink_id , msg , _unique_keys (self .aelinks )))
765801
766802 def AEParam (self , aeparm_name : str , msg : str = '' ) -> AEPARM :
767803 """gets an AEPARM"""
768- #if isinstance(aeparam_name, integer_types):
769- # aeparam_id = aeparam_name
770- # try:
771- # return self.aeparams[aesurf_id]
772- # except KeyError:
773- # raise KeyError('aesurf=%s not found%s. Allowed AEPARM=%s'
774- # % (aesurf_id, msg, _unique_keys(self.aesurf)))
775- #else:
804+ # if isinstance(aeparam_name, integer_types):
805+ # aeparam_id = aeparam_name
806+ # try:
807+ # return self.aeparams[aesurf_id]
808+ # except KeyError:
809+ # raise KeyError('aesurf=%s not found%s. Allowed AEPARM=%s'
810+ # % (aesurf_id, msg, _unique_keys(self.aesurf)))
811+ # else:
776812 assert isinstance (aeparm_name , str ), f'aeparm_name={ aeparm_name !r} '
777813
778814 for aeparam_int , aeparam in self .aeparams .items ():
@@ -969,13 +1005,15 @@ def DEQATN(self, equation_id: int, msg: str='') -> DEQATN:
9691005 raise KeyError ('equation_id=%s not found%s. Allowed DEQATNs=%s'
9701006 % (equation_id , msg , _unique_keys (self .dequations )))
9711007
1008+
9721009def get_pid_to_eid_map (model : BDF ) -> dict [int , list [int ]]:
9731010 pid_to_eid_map = defaultdict (set )
9741011 for eid , elem in model .elements .items ():
9751012 pid = elem .pid
9761013 pid_to_eid_map [pid ].add (eid )
9771014 return pid_to_eid_map
9781015
1016+
9791017def get_pid_to_nid_map (model : BDF ) -> dict [int , list [int ]]:
9801018 """TODO: doesn't support CONROD"""
9811019 from collections import defaultdict
@@ -992,6 +1030,7 @@ def get_pid_to_nid_map(model: BDF) -> dict[int, list[int]]:
9921030 property_to_nodes_map2 [pid ] = nodes_list
9931031 return property_to_nodes_map2
9941032
1033+
9951034def _unique_keys (mydict : dict [int , Any ]) -> str :
9961035 """helper method"""
9971036 return np .unique (list (mydict .keys ()))
0 commit comments