﻿ 基于CUDA的散货船稳性并行计算
 舰船科学技术  2017, Vol. 39 Issue (10): 40-44 PDF

CUDA based bulk carrier stability parallel calculation
WANG Zhi-zhou, SUN Xiao-feng, YIN Yong, LIU Chun-lei, LI Jun-yi
Key Laboratory of Marine Simulation and Control, Dalian Maritime University, Dalian 116026, China
Abstract: This paper designs a method to accelerate calculation progress using the NVIDIA CUDA (Compute Unified Device Architecture). By using the slicing module in CGAL(Computational Geometry Algorithms Library), the offset table was obtained through longitudinally slicing 3D design surface; The shell data were gained by simplification and equidistant offsetting and sent to GPU; Jacobi matrix coefficients were gained parallelly by intersecting water plane and shell data; The Jacobi matrix coefficients were sent to CPU to solve equations. Our results show speed up of 6 to 10 times and the real time performance of the program is improved effectively.
0 引 言

1 基于CGAL的船舶数据库建立

CGAL（Computational Geometry Algorithms Library，计算几何算法库）[11]以C++库的形式提供高效、可靠的几何算法。CGAL提供计算几何相关的数据结构和算法，如三角剖分、Voronoi图、多边形、几何处理和凸包算法等。

 图 1 散货船SHANDONG REN HE型表面横剖面示意图 Fig. 1 Molded surface transverse sections of bulk carrier SHANDONG REN HE
2 稳性计算 2.1 船舶稳性方程组求解

 $\left\{ \begin{array}{l}Mxz = VYB - \frac{P}{\rho }YG\text{，}\\Myz = VXB - \frac{P}{\rho }XG\text{，}\\Mxy = VZB - \frac{P}{\rho }ZG\text{，}\end{array} \right.$ (1)

 $\cos \alpha = 1/\sqrt {1 + {{\tan }^2}\theta + {{\tan }^2}\varphi }{\text{。}}$ (2)

 $\left\{ \begin{array}{l}f_1 = V - V0 = 0\text{，}\\[4pt]f_2 = (1 \!+\! \tan \theta \tan \theta_0 \!+\! \tan \varphi \tan \varphi_0)\cos \alpha \cos \alpha_0 \\ \,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,-\! \cos \alpha_1 \!=\! 0\text{，}\\[4pt]f_3 = Mxz(tan\varphi - tan\varphi_0) - Myz(\tan \theta - \tan \theta_0)\text{，}\\[4pt] - Mxy(\tan \theta tan\varphi_0 - tan\varphi \tan \theta_0) = 0\text{。}\end{array}\!\!\! \right.$ (3)

 ${{F(x)}} = \left( \begin{array}{l}f_1(x)\\f_2(x)\\f_3(x)\end{array} \right),{{x}} = \left( \begin{array}{l}T_m\\\tan \theta \\\tan \varphi \end{array} \right),{{0}} = \left( \begin{array}{l}0\\0\\0\end{array} \right)\text{。}$ (4)

 $F'({x_k})\Delta {x_k} + F({x_k}) = 0\ (k = 0,1,2,...){\text{。}}$ (5)

 $\begin{split} & \left( {\begin{array}{*{20}{c}}{\displaystyle\frac{{\partial f_1}}{{\partial T_m}}}&{\displaystyle\frac{{\partial f_1}}{{\partial \tan_\theta }}}&{\displaystyle\frac{{\partial f_1}}{{\partial \tan_\varphi }}}\\{\displaystyle\frac{{\partial f_2}}{{\partial T_m}}}&{\displaystyle\frac{{\partial f_2}}{{\partial \tan_\theta }}}&{\displaystyle\frac{{\partial f_2}}{{\partial \tan_\varphi }}}\\{\displaystyle\frac{{\partial f_3}}{{\partial T_m}}}&{\displaystyle\frac{{\partial f_3}}{{\partial \tan_\theta }}}&{\displaystyle\frac{{\partial f_3}}{{\partial \tan_\varphi }}}\end{array}} \right) \cdot \left( \begin{array}{l}\delta {T_{mk}}\\\delta \tan {\theta _k}\\\delta \tan {\varphi _k}\end{array} \right) +\\ &\left( \begin{array}{l}f_1({T_{mk}},\tan {\theta _k},\tan {\varphi _k})\\f_2({T_{mk}},\tan {\theta _k},\tan {\varphi _k})\\f_3({T_{mk}},\tan {\theta _k},\tan {\varphi _k})\end{array} \right) = {{0}}{\text{。}}\end{split}$ (6)

 $\left(\! {\begin{array}{*{20}{c}}\!\!\!\!\!\! S&{SY_F}&{SX_F}\\\!\!\!\!\!\! 0&\begin{array}{l}\cos \alpha_0\cos \alpha \left[ {} \right. \tan\theta_0 - \tan\theta {\cos ^2}\alpha \\ \cdot (1 + \tan\theta \tan\theta_0 + \tan \varphi \tan \varphi_0)\left. {} \right]\end{array}&\begin{array}{l}\cos \alpha_0\cos \alpha \left[ {} \right.\tan \varphi_0 - \tan\varphi {\cos ^2}\alpha \\ \cdot (1 + \tan\theta \tan\theta_0 + \tan \varphi \tan \varphi_0)\left. {} \right]\end{array}\\\begin{array}{l}\!\!\!\!\!\! SY_F(\tan\varphi -\\ \!\!\!\!\!\! \tan\varphi_0) - SX_F(\tan\theta - \tan\theta_0)\\ \!\!\!\!\!\! - SZ_F(\tan\theta \tan\varphi_0 - \tan\varphi \tan\theta_0)\end{array}&\begin{array}{l}I_x(\tan\varphi - \tan\varphi_0) - I_{xy}(\tan\theta - \tan\theta_0)\\ - (I_x \tan\theta + I_{xy} \tan\varphi + SY_FT_m)(\tan\theta \tan\varphi_0\\ - \tan\varphi \tan\theta_0) - (M_{yz} + M_{xy} \tan\varphi_0)\end{array}&\begin{array}{l}I_{xy}(\tan\varphi - \tan\varphi_0) - I_y(\tan\theta - \tan\theta_0)\\ \!\!\!\!\!\!\!\! - (I_y \tan\varphi + I_{xy} \tan\theta + SX_FT_m)\\ \!\!\!\!\!\! (\tan\theta \tan\varphi_0 - \tan\varphi \tan\theta_0) -\\ (M_{xz} + M_{xy} \tan\varphi_0)\!\!\!\!\!\end{array}\end{array}} \!\!\!\!\!\right){\text{。}}$ (7)

 $\begin{split}L = & \cos \alpha \left\{ {{{\left[ {\left( {X_B - X_G} \right)\tan \theta - (Y_B - Y_G)\tan \varphi } \right]}^2}} \right.+ \\ & {\left[ {(Y_B - Y_G) + (Z_B - Z_G)\tan \theta } \right]^2} +\\ &\left[ {(X_B - X_G)} \right. + (Z_B - Z_G)\tan \varphi {\left. {} \right]^2}{\left. {} \right\}^{1/2}}{\text{。}}\end{split}$ (8)
2.2 雅克比矩阵系数计算 2.2.1 水线面系数计算

 $x\tan \varphi + y\tan \theta - z + T_m = 0{\text{。}}$ (9)

 $S = \int_{x_0}^{x_n} {{\rm{d}}x\int_{s(x)}^{p(x)} {{\rm{d}}y} } = \int_{x_0}^{x_n} {\left( {p(x) - s(x)} \right){\rm{d}}x}\text{。}$ (10)

 $X_F = \frac{{\int_{x_0}^{x_n} {\left( {p(x) - s(x)} \right) \cdot x{\rm{d}}x} }}{S},$ (11)
 $Y_F = \frac{{\int_{x_0}^{x_n} {{{\left( {p(x) - s(x)} \right)}^2}{\rm{d}}x} }}{{2S}},$ (12)
 $\begin{split}{l}&Z_F = \displaystyle\frac{1}{S}\int_{x_0}^{x_n} {\left( {(x \cdot \tan \varphi + T_m) \cdot } \right.} \left[ {p(x) - s(x)} \right]{\rm{ + }}\\&\;\;\;\;\;\;\;\;{\displaystyle\frac{1}{2} \cdot {\rm{tan}}\theta \cdot {{\left[ {p(x) - s(x)} \right]}^2}}{\rm{d}}x{\text{。}}\end{split}$ (13)

 $I_x = \frac{1}{3}\left( {\int_{x_0}^{x_n} {p{{(x)}^3}{\rm{d}}x} - \int_{x_0}^{x_n} {s{{(x)}^3}{\rm{d}}x} } \right),$ (14)
 $I_y = \int_{x_0}^{x_n} {{x^2}p(x){\rm{d}}x} - \int_{x_0}^{x_n} {{x^2} \cdot s(x){\rm{d}}x}{\text{。}}$ (15)
 $I_{LF} = I_y - S \cdot {X^2}_F,$ (16)
 $I_{xy} = \frac{1}{2}\left( {\int_{x_0}^{x_n} {x \cdot p{{(x)}^2}{\rm{d}}x} + \int_{x_0}^{x_n} {x \cdot s{{(x)}^2}{\rm{d}}x} } \right){\text{。}}$ (17)

2.2.2 排水体积和浮心的计算

 $V = \int_{x_0}^{x_n} {As{\rm{d}}x},$ (18)

 $X_B = \frac{{M_yO_z}}{V} = \frac{{\int_{x_0}^{x_n} {x_aA_s{\rm{d}}x} }}{V},$ (19)
 $Y_B = \frac{{M_xO_z}}{V} = \frac{{\int_{x_0}^{x_n} {y_aA_s{\rm{d}}x} }}{V},$ (20)
 $Z_B = \frac{{M_xO_y}}{V} = \frac{{\int_{x_0}^{x_n} {z_aA_s{\rm{d}}x} }}{V}{\text{。}}$ (21)

2.3 基于CUDA的程序设计

NVIDIA公司为了推动GPU在大规模高性能计算领域里的发展，在2006年11月推出为通用并行计算开发的CUDA通用并行计算架构，由于它的编程方便与并行性能高的特点，充分利用了CPU和GPU各自的优点，实现CPU/GPU联合执行，使得并行计算得到更快的发展[10]

 图 2 CUDA并行结构示意图[14] Fig. 2 CUDA structure diagram

CUDA在编译时，会将CPU代码和GPU代码分开编译。程序从主机端的CPU代码开始执行，当执行到GPU代码时，调用内核函数，并将代码切换到GPU。当内核函数执行完后，设备代码被切换到CPU端，继续执行代码。

 图 3 稳性计算流程图 Fig. 3 Stability calculation flowchart

3 算　例

 图 4 压载出港稳性力臂对比图 Fig. 4 Comparison of GZ during ballast condition at DEP

 图 5 压载途中稳性力臂对比图 Fig. 5 Comparison of GZ during ballast condition in MID

 图 6 压载到港稳性力臂对比图 Fig. 6 Comparison of GZ during ballast condition at ARR
4 结 语

 [1] 盛振邦, 刘应中. 船舶原理[M]. 上海交通大学出版社, 2003. [2] 赵晓非, 蔡伟科. 船舶稳性计算优化方法研究[J]. 中国造船, 1987 (02): 88–94. ZHAO Xiao-fei, CAI Wei-ke. An Optimization Methodforthe Calculation of Ships Stability Curves[J]. Shipbuilding of China, 1987 (02): 88–94. [3] 桑松, 徐学军. 浮式结构物完整稳性优化计算原理[J]. 上海交通大学学报, 2009 (10): 1568–1572. SANG Song, XU Xue-jun. Optimization Calculational Principle on Intact Stability of Floating Structures[J]. Journal of Shanghai Jiaotong University, 2009 (10): 1568–1572. DOI: 10.3321/j.issn:1006-2467.2009.10.011 [4] 孙承猛, 刘寅东. 一种船舶最小稳性和自由浮态计算的改进算法[J]. 中国造船, 2007 (03): 1–4. SUN Cheng-meng, LIU Yin-dong. An Improved Algorithm for Calculating Ship’s Minimum Stability and Free Floatation[J]. Shipbuilding of China, 2007 (03): 1–4. DOI: 10.3969/j.issn.1000-4882.2007.03.001 [5] 马坤, 张明霞, 纪卓尚, 等. 非线性规划法计算船舶稳性[J]. 中国造船, 2003 (02): 83–86. MA Kun, ZHANG Ming-xia, JI Zhou-shang, et al. Application of Nonlinear Programming to Calculation of Ship Stability Curve[J]. Shipbuilding of China, 2003 (02): 83–86. [6] 令波. 浮性与完整稳性的直接计算法[D]. 武汉: 华中科技大学, 2013. [7] 程智斌, 魏建志, 曾宏军. 计算破损船舶稳性的表面元法[J]. 海军工程大学学报, 2002 (4): 41–44. [8] RADWAN A M. A different method to evaluate the intact stability of floating structures[J]. Marine Technology and Sname News, 1983, 20 (1): 21–25. [9] COOK S. CUDA programming: a developer’s guide to parallel computing with GPUs[M]. Newnes, 2012. [10] KIRK D B, Wen-mei W H. Programming massively parallel processors: a hands-on approach[M]. Newnes, 2012. [11] The Computational Geometry Algorithms Library[EB/OL]. [2016-8-19]. http://www.cgal.org. [12] 王智洲, 孙霄峰, 尹勇, 等. 基于三维设计数据的船舶湿面积计算[J]. 船舶工程, 2016, 38 (05): 5–8. WANG Zhi-zhou, SUN Xiao-feng, YIN Yong, et al. Ship’s Wetted Surface Calculation Based on 3D Design Data[J]. Ship Engineering, 2016, 38 (05): 5–8. [13] 张明霞. 基于NURBS曲面的船舶破舱稳性计算方法研究[D]. 大连理工大学, 2002. [14] NVIDIA. CUDA programming guide V 7.5[Z]. 2015.