def LWTDWS(alpha, c, cg, c0, H): alpha0 = None H0 = None errorMsg = None deg2rad = math.pi / 180.0 arg = (c0 / c) * cmath.sin(alpha * deg2rad) if ComplexUtil.greaterThanEqual(arg, 1): errorMsg = "Error: Violation of assumptions for Snells Law" return alpha0, H0, errorMsg alpha0 = (cmath.asin(arg)) / deg2rad ksf = cmath.sqrt(c0 / (2 * cg)) # shoaling coefficient alphaCos = cmath.cos(alpha0 * deg2rad) / cmath.cos(alpha * deg2rad) if ComplexUtil.lessThan(alphaCos, 0): errorMsg = "Error: Alpha1 data out of range" return alpha0, H0, errorMsg krf = cmath.sqrt(alphaCos) # refraction coefficient H0 = H / (ksf * krf) return alpha0, H0, errorMsg
def performCalculations(self, caseInputList, caseIndex = 0): Hmo, Tp, d = self.getCalcValues(caseInputList) dataDict = {"Hmo": Hmo, "Tp": Tp, "d": d} Htype = [] Htype.append(0.50) #Hmed; Htype.append(0.66) #H1/3 (1-1/3); Htype.append(0.90) #H1/10 (1-1/10); Htype.append(0.99) #H1/100 (1-1/100); Hb = ERRWAVBRK1(d, 0.9) if Hmo >= Hb: self.errorMsg =\ "Error: Input wave broken (Hb = %6.2f %s)" % (Hb, self.labelUnitDist) print(self.errorMsg) self.fileOutputWriteMain(dataDict, caseIndex) return L, k = WAVELEN(d, Tp, 50, self.g) steep, maxstp = ERRSTP(Hmo, d, L) if ComplexUtil.greaterThanEqual(steep, maxstp): self.errorMsg =\ "Error: Input wave unstable (Max: %0.4f, [H/L] = %0.4f)" %\ (maxstp.real, steep.real) print(self.errorMsg) self.fileOutputWriteMain(dataDict, caseIndex) return dterm = d/(self.g*Tp**2) k = 0 sum1 = 0 if dterm > 0.01: print("Input conditions indicate Rayleigh distribution") Hb = math.sqrt(5)*Hmo Hinc = Hb/10000 sigma = Hmo/4 Hrms = 2*math.sqrt(2)*sigma H = [0] p = [0] index = [0, 0, 0, 0] for i in range(2, 10002): # Rayleigh distribution H.append(Hinc * (i - 1)) term1 = math.exp(-(H[i - 1]/Hrms)**2) term2 = (2 * H[i - 1])/Hrms**2 p.append(term1 * term2) sum1 = sum1 + (p[i - 1]*Hinc) if k < 4 and sum1 > Htype[k]: index[k] = i k = k + 1 Hout = [] for k in range(1, 4): sum2 = 0 Hstart = H[index[k]] Hinc = (Hb - Hstart)/10000 pprv = p[index[k]] Hprv = Hstart for i in range(2, 10001): Hnxt = Hstart + Hinc*(i - 1) term1 = math.exp(-(Hnxt/Hrms)**2) term2 = (2 * Hnxt)/Hrms**2 pnxt = term1 * term2 darea = 0.5*(pprv + pnxt)*Hinc # area of a trapezoid sum2 = sum2 + (Hinc/2.0 + Hprv)*darea pprv = pnxt Hprv = Hnxt Hout.append(sum2 / (1 - Htype[k])) # computing centroid (areasum = 1-Htype) else: Hb = d Hinc = Hb / 100.0 print("Input conditions indicate Beta-Rayleigh distribution") a1 = 0.00089 b1 = 0.834 a2 = 0.000098 b2 = 1.208 d1 = a1*dterm**(-b1) if d1 > 35.0: self.errorMsg = "Error: d/gT^2 approaching infinity" print(self.errorMsg) self.fileOutputWriteMain(dataDict, caseIndex) return Hrms = (1/math.sqrt(2))*math.exp(d1)*Hmo # root-mean-square wave height d2 = a2 * dterm**(-b2) if d2 > 35.0: self.errorMsg = "Error: d/gT^2 approaching infinity" print(self.errorMsg) self.fileOutputWriteMain(dataDict, caseIndex) return Hrmsq = (1/math.sqrt(2))*math.exp(d2)*Hmo**2 # root-mean-quad wave height # Computing alpha and beta K1 = (Hrms / Hb)**2 K2 = (Hrmsq**2) / (Hb**4) alpha = (K1*(K2 - K1))/(K1**2 - K2) beta = ((1.0 - K1)*(K2 - K1))/(K1**2 - K2) term1 = (2*sp.gamma(alpha + beta))/(sp.gamma(alpha)*sp.gamma(beta)) H = [] p = [] index = [0, 0, 0, 0] for i in range(101): # Beta-Rayleigh distribution H.append(Hinc*i) # Avoid division by zero try: term2 = (H[i]**(2*alpha - 1))/(Hb**(2*alpha)) except: term2 = float('inf') # Avoid division by zero try: term3 = (1.0 - (H[i]/Hb)**2)**(beta - 1.0) except: term3 = float('inf') p.append(term1 * term2 * term3) sum1 = sum1 + (p[i]*Hinc) if k < 4 and sum1 > Htype[k]: index[k] = i k = k + 1 Hout = [] for k in range(1, 4): sum2 = 0 Hstart = H[index[k]] Hinc = (Hb - Hstart)/20 pprv = p[index[k]] Hprv = Hstart for i in range(1, 20): Hnxt = Hstart + Hinc*i term2 = (Hnxt**(2*alpha - 1))/(Hb**(2*alpha)) # Avoid division by zero try: term3 = (1 - (Hnxt/Hb)**2)**(beta - 1) except: term3 = float('inf') pnxt = term1*term2*term3 darea = 0.5*(pprv + pnxt)*Hinc # area of a trapezoid sum2 = sum2 + (Hinc/2.0 + Hprv)*darea pprv = pnxt Hprv = Hnxt Hout.append(sum2 / (1 - Htype[k])) # computing centroid (areasum = 1-Htype) Hmed = H[index[0]] print("Wave heights") print("Hrms\t\t%6.2f %s" % (Hrms, self.labelUnitDist)) print("Hmed\t\t%6.2f %s" % (Hmed, self.labelUnitDist)) print("H(1/3)\t\t%6.2f %s" % (Hout[0], self.labelUnitDist)) print("H(1/10)\t\t%6.2f %s" % (Hout[1], self.labelUnitDist)) print("H(1/100)\t%6.2f %s" % (Hout[2], self.labelUnitDist)) dataDict["Hrms"] = Hrms dataDict["Hmed"] = Hmed dataDict["Hout"] = Hout self.fileOutputWriteMain(dataDict, caseIndex) if self.isSingleCase: self.plotDict = {"Hrms": Hrms, "Hmed": Hmed, "Hout": Hout,\ "H": H, "p": p}