@@ -194,8 +194,14 @@ def __init__(
194194
195195 coefficients_dict = {}
196196 if kwargs .get ("kxx" ) is None :
197- pool = multiprocessing .Pool ()
198- coefficients_dict_list = pool .map (self .run , frequency )
197+ # Use multiprocessing only when beneficial (>4 frequencies)
198+ # For small workloads, sequential execution avoids process spawn overhead
199+ if len (frequency ) > 4 :
200+ with multiprocessing .Pool () as pool :
201+ coefficients_dict_list = pool .map (self .run , frequency )
202+ else :
203+ coefficients_dict_list = [self .run (freq ) for freq in frequency ]
204+
199205 coefficients_dict = {k : [] for k in coefficients_dict_list [0 ].keys ()}
200206 for d in coefficients_dict_list :
201207 for k in coefficients_dict :
@@ -256,13 +262,8 @@ def setup(self):
256262 self .nc = self .n_teeth - 1
257263 self .np = self .n_teeth + 1
258264
259- for i in range (1 , self .n_teeth ):
260- self .radial_clearance [i ] = self .radial_clearance [0 ]
261- self .tooth_height [i ] = self .tooth_height [0 ]
262- self .tooth_width [i ] = self .tooth_width [0 ]
263-
264- for i in range (1 , self .nc ):
265- self .pitch [i ] = self .pitch [0 ]
265+ # Arrays already initialized with np.full() in __init__
266+ # No need to re-assign values that are already set
266267
267268 self .ndof = 8 * self .nc
268269 self .nbw = 33
@@ -1088,11 +1089,7 @@ def pert(self):
10881089 cont = 1
10891090 else :
10901091 gmfull [i ][i + j - 16 ] = self .gm [i ][j ]
1091- maux = [[0 for j in range (8 * self .nc )] for i in range (8 * self .nc )]
1092- for i in range (0 , self .nc * 8 ):
1093- for j in range (0 , self .nc * 8 ):
1094- maux [i ][j ] = gmfull [i ][j ]
1095- A = np .array (maux )
1092+ A = gmfull [: 8 * self .nc , : 8 * self .nc ].copy ()
10961093 lu , piv = lu_factor (A )
10971094 for i in range (0 , 8 * self .nc ):
10981095 rhs1 [i ] = self .rhs [i ][0 ]
0 commit comments