Constructor function for the spectrum object.
monochromatic
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=rk), | intent(in) | :: | fmin | Minimum frequency bin [Hz] |
||
real(kind=rk), | intent(in) | :: | fmax | Maximum frequency bin [Hz] |
||
real(kind=rk), | intent(in) | :: | df | Frequency increment, df = f(n+1)/f(n) |
||
integer, | intent(in) | :: | ndirs | Number of directional bins |
||
real(kind=rk), | intent(in) | :: | depth | Mean water depth [m] |
||
real(kind=rk), | intent(in), | optional | :: | grav | Gravitational acceleration [m/s^2] |
|
real(kind=rk), | intent(in), | optional | :: | air_density | Air density [kg/m^3] |
|
real(kind=rk), | intent(in), | optional | :: | water_density | Water density [kg/m^3] |
|
real(kind=rk), | intent(in), | optional | :: | surface_tension | Surface tension [N/m] |
pure elemental type(spectrum_type) function constructor(fmin,fmax,df,ndirs,&
depth,grav,air_density,water_density,surface_tension) result(spectrum)
!! Constructor function for the spectrum object.
real(kind=rk),intent(in) :: fmin
!! Minimum frequency bin [Hz]
real(kind=rk),intent(in) :: fmax
!! Maximum frequency bin [Hz]
real(kind=rk),intent(in) :: df
!! Frequency increment, df = f(n+1)/f(n)
integer,intent(in) :: ndirs
!! Number of directional bins
real(kind=rk),intent(in) :: depth
!! Mean water depth [m]
real(kind=rk),intent(in),optional :: grav
!! Gravitational acceleration [m/s^2]
real(kind=rk),intent(in),optional :: air_density
!! Air density [kg/m^3]
real(kind=rk),intent(in),optional :: water_density
!! Water density [kg/m^3]
real(kind=rk),intent(in),optional :: surface_tension
!! Surface tension [N/m]
integer :: n
integer :: nfreqs
if(present(grav))then
spectrum % grav = grav
else
spectrum % grav = 9.8_rk
endif
if(present(air_density))then
spectrum % air_density = air_density
else
spectrum % air_density = 1.2_rk
endif
if(present(water_density))then
spectrum % water_density = water_density
else
spectrum % water_density = 1e3_rk
endif
if(present(surface_tension))then
spectrum % surface_tension = surface_tension
else
spectrum % surface_tension = 0.07_rk
endif
spectrum % depth = depth
if(fmin == fmax)then
!! monochromatic
nfreqs = 1
else
nfreqs = int((log(fmax)-log(fmin))/log(df))
endif
allocate(spectrum % spec(nfreqs,ndirs))
spectrum % spec = 0
allocate(spectrum % f(nfreqs))
allocate(spectrum % df(nfreqs))
allocate(spectrum % k(nfreqs))
allocate(spectrum % dk(nfreqs))
allocate(spectrum % cp(nfreqs))
allocate(spectrum % cg(nfreqs))
allocate(spectrum % th(ndirs))
if(nfreqs == 1)then
spectrum % f(n) = fmin
else
do concurrent(n = 1:nfreqs)
spectrum % f(n) = exp(log(fmin)+(n-1)*log(df))
enddo
endif
do concurrent(n = 1:nfreqs)
spectrum % k(n) = wavenumber(spectrum % f(n), &
spectrum % depth, &
spectrum % water_density,&
spectrum % grav, &
spectrum % surface_tension)
enddo
spectrum % cp = twopi * spectrum % f / spectrum % k
spectrum % cg = twopi * diff(spectrum % f) / diff(spectrum % k)
do concurrent(n = 1:ndirs)
spectrum % th(n) = (n-0.5*(ndirs+1))*twopi/ndirs
enddo
spectrum % df = diff(spectrum % f)
spectrum % dk = diff(spectrum % k)
if(ndirs > 1)then
spectrum % dth = diff_periodic(spectrum % th)
spectrum % dth(1) = spectrum % dth(2)
spectrum % dth(ndirs) = spectrum % dth(ndirs-1)
else
spectrum % dth = [1]
endif
call spectrum % setCurrent2d([0._rk],[0._rk],[0._rk])
endfunction constructor