defCalcPerturbation(self): """ Calculate the ambient water pressure perturbation. Parameters: x (float): Coordinate of the model nose related to the model length. SwPert (int): Type of perturbation (1: Impulse, 2: Periodic, 3: User, 4: No perturbation). Lm (float): Length of the model. Timp (float): Time constant for impulse perturbation. V0 (float): Initial velocity. PmaxImp (float): Maximum pressure for impulse perturbation. Head0 (float): Initial water head. XpImp (float): Position of the impulse perturbation. AmPer (float): Amplitude of the periodic perturbation. ShPer (float): Spatial frequency of the periodic perturbation. Xuser (list of float): User-defined positions for user perturbation. Pw_User (list of float): User-defined pressures for user perturbation. Np (int): Number of user-defined points for user perturbation. Returns: P1n (float): Calculated pressure perturbation. """ # 计算环境水压扰动 # def calc_perturbation(x, SwPert, Lm, Timp, V0, PmaxImp, Head0, XpImp, AmPer, ShPer, Xuser, Pw_User, Np): # 扰动标识,默认为4没有压强扰动 SwPert = self.SwPert # 脉冲扰动的时间常数,单位为ms Timp = self.Timp # 模型长度 Lm = self.Lm # 模型初速度 V0 = self.V0 # 脉冲扰动的最大压力。 PmaxImp = self.PmaxImp # 初始水头 Head0 = self.Head0 # 冲击扰动的中心位置? XpImp = self.XpImp # 当前无量纲位置 x = self.x # 周期性扰动的振幅 AmPer = self.AmPer # 周期性扰动的波数 ShPer = self.ShPer # 用户定义的扰动 Xuser = self.Xuser # 用户定义的扰动的点数 Np = self.Np # 用户定义扰动的压力分布(数组,单位:MPa) Pw_User = self.Pw_User
# Initialize pressure perturbation to zero P1n = 0.0 # 强迫 # Impulse if SwPert == 1: St = 2.0 * np.pi * Lm * 1e3 / (Timp * V0) Aka = PmaxImp * 1e6 / Head0 Xmp = XpImp / Lm if x <= Xmp - np.pi / St or x >= Xmp + np.pi / St: P1n = 0.0 else: P1n = Aka * (1.0 + np.cos(St * (x - Xmp))) / 2.0 # Periodic # 周期性 elif SwPert == 2: P1n = AmPer * np.sin(ShPer * x) # 用户定义,摒弃? elif SwPert == 3: # User if x < Xuser[0] / Lm or x > Xuser[Np - 1] / Lm: P1n = 0.0 else: # Interpolate user-defined pressure values Xuser_norm = np.array(Xuser) / Lm Pw_User_norm = np.array(Pw_User) * 1e6 / Head0 P1n = np.interp(x, Xuser_norm, Pw_User_norm)