Commit 81dede1c99d6bb5bc7303ee5c4f5fd960a3af285

Authored by Jérémy Baudry
0 parents
Exists in master

first commit

nml/parameter.nml 0 → 100644
  1 +++ a/nml/parameter.nml
@@ -0,0 +1,40 @@ @@ -0,0 +1,40 @@
  1 +
  2 +&waves_parameters
  3 +
  4 +Tm =6
  5 +Hs =1
  6 +disp =0
  7 +
  8 +
  9 +
  10 +/
  11 +
  12 +&model_parameter
  13 +
  14 +nbin =10
  15 +dx =5000
  16 +Cfl =0.7
  17 +/
  18 +
  19 +
  20 +&spectrum_parameters
  21 +
  22 +
  23 +nfreq =60
  24 +Tmin =2.5
  25 +Tmax =20
  26 +alpha_s =0.2044
  27 +beta_s =1.2500
  28 +gamma_s =3.3
  29 +
  30 +
  31 +/
  32 +
  33 +&ice_parameters
  34 +cice =0.5
  35 +hice =1
  36 +D0 =500
  37 +gam =1.5
  38 +Dmin =20
  39 +
  40 +/
nml/parameter.nml~ 0 → 100644
  1 +++ a/nml/parameter.nml~
@@ -0,0 +1,40 @@ @@ -0,0 +1,40 @@
  1 +
  2 +&waves_parameters
  3 +
  4 +Tm =6
  5 +Hs =1
  6 +disp =0
  7 +
  8 +
  9 +
  10 +/
  11 +
  12 +&model_parameter
  13 +
  14 +nbin =10
  15 +dx =5000
  16 +Cfl =0.1
  17 +/
  18 +
  19 +
  20 +&spectrum_parameters
  21 +
  22 +
  23 +nfreq =60
  24 +Tmin =2.5
  25 +Tmax =20
  26 +alpha_s =0.2044
  27 +beta_s =1.2500
  28 +gamma_s =3.3
  29 +
  30 +
  31 +/
  32 +
  33 +&ice_parameters
  34 +cice =0.5
  35 +hice =1
  36 +D0 =500
  37 +gam =1.5
  38 +Dmin =20
  39 +
  40 +/
output/data_treatment.m 0 → 100644
  1 +++ a/output/data_treatment.m
@@ -0,0 +1,18 @@ @@ -0,0 +1,18 @@
  1 +% clear all;
  2 +close all;
  3 +
  4 +E=load('output/Energy_spectrum.dat');
  5 +subplot(1,2,1)
  6 +cmap=jet(size(E,1));
  7 +for i=1:size(E,1)
  8 + plot(E(i,:),'color',cmap(i,:))
  9 + hold on
  10 +
  11 +
  12 +end
  13 +
  14 +FSD=load('output/floe_size.dat');
  15 +subplot(1,2,2)
  16 +plot(FSD(:,1))
  17 +hold on
  18 +plot(FSD(:,2),'r')
src/advection.f90 0 → 100644
  1 +++ a/src/advection.f90
@@ -0,0 +1,38 @@ @@ -0,0 +1,38 @@
  1 +subroutine advection
  2 +
  3 +use parameters
  4 +
  5 +implicit none
  6 +
  7 + double precision, allocatable :: beta_1(:),beta_2(:),beta_3(:)
  8 +
  9 +
  10 + allocate(beta_1(nfreq))
  11 + allocate(beta_2(nfreq))
  12 + allocate(beta_3(nfreq))
  13 +
  14 + beta_1=CN/2*(CN+1)
  15 + beta_2=1-CN**2
  16 + beta_3=CN/2*(CN-1)
  17 +
  18 +
  19 + E(n,1,1:nfreq)=beta_2*E(n-1,1,1:nfreq)+beta_3*E(n-1,2,1:nfreq)
  20 +
  21 + if (i.le.nbin) then
  22 + E(n,i,1:nfreq)=beta_1*E(n-1,i-1,1:nfreq)+beta_2*E(n-1,i,1:nfreq)+beta_3*E(n-1,i+1,1:nfreq)
  23 + else
  24 +
  25 + E(n,i,1:nfreq)=beta_1*E(n-1,i-1,1:nfreq)!+beta_2*E(n-1,i,1:nfreq)
  26 + end if
  27 +
  28 +
  29 + do j=1,nbin
  30 + do ii=1,nfreq
  31 + if (E(n,j,ii).lt.0) then
  32 + E(n,j,ii)=0
  33 + end if
  34 + end do
  35 + end do
  36 +
  37 +
  38 +end subroutine advection
src/attenuation.f90 0 → 100644
  1 +++ a/src/attenuation.f90
@@ -0,0 +1,56 @@ @@ -0,0 +1,56 @@
  1 +subroutine attenuation
  2 +use parameters
  3 +
  4 +implicit none
  5 +
  6 + double precision :: q11,q12,q13,q14,q15,q21,q22,q23,q24,q25
  7 + double precision :: q31,q32,q33,q34,q35
  8 + double precision, allocatable ::p1(:),p2(:),p3(:),att(:)
  9 +
  10 + allocate(p1(nfreq))
  11 + allocate(p2(nfreq))
  12 + allocate(p3(nfreq))
  13 + allocate(att(nfreq))
  14 +
  15 +
  16 +q11 = -0.00000777
  17 +q12 = 0.00032080
  18 +q13 = -0.00437542
  19 +q14 = 0.02047559
  20 +q15 = -0.01356537
  21 +
  22 +q21 = 0.00003635
  23 +q22 = -0.00153484
  24 +q23 = 0.02121709
  25 +q24 = -0.09289399
  26 +q25 = -0.03693082
  27 +
  28 +q31 = -0.00004509
  29 +q32 = 0.00214484
  30 +q33 = -0.03663425
  31 +q34 = 0.26065369
  32 +q35 = -0.62474085
  33 +
  34 +p1 = q11*T**4 + q12*T**3 + q13*T**2 + q14*T + q15
  35 +p2 = q21*T**4 + q22*T**3 + q23*T**2 + q24*T + q25
  36 +p3 = q31*T**4 + q32*T**3 + q33*T**2 + q34*T + q35
  37 +
  38 +alpha(i,1:nfreq)=-1*(p1*h(i)**2 + p2*h(i) + p3)
  39 +
  40 +do j=1,nfreq
  41 +if (alpha(i,j).lt.0)then
  42 +alpha(i,j)=0
  43 +end if
  44 +end do
  45 +
  46 +att=C_ice(i)*alpha(i,1:nfreq)/Dave(i)
  47 +
  48 +
  49 +S_ice(i,1:nfreq)=-att*E(n,i,1:nfreq)
  50 +
  51 +E(n,i,1:nfreq)=E(n,i,1:nfreq)*exp(-att*Cg*dt)
  52 +
  53 +
  54 +
  55 +
  56 +end subroutine attenuation
src/floe_breaking.f90 0 → 100644
  1 +++ a/src/floe_breaking.f90
@@ -0,0 +1,73 @@ @@ -0,0 +1,73 @@
  1 +subroutine floe_breaking
  2 +
  3 +use parameters
  4 +
  5 +implicit none
  6 + double precision, allocatable :: WN_ice(:),fnt(:),k(:)
  7 + double precision ::rho=1025,d,F,Y=5.5,v=0.3
  8 + integer :: acc=1000
  9 + double precision, allocatable :: W(:)
  10 + double precision, allocatable :: fnt_d(:)
  11 +
  12 + double precision, allocatable :: S(:)
  13 + double precision :: SS
  14 + double precision :: WN_ice_d
  15 + double precision :: RS=7.05e-05
  16 + double precision :: m0_s
  17 + double precision :: m0_a
  18 + double precision :: m2_a
  19 + double precision :: Tw
  20 + double precision :: om_d
  21 + double precision :: wl_w
  22 +
  23 + allocate(fnt(acc+1))
  24 + allocate(k(acc+1))
  25 + allocate(WN_ice(nfreq))
  26 + allocate(W(nfreq))
  27 + allocate(fnt_d(acc+1))
  28 + allocate(S(nfreq))
  29 +
  30 +
  31 + F=Y*h(i)**3/12*(1-v**2)
  32 + d=0.9*h(i)
  33 +
  34 + jj=1
  35 + do ii=0,acc
  36 + k(jj)=real(ii)*2/real(acc)
  37 + jj=jj+1
  38 + end do
  39 +
  40 +
  41 + do j=1,nfreq
  42 + fnt=F*k**5+rho*(g-d*omega(j)**2)*k-rho*omega(j)**2
  43 + WN_ice(j)=k(minloc(abs(fnt),DIM=1))
  44 +
  45 + end do
  46 +
  47 +
  48 + W=g*WN_ice/omega**2
  49 + S=(h(i)/2)*WN_ice**2*W
  50 + m0_s=sum(E(n,i,1:nfreq)*S**2)*domega
  51 + SS=2*sqrt(m0_s)
  52 +
  53 + if (SS.gt.RS) then
  54 +
  55 + m0_a=sum(E(n,i,1:nfreq)*W**2)*domega
  56 + m2_a=sum(omega**2*E(n,i,1:nfreq)*W**2)*domega
  57 + Tw=2*pi*sqrt(m0_a/m2_a)
  58 + om_d=2*pi/Tw
  59 +
  60 + fnt_d=F*k**5+rho*(g-d*om_d**2)*k-rho*om_d**2
  61 + WN_ice_d=k(minloc(abs(fnt_d),DIM=1))
  62 +
  63 + wl_w=2*pi/WN_ice_d
  64 +
  65 + Dmax(i)=max(Dmin,min(wl_w/2,Dmax(i)))
  66 +
  67 +
  68 + end if
  69 +
  70 +
  71 +
  72 +
  73 +end subroutine floe_breaking
src/fsd_build.f90 0 → 100644
  1 +++ a/src/fsd_build.f90
@@ -0,0 +1,17 @@ @@ -0,0 +1,17 @@
  1 +subroutine fsd_build
  2 +use parameters
  3 +
  4 + implicit none
  5 + double precision :: coeff
  6 +
  7 + if (Dmax(i).eq.Dmin) then
  8 + Dave(i)=Dmin
  9 + elseif (Dmax(i).eq.D0) then
  10 + Dave(i)=Dmax(i)
  11 + else
  12 + coeff=1/((1/(1-gam))*(Dmax(i)**(1-gam)-Dmin**(1-gam)))
  13 + Dave(i)=coeff*(1/(2-gam))*(Dmax(i)**(2-gam)-Dmin**(2-gam))
  14 + end if
  15 +
  16 +
  17 +end subroutine fsd_build
src/initialization.f90 0 → 100644
  1 +++ a/src/initialization.f90
@@ -0,0 +1,37 @@ @@ -0,0 +1,37 @@
  1 +subroutine initialization
  2 +use parameters
  3 +
  4 +!local parameters
  5 +implicit none
  6 + double precision, allocatable ::Gf(:),PM(:)
  7 +
  8 + allocate(Gf(nfreq))
  9 + allocate(PM(nfreq))
  10 +
  11 +
  12 +
  13 +!_________________________INITIAL SPECTRUM_____________________________
  14 + E(1,1:nbin,1:nfreq)=0
  15 +
  16 + !build JONSWAP spectrum
  17 +
  18 + do i=1,nfreq
  19 + if (freq(i).le.freq_s) then
  20 + sigma_s(i)=0.07
  21 + else
  22 + sigma_s(i)=0.09
  23 + end if
  24 + end do
  25 +
  26 + Gf=gamma_s**(exp((-(freq-freq_s)**2)/(2*sigma_s**2*freq_s**2)))
  27 + PM=alpha_s*Hs**2*(freq_s**4/freq**5)*exp(-beta_s*(freq_s/freq)**4)
  28 +
  29 + Ei=Gf*PM
  30 +
  31 +
  32 +
  33 + E(1,1,1:nfreq)=Ei
  34 +
  35 +!_______________________________________________________________________
  36 +
  37 +end subroutine initialization
src/main.f90 0 → 100644
  1 +++ a/src/main.f90
@@ -0,0 +1,67 @@ @@ -0,0 +1,67 @@
  1 +PROGRAM WIM2
  2 +
  3 +
  4 + use parameters
  5 + call read_namelist
  6 + call array_allocation
  7 + call initialization
  8 +
  9 +
  10 +
  11 +
  12 +!______________________________________________________
  13 +
  14 +
  15 +
  16 +
  17 +
  18 +!_______________________TIME LOOP______________________
  19 + do n=2,nsteps
  20 +
  21 + call progress(n,nsteps)
  22 +
  23 + do i=2,nbin
  24 + call advection
  25 + !call attenuation
  26 + !call floe_breaking
  27 + !call fsd_build
  28 + end do
  29 + end do
  30 + !______________________OUTPUTS_________________________
  31 + root='output/'
  32 + spectrum=trim(root)//'Energy_spectrum.dat'
  33 + floe_size=trim(root)//'floe_size.dat'
  34 +
  35 +
  36 + open(10,file=spectrum)
  37 + open(11,file=floe_size)
  38 +
  39 + !call write_output
  40 + do i=1,nbin
  41 + !do j=1,nsteps
  42 + write(10,*)E(nsteps,i,1:nfreq)
  43 + !end do
  44 + write(11,*)Dave(i),Dmax(i)
  45 + end do
  46 +
  47 + close(10)
  48 + close(11)
  49 +
  50 +
  51 +
  52 +contains
  53 +
  54 +subroutine progress(j,jmax)
  55 + implicit none
  56 + integer::j,k,jmax
  57 + character(len=15)::bar="processing ???%"
  58 + write(unit=bar(12:14),fmt="(i3)")ceiling((real(j)/real(jmax))*100)
  59 + write(unit=6,fmt="(a1,a17)",advance="no") char(13), bar
  60 + if (ceiling((real(j)/real(jmax))*100).eq.100) then
  61 + write(unit=6,fmt=*)
  62 + write(*,*)'simulation completed!'
  63 +
  64 + endif
  65 +end subroutine progress
  66 +
  67 +END PROGRAM WIM2
src/makefile 0 → 100644
  1 +++ a/src/makefile
@@ -0,0 +1,37 @@ @@ -0,0 +1,37 @@
  1 +COMPILER= gfortran
  2 +
  3 +OPTION= -O3
  4 +
  5 +
  6 +NETCDFinc= -I/usr/local/include
  7 +NETCDFLIB= -L/usr/local/lib -lnetcdf
  8 +
  9 +OBJ= *.o
  10 +
  11 +SRC= *.f90
  12 +
  13 +MOD= parameters.mod
  14 +
  15 +EXEC= WIM2
  16 +
  17 +
  18 +
  19 +WIM2: $(OBJ)
  20 + $(COMPILER) $(OPTION) $(NETCDFinc) -o $(EXEC) $(OBJ) $(NETCDFLIB)
  21 + mv WIM2 ../
  22 +
  23 +
  24 +$(MOD): parameters.f90
  25 + $(COMPILER) -c parameters.f90
  26 +
  27 +
  28 +$(OBJ): $(SRC) $(MOD)
  29 + $(COMPILER) $(NETCDFinc) -c $(SRC) $(NETCDFLIB)
  30 +
  31 +
  32 +clean:
  33 + rm -f *.o *.mod
  34 +
  35 +mrproper:
  36 +
  37 + rm -f *.o *.mod ../WIM2
src/makefile~ 0 → 100644
  1 +++ a/src/makefile~
@@ -0,0 +1,37 @@ @@ -0,0 +1,37 @@
  1 +COMPILER= ifort
  2 +
  3 +OPTION= -O3
  4 +
  5 +
  6 +NETCDFinc= -I/usr/local/include
  7 +NETCDFLIB= -L/usr/local/lib -lnetcdf
  8 +
  9 +OBJ= *.o
  10 +
  11 +SRC= *.f90
  12 +
  13 +MOD= parameters.mod
  14 +
  15 +EXEC= WIM2
  16 +
  17 +
  18 +
  19 +WIM2: $(OBJ)
  20 + $(COMPILER) $(OPTION) $(NETCDFinc) -o $(EXEC) $(OBJ) $(NETCDFLIB)
  21 + mv WIM2 ../
  22 +
  23 +
  24 +$(MOD): parameters.f90
  25 + $(COMPILER) -c parameters.f90
  26 +
  27 +
  28 +$(OBJ): $(SRC) $(MOD)
  29 + $(COMPILER) $(NETCDFinc) -c $(SRC) $(NETCDFLIB)
  30 +
  31 +
  32 +clean:
  33 + rm -f *.o *.mod
  34 +
  35 +mrproper:
  36 +
  37 + rm -f *.o *.mod ../WIM2
src/parameters.f90 0 → 100644
  1 +++ a/src/parameters.f90
@@ -0,0 +1,147 @@ @@ -0,0 +1,147 @@
  1 +module parameters
  2 +
  3 +implicit none
  4 +
  5 +!__________________name of files__________________
  6 + character(len=100) ::root,spectrum,floe_size
  7 +
  8 +!______________dummys_____________________________
  9 + integer :: i,ii,n,j,jj
  10 +!______________global parameters__________________
  11 +
  12 + double precision :: g=9.81,pi=3.1416
  13 +!____________Spectrum_____________________________
  14 + double precision, allocatable :: E(:,:,:),Ei(:),T(:)
  15 + double precision, allocatable :: omega(:),freq(:),sigma_s(:)
  16 + integer :: nbin=10,nfreq=60
  17 + double precision :: alpha_s=8.1e-3,beta_s=1.25
  18 + double precision :: Tmin=2.5,Tmax=20,Tm=6,Hs=1
  19 + double precision :: gamma_s=3.3,freq_s,domega
  20 +!____________waves_________________________________
  21 + double precision, allocatable ::wl(:),Cp(:),Cg(:),CN(:)
  22 + integer ::disp=0
  23 +!____________grid parameters________________________
  24 + double precision :: dt,dx=500
  25 + integer :: nsteps
  26 + double precision :: Cfl=1
  27 +!_____________ICE_____________________________________
  28 + double precision, allocatable :: alpha(:,:)
  29 + double precision, allocatable :: h(:)
  30 + double precision, allocatable :: C_ice(:)
  31 + double precision, allocatable :: S_ice(:,:)
  32 + double precision :: cice=1
  33 + double precision :: hice=1
  34 + double precision, allocatable :: Dave(:)
  35 + double precision, allocatable :: Dmax(:)
  36 + double precision :: D0=200
  37 + double precision :: gam=2
  38 + double precision :: Dmin=20
  39 +
  40 +
  41 +
  42 +
  43 +
  44 +contains
  45 +
  46 +
  47 +subroutine read_namelist
  48 +
  49 + namelist /spectrum_parameters/ nfreq,alpha_s, &
  50 + beta_s,Tmin,Tmax,gamma_s
  51 + namelist /model_parameter/ nbin,dx,Cfl
  52 + namelist /waves_parameters/ Tm,Hs,disp
  53 + namelist /ice_parameters/ cice,hice,D0,gam,Dmin
  54 +
  55 + open(30,file='nml/parameter.nml',status='old')
  56 + read(30,nml=spectrum_parameters)
  57 + close(30)
  58 +
  59 + open(30,file='nml/parameter.nml',status='old')
  60 + read(30,nml=model_parameter)
  61 + close(30)
  62 +
  63 + open(30,file='nml/parameter.nml',status='old')
  64 + read(30,nml=waves_parameters)
  65 + close(30)
  66 +
  67 + open(30,file='nml/parameter.nml',status='old')
  68 + read(30,nml=ice_parameters)
  69 + close(30)
  70 +
  71 +
  72 +end subroutine read_namelist
  73 +
  74 +
  75 +
  76 +subroutine array_allocation
  77 +
  78 +nfreq=nfreq+1
  79 +
  80 +
  81 +
  82 +
  83 +allocate(Ei(nfreq))
  84 +allocate(T(nfreq))
  85 +allocate(omega(nfreq))
  86 +allocate(freq(nfreq))
  87 +allocate(sigma_s(nfreq))
  88 +allocate(wl(nfreq))
  89 +allocate(Cp(nfreq))
  90 +allocate(Cg(nfreq))
  91 +allocate(CN(nfreq))
  92 +allocate(alpha(nbin,nfreq))
  93 +allocate(h(nbin))
  94 +allocate(C_ice(nbin))
  95 +allocate(S_ice(nbin,nfreq))
  96 +
  97 +
  98 +
  99 + domega=(2*pi/Tmin-2*pi/Tmax)/(nfreq-1)
  100 + ii=1
  101 + do i=0,nfreq-1
  102 + omega(ii)=2*pi/Tmax+i*domega
  103 + freq(ii)=1/Tmax+i*(1/Tmin-1/Tmax)/(nfreq-1)
  104 + ii=ii+1
  105 + end do
  106 + T=1/freq
  107 + freq_s=1/Tm
  108 + wl=g*T**2/(2*pi)
  109 + Cp=sqrt(g*wl/(2*pi))
  110 + Cg=Cp/2
  111 +
  112 +
  113 +
  114 + if (disp.eq.0) then
  115 + CN=Cfl
  116 + Cg=maxval(Cg)
  117 + dt=CN(1)*dx/maxval(Cg)
  118 + end if
  119 +
  120 +
  121 +
  122 + nsteps=ceiling(nbin/minval(CN))
  123 +
  124 + h(1:nbin)=hice
  125 + C_ice(1:nbin)=cice
  126 +
  127 +
  128 +
  129 +
  130 +allocate(E(nsteps,nbin,nfreq))
  131 +allocate(Dmax(nbin))
  132 +allocate(Dave(nbin))
  133 +
  134 + Dmax=D0
  135 + Dave=D0
  136 + Dmax(1)=0
  137 + Dave(1)=0
  138 +
  139 +end subroutine array_allocation
  140 +
  141 +
  142 +
  143 +
  144 +
  145 +
  146 +
  147 +end module parameters
src/write_output.f90 0 → 100644
  1 +++ a/src/write_output.f90
@@ -0,0 +1,28 @@ @@ -0,0 +1,28 @@
  1 +subroutine write_output
  2 +
  3 +use netcdf
  4 +use parameters
  5 +implicit none
  6 +include 'netcdf.inc'
  7 + integer :: ncid,omID,xID,tID,SpectreID
  8 + integer :: om_varID,x_varID,t_varID
  9 +
  10 +
  11 +nf90_create("foo.nc",nf90_noclobber,ncid)
  12 +
  13 +nf90_def_dim(ncid,"omega", nfreq, omID)
  14 +nf90_def_dim(ncid,"x_axis", nbin, xID)
  15 +nf90_def_dim(ncid,"time", nsteps, tID)
  16 +
  17 +nf90_def_var(ncid,"omega",nf90_double,omID,om_varID)
  18 +nf90_def_var(ncid,"x_axis",nf90_double,xID,x_varID)
  19 +nf90_def_var(ncid,"time",nf90_double,tID,t_varID)
  20 +nf90_def_var(ncid,"Spectrum",nf90_double,(/ tID, xID, omID /),SpectreID)
  21 +
  22 +
  23 +nf90_put_att(ncid,ID,"units", values)
  24 +nf90_put_var(ncid,SpectreID,E)
  25 +
  26 +
  27 +
  28 +end subroutine write_output