Skip to content

Commit a3c3654

Browse files
authored
Merge pull request #62 from ShipMMG/dev
Considering wind force and moment in MMG 3DOF model
2 parents c2aeabe + c9d6089 commit a3c3654

File tree

13 files changed

+1629
-132
lines changed

13 files changed

+1629
-132
lines changed

.JuliaFormatter.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
remove_extra_newlines=true
2+
join_lines_based_on_source=true
3+
whitespace_in_kwargs=false
4+
short_to_long_function_def=true
5+
always_for_in=true
6+
verbose=true
7+
margin=88

.github/workflows/Test.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Run tests
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
- dev
11+
12+
jobs:
13+
test:
14+
runs-on: ${{ matrix.os }}
15+
strategy:
16+
matrix:
17+
julia-version: ['1']
18+
julia-arch: [x64]
19+
os: [ubuntu-latest]
20+
21+
steps:
22+
- uses: actions/checkout@v2
23+
- uses: julia-actions/[email protected]
24+
with:
25+
version: ${{ matrix.julia-version }}
26+
arch: ${{ matrix.julia-arch }}
27+
- uses: julia-actions/julia-buildpkg@v1
28+
- uses: julia-actions/julia-runtest@v1
29+
with:
30+
annotate: true

Project.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
name = "ShipMMG"
22
uuid = "37f2b0bf-0c13-4883-8808-e75eb56597e7"
33
authors = ["Taiga MITSUYUKI <[email protected]>"]
4-
version = "0.0.6"
4+
version = "0.0.7"
55

66
[deps]
77
AdvancedPS = "576499cb-2369-40b2-a588-c64705576edc"
88
Dierckx = "39dd38d3-220a-591b-8e3c-4c3a8c710a94"
99
DifferentialEquations = "0c46a032-eb83-5123-abaf-570d42b7fbaa"
1010
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
11+
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
12+
KernelDensity = "5ab0869b-81aa-558d-bb23-cbf5423bbe9b"
1113
Libtask = "6f1fad26-d15e-5dc8-ae53-837a1d7b8c9f"
1214
ParameterizedFunctions = "65888b18-ceab-5e60-b2b9-181511a3b968"
1315
Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a"
14-
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
1516
Turing = "fce5fe82-541a-59a6-adf8-730c64b5f9a0"
1617

1718
[compat]
@@ -22,7 +23,6 @@ Distributions = "^0.25"
2223
Libtask = "^0.8"
2324
ParameterizedFunctions = "^5.12"
2425
Parameters = "0.12"
25-
Plots = "^1"
2626
Turing = "^0.24"
2727
julia = "^1.6"
2828

src/ShipMMG.jl

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,19 @@ module ShipMMG
33
using DifferentialEquations
44
using ParameterizedFunctions
55
using Dierckx
6-
using Plots
76
using Parameters
87
using Distributions
98
using Turing
9+
using ForwardDiff
1010

1111
include("data.jl")
1212
export calc_position,
1313
ShipData,
14+
EnvironmentData,
1415
get_KVLCC2_L7_basic_params,
1516
get_KVLCC2_L7_maneuvering_params,
1617
get_KVLCC2_L7_params,
18+
get_example_ship_wind_force_moment_params,
1719
nuts_sampling_single_thread,
1820
nuts_sampling_multi_threads
1921

@@ -35,7 +37,17 @@ export Mmg3DofBasicParams,
3537
estimate_mmg_approx_lsm_time_window_sampling,
3638
create_model_for_mcmc_sample_mmg
3739

38-
include("draw.jl")
39-
export draw_gif_result, calc_position
40+
include("mmg_wind.jl")
41+
export Mmg3DofBasicParams,
42+
Mmg3DofManeuveringParams,
43+
Mmg3DofWindForceMomentParams,
44+
apparent_wind_speed_and_angle,
45+
mmg_3dof_simulate,
46+
mmg_3dof_wind_model!,
47+
mmg_3dof_zigzag_test,
48+
estimate_mmg_approx_lsm,
49+
estimate_mmg_approx_lsm_time_window_sampling,
50+
create_model_for_mcmc_sample_mmg,
51+
wind_force_and_moment_coefficients
4052

4153
end

src/data.jl

Lines changed: 138 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@
1010
n_p::Tn_p
1111
end
1212

13-
function get_KVLCC2_L7_basic_params= 1025.0)
13+
@with_kw struct EnvironmentData{Tt,TU_W,Tψ_W}
14+
time::Tt
15+
U_W::TU_W
16+
ψ_W::Tψ_W
17+
end
18+
19+
function get_KVLCC2_L7_basic_params=1025.0)
1420
L_pp = 7.00 # 船長Lpp[m]
1521
B = 1.27 # 船幅[m]
1622
d = 0.46 # 喫水[m]
@@ -144,19 +150,140 @@ function get_KVLCC2_L7_params()
144150
basic_params, maneuvering_params
145151
end
146152

147-
function calc_position(time_vec, u_vec, v_vec, r_vec; x0 = 0.0, y0 = 0.0, ψ0 = 0.0)
153+
"""
154+
wind_force_and_moment_coefficients(ψ_A,p)
155+
156+
compute the parameter C_X,C_Y,C_N from Fujiwara's estimation method (1994).
157+
158+
# Arguments
159+
-`ψ_A`: Wind attack of angle [rad]
160+
- L_pp
161+
- B
162+
- A_OD
163+
- A_F
164+
- A_L
165+
- H_BR
166+
- H_C
167+
- C
168+
"""
169+
function wind_force_and_moment_coefficients(
170+
ψ_A,
171+
L_pp,
172+
B,
173+
A_OD,
174+
A_F,
175+
A_L,
176+
H_BR,
177+
H_C,
178+
C,
179+
)
180+
#C_LF1の場合で調整
181+
C_CF = 0.404 + 0.368 * A_F / (B * H_BR) + 0.902 * H_BR / L_pp
182+
183+
if deg2rad(0) <= ψ_A <= deg2rad(90)
184+
C_LF = -0.992 + 0.507 * A_L / (L_pp * B) + 1.162 * C / L_pp
185+
C_XLI = 0.458 + 3.245 * A_L / (L_pp * H_BR) - 2.313 * A_F / (B * H_BR)
186+
C_ALF = -0.585 - 0.906 * A_OD / A_L + 3.239 * B / L_pp
187+
C_YLI = pi * A_L / L_pp^2 + 0.116 + 3.345 * A_F / (L_pp * B)
188+
189+
elseif deg2rad(90) < ψ_A <= deg2rad(180)
190+
C_LF =
191+
0.018 - 5.091 * B / L_pp + 10.367 * H_C / L_pp - 3.011 * A_OD / L_pp^2 -
192+
0.341 * A_F / B^2
193+
C_XLI =
194+
-1.901 + 12.727 * A_L / (L_pp * H_BR) + 24.407 * A_F / A_L -
195+
40.310 * B / L_pp - 0.341 * A_F / (B * H_BR)
196+
C_ALF = -0.314 - 1.117 * A_OD / A_L
197+
C_YLI = pi * A_L / L_pp^2 + 0.446 + 2.192 * A_F / L_pp^2
198+
199+
elseif deg2rad(180) < ψ_A <= deg2rad(270)
200+
C_LF =
201+
0.018 - 5.091 * B / L_pp + 10.367 * H_C / L_pp - 3.011 * A_OD / L_pp^2 -
202+
0.341 * A_F / B^2
203+
C_XLI =
204+
-1.901 + 12.727 * A_L / (L_pp * H_BR) + 24.407 * A_F / A_L -
205+
40.310 * B / L_pp - 0.341 * A_F / (B * H_BR)
206+
C_ALF = -(-0.314 - 1.117 * A_OD / A_L)
207+
C_YLI = -(pi * A_L / L_pp^2 + 0.446 + 2.192 * A_F / L_pp^2)
208+
209+
elseif deg2rad(270) < ψ_A <= deg2rad(360)
210+
C_LF = -0.992 + 0.507 * A_L / (L_pp * B) + 1.162 * C / L_pp
211+
C_XLI = 0.458 + 3.245 * A_L / (L_pp * H_BR) - 2.313 * A_F / (B * H_BR)
212+
C_ALF = -(-0.585 - 0.906 * A_OD / A_L + 3.239 * B / L_pp)
213+
C_YLI = -(pi * A_L / L_pp^2 + 0.116 + 3.345 * A_F / (L_pp * B))
214+
end
215+
216+
C_X =
217+
C_LF * cos(ψ_A) +
218+
C_XLI * (sin(ψ_A) - sin(ψ_A) * cos(ψ_A)^2 / 2) * sin(ψ_A) * cos(ψ_A) +
219+
C_ALF * sin(ψ_A) * cos(ψ_A)^3
220+
C_Y =
221+
C_CF * sin(ψ_A)^2 +
222+
C_YLI * (cos(ψ_A) + sin(ψ_A)^2 * cos(ψ_A) / 2) * sin(ψ_A) * cos(ψ_A)
223+
C_N = C_Y * (0.297 * C / L_pp - 0.149 * (ψ_A - deg2rad(90)))
224+
225+
C_X, C_Y, C_N
226+
end
227+
228+
function get_example_ship_wind_force_moment_params()
229+
L_pp = 7.00 # 船長Lpp[m]
230+
B = 1.27 # 船幅[m]
231+
d = 0.46 # 喫水[m]
232+
D = 0.6563 # 深さ[m]
233+
A_OD = 0.65 # デッキ上の構造物の側面投影面積[m^2]
234+
H_BR = 0.85 # 喫水からブリッジ主要構造物の最高位[m]
235+
H_C = 0.235 # 喫水から側面積中心までの高さ[m]
236+
C = 0.0 # 船体中心から側面積中心までの前後方向座標(船首方向を正)[m]
237+
238+
A_OD = A_OD # デッキ上の構造物の側面投影面積[m^2]
239+
A_F = (D - d) * B # 船体の正面投影面積[m^2]
240+
A_L = (D - d) * L_pp # 船体の側面投影面積[m^2]
241+
H_BR = H_BR # 喫水からブリッジ主要構造物の最高位[m]
242+
H_C = H_C # 喫水から側面積中心までの高さ[m]
243+
C = C # 船体中心から側面積中心までの前後方向座標[m]
244+
245+
ψ_A_vec = deg2rad.(collect(0:10:360))
246+
C_X_vec = Array{Float64}(undef, length(ψ_A_vec))
247+
C_Y_vec = Array{Float64}(undef, length(ψ_A_vec))
248+
C_N_vec = Array{Float64}(undef, length(ψ_A_vec))
249+
for (index, ψ_A) in enumerate(ψ_A_vec)
250+
C_X, C_Y, C_N = wind_force_and_moment_coefficients(
251+
ψ_A,
252+
L_pp,
253+
B,
254+
A_OD,
255+
A_F,
256+
A_L,
257+
H_BR,
258+
H_C,
259+
C,
260+
)
261+
C_X_vec[index] = C_X
262+
C_Y_vec[index] = C_Y
263+
C_N_vec[index] = C_N
264+
end
265+
spl_C_X = Spline1D(ψ_A_vec, C_X_vec)
266+
spl_C_Y = Spline1D(ψ_A_vec, C_Y_vec)
267+
spl_C_N = Spline1D(ψ_A_vec, C_N_vec)
268+
269+
Mmg3DofWindForceMomentParams(A_F, A_L, spl_C_X, spl_C_Y, spl_C_N)
270+
end
271+
272+
function calc_position(time_vec, u_vec, v_vec, r_vec; x0=0.0, y0=0.0, ψ0=0.0)
148273
dim = length(time_vec)
149274
x_vec = zeros(Float64, dim)
150275
y_vec = zeros(Float64, dim)
151276
ψ_vec = zeros(Float64, dim)
152277
x_vec[1] = x0
153278
y_vec[1] = y0
154279
ψ_vec[1] = ψ0
155-
for i = 2:dim
280+
for i in 2:dim
156281
Δt = time_vec[i] - time_vec[i-1]
157282
ψ_vec[i] = ψ_vec[i-1] + r_vec[i] * Δt
158-
x_vec[i] = x_vec[i-1] + (u_vec[i] * cos(ψ_vec[i]) - v_vec[i] * sin(ψ_vec[i])) * Δt
159-
y_vec[i] = y_vec[i-1] + (u_vec[i] * sin(ψ_vec[i]) + v_vec[i] * cos(ψ_vec[i])) * Δt
283+
x_vec[i] =
284+
x_vec[i-1] + (u_vec[i] * cos(ψ_vec[i]) - v_vec[i] * sin(ψ_vec[i])) * Δt
285+
y_vec[i] =
286+
y_vec[i-1] + (u_vec[i] * sin(ψ_vec[i]) + v_vec[i] * cos(ψ_vec[i])) * Δt
160287
end
161288
x_vec, y_vec, ψ_vec
162289
end
@@ -165,12 +292,12 @@ function nuts_sampling_single_thread(
165292
model,
166293
n_samples::Int,
167294
n_chains::Int;
168-
target_acceptance::Float64 = 0.65,
169-
progress = true,
295+
target_acceptance::Float64=0.65,
296+
progress=true,
170297
)
171298
sampler = NUTS(target_acceptance)
172299
mapreduce(
173-
c -> sample(model, sampler, n_samples, progress = progress),
300+
c -> sample(model, sampler, n_samples, progress=progress),
174301
chainscat,
175302
1:n_chains,
176303
)
@@ -180,9 +307,9 @@ function nuts_sampling_multi_threads(
180307
model,
181308
n_samples::Int,
182309
n_chains::Int;
183-
target_acceptance::Float64 = 0.65,
184-
progress = false,
310+
target_acceptance::Float64=0.65,
311+
progress=false,
185312
)
186313
sampler = NUTS(target_acceptance)
187-
sample(model, sampler, MCMCThreads(), n_samples, n_chains, progress = progress)
314+
sample(model, sampler, MCMCThreads(), n_samples, n_chains, progress=progress)
188315
end

src/draw.jl

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)