This repository was archived by the owner on May 15, 2024. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathwaveFunctions.f90
More file actions
322 lines (271 loc) · 11.4 KB
/
Copy pathwaveFunctions.f90
File metadata and controls
322 lines (271 loc) · 11.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
!! SPDX-FileCopyrightText: 2023 SAP SE
!!
!! SPDX-License-Identifier: Apache-2.0
!!
!! This file is part of FEDEM - https://openfedem.org
!!==============================================================================
!> @file waveFunctions.f90
!> @brief Global functions callable from C++ code.
!>
!> @details This file contains global function wrappers of subroutines from the
!> wavefunctionsmodule, such that they can be invoked from C++ or python.
!!==============================================================================
!> @brief Initializes parameters for a wave function from given file.
!> @param[in] fName Name of file to read parameters from
!> @param[in] nWave Number of wave components to read
!> @param[in] rSeed Seed for (pseudo-)random phase shift
!> @param[out] rfunc Wave function parameters (amplitude, frequency, ...)
!> @param[out] ierr Error flag
subroutine initWaveFuncFromFile (fName, nWave, rSeed, rfunc, ierr)
use WaveFunctionsModule, only : dp, initFUNC4
character(len=*), intent(in) :: fName
integer , intent(in) :: nWave, rSeed
real(dp) , intent(out) :: rfunc(3,nWave)
integer , intent(out) :: ierr
!! --- Logic section ---
call initFUNC4 (fName,0.0_dp,0.0_dp,rfunc,ierr,rSeed)
end subroutine initWaveFuncFromFile
!!==============================================================================
!> @brief Initializes parameters for a wave function from a wave spectrum.
!> @param[in] iopW Wave spectrum model
!> @param[in] nWave Number of wave components to generate
!> @param[in] nDir Number of wave directions (for @a iopW > 4 only)
!> @param[in] sprExp Wave spreading exponent (for @a iopW > 4 and @a nDir > 1)
!> @param[in] rSeed Seed for (pseudo-)random phase shift
!> @param[out] rfunc Wave function parameters (amplitude, frequency, ...)
!> @param[out] ierr Error flag
subroutine initWaveFuncSpectrum (iopW, nWave, nDir, sprExp, rSeed, rfunc, ierr)
use WaveFunctionsModule, only : dp, twoPi, initFUNC4
integer , intent(in) :: iopW, nWave, nDir, sprExp, rSeed
real(dp), intent(inout) :: rfunc(3,nWave*nDir)
integer , intent(out) :: ierr
!! Local variables
real(dp) :: H3, T1, w0, w1, dw, Ga
!! --- Logic section ---
H3 = rfunc(1,1)
T1 = rfunc(2,1)
Ga = rfunc(2,2)
if (rfunc(3,1) > 0.0_dp .and. rfunc(1,2) > 0.0_dp) then
w0 = twoPi/rfunc(3,1)
w1 = twoPi/rfunc(1,2)
else
!! Assuming the frequency range is specified directly
w0 = abs(rfunc(3,1))
w1 = abs(rfunc(1,2))
end if
dw = (w1-w0)/real(nWave,dp)
if (iopW > 4) then
!! Use new implementation, based on the DNV RP 205
if (iopW == 5 .or. iopW == 6) Ga = 1.0_dp ! Pierson-Moskowitz
if (iopW == 5 .or. iopW == 7) w0 = -w0 ! Use constant frequency intervals
call initFUNC4 (H3,T1,Ga,w0,dw,0.0_dp,0.0_dp,rfunc,ierr,rSeed,nDir,sprExp)
else
!! Old implementation, based on O. Faltinsen's book
call initFUNC4 (iopW,H3,T1,Ga,w0,dw,0.0_dp,0.0_dp,rfunc,ierr,rSeed)
end if
end subroutine initWaveFuncSpectrum
!!==============================================================================
!> @brief Initializes parameters for a non-linear wave function.
!> @param[in] iopW Wave model option
!> @param[in] g Gravity constant
!> @param[in] D Water depth
!> @param RFUNC Wave function parameters
!> @param[out] stat Error flag
subroutine initNonlinWaveFunc (iopW, g, D, RFUNC, stat)
use WaveFunctionsModule, only : dp, initFUNC7, initFUNC8
integer , intent(in) :: iopW
real(dp), intent(in) :: g, D
real(dp), intent(inout) :: rfunc(*)
integer , intent(out) :: stat
!! --- Logic section ---
if (iopW == 7) then
call initFUNC7 (rfunc(2),rfunc(1),rfunc(3),g,D,RFUNC,stat)
else
call initFUNC8 (rfunc(2),rfunc(1),rfunc(3),g,D,RFUNC,stat)
end if
if (stat > 0) stat = 2*stat+1 ! = size(rfunc)
end subroutine initNonlinWaveFunc
!!==============================================================================
!> @brief Initializes parameters for an embedded non-linear wave function.
!> @param[in] iopW Wave model option
!> @param[in] nWave Number of wave components
!> @param[in] rSeed Seed for (pseudo-)random phase shift
!> @param[in] g Gravity constant
!> @param[in] D Water depth
!> @param ifunc Integer wave function parameters
!> @param rfunc Real wave function parameters
!> @param[out] ierr Error flag
subroutine initEmbeddedWave (iopW, nWave, rSeed, g, D, ifunc, rfunc, ierr)
use WaveFunctionsModule, only : dp, twoPi, initFUNC9
use FFaMsgInterface , only : ffamsg_list
integer , intent(in) :: iopW, nWave, rSeed
real(dp), intent(in) :: g, D
integer , intent(inout) :: ifunc(*)
real(dp), intent(inout) :: rfunc(*)
integer , intent(out) :: ierr
!! Local variables
integer :: nS, nR
real(dp) :: H3, T1, w0, w1, dw, Ga, ramp(2)
real(dp), allocatable :: sfunc(:,:)
!! --- Logic section ---
nS = ifunc(4)
allocate(sfunc(3,nS),stat=ierr)
if (ierr /= 0) then
call ffamsg_list ('initEmbeddedWave: Allocation failure',ierr)
ierr = -abs(ierr)
return
else
sfunc = reshape(rfunc(8:7+3*nS),(/3,nS/))
end if
nR = ifunc(5)
H3 = rfunc(1)
T1 = rfunc(2)
Ga = rfunc(5)
if (rfunc(3) > 0.0_dp .and. rfunc(4) > 0.0_dp) then
w0 = twoPi/rfunc(3)
w1 = twoPi/rfunc(4)
else
!! Assuming the frequency range is specified directly
w0 = abs(rfunc(3))
w1 = abs(rfunc(4))
end if
dw = (w1-w0)/real(nWave,dp)
ramp = rfunc(6:7)
if (iopW == 5 .or. iopW == 6) Ga = 1.0_dp ! Pierson-Moskowitz
if (iopW == 5 .or. iopW == 7) w0 = -w0 ! Use constant frequency intervals
call initFUNC9 (iopW,3,nWave,H3,T1,Ga,w0,dw,g,D,ramp,sfunc, &
& ifunc(1:4+nS),rfunc(1:nR),ierr,rSeed)
deallocate(sfunc)
end subroutine initEmbeddedWave
!!==============================================================================
!> @brief Evaluates a wave profile function.
!> @param[in] iopW Wave model option
!> @param[in] ldi Number of integer parameters
!> @param[in] ldr Number of real parameters per wave component
!> @param[in] nWave Number of wave components
!> @param[in] nDir Number of wave directions
!> @param[in] ifunc Integer wave function parameters
!> @param[in] rfunc Real wave function parameters
!> @param[in] g Gravity constant
!> @param[in] d Water depth
!> @param[in] x Position to evaluate wave profile at
!> @param[in] t Time to evaluate wave profile at
!> @return Wave elevation
function waveProfile (iopW, ldi, ldr, nWave, nDir, ifunc, rfunc, &
& g, d, x, t) result(h)
use WaveFunctionsModule , only : dp, deepWave, deepWaves
use WaveFunctionsModule , only : finiteDepthWave, finiteDepthWaves
use WaveFunctionsModule , only : stokes2Wave, stokes5Wave, streamWave
use WaveFunctionsModule , only : embeddedWave, userDefinedWave
use ExplicitFunctionsModule, only : WAVE_STOKES5_p, WAVE_STREAMLINE_p
use ExplicitFunctionsModule, only : WAVE_EMBEDDED_p, USER_DEFINED_p
integer , intent(in) :: iopW, ldi, ldr, nWave, ifunc(ldi)
real(dp), intent(in) :: rfunc(ldr,nWave,nDir), g, d, x(3), t
integer :: ierr
real(dp) :: h, v(3), a(3), Xt(4)
real(dp), parameter :: z = 100000.0_dp
logical , parameter :: atS_p = .false., noWS_p = .false.
!! --- Logic section ---
select case (iopW)
case (0)
if (nDir < 2) then
call deepWave (rfunc(:,:,1),g,x(1),z,t,atS_p,noWS_p, &
& h,v(1),v(3),a(1),a(3))
else
call deepWaves (rfunc,g,x(1),x(2),z,t,atS_p,noWS_p, &
& h,v(1),v(2),v(3),a(1),a(2),a(3))
end if
case (1)
if (nDir < 2) then
call finiteDepthWave (rfunc(:,:,1),g,d,x(1),z,t,atS_p,noWS_p, &
& h,v(1),v(3),a(1),a(3))
else
call finiteDepthWaves (rfunc,g,d,x(1),x(2),z,t,atS_p,noWS_p, &
& h,v(1),v(2),v(3),a(1),a(2),a(3))
end if
case (2)
call stokes2Wave (rfunc(:,:,1),g,d,x(1),z,t,atS_p,noWS_p, &
& h,v(1),v(3),a(1),a(3))
case (WAVE_STOKES5_p)
call stokes5Wave (rfunc(:,1,1),d,x(1),z,t,atS_p, &
& h,v(1),v(3),a(1),a(3))
case (WAVE_STREAMLINE_p)
call streamWave (rfunc(:,1,1),d,x(1),z,t,atS_p, &
& h,v(1),v(3),a(1),a(3))
case (WAVE_EMBEDDED_p)
call embeddedWave (ifunc,rfunc(:,1,1),g,d,x(1),z,t,atS_p,noWS_p, &
& h,v(1),v(3),a(1),a(3))
case (USER_DEFINED_p)
Xt(1:3) = x; Xt(4) = t
call userDefinedWave (1,ifunc,rfunc(:,1,1),g,d,Xt,atS_p,h,v,a,ierr)
case default
h = 0.0_dp ! Invalid wave function type
end select
end function waveProfile
!!==============================================================================
!> @brief Evaluates a wave profile.
!> @param[in] iopW Wave model option
!> @param[in] ldi Number of integer parameters
!> @param[in] ldr Number of real parameters per wave component
!> @param[in] nWave Number of wave components
!> @param[in] nDir Number of wave directions
!> @param[in] ifunc Integer wave function parameters
!> @param[in] rfunc Real wave function parameters
!> @param[in] g Gravity constant
!> @param[in] d Water depth
!> @param[in] x Position to evaluate wave profile at
!> @param[in] t Time to evaluate wave profile at
!> @param[out] h Wave elevation
!> @param[out] v Water particle velocity
!> @param[out] a Water particle acceleration
subroutine evalWave (iopW, ldi, ldr, nWave, nDir, ifunc, rfunc, &
& g, d, x, t, h, v, a)
use WaveFunctionsModule , only : dp, deepWave, deepWaves
use WaveFunctionsModule , only : finiteDepthWave, finiteDepthWaves
use WaveFunctionsModule , only : stokes2Wave, stokes5Wave, streamWave
use WaveFunctionsModule , only : embeddedWave, userDefinedWave
use ExplicitFunctionsModule, only : WAVE_STOKES5_p, WAVE_STREAMLINE_p
use ExplicitFunctionsModule, only : WAVE_EMBEDDED_p, USER_DEFINED_p
integer , intent(in) :: iopW, ldi, ldr, nWave, ifunc(ldi)
real(dp), intent(in) :: rfunc(ldr,nWave,nDir), g, d, x(3), t
integer :: ierr
real(dp) :: Xt(4)
real(dp), intent(out) :: h, v(3), a(3)
logical , parameter :: atS_p = .false., noWS_p = .false.
!! --- Logic section ---
v(2) = 0.0_dp
a(2) = 0.0_dp
select case (iopW)
case (0)
if (nDir < 2) then
call deepWave (rfunc(:,:,1),g,x(1),x(3),t,atS_p,noWS_p, &
& h,v(1),v(3),a(1),a(3))
else
call deepWaves (rfunc,g,x(1),x(2),x(3),t,atS_p,noWS_p,h, &
& v(1),v(2),v(3),a(1),a(2),a(3))
end if
case (1)
if (nDir < 2) then
call finiteDepthWave (rfunc(:,:,1),g,d,x(1),x(3),t,atS_p,noWS_p, &
& h,v(1),v(3),a(1),a(3))
else
call finiteDepthWaves (rfunc,g,d,x(1),x(2),x(3),t,atS_p,noWS_p, &
& h,v(1),v(2),v(3),a(1),a(2),a(3))
end if
case (2)
call stokes2Wave (rfunc(:,:,1),g,d,x(1),x(3),t,atS_p,noWS_p, &
& h,v(1),v(3),a(1),a(3))
case (WAVE_STOKES5_p)
call stokes5Wave (rfunc(:,1,1),d,x(1),x(3),t,atS_p,h,v(1),v(3),a(1),a(3))
case (WAVE_STREAMLINE_p)
call streamWave (rfunc(:,1,1),d,x(1),x(3),t,atS_p,h,v(1),v(3),a(1),a(3))
case (WAVE_EMBEDDED_p)
call embeddedWave (ifunc,rfunc(:,1,1),g,d,x(1),x(3),t,atS_p,noWS_p, &
& h,v(1),v(3),a(1),a(3))
case (USER_DEFINED_p)
Xt(1:3) = x; Xt(4) = t
call userDefinedWave (1,ifunc,rfunc(:,1,1),g,d,Xt,atS_p,h,v,a,ierr)
case default
h = 0.0_dp ! Invalid wave function type
end select
end subroutine evalWave